I’m having some issues with resizing a node (while maintaining aspect ratio) after rotating the node.
The resizing code I have that is working when the RotationAngle is 0:
protected override void DoResize(Rect newr){
double widthChange = newr.Width - this.AdornedNode.ActualWidth;
double heightChange = newr.Height - this.AdornedNode.ActualHeight;
double width;
double height;
if (heightChange > widthChange)
{
<span ="Apple-tab-span" style="white-space:pre"> </span>width = (newr.Height * this.AdornedNode.ActualWidth) / this.AdornedNode.ActualHeight;
<span ="Apple-tab-span" style="white-space:pre"> </span>width = Math.Round(width, 0);
<span ="Apple-tab-span" style="white-space:pre"> </span>height = newr.Height;
}
else
{
<span ="Apple-tab-span" style="white-space:pre"> </span>width = newr.Width;
<span ="Apple-tab-span" style="white-space:pre"> </span> height = (newr.Width * this.AdornedNode.ActualHeight) / this.AdornedNode.ActualWidth;
<span ="Apple-tab-span" style="white-space:pre"> </span>height = Math.Round(height, 0);
}
Point topLeft;
double left = this.AdornedNode.Location.X - (this.AdornedNode.ActualWidth / 2);
double right = this.AdornedNode.Location.X + (this.AdornedNode.ActualWidth / 2);
double top = this.AdornedNode.Location.Y - (this.AdornedNode.ActualHeight / 2);
double bottom = this.AdornedNode.Location.Y + (this.AdornedNode.ActualHeight / 2);
switch (this.ResizingAnchor)
{
<span ="Apple-tab-span" style="white-space:pre"> </span>case "TopLeft":
<span ="Apple-tab-span" style="white-space:pre"> </span>topLeft = new Point((right - width), (bottom - height));
<span ="Apple-tab-span" style="white-space:pre"> </span>break;
<span ="Apple-tab-span" style="white-space:pre"> </span>case "TopRight":
<span ="Apple-tab-span" style="white-space:pre"> </span> topLeft = new Point(left, (bottom - height));
<span ="Apple-tab-span" style="white-space:pre"> </span>break;
<span ="Apple-tab-span" style="white-space:pre"> </span>case "BottomLeft":
<span ="Apple-tab-span" style="white-space:pre"> </span>topLeft = new Point((right - width), top);
<span ="Apple-tab-span" style="white-space:pre"> </span>break;
<span ="Apple-tab-span" style="white-space:pre"> </span>default:
<span ="Apple-tab-span" style="white-space:pre"> </span>topLeft = newr.Location;
<span ="Apple-tab-span" style="white-space:pre"> </span>break;
}
newr = new Rect(topLeft.X, topLeft.Y, width, height);
base.DoResize(newr);
}
I’m having trouble wrapping my head around how the resizing is working with rotated nodes and was hoping to get steered in the right direction.
Thanks
Ryan