DrawPPhaseRectangle.cs 2.6 KB

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