Gin
Loading...
Searching...
No Matches
Crossfade< T > Class Template Reference

A discrete value that can't blend, like a text or an icon: on a change the previous value fades out while the new one fades in, over a Transition found exactly like Animated's (layout "transition" by property name, preset, inline spec). More...

#include <gin_animated.h>

Inheritance diagram for Crossfade< T >:

Public Member Functions

 Crossfade (juce::Component &owner, const juce::String &property={}, T initial=T())
const T & getCurrent () const
 The incoming value, the only one once the fade ends.
const T & getPrevious () const
 The outgoing value; equals getCurrent() when no fade runs.
float getProgress () const
 0 shows only the previous value, 1 only the current one
template<typename PaintFn>
void draw (PaintFn &&paintOne) const
 Paints both sides of the fade with your own drawing: calls paintOne (value, opacity) for the previous value at 1 - progress and the current one at progress, skipping a side at opacity 0.
void setValue (T newValue)
 Jumps to the value, stopping any fade.
void updateTarget (T newValue)
 Changes the incoming value without restarting a running fade, e.g.
void setTarget (T newTarget)
 Fades to the value with the owner's transition for the property.
void setTarget (T newTarget, const juce::String &nameOrSpec)
 Fades to the value with a preset name (looked up from the owner up), an inline spec like "150 inOutQuad" or "none".
void setTarget (T newTarget, const Transition &t)
 Fades to the value with an explicit Transition.
Public Member Functions inherited from AnimatedBase
 AnimatedBase (juce::Component &owner, const juce::String &property)
virtual ~AnimatedBase ()
bool isAnimating () const
 True while a transition runs.
juce::Component * getOwner () const
 The owning component, nullptr once it was deleted.
const juce::String & getProperty () const
 The name the layout's "transition" entries know this value by.
Transition getTransition () const
 The transition setTarget (value) uses: the owner's for the property, see Transition::forProperty.

Additional Inherited Members

Public Attributes inherited from AnimatedBase
std::function< void()> onChange
 Called on every change of the current value (each animation step, and jumps), after the owner was asked to repaint.
Protected Member Functions inherited from AnimatedBase
bool start (const Transition &t)
 Returns false when the change has to apply at once: an instant transition or an owner not on screen.
void stop ()
void changed ()
virtual void valueChanged ()
 For subclasses that apply the value somewhere: called on every change, before onChange.
float getLastProgress () const
 The eased progress of the latest step of the running transition.

Detailed Description

template<typename T>
class Crossfade< T >

A discrete value that can't blend, like a text or an icon: on a change the previous value fades out while the new one fades in, over a Transition found exactly like Animated's (layout "transition" by property name, preset, inline spec).

Painting draws getPrevious() at an opacity of 1 - getProgress() and getCurrent() at getProgress(), or uses the drawText / drawIcon helpers which do just that. T needs copy assignment and operator==; juce::String and juce::Path are the usual ones.

A new target while a fade runs restarts it from 0, with the value that showed more so far as the one fading out. updateTarget() changes the incoming value without a restart.

// layout json: { "id": "status", "transition": { "caption": "150 inOutQuad" } }
class Status : public juce::Component
{
public:
void setOnline (bool online) { caption.setTarget (online ? "Online" : "Offline"); }
void paint (juce::Graphics& g) override
{
gin::drawText (g, caption, getLocalBounds().toFloat(), juce::Font (juce::FontOptions (15.0f)),
juce::Colours::white, juce::Justification::centred);
}
private:
gin::Crossfade<juce::String> caption { *this, "caption", "Offline" };
};
See also
Animated, drawText, drawIcon

Constructor & Destructor Documentation

◆ Crossfade()

template<typename T>
Crossfade< T >::Crossfade ( juce::Component & owner,
const juce::String & property = {},
T initial = T() )
Parameters
ownerThe component that repaints on every step and whose layout transitions apply
propertyThe name the layout's "transition" object knows this value by
initialThe starting value, shown alone

Member Function Documentation

◆ getCurrent()

template<typename T>
const T & Crossfade< T >::getCurrent ( ) const

The incoming value, the only one once the fade ends.

◆ getPrevious()

template<typename T>
const T & Crossfade< T >::getPrevious ( ) const

The outgoing value; equals getCurrent() when no fade runs.

◆ getProgress()

template<typename T>
float Crossfade< T >::getProgress ( ) const

0 shows only the previous value, 1 only the current one

◆ draw()

template<typename T>
template<typename PaintFn>
void Crossfade< T >::draw ( PaintFn && paintOne) const

Paints both sides of the fade with your own drawing: calls paintOne (value, opacity) for the previous value at 1 - progress and the current one at progress, skipping a side at opacity 0.

Multiply your colours' alpha by the opacity.

weight.draw ([&] (int w, float opacity)
{
g.setColour (juce::Colours::white.withMultipliedAlpha (opacity));
g.setFont (juce::FontOptions (14.0f).withStyle (w > 500 ? "Bold" : "Regular"));
g.drawText (label, area, juce::Justification::centred);
});

◆ setValue()

template<typename T>
void Crossfade< T >::setValue ( T newValue)

Jumps to the value, stopping any fade.

References AnimatedBase::changed(), and AnimatedBase::stop().

Referenced by setTarget(), setTarget(), and updateTarget().

◆ updateTarget()

template<typename T>
void Crossfade< T >::updateTarget ( T newValue)

Changes the incoming value without restarting a running fade, e.g.

a counter that keeps changing while it fades in. Without a fade it jumps.

References AnimatedBase::changed(), AnimatedBase::isAnimating(), and setValue().

◆ setTarget() [1/3]

template<typename T>
void Crossfade< T >::setTarget ( T newTarget)

Fades to the value with the owner's transition for the property.

References AnimatedBase::getTransition(), and setTarget().

Referenced by setTarget(), and setTarget().

◆ setTarget() [2/3]

template<typename T>
void Crossfade< T >::setTarget ( T newTarget,
const juce::String & nameOrSpec )

Fades to the value with a preset name (looked up from the owner up), an inline spec like "150 inOutQuad" or "none".

References AnimatedBase::getOwner(), Transition::resolve(), setTarget(), and setValue().

◆ setTarget() [3/3]

template<typename T>
void Crossfade< T >::setTarget ( T newTarget,
const Transition & t )

Fades to the value with an explicit Transition.

References AnimatedBase::changed(), setValue(), and AnimatedBase::start().


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