using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; using System.Windows.Forms; using PaintDotNet.Annotation.Enum; namespace PaintDotNet.Annotation.Measure { public class ToolMeasureBrokenLine : ToolMeasureObject { private static MeasureBrokenLine newBrokenLine; private static int clickCount = 0; //辅助计算点击次数 /// /// Left nouse button is pressed /// /// /// public static void OnMouseDown(ISurfaceBox drawArea, MouseEventArgs e) { if (e.Button == MouseButtons.Left && e.Clicks != 2) { clickCount += 1; Point p = GetEventPointInArea(drawArea, e.Location); if (newBrokenLine == null) { newBrokenLine = new MeasureBrokenLine(drawArea, p.X, p.Y, true); newBrokenLine.ISurfaceBox = drawArea; AddNewObject(drawArea, newBrokenLine); } drawArea.Refresh(); } else { if(newBrokenLine != null) { if (e.Clicks == 2 && clickCount == 1) { for (int i = 0; i < drawArea.GraphicsList.Count; i++) { if (drawArea.GraphicsList[i].drawToolType == newBrokenLine.drawToolType) { drawArea.GraphicsList.RemoveAt(i); break; } } } } OnMouseNotLeftDown(drawArea, newBrokenLine); if (newBrokenLine != null) newBrokenLine.pointChange = false; clickCount = 0; newBrokenLine = null; OnMouseUpTwo(drawArea, e); if (!drawArea.ContinuousDrawingMeasure()) drawArea.ActiveTool = DrawToolType.Pointer; } } /// /// 目前设计的交互形式是左键点击 /// 所以鼠标移动什么都不做 /// 如果交互形式改变,再说 /// /// /// public static void OnMouseMove(ISurfaceBox drawArea, MouseEventArgs e) { //drawArea.Cursor = Cursor; Point pointscroll = GetEventPointInArea(drawArea, e.Location); if (newBrokenLine != null) { if (drawArea.GraphicsList[0] != null) { if (clickCount == 1) { if (newBrokenLine.pointArray.Count == 1) newBrokenLine.setNextPoint(pointscroll); else newBrokenLine.pointArray[1] = pointscroll; } if (clickCount > 1) { if (newBrokenLine.pointArray.Count == clickCount) newBrokenLine.setNextPoint(pointscroll); else newBrokenLine.pointArray[clickCount] = pointscroll; } drawArea.Refresh(); drawArea.GraphicsList.Dirty = true; } } } /// /// 鼠标抬起事件(连续绘制) /// /// /// public static void OnMouseUp(ISurfaceBox drawArea, MouseEventArgs e) { } public static void OnMouseClick(ISurfaceBox surfacebox, 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() { newBrokenLine = null; clickCount = 0; } } }