123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- 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 ViewRectangle : ViewBase
- {
- public override double Width
- {
- get => Rectangle.Width;
- set
- {
- MoveHandleTo(new PointF((float)(value + Points[0].X), 0), 4);
- }
- }
- public override double Height
- {
- get => Rectangle.Height;
- set
- {
- MoveHandleTo(new PointF(0, (float)(value + Points[0].Y)), 6);
- }
- }
- #region Constructor
- public ViewRectangle()
- {
- objectType = DrawClass.View;
- drawToolType = DrawToolType.ViewRectangle;
- Initialize();
- }
- public ViewRectangle(int x, int y) : this()
- {
- for (int i = 0; i < 4; i++) AddPoint(x, y);
- }
- public ViewRectangle(int x, int y, int width, int height) : this()
- {
- AddPoint(new PointF(x, y));
- AddPoint(new PointF(x + width, y));
- AddPoint(new PointF(x + width, y + height));
- AddPoint(new PointF(x, y + height));
- }
- public ViewRectangle(List<PointF> points) : this()
- {
- Points = points;
- }
- #endregion
- #region Handle
- public override int HandleCount
- {
- get
- {
- return 8;
- }
- }
- public override PointF GetHandle(int handleIndex)
- {
- var count = Points.Count;
- var x = Points[(handleIndex / 2) % count].X + Points[(handleIndex - 1) / 2].X;
- var y = Points[(handleIndex / 2) % count].Y + Points[(handleIndex - 1) / 2].Y;
- return new PointF(x / 2, y / 2);
- }
- public override Cursor GetHandleCursor(int handleNumber)
- {
- switch (handleNumber)
- {
- case 1:
- return Cursors.SizeNWSE;
- case 2:
- return Cursors.SizeNS;
- case 3:
- return Cursors.SizeNESW;
- case 4:
- return Cursors.SizeWE;
- case 5:
- return Cursors.SizeNWSE;
- case 6:
- return Cursors.SizeNS;
- case 7:
- return Cursors.SizeNESW;
- case 8:
- return Cursors.SizeWE;
- default:
- return Cursors.Default;
- }
- }
- public override void MoveHandleTo(Point point, int handleNumber)
- {
- MoveHandleTo((PointF)point, handleNumber);
- }
- public override void MoveHandleTo(PointF point, int handleNumber)
- {
- if (handleNumber % 2 == 0)
- MoveEdge(point, handleNumber / 2 - 1);
- else
- MoveCorner(point, handleNumber / 2);
- OnPropertyChanged();
- }
- private void MoveCorner(PointF point, int i)
- {
- Points[i] = point;
- if (i % 2 == 0)
- {
- Points[(i + 1) % 4] = new PointF(Points[(i + 1) % 4].X, point.Y);
- Points[(i + 3) % 4] = new PointF(point.X, Points[(i + 3) % 4].Y);
- }
- else
- {
- Points[(i + 1) % 4] = new PointF(point.X, Points[(i + 1) % 4].Y);
- Points[(i + 3) % 4] = new PointF(Points[(i + 3) % 4].X, point.Y);
- }
- }
- private void MoveEdge(PointF 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);
- }
- public override DrawObject Clone(ISurfaceBox surfaceBox)
- {
- ViewRectangle drawRectangle = new ViewRectangle(Points);
- drawRectangle.ISurfaceBox = surfaceBox;
- drawRectangle.combineMode = combineMode;
- drawRectangle.Color = Color;
- drawRectangle.ID = ID;
- FillDrawObjectFields(drawRectangle);
- return drawRectangle;
- }
- #endregion
- }
- }
|