aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/examples/evas-stacking.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/evas/src/examples/evas-stacking.c')
-rw-r--r--libraries/evas/src/examples/evas-stacking.c329
1 files changed, 0 insertions, 329 deletions
diff --git a/libraries/evas/src/examples/evas-stacking.c b/libraries/evas/src/examples/evas-stacking.c
deleted file mode 100644
index 49fc819..0000000
--- a/libraries/evas/src/examples/evas-stacking.c
+++ /dev/null
@@ -1,329 +0,0 @@
1/**
2 * Simple Evas example illustrating <b>objects stacking</b> and
3 * <b>canvas layers</b>.
4 *
5 * You'll need at least one engine built for it (excluding the buffer
6 * one) and the png image loader also built. See stdout/stderr for
7 * output.
8 *
9 * @verbatim
10 * gcc -o evas-stacking evas-stacking.c `pkg-config --libs --cflags evas ecore ecore-evas edje`
11 * @endverbatim
12 */
13
14#ifdef HAVE_CONFIG_H
15#include "config.h"
16#else
17
18#define __UNUSED__
19
20#endif
21
22#include <Ecore.h>
23#include <Ecore_Evas.h>
24
25#include <stdlib.h>
26#include <stdio.h>
27#include <string.h>
28
29#define WIDTH 320
30#define HEIGHT 320
31
32struct test_data
33{
34 Ecore_Evas *ee;
35 Evas *canvas;
36 Evas_Object *bg;
37 Evas_Object *rects[3]; /* red, green, blue */
38 int layers[3]; /* default, below it, above it */
39 int cur_rect, cur_layer;
40};
41
42static struct test_data d = {0};
43
44static const char *commands = \
45 "commands are:\n"
46 "\tc - change the target rectangle to operate on\n"
47 "\ta - stack target rectangle one level above\n"
48 "\tb - stack target rectangle one level below\n"
49 "\tt - stack target rectangle up to the top of its layer\n"
50 "\tm - stack target rectangle down to the bottom of its layer\n"
51 "\tp - toggle target rectangle's 'pass events' property\n"
52 "\tr - toggle target rectangle's 'repeat events' property\n"
53 "\ts - print current stacking information\n"
54 "\tl - change background rectangle's layer\n"
55 "\th - print help\n";
56
57static void
58_on_mouse_down(void *data __UNUSED__,
59 Evas *evas __UNUSED__,
60 Evas_Object *o,
61 void *einfo __UNUSED__)
62{
63 fprintf(stdout, "Mouse down on rectangle %s!\n", evas_object_name_get(o));
64}
65
66/* here just to keep our example's window size and background image's
67 * size in synchrony */
68static void
69_canvas_resize_cb(Ecore_Evas *ee)
70{
71 int w, h;
72
73 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
74 evas_object_resize(d.bg, w, h);
75}
76
77/* use the following commands to interact with this example - 'h' is
78 * the key for help */
79static void
80_on_keydown(void *data __UNUSED__,
81 Evas *evas __UNUSED__,
82 Evas_Object *o __UNUSED__,
83 void *einfo)
84{
85 Evas_Event_Key_Down *ev = einfo;
86 const char *name = evas_object_name_get(d.rects[d.cur_rect]);
87
88 if (strcmp(ev->keyname, "h") == 0) /* print help */
89 {
90 fprintf(stdout, commands);
91 return;
92 }
93
94 if (strcmp(ev->keyname, "s") == 0) /* get status of the
95 * rectangles WRT size
96 * hints */
97 {
98 Evas_Object *rect;
99
100 fprintf(stdout, "Order of stacking, from top to bottom, is: ");
101
102 rect = evas_object_top_get(evas);
103 fprintf(stdout, "%s", evas_object_name_get(rect));
104
105 rect = evas_object_below_get(rect);
106 while (rect)
107 {
108 fprintf(stdout, ", %s", evas_object_name_get(rect));
109 rect = evas_object_below_get(rect);
110 }
111
112 fprintf(stdout, ".\n");
113
114 fprintf(stdout, "Current target rectangle is %s\n",
115 evas_object_name_get(d.rects[d.cur_rect]));
116
117 fprintf(stdout, "Background rectangle's layer is %d\n",
118 evas_object_layer_get(d.bg));
119
120 return;
121 }
122
123 if (strcmp(ev->keyname, "l") == 0) /* change background rectangle's layer */
124 {
125 d.cur_layer = (d.cur_layer + 1) % 3;
126 evas_object_layer_set(d.bg, d.layers[d.cur_layer]);
127
128 fprintf(stdout, "Changing background rectangle's layer to %d\n",
129 d.layers[d.cur_layer]);
130 return;
131 }
132
133 if (strcmp(ev->keyname, "c") == 0) /* change rectangle to operate on */
134 {
135 d.cur_rect = (d.cur_rect + 1) % 3;
136
137 fprintf(stdout, "Changing target rectangle to the %s one\n",
138 evas_object_name_get(d.rects[d.cur_rect]));
139 return;
140 }
141
142 if (strcmp(ev->keyname, "t") == 0) /* bring target to top */
143 {
144 Evas_Object *neighbour;
145
146 evas_object_raise(d.rects[d.cur_rect]);
147
148 fprintf(stdout, "%s rectangle was re-stacked to the top if its layer\n",
149 name);
150
151 neighbour = evas_object_below_get(d.rects[d.cur_rect]);
152 fprintf(stdout, "Below of %s rect is %s\n", name,
153 neighbour ? evas_object_name_get(neighbour) : "no object");
154 return;
155 }
156
157 if (strcmp(ev->keyname, "m") == 0) /* bring target to bottom */
158 {
159 Evas_Object *neighbour;
160
161 evas_object_lower(d.rects[d.cur_rect]);
162
163 fprintf(stdout,
164 "%s rectangle was re-stacked to the bottom if its layer\n",
165 name);
166
167 neighbour = evas_object_below_get(d.rects[d.cur_rect]);
168 fprintf(stdout, "Below of %s rect is %s\n", name,
169 neighbour ? evas_object_name_get(neighbour) : "no object");
170 return;
171 }
172
173 if (strcmp(ev->keyname, "p") == 0) /* toggle pass events */
174 {
175 Eina_Bool pass = evas_object_pass_events_get(d.rects[d.cur_rect]);
176
177 evas_object_pass_events_set(d.rects[d.cur_rect], !pass);
178
179 fprintf(stdout, "%s rectangle is now set to%s pass (ignore) events\n",
180 name, pass ? " NOT" : "");
181
182 return;
183 }
184
185 if (strcmp(ev->keyname, "r") == 0) /* toggle repeat events */
186 {
187 Eina_Bool repeat = evas_object_repeat_events_get(d.rects[d.cur_rect]);
188
189 evas_object_repeat_events_set(d.rects[d.cur_rect], !repeat);
190
191 fprintf(stdout, "%s rectangle is now set to%s repeat events\n",
192 name, repeat ? " NOT" : "");
193
194 return;
195 }
196
197 if (strcmp(ev->keyname, "a") == 0) /* stack target above */
198 {
199 Evas_Object *neighbour = evas_object_above_get(d.rects[d.cur_rect]);
200
201 if (!neighbour || (evas_object_layer_get(d.rects[d.cur_rect]) !=
202 evas_object_layer_get(neighbour)))
203 return;
204
205 evas_object_stack_above(d.rects[d.cur_rect], neighbour);
206
207 fprintf(stdout, "%s rectangle was re-stacked one level above\n", name);
208
209 neighbour = evas_object_above_get(d.rects[d.cur_rect]);
210 fprintf(stdout, "Above of %s rect is %s\n", name,
211 neighbour ? evas_object_name_get(neighbour) : "no object");
212
213 neighbour = evas_object_below_get(d.rects[d.cur_rect]);
214 fprintf(stdout, "Below of %s rect is %s\n", name,
215 neighbour ? evas_object_name_get(neighbour) : "no object");
216 return;
217 }
218
219 if (strcmp(ev->keyname, "b") == 0) /* stack target below */
220 {
221 Evas_Object *neighbour = evas_object_below_get(d.rects[d.cur_rect]);
222
223 if (!neighbour || (evas_object_layer_get(d.rects[d.cur_rect]) !=
224 evas_object_layer_get(neighbour)))
225 return;
226
227 evas_object_stack_below(d.rects[d.cur_rect], neighbour);
228
229 fprintf(stdout, "%s rectangle was re-stacked one level below\n", name);
230
231 neighbour = evas_object_above_get(d.rects[d.cur_rect]);
232 fprintf(stdout, "Above of %s rect is %s\n", name,
233 neighbour ? evas_object_name_get(neighbour) : "no object");
234
235 neighbour = evas_object_below_get(d.rects[d.cur_rect]);
236
237 fprintf(stdout, "Below of %s rect is %s\n", name,
238 neighbour ? evas_object_name_get(neighbour) : "no object");
239 return;
240 }
241}
242
243static void
244_on_destroy(Ecore_Evas *ee __UNUSED__)
245{
246 ecore_main_loop_quit();
247}
248
249int
250main(void)
251{
252 if (!ecore_evas_init())
253 return EXIT_FAILURE;
254
255 /* this will give you a window with an Evas canvas under the first
256 * engine available */
257 d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
258 if (!d.ee)
259 goto error;
260
261 ecore_evas_callback_destroy_set(d.ee, _on_destroy);
262 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
263 ecore_evas_show(d.ee);
264
265 /* the canvas pointer, de facto */
266 d.canvas = ecore_evas_get(d.ee);
267
268 d.bg = evas_object_rectangle_add(d.canvas);
269 evas_object_name_set(d.bg, "background"); /* white bg */
270 evas_object_color_set(d.bg, 255, 255, 255, 255);
271 evas_object_move(d.bg, 0, 0);
272 evas_object_resize(d.bg, WIDTH, HEIGHT);
273
274 d.layers[0] = evas_object_layer_get(d.bg);
275 d.layers[1] = d.layers[0] - 1;
276 d.layers[2] = d.layers[0] + 1;
277
278 d.cur_layer = 1;
279 evas_object_layer_set(d.bg, d.layers[d.cur_layer]); /* let's start with it
280 * below the default
281 * layer */
282
283 evas_object_show(d.bg);
284
285 evas_object_focus_set(d.bg, EINA_TRUE);
286 evas_object_event_callback_add(
287 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
288
289 d.rects[2] = evas_object_rectangle_add(d.canvas);
290 evas_object_name_set(d.rects[2], "blue");
291 evas_object_color_set(d.rects[2], 0, 0, 255, 255);
292
293 evas_object_resize(d.rects[2], WIDTH / 2.2, WIDTH / 2.2);
294 evas_object_move(d.rects[2], WIDTH / 6, WIDTH / 4.5);
295 evas_object_show(d.rects[2]);
296 evas_object_event_callback_add(
297 d.rects[2], EVAS_CALLBACK_MOUSE_DOWN, _on_mouse_down, NULL);
298
299 d.rects[1] = evas_object_rectangle_add(d.canvas);
300 evas_object_name_set(d.rects[1], "green");
301 evas_object_color_set(d.rects[1], 0, 255, 0, 255);
302
303 evas_object_resize(d.rects[1], WIDTH / 2.2, WIDTH / 2.2);
304 evas_object_move(d.rects[1], WIDTH / 2.5, WIDTH / 7);
305 evas_object_show(d.rects[1]);
306 evas_object_event_callback_add(
307 d.rects[1], EVAS_CALLBACK_MOUSE_DOWN, _on_mouse_down, NULL);
308
309 d.rects[0] = evas_object_rectangle_add(d.canvas);
310 evas_object_name_set(d.rects[0], "red");
311 evas_object_color_set(d.rects[0], 255, 0, 0, 255);
312
313 evas_object_resize(d.rects[0], WIDTH / 2.2, WIDTH / 2.2);
314 evas_object_move(d.rects[0], WIDTH / 3, WIDTH / 2.5);
315 evas_object_show(d.rects[0]);
316 evas_object_event_callback_add(
317 d.rects[0], EVAS_CALLBACK_MOUSE_DOWN, _on_mouse_down, NULL);
318
319 fprintf(stdout, commands);
320 ecore_main_loop_begin();
321
322 ecore_evas_shutdown();
323 return 0;
324
325error:
326 fprintf(stderr, "you got to have at least one evas engine built and linked"
327 " up to ecore-evas for this example to run properly.\n");
328 return -1;
329}