SvgAnimator Class

Platform Contract

#include <vortex/vsvganim.h>

Public Functions

SvgAnimator(const std::string & svg)
~SvgAnimator()
SvgAnimator(SvgAnimator &&)
SvgAnimator & operator=(SvgAnimator &&)
SvgAnimator(const SvgAnimator &)
SvgAnimator & operator=(const SvgAnimator &)
bool animated()
double duration_ms()
std::string bake(double time_ms)

Detailed Description

Animator that plays an SVG's animations on platforms whose SVG renderer only draws still images, by turning each frame into a still SVG.

Browsers play SMIL animations (<animate> and <animateTransform>) and CSS @keyframes themselves, so only the desktop and Android widgets that show SVGs use an SvgAnimator. For each frame, bake() returns the SVG as it looks at that time, with the animated values written in as plain attributes, and the widget hands that to the platform's SVG renderer:

Vortex::SvgAnimator animator(svg_text);

if (animator.animated())
    start_frame_timer();

// On each frame
draw_svg(animator.bake(elapsed_ms));

It animates transforms (CSS motion paths among them), opacity, and numeric attributes like cx, width, and stroke-width. Colors, like fill and stroke, stay at their values in the source.

Creating an animator parses the SVG, which is the slow step, while bake() is fast enough to call on every frame. Keep one for as long as its widget shows the same SVG.

Member Function Documentation

SvgAnimator(const std::string & svg)

No description available.

~SvgAnimator()

No description available.

SvgAnimator(SvgAnimator &&)

No description available.

SvgAnimator & operator=(SvgAnimator &&)

No description available.

SvgAnimator(const SvgAnimator &)

Not copyable, since it owns the parsed SVG. Move it instead.

SvgAnimator & operator=(const SvgAnimator &)

No description available.

bool animated()

Returns true when the SVG has an animation, so its widget needs a frame timer.

Without one, every bake() returns the same frame, so one call is enough.

double duration_ms()

Returns the length (ms) of the longest animation, or 0 without any, like for choosing a timer that loops cleanly.

std::string bake(double time_ms)

Returns the SVG as it looks time_ms after its animations start.

The frame keeps the source's text everywhere except the animated values, which are written in as attributes, and the animation declarations, which are removed.

› Documentation
Appearance
Theme
—