Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SVGObject : Drawable
- {
- public:
- SVGObject() {}
- SVGObject(const String & svg)
- {
- if (svg.isEmpty())
- return;
- ScopedPointer<XmlElement> xml(XmlDocument::parse(svg));
- drawable = createFromSVG(*xml);
- svgBounds = static_cast<DrawableComposite*>(drawable.get())->getContentArea();
- }
- ~SVGObject() = default;
- Drawable* createCopy() const override
- {
- return static_cast<DrawableComposite*>(drawable.get())->createCopy();
- }
- void draw(Graphics & g, const juce::Rectangle<float> & rectangle, float opacity = 1.f) const
- {
- juce::AffineTransform xform = RectanglePlacement(RectanglePlacement::centred).getTransformToFit(svgBounds, rectangle);
- drawable->draw(g, opacity, xform);
- }
- void drawWithColor(Graphics & g, const juce::Rectangle<float> & rectangle, const Colour & colorToReplace, const Colour & newColor, float opacity = 1.f)
- {
- juce::AffineTransform xform = RectanglePlacement(RectanglePlacement::centred).getTransformToFit(svgBounds, rectangle);
- drawable->replaceColour(colorToReplace, newColor);
- drawable->draw(g, opacity, xform);
- drawable->replaceColour(newColor, colorToReplace);
- }
- void drawWithRotation(Graphics & g, const juce::Rectangle<float> & rectangle, float rotationDegrees, float opacity = 1.f) const
- {
- juce::AffineTransform xform = RectanglePlacement(RectanglePlacement::centred).getTransformToFit(svgBounds, rectangle)
- .rotated(juce::degreesToRadians(rotationDegrees), rectangle.getCentreX(), rectangle.getCentreY());
- drawable->draw(g, opacity, xform);
- }
- Rectangle<float> getDrawableBounds() const override { return svgBounds; }
- Path getOutlineAsPath() const override { jassertfalse; return {}; };
- bool isValid()
- {
- return drawable != nullptr;
- }
- protected:
- juce::Rectangle<float> svgBounds;
- ScopedPointer<Drawable> drawable;
- };
Advertisement
Add Comment
Please, Sign In to add comment