diff options
author | David Walter Seikel | 2012-04-22 09:19:23 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-04-22 09:19:23 +1000 |
commit | c963d75dfdeec11f82e79e727062fbf89afa2c04 (patch) | |
tree | 895633dbf641110be46f117c29890c49b3ffc0bd /libraries/edje/src/examples/sigtest.c | |
parent | Adding the new extantz viewer and grid manager. (diff) | |
download | SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.zip SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.gz SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.bz2 SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.xz |
Update EFL to latest beta.
Diffstat (limited to 'libraries/edje/src/examples/sigtest.c')
-rw-r--r-- | libraries/edje/src/examples/sigtest.c | 110 |
1 files changed, 71 insertions, 39 deletions
diff --git a/libraries/edje/src/examples/sigtest.c b/libraries/edje/src/examples/sigtest.c index 6e4d85f..9538e13 100644 --- a/libraries/edje/src/examples/sigtest.c +++ b/libraries/edje/src/examples/sigtest.c | |||
@@ -13,35 +13,37 @@ | |||
13 | #define WIDTH (300) | 13 | #define WIDTH (300) |
14 | #define HEIGHT (300) | 14 | #define HEIGHT (300) |
15 | 15 | ||
16 | static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png"; | ||
17 | static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/sigtest.edj"; | ||
18 | |||
19 | static Ecore_Evas *ee; | ||
20 | static Evas_Object *edje_obj; | ||
21 | |||
22 | static const char commands[] = \ | 16 | static const char commands[] = \ |
23 | "commands are:\n" | 17 | "commands are:\n" |
24 | "\te - change te edje base\n" | 18 | "\te - change te edje base\n" |
25 | "\tl - change to lua base\n" | 19 | "\tl - change to lua base\n" |
26 | "\tm - send message\n" | 20 | "\tm - send message\n" |
27 | "\ts - send signal\n" | 21 | "\ts - send signal\n" |
22 | "\tEsc - exit\n" | ||
28 | "\th - print help\n"; | 23 | "\th - print help\n"; |
29 | 24 | ||
30 | static void | 25 | static void |
31 | _on_keydown(void *data __UNUSED__, | 26 | _on_keydown(void *data, |
32 | Evas *evas __UNUSED__, | 27 | Evas *evas __UNUSED__, |
33 | Evas_Object *o __UNUSED__, | 28 | Evas_Object *o __UNUSED__, |
34 | void *einfo) | 29 | void *einfo) |
35 | { | 30 | { |
36 | Evas_Event_Key_Down *ev = einfo; | 31 | Ecore_Evas *ee; |
32 | Evas_Event_Key_Down *ev; | ||
33 | Evas_Object *edje_obj; | ||
34 | char *edje_file_path; | ||
35 | |||
36 | ee = (Ecore_Evas *)data; | ||
37 | ev = (Evas_Event_Key_Down *)einfo; | ||
38 | edje_obj = ecore_evas_data_get(ee, "edje_obj"); | ||
39 | edje_file_path = ecore_evas_data_get(ee, "file_path"); | ||
37 | 40 | ||
38 | if (strcmp(ev->keyname, "h") == 0) | 41 | if (!strcmp(ev->keyname, "h")) |
39 | { | 42 | { |
40 | fprintf(stdout, commands); | 43 | fprintf(stdout, commands); |
41 | return; | 44 | return; |
42 | } | 45 | } |
43 | 46 | else if (!strcmp(ev->keyname, "e")) | |
44 | if (strcmp(ev->keyname, "e") == 0) | ||
45 | { | 47 | { |
46 | if (!edje_object_file_set(edje_obj, edje_file_path, "plain/edje/group")) | 48 | if (!edje_object_file_set(edje_obj, edje_file_path, "plain/edje/group")) |
47 | { | 49 | { |
@@ -55,8 +57,7 @@ _on_keydown(void *data __UNUSED__, | |||
55 | " file sigtest.edj with success!\n"); | 57 | " file sigtest.edj with success!\n"); |
56 | return; | 58 | return; |
57 | } | 59 | } |
58 | 60 | else if (!strcmp(ev->keyname, "l")) | |
59 | if (strcmp(ev->keyname, "l") == 0) | ||
60 | { | 61 | { |
61 | if (!edje_object_file_set(edje_obj, edje_file_path, "lua_base")) | 62 | if (!edje_object_file_set(edje_obj, edje_file_path, "lua_base")) |
62 | { | 63 | { |
@@ -70,8 +71,7 @@ _on_keydown(void *data __UNUSED__, | |||
70 | " file sigtest.edj with success!\n"); | 71 | " file sigtest.edj with success!\n"); |
71 | return; | 72 | return; |
72 | } | 73 | } |
73 | 74 | else if (!strcmp(ev->keyname, "m")) | |
74 | if (strcmp(ev->keyname, "m") == 0) | ||
75 | { | 75 | { |
76 | Edje_Message_String *msg = malloc(sizeof(*msg)); | 76 | Edje_Message_String *msg = malloc(sizeof(*msg)); |
77 | 77 | ||
@@ -82,8 +82,7 @@ _on_keydown(void *data __UNUSED__, | |||
82 | fprintf(stdout, "C message sent\n"); | 82 | fprintf(stdout, "C message sent\n"); |
83 | return; | 83 | return; |
84 | } | 84 | } |
85 | 85 | else if (!strcmp(ev->keyname, "s")) | |
86 | if (strcmp(ev->keyname, "s") == 0) | ||
87 | { | 86 | { |
88 | fprintf(stdout, "\n"); | 87 | fprintf(stdout, "\n"); |
89 | edje_object_signal_emit(edje_obj, "C signal 1", "Csource"); | 88 | edje_object_signal_emit(edje_obj, "C signal 1", "Csource"); |
@@ -91,10 +90,17 @@ _on_keydown(void *data __UNUSED__, | |||
91 | fprintf(stdout, "C signal sent\n"); | 90 | fprintf(stdout, "C signal sent\n"); |
92 | return; | 91 | return; |
93 | } | 92 | } |
93 | else if (!strcmp(ev->keyname, "Escape")) | ||
94 | ecore_main_loop_quit(); | ||
95 | else | ||
96 | { | ||
97 | printf("unhandled key: %s\n", ev->keyname); | ||
98 | fprintf(stdout, commands); | ||
99 | } | ||
94 | } | 100 | } |
95 | 101 | ||
96 | static void | 102 | static void |
97 | _on_message(void *data, Evas_Object *obj, Edje_Message_Type type, int id, void *msg) | 103 | _on_message(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Edje_Message_Type type, int id, void *msg) |
98 | { | 104 | { |
99 | int i; | 105 | int i; |
100 | 106 | ||
@@ -207,7 +213,7 @@ _on_message(void *data, Evas_Object *obj, Edje_Message_Type type, int id, void * | |||
207 | } | 213 | } |
208 | 214 | ||
209 | static void | 215 | static void |
210 | _on_signal(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source) | 216 | _on_signal(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *emission, const char *source) |
211 | { | 217 | { |
212 | fprintf(stdout, "C::signal sig=|%s| src=|%s|\n", emission, source); | 218 | fprintf(stdout, "C::signal sig=|%s| src=|%s|\n", emission, source); |
213 | } | 219 | } |
@@ -219,26 +225,43 @@ _on_delete(Ecore_Evas *ee __UNUSED__) | |||
219 | } | 225 | } |
220 | 226 | ||
221 | int | 227 | int |
222 | main(void) | 228 | main(int argc __UNUSED__, char *argv[]) |
223 | { | 229 | { |
224 | Evas_Object *border, *bg; | 230 | char border_img_path[PATH_MAX]; |
225 | Evas *evas; | 231 | char edje_file_path[PATH_MAX]; |
232 | const char *edje_file = "sigtest.edj"; | ||
233 | Ecore_Evas *ee; | ||
234 | Evas *evas; | ||
235 | Evas_Object *bg; | ||
236 | Evas_Object *border; | ||
237 | Evas_Object *edje_obj; | ||
238 | Eina_Prefix *pfx; | ||
226 | 239 | ||
227 | if (!ecore_evas_init()) | 240 | if (!ecore_evas_init()) |
228 | return EXIT_FAILURE; | 241 | return EXIT_FAILURE; |
229 | 242 | ||
230 | if (!edje_init()) | 243 | if (!edje_init()) |
231 | return EXIT_FAILURE; | 244 | goto shutdown_ecore_evas; |
245 | |||
246 | pfx = eina_prefix_new(argv[0], main, | ||
247 | "EDJE_EXAMPLES", | ||
248 | "edje/examples", | ||
249 | edje_file, | ||
250 | PACKAGE_BIN_DIR, | ||
251 | PACKAGE_LIB_DIR, | ||
252 | PACKAGE_DATA_DIR, | ||
253 | PACKAGE_DATA_DIR); | ||
254 | if (!pfx) | ||
255 | goto shutdown_edje; | ||
232 | 256 | ||
233 | /* this will give you a window with an Evas canvas under the first | 257 | /* this will give you a window with an Evas canvas under the first |
234 | * engine available */ | 258 | * engine available */ |
235 | ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); | 259 | ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); |
236 | if (!ee) | 260 | if (!ee) |
237 | goto error; | 261 | goto free_prefix; |
238 | 262 | ||
239 | ecore_evas_callback_delete_request_set(ee, _on_delete); | 263 | ecore_evas_callback_delete_request_set(ee, _on_delete); |
240 | ecore_evas_title_set(ee, "Signals and wessages tester"); | 264 | ecore_evas_title_set(ee, "Signals and wessages tester"); |
241 | ecore_evas_show(ee); | ||
242 | 265 | ||
243 | evas = ecore_evas_get(ee); | 266 | evas = ecore_evas_get(ee); |
244 | 267 | ||
@@ -250,14 +273,14 @@ main(void) | |||
250 | ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE); | 273 | ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE); |
251 | 274 | ||
252 | evas_object_focus_set(bg, EINA_TRUE); | 275 | evas_object_focus_set(bg, EINA_TRUE); |
253 | evas_object_event_callback_add( | ||
254 | bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL); | ||
255 | 276 | ||
256 | edje_obj = edje_object_add(evas); | 277 | edje_obj = edje_object_add(evas); |
257 | 278 | ||
258 | edje_object_message_handler_set(edje_obj, _on_message, NULL); | 279 | edje_object_message_handler_set(edje_obj, _on_message, NULL); |
259 | edje_object_signal_callback_add(edje_obj, "*", "*", _on_signal, NULL); | 280 | edje_object_signal_callback_add(edje_obj, "*", "*", _on_signal, NULL); |
260 | 281 | ||
282 | snprintf(edje_file_path, sizeof(edje_file_path), | ||
283 | "%s/examples/%s", eina_prefix_data_get(pfx), edje_file); | ||
261 | if (!edje_object_file_set(edje_obj, edje_file_path, "lua_base")) | 284 | if (!edje_object_file_set(edje_obj, edje_file_path, "lua_base")) |
262 | { | 285 | { |
263 | int err = edje_object_load_error_get(edje_obj); | 286 | int err = edje_object_load_error_get(edje_obj); |
@@ -266,7 +289,7 @@ main(void) | |||
266 | errmsg); | 289 | errmsg); |
267 | 290 | ||
268 | evas_object_del(edje_obj); | 291 | evas_object_del(edje_obj); |
269 | goto error_edj; | 292 | goto free_prefix; |
270 | } | 293 | } |
271 | 294 | ||
272 | fprintf(stdout, "Loaded Edje object bound to group 'lua_base' from" | 295 | fprintf(stdout, "Loaded Edje object bound to group 'lua_base' from" |
@@ -275,6 +298,13 @@ main(void) | |||
275 | evas_object_move(edje_obj, 20, 20); | 298 | evas_object_move(edje_obj, 20, 20); |
276 | evas_object_resize(edje_obj, WIDTH - 40, HEIGHT - 40); | 299 | evas_object_resize(edje_obj, WIDTH - 40, HEIGHT - 40); |
277 | evas_object_show(edje_obj); | 300 | evas_object_show(edje_obj); |
301 | ecore_evas_data_set(ee, "edje_obj", edje_obj); | ||
302 | ecore_evas_data_set(ee, "file_path", edje_file_path); | ||
303 | |||
304 | evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, ee); | ||
305 | |||
306 | snprintf(border_img_path, sizeof(border_img_path), | ||
307 | "%s/edje/examples/red.png", eina_prefix_data_get(pfx)); | ||
278 | 308 | ||
279 | /* this is a border around the Edje object above, here just to | 309 | /* this is a border around the Edje object above, here just to |
280 | * emphasize its geometry */ | 310 | * emphasize its geometry */ |
@@ -287,23 +317,25 @@ main(void) | |||
287 | evas_object_move(border, 20 - 2, 20 - 2); | 317 | evas_object_move(border, 20 - 2, 20 - 2); |
288 | evas_object_show(border); | 318 | evas_object_show(border); |
289 | 319 | ||
320 | fprintf(stdout, commands); | ||
321 | |||
322 | ecore_evas_show(ee); | ||
323 | |||
290 | ecore_main_loop_begin(); | 324 | ecore_main_loop_begin(); |
291 | 325 | ||
326 | eina_prefix_free(pfx); | ||
292 | ecore_evas_free(ee); | 327 | ecore_evas_free(ee); |
293 | ecore_evas_shutdown(); | 328 | ecore_evas_shutdown(); |
294 | edje_shutdown(); | 329 | edje_shutdown(); |
295 | return 0; | ||
296 | |||
297 | error: | ||
298 | fprintf(stderr, "You got to have at least one evas engine built" | ||
299 | " and linked up to ecore-evas for this example to run" | ||
300 | " properly.\n"); | ||
301 | ecore_evas_shutdown(); | ||
302 | return -1; | ||
303 | 330 | ||
304 | error_edj: | 331 | return EXIT_SUCCESS; |
305 | fprintf(stderr, "Failed to load sigtest.edj!\n"); | ||
306 | 332 | ||
333 | free_prefix: | ||
334 | eina_prefix_free(pfx); | ||
335 | shutdown_edje: | ||
336 | edje_shutdown(); | ||
337 | shutdown_ecore_evas: | ||
307 | ecore_evas_shutdown(); | 338 | ecore_evas_shutdown(); |
308 | return -2; | 339 | |
340 | return EXIT_FAILURE; | ||
309 | } | 341 | } |