Audio plugin host https://kx.studio/carla
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.

192 lines
6.5KB

  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_H_INCLUDED
  18. #define JUCE_RELATIVEPOINTPATH_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A path object that consists of RelativePoint coordinates rather than the normal fixed ones.
  22. One of these paths can be converted into a Path object for drawing and manipulation, but
  23. unlike a Path, its points can be dynamic instead of just fixed.
  24. @see RelativePoint, RelativeCoordinate
  25. */
  26. class JUCE_API RelativePointPath
  27. {
  28. public:
  29. //==============================================================================
  30. RelativePointPath();
  31. RelativePointPath (const RelativePointPath& other);
  32. explicit RelativePointPath (const Path& path);
  33. ~RelativePointPath();
  34. bool operator== (const RelativePointPath& other) const noexcept;
  35. bool operator!= (const RelativePointPath& other) const noexcept;
  36. //==============================================================================
  37. /** Resolves this points in this path and adds them to a normal Path object. */
  38. void createPath (Path& path, Expression::Scope* scope) const;
  39. /** Returns true if the path contains any non-fixed points. */
  40. bool containsAnyDynamicPoints() const;
  41. /** Quickly swaps the contents of this path with another. */
  42. void swapWith (RelativePointPath& other) noexcept;
  43. //==============================================================================
  44. /** The types of element that may be contained in this path.
  45. @see RelativePointPath::ElementBase
  46. */
  47. enum ElementType
  48. {
  49. nullElement,
  50. startSubPathElement,
  51. closeSubPathElement,
  52. lineToElement,
  53. quadraticToElement,
  54. cubicToElement
  55. };
  56. //==============================================================================
  57. /** Base class for the elements that make up a RelativePointPath.
  58. */
  59. class JUCE_API ElementBase
  60. {
  61. public:
  62. ElementBase (ElementType type);
  63. virtual ~ElementBase() {}
  64. virtual ValueTree createTree() const = 0;
  65. virtual void addToPath (Path& path, Expression::Scope*) const = 0;
  66. virtual RelativePoint* getControlPoints (int& numPoints) = 0;
  67. virtual ElementBase* clone() const = 0;
  68. bool isDynamic();
  69. const ElementType type;
  70. private:
  71. JUCE_DECLARE_NON_COPYABLE (ElementBase)
  72. };
  73. //==============================================================================
  74. class JUCE_API StartSubPath : public ElementBase
  75. {
  76. public:
  77. StartSubPath (const RelativePoint& pos);
  78. ValueTree createTree() const;
  79. void addToPath (Path& path, Expression::Scope*) const;
  80. RelativePoint* getControlPoints (int& numPoints);
  81. ElementBase* clone() const;
  82. RelativePoint startPos;
  83. private:
  84. JUCE_DECLARE_NON_COPYABLE (StartSubPath)
  85. };
  86. //==============================================================================
  87. class JUCE_API CloseSubPath : public ElementBase
  88. {
  89. public:
  90. CloseSubPath();
  91. ValueTree createTree() const;
  92. void addToPath (Path& path, Expression::Scope*) const;
  93. RelativePoint* getControlPoints (int& numPoints);
  94. ElementBase* clone() const;
  95. private:
  96. JUCE_DECLARE_NON_COPYABLE (CloseSubPath)
  97. };
  98. //==============================================================================
  99. class JUCE_API LineTo : public ElementBase
  100. {
  101. public:
  102. LineTo (const RelativePoint& endPoint);
  103. ValueTree createTree() const;
  104. void addToPath (Path& path, Expression::Scope*) const;
  105. RelativePoint* getControlPoints (int& numPoints);
  106. ElementBase* clone() const;
  107. RelativePoint endPoint;
  108. private:
  109. JUCE_DECLARE_NON_COPYABLE (LineTo)
  110. };
  111. //==============================================================================
  112. class JUCE_API QuadraticTo : public ElementBase
  113. {
  114. public:
  115. QuadraticTo (const RelativePoint& controlPoint, const RelativePoint& endPoint);
  116. ValueTree createTree() const;
  117. void addToPath (Path& path, Expression::Scope*) const;
  118. RelativePoint* getControlPoints (int& numPoints);
  119. ElementBase* clone() const;
  120. RelativePoint controlPoints[2];
  121. private:
  122. JUCE_DECLARE_NON_COPYABLE (QuadraticTo)
  123. };
  124. //==============================================================================
  125. class JUCE_API CubicTo : public ElementBase
  126. {
  127. public:
  128. CubicTo (const RelativePoint& controlPoint1, const RelativePoint& controlPoint2, const RelativePoint& endPoint);
  129. ValueTree createTree() const;
  130. void addToPath (Path& path, Expression::Scope*) const;
  131. RelativePoint* getControlPoints (int& numPoints);
  132. ElementBase* clone() const;
  133. RelativePoint controlPoints[3];
  134. private:
  135. JUCE_DECLARE_NON_COPYABLE (CubicTo)
  136. };
  137. //==============================================================================
  138. void addElement (ElementBase* newElement);
  139. //==============================================================================
  140. OwnedArray <ElementBase> elements;
  141. bool usesNonZeroWinding;
  142. private:
  143. class Positioner;
  144. friend class Positioner;
  145. bool containsDynamicPoints;
  146. void applyTo (DrawablePath& path) const;
  147. RelativePointPath& operator= (const RelativePointPath&);
  148. JUCE_LEAK_DETECTOR (RelativePointPath)
  149. };
  150. #endif // JUCE_RELATIVEPOINTPATH_H_INCLUDED