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

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_RELATIVEPOINTPATH_JUCEHEADER__
  19. #define __JUCE_RELATIVEPOINTPATH_JUCEHEADER__
  20. #include "juce_RelativePoint.h"
  21. class DrawablePath;
  22. //==============================================================================
  23. /**
  24. A path object that consists of RelativePoint coordinates rather than the normal fixed ones.
  25. One of these paths can be converted into a Path object for drawing and manipulation, but
  26. unlike a Path, its points can be dynamic instead of just fixed.
  27. @see RelativePoint, RelativeCoordinate
  28. */
  29. class JUCE_API RelativePointPath
  30. {
  31. public:
  32. //==============================================================================
  33. RelativePointPath();
  34. RelativePointPath (const RelativePointPath& other);
  35. explicit RelativePointPath (const Path& path);
  36. ~RelativePointPath();
  37. bool operator== (const RelativePointPath& other) const noexcept;
  38. bool operator!= (const RelativePointPath& other) 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& other) 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 ValueTree createTree() const = 0;
  68. virtual void addToPath (Path& path, Expression::Scope*) const = 0;
  69. virtual RelativePoint* getControlPoints (int& numPoints) = 0;
  70. virtual ElementBase* clone() const = 0;
  71. bool isDynamic();
  72. const ElementType type;
  73. private:
  74. JUCE_DECLARE_NON_COPYABLE (ElementBase);
  75. };
  76. //==============================================================================
  77. class JUCE_API StartSubPath : public ElementBase
  78. {
  79. public:
  80. StartSubPath (const RelativePoint& pos);
  81. ValueTree createTree() const;
  82. void addToPath (Path& path, Expression::Scope*) const;
  83. RelativePoint* getControlPoints (int& numPoints);
  84. ElementBase* clone() const;
  85. RelativePoint startPos;
  86. private:
  87. JUCE_DECLARE_NON_COPYABLE (StartSubPath);
  88. };
  89. //==============================================================================
  90. class JUCE_API CloseSubPath : public ElementBase
  91. {
  92. public:
  93. CloseSubPath();
  94. ValueTree createTree() const;
  95. void addToPath (Path& path, Expression::Scope*) const;
  96. RelativePoint* getControlPoints (int& numPoints);
  97. ElementBase* clone() const;
  98. private:
  99. JUCE_DECLARE_NON_COPYABLE (CloseSubPath);
  100. };
  101. //==============================================================================
  102. class JUCE_API LineTo : public ElementBase
  103. {
  104. public:
  105. LineTo (const RelativePoint& endPoint);
  106. ValueTree createTree() const;
  107. void addToPath (Path& path, Expression::Scope*) const;
  108. RelativePoint* getControlPoints (int& numPoints);
  109. ElementBase* clone() const;
  110. RelativePoint endPoint;
  111. private:
  112. JUCE_DECLARE_NON_COPYABLE (LineTo);
  113. };
  114. //==============================================================================
  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;
  121. RelativePoint* getControlPoints (int& numPoints);
  122. ElementBase* clone() const;
  123. RelativePoint controlPoints[2];
  124. private:
  125. JUCE_DECLARE_NON_COPYABLE (QuadraticTo);
  126. };
  127. //==============================================================================
  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;
  134. RelativePoint* getControlPoints (int& numPoints);
  135. ElementBase* clone() const;
  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. #endif // __JUCE_RELATIVEPOINTPATH_JUCEHEADER__