123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Media;
- namespace ComPDFKit.Tool.DrawTool
- {
- public partial class SelectedRect
- {
- #region Properties
- /// <summary>
- /// Current control point drawing style.
- /// </summary>
- protected DrawPointType currentDrawPointType
- {
- get;
- set;
- }
- /// <summary>
- /// Current drag drawing style.
- /// </summary>
- protected DrawMoveType currentDrawMoveType { get; set; }
- /// <summary>
- /// Current click hit control point.
- /// </summary>
- protected PointControlType hitControlType
- {
- get;
- set;
- }
- /// <summary>
- /// Mouse down position information.
- /// </summary>
- protected Point mouseDownPoint { get; set; }
- /// <summary>
- /// Whether the mouse is pressed.
- /// </summary>
- protected bool isMouseDown { get; set; }
- protected bool isInRotate { get; set; } = false;
- protected bool isInScaling { get; set; } = false;
- /// <summary>
- /// Whether proportional scaling is required.
- /// </summary>
- protected bool isProportionalScaling { get; set; } = false;
- /// <summary>
- /// Current control point size.
- /// </summary>
- protected int pointSize { get; set; } = 4;
- /// <summary>
- /// Rectangular minimum width.
- /// </summary>
- public int RectMinWidth { get; set; } = 10;
- /// <summary>
- /// Rectangular minimum height.
- /// </summary>
- public int RectMinHeight { get; set; } = 10;
- /// <summary>
- /// Current set of ignore points.
- /// </summary>
- protected List<PointControlType> ignorePoints { get; set; } = new List<PointControlType>();
- /// <summary>
- /// Current set of drawing rectangles (original data).
- /// </summary>
- protected Rect SetDrawRect
- {
- get;
- set;
- } = new Rect(0, 0, 0, 0);
- /// <summary>
- /// Current drawing rectangle (calculated during operation).
- /// </summary>
- protected Rect drawRect
- {
- get;
- set;
- } = new Rect(0, 0, 0, 0);
- /// <summary>
- /// Maximum range that can be drawn.
- /// </summary>
- protected Rect maxRect { get; set; } = new Rect(0, 0, 0, 0);
- /// <summary>
- /// Current center point of the drawing rectangle.
- /// </summary>
- protected Point drawCenterPoint { get; private set; } = new Point(0, 0);
- /// <summary>
- /// When the mouse is pressed, the cached rectangle.
- /// </summary>
- protected Rect cacheRect { get; set; } = new Rect(0, 0, 0, 0);
- /// <summary>
- /// Current control point coordinates.
- /// </summary>
- protected List<Point> controlPoints { get; set; } = new List<Point>();
- protected Point centerPoint = new Point();
- protected Point rotationPoint = new Point();
- protected Point dragRotationPoint = new Point();
- /// <summary>
- /// Move offset during movement.
- /// </summary>
- protected Point moveOffset { get; set; } = new Point(0, 0);
- /// <summary>
- /// Current drawing rectangle (calculated during operation).
- /// </summary>
- protected Thickness clipThickness = new Thickness(0, 0, 0, 0);
- private Pen editPen { get; set; } = new Pen(new SolidColorBrush(Color.FromRgb(71, 126, 222)), 2) { DashStyle = DashStyles.Dash };
- private Pen editHoverPen { get; set; } = new Pen(new SolidColorBrush(Color.FromRgb(71, 126, 222)), 2) { DashStyle = DashStyles.Dash };
- private bool showCreatTextRect = false;
- protected bool isOutSideScaling = false;
- /// <summary>
- /// Current actual display width and height of PDFVIewer.
- /// </summary>
- protected double PDFViewerActualWidth { get; set; } = 0;
- protected double PDFViewerActualHeight { get; set; } = 0;
- protected int rotateAngle { get; set; } = 0;
- protected int pageRotation { get; set; } = 0;
- protected double rectPadding = 6;
- protected double currentZoom = 1;
- protected SelectedAnnotData selectedRectData = new SelectedAnnotData();
- protected bool disable = false;
- protected List<Point> rotateControlPoints = new List<Point>();
- protected Rect rotateRect = new Rect();
- public bool IsPath { get; set; } = false;
- #endregion
- #region Functions
- /// <summary>
- /// Calcuate the control points
- /// </summary>
- /// <param name="currentRect">
- /// Control points in the target rectangle
- /// </param>
- protected void CalcControlPoint(Rect currentRect)
- {
- controlPoints.Clear();
- centerPoint.X = (int)(currentRect.Left + currentRect.Right) / 2;
- centerPoint.Y = (int)(currentRect.Top + currentRect.Bottom) / 2;
- controlPoints.Add(new Point(currentRect.Left, currentRect.Top));
- controlPoints.Add(new Point(currentRect.Left, centerPoint.Y));
- controlPoints.Add(new Point(currentRect.Left, currentRect.Bottom));
- controlPoints.Add(new Point(centerPoint.X, currentRect.Bottom));
- controlPoints.Add(new Point(currentRect.Right, currentRect.Bottom));
- controlPoints.Add(new Point(currentRect.Right, centerPoint.Y));
- controlPoints.Add(new Point(currentRect.Right, currentRect.Top));
- controlPoints.Add(new Point(centerPoint.X, currentRect.Top));
- if (canRotate)
- {
- rotationPoint = new Point(centerPoint.X, currentRect.Top - 30);
- switch (pageRotation)
- {
- case 0:
- rotationPoint = new Point(centerPoint.X, currentRect.Top - 30);
- break;
- case 1:
- rotationPoint = new Point(currentRect.Right + 30, centerPoint.Y);
- break;
- case 2:
- rotationPoint = new Point(centerPoint.X, currentRect.Bottom + 30);
- break;
- case 3:
- rotationPoint = new Point(currentRect.Left - 30, centerPoint.Y);
- break;
- default:
- break;
- }
- }
- }
- protected List<Point> GetControlPoint(Rect currentRect)
- {
- List<Point> controlCurrentPoints = new List<Point>();
- controlCurrentPoints.Clear();
- int centerX = (int)(currentRect.Left + currentRect.Right) / 2;
- int centerY = (int)(currentRect.Top + currentRect.Bottom) / 2;
- controlCurrentPoints.Add(new Point(currentRect.Left, currentRect.Top));
- controlCurrentPoints.Add(new Point(currentRect.Left, centerY));
- controlCurrentPoints.Add(new Point(currentRect.Left, currentRect.Bottom));
- controlCurrentPoints.Add(new Point(centerX, currentRect.Bottom));
- controlCurrentPoints.Add(new Point(currentRect.Right, currentRect.Bottom));
- controlCurrentPoints.Add(new Point(currentRect.Right, centerY));
- controlCurrentPoints.Add(new Point(currentRect.Right, currentRect.Top));
- controlCurrentPoints.Add(new Point(centerX, currentRect.Top));
- return controlCurrentPoints;
- }
- /// <summary>
- /// Calcuate the offset of the current rectangle in the maximum rectangle range
- /// </summary>
- /// <param name="currentRect">
- /// The rectangle cached when pressed
- /// </param>
- /// <param name="offsetPoint">
- /// Equivalent to the offset value when pressed
- /// </param>
- /// <param name="maxRect">
- /// The maximum rectangle range.
- /// </param>
- /// <returns></returns>
- protected Point CalcMoveBound(Rect currentRect, Point offsetPoint, Rect maxRect)
- {
- double cLeft = currentRect.Left;
- double cRight = currentRect.Right;
- double cUp = currentRect.Top;
- double cDown = currentRect.Bottom;
- double TmpLeft = cLeft + offsetPoint.X;
- double TmpRight = cRight + offsetPoint.X;
- double TmpUp = cUp + offsetPoint.Y;
- double TmpDown = cDown + offsetPoint.Y;
- if (TmpLeft < maxRect.Left)
- {
- TmpRight = (cRight - cLeft) + maxRect.Left;
- TmpLeft = maxRect.Left;
- }
- if (TmpUp < maxRect.Top)
- {
- TmpDown = (cDown - cUp) + maxRect.Top;
- TmpUp = maxRect.Top;
- }
- if (TmpRight > maxRect.Right)
- {
- TmpLeft = maxRect.Right - (cRight - cLeft);
- TmpRight = maxRect.Right;
- }
- if (TmpDown > maxRect.Bottom)
- {
- TmpUp = maxRect.Bottom - (cDown - cUp);
- TmpDown = maxRect.Bottom;
- }
- offsetPoint = new Point(TmpLeft - cLeft, TmpUp - cUp);
- return offsetPoint;
- }
- /// <summary>
- /// Calculate the movement of the hit point
- /// </summary>
- /// <param name="mousePoint">
- /// Current mouse position
- /// </param>
- /// <returns>
- /// Whether the movement is successful
- /// </returns>
- protected bool CalcHitPointMove(Point mousePoint)
- {
- if (isMouseDown == false || hitControlType == PointControlType.None)
- {
- return false;
- }
- if (hitControlType == PointControlType.Rotate)
- {
- SetRotateByMousePoint(mousePoint);
- return false;
- }
- if (!isOutSideScaling)
- {
- if (selectedRectData.rotationAngle != 0)
- {
- return RotateScaling(mousePoint);
- }
- else
- {
- return NormalScaling(mousePoint);
- }
- }
- else
- {
- return OutSideScaling(mousePoint);
- }
- }
- public void SetOutSideScaling(bool IsOutSideScaling)
- {
- isOutSideScaling = IsOutSideScaling;
- }
- private Size GetProportionalScalingSize(double width, double height)
- {
- double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
- double minWidth = RectMinWidth + 2 * rectPadding * currentZoom;
- if (minWidth > width || minHeight > height)
- {
- if (cacheRect.Width >= cacheRect.Height)
- {
- width = cacheRect.Width * minHeight / cacheRect.Height;
- height = minHeight;
- }
- else
- {
- height = cacheRect.Height * minWidth / cacheRect.Width;
- width = minWidth;
- }
- }
- return new Size(width, height);
- }
- private void SetRotateByMousePoint(Point mousePoint)
- {
- dragRotationPoint = mousePoint;
- Vector moveVector = (mousePoint - centerPoint);
- rotateAngle = (int)(Math.Atan2(moveVector.X, -moveVector.Y) * 180 / Math.PI) - pageRotation * 90;
- }
- /// <summary>
- /// Draw the algorithm in the form of normal scaling (drag a point, only scale in one direction).
- /// </summary>
- /// <param name="mousePoint">Current mouse position.</param>
- /// <returns></returns>
- protected bool NormalScaling(Point mousePoint)
- {
- try
- {
- double left = 0, right = 0, top = 0, bottom = 0;
- double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
- double minWidth = RectMinWidth + 2 * rectPadding * currentZoom;
- Point centerPoint = new Point((cacheRect.Right + cacheRect.Left) / 2, (cacheRect.Bottom + cacheRect.Top) / 2);
- Point moveVector = (Point)(mousePoint - centerPoint);
- moveVector = ProportionalScalingOffsetPos(moveVector);
- switch (hitControlType)
- {
- case PointControlType.LeftTop:
- {
- left = centerPoint.X + moveVector.X;
- right = cacheRect.Right;
- top = centerPoint.Y + moveVector.Y;
- bottom = cacheRect.Bottom;
- if (isProportionalScaling)
- {
- Size size = GetProportionalScalingSize(right - left, bottom - top);
- left = right - size.Width;
- top = bottom - size.Height;
- if (left < maxRect.Left)
- {
- double tmpWidth = right - left;
- left = maxRect.Left;
- double width = right - left;
- double height = (bottom - top) * width / tmpWidth;
- top = bottom - height;
- }
- if (top < maxRect.Top)
- {
- double tmpHeight = bottom - top;
- top = maxRect.Top;
- double height = bottom - top;
- double width = (right - left) * height / tmpHeight;
- left = right - width;
- }
- }
- else
- {
- if (left + minWidth > right)
- {
- left = right - minWidth;
- }
- if (top + minHeight > bottom)
- {
- top = bottom - minHeight;
- }
- }
- }
- break;
- case PointControlType.LeftMiddle:
- {
- left = centerPoint.X + moveVector.X;
- right = cacheRect.Right;
- top = cacheRect.Top;
- bottom = cacheRect.Bottom;
- if (left + minWidth > right)
- {
- left = right - minWidth;
- }
- }
- break;
- case PointControlType.LeftBottom:
- {
- left = centerPoint.X + moveVector.X;
- right = cacheRect.Right;
- top = cacheRect.Top;
- bottom = centerPoint.Y + moveVector.Y;
- if (isProportionalScaling)
- {
- Size size = GetProportionalScalingSize(right - left, bottom - top);
- left = right - size.Width;
- bottom = top + size.Height;
- if (left < maxRect.Left)
- {
- double tmpWidth = right - left;
- left = maxRect.Left;
- double width = right - left;
- double height = (bottom - top) * width / tmpWidth;
- bottom = top + height;
- }
- if (bottom > maxRect.Bottom)
- {
- double tmpHeight = bottom - top;
- bottom = maxRect.Bottom;
- double height = bottom - top;
- double width = (right - left) * height / tmpHeight;
- left = right - width;
- }
- }
- else
- {
- if (left + minWidth > right)
- {
- left = right - minWidth;
- }
- if (top + minHeight > bottom)
- {
- bottom = top + minHeight;
- }
- }
- }
- break;
- case PointControlType.MiddleBottom:
- {
- left = cacheRect.Left;
- right = cacheRect.Right;
- top = cacheRect.Top;
- bottom = centerPoint.Y + moveVector.Y;
- if (top + minHeight > bottom)
- {
- bottom = top + minHeight;
- }
- }
- break;
- case PointControlType.RightBottom:
- {
- left = cacheRect.Left;
- right = centerPoint.X + moveVector.X;
- top = cacheRect.Top;
- bottom = centerPoint.Y + moveVector.Y;
- if (isProportionalScaling)
- {
- Size size = GetProportionalScalingSize(right - left, bottom - top);
- right = left + size.Width;
- bottom = top + size.Height;
- if (right > maxRect.Right)
- {
- double tmpWidth = right - left;
- right = maxRect.Right;
- double width = right - left;
- double height = (bottom - top) * width / tmpWidth;
- bottom = top + height;
- }
- if (bottom > maxRect.Bottom)
- {
- double tmpHeight = bottom - top;
- bottom = maxRect.Bottom;
- double height = bottom - top;
- double width = (right - left) * height / tmpHeight;
- right = left + width;
- }
- }
- else
- {
- if (left + minWidth > right)
- {
- right = left + minWidth;
- }
- if (top + minHeight > bottom)
- {
- bottom = top + minHeight;
- }
- }
- }
- break;
- case PointControlType.RightMiddle:
- {
- left = cacheRect.Left;
- right = centerPoint.X + moveVector.X;
- top = cacheRect.Top;
- bottom = cacheRect.Bottom;
- if (left + minWidth > right)
- {
- right = left + minWidth;
- }
- }
- break;
- case PointControlType.RightTop:
- {
- left = cacheRect.Left;
- right = centerPoint.X + moveVector.X;
- top = centerPoint.Y + moveVector.Y;
- bottom = cacheRect.Bottom;
- if (isProportionalScaling)
- {
- Size size = GetProportionalScalingSize(right - left, bottom - top);
- right = left + size.Width;
- top = bottom - size.Height;
- if (right > maxRect.Right)
- {
- double tmpWidth = right - left;
- right = maxRect.Right;
- double width = right - left;
- double height = (bottom - top) * width / tmpWidth;
- top = bottom - height;
- }
- if (top < maxRect.Top)
- {
- double tmpHeight = bottom - top;
- top = maxRect.Top;
- double height = bottom - top;
- double width = (right - left) * height / tmpHeight;
- right = left + width;
- }
- }
- else
- {
- if (left + minWidth > right)
- {
- right = left + minWidth;
- }
- if (top + minHeight > bottom)
- {
- top = bottom - minHeight;
- }
- }
- }
- break;
- case PointControlType.MiddleTop:
- {
- left = cacheRect.Left;
- right = cacheRect.Right;
- top = centerPoint.Y + moveVector.Y;
- bottom = cacheRect.Bottom;
- if (top + minHeight > bottom)
- {
- top = bottom - minHeight;
- }
- }
- break;
- case PointControlType.Body:
- case PointControlType.Line:
- {
- Point offsetPos = CalcMoveBound(cacheRect, ((Point)(mousePoint - mouseDownPoint)), maxRect);
- left = cacheRect.Left + offsetPos.X;
- right = cacheRect.Right + offsetPos.X;
- top = cacheRect.Top + offsetPos.Y;
- bottom = cacheRect.Bottom + offsetPos.Y;
- }
- break;
- default:
- break;
- }
- if (left < maxRect.Left)
- {
- left = maxRect.Left;
- }
- if (top < maxRect.Top)
- {
- top = maxRect.Top;
- }
- if (right > maxRect.Right)
- {
- right = maxRect.Right;
- }
- if (bottom > maxRect.Bottom)
- {
- bottom = maxRect.Bottom;
- }
- drawRect = new Rect(left, top, right - left, bottom - top);
- moveOffset = new Point(drawRect.X - cacheRect.X, drawRect.Y - cacheRect.Y);
- return true;
- }
- catch (Exception ex)
- {
- }
- return false;
- }
- protected bool RotateScaling(Point mouseMovePoint)
- {
- Point rotatePoint = new Point();
- Point hitControlUIPos = new Point();
- if (hitControlType < PointControlType.Body)
- {
- hitControlUIPos = rotateControlPoints[(int)hitControlType];
- }
- hitControlUIPos = GetRotateUIPoint(hitControlUIPos);
- Point centerPoint = new Point((rotateRect.Left + rotateRect.Right) / 2, (rotateRect.Top + rotateRect.Bottom) / 2);
- Vector moveVector = mouseMovePoint - mouseDownPoint;
- Vector hitVector = hitControlUIPos - centerPoint;
- Rect tmpRect = cacheRect;
- if (hitControlType == PointControlType.LeftTop
- || hitControlType == PointControlType.LeftBottom
- || hitControlType == PointControlType.RightTop
- || hitControlType == PointControlType.RightBottom)
- {
- if (isProportionalScaling)
- {
- double vectorAngle = Vector.AngleBetween(moveVector, hitVector);
- double newLenght = Math.Cos(Math.PI / 180.0 * vectorAngle) * moveVector.Length;
- hitVector.Normalize();
- hitVector.X *= newLenght;
- hitVector.Y *= newLenght;
- rotatePoint = new Point(hitControlUIPos.X + hitVector.X, hitControlUIPos.Y + hitVector.Y);
- }
- }
- switch (hitControlType)
- {
- case PointControlType.LeftTop:
- {
- Point rightBottomPoint = rotateControlPoints[(int)PointControlType.RightBottom];
- Point rightBottomUIPos = GetRotateUIPoint(rightBottomPoint);
- centerPoint = new Point((rotatePoint.X + rightBottomUIPos.X) / 2, (rotatePoint.Y + rightBottomUIPos.Y) / 2);
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.RotateAt(-rotateAngle, centerPoint.X, centerPoint.Y);
- Point leftTopPoint = rotateMatrix.Transform(rotatePoint);
- rightBottomPoint = rotateMatrix.Transform(rightBottomUIPos);
- tmpRect = new Rect(leftTopPoint, rightBottomPoint);
- }
- break;
- case PointControlType.LeftBottom:
- {
- Point rightTopPoint = rotateControlPoints[(int)PointControlType.RightTop];
- Point rightTopUIPos = GetRotateUIPoint(rightTopPoint);
- centerPoint = new Point((rotatePoint.X + rightTopUIPos.X) / 2, (rotatePoint.Y + rightTopUIPos.Y) / 2);
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.RotateAt(-rotateAngle, centerPoint.X, centerPoint.Y);
- Point leftBottomPoint = rotateMatrix.Transform(rotatePoint);
- rightTopPoint = rotateMatrix.Transform(rightTopUIPos);
- tmpRect = new Rect(leftBottomPoint, rightTopPoint);
- }
- break;
- case PointControlType.RightTop:
- {
- Point leftBottomPoint = rotateControlPoints[(int)PointControlType.LeftBottom];
- Point leftBottomUIPos = GetRotateUIPoint(leftBottomPoint);
- centerPoint = new Point((rotatePoint.X + leftBottomUIPos.X) / 2, (rotatePoint.Y + leftBottomUIPos.Y) / 2);
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.RotateAt(-rotateAngle, centerPoint.X, centerPoint.Y);
- Point rightTopPoint = rotateMatrix.Transform(rotatePoint);
- leftBottomPoint = rotateMatrix.Transform(leftBottomUIPos);
- tmpRect = new Rect(leftBottomPoint, rightTopPoint);
- }
- break;
- case PointControlType.RightBottom:
- {
- Point leftTopPoint = rotateControlPoints[(int)PointControlType.LeftTop];
- Point leftTopUIPos = GetRotateUIPoint(leftTopPoint);
- centerPoint = new Point((rotatePoint.X + leftTopUIPos.X) / 2, (rotatePoint.Y + leftTopUIPos.Y) / 2);
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.RotateAt(-rotateAngle, centerPoint.X, centerPoint.Y);
- Point rightBottomPoint = rotateMatrix.Transform(rotatePoint);
- leftTopPoint = rotateMatrix.Transform(leftTopUIPos);
- tmpRect = new Rect(leftTopPoint, rightBottomPoint);
- }
- break;
- case PointControlType.Body:
- case PointControlType.Line:
- {
- Point offsetPos = (Point)(mouseMovePoint - mouseDownPoint);
- double left = cacheRect.Left + offsetPos.X;
- double right = cacheRect.Right + offsetPos.X;
- double top = cacheRect.Top + offsetPos.Y;
- double bottom = cacheRect.Bottom + offsetPos.Y;
- tmpRect = new Rect(new Point(left, top), new Point(right, bottom));
- }
- break;
- default:
- break;
- }
- List<Point> tempPoints = new List<Point>
- {
- new Point(tmpRect.Left, tmpRect.Top),
- new Point(tmpRect.Right, tmpRect.Top),
- new Point(tmpRect.Right, tmpRect.Bottom),
- new Point(tmpRect.Left, tmpRect.Bottom)
- };
- List<Point> boundPoint = new List<Point>();
- Point center = new Point((tmpRect.Left + tmpRect.Right) / 2, (tmpRect.Top + tmpRect.Bottom) / 2);
- foreach (Point point in tempPoints)
- {
- float x = (float)(center.X + (point.X - center.X) * Math.Cos(rotateAngle * Math.PI / 180) - (point.Y - center.Y) * Math.Sin(rotateAngle * Math.PI / 180));
- float y = (float)(center.Y + (point.X - center.X) * Math.Sin(rotateAngle * Math.PI / 180) + (point.Y - center.Y) * Math.Cos(rotateAngle * Math.PI / 180));
- boundPoint.Add(new Point(x, y));
- }
- Rect boundRect = new Rect(new Point(boundPoint.Min(p => p.X), boundPoint.Min(p => p.Y)), new Point(boundPoint.Max(p => p.X), boundPoint.Max(p => p.Y)));
- if (maxRect.Contains(boundRect))
- {
- drawRect = tmpRect;
- }
- else
- {
- if (hitControlType == PointControlType.Body || hitControlType == PointControlType.Line)
- {
- Point boundRectCenterPos = new Point((boundRect.Left + boundRect.Right) / 2, (boundRect.Top + boundRect.Bottom) / 2);
- Point maxRectCenterPos = new Point((maxRect.Left + maxRect.Right) / 2, (maxRect.Top + maxRect.Bottom) / 2);
- Vector moveCenterVector = boundRectCenterPos - maxRectCenterPos;
- Point moveOffsetPos = new Point(0, 0);
- if (Math.Abs(moveCenterVector.X) > (maxRect.Width - boundRect.Width) / 2)
- {
- double moveLength = maxRectCenterPos.X - boundRectCenterPos.X;
- moveOffsetPos.X = Math.Abs(moveLength) - (maxRect.Width - boundRect.Width) / 2;
- if (moveLength < 0)
- {
- moveOffsetPos.X *= -1;
- }
- }
- if (Math.Abs(moveCenterVector.Y) > (maxRect.Height - boundRect.Height) / 2)
- {
- double moveLength = maxRectCenterPos.Y - boundRectCenterPos.Y;
- moveOffsetPos.Y = Math.Abs(moveLength) - (maxRect.Height - boundRect.Height) / 2;
- if (moveLength < 0)
- {
- moveOffsetPos.Y *= -1;
- }
- }
- drawRect = new Rect(tmpRect.Left + moveOffsetPos.X, tmpRect.Top + moveOffsetPos.Y, tmpRect.Width, tmpRect.Height);
- }
- }
- moveOffset = new Point(drawRect.X - cacheRect.X, drawRect.Y - cacheRect.Y);
- return true;
- }
- private Point GetRotateUIPoint(Point point)
- {
- Point centerPoint = new Point((rotateRect.Left + rotateRect.Right) / 2, (rotateRect.Top + rotateRect.Bottom) / 2);
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.RotateAt(rotateAngle, centerPoint.X, centerPoint.Y);
- return rotateMatrix.Transform(point);
- }
- /// <summary>
- /// Provisional logic, to be further improved, not yet used: Draw the algorithm in the form of normal scaling (drag a point, only scale in one direction).
- /// </summary>
- /// <param name="mousePoint">Current mouse position.</param>
- /// <returns></returns>
- protected bool OutSideScaling(Point mousePoint)
- {
- try
- {
- double left = 0, right = 0, top = 0, bottom = 0;
- double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
- double minWidth = RectMinWidth + 2 * rectPadding * currentZoom;
- Point centerPoint = new Point((cacheRect.Right + cacheRect.Left) / 2, (cacheRect.Bottom + cacheRect.Top) / 2);
- Point moveVector = (Point)(mousePoint - centerPoint);
- moveVector = ProportionalScalingOffsetPos(moveVector);
- switch (hitControlType)
- {
- case PointControlType.LeftTop:
- {
- left = centerPoint.X + moveVector.X;
- right = cacheRect.Right;
- top = centerPoint.Y + moveVector.Y;
- bottom = cacheRect.Bottom;
- if (isProportionalScaling)
- {
- Size size = GetProportionalScalingSize(right - left, bottom - top);
- left = right - size.Width;
- top = bottom - size.Height;
- if (left < maxRect.Left)
- {
- double tmpWidth = right - left;
- left = maxRect.Left;
- double width = right - left;
- double height = (bottom - top) * width / tmpWidth;
- top = bottom - height;
- }
- if (top < maxRect.Top)
- {
- double tmpHeight = bottom - top;
- top = maxRect.Top;
- double height = bottom - top;
- double width = (right - left) * height / tmpHeight;
- left = right - width;
- }
- }
- else
- {
- if (left + minWidth > right)
- {
- left = right - minWidth;
- }
- if (top + minHeight > bottom)
- {
- top = bottom - minHeight;
- }
- }
- }
- break;
- case PointControlType.LeftMiddle:
- {
- left = centerPoint.X + moveVector.X;
- right = cacheRect.Right;
- top = cacheRect.Top;
- bottom = cacheRect.Bottom;
- if (left + minWidth > right)
- {
- left = right - minWidth;
- }
- }
- break;
- case PointControlType.LeftBottom:
- {
- left = centerPoint.X + moveVector.X;
- right = cacheRect.Right;
- top = cacheRect.Top;
- bottom = centerPoint.Y + moveVector.Y;
- if (isProportionalScaling)
- {
- Size size = GetProportionalScalingSize(right - left, bottom - top);
- left = right - size.Width;
- bottom = top + size.Height;
- if (left < maxRect.Left)
- {
- double tmpWidth = right - left;
- left = maxRect.Left;
- double width = right - left;
- double height = (bottom - top) * width / tmpWidth;
- bottom = top + height;
- }
- if (bottom > maxRect.Bottom)
- {
- double tmpHeight = bottom - top;
- bottom = maxRect.Bottom;
- double height = bottom - top;
- double width = (right - left) * height / tmpHeight;
- left = right - width;
- }
- }
- else
- {
- if (left + minWidth > right)
- {
- left = right - minWidth;
- }
- if (top + minHeight > bottom)
- {
- bottom = top + minHeight;
- }
- }
- }
- break;
- case PointControlType.MiddleBottom:
- {
- left = cacheRect.Left;
- right = cacheRect.Right;
- top = cacheRect.Top;
- bottom = centerPoint.Y + moveVector.Y;
- if (top + minHeight > bottom)
- {
- bottom = top + minHeight;
- }
- }
- break;
- case PointControlType.RightBottom:
- {
- left = cacheRect.Left;
- right = centerPoint.X + moveVector.X;
- top = cacheRect.Top;
- bottom = centerPoint.Y + moveVector.Y;
- if (isProportionalScaling)
- {
- Size size = GetProportionalScalingSize(right - left, bottom - top);
- right = left + size.Width;
- bottom = top + size.Height;
- if (right > maxRect.Right)
- {
- double tmpWidth = right - left;
- right = maxRect.Right;
- double width = right - left;
- double height = (bottom - top) * width / tmpWidth;
- bottom = top + height;
- }
- if (bottom > maxRect.Bottom)
- {
- double tmpHeight = bottom - top;
- bottom = maxRect.Bottom;
- double height = bottom - top;
- double width = (right - left) * height / tmpHeight;
- right = left + width;
- }
- }
- else
- {
- if (left + minWidth > right)
- {
- right = left + minWidth;
- }
- if (top + minHeight > bottom)
- {
- bottom = top + minHeight;
- }
- }
- }
- break;
- case PointControlType.RightMiddle:
- {
- left = cacheRect.Left;
- right = centerPoint.X + moveVector.X;
- top = cacheRect.Top;
- bottom = cacheRect.Bottom;
- if (left + minWidth > right)
- {
- right = left + minWidth;
- }
- }
- break;
- case PointControlType.RightTop:
- {
- left = cacheRect.Left;
- right = centerPoint.X + moveVector.X;
- top = centerPoint.Y + moveVector.Y;
- bottom = cacheRect.Bottom;
- if (isProportionalScaling)
- {
- Size size = GetProportionalScalingSize(right - left, bottom - top);
- right = left + size.Width;
- top = bottom - size.Height;
- if (right > maxRect.Right)
- {
- double tmpWidth = right - left;
- right = maxRect.Right;
- double width = right - left;
- double height = (bottom - top) * width / tmpWidth;
- top = bottom - height;
- }
- if (top < maxRect.Top)
- {
- double tmpHeight = bottom - top;
- top = maxRect.Top;
- double height = bottom - top;
- double width = (right - left) * height / tmpHeight;
- right = left + width;
- }
- }
- else
- {
- if (left + minWidth > right)
- {
- right = left + minWidth;
- }
- if (top + minHeight > bottom)
- {
- top = bottom - minHeight;
- }
- }
- }
- break;
- case PointControlType.MiddleTop:
- {
- left = cacheRect.Left;
- right = cacheRect.Right;
- top = centerPoint.Y + moveVector.Y;
- bottom = cacheRect.Bottom;
- if (top + minHeight > bottom)
- {
- top = bottom - minHeight;
- }
- }
- break;
- case PointControlType.Body:
- case PointControlType.Line:
- {
- double newleft = maxRect.Left - SetDrawRect.Width + 10;
- double newright = maxRect.Right + SetDrawRect.Width - 10;
- double newtop = maxRect.Top - SetDrawRect.Height + 10;
- double newbottom = maxRect.Bottom + SetDrawRect.Height - 10;
- if (newleft < 0)
- {
- newleft = 0;
- }
- Rect newMaxRect = new Rect(newleft, newtop, newright - newleft, newbottom - newtop);
- Point OffsetPos = CalcMoveBound(cacheRect, ((Point)(mousePoint - mouseDownPoint)), newMaxRect);
- left = cacheRect.Left + OffsetPos.X;
- right = cacheRect.Right + OffsetPos.X;
- top = cacheRect.Top + OffsetPos.Y;
- bottom = cacheRect.Bottom + OffsetPos.Y;
- }
- break;
- default:
- break;
- }
- //if (left < maxRect.Left)
- //{
- // left = maxRect.Left;
- //}
- //if (top < maxRect.Top)
- //{
- // top = maxRect.Top;
- //}
- if (right > maxRect.Right + SetDrawRect.Width - 10)
- {
- if (left > maxRect.Right - 10)
- {
- left = maxRect.Right - 10;
- }
- right = maxRect.Right + SetDrawRect.Width - 10;
- }
- if (bottom > maxRect.Bottom + SetDrawRect.Height - 10)
- {
- if (top > maxRect.Bottom - 10)
- {
- top = maxRect.Bottom - 10;
- }
- bottom = maxRect.Bottom + SetDrawRect.Height - 10;
- }
- drawRect = new Rect(left, top, right - left, bottom - top);
- moveOffset = new Point(drawRect.X - cacheRect.X, drawRect.Y - cacheRect.Y);
- return true;
- }
- catch (Exception ex)
- {
- }
- return false;
- }
- /// <summary>
- /// Proportional scaling offset calibration
- /// </summary>
- /// <param name="movePoint">
- /// The current movement point
- /// </param>
- /// <returns>
- /// The offset point after the proportional scaling
- /// </returns>
- protected Point ProportionalScalingOffsetPos(Point movePoint)
- {
- if (isProportionalScaling)
- {
- Point offsetPos = movePoint;
- double ratioX = cacheRect.Width > 0 ? cacheRect.Height / cacheRect.Width : 1;
- double ratioY = cacheRect.Height > 0 ? cacheRect.Width / cacheRect.Height : 1;
- switch (hitControlType)
- {
- case PointControlType.LeftTop:
- case PointControlType.RightBottom:
- offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? -1 : 1));
- break;
- case PointControlType.LeftBottom:
- case PointControlType.RightTop:
- offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? 1 : -1));
- break;
- case PointControlType.LeftMiddle:
- offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? 1 : -1));
- break;
- case PointControlType.RightMiddle:
- offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? -1 : 1));
- break;
- case PointControlType.MiddleBottom:
- offsetPos = new Point(Math.Abs(movePoint.Y) * ratioY * (movePoint.Y < 0 ? 1 : -1), movePoint.Y);
- break;
- case PointControlType.MiddleTop:
- offsetPos = new Point(Math.Abs(movePoint.Y) * ratioY * (movePoint.Y < 0 ? -1 : 1), movePoint.Y);
- break;
- default:
- break;
- }
- return offsetPos;
- }
- else
- {
- return movePoint;
- }
- }
- /// <summary>
- /// Inner drawing circle point
- /// </summary>
- /// <param name="drawingContext">
- /// Drawing context
- /// </param>
- /// <param name="ignoreList">
- /// Collection of positions that need to be drawn
- /// </param>
- /// <param name="PointSize">
- /// Size of the point
- /// </param>
- /// <param name="PointPen">
- /// Brush for drawing points
- /// </param>
- /// <param name="BorderBrush">
- /// Border brush for drawing points
- /// </param>
- protected void DrawCirclePoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
- {
- GeometryGroup controlGroup = new GeometryGroup();
- controlGroup.FillRule = FillRule.Nonzero;
- List<Point> ignorePointsList = new List<Point>();
- // Get specific points
- foreach (PointControlType type in ignoreList)
- {
- if ((int)type < controlPoints.Count)
- {
- ignorePointsList.Add(controlPoints[(int)type]);
- }
- }
- for (int i = 0; i < controlPoints.Count; i++)
- {
- Point controlPoint = controlPoints[i];
- if (ignorePointsList.Contains(controlPoint))
- {
- continue;
- }
- EllipseGeometry circlPoint = new EllipseGeometry(controlPoint, PointSize, PointSize);
- controlGroup.Children.Add(circlPoint);
- }
- drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
- }
- /// <summary>
- /// Inner drawing square
- /// </summary>
- /// <param name="drawingContext">
- /// Drawing context
- /// </param>
- /// <param name="ControlPoints">
- /// Collection of positions that need to be drawn
- /// </param>
- /// <param name="PointSize">
- /// Size of the point
- /// </param>
- /// <param name="PointPen">
- /// Brush for drawing points
- /// </param>
- /// <param name="BorderBrush">
- /// Border brush for drawing points
- /// </param>
- protected void DrawSquarePoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
- {
- RotateTransform rotateTransform = new RotateTransform(rotateAngle, centerPoint.X, centerPoint.Y);
- if (canRotate && !isInScaling)
- {
- Point currentRotationPoint = isInRotate ? dragRotationPoint : rotationPoint;
- double angleInRadians = rotateAngle * (Math.PI / 180);
- double sinValue = Math.Sin(angleInRadians);
- double cosValue = Math.Cos(angleInRadians);
- double rotatedX = 0;
- double rotatedY = 0;
- switch (pageRotation)
- {
- case 0:
- rotatedX = currentRotationPoint.X - pointSize * sinValue;
- rotatedY = currentRotationPoint.Y + pointSize * cosValue;
- break;
- case 1:
- rotatedX = currentRotationPoint.X - pointSize * cosValue;
- rotatedY = currentRotationPoint.Y + pointSize * sinValue;
- break;
- case 2:
- rotatedX = currentRotationPoint.X + pointSize * sinValue;
- rotatedY = currentRotationPoint.Y - pointSize * cosValue;
- break;
- case 3:
- rotatedX = currentRotationPoint.X + pointSize * sinValue;
- rotatedY = currentRotationPoint.Y - pointSize * cosValue;
- break;
- default:
- break;
- }
- GeometryGroup rotateGroup = new GeometryGroup();
- LineGeometry moveLineGeometry = new LineGeometry(centerPoint, new Point(rotatedX, rotatedY));
- EllipseGeometry ellipseGeometry = new EllipseGeometry(currentRotationPoint, PointSize, pointSize);
- rotateGroup.Children.Add(moveLineGeometry);
- rotateGroup.Children.Add(ellipseGeometry);
- if (!isInRotate)
- {
- rotateGroup.Children.Remove(moveLineGeometry);
- LineGeometry stopLineGeometry = new LineGeometry(centerPoint, new Point(currentRotationPoint.X, currentRotationPoint.Y + pointSize));
- switch (pageRotation)
- {
- case 0:
- stopLineGeometry = new LineGeometry(centerPoint, new Point(currentRotationPoint.X, currentRotationPoint.Y + pointSize));
- break;
- case 1:
- stopLineGeometry = new LineGeometry(centerPoint, new Point(currentRotationPoint.X - pointSize, currentRotationPoint.Y));
- break;
- case 2:
- stopLineGeometry = new LineGeometry(centerPoint, new Point(currentRotationPoint.X, currentRotationPoint.Y - pointSize));
- break;
- case 3:
- stopLineGeometry = new LineGeometry(centerPoint, new Point(currentRotationPoint.X + pointSize, currentRotationPoint.Y));
- break;
- default:
- break;
- }
- rotateGroup.Children.Add(stopLineGeometry);
- drawingContext.PushTransform(rotateTransform);
- }
- drawingContext?.DrawGeometry(BorderBrush, PointPen, rotateGroup);
- if (!isInRotate)
- {
- drawingContext.Pop();
- }
- }
- if (!isInRotate)
- {
- GeometryGroup controlGroup = new GeometryGroup();
- controlGroup.FillRule = FillRule.Nonzero;
- List<Point> ignorePointsList = new List<Point>();
- // Get specific points
- foreach (PointControlType type in ignoreList)
- {
- if ((int)type < controlPoints.Count)
- {
- ignorePointsList.Add(controlPoints[(int)type]);
- }
- }
- for (int i = 0; i < controlPoints.Count; i++)
- {
- Point controlPoint = controlPoints[i];
- if (ignorePointsList.Contains(controlPoint))
- {
- continue;
- }
- RectangleGeometry rectPoint = new RectangleGeometry(new Rect(controlPoint.X - PointSize, controlPoint.Y - PointSize,
- PointSize * 2, PointSize * 2), 1, 1);
- controlGroup.Children.Add(rectPoint);
- }
- drawingContext.PushTransform(rotateTransform);
- drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
- drawingContext.Pop();
- }
- }
- protected void DrawCropPoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
- {
- //GeometryGroup controlGroup = new GeometryGroup();
- //controlGroup.FillRule = FillRule.Nonzero;
- clipThickness.Left = (SetDrawRect.Left - drawRect.Left) / currentZoom;
- clipThickness.Top = (SetDrawRect.Top - drawRect.Top) / currentZoom;
- clipThickness.Right = (SetDrawRect.Right - drawRect.Right) / currentZoom;
- clipThickness.Bottom = (SetDrawRect.Bottom - drawRect.Bottom) / currentZoom;
- List<Point> controlCurrentPoints = GetControlPoint(drawRect);
- CombinedGeometry controlGroup = new CombinedGeometry();
- RectangleGeometry paintGeometry = new RectangleGeometry();
- paintGeometry.Rect = SetDrawRect;
- controlGroup.Geometry1 = paintGeometry;
- RectangleGeometry moveGeometry = new RectangleGeometry();
- Rect clippedBorder = drawRect;
- if (clippedBorder.IsEmpty == false)
- {
- moveGeometry.Rect = drawRect;
- }
- controlGroup.Geometry2 = moveGeometry;
- controlGroup.GeometryCombineMode = GeometryCombineMode.Exclude;
- //Left Top Corner
- if (!ignoreList.Contains(PointControlType.LeftTop))
- {
- drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[0].X - PointSize, controlCurrentPoints[0].Y - PointSize, PointSize, PointSize * 4));
- drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[0].X - PointSize, controlCurrentPoints[0].Y - PointSize, PointSize * 4, PointSize));
- }
- //Left Center
- if (!ignoreList.Contains(PointControlType.LeftMiddle))
- {
- drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[1].X - PointSize, (controlCurrentPoints[1].Y + controlCurrentPoints[1].Y - PointSize * 5) / 2, PointSize, PointSize * 5));
- }
- //Left Bottom Corner
- if (!ignoreList.Contains(PointControlType.LeftBottom))
- {
- drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[2].X - PointSize, controlCurrentPoints[2].Y - PointSize * 3, PointSize, PointSize * 4));
- drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[2].X - PointSize, controlCurrentPoints[2].Y, PointSize * 4, PointSize));
- }
- //Bottom Center
- if (!ignoreList.Contains(PointControlType.MiddleBottom))
- {
- drawingContext?.DrawRectangle(BorderBrush, null, new Rect((controlCurrentPoints[3].X + controlCurrentPoints[3].X - PointSize * 5) / 2, controlCurrentPoints[3].Y, PointSize * 5, PointSize));
- }
- //Bottom Right Corner
- if (!ignoreList.Contains(PointControlType.RightBottom))
- {
- drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[4].X, controlCurrentPoints[4].Y - PointSize * 3, PointSize, PointSize * 4));
- drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[4].X - PointSize * 3, controlCurrentPoints[4].Y, PointSize * 4, PointSize));
- }
- //Right Center
- if (!ignoreList.Contains(PointControlType.RightMiddle))
- {
- drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[5].X, (controlCurrentPoints[5].Y + controlCurrentPoints[5].Y - PointSize * 5) / 2, PointSize, PointSize * 5));
- }
- //Right Top Corner
- if (!ignoreList.Contains(PointControlType.RightTop))
- {
- drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[6].X, controlCurrentPoints[6].Y - PointSize, PointSize, PointSize * 4));
- drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[6].X - PointSize * 4, controlCurrentPoints[6].Y - PointSize, PointSize * 4, PointSize));
- }
- //Top Center
- if (!ignoreList.Contains(PointControlType.MiddleTop))
- {
- drawingContext?.DrawRectangle(BorderBrush, null, new Rect((controlCurrentPoints[7].X + controlCurrentPoints[7].X - PointSize * 5) / 2, controlCurrentPoints[7].Y - PointSize, PointSize * 5, PointSize));
- }
- BorderBrush = new SolidColorBrush(Color.FromArgb(0x3F, 0x00, 0x00, 0x00));
- drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
- }
- /// <summary>
- /// Draw the reference line in the moving state
- /// </summary>
- /// <param name="drawDc">
- /// Draw context handle
- /// </param>
- /// <param name="controltype">
- /// Current selected control point type
- /// </param>
- /// <param name="activePen">
- /// Brush for drawing lines
- /// </param>
- /// <param name="moveBrush">
- /// Brush for drawing rectangles
- /// </param>
- /// <param name="moveRect">
- /// Current rectangle to draw
- /// </param>
- protected void DrawMoveBounds(DrawingContext drawDc, PointControlType controltype, Pen activePen, Brush moveBrush, Rect moveRect, Pen RectPen = null)
- {
- switch (controltype)
- {
- case PointControlType.LeftTop:
- drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
- drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
- break;
- case PointControlType.LeftMiddle:
- drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
- break;
- case PointControlType.LeftBottom:
- drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
- drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
- break;
- case PointControlType.MiddleBottom:
- drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
- break;
- case PointControlType.RightBottom:
- drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
- drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
- break;
- case PointControlType.RightMiddle:
- drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
- break;
- case PointControlType.RightTop:
- drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
- drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
- break;
- case PointControlType.MiddleTop:
- drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
- break;
- case PointControlType.Rotate:
- drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(moveRect.Left, moveRect.Top));
- drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
- drawDc?.DrawLine(activePen, new Point(moveRect.Left, moveRect.Top), new Point(moveRect.Left, 0));
- drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Top), new Point(moveRect.Right, 0));
- drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(moveRect.Left, moveRect.Bottom));
- drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
- drawDc?.DrawLine(activePen, new Point(moveRect.Left, moveRect.Bottom), new Point(moveRect.Left, PDFViewerActualHeight));
- drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Bottom), new Point(moveRect.Right, PDFViewerActualHeight));
- break;
- case PointControlType.Body:
- case PointControlType.Line:
- drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(moveRect.Left, moveRect.Top));
- drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
- drawDc?.DrawLine(activePen, new Point(moveRect.Left, moveRect.Top), new Point(moveRect.Left, 0));
- drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Top), new Point(moveRect.Right, 0));
- drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(moveRect.Left, moveRect.Bottom));
- drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
- drawDc?.DrawLine(activePen, new Point(moveRect.Left, moveRect.Bottom), new Point(moveRect.Left, PDFViewerActualHeight));
- drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Bottom), new Point(moveRect.Right, PDFViewerActualHeight));
- break;
- default:
- break;
- }
- drawDc?.DrawRectangle(moveBrush, RectPen, moveRect);
- }
- /// <summary>
- /// Notify the event during/after the drawing data
- /// </summary>
- /// <param name="isFinish">
- /// Identifies whether the data change is complete
- /// </param>
- protected void InvokeDataChangEvent(bool isFinish)
- {
- selectedRectData.Square = GetRect();
- selectedRectData.rotationAngle = rotateAngle;
- if (isFinish)
- {
- DataChanged?.Invoke(this, selectedRectData);
- }
- else
- {
- DataChanging?.Invoke(this, selectedRectData);
- }
- }
- /// <summary>
- /// Align the rectangle drawing
- /// </summary>
- /// <param name="RectMovePoint">
- /// Move distance required for the aligned algorithm to obtain the rectangle
- /// </param>
- private void DrawAlignRect(Point RectMovePoint)
- {
- double TmpLeft, TmpRight, TmpUp, TmpDown;
- Point OffsetPos = CalcMoveBound(drawRect, RectMovePoint, maxRect);
- TmpLeft = drawRect.Left + OffsetPos.X;
- TmpRight = drawRect.Right + OffsetPos.X;
- TmpUp = drawRect.Top + OffsetPos.Y;
- TmpDown = drawRect.Bottom + OffsetPos.Y;
- SetDrawRect = drawRect = new Rect(TmpLeft, TmpUp, TmpRight - TmpLeft, TmpDown - TmpUp);
- Draw();
- }
- /// <summary>
- /// Get the current set of ignore points
- /// </summary>
- /// <returns>
- /// Data set of ignored points
- /// </returns>
- private List<PointControlType> GetIgnorePoints()
- {
- List<PointControlType> IgnorePointsList = new List<PointControlType>();
- foreach (PointControlType type in ignorePoints)
- {
- IgnorePointsList.Add(type);
- }
- return IgnorePointsList;
- }
- #endregion
- }
- }
|