|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- /*
- ==============================================================================
-
- This file is part of the JUCE library.
- Copyright (c) 2020 - Raw Material Software Limited
-
- JUCE is an open source library subject to commercial or open-source
- licensing.
-
- By using JUCE, you agree to the terms of both the JUCE 6 End-User License
- Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
-
- End User License Agreement: www.juce.com/juce-6-licence
- Privacy Policy: www.juce.com/juce-privacy-policy
-
- Or: You may also use this code under the terms of the GPL v3 (see
- www.gnu.org/licenses).
-
- JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
- EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
- DISCLAIMED.
-
- ==============================================================================
- */
-
- namespace juce
- {
-
- //==============================================================================
- /**
- A path object that consists of RelativePoint coordinates rather than the normal fixed ones.
-
- One of these paths can be converted into a Path object for drawing and manipulation, but
- unlike a Path, its points can be dynamic instead of just fixed.
-
- @see RelativePoint, RelativeCoordinate
-
- @tags{GUI}
- */
- class JUCE_API RelativePointPath
- {
- public:
- //==============================================================================
- RelativePointPath();
- RelativePointPath (const RelativePointPath&);
- explicit RelativePointPath (const Path& path);
- ~RelativePointPath();
-
- bool operator== (const RelativePointPath&) const noexcept;
- bool operator!= (const RelativePointPath&) const noexcept;
-
- //==============================================================================
- /** Resolves this points in this path and adds them to a normal Path object. */
- void createPath (Path& path, Expression::Scope* scope) const;
-
- /** Returns true if the path contains any non-fixed points. */
- bool containsAnyDynamicPoints() const;
-
- /** Quickly swaps the contents of this path with another. */
- void swapWith (RelativePointPath&) noexcept;
-
- //==============================================================================
- /** The types of element that may be contained in this path.
- @see RelativePointPath::ElementBase
- */
- enum ElementType
- {
- nullElement,
- startSubPathElement,
- closeSubPathElement,
- lineToElement,
- quadraticToElement,
- cubicToElement
- };
-
- //==============================================================================
- /** Base class for the elements that make up a RelativePointPath.
- */
- class JUCE_API ElementBase
- {
- public:
- ElementBase (ElementType type);
- virtual ~ElementBase() = default;
- virtual void addToPath (Path& path, Expression::Scope*) const = 0;
- virtual RelativePoint* getControlPoints (int& numPoints) = 0;
- virtual ElementBase* clone() const = 0;
- bool isDynamic();
-
- const ElementType type;
-
- private:
- JUCE_DECLARE_NON_COPYABLE (ElementBase)
- };
-
- //==============================================================================
- /** Class for the start sub path element */
- class JUCE_API StartSubPath : public ElementBase
- {
- public:
- StartSubPath (const RelativePoint& pos);
- void addToPath (Path& path, Expression::Scope*) const override;
- RelativePoint* getControlPoints (int& numPoints) override;
- ElementBase* clone() const override;
-
- RelativePoint startPos;
-
- private:
- JUCE_DECLARE_NON_COPYABLE (StartSubPath)
- };
-
- //==============================================================================
- /** Class for the close sub path element */
- class JUCE_API CloseSubPath : public ElementBase
- {
- public:
- CloseSubPath();
- void addToPath (Path& path, Expression::Scope*) const override;
- RelativePoint* getControlPoints (int& numPoints) override;
- ElementBase* clone() const override;
-
- private:
- JUCE_DECLARE_NON_COPYABLE (CloseSubPath)
- };
-
- //==============================================================================
- /** Class for the line to element */
- class JUCE_API LineTo : public ElementBase
- {
- public:
- LineTo (const RelativePoint& endPoint);
- void addToPath (Path& path, Expression::Scope*) const override;
- RelativePoint* getControlPoints (int& numPoints) override;
- ElementBase* clone() const override;
-
- RelativePoint endPoint;
-
- private:
- JUCE_DECLARE_NON_COPYABLE (LineTo)
- };
-
- //==============================================================================
- /** Class for the quadratic to element */
- class JUCE_API QuadraticTo : public ElementBase
- {
- public:
- QuadraticTo (const RelativePoint& controlPoint, const RelativePoint& endPoint);
- ValueTree createTree() const;
- void addToPath (Path& path, Expression::Scope*) const override;
- RelativePoint* getControlPoints (int& numPoints) override;
- ElementBase* clone() const override;
-
- RelativePoint controlPoints[2];
-
- private:
- JUCE_DECLARE_NON_COPYABLE (QuadraticTo)
- };
-
- //==============================================================================
- /** Class for the cubic to element */
- class JUCE_API CubicTo : public ElementBase
- {
- public:
- CubicTo (const RelativePoint& controlPoint1, const RelativePoint& controlPoint2, const RelativePoint& endPoint);
- ValueTree createTree() const;
- void addToPath (Path& path, Expression::Scope*) const override;
- RelativePoint* getControlPoints (int& numPoints) override;
- ElementBase* clone() const override;
-
- RelativePoint controlPoints[3];
-
- private:
- JUCE_DECLARE_NON_COPYABLE (CubicTo)
- };
-
- //==============================================================================
- void addElement (ElementBase* newElement);
-
- //==============================================================================
- OwnedArray<ElementBase> elements;
- bool usesNonZeroWinding;
-
- private:
- class Positioner;
- friend class Positioner;
- bool containsDynamicPoints;
-
- void applyTo (DrawablePath& path) const;
-
- RelativePointPath& operator= (const RelativePointPath&);
- JUCE_LEAK_DETECTOR (RelativePointPath)
- };
-
- } // namespace juce
|