Gin
Loading...
Searching...
No Matches
gin_animated.h File Reference

Classes

class  Transition
 Duration and easing of an animated change, CSS transition style. More...
struct  Interpolator< T >
 How Animated blends and compares values of a type. More...
struct  Interpolator< float >
 Floats cover any scalar, a font height or a corner radius alike. More...
struct  Interpolator< juce::Colour >
struct  Interpolator< juce::Rectangle< float > >
 Blends the edges, so a rectangle moving and resizing keeps its edges steady. More...
struct  Interpolator< juce::Rectangle< int > >
struct  Interpolator< juce::Font >
 Blends the height; the other attributes are the target's. More...
struct  Interpolator< juce::ColourGradient >
 Resamples both gradients onto the union of their stop positions and blends the colours there, and the end points. More...
class  AnimationDriver
 Ticks all running Animated and Crossfade values on the vertical blank of the window they show in. More...
class  AnimatedBase
 The non-template part of Animated and Crossfade: the owner, the property name, the running transition and the registration with the shared AnimationDriver. More...
class  Animated< T >
 A value that eases to a new target over a Transition and repaints its owner on every step. More...
class  AnimatedScale
 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...
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). More...
class  ImageFilter
 A chain of image filters (as CSS filter), applied in order with Gin's applyX functions, parsed from a spec string of names, each followed by its value where it takes one. More...
class  AnimatedImageFilter
 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...

Functions

std::optional< juce::Point< float > > parseTransformOrigin (const juce::String &origin)
 Parses a CSS transform-origin style string into a point relative to a component's bounds, (0, 0) its top left, (1, 1) its bottom right:
juce::AffineTransform scaleTransform (juce::Rectangle< int > bounds, float s, juce::Point< float > origin={ 0.5f, 0.5f })
 The transform that scales a component by s about a point relative to its bounds (see parseTransformOrigin), in its parent's coordinates as juce::Component::setTransform takes it.
Paint helpers

They take plain values, so Animated<T> members pass straight in through their implicit conversion; the Crossfade overloads draw both sides of a fade.

class Card : public juce::Component
{
public:
void paint (juce::Graphics& g) override
{
auto rc = getLocalBounds().toFloat();
gin::fillGradient (g, rc, 12.0f, fill);
gin::drawIcon (g, icon, rc.removeFromLeft (rc.getHeight()).reduced (8.0f), ink);
gin::drawText (g, title, rc, juce::Font (juce::FontOptions (20.0f)), ink, juce::Justification::centredLeft);
}
gin::Animated<juce::ColourGradient> fill { *this, "fill" }; // relative points, see fillGradient
gin::Animated<juce::Colour> ink { *this, "ink", juce::Colours::white };
gin::Crossfade<juce::Path> icon { *this, "icon" }; // relative paths, see drawIcon
gin::Crossfade<juce::String> title { *this, "title" };
};
void fillGradient (juce::Graphics &g, juce::Rectangle< float > area, float cornerRadius, const juce::ColourGradient &relativeGradient)
 Fills a rectangle, rounded when cornerRadius > 0, with a gradient whose points are relative to it: (0, 0) is its top left, (1, 1) its bottom right.
void drawText (juce::Graphics &g, const Crossfade< juce::String > &text, juce::Rectangle< float > area, const juce::Font &font, juce::Colour colour, juce::Justification justification)
 Draws a Crossfade<juce::String> with juce::Graphics::drawText (ellipsis on overflow): the previous text at the colour's alpha times 1 - progress, the current one times progress.
void drawIcon (juce::Graphics &g, const juce::Path &relativePath, juce::Rectangle< float > area, juce::Colour colour)
 Fills a path whose coordinates are relative: (0, 0)..(1, 1) maps onto the largest square centred in the area.
void drawIcon (juce::Graphics &g, const Crossfade< juce::Path > &icon, juce::Rectangle< float > area, juce::Colour colour)
 Draws a Crossfade<juce::Path> of relative paths (see the other drawIcon), the previous icon fading out as the current one fades in.
void drawImage (juce::Graphics &g, const Crossfade< MipMap > &image, juce::Rectangle< float > area, juce::RectanglePlacement placement=0)
 Draws a Crossfade<MipMap> with drawBlend: the previous image at full opacity, the current one on top at the fade's progress, so an opaque image never shows through to the background mid-fade.