2018-06-17 20:34:53 +08:00
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
This file is part of the JUCE library.
|
|
|
|
Copyright (c) 2017 - ROLI Ltd.
|
|
|
|
|
|
|
|
JUCE is an open source library subject to commercial or open-source
|
|
|
|
licensing.
|
|
|
|
|
|
|
|
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
|
|
|
|
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
|
|
|
|
27th April 2017).
|
|
|
|
|
|
|
|
End User License Agreement: www.juce.com/juce-5-licence
|
|
|
|
Privacy Policy: www.juce.com/juce-5-privacy-policy
|
|
|
|
|
|
|
|
Or: You may also use this code under the terms of the GPL v3 (see
|
|
|
|
www.gnu.org/licenses).
|
|
|
|
|
|
|
|
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. */
|
2019-06-23 03:41:38 +08:00
|
|
|
DropShadow() = default;
|
2018-06-17 20:34:53 +08:00
|
|
|
|
|
|
|
/** Creates a drop-shadow object with the given parameters. */
|
|
|
|
DropShadow (Colour shadowColour, int radius, Point<int> 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<int>& 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
|
|
|
|
*/
|
2019-06-23 03:41:38 +08:00
|
|
|
Colour colour { 0x90000000 };
|
2018-06-17 20:34:53 +08:00
|
|
|
|
|
|
|
/** The approximate spread of the shadow. */
|
2019-06-23 03:41:38 +08:00
|
|
|
int radius { 4 };
|
2018-06-17 20:34:53 +08:00
|
|
|
|
|
|
|
/** The offset of the shadow. */
|
|
|
|
Point<int> 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. */
|
2019-06-23 03:41:38 +08:00
|
|
|
~DropShadowEffect() override;
|
2018-06-17 20:34:53 +08:00
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
/** 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
|