Loading...
Searching...
No Matches
tween.h
/*
This file is part of the Tweeny library.
Copyright (c) 2016-2018 Leonardo G. Lucena de Freitas
Copyright (c) 2016 Guilherme R. Costa
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef TWEENY_TWEEN_H
#define TWEENY_TWEEN_H
#include <tuple>
#include <vector>
#include <functional>
#include "tweentraits.h"
#include "tweenpoint.h"
namespace tweeny {
template<typename T, typename... Ts>
class tween {
public:
static tween<T, Ts...> from(T t, Ts... vs);
public:
tween();
tween<T, Ts...> & to(T t, Ts... vs);
template<typename... Fs> tween<T, Ts...> & via(Fs... fs);
template<typename... Fs> tween<T, Ts...> & via(int index, Fs... fs);
template<typename... Ds> tween<T, Ts...> & during(Ds... ds);
const typename detail::tweentraits<T, Ts...>::valuesType & step(int32_t dt, bool suppressCallbacks = false);
const typename detail::tweentraits<T, Ts...>::valuesType & step(uint32_t dt, bool suppressCallbacks = false);
const typename detail::tweentraits<T, Ts...>::valuesType & step(float dp, bool suppressCallbacks = false);
const typename detail::tweentraits<T, Ts...>::valuesType & seek(float p, bool suppressCallbacks = false);
const typename detail::tweentraits<T, Ts...>::valuesType & seek(int32_t d, bool suppressCallbacks = false);
const typename detail::tweentraits<T, Ts...>::valuesType & seek(uint32_t d, bool suppressCallbacks = false);
tween<T, Ts...> & onStep(typename detail::tweentraits<T, Ts...>::callbackType callback);
tween<T, Ts...> & onStep(typename detail::tweentraits<T, Ts...>::noValuesCallbackType callback);
tween<T, Ts...> & onStep(typename detail::tweentraits<T, Ts...>::noTweenCallbackType callback);
tween<T, Ts...> & onSeek(typename detail::tweentraits<T, Ts...>::callbackType callback);
tween<T, Ts...> & onSeek(typename detail::tweentraits<T, Ts...>::noTweenCallbackType callback);
tween<T, Ts...> & onSeek(typename detail::tweentraits<T, Ts...>::noValuesCallbackType callback);
uint32_t duration() const;
const typename detail::tweentraits<T, Ts...>::valuesType & peek() const;
const typename detail::tweentraits<T, Ts...>::valuesType peek(float progress) const;
const typename detail::tweentraits<T, Ts...>::valuesType peek(uint32_t time) const;
float progress() const;
tween<T, Ts...> & forward();
tween<T, Ts...> & backward();
int direction() const;
const typename detail::tweentraits<T, Ts...>::valuesType & jump(int32_t point, bool suppressCallbacks = false);
uint16_t point() const;
private /* member types */:
using traits = detail::tweentraits<T, Ts...>;
private /* member variables */:
uint32_t total = 0; // total runtime
uint16_t currentPoint = 0; // current currentPoint
float currentProgress = 0; // current currentProgress
std::vector<detail::tweenpoint<T, Ts...>> points;
typename traits::valuesType current;
std::vector<typename traits::callbackType> onStepCallbacks;
std::vector<typename traits::callbackType> onSeekCallbacks;
int8_t currentDirection = 1;
private:
/* member functions */
tween(T t, Ts... vs);
template<size_t I> void interpolate(float prog, unsigned point, typename traits::valuesType & values, detail::int2type<I>) const;
void interpolate(float prog, unsigned point, typename traits::valuesType & values, detail::int2type<0>) const;
void render(float p);
void dispatch(std::vector<typename traits::callbackType> & cbVector);
uint16_t pointAt(float progress) const;
};
template<typename T>
class tween<T> {
public:
static tween<T> from(T t);
public:
tween();
tween<T> & to(T t);
template<typename... Fs> tween<T> & via(Fs... fs);
template<typename... Fs> tween<T> & via(int index, Fs... fs);
template<typename... Ds> tween<T> & during(Ds... ds);
const T & step(int32_t dt, bool suppressCallbacks = false);
const T & step(uint32_t dt, bool suppressCallbacks = false);
const T & step(float dp, bool suppressCallbacks = false);
const T & seek(float p, bool suppressCallbacks = false);
const T & seek(int32_t d, bool suppressCallbacks = false);
const T & seek(uint32_t d, bool suppressCallbacks = false);
tween<T> & onStep(typename detail::tweentraits<T>::callbackType callback);
tween<T> & onStep(typename detail::tweentraits<T>::noValuesCallbackType callback);
tween<T> & onStep(typename detail::tweentraits<T>::noTweenCallbackType callback);
tween<T> & onSeek(typename detail::tweentraits<T>::callbackType callback);
tween<T> & onSeek(typename detail::tweentraits<T>::noValuesCallbackType callback);
tween<T> & onSeek(typename detail::tweentraits<T>::noTweenCallbackType callback);
const T & peek() const;
T peek(float progress) const;
T peek(uint32_t time) const;
uint32_t duration() const;
float progress() const;
tween<T> & forward();
tween<T> & backward();
int direction() const;
const T & jump(int32_t point, bool suppressCallbacks = false);
uint16_t point() const;
private /* member types */:
using traits = detail::tweentraits<T>;
private /* member variables */:
uint32_t total = 0; // total runtime
uint16_t currentPoint = 0; // current currentPoint
float currentProgress = 0; // current currentProgress
std::vector<detail::tweenpoint<T>> points;
T current;
std::vector<typename traits::callbackType> onStepCallbacks;
std::vector<typename traits::callbackType> onSeekCallbacks;
int8_t currentDirection = 1;
private:
/* member functions */
tween(T t);
void interpolate(float prog, unsigned point, T & value) const;
void render(float p);
void dispatch(std::vector<typename traits::callbackType> & cbVector);
uint16_t pointAt(float progress) const;
};
}
#include "tween.tcc"
#include "tweenone.tcc"
#endif //TWEENY_TWEEN_H
tweeny::tween< T >::onStep
tween< T > & onStep(typename detail::tweentraits< T >::noValuesCallbackType callback)
tweeny::tween< T >::direction
int direction() const
tweeny::tween< T >::jump
const T & jump(int32_t point, bool suppressCallbacks=false)
tweeny::tween< T >::via
tween< T > & via(int index, Fs... fs)
tweeny::tween< T >::during
tween< T > & during(Ds... ds)
tweeny::tween< T >::point
uint16_t point() const
tweeny::tween< T >::seek
const T & seek(int32_t d, bool suppressCallbacks=false)
tweeny::tween< T >::to
tween< T > & to(T t)
tweeny::tween< T >::tween
tween()
tweeny::tween< T >::peek
T peek(float progress) const
tweeny::tween< T >::onStep
tween< T > & onStep(typename detail::tweentraits< T >::callbackType callback)
tweeny::tween< T >::peek
T peek(uint32_t time) const
tweeny::tween< T >::onSeek
tween< T > & onSeek(typename detail::tweentraits< T >::callbackType callback)
tweeny::tween< T >::step
const T & step(uint32_t dt, bool suppressCallbacks=false)
tweeny::tween< T >::forward
tween< T > & forward()
tweeny::tween< T >::onStep
tween< T > & onStep(typename detail::tweentraits< T >::noTweenCallbackType callback)
tweeny::tween< T >::seek
const T & seek(uint32_t d, bool suppressCallbacks=false)
tweeny::tween< T >::via
tween< T > & via(Fs... fs)
tweeny::tween< T >::onSeek
tween< T > & onSeek(typename detail::tweentraits< T >::noValuesCallbackType callback)
tweeny::tween< T >::duration
uint32_t duration() const
tweeny::tween< T >::seek
const T & seek(float p, bool suppressCallbacks=false)
tweeny::tween< T >::step
const T & step(int32_t dt, bool suppressCallbacks=false)
tweeny::tween< T >::step
const T & step(float dp, bool suppressCallbacks=false)
tweeny::tween< T >::peek
const T & peek() const
tweeny::tween< T >::backward
tween< T > & backward()
tweeny::tween< T >::onSeek
tween< T > & onSeek(typename detail::tweentraits< T >::noTweenCallbackType callback)
tweeny::tween< T >::progress
float progress() const
tweeny::tween::step
const detail::tweentraits< T, Ts... >::valuesType & step(uint32_t dt, bool suppressCallbacks=false)
Steps the animation by the designated delta amount.
tweeny::tween::direction
int direction() const
Returns the current direction of this tween.
tweeny::tween::seek
const detail::tweentraits< T, Ts... >::valuesType & seek(int32_t d, bool suppressCallbacks=false)
Seeks to a specified currentPoint in time.
tweeny::tween::onStep
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.
tweeny::tween::seek
const detail::tweentraits< T, Ts... >::valuesType & seek(uint32_t d, bool suppressCallbacks=false)
Seeks to a specified currentPoint in time.
tweeny::tween::step
const detail::tweentraits< T, Ts... >::valuesType & step(float dp, bool suppressCallbacks=false)
Steps the animation by the designated percentage amount.
tweeny::tween::point
uint16_t point() const
Returns the current tween point.
tweeny::tween::seek
const detail::tweentraits< T, Ts... >::valuesType & seek(float p, bool suppressCallbacks=false)
Seeks to a specified currentPoint in time based on the currentProgress.
tweeny::tween::to
tween< T, Ts... > & to(T t, Ts... vs)
Adds a new currentPoint in this tweening.
tweeny::tween::via
tween< T, Ts... > & via(int index, Fs... fs)
Specifies the easing function for a specific currentPoint.
tweeny::tween::peek
const detail::tweentraits< T, Ts... >::valuesType peek(uint32_t time) const
Calculates and return the tween values at a given time.
tweeny::tween::tween
tween()
Default constructor for a tween.
tweeny::tween::from
static tween< T, Ts... > from(T t, Ts... vs)
Instantiates a tween from a starting currentPoint.
tweeny::tween::onSeek
tween< T, Ts... > & onSeek(typename detail::tweentraits< T, Ts... >::callbackType callback)
Adds a callback for that will be called when seeking occurs.
tweeny::tween::during
tween< T, Ts... > & during(Ds... ds)
Specifies the duration, typically in milliseconds, for the tweening of values in last currentPoint.
tweeny::tween::backward
tween< T, Ts... > & backward()
Sets the direction of this tween backward.
tweeny::tween::peek
const detail::tweentraits< T, Ts... >::valuesType & peek() const
Returns the current tween values.
tweeny::tween::onSeek
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.
tweeny::tween::onStep
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.
tweeny::tween::peek
const detail::tweentraits< T, Ts... >::valuesType peek(float progress) const
Calculates and returns the tween values at a given progress.
tweeny::tween::duration
uint32_t duration() const
Returns the total duration of this tween.
tweeny::tween::forward
tween< T, Ts... > & forward()
Sets the direction of this tween forward.
tweeny::tween::via
tween< T, Ts... > & via(Fs... fs)
Specifies the easing function for the last added currentPoint.
tweeny::tween::onStep
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.
tweeny::tween::onSeek
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.
tweeny::tween::jump
const detail::tweentraits< T, Ts... >::valuesType & jump(int32_t point, bool suppressCallbacks=false)
Jumps to a specific tween currentPoint.
tweeny::tween::step
const detail::tweentraits< T, Ts... >::valuesType & step(int32_t dt, bool suppressCallbacks=false)
Steps the animation by the designated delta amount.
tweeny::tween::progress
float progress() const
Returns the current currentProgress of the interpolation.
tweeny::tween
The tween class is the core class of tweeny. It controls the interpolation steps, easings and duratio...
Definition tween.h:48
tweeny
The tweeny namespace contains all symbols and names for the Tweeny library.
Definition MANUAL.dox:1