ecore_animator_example.c
//Compile with:
//gcc -g -Wall -o ecore_animator_example ecore_animator_example.c `pkg-config --cflags --libs evas ecore-evas ecore`
#include <Ecore.h>
#include <Ecore_Evas.h>
static Eina_Bool _advance_frame(void *data, double pos);
static Eina_Bool _advance_frame2(void *data, double pos);
static Eina_Bool _advance_frame3(void *data);
static Eina_Bool _start_second_anim(void *data);
static Eina_Bool _freeze_third_anim(void *data);
static Eina_Bool _thaw_third_anim(void *data);
int
main(void)
{
Evas_Object *rect, *bg, *rect2;
Ecore_Evas *ee;
Evas *evas;
Ecore_Animator *anim;
ecore_evas_init();
ee = ecore_evas_new(NULL, 0, 0, 300, 400, NULL);
ecore_evas_show(ee);
evas = ecore_evas_get(ee);
bg = evas_object_rectangle_add(evas);
evas_object_resize(bg, 300, 400);
evas_object_show(bg);
rect = evas_object_rectangle_add(evas);
evas_object_color_set(rect, 0, 0, 255, 255);
evas_object_resize(rect, 50, 50);
evas_object_show(rect);
rect2 = evas_object_rectangle_add(evas);
evas_object_color_set(rect2, 0, 55, 0, 255);
evas_object_resize(rect2, 50, 50);
evas_object_show(rect2);
ecore_animator_frametime_set(1. / 50);
ecore_animator_timeline_add(5, _advance_frame, rect);
anim = ecore_animator_add(_advance_frame3, rect2);
ecore_timer_add(10, _start_second_anim, rect);
ecore_timer_add(5, _freeze_third_anim, anim);
ecore_timer_add(10, _thaw_third_anim, anim);
ecore_main_loop_begin();
evas_object_del(rect);
ecore_evas_free(ee);
ecore_animator_del(anim);
ecore_evas_shutdown();
return 0;
}
static Eina_Bool
_advance_frame(void *data, double pos)
{
double frame = pos;
frame = ecore_animator_pos_map(pos, ECORE_POS_MAP_SPRING, 1.2, 15);
evas_object_resize(data, 50 * (1 + frame), 50 * (1 + frame));
evas_object_move(data, 100 * frame, 100 * frame);
evas_object_color_set(data, 255 * frame, 0, 255 * (1 - frame), 255);
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
_start_second_anim(void *data)
{
ecore_animator_frametime_set(1. / 10);
ecore_animator_timeline_add(20, _advance_frame2, data);
return ECORE_CALLBACK_CANCEL;
}
static Eina_Bool
_advance_frame2(void *data, double pos)
{
double frame = pos;
frame = ecore_animator_pos_map(pos, ECORE_POS_MAP_BOUNCE, 1.2, 50);
evas_object_resize(data, 100 - (50 * frame), 100 - (50 * frame));
evas_object_move(data, 100 * (1 - frame), 100 * (1 - frame));
evas_object_color_set(data, 255 * (1 - frame), 0, 255 * frame, 255);
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
_advance_frame3(void *data)
{
static int x = 0;
if (x >= 250)
x = 0;
evas_object_move(data, ++x, 350);
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
_freeze_third_anim(void *data)
{
ecore_animator_freeze(data);
return ECORE_CALLBACK_CANCEL;
}
static Eina_Bool
_thaw_third_anim(void *data)
{
ecore_animator_thaw(data);
return ECORE_CALLBACK_CANCEL;
}
Ecore_Evas.h
Evas wrapper functions.
ecore_animator_add
Ecore_Animator * ecore_animator_add(Ecore_Task_Cb func, const void *data)
Adds an animator to call func at every animation tick during main loop execution.
Definition ecore_anim.c:537
ecore_animator_thaw
void ecore_animator_thaw(Ecore_Animator *animator)
Restores execution of the specified animator.
Definition ecore_anim.c:910
ecore_animator_frametime_set
void ecore_animator_frametime_set(double frametime)
Sets the animator call interval in seconds.
Definition ecore_anim.c:874
ecore_animator_pos_map
double ecore_animator_pos_map(double pos, Ecore_Pos_Map map, double v1, double v2)
Maps an input position from 0.0 to 1.0 along a timeline to a position in a different curve.
Definition ecore_anim.c:833
ecore_animator_del
void * ecore_animator_del(Ecore_Animator *animator)
Deletes the specified animator from the animator list.
Definition ecore_anim.c:846
ecore_animator_timeline_add
Ecore_Animator * ecore_animator_timeline_add(double runtime, Ecore_Timeline_Cb func, const void *data)
Adds an animator that runs for a limited time.
Definition ecore_anim.c:544
ecore_animator_freeze
void ecore_animator_freeze(Ecore_Animator *animator)
Suspends the specified animator.
Definition ecore_anim.c:892
ECORE_POS_MAP_BOUNCE
@ ECORE_POS_MAP_BOUNCE
Start at 0.0 then "drop" like a ball bouncing to the ground at 1.0, and bounce v2 times,...
Definition Ecore_Common.h:2792
ECORE_POS_MAP_SPRING
@ ECORE_POS_MAP_SPRING
Start at 0.0 then "wobble" like a spring rest position 1.0, and wobble v2 times, with decay factor of...
Definition Ecore_Common.h:2795
ecore_evas_init
EAPI int ecore_evas_init(void)
Inits the Ecore_Evas system.
Definition ecore_evas.c:608
ecore_evas_show
EAPI void ecore_evas_show(Ecore_Evas *ee)
Shows an Ecore_Evas' window.
Definition ecore_evas.c:1494
ecore_evas_get
EAPI Evas * ecore_evas_get(const Ecore_Evas *ee)
Gets an Ecore_Evas's Evas.
Definition ecore_evas.c:1314
ecore_evas_new
EAPI Ecore_Evas * ecore_evas_new(const char *engine_name, int x, int y, int w, int h, const char *extra_options)
Creates a new Ecore_Evas based on engine name and common parameters.
Definition ecore_evas.c:1053
ecore_evas_shutdown
EAPI int ecore_evas_shutdown(void)
Shuts down the Ecore_Evas system.
Definition ecore_evas.c:672
ecore_evas_free
EAPI void ecore_evas_free(Ecore_Evas *ee)
Frees an Ecore_Evas.
Definition ecore_evas.c:1097
ECORE_CALLBACK_RENEW
#define ECORE_CALLBACK_RENEW
Return value to keep a callback.
Definition Ecore_Common.h:153
ECORE_CALLBACK_CANCEL
#define ECORE_CALLBACK_CANCEL
Return value to remove a callback.
Definition Ecore_Common.h:152
ecore_main_loop_begin
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition ecore_main.c:1311
ecore_timer_add
Ecore_Timer * ecore_timer_add(double in, Ecore_Task_Cb func, const void *data)
Creates a timer to call the given function in the given period of time.
Definition ecore_timer.c:189
Eina_Bool
unsigned char Eina_Bool
Type to mimic a boolean.
Definition eina_types.h:527
Evas
Eo Evas
An opaque handle to an Evas canvas.
Definition Evas_Common.h:163
evas_object_show
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition evas_object_main.c:1814
evas_object_del
EVAS_API void evas_object_del(Evas_Object *obj)
Marks the given Evas object for deletion (when Evas will free its memory).
Definition evas_object_main.c:928
evas_object_color_set
EVAS_API void evas_object_color_set(Evas_Object *obj, int r, int g, int b, int a)
Sets the general/main color of the given Evas object to the given one.
Definition evas_object_main.c:2024
evas_object_move
EVAS_API void evas_object_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
Move the given Evas object to the given location inside its canvas' viewport.
Definition evas_object_main.c:1171
Evas_Object
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition Evas_Common.h:185
evas_object_resize
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition evas_object_main.c:1236
evas_object_rectangle_add
EVAS_API Evas_Object * evas_object_rectangle_add(Evas *e)
Adds a rectangle to the given evas.
Definition evas_object_rectangle.c:78
Ecore_Animator
Opaque handle to manage Ecore Animator objects.