ToolMeasureLength.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 ToolMeasureLength : ToolMeasureObject
  10. {
  11. private static MeasureLength newLength;
  12. private static int clickCount = 0; //辅助计算点击次数
  13. /// <summary>
  14. /// Left nouse button is pressed
  15. /// </summary>
  16. /// <param name="drawArea"></param>
  17. /// <param name="e"></param>
  18. public static void OnMouseDown(ISurfaceBox drawArea, MouseEventArgs e)
  19. {
  20. if (e.Button == MouseButtons.Left)
  21. {
  22. clickCount += 1;
  23. Point p = GetEventPointInArea(drawArea, e.Location);
  24. if (newLength == null)
  25. {
  26. newLength = new MeasureLength(drawArea, p.X, p.Y, true);
  27. newLength.ISurfaceBox = drawArea;
  28. AddNewObject(drawArea, newLength);
  29. }
  30. drawArea.Refresh();
  31. if (clickCount == 3)
  32. {
  33. newLength.pointChange = false;
  34. clickCount = 0;
  35. newLength = null;
  36. OnMouseUpTwo(drawArea, e);
  37. if (!drawArea.ContinuousDrawingMeasure())
  38. drawArea.ActiveTool = DrawToolType.Pointer;
  39. }
  40. }
  41. else
  42. {
  43. if(newLength != null)
  44. {
  45. if ((e.Clicks == 1 && clickCount == 1) || (e.Clicks == 2 && clickCount < 3))
  46. {
  47. for (int i = 0; i < drawArea.GraphicsList.Count; i++)
  48. {
  49. if (drawArea.GraphicsList[i].drawToolType == newLength.drawToolType)
  50. {
  51. drawArea.GraphicsList.RemoveAt(i);
  52. break;
  53. }
  54. }
  55. }
  56. }
  57. OnMouseNotLeftDown(drawArea, newLength);
  58. if (newLength != null)
  59. newLength.pointChange = false;
  60. newLength = null;
  61. clickCount = 0;
  62. OnMouseUpTwo(drawArea, e);
  63. if (!drawArea.ContinuousDrawingMeasure())
  64. {
  65. drawArea.ActiveTool = DrawToolType.Pointer;
  66. }
  67. }
  68. }
  69. /// <summary>
  70. /// 鼠标移动,需要进行绘制
  71. /// </summary>
  72. /// <param name="drawArea"></param>
  73. /// <param name="e"></param>
  74. public static void OnMouseMove(ISurfaceBox drawArea, MouseEventArgs e)
  75. {
  76. Point pointscroll = GetEventPointInArea(drawArea, e.Location);
  77. if (newLength != null)
  78. {
  79. if (clickCount < 3)
  80. {
  81. if (drawArea.GraphicsList[0] != null)
  82. {
  83. if (clickCount == 1)
  84. {
  85. pointscroll = new Point(pointscroll.X + 1, pointscroll.Y + 1);
  86. if (newLength.pointArray.Count == 1)
  87. newLength.setNextPoint(pointscroll);
  88. else
  89. newLength.pointArray[1] = pointscroll;
  90. }
  91. if (clickCount == 2)
  92. {
  93. pointscroll = new Point(pointscroll.X + 3, pointscroll.Y + 3);
  94. if (newLength.pointArray.Count == 2)
  95. newLength.setNextPoint(pointscroll);
  96. else {
  97. newLength.pointArray[2] = pointscroll;
  98. }
  99. }
  100. drawArea.Refresh();
  101. drawArea.GraphicsList.Dirty = true;
  102. }
  103. }
  104. }
  105. }
  106. /// <summary>
  107. /// 鼠标抬起事件
  108. /// </summary>
  109. /// <param name="drawArea"></param>
  110. /// <param name="e"></param>
  111. public static void OnMouseUp(ISurfaceBox drawArea, MouseEventArgs e)
  112. {
  113. }
  114. public static void OnMouseClick(ISurfaceBox surfacebox, MouseEventArgs e)
  115. {
  116. }
  117. /// <summary>
  118. /// 鼠标左键双击
  119. /// </summary>
  120. /// <param name="drawArea"></param>
  121. /// <param name="e"></param>
  122. public static void OnMouseLeftDoubleClick(ISurfaceBox surfacebox, MouseEventArgs e)
  123. {
  124. }
  125. /// <summary>
  126. /// 删除按键
  127. /// </summary>
  128. /// <param name="surfacebox"></param>
  129. /// <param name="e"></param>
  130. public static void OnDelKeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  131. {
  132. }
  133. /// <summary>
  134. /// 删除划痕处理&污迹处理选择区域的痕迹
  135. /// </summary>
  136. /// <param name="surfacebox"></param>
  137. /// <param name="e"></param>
  138. public static void OnDel2KeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  139. {
  140. }
  141. /// <summary>
  142. /// 清空全部时调用该方法,将可能未绘制完的对象清空
  143. /// </summary>
  144. public static void beginWithNewObject()
  145. {
  146. newLength = null;
  147. clickCount = 0;
  148. }
  149. }
  150. }