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.2KB

  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. */
  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() {}
  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 JUCE_API StartSubPath : public ElementBase
  76. {
  77. public:
  78. StartSubPath (const RelativePoint& pos);
  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. 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. void addToPath (Path& path, Expression::Scope*) const;
  103. RelativePoint* getControlPoints (int& numPoints);
  104. ElementBase* clone() const;
  105. RelativePoint endPoint;
  106. private:
  107. JUCE_DECLARE_NON_COPYABLE (LineTo)
  108. };
  109. //==============================================================================
  110. class JUCE_API QuadraticTo : public ElementBase
  111. {
  112. public:
  113. QuadraticTo (const RelativePoint& controlPoint, const RelativePoint& endPoint);
  114. ValueTree createTree() const;
  115. void addToPath (Path& path, Expression::Scope*) const;
  116. RelativePoint* getControlPoints (int& numPoints);
  117. ElementBase* clone() const;
  118. RelativePoint controlPoints[2];
  119. private:
  120. JUCE_DECLARE_NON_COPYABLE (QuadraticTo)
  121. };
  122. //==============================================================================
  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;
  129. RelativePoint* getControlPoints (int& numPoints);
  130. ElementBase* clone() const;
  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