ToolMeasureLine.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using PaintDotNet.Annotation.Enum;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace PaintDotNet.Annotation.Measure
  5. {
  6. /// <summary>
  7. /// 测量->直线->直线
  8. /// </summary>
  9. public class ToolMeasureLine : ToolMeasureObject
  10. {
  11. private static MeasureLine line;
  12. private static bool moved = false;
  13. public static void OnMouseDown(ISurfaceBox drawArea, MouseEventArgs e)
  14. {
  15. if (e.Button == MouseButtons.Left)
  16. {
  17. Point pointscroll = GetEventPointInArea(drawArea, e.Location);
  18. if (line == null)
  19. {
  20. line = new MeasureLine(drawArea, new Point(pointscroll.X, pointscroll.Y), new Point(pointscroll.X + 1, pointscroll.Y + 1));
  21. line.ISurfaceBox = drawArea;
  22. AddNewObject(drawArea, line);
  23. }
  24. }
  25. else
  26. {
  27. line = null;
  28. if (!drawArea.ContinuousDrawingMeasure())
  29. {
  30. drawArea.ActiveTool = DrawToolType.Pointer;
  31. }
  32. OnMouseNotLeftDown(drawArea,line);
  33. }
  34. }
  35. public static void OnMouseMove(ISurfaceBox drawArea, MouseEventArgs e)
  36. {
  37. if (line != null)
  38. {
  39. line.moved = true;
  40. moved = true;
  41. Point pointscroll = GetEventPointInArea(drawArea, e.Location);
  42. if (line!= null)
  43. {
  44. line.MoveHandleTo(pointscroll, 2);
  45. drawArea.Refresh();
  46. drawArea.GraphicsList.Dirty = true;
  47. }
  48. }
  49. }
  50. public static void OnMouseUp(ISurfaceBox drawArea, MouseEventArgs e)
  51. {
  52. //1、鼠标抬起的时候,先判断位置是不是等于第一个点
  53. //2、如果是第一个点,那就是点击,不是拖动
  54. //3、如果不是第一个点,那就画线
  55. try
  56. {
  57. if (e.Button == MouseButtons.Left)
  58. {
  59. Point pointscroll = GetEventPointInArea(drawArea, e.Location);
  60. if ((pointscroll.X == line.startPoint.X && pointscroll.Y == line.startPoint.Y))
  61. {
  62. return;
  63. }
  64. line.endPoint = pointscroll;
  65. if (!moved)
  66. {
  67. if (line != null)
  68. {
  69. for (int i = 0; i < drawArea.GraphicsList.Count; i++)
  70. {
  71. if (drawArea.GraphicsList[i].drawToolType == line.drawToolType)
  72. {
  73. drawArea.GraphicsList.RemoveAt(i);
  74. break;
  75. }
  76. }
  77. }
  78. }
  79. moved = false;
  80. if (line != null)
  81. {
  82. line.pointChange = false;
  83. line.mouseUpPointChange = false;
  84. }
  85. line = null;
  86. if (!drawArea.ContinuousDrawingMeasure())
  87. {
  88. drawArea.ActiveTool = DrawToolType.Pointer;
  89. }
  90. OnMouseUpTwo(drawArea, e);
  91. }
  92. }
  93. catch (System.Exception)
  94. {
  95. }
  96. }
  97. public static void OnMouseClick(ISurfaceBox drawArea, MouseEventArgs e)
  98. {
  99. }
  100. /// <summary>
  101. /// 鼠标左键双击
  102. /// </summary>
  103. /// <param name="drawArea"></param>
  104. /// <param name="e"></param>
  105. public static void OnMouseLeftDoubleClick(ISurfaceBox surfacebox, MouseEventArgs e)
  106. {
  107. var abc = "str";
  108. }
  109. /// <summary>
  110. /// 删除按键
  111. /// </summary>
  112. /// <param name="surfacebox"></param>
  113. /// <param name="e"></param>
  114. public static void OnDelKeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  115. {
  116. }
  117. /// <summary>
  118. /// 删除划痕处理&污迹处理选择区域的痕迹
  119. /// </summary>
  120. /// <param name="surfacebox"></param>
  121. /// <param name="e"></param>
  122. public static void OnDel2KeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  123. {
  124. }
  125. /// <summary>
  126. /// 清空全部时调用该方法,将可能未绘制完的对象清空
  127. /// </summary>
  128. public static void beginWithNewObject()
  129. {
  130. line = null;
  131. }
  132. }
  133. }