ViewTriangleEx.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using PaintDotNet.Annotation.Enum;
  2. using PaintDotNet.Base.CommTool;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.Drawing.Drawing2D;
  8. using System.Globalization;
  9. using System.Runtime.Serialization;
  10. using System.Windows.Forms;
  11. namespace PaintDotNet.Annotation.FieldView
  12. {
  13. /// <summary>
  14. /// 多边形视场绘制
  15. /// </summary>
  16. public class ViewTriangleEx : ViewBase
  17. {
  18. #region Constructor
  19. private ViewTriangleEx()
  20. {
  21. objectType = DrawClass.View;
  22. drawToolType = DrawToolType.ViewTriangleEx;
  23. Rotatable = true;
  24. Initialize();
  25. }
  26. public ViewTriangleEx(int x, int y) : this()
  27. {
  28. Points = new List<PointF>();
  29. AddPoint(new PointF(x, y));
  30. }
  31. public ViewTriangleEx(List<PointF> points) : this()
  32. {
  33. Points = points;
  34. }
  35. #endregion
  36. internal void SetNextPoint(Point p)
  37. {
  38. AddPoint(p);
  39. }
  40. #region Handle
  41. public override int HandleCount
  42. {
  43. get => Points.Count > 2 ? Points.Count + 1 : Points.Count;
  44. }
  45. public override Cursor GetHandleCursor(int handleNumber)
  46. {
  47. if (handleNumber > Points.Count)
  48. return m_rotateCursor;
  49. else
  50. return m_resizeCursor;
  51. }
  52. public override PointF GetHandle(int handleNumber)
  53. {
  54. if (handleNumber < 4) return Points[handleNumber - 1];
  55. else
  56. {
  57. var x = (Points[0].X + Points[1].X) / 2;
  58. var y = (Points[0].Y + Points[1].Y) / 2;
  59. return new PointF(x, y);
  60. }
  61. }
  62. public override void MoveHandleTo(Point point, int handleNumber)
  63. {
  64. if (handleNumber == 4)
  65. MoveRotate(point);
  66. else
  67. Points[handleNumber - 1] = point;
  68. OnPropertyChanged();
  69. }
  70. #endregion
  71. #region Clone
  72. public override DrawObject Clone()
  73. {
  74. return Clone(ISurfaceBox);
  75. }
  76. public override DrawObject Clone(ISurfaceBox surfaceBox)
  77. {
  78. ViewTriangleEx drawRectangle = new ViewTriangleEx(Points);
  79. drawRectangle.ISurfaceBox = surfaceBox;
  80. drawRectangle.Color = Color;
  81. drawRectangle.combineMode = combineMode;
  82. drawRectangle.ID = ID;
  83. FillDrawObjectFields(drawRectangle);
  84. return drawRectangle;
  85. }
  86. #endregion
  87. }
  88. }