private void RedrawBrushLayer(Point p, bool justClear = false)
{
using (Graphics g = Graphics.FromImage(Layers[BrushLayerIndex].Image))
{
g.Clear(Color.Transparent);
if (!SelectionBounds.IsEmpty)
g.SetClip(SelectionBounds);
if (!justClear)
{
if (customBrush != null)
{
g.DrawImage(customBrush, p.X - (customBrush.Width >> 1), p.Y - (customBrush.Height >> 1));
}
else
{
if (SelectionBounds.IsEmpty || SelectionBounds.Contains(p))
Layers[BrushLayerIndex].Image.SetPixel(p.X, p.Y, Color.Black);
Brush b = new SolidBrush(Color.Black);
if (Brush == BrushType.Rectangle)
{
if ((mouse1Down || mouse2Down) && mouseDownLast.X != -1 && mouseDownLast.Y != -1)
{
g.FillRectangle(b, Rectangle.FromLTRB(Math.Min(mouseDownLast.X, p.X), Math.Min(mouseDownLast.Y, p.Y), Math.Max(mouseDownLast.X, p.X), Math.Max(mouseDownLast.Y, p.Y)));
}
}
else if (Brush == BrushType.Round)
{
g.FillEllipse(b, p.X - BrushDiameter / 2, p.Y - BrushDiameter / 2, BrushDiameter, BrushDiameter);
}
else if (Brush == BrushType.Square)
{
g.FillRectangle(b, p.X - BrushDiameter / 2, p.Y - BrushDiameter / 2, BrushDiameter, BrushDiameter);
}
b.Dispose();
}
}
}
}