/* ============================================================================== This file is part of the JUCE 6 technical preview. Copyright (c) 2020 - Raw Material Software Limited You may use this code under the terms of the GPL v3 (see www.gnu.org/licenses). For this technical preview, this file is not subject to commercial licensing. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE DISCLAIMED. ============================================================================== */ namespace juce { //============================================================================== /** Defines a drop-shadow effect. @tags{Graphics} */ struct JUCE_API DropShadow { /** Creates a default drop-shadow effect. */ DropShadow() = default; /** Creates a drop-shadow object with the given parameters. */ DropShadow (Colour shadowColour, int radius, Point offset) noexcept; /** Renders a drop-shadow based on the alpha-channel of the given image. */ void drawForImage (Graphics& g, const Image& srcImage) const; /** Renders a drop-shadow based on the shape of a path. */ void drawForPath (Graphics& g, const Path& path) const; /** Renders a drop-shadow for a rectangle. Note that for speed, this approximates the shadow using gradients. */ void drawForRectangle (Graphics& g, const Rectangle& area) const; /** The colour with which to render the shadow. In most cases you'll probably want to leave this as black with an alpha value of around 0.5 */ Colour colour { 0x90000000 }; /** The approximate spread of the shadow. */ int radius { 4 }; /** The offset of the shadow. */ Point offset; }; //============================================================================== /** An effect filter that adds a drop-shadow behind the image's content. (This will only work on images/components that aren't opaque, of course). When added to a component, this effect will draw a soft-edged shadow based on what gets drawn inside it. The shadow will also be applied to the component's children. For speed, this doesn't use a proper gaussian blur, but cheats by using a simple bilinear filter. If you need a really high-quality shadow, check out ImageConvolutionKernel::createGaussianBlur() @see Component::setComponentEffect @tags{Graphics} */ class JUCE_API DropShadowEffect : public ImageEffectFilter { public: //============================================================================== /** Creates a default drop-shadow effect. To customise the shadow's appearance, use the setShadowProperties() method. */ DropShadowEffect(); /** Destructor. */ ~DropShadowEffect() override; //============================================================================== /** Sets up parameters affecting the shadow's appearance. */ void setShadowProperties (const DropShadow& newShadow); //============================================================================== /** @internal */ void applyEffect (Image& sourceImage, Graphics& destContext, float scaleFactor, float alpha) override; private: //============================================================================== DropShadow shadow; JUCE_LEAK_DETECTOR (DropShadowEffect) }; } // namespace juce