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.

115 lines
3.8KB

  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. Defines a drop-shadow effect.
  24. @tags{Graphics}
  25. */
  26. struct JUCE_API DropShadow
  27. {
  28. /** Creates a default drop-shadow effect. */
  29. DropShadow() = default;
  30. /** Creates a drop-shadow object with the given parameters. */
  31. DropShadow (Colour shadowColour, int radius, Point<int> offset) noexcept;
  32. /** Renders a drop-shadow based on the alpha-channel of the given image. */
  33. void drawForImage (Graphics& g, const Image& srcImage) const;
  34. /** Renders a drop-shadow based on the shape of a path. */
  35. void drawForPath (Graphics& g, const Path& path) const;
  36. /** Renders a drop-shadow for a rectangle.
  37. Note that for speed, this approximates the shadow using gradients.
  38. */
  39. void drawForRectangle (Graphics& g, const Rectangle<int>& area) const;
  40. /** The colour with which to render the shadow.
  41. In most cases you'll probably want to leave this as black with an alpha
  42. value of around 0.5
  43. */
  44. Colour colour { 0x90000000 };
  45. /** The approximate spread of the shadow. */
  46. int radius { 4 };
  47. /** The offset of the shadow. */
  48. Point<int> offset;
  49. };
  50. //==============================================================================
  51. /**
  52. An effect filter that adds a drop-shadow behind the image's content.
  53. (This will only work on images/components that aren't opaque, of course).
  54. When added to a component, this effect will draw a soft-edged
  55. shadow based on what gets drawn inside it. The shadow will also
  56. be applied to the component's children.
  57. For speed, this doesn't use a proper gaussian blur, but cheats by
  58. using a simple bilinear filter. If you need a really high-quality
  59. shadow, check out ImageConvolutionKernel::createGaussianBlur()
  60. @see Component::setComponentEffect
  61. @tags{Graphics}
  62. */
  63. class JUCE_API DropShadowEffect : public ImageEffectFilter
  64. {
  65. public:
  66. //==============================================================================
  67. /** Creates a default drop-shadow effect.
  68. To customise the shadow's appearance, use the setShadowProperties() method.
  69. */
  70. DropShadowEffect();
  71. /** Destructor. */
  72. ~DropShadowEffect();
  73. //==============================================================================
  74. /** Sets up parameters affecting the shadow's appearance. */
  75. void setShadowProperties (const DropShadow& newShadow);
  76. //==============================================================================
  77. /** @internal */
  78. void applyEffect (Image& sourceImage, Graphics& destContext, float scaleFactor, float alpha) override;
  79. private:
  80. //==============================================================================
  81. DropShadow shadow;
  82. JUCE_LEAK_DETECTOR (DropShadowEffect)
  83. };
  84. } // namespace juce