DedicatedAnalysisDrawObject.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using PaintDotNet.Annotation.Enum;
  2. using PaintDotNet.Annotation.FieldView;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace PaintDotNet.Annotation.DedicatedAnalysis
  12. {
  13. public class DrawRecognitionAreaDrawObject : DedicatedAnalysisDrawObject
  14. {
  15. public CombineMode combineMode;
  16. public DrawRecognitionAreaDrawObject():base(null)
  17. {
  18. Initialize();
  19. }
  20. public DrawRecognitionAreaDrawObject(int x, int y, int width, int height) : base(null)
  21. {
  22. this.objectType = DrawClass.Other;
  23. this.drawToolType = DrawToolType.InclusionDrawRecognitionArea;
  24. this.rectangle.X = x;
  25. this.rectangle.Y = y;
  26. this.rectangle.Width = width;
  27. this.rectangle.Height = height;
  28. Initialize();
  29. }
  30. public DrawRecognitionAreaDrawObject(RectangleF rectangle) : base(null)
  31. {
  32. this.objectType = DrawClass.Other;
  33. this.drawToolType = DrawToolType.InclusionDrawRecognitionArea;
  34. this.rectangle = rectangle;
  35. Initialize();
  36. }
  37. /// <summary>
  38. /// Draw rectangle
  39. /// </summary>
  40. /// <param name="g"></param>
  41. public override void Draw(Graphics g)
  42. {
  43. g.DrawRectangles(new Pen(Color.Black, Selected ? 10 : 1),new RectangleF[] { this.rectangle });
  44. }
  45. protected void SetRectangle(float x, float y, float width, float height)
  46. {
  47. this.rectangle.X = x;
  48. this.rectangle.Y = y;
  49. this.rectangle.Width = width;
  50. this.rectangle.Height = height;
  51. }
  52. protected override bool PointInObject(Point point)
  53. {
  54. return rectangle.Contains(point);
  55. }
  56. /// <summary>
  57. /// Move handle to new pointscroll (resizing)
  58. /// </summary>
  59. /// <param name="pointscroll"></param>
  60. /// <param name="handleNumber"></param>
  61. public override void MoveHandleTo(Point point, int handleNumber)
  62. {
  63. float left = rectangle.Left;
  64. float top = rectangle.Top;
  65. float right = rectangle.Right;
  66. float bottom = rectangle.Bottom;
  67. switch (handleNumber)
  68. {
  69. case 1:
  70. left = point.X;
  71. top = point.Y;
  72. break;
  73. case 2:
  74. top = point.Y;
  75. break;
  76. case 3:
  77. right = point.X;
  78. top = point.Y;
  79. break;
  80. case 4:
  81. right = point.X;
  82. break;
  83. case 5:
  84. right = point.X;
  85. bottom = point.Y;
  86. break;
  87. case 6:
  88. bottom = point.Y;
  89. break;
  90. case 7:
  91. left = point.X;
  92. bottom = point.Y;
  93. break;
  94. case 8:
  95. left = point.X;
  96. break;
  97. }
  98. SetRectangle(left, top, right - left, bottom - top);
  99. base.MoveHandleTo(point, handleNumber);
  100. }
  101. public override bool IntersectsWith(Rectangle rectangle)
  102. {
  103. return this.rectangle.IntersectsWith(rectangle);
  104. }
  105. public override void Normalize()
  106. {
  107. rectangle = GetNormalizedRectangle(rectangle.X, rectangle.Y, rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height);
  108. }
  109. /// <summary>
  110. /// Move object
  111. /// </summary>
  112. /// <param name="deltaX"></param>
  113. /// <param name="deltaY"></param>
  114. public override void Move(int deltaX, int deltaY)
  115. {
  116. int x = ISurfaceBox.UnscaleScalar(deltaX);
  117. int y = ISurfaceBox.UnscaleScalar(deltaY);
  118. this.rectangle.X += x;
  119. this.rectangle.Y += y;
  120. base.Move(deltaX, deltaY);
  121. }
  122. public override List<PointF> GetPoints()
  123. {
  124. List<PointF> points = new List<PointF>();
  125. points.Add(GetHandle(1));
  126. points.Add(GetHandle(5));
  127. return points;
  128. }
  129. }
  130. }