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.

142 lines
5.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /**
  20. A drawable object which renders a filled or outlined shape.
  21. For details on how to change the fill and stroke, see the DrawableShape class.
  22. @see Drawable, DrawableShape
  23. */
  24. class JUCE_API DrawablePath : public DrawableShape
  25. {
  26. public:
  27. //==============================================================================
  28. /** Creates a DrawablePath. */
  29. DrawablePath();
  30. DrawablePath (const DrawablePath&);
  31. /** Destructor. */
  32. ~DrawablePath();
  33. //==============================================================================
  34. /** Changes the path that will be drawn.
  35. @see setFillColour, setStrokeType
  36. */
  37. void setPath (const Path& newPath);
  38. /** Sets the path using a RelativePointPath.
  39. Calling this will set up a Component::Positioner to automatically update the path
  40. if any of the points in the source path are dynamic.
  41. */
  42. void setPath (const RelativePointPath& newPath);
  43. /** Returns the current path. */
  44. const Path& getPath() const;
  45. /** Returns the current path for the outline. */
  46. const Path& getStrokePath() const;
  47. //==============================================================================
  48. /** @internal */
  49. Drawable* createCopy() const;
  50. /** @internal */
  51. void refreshFromValueTree (const ValueTree& tree, ComponentBuilder& builder);
  52. /** @internal */
  53. ValueTree createValueTree (ComponentBuilder::ImageProvider* imageProvider) const;
  54. /** @internal */
  55. static const Identifier valueTreeType;
  56. //==============================================================================
  57. /** Internally-used class for wrapping a DrawablePath's state into a ValueTree. */
  58. class ValueTreeWrapper : public DrawableShape::FillAndStrokeState
  59. {
  60. public:
  61. ValueTreeWrapper (const ValueTree& state);
  62. bool usesNonZeroWinding() const;
  63. void setUsesNonZeroWinding (bool b, UndoManager* undoManager);
  64. class Element
  65. {
  66. public:
  67. explicit Element (const ValueTree& state);
  68. ~Element();
  69. const Identifier getType() const noexcept { return state.getType(); }
  70. int getNumControlPoints() const noexcept;
  71. RelativePoint getControlPoint (int index) const;
  72. Value getControlPointValue (int index, UndoManager*);
  73. RelativePoint getStartPoint() const;
  74. RelativePoint getEndPoint() const;
  75. void setControlPoint (int index, const RelativePoint& point, UndoManager*);
  76. float getLength (Expression::Scope*) const;
  77. ValueTreeWrapper getParent() const;
  78. Element getPreviousElement() const;
  79. String getModeOfEndPoint() const;
  80. void setModeOfEndPoint (const String& newMode, UndoManager*);
  81. void convertToLine (UndoManager*);
  82. void convertToCubic (Expression::Scope*, UndoManager*);
  83. void convertToPathBreak (UndoManager* undoManager);
  84. ValueTree insertPoint (Point<float> targetPoint, Expression::Scope*, UndoManager*);
  85. void removePoint (UndoManager* undoManager);
  86. float findProportionAlongLine (Point<float> targetPoint, Expression::Scope*) const;
  87. static const Identifier mode, startSubPathElement, closeSubPathElement,
  88. lineToElement, quadraticToElement, cubicToElement;
  89. static const char* cornerMode;
  90. static const char* roundedMode;
  91. static const char* symmetricMode;
  92. ValueTree state;
  93. };
  94. ValueTree getPathState();
  95. void readFrom (const RelativePointPath& relativePath, UndoManager* undoManager);
  96. void writeTo (RelativePointPath& relativePath) const;
  97. static const Identifier nonZeroWinding, point1, point2, point3;
  98. };
  99. private:
  100. //==============================================================================
  101. ScopedPointer<RelativePointPath> relativePath;
  102. class RelativePositioner;
  103. friend class RelativePositioner;
  104. void applyRelativePath (const RelativePointPath&, Expression::Scope*);
  105. DrawablePath& operator= (const DrawablePath&);
  106. JUCE_LEAK_DETECTOR (DrawablePath)
  107. };