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_DrawablePath.h 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef JUCE_DRAWABLEPATH_H_INCLUDED
  18. #define JUCE_DRAWABLEPATH_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A drawable object which renders a filled or outlined shape.
  22. For details on how to change the fill and stroke, see the DrawableShape class.
  23. @see Drawable, DrawableShape
  24. */
  25. class JUCE_API DrawablePath : public DrawableShape
  26. {
  27. public:
  28. //==============================================================================
  29. /** Creates a DrawablePath. */
  30. DrawablePath();
  31. DrawablePath (const DrawablePath& other);
  32. /** Destructor. */
  33. ~DrawablePath();
  34. //==============================================================================
  35. /** Changes the path that will be drawn.
  36. @see setFillColour, setStrokeType
  37. */
  38. void setPath (const Path& newPath);
  39. /** Sets the path using a RelativePointPath.
  40. Calling this will set up a Component::Positioner to automatically update the path
  41. if any of the points in the source path are dynamic.
  42. */
  43. void setPath (const RelativePointPath& newPath);
  44. /** Returns the current path. */
  45. const Path& getPath() const;
  46. /** Returns the current path for the outline. */
  47. const Path& getStrokePath() const;
  48. //==============================================================================
  49. /** @internal */
  50. Drawable* createCopy() const;
  51. /** @internal */
  52. void refreshFromValueTree (const ValueTree& tree, ComponentBuilder& builder);
  53. /** @internal */
  54. ValueTree createValueTree (ComponentBuilder::ImageProvider* imageProvider) const;
  55. /** @internal */
  56. static const Identifier valueTreeType;
  57. //==============================================================================
  58. /** Internally-used class for wrapping a DrawablePath's state into a ValueTree. */
  59. class ValueTreeWrapper : public DrawableShape::FillAndStrokeState
  60. {
  61. public:
  62. ValueTreeWrapper (const ValueTree& state);
  63. bool usesNonZeroWinding() const;
  64. void setUsesNonZeroWinding (bool b, UndoManager* undoManager);
  65. class Element
  66. {
  67. public:
  68. explicit Element (const ValueTree& state);
  69. ~Element();
  70. const Identifier getType() const noexcept { return state.getType(); }
  71. int getNumControlPoints() const noexcept;
  72. RelativePoint getControlPoint (int index) const;
  73. Value getControlPointValue (int index, UndoManager*);
  74. RelativePoint getStartPoint() const;
  75. RelativePoint getEndPoint() const;
  76. void setControlPoint (int index, const RelativePoint& point, UndoManager*);
  77. float getLength (Expression::Scope*) const;
  78. ValueTreeWrapper getParent() const;
  79. Element getPreviousElement() const;
  80. String getModeOfEndPoint() const;
  81. void setModeOfEndPoint (const String& newMode, UndoManager*);
  82. void convertToLine (UndoManager*);
  83. void convertToCubic (Expression::Scope*, UndoManager*);
  84. void convertToPathBreak (UndoManager* undoManager);
  85. ValueTree insertPoint (Point<float> targetPoint, Expression::Scope*, UndoManager*);
  86. void removePoint (UndoManager* undoManager);
  87. float findProportionAlongLine (Point<float> targetPoint, Expression::Scope*) const;
  88. static const Identifier mode, startSubPathElement, closeSubPathElement,
  89. lineToElement, quadraticToElement, cubicToElement;
  90. static const char* cornerMode;
  91. static const char* roundedMode;
  92. static const char* symmetricMode;
  93. ValueTree state;
  94. };
  95. ValueTree getPathState();
  96. void readFrom (const RelativePointPath& path, UndoManager* undoManager);
  97. void writeTo (RelativePointPath& path) const;
  98. static const Identifier nonZeroWinding, point1, point2, point3;
  99. };
  100. private:
  101. //==============================================================================
  102. ScopedPointer<RelativePointPath> relativePath;
  103. class RelativePositioner;
  104. friend class RelativePositioner;
  105. void applyRelativePath (const RelativePointPath&, Expression::Scope*);
  106. DrawablePath& operator= (const DrawablePath&);
  107. JUCE_LEAK_DETECTOR (DrawablePath)
  108. };
  109. #endif // JUCE_DRAWABLEPATH_H_INCLUDED