diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/ecore/src/examples/ecore_evas_ews_example.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to '')
-rw-r--r-- | libraries/ecore/src/examples/ecore_evas_ews_example.c | 253 |
1 files changed, 253 insertions, 0 deletions
diff --git a/libraries/ecore/src/examples/ecore_evas_ews_example.c b/libraries/ecore/src/examples/ecore_evas_ews_example.c new file mode 100644 index 0000000..9be725a --- /dev/null +++ b/libraries/ecore/src/examples/ecore_evas_ews_example.c | |||
@@ -0,0 +1,253 @@ | |||
1 | /** | ||
2 | * Ecore example illustrating the ews 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_ews_example ecore_evas_ews_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 | #include <stdio.h> | ||
16 | #include <ctype.h> | ||
17 | |||
18 | static Eina_Bool | ||
19 | _wm_win_add(void *data, int type, void *event_info) | ||
20 | { | ||
21 | Ecore_Evas *ee = event_info; | ||
22 | printf("WM: new window=%p\n", ee); | ||
23 | return EINA_TRUE; | ||
24 | } | ||
25 | |||
26 | static Eina_Bool | ||
27 | _wm_win_move(void *data, int type, void *event_info) | ||
28 | { | ||
29 | Ecore_Evas *ee = event_info; | ||
30 | int x, y; | ||
31 | ecore_evas_geometry_get(ee, &x, &y, NULL, NULL); | ||
32 | printf("WM: window=%p moved to %d,%d\n", ee, x, y); | ||
33 | return EINA_TRUE; | ||
34 | } | ||
35 | |||
36 | static Eina_Bool | ||
37 | _wm_win_resize(void *data, int type, void *event_info) | ||
38 | { | ||
39 | Ecore_Evas *ee = event_info; | ||
40 | int w, h; | ||
41 | ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); | ||
42 | printf("WM: window=%p resized to %dx%d\n", ee, w, h); | ||
43 | return EINA_TRUE; | ||
44 | } | ||
45 | |||
46 | static Eina_Bool | ||
47 | _wm_win_show(void *data, int type, void *event_info) | ||
48 | { | ||
49 | Ecore_Evas *ee = event_info; | ||
50 | printf("WM: show window=%p\n", ee); | ||
51 | return EINA_TRUE; | ||
52 | } | ||
53 | |||
54 | static void | ||
55 | optional_ews_window_manager_setup(void) | ||
56 | { | ||
57 | ecore_event_handler_add(ECORE_EVAS_EWS_EVENT_ADD, _wm_win_add, NULL); | ||
58 | ecore_event_handler_add(ECORE_EVAS_EWS_EVENT_MOVE, _wm_win_move, NULL); | ||
59 | ecore_event_handler_add(ECORE_EVAS_EWS_EVENT_RESIZE, _wm_win_resize, NULL); | ||
60 | ecore_event_handler_add(ECORE_EVAS_EWS_EVENT_SHOW, _wm_win_show, NULL); | ||
61 | |||
62 | /* one may use any known unique identifier, like an app function pointer */ | ||
63 | ecore_evas_ews_manager_set(optional_ews_window_manager_setup); | ||
64 | } | ||
65 | |||
66 | static void | ||
67 | optional_ews_setup(void) | ||
68 | { | ||
69 | Evas_Object *bg; | ||
70 | Evas *e; | ||
71 | |||
72 | ecore_evas_ews_setup(0, 0, 800, 600); /* "screen" size */ | ||
73 | e = ecore_evas_ews_evas_get(); /* forces "screen" to be allocated */ | ||
74 | |||
75 | bg = evas_object_rectangle_add(e); | ||
76 | evas_object_color_set(bg, 128, 32, 32, 255); | ||
77 | ecore_evas_ews_background_set(bg); | ||
78 | } | ||
79 | |||
80 | static Eina_Bool | ||
81 | _stdin_cb(void *data, Ecore_Fd_Handler *handler) | ||
82 | { | ||
83 | const Eina_List *l; | ||
84 | Ecore_Evas *ee; | ||
85 | char c = getchar(); | ||
86 | |||
87 | if (c == EOF) | ||
88 | { | ||
89 | ecore_main_loop_quit(); | ||
90 | return EINA_FALSE; | ||
91 | } | ||
92 | |||
93 | switch (c) { | ||
94 | case 'h': | ||
95 | printf("hide all windows\n"); | ||
96 | EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee) | ||
97 | ecore_evas_hide(ee); | ||
98 | break; | ||
99 | case 's': | ||
100 | printf("show all windows\n"); | ||
101 | EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee) | ||
102 | ecore_evas_show(ee); | ||
103 | break; | ||
104 | case 'l': | ||
105 | printf("move all windows left\n"); | ||
106 | EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee) | ||
107 | { | ||
108 | int x, y; | ||
109 | ecore_evas_geometry_get(ee, &x, &y, NULL, NULL); | ||
110 | ecore_evas_move(ee, x - 10, y); | ||
111 | } | ||
112 | break; | ||
113 | case 'r': | ||
114 | printf("move all windows right\n"); | ||
115 | EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee) | ||
116 | { | ||
117 | int x, y; | ||
118 | ecore_evas_geometry_get(ee, &x, &y, NULL, NULL); | ||
119 | ecore_evas_move(ee, x + 10, y); | ||
120 | } | ||
121 | break; | ||
122 | case 't': | ||
123 | printf("move all windows top\n"); | ||
124 | EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee) | ||
125 | { | ||
126 | int x, y; | ||
127 | ecore_evas_geometry_get(ee, &x, &y, NULL, NULL); | ||
128 | ecore_evas_move(ee, x, y - 10); | ||
129 | } | ||
130 | break; | ||
131 | case 'b': | ||
132 | printf("move all windows bottom\n"); | ||
133 | EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee) | ||
134 | { | ||
135 | int x, y; | ||
136 | ecore_evas_geometry_get(ee, &x, &y, NULL, NULL); | ||
137 | ecore_evas_move(ee, x, y + 10); | ||
138 | } | ||
139 | break; | ||
140 | case 'S': | ||
141 | printf("make all windows smaller\n"); | ||
142 | EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee) | ||
143 | { | ||
144 | int w, h; | ||
145 | ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); | ||
146 | ecore_evas_resize(ee, w - 10, h - 10); | ||
147 | } | ||
148 | break; | ||
149 | case 'B': | ||
150 | printf("make all windows bigger\n"); | ||
151 | EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee) | ||
152 | { | ||
153 | int w, h; | ||
154 | ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); | ||
155 | ecore_evas_resize(ee, w + 10, h + 10); | ||
156 | } | ||
157 | break; | ||
158 | case 'm': | ||
159 | printf("make all windows unmaximized\n"); | ||
160 | EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee) | ||
161 | ecore_evas_maximized_set(ee, EINA_FALSE); | ||
162 | break; | ||
163 | case 'M': | ||
164 | printf("make all windows maximized\n"); | ||
165 | EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee) | ||
166 | ecore_evas_maximized_set(ee, EINA_TRUE); | ||
167 | break; | ||
168 | case 'i': | ||
169 | printf("make all windows uniconified\n"); | ||
170 | EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee) | ||
171 | ecore_evas_iconified_set(ee, EINA_FALSE); | ||
172 | break; | ||
173 | case 'I': | ||
174 | printf("make all windows iconified\n"); | ||
175 | EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee) | ||
176 | ecore_evas_iconified_set(ee, EINA_TRUE); | ||
177 | break; | ||
178 | case 'f': | ||
179 | printf("make all windows unfullscreen\n"); | ||
180 | EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee) | ||
181 | ecore_evas_fullscreen_set(ee, EINA_FALSE); | ||
182 | break; | ||
183 | case 'F': | ||
184 | printf("make all windows fullscreen\n"); | ||
185 | EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee) | ||
186 | ecore_evas_fullscreen_set(ee, EINA_TRUE); | ||
187 | break; | ||
188 | case 'q': | ||
189 | printf("quit\n"); | ||
190 | ecore_main_loop_quit(); | ||
191 | break; | ||
192 | default: | ||
193 | if (!isspace(c)) | ||
194 | printf("Unknown command: %c\n", c); | ||
195 | } | ||
196 | return ECORE_CALLBACK_RENEW; | ||
197 | } | ||
198 | |||
199 | static void | ||
200 | _on_delete(Ecore_Evas *ee) | ||
201 | { | ||
202 | free(ecore_evas_data_get(ee, "key")); | ||
203 | ecore_main_loop_quit(); | ||
204 | } | ||
205 | |||
206 | int | ||
207 | main(void) | ||
208 | { | ||
209 | Ecore_Evas *ee; | ||
210 | Evas *canvas; | ||
211 | Evas_Object *bg; | ||
212 | |||
213 | if (ecore_evas_init() <= 0) | ||
214 | return 1; | ||
215 | |||
216 | optional_ews_setup(); | ||
217 | optional_ews_window_manager_setup(); | ||
218 | |||
219 | /* everything should look similar to ecore_evas_basic_example */ | ||
220 | ee = ecore_evas_ews_new(0, 0, 200, 200); | ||
221 | ecore_evas_title_set(ee, "Ecore Evas EWS Example"); | ||
222 | ecore_evas_show(ee); | ||
223 | |||
224 | ecore_evas_data_set(ee, "key", strdup("hello")); | ||
225 | ecore_evas_callback_delete_request_set(ee, _on_delete); | ||
226 | |||
227 | printf("Using %s engine!\n", ecore_evas_engine_name_get(ee)); | ||
228 | |||
229 | canvas = ecore_evas_get(ee); | ||
230 | if(ecore_evas_ecore_evas_get(canvas) == ee) | ||
231 | printf("Everything is sane!\n"); | ||
232 | |||
233 | bg = evas_object_rectangle_add(canvas); | ||
234 | evas_object_color_set(bg, 0, 0, 255, 255); | ||
235 | evas_object_resize(bg, 200, 200); | ||
236 | evas_object_show(bg); | ||
237 | ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE); | ||
238 | |||
239 | /* moving the window should move it in the screen */ | ||
240 | ecore_evas_move(ee, 50, 50); | ||
241 | |||
242 | ecore_main_fd_handler_add(STDIN_FILENO, | ||
243 | ECORE_FD_READ | ECORE_FD_ERROR, | ||
244 | _stdin_cb, | ||
245 | NULL, NULL, NULL); | ||
246 | |||
247 | ecore_main_loop_begin(); | ||
248 | |||
249 | ecore_evas_free(ee); | ||
250 | ecore_evas_shutdown(); | ||
251 | |||
252 | return 0; | ||
253 | } | ||