tweeny_tween(3)

tween< T, Ts >(3) Tweeny tween< T, Ts >(3)

NAME

tween< T, Ts >

Detailed Description

template<typename T, typename... Ts>

class tweeny::tween< T, Ts >" The tween class is the core class of tweeny. It controls the interpolation steps, easings and durations.

It should not be constructed manually but rather from tweeny::from, to facilitate template argument deduction (and also to keep your code clean).

#include <tween.h>

Public Member Functions


tween ()
Default constructor for a tween. tween< T, Ts... > & to (T t, Ts... vs)
Adds a new currentPoint in this tweening. template<typename... Fs> tween< T, Ts... > & via (Fs... fs)
Specifies the easing function for the last added currentPoint. template<typename... Fs> tween< T, Ts... > & via (int index, Fs... fs)
Specifies the easing function for a specific currentPoint. template<typename... Ds> tween< T, Ts... > & during (Ds... ds)
Specifies the duration, typically in milliseconds, for the tweening of values in last currentPoint. const detail::tweentraits< T, Ts... >::valuesType & step (int32_t dt, bool suppressCallbacks=false)
Steps the animation by the designated delta amount. const detail::tweentraits< T, Ts... >::valuesType & step (uint32_t dt, bool suppressCallbacks=false)
Steps the animation by the designated delta amount. const detail::tweentraits< T, Ts... >::valuesType & step (float dp, bool suppressCallbacks=false)
Steps the animation by the designated percentage amount. const detail::tweentraits< T, Ts... >::valuesType & seek (float p, bool suppressCallbacks=false)
Seeks to a specified currentPoint in time based on the currentProgress. const detail::tweentraits< T, Ts... >::valuesType & seek (int32_t d, bool suppressCallbacks=false)
Seeks to a specified currentPoint in time. const detail::tweentraits< T, Ts... >::valuesType & seek (uint32_t d, bool suppressCallbacks=false)
Seeks to a specified currentPoint in time. tween< T, Ts... > & onStep (typename detail::tweentraits< T, Ts... >::callbackType callback)
Adds a callback that will be called when stepping occurs, accepting both the tween and its values. tween< T, Ts... > & onStep (typename detail::tweentraits< T, Ts... >::noValuesCallbackType callback)
Adds a callback that will be called when stepping occurs, accepting only the tween. tween< T, Ts... > & onStep (typename detail::tweentraits< T, Ts... >::noTweenCallbackType callback)
Adds a callback that will be called when stepping occurs, accepting only the tween values. tween< T, Ts... > & onSeek (typename detail::tweentraits< T, Ts... >::callbackType callback)
Adds a callback for that will be called when seeking occurs. tween< T, Ts... > & onSeek (typename detail::tweentraits< T, Ts... >::noTweenCallbackType callback)
Adds a callback for that will be called when seeking occurs, accepting only the tween values. tween< T, Ts... > & onSeek (typename detail::tweentraits< T, Ts... >::noValuesCallbackType callback)
Adds a callback for that will be called when seeking occurs, accepting only the tween. uint32_t duration () const
Returns the total duration of this tween. const detail::tweentraits< T, Ts... >::valuesType & peek () const
Returns the current tween values. const detail::tweentraits< T, Ts... >::valuesType peek (float progress) const
Calculates and returns the tween values at a given progress. const detail::tweentraits< T, Ts... >::valuesType peek (uint32_t time) const
Calculates and return the tween values at a given time. float progress () const
Returns the current currentProgress of the interpolation. tween< T, Ts... > & forward ()
Sets the direction of this tween forward. tween< T, Ts... > & backward ()
Sets the direction of this tween backward. int direction () const
Returns the current direction of this tween. const detail::tweentraits< T, Ts... >::valuesType & jump (int32_t point, bool suppressCallbacks=false)
Jumps to a specific tween currentPoint. uint16_t point () const
Returns the current tween point.

Static Public Member Functions


static tween< T, Ts... > from (T t, Ts... vs)
Instantiates a tween from a starting currentPoint.

Constructor & Destructor Documentation

tween ()

Default constructor for a tween. This constructor is provided to facilitate the usage of containers of tweens (e.g, std::vector). It should not be used manually as the tweening created by it is invalid.

Member Function Documentation

