Loading...
Searching...
No Matches
juce::Drawable Class Referenceabstract

Detailed Description

The base class for objects which can draw themselves, e.g.

polygons, images, etc.

See also
DrawableComposite, DrawableImage, DrawablePath, DrawableText

The documentation for this class was generated from the following file:
Inheritance diagram for juce::Drawable:

Classes

class  Listener

Public Member Functions

 Drawable ()=default
 Constructor.
 Drawable (const Drawable &other)
 Copy constructor.
virtual ~Drawable ()=default
 Destructor.
virtual std::unique_ptr< DrawablecreateCopy () const =0
 Creates a deep copy of this Drawable object.
virtual Path getOutlineAsPath () const =0
 Creates a path that describes the outline of this drawable.
void draw (Graphics &g, float opacity, const AffineTransform &transform=AffineTransform()) const
 Renders this Drawable object.
void drawAt (Graphics &g, float x, float y, float opacity) const
 Renders the Drawable at a given offset within the Graphics context.
void drawWithin (Graphics &g, Rectangle< float > destArea, RectanglePlacement placement, float opacity) const
 Renders the Drawable within a rectangle, scaling it to fit neatly inside without changing its aspect-ratio.
void setClipPath (std::unique_ptr< Drawable > drawableClipPath)
 Sets a the clipping region of this drawable using another drawable.
virtual bool hitTest (Point< float >) const =0
 Tests whether a given point is inside the Drawable.
Rectangle< float > getDrawableBounds () const
 Returns the area that this drawable covers.
virtual Rectangle< float > getDrawableBoundsUntransformed () const =0
 Returns the area that this drawable covers in its original coordinate system.
int getWidth () const
 Returns the width of the drawable bounds rounded up to the nearest integer.
int getHeight () const
 Returns the height of the drawable bounds rounded up to the nearest integer.
virtual bool replaceColour (Colour originalColour, Colour replacementColour)
 Recursively replaces a colour that might be used for filling or stroking.
void setDrawableTransform (const AffineTransform &transform)
 Sets a transformation that applies to the same coordinate system in which the rest of the draw calls are made.
void setDrawableTransformToFit (const Rectangle< float > &area, RectanglePlacement placement)
 Calls setDrawableTransform() with a transform that will position this Drawable within the specified area in the untransformed coordinate system of the Drawable.
AffineTransform getDrawableTransform () const
 Returns the transform that is currently being applied to this drawable.
const StringgetName () const
 Returns the name of this Drawable object.
void setName (const String &newName)
 Sets the name of this drawable object.
void addListener (Listener *newListener)
 Adds a listener.
void removeListener (Listener *listenerToRemove)
 Removes a listener.
virtual bool isImage () const
virtual std::optional< StringgetContainedText () const
virtual bool requiresBlendBuffer () const

Static Public Member Functions

static std::unique_ptr< DrawablecreateFromImageData (const void *data, size_t numBytes)
 Tries to turn some kind of image file into a drawable.
static std::unique_ptr< DrawablecreateFromImageDataStream (InputStream &dataSource)
 Tries to turn a stream containing some kind of image data into a drawable.
static std::unique_ptr< DrawablecreateFromImageFile (const File &file)
 Tries to turn a file containing some kind of image data into a drawable.
static std::unique_ptr< DrawablecreateFromSVGFile (const File &svgFile)
 Attempts to parse an SVG (Scalable Vector Graphics) document from a file, and to turn this into a Drawable tree.
static std::unique_ptr< DrawableCompositecreateFromSVGString (const String &svgString)
 Attempts to parse an SVG (Scalable Vector Graphics) document from a string, and to turn this into a Drawable tree.
static Path parseSVGPath (const String &svgPath)
 Parses an SVG path string and returns it.

Protected Member Functions

virtual void paint (Graphics &g) const =0
virtual AffineTransform getTransform () const
void callListeners ()

Constructors and Destructors

◆ Drawable() [1/2]

◆ Drawable() [2/2]

juce::Drawable::Drawable ( const Drawable & other)

Copy constructor.

References Drawable().

◆ ~Drawable()

virtual juce::Drawable::~Drawable ( )
virtualdefault

Destructor.

