mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-11 23:54:18 +00:00
Drawable: Add setDrawableTransform() and use it in SVGParser
Using this new function a previous bug is avoided where transforms were applied differently to drawable paths and text elements.
This commit is contained in:
parent
6c09aa69d9
commit
a99422efee
3 changed files with 31 additions and 2 deletions
|
|
@ -140,6 +140,7 @@ void Drawable::setBoundsToEnclose (Rectangle<float> area)
|
|||
auto newBounds = area.getSmallestIntegerContainer() + parentOrigin;
|
||||
originRelativeToComponent = parentOrigin - newBounds.getPosition();
|
||||
setBounds (newBounds);
|
||||
updateTransform();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -154,6 +155,20 @@ bool Drawable::replaceColour (Colour original, Colour replacement)
|
|||
return changed;
|
||||
}
|
||||
|
||||
void Drawable::setDrawableTransform (const AffineTransform& transform)
|
||||
{
|
||||
drawableTransform = transform;
|
||||
updateTransform();
|
||||
}
|
||||
|
||||
void Drawable::updateTransform()
|
||||
{
|
||||
const auto transformationOrigin = originRelativeToComponent + getPosition();
|
||||
setTransform (AffineTransform::translation (transformationOrigin * (-1))
|
||||
.followedBy (drawableTransform)
|
||||
.followedBy (AffineTransform::translation (transformationOrigin)));
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void Drawable::setOriginWithOriginalSize (Point<float> originWithinParent)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -186,6 +186,18 @@ public:
|
|||
*/
|
||||
virtual bool replaceColour (Colour originalColour, Colour replacementColour);
|
||||
|
||||
/** Sets a transformation that applies to the same coordinate system in which the rest of the
|
||||
draw calls are made. You almost certainly want to call this function when working with
|
||||
Drawables as opposed to Component::setTransform().
|
||||
|
||||
The reason for this is that the origin of a Drawable is not the same as the point returned
|
||||
by Component::getPosition() but has an additional offset internal to the Drawable class.
|
||||
|
||||
Using setDrawableTransform() will take this internal offset into account when applying the
|
||||
transform to the Component base.
|
||||
*/
|
||||
void setDrawableTransform (const AffineTransform& transform);
|
||||
|
||||
protected:
|
||||
//==============================================================================
|
||||
friend class DrawableComposite;
|
||||
|
|
@ -202,8 +214,10 @@ protected:
|
|||
|
||||
Point<int> originRelativeToComponent;
|
||||
std::unique_ptr<Drawable> drawableClipPath;
|
||||
AffineTransform drawableTransform;
|
||||
|
||||
void nonConstDraw (Graphics&, float opacity, const AffineTransform&);
|
||||
void updateTransform();
|
||||
|
||||
Drawable (const Drawable&);
|
||||
Drawable& operator= (const Drawable&);
|
||||
|
|
|
|||
|
|
@ -1093,9 +1093,9 @@ private:
|
|||
dt->setFont (font, true);
|
||||
|
||||
if (additonalTransform != nullptr)
|
||||
dt->setTransform (transform.followedBy (*additonalTransform));
|
||||
dt->setDrawableTransform (transform.followedBy (*additonalTransform));
|
||||
else
|
||||
dt->setTransform (transform);
|
||||
dt->setDrawableTransform (transform);
|
||||
|
||||
dt->setColour (parseColour (xml, "fill", Colours::black)
|
||||
.withMultipliedAlpha (parseSafeFloat (getStyleAttribute (xml, "fill-opacity", "1"))));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue