123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Base.CommTool;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Globalization;
- using System.Runtime.Serialization;
- using System.Windows.Forms;
- namespace PaintDotNet.Annotation.FieldView
- {
- /// <summary>
- /// 三角形视场绘制
- /// </summary>
- public class ViewTriangle : ViewBase
- {
- public override double Width
- {
- get => BasicCalculationHelper.GetDistance(Points[1], Points[2]);
- set
- {
- var angle = BasicCalculationHelper.CalculateAngle(Points[2], new PointF(Points[2].X + 100, Points[2].Y), Points[1]);
- var p = new PointF((float)(Points[2].X + value), Points[2].Y);
- p = BasicCalculationHelper.GetAnglePoint(p, Points[2], angle);
- MoveHandleTo(p, 2);
- }
- }
- public override double Height
- {
- get => BasicCalculationHelper.GetDistance(Points[0], Points[2]);
- set
- {
- var angle = BasicCalculationHelper.CalculateAngle(Points[2],new PointF(Points[2].X + 100, Points[2].Y), Points[0]);
- var p = new PointF((float)(Points[2].X + value), Points[2].Y);
- p = BasicCalculationHelper.GetAnglePoint(p, Points[2], angle);
- MoveHandleTo(p, 1);
- }
- }
- #region Structure
- public ViewTriangle()
- {
- objectType = DrawClass.View;
- drawToolType = DrawToolType.ViewTriangle;
- Rotatable = true;
- Initialize();
- }
- public ViewTriangle(int x, int y) : this()
- {
- AddPoint(x, y);
- AddPoint(x, y);
- AddPoint(x, y);
- }
- public ViewTriangle(List<PointF> points) : this()
- {
- Points = points;
- }
- #endregion
- #region Handle
- public override int HandleCount => 3;
- public override PointF GetHandle(int handleNumber)
- {
- return Points[handleNumber - 1];
- }
- public override Cursor GetHandleCursor(int handleNumber)
- {
- switch (handleNumber)
- {
- case 3:
- return m_rotateCursor;
- default:
- return m_resizeCursor;
- }
- }
- public override void MoveHandleTo(Point point, int handleNumber)
- {
- MoveHandleTo((PointF)point, handleNumber);
- }
- public override void MoveHandleTo(PointF point, int handleNumber)
- {
- if (handleNumber == 3)
- MoveRotate(point);
- else
- MoveCorner(point, handleNumber - 1);
- base.MoveHandleTo(point, handleNumber);
- }
- private void MoveCorner(PointF point, int i)
- {
- var k = i == 1 ? K : -1 / K;
- this.pointArrayList[i] = point;
- this.pointArrayList[2] = BasicCalculationHelper.GetDropFeet(this.pointArrayList[1 - i], -1 / k, point);
- }
- public override void SetK()
- {
- K = (double)(pointArrayList[1].Y - pointArrayList[2].Y) / (pointArrayList[1].X - pointArrayList[2].X);
- }
- #endregion
- #region Clone
- public override DrawObject Clone()
- {
- return Clone(ISurfaceBox);
- }
- public override DrawObject Clone(ISurfaceBox surfaceBox)
- {
- ViewTriangle triange = new ViewTriangle(Points);
- triange.ISurfaceBox = surfaceBox;
- triange.combineMode = combineMode;
- triange.Color = Color;
- triange.ID = ID;
- FillDrawObjectFields(triange);
- return triange;
- }
- #endregion
- }
- }
|