|
@@ -1,6 +1,5 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
-using System.Linq;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Media;
|
|
|
|
|
@@ -152,6 +151,9 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
|
|
|
protected bool disable = false;
|
|
|
|
|
|
+ protected List<Point> rotateControlPoints = new List<Point>();
|
|
|
+
|
|
|
+ protected Rect rotateRect = new Rect();
|
|
|
|
|
|
#endregion
|
|
|
|
|
@@ -272,7 +274,14 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
|
|
|
if (!isOutSideScaling)
|
|
|
{
|
|
|
- return NormalScaling(mousePoint);
|
|
|
+ if (selectedRectData.rotationAngle != 0 && (hitControlType >= PointControlType.LeftTop && hitControlType <= PointControlType.MiddleTop))
|
|
|
+ {
|
|
|
+ return RotateScaling(mousePoint);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return NormalScaling(mousePoint);
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -608,6 +617,119 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
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>
|