Member Functions

◆ createCopy()

virtual std::unique_ptr< Drawable > juce::Drawable::createCopy ( ) const
pure virtual

Creates a deep copy of this Drawable object.

Use this to create a new copy of this and any sub-objects in the tree.

Implemented in juce::DrawableComposite, juce::DrawableImage, juce::DrawablePath, juce::DrawableRectangle, and juce::DrawableText.

Referenced by juce::OwningDrawableComponent::createFromCopy().

◆ getOutlineAsPath()

virtual Path juce::Drawable::getOutlineAsPath ( ) const
pure virtual

Creates a path that describes the outline of this drawable.

Implemented in juce::DrawableComposite, juce::DrawableImage, juce::DrawableShape, and juce::DrawableText.

◆ draw()

void juce::Drawable::draw ( Graphics & g,
float opacity,
const AffineTransform & transform = AffineTransform() ) const

Renders this Drawable object.

See also
drawWithin

◆ drawAt()

void juce::Drawable::drawAt ( Graphics & g,
float x,
float y,
float opacity ) const

Renders the Drawable at a given offset within the Graphics context.

The coordinates passed-in are used to translate the object relative to its own origin before drawing it - this is basically a quick way of saying:

static AffineTransform translation(float deltaX, float deltaY) noexcept
Returns a new transform which is a translation.
void draw(Graphics &g, float opacity, const AffineTransform &transform=AffineTransform()) const
Renders this Drawable object.
float x
Definition juce_UnityPluginInterface.h:197
float float y
Definition juce_UnityPluginInterface.h:197

Note that the preferred way to render a drawable in future is by using it as a component and adding it to a parent, so you might want to consider that before using this method.

References x, and y.

◆ drawWithin()

void juce::Drawable::drawWithin ( Graphics & g,
Rectangle< float > destArea,
RectanglePlacement placement,
float opacity ) const

Renders the Drawable within a rectangle, scaling it to fit neatly inside without changing its aspect-ratio.

The object can placed arbitrarily within the rectangle based on a Justification type, and can either be made as big as possible, or just reduced to fit.

Note that the preferred way to render a drawable in future is by using it as a component and adding it to a parent, so you might want to consider that before using this method.

Parameters
gthe graphics context to render onto
destAreathe target rectangle to fit the drawable into
placementdefines the alignment and rescaling to use to fit this object within the target rectangle.
opacitythe opacity to use, in the range 0 to 1.0

◆ setClipPath()

void juce::Drawable::setClipPath ( std::unique_ptr< Drawable > drawableClipPath)

Sets a the clipping region of this drawable using another drawable.

The drawable passed in will be deleted when no longer needed.

◆ hitTest()

virtual bool juce::Drawable::hitTest ( Point< float > ) const
pure virtual

Tests whether a given point is inside the Drawable.

Implemented in juce::DrawableComposite, juce::DrawableImage, juce::DrawableShape, and juce::DrawableText.

◆ createFromImageData()

std::unique_ptr< Drawable > juce::Drawable::createFromImageData ( const void * data,
size_t numBytes )
static

Tries to turn some kind of image file into a drawable.

The data could be an image that the ImageFileFormat class understands, or it could be SVG.

◆ createFromImageDataStream()

std::unique_ptr< Drawable > juce::Drawable::createFromImageDataStream ( InputStream & dataSource)
static

Tries to turn a stream containing some kind of image data into a drawable.

The data could be an image that the ImageFileFormat class understands, or it could be SVG.

◆ createFromImageFile()

std::unique_ptr< Drawable > juce::Drawable::createFromImageFile ( const File & file)
static

Tries to turn a file containing some kind of image data into a drawable.

The data could be an image that the ImageFileFormat class understands, or it could be SVG.

◆ createFromSVGFile()

std::unique_ptr< Drawable > juce::Drawable::createFromSVGFile ( const File & svgFile)
static

Attempts to parse an SVG (Scalable Vector Graphics) document from a file, and to turn this into a Drawable tree.

If something goes wrong while parsing, it may return nullptr.

SVG is a pretty large and complex spec, and this doesn't aim to be a full implementation, but it can return the basic vector objects.