tween<T, Ts...>& backward ()

Sets the direction of this tween backward. Note that this only affects tween::step() function.

Returns

*this

See also

forward

int direction () const

Returns the current direction of this tween.

Returns

-1 If it is mobin backwards in time, 1 if it is moving forward in time

uint32_t duration () const

Returns the total duration of this tween.

Returns

The duration of all the tween points.

tween<T, Ts...>& during (Ds... ds)

Specifies the duration, typically in milliseconds, for the tweening of values in last currentPoint. You can either specify a single duration for all values or give every value its own duration. Value types must be convertible to the uint16_t type.

Example:

// Specify that the first currentPoint will be reached in 100 milliseconds and the first value in the second
// currentPoint in 100, whereas the second value will be reached in 500.
auto tween = tweeny::from(0, 0).to(100, 200).during(100).to(200, 300).during(100, 500);

Parameters

ds Duration values

Returns

*this

tween<T, Ts...>& forward ()

Sets the direction of this tween forward. Note that this only affects tween::step() function.

Returns

*this

See also

backward

static tween<T, Ts...> from (T t, Ts... vs) [static]

Instantiates a tween from a starting currentPoint. This is a static factory helper function to be used by tweeny::from. You should not use this directly. t The first value in the point vs The remaining values

const detail::tweentraits<T, Ts...>::valuesType& jump (int32_t point, bool suppressCallbacks = false)

Jumps to a specific tween currentPoint. This will seek the tween to a percentage matching the beginning of that step.

Parameters

point The currentPoint to seek to. 0 means the currentPoint passed in tweeny::from
suppressCallbacks (optional) set to true to suppress seek() callbacks

Returns

current values

See also

seek

tween<T, Ts...>& onSeek (typename detail::tweentraits< T, Ts... >::callbackType callback)

Adds a callback for that will be called when seeking occurs. You can add as many callbacks as you want. Its arguments types must be equal to the argument types of a tween instance, preceded by a variable of the tween typve. Callbacks can be of any callable type. It will be called via tween::seek() functions. For step callbacks, see tween::onStep().

Keep in mind that the function will be copied into an array, so any variable captured by value will also be copied with it.

If the callback returns false, it will be called next time. If it returns true, it will be removed from the callback queue.

Example:

auto t = t:from(0).to(100).during(100);
// pass a lambda
t.onSeek([](tweeny::tween<int> & t, int v) { printf("%d ", v); });
// pass a functor instance
struct ftor { void operator()(tweeny::tween<int> & t, int v) { printf("%d ", v); } };
t.onSeek(ftor());

Parameters

callback A callback in with the prototype bool callback(tween<Ts...> & t, Ts...)

tween<T, Ts...>& onSeek (typename detail::tweentraits< T, Ts... >::noTweenCallbackType callback)

Adds a callback for that will be called when seeking occurs, accepting only the tween values. You can add as many callbacks as you want. It must receive the tween as an argument. Callbacks can be of any callable type. It will be called via tween::seek() functions. For step callbacks, see tween::onStep().

Keep in mind that the function will be copied into an array, so any variable captured by value will also be copied again.

If the callback returns false, it will be called next time. If it returns true, it will be removed from the callback queue.

Example:

auto t = t:from(0).to(100).during(100);
// pass a lambda
t.onSeek([](int v) { printf("%d ", v); });
// pass a functor instance
struct ftor { void operator()(int v) { printf("%d ", v); return false; } };
t.onSeek(ftor());

Parameters

callback A callback in the form bool f(Ts...)

tween<T, Ts...>& onSeek (typename detail::tweentraits< T, Ts... >::noValuesCallbackType callback)

Adds a callback for that will be called when seeking occurs, accepting only the tween. You can add as many callbacks as you want. It must receive the tween as an argument. Callbacks can be of any callable type. It will be called via tween::seek() functions. For step callbacks, see tween::onStep().

Keep in mind that the function will be copied into an array, so any variable captured by value will also be copied again.

If the callback returns false, it will be called next time. If it returns true, it will be removed from the callback queue.

Example:

auto t = t:from(0).to(100).during(100);
// pass a lambda
t.onSeek([](tweeny::tween<int> & t) { printf("%d ", t.value()); return false; });
// pass a functor instance
struct ftor { void operator()(tweeny::tween<int> & t) { printf("%d ",  t.value()); return false; } };
t.onSeek(ftor());

