private void BitmapSelector_MouseMove(object sender, MouseEventArgs e)
{
//so we can capture the mouse wheel event
if (!Focused)
this.Focus();
Point p = Translate(e.Location);
if (p == mouseLast)
return;
if (p.X < 0 || p.X >= Width || p.Y < 0 || p.Y >= Height)
return;
if (!mouse1Down && !mouse2Down && ShowToolTips && ToolTips[p.X, p.Y] != null && ToolTips[p.X, p.Y].Length > 0)
toolTip.Show(ToolTips[p.X, p.Y], this, new Point(e.X + 1, e.Y + 1));
else
toolTip.Hide(this);
bool needToRedraw = false;
if ((mouse1Down || mouse2Down) && (Brush == BrushType.Round || Brush == BrushType.Square))
{
using (Graphics g = Graphics.FromImage(Layers[SelectionLayerIndex].Image))
{
if (!SelectionBounds.IsEmpty)
g.SetClip(SelectionBounds);
g.CompositingMode = CompositingMode.SourceCopy;
Pen pen = new Pen(mouse1Down ? SelectionColor : Color.Transparent, BrushDiameter);
SolidBrush b = new SolidBrush(mouse1Down ? SelectionColor : Color.Transparent);
if (Brush == BrushType.Round)
{
g.DrawLine(pen, mouseLast, p);
g.FillEllipse(b, p.X - BrushDiameter / 2, p.Y - BrushDiameter / 2, BrushDiameter, BrushDiameter);
}
else //Square
{
if (BrushDiameter == 1)
{
g.DrawLine(pen, mouseLast, p);
}
else
{
Point[] parallelogram = new Point[4];
double m = ((double)(p.Y - mouseLast.Y)) / ((double)(p.X - mouseLast.X));
if (m < 0.0)
{
parallelogram[0] = new Point(p.X - (int)(BrushDiameter / 2.0), p.Y - (int)(BrushDiameter / 2.0));
parallelogram[1] = new Point(p.X + (int)(BrushDiameter / 2.0), p.Y + (int)(BrushDiameter / 2.0));
parallelogram[2] = new Point(mouseLast.X + (int)(BrushDiameter / 2.0), mouseLast.Y + (int)(BrushDiameter / 2.0));
parallelogram[3] = new Point(mouseLast.X - (int)(BrushDiameter / 2.0), mouseLast.Y - (int)(BrushDiameter / 2.0));
}
else
{
parallelogram[0] = new Point(p.X + (int)(BrushDiameter / 2.0), p.Y - (int)(BrushDiameter / 2.0));
parallelogram[1] = new Point(p.X - (int)(BrushDiameter / 2.0), p.Y + (int)(BrushDiameter / 2.0));
parallelogram[2] = new Point(mouseLast.X - (int)(BrushDiameter / 2.0), mouseLast.Y + (int)(BrushDiameter / 2.0));
parallelogram[3] = new Point(mouseLast.X + (int)(BrushDiameter / 2.0), mouseLast.Y - (int)(BrushDiameter / 2.0));
}
g.FillPolygon(b, parallelogram);
}
g.FillRectangle(b, p.X - BrushDiameter / 2, p.Y - BrushDiameter / 2, BrushDiameter, BrushDiameter);
}
pen.Dispose();
b.Dispose();
}
needToRedraw = true;
}
if (Layers[BrushLayerIndex].Visible)
{
RedrawBrushLayer(p);
needToRedraw = true;
}
if (needToRedraw)
Redraw();
mouseLast = p;
}