ToolViewRectangleEx.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using PaintDotNet.Annotation.Enum;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace PaintDotNet.Annotation.FieldView
  5. {
  6. public class ToolViewRectangleEx : ToolObject
  7. {
  8. private static ViewRectangleEx rect;
  9. /// <summary>
  10. /// 鼠标按下事件
  11. /// </summary>
  12. /// <param name="drawArea"></param>
  13. /// <param name="e"></param>
  14. public static void OnMouseDown(ISurfaceBox surfaceBox, MouseEventArgs e)
  15. {
  16. WorkFlowCreat(surfaceBox, e, EventType.Down);
  17. }
  18. /// <summary>
  19. /// 鼠标移动事件
  20. /// </summary>
  21. /// <param name="drawArea"></param>
  22. /// <param name="e"></param>
  23. public static void OnMouseMove(ISurfaceBox drawArea, MouseEventArgs e)
  24. {
  25. WorkFlowCreat(drawArea, e, EventType.Move);
  26. drawArea.Refresh();
  27. drawArea.GraphicsList.Dirty = true;
  28. }
  29. static void Done(ISurfaceBox drawArea)
  30. {
  31. drawArea.ActiveTool = DrawToolType.Pointer;
  32. drawArea.GraphicsList.OnSelectChanged();
  33. drawArea.Refresh();
  34. rect = null;
  35. _step = 0;
  36. }
  37. static void Cancel(ISurfaceBox drawArea)
  38. {
  39. if (rect != null)
  40. {
  41. drawArea.GraphicsList.RemoveObj(rect);
  42. }
  43. Done(drawArea);
  44. }
  45. static int _step = 0;
  46. private static void WorkFlowCreat(ISurfaceBox surfaceBox, MouseEventArgs e, EventType type)
  47. {
  48. Point p = GetEventPointInArea(surfaceBox, e.Location);
  49. if (e.Button == MouseButtons.Right)
  50. Cancel(surfaceBox);
  51. switch (_step)
  52. {
  53. case 0:
  54. if (e.Button == MouseButtons.Left && type == EventType.Down)
  55. {
  56. rect = new ViewRectangleEx(p);
  57. rect.ISurfaceBox = surfaceBox;
  58. rect.combineMode = surfaceBox.GetCombineMode();
  59. AddNewObjectForView(surfaceBox, rect);
  60. _step++;
  61. }
  62. break;
  63. case 1:
  64. if (e.Button == MouseButtons.Left && type == EventType.Down)
  65. {
  66. _step++;
  67. }
  68. else if (type == EventType.Move)
  69. {
  70. rect.CreatStep(p, _step);
  71. }
  72. break;
  73. case 2:
  74. if (e.Button == MouseButtons.Left && type == EventType.Down)
  75. {
  76. Done(surfaceBox);
  77. }
  78. else if (type == EventType.Move)
  79. {
  80. rect.CreatStep(p, _step);
  81. }
  82. break;
  83. }
  84. }
  85. private enum EventType
  86. {
  87. Down, Up, Move
  88. }
  89. #region Useless
  90. public static void OnMouseUp(ISurfaceBox drawArea, MouseEventArgs e)
  91. {
  92. }
  93. public static void OnMouseClick(ISurfaceBox drawArea, MouseEventArgs e)
  94. {
  95. }
  96. /// <summary>
  97. /// 鼠标左键双击
  98. /// </summary>
  99. /// <param name="drawArea"></param>
  100. /// <param name="e"></param>
  101. public static void OnMouseLeftDoubleClick(ISurfaceBox surfacebox, MouseEventArgs e)
  102. {
  103. }
  104. /// <summary>
  105. /// 删除按键
  106. /// </summary>
  107. /// <param name="surfacebox"></param>
  108. /// <param name="e"></param>
  109. public static void OnDelKeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  110. {
  111. }
  112. /// <summary>
  113. /// 删除划痕处理&污迹处理选择区域的痕迹
  114. /// </summary>
  115. /// <param name="surfacebox"></param>
  116. /// <param name="e"></param>
  117. public static void OnDel2KeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  118. {
  119. }
  120. /// <summary>
  121. /// 清空全部时调用该方法,将可能未绘制完的对象清空
  122. /// </summary>
  123. public static void beginWithNewObject()
  124. {
  125. }
  126. #endregion
  127. }
  128. }