|
@@ -1,6 +1,8 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Diagnostics;
|
|
|
using System.Windows;
|
|
|
+using System.Windows.Input;
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
namespace ComPDFKit.Tool.DrawTool
|
|
@@ -27,7 +29,11 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
/// <summary>
|
|
|
/// Current click hit control point.
|
|
|
/// </summary>
|
|
|
- protected PointControlType hitControlType { get; set; }
|
|
|
+ protected PointControlType hitControlType
|
|
|
+ {
|
|
|
+ get;
|
|
|
+ set;
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// Mouse down position information.
|
|
@@ -39,6 +45,10 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
/// </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>
|
|
@@ -94,6 +104,12 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
/// </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>
|
|
@@ -119,6 +135,8 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
|
|
|
protected double PDFViewerActualHeight { get; set; } = 0;
|
|
|
|
|
|
+ protected double rotateAngle { get; set; } = 0;
|
|
|
+
|
|
|
protected double rectPadding = 6;
|
|
|
|
|
|
protected double currentZoom = 1;
|
|
@@ -127,6 +145,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
|
|
|
protected bool disable = false;
|
|
|
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region Functions
|
|
@@ -140,17 +159,22 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
protected void CalcControlPoint(Rect currentRect)
|
|
|
{
|
|
|
controlPoints.Clear();
|
|
|
- int centerX = (int)(currentRect.Left + currentRect.Right) / 2;
|
|
|
- int centerY = (int)(currentRect.Top + currentRect.Bottom) / 2;
|
|
|
+ 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, centerY));
|
|
|
+ controlPoints.Add(new Point(currentRect.Left, centerPoint.Y));
|
|
|
controlPoints.Add(new Point(currentRect.Left, currentRect.Bottom));
|
|
|
- controlPoints.Add(new Point(centerX, currentRect.Bottom));
|
|
|
+ controlPoints.Add(new Point(centerPoint.X, currentRect.Bottom));
|
|
|
controlPoints.Add(new Point(currentRect.Right, currentRect.Bottom));
|
|
|
- controlPoints.Add(new Point(currentRect.Right, centerY));
|
|
|
+ controlPoints.Add(new Point(currentRect.Right, centerPoint.Y));
|
|
|
controlPoints.Add(new Point(currentRect.Right, currentRect.Top));
|
|
|
- controlPoints.Add(new Point(centerX, 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)
|
|
@@ -234,6 +258,11 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
+ if (hitControlType == PointControlType.Rotate)
|
|
|
+ {
|
|
|
+ return SetRotate(mousePoint);
|
|
|
+ }
|
|
|
+
|
|
|
if (!isOutSideScaling)
|
|
|
{
|
|
|
return NormalScaling(mousePoint);
|
|
@@ -270,6 +299,15 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
|
|
|
return new Size(width, height);
|
|
|
}
|
|
|
+ private bool SetRotate(Point mousePoint)
|
|
|
+ {
|
|
|
+ dragRotationPoint = mousePoint;
|
|
|
+ Vector moveVector = (mousePoint - centerPoint);
|
|
|
+
|
|
|
+ rotateAngle = 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).
|
|
@@ -391,7 +429,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
- case PointControlType.MiddlBottom:
|
|
|
+ case PointControlType.MiddleBottom:
|
|
|
{
|
|
|
left = cacheRect.Left;
|
|
|
right = cacheRect.Right;
|
|
@@ -683,7 +721,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
- case PointControlType.MiddlBottom:
|
|
|
+ case PointControlType.MiddleBottom:
|
|
|
{
|
|
|
left = cacheRect.Left;
|
|
|
right = cacheRect.Right;
|
|
@@ -905,7 +943,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
case PointControlType.RightMiddle:
|
|
|
offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? -1 : 1));
|
|
|
break;
|
|
|
- case PointControlType.MiddlBottom:
|
|
|
+ case PointControlType.MiddleBottom:
|
|
|
offsetPos = new Point(Math.Abs(movePoint.Y) * ratioY * (movePoint.Y < 0 ? 1 : -1), movePoint.Y);
|
|
|
break;
|
|
|
case PointControlType.MiddleTop:
|
|
@@ -988,36 +1026,82 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
/// </param>
|
|
|
protected void DrawSquarePoint(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)
|
|
|
+
|
|
|
+ RotateTransform rotateTransform = new RotateTransform(rotateAngle, centerPoint.X, centerPoint.Y);
|
|
|
+ if (canRotation && !isInScaling)
|
|
|
{
|
|
|
- if ((int)type < controlPoints.Count)
|
|
|
+ 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)
|
|
|
{
|
|
|
- ignorePointsList.Add(controlPoints[(int)type]);
|
|
|
+ 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();
|
|
|
}
|
|
|
}
|
|
|
- for (int i = 0; i < controlPoints.Count; i++)
|
|
|
+ if (!isInRotate)
|
|
|
{
|
|
|
- Point controlPoint = controlPoints[i];
|
|
|
- if (ignorePointsList.Contains(controlPoint))
|
|
|
+ GeometryGroup controlGroup = new GeometryGroup();
|
|
|
+ controlGroup.FillRule = FillRule.Nonzero;
|
|
|
+ List<Point> ignorePointsList = new List<Point>();
|
|
|
+ // Get specific points
|
|
|
+ foreach (PointControlType type in ignoreList)
|
|
|
{
|
|
|
- continue;
|
|
|
+ if ((int)type < controlPoints.Count)
|
|
|
+ {
|
|
|
+ ignorePointsList.Add(controlPoints[(int)type]);
|
|
|
+ }
|
|
|
}
|
|
|
- RectangleGeometry rectPoint = new RectangleGeometry(new Rect(controlPoint.X - PointSize, controlPoint.Y - PointSize,
|
|
|
- PointSize * 2, PointSize * 2), 1, 1);
|
|
|
- controlGroup.Children.Add(rectPoint);
|
|
|
+ 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();
|
|
|
}
|
|
|
- drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
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.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;
|
|
@@ -1055,7 +1139,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
}
|
|
|
|
|
|
//Bottom Center
|
|
|
- if (!ignoreList.Contains(PointControlType.MiddlBottom))
|
|
|
+ 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));
|
|
|
}
|
|
@@ -1122,7 +1206,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
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.MiddlBottom:
|
|
|
+ case PointControlType.MiddleBottom:
|
|
|
drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
|
|
|
break;
|
|
|
case PointControlType.RightBottom:
|
|
@@ -1140,6 +1224,15 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
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:
|