when using setTransformToFit on a Drawable that has been created from a SVG image it doesn’t seem to work. It works fine with Drawables created from a png image.
Adding the following code to the Juce Demo shows this:
// WidgetsDemo.cpp / ButtonPage (~ line 459)
ButtonPage()
[ // add this to constructor
// load svg from desktop, only zipped as binary resource available
d = Drawable::createFromImageFile (File::getSpecialLocation(File::userDesktopDirectory).getChildFile("svgfile.svg"));
]
void resized()
{
if (d != nullptr)
d->setTransformToFit(juce::Rectangle<float> (0.5f*getWidth(), 0.5f*getHeight(), 2.5f*getWidth(), 2.5f*getHeight()), RectanglePlacement::centred);
}
void paint(Graphics& g)
{
if (d != nullptr)
d->draw(g, 0.5f);
}
ScopedPointer<Drawable> d;
You’re misunderstanding the meaning of setTransform - it’s actually Component::setTransform() that gets called, so if you bypass the normal component painting mechanism by directly calling the old draw() method, then any components transforms will be ignored.
setTransformToFit() is a Drawable member and calls Component::setTransform(), but I assume it’s now only meant for changing child bounds. I’m quite sure that draw used the Component’s transform some time ago (as the above code worked with the older JUCE). What would be the correct approach now to display a Drawable? I think adding as child component won’t work when variable transparency is a requirement.