From c963d75dfdeec11f82e79e727062fbf89afa2c04 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 22 Apr 2012 09:19:23 +1000 Subject: Update EFL to latest beta. --- libraries/edje/src/examples/edje-animations.c | 125 ++++++++++++++++++++------ 1 file changed, 98 insertions(+), 27 deletions(-) (limited to 'libraries/edje/src/examples/edje-animations.c') diff --git a/libraries/edje/src/examples/edje-animations.c b/libraries/edje/src/examples/edje-animations.c index 9363471..15f2ee0 100644 --- a/libraries/edje/src/examples/edje-animations.c +++ b/libraries/edje/src/examples/edje-animations.c @@ -10,10 +10,9 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #else -#define PACKAGE_EXAMPLES_DIR "." -#define __UNUSED__ +# define __UNUSED__ #endif #include @@ -23,34 +22,59 @@ #define WIDTH (400) #define HEIGHT (300) -static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/animations.edj"; -static Ecore_Evas *ee; -static Evas_Object *bg, *edje_obj; -static double frametime = 1.0/30.0; /* default value */ +static const char commands[] = \ + "commands are:\n" + "\t+ - increase frametime\n" + "\t- - decrease frametime\n" + "\t= - status of the animation\n" + "\ts - pause\n" + "\tp - play\n" + "\tf - freeze one object\n" + "\tF - freeze all objects\n" + "\tt - thaw one object\n" + "\tT - thaw all objects\n" + "\ta - start animation of one object\n" + "\tA - stop animation of one object\n" + "\tEsc - exit\n" + "\th - print help\n"; + +static double frametime = 1.0 / 30.0; /* default value */ static void -_on_delete_cb(Ecore_Evas *ee) +_on_delete_cb(Ecore_Evas *ee __UNUSED__) { ecore_main_loop_quit(); } static void -_canvas_resize_cb(Ecore_Evas *ee) +_on_canvas_resize(Ecore_Evas *ee) { - int w, h; - - ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); - evas_object_resize(bg, w, h); - evas_object_resize(edje_obj, w, h); + Evas_Object *bg; + Evas_Object *edje_obj; + int w; + int h; + + bg = ecore_evas_data_get(ee, "background"); + edje_obj = ecore_evas_data_get(ee, "edje_obj"); + ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); + evas_object_resize(bg, w, h); + evas_object_resize(edje_obj, w, h); } static void -_on_key_down_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info) +_on_key_down(void *data __UNUSED__, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info) { - Evas_Event_Key_Down *ev = event_info; - double ft; + Evas_Event_Key_Down *ev; + double ft; + + ev = (Evas_Event_Key_Down *)event_info; - if (!strcmp(ev->key, "plus")) + if (!strcmp(ev->keyname, "h")) + { + fprintf(stdout, commands); + return; + } + else if (!strcmp(ev->key, "plus")) { frametime *= 2.0; fprintf(stdout, "Increasing frametime to: %f\n", frametime); @@ -109,24 +133,52 @@ _on_key_down_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info) edje_object_animation_set(obj, EINA_FALSE); fprintf(stdout, "Stopping the animation in the Edje object\n"); } + else if (!strcmp(ev->keyname, "Escape")) + ecore_main_loop_quit(); + else + { + printf("unhandled key: %s\n", ev->keyname); + fprintf(stdout, commands); + } } int -main(int argc, char *argv[]) +main(int argc __UNUSED__, char *argv[]) { - Evas *evas; - - ecore_evas_init(); - edje_init(); + char edje_file_path[PATH_MAX]; + const char *edje_file = "animations.edj"; + Ecore_Evas *ee; + Evas *evas; + Evas_Object *bg; + Evas_Object *edje_obj; + Eina_Prefix *pfx; + + if (!ecore_evas_init()) + return EXIT_FAILURE; + + if (!edje_init()) + goto shutdown_ecore_evas; + + pfx = eina_prefix_new(argv[0], main, + "EDJE_EXAMPLES", + "edje/examples", + edje_file, + PACKAGE_BIN_DIR, + PACKAGE_LIB_DIR, + PACKAGE_DATA_DIR, + PACKAGE_DATA_DIR); + if (!pfx) + goto shutdown_edje; /* this will give you a window with an Evas canvas under the first * engine available */ ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); + if (!ee) + goto free_prefix; ecore_evas_callback_delete_request_set(ee, _on_delete_cb); - ecore_evas_callback_resize_set(ee, _canvas_resize_cb); + ecore_evas_callback_resize_set(ee, _on_canvas_resize); ecore_evas_title_set(ee, "Edje Animations Example"); - ecore_evas_show(ee); evas = ecore_evas_get(ee); @@ -135,22 +187,41 @@ main(int argc, char *argv[]) evas_object_move(bg, 0, 0); /* at canvas' origin */ evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */ evas_object_show(bg); + ecore_evas_data_set(ee, "background", bg); edje_obj = edje_object_add(evas); + snprintf(edje_file_path, sizeof(edje_file_path), + "%s/examples/%s", eina_prefix_data_get(pfx), edje_file); edje_object_file_set(edje_obj, edje_file_path, "animations_group"); evas_object_move(edje_obj, 0, 0); evas_object_resize(edje_obj, WIDTH, HEIGHT); evas_object_show(edje_obj); + ecore_evas_data_set(ee, "edje_obj", edje_obj); evas_object_event_callback_add(edje_obj, EVAS_CALLBACK_KEY_DOWN, - _on_key_down_cb, NULL); + _on_key_down, NULL); evas_object_focus_set(edje_obj, EINA_TRUE); + fprintf(stdout, commands); + + ecore_evas_show(ee); + ecore_main_loop_begin(); + eina_prefix_free(pfx); ecore_evas_free(ee); ecore_evas_shutdown(); edje_shutdown(); - return 0; + + return EXIT_SUCCESS; + + free_prefix: + eina_prefix_free(pfx); + shutdown_edje: + edje_shutdown(); + shutdown_ecore_evas: + ecore_evas_shutdown(); + + return EXIT_FAILURE; } -- cgit v1.1