juce_DrawableShape.h 4.4 KB

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