Add remaining files
[juce-lv2.git] / juce / source / src / gui / components / positioning / juce_RelativePointPath.h
blobb0e4a4e8e169503bdbab670c730a1e5d56f7961b
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_RELATIVEPOINTPATH_JUCEHEADER__
27 #define __JUCE_RELATIVEPOINTPATH_JUCEHEADER__
29 #include "juce_RelativePoint.h"
30 #include "../../../containers/juce_OwnedArray.h"
31 #include "../../../containers/juce_ValueTree.h"
32 class DrawablePath;
34 //==============================================================================
35 /**
36 A path object that consists of RelativePoint coordinates rather than the normal fixed ones.
38 One of these paths can be converted into a Path object for drawing and manipulation, but
39 unlike a Path, its points can be dynamic instead of just fixed.
41 @see RelativePoint, RelativeCoordinate
43 class JUCE_API RelativePointPath
45 public:
46 //==============================================================================
47 RelativePointPath();
48 RelativePointPath (const RelativePointPath& other);
49 explicit RelativePointPath (const Path& path);
50 ~RelativePointPath();
52 bool operator== (const RelativePointPath& other) const noexcept;
53 bool operator!= (const RelativePointPath& other) const noexcept;
55 //==============================================================================
56 /** Resolves this points in this path and adds them to a normal Path object. */
57 void createPath (Path& path, Expression::Scope* scope) const;
59 /** Returns true if the path contains any non-fixed points. */
60 bool containsAnyDynamicPoints() const;
62 /** Quickly swaps the contents of this path with another. */
63 void swapWith (RelativePointPath& other) noexcept;
65 //==============================================================================
66 /** The types of element that may be contained in this path.
67 @see RelativePointPath::ElementBase
69 enum ElementType
71 nullElement,
72 startSubPathElement,
73 closeSubPathElement,
74 lineToElement,
75 quadraticToElement,
76 cubicToElement
79 //==============================================================================
80 /** Base class for the elements that make up a RelativePointPath.
82 class JUCE_API ElementBase
84 public:
85 ElementBase (ElementType type);
86 virtual ~ElementBase() {}
87 virtual ValueTree createTree() const = 0;
88 virtual void addToPath (Path& path, Expression::Scope*) const = 0;
89 virtual RelativePoint* getControlPoints (int& numPoints) = 0;
90 virtual ElementBase* clone() const = 0;
91 bool isDynamic();
93 const ElementType type;
95 private:
96 JUCE_DECLARE_NON_COPYABLE (ElementBase);
99 //==============================================================================
100 class JUCE_API StartSubPath : public ElementBase
102 public:
103 StartSubPath (const RelativePoint& pos);
104 ValueTree createTree() const;
105 void addToPath (Path& path, Expression::Scope*) const;
106 RelativePoint* getControlPoints (int& numPoints);
107 ElementBase* clone() const;
109 RelativePoint startPos;
111 private:
112 JUCE_DECLARE_NON_COPYABLE (StartSubPath);
115 //==============================================================================
116 class JUCE_API CloseSubPath : public ElementBase
118 public:
119 CloseSubPath();
120 ValueTree createTree() const;
121 void addToPath (Path& path, Expression::Scope*) const;
122 RelativePoint* getControlPoints (int& numPoints);
123 ElementBase* clone() const;
125 private:
126 JUCE_DECLARE_NON_COPYABLE (CloseSubPath);
129 //==============================================================================
130 class JUCE_API LineTo : public ElementBase
132 public:
133 LineTo (const RelativePoint& endPoint);
134 ValueTree createTree() const;
135 void addToPath (Path& path, Expression::Scope*) const;
136 RelativePoint* getControlPoints (int& numPoints);
137 ElementBase* clone() const;
139 RelativePoint endPoint;
141 private:
142 JUCE_DECLARE_NON_COPYABLE (LineTo);
145 //==============================================================================
146 class JUCE_API QuadraticTo : public ElementBase
148 public:
149 QuadraticTo (const RelativePoint& controlPoint, const RelativePoint& endPoint);
150 ValueTree createTree() const;
151 void addToPath (Path& path, Expression::Scope*) const;
152 RelativePoint* getControlPoints (int& numPoints);
153 ElementBase* clone() const;
155 RelativePoint controlPoints[2];
157 private:
158 JUCE_DECLARE_NON_COPYABLE (QuadraticTo);
161 //==============================================================================
162 class JUCE_API CubicTo : public ElementBase
164 public:
165 CubicTo (const RelativePoint& controlPoint1, const RelativePoint& controlPoint2, const RelativePoint& endPoint);
166 ValueTree createTree() const;
167 void addToPath (Path& path, Expression::Scope*) const;
168 RelativePoint* getControlPoints (int& numPoints);
169 ElementBase* clone() const;
171 RelativePoint controlPoints[3];
173 private:
174 JUCE_DECLARE_NON_COPYABLE (CubicTo);
177 //==============================================================================
178 void addElement (ElementBase* newElement);
180 //==============================================================================
181 OwnedArray <ElementBase> elements;
182 bool usesNonZeroWinding;
184 private:
185 class Positioner;
186 friend class Positioner;
187 bool containsDynamicPoints;
189 void applyTo (DrawablePath& path) const;
191 RelativePointPath& operator= (const RelativePointPath&);
192 JUCE_LEAK_DETECTOR (RelativePointPath);
196 #endif // __JUCE_RELATIVEPOINTPATH_JUCEHEADER__