Parameters

callback A callback in the form bool f(tween<Ts...> & t)

tween<T, Ts...>& onStep (typename detail::tweentraits< T, Ts... >::callbackType callback)

Adds a callback that will be called when stepping occurs, accepting both the tween and its values. You can add as many callbacks as you want. Its arguments types must be equal to the argument types of a tween instance, preceded by a variable of the tween type. Callbacks can be of any callable type. It will only be called via tween::step() functions. For seek callbacks, see tween::onSeek().

Keep in mind that the function will be copied into an array, so any variable captured by value will also be copied with it.

If the callback returns false, it will be called next time. If it returns true, it will be removed from the callback queue.

Example:

auto t = tweeny:from(0).to(100).during(100);
// pass a lambda
t.onStep([](tweeny::tween<int> & t, int v) { printf("%d ", v); return false; });
// pass a functor instance
struct ftor { void operator()(tweeny::tween<int> & t, int v) { printf("%d ", v); return false; } };
t.onStep(ftor());

See also

step

seek

onSeek

Parameters

callback A callback in with the prototype bool callback(tween<Ts...> & t, Ts...)

tween<T, Ts...>& onStep (typename detail::tweentraits< T, Ts... >::noTweenCallbackType callback)

Adds a callback that will be called when stepping occurs, accepting only the tween values. You can add as many callbacks as you want. It must receive the tween values as an argument. Callbacks can be of any callable type. It will only be called via tween::step() functions. For seek callbacks, see tween::onSeek().

Keep in mind that the function will be copied into an array, so any variable captured by value will also be copied with it.

If the callback returns false, it will be called next time. If it returns true, it will be removed from the callback queue.

Example:

auto t = tweeny:from(0).to(100).during(100);
// pass a lambda
t.onStep([](int v) { printf("%d ", v); return false; });
// pass a functor instance
struct ftor { void operator()(int x) { printf("%d ", x); return false; } };
t.onStep(ftor());

See also

step

seek

onSeek

Parameters

callback A callback in the form bool f(Ts...)

tween<T, Ts...>& onStep (typename detail::tweentraits< T, Ts... >::noValuesCallbackType callback)

Adds a callback that will be called when stepping occurs, accepting only the tween. You can add as many callbacks as you want. It must receive the tween as an argument. Callbacks can be of any callable type. It will only be called via tween::step() functions. For seek callbacks, see tween::onSeek().

Keep in mind that the function will be copied into an array, so any variable captured by value will also be copied with it.

If the callback returns false, it will be called next time. If it returns true, it will be removed from the callback queue.

Example:

auto t = tweeny:from(0).to(100).during(100);
// pass a lambda
t.onStep([](tweeny::tween<int> & t) { printf("%d ", t.value()); return false; });
// pass a functor instance
struct ftor { void operator()(tweeny::tween<int> & t) { printf("%d ", t.values()); return false; } };
t.onStep(ftor());

See also

step

seek

onSeek

Parameters

callback A callback in the form bool f(tween<Ts...> & t)

const detail::tweentraits<T, Ts...>::valuesType& peek () const

Returns the current tween values. This returns the current tween value as returned by the tween::step() function, except that it does not perform a step.

Returns

std::tuple<Ts...> with the current tween values.

const detail::tweentraits<T, Ts...>::valuesType peek (float progress) const

Calculates and returns the tween values at a given progress. This returns the tween value at the requested progress, without stepping or seeking.

Returns

std::tuple<Ts...> with the current tween values.

const detail::tweentraits<T, Ts...>::valuesType peek (uint32_t time) const

Calculates and return the tween values at a given time. This returns the tween values at the requested time, without stepping or seeking.

Returns

std::tuple<Ts...> with the calculated tween values.

uint16_t point () const

Returns the current tween point.

Returns

Current tween point

float progress () const

Returns the current currentProgress of the interpolation. 0 means its at the values passed in the construction, 1 means the last step.

Returns

the current currentProgress between 0 and 1 (inclusive)

const detail::tweentraits<T, Ts...>::valuesType& seek (float p, bool suppressCallbacks = false)

