internal void drawPossibleConstraints(PaintEventArgs e) { foreach (List <Variable> list in dragConstraints) { CellTools.drawPossibleConstraint(e, list, lastConstraint.getColor()); } }
internal void drawConstraintsInCell(DataGridViewCellPaintingEventArgs e, CPInstance i) { foreach (Constraint c in involvedInConstraint) { CellTools.drawConstraint(this, c, e, i); } }
internal static void drawConstraint(Variable variable, Constraint c, DataGridViewCellPaintingEventArgs e, CPInstance i) { Pen p = new Pen(Color.FromArgb(Math.Max(0, 255 - c.duplication_distance * 10), c.getColor())); if (c.duplication_distance == 0) { p.Width = 4f; } else { p.Width = 1.5f + 1.0f / c.duplication_distance; } Variable[] n = i.getNeighbours(variable, c); for (int k = 0; k < 4; k++) { if (n[k] == null)// && n[(k + 4 - 1) % 4] != null && n[(k + 4 + 1) % 4] != null) { CellTools.drawStraight(e, k, p); } } }
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.ColumnIndex < 0 || e.RowIndex < 0) { return; } DataGridViewCell currentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; if (instance.getVar(currentCell) == null) { // empty cell //e.Handled = false; <- let event be handled by default handler. (done implicit) return; } else { Variable currentVar = instance.getVar(currentCell); if (rectDrag) { dataGridView1.ClearSelection(); } // Erase the cell. e.Graphics.FillRectangle(new SolidBrush(currentVar.getColor()), e.CellBounds); if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected) { e.Graphics.FillRectangle(Brushes.DarkKhaki, e.CellBounds); } CellTools.drawGrid(e, gridColor); if (drawConstraints) { currentVar.drawConstraintsInCell(e, instance); } e.Graphics.DrawString(currentVar.getFormattedText(), e.CellStyle.Font, Brushes.Black, e.CellBounds.X + 2, e.CellBounds.Y + 2, StringFormat.GenericDefault); currentVar.fixedVal = currentVar.fixedVal.Trim(); if (currentVar.fixedVal != "") { if (instance.solved) { e.Graphics.DrawString(currentVar.solvedValue, e.CellStyle.Font, Brushes.Crimson, e.CellBounds.X + 2, e.CellBounds.Y + 20, StringFormat.GenericDefault); } else { e.Graphics.DrawString(currentVar.fixedVal, e.CellStyle.Font, Brushes.Crimson, e.CellBounds.X + 2, e.CellBounds.Y + 20, StringFormat.GenericDefault); } } else { if (instance.solved) { e.Graphics.DrawString(currentVar.solvedValue, e.CellStyle.Font, Brushes.Black, e.CellBounds.X + 2, e.CellBounds.Y + 20, StringFormat.GenericDefault); } if (!instance.solved) { e.Graphics.DrawString(currentVar.solvedValue, e.CellStyle.Font, Brushes.LightGray, e.CellBounds.X + 2, e.CellBounds.Y + 20, StringFormat.GenericDefault); } } e.Handled = true; } }