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 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 void Start()
Start running this Tween, as configured.
-
inline void Stop()
Pause this Tween.
Private Functions
-
inline void AdvanceFrame()
Private Members
-
double duration
-
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
-
inline Tween(double d = 1.0, const Widget &t = nullptr)