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.

juce_RelativePointPath.h 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. A path object that consists of RelativePoint coordinates rather than the normal fixed ones.
  23. One of these paths can be converted into a Path object for drawing and manipulation, but
  24. unlike a Path, its points can be dynamic instead of just fixed.
  25. @see RelativePoint, RelativeCoordinate
  26. @tags{GUI}
  27. */
  28. class JUCE_API RelativePointPath
  29. {
  30. public:
  31. //==============================================================================
  32. RelativePointPath();
  33. RelativePointPath (const RelativePointPath&);
  34. explicit RelativePointPath (const Path& path);
  35. ~RelativePointPath();
  36. bool operator== (const RelativePointPath&) const noexcept;
  37. bool operator!= (const RelativePointPath&) 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&) 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() = default;
  66. virtual void addToPath (Path& path, Expression::Scope*) const = 0;
  67. virtual RelativePoint* getControlPoints (int& numPoints) = 0;
  68. virtual ElementBase* clone() const = 0;
  69. bool isDynamic();
  70. const ElementType type;
  71. private:
  72. JUCE_DECLARE_NON_COPYABLE (ElementBase)
  73. };
  74. //==============================================================================
  75. /** Class for the start sub path element */
  76. class JUCE_API StartSubPath : public ElementBase
  77. {
  78. public:
  79. StartSubPath (const RelativePoint& pos);
  80. void addToPath (Path& path, Expression::Scope*) const override;
  81. RelativePoint* getControlPoints (int& numPoints) override;
  82. ElementBase* clone() const override;
  83. RelativePoint startPos;
  84. private:
  85. JUCE_DECLARE_NON_COPYABLE (StartSubPath)
  86. };
  87. //==============================================================================
  88. /** Class for the close sub path element */
  89. class JUCE_API CloseSubPath : public ElementBase
  90. {
  91. public:
  92. CloseSubPath();
  93. void addToPath (Path& path, Expression::Scope*) const override;
  94. RelativePoint* getControlPoints (int& numPoints) override;
  95. ElementBase* clone() const override;
  96. private:
  97. JUCE_DECLARE_NON_COPYABLE (CloseSubPath)
  98. };
  99. //==============================================================================
  100. /** Class for the line to element */
  101. class JUCE_API LineTo : public ElementBase
  102. {
  103. public:
  104. LineTo (const RelativePoint& endPoint);
  105. void addToPath (Path& path, Expression::Scope*) const override;
  106. RelativePoint* getControlPoints (int& numPoints) override;
  107. ElementBase* clone() const override;
  108. RelativePoint endPoint;
  109. private:
  110. JUCE_DECLARE_NON_COPYABLE (LineTo)
  111. };
  112. //==============================================================================
  113. /** Class for the quadratic to element */
  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 override;
  120. RelativePoint* getControlPoints (int& numPoints) override;
  121. ElementBase* clone() const override;
  122. RelativePoint controlPoints[2];
  123. private:
  124. JUCE_DECLARE_NON_COPYABLE (QuadraticTo)
  125. };
  126. //==============================================================================
  127. /** Class for the cubic to element */
  128. class JUCE_API CubicTo : public ElementBase
  129. {
  130. public:
  131. CubicTo (const RelativePoint& controlPoint1, const RelativePoint& controlPoint2, const RelativePoint& endPoint);
  132. ValueTree createTree() const;
  133. void addToPath (Path& path, Expression::Scope*) const override;
  134. RelativePoint* getControlPoints (int& numPoints) override;
  135. ElementBase* clone() const override;
  136. RelativePoint controlPoints[3];
  137. private:
  138. JUCE_DECLARE_NON_COPYABLE (CubicTo)
  139. };
  140. //==============================================================================
  141. void addElement (ElementBase* newElement);
  142. //==============================================================================
  143. OwnedArray<ElementBase> elements;
  144. bool usesNonZeroWinding;
  145. private:
  146. class Positioner;
  147. friend class Positioner;
  148. bool containsDynamicPoints;
  149. void applyTo (DrawablePath& path) const;
  150. RelativePointPath& operator= (const RelativePointPath&);
  151. JUCE_LEAK_DETECTOR (RelativePointPath)
  152. };
  153. } // namespace juce