Centered path even after resize and rotation


#1

I've used the SVG Tool to convert my path into a stream and I load it as suggest. now I'd like to rotate it while keeping it centered in my graphic bounderies.

 

So my path loading function is:

static const unsigned char pathData[] {...}        
Path p;
p.loadPathFromData (pathData, sizeof (pathData));

I've also tried as I saw being used within JUCE code for drawing arrow (I'm providing the height and get the path in return):

p.scaleToFit (0, 0, height, height, true);

However no matter where I try to add transformation:

  p.applyTransform (juce::AffineTransform::rotation (angle,0.5f * width, 0.5f * height));

// or this one
  p.applyTransform(juce::AffineTransform::rotation(angle));

I'm never being able to keep the image centered just rotating it "in-place".

I think the thing I'm missing is how can I make the Path or an object that has bounds of my desired area.

Because when I call:

DBG(String::formatted("%d : %d : %d : %d",p.getBounds().getX(),p.getBounds().getY(),p.getBounds().getWidth(),p.getBounds().getHeight()));

I'm getting very big canvas:

1606405377 : 1606405792 : 23178600 : 23178604

So I guess the scaleToFit (or other call I'm trying to make the path within the desired boundaries) isn't really commiting to the Path.

I guess I'm missing something.


#2

You're probably re-applying some kind of transformation many times?


#3

Check the path's coordinate system. If you apply a rotation, only the path's origin will be centered. Probably the points of the path are not located around the origin.

To create a rotation, create a translation from the origin to the desired rotation center, add the rotation to the matrix and apply the inverse of the first translation. This matrix should do what you wanted.


#4

Thanks Jules and Daniel!

On my case it seems that the main issue arised when I've seen that the LookAndFeel Slider knob draw callback will provide the area you should put your knob which isn't the entire graphic area/canvas.

Also some lack of understanding the relations between which call are Drawable's and which are Component's made me scratch my head for a while.

Thank you again!