ViewPolygon.cs 2.7 KB

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