Seeks to a specified currentPoint in time based on the currentProgress. This function sets the current animation time and currentProgress. Callbacks set by call will be triggered.

Parameters

p The percentage to seek to, between 0.0f and 1.0f, inclusive.
suppressCallbacks (Optional) Suppress callbacks registered with tween::onSeek()

Returns

std::tuple<Ts...> with the current tween values.

const detail::tweentraits<T, Ts...>::valuesType& seek (int32_t d, bool suppressCallbacks = false)

Seeks to a specified currentPoint in time. This function sets the current animation time and currentProgress. Callbacks set by call will be triggered.

Parameters

d The duration to seek to, between 0 and the total duration.
suppressCallbacks (Optional) Suppress callbacks registered with tween::onSeek()

Returns

std::tuple<Ts...> with the current tween values.

See also

duration

const detail::tweentraits<T, Ts...>::valuesType& seek (uint32_t d, bool suppressCallbacks = false)

Seeks to a specified currentPoint in time. This function sets the current animation time and currentProgress. Callbacks set by call will be triggered.

Parameters

d The duration to seek to, between 0 and the total duration.
suppressCallbacks (Optional) Suppress callbacks registered with tween::onSeek()

Returns

std::tuple<Ts...> with the current tween values.

See also

duration

const detail::tweentraits<T, Ts...>::valuesType& step (float dp, bool suppressCallbacks = false)

Steps the animation by the designated percentage amount. You can use this function to step the tweening by a specified percentage delta.

Example:

// tween duration is 100ms
auto tween = tweeny::from(0).to(100).during(100);
// steps for 16ms
tween.step(0.001f);

Parameters

dp Delta percentage, between 0.0f and 1.0f
suppressCallbacks (Optional) Suppress callbacks registered with tween::onStep()

Returns

std::tuple<Ts...> with the current tween values.

const detail::tweentraits<T, Ts...>::valuesType& step (int32_t dt, bool suppressCallbacks = false)

Steps the animation by the designated delta amount. You should call this every frame of your application, passing in the amount of delta time that you want to animate.

Example:

// tween duration is 100ms
auto tween = tweeny::from(0).to(100).during(100);
// steps for 16ms
tween.step(16);

Parameters

dt Delta duration
suppressCallbacks (Optional) Suppress callbacks registered with tween::onStep()

Returns

std::tuple<Ts...> with the current tween values.

const detail::tweentraits<T, Ts...>::valuesType& step (uint32_t dt, bool suppressCallbacks = false)

Steps the animation by the designated delta amount. You should call this every frame of your application, passing in the amount of delta time that you want to animate. This overload exists to match unsigned int arguments.

Parameters

dt Delta duration
suppressCallbacks (Optional) Suppress callbacks registered with tween::onStep()

Returns

std::tuple<Ts...> with the current tween values.

tween<T, Ts...>& to (T t, Ts... vs)

Adds a new currentPoint in this tweening. This will add a new tweening currentPoint with the specified values. Next calls to via and during will refer to this currentPoint.

Example

auto t = tweeny::from(0).to(100).to(200);

Parameters

t,vs Point values

Returns

*this

tween<T, Ts...>& via (Fs... fs)

Specifies the easing function for the last added currentPoint. This will specify the easing between the last tween currentPoint added by to and its previous step. You can use any callable object. Additionally, you can use the easing objects specified in the class easing.

If it is a multi-value currentPoint, you can either specify a single easing function that will be used for every value or you can specify an easing function for each value. You can mix and match callable objects, lambdas and bundled easing objects.

Example:

// use bundled linear easing
auto tween1 = tweeny::from(0).to(100).via(tweeny::easing::linear);
// use custom lambda easing
auto tween2 = tweeny::from(0).to(100).via([](float p, int a, int b) { return (b-a) * p + a; });

Parameters

fs The functions

Returns

*this

See also

tweeny::easing

tween<T, Ts...>& via (int index, Fs... fs)

Specifies the easing function for a specific currentPoint. Points starts at index 0. The index 0 refers to the first to call. Using this function without adding a currentPoint with to leads to undefined behaviour.

Parameters

index The tween currentPoint index
fs The functions

Returns

*this

See also

tweeny::easing

Author

Generated automatically by Doxygen for Tweeny from the source code.

Wed May 5 2021 Version 3.1.1