ToolMeasureRectangle.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. 
  2. using PaintDotNet.Annotation.Enum;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace PaintDotNet.Annotation.Measure
  6. {
  7. /// <summary>
  8. /// 测量->多边形测量->矩形
  9. /// </summary>
  10. public class ToolMeasureRectangle : ToolMeasureObject
  11. {
  12. private static MeasureRectangle newRectangle;
  13. private static bool moved = false;
  14. /// <summary>
  15. /// Left nouse button is pressed
  16. /// </summary>
  17. /// <param name="drawArea"></param>
  18. /// <param name="e"></param>
  19. public static void OnMouseDown(ISurfaceBox drawArea, MouseEventArgs e)
  20. {
  21. if (e.Button == MouseButtons.Left)
  22. {
  23. if (newRectangle == null)
  24. {
  25. Point p = GetEventPointInArea(drawArea, e.Location);
  26. newRectangle = new MeasureRectangle(drawArea, new Point(p.X, p.Y), new Point(p.X + 1, p.Y + 1), true);
  27. newRectangle.ISurfaceBox = drawArea;
  28. AddNewObject(drawArea, newRectangle);
  29. }
  30. }
  31. else
  32. {
  33. if(newRectangle != null)
  34. {
  35. if (e.Clicks == 2)
  36. {
  37. for (int i = 0; i < drawArea.GraphicsList.Count; i++)
  38. {
  39. if (drawArea.GraphicsList[i].drawToolType == newRectangle.drawToolType)
  40. {
  41. drawArea.GraphicsList.RemoveAt(i);
  42. break;
  43. }
  44. }
  45. }
  46. }
  47. if (!drawArea.ContinuousDrawingMeasure())
  48. {
  49. drawArea.ActiveTool = DrawToolType.Pointer;
  50. }
  51. if (e.Button == MouseButtons.Right && e.Clicks == 1) {
  52. OnMouseNotLeftDown(drawArea, null);
  53. }
  54. }
  55. }
  56. /// <summary>
  57. /// 鼠标移动,需要进行绘制
  58. /// </summary>
  59. /// <param name="drawArea"></param>
  60. /// <param name="e"></param>
  61. public static void OnMouseMove(ISurfaceBox drawArea, MouseEventArgs e)
  62. {
  63. Point pointscroll = GetEventPointInArea(drawArea, e.Location);
  64. if (newRectangle != null)
  65. {
  66. newRectangle.moved = true;
  67. moved = true;
  68. if (drawArea.GraphicsList[0] != null)
  69. {
  70. drawArea.GraphicsList[0].MoveHandleTo(pointscroll, 2);
  71. drawArea.Refresh();
  72. drawArea.GraphicsList.Dirty = true;
  73. }
  74. }
  75. }
  76. /// <summary>
  77. /// 鼠标抬起事件
  78. /// </summary>
  79. /// <param name="drawArea"></param>
  80. /// <param name="e"></param>
  81. public static void OnMouseUp(ISurfaceBox drawArea, MouseEventArgs e)
  82. {
  83. if (e.Button == MouseButtons.Left)
  84. {
  85. if (newRectangle.area == 0)
  86. {
  87. return;
  88. }
  89. if (!moved)
  90. {
  91. if (newRectangle != null)
  92. {
  93. for (int i = 0; i < drawArea.GraphicsList.Count; i++)
  94. {
  95. if (drawArea.GraphicsList[i].drawToolType == newRectangle.drawToolType)
  96. {
  97. drawArea.GraphicsList.RemoveAt(i);
  98. break;
  99. }
  100. }
  101. }
  102. }
  103. moved = false;
  104. if (newRectangle != null)
  105. {
  106. newRectangle.pointChange = false;
  107. newRectangle.mouseUpPointChange = false;
  108. }
  109. newRectangle = null;
  110. if (!drawArea.ContinuousDrawingMeasure())
  111. drawArea.ActiveTool = DrawToolType.Pointer;
  112. OnMouseUpTwo(drawArea, 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. public static void beginWithNewObject()
  143. {
  144. newRectangle = null;
  145. }
  146. }
  147. }