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