improve:墨迹选择
This commit is contained in:
@@ -875,48 +875,55 @@ namespace Ink_Canvas
|
|||||||
private Rect CalculateNewBounds(Rect originalBounds, Point delta, string handleName)
|
private Rect CalculateNewBounds(Rect originalBounds, Point delta, string handleName)
|
||||||
{
|
{
|
||||||
var newBounds = originalBounds;
|
var newBounds = originalBounds;
|
||||||
|
double newWidth = originalBounds.Width;
|
||||||
|
double newHeight = originalBounds.Height;
|
||||||
|
double newX = originalBounds.X;
|
||||||
|
double newY = originalBounds.Y;
|
||||||
|
|
||||||
switch (handleName)
|
switch (handleName)
|
||||||
{
|
{
|
||||||
case "TopLeftHandle":
|
case "TopLeftHandle":
|
||||||
newBounds.X = originalBounds.X + delta.X;
|
newX = originalBounds.X + delta.X;
|
||||||
newBounds.Y = originalBounds.Y + delta.Y;
|
newY = originalBounds.Y + delta.Y;
|
||||||
newBounds.Width = originalBounds.Width - delta.X;
|
newWidth = originalBounds.Width - delta.X;
|
||||||
newBounds.Height = originalBounds.Height - delta.Y;
|
newHeight = originalBounds.Height - delta.Y;
|
||||||
break;
|
break;
|
||||||
case "TopRightHandle":
|
case "TopRightHandle":
|
||||||
newBounds.Y = originalBounds.Y + delta.Y;
|
newY = originalBounds.Y + delta.Y;
|
||||||
newBounds.Width = originalBounds.Width + delta.X;
|
newWidth = originalBounds.Width + delta.X;
|
||||||
newBounds.Height = originalBounds.Height - delta.Y;
|
newHeight = originalBounds.Height - delta.Y;
|
||||||
break;
|
break;
|
||||||
case "BottomLeftHandle":
|
case "BottomLeftHandle":
|
||||||
newBounds.X = originalBounds.X + delta.X;
|
newX = originalBounds.X + delta.X;
|
||||||
newBounds.Width = originalBounds.Width - delta.X;
|
newWidth = originalBounds.Width - delta.X;
|
||||||
newBounds.Height = originalBounds.Height + delta.Y;
|
newHeight = originalBounds.Height + delta.Y;
|
||||||
break;
|
break;
|
||||||
case "BottomRightHandle":
|
case "BottomRightHandle":
|
||||||
newBounds.Width = originalBounds.Width + delta.X;
|
newWidth = originalBounds.Width + delta.X;
|
||||||
newBounds.Height = originalBounds.Height + delta.Y;
|
newHeight = originalBounds.Height + delta.Y;
|
||||||
break;
|
break;
|
||||||
case "TopHandle":
|
case "TopHandle":
|
||||||
newBounds.Y = originalBounds.Y + delta.Y;
|
newY = originalBounds.Y + delta.Y;
|
||||||
newBounds.Height = originalBounds.Height - delta.Y;
|
newHeight = originalBounds.Height - delta.Y;
|
||||||
break;
|
break;
|
||||||
case "BottomHandle":
|
case "BottomHandle":
|
||||||
newBounds.Height = originalBounds.Height + delta.Y;
|
newHeight = originalBounds.Height + delta.Y;
|
||||||
break;
|
break;
|
||||||
case "LeftHandle":
|
case "LeftHandle":
|
||||||
newBounds.X = originalBounds.X + delta.X;
|
newX = originalBounds.X + delta.X;
|
||||||
newBounds.Width = originalBounds.Width - delta.X;
|
newWidth = originalBounds.Width - delta.X;
|
||||||
break;
|
break;
|
||||||
case "RightHandle":
|
case "RightHandle":
|
||||||
newBounds.Width = originalBounds.Width + delta.X;
|
newWidth = originalBounds.Width + delta.X;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确保最小尺寸
|
// 确保最小尺寸和正值
|
||||||
if (newBounds.Width < 10) newBounds.Width = 10;
|
if (newWidth < 10) newWidth = 10;
|
||||||
if (newBounds.Height < 10) newBounds.Height = 10;
|
if (newHeight < 10) newHeight = 10;
|
||||||
|
|
||||||
|
// 创建新的Rect,确保所有值都是有效的
|
||||||
|
newBounds = new Rect(newX, newY, newWidth, newHeight);
|
||||||
|
|
||||||
return newBounds;
|
return newBounds;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user