ToolMeasureVLine.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using PaintDotNet.Annotation.Command;
  2. using PaintDotNet.Annotation.Enum;
  3. using PaintDotNet.Base.CommTool;
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. namespace PaintDotNet.Annotation.Measure
  8. {
  9. /// <summary>
  10. /// 测量->直线->垂直线
  11. /// </summary>
  12. public class ToolMeasureVLine : ToolMeasureObject
  13. {
  14. private static MeasureVLine line;
  15. private static bool moved = false;
  16. public static void OnMouseDown(ISurfaceBox drawArea, MouseEventArgs e)
  17. {
  18. if (e.Button == MouseButtons.Left)
  19. {
  20. if (line == null)
  21. {
  22. Point pointscroll = GetEventPointInArea(drawArea, e.Location);
  23. line = new MeasureVLine(drawArea, new Point(pointscroll.X, pointscroll.Y), new Point(pointscroll.X, pointscroll.Y + 1));
  24. line.ISurfaceBox = drawArea;
  25. AddNewObject(drawArea, line);
  26. }
  27. }
  28. else
  29. {
  30. if (!drawArea.ContinuousDrawingMeasure())
  31. {
  32. drawArea.ActiveTool = DrawToolType.Pointer;
  33. }
  34. if (e.Button == MouseButtons.Right && e.Clicks == 1)
  35. {
  36. OnMouseNotLeftDown(drawArea, null);
  37. }
  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. /// <summary>
  56. /// 鼠标抬起事件
  57. /// </summary>
  58. /// <param name="drawArea"></param>
  59. /// <param name="e"></param>
  60. public static void OnMouseUp(ISurfaceBox drawArea, MouseEventArgs e)
  61. {
  62. if (e.Button == MouseButtons.Left)
  63. {
  64. Point pointscroll = GetEventPointInArea(drawArea, e.Location);
  65. if ((pointscroll.X == line.startPoint.X && pointscroll.Y == line.startPoint.Y))
  66. {
  67. return;
  68. }
  69. line.endPoint = new PointF(line.startPoint.X, pointscroll.Y);
  70. if (!moved)
  71. {
  72. if (line != null)
  73. {
  74. for (int i = 0; i < drawArea.GraphicsList.Count; i++)
  75. {
  76. if (drawArea.GraphicsList[i].drawToolType == line.drawToolType)
  77. {
  78. drawArea.GraphicsList.RemoveAt(i);
  79. break;
  80. }
  81. }
  82. }
  83. }
  84. moved = false;
  85. if (line != null)
  86. {
  87. line.pointChange = false;
  88. line.mouseUpPointChange = false;
  89. }
  90. line = null;
  91. if (!drawArea.ContinuousDrawingMeasure())
  92. drawArea.ActiveTool = DrawToolType.Pointer;
  93. OnMouseUpTwo(drawArea, e);
  94. }
  95. }
  96. public static void OnMouseClick(ISurfaceBox drawArea, MouseEventArgs e)
  97. {
  98. }
  99. /// <summary>
  100. /// 鼠标左键双击
  101. /// </summary>
  102. /// <param name="drawArea"></param>
  103. /// <param name="e"></param>
  104. public static void OnMouseLeftDoubleClick(ISurfaceBox surfacebox, MouseEventArgs e)
  105. {
  106. }
  107. /// <summary>
  108. /// 删除按键
  109. /// </summary>
  110. /// <param name="surfacebox"></param>
  111. /// <param name="e"></param>
  112. public static void OnDelKeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  113. {
  114. }
  115. /// <summary>
  116. /// 删除划痕处理&污迹处理选择区域的痕迹
  117. /// </summary>
  118. /// <param name="surfacebox"></param>
  119. /// <param name="e"></param>
  120. public static void OnDel2KeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  121. {
  122. }
  123. /// <summary>
  124. /// 清空全部时调用该方法,将可能未绘制完的对象清空
  125. /// </summary>
  126. public static void beginWithNewObject()
  127. {
  128. line = null;
  129. }
  130. }
  131. }