using PaintDotNet.Annotation.Enum; using System.Drawing; using System.Windows.Forms; namespace PaintDotNet.Annotation.Measure { /// /// 测量->多边形测量->任意矩形 /// public class ToolMeasureRandRectangle : ToolMeasureObject { private static MeasureRandRectangle newRandRectangle; private static int clickCount = 0; public static void OnMouseDown(ISurfaceBox drawArea, MouseEventArgs e) { if (e.Button == MouseButtons.Left && e.Clicks != 2) { Point p = GetEventPointInArea(drawArea, e.Location); if (newRandRectangle == null) { newRandRectangle = new MeasureRandRectangle(drawArea, p.X, p.Y, p.X + 1, p.Y + 1, true); newRandRectangle.ISurfaceBox = drawArea; AddNewObject(drawArea, newRandRectangle); clickCount++; } else { clickCount++; if (clickCount == 3) { newRandRectangle.pointChange = false; //newRandRectangle.CalcSlope(); //newRandRectangle.CalcCenter(); //newRandRectangle.finish = true; clickCount = 0; newRandRectangle = null; OnMouseUpTwo(drawArea, e); if (!drawArea.ContinuousDrawingMeasure()) drawArea.ActiveTool = DrawToolType.Pointer; } } } else { if(newRandRectangle != null) { if ((e.Clicks == 1 && clickCount == 1) || (e.Clicks == 2 && clickCount < 3)) { for (int i = 0; i < drawArea.GraphicsList.Count; i++) { if (drawArea.GraphicsList[i].drawToolType == newRandRectangle.drawToolType) { drawArea.GraphicsList.RemoveAt(i); break; } } } } OnMouseNotLeftDown(drawArea, newRandRectangle); if (newRandRectangle != null) newRandRectangle.pointChange = false; //newRandRectangle.CalcSlope(); //newRandRectangle.CalcCenter(); //newRandRectangle.finish = true; clickCount = 0; newRandRectangle = null; OnMouseUpTwo(drawArea, e); if (!drawArea.ContinuousDrawingMeasure()) { drawArea.ActiveTool = DrawToolType.Pointer; } } } /// /// 鼠标移动,需要进行绘制 /// /// /// public static void OnMouseMove(ISurfaceBox drawArea, MouseEventArgs e) { Point pointscroll = GetEventPointInArea(drawArea, e.Location); //if (e.Button == MouseButtons.Left) { if (drawArea.GraphicsList[0] != null) { if(clickCount == 1) { drawArea.GraphicsList[0].MoveHandleTo(pointscroll, 2); } else if(clickCount == 2) { drawArea.GraphicsList[0].MoveHandleTo(pointscroll, 3); } drawArea.Refresh(); drawArea.GraphicsList.Dirty = true; } } } /// /// 鼠标抬起事件 /// /// /// public static void OnMouseUp(ISurfaceBox drawArea, MouseEventArgs e) { } public static void OnMouseClick(ISurfaceBox drawArea, MouseEventArgs e) { } /// /// 鼠标左键双击 /// /// /// public static void OnMouseLeftDoubleClick(ISurfaceBox surfacebox, MouseEventArgs e) { } /// /// 删除按键 /// /// /// public static void OnDelKeyDown(ISurfaceBox surfacebox, MouseEventArgs e) { } /// /// 删除划痕处理&污迹处理选择区域的痕迹 /// /// /// public static void OnDel2KeyDown(ISurfaceBox surfacebox, MouseEventArgs e) { } /// /// 清空全部时调用该方法,将可能未绘制完的对象清空 /// public static void beginWithNewObject() { newRandRectangle = null; clickCount = 0; } } }