ToolLine.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using PaintDotNet.Annotation.Enum;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace PaintDotNet.Annotation.Label
  5. {
  6. /// <summary>
  7. /// 标注->直线->直线
  8. /// </summary>
  9. public class ToolLine : ToolObject
  10. {
  11. private static Cursor cursor = new Cursor(PdnResources.GetResourceStream("Cursors.AnnotationLine.cur"));
  12. private static DrawLine line;
  13. public static void OnMouseDown(ISurfaceBox drawArea, MouseEventArgs e)
  14. {
  15. if (e.Button == MouseButtons.Left)
  16. {
  17. if (line == null)
  18. {
  19. Point pointscroll = GetEventPointInArea(drawArea, e.Location);
  20. line = new DrawLine(drawArea, pointscroll.X, pointscroll.Y, pointscroll.X + 1, pointscroll.Y + 1);
  21. line.ISurfaceBox = drawArea;
  22. AddNewObject(drawArea, line);
  23. }
  24. }
  25. else
  26. {
  27. OnMouseNotLeftDown(drawArea, null);
  28. }
  29. }
  30. public static void OnMouseMove(ISurfaceBox drawArea, MouseEventArgs e)
  31. {
  32. Point pointscroll = GetEventPointInArea(drawArea, e.Location);
  33. drawArea.Cursor = cursor;
  34. if (line != null)
  35. {
  36. line.MoveHandleTo(pointscroll, 2);
  37. drawArea.Refresh();
  38. drawArea.GraphicsList.Dirty = true;
  39. }
  40. }
  41. public static void OnMouseUp(ISurfaceBox drawArea, MouseEventArgs e)
  42. {
  43. if (e.Button == MouseButtons.Left)
  44. {
  45. if (line != null)
  46. {
  47. Point pointscroll = GetEventPointInArea(drawArea, e.Location);
  48. if (pointscroll.X == drawArea.GraphicsList[0].startPoint.X && pointscroll.Y == drawArea.GraphicsList[0].startPoint.Y)
  49. {
  50. return;
  51. }
  52. line.endPoint = pointscroll;
  53. }
  54. if (!drawArea.ContinuousDrawingLabel())
  55. {
  56. drawArea.ActiveTool = DrawToolType.Pointer;
  57. }
  58. line = null;
  59. OnMouseUpTwo(drawArea, e);
  60. }
  61. }
  62. public static void OnMouseClick(ISurfaceBox surfacebox, MouseEventArgs e)
  63. {
  64. }
  65. /// <summary>
  66. /// 鼠标左键双击
  67. /// </summary>
  68. /// <param name="drawArea"></param>
  69. /// <param name="e"></param>
  70. public static void OnMouseLeftDoubleClick(ISurfaceBox surfacebox, MouseEventArgs e)
  71. {
  72. }
  73. /// <summary>
  74. /// 删除按键
  75. /// </summary>
  76. /// <param name="surfacebox"></param>
  77. /// <param name="e"></param>
  78. public static void OnDelKeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  79. {
  80. }
  81. /// <summary>
  82. /// 删除划痕处理&污迹处理选择区域的痕迹
  83. /// </summary>
  84. /// <param name="surfacebox"></param>
  85. /// <param name="e"></param>
  86. public static void OnDel2KeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
  87. {
  88. }
  89. public static void beginWithNewObject()
  90. {
  91. line = null;
  92. }
  93. }
  94. }