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.

107 lines
3.5KB

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