ToolMeasureRectangle.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 && e.Clicks != 2)
  22. {
  23. Point p = GetEventPointInArea(drawArea, e.Location);
  24. newRectangle = new MeasureRectangle(drawArea, new Point(p.X, p.Y), new Point(p.X + 1, p.Y + 1), true);
  25. newRectangle.ISurfaceBox = drawArea;
  26. AddNewObject(drawArea, newRectangle);
  27. }
  28. else
  29. {
  30. if(newRectangle != null)
  31. {
  32. if (e.Clicks == 2)
  33. {
  34. for (int i = 0; i < drawArea.GraphicsList.Count; i++)
  35. {
  36. if (drawArea.GraphicsList[i].drawToolType == newRectangle.drawToolType)
  37. {
  38. drawArea.GraphicsList.RemoveAt(i);
  39. break;
  40. }
  41. }
  42. }
  43. }
  44. if (!drawArea.ContinuousDrawingMeasure())
  45. {
  46. drawArea.ActiveTool = DrawToolType.Pointer;
  47. }
  48. if (e.Button == MouseButtons.Right && e.Clicks == 1) {
  49. OnMouseNotLeftDown(drawArea, null);
  50. }
  51. }
  52. }
  53. /// <summary>
  54. /// 鼠标移动,需要进行绘制
  55. /// </summary>
  56. /// <param name="drawArea"></param>
  57. /// <param name="e"></param>
  58. public static void OnMouseMove(ISurfaceBox drawArea, MouseEventArgs e)
  59. {
  60. if (e.Button == MouseButtons.Left)
  61. {
  62. Point pointscroll = GetEventPointInArea(drawArea, e.Location);
  63. if (e.Button == MouseButtons.Left)
  64. {
  65. if (newRectangle != null)
  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. }
  77. /// <summary>
  78. /// 鼠标抬起事件
  79. /// </summary>
  80. /// <param name="drawArea"></param>
  81. /// <param name="e"></param>
  82. public static void OnMouseUp(ISurfaceBox drawArea, MouseEventArgs e)
  83. {
  84. if (e.Button == MouseButtons.Left)
  85. {
  86. if (!moved)
  87. {
  88. if (newRectangle != null)
  89. {
  90. for (int i = 0; i < drawArea.GraphicsList.Count; i++)
  91. {
  92. if (drawArea.GraphicsList[i].drawToolType == newRectangle.drawToolType)
  93. {
  94. drawArea.GraphicsList.RemoveAt(i);
  95. break;
  96. }
  97. }
  98. }
  99. }
  100. moved = false;
  101. if (newRectangle != null)
  102. {
  103. newRectangle.pointChange = false;
  104. newRectangle.mouseUpPointChange = false;
  105. }
  106. if (!drawArea.ContinuousDrawingMeasure())
  107. drawArea.ActiveTool = DrawToolType.Pointer;
  108. OnMouseUpTwo(drawArea, e);
  109. }
  110. }
  111. public static void OnMouseClick(ISurfaceBox drawArea, MouseEventArgs e)
  112. {
  113. }
  114. /// <summary>
  115. /// 鼠标左键双击
  116. /// </summary>
  117. /// <param name="drawArea"></param>
  118. /// <param name="e"></param>
  119. public static void OnMouseLeftDoubleClick(ISurfaceBox surfacebox, MouseEventArgs e)
  120. {
  121. }
  122. /// <summary>
  123. /// 删除按键
  124. /// </summary>
  125. /// <param name="surfacebox"></param>
  126. /// <param name="e"></param>
  127. public static void OnDelKeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  128. {
  129. }
  130. /// <summary>
  131. /// 删除划痕处理&污迹处理选择区域的痕迹
  132. /// </summary>
  133. /// <param name="surfacebox"></param>
  134. /// <param name="e"></param>
  135. public static void OnDel2KeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  136. {
  137. }
  138. public static void beginWithNewObject()
  139. {
  140. newRectangle = null;
  141. }
  142. }
  143. }