12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433 |
- using System;
- using System.Collections.Generic;
- 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 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();
- #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 (canRotation)
- {
- rotationPoint = new Point(centerPoint.X, currentRect.Top - 30);
- }
- }
- 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)
- {
- return SetRotateByMousePoint(mousePoint);
- }
- if (!isOutSideScaling)
- {
- if (selectedRectData.rotationAngle != 0 && (hitControlType >= PointControlType.LeftTop && hitControlType <= PointControlType.MiddleTop))
- {
- 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 bool SetRotateByMousePoint(Point mousePoint)
- {
- dragRotationPoint = mousePoint;
- Vector moveVector = (mousePoint - centerPoint);
- rotateAngle = (int)(Math.Atan2(moveVector.X, -moveVector.Y) * 180 / Math.PI);
- return false;
- }
- /// <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];
- //Debug.WriteLine(hitControlUIPos.ToString());
- //Debug.WriteLine(rotateRect.ToString());
- }
- 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;
- 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);
- drawRect = 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);
- drawRect = 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);
- drawRect = 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);
- drawRect = new Rect(leftTopPoint, rightBottomPoint);
- }
- break;
- default:
- break;
- }
- 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 (canRotation && !isInScaling)
- {
- Point currentRotationPoint = isInRotate ? dragRotationPoint : rotationPoint;
- GeometryGroup rotateGroup = new GeometryGroup();
- double angleInRadians = rotateAngle * (Math.PI / 180);
- double sinValue = Math.Sin(angleInRadians);
- double cosValue = Math.Cos(angleInRadians);
- double rotatedX = currentRotationPoint.X - pointSize * sinValue;
- double rotatedY = currentRotationPoint.Y + pointSize * cosValue;
- 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));
- 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
- }
- }
|