|
@@ -1,5 +1,6 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Media;
|
|
|
|
|
@@ -8,7 +9,6 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
public partial class SelectedRect
|
|
|
{
|
|
|
#region Properties
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// Current control point drawing style.
|
|
|
/// </summary>
|
|
@@ -18,7 +18,6 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
set;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// Current drag drawing style.
|
|
|
/// </summary>
|
|
@@ -180,7 +179,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
controlPoints.Add(new Point(currentRect.Right, currentRect.Top));
|
|
|
controlPoints.Add(new Point(centerPoint.X, currentRect.Top));
|
|
|
|
|
|
- if (canRotation)
|
|
|
+ if (canRotate)
|
|
|
{
|
|
|
rotationPoint = new Point(centerPoint.X, currentRect.Top - 30);
|
|
|
}
|
|
@@ -274,7 +273,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
|
|
|
if (!isOutSideScaling)
|
|
|
{
|
|
|
- if (selectedRectData.rotationAngle != 0 && (hitControlType >= PointControlType.LeftTop && hitControlType <= PointControlType.MiddleTop))
|
|
|
+ if (selectedRectData.rotationAngle != 0)
|
|
|
{
|
|
|
return RotateScaling(mousePoint);
|
|
|
}
|
|
@@ -321,7 +320,6 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
Vector moveVector = (mousePoint - centerPoint);
|
|
|
|
|
|
rotateAngle = (int)(Math.Atan2(moveVector.X, -moveVector.Y) * 180 / Math.PI);
|
|
|
-
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -575,11 +573,11 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
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;
|
|
|
+ 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;
|
|
|
|
|
@@ -624,8 +622,6 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
if (hitControlType < PointControlType.Body)
|
|
|
{
|
|
|
hitControlUIPos = rotateControlPoints[(int)hitControlType];
|
|
|
- //Debug.WriteLine(hitControlUIPos.ToString());
|
|
|
- //Debug.WriteLine(rotateRect.ToString());
|
|
|
}
|
|
|
|
|
|
hitControlUIPos = GetRotateUIPoint(hitControlUIPos);
|
|
@@ -633,6 +629,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
Vector moveVector = mouseMovePoint - mouseDownPoint;
|
|
|
Vector hitVector = hitControlUIPos - centerPoint;
|
|
|
|
|
|
+ Rect tmpRect = cacheRect;
|
|
|
if (hitControlType == PointControlType.LeftTop
|
|
|
|| hitControlType == PointControlType.LeftBottom
|
|
|
|| hitControlType == PointControlType.RightTop
|
|
@@ -663,7 +660,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
|
|
|
Point leftTopPoint = rotateMatrix.Transform(rotatePoint);
|
|
|
rightBottomPoint = rotateMatrix.Transform(rightBottomUIPos);
|
|
|
- drawRect = new Rect(leftTopPoint, rightBottomPoint);
|
|
|
+ tmpRect = new Rect(leftTopPoint, rightBottomPoint);
|
|
|
}
|
|
|
break;
|
|
|
|
|
@@ -678,7 +675,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
|
|
|
Point leftBottomPoint = rotateMatrix.Transform(rotatePoint);
|
|
|
rightTopPoint = rotateMatrix.Transform(rightTopUIPos);
|
|
|
- drawRect = new Rect(leftBottomPoint, rightTopPoint);
|
|
|
+ tmpRect = new Rect(leftBottomPoint, rightTopPoint);
|
|
|
}
|
|
|
break;
|
|
|
|
|
@@ -693,8 +690,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
|
|
|
Point rightTopPoint = rotateMatrix.Transform(rotatePoint);
|
|
|
leftBottomPoint = rotateMatrix.Transform(leftBottomUIPos);
|
|
|
-
|
|
|
- drawRect = new Rect(leftBottomPoint, rightTopPoint);
|
|
|
+ tmpRect = new Rect(leftBottomPoint, rightTopPoint);
|
|
|
}
|
|
|
break;
|
|
|
|
|
@@ -709,8 +705,19 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
|
|
|
Point rightBottomPoint = rotateMatrix.Transform(rotatePoint);
|
|
|
leftTopPoint = rotateMatrix.Transform(leftTopUIPos);
|
|
|
+ tmpRect = new Rect(leftTopPoint, rightBottomPoint);
|
|
|
+ }
|
|
|
+ break;
|
|
|
|
|
|
- drawRect = new Rect(leftTopPoint, rightBottomPoint);
|
|
|
+ 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;
|
|
|
|
|
@@ -718,6 +725,60 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
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;
|
|
|
}
|
|
@@ -1156,17 +1217,16 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
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)
|
|
|
+ if (canRotate && !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;
|
|
|
|
|
|
+ GeometryGroup rotateGroup = new GeometryGroup();
|
|
|
LineGeometry moveLineGeometry = new LineGeometry(centerPoint, new Point(rotatedX, rotatedY));
|
|
|
EllipseGeometry ellipseGeometry = new EllipseGeometry(currentRotationPoint, PointSize, pointSize);
|
|
|
rotateGroup.Children.Add(moveLineGeometry);
|