public override void OnRender(nanoFramework.Presentation.Media.DrawingContext dc) { // Draw outline rectangle dc.DrawRectangle(_fillBrush, _linePen, 0, 0, COLUMN_WIDTH * COLUMNS, ROW_HEIGHT * ROWS); // Performance tuning - save all property calls to variables int blockCols = _universe.NextBlock.Columns; int blockRows = _universe.NextBlock.Rows; int offsetX = (Width - (blockCols * COLUMN_WIDTH) + 2) / 2; int offsetY = (Height - (blockRows * ROW_HEIGHT) + 2) / 2; // Draw block for (int row = 0; row < blockRows; row++) { for (int col = 0; col < blockCols; col++) { int brushType = _universe.NextBlock.GetCell(row, col) - 1; if (brushType >= 0) { dc.DrawRectangle(BlockBrushes.Instance.GetBrush(brushType), _blockPen, (col * COLUMN_WIDTH) + offsetX, (row * ROW_HEIGHT) + offsetY, COLUMN_WIDTH - 1, ROW_HEIGHT - 1); } } } base.OnRender(dc); }
public override void OnRender(nanoFramework.Presentation.Media.DrawingContext dc) { // Saving performance create fill brush only once if (gradientBrush == null) { gradientBrush = new LinearGradientBrush(startColor, endColor, 0, this.Height / 2, 0, this.Height); } // Gradient fill dc.DrawRectangle(gradientBrush, null, 0, 0, this.Width, this.Height); // Left line separator dc.DrawRectangle(solidBrush, null, 0, 0, 2, this.Height); }