public void Write(int row, int col, ColorGlyph cg) { int idx = col + row * Cols; if (screenMemory[idx].Equals(cg)) { return; } Color color = cg.ForegroundColor.ResolveColor(); // Random colors won't match at first, but Color bgColor = cg.BackgroundColor.ResolveColor(); // might match after being resolved, so check again: if (screenMemory[idx].Equals(cg.GlyphIndex, color, bgColor)) { return; } screenMemory[idx] = new ColorGlyph(cg.GlyphIndex, color, bgColor); if (firstChangedIdx > idx) { firstChangedIdx = idx; } if (lastChangedIdx < idx) { lastChangedIdx = idx; } if (holdUpdatesCount == 0) { SendDataToWindow(); } }
private void SendDataToWindow() { if (lastChangedIdx == -1) { return; } int count = lastChangedIdx - firstChangedIdx + 1; int[] sprites = new int[count]; float[][] colors = new float[2][]; colors[0] = new float[4 * count]; colors[1] = new float[4 * count]; for (int n = 0; n < count; ++n) { ColorGlyph cg = screenMemory[firstChangedIdx + n]; float[] fgRgba = cg.ForegroundColor.GetRGBA(); float[] bgRgba = cg.BackgroundColor.GetRGBA(); sprites[n] = cg.GlyphIndex; int idx4 = n * 4; colors[0][idx4] = fgRgba[0]; colors[0][idx4 + 1] = fgRgba[1]; colors[0][idx4 + 2] = fgRgba[2]; colors[0][idx4 + 3] = fgRgba[3]; colors[1][idx4] = bgRgba[0]; colors[1][idx4 + 1] = bgRgba[1]; colors[1][idx4 + 2] = bgRgba[2]; colors[1][idx4 + 3] = bgRgba[3]; } Window.UpdateOtherVertexArray(Window.TextSurface, sprites, colors, firstChangedIdx); ResetChangedIndices(); }
public void Write(int startRow, int startCol, ColorGlyph[][] colorGlyphs) { for (int i = 0; i < colorGlyphs.Length; ++i) { if (startRow + i >= Rows) { break; } ColorGlyph[] line = colorGlyphs[i]; int count; if (startCol + line.Length > Cols) { count = Cols - startCol; // Cut off too-long strings } else { count = line.Length; } int startIdx = startCol + (startRow + i) * Cols; for (int j = 0; j < count; ++j) { int idx = startIdx + j; ColorGlyph cg = line[j]; if (screenMemory[idx].Equals(cg)) { continue; } Color color = cg.ForegroundColor.ResolveColor(); // Random colors won't match at first, but Color bgColor = cg.BackgroundColor.ResolveColor(); // might match after being resolved, so check again: if (screenMemory[idx].Equals(cg.GlyphIndex, color, bgColor)) { return; } screenMemory[idx] = new ColorGlyph(cg.GlyphIndex, color, bgColor); if (firstChangedIdx > idx) { firstChangedIdx = idx; } if (lastChangedIdx < idx) { lastChangedIdx = idx; } } } if (holdUpdatesCount == 0) { SendDataToWindow(); } }
public void Write(int row, int col, string str, Color color = Color.Gray, Color bgColor = Color.Black) { int count; if (col + str.Length > Cols) { count = Cols - col; // Cut off too-long strings } else { count = str.Length; } int startIdx = col + row * Cols; for (int n = 0; n < count; ++n) { int idx = startIdx + n; int glyphIndex = (int)str[n]; if (screenMemory[idx].Equals(glyphIndex, color, bgColor)) { continue; } Color charColor = color.ResolveColor(); // Random colors won't match at first, but Color charBgColor = bgColor.ResolveColor(); // might match after being resolved, so check again: if (screenMemory[idx].Equals(glyphIndex, charColor, charBgColor)) { return; } screenMemory[idx] = new ColorGlyph(glyphIndex, charColor, charBgColor); if (firstChangedIdx > idx) { firstChangedIdx = idx; } if (lastChangedIdx < idx) { lastChangedIdx = idx; } } if (holdUpdatesCount == 0) { SendDataToWindow(); } }
public void Write(int row, int col, ColorGlyph cg) { throw new NotImplementedException(); }