DrawPPhasePolygon.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using PaintDotNet.Annotation.Enum;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. namespace PaintDotNet.Annotation.PhysicalPhaseAction
  5. {
  6. /// <summary>
  7. /// 物相提取->定义物体->轮廓->椭圆
  8. /// </summary>
  9. public class DrawPPhasePolygon : DrawObject
  10. {
  11. /// <summary>
  12. /// 点集合
  13. /// </summary>
  14. public List<PointF> pointArray = new List<PointF>();
  15. /// <summary>
  16. /// 画笔
  17. /// </summary>
  18. private Pen pen = new Pen(Color.Blue, 2);
  19. public DrawPPhasePolygon(ISurfaceBox surfaceBox, int x, int y) : base()
  20. {
  21. this.objectType = DrawClass.PhaseExtraction;
  22. this.drawToolType = DrawToolType.PPhasePolygon;
  23. pointArray.Add(new Point(x, y));
  24. startPoint.X = x;
  25. startPoint.Y = y;
  26. this.rectangle.X = x;
  27. this.rectangle.Y = y;
  28. }
  29. public override void Draw(Graphics g)
  30. {
  31. if (HandleCount >= 3)
  32. {
  33. g.DrawPolygon(pen, pointArray.ToArray());
  34. }
  35. }
  36. /// <summary>
  37. /// Move handle to new pointscroll (resizing)
  38. /// </summary>
  39. /// <param name="pointscroll"></param>
  40. /// <param name="handleNumber"></param>
  41. public override void MoveHandleTo(Point point, int handleNumber)
  42. {
  43. float left = Rectangle.Left;
  44. float top = Rectangle.Top;
  45. float right = Rectangle.Right;
  46. float bottom = Rectangle.Bottom;
  47. switch (handleNumber)
  48. {
  49. case 1:
  50. left = point.X;
  51. top = point.Y;
  52. break;
  53. case 2:
  54. top = point.Y;
  55. break;
  56. case 3:
  57. right = point.X;
  58. top = point.Y;
  59. break;
  60. case 4:
  61. right = point.X;
  62. break;
  63. case 5:
  64. right = point.X;
  65. bottom = point.Y;
  66. break;
  67. case 6:
  68. bottom = point.Y;
  69. break;
  70. case 7:
  71. left = point.X;
  72. bottom = point.Y;
  73. break;
  74. case 8:
  75. left = point.X;
  76. break;
  77. }
  78. SetRectangle(left, top, right - left, bottom - top);
  79. }
  80. protected void SetRectangle(float x, float y, float width, float height)
  81. {
  82. this.rectangle.X = x;
  83. this.rectangle.Y = y;
  84. this.rectangle.Width = width;
  85. this.rectangle.Height = height;
  86. }
  87. public void AddPoint(Point point)
  88. {
  89. pointArray.Add(point);
  90. }
  91. internal void setNextPoint(Point p)
  92. {
  93. AddPoint(p);
  94. startPoint = endPoint;
  95. endPoint = p;
  96. }
  97. public override int HandleCount
  98. {
  99. get
  100. {
  101. return pointArray.Count;
  102. }
  103. }
  104. public override void DrawTracker(Graphics g)
  105. {
  106. }
  107. public override DrawObject Clone()
  108. {
  109. return null;
  110. }
  111. public override RectangleF GetBoundingBox()
  112. {
  113. return rectangle;
  114. }
  115. }
  116. }