123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 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
- {
- /// <summary>
- /// 多边形视场绘制
- /// </summary>
- 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<PointF> 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);
- }
- /// <summary>
- /// Clone this instance
- /// </summary>
- 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
- }
- }
|