DrawPPhaseOval.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using PaintDotNet.Annotation.Enum;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace PaintDotNet.Annotation.PhysicalPhaseAction
  9. {
  10. /// <summary>
  11. /// 物相提取->定义物体->轮廓->椭圆
  12. /// </summary>
  13. public class DrawPPhaseOval : DrawObject
  14. {
  15. private Pen pen = new Pen(Color.Blue, 2);
  16. public DrawPPhaseOval(ISurfaceBox surfaceBox, int x, int y, int width, int height) : base()
  17. {
  18. this.objectType = DrawClass.PhaseExtraction;
  19. this.drawToolType = DrawToolType.PPhaseOval;
  20. this.rectangle.X = x;
  21. this.rectangle.Y = y;
  22. this.rectangle.Width = width;
  23. this.rectangle.Height = height;
  24. }
  25. public override void Draw(Graphics g)
  26. {
  27. g.DrawEllipse(pen, GetNormalizedRectangle(Rectangle));
  28. }
  29. /// <summary>
  30. /// Move handle to new pointscroll (resizing)
  31. /// </summary>
  32. /// <param name="pointscroll"></param>
  33. /// <param name="handleNumber"></param>
  34. public override void MoveHandleTo(Point point, int handleNumber)
  35. {
  36. float left = Rectangle.Left;
  37. float top = Rectangle.Top;
  38. float right = Rectangle.Right;
  39. float bottom = Rectangle.Bottom;
  40. switch (handleNumber)
  41. {
  42. case 1:
  43. left = point.X;
  44. top = point.Y;
  45. break;
  46. case 2:
  47. top = point.Y;
  48. break;
  49. case 3:
  50. right = point.X;
  51. top = point.Y;
  52. break;
  53. case 4:
  54. right = point.X;
  55. break;
  56. case 5:
  57. right = point.X;
  58. bottom = point.Y;
  59. break;
  60. case 6:
  61. bottom = point.Y;
  62. break;
  63. case 7:
  64. left = point.X;
  65. bottom = point.Y;
  66. break;
  67. case 8:
  68. left = point.X;
  69. break;
  70. }
  71. SetRectangle(left, top, right - left, bottom - top);
  72. }
  73. protected void SetRectangle(float x, float y, float width, float height)
  74. {
  75. this.rectangle.X = x;
  76. this.rectangle.Y = y;
  77. this.rectangle.Width = width;
  78. this.rectangle.Height = height;
  79. }
  80. public override DrawObject Clone()
  81. {
  82. return null;
  83. }
  84. public override RectangleF GetBoundingBox()
  85. {
  86. return rectangle;
  87. }
  88. }
  89. }