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.

188 lines
6.4KB

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