Scaling a path problem


#1

Hey folks, i’m having a tough time figuring out how to scale a path properly based on window size. When I defined my path, the window was fixed in size. now I’m adding support for scaling the path as the window scales, including the path stroke thickness.

auto r = getLocalBounds().toFloat().reduced(1); //this is the rectangle(app window) our path is being drawn in. 
Path p(mPath);
float ratio;
if( getHeight() > getWidth() )  { ratio = getHeight() / getWidth(); }
else                            { ratio = getWidth() / getHeight(); }

//when the window is 30x30, the path looks PERFECT when r is reduced 7px, and shifted down 10px on the y axis
p.applyTransform(mPath.getTransformToScaleToFit(r.reduced(7.f * ratio).withY(10.f * ratio), false));
PathStrokeType pst2(pst); //PathStrokeType pst(3, PathStrokeType::JointStyle::mitered);

//when the window is 30x30, the path looks PERFECT when the stroke is 3, or 10% of the window size
pst2.setStrokeThickness(3.f * ratio); 

//when the window is 30x30, the corner for the roundedRect surrounding the path looks PERFECT with a corner size of 4px
auto cornerSize = 4.f * ratio;

Here’s a video of what happens when I scale the window in realtime via ProJucer:


Path::getTransformToScaleToFit() from normalized path oddities
#3

I figured out that I needed to not use Graphics::strokePath(), but instead needed to convert the stroked path into a path of its own and use Graphics::fillPath() instead. that allowed me to scale as needed with no problems.