ToolMeasureThreePointAngle.cs 5.6 KB

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