DrawBinaryChoiseRectangle.cs 3.0 KB

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