public void SetCharacter(int pos, char c, CharacterCell.ColorCodes textColor, CharacterCell.ColorCodes backColor, CharacterCell.AttributeCodes attribute) { if (pos < 0 || pos >= CharacterData.Length) { return; } CharacterData[pos] = c; TextColorData[pos] = textColor; BackColorData[pos] = backColor; AttributeData[pos] = attribute; }
private void DisplayControl_Paint(object sender, PaintEventArgs e) { UpdateTextCursorMode(); if (!FontValid) { Font = GetBestFont(); FontValid = true; } Graphics g = e.Graphics; g.Clear(Color.Black); float right = (Columns + 1) * ColWidth; float bottom = (Rows + 1) * RowHeight; float x = 0; float y = 0; float xo = 0; if (right < ClientRectangle.Width) { xo = (ClientRectangle.Width - right) / 2; } float yo = 0; g.TranslateTransform(xo, yo); g.DrawRectangle(borderPen, -2, -2, right + 4, bottom + 4); g.FillRectangle(Brushes[(int)CurrentBackground], 0, 0, right, bottom); for (int row = 0; row < Rows; row++) { for (int col = 0; col < Columns; col++) { int pos = GetPos(row, col); x = col * ColWidth; y = row * RowHeight; CharacterCell.ColorCodes color = BackColorData[pos]; Brush b = Brushes[(int)TextColorData[pos]]; Brush bg = Brushes[(int)BackColorData[pos]]; if (color != CurrentBackground) { g.FillRectangle(bg, x, y, ColWidth, RowHeight); } if (AttributeData[pos].HasFlag(CharacterCell.AttributeCodes.Reverse)) { g.FillRectangle(b, x, y, ColWidth, RowHeight); b = bg; } g.DrawString(CharacterData[pos].ToString(), Font, b, x, y, StringFormat.GenericTypographic); } } x = CurrentColumn * ColWidth - 1; y = CurrentRow * RowHeight; if (CursorOn) { switch (TextCursor) { case TextCursorStyles.None: break; case TextCursorStyles.Underline: float h = RowHeight / 4; g.FillRectangle(Brushes[(int)CurrentTextColor], x, y + (RowHeight - h), ColWidth, h); break; case TextCursorStyles.Left: g.FillRectangle(Brushes[(int)CurrentTextColor], x, y, ColWidth / 4, RowHeight); break; case TextCursorStyles.Block: default: g.FillRectangle(Brushes[(int)CurrentTextColor], x, y, ColWidth, RowHeight); break; } } g.ResetTransform(); }
public void SetCharacter(int row, int col, char c, CharacterCell.ColorCodes textColor, CharacterCell.ColorCodes backColor, CharacterCell.AttributeCodes attribute) { int pos = GetPos(row, col); SetCharacter(pos, c, textColor, backColor, attribute); }