diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/ecore/src/examples/ecore_evas_basics_example.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/libraries/ecore/src/examples/ecore_evas_basics_example.c b/libraries/ecore/src/examples/ecore_evas_basics_example.c new file mode 100644 index 0000000..5f0231f --- /dev/null +++ b/libraries/ecore/src/examples/ecore_evas_basics_example.c | |||
@@ -0,0 +1,91 @@ | |||
1 | /** | ||
2 | * Ecore example illustrating the basics of ecore evas usage. | ||
3 | * | ||
4 | * You'll need at least one Evas engine built for it (excluding the | ||
5 | * buffer one). See stdout/stderr for output. | ||
6 | * | ||
7 | * @verbatim | ||
8 | * gcc -o ecore_evas_basics_example ecore_evas_basics_example.c `pkg-config --libs --cflags ecore-evas` | ||
9 | * @endverbatim | ||
10 | */ | ||
11 | |||
12 | #include <Ecore.h> | ||
13 | #include <Ecore_Evas.h> | ||
14 | #include <unistd.h> | ||
15 | |||
16 | static Eina_Bool | ||
17 | _stdin_cb(void *data, Ecore_Fd_Handler *handler) | ||
18 | { | ||
19 | Eina_List *l; | ||
20 | Ecore_Evas *ee; | ||
21 | char c; | ||
22 | |||
23 | scanf("%c", &c); | ||
24 | if (c == 'h') | ||
25 | EINA_LIST_FOREACH(ecore_evas_ecore_evas_list_get(), l, ee) | ||
26 | ecore_evas_hide(ee); | ||
27 | else if (c == 's') | ||
28 | EINA_LIST_FOREACH(ecore_evas_ecore_evas_list_get(), l, ee) | ||
29 | ecore_evas_show(ee); | ||
30 | |||
31 | return ECORE_CALLBACK_RENEW; | ||
32 | } | ||
33 | |||
34 | static void | ||
35 | _on_delete(Ecore_Evas *ee) | ||
36 | { | ||
37 | free(ecore_evas_data_get(ee, "key")); | ||
38 | ecore_main_loop_quit(); | ||
39 | } | ||
40 | |||
41 | int | ||
42 | main(void) | ||
43 | { | ||
44 | Ecore_Evas *ee; | ||
45 | Evas *canvas; | ||
46 | Evas_Object *bg; | ||
47 | Eina_List *engines, *l; | ||
48 | char *data; | ||
49 | |||
50 | if(ecore_evas_init() <= 0) | ||
51 | return 1; | ||
52 | |||
53 | engines = ecore_evas_engines_get(); | ||
54 | printf("Available engines:\n"); | ||
55 | EINA_LIST_FOREACH(engines, l, data) | ||
56 | printf("%s\n", data); | ||
57 | ecore_evas_engines_free(engines); | ||
58 | |||
59 | ee = ecore_evas_new(NULL, 0, 0, 200, 200, NULL); | ||
60 | ecore_evas_title_set(ee, "Ecore Evas basics Example"); | ||
61 | ecore_evas_show(ee); | ||
62 | |||
63 | data = malloc(sizeof(char) * 6); | ||
64 | sprintf(data, "%s", "hello"); | ||
65 | ecore_evas_data_set(ee, "key", data); | ||
66 | ecore_evas_callback_delete_request_set(ee, _on_delete); | ||
67 | |||
68 | printf("Using %s engine!\n", ecore_evas_engine_name_get(ee)); | ||
69 | |||
70 | canvas = ecore_evas_get(ee); | ||
71 | if(ecore_evas_ecore_evas_get(canvas) == ee) | ||
72 | printf("Everything is sane!\n"); | ||
73 | |||
74 | bg = evas_object_rectangle_add(canvas); | ||
75 | evas_object_color_set(bg, 0, 0, 255, 255); | ||
76 | evas_object_resize(bg, 200, 200); | ||
77 | evas_object_show(bg); | ||
78 | ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE); | ||
79 | |||
80 | ecore_main_fd_handler_add(STDIN_FILENO, | ||
81 | ECORE_FD_READ | ECORE_FD_ERROR, | ||
82 | _stdin_cb, | ||
83 | NULL, NULL, NULL); | ||
84 | |||
85 | ecore_main_loop_begin(); | ||
86 | |||
87 | ecore_evas_free(ee); | ||
88 | ecore_evas_shutdown(); | ||
89 | |||
90 | return 0; | ||
91 | } | ||