Animators are a specific type of timer, specially designed for on-screen animation purposes:
To implement animators, Ecore provides the Ecore animator subsystem.
To create an animation that runs for an indefinite time:
Eina_Bool my_anim_cb(void *data) { static int count = 0; count++; if (count < 5) return ECORE_CALLBACK_RENEW; return ECORE_CALLBACK_CANCEL; } ecore_animator_add(my_anim_cb, my_data);
This example looks the same as the one using an Ecore timer. The
ecore_animator_add()
function takes the callback function and data to pass
to it, and returns an Ecore_Animator
object. The function is called at a
system-defined interval until it returns ECORE_CALLBACK_CANCEL
instead of
ECORE_CALLBACK_RENEW
.
An animator callback for an animator running a specific time has a different prototype than the forever running animator.
This callback function receives both data and a position which represents the
current time among the full timeline, 0 meaning the beginning of the
animation, and 1 meaning the end of the animation, returning
ECORE_CALLBACK_CANCEL
to abort, or ECORE_CALLBACK_RENEW
to continue.
Use the ecore_animator_timeline_add()
function. The first parameter
specifies the animator duration, the second parameter is the callback
function, and the third parameter is the data to pass to the callback. The
data parameter is optional.
Eina_Bool my_anim_cb(void *data, double position) { if (position < .5) return ECORE_CALLBACK_RENEW; return ECORE_CALLBACK_CANCEL; } ecore_animator_timeline_add(5., my_anim_cb, my_data);
In this example, the animator is specified to run for five seconds. The
function returns ECORE_CALLBACK_CANCEL
as soon as the position among the
timeline passes half of the duration, 2.5 seconds.
Ecore can generate a virtual position from the original one using
ecore_animator_pos_map(position, map, v1, v2)
. Several maps are available:
ECORE_POS_MAP_LINEAR
: linear from 0.0 to 1.0.ECORE_POS_MAP_ACCELERATE
: start slow, then speed up.ECORE_POS_MAP_DECELERATE
: start fast, then slow down.ECORE_POS_MAP_SINUSOIDAL
: start slow, speed up, then slow down at the end.ECORE_POS_MAP_ACCELERATE_FACTOR
: start slow, then speed up, v1 being a power factor: 0.0 is linear, 1.0 is standard acceleration, 2.0 is a much more pronounced acceleration (squared), and 3.0 is cubed.ECORE_POS_MAP_DECELERATE_FACTOR
: start fast, then slow down, v1 being a power factor: 0.0 is linear, 1.0 is standard deceleration, 2.0 is a much more pronounced deceleration (squared), and 3.0 is cubed.ECORE_POS_MAP_SINUSOIDAL_FACTOR
: start slow, speed up, then slow down at the end, v1 being a power factor: 0.0 is linear, 1.0 is a standard sinusoidal, 2.0 is a much more pronounced sinusoidal (squared), and 3.0 is cubed.ECORE_POS_MAP_DIVISOR_INTERP
: start at gradient * v1, interpolated with the power of v2 curve.ECORE_POS_MAP_BOUNCE
: start at 0.0, then drop like a ball bouncing to the ground at 1.0, and bounce v2 times, with a decay factor of v1.ECORE_POS_MAP_SPRING
: start at 0.0, then wobble like a spring to the rest position 1.0, and wobble v2 times, with a decay factor of v1.
Use the ecore_animator_del()
function. The animator to destroy must be
running, that is, it has not returned a false
value. If the animator is
not running, the function cannot be called.
Use the ecore_animator_freeze()
function. Note that time continues ticking
even if the animator is frozen, and that resuming the animation using the
ecore_animator_thaw()
function does not actually resume, if the full
runtime has been passed in the meanwhile.
Use the ecore_animator_frametime_get()
function.
Use the ecore_animator_frametime_set(interval)
function. Note that too
small a value causes performance and power consumption issues, and too high a
value makes the animation jerky.