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.

107 lines
3.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /**
  20. Defines a drop-shadow effect.
  21. */
  22. struct JUCE_API DropShadow
  23. {
  24. /** Creates a default drop-shadow effect. */
  25. DropShadow() noexcept;
  26. /** Creates a drop-shadow object with the given parameters. */
  27. DropShadow (Colour shadowColour, int radius, Point<int> offset) noexcept;
  28. /** Renders a drop-shadow based on the alpha-channel of the given image. */
  29. void drawForImage (Graphics& g, const Image& srcImage) const;
  30. /** Renders a drop-shadow based on the shape of a path. */
  31. void drawForPath (Graphics& g, const Path& path) const;
  32. /** Renders a drop-shadow for a rectangle.
  33. Note that for speed, this approximates the shadow using gradients.
  34. */
  35. void drawForRectangle (Graphics& g, const Rectangle<int>& area) const;
  36. /** The colour with which to render the shadow.
  37. In most cases you'll probably want to leave this as black with an alpha
  38. value of around 0.5
  39. */
  40. Colour colour;
  41. /** The approximate spread of the shadow. */
  42. int radius;
  43. /** The offset of the shadow. */
  44. Point<int> offset;
  45. };
  46. //==============================================================================
  47. /**
  48. An effect filter that adds a drop-shadow behind the image's content.
  49. (This will only work on images/components that aren't opaque, of course).
  50. When added to a component, this effect will draw a soft-edged
  51. shadow based on what gets drawn inside it. The shadow will also
  52. be applied to the component's children.
  53. For speed, this doesn't use a proper gaussian blur, but cheats by
  54. using a simple bilinear filter. If you need a really high-quality
  55. shadow, check out ImageConvolutionKernel::createGaussianBlur()
  56. @see Component::setComponentEffect
  57. */
  58. class JUCE_API DropShadowEffect : public ImageEffectFilter
  59. {
  60. public:
  61. //==============================================================================
  62. /** Creates a default drop-shadow effect.
  63. To customise the shadow's appearance, use the setShadowProperties() method.
  64. */
  65. DropShadowEffect();
  66. /** Destructor. */
  67. ~DropShadowEffect();
  68. //==============================================================================
  69. /** Sets up parameters affecting the shadow's appearance. */
  70. void setShadowProperties (const DropShadow& newShadow);
  71. //==============================================================================
  72. /** @internal */
  73. void applyEffect (Image& sourceImage, Graphics& destContext, float scaleFactor, float alpha);
  74. private:
  75. //==============================================================================
  76. DropShadow shadow;
  77. JUCE_LEAK_DETECTOR (DropShadowEffect)
  78. };