The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

194 lines
6.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __JUCE_RELATIVEPOINTPATH_JUCEHEADER__
  18. #define __JUCE_RELATIVEPOINTPATH_JUCEHEADER__
  19. #include "juce_RelativePoint.h"
  20. class DrawablePath;
  21. //==============================================================================
  22. /**
  23. A path object that consists of RelativePoint coordinates rather than the normal fixed ones.
  24. One of these paths can be converted into a Path object for drawing and manipulation, but
  25. unlike a Path, its points can be dynamic instead of just fixed.
  26. @see RelativePoint, RelativeCoordinate
  27. */
  28. class JUCE_API RelativePointPath
  29. {
  30. public:
  31. //==============================================================================
  32. RelativePointPath();
  33. RelativePointPath (const RelativePointPath& other);
  34. explicit RelativePointPath (const Path& path);
  35. ~RelativePointPath();
  36. bool operator== (const RelativePointPath& other) const noexcept;
  37. bool operator!= (const RelativePointPath& other) const noexcept;
  38. //==============================================================================
  39. /** Resolves this points in this path and adds them to a normal Path object. */
  40. void createPath (Path& path, Expression::Scope* scope) const;
  41. /** Returns true if the path contains any non-fixed points. */
  42. bool containsAnyDynamicPoints() const;
  43. /** Quickly swaps the contents of this path with another. */
  44. void swapWith (RelativePointPath& other) noexcept;
  45. //==============================================================================
  46. /** The types of element that may be contained in this path.
  47. @see RelativePointPath::ElementBase
  48. */
  49. enum ElementType
  50. {
  51. nullElement,
  52. startSubPathElement,
  53. closeSubPathElement,
  54. lineToElement,
  55. quadraticToElement,
  56. cubicToElement
  57. };
  58. //==============================================================================
  59. /** Base class for the elements that make up a RelativePointPath.
  60. */
  61. class JUCE_API ElementBase
  62. {
  63. public:
  64. ElementBase (ElementType type);
  65. virtual ~ElementBase() {}
  66. virtual ValueTree createTree() const = 0;
  67. virtual void addToPath (Path& path, Expression::Scope*) const = 0;
  68. virtual RelativePoint* getControlPoints (int& numPoints) = 0;
  69. virtual ElementBase* clone() const = 0;
  70. bool isDynamic();
  71. const ElementType type;
  72. private:
  73. JUCE_DECLARE_NON_COPYABLE (ElementBase)
  74. };
  75. //==============================================================================
  76. class JUCE_API StartSubPath : public ElementBase
  77. {
  78. public:
  79. StartSubPath (const RelativePoint& pos);
  80. ValueTree createTree() const;
  81. void addToPath (Path& path, Expression::Scope*) const;
  82. RelativePoint* getControlPoints (int& numPoints);
  83. ElementBase* clone() const;
  84. RelativePoint startPos;
  85. private:
  86. JUCE_DECLARE_NON_COPYABLE (StartSubPath)
  87. };
  88. //==============================================================================
  89. class JUCE_API CloseSubPath : public ElementBase
  90. {
  91. public:
  92. CloseSubPath();
  93. ValueTree createTree() const;
  94. void addToPath (Path& path, Expression::Scope*) const;
  95. RelativePoint* getControlPoints (int& numPoints);
  96. ElementBase* clone() const;
  97. private:
  98. JUCE_DECLARE_NON_COPYABLE (CloseSubPath)
  99. };
  100. //==============================================================================
  101. class JUCE_API LineTo : public ElementBase
  102. {
  103. public:
  104. LineTo (const RelativePoint& endPoint);
  105. ValueTree createTree() const;
  106. void addToPath (Path& path, Expression::Scope*) const;
  107. RelativePoint* getControlPoints (int& numPoints);
  108. ElementBase* clone() const;
  109. RelativePoint endPoint;
  110. private:
  111. JUCE_DECLARE_NON_COPYABLE (LineTo)
  112. };
  113. //==============================================================================
  114. class JUCE_API QuadraticTo : public ElementBase
  115. {
  116. public:
  117. QuadraticTo (const RelativePoint& controlPoint, const RelativePoint& endPoint);
  118. ValueTree createTree() const;
  119. void addToPath (Path& path, Expression::Scope*) const;
  120. RelativePoint* getControlPoints (int& numPoints);
  121. ElementBase* clone() const;
  122. RelativePoint controlPoints[2];
  123. private:
  124. JUCE_DECLARE_NON_COPYABLE (QuadraticTo)
  125. };
  126. //==============================================================================
  127. class JUCE_API CubicTo : public ElementBase
  128. {
  129. public:
  130. CubicTo (const RelativePoint& controlPoint1, const RelativePoint& controlPoint2, const RelativePoint& endPoint);
  131. ValueTree createTree() const;
  132. void addToPath (Path& path, Expression::Scope*) const;
  133. RelativePoint* getControlPoints (int& numPoints);
  134. ElementBase* clone() const;
  135. RelativePoint controlPoints[3];
  136. private:
  137. JUCE_DECLARE_NON_COPYABLE (CubicTo)
  138. };
  139. //==============================================================================
  140. void addElement (ElementBase* newElement);
  141. //==============================================================================
  142. OwnedArray <ElementBase> elements;
  143. bool usesNonZeroWinding;
  144. private:
  145. class Positioner;
  146. friend class Positioner;
  147. bool containsDynamicPoints;
  148. void applyTo (DrawablePath& path) const;
  149. RelativePointPath& operator= (const RelativePointPath&);
  150. JUCE_LEAK_DETECTOR (RelativePointPath)
  151. };
  152. #endif // __JUCE_RELATIVEPOINTPATH_JUCEHEADER__