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_DropShadowEffect.h 3.8KB

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