DrawBinaryAddTrack.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using PaintDotNet.Annotation.Enum;
  2. using PaintDotNet.Annotation.Label;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using System.Windows.Forms;
  7. namespace PaintDotNet.Annotation.Other
  8. {
  9. /// <summary>
  10. /// 二值提取-交互操作-删除-多边形
  11. /// </summary>
  12. public class DrawBinaryAddTrack : DrawObject
  13. {
  14. public List<PointF> pointArray = new List<PointF>();
  15. public DrawBinaryAddTrack(ISurfaceBox surfaceBox, int x, int y) : base()
  16. {
  17. this.objectType = DrawClass.Interaction;
  18. this.drawToolType = DrawToolType.BinaryAddTrack;
  19. pointArray.Add(new Point(x, y));
  20. startPoint.X = x;
  21. startPoint.Y = y;
  22. this.rectangle.X = x;
  23. this.rectangle.Y = y;
  24. Initialize();
  25. }
  26. public override DrawObject Clone()
  27. {
  28. return null;
  29. }
  30. public override void Draw(Graphics g)
  31. {
  32. if (HandleCount >= 2)
  33. {
  34. g.SmoothingMode = SmoothingMode.AntiAlias;
  35. Color color = Color.Red;
  36. Pen pen = new Pen(color, PenWidth);
  37. int penWidth = 3;
  38. pen.DashStyle = DashStyle.Dot;
  39. pen.Width = penWidth;
  40. Color fillColor = Color.Transparent;
  41. SolidBrush fillBrush = new SolidBrush(fillColor);
  42. g.FillPolygon(fillBrush, pointArray.ToArray());
  43. g.DrawLines(pen, pointArray.ToArray());
  44. pen.Dispose();
  45. fillBrush.Dispose();
  46. }
  47. }
  48. public override int HandleCount
  49. {
  50. get
  51. {
  52. return pointArray.Count;
  53. }
  54. }
  55. public override RectangleF GetBoundingBox()
  56. {
  57. return rectangle;
  58. }
  59. /// <summary>
  60. /// Move handle to new pointscroll (resizing)
  61. /// </summary>
  62. /// <param name="pointscroll"></param>
  63. /// <param name="handleNumber"></param>
  64. public override void MoveHandleTo(Point point, int handleNumber)
  65. {
  66. float left = Rectangle.Left;
  67. float top = Rectangle.Top;
  68. float right = Rectangle.Right;
  69. float bottom = Rectangle.Bottom;
  70. switch (handleNumber)
  71. {
  72. case 1:
  73. left = point.X;
  74. top = point.Y;
  75. break;
  76. case 2:
  77. top = point.Y;
  78. break;
  79. case 3:
  80. right = point.X;
  81. top = point.Y;
  82. break;
  83. case 4:
  84. right = point.X;
  85. break;
  86. case 5:
  87. right = point.X;
  88. bottom = point.Y;
  89. break;
  90. case 6:
  91. bottom = point.Y;
  92. break;
  93. case 7:
  94. left = point.X;
  95. bottom = point.Y;
  96. break;
  97. case 8:
  98. left = point.X;
  99. break;
  100. }
  101. SetRectangle(left, top, right - left, bottom - top);
  102. }
  103. protected void SetRectangle(float x, float y, float width, float height)
  104. {
  105. this.rectangle.X = x;
  106. this.rectangle.Y = y;
  107. this.rectangle.Width = width;
  108. this.rectangle.Height = height;
  109. }
  110. public void AddPoint(Point point)
  111. {
  112. pointArray.Add(point);
  113. }
  114. internal void setNextPoint(Point p)
  115. {
  116. AddPoint(p);
  117. startPoint = endPoint;
  118. endPoint = p;
  119. }
  120. }
  121. }