Add remaining files
[juce-lv2.git] / juce / source / src / gui / graphics / drawables / juce_DrawableImage.h
blob49ffca1430097544aa7b9320326c279ec7cdb801
1 /*
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 //==============================================================================
35 /**
36 A drawable object which is a bitmap image.
38 @see Drawable
40 class JUCE_API DrawableImage : public Drawable
42 public:
43 //==============================================================================
44 DrawableImage();
45 DrawableImage (const DrawableImage& other);
47 /** Destructor. */
48 ~DrawableImage();
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
67 channel as a mask.
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.
82 @see setTransform
84 const RelativeParallelogram& getBoundingBox() const noexcept { return bounds; }
86 //==============================================================================
87 /** @internal */
88 void paint (Graphics& g);
89 /** @internal */
90 bool hitTest (int x, int y);
91 /** @internal */
92 Drawable* createCopy() const;
93 /** @internal */
94 Rectangle<float> getDrawableBounds() const;
95 /** @internal */
96 void refreshFromValueTree (const ValueTree& tree, ComponentBuilder& builder);
97 /** @internal */
98 ValueTree createValueTree (ComponentBuilder::ImageProvider* imageProvider) const;
99 /** @internal */
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
106 public:
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;
127 private:
128 //==============================================================================
129 Image image;
130 float opacity;
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__