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_DrawableShape.h 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. A base class implementing common functionality for Drawable classes which
  23. consist of some kind of filled and stroked outline.
  24. @see DrawablePath, DrawableRectangle
  25. @tags{GUI}
  26. */
  27. class JUCE_API DrawableShape : public Drawable
  28. {
  29. protected:
  30. //==============================================================================
  31. DrawableShape();
  32. DrawableShape (const DrawableShape&);
  33. public:
  34. /** Destructor. */
  35. ~DrawableShape() override;
  36. //==============================================================================
  37. /** Sets a fill type for the path.
  38. This colour is used to fill the path - if you don't want the path to be
  39. filled (e.g. if you're just drawing an outline), set this to a transparent
  40. colour.
  41. @see setPath, setStrokeFill
  42. */
  43. void setFill (const FillType& newFill);
  44. /** Returns the current fill type.
  45. @see setFill
  46. */
  47. const FillType& getFill() const noexcept { return mainFill; }
  48. /** Sets the fill type with which the outline will be drawn.
  49. @see setFill
  50. */
  51. void setStrokeFill (const FillType& newStrokeFill);
  52. /** Returns the current stroke fill.
  53. @see setStrokeFill
  54. */
  55. const FillType& getStrokeFill() const noexcept { return strokeFill; }
  56. /** Changes the properties of the outline that will be drawn around the path.
  57. If the stroke has 0 thickness, no stroke will be drawn.
  58. @see setStrokeThickness, setStrokeColour
  59. */
  60. void setStrokeType (const PathStrokeType& newStrokeType);
  61. /** Changes the stroke thickness.
  62. This is a shortcut for calling setStrokeType.
  63. */
  64. void setStrokeThickness (float newThickness);
  65. /** Returns the current outline style. */
  66. const PathStrokeType& getStrokeType() const noexcept { return strokeType; }
  67. /** Provides a set of dash lengths to use for stroking the path. */
  68. void setDashLengths (const Array<float>& newDashLengths);
  69. /** Returns the set of dash lengths that the path is using. */
  70. const Array<float>& getDashLengths() const noexcept { return dashLengths; }
  71. //==============================================================================
  72. /** @internal */
  73. Rectangle<float> getDrawableBounds() const override;
  74. /** @internal */
  75. void paint (Graphics&) override;
  76. /** @internal */
  77. bool hitTest (int x, int y) override;
  78. /** @internal */
  79. bool replaceColour (Colour originalColour, Colour replacementColour) override;
  80. /** @internal */
  81. Path getOutlineAsPath() const override;
  82. protected:
  83. //==============================================================================
  84. /** Called when the cached path should be updated. */
  85. void pathChanged();
  86. /** Called when the cached stroke should be updated. */
  87. void strokeChanged();
  88. /** True if there's a stroke with a non-zero thickness and non-transparent colour. */
  89. bool isStrokeVisible() const noexcept;
  90. //==============================================================================
  91. PathStrokeType strokeType;
  92. Array<float> dashLengths;
  93. Path path, strokePath;
  94. private:
  95. FillType mainFill, strokeFill;
  96. DrawableShape& operator= (const DrawableShape&);
  97. };
  98. } // namespace juce