Gin
Loading...
Searching...
No Matches
AnimatedImageFilter Class Reference

An image and an ImageFilter version of it, blended by an Animated<float> amount: 0 shows the image, 1 the filtered one, e.g. More...

#include <gin_animated.h>

Public Member Functions

 AnimatedImageFilter (juce::Component &owner, const juce::String &property="imageFilter")
 ~AnimatedImageFilter ()
void setImage (const MipMap &image)
 Sets the image; the filtered version is built again if it differs.
void setFilter (const ImageFilter &filter)
 Sets the filter; the filtered version is built again if it differs.
void setFilter (const juce::String &spec)
void draw (juce::Graphics &g, juce::Rectangle< float > area, juce::RectanglePlacement placement=0) const
 Draws the blend at the amount's current value.
const MipMap & getImage () const
const MipMap & getFilteredImage () const

Public Attributes

Animated< float > amount
 0 = the image, 1 = the filtered one

Detailed Description

An image and an ImageFilter version of it, blended by an Animated<float> amount: 0 shows the image, 1 the filtered one, e.g.

a contrast boost while hovered. Only what is drawn through draw() is filtered, never the owner's other painting or its children.

The filter is applied once to the full size image and a second MipMap built from the result; that happens again only when the image or the filter changes, so painting at any size or scale (HiDPI) costs two MipMap::draw calls at most (see drawBlend).

The amount's transition comes from the layout like any Animated's ("imageFilter" by default). The owner's "states" (see States) drive it: a state with an "imageFilter" spec sets the filter and eases the amount to 1 while it is active, back to 0 after:

// layout json: { "id": "cover", "states": { "hover": { "imageFilter": "contrast 30 saturation 120" } },
// "transition": { "imageFilter": "150 outQuad" } }
class Cover : public juce::Component
{
public:
Cover() { image.setImage (gin::MipMap (loadCover())); }
void paint (juce::Graphics& g) override { image.draw (g, getLocalBounds().toFloat()); }
private:
gin::AnimatedImageFilter image { *this };
};

Without states, set the filter and drive amount yourself.

Constructor & Destructor Documentation

◆ AnimatedImageFilter()

AnimatedImageFilter::AnimatedImageFilter ( juce::Component & owner,
const juce::String & property = "imageFilter" )
Parameters
ownerThe component that repaints on every step, whose layout transitions and states apply
propertyThe name the layout's "transition" object knows the amount by

◆ ~AnimatedImageFilter()

AnimatedImageFilter::~AnimatedImageFilter ( )

Member Function Documentation

◆ setImage()

void AnimatedImageFilter::setImage ( const MipMap & image)

Sets the image; the filtered version is built again if it differs.

◆ setFilter() [1/2]

void AnimatedImageFilter::setFilter ( const ImageFilter & filter)

Sets the filter; the filtered version is built again if it differs.

An invalid spec asserts and counts as no filter.

◆ setFilter() [2/2]

void AnimatedImageFilter::setFilter ( const juce::String & spec)

◆ draw()

void AnimatedImageFilter::draw ( juce::Graphics & g,
juce::Rectangle< float > area,
juce::RectanglePlacement placement = 0 ) const

Draws the blend at the amount's current value.

◆ getImage()

const MipMap & AnimatedImageFilter::getImage ( ) const

◆ getFilteredImage()

const MipMap & AnimatedImageFilter::getFilteredImage ( ) const

Member Data Documentation

◆ amount

Animated<float> AnimatedImageFilter::amount

0 = the image, 1 = the filtered one


The documentation for this class was generated from the following file: