Add remaining files
[juce-lv2.git] / juce / source / src / gui / graphics / drawables / juce_DrawableShape.h
blob8415bb53cfd360f625d861066e747f8c57a0e1bc
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_DRAWABLESHAPE_JUCEHEADER__
27 #define __JUCE_DRAWABLESHAPE_JUCEHEADER__
29 #include "juce_Drawable.h"
30 #include "../contexts/juce_FillType.h"
31 #include "../colour/juce_ColourGradient.h"
32 #include "../../components/positioning/juce_RelativeCoordinatePositioner.h"
35 //==============================================================================
36 /**
37 A base class implementing common functionality for Drawable classes which
38 consist of some kind of filled and stroked outline.
40 @see DrawablePath, DrawableRectangle
42 class JUCE_API DrawableShape : public Drawable
44 protected:
45 //==============================================================================
46 DrawableShape();
47 DrawableShape (const DrawableShape&);
49 public:
50 /** Destructor. */
51 ~DrawableShape();
53 //==============================================================================
54 /** A FillType wrapper that allows the gradient coordinates to be implemented using RelativePoint.
56 class RelativeFillType
58 public:
59 RelativeFillType();
60 RelativeFillType (const FillType& fill);
61 RelativeFillType (const RelativeFillType&);
62 RelativeFillType& operator= (const RelativeFillType&);
64 bool operator== (const RelativeFillType&) const;
65 bool operator!= (const RelativeFillType&) const;
67 bool isDynamic() const;
68 bool recalculateCoords (Expression::Scope* scope);
70 void writeTo (ValueTree& v, ComponentBuilder::ImageProvider*, UndoManager*) const;
71 bool readFrom (const ValueTree& v, ComponentBuilder::ImageProvider*);
73 //==============================================================================
74 FillType fill;
75 RelativePoint gradientPoint1, gradientPoint2, gradientPoint3;
78 //==============================================================================
79 /** Sets a fill type for the path.
80 This colour is used to fill the path - if you don't want the path to be
81 filled (e.g. if you're just drawing an outline), set this to a transparent
82 colour.
84 @see setPath, setStrokeFill
86 void setFill (const FillType& newFill);
88 /** Sets a fill type for the path.
89 This colour is used to fill the path - if you don't want the path to be
90 filled (e.g. if you're just drawing an outline), set this to a transparent
91 colour.
93 @see setPath, setStrokeFill
95 void setFill (const RelativeFillType& newFill);
97 /** Returns the current fill type.
98 @see setFill
100 const RelativeFillType& getFill() const noexcept { return mainFill; }
102 /** Sets the fill type with which the outline will be drawn.
103 @see setFill
105 void setStrokeFill (const FillType& newStrokeFill);
107 /** Sets the fill type with which the outline will be drawn.
108 @see setFill
110 void setStrokeFill (const RelativeFillType& newStrokeFill);
112 /** Returns the current stroke fill.
113 @see setStrokeFill
115 const RelativeFillType& getStrokeFill() const noexcept { return strokeFill; }
117 /** Changes the properties of the outline that will be drawn around the path.
118 If the stroke has 0 thickness, no stroke will be drawn.
119 @see setStrokeThickness, setStrokeColour
121 void setStrokeType (const PathStrokeType& newStrokeType);
123 /** Changes the stroke thickness.
124 This is a shortcut for calling setStrokeType.
126 void setStrokeThickness (float newThickness);
128 /** Returns the current outline style. */
129 const PathStrokeType& getStrokeType() const noexcept { return strokeType; }
131 //==============================================================================
132 /** @internal */
133 class FillAndStrokeState : public Drawable::ValueTreeWrapperBase
135 public:
136 FillAndStrokeState (const ValueTree& state);
138 ValueTree getFillState (const Identifier& fillOrStrokeType);
139 RelativeFillType getFill (const Identifier& fillOrStrokeType, ComponentBuilder::ImageProvider*) const;
140 void setFill (const Identifier& fillOrStrokeType, const RelativeFillType& newFill,
141 ComponentBuilder::ImageProvider*, UndoManager*);
143 PathStrokeType getStrokeType() const;
144 void setStrokeType (const PathStrokeType& newStrokeType, UndoManager*);
146 static const Identifier type, colour, colours, fill, stroke, path, jointStyle, capStyle, strokeWidth,
147 gradientPoint1, gradientPoint2, gradientPoint3, radial, imageId, imageOpacity;
150 /** @internal */
151 Rectangle<float> getDrawableBounds() const;
152 /** @internal */
153 void paint (Graphics& g);
154 /** @internal */
155 bool hitTest (int x, int y);
157 protected:
158 //==============================================================================
159 /** Called when the cached path should be updated. */
160 void pathChanged();
161 /** Called when the cached stroke should be updated. */
162 void strokeChanged();
163 /** True if there's a stroke with a non-zero thickness and non-transparent colour. */
164 bool isStrokeVisible() const noexcept;
165 /** Updates the details from a FillAndStrokeState object, returning true if something changed. */
166 void refreshFillTypes (const FillAndStrokeState& newState, ComponentBuilder::ImageProvider*);
167 /** Writes the stroke and fill details to a FillAndStrokeState object. */
168 void writeTo (FillAndStrokeState& state, ComponentBuilder::ImageProvider*, UndoManager*) const;
170 //==============================================================================
171 PathStrokeType strokeType;
172 Path path, strokePath;
174 private:
175 class RelativePositioner;
176 RelativeFillType mainFill, strokeFill;
177 ScopedPointer<RelativeCoordinatePositionerBase> mainFillPositioner, strokeFillPositioner;
179 void setFillInternal (RelativeFillType& fill, const RelativeFillType& newFill,
180 ScopedPointer<RelativeCoordinatePositionerBase>& positioner);
182 DrawableShape& operator= (const DrawableShape&);
186 #endif // __JUCE_DRAWABLESHAPE_JUCEHEADER__