summaryrefslogtreecommitdiff
path: root/src/examples/evas
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-11-14 20:12:53 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-11-14 20:12:53 +0000
commit80910393d6c88f55a8d02813a05481b298a6ef71 (patch)
treec55d60a98628be19a7336ef20a120e8ed78c7f54 /src/examples/evas
parent52e0d5417466418af18254cf40a2099dc5c6e2f0 (diff)
merge: add evas tests and examples
SVN revision: 79300
Diffstat (limited to 'src/examples/evas')
-rw-r--r--src/examples/evas/Makefile.ambin0 -> 3911 bytes
-rw-r--r--src/examples/evas/aspect.edc17
-rw-r--r--src/examples/evas/cube1.pngbin0 -> 183167 bytes
-rw-r--r--src/examples/evas/enlightenment.pngbin0 -> 17541 bytes
-rw-r--r--src/examples/evas/evas-aspect-hints.c249
-rw-r--r--src/examples/evas/evas-box.c382
-rw-r--r--src/examples/evas/evas-buffer-simple.c228
-rw-r--r--src/examples/evas/evas-events.c413
-rw-r--r--src/examples/evas/evas-hints.c378
-rw-r--r--src/examples/evas/evas-images.c353
-rw-r--r--src/examples/evas/evas-images2.c311
-rw-r--r--src/examples/evas/evas-images3.c196
-rw-r--r--src/examples/evas/evas-init-shutdown.c56
-rw-r--r--src/examples/evas/evas-map-utils.c321
-rw-r--r--src/examples/evas/evas-object-manipulation.c235
-rw-r--r--src/examples/evas/evas-smart-interface.c790
-rw-r--r--src/examples/evas/evas-smart-object.c756
-rw-r--r--src/examples/evas/evas-stacking.c329
-rw-r--r--src/examples/evas/evas-table.c120
-rw-r--r--src/examples/evas/evas-text.c411
-rw-r--r--src/examples/evas/im1.pngbin0 -> 467518 bytes
-rw-r--r--src/examples/evas/red.pngbin0 -> 225 bytes
22 files changed, 5545 insertions, 0 deletions
diff --git a/src/examples/evas/Makefile.am b/src/examples/evas/Makefile.am
new file mode 100644
index 0000000..5da4518
--- /dev/null
+++ b/src/examples/evas/Makefile.am
Binary files differ
diff --git a/src/examples/evas/aspect.edc b/src/examples/evas/aspect.edc
new file mode 100644
index 0000000..b8bfb31
--- /dev/null
+++ b/src/examples/evas/aspect.edc
@@ -0,0 +1,17 @@
1collections {
2 group {
3 name: "main";
4 parts {
5 part {
6 name: "content";
7 mouse_events: 0;
8 type: SWALLOW;
9 description {
10 state: "default" 0.0;
11 visible: 1;
12 }
13 }
14 }
15 }
16}
17
diff --git a/src/examples/evas/cube1.png b/src/examples/evas/cube1.png
new file mode 100644
index 0000000..c2f4fda
--- /dev/null
+++ b/src/examples/evas/cube1.png
Binary files differ
diff --git a/src/examples/evas/enlightenment.png b/src/examples/evas/enlightenment.png
new file mode 100644
index 0000000..aeb836b
--- /dev/null
+++ b/src/examples/evas/enlightenment.png
Binary files differ
diff --git a/src/examples/evas/evas-aspect-hints.c b/src/examples/evas/evas-aspect-hints.c
new file mode 100644
index 0000000..de8ed50
--- /dev/null
+++ b/src/examples/evas/evas-aspect-hints.c
@@ -0,0 +1,249 @@
1/**
2 * Simple Evas example illustrating aspect control hints on objects.
3 *
4 * You'll need at least one engine built for it (excluding the buffer
5 * one) and the png image loader also built. See stdout/stderr for
6 * output.
7 *
8 * You'll also need @b Edje for this one, as it has the only smart
9 * object implementing aspect control for children.
10 *
11 * @verbatim
12 * gcc -o evas-events evas-events.c `pkg-config --libs --cflags ecore-evas edje`
13 * @endverbatim
14 */
15
16#ifdef HAVE_CONFIG_H
17
18#include "config.h"
19#endif
20
21#include <Ecore.h>
22#include <Ecore_Evas.h>
23#include <Edje.h>
24#include <stdio.h>
25#include <errno.h>
26
27#define WIDTH 320
28#define HEIGHT 480
29
30static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
31static const char *edje_file_path = PACKAGE_EXAMPLES_DIR "/aspect.edj";
32
33struct test_data
34{
35 Ecore_Evas *ee;
36 Evas *canvas;
37 Evas_Object *bg, *rect, *container, *border;
38};
39
40static struct test_data d = {0};
41
42/* here just to keep our example's window size and background image's
43 * size in synchrony */
44static void
45_canvas_resize_cb(Ecore_Evas *ee)
46{
47 int w, h;
48
49 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
50 evas_object_resize(d.bg, w, h);
51}
52
53static const char *
54_get_aspect_name(Evas_Aspect_Control aspect)
55{
56 switch (aspect)
57 {
58 case 0:
59 return "NONE";
60
61 case 1:
62 return "NEITHER";
63
64 case 2:
65 return "HORIZONTAL";
66
67 case 3:
68 return "VERTICAL";
69
70 case 4:
71 return "BOTH";
72
73 default:
74 return "INVALID";
75 }
76}
77
78static void
79_on_keydown(void *data __UNUSED__,
80 Evas *evas __UNUSED__,
81 Evas_Object *o,
82 void *einfo)
83{
84 const Evas_Modifier *mods;
85 Evas_Event_Key_Down *ev = einfo;
86
87 mods = evas_key_modifier_get(evas_object_evas_get(o));
88
89 if (evas_key_modifier_is_set(mods, "Shift") &&
90 strcmp(ev->keyname, "h") == 0) /* print help */
91 {
92 fprintf(stdout, "commands are:\n"
93 "\tc - cycle aspect control on object\n"
94 "\th - change horizontal aspect component\n"
95 "\tv - change vertical aspect component\n"
96 "\ts - print current object's status\n"
97 "\tH - print help\n");
98 return;
99 }
100
101 if (strcmp(ev->keyname, "s") == 0) /* get aspect status of the obj */
102 {
103 Evas_Coord w, h;
104 Evas_Aspect_Control aspect;
105
106 evas_object_size_hint_aspect_get(d.rect, &aspect, &w, &h);
107
108 fprintf(stdout, "Object has aspect %s, with horizontal compontent %d"
109 " and vertical compontent %d\n",
110 _get_aspect_name(aspect), w, h);
111
112 return;
113 }
114
115 if (strcmp(ev->keyname, "c") == 0) /* cycle aspect control on obj */
116 {
117 Evas_Coord w, h;
118 Evas_Aspect_Control aspect;
119
120 evas_object_size_hint_aspect_get(d.rect, &aspect, &w, &h);
121
122 aspect = (aspect + 1) % 5;
123
124 evas_object_size_hint_aspect_set(d.rect, aspect, w, h);
125
126 fprintf(stdout, "Changing aspect control to %s\n",
127 _get_aspect_name(aspect));
128
129 return;
130 }
131
132 if (strcmp(ev->keyname, "h") == 0) /* change horizontal aspect component */
133 {
134 Evas_Coord w, h;
135 Evas_Aspect_Control aspect;
136
137 evas_object_size_hint_aspect_get(d.rect, &aspect, &w, &h);
138
139 w = (w + 1) % 3;
140
141 evas_object_size_hint_aspect_set(d.rect, aspect, w, h);
142
143 fprintf(stdout, "Changing horizontal aspect component to %d\n", w);
144
145 return;
146 }
147
148 if (strcmp(ev->keyname, "v") == 0) /* change vertical aspect component */
149 {
150 Evas_Coord w, h;
151 Evas_Aspect_Control aspect;
152
153 evas_object_size_hint_aspect_get(d.rect, &aspect, &w, &h);
154
155 h = (h + 1) % 3;
156
157 evas_object_size_hint_aspect_set(d.rect, aspect, w, h);
158
159 fprintf(stdout, "Changing vertical aspect component to %d\n", h);
160
161 return;
162 }
163}
164
165int
166main(void)
167{
168 Eina_Bool ret;
169
170 if (!ecore_evas_init())
171 return EXIT_FAILURE;
172
173 if (!edje_init())
174 return EXIT_FAILURE;
175
176 /* this will give you a window with an Evas canvas under the first
177 * engine available */
178 d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
179 if (!d.ee)
180 goto error;
181
182 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
183 ecore_evas_show(d.ee);
184
185 /* the canvas pointer, de facto */
186 d.canvas = ecore_evas_get(d.ee);
187
188 d.bg = evas_object_rectangle_add(d.canvas);
189 evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
190 evas_object_move(d.bg, 0, 0); /* at canvas' origin */
191 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
192 evas_object_show(d.bg);
193
194 evas_object_focus_set(d.bg, EINA_TRUE);
195 evas_object_event_callback_add(
196 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
197
198 d.container = edje_object_add(d.canvas);
199 ret = edje_object_file_set(d.container, edje_file_path, "main");
200 if (!ret)
201 {
202 Edje_Load_Error err = edje_object_load_error_get(d.container);
203 const char *msg = edje_load_error_str(err);
204 fprintf(stderr, "could not load 'main' from %s: %s",
205 edje_file_path, msg);
206
207 goto panic;
208 }
209
210 evas_object_move(d.container, (WIDTH / 4), (HEIGHT / 4));
211 evas_object_resize(d.container, (WIDTH / 2), (HEIGHT / 2));
212 evas_object_show(d.container);
213
214 d.rect = evas_object_rectangle_add(d.canvas);
215 evas_object_color_set(d.rect, 0, 0, 255, 255);
216 evas_object_size_hint_aspect_set(d.rect, EVAS_ASPECT_CONTROL_NONE, 1, 1);
217 evas_object_show(d.rect);
218
219 edje_object_part_swallow(d.container, "content", d.rect);
220 evas_object_smart_changed(d.container);
221
222 /* this is a border around the edje object, container of the
223 * rectangle we are going to experiment with (change its aspect
224 * hints). this way you can see how their sizes relate */
225 d.border = evas_object_image_filled_add(d.canvas);
226 evas_object_image_file_set(d.border, border_img_path, NULL);
227 evas_object_image_border_set(d.border, 3, 3, 3, 3);
228 evas_object_image_border_center_fill_set(d.border, EVAS_BORDER_FILL_NONE);
229 evas_object_move(d.border, (WIDTH / 4) - 3, (HEIGHT / 4) - 3);
230 evas_object_resize(d.border, (WIDTH / 2) + 6, (HEIGHT / 2) + 6);
231 evas_object_show(d.border);
232
233 ecore_main_loop_begin();
234
235 ecore_evas_free(d.ee);
236 ecore_evas_shutdown();
237 edje_shutdown();
238 return 0;
239
240error:
241 fprintf(stderr, "you got to have at least one evas engine built and linked"
242 " up to ecore-evas for this example to run properly.\n");
243panic:
244 ecore_evas_free(d.ee);
245 ecore_evas_shutdown();
246 edje_shutdown();
247
248 return -1;
249}
diff --git a/src/examples/evas/evas-box.c b/src/examples/evas/evas-box.c
new file mode 100644
index 0000000..ec79535
--- /dev/null
+++ b/src/examples/evas/evas-box.c
@@ -0,0 +1,382 @@
1/**
2 * Simple Evas example illustrating a custom Evas box object
3 *
4 * You'll need at least one engine built for it (excluding the buffer
5 * one). See stdout/stderr for output.
6 *
7 * @verbatim
8 * gcc -o evas-box evas-box.c `pkg-config --libs --cflags evas ecore ecore-evas eina`
9 * @endverbatim
10 */
11
12#ifdef HAVE_CONFIG_H
13
14#include "config.h"
15#else
16#define PACKAGE_EXAMPLES_DIR "."
17#define __UNUSED__
18#endif
19
20#include <Ecore.h>
21#include <Ecore_Evas.h>
22
23#include <stdlib.h>
24#include <stdio.h>
25#include <string.h>
26
27#define WIDTH (640)
28#define HEIGHT (480)
29
30static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
31
32static const char *commands = \
33 "commands are:\n"
34 "\ta - change the box's alignment values\n"
35 "\tp - change the box's padding values\n"
36 "\t1 - change the box's layout to horizontal\n"
37 "\t2 - change the box's layout to vertical\n"
38 "\t3 - change the box's layout to horizontal homogeneous\n"
39 "\t4 - change the box's layout to vertical homogeneous\n"
40 "\t5 - change the box's layout to horizontal maximum size homogeneous\n"
41 "\t6 - change the box's layout to vertical maximum size homogeneous\n"
42 "\t7 - change the box's layout to horizontal flow\n"
43 "\t8 - change the box's layout to vertical flow\n"
44 "\t9 - change the box's layout to stack\n"
45 "\t0 - change the box's layout to a custom-made one\n"
46 "\tCtrl + NUMBER - insert a new child object at that position in the box\n"
47 "\tShift + NUMBER - remove the child object at that position in the box\n"
48 "\th - print help\n";
49
50struct exemple_data
51{
52 Ecore_Evas *ee;
53 Evas *evas;
54 Evas_Object *bg, *box, *border;
55};
56
57static struct exemple_data d;
58
59static void /* custom 'diagonal' layout */
60_custom_layout(Evas_Object *o,
61 Evas_Object_Box_Data *p,
62 void *data __UNUSED__)
63{
64 int x, y, w, h;
65 int xx, yy, ww, hh;
66 int count;
67 Eina_List *l;
68 Evas_Object_Box_Option *opt;
69
70 evas_object_geometry_get(o, &x, &y, &w, &h);
71 count = eina_list_count(p->children);
72 ww = w / (count ? : 1);
73 hh = h / (count ? : 1);
74 if (ww < 1) ww = 1;
75 if (hh < 1) hh = 1;
76
77 xx = x;
78 yy = y;
79 EINA_LIST_FOREACH(p->children, l, opt)
80 {
81 evas_object_move(opt->obj, xx, yy);
82 xx += ww;
83 yy += hh;
84 }
85}
86
87static Evas_Object * /* new rectangle to be put in the box */
88_new_rectangle_add(Evas *e)
89{
90 Evas_Object *o;
91
92 o = evas_object_rectangle_add(e);
93 evas_object_resize(o, 10, 10);
94 evas_object_color_set(o, 0, 255, 0, 255);
95 evas_object_show(o);
96
97 return o;
98}
99
100/* use the following commands to interact with this example - 'h' is
101 * the key for help */
102static void
103_on_keydown(void *data __UNUSED__,
104 Evas *evas __UNUSED__,
105 Evas_Object *o __UNUSED__,
106 void *einfo)
107{
108 Evas_Event_Key_Down *ev = einfo;
109 const Evas_Modifier *mods = evas_key_modifier_get(evas);
110
111 if (strcmp(ev->keyname, "h") == 0) /* print help */
112 {
113 fprintf(stdout, commands);
114 return;
115 }
116
117 if (evas_key_modifier_is_set(mods, "Shift"))
118 {
119 int pos;
120 Eina_Bool ret;
121 Evas_Object *obj;
122 Eina_List *children;
123
124 pos = atoi(ev->keyname);
125 children = evas_object_box_children_get(d.box);
126
127 obj = eina_list_nth(children, pos);
128 if (!obj) goto list_free;
129
130 ret = evas_object_box_remove_at(d.box, pos);
131 if (ret) evas_object_del(obj);
132
133list_free:
134 eina_list_free(children);
135 return;
136 }
137
138 if (evas_key_modifier_is_set(mods, "Control"))
139 {
140 Evas_Object *o;
141 int pos;
142 pos = atoi(ev->keyname);
143 o = _new_rectangle_add(d.evas);
144 if (!evas_object_box_insert_at(d.box, o, pos))
145 evas_object_box_append(d.box, o);
146 return;
147 }
148
149 if (strcmp(ev->keyname, "a") == 0)
150 {
151 double h, v;
152
153 evas_object_box_align_get(d.box, &h, &v);
154
155 if (h == 0.5)
156 h = v = 1.0;
157 else if (h == 1.0)
158 h = v = -1.0;
159 else if (h == -1.0)
160 h = v = 0.0;
161 else if (h == 0.0)
162 h = v = 0.5;
163
164 evas_object_box_align_set(d.box, h, v);
165
166 fprintf(stdout, "Applying new alignment values (%.1f, %.1f)"
167 " on the box\n", h, v);
168 return;
169 }
170
171 if (strcmp(ev->keyname, "p") == 0)
172 {
173 int h, v;
174
175 evas_object_box_padding_get(d.box, &h, &v);
176
177 if (h == 0)
178 h = v = 50;
179 else
180 h = v = 0;
181
182 evas_object_box_padding_set(d.box, h, v);
183
184 fprintf(stdout, "Applying new padding values (%d, %d)"
185 " on the box\n", h, v);
186 return;
187 }
188
189 if (strcmp(ev->keyname, "1") == 0)
190 {
191 evas_object_box_layout_set(
192 d.box, evas_object_box_layout_horizontal, NULL, NULL);
193
194 fprintf(stdout, "Applying '%s' layout on the box\n", "horizontal");
195 return;
196 }
197
198 if (strcmp(ev->keyname, "2") == 0)
199 {
200 evas_object_box_layout_set(
201 d.box, evas_object_box_layout_vertical, NULL, NULL);
202
203 fprintf(stdout, "Applying '%s' layout on the box\n", "vertical");
204 return;
205 }
206
207 if (strcmp(ev->keyname, "3") == 0)
208 {
209 evas_object_box_layout_set(
210 d.box, evas_object_box_layout_homogeneous_horizontal, NULL,
211 NULL);
212
213 fprintf(stdout, "Applying '%s' layout on the box\n",
214 "horizontal homogeneous");
215 return;
216 }
217
218 if (strcmp(ev->keyname, "4") == 0)
219 {
220 evas_object_box_layout_set(
221 d.box, evas_object_box_layout_homogeneous_vertical, NULL, NULL);
222
223 fprintf(stdout, "Applying '%s' layout on the box\n",
224 "vertical homogeneous");
225 return;
226 }
227
228 if (strcmp(ev->keyname, "5") == 0)
229 {
230 evas_object_box_layout_set(
231 d.box, evas_object_box_layout_homogeneous_max_size_horizontal,
232 NULL, NULL);
233
234 fprintf(stdout, "Applying '%s' layout on the box\n",
235 "horizontal maximum size homogeneous");
236 return;
237 }
238
239 if (strcmp(ev->keyname, "6") == 0)
240 {
241 evas_object_box_layout_set(
242 d.box, evas_object_box_layout_homogeneous_max_size_vertical,
243 NULL, NULL);
244
245 fprintf(stdout, "Applying '%s' layout on the box\n",
246 "vertical maximum size homogeneous");
247 return;
248 }
249
250 if (strcmp(ev->keyname, "7") == 0)
251 {
252 evas_object_box_layout_set(
253 d.box, evas_object_box_layout_flow_horizontal, NULL, NULL);
254
255 fprintf(stdout, "Applying '%s' layout on the box\n", "horizontal flow");
256 return;
257 }
258
259 if (strcmp(ev->keyname, "8") == 0)
260 {
261 evas_object_box_layout_set(
262 d.box, evas_object_box_layout_flow_vertical, NULL, NULL);
263
264 fprintf(stdout, "Applying '%s' layout on the box\n", "vertical flow");
265 return;
266 }
267
268 if (strcmp(ev->keyname, "9") == 0)
269 {
270 evas_object_box_layout_set(
271 d.box, evas_object_box_layout_stack, NULL, NULL);
272
273 fprintf(stdout, "Applying '%s' layout on the box\n", "stack");
274 return;
275 }
276
277 if (strcmp(ev->keyname, "0") == 0)
278 {
279 evas_object_box_layout_set(d.box, _custom_layout, NULL, NULL);
280
281 fprintf(stdout, "Applying '%s' layout on the box\n", "CUSTOM");
282 return;
283 }
284}
285
286static void
287_on_delete(Ecore_Evas *ee __UNUSED__)
288{
289 ecore_main_loop_quit();
290}
291
292static void /* adjust canvas' contents on resizes */
293_canvas_resize_cb(Ecore_Evas *ee)
294{
295 int w, h;
296
297 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
298
299 evas_object_resize(d.bg, w, h);
300
301 evas_object_move(d.box, (w / 4), (h / 4));
302 evas_object_resize(d.box, (w / 2), (h / 2));
303
304 evas_object_move(d.border, (w / 4) - 2, (h / 4) - 2);
305 evas_object_resize(d.border, (w / 2) + 4, (h / 2) + 4);
306}
307
308int
309main(void)
310{
311 Evas_Object *last, *o;
312 int i;
313
314 srand(time(NULL));
315
316 if (!ecore_evas_init())
317 return EXIT_FAILURE;
318
319 /* this will give you a window with an Evas canvas under the first
320 * engine available */
321 d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
322 if (!d.ee)
323 goto panic;
324
325 ecore_evas_callback_delete_request_set(d.ee, _on_delete);
326 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
327 ecore_evas_show(d.ee);
328
329 d.evas = ecore_evas_get(d.ee);
330
331 d.bg = evas_object_rectangle_add(d.evas);
332 evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
333 evas_object_show(d.bg);
334
335 evas_object_focus_set(d.bg, EINA_TRUE);
336 evas_object_event_callback_add(
337 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
338
339 d.box = evas_object_box_add(d.evas);
340 evas_object_show(d.box);
341
342 for (i = 1; i <= 5; i++)
343 {
344 o = last = evas_object_rectangle_add(d.evas);
345 evas_object_size_hint_min_set(o, 50, 50);
346 evas_object_color_set(
347 o, rand() % 256, rand() % 256, rand() % 256, 255);
348 evas_object_show(o);
349
350 if (!evas_object_box_append(d.box, o))
351 {
352 fprintf(stderr, "Error appending child object on the box!\n");
353 goto error;
354 }
355 }
356
357 /* this is a border around the box, container of the rectangles we
358 * are going to experiment with. this way you can see how the
359 * container relates to the children */
360 d.border = evas_object_image_filled_add(d.evas);
361 evas_object_image_file_set(d.border, border_img_path, NULL);
362 evas_object_image_border_set(d.border, 2, 2, 2, 2);
363 evas_object_image_border_center_fill_set(d.border, EVAS_BORDER_FILL_NONE);
364 evas_object_show(d.border);
365
366 fprintf(stdout, commands);
367
368 _canvas_resize_cb(d.ee);
369 ecore_main_loop_begin();
370 ecore_evas_shutdown();
371 return 0;
372
373error:
374 ecore_evas_shutdown();
375 return -1;
376
377panic:
378 fprintf(stderr, "You got to have at least one evas engine built and linked"
379 " up to ecore-evas for this example to run properly.\n");
380 return -2;
381}
382
diff --git a/src/examples/evas/evas-buffer-simple.c b/src/examples/evas/evas-buffer-simple.c
new file mode 100644
index 0000000..6676ef1
--- /dev/null
+++ b/src/examples/evas/evas-buffer-simple.c
@@ -0,0 +1,228 @@
1/**
2 * Simple Evas example using the Buffer engine.
3 *
4 * You must have Evas compiled with the buffer engine, and have the
5 * evas-software-buffer pkg-config files installed.
6 *
7 * Compile with:
8 *
9 * @verbatim
10 * gcc -o evas-buffer-simple evas-buffer-simple.c `pkg-config --libs --cflags evas evas-software-buffer`
11 * @endverbatim
12 *
13 */
14#include <Evas.h>
15#include <Evas_Engine_Buffer.h>
16#include <stdio.h>
17#include <errno.h>
18
19#define WIDTH (320)
20#define HEIGHT (240)
21
22/*
23 * create_canvas(), destroy_canvas() and draw_scene() are support functions.
24 *
25 * They are only required to use raw Evas, but for real world usage,
26 * it is recommended to use ecore and its ecore-evas submodule, that
27 * provide convenience canvas creators, integration with main loop and
28 * automatic render of updates (draw_scene()) when system goes back to
29 * main loop.
30 */
31static Evas *create_canvas(int width, int height);
32static void destroy_canvas(Evas *canvas);
33static void draw_scene(Evas *canvas);
34
35// support function to save scene as PPM image
36static void save_scene(Evas *canvas, const char *dest);
37
38int main(void)
39{
40 Evas *canvas;
41 Evas_Object *bg, *r1, *r2, *r3;
42
43 evas_init();
44
45 // create your canvas
46 // NOTE: consider using ecore_evas_buffer_new() instead!
47 canvas = create_canvas(WIDTH, HEIGHT);
48 if (!canvas)
49 return -1;
50
51 bg = evas_object_rectangle_add(canvas);
52 evas_object_color_set(bg, 255, 255, 255, 255); // white bg
53 evas_object_move(bg, 0, 0); // at origin
54 evas_object_resize(bg, WIDTH, HEIGHT); // covers full canvas
55 evas_object_show(bg);
56
57 puts("initial scene, with just background:");
58 draw_scene(canvas);
59
60 r1 = evas_object_rectangle_add(canvas);
61 evas_object_color_set(r1, 255, 0, 0, 255); // 100% opaque red
62 evas_object_move(r1, 10, 10);
63 evas_object_resize(r1, 100, 100);
64 evas_object_show(r1);
65
66 // pay attention to transparency! Evas color values are pre-multiplied by
67 // alpha, so 50% opaque green is:
68 // non-premul: r=0, g=255, b=0 a=128 (50% alpha)
69 // premul:
70 // r_premul = r * a / 255 = 0 * 128 / 255 = 0
71 // g_premul = g * a / 255 = 255 * 128 / 255 = 128
72 // b_premul = b * a / 255 = 0 * 128 / 255 = 0
73 //
74 // this 50% green is over a red background, so it will show in the
75 // final output as yellow (green + red = yellow)
76 r2 = evas_object_rectangle_add(canvas);
77 evas_object_color_set(r2, 0, 128, 0, 128); // 50% opaque green
78 evas_object_move(r2, 10, 10);
79 evas_object_resize(r2, 50, 50);
80 evas_object_show(r2);
81
82 r3 = evas_object_rectangle_add(canvas);
83 evas_object_color_set(r3, 0, 128, 0, 255); // 100% opaque dark green
84 evas_object_move(r3, 60, 60);
85 evas_object_resize(r3, 50, 50);
86 evas_object_show(r3);
87
88 puts("final scene (note updates):");
89 draw_scene(canvas);
90 save_scene(canvas, "/tmp/evas-buffer-simple-render.ppm");
91
92 // NOTE: use ecore_evas_buffer_new() and here ecore_evas_free()
93 destroy_canvas(canvas);
94
95 evas_shutdown();
96
97 return 0;
98}
99
100static Evas *create_canvas(int width, int height)
101{
102 Evas *canvas;
103 Evas_Engine_Info_Buffer *einfo;
104 int method;
105 void *pixels;
106
107 method = evas_render_method_lookup("buffer");
108 if (method <= 0)
109 {
110 fputs("ERROR: evas was not compiled with 'buffer' engine!\n", stderr);
111 return NULL;
112 }
113
114 canvas = evas_new();
115 if (!canvas)
116 {
117 fputs("ERROR: could not instantiate new evas canvas.\n", stderr);
118 return NULL;
119 }
120
121 evas_output_method_set(canvas, method);
122 evas_output_size_set(canvas, width, height);
123 evas_output_viewport_set(canvas, 0, 0, width, height);
124
125 einfo = (Evas_Engine_Info_Buffer *)evas_engine_info_get(canvas);
126 if (!einfo)
127 {
128 fputs("ERROR: could not get evas engine info!\n", stderr);
129 evas_free(canvas);
130 return NULL;
131 }
132
133 // ARGB32 is sizeof(int), that is 4 bytes, per pixel
134 pixels = malloc(width * height * sizeof(int));
135 if (!pixels)
136 {
137 fputs("ERROR: could not allocate canvas pixels!\n", stderr);
138 evas_free(canvas);
139 return NULL;
140 }
141
142 einfo->info.depth_type = EVAS_ENGINE_BUFFER_DEPTH_ARGB32;
143 einfo->info.dest_buffer = pixels;
144 einfo->info.dest_buffer_row_bytes = width * sizeof(int);
145 einfo->info.use_color_key = 0;
146 einfo->info.alpha_threshold = 0;
147 einfo->info.func.new_update_region = NULL;
148 einfo->info.func.free_update_region = NULL;
149 evas_engine_info_set(canvas, (Evas_Engine_Info *)einfo);
150
151 return canvas;
152}
153
154static void destroy_canvas(Evas *canvas)
155{
156 Evas_Engine_Info_Buffer *einfo;
157
158 einfo = (Evas_Engine_Info_Buffer *)evas_engine_info_get(canvas);
159 if (!einfo)
160 {
161 fputs("ERROR: could not get evas engine info!\n", stderr);
162 evas_free(canvas);
163 return;
164 }
165
166 free(einfo->info.dest_buffer);
167 evas_free(canvas);
168}
169
170static void draw_scene(Evas *canvas)
171{
172 Eina_List *updates, *n;
173 Eina_Rectangle *update;
174
175 // render and get the updated rectangles:
176 updates = evas_render_updates(canvas);
177
178 // informative only here, just print the updated areas:
179 EINA_LIST_FOREACH(updates, n, update)
180 printf("UPDATED REGION: pos: %3d, %3d size: %3dx%3d\n",
181 update->x, update->y, update->w, update->h);
182
183 // free list of updates
184 evas_render_updates_free(updates);
185}
186
187static void save_scene(Evas *canvas, const char *dest)
188{
189 Evas_Engine_Info_Buffer *einfo;
190 const unsigned int *pixels, *pixels_end;
191 int width, height;
192 FILE *f;
193
194 einfo = (Evas_Engine_Info_Buffer *)evas_engine_info_get(canvas);
195 if (!einfo)
196 {
197 fputs("ERROR: could not get evas engine info!\n", stderr);
198 return;
199 }
200 evas_output_size_get(canvas, &width, &height);
201
202 f = fopen(dest, "wb+");
203 if (!f)
204 {
205 fprintf(stderr, "ERROR: could not open for writing '%s': %s\n",
206 dest, strerror(errno));
207 return;
208 }
209
210 pixels = einfo->info.dest_buffer;
211 pixels_end = pixels + (width * height);
212
213 // PPM P6 format is dead simple to write:
214 fprintf(f, "P6\n%d %d\n255\n", width, height);
215 for (; pixels < pixels_end; pixels++)
216 {
217 int r, g, b;
218
219 r = ((*pixels) & 0xff0000) >> 16;
220 g = ((*pixels) & 0x00ff00) >> 8;
221 b = (*pixels) & 0x0000ff;
222
223 fprintf(f, "%c%c%c", r, g, b);
224 }
225
226 fclose(f);
227 printf("saved scene as '%s'\n", dest);
228}
diff --git a/src/examples/evas/evas-events.c b/src/examples/evas/evas-events.c
new file mode 100644
index 0000000..28b22ed
--- /dev/null
+++ b/src/examples/evas/evas-events.c
@@ -0,0 +1,413 @@
1/**
2 * Simple Evas example illustrating how to interact with canvas' (and
3 * its objects') events and other canvas operations.
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-events evas-events.c `pkg-config --libs --cflags evas ecore ecore-evas`
11 * @endverbatim
12 */
13
14#ifdef HAVE_CONFIG_H
15
16#include "config.h"
17#else
18
19#define PACKAGE_EXAMPLES_DIR "."
20#define __UNUSED__
21
22#endif
23
24#include <Ecore.h>
25#include <Ecore_Evas.h>
26#include <stdio.h>
27#include <errno.h>
28
29#define WIDTH (320)
30#define HEIGHT (240)
31
32static const char *img_path = PACKAGE_EXAMPLES_DIR "/enlightenment.png";
33
34static const char *commands = \
35 "commands are:\n"
36 "\ta - toggle animation timer\n"
37 "\tc - cycle between focus and key grabs for key input\n"
38 "\td - delete canvas callbacks\n"
39 "\tf - freeze input for 3 seconds\n"
40 "\tp - toggle precise point collision detection on image\n"
41 "\tControl + o - add an obscured rectangle\n"
42 "\th - print help\n";
43
44struct test_data
45{
46 Ecore_Evas *ee;
47 Evas *canvas;
48 Evas_Object *img, *bg;
49 Ecore_Timer *resize_timer, *freeze_timer;
50 Eina_Bool obscured, focus;
51};
52
53static struct test_data d = {0};
54
55/* here to keep our example's window size and background image's
56 * size in synchrony */
57static void
58_canvas_resize_cb(Ecore_Evas *ee)
59{
60 int w, h;
61
62 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
63 evas_object_resize(d.bg, w, h);
64}
65
66/* called when our rectangle gets focus */
67static void
68_object_focus_in_cb(void *data __UNUSED__,
69 Evas *e,
70 void *event_info)
71{
72 fprintf(stdout, "An object got focused: %s\n",
73 evas_object_name_get(event_info));
74
75 fprintf(stdout, "Let's recheck it: %s\n",
76 evas_object_name_get(evas_focus_get(e)));
77
78 fprintf(stdout, "And again: %s\n", evas_object_focus_get(event_info) ?
79 "OK!" : "Oops, something is bad.");
80}
81
82/* render flush callback */
83static void
84_render_flush_cb(void *data __UNUSED__,
85 Evas *e __UNUSED__,
86 void *event_info __UNUSED__)
87{
88 fprintf(stdout, "Canvas is about to flush its rendering pipeline!\n");
89}
90
91/* put some action in the canvas */
92static Eina_Bool
93_resize_cb(void *data __UNUSED__)
94{
95 int w, h, cw, ch;
96
97 evas_object_geometry_get(d.img, NULL, NULL, &w, &h);
98 ecore_evas_geometry_get(d.ee, NULL, NULL, &cw, &ch);
99
100 if (w < cw)
101 evas_object_resize(d.img, cw, ch);
102 else
103 evas_object_resize(d.img, cw / 2, ch / 2);
104
105 return EINA_TRUE; /* re-issue the timer */
106}
107
108/* let's have our events back */
109static Eina_Bool
110_thaw_cb(void *data __UNUSED__)
111{
112 fprintf(stdout, "Canvas was frozen %d times, now thawing.\n",
113 evas_event_freeze_get(d.canvas));
114 evas_event_thaw(d.canvas);
115 return EINA_FALSE; /* do not re-issue the timer */
116}
117
118/* mouse enters the object's area */
119static void
120_on_mouse_in(void *data __UNUSED__,
121 Evas *evas __UNUSED__,
122 Evas_Object *o __UNUSED__,
123 void *einfo __UNUSED__)
124{
125 fprintf(stdout, "Enlightenment logo has had the mouse in.\n");
126}
127
128static void
129_on_mouse_out(void *data __UNUSED__,
130 Evas *evas __UNUSED__,
131 Evas_Object *o __UNUSED__,
132 void *einfo __UNUSED__)
133{
134 fprintf(stdout, "Enlightenment logo has had the mouse out.\n");
135} /* mouse exits the object's area */
136
137/* examine the keys pressed */
138static void
139_on_keydown(void *data __UNUSED__,
140 Evas *evas,
141 Evas_Object *o __UNUSED__,
142 void *einfo)
143{
144 const Evas_Modifier *mods;
145 Evas_Event_Key_Down *ev = einfo;
146
147 fprintf(stdout, "We've got key input: %s\n", ev->keyname);
148 fprintf(stdout, "It actually came from %s\n", d.focus ?
149 "focus" : "key grab");
150
151 if (strcmp(ev->keyname, "h") == 0) /* print help */
152 {
153 fprintf(stdout, commands);
154 return;
155 }
156
157 if (strcmp(ev->keyname, "a") == 0) /* toggle animation timer */
158 {
159 if (d.resize_timer != NULL)
160 {
161 fprintf(stdout, "Stopping animation timer\n");
162 ecore_timer_del(d.resize_timer);
163 d.resize_timer = NULL;
164 }
165 else
166 {
167 fprintf(stdout, "Re-issuing animation timer\n");
168 d.resize_timer = ecore_timer_add(2, _resize_cb, NULL);
169 }
170 return;
171 }
172
173 if (strcmp(ev->keyname, "c") == 0) /* cycle between focus and key
174 * grabs for key input */
175 {
176 Eina_Bool ret;
177 Evas_Modifier_Mask mask =
178 evas_key_modifier_mask_get(d.canvas, "Control");
179
180 fprintf(stdout, "Switching to %s for key input\n", d.focus ?
181 "key grabs" : "focus");
182
183 if (d.focus)
184 {
185 evas_object_focus_set(d.bg, EINA_FALSE);
186 fprintf(stdout, "Focused object is now %s\n",
187 evas_focus_get(d.canvas) ?
188 "still valid! Something went wrong." : "none.");
189
190 ret = evas_object_key_grab(d.bg, "a", 0, 0, EINA_TRUE);
191 if (!ret)
192 {
193 fprintf(stdout, "Something went wrong with key grabs.\n");
194 goto c_end;
195 }
196 ret = evas_object_key_grab(d.bg, "c", 0, 0, EINA_TRUE);
197 if (!ret)
198 {
199 fprintf(stdout, "Something went wrong with key grabs.\n");
200 goto c_end;
201 }
202 ret = evas_object_key_grab(d.bg, "d", 0, 0, EINA_TRUE);
203 if (!ret)
204 {
205 fprintf(stdout, "Something went wrong with key grabs.\n");
206 goto c_end;
207 }
208 ret = evas_object_key_grab(d.bg, "f", 0, 0, EINA_TRUE);
209 if (!ret)
210 {
211 fprintf(stdout, "Something went wrong with key grabs.\n");
212 goto c_end;
213 }
214 ret = evas_object_key_grab(d.bg, "p", 0, 0, EINA_TRUE);
215 if (!ret)
216 {
217 fprintf(stdout, "Something went wrong with key grabs.\n");
218 goto c_end;
219 }
220 ret = evas_object_key_grab(d.bg, "o", mask, 0, EINA_TRUE);
221 if (!ret)
222 {
223 fprintf(stdout, "Something went wrong with key grabs.\n");
224 goto c_end;
225 }
226 ret = evas_object_key_grab(d.bg, "h", 0, 0, EINA_TRUE);
227 if (!ret)
228 {
229 fprintf(stdout, "Something went wrong with key grabs.\n");
230 goto c_end;
231 }
232 }
233 else /* got here by key grabs */
234 {
235 evas_object_key_ungrab(d.bg, "a", 0, 0);
236 evas_object_key_ungrab(d.bg, "c", 0, 0);
237 evas_object_key_ungrab(d.bg, "d", 0, 0);
238 evas_object_key_ungrab(d.bg, "f", 0, 0);
239 evas_object_key_ungrab(d.bg, "p", 0, 0);
240 evas_object_key_ungrab(d.bg, "o", mask, 0);
241 evas_object_key_ungrab(d.bg, "h", 0, 0);
242
243 evas_object_focus_set(d.bg, EINA_TRUE);
244 }
245
246c_end:
247 d.focus = !d.focus;
248
249 return;
250 }
251
252 if (strcmp(ev->keyname, "d") == 0) /* delete canvas' callbacks */
253 {
254 fprintf(stdout, "Deleting canvas event callbacks\n");
255 evas_event_callback_del_full(evas, EVAS_CALLBACK_RENDER_FLUSH_PRE,
256 _render_flush_cb, NULL);
257 evas_event_callback_del_full(
258 evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
259 _object_focus_in_cb, NULL);
260 return;
261 }
262
263 if (strcmp(ev->keyname, "f") == 0) /* freeze input for 3 seconds */
264 {
265 fprintf(stdout, "Freezing input for 3 seconds\n");
266 evas_event_freeze(evas);
267 d.freeze_timer = ecore_timer_add(3, _thaw_cb, NULL);
268 return;
269 }
270
271 if (strcmp(ev->keyname, "p") == 0) /* toggle precise point
272 * collision detection */
273 {
274 Eina_Bool precise = evas_object_precise_is_inside_get(d.img);
275
276 fprintf(stdout, "Toggling precise point collision detection %s on"
277 " Enlightenment logo\n", precise ? "off" : "on");
278 evas_object_precise_is_inside_set(d.img, !precise);
279
280 return;
281 }
282
283 mods = evas_key_modifier_get(evas);
284 if (evas_key_modifier_is_set(mods, "Control") &&
285 (strcmp(ev->keyname, "o") == 0)) /* add an obscured
286 * rectangle to the middle
287 * of the canvas */
288 {
289 fprintf(stdout, "Toggling obscured rectangle on canvas\n");
290 if (!d.obscured)
291 {
292 int w, h;
293 evas_output_viewport_get(evas, NULL, NULL, &w, &h);
294 evas_obscured_rectangle_add(evas, w / 4, h / 4, w / 2, h / 2);
295 }
296 else
297 {
298 int w, h;
299 Eina_Rectangle *rect;
300 Eina_List *updates, *l;
301
302 evas_output_viewport_get(evas, NULL, NULL, &w, &h);
303 evas_obscured_clear(evas);
304
305 /* we have to flag a damage region here because
306 * evas_obscured_clear() doesn't change the canvas'
307 * state. we'd have to wait for an animation step, for
308 * example, to get the result, without it */
309 evas_damage_rectangle_add(evas, 0, 0, w, h);
310
311 updates = evas_render_updates(evas);
312
313 EINA_LIST_FOREACH(updates, l, rect)
314 {
315 fprintf(stdout, "Rectangle (%d, %d, %d, %d) on canvas got a"
316 " rendering update.\n", rect->x, rect->y,
317 rect->w,
318 rect->h);
319 }
320 evas_render_updates_free(updates);
321 }
322 d.obscured = !d.obscured;
323 } /* end of obscured region command */
324}
325
326int
327main(void)
328{
329 int err;
330
331 if (!ecore_evas_init())
332 return EXIT_FAILURE;
333
334 /* this will give you a window with an Evas canvas under the first
335 * engine available */
336 d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
337 if (!d.ee)
338 goto error;
339
340 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
341 ecore_evas_show(d.ee);
342
343 /* the canvas pointer, de facto */
344 d.canvas = ecore_evas_get(d.ee);
345
346 evas_event_callback_add(d.canvas, EVAS_CALLBACK_RENDER_FLUSH_PRE,
347 _render_flush_cb, NULL);
348 if (evas_alloc_error() != EVAS_ALLOC_ERROR_NONE)
349 {
350 fprintf(stderr, "ERROR: Callback registering failed! Aborting.\n");
351 goto panic;
352 }
353
354 evas_event_callback_add(d.canvas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
355 _object_focus_in_cb, NULL);
356 if (evas_alloc_error() != EVAS_ALLOC_ERROR_NONE)
357 {
358 fprintf(stderr, "ERROR: Callback registering failed! Aborting.\n");
359 goto panic;
360 } /* two canvas event callbacks */
361
362 d.bg = evas_object_rectangle_add(d.canvas);
363 evas_object_name_set(d.bg, "our dear rectangle");
364 evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
365 evas_object_move(d.bg, 0, 0); /* at canvas' origin */
366 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
367 evas_object_show(d.bg);
368
369 evas_object_focus_set(d.bg, EINA_TRUE); /* so we get input events */
370 d.focus = EINA_TRUE;
371
372 evas_object_event_callback_add(
373 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
374 if (evas_alloc_error() != EVAS_ALLOC_ERROR_NONE)
375 {
376 fprintf(stderr, "ERROR: Callback registering failed! Aborting.\n");
377 goto panic;
378 }
379
380 d.img = evas_object_image_filled_add(d.canvas);
381 evas_object_image_file_set(d.img, img_path, NULL);
382 err = evas_object_image_load_error_get(d.img);
383 if (err != EVAS_LOAD_ERROR_NONE)
384 {
385 goto panic;
386 }
387 else
388 {
389 evas_object_move(d.img, 0, 0);
390 evas_object_resize(d.img, WIDTH, HEIGHT);
391 evas_object_show(d.img);
392 evas_object_event_callback_add(
393 d.img, EVAS_CALLBACK_MOUSE_IN, _on_mouse_in, NULL);
394 evas_object_event_callback_add(
395 d.img, EVAS_CALLBACK_MOUSE_OUT, _on_mouse_out, NULL);
396 }
397
398 d.resize_timer = ecore_timer_add(2, _resize_cb, NULL);
399
400 fprintf(stdout, commands);
401 ecore_main_loop_begin();
402
403 ecore_evas_free(d.ee);
404 ecore_evas_shutdown();
405 return 0;
406
407error:
408 fprintf(stderr, "you got to have at least one evas engine built and linked"
409 " up to ecore-evas for this example to run properly.\n");
410panic:
411 ecore_evas_shutdown();
412 return -1;
413}
diff --git a/src/examples/evas/evas-hints.c b/src/examples/evas/evas-hints.c
new file mode 100644
index 0000000..78c09ba
--- /dev/null
+++ b/src/examples/evas/evas-hints.c
@@ -0,0 +1,378 @@
1/**
2 * Simple Evas example illustrating <b>alignment, minimum size, maximum
3 * size, padding and weight</b> hints on objects.
4 *
5 * To exemplify those hints, whe use the Evas box object, one of the
6 * managers using size hints to layout its children.
7 *
8 * You'll need at least one engine built for it (excluding the buffer
9 * one) and the png image loader also built. See stdout/stderr for
10 * output.
11 *
12 * @verbatim
13 * gcc -o evas-events evas-events.c `pkg-config --libs --cflags ecore-evas`
14 * @endverbatim
15 */
16
17#ifdef HAVE_CONFIG_H
18#include "config.h"
19#else
20#define __UNUSED__
21#endif
22
23#include <Ecore.h>
24#include <Ecore_Evas.h>
25
26#include <stdlib.h>
27#include <stdio.h>
28#include <string.h>
29
30#define WIDTH 320
31#define HEIGHT 480
32#define PACKAGE_EXAMPLES_DIR "."
33
34static const char commands[] = \
35 "commands are:\n"
36 "\tShift + a - change alignment hints on top rectangle\n"
37 "\tShift + m - change min. size hint on top rectangle\n"
38 "\tShift + n - change max. size hint on top rectangle\n"
39 "\tShift + p - change padding hints on top rectangle\n"
40 "\tShift + w - change weight hints on top rectangle\n\n"
41 "\tControl + a - change alignment hints on bottom rectangle\n"
42 "\tControl + m - change min. size hint on bottom rectangle\n"
43 "\tControl + n - change max. size hint on bottom rectangle\n"
44 "\tControl + p - change padding hints on bottom rectangle\n"
45 "\tControl + w - change weight hints on bottom rectangle\n\n"
46 "\ts - print current hints information\n"
47 "\th - print help\n";
48
49static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
50
51struct coord_tuple
52{
53 Evas_Coord w, h;
54};
55
56struct weight_tuple
57{
58 double x, y;
59};
60
61struct padding_tuple
62{
63 Evas_Coord l, r, t, b;
64};
65
66struct rect_data
67{
68 struct coord_tuple *min_ptr;
69 struct coord_tuple min[4];
70
71 struct coord_tuple *max_ptr;
72 struct coord_tuple max[4];
73
74 struct weight_tuple *align_ptr;
75 struct weight_tuple align[3];
76
77 struct weight_tuple *weight_ptr;
78 struct weight_tuple weight[3];
79
80 struct padding_tuple *padding_ptr;
81 struct padding_tuple padding[3];
82};
83
84struct test_data
85{
86 Ecore_Evas *ee;
87 Evas *canvas;
88 struct rect_data t_data, b_data;
89 Evas_Object *bg, *box, *t_rect, *b_rect, *border;
90};
91
92static struct test_data d = {0};
93
94/* here just to keep our example's window size and background image's
95 * size in synchrony */
96static void
97_canvas_resize_cb(Ecore_Evas *ee)
98{
99 int w, h;
100
101 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
102 evas_object_resize(d.bg, w, h);
103
104 evas_object_move(d.box, (w / 4), (h / 4));
105 evas_object_resize(d.box, (w / 2), (h / 2));
106
107 evas_object_move(d.border, (w / 4) - 3, (h / 4) - 3);
108 evas_object_resize(d.border, (w / 2) + 6, (h / 2) + 6);
109}
110
111static void
112_print_rect_stats(Evas_Object *rect)
113{
114 Evas_Coord w, h, l, r, t, b;
115 double x, y;
116
117 evas_object_size_hint_align_get(rect, &x, &y);
118 fprintf(stdout, "\talign hints: h(%f), v(%f)\n", x, y);
119
120 evas_object_size_hint_min_get(rect, &w, &h);
121 fprintf(stdout, "\tmin. size hints: h(%d), v(%d)\n", w, h);
122
123 evas_object_size_hint_max_get(rect, &w, &h);
124 fprintf(stdout, "\tmax. size hints: h(%d), v(%d)\n", w, h);
125
126 evas_object_size_hint_padding_get(rect, &l, &r, &t, &b);
127 fprintf(stdout, "\tpadding hints: l(%d), r(%d), t(%d), b(%d)\n",
128 l, r, t, b);
129
130 evas_object_size_hint_weight_get(rect, &x, &y);
131 fprintf(stdout, "\tweight hints: h(%f), v(%f)\n", x, y);
132}
133
134/* use the following commands to interact with this example - 'h' is
135 * the key for help */
136static void
137_on_keydown(void *data __UNUSED__,
138 Evas *evas __UNUSED__,
139 Evas_Object *o __UNUSED__,
140 void *einfo)
141{
142 Evas_Event_Key_Down *ev = einfo;
143 struct rect_data *r_data = NULL;
144 const Evas_Modifier *mods;
145 Evas_Object *rect = NULL;
146 const char *name = NULL;
147
148 mods = evas_key_modifier_get(evas);
149 if (evas_key_modifier_is_set(mods, "Shift"))
150 {
151 rect = d.t_rect;
152 r_data = &d.t_data;
153 name = "top";
154 }
155 else if (evas_key_modifier_is_set(mods, "Control"))
156 {
157 rect = d.b_rect;
158 r_data = &d.b_data;
159 name = "bottom";
160 }
161 else if (strcmp(ev->keyname, "h") == 0) /* print help */
162 {
163 fprintf(stdout, commands);
164 return;
165 }
166 else if (strcmp(ev->keyname, "s") == 0) /* get aspect status of the
167 * rectangles WRT size
168 * hints */
169 {
170 fprintf(stdout, "Top rectangle:\n");
171 _print_rect_stats(d.t_rect);
172
173 fprintf(stdout, "\nBottom rectangle:\n");
174 _print_rect_stats(d.b_rect);
175
176 return;
177 }
178
179 if (!rect) return;
180
181 if (strcmp(ev->keyname, "a") == 0) /* alignment hints */
182 {
183 (r_data->align_ptr)++;
184
185 if ((unsigned)
186 (((void *)(r_data->align_ptr)) - ((void *)(r_data->align))) >=
187 sizeof(r_data->align))
188 r_data->align_ptr = r_data->align;
189
190 evas_object_size_hint_align_set(
191 rect, r_data->align_ptr->x, r_data->align_ptr->y);
192
193 fprintf(stdout, "Changing align hints for %s rect. to (%f, %f)\n",
194 name, r_data->align_ptr->x, r_data->align_ptr->y);
195 return;
196 }
197
198 if (strcmp(ev->keyname, "m") == 0) /* min. size hints */
199 {
200 (r_data->min_ptr)++;
201
202 if ((unsigned)
203 (((void *)(r_data->min_ptr)) - ((void *)(r_data->min))) >=
204 sizeof(r_data->min))
205 r_data->min_ptr = r_data->min;
206
207 evas_object_size_hint_min_set(
208 rect, r_data->min_ptr->w, r_data->min_ptr->h);
209
210 fprintf(stdout, "Changing min. size hints for %s rect. to (%d, %d)\n",
211 name, r_data->min_ptr->w, r_data->min_ptr->h);
212 return;
213 }
214
215 if (strcmp(ev->keyname, "n") == 0) /* max. size hints */
216 {
217 (r_data->max_ptr)++;
218
219 if ((unsigned)
220 (((void *)(r_data->max_ptr)) - ((void *)(r_data->max))) >=
221 sizeof(r_data->max))
222 r_data->max_ptr = r_data->max;
223
224 evas_object_size_hint_max_set(
225 rect, r_data->max_ptr->w, r_data->max_ptr->h);
226
227 fprintf(stdout, "Changing max. size hints for %s rect. to (%d, %d)\n",
228 name, r_data->max_ptr->w, r_data->max_ptr->h);
229 return;
230 }
231
232 if (strcmp(ev->keyname, "p") == 0) /* padding size hints */
233 {
234 (r_data->padding_ptr)++;
235
236 if ((unsigned)
237 (((void *)(r_data->padding_ptr)) - ((void *)(r_data->padding))) >=
238 sizeof(r_data->padding))
239 r_data->padding_ptr = r_data->padding;
240
241 evas_object_size_hint_padding_set(
242 rect, r_data->padding_ptr->l, r_data->padding_ptr->r,
243 r_data->padding_ptr->t, r_data->padding_ptr->b);
244
245 fprintf(stdout, "Changing padding size hints for %s rect."
246 " to (%d, %d, %d, %d)\n",
247 name, r_data->padding_ptr->l, r_data->padding_ptr->r,
248 r_data->padding_ptr->t, r_data->padding_ptr->b);
249 return;
250 }
251
252 /* experiment with weights here. keep in mind that, for the box
253 * object, only if all the children have non zero weights this hint
254 * will have an effect */
255 if (strcmp(ev->keyname, "w") == 0) /* weight hints */
256 {
257 (r_data->weight_ptr)++;
258
259 if ((unsigned)
260 (((void *)(r_data->weight_ptr)) - ((void *)(r_data->weight))) >=
261 sizeof(r_data->weight))
262 r_data->weight_ptr = r_data->weight;
263
264 evas_object_size_hint_weight_set(
265 rect, r_data->weight_ptr->x, r_data->weight_ptr->y);
266
267 fprintf(stdout, "Changing weight hints for %s rect. to (%f, %f)\n",
268 name, r_data->weight_ptr->x, r_data->weight_ptr->y);
269 return;
270 }
271}
272
273static void
274_on_destroy(Ecore_Evas *ee __UNUSED__)
275{
276 ecore_main_loop_quit();
277}
278
279int
280main(void)
281{
282 if (!ecore_evas_init())
283 return EXIT_FAILURE;
284
285 /* init values one is going to cycle through while running this
286 * example */
287 struct rect_data init_data = \
288 {
289 .min = {{0, 0}, {30, 30}, {100, 70}, {200, 200}},
290 .max = {{0, 0}, {100, 100}, {100, 70}, {300, 300}},
291 .align = {{0.0, 0.0}, {0.5, 0.5}, {1.0, 0.5}},
292 .weight = {{0.0, 0.0}, {3, 6}, {10, 100}},
293 .padding = {{0, 0, 0, 0}, {3, 6, 9, 12}, {10, 20, 0, 30}}
294 };
295
296 d.t_data = init_data;
297
298 d.t_data.min_ptr = d.t_data.min + 1;
299 d.t_data.max_ptr = d.t_data.max + 1;
300 d.t_data.align_ptr = d.t_data.align;
301 d.t_data.weight_ptr = d.t_data.weight;
302 d.t_data.padding_ptr = d.t_data.padding;
303
304 d.b_data = init_data;
305
306 d.b_data.min_ptr = d.b_data.min + 1;
307 d.b_data.max_ptr = d.b_data.max + 1;
308 d.b_data.align_ptr = d.b_data.align;
309 d.b_data.weight_ptr = d.b_data.weight;
310 d.b_data.padding_ptr = d.b_data.padding;
311
312 /* this will give you a window with an Evas canvas under the first
313 * engine available */
314 d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
315 if (!d.ee)
316 goto error;
317
318 ecore_evas_callback_destroy_set(d.ee, _on_destroy);
319 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
320 ecore_evas_show(d.ee);
321
322 /* the canvas pointer, de facto */
323 d.canvas = ecore_evas_get(d.ee);
324
325 d.bg = evas_object_rectangle_add(d.canvas);
326 evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
327 evas_object_move(d.bg, 0, 0); /* at canvas' origin */
328 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
329 evas_object_show(d.bg);
330
331 evas_object_focus_set(d.bg, EINA_TRUE);
332 evas_object_event_callback_add(
333 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
334
335 /* Evas box with vertical layout */
336 d.box = evas_object_box_add(d.canvas);
337 evas_object_box_layout_set(
338 d.box, evas_object_box_layout_vertical, NULL, NULL);
339 evas_object_show(d.box);
340
341 /* this is a border around the box, container of the rectangles we
342 * are going to experiment with (changing some size hints). this
343 * way you can see how the container relates to the children */
344 d.border = evas_object_image_filled_add(d.canvas);
345 evas_object_image_file_set(d.border, border_img_path, NULL);
346 evas_object_image_border_set(d.border, 3, 3, 3, 3);
347 evas_object_image_border_center_fill_set(d.border, EVAS_BORDER_FILL_NONE);
348 evas_object_show(d.border);
349
350 d.t_rect = evas_object_rectangle_add(d.canvas);
351 evas_object_color_set(d.t_rect, 0, 0, 255, 255);
352
353 evas_object_size_hint_min_set(
354 d.t_rect, d.t_data.min_ptr->w, d.t_data.min_ptr->h);
355 evas_object_show(d.t_rect);
356 evas_object_box_append(d.box, d.t_rect);
357
358 d.b_rect = evas_object_rectangle_add(d.canvas);
359 evas_object_color_set(d.b_rect, 0, 255, 0, 255);
360
361 evas_object_size_hint_min_set(
362 d.b_rect, d.b_data.min_ptr->w, d.b_data.min_ptr->h);
363 evas_object_show(d.b_rect);
364 evas_object_box_append(d.box, d.b_rect);
365
366 _canvas_resize_cb(d.ee);
367
368 fprintf(stdout, commands);
369 ecore_main_loop_begin();
370 ecore_evas_shutdown();
371 return 0;
372
373error:
374 fprintf(stderr, "You got to have at least one evas engine built and linked"
375 " up to ecore-evas for this example to run properly.\n");
376 return -1;
377}
378
diff --git a/src/examples/evas/evas-images.c b/src/examples/evas/evas-images.c
new file mode 100644
index 0000000..a8cf3c4
--- /dev/null
+++ b/src/examples/evas/evas-images.c
@@ -0,0 +1,353 @@
1/**
2 * Simple Evas example illustrating some image objects functions
3 *
4 * You'll need at least one engine built for it (excluding the buffer
5 * one) and the png image loader also built. See stdout/stderr for
6 * output.
7 *
8 * @verbatim
9 * gcc -o evas-images evas-images.c `pkg-config --libs --cflags evas ecore ecore-evas`
10 * @endverbatim
11 */
12
13#ifdef HAVE_CONFIG_H
14
15#include "config.h"
16#else
17
18#define PACKAGE_EXAMPLES_DIR "."
19#define __UNUSED__
20
21#endif
22
23#include <Ecore.h>
24#include <Ecore_Evas.h>
25#include <stdio.h>
26#include <errno.h>
27
28#define WIDTH (320)
29#define HEIGHT (240)
30
31static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
32static const char *valid_path = PACKAGE_EXAMPLES_DIR "/enlightenment.png";
33static const char *bogus_path = "/tmp/non-existent-220986.png";
34static const char *commands = \
35 "commands are:\n"
36 "\tx - change image's x fill coordinate\n"
37 "\ty - change image's y fill coordinate\n"
38 "\tw - change image's w fill size\n"
39 "\te - change image's h fill size\n"
40 "\tf - toggle image filled property (overrides fill)\n"
41 "\ta - toggle image's alpha channel usage\n"
42 "\tm - toggle border's smooth scaling\n"
43 "\tt - change border's thickness\n"
44 "\tb - change border's center region aspect\n"
45 "\tc - change border's scaling factor\n"
46 "\ts - print image's fill property status\n"
47 "\th - print help\n";
48
49struct test_data
50{
51 Ecore_Evas *ee;
52 Evas *evas;
53 Evas_Object *img1, *img2, *bg, *border;
54};
55
56static struct test_data d = {0};
57
58static void
59_on_destroy(Ecore_Evas *ee __UNUSED__)
60{
61 ecore_main_loop_quit();
62}
63
64/* here just to keep our example's window size and background image's
65 * size in synchrony */
66static void
67_canvas_resize_cb(Ecore_Evas *ee)
68{
69 int w, h;
70
71 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
72 evas_object_resize(d.bg, w, h);
73}
74
75static const char *
76_border_fill_mode_to_str(Evas_Border_Fill_Mode mode)
77{
78 switch (mode)
79 {
80 case EVAS_BORDER_FILL_NONE:
81 return "none";
82
83 case EVAS_BORDER_FILL_DEFAULT:
84 return "default";
85
86 case EVAS_BORDER_FILL_SOLID:
87 return "solid";
88
89 default:
90 return "invalid";
91 }
92}
93
94static void
95_on_keydown(void *data __UNUSED__,
96 Evas *evas __UNUSED__,
97 Evas_Object *o __UNUSED__,
98 void *einfo)
99{
100 Evas_Event_Key_Down *ev = einfo;
101
102 if (strcmp(ev->keyname, "h") == 0) /* print help */
103 {
104 fprintf(stdout, commands);
105 return;
106 }
107
108 if (strcmp(ev->keyname, "m") == 0) /* toggle border image's smooth scaling */
109 {
110 Eina_Bool smooth_scale = evas_object_image_smooth_scale_get(d.border);
111
112 evas_object_image_smooth_scale_set(d.border, !smooth_scale);
113
114 fprintf(stdout, "Image's border is now %s smooth scaling\n",
115 smooth_scale ? "without" : "with");
116
117 return;
118 }
119
120 if (strcmp(ev->keyname, "t") == 0) /* change border's thickness */
121 {
122 int l, r, t, b;
123
124 evas_object_image_border_get(d.border, &l, &r, &t, &b);
125
126 l = (l + 3) % 9;
127 r = (r + 3) % 9;
128 t = (t + 3) % 9;
129 b = (b + 3) % 9;
130
131 evas_object_image_border_set(d.border, l, r, t, b);
132
133 fprintf(stdout, "Image's border thickness is now %d\n", l);
134
135 return;
136 }
137
138 if (strcmp(ev->keyname, "c") == 0) /* change border's scaling factor */
139 {
140 double scale = evas_object_image_border_scale_get(d.border);
141
142 scale *= 2;
143 if (scale > 4.0) scale = 1.0;
144
145 evas_object_image_border_scale_set(d.border, scale);
146
147 fprintf(stdout, "Image's border scaling factor is now %f\n", scale);
148
149 return;
150 }
151
152 if (strcmp(ev->keyname, "b") == 0) /* change border's center
153 * region's aspect */
154 {
155 Eina_Bool fill = \
156 evas_object_image_border_center_fill_get(d.border);
157
158 fill = (fill + 1) % 3;
159
160 evas_object_image_border_center_fill_set(d.border, fill);
161
162 fprintf(stdout, "Image's border center region aspect is now \"%s\"\n",
163 _border_fill_mode_to_str(fill));
164
165 return;
166 }
167
168 if (strcmp(ev->keyname, "a") == 0) /* toggle alpha channel usage */
169 {
170 Eina_Bool alpha = evas_object_image_alpha_get(d.img1);
171
172 evas_object_image_alpha_set(d.img1, !alpha);
173
174 fprintf(stdout, "Image's alpha channel is now %s\n",
175 alpha ? "off" : "on");
176
177 return;
178 }
179
180 if (strcmp(ev->keyname, "f") == 0) /* toggle filled property */
181 {
182 Eina_Bool filled = evas_object_image_filled_get(d.img1);
183
184 evas_object_image_filled_set(d.img1, !filled);
185
186 fprintf(stdout, "Image's x filled property is now %s\n",
187 filled ? "off" : "on");
188
189 return;
190 }
191
192 if (strcmp(ev->keyname, "x") == 0) /* change x fill coordinate */
193 {
194 Evas_Coord x, y, w, h;
195
196 evas_object_image_fill_get(d.img1, &x, &y, &w, &h);
197 x = (x + 20) % (WIDTH / 2);
198 evas_object_image_fill_set(d.img1, x, y, w, h);
199
200 fprintf(stdout, "Image's x fill coordinate changed to %d\n", x);
201
202 return;
203 }
204
205 if (strcmp(ev->keyname, "y") == 0) /* change y fill coordinate */
206 {
207 Evas_Coord x, y, w, h;
208
209 evas_object_image_fill_get(d.img1, &x, &y, &w, &h);
210 y = (y + 20) % (HEIGHT / 2);
211 evas_object_image_fill_set(d.img1, x, y, w, h);
212
213 fprintf(stdout, "Image's y fill coordinate changed to %d\n", y);
214
215 return;
216 }
217
218 if (strcmp(ev->keyname, "w") == 0) /* change w fill size */
219 {
220 Evas_Coord x, y, w, h;
221
222 evas_object_image_fill_get(d.img1, &x, &y, &w, &h);
223 if (w == (WIDTH / 4)) w = (WIDTH / 2);
224 else if (w == WIDTH / 2) w = WIDTH;
225 else w = (WIDTH / 4);
226 evas_object_image_fill_set(d.img1, x, y, w, h);
227
228 fprintf(stdout, "Image's w fill size changed to %d\n", w);
229
230 return;
231 }
232
233 if (strcmp(ev->keyname, "e") == 0) /* change h fill size */
234 {
235 Evas_Coord x, y, w, h;
236
237 evas_object_image_fill_get(d.img1, &x, &y, &w, &h);
238 if (h == (HEIGHT / 4)) h = (HEIGHT / 2);
239 else if (h == HEIGHT / 2) h = HEIGHT;
240 else h = (HEIGHT / 4);
241 evas_object_image_fill_set(d.img1, x, y, w, h);
242
243 fprintf(stdout, "Image's h fill size changed to %d\n", h);
244
245 return;
246 }
247
248 if (strcmp(ev->keyname, "s") == 0) /* status */
249 {
250 Evas_Coord x, y, w, h;
251
252 evas_object_image_fill_get(d.img1, &x, &y, &w, &h);
253
254 fprintf(stdout, "Image has fill properties set to: %d, %d, %d, %d\n",
255 x, y, w, h);
256
257 return;
258 }
259}
260
261int
262main(void)
263{
264 int err;
265
266 if (!ecore_evas_init())
267 return EXIT_FAILURE;
268
269 /* this will give you a window with an Evas canvas under the first
270 * engine available */
271 d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
272 if (!d.ee)
273 goto error;
274
275 ecore_evas_callback_destroy_set(d.ee, _on_destroy);
276 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
277 ecore_evas_show(d.ee);
278
279 /* the canvas pointer, de facto */
280 d.evas = ecore_evas_get(d.ee);
281
282 d.bg = evas_object_rectangle_add(d.evas);
283 evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
284 evas_object_move(d.bg, 0, 0); /* at canvas' origin */
285 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
286 evas_object_show(d.bg);
287
288 d.img1 = evas_object_image_add(d.evas);
289 evas_object_image_file_set(d.img1, valid_path, NULL);
290 err = evas_object_image_load_error_get(d.img1);
291 if (err != EVAS_LOAD_ERROR_NONE)
292 {
293 fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
294 valid_path, evas_load_error_str(err));
295 }
296 else
297 {
298 fprintf(stdout,
299 "loaded image '%s' with succes! error string is \"%s\"\n",
300 valid_path, evas_load_error_str(err));
301
302 evas_object_move(d.img1, 3, 3);
303 evas_object_image_fill_set(d.img1, 0, 0, WIDTH / 2, HEIGHT / 2);
304 evas_object_resize(d.img1, WIDTH / 2, HEIGHT / 2);
305 evas_object_show(d.img1);
306
307 evas_object_focus_set(d.bg, EINA_TRUE);
308 evas_object_event_callback_add(
309 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
310 }
311
312 /* this is a border around the image above, here just to emphasize
313 * its geometry */
314 d.border = evas_object_image_filled_add(d.evas);
315 evas_object_image_file_set(d.border, border_img_path, NULL);
316 evas_object_image_border_set(d.border, 3, 3, 3, 3);
317 evas_object_image_border_center_fill_set(d.border, EVAS_BORDER_FILL_NONE);
318
319 evas_object_move(d.border, 0, 0);
320 evas_object_resize(d.border, (WIDTH / 2) + 6, (HEIGHT / 2) + 6);
321 evas_object_show(d.border);
322
323 /* image loading will fail for this one -- unless one cheats and
324 * puts a valid image on that path */
325 d.img2 = evas_object_image_add(d.evas);
326 evas_object_image_file_set(d.img2, bogus_path, NULL);
327 err = evas_object_image_load_error_get(d.img2);
328 if (err != EVAS_LOAD_ERROR_NONE)
329 {
330 fprintf(stderr, "could not load image '%s': error string is \"%s\"\n",
331 bogus_path, evas_load_error_str(err));
332 }
333 else
334 {
335 evas_object_move(d.img2, WIDTH / 2, HEIGHT / 2);
336 evas_object_image_fill_set(d.img2, 0, 0, WIDTH / 2, HEIGHT / 2);
337 evas_object_resize(d.img2, WIDTH / 2, HEIGHT / 2);
338 evas_object_show(d.img2);
339 }
340
341 fprintf(stdout, commands);
342 ecore_main_loop_begin();
343
344 ecore_evas_free(d.ee);
345 ecore_evas_shutdown();
346 return 0;
347
348error:
349 fprintf(stderr, "you got to have at least one evas engine built and linked"
350 " up to ecore-evas for this example to run properly.\n");
351 ecore_evas_shutdown();
352 return -1;
353}
diff --git a/src/examples/evas/evas-images2.c b/src/examples/evas/evas-images2.c
new file mode 100644
index 0000000..64f4c9f
--- /dev/null
+++ b/src/examples/evas/evas-images2.c
@@ -0,0 +1,311 @@
1/**
2 * Simple Evas example illustrating some image objects functions
3 *
4 * You'll need at least one engine built for it (excluding the buffer
5 * one) and the png image loader/saver also built. See stdout/stderr
6 * for output.
7 *
8 * @verbatim
9 * gcc -o evas-images2 evas-images2.c `pkg-config --libs --cflags evas ecore ecore-evas`
10 * @endverbatim
11 */
12
13#ifdef HAVE_CONFIG_H
14
15#include "config.h"
16#else
17
18#define PACKAGE_EXAMPLES_DIR "."
19#define __UNUSED__
20
21#endif
22
23#include <Ecore.h>
24#include <Ecore_Evas.h>
25#include <stdio.h>
26#include <errno.h>
27
28#define WIDTH (320)
29#define HEIGHT (240)
30
31static const char *img_path = PACKAGE_EXAMPLES_DIR "/enlightenment.png";
32static const char *commands = \
33 "commands are:\n"
34 "\tp - change proxy image's source\n"
35 "\ts - print noise image's stride value\n"
36 "\ta - save noise image to disk (/tmp dir)\n"
37 "\tv - change source visibility\n"
38 "\te - enable/disable source events\n"
39 "\th - print help\n";
40
41const char *file_path = "/tmp/evas-images2-example.png";
42const char *quality_str = "quality=100";
43
44struct test_data
45{
46 Ecore_Evas *ee;
47 Evas *evas;
48 Evas_Object *logo, *noise_img, *proxy_img, *bg;
49};
50
51static struct test_data d = {0};
52
53static void
54_mouse_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
55 void *event_info)
56{
57 Evas_Event_Mouse_Down *ev = event_info;
58 printf("Mouse Down - obj(%p), coords(%d %d)\n", obj, ev->canvas.x,
59 ev->canvas.y);
60}
61
62static void
63_mouse_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
64 void *event_info)
65{
66 Evas_Event_Mouse_Move *ev = event_info;
67 printf("Mouse Move - obj(%p), coords(%d %d)\n", obj, ev->cur.canvas.x,
68 ev->cur.canvas.y);
69}
70
71static void
72_mouse_up(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
73 void *event_info)
74{
75 Evas_Event_Mouse_Up *ev = event_info;
76 printf("Mouse Up - obj(%p), coords(%d %d)\n", obj, ev->canvas.x,
77 ev->canvas.y);
78}
79
80static void
81_multi_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
82 void *event_info)
83{
84 Evas_Event_Multi_Down *ev = event_info;
85 printf("Multi Down - obj(%p), coords(%d %d)\n", obj, ev->canvas.x,
86 ev->canvas.y);
87}
88
89static void
90_multi_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
91 void *event_info)
92{
93 Evas_Event_Multi_Move *ev = event_info;
94 printf("Multi Move - obj(%p), coords(%d %d)\n", obj, ev->cur.canvas.x,
95 ev->cur.canvas.y);
96}
97
98static void
99_multi_up(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
100 void *event_info)
101{
102 Evas_Event_Multi_Up *ev = event_info;
103 printf("Multi Up - obj(%p), coords(%d %d)\n", obj, ev->canvas.x,
104 ev->canvas.y);
105}
106
107static void
108_mouse_in(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
109 void *event_info)
110{
111 Evas_Event_Mouse_In *ev = event_info;
112 printf("Mouse In - obj(%p), coords(%d %d)\n", obj, ev->canvas.x,
113 ev->canvas.y);
114}
115
116static void
117_mouse_out(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
118 void *event_info)
119{
120 Evas_Event_Mouse_Out *ev = event_info;
121 printf("Mouse Out - obj(%p), coords(%d %d)\n", obj, ev->canvas.x,
122 ev->canvas.y);
123}
124
125static void
126_hold(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
127 void *event_info)
128{
129 Evas_Event_Hold *ev = event_info;
130 printf("Hold - obj(%p), hold(%d)\n", obj, ev->hold);
131}
132
133static void
134_on_preloaded(void *data __UNUSED__,
135 Evas *e __UNUSED__,
136 Evas_Object *obj __UNUSED__,
137 void *event_info __UNUSED__)
138{
139 fprintf(stdout, "Image has been pre-loaded!\n");
140}
141
142static void
143_on_destroy(Ecore_Evas *ee __UNUSED__)
144{
145 ecore_main_loop_quit();
146}
147
148/* here just to keep our example's window size and background image's
149 * size in synchrony */
150static void
151_canvas_resize_cb(Ecore_Evas *ee)
152{
153 int w, h;
154
155 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
156 evas_object_resize(d.bg, w, h);
157}
158
159static void
160_on_keydown(void *data __UNUSED__,
161 Evas *evas __UNUSED__,
162 Evas_Object *o __UNUSED__,
163 void *einfo)
164{
165 Evas_Event_Key_Down *ev = einfo;
166
167 if (strcmp(ev->keyname, "h") == 0) /* print help */
168 {
169 fprintf(stdout, commands);
170 return;
171 }
172
173 if (strcmp(ev->keyname, "s") == 0) /* print proxy image' stride value */
174 {
175 int stride = evas_object_image_stride_get(d.noise_img);
176
177 fprintf(stdout, "Image has row stride value of %d, which accounts"
178 " for %d pixels\n", stride, stride / 4);
179
180 return;
181 }
182
183 if (strcmp(ev->keyname, "p") == 0) /* change proxy's source */
184 {
185 Evas_Object *source = evas_object_image_source_get(d.proxy_img);
186
187 if (source == d.logo) source = d.noise_img;
188 else source = d.logo;
189
190 evas_object_image_source_set(d.proxy_img, source);
191
192 fprintf(stdout, "Proxy image's source changed\n");
193
194 return;
195 }
196
197 if (strcmp(ev->keyname, "a") == 0) /* save noise image to disk */
198 {
199 if (!evas_object_image_save(d.noise_img, file_path, NULL, quality_str))
200 fprintf(stderr, "Cannot save image to '%s' (flags '%s')\n",
201 file_path, quality_str);
202 else
203 fprintf(stdout, "Image saved to '%s' (flags '%s'), check it out with "
204 "an image viewer\n", file_path, quality_str);
205
206 return;
207 }
208
209 if (strcmp(ev->keyname, "v") == 0) /* change source visibility */
210 {
211 Eina_Bool src_visible =
212 evas_object_image_source_visible_get(d.proxy_img);
213 evas_object_image_source_visible_set(d.proxy_img, !src_visible);
214 return;
215 }
216
217 if (strcmp(ev->keyname, "e") == 0) /* change source events */
218 {
219 Eina_Bool src_events = evas_object_image_source_events_get(d.proxy_img);
220 evas_object_image_source_events_set(d.proxy_img, !src_events);
221 return;
222 }
223}
224
225int
226main(void)
227{
228 unsigned int i;
229 unsigned int pixels[(WIDTH / 4) * (HEIGHT / 4)];
230
231 srand(time(NULL));
232
233 if (!ecore_evas_init())
234 return EXIT_FAILURE;
235
236 /* this will give you a window with an Evas canvas under the first
237 * engine available */
238 d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
239 if (!d.ee)
240 goto error;
241
242 ecore_evas_callback_destroy_set(d.ee, _on_destroy);
243 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
244 ecore_evas_show(d.ee);
245
246 /* the canvas pointer, de facto */
247 d.evas = ecore_evas_get(d.ee);
248
249 d.bg = evas_object_rectangle_add(d.evas);
250 evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
251 evas_object_move(d.bg, 0, 0); /* at canvas' origin */
252 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
253 evas_object_show(d.bg);
254
255 evas_object_focus_set(d.bg, EINA_TRUE);
256 evas_object_event_callback_add(
257 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
258
259 d.logo = evas_object_image_filled_add(d.evas);
260
261 evas_object_event_callback_add(
262 d.logo, EVAS_CALLBACK_IMAGE_PRELOADED, _on_preloaded, NULL);
263 evas_object_image_preload(d.logo, EINA_TRUE);
264
265 evas_object_image_file_set(d.logo, img_path, NULL);
266 evas_object_resize(d.logo, WIDTH / 2, HEIGHT / 2);
267 evas_object_event_callback_add(d.logo, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, 0);
268 evas_object_event_callback_add(d.logo, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, 0);
269 evas_object_event_callback_add(d.logo, EVAS_CALLBACK_MOUSE_UP, _mouse_up, 0);
270 evas_object_event_callback_add(d.logo, EVAS_CALLBACK_MOUSE_IN, _mouse_in, 0);
271 evas_object_event_callback_add(d.logo, EVAS_CALLBACK_MOUSE_OUT, _mouse_out, 0);
272 evas_object_event_callback_add(d.logo, EVAS_CALLBACK_MULTI_DOWN, _multi_down, 0);
273 evas_object_event_callback_add(d.logo, EVAS_CALLBACK_MULTI_UP, _multi_up, 0);
274 evas_object_event_callback_add(d.logo, EVAS_CALLBACK_MULTI_MOVE, _multi_move, 0);
275 evas_object_event_callback_add(d.logo, EVAS_CALLBACK_HOLD, _hold, 0);
276
277 evas_object_show(d.logo);
278
279 /* creating noise image */
280 for (i = 0; i < sizeof(pixels) / sizeof(pixels[0]); i++)
281 pixels[i] = rand();
282
283 d.noise_img = evas_object_image_add(d.evas);
284 evas_object_image_size_set(d.noise_img, WIDTH / 4, HEIGHT / 4);
285 evas_object_image_data_set(d.noise_img, pixels);
286 evas_object_image_filled_set(d.noise_img, EINA_TRUE);
287 evas_object_move(d.noise_img, (WIDTH * 3) / 4, 0);
288 evas_object_resize(d.noise_img, WIDTH / 4, HEIGHT / 4);
289 evas_object_show(d.noise_img);
290 fprintf(stdout, "Creating noise image with size %d, %d\n",
291 WIDTH / 4, HEIGHT / 4);
292
293 d.proxy_img = evas_object_image_filled_add(d.evas);
294 evas_object_image_source_set(d.proxy_img, d.logo);
295 evas_object_move(d.proxy_img, WIDTH / 4, HEIGHT / 2);
296 evas_object_resize(d.proxy_img, WIDTH / 2, HEIGHT / 2);
297 evas_object_show(d.proxy_img);
298
299 fprintf(stdout, commands);
300 ecore_main_loop_begin();
301
302 ecore_evas_free(d.ee);
303 ecore_evas_shutdown();
304 return 0;
305
306error:
307 fprintf(stderr, "you got to have at least one evas engine built and linked"
308 " up to ecore-evas for this example to run properly.\n");
309 ecore_evas_shutdown();
310 return -1;
311}
diff --git a/src/examples/evas/evas-images3.c b/src/examples/evas/evas-images3.c
new file mode 100644
index 0000000..5d627b0
--- /dev/null
+++ b/src/examples/evas/evas-images3.c
@@ -0,0 +1,196 @@
1/**
2 * Simple Evas example illustrating some image objects functions
3 *
4 * You'll need at least one engine built for it (excluding the buffer
5 * one) and the png image loader/saver also built. See stdout/stderr
6 * for output.
7 *
8 * @verbatim
9 * gcc -o evas-images2 evas-images2.c `pkg-config --libs --cflags evas ecore ecore-evas`
10 * @endverbatim
11 */
12
13#ifdef HAVE_CONFIG_H
14
15#include "config.h"
16#else
17
18#define PACKAGE_EXAMPLES_DIR "."
19#define __UNUSED__
20
21#endif
22
23#include <Ecore.h>
24#include <Ecore_Evas.h>
25#include <stdio.h>
26#include <errno.h>
27
28#define WIDTH (320)
29#define HEIGHT (240)
30
31static const char *img_path = PACKAGE_EXAMPLES_DIR "/enlightenment.png";
32static const char *commands = \
33 "commands are:\n"
34 "\tw - write new pixel data to image\n"
35 "\ti - print image info\n"
36 "\ta - save noise image to disk (/tmp dir)\n"
37 "\th - print help\n";
38
39const char *file_path = "/tmp/evas-images2-example.png";
40const char *quality_str = "quality=100";
41
42struct test_data
43{
44 Ecore_Evas *ee;
45 Evas *evas;
46 Evas_Object *bg;
47 Evas_Object *logo, *logo1;
48};
49
50static struct test_data d = {0};
51
52static void
53_on_destroy(Ecore_Evas *ee __UNUSED__)
54{
55 ecore_main_loop_quit();
56}
57
58/* here just to keep our example's window size and background image's
59 * size in synchrony */
60static void
61_canvas_resize_cb(Ecore_Evas *ee)
62{
63 int w, h;
64
65 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
66 evas_object_resize(d.bg, w, h);
67 evas_object_resize(d.logo, w / 2, h);
68 evas_object_move(d.logo1, w / 2, 0);
69 evas_object_resize(d.logo1, w / 2, h);
70}
71
72static void
73_on_keydown(void *data __UNUSED__,
74 Evas *evas __UNUSED__,
75 Evas_Object *o __UNUSED__,
76 void *einfo)
77{
78 Evas_Event_Key_Down *ev = einfo;
79
80 if (strcmp(ev->keyname, "h") == 0) /* print help */
81 {
82 fprintf(stdout, commands);
83 return;
84 }
85
86 if (strcmp(ev->keyname, "i") == 0) /* change proxy's source */
87 {
88 int stride = evas_object_image_stride_get(d.logo);
89 int w, h;
90
91 evas_object_image_size_get(d.logo, &w, &h);
92
93 printf("image size: %dx%d; stride: %d\n", w, h, stride);
94
95 return;
96 }
97
98 if (strcmp(ev->keyname, "w") == 0) /* save noise image to disk */
99 {
100 int i;
101 char *pixels = evas_object_image_data_get(d.logo, EINA_FALSE);
102 char *bufpixels;
103 int w, h;
104 int stride;
105 Eina_Bool equal = EINA_TRUE;
106
107 evas_object_image_size_get(d.logo, &w, &h);
108 stride = evas_object_image_stride_get(d.logo);
109
110 bufpixels = malloc(sizeof(char) * stride * h);
111 memcpy(bufpixels, pixels, sizeof(char) * stride * h);
112
113 pixels = evas_object_image_data_get(d.logo, EINA_TRUE);
114
115 for (i = 0; i < (stride * h); i++)
116 {
117 if (bufpixels[i] != pixels[i])
118 {
119 equal = EINA_FALSE;
120 break;
121 }
122 }
123
124 free(bufpixels);
125
126 if (!equal)
127 printf("write pixels different from readonly pixels.\n");
128
129 for (i = ((stride * h) / 4) ; i < ((stride * h) / 2) ; i++)
130 {
131 pixels[i] = 0;
132 }
133
134 // evas_object_image_data_set(d.logo, pixels);
135 evas_object_image_data_update_add(d.logo, 0, 0, w, h);
136 return;
137 }
138}
139
140int
141main(void)
142{
143 // unsigned int i;
144 // unsigned int pixels[(WIDTH / 4) * (HEIGHT / 4)];
145
146 if (!ecore_evas_init())
147 return EXIT_FAILURE;
148
149 /* this will give you a window with an Evas canvas under the first
150 * engine available */
151 d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
152 if (!d.ee)
153 goto error;
154
155 ecore_evas_callback_destroy_set(d.ee, _on_destroy);
156 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
157 ecore_evas_show(d.ee);
158
159 /* the canvas pointer, de facto */
160 d.evas = ecore_evas_get(d.ee);
161
162 d.bg = evas_object_rectangle_add(d.evas);
163 evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
164 evas_object_move(d.bg, 0, 0); /* at canvas' origin */
165 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
166 evas_object_show(d.bg);
167
168 evas_object_focus_set(d.bg, EINA_TRUE);
169 evas_object_event_callback_add(
170 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
171
172 d.logo = evas_object_image_filled_add(d.evas);
173
174 evas_object_image_file_set(d.logo, img_path, NULL);
175 evas_object_resize(d.logo, WIDTH / 2, HEIGHT);
176 evas_object_show(d.logo);
177
178 d.logo1 = evas_object_image_filled_add(d.evas);
179 evas_object_image_file_set(d.logo1, img_path, NULL);
180 evas_object_resize(d.logo1, WIDTH / 2, HEIGHT);
181 evas_object_move(d.logo1, WIDTH / 2, 0);
182 evas_object_show(d.logo1);
183
184 fprintf(stdout, commands);
185 ecore_main_loop_begin();
186
187 ecore_evas_free(d.ee);
188 ecore_evas_shutdown();
189 return 0;
190
191error:
192 fprintf(stderr, "you got to have at least one evas engine built and linked"
193 " up to ecore-evas for this example to run properly.\n");
194 ecore_evas_shutdown();
195 return -1;
196}
diff --git a/src/examples/evas/evas-init-shutdown.c b/src/examples/evas/evas-init-shutdown.c
new file mode 100644
index 0000000..a7508d8
--- /dev/null
+++ b/src/examples/evas/evas-init-shutdown.c
@@ -0,0 +1,56 @@
1/**
2 * Simple example illustrating usage of evas_init() and
3 * evas_shutdown(). Usually one would instantiate a canvas to have
4 * something useful out of Evas. For an example of this kind, see the
5 * @ref Example_Evas_Buffer_Simple.
6 *
7 * Here, we are just listing the engine Evas was compiled with support
8 * to.
9 *
10 * @verbatim
11 * gcc -o evas-init-shutdown evas-init-shutdown.c `pkg-config --libs \
12 * --cflags evas`
13 * @endverbatim
14 *
15 */
16
17#include <Evas.h>
18#include <stdio.h>
19#include <errno.h>
20
21/*
22 * Simple example illustrating usage of evas_init() and
23 * evas_shutdown(). Usually one would instantiate a canvas to have
24 * something useful out of Evas. For an example of this kind, see the
25 * evas-buffer-simple.c, which requires the buffer engine module
26 * compiled in Evas.
27 *
28 * Here, we are just listing the engine Evas was compiled with support
29 * to.
30 */
31
32int
33main(void)
34{
35 Eina_List *engine_list, *l;
36 char *engine_name;
37
38 evas_init();
39
40 engine_list = evas_render_method_list();
41 if (!engine_list)
42 {
43 fprintf(stderr, "ERROR: Evas supports no engines! Exit.\n");
44 exit(-1);
45 }
46
47 printf("Available Evas Engines:\n");
48 EINA_LIST_FOREACH(engine_list, l, engine_name)
49 printf("%s\n", engine_name);
50
51 evas_render_method_list_free(engine_list);
52
53 evas_shutdown();
54 return 0;
55 }
56
diff --git a/src/examples/evas/evas-map-utils.c b/src/examples/evas/evas-map-utils.c
new file mode 100644
index 0000000..2d15882
--- /dev/null
+++ b/src/examples/evas/evas-map-utils.c
@@ -0,0 +1,321 @@
1/*
2 * gcc -o evas-map-utils evas-map-utils.c `pkg-config --cflags --libs evas ecore ecore-evas`
3 */
4#ifdef HAVE_CONFIG_H
5#include "config.h"
6#else
7#define __UNUSED__
8#endif
9
10#include <Ecore.h>
11#include <Ecore_Evas.h>
12
13#include <stdlib.h>
14#include <stdio.h>
15#include <string.h>
16#include <math.h>
17
18#define WIDTH 480
19#define HEIGHT 480
20
21typedef struct
22{
23 Ecore_Evas *ee;
24 Evas *canvas;
25 struct {
26 int r, g, b, a;
27 } colors[6];
28 int colors_index;
29 int frame;
30 Eina_Bool alpha : 1;
31 Eina_Bool smooth : 1;
32 Eina_Bool backface_culling : 1;
33 Eina_Bool apply_perspective : 1;
34 Eina_Bool apply_lighting : 1;
35} App_Data;
36
37static const char *help_string =
38 "Valid commands:\n"
39 "\ta - toggle alpha for maps\n"
40 "\ts - toggle smooth for maps\n"
41 "\tc - switch map color\n"
42 "\tb - toggle backface culling\n"
43 "\tp - toggle perspective\n"
44 "\tl - toggle lighting\n"
45 "\th - prints this help\n";
46
47static Eina_Bool
48_anim_cb(void *data)
49{
50 App_Data *ad = data;
51 Evas_Map *m;
52 const Evas_Map *old_map;
53 Evas_Object *o;
54 int r, g, b, a;
55 int win_w, win_h, img_w, img_h;
56 Evas_Coord x, y, w, h;
57
58 evas_output_size_get(ad->canvas, &win_w, &win_h);
59
60 m = evas_map_new(4);
61 evas_map_smooth_set(m, ad->smooth);
62 evas_map_alpha_set(m, ad->alpha);
63
64 r = ad->colors[ad->colors_index].r;
65 g = ad->colors[ad->colors_index].g;
66 b = ad->colors[ad->colors_index].b;
67 a = ad->colors[ad->colors_index].a;
68 evas_map_util_points_color_set(m, r, g, b, a);
69
70 o = evas_object_name_find(ad->canvas, "obj1");
71 evas_object_geometry_get(o, &x, &y, &w, &h);
72
73 evas_map_util_points_populate_from_object(m, o);
74 evas_map_util_rotate(m, 3 * ad->frame, x + (w / 2), y + (h / 2));
75 evas_object_map_set(o, m);
76 evas_object_map_enable_set(o, EINA_TRUE);
77
78 o = evas_object_name_find(ad->canvas, "obj2");
79 evas_object_geometry_get(o, &x, &y, &w, &h);
80 evas_object_image_size_get(o, &img_w, &img_h);
81
82 evas_map_util_points_populate_from_object_full(m, o, 100);
83 evas_map_point_image_uv_set(m, 0, 0, 0);
84 evas_map_point_image_uv_set(m, 1, img_w, 0);
85 evas_map_point_image_uv_set(m, 2, img_w, img_h);
86 evas_map_point_image_uv_set(m, 3, 0, img_h);
87 evas_map_util_3d_rotate(m, ad->frame * 6, ad->frame * 6, ad->frame * 6,
88 x + (w / 3), y + 10, 0);
89 if (ad->apply_lighting)
90 evas_map_util_3d_lighting(m, win_w / 2, win_h / 2, -100,
91 255, 255, 255, 0, 0, 0);
92 evas_object_map_set(o, m);
93 evas_object_map_enable_set(o, EINA_TRUE);
94
95 o = evas_object_name_find(ad->canvas, "obj3");
96 evas_object_geometry_get(o, &x, &y, &w, &h);
97 evas_object_image_size_get(o, &img_w, &img_h);
98
99 evas_map_util_points_populate_from_geometry(m, x, y + (h / 2), w, h, -20);
100 evas_map_point_image_uv_set(m, 0, 0, 0);
101 evas_map_point_image_uv_set(m, 1, img_w, 0);
102 evas_map_point_image_uv_set(m, 2, img_w, img_h);
103 evas_map_point_image_uv_set(m, 3, 0, img_h);
104 evas_map_util_3d_rotate(m, 20, ad->frame * 6, 0,
105 x + (w / 2), y + (w / 2), w / 2);
106
107 if (ad->apply_perspective)
108 evas_map_util_3d_perspective(m, x + (w / 2), y + (h / 2), 0, 256);
109 if (ad->apply_lighting)
110 {
111 Evas_Coord mx, my;
112 evas_pointer_canvas_xy_get(ad->canvas, &mx, &my);
113 evas_map_util_3d_lighting(m, mx, my, -256,
114 255, 255, 255, 0, 0, 0);
115 }
116 if (ad->backface_culling)
117 {
118 if (evas_map_util_clockwise_get(m))
119 evas_object_show(o);
120 else
121 evas_object_hide(o);
122 }
123 else
124 evas_object_show(o);
125 evas_object_map_set(o, m);
126 evas_object_map_enable_set(o, EINA_TRUE);
127
128 evas_map_free(m);
129
130 o = evas_object_name_find(ad->canvas, "obj4");
131 evas_object_geometry_get(o, &x, &y, &w, &h);
132 evas_object_image_size_get(evas_object_image_source_get(o), &img_w, &img_h);
133
134 m = evas_map_new(4);
135 evas_map_point_coord_set(m, 0, x, y + h, 0);
136 evas_map_point_coord_set(m, 1, x + w, y + h, 0);
137 evas_map_point_coord_set(m, 2, win_w - 10, win_h - 30, 0);
138 evas_map_point_coord_set(m, 3, (win_w / 2) + 10, win_h - 30, 0);
139 evas_map_point_image_uv_set(m, 0, 0, img_h);
140 evas_map_point_image_uv_set(m, 1, img_w, img_h);
141 evas_map_point_image_uv_set(m, 2, img_w, 2 * (img_h / 3));
142 evas_map_point_image_uv_set(m, 3, 0, 2 * (img_h / 3));
143 evas_map_point_color_set(m, 0, 200, 200, 200, 150);
144 evas_map_point_color_set(m, 1, 200, 200, 200, 150);
145 evas_map_point_color_set(m, 2, 0, 0, 0, 0);
146 evas_map_point_color_set(m, 3, 0, 0, 0, 0);
147 evas_object_map_set(o, m);
148 evas_object_map_enable_set(o, EINA_TRUE);
149
150 evas_map_free(m);
151
152 ad->frame = (ad->frame + 1) % 60;
153
154 return EINA_TRUE;
155}
156
157static void
158_on_keydown(void *data, Evas *e, Evas_Object *o, void *event)
159{
160 App_Data *ad = data;
161 Evas_Event_Key_Down *ev = event;
162 const Evas_Modifier *mods;
163
164 mods = evas_key_modifier_get(ad->canvas);
165 switch (ev->keyname[0])
166 {
167 case 'a':
168 ad->alpha = !ad->alpha;
169 break;
170 case 's':
171 ad->smooth = !ad->smooth;
172 break;
173 case 'c':
174 ad->colors_index = (ad->colors_index + 1) % 6;
175 break;
176 case 'b':
177 ad->backface_culling = !ad->backface_culling;
178 break;
179 case 'p':
180 ad->apply_perspective = !ad->apply_perspective;
181 break;
182 case 'l':
183 ad->apply_lighting = !ad->apply_lighting;
184 break;
185 case 'h':
186 puts(help_string);
187 break;
188 default:
189 break;
190 }
191}
192
193static void
194_objs_fit(Evas *e)
195{
196 Evas_Object *o;
197 int w, h;
198
199 evas_output_size_get(e, &w, &h);
200 w /= 2;
201 h /= 2;
202
203 o = evas_object_name_find(e, "obj1");
204 evas_object_move(o, w / 4, h / 4);
205 evas_object_resize(o, w / 2, h / 2);
206
207 o = evas_object_name_find(e, "obj2");
208 evas_object_move(o, 5 * w / 4, h / 4);
209 evas_object_resize(o, w / 2, h / 2);
210
211 o = evas_object_name_find(e, "obj3");
212 evas_object_move(o, w / 4, 5 * h / 4);
213 evas_object_resize(o, w / 2, h / 2);
214
215 o = evas_object_name_find(e, "obj4_source");
216 evas_object_move(o, 5 * w / 4, 5 * h / 4);
217 evas_object_resize(o, w / 2, h / 2);
218
219 o = evas_object_name_find(e, "obj4");
220 evas_object_move(o, 5 * w / 4, 5 * h / 4);
221 evas_object_resize(o, w / 2, h / 2);
222}
223
224static void
225_on_resize(void *data __UNUSED__, Evas *e, Evas_Object *o __UNUSED__, void *event __UNUSED__)
226{
227 _objs_fit(e);
228}
229
230static void
231_on_free(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event __UNUSED__)
232{
233 ecore_main_loop_quit();
234}
235
236int
237main(void)
238{
239 Evas_Object *bg, *o, *osrc;
240 static App_Data d = {
241 .ee = NULL,
242 .canvas = NULL,
243 .colors = {
244 { 255, 255, 255, 255 },
245 { 128, 128, 0, 128 },
246 { 255, 0, 0, 255 },
247 { 64, 128, 255, 255 },
248 { 11, 23, 58, 132 },
249 { 0, 0, 0, 255 }
250 },
251 .colors_index = 0,
252 .frame = 0,
253 .alpha = EINA_FALSE,
254 .smooth = EINA_FALSE,
255 .backface_culling = EINA_FALSE,
256 .apply_perspective = EINA_TRUE,
257 .apply_lighting = EINA_TRUE
258 };
259
260 if (!ecore_evas_init())
261 return EXIT_FAILURE;
262
263 d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
264 if (!d.ee)
265 goto error;
266
267 d.canvas = ecore_evas_get(d.ee);
268
269 bg = evas_object_image_filled_add(d.canvas);
270 evas_object_image_file_set(bg, "cube1.png", NULL);
271 ecore_evas_object_associate(d.ee, bg, 0);
272 evas_object_focus_set(bg, EINA_TRUE);
273 evas_object_move(bg, 0, 0);
274 evas_object_resize(bg, WIDTH, HEIGHT);
275 evas_object_show(bg);
276
277 o = evas_object_rectangle_add(d.canvas);
278 evas_object_name_set(o, "obj1");
279 evas_object_color_set(o, 128, 0, 200, 200);
280 evas_object_show(o);
281
282 o = evas_object_image_filled_add(d.canvas);
283 evas_object_name_set(o, "obj2");
284 evas_object_image_file_set(o, "enlightenment.png", NULL);
285 evas_object_show(o);
286
287 o = evas_object_image_filled_add(d.canvas);
288 evas_object_name_set(o, "obj3");
289 evas_object_image_file_set(o, "enlightenment.png", NULL);
290 evas_object_show(o);
291
292 osrc = evas_object_image_filled_add(d.canvas);
293 evas_object_image_file_set(osrc, "im1.png", NULL);
294 evas_object_name_set(osrc, "obj4_source");
295 evas_object_show(osrc);
296
297 o = evas_object_image_filled_add(d.canvas);
298 evas_object_image_source_set(o, osrc);
299 evas_object_name_set(o, "obj4");
300 evas_object_show(o);
301
302 _objs_fit(d.canvas);
303
304 evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, &d);
305 evas_object_event_callback_add(bg, EVAS_CALLBACK_RESIZE, _on_resize, NULL);
306 evas_object_event_callback_add(bg, EVAS_CALLBACK_FREE, _on_free, NULL);
307
308 ecore_animator_add(_anim_cb, &d);
309
310 ecore_main_loop_begin();
311
312 ecore_evas_shutdown();
313 return 0;
314
315error:
316 fprintf(stderr, "you got to have at least one evas engine built and linked"
317 " up to ecore-evas for this example to run properly.\n");
318panic:
319 ecore_evas_shutdown();
320 return -1;
321}
diff --git a/src/examples/evas/evas-object-manipulation.c b/src/examples/evas/evas-object-manipulation.c
new file mode 100644
index 0000000..e9c9442
--- /dev/null
+++ b/src/examples/evas/evas-object-manipulation.c
@@ -0,0 +1,235 @@
1/**
2 * Simple Evas example illustrating basic objects manipulation.
3 *
4 * You'll need at least one engine built for it (excluding the buffer
5 * one) and the png image loader also built. See stdout/stderr for
6 * output.
7 *
8 * @verbatim
9 * gcc -o evas-object-manipulation evas-object-manipulation.c `pkg-config --libs --cflags ecore evas ecore-evas`
10 * @endverbatim
11 */
12
13#ifdef HAVE_CONFIG_H
14
15#include "config.h"
16#else
17
18#define PACKAGE_EXAMPLES_DIR "."
19#define __UNUSED__
20
21#endif
22
23#include <Ecore.h>
24#include <Ecore_Evas.h>
25#include <stdio.h>
26#include <errno.h>
27
28#define WIDTH (320)
29#define HEIGHT (240)
30
31static const char *img_path = PACKAGE_EXAMPLES_DIR "/enlightenment.png";
32static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
33
34struct test_data
35{
36 Ecore_Evas *ee;
37 Evas *canvas;
38 Evas_Object *img, *bg, *clipper, *clipper_border, *text;
39};
40
41static struct test_data d = {0};
42
43/* here just to keep our example's window size and background image's
44 * size in synchrony */
45static void
46_canvas_resize_cb(Ecore_Evas *ee)
47{
48 int w, h;
49
50 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
51 evas_object_resize(d.bg, w, h);
52}
53
54static void
55_on_keydown(void *data __UNUSED__,
56 Evas *evas __UNUSED__,
57 Evas_Object *o __UNUSED__,
58 void *einfo)
59{
60 Evas_Event_Key_Down *ev = einfo;
61
62 if (strcmp(ev->keyname, "h") == 0) /* print help */
63 {
64 fprintf(stdout, "commands are:\n"
65 "\to - change clipper's opacity\n"
66 "\tr - toggle clipper's color between red and white\n"
67 "\tc - toggle clipper's clipping function\n"
68 "\tv - toggle clipper's visibility\n");
69 return;
70 }
71
72 if (strcmp(ev->keyname, "o") == 0) /* change clipper's opacity */
73 {
74 int alpha, r, g, b;
75
76 evas_object_color_get(d.clipper, &r, &g, &b, &alpha);
77 alpha -= 20;
78 if (alpha < 0)
79 alpha = 255;
80
81 evas_object_color_set(d.clipper, r, g, b, alpha);
82
83 fprintf(stdout, "Changing clipper's opacity: %d%%\n",
84 (int)((alpha / 255.0) * 100));
85 return;
86 }
87
88 if (strcmp(ev->keyname, "r") == 0) /* toggle clipper's color
89 * between red and white */
90 {
91 int alpha, r, g, b;
92
93 fprintf(stdout, "Changing clipper's color to");
94
95 evas_object_color_get(d.clipper, &r, &g, &b, &alpha);
96 if (g > 0)
97 {
98 fprintf(stdout, "red\n");
99 g = b = 0;
100 }
101 else
102 {
103 fprintf(stdout, "white\n");
104 g = b = 255;
105 }
106
107 evas_object_color_set(d.clipper, r, g, b, alpha);
108 return;
109 }
110
111 if (strcmp(ev->keyname, "c") == 0) /* toggle clipper's clipping function */
112 {
113 fprintf(stdout, "Toggling clipping ");
114
115 if (evas_object_clip_get(d.img) == d.clipper)
116 {
117 evas_object_clip_unset(d.img);
118 fprintf(stdout, "off\n");
119 }
120 else
121 {
122 evas_object_clip_set(d.img, d.clipper);
123 fprintf(stdout, "on\n");
124 }
125 return;
126 }
127
128 if (strcmp(ev->keyname, "v") == 0) /* toggle clipper's visibility */
129 {
130 fprintf(stdout, "Clipper is now ");
131
132 if (evas_object_visible_get(d.clipper))
133 {
134 evas_object_hide(d.clipper);
135 fprintf(stdout, "hidden\n");
136 }
137 else
138 {
139 evas_object_show(d.clipper);
140 fprintf(stdout, "visible\n");
141 }
142 return;
143 }
144}
145
146int
147main(void)
148{
149 int err;
150
151 if (!ecore_evas_init())
152 return EXIT_FAILURE;
153
154 /* this will give you a window with an Evas canvas under the first
155 * engine available */
156 d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
157 if (!d.ee)
158 goto error;
159
160 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
161 ecore_evas_show(d.ee);
162
163 /* the canvas pointer, de facto */
164 d.canvas = ecore_evas_get(d.ee);
165
166 d.bg = evas_object_rectangle_add(d.canvas);
167 evas_object_name_set(d.bg, "background rectangle");
168 evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
169 evas_object_move(d.bg, 0, 0); /* at canvas' origin */
170 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
171 evas_object_show(d.bg);
172
173 evas_object_focus_set(d.bg, EINA_TRUE);
174 evas_object_event_callback_add(
175 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
176
177 d.img = evas_object_image_filled_add(d.canvas);
178 evas_object_image_file_set(d.img, img_path, NULL);
179 err = evas_object_image_load_error_get(d.img);
180 if (err != EVAS_LOAD_ERROR_NONE)
181 {
182 goto panic;
183 }
184 else
185 {
186 evas_object_move(d.img, 0, 0);
187 evas_object_resize(d.img, WIDTH, HEIGHT);
188 evas_object_show(d.img);
189
190 fprintf(stdout, "Image object added, type is: %s\n",
191 evas_object_type_get(d.img));
192 }
193
194 /* border on the image's clipper, here just to emphasize its position */
195 d.clipper_border = evas_object_image_filled_add(d.canvas);
196 evas_object_image_file_set(d.clipper_border, border_img_path, NULL);
197 err = evas_object_image_load_error_get(d.clipper_border);
198 if (err != EVAS_LOAD_ERROR_NONE)
199 {
200 goto panic;
201 }
202 else
203 {
204 evas_object_image_border_set(d.clipper_border, 3, 3, 3, 3);
205 evas_object_image_border_center_fill_set(
206 d.clipper_border, EVAS_BORDER_FILL_NONE);
207 evas_object_move(d.clipper_border, (WIDTH / 4) - 3, (HEIGHT / 4) - 3);
208 evas_object_resize(
209 d.clipper_border, (WIDTH / 2) + 6, (HEIGHT / 2) + 6);
210 evas_object_show(d.clipper_border);
211 }
212
213 /* solid white clipper (note that it's the default color for a
214 * rectangle) - it won't change clippees' colors, then (multiplying
215 * by 255) */
216 d.clipper = evas_object_rectangle_add(d.canvas);
217 evas_object_move(d.clipper, WIDTH / 4, HEIGHT / 4);
218 evas_object_resize(d.clipper, WIDTH / 2, HEIGHT / 2);
219 evas_object_clip_set(d.img, d.clipper);
220 evas_object_show(d.clipper);
221
222 ecore_main_loop_begin();
223
224 ecore_evas_free(d.ee);
225 ecore_evas_shutdown();
226 return 0;
227
228error:
229 fprintf(stderr, "you got to have at least one evas engine built and linked"
230 " up to ecore-evas for this example to run properly.\n");
231panic:
232 ecore_evas_free(d.ee);
233 ecore_evas_shutdown();
234 return -1;
235}
diff --git a/src/examples/evas/evas-smart-interface.c b/src/examples/evas/evas-smart-interface.c
new file mode 100644
index 0000000..97b9a9e
--- /dev/null
+++ b/src/examples/evas/evas-smart-interface.c
@@ -0,0 +1,790 @@
1/**
2 * Simple Evas example illustrating Evas smart interfaces
3 *
4 * You'll need at least one engine built for it (excluding the buffer
5 * one). See stdout/stderr for output.
6 *
7 * @verbatim
8 * gcc -o evas-smart-interface evas-smart-interface.c `pkg-config --libs --cflags evas ecore ecore-evas`
9 * @endverbatim
10 */
11
12#ifdef HAVE_CONFIG_H
13
14#include "config.h"
15#else
16
17#define PACKAGE_EXAMPLES_DIR "."
18#define __UNUSED__
19
20#endif
21
22#include <Ecore.h>
23#include <Ecore_Evas.h>
24#include <stdio.h>
25#include <errno.h>
26
27#define WIDTH (320)
28#define HEIGHT (240)
29
30static const char *commands = \
31 "commands are:\n"
32 "\tl - insert child rectangle on the left\n"
33 "\tr - insert child rectangle on the right\n"
34 "\tw - remove and delete all members from the smart object\n"
35 "\tright arrow - move smart object to the right\n"
36 "\tleft arrow - move smart object to the left\n"
37 "\tup arrow - move smart object up\n"
38 "\tdown arrow - move smart object down\n"
39 "\td - decrease smart object's size\n"
40 "\ti - increase smart object's size\n"
41 "\tc - change smart object's clipper color\n"
42 "\th - print help\n"
43 "\tq - quit\n"
44;
45
46#define WHITE {255, 255, 255, 255}
47#define RED {255, 0, 0, 255}
48#define GREEN {0, 255, 0, 255}
49#define BLUE {0, 0, 255, 255}
50
51struct test_data
52{
53 Ecore_Evas *ee;
54 Evas *evas;
55 Evas_Object *smt, *bg, *clipper, *rects[2];
56};
57
58struct color_tuple
59{
60 int r, g, b, a;
61} clipper_colors[4] = {WHITE, RED, GREEN, BLUE};
62int cur_color = 0;
63
64static const char *
65_index_to_color(int i)
66{
67 switch (i)
68 {
69 case 0:
70 return "WHITE (default)";
71
72 case 1:
73 return "RED";
74
75 case 2:
76 return "GREEN";
77
78 case 3:
79 return "BLUE";
80
81 default:
82 return "other";
83 }
84}
85
86static struct test_data d = {0};
87static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
88
89#define _evas_smart_example_type "Evas_Smart_Example"
90
91static const char iface1_data[] = "iface1_data";
92static const char IFACE1_NAME[] = "iface1";
93
94static Eina_Bool _iface1_add(Evas_Object *);
95static void _iface1_del(Evas_Object *);
96static void _iface1_custom_fn(Evas_Object *);
97
98typedef struct _Evas_Smart_Example_Interface Evas_Smart_Example_Interface;
99struct _Evas_Smart_Example_Interface
100{
101 Evas_Smart_Interface base;
102 void (*example_func)(Evas_Object *obj);
103};
104
105static Evas_Smart_Example_Interface iface1;
106
107static Eina_Bool
108_iface1_add(Evas_Object *obj)
109{
110 printf("iface1's add()!\n");
111
112 return EINA_TRUE;
113}
114
115static void
116_iface1_del(Evas_Object *obj)
117{
118 printf("iface1's del()! Data is %s\n",
119 (char *)evas_object_smart_interface_data_get
120 (obj, (Evas_Smart_Interface *)&iface1));
121}
122
123static void
124_iface1_custom_fn(Evas_Object *obj)
125{
126 printf("iface1's custom_fn()!\n");
127}
128
129static const Evas_Smart_Interface *_smart_interfaces[] =
130{
131 (Evas_Smart_Interface *)&iface1, NULL
132};
133
134#define EVT_CHILDREN_NUMBER_CHANGED "children,changed"
135
136static const Evas_Smart_Cb_Description _smart_callbacks[] =
137{
138 {EVT_CHILDREN_NUMBER_CHANGED, "i"},
139 {NULL, NULL}
140};
141
142typedef struct _Evas_Smart_Example_Data Evas_Smart_Example_Data;
143/*
144 * This structure augments clipped smart object's instance data,
145 * providing extra members required by our example smart object's
146 * implementation.
147 */
148struct _Evas_Smart_Example_Data
149{
150 Evas_Object_Smart_Clipped_Data base;
151 Evas_Object *children[2], *border;
152 int child_count;
153};
154
155#define EVAS_SMART_EXAMPLE_DATA_GET(o, ptr) \
156 Evas_Smart_Example_Data * ptr = evas_object_smart_data_get(o)
157
158#define EVAS_SMART_EXAMPLE_DATA_GET_OR_RETURN(o, ptr) \
159 EVAS_SMART_EXAMPLE_DATA_GET(o, ptr); \
160 if (!ptr) \
161 { \
162 fprintf(stderr, "No widget data for object %p (%s)!", \
163 o, evas_object_type_get(o)); \
164 fflush(stderr); \
165 abort(); \
166 return; \
167 }
168
169#define EVAS_SMART_EXAMPLE_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
170 EVAS_SMART_EXAMPLE_DATA_GET(o, ptr); \
171 if (!ptr) \
172 { \
173 fprintf(stderr, "No widget data for object %p (%s)!", \
174 o, evas_object_type_get(o)); \
175 fflush(stderr); \
176 abort(); \
177 return val; \
178 }
179
180EVAS_SMART_SUBCLASS_IFACE_NEW
181 (_evas_smart_example_type, _evas_smart_example, Evas_Smart_Class,
182 Evas_Smart_Class, evas_object_smart_clipped_class_get, _smart_callbacks,
183 _smart_interfaces);
184
185static void
186_on_destroy(Ecore_Evas *ee __UNUSED__)
187{
188 ecore_main_loop_quit();
189}
190
191/* here just to keep our example's window size and background image's
192 * size in synchrony */
193static void
194_canvas_resize_cb(Ecore_Evas *ee)
195{
196 int w, h;
197
198 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
199 evas_object_resize(d.bg, w, h);
200}
201
202static void
203_on_child_del(void *data,
204 Evas *evas __UNUSED__,
205 Evas_Object *o,
206 void *einfo __UNUSED__)
207{
208 Evas_Object *example_smart = data;
209 long idx;
210
211 EVAS_SMART_EXAMPLE_DATA_GET(example_smart, priv);
212
213 idx = (long)evas_object_data_get(o, "index");
214 idx--;
215
216 priv->children[idx] = NULL;
217
218 evas_object_smart_member_del(o);
219 evas_object_smart_changed(example_smart);
220}
221
222static void
223_evas_smart_example_child_callbacks_unregister(Evas_Object *obj)
224{
225 evas_object_data_set(obj, "index", NULL);
226 evas_object_event_callback_del(obj, EVAS_CALLBACK_FREE, _on_child_del);
227}
228
229static void
230_evas_smart_example_child_callbacks_register(Evas_Object *o,
231 Evas_Object *child,
232 long idx)
233{
234 evas_object_event_callback_add(child, EVAS_CALLBACK_FREE, _on_child_del, o);
235 evas_object_data_set(child, "index", (void *)(++idx));
236}
237
238/* create and setup a new example smart object's internals */
239static void
240_evas_smart_example_smart_add(Evas_Object *o)
241{
242 EVAS_SMART_DATA_ALLOC(o, Evas_Smart_Example_Data);
243
244 /* this is a border around the smart object's area, delimiting it */
245 priv->border = evas_object_image_filled_add(evas_object_evas_get(o));
246 evas_object_image_file_set(priv->border, border_img_path, NULL);
247 evas_object_image_border_set(priv->border, 3, 3, 3, 3);
248 evas_object_image_border_center_fill_set(
249 priv->border, EVAS_BORDER_FILL_NONE);
250 evas_object_smart_member_add(priv->border, o);
251
252 _evas_smart_example_parent_sc->add(o);
253}
254
255static void
256_evas_smart_example_smart_del(Evas_Object *o)
257{
258 EVAS_SMART_EXAMPLE_DATA_GET(o, priv);
259
260 if (priv->children[0])
261 {
262 _evas_smart_example_child_callbacks_unregister(priv->children[0]);
263 priv->children[0] = NULL;
264 }
265
266 if (priv->children[1])
267 {
268 _evas_smart_example_child_callbacks_unregister(priv->children[1]);
269 priv->children[1] = NULL;
270 }
271
272 _evas_smart_example_parent_sc->del(o);
273}
274
275static void
276_evas_smart_example_smart_show(Evas_Object *o)
277{
278 EVAS_SMART_EXAMPLE_DATA_GET(o, priv);
279
280 if (priv->children[0]) evas_object_show(priv->children[0]);
281 if (priv->children[1]) evas_object_show(priv->children[1]);
282 evas_object_show(priv->border);
283
284 _evas_smart_example_parent_sc->show(o);
285}
286
287static void
288_evas_smart_example_smart_hide(Evas_Object *o)
289{
290 EVAS_SMART_EXAMPLE_DATA_GET(o, priv);
291
292 if (priv->children[0]) evas_object_hide(priv->children[0]);
293 if (priv->children[1]) evas_object_hide(priv->children[1]);
294 evas_object_hide(priv->border);
295
296 _evas_smart_example_parent_sc->hide(o);
297}
298
299static void
300_evas_smart_example_smart_resize(Evas_Object *o,
301 Evas_Coord w,
302 Evas_Coord h)
303{
304 Evas_Coord ow, oh;
305 evas_object_geometry_get(o, NULL, NULL, &ow, &oh);
306 if ((ow == w) && (oh == h)) return;
307
308 /* this will trigger recalculation */
309 evas_object_smart_changed(o);
310}
311
312/* act on child objects' properties, before rendering */
313static void
314_evas_smart_example_smart_calculate(Evas_Object *o)
315{
316 Evas_Coord x, y, w, h;
317
318 EVAS_SMART_EXAMPLE_DATA_GET_OR_RETURN(o, priv);
319 evas_object_geometry_get(o, &x, &y, &w, &h);
320
321 evas_object_resize(priv->border, w, h);
322 evas_object_move(priv->border, x, y);
323
324 if (priv->children[0])
325 {
326 evas_object_move(priv->children[0], x + 3, y + 3);
327 evas_object_resize(priv->children[0], (w / 2) - 3, (h / 2) - 3);
328 }
329
330 if (priv->children[1])
331 {
332 evas_object_move(priv->children[1], x + (w / 2), y + (h / 2));
333 evas_object_resize(priv->children[1], (w / 2) - 3, (h / 2) - 3);
334 }
335}
336
337/* setting our smart interface */
338static void
339_evas_smart_example_smart_set_user(Evas_Smart_Class *sc)
340{
341 /* specializing these two */
342 sc->add = _evas_smart_example_smart_add;
343 sc->del = _evas_smart_example_smart_del;
344 sc->show = _evas_smart_example_smart_show;
345 sc->hide = _evas_smart_example_smart_hide;
346
347 /* clipped smart object has no hook on resizes or calculations */
348 sc->resize = _evas_smart_example_smart_resize;
349 sc->calculate = _evas_smart_example_smart_calculate;
350}
351
352/* BEGINS example smart object's own interface */
353
354/* add a new example smart object to a canvas */
355Evas_Object *
356evas_smart_example_add(Evas *evas)
357{
358 return evas_object_smart_add(evas, _evas_smart_example_smart_class_new());
359}
360
361static void
362_evas_smart_example_remove_do(Evas_Smart_Example_Data *priv,
363 Evas_Object *child,
364 int idx)
365{
366 priv->children[idx] = NULL;
367 priv->child_count--;
368 _evas_smart_example_child_callbacks_unregister(child);
369 evas_object_smart_member_del(child);
370}
371
372/* remove a child element, return its pointer (or NULL on errors) */
373Evas_Object *
374evas_smart_example_remove(Evas_Object *o,
375 Evas_Object *child)
376{
377 long idx;
378
379 EVAS_SMART_EXAMPLE_DATA_GET_OR_RETURN_VAL(o, priv, NULL);
380
381 if (priv->children[0] != child && priv->children[1] != child)
382 {
383 fprintf(stderr, "You are trying to remove something not belonging to"
384 " the example smart object!\n");
385 return NULL;
386 }
387
388 idx = (long)evas_object_data_get(child, "index");
389 idx--;
390
391 _evas_smart_example_remove_do(priv, child, idx);
392
393 evas_object_smart_callback_call(
394 o, EVT_CHILDREN_NUMBER_CHANGED, (void *)(long)priv->child_count);
395 evas_object_smart_changed(o);
396
397 return child;
398}
399
400/* set to return any previous object set to the left position of the
401 * smart object or NULL, if any (or on errors) */
402Evas_Object *
403evas_smart_example_set_left(Evas_Object *o,
404 Evas_Object *child)
405{
406 Evas_Object *ret = NULL;
407
408 EVAS_SMART_EXAMPLE_DATA_GET_OR_RETURN_VAL(o, priv, NULL);
409 if (!child)
410 return NULL;
411
412 if (priv->children[1] == child)
413 {
414 fprintf(stderr, "You mustn't place a child on both slots of"
415 " the example smart object!\n");
416 return NULL;
417 }
418
419 if (priv->children[0])
420 {
421 if (priv->children[0] != child)
422 {
423 ret = priv->children[0];
424 _evas_smart_example_remove_do(priv, priv->children[0], 0);
425 }
426 else return child;
427 }
428
429 priv->children[0] = child;
430 _evas_smart_example_child_callbacks_register(o, child, 0);
431 evas_object_smart_member_add(child, o);
432 evas_object_smart_changed(o);
433
434 priv->child_count++;
435 if (!ret)
436 {
437 evas_object_smart_callback_call(
438 o, EVT_CHILDREN_NUMBER_CHANGED, (void *)(long)priv->child_count);
439 }
440
441 return ret;
442}
443
444/* set to return any previous object set to the right position of the
445 * smart object or NULL, if any (or on errors) */
446Evas_Object *
447evas_smart_example_set_right(Evas_Object *o,
448 Evas_Object *child)
449{
450 Evas_Object *ret = NULL;
451
452 EVAS_SMART_EXAMPLE_DATA_GET_OR_RETURN_VAL(o, priv, NULL);
453 if (!child)
454 return NULL;
455
456 if (priv->children[0] == child)
457 {
458 fprintf(stderr, "You mustn't place a child on both slots of"
459 " the example smart object!\n");
460 return NULL;
461 }
462
463 if (priv->children[1])
464 {
465 if (priv->children[1] != child)
466 {
467 ret = priv->children[1];
468 _evas_smart_example_remove_do(priv, priv->children[1], 1);
469 }
470 else return child;
471 }
472
473 priv->children[1] = child;
474 _evas_smart_example_child_callbacks_register(o, child, 1);
475 evas_object_smart_member_add(child, o);
476 evas_object_smart_changed(o);
477
478 priv->child_count++;
479 if (!ret)
480 {
481 evas_object_smart_callback_call(
482 o, EVT_CHILDREN_NUMBER_CHANGED, (void *)(long)priv->child_count);
483 }
484
485 return ret;
486}
487
488/* END OF example smart object's own interface */
489
490static void
491_on_keydown(void *data __UNUSED__,
492 Evas *evas __UNUSED__,
493 Evas_Object *o __UNUSED__,
494 void *einfo)
495{
496 Evas_Event_Key_Down *ev = einfo;
497
498 if (strcmp(ev->keyname, "q") == 0) /* print help */
499 {
500 _on_destroy(NULL);
501 return;
502 }
503
504 if (strcmp(ev->keyname, "h") == 0) /* print help */
505 {
506 fprintf(stdout, commands);
507 return;
508 }
509
510 if (strcmp(ev->keyname, "w") == 0) /* clear out smart object (WRT
511 * members) */
512 {
513 if (d.rects[0])
514 {
515 evas_smart_example_remove(d.smt, d.rects[0]);
516 evas_object_del(d.rects[0]);
517 }
518 if (d.rects[1])
519 {
520 evas_smart_example_remove(d.smt, d.rects[1]);
521 evas_object_del(d.rects[1]);
522 }
523
524 memset(d.rects, 0, sizeof(d.rects));
525
526 fprintf(stdout, "Deleting all members of the smart object.\n");
527
528 return;
529 }
530
531 if (strcmp(ev->keyname, "l") == 0) /* insert random colored
532 * rectangle on the left */
533 {
534 Evas_Object *rect = evas_object_rectangle_add(d.evas), *prev;
535 evas_object_color_set(
536 rect, rand() % 255, rand() % 255, rand() % 255, 255);
537 evas_object_show(rect);
538
539 prev = evas_smart_example_set_left(d.smt, rect);
540 d.rects[0] = rect;
541
542 fprintf(stdout, "Setting smart object's left spot with a new"
543 " rectangle.\n");
544 fprintf(stdout, "Checking its new smart object parent: %s\n",
545 evas_object_smart_parent_get(rect) == d.smt ? "OK!" :
546 "Failure!");
547 if (prev)
548 {
549 int r, g, b;
550
551 evas_object_color_get(prev, &r, &g, &b, NULL);
552 fprintf(stdout, "Deleting previous left child,"
553 " which had colors (%d, %d, %d)\n", r, g, b);
554 evas_object_del(prev);
555 }
556
557 return;
558 }
559
560 if (strcmp(ev->keyname, "r") == 0) /* insert random colored
561 * rectangle on the right */
562 {
563 Evas_Object *rect = evas_object_rectangle_add(d.evas), *prev;
564 evas_object_color_set(
565 rect, rand() % 255, rand() % 255, rand() % 255, 255);
566 evas_object_show(rect);
567
568 prev = evas_smart_example_set_right(d.smt, rect);
569 d.rects[1] = rect;
570
571 fprintf(stdout, "Setting smart object's right spot with a new"
572 " rectangle.\n");
573 fprintf(stdout, "Checking its new smart object parent: %s\n",
574 evas_object_smart_parent_get(rect) == d.smt ? "OK!" :
575 "Failure!");
576 if (prev)
577 {
578 int r, g, b;
579
580 evas_object_color_get(prev, &r, &g, &b, NULL);
581 fprintf(stdout, "Deleting previous right child,"
582 " which had colors (%d, %d, %d)\n", r, g, b);
583 evas_object_del(prev);
584 }
585
586 return;
587 }
588
589 /* move smart object along the canvas */
590 if (strcmp(ev->keyname, "Right") == 0 || strcmp(ev->keyname, "Left") == 0 ||
591 strcmp(ev->keyname, "Up") == 0 || strcmp(ev->keyname, "Down") == 0)
592 {
593 Evas_Coord x, y;
594
595 evas_object_geometry_get(d.smt, &x, &y, NULL, NULL);
596
597 switch (ev->keyname[0])
598 {
599 case 'R':
600 x += 20;
601 break;
602
603 case 'L':
604 x -= 20;
605 break;
606
607 case 'U':
608 y -= 20;
609 break;
610
611 case 'D':
612 y += 20;
613 break;
614 }
615
616 evas_object_move(d.smt, x, y);
617
618 return;
619 }
620
621 /* increase smart object's size */
622 if (strcmp(ev->keyname, "i") == 0)
623 {
624 Evas_Coord w, h;
625
626 evas_object_geometry_get(d.smt, NULL, NULL, &w, &h);
627
628 w *= 1.1;
629 h *= 1.1;
630
631 evas_object_resize(d.smt, w, h);
632
633 return;
634 }
635
636 /* decrease smart object's size */
637 if (strcmp(ev->keyname, "d") == 0)
638 {
639 Evas_Coord w, h;
640