Scaling multiple objects relative to a bounding rectangle

734 Views Asked by At

I'm trying to figure out the algorithm for scaling multiple selected objects on a canvas (similar to Visio's behavior). Say for instance I have the following selected objects in my application:

I then drag the lower-right handle of the bounding box to increase the size of the selected objects and thus produce the following results:

enter image description here

My questions are as follows:

  1. How do I get the amount of scaling to be applied to each object?
  2. How do I get the amount of translation to be applied to each object?

I hope this question makes sense. And I hope you could help.

1

There are 1 best solutions below

4
On

Hi I dont think there is any Translation , There is only Scaleing . One easy way to do that is preserve the Width and Height of your object like (TextBoxes above) and then when you want to get Scaleing values of that object

ScaleTransform scale = new ScaleTransform();
        //_text is the scaled object
        scale.ScaleX = text.ActualWidth - _width; //_width is width of the textbox at beginning.
        scale.ScaleY = text.ActualHeight - _height; //_height is the height of textbox at the beginning.

This will give you the amount by which object is scaled corressponding to the Width and Height of TextBox at the beginning (i.e When window initialized) . I hyope this will give you an idea.