public void OnPaint(PaintEventArgs e) { var g = e.Graphics; var rect = new Rectangle(_bounds.X + 5, _bounds.Y + 5, _bounds.Width - 10, _bounds.Height - 10); Brush brush = new SolidBrush(_preferences.GetBallColor(Ball.Color)); var pen = new Pen(_preferences.GetBallBorderColor(Ball.Color)); // Background g.FillRectangle(new SolidBrush(Color.Transparent), rect); // Ball itself rect.Inflate(-3, -3); // Draw the ball depending on the select status if (_ball.Selected) { switch (_jumpPosition) { case 0: break; case 1: rect.Inflate(0, -1); rect.Offset(0, -1); break; case 2: rect.Inflate(0, -1); rect.Offset(0, -2); break; case 3: rect.Inflate(0, 0); rect.Offset(0, -1); break; case 4: rect.Inflate(0, -1); rect.Offset(0, +1); break; case 5: rect.Inflate(0, -1); rect.Offset(0, +2); break; case 6: rect.Inflate(0, -1); rect.Offset(0, +1); break; } } g.FillEllipse(brush, rect); g.DrawEllipse(pen, rect); }
protected override void OnPaint(PaintEventArgs e) { // Draw frame var g = e.Graphics; var box = new Rectangle(0, 0, Width - 1, Height - 1); g.FillRectangle(new SolidBrush(Preferences.IndicatorCtrlBgColor), box); // Exit if Game isn't defined if (Game == null) { return; } var fieldPen = new Pen(Preferences.IndicatorFgColor); var padding = (Width - GetCellSize() * Game.BallsPerStep) / 2; // Balls var cellRect = new Rectangle(padding, 1, GetCellSize(), GetCellSize()); var ballRect = cellRect; ballRect.Inflate(-2, -2); if (Game.VirtualBalls != null) { var balls = Game.VirtualBalls; foreach (var t in balls) { g.FillRectangle(new SolidBrush(Preferences.IndicatorBgColor), cellRect); g.DrawRectangle(fieldPen, cellRect); g.FillEllipse(new SolidBrush(Preferences.GetBallColor(t.Color)), ballRect); g.DrawEllipse(new Pen(Preferences.GetBallBorderColor(t.Color)), ballRect); cellRect.Offset(GetCellSize(), 0); ballRect.Offset(GetCellSize(), 0); } } // Step indicator float fontSizePx = GetCellSize() - 5; var fontSizePt = fontSizePx * AppSettings.Instance.FactorPxToPt; Brush textBrush = new SolidBrush(Preferences.IndicatorTextColor); var font = new Font(FontFamily.GenericSansSerif, fontSizePt, FontStyle.Bold); var textRect = new RectangleF(3, 4, padding - 6, Height - 2); g.DrawString("Step: " + Game.StepCount, font, textBrush, textRect); // Score indicator textRect = new RectangleF(Width - 200, 4, padding - 6, Height - 2); g.DrawString("Score: " + Game.Score, font, textBrush, textRect); }