123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Base.CommTool;
- 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 ViewRectangleEx : ViewBase
- {
- public override void SetK()
- {
- K = (double)(Points[1].Y - Points[0].Y) / (Points[1].X - Points[0].X);
- }
- #region Constructor
- public ViewRectangleEx()
- {
- objectType = DrawClass.View;
- drawToolType = DrawToolType.ViewRectangleEx;
- Rotatable = true;
- Initialize();
- }
- public ViewRectangleEx(Point p) : this()
- {
- for (int i = 0; i < 4; i++) AddPoint(p);
- }
- public ViewRectangleEx(List<PointF> points) : this()
- {
- Points = points;
- SetK();
- }
- #endregion
- /// <summary>
- /// 帮助创建任意四边形视场
- /// </summary>
- ///
- public void CreatStep(Point point, int step)
- {
- switch (step)
- {
- case 1:
- Points[1] = point;
- Points[2] = point;
- SetK();
- break;
- case 2:
- MoveCorner(point, 2);
- break;
- }
- OnPropertyChanged();
- }
- #region Handle
- public override int HandleCount => 9;
- public override PointF GetHandle(int i)
- {
- if (i == 9)
- {
- var x = GetHandle(2).X + GetHandle(3).X;
- var y = GetHandle(2).Y + GetHandle(3).Y;
- x = (float)((x / 2));
- y = (float)((y / 2));
- return new PointF(x, y);
- }
- else
- {
- var count = Points.Count;
- var x = Points[(i / 2) % count].X + Points[(i - 1) / 2].X;
- var y = Points[(i / 2) % count].Y + Points[(i - 1) / 2].Y;
- return new PointF(x / 2, y / 2);
- }
- }
- public override Cursor GetHandleCursor(int handleNumber)
- {
- if (handleNumber == 9)
- return m_rotateCursor;
- else
- return m_resizeCursor;
- }
- public override void MoveHandleTo(Point point, int handleNumber)
- {
- if (handleNumber == 9)
- MoveRotate(point);
- else if (handleNumber % 2 == 0)
- MoveEdge(point, handleNumber / 2 - 1);
- else
- MoveCorner(point, handleNumber / 2);
- OnPropertyChanged();
- }
- private void MoveCorner(Point point, int i)
- {
- this.Points[i] = point;
- if (i % 2 == 0)
- {
- this.Points[(i + 3) % 4] = BasicCalculationHelper.GetDropFeet(this.Points[(i + 2) % 4], K, point);
- this.Points[(i + 1) % 4] = BasicCalculationHelper.GetDropFeet(this.Points[(i + 2) % 4], -1 / K, point);
- }
- else
- {
- this.Points[(i + 1) % 4] = BasicCalculationHelper.GetDropFeet(this.Points[(i + 2) % 4], K, point);
- this.Points[(i + 3) % 4] = BasicCalculationHelper.GetDropFeet(this.Points[(i + 2) % 4], -1 / K, point);
- }
- }
- private void MoveEdge(Point point, int i)
- {
- var tempk = i % 2 != 0 ? K : -1 / K;
- this.Points[i] = BasicCalculationHelper.GetDropFeet(Points[(i + 3) % 4], tempk, point);
- this.Points[(i + 1) % 4] = BasicCalculationHelper.GetDropFeet(Points[(i + 2) % 4], tempk, point);
- }
- #endregion
- #region Clone
- public override DrawObject Clone()
- {
- return Clone(ISurfaceBox);
- }
- /// <summary>
- /// Clone this instance
- /// </summary>
- public override DrawObject Clone(ISurfaceBox surfaceBox)
- {
- ViewRectangleEx drawRectangle = new ViewRectangleEx(Points);
- drawRectangle.ISurfaceBox = surfaceBox;
- drawRectangle.combineMode = this.combineMode;
- drawRectangle.Color = Color;
- drawRectangle.ID = ID;
- FillDrawObjectFields(drawRectangle);
- return drawRectangle;
- }
- #endregion
- }
- }
|