Tween.hpp

A Tween manages the gradual shift in properties of one or more widgets over time.

To create a Tween, a duration must be specified, along with an optional default target. Once a Tween is setup, paths can be added to it, which represent the changes that should occur over the specified duration.

A path can be a function to call (with the 0.0 to 1.0 fraction of the time that’s gone by) or a variable to set to the current fraction. Dependants can also be set to refresh with each Tween update.

Available methods include: Tween & AddPath(std::function<void(double)> set_fun, double start_val, double end_val, std::function<double(double)> timing=LINEAR); Tween & AddPath(double & set_var, double start_val, double end_val, std::function<double(double)> timing=LINEAR); Tween & AddDependant(Widget w); void Start(); void Stop();

Todo:

Need to setup an AddPath that actually uses widgets and properties (stub in place).

Need a Reverse(), which swaps start and end positions.

Need a Reset()

class Tween
#include <Tween.hpp>

Public Functions

inline Tween(double d = 1.0, const Widget &t = nullptr)

Build a new tween, specifying the duration it should run for and the widget it should modify.

inline ~Tween()
inline double GetDuration() const

Retrieve the full duration of this Tween.

inline Widget GetDefaultTarget() const

Which widget does this Tween modify?

inline Tween &SetDuration(double d)

Change the duration of this Tween.

inline Tween &SetDefaultTarget(const Widget &w)

Change the target of this tween.

inline Tween &AddPath(std::function<void(double)> set_fun, double start_val, double end_val, std::function<double(double)> timing = LINEAR)

Alter the path of the change that this tween should take and the function it should call.

inline Tween &AddPath(double &set_var, double start_val, double end_val, std::function<double(double)> timing = LINEAR)

Alter the path of the change that this tween should take and the variable it should modify.

inline Tween &AddPath(Widget w, std::string setting, double start_val, double end_val)

Alter the path of the change that this tween should take and the widget setting it should alter. (TODO!)

inline Tween &AddUpdate(std::function<void(void)> ud_fun)

Add an additional function to update as the Tween runs.

inline Tween &AddDependant(Widget w)

Add a dependant Widget to update as the Tween runs.

inline void Start()

Start running this Tween, as configured.

inline void Stop()

Pause this Tween.

Private Functions

inline void AdvanceFrame()

Private Members

double duration
Widget default_target
vector<Path*> paths
vector<Event*> events
vector<std::function<void()>> update_funs
vector<Widget> dependants
bool running
size_t callback_id
double start_time
double cur_time
double run_time

Private Static Functions

static inline double LINEAR(double in)
struct Event

Public Members

double time
std::function<void()> trigger
struct Path

Public Functions

inline void Set(const double frac)

Public Members

std::function<void(double)> set_fun
double start_val
double end_val
std::function<double(double)> timing