private void Grid_Paint(object sender, PaintEventArgs e)
{
int width = Width;
int height = Height;
int rows = height / m_cellSize;
int cols = width / m_cellSize;
Graphics graphics = e.Graphics;
Rectangle client = ClientRectangle;
client.Inflate(200, 200);
foreach (Point p in m_cells.Keys)
{
if (client.Contains(new System.Drawing.Point(p.X, p.Y)))
{
int r, g, b;
r = m_cells[p].R;
g = m_cells[p].G;
b = m_cells[p].B;
if(m_invertScale)
{
r = 255 - r;
b = 255 - b;
g = 255 - g;
}
Color cellColor = Color.FromArgb(r, g, b);
graphics.FillRectangle(new SolidBrush(cellColor), new Rectangle(m_offsetX + (p.X * m_cellSize), m_offsetY + (p.Y * m_cellSize), m_cellSize, m_cellSize));
}
}
if(m_showGrid)
{
for (int index = 0; index <= rows+1; index++)
{
int yPos = (index * m_cellSize) + (m_offsetY % m_cellSize);
graphics.DrawLine(m_gridPen, new System.Drawing.Point(0, yPos), new System.Drawing.Point(width, yPos));
}
for (int index = 0; index <= cols; index++)
{
int xPos = (index * m_cellSize) + (m_offsetX % m_cellSize);
graphics.DrawLine(m_gridPen, new System.Drawing.Point(xPos, 0), new System.Drawing.Point(xPos, width));
}
}
graphics.DrawRectangle(new Pen(Brushes.Red, 3), m_offsetX, m_offsetY, m_cellSize * bounds.Width, m_cellSize * bounds.Height);
if (client.Contains(new System.Drawing.Point(m_offsetX, m_offsetY)))
{
graphics.DrawString("(0, 0) (" + m_cellOffsetX + ", " + m_cellOffsetY + ")",
new Font("Arial", 20), Brushes.Red,
new Point(m_offsetX, m_offsetY));
graphics.DrawEllipse(Pens.Red, new Rectangle(new Point(m_offsetX - 4, m_offsetY - 4), new Size(8, 8)));
}
if (client.Contains(new System.Drawing.Point(m_offsetX + (bounds.Width * m_cellSize), m_offsetY + (bounds.Height * m_cellSize))))
{
graphics.DrawString("(" + bounds.Width + ", " + bounds.Height + ")",
new Font("Arial", 20), Brushes.Red,
new Point(m_offsetX + (bounds.Width * m_cellSize), m_offsetY + (bounds.Height * m_cellSize)));
graphics.DrawEllipse(Pens.Red, new Rectangle(new Point((m_offsetX + (bounds.Width * m_cellSize)) - 4, (m_offsetY + (bounds.Height * m_cellSize)) - 4), new Size(8, 8)));
}
int selectedSizeX = selection.Width / m_cellSize;
int selectedSizeY = selection.Height / m_cellSize;
graphics.DrawString("(" + m_selectedX + "," + m_selectedY + ") (" + selectedSizeX + ", " + selectedSizeY + ")",
new Font("Arial", 20), Brushes.Red,
new Point(0, this.Height - 35));
graphics.DrawRectangle(m_selectionPen, selection);
}