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

An Animated<float> scale applied to its owner with juce::Component::setTransform, about an origin relative to the owner's bounds (its centre by default), so it zooms from the centre instead of towards the bottom right. More...

#include <gin_animated.h>

Inheritance diagram for AnimatedScale:

Public Member Functions

 AnimatedScale (juce::Component &owner, const juce::String &property="scale", float initial=1.0f)
 ~AnimatedScale () override
void setOrigin (juce::Point< float > relativeOrigin)
 Sets the pivot relative to the owner's bounds, (0.5, 0.5) its centre.
juce::Point< float > getOrigin () const
Public Member Functions inherited from Animated< float >
 Animated (juce::Component &owner, const juce::String &property={}, float initial=float())
const float & get () const
 Returns the current, possibly mid-transition, value.
 operator const float & () const
 Returns the current value, so an Animated<T> can be passed where a T is expected.
const float & getTarget () const
 Returns the value the transition heads for, the current one when none runs.
void setValue (float newValue)
 Jumps to the value, stopping any transition.
void setTarget (float newTarget)
 Eases to the value with the owner's transition for the property.
void updateTarget (float newTarget)
 Changes the target of a running transition without restarting it: start value, start time and easing stay, so it still ends on time.
void followTarget (float newTarget)
 For a target that streams in, like live colours or a meter: starts a transition when none runs, otherwise moves the running one's target (updateTarget()).
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 ()
float getLastProgress () const
 The eased progress of the latest step of the running transition.

Detailed Description

An Animated<float> scale applied to its owner with juce::Component::setTransform, about an origin relative to the owner's bounds (its centre by default), so it zooms from the centre instead of towards the bottom right.

The pivot follows the owner when it moves or resizes, also during a "bounds" transition. A scale of 1 clears the transform.

It owns the owner's transform: a transform set elsewhere is replaced on the next change. A component that needs its own transform too should be scaled through a parent or child. Hit testing follows the transform; JUCE repaints the enlarged area. Decorations painted by an ancestor (shadows) can follow it through a juce::ComponentListener on the owner: setTransform sends componentMovedOrResized (c, false, false).

The layout's "scale" entry uses it as well (with "origin"); give a component a scale from the layout or from code, not both.

// layout json: { "id": "tile", "transition": { "scale": "60 inOutQuad" } }
class Tile : public juce::Button
{
public:
void buttonStateChanged() override { zoom.setTarget (isOver() ? 1.03f : 1.0f); }
private:
gin::AnimatedScale zoom { *this };
};

Constructor & Destructor Documentation

◆ AnimatedScale()

AnimatedScale::AnimatedScale ( juce::Component & owner,
const juce::String & property = "scale",
float initial = 1.0f )
Parameters
ownerThe component that scales
propertyThe name the layout's "transition" object knows this value by
initialThe starting scale

◆ ~AnimatedScale()

AnimatedScale::~AnimatedScale ( )
override

Member Function Documentation

◆ setOrigin()

void AnimatedScale::setOrigin ( juce::Point< float > relativeOrigin)

Sets the pivot relative to the owner's bounds, (0.5, 0.5) its centre.

◆ getOrigin()

juce::Point< float > AnimatedScale::getOrigin ( ) const

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