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.

195 lines
6.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  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. @tags{GUI}
  28. */
  29. class JUCE_API RelativePointPath
  30. {
  31. public:
  32. //==============================================================================
  33. RelativePointPath();
  34. RelativePointPath (const RelativePointPath&);
  35. explicit RelativePointPath (const Path& path);
  36. ~RelativePointPath();
  37. bool operator== (const RelativePointPath&) const noexcept;
  38. bool operator!= (const RelativePointPath&) const noexcept;
  39. //==============================================================================
  40. /** Resolves this points in this path and adds them to a normal Path object. */
  41. void createPath (Path& path, Expression::Scope* scope) const;
  42. /** Returns true if the path contains any non-fixed points. */
  43. bool containsAnyDynamicPoints() const;
  44. /** Quickly swaps the contents of this path with another. */
  45. void swapWith (RelativePointPath&) noexcept;
  46. //==============================================================================
  47. /** The types of element that may be contained in this path.
  48. @see RelativePointPath::ElementBase
  49. */
  50. enum ElementType
  51. {
  52. nullElement,
  53. startSubPathElement,
  54. closeSubPathElement,
  55. lineToElement,
  56. quadraticToElement,
  57. cubicToElement
  58. };
  59. //==============================================================================
  60. /** Base class for the elements that make up a RelativePointPath.
  61. */
  62. class JUCE_API ElementBase
  63. {
  64. public:
  65. ElementBase (ElementType type);
  66. virtual ~ElementBase() {}
  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 for the start sub path element */
  77. class JUCE_API StartSubPath : public ElementBase
  78. {
  79. public:
  80. StartSubPath (const RelativePoint& pos);
  81. void addToPath (Path& path, Expression::Scope*) const override;
  82. RelativePoint* getControlPoints (int& numPoints) override;
  83. ElementBase* clone() const override;
  84. RelativePoint startPos;
  85. private:
  86. JUCE_DECLARE_NON_COPYABLE (StartSubPath)
  87. };
  88. //==============================================================================
  89. /** Class for the close sub path element */
  90. class JUCE_API CloseSubPath : public ElementBase
  91. {
  92. public:
  93. CloseSubPath();
  94. void addToPath (Path& path, Expression::Scope*) const override;
  95. RelativePoint* getControlPoints (int& numPoints) override;
  96. ElementBase* clone() const override;
  97. private:
  98. JUCE_DECLARE_NON_COPYABLE (CloseSubPath)
  99. };
  100. //==============================================================================
  101. /** Class for the line to element */
  102. class JUCE_API LineTo : public ElementBase
  103. {
  104. public:
  105. LineTo (const RelativePoint& endPoint);
  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 for the quadratic to element */
  115. class JUCE_API QuadraticTo : public ElementBase
  116. {
  117. public:
  118. QuadraticTo (const RelativePoint& controlPoint, const RelativePoint& endPoint);
  119. ValueTree createTree() const;
  120. void addToPath (Path& path, Expression::Scope*) const override;
  121. RelativePoint* getControlPoints (int& numPoints) override;
  122. ElementBase* clone() const override;
  123. RelativePoint controlPoints[2];
  124. private:
  125. JUCE_DECLARE_NON_COPYABLE (QuadraticTo)
  126. };
  127. //==============================================================================
  128. /** Class for the cubic to element */
  129. class JUCE_API CubicTo : public ElementBase
  130. {
  131. public:
  132. CubicTo (const RelativePoint& controlPoint1, const RelativePoint& controlPoint2, const RelativePoint& endPoint);
  133. ValueTree createTree() const;
  134. void addToPath (Path& path, Expression::Scope*) const override;
  135. RelativePoint* getControlPoints (int& numPoints) override;
  136. ElementBase* clone() const override;
  137. RelativePoint controlPoints[3];
  138. private:
  139. JUCE_DECLARE_NON_COPYABLE (CubicTo)
  140. };
  141. //==============================================================================
  142. void addElement (ElementBase* newElement);
  143. //==============================================================================
  144. OwnedArray<ElementBase> elements;
  145. bool usesNonZeroWinding;
  146. private:
  147. class Positioner;
  148. friend class Positioner;
  149. bool containsDynamicPoints;
  150. void applyTo (DrawablePath& path) const;
  151. RelativePointPath& operator= (const RelativePointPath&);
  152. JUCE_LEAK_DETECTOR (RelativePointPath)
  153. };
  154. } // namespace juce