public override void PaintBackground(HintPainter hp, Hint.Kind v) { PaintContext context = (PaintContext)hp; int Cells = context.grid.Cells; Brush back = PaintContext.BackgroundBrush(v); if (house == Houses.Cell) { context.FillCell(i0, i1, back); } else if (house == Houses.Column) { context.FillColumn(i0, back); } else if (house == Houses.Row) { context.FillRow(i0, back); } else if (house == Houses.Box) { context.FillBox(i0, back); } else if (house == Houses.MajorDiagonal) { for (int x = 0; x < Cells; ++x) { context.FillCell(x, x, back); } } else if (house == Houses.MinorDiagonal) { for (int x = 0; x < Cells; ++x) { context.FillCell(x, Cells - x - 1, back); } } }
public void Paint(PaintContext context) { Graphics graphics = context.graphics; // Background Brush back = InEditMode ? Brushes.LightSalmon : (solver.UnfulfilledRequirements.Length == 0) ? Brushes.LightGreen : Brushes.White; context.FillBackground(back); // Coloured cages or boxes if (gridOptions.colours != null) { Color[] cage_colours = new Color[] { Color.FromArgb(255, 253, 152), Color.FromArgb(207, 231, 153), Color.FromArgb(203, 232, 250), Color.FromArgb(248, 207, 223) }; Brush[] cage_brushes = new Brush[4]; for (int i = 0; i < 4; ++i) { cage_brushes[i] = new SolidBrush(cage_colours[i]); } for (int x = 0; x < Cells; ++x) { for (int y = 0; y < Cells; ++y) { context.FillCell(x, y, cage_brushes[gridOptions.colours[x, y]]); } } for (int i = 0; i < 4; ++i) { cage_brushes[i].Dispose(); } } // Diagonals - brush previously Brushes.LightGray if (MajorDiagonal) { using (Brush br = new HatchBrush(HatchStyle.ForwardDiagonal, Color.DarkGray, Color.Transparent)) for (int x = 0; x < Cells; ++x) { context.FillCell(x, x, br); } } if (MinorDiagonal) { using (Brush br = new HatchBrush(HatchStyle.BackwardDiagonal, Color.DarkGray, Color.Transparent)) for (int x = 0; x < Cells; ++x) { context.FillCell(x, Cells - x - 1, br); } } // Cage totals if (IsKiller) { Point?[] cage_indicators = new Point?[NumCages]; for (int y = Cells - 1; y >= 0; --y) { for (int x = Cells - 1; x >= 0; --x) { if (flags[x, y] == CellFlags.Free) { cage_indicators[cageInfo.cages[x, y]] = new Point(x, y); } } } using (Pen inner = new Pen(Color.White, 5.0f)) PaintCages(context, inner); for (int i = 0; i < NumCages; ++i) { if (cage_indicators[i] != null) { context.DrawTotal(Brushes.Black, cage_indicators[i].Value.X, cage_indicators[i].Value.Y, cageInfo.remaining_totals[i].ToString()); } } } foreach (Hint hint in paintedHints) { hint.PaintBackground(context); } context.DrawSelection(); // Grid Dictionary <int, int> bs = new Dictionary <int, int>(); for (int x = 0; x < Cells; ++x) { for (int y = 0; y < Cells; ++y) { int b = BoxAt(x, y); if (bs.ContainsKey(b)) { ++bs[b]; } else { bs[b] = 1; } } } Func <int, int, int, int, int> border = (int x0, int y0, int x1, int y1) => { int b0 = BoxAt(x0, y0), b1 = BoxAt(x1, y1); if (b0 == b1) { return(0); } if (bs[b0] < Cells || bs[b1] < Cells) { return(2); } return(1); }; using (Pen thick = new Pen(Color.Black, 3.0f)) using (Pen wrong = new Pen(Color.Red, 3.0f)) { Pen[] pens = { Pens.Black, thick, wrong }; for (int x = 0; x < Cells - 1; ++x) { for (int y = 0; y < Cells; ++y) { context.DrawVerticalLine(x, y, pens[border(x, y, x + 1, y)]); } } for (int x = 0; x < Cells; ++x) { for (int y = 0; y < Cells - 1; ++y) { context.DrawHorizontalLine(x, y, pens[border(x, y, x, y + 1)]); } } } // Givens { for (int x = 0; x < Cells; ++x) { for (int y = 0; y < Cells; ++y) { if (flags[x, y] == CellFlags.Fixed) { context.DrawCell(Brushes.Black, x, y, values[x, y]); } else if (flags[x, y] == CellFlags.Play) { context.DrawCell(Brushes.Purple, x, y, values[x, y]); } else if (flags[x, y] == CellFlags.Solved) { context.DrawCell(Brushes.Green, x, y, values[x, y]); } } } } // Knowns of solver { foreach (Candidate k in solver.SelectedCandidates) { SudokuCandidate sc = (SudokuCandidate)k; if (flags[sc.x, sc.y] == CellFlags.Free) { context.DrawCell(Brushes.Green, sc.x, sc.y, sc.n); } } } // Unknowns as pencil marks if (HintFlags.PaintPencilMarks) { foreach (SudokuCandidate k in solver.UnselectedCandidates) { context.SetPencil(k, Hint.Kind.Maybe); } } foreach (Hint hint in paintedHints) { hint.PaintForeground(context); } context.PaintPencilMarksAndHints(); }
public override void PaintBackground(HintPainter hp, Hint.Kind v) { PaintContext context = (PaintContext)hp; context.FillCell(x, y, v); }