The base class for objects which can draw themselves, e.g. More...
Inherits Component.
Inherited by DrawableComposite, DrawableImage, DrawableShape, and DrawableText.
Classes | |
| class | ValueTreeWrapperBase |
| Internal class used to manage ValueTrees that represent Drawables. More... | |
Public Member Functions | |
| virtual | ~Drawable () |
| Destructor. | |
| virtual Drawable * | createCopy () const =0 |
| Creates a deep copy of this Drawable object. | |
| void | draw (Graphics &g, float opacity, const AffineTransform &transform=AffineTransform::identity) 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, const Rectangle< float > &destArea, const RectanglePlacement &placement, float opacity) const |
| Renders the Drawable within a rectangle, scaling it to fit neatly inside without changing its aspect-ratio. | |
| void | setOriginWithOriginalSize (const Point< float > &originWithinParent) |
| Resets any transformations on this drawable, and positions its origin within its parent component. | |
| void | setTransformToFit (const Rectangle< float > &areaInParent, const RectanglePlacement &placement) |
| Sets a transform for this drawable that will position it within the specified area of its parent component. | |
| DrawableComposite * | getParent () const |
| Returns the DrawableComposite that contains this object, if there is one. | |
| virtual ValueTree | createValueTree (ComponentBuilder::ImageProvider *imageProvider) const =0 |
| Creates a ValueTree to represent this Drawable. | |
| virtual Rectangle< float > | getDrawableBounds () const =0 |
| Returns the area that this drawble covers. | |
Static Public Member Functions | |
| static Drawable * | createFromImageData (const void *data, size_t numBytes) |
| Tries to turn some kind of image file into a drawable. | |
| static Drawable * | createFromImageDataStream (InputStream &dataSource) |
| Tries to turn a stream containing some kind of image data into a drawable. | |
| static Drawable * | createFromImageFile (const File &file) |
| Tries to turn a file containing some kind of image data into a drawable. | |
| static Drawable * | createFromSVG (const XmlElement &svgDocument) |
| Attempts to parse an SVG (Scalable Vector Graphics) document, and to turn this into a Drawable tree. | |
| static Drawable * | createFromValueTree (const ValueTree &tree, ComponentBuilder::ImageProvider *imageProvider) |
| Tries to create a Drawable from a previously-saved ValueTree. | |
| static void | registerDrawableTypeHandlers (ComponentBuilder &componentBuilder) |
| Registers a set of ComponentBuilder::TypeHandler objects that can be used to load all the different Drawable types from a saved state. | |
Protected Member Functions | |
| Drawable () | |
| The base class can't be instantiated directly. | |
| void | transformContextToCorrectOrigin (Graphics &g) |
| void | parentHierarchyChanged () |
| Called to indicate that the component's parents have changed. | |
| void | setBoundsToEnclose (const Rectangle< float > &area) |
Protected Attributes | |
| Point< int > | originRelativeToComponent |
The base class for objects which can draw themselves, e.g.
polygons, images, etc.
| Drawable::Drawable | ( | ) | [protected] |
The base class can't be instantiated directly.
| virtual Drawable::~Drawable | ( | ) | [virtual] |
Destructor.
| virtual Drawable* 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 DrawableComposite, DrawableImage, DrawablePath, DrawableRectangle, and DrawableText.
| void Drawable::draw | ( | Graphics & | g, |
| float | opacity, | ||
| const AffineTransform & | transform = AffineTransform::identity |
||
| ) | const |
Renders this Drawable object.
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.
| void Drawable::drawAt | ( | Graphics & | g, |
| float | x, | ||
| float | y, | ||
| float | opacity | ||
| ) | const |
Renders the Drawable at a given offset within the Graphics context.
The co-ordinates passed-in are used to translate the object relative to its own origin before drawing it - this is basically a quick way of saying:
draw (g, AffineTransform::translation (x, y)).
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.
| void Drawable::drawWithin | ( | Graphics & | g, |
| const Rectangle< float > & | destArea, | ||
| const 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.
| g | the graphics context to render onto |
| destArea | the target rectangle to fit the drawable into |
| placement | defines the alignment and rescaling to use to fit this object within the target rectangle. |
| opacity | the opacity to use, in the range 0 to 1.0 |
| void Drawable::setOriginWithOriginalSize | ( | const Point< float > & | originWithinParent ) |
Resets any transformations on this drawable, and positions its origin within its parent component.
| void Drawable::setTransformToFit | ( | const Rectangle< float > & | areaInParent, |
| const RectanglePlacement & | placement | ||
| ) |
Sets a transform for this drawable that will position it within the specified area of its parent component.
| DrawableComposite* Drawable::getParent | ( | ) | const |
Returns the DrawableComposite that contains this object, if there is one.
| static Drawable* 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.
| static Drawable* 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.
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.
| static Drawable* Drawable::createFromSVG | ( | const XmlElement & | svgDocument ) | [static] |
Attempts to parse an SVG (Scalable Vector Graphics) document, and to turn this into a Drawable tree.
The object returned must be deleted by the caller. If something goes wrong while parsing, it may return 0.
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.
| static Drawable* Drawable::createFromValueTree | ( | const ValueTree & | tree, |
| ComponentBuilder::ImageProvider * | imageProvider | ||
| ) | [static] |
Tries to create a Drawable from a previously-saved ValueTree.
The ValueTree must have been created by the createValueTree() method. If there are any images used within the drawable, you'll need to provide a valid ImageProvider object that can be used to retrieve these images from whatever type of identifier is used to represent them. Internally, this uses a ComponentBuilder, and registerDrawableTypeHandlers().
| virtual ValueTree Drawable::createValueTree | ( | ComponentBuilder::ImageProvider * | imageProvider ) | const [pure virtual] |
Creates a ValueTree to represent this Drawable.
The ValueTree that is returned can be turned back into a Drawable with createFromValueTree(). If there are any images used in this drawable, you'll need to provide a valid ImageProvider object that can be used to create storable representations of them.
Implemented in DrawableComposite, DrawableImage, DrawablePath, DrawableRectangle, and DrawableText.
| virtual Rectangle<float> Drawable::getDrawableBounds | ( | ) | const [pure virtual] |
Returns the area that this drawble covers.
The result is expressed in this drawable's own coordinate space, and does not take into account any transforms that may be applied to the component.
Implemented in DrawableComposite, DrawableImage, DrawableShape, and DrawableText.
| static void Drawable::registerDrawableTypeHandlers | ( | ComponentBuilder & | componentBuilder ) | [static] |
Registers a set of ComponentBuilder::TypeHandler objects that can be used to load all the different Drawable types from a saved state.
| void Drawable::transformContextToCorrectOrigin | ( | Graphics & | g ) | [protected] |
| void Drawable::parentHierarchyChanged | ( | ) | [protected, virtual] |
Called to indicate that the component's parents have changed.
When a component is added or removed from its parent, this method will be called on all of its children (recursively - so all children of its children will also be called as well).
Subclasses can override this if they need to react to this in some way.
Reimplemented from Component.
Reimplemented in DrawableComposite.
| void Drawable::setBoundsToEnclose | ( | const Rectangle< float > & | area ) | [protected] |
Point<int> Drawable::originRelativeToComponent [protected] |