Browse Source

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.
v7.0.9
attila 2 years ago
parent
commit
a99422efee
3 changed files with 31 additions and 2 deletions
  1. +15
    -0
      modules/juce_gui_basics/drawables/juce_Drawable.cpp
  2. +14
    -0
      modules/juce_gui_basics/drawables/juce_Drawable.h
  3. +2
    -2
      modules/juce_gui_basics/drawables/juce_SVGParser.cpp

+ 15
- 0
modules/juce_gui_basics/drawables/juce_Drawable.cpp View File

@@ -140,6 +140,7 @@ void Drawable::setBoundsToEnclose (Rectangle<float> area)
auto newBounds = area.getSmallestIntegerContainer() + parentOrigin; auto newBounds = area.getSmallestIntegerContainer() + parentOrigin;
originRelativeToComponent = parentOrigin - newBounds.getPosition(); originRelativeToComponent = parentOrigin - newBounds.getPosition();
setBounds (newBounds); setBounds (newBounds);
updateTransform();
} }
//============================================================================== //==============================================================================
@@ -154,6 +155,20 @@ bool Drawable::replaceColour (Colour original, Colour replacement)
return changed; 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) void Drawable::setOriginWithOriginalSize (Point<float> originWithinParent)
{ {


+ 14
- 0
modules/juce_gui_basics/drawables/juce_Drawable.h View File

@@ -186,6 +186,18 @@ public:
*/ */
virtual bool replaceColour (Colour originalColour, Colour replacementColour); 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: protected:
//============================================================================== //==============================================================================
friend class DrawableComposite; friend class DrawableComposite;
@@ -202,8 +214,10 @@ protected:
Point<int> originRelativeToComponent; Point<int> originRelativeToComponent;
std::unique_ptr<Drawable> drawableClipPath; std::unique_ptr<Drawable> drawableClipPath;
AffineTransform drawableTransform;
void nonConstDraw (Graphics&, float opacity, const AffineTransform&); void nonConstDraw (Graphics&, float opacity, const AffineTransform&);
void updateTransform();
Drawable (const Drawable&); Drawable (const Drawable&);
Drawable& operator= (const Drawable&); Drawable& operator= (const Drawable&);


+ 2
- 2
modules/juce_gui_basics/drawables/juce_SVGParser.cpp View File

@@ -1093,9 +1093,9 @@ private:
dt->setFont (font, true); dt->setFont (font, true);
if (additonalTransform != nullptr) if (additonalTransform != nullptr)
dt->setTransform (transform.followedBy (*additonalTransform));
dt->setDrawableTransform (transform.followedBy (*additonalTransform));
else else
dt->setTransform (transform);
dt->setDrawableTransform (transform);
dt->setColour (parseColour (xml, "fill", Colours::black) dt->setColour (parseColour (xml, "fill", Colours::black)
.withMultipliedAlpha (parseSafeFloat (getStyleAttribute (xml, "fill-opacity", "1")))); .withMultipliedAlpha (parseSafeFloat (getStyleAttribute (xml, "fill-opacity", "1"))));


Loading…
Cancel
Save