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.

190 lines
7.4KB

  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. #ifndef JUCE_DRAWABLESHAPE_H_INCLUDED
  18. #define JUCE_DRAWABLESHAPE_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A base class implementing common functionality for Drawable classes which
  22. consist of some kind of filled and stroked outline.
  23. @see DrawablePath, DrawableRectangle
  24. */
  25. class JUCE_API DrawableShape : public Drawable
  26. {
  27. protected:
  28. //==============================================================================
  29. DrawableShape();
  30. DrawableShape (const DrawableShape&);
  31. public:
  32. /** Destructor. */
  33. ~DrawableShape();
  34. //==============================================================================
  35. /** A FillType wrapper that allows the gradient coordinates to be implemented using RelativePoint.
  36. */
  37. class RelativeFillType
  38. {
  39. public:
  40. RelativeFillType();
  41. RelativeFillType (const FillType& fill);
  42. RelativeFillType (const RelativeFillType&);
  43. RelativeFillType& operator= (const RelativeFillType&);
  44. bool operator== (const RelativeFillType&) const;
  45. bool operator!= (const RelativeFillType&) const;
  46. bool isDynamic() const;
  47. bool recalculateCoords (Expression::Scope* scope);
  48. void writeTo (ValueTree& v, ComponentBuilder::ImageProvider*, UndoManager*) const;
  49. bool readFrom (const ValueTree& v, ComponentBuilder::ImageProvider*);
  50. //==============================================================================
  51. FillType fill;
  52. RelativePoint gradientPoint1, gradientPoint2, gradientPoint3;
  53. };
  54. //==============================================================================
  55. /** Sets a fill type for the path.
  56. This colour is used to fill the path - if you don't want the path to be
  57. filled (e.g. if you're just drawing an outline), set this to a transparent
  58. colour.
  59. @see setPath, setStrokeFill
  60. */
  61. void setFill (const FillType& newFill);
  62. /** Sets a fill type for the path.
  63. This colour is used to fill the path - if you don't want the path to be
  64. filled (e.g. if you're just drawing an outline), set this to a transparent
  65. colour.
  66. @see setPath, setStrokeFill
  67. */
  68. void setFill (const RelativeFillType& newFill);
  69. /** Returns the current fill type.
  70. @see setFill
  71. */
  72. const RelativeFillType& getFill() const noexcept { return mainFill; }
  73. /** Sets the fill type with which the outline will be drawn.
  74. @see setFill
  75. */
  76. void setStrokeFill (const FillType& newStrokeFill);
  77. /** Sets the fill type with which the outline will be drawn.
  78. @see setFill
  79. */
  80. void setStrokeFill (const RelativeFillType& newStrokeFill);
  81. /** Returns the current stroke fill.
  82. @see setStrokeFill
  83. */
  84. const RelativeFillType& getStrokeFill() const noexcept { return strokeFill; }
  85. /** Changes the properties of the outline that will be drawn around the path.
  86. If the stroke has 0 thickness, no stroke will be drawn.
  87. @see setStrokeThickness, setStrokeColour
  88. */
  89. void setStrokeType (const PathStrokeType& newStrokeType);
  90. /** Changes the stroke thickness.
  91. This is a shortcut for calling setStrokeType.
  92. */
  93. void setStrokeThickness (float newThickness);
  94. /** Returns the current outline style. */
  95. const PathStrokeType& getStrokeType() const noexcept { return strokeType; }
  96. /** Provides a set of dash lengths to use for stroking the path. */
  97. void setDashLengths (const Array<float>& newDashLengths);
  98. /** Returns the set of dash lengths that the path is using. */
  99. const Array<float>& getDashLengths() const noexcept { return dashLengths; };
  100. //==============================================================================
  101. /** @internal */
  102. class FillAndStrokeState : public Drawable::ValueTreeWrapperBase
  103. {
  104. public:
  105. FillAndStrokeState (const ValueTree& state);
  106. ValueTree getFillState (const Identifier& fillOrStrokeType);
  107. RelativeFillType getFill (const Identifier& fillOrStrokeType, ComponentBuilder::ImageProvider*) const;
  108. void setFill (const Identifier& fillOrStrokeType, const RelativeFillType& newFill,
  109. ComponentBuilder::ImageProvider*, UndoManager*);
  110. PathStrokeType getStrokeType() const;
  111. void setStrokeType (const PathStrokeType& newStrokeType, UndoManager*);
  112. static const Identifier type, colour, colours, fill, stroke, path, jointStyle, capStyle, strokeWidth,
  113. gradientPoint1, gradientPoint2, gradientPoint3, radial, imageId, imageOpacity;
  114. };
  115. /** @internal */
  116. Rectangle<float> getDrawableBounds() const override;
  117. /** @internal */
  118. void paint (Graphics&) override;
  119. /** @internal */
  120. bool hitTest (int x, int y) override;
  121. /** @internal */
  122. bool replaceColour (Colour originalColour, Colour replacementColour) override;
  123. protected:
  124. //==============================================================================
  125. /** Called when the cached path should be updated. */
  126. void pathChanged();
  127. /** Called when the cached stroke should be updated. */
  128. void strokeChanged();
  129. /** True if there's a stroke with a non-zero thickness and non-transparent colour. */
  130. bool isStrokeVisible() const noexcept;
  131. /** Updates the details from a FillAndStrokeState object, returning true if something changed. */
  132. void refreshFillTypes (const FillAndStrokeState& newState, ComponentBuilder::ImageProvider*);
  133. /** Writes the stroke and fill details to a FillAndStrokeState object. */
  134. void writeTo (FillAndStrokeState& state, ComponentBuilder::ImageProvider*, UndoManager*) const;
  135. //==============================================================================
  136. PathStrokeType strokeType;
  137. Array<float> dashLengths;
  138. Path path, strokePath;
  139. private:
  140. class RelativePositioner;
  141. RelativeFillType mainFill, strokeFill;
  142. ScopedPointer<RelativeCoordinatePositionerBase> mainFillPositioner, strokeFillPositioner;
  143. void setFillInternal (RelativeFillType& fill, const RelativeFillType& newFill,
  144. ScopedPointer<RelativeCoordinatePositionerBase>& positioner);
  145. DrawableShape& operator= (const DrawableShape&);
  146. };
  147. #endif // JUCE_DRAWABLESHAPE_H_INCLUDED