Ecore: Ecore_Animator example.

SVN revision: 61131
This commit is contained in:
Jonas M. Gastal 2011-07-07 18:57:10 +00:00
parent cb9c1403fc
commit 54fb59c642
4 changed files with 199 additions and 1 deletions

View File

@ -613,3 +613,77 @@
*
* @example ecore_pipe_simple_example.c
*/
/**
* @page tutorial_ecore_animator Ecore animator example
* @dontinclude ecore_animator_example.c
*
* For this example we are going to animate a rectangle growing, moving and
* changing color, and then move it back to it's initial state with a
* different animation. We are also going to have a second rectangle moving
* along the bootom of the screen. To do this we are going to use ecore_evas,
* but since that is not the focus here we won't going into detail about it.
*
* @skip #include
* @until evas_object_show
* @until evas_object_show
* All of this is just setup, not what we're interested in right now.
*
* Now we are going to set the frametime for our animation to one fiftieth of
* a second, this will make our program consume more resources but should make
* our animation extra smooth:
* @until frametime
*
* And now we get right to the business of creating our ecore_animator:
* @until timeline
* @note We are telling our animation to last 10 second and to call
* _advance_frame with rect as data.
*
* So far we setup the first and second animations, the third one however is a
* bit different, this time we won't use a timeline animation, that's because we
* don't want our animation to stop:
* @until animator_add
*
* Next we set a few timers to execute _start_second_anim, _freeze_third_anim
* and _thaw_thir_anim in 10, 5 and 10 seconds respectively:
* @until thaw
*
* And now we tell ecore to begin the main loop and free some resources once
* it leaves the main loop:
* @until }
*
* Here we have the callback function for our first animation, which first
* takes @p pos(where in the timeline we are), maps it to a SPRING curve that
* which will wooble 15 times and will decay by a factor of 1.2:
* @until pos_map
*
* Now that we have the frame we can adjust the rectangle to its apropriate
* state:
* @until }
*
* And now the callback that will run 10 seconds after the program starts(5
* seconds after the first animation finishes) and starts our second
* animation:
* @until }
* @note For this animation we made the frametime much larger which means our
* animation might get "jerky".
*
* The callback for our second animation, our savy reader no doubt noted that
* it's very similar to the callback for the first animation. What we change for
* this one is the type of animation to BOUNCE and the number of times it will
* bounce to 50:
* @until }
*
* And for our last animation callback something simpler, we just move our
* rectangle right by one pixel until it reaches the end of the screen and then
* start at the beggining again:
* @until }
*
* Our next two functions respectively freezes and thaw our third animation, so
* that it won't happen for the 5 seconds after the first animation ends and the
* second animation begins:
* @until }
* @until }
*
* @example ecore_animator_example.c
*/

View File

@ -5,8 +5,10 @@ pkglibdir = $(datadir)/$(PACKAGE)/examples
AM_CPPFLAGS = \
-I. \
-I$(top_srcdir)/src/lib/ecore \
-I$(top_srcdir)/src/lib/ecore_evas \
-I$(top_srcdir)/src/lib/ecore_input \
-I$(top_srcdir)/src/lib/ecore_con \
@GLIB_CFLAGS@ @EVIL_CFLAGS@ @EINA_CFLAGS@ @WIN32_CPPFLAGS@ @EFL_ECORE_BUILD@
@GLIB_CFLAGS@ @EVIL_CFLAGS@ @EVAS_CFLAGS@ @EINA_CFLAGS@ @WIN32_CPPFLAGS@ @EFL_ECORE_BUILD@
ECOREBASELDADD = \
$(top_builddir)/src/lib/ecore/libecore.la \
@ -17,6 +19,7 @@ LDADD = \
$(ECOREBASELDADD)
SRCS = \
ecore_animator_example.c \
ecore_fd_handler_example.c \
ecore_poller_example.c \
ecore_event_example.c \
@ -45,6 +48,7 @@ endif
if EFL_BUILD_EXAMPLES
pkglib_PROGRAMS += \
ecore_animator_example \
ecore_fd_handler_example \
ecore_poller_example \
ecore_event_example \
@ -56,5 +60,6 @@ pkglib_PROGRAMS += \
ecore_con_lookup_example
ecore_con_lookup_example_LDADD = $(ECOREBASELDADD) $(top_builddir)/src/lib/ecore_con/libecore_con.la
ecore_animator_example_LDADD = $(ECOREBASELDADD) $(top_builddir)/src/lib/ecore_evas/libecore_evas.la
endif

View File

@ -0,0 +1,116 @@
//Compile with:
//gcc -g -Wall `pkg-config --cflags --libs ecore-evas` -o ecore_animator_example ecore_animator_example.c
#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 (int argc, char *argv[])
{
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 EINA_TRUE;
}
static Eina_Bool
_start_second_anim(void *data)
{
ecore_animator_frametime_set(1./10);
ecore_animator_timeline_add(20, _advance_frame2, data);
return EINA_FALSE;
}
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 EINA_TRUE;
}
static Eina_Bool
_advance_frame3(void *data)
{
static int x = 0;
if(x >= 250)
x = 0;
evas_object_move(data, ++x, 350);
return EINA_TRUE;
}
static Eina_Bool
_freeze_third_anim(void *data)
{
ecore_animator_freeze(data);
return EINA_FALSE;
}
static Eina_Bool
_thaw_third_anim(void *data)
{
ecore_animator_thaw(data);
return EINA_FALSE;
}

View File

@ -1582,6 +1582,9 @@ extern "C" {
* This function sets the time interval (in seconds) between animator ticks.
* At every tick the callback of every existing animator will be called.
*
* @warning Too small a value may cause performance issues and too high a
* value may cause your animation to seem "jerky".
*
* @note The default @p frametime value is 1/30th of a second.
*/
EAPI void ecore_animator_frametime_set(double frametime);