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. --- .../edje/src/examples/edje-signals-messages.c | 112 +++++++++++++-------- 1 file changed, 68 insertions(+), 44 deletions(-) (limited to 'libraries/edje/src/examples/edje-signals-messages.c') diff --git a/libraries/edje/src/examples/edje-signals-messages.c b/libraries/edje/src/examples/edje-signals-messages.c index 2345738..4949415 100644 --- a/libraries/edje/src/examples/edje-signals-messages.c +++ b/libraries/edje/src/examples/edje-signals-messages.c @@ -27,34 +27,32 @@ #define MSG_COLOR 1 #define MSG_TEXT 2 -static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png"; -static const char *edje_file_path = \ - PACKAGE_EXAMPLES_DIR "/signals-messages.edj"; - -static Ecore_Evas *ee; -static Evas_Object *edje_obj; -static Eina_Bool right_rect_show = EINA_TRUE; - -static const char *commands = \ +static const char commands[] = \ "commands are:\n" "\tt - toggle right rectangle's visibility\n" + "\tEsc - exit\n" "\th - print help\n"; +static Eina_Bool right_rect_show = EINA_TRUE; + static void -_on_keydown(void *data __UNUSED__, +_on_keydown(void *data, Evas *evas __UNUSED__, Evas_Object *o __UNUSED__, void *einfo) { - Evas_Event_Key_Down *ev = einfo; + Evas_Event_Key_Down *ev; + Evas_Object *edje_obj; + + ev = (Evas_Event_Key_Down *)einfo; + edje_obj = (Evas_Object *)data; - if (strcmp(ev->keyname, "h") == 0) /* print help */ + if (!strcmp(ev->keyname, "h")) /* print help */ { fprintf(stdout, commands); return; } - - if (strcmp(ev->keyname, "t") == 0) /* toggle right rectangle's visibility */ + else if (!strcmp(ev->keyname, "t")) /* toggle right rectangle's visibility */ { char buf[1024]; @@ -68,6 +66,13 @@ _on_keydown(void *data __UNUSED__, return; } + else if (!strcmp(ev->keyname, "Escape")) + ecore_main_loop_quit(); + else + { + printf("unhandled key: %s\n", ev->keyname); + fprintf(stdout, commands); + } } static void @@ -85,7 +90,7 @@ _sig_print(const char *emission, } static void -_mouse_wheel_cb(void *data __UNUSED__, +_on_mouse_wheel(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *emission, const char *source) @@ -95,8 +100,8 @@ _mouse_wheel_cb(void *data __UNUSED__, /* mouse over signals */ static void -_mouse_over_cb(void *data __UNUSED__, - Evas_Object *obj __UNUSED__, +_on_mouse_over(void *data __UNUSED__, + Evas_Object *edje_obj, const char *emission, const char *source) { @@ -133,28 +138,43 @@ _message_handle(void *data __UNUSED__, } int -main(void) +main(int argc __UNUSED__, char *argv[]) { - Evas_Object *border, *bg; - Evas *evas; - - srand(time(NULL)); + char border_img_path[PATH_MAX]; + char edje_file_path[PATH_MAX]; + const char *edje_file = "signals-messages.edj"; + Ecore_Evas *ee; + Evas *evas; + Evas_Object *bg; + Evas_Object *edje_obj; + Evas_Object *border; + Eina_Prefix *pfx; if (!ecore_evas_init()) return EXIT_FAILURE; if (!edje_init()) - return EXIT_FAILURE; + 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 error; + goto free_prefix; ecore_evas_callback_delete_request_set(ee, _on_delete); ecore_evas_title_set(ee, "Edje Basics Example"); - ecore_evas_show(ee); evas = ecore_evas_get(ee); @@ -163,14 +183,13 @@ main(void) evas_object_move(bg, 0, 0); /* at canvas' origin */ evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */ evas_object_show(bg); - ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE); - evas_object_focus_set(bg, EINA_TRUE); - evas_object_event_callback_add( - bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL); + ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE); edje_obj = edje_object_add(evas); + snprintf(edje_file_path, sizeof(edje_file_path), + "%s/examples/%s", eina_prefix_data_get(pfx), edje_file); if (!edje_object_file_set(edje_obj, edje_file_path, "example_group")) { int err = edje_object_load_error_get(edje_obj); @@ -179,14 +198,14 @@ main(void) "signals-messages.edj: %s\n", errmsg); evas_object_del(edje_obj); - goto error_edj; + goto free_prefix; } edje_object_signal_callback_add(edje_obj, "mouse,wheel,*", "part_left", - _mouse_wheel_cb, NULL); + _on_mouse_wheel, NULL); edje_object_signal_callback_add(edje_obj, "mouse,over", "part_right", - _mouse_over_cb, NULL); + _on_mouse_over, NULL); edje_object_message_handler_set(edje_obj, _message_handle, NULL); @@ -194,6 +213,11 @@ main(void) evas_object_resize(edje_obj, WIDTH - 40, HEIGHT - 40); evas_object_show(edje_obj); + evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, edje_obj); + + snprintf(border_img_path, sizeof(border_img_path), + "%s/edje/examples/red.png", eina_prefix_data_get(pfx)); + /* this is a border around the Edje object above, here just to * emphasize its geometry */ border = evas_object_image_filled_add(evas); @@ -207,24 +231,24 @@ main(void) evas_object_show(border); 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; - -error: - fprintf(stderr, "You got to have at least one Evas engine built" - " and linked up to ecore-evas for this example to run" - " properly.\n"); - ecore_evas_shutdown(); - return -1; -error_edj: - fprintf(stderr, "Failed to load signals-messages.edj!\n"); + return EXIT_SUCCESS; + free_prefix: + eina_prefix_free(pfx); + shutdown_edje: + edje_shutdown(); + shutdown_ecore_evas: ecore_evas_shutdown(); - return -2; -} + return EXIT_FAILURE; +} -- cgit v1.1