DrawBinaryConnectionOval.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using PaintDotNet.Annotation.Enum;
  2. using PaintDotNet.Annotation.Label;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace PaintDotNet.Annotation.Other
  6. {
  7. /// <summary>
  8. /// 二值提取-交互操作-矩形
  9. /// </summary>
  10. public class DrawBinaryConnectionOval : DrawObject
  11. {
  12. public DrawBinaryConnectionOval(ISurfaceBox surfaceBox, int x, int y, int width, int height) : base()
  13. {
  14. this.objectType = DrawClass.Interaction;
  15. this.drawToolType = DrawToolType.BinaryConnectionOval;
  16. this.ISurfaceBox = surfaceBox;
  17. this.rectangle.X = x;
  18. this.rectangle.Y = y;
  19. this.rectangle.Width = width;
  20. this.rectangle.Height = height;
  21. Initialize();
  22. }
  23. public override DrawObject Clone()
  24. {
  25. return null;
  26. }
  27. public override void Draw(Graphics g)
  28. {
  29. Pen pen = new Pen(Color.Red, this.ISurfaceBox.GetConnectionWidth());
  30. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  31. SolidBrush fillBrush = new SolidBrush(Color.Transparent);
  32. g.FillRectangle(fillBrush, DrawRectangle.GetNormalizedRectangle(Rectangle));
  33. g.DrawEllipse(pen, DrawRectangle.GetNormalizedRectangle(Rectangle));
  34. fillBrush.Dispose();
  35. pen.Dispose();
  36. }
  37. public override RectangleF GetBoundingBox()
  38. {
  39. return rectangle;
  40. }
  41. /// <summary>
  42. /// Move handle to new pointscroll (resizing)
  43. /// </summary>
  44. /// <param name="pointscroll"></param>
  45. /// <param name="handleNumber"></param>
  46. public override void MoveHandleTo(Point point, int handleNumber)
  47. {
  48. float left = Rectangle.Left;
  49. float top = Rectangle.Top;
  50. float right = Rectangle.Right;
  51. float bottom = Rectangle.Bottom;
  52. switch (handleNumber)
  53. {
  54. case 1:
  55. left = point.X;
  56. top = point.Y;
  57. break;
  58. case 2:
  59. top = point.Y;
  60. break;
  61. case 3:
  62. right = point.X;
  63. top = point.Y;
  64. break;
  65. case 4:
  66. right = point.X;
  67. break;
  68. case 5:
  69. right = point.X;
  70. bottom = point.Y;
  71. break;
  72. case 6:
  73. bottom = point.Y;
  74. break;
  75. case 7:
  76. left = point.X;
  77. bottom = point.Y;
  78. break;
  79. case 8:
  80. left = point.X;
  81. break;
  82. }
  83. SetRectangle(left, top, right - left, bottom - top);
  84. }
  85. protected void SetRectangle(float x, float y, float width, float height)
  86. {
  87. this.rectangle.X = x;
  88. this.rectangle.Y = y;
  89. this.rectangle.Width = width;
  90. this.rectangle.Height = height;
  91. }
  92. }
  93. }