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.

120 lines
4.1KB

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