2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_DRAWABLEIMAGE_JUCEHEADER__
27 #define __JUCE_DRAWABLEIMAGE_JUCEHEADER__
29 #include "juce_Drawable.h"
30 #include "../imaging/juce_Image.h"
31 #include "../../components/positioning/juce_RelativeParallelogram.h"
34 //==============================================================================
36 A drawable object which is a bitmap image.
40 class JUCE_API DrawableImage
: public Drawable
43 //==============================================================================
45 DrawableImage (const DrawableImage
& other
);
50 //==============================================================================
51 /** Sets the image that this drawable will render. */
52 void setImage (const Image
& imageToUse
);
54 /** Returns the current image. */
55 const Image
& getImage() const noexcept
{ return image
; }
57 /** Sets the opacity to use when drawing the image. */
58 void setOpacity (float newOpacity
);
60 /** Returns the image's opacity. */
61 float getOpacity() const noexcept
{ return opacity
; }
63 /** Sets a colour to draw over the image's alpha channel.
65 By default this is transparent so isn't drawn, but if you set a non-transparent
66 colour here, then it will be overlaid on the image, using the image's alpha
69 This is handy for doing things like darkening or lightening an image by overlaying
70 it with semi-transparent black or white.
72 void setOverlayColour (const Colour
& newOverlayColour
);
74 /** Returns the overlay colour. */
75 const Colour
& getOverlayColour() const noexcept
{ return overlayColour
; }
77 /** Sets the bounding box within which the image should be displayed. */
78 void setBoundingBox (const RelativeParallelogram
& newBounds
);
80 /** Returns the position to which the image's top-left corner should be remapped in the target
81 coordinate space when rendering this object.
84 const RelativeParallelogram
& getBoundingBox() const noexcept
{ return bounds
; }
86 //==============================================================================
88 void paint (Graphics
& g
);
90 bool hitTest (int x
, int y
);
92 Drawable
* createCopy() const;
94 Rectangle
<float> getDrawableBounds() const;
96 void refreshFromValueTree (const ValueTree
& tree
, ComponentBuilder
& builder
);
98 ValueTree
createValueTree (ComponentBuilder::ImageProvider
* imageProvider
) const;
100 static const Identifier valueTreeType
;
102 //==============================================================================
103 /** Internally-used class for wrapping a DrawableImage's state into a ValueTree. */
104 class ValueTreeWrapper
: public Drawable::ValueTreeWrapperBase
107 ValueTreeWrapper (const ValueTree
& state
);
109 var
getImageIdentifier() const;
110 void setImageIdentifier (const var
& newIdentifier
, UndoManager
* undoManager
);
111 Value
getImageIdentifierValue (UndoManager
* undoManager
);
113 float getOpacity() const;
114 void setOpacity (float newOpacity
, UndoManager
* undoManager
);
115 Value
getOpacityValue (UndoManager
* undoManager
);
117 const Colour
getOverlayColour() const;
118 void setOverlayColour (const Colour
& newColour
, UndoManager
* undoManager
);
119 Value
getOverlayColourValue (UndoManager
* undoManager
);
121 RelativeParallelogram
getBoundingBox() const;
122 void setBoundingBox (const RelativeParallelogram
& newBounds
, UndoManager
* undoManager
);
124 static const Identifier opacity
, overlay
, image
, topLeft
, topRight
, bottomLeft
;
128 //==============================================================================
131 Colour overlayColour
;
132 RelativeParallelogram bounds
;
134 friend class Drawable::Positioner
<DrawableImage
>;
135 bool registerCoordinates (RelativeCoordinatePositionerBase
&);
136 void recalculateCoordinates (Expression::Scope
*);
138 DrawableImage
& operator= (const DrawableImage
&);
139 JUCE_LEAK_DETECTOR (DrawableImage
);
143 #endif // __JUCE_DRAWABLEIMAGE_JUCEHEADER__