using PaintDotNet.Annotation.Enum; using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Globalization; using System.Runtime.Serialization; using System.Windows.Forms; namespace PaintDotNet.Annotation.FieldView { /// /// 多边形视场绘制 /// public class ViewPolygon : ViewBase { #region Constructor public ViewPolygon() { objectType = DrawClass.View; drawToolType = DrawToolType.ViewPolygon; Rotatable = true; Initialize(); } public ViewPolygon(int x, int y) : this() { AddPoint(x, y); } public ViewPolygon(List points) : this() { Points = points; } #endregion internal void setNextPoint(Point p) { AddPoint(p); } #region HandleCount public override int HandleCount { get { //直到有面积后,才可以出现旋转点 return Points.Count > 2 ? Points.Count + 1 : Points.Count; } } public override Cursor GetHandleCursor(int handleNumber) { if (handleNumber > Points.Count) return m_rotateCursor; else return m_resizeCursor; } public override PointF GetHandle(int handleNumber) { if (handleNumber > Points.Count) { var x = (Points[0].X + Points[1].X) / 2; var y = (Points[0].Y + Points[1].Y) / 2; return new PointF(x, y); } else { return Points[handleNumber - 1]; } } public override void MoveHandleTo(Point point, int handleNumber) { if (handleNumber > Points.Count) MoveRotate(point); else Points[handleNumber - 1] = point; OnPropertyChanged(); } #endregion #region Clone public override DrawObject Clone() { return Clone(ISurfaceBox); } /// /// Clone this instance /// public override DrawObject Clone(ISurfaceBox surfaceBox) { ViewPolygon drawRectangle = new ViewPolygon(Points); drawRectangle.ISurfaceBox = surfaceBox; drawRectangle.Color = Color; drawRectangle.combineMode = combineMode; drawRectangle.ID = ID; FillDrawObjectFields(drawRectangle); return drawRectangle; } #endregion } }