The MindFusion Forums
Flow Diagramming Components >> WPF >> Resize rotated nodes
https://mindfusion.eu/Forum/YaBB.pl?num=1495025764

Message started by Kris on May 17th, 2017 at 12:56pm

Title: Resize rotated nodes
Post by Kris on May 17th, 2017 at 12:56pm
Hi,

I'm trying to resize rotated node, not via resize handles but just changing the node Size (DiagramAdapterNode.Resize(w,h)

the problem is that when node is rotated the locations is changing not in proper way - i.e when node is rotated 45deg, and when resizing via right bottom handle - the left top position is kept, but when I resize the node via Resize method the location is moved. How to achieve the same behavior when resizing node the same as when resizing via resize handles ?

Regards,
K

Title: Re: Resize rotated nodes
Post by Slavcho on May 17th, 2017 at 7:10pm
Hi,

Try this method -
[code]
void Resize(DiagramNode node, double width, double height)
{
     var topLeft = new Point(0, 0);
     topLeft = node.TransformItemToDiagram(topLeft);

     double rad = node.RotationAngle * Math.PI / 180;
     var rightVector = new Vector(
           width * Math.Cos(rad), width * Math.Sin(rad));
     rad += Math.PI / 2;
     var downVector = new Vector(
           height * Math.Cos(rad), height * Math.Sin(rad));

     var bottomRight = topLeft + rightVector + downVector;
     var center = topLeft + rightVector / 2 + downVector / 2;
     var rotate = new RotateTransform(
           -node.RotationAngle, center.X, center.Y);
     topLeft = rotate.Transform(topLeft);
     bottomRight = rotate.Transform(bottomRight);
     node.Bounds = new Rect(topLeft, bottomRight);
}[/code]

Regards,
Slavcho
Mindfusion

Title: Re: Resize rotated nodes
Post by Kris on May 19th, 2017 at 8:50am
Thanks,

adapted it to work in all expand/shrink directions.
Don't you thought about putting it to the API or if already is hidden make it public ?

Regards
Kris

Title: Re: Resize rotated nodes
Post by Slavcho on May 19th, 2017 at 9:02am
I guess we could add a pivot-point argument to usual Resize method, we'll have it in mind for next releases.

Regards,
Slavcho

The MindFusion Forums » Powered by YaBB 2.6.11!
YaBB Forum Software © 2000-2024. All Rights Reserved.