Any references to references to external image files will be relative to the parent directory of the file passed.

Referenced by juce::OwningDrawableComponent::createFromSVGFile().

◆ createFromSVGString()

std::unique_ptr< DrawableComposite > juce::Drawable::createFromSVGString ( const String & svgString)
static

Attempts to parse an SVG (Scalable Vector Graphics) document from a string, and to turn this into a Drawable tree.

Referenced by juce::OwningDrawableComponent::createFromSVGString().

◆ parseSVGPath()

Path juce::Drawable::parseSVGPath ( const String & svgPath)
static

Parses an SVG path string and returns it.

◆ getDrawableBounds()

Rectangle< float > juce::Drawable::getDrawableBounds ( ) const

Returns the area that this drawable covers.

These bounds are affected by the transform passed to setDrawableTransform(). To get the original, untransformed bounds use getDrawableBoundsUntransformed().

Referenced by getHeight(), and getWidth().

◆ getDrawableBoundsUntransformed()

virtual Rectangle< float > juce::Drawable::getDrawableBoundsUntransformed ( ) const
pure virtual

Returns the area that this drawable covers in its original coordinate system.

These bounds are not affected by setDrawableTransform().

See also
getDrawableBounds

Implemented in juce::DrawableComposite, juce::DrawableImage, juce::DrawableShape, and juce::DrawableText.

◆ getWidth()

int juce::Drawable::getWidth ( ) const
inline

Returns the width of the drawable bounds rounded up to the nearest integer.

See also
getDrawableBounds

References getDrawableBounds().

◆ getHeight()

int juce::Drawable::getHeight ( ) const
inline

Returns the height of the drawable bounds rounded up to the nearest integer.

See also
getDrawableBounds

References getDrawableBounds().

◆ replaceColour()

virtual bool juce::Drawable::replaceColour ( Colour originalColour,
Colour replacementColour )
virtual

Recursively replaces a colour that might be used for filling or stroking.

return true if any instances of this colour were found.

Reimplemented in juce::DrawableComposite, juce::DrawableShape, and juce::DrawableText.

◆ setDrawableTransform()

void juce::Drawable::setDrawableTransform ( const AffineTransform & transform)

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.

You can only use Drawable::setDrawableTransform() or Component::setTransform() for a given object. Using both will lead to unpredictable behaviour.

◆ setDrawableTransformToFit()

void juce::Drawable::setDrawableTransformToFit ( const Rectangle< float > & area,
RectanglePlacement placement )

Calls setDrawableTransform() with a transform that will position this Drawable within the specified area in the untransformed coordinate system of the Drawable.

◆ getDrawableTransform()

AffineTransform juce::Drawable::getDrawableTransform ( ) const

Returns the transform that is currently being applied to this drawable.

See also
setTransform

◆ getName()

const String & juce::Drawable::getName ( ) const
inline

Returns the name of this Drawable object.

The SVG parser attempts to set this value to the id attribute of the corresponding SVG element. However, since it's possible to reference and draw a single SVG element multiple times, this value is not guaranteed to be unique.

See also
setName

◆ setName()

void juce::Drawable::setName ( const String & newName)
inline

Sets the name of this drawable object.

See also
getName

◆ addListener()

void juce::Drawable::addListener ( Listener * newListener)
inline

Adds a listener.

◆ removeListener()

void juce::Drawable::removeListener ( Listener * listenerToRemove)
inline

Removes a listener.

◆ isImage()

virtual bool juce::Drawable::isImage ( ) const
inlinevirtual

Reimplemented in juce::DrawableImage.

◆ getContainedText()

virtual std::optional< String > juce::Drawable::getContainedText ( ) const
inlinevirtual

Reimplemented in juce::DrawableText.

◆ requiresBlendBuffer()

virtual bool juce::Drawable::requiresBlendBuffer ( ) const
inlinevirtual

◆ paint()

virtual void juce::Drawable::paint ( Graphics & g) const
protectedpure virtual

Implemented in juce::DrawableImage.

◆ getTransform()

virtual AffineTransform juce::Drawable::getTransform ( ) const
protectedvirtual

◆ callListeners()

void juce::Drawable::callListeners ( )
inlineprotected
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram