ToolMeasureDistanceLine.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using PaintDotNet.Annotation.Enum;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. namespace PaintDotNet.Annotation.Measure
  10. {
  11. public class ToolMeasureDistanceLine : ToolMeasureObject
  12. {
  13. private static MeasureDistanceLine line;
  14. private static bool moved = false;
  15. public static void OnMouseDown(ISurfaceBox drawArea, MouseEventArgs e)
  16. {
  17. if (e.Button == MouseButtons.Left)
  18. {
  19. if (line == null)
  20. {
  21. Point pointscroll = GetEventPointInArea(drawArea, e.Location);
  22. if (line == null)
  23. {
  24. line = new MeasureDistanceLine(drawArea, new Point(pointscroll.X, pointscroll.Y), new Point(pointscroll.X + 1, pointscroll.Y + 1));
  25. line.ISurfaceBox = drawArea;
  26. AddNewObject(drawArea, line);
  27. }
  28. }
  29. }
  30. else
  31. {
  32. line = null;
  33. if (!drawArea.ContinuousDrawingMeasure())
  34. {
  35. drawArea.ActiveTool = DrawToolType.Pointer;
  36. }
  37. OnMouseNotLeftDown(drawArea, line);
  38. }
  39. }
  40. public static void OnMouseMove(ISurfaceBox drawArea, MouseEventArgs e)
  41. {
  42. if (line != null)
  43. {
  44. line.moved = true;
  45. moved = true;
  46. Point pointscroll = GetEventPointInArea(drawArea, e.Location);
  47. if (drawArea.GraphicsList[0] != null)
  48. {
  49. drawArea.GraphicsList[0].MoveHandleTo(pointscroll, 2);
  50. drawArea.Refresh();
  51. drawArea.GraphicsList.Dirty = true;
  52. }
  53. }
  54. }
  55. public static void OnMouseUp(ISurfaceBox drawArea, MouseEventArgs e)
  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. public static void OnMouseClick(ISurfaceBox drawArea, MouseEventArgs e)
  94. {
  95. }
  96. /// <summary>
  97. /// 鼠标左键双击
  98. /// </summary>
  99. /// <param name="drawArea"></param>
  100. /// <param name="e"></param>
  101. public static void OnMouseLeftDoubleClick(ISurfaceBox surfacebox, MouseEventArgs e)
  102. {
  103. }
  104. /// <summary>
  105. /// 删除按键
  106. /// </summary>
  107. /// <param name="surfacebox"></param>
  108. /// <param name="e"></param>
  109. public static void OnDelKeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  110. {
  111. }
  112. /// <summary>
  113. /// 删除划痕处理&污迹处理选择区域的痕迹
  114. /// </summary>
  115. /// <param name="surfacebox"></param>
  116. /// <param name="e"></param>
  117. public static void OnDel2KeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  118. {
  119. }
  120. /// <summary>
  121. /// 清空全部时调用该方法,将可能未绘制完的对象清空
  122. /// </summary>
  123. public static void beginWithNewObject()
  124. {
  125. line = null;
  126. }
  127. }
  128. }