private void GameLogDisplay_Paint(object sender, PaintEventArgs e) { Color highlightBackColor = Color.FromArgb( (ForeColor.R + 3 * BackColor.R) / 4, (ForeColor.G + 3 * BackColor.G) / 4, (ForeColor.B + 3 * BackColor.B) / 4); int top = CellMargin; Rectangle currentRect = new Rectangle(0, top, 0, top + CellHeight); foreach (var col in Columns) { currentRect.X = currentRect.Right + CellMargin; currentRect.Width = col.Width; TextRenderer.DrawText(e.Graphics, col.Title, TitleFont, currentRect, ForeColor, col.TextFormat); } e.Graphics.DrawLine(new Pen(ForeColor, 1), new Point(CellMargin, currentRect.Bottom), new Point(currentRect.Right, currentRect.Bottom)); currentRect = new Rectangle(0, top, 0, top + CellHeight); Color lineColor = Color.FromArgb( (ForeColor.R + 3 * BackColor.R) / 4, (ForeColor.G + 3 * BackColor.G) / 4, (ForeColor.B + 3 * BackColor.B) / 4); for (int i = 0; i < Games.Count; i++) { GameRecord game = Games[i]; currentRect.X = 0; currentRect.Width = 0; currentRect.Y += CellHeight + CellMargin; if (i == HighlightedCell.Y) { e.Graphics.FillRectangle(new SolidBrush(highlightBackColor), GetCellRectangle(-1, HighlightedCell.Y)); } for (int j = 0; j < Columns.Length; j++) { var col = Columns[j]; currentRect.X = currentRect.Right + CellMargin; currentRect.Width = col.Width; string text = game.ReadPropertyAsString(col.PropertyName); TextRenderer.DrawText(e.Graphics, text, ListFont, currentRect, ForeColor, col.TextFormat); } e.Graphics.DrawLine(new Pen(lineColor, 1), new Point(CellMargin, currentRect.Bottom), new Point(currentRect.Right, currentRect.Bottom)); } }
/// <summary> /// Adda game to history /// </summary> /// <param name="gr">Game record to add</param> /// <param name="shouldInvalidate">Should window be redrawn</param> public void AddGameRecord(GameRecord gr, bool shouldInvalidate = true) { GameTextRectangles.Insert(1, new Rectangle[Columns.Length]); // Move all existing rectangles down for (int i = 2; i < GameTextRectangles.Count; i++) { for (int j = 0; j < GameTextRectangles[i].Length; j++) { GameTextRectangles[i][j].Offset(0, CellHeight + CellMargin); } } int left = CellMargin; for (int i = 0; i < Columns.Length; i++) { GameHistoryColumn col = Columns[i]; string text = gr.ReadPropertyAsString(col.PropertyName); GameTextRectangles[1][i] = new Rectangle(new Point(left, CellMargin + CellHeight + CellMargin), TextRenderer.MeasureText(text, ListFont, CellRectangles[i].Size)); left += col.Width + CellMargin; if (col.TextFormat.HasFlag(TextFormatFlags.VerticalCenter)) { GameTextRectangles[1][i].Offset(0, (CellHeight - GameTextRectangles[1][i].Height) / 2); } if (col.TextFormat.HasFlag(TextFormatFlags.HorizontalCenter)) { GameTextRectangles[1][i].Offset((CellRectangles[i].Width - GameTextRectangles[1][i].Width) / 2, 0); } } GameLogDisplay.Width = BestWidth; GameLogDisplay.Height = BestHeight; if (shouldInvalidate) { Invalidate(); } }