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.

187 lines
6.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. //==============================================================================
  16. /**
  17. A path object that consists of RelativePoint coordinates rather than the normal fixed ones.
  18. One of these paths can be converted into a Path object for drawing and manipulation, but
  19. unlike a Path, its points can be dynamic instead of just fixed.
  20. @see RelativePoint, RelativeCoordinate
  21. @tags{GUI}
  22. */
  23. class JUCE_API RelativePointPath
  24. {
  25. public:
  26. //==============================================================================
  27. RelativePointPath();
  28. RelativePointPath (const RelativePointPath&);
  29. explicit RelativePointPath (const Path& path);
  30. ~RelativePointPath();
  31. bool operator== (const RelativePointPath&) const noexcept;
  32. bool operator!= (const RelativePointPath&) const noexcept;
  33. //==============================================================================
  34. /** Resolves this points in this path and adds them to a normal Path object. */
  35. void createPath (Path& path, Expression::Scope* scope) const;
  36. /** Returns true if the path contains any non-fixed points. */
  37. bool containsAnyDynamicPoints() const;
  38. /** Quickly swaps the contents of this path with another. */
  39. void swapWith (RelativePointPath&) noexcept;
  40. //==============================================================================
  41. /** The types of element that may be contained in this path.
  42. @see RelativePointPath::ElementBase
  43. */
  44. enum ElementType
  45. {
  46. nullElement,
  47. startSubPathElement,
  48. closeSubPathElement,
  49. lineToElement,
  50. quadraticToElement,
  51. cubicToElement
  52. };
  53. //==============================================================================
  54. /** Base class for the elements that make up a RelativePointPath.
  55. */
  56. class JUCE_API ElementBase
  57. {
  58. public:
  59. ElementBase (ElementType type);
  60. virtual ~ElementBase() = default;
  61. virtual void addToPath (Path& path, Expression::Scope*) const = 0;
  62. virtual RelativePoint* getControlPoints (int& numPoints) = 0;
  63. virtual ElementBase* clone() const = 0;
  64. bool isDynamic();
  65. const ElementType type;
  66. private:
  67. JUCE_DECLARE_NON_COPYABLE (ElementBase)
  68. };
  69. //==============================================================================
  70. /** Class for the start sub path element */
  71. class JUCE_API StartSubPath : public ElementBase
  72. {
  73. public:
  74. StartSubPath (const RelativePoint& pos);
  75. void addToPath (Path& path, Expression::Scope*) const override;
  76. RelativePoint* getControlPoints (int& numPoints) override;
  77. ElementBase* clone() const override;
  78. RelativePoint startPos;
  79. private:
  80. JUCE_DECLARE_NON_COPYABLE (StartSubPath)
  81. };
  82. //==============================================================================
  83. /** Class for the close sub path element */
  84. class JUCE_API CloseSubPath : public ElementBase
  85. {
  86. public:
  87. CloseSubPath();
  88. void addToPath (Path& path, Expression::Scope*) const override;
  89. RelativePoint* getControlPoints (int& numPoints) override;
  90. ElementBase* clone() const override;
  91. private:
  92. JUCE_DECLARE_NON_COPYABLE (CloseSubPath)
  93. };
  94. //==============================================================================
  95. /** Class for the line to element */
  96. class JUCE_API LineTo : public ElementBase
  97. {
  98. public:
  99. LineTo (const RelativePoint& endPoint);
  100. void addToPath (Path& path, Expression::Scope*) const override;
  101. RelativePoint* getControlPoints (int& numPoints) override;
  102. ElementBase* clone() const override;
  103. RelativePoint endPoint;
  104. private:
  105. JUCE_DECLARE_NON_COPYABLE (LineTo)
  106. };
  107. //==============================================================================
  108. /** Class for the quadratic to element */
  109. class JUCE_API QuadraticTo : public ElementBase
  110. {
  111. public:
  112. QuadraticTo (const RelativePoint& controlPoint, const RelativePoint& endPoint);
  113. ValueTree createTree() const;
  114. void addToPath (Path& path, Expression::Scope*) const override;
  115. RelativePoint* getControlPoints (int& numPoints) override;
  116. ElementBase* clone() const override;
  117. RelativePoint controlPoints[2];
  118. private:
  119. JUCE_DECLARE_NON_COPYABLE (QuadraticTo)
  120. };
  121. //==============================================================================
  122. /** Class for the cubic to element */
  123. class JUCE_API CubicTo : public ElementBase
  124. {
  125. public:
  126. CubicTo (const RelativePoint& controlPoint1, const RelativePoint& controlPoint2, const RelativePoint& endPoint);
  127. ValueTree createTree() const;
  128. void addToPath (Path& path, Expression::Scope*) const override;
  129. RelativePoint* getControlPoints (int& numPoints) override;
  130. ElementBase* clone() const override;
  131. RelativePoint controlPoints[3];
  132. private:
  133. JUCE_DECLARE_NON_COPYABLE (CubicTo)
  134. };
  135. //==============================================================================
  136. void addElement (ElementBase* newElement);
  137. //==============================================================================
  138. OwnedArray<ElementBase> elements;
  139. bool usesNonZeroWinding;
  140. private:
  141. class Positioner;
  142. friend class Positioner;
  143. bool containsDynamicPoints;
  144. void applyTo (DrawablePath& path) const;
  145. RelativePointPath& operator= (const RelativePointPath&);
  146. JUCE_LEAK_DETECTOR (RelativePointPath)
  147. };
  148. } // namespace juce