summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2016-06-29 10:24:39 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2016-06-29 10:38:31 +0900
commit0706ae31b14408a941af60d8fd4f268d1961da65 (patch)
tree6bdea2ce10409ada4544db27097cc4a2bd0dd231 /src/examples
parentb13ae2fb8299807f057e79b514933cb6a33e770c (diff)
evas: Add 2 EO examples for maps
Those are copy & paste & eo-ified versions of the legacy samples. I did not touch the other legacy APIs, only maps.
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/evas/.gitignore2
-rw-r--r--src/examples/evas/Makefile.am10
-rw-r--r--src/examples/evas/evas-map-aa-eo.c362
-rw-r--r--src/examples/evas/evas-map-utils-eo.c328
4 files changed, 702 insertions, 0 deletions
diff --git a/src/examples/evas/.gitignore b/src/examples/evas/.gitignore
index 9ee533c..e0621bb 100644
--- a/src/examples/evas/.gitignore
+++ b/src/examples/evas/.gitignore
@@ -16,6 +16,7 @@
16/evas_text 16/evas_text
17/evas_aspect_hints 17/evas_aspect_hints
18/evas_map_utils 18/evas_map_utils
19/evas_map_utils_eo
19/evas_table 20/evas_table
20/evas_multi_touch 21/evas_multi_touch
21/evas_3d_cube 22/evas_3d_cube
@@ -37,6 +38,7 @@
37/saved_Sonic_EET.eet 38/saved_Sonic_EET.eet
38/evas_3d_blending 39/evas_3d_blending
39/evas_map_aa 40/evas_map_aa
41/evas_map_aa_eo
40/evas_3d_mmap 42/evas_3d_mmap
41/evas_3d_shadows 43/evas_3d_shadows
42/evas_3d_parallax_occlusion 44/evas_3d_parallax_occlusion
diff --git a/src/examples/evas/Makefile.am b/src/examples/evas/Makefile.am
index e13aefa..e179934 100644
--- a/src/examples/evas/Makefile.am
+++ b/src/examples/evas/Makefile.am
@@ -194,6 +194,16 @@ evas_map_aa_SOURCES = evas-map-aa.c
194evas_map_aa_LDADD = $(ECORE_EVAS_COMMON_LDADD) 194evas_map_aa_LDADD = $(ECORE_EVAS_COMMON_LDADD)
195evas_map_aa_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS) 195evas_map_aa_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS)
196 196
197EXTRA_PROGRAMS += evas_map_utils-eo
198evas_map_utils_eo_SOURCES = evas-map-utils-eo.c
199evas_map_utils_eo_LDADD = $(ECORE_EVAS_COMMON_LDADD)
200evas_map_utils_eo_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS)
201
202EXTRA_PROGRAMS += evas_map_aa_eo
203evas_map_aa_eo_SOURCES = evas-map-aa-eo.c
204evas_map_aa_eo_LDADD = $(ECORE_EVAS_COMMON_LDADD)
205evas_map_aa_eo_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS)
206
197EXTRA_PROGRAMS += evas_table 207EXTRA_PROGRAMS += evas_table
198evas_table_SOURCES = evas-table.c 208evas_table_SOURCES = evas-table.c
199evas_table_LDADD = $(ECORE_EVAS_COMMON_LDADD) 209evas_table_LDADD = $(ECORE_EVAS_COMMON_LDADD)
diff --git a/src/examples/evas/evas-map-aa-eo.c b/src/examples/evas/evas-map-aa-eo.c
new file mode 100644
index 0000000..00a5bfd
--- /dev/null
+++ b/src/examples/evas/evas-map-aa-eo.c
@@ -0,0 +1,362 @@
1/**
2 * Example showing the difference between Evas Map with and without
3 * anti-aliasing (AA).
4 *
5 * @verbatim
6 * gcc -o evas_map_aa_eo evas-map-aa-eo.c `pkg-config --libs --cflags evas ecore ecore-evas eina`
7 * @endverbatim
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#else
13#define PACKAGE_EXAMPLES_DIR "."
14#endif
15
16#ifndef EFL_BETA_API_SUPPORT
17# define EFL_BETA_API_SUPPORT
18#endif
19
20#ifndef EFL_EO_API_SUPPORT
21# define EFL_EO_API_SUPPORT
22#endif
23
24#include <Ecore.h>
25#include <Ecore_Evas.h>
26#include <stdlib.h>
27#include <stdio.h>
28#include <string.h>
29#include "evas-common.h"
30
31#define WIDTH (800)
32#define HEIGHT (400)
33
34#define IMAGE_SIZE_W 256
35#define IMAGE_SIZE_H 256
36
37struct exemple_data
38{
39 Ecore_Evas *ee;
40 Evas *evas;
41 Evas_Object *bg;
42 Evas_Object *target1;
43 Evas_Object *target2;
44 Evas_Coord px1, py1;
45 Evas_Coord px2, py2;
46 Evas_Coord px3, py3;
47 Evas_Coord px4, py4;
48 Eina_Bool r1_down;
49 Eina_Bool r2_down;
50 Eina_Bool r3_down;
51 Eina_Bool r4_down;
52 Eina_Bool image;
53};
54
55static const char *img_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/cube1.png";
56
57static struct exemple_data d =
58{ NULL, NULL, NULL, NULL, NULL, 62, 62, 262, 62, 262, 262, 62, 262,
59 EINA_FALSE, EINA_FALSE, EINA_FALSE, EINA_FALSE, EINA_FALSE };
60
61static void
62update()
63{
64 efl_gfx_map_populate(d.target1, 0);
65
66 efl_gfx_map_point_coord_set(d.target1, 0, d.px1, d.py1, 0);
67 efl_gfx_map_point_coord_set(d.target1, 1, d.px2, d.py2, 0);
68 efl_gfx_map_point_coord_set(d.target1, 2, d.px3, d.py3, 0);
69 efl_gfx_map_point_coord_set(d.target1, 3, d.px4, d.py4, 0);
70
71 efl_gfx_map_point_image_uv_set(d.target1, 0, 0, 0);
72 efl_gfx_map_point_image_uv_set(d.target1, 1, IMAGE_SIZE_W, 0);
73 efl_gfx_map_point_image_uv_set(d.target1, 2, IMAGE_SIZE_W, IMAGE_SIZE_H);
74 efl_gfx_map_point_image_uv_set(d.target1, 3, 0, IMAGE_SIZE_H);
75
76 efl_gfx_map_enable_set(d.target1, EINA_TRUE);
77
78 efl_gfx_map_dup(d.target2, d.target1);
79
80 efl_gfx_map_point_coord_set(d.target2, 0, d.px1 + 400, d.py1, 0);
81 efl_gfx_map_point_coord_set(d.target2, 1, d.px2 + 400, d.py2, 0);
82 efl_gfx_map_point_coord_set(d.target2, 2, d.px3 + 400, d.py3, 0);
83 efl_gfx_map_point_coord_set(d.target2, 3, d.px4 + 400, d.py4, 0);
84
85 efl_gfx_map_enable_set(d.target2, EINA_TRUE);
86}
87
88static void
89r1_down_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
90 Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
91{
92 d.r1_down = EINA_TRUE;
93}
94
95static void
96r1_up_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
97 Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
98{
99 d.r1_down = EINA_FALSE;
100}
101
102static void
103r1_move_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj,
104 void *event_info)
105{
106 Evas_Coord x, y, w, h;
107
108 if (!d.r1_down) return;
109
110 Evas_Event_Mouse_Move *ev = event_info;
111
112 evas_object_geometry_get(obj, &x, &y, &w, &h);
113
114 evas_object_move(obj, ev->cur.canvas.x - (w/2), ev->cur.canvas.y - (h/2));
115
116 d.px1 = ev->cur.canvas.x;
117 d.py1 = ev->cur.canvas.y;
118
119 update();
120}
121
122static void
123r2_down_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
124 Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
125{
126 d.r2_down = EINA_TRUE;
127}
128
129static void
130r2_up_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
131 Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
132{
133 d.r2_down = EINA_FALSE;
134}
135
136static void
137r2_move_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj,
138 void *event_info)
139{
140 Evas_Coord x, y, w, h;
141
142 if (!d.r2_down) return;
143
144 Evas_Event_Mouse_Move *ev = event_info;
145
146 evas_object_geometry_get(obj, &x, &y, &w, &h);
147
148 evas_object_move(obj, ev->cur.canvas.x - (w/2), ev->cur.canvas.y - (h/2));
149
150 d.px2 = ev->cur.canvas.x;
151 d.py2 = ev->cur.canvas.y;
152
153 update();
154}
155
156static void
157r3_down_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
158 Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
159{
160 d.r3_down = EINA_TRUE;
161}
162
163static void
164r3_up_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
165 Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
166{
167 d.r3_down = EINA_FALSE;
168}
169
170static void
171r3_move_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj,
172 void *event_info)
173{
174 Evas_Coord x, y, w, h;
175
176 if (!d.r3_down) return;
177
178 Evas_Event_Mouse_Move *ev = event_info;
179
180 evas_object_geometry_get(obj, &x, &y, &w, &h);
181
182 evas_object_move(obj, ev->cur.canvas.x - (w/2), ev->cur.canvas.y - (h/2));
183
184 d.px3 = ev->cur.canvas.x;
185 d.py3 = ev->cur.canvas.y;
186
187 update();
188}
189
190static void
191r4_down_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
192 Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
193{
194 d.r4_down = EINA_TRUE;
195}
196
197static void
198r4_up_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
199 Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
200{
201 d.r4_down = EINA_FALSE;
202}
203
204static void
205r4_move_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj,
206 void *event_info)
207{
208 if (!d.r4_down) return;
209
210 Evas_Event_Mouse_Move *ev = event_info;
211
212 Evas_Coord x, y, w, h;
213 evas_object_geometry_get(obj, &x, &y, &w, &h);
214
215 evas_object_move(obj, ev->cur.canvas.x - (w/2), ev->cur.canvas.y - (h/2));
216
217 d.px4 = ev->cur.canvas.x;
218 d.py4 = ev->cur.canvas.y;
219
220 update();
221}
222
223static void
224_on_keydown(void *data EINA_UNUSED, Evas *e, Evas_Object *obj EINA_UNUSED,
225 void *event_info)
226{
227 Evas_Event_Key_Down *ev = event_info;
228
229 if (!strcmp(ev->keyname, "i") || !strcmp(ev->keyname, "I"))
230 {
231 d.image = !d.image;
232
233 if (d.image)
234 {
235 evas_object_del(d.target1);
236 d.target1 = evas_object_image_filled_add(e);
237 evas_object_image_file_set(d.target1, img_path, NULL);
238 evas_object_image_smooth_scale_set(d.target1, 0);
239 evas_object_resize(d.target1, 200, 200);
240 evas_object_show(d.target1);
241
242 evas_object_del(d.target2);
243 d.target2 = evas_object_image_filled_add(e);
244 evas_object_image_file_set(d.target2, img_path, NULL);
245 evas_object_image_smooth_scale_set(d.target2, 0);
246 evas_object_anti_alias_set(d.target2, EINA_TRUE);
247 evas_object_resize(d.target2, 200, 200);
248 evas_object_show(d.target2);
249 }
250 else
251 {
252 evas_object_del(d.target1);
253 d.target1 = evas_object_rectangle_add(e);
254 evas_object_color_set(d.target1, 255, 0, 0, 255);
255 evas_object_resize(d.target1, 200, 200);
256 evas_object_move(d.target1, 64, 64);
257 evas_object_show(d.target1);
258
259 evas_object_del(d.target2);
260 d.target2 = evas_object_rectangle_add(e);
261 evas_object_anti_alias_set(d.target2, EINA_TRUE);
262 evas_object_color_set(d.target2, 255, 0, 0, 255);
263 evas_object_resize(d.target2, 200, 200);
264 evas_object_move(d.target2, 464, 64);
265 evas_object_show(d.target2);
266 }
267 update();
268 }
269}
270
271static void
272_on_delete(Ecore_Evas *ee EINA_UNUSED)
273{
274 ecore_main_loop_quit();
275}
276
277int
278main(void)
279{
280 if (!ecore_evas_init())
281 return EXIT_FAILURE;
282
283 d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
284 if (!d.ee)
285 goto panic;
286
287 ecore_evas_callback_delete_request_set(d.ee, _on_delete);
288 ecore_evas_show(d.ee);
289
290 d.evas = ecore_evas_get(d.ee);
291
292 d.bg = evas_object_rectangle_add(d.evas);
293 evas_object_resize(d.bg, WIDTH, HEIGHT);
294 evas_object_color_set(d.bg, 255, 255, 255, 255);
295 evas_object_show(d.bg);
296
297 evas_object_focus_set(d.bg, EINA_TRUE);
298 evas_object_event_callback_add(d.bg, EVAS_CALLBACK_KEY_DOWN,
299 _on_keydown, NULL);
300
301 Evas_Object *r1 = evas_object_rectangle_add(d.evas);
302 evas_object_event_callback_add(r1, EVAS_CALLBACK_MOUSE_DOWN, r1_down_cb, 0);
303 evas_object_event_callback_add(r1, EVAS_CALLBACK_MOUSE_MOVE, r1_move_cb, 0);
304 evas_object_event_callback_add(r1, EVAS_CALLBACK_MOUSE_UP, r1_up_cb, 0);
305 evas_object_layer_set(r1, EVAS_LAYER_MAX);
306 evas_object_color_set(r1, 125, 0, 125, 125);
307 evas_object_move(r1, 50, 50);
308 evas_object_resize(r1, 25, 25);
309 evas_object_show(r1);
310
311 Evas_Object *r2 = evas_object_rectangle_add(d.evas);
312 evas_object_event_callback_add(r2, EVAS_CALLBACK_MOUSE_DOWN, r2_down_cb, 0);
313 evas_object_event_callback_add(r2, EVAS_CALLBACK_MOUSE_MOVE, r2_move_cb, 0);
314 evas_object_event_callback_add(r2, EVAS_CALLBACK_MOUSE_UP, r2_up_cb, 0);
315 evas_object_layer_set(r2, EVAS_LAYER_MAX);
316 evas_object_color_set(r2, 0, 0, 0, 125);
317 evas_object_move(r2, 250, 50);
318 evas_object_resize(r2, 25, 25);
319 evas_object_show(r2);
320
321 Evas_Object *r3 = evas_object_rectangle_add(d.evas);
322 evas_object_event_callback_add(r3, EVAS_CALLBACK_MOUSE_DOWN, r3_down_cb, 0);
323 evas_object_event_callback_add(r3, EVAS_CALLBACK_MOUSE_MOVE, r3_move_cb, 0);
324 evas_object_event_callback_add(r3, EVAS_CALLBACK_MOUSE_UP, r3_up_cb, 0);
325 evas_object_color_set(r3, 0, 0, 125, 125);
326 evas_object_layer_set(r3, EVAS_LAYER_MAX);
327 evas_object_move(r3, 250, 250);
328 evas_object_resize(r3, 25, 25);
329 evas_object_show(r3);
330
331 Evas_Object *r4 = evas_object_rectangle_add(d.evas);
332 evas_object_event_callback_add(r4, EVAS_CALLBACK_MOUSE_DOWN, r4_down_cb, 0);
333 evas_object_event_callback_add(r4, EVAS_CALLBACK_MOUSE_MOVE, r4_move_cb, 0);
334 evas_object_event_callback_add(r4, EVAS_CALLBACK_MOUSE_UP, r4_up_cb, 0);
335 evas_object_color_set(r4, 0, 125, 0, 125);
336 evas_object_layer_set(r4, EVAS_LAYER_MAX);
337 evas_object_move(r4, 50, 250);
338 evas_object_resize(r4, 25, 25);
339 evas_object_show(r4);
340
341 d.target1 = evas_object_rectangle_add(d.evas);
342 evas_object_color_set(d.target1, 255, 0, 0, 255);
343 evas_object_resize(d.target1, 200, 200);
344 evas_object_move(d.target1, 64, 64);
345 evas_object_show(d.target1);
346
347 d.target2 = evas_object_rectangle_add(d.evas);
348 evas_object_anti_alias_set(d.target2, EINA_TRUE);
349 evas_object_color_set(d.target2, 255, 0, 0, 255);
350 evas_object_resize(d.target2, 200, 200);
351 evas_object_move(d.target2, 464, 64);
352 evas_object_show(d.target2);
353
354 ecore_main_loop_begin();
355 ecore_evas_shutdown();
356 return 0;
357
358panic:
359 fprintf(stderr, "You got to have at least one evas engine built and linked"
360 " up to ecore-evas for this example to run properly.\n");
361 return -2;
362}
diff --git a/src/examples/evas/evas-map-utils-eo.c b/src/examples/evas/evas-map-utils-eo.c
new file mode 100644
index 0000000..0894518
--- /dev/null
+++ b/src/examples/evas/evas-map-utils-eo.c
@@ -0,0 +1,328 @@
1/**
2 * Simple Evas example illustrating basic map utils.
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_map_utils_eo evas-map-utils-eo.c `pkg-config --cflags --libs evas ecore ecore-evas`
9 * @endverbatim
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#else
15#define PACKAGE_EXAMPLES_DIR "."
16#endif
17
18#ifndef EFL_BETA_API_SUPPORT
19# define EFL_BETA_API_SUPPORT
20#endif
21
22#ifndef EFL_EO_API_SUPPORT
23# define EFL_EO_API_SUPPORT
24#endif
25
26#include <Ecore.h>
27#include <Ecore_Evas.h>
28
29#include <stdlib.h>
30#include <stdio.h>
31#include <string.h>
32#include <math.h>
33#include "evas-common.h"
34
35#define WIDTH 480
36#define HEIGHT 480
37
38typedef struct
39{
40 Ecore_Evas *ee;
41 Evas *canvas;
42 struct {
43 int r, g, b, a;
44 } colors[6];
45 int colors_index;
46 int frame;
47 Eina_Bool alpha : 1;
48 Eina_Bool smooth : 1;
49 Eina_Bool backface_culling : 1;
50 Eina_Bool apply_perspective : 1;
51 Eina_Bool apply_lighting : 1;
52} App_Data;
53
54static const char *img1_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/cube1.png";
55static const char *img2_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/enlightenment.png";
56static const char *img3_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/im1.png";
57
58static const char *help_string =
59 "Valid commands:\n"
60 "\ta - toggle alpha for maps\n"
61 "\ts - toggle smooth for maps\n"
62 "\tc - switch map color\n"
63 "\tb - toggle backface culling\n"
64 "\tp - toggle perspective\n"
65 "\tl - toggle lighting\n"
66 "\th - prints this help\n";
67
68static Eina_Bool
69_anim_cb(void *data)
70{
71 App_Data *ad = data;
72 Evas_Object *o, *ref;
73 int r, g, b, a;
74 int win_w, win_h, img_w, img_h;
75 Evas_Coord x, y, w, h;
76
77 evas_output_size_get(ad->canvas, &win_w, &win_h);
78
79 r = ad->colors[ad->colors_index].r;
80 g = ad->colors[ad->colors_index].g;
81 b = ad->colors[ad->colors_index].b;
82 a = ad->colors[ad->colors_index].a;
83
84 o = evas_object_name_find(ad->canvas, "obj1");
85 evas_object_geometry_get(o, &x, &y, &w, &h);
86
87 efl_gfx_map_populate(o, 0);
88 efl_gfx_map_rotate(o, 3 * ad->frame, x + (w / 2), y + (h / 2));
89 efl_gfx_map_smooth_set(o, ad->smooth);
90 efl_gfx_map_alpha_set(o, ad->alpha);
91 efl_gfx_map_color_set(o, -1, r, g, b, a);
92 efl_gfx_map_enable_set(o, EINA_TRUE);
93 ref = o;
94
95 o = evas_object_name_find(ad->canvas, "obj2");
96 evas_object_geometry_get(o, &x, &y, &w, &h);
97 evas_object_image_size_get(o, &img_w, &img_h);
98
99 efl_gfx_map_dup(o, ref);
100 efl_gfx_map_populate(o, 100);
101 efl_gfx_map_point_image_uv_set(o, 0, 0, 0);
102 efl_gfx_map_point_image_uv_set(o, 1, img_w, 0);
103 efl_gfx_map_point_image_uv_set(o, 2, img_w, img_h);
104 efl_gfx_map_point_image_uv_set(o, 3, 0, img_h);
105 efl_gfx_map_rotate_3d(o, ad->frame * 6, ad->frame * 6, ad->frame * 6,
106 x + (w / 3), y + 10, 0);
107 if (ad->apply_lighting)
108 efl_gfx_map_lightning_3d(o, win_w / 2, win_h / 2, -100,
109 255, 255, 255, 0, 0, 0);
110 efl_gfx_map_enable_set(o, EINA_TRUE);
111
112 o = evas_object_name_find(ad->canvas, "obj3");
113 evas_object_geometry_get(o, &x, &y, &w, &h);
114 evas_object_image_size_get(o, &img_w, &img_h);
115
116 efl_gfx_map_dup(o, ref);
117 efl_gfx_map_populate_manual(o, x, y + (h / 2), w, h, -20);
118 efl_gfx_map_point_image_uv_set(o, 0, 0, 0);
119 efl_gfx_map_point_image_uv_set(o, 1, img_w, 0);
120 efl_gfx_map_point_image_uv_set(o, 2, img_w, img_h);
121 efl_gfx_map_point_image_uv_set(o, 3, 0, img_h);
122 efl_gfx_map_rotate_3d(o, 20, ad->frame * 6, 0,
123 x + (w / 2), y + (w / 2), w / 2);
124
125 if (ad->apply_perspective)
126 efl_gfx_map_perspective_3d(o, x + (w / 2), y + (h / 2), 0, 256);
127 if (ad->apply_lighting)
128 {
129 Evas_Coord mx, my;
130 evas_pointer_canvas_xy_get(ad->canvas, &mx, &my);
131 efl_gfx_map_lightning_3d(o, mx, my, -256, 255, 255, 255, 0, 0, 0);
132 }
133 if (ad->backface_culling)
134 {
135 if (efl_gfx_map_clockwise_get(o))
136 evas_object_show(o);
137 else
138 evas_object_hide(o);
139 }
140 else
141 evas_object_show(o);
142 efl_gfx_map_enable_set(o, EINA_TRUE);
143
144 o = evas_object_name_find(ad->canvas, "obj4");
145 evas_object_geometry_get(o, &x, &y, &w, &h);
146 evas_object_image_size_get(evas_object_image_source_get(o), &img_w, &img_h);
147
148 efl_gfx_map_dup(o, ref);
149 efl_gfx_map_point_coord_set(o, 0, x, y + h, 0);
150 efl_gfx_map_point_coord_set(o, 1, x + w, y + h, 0);
151 efl_gfx_map_point_coord_set(o, 2, win_w - 10, win_h - 30, 0);
152 efl_gfx_map_point_coord_set(o, 3, (win_w / 2) + 10, win_h - 30, 0);
153 efl_gfx_map_point_image_uv_set(o, 0, 0, img_h);
154 efl_gfx_map_point_image_uv_set(o, 1, img_w, img_h);
155 efl_gfx_map_point_image_uv_set(o, 2, img_w, 2 * (img_h / 3));
156 efl_gfx_map_point_image_uv_set(o, 3, 0, 2 * (img_h / 3));
157 efl_gfx_map_color_set(o, 0, 200, 200, 200, 150);
158 efl_gfx_map_color_set(o, 1, 200, 200, 200, 150);
159 efl_gfx_map_color_set(o, 2, 0, 0, 0, 0);
160 efl_gfx_map_color_set(o, 3, 0, 0, 0, 0);
161 efl_gfx_map_enable_set(o, EINA_TRUE);
162
163 ad->frame = (ad->frame + 1) % 60;
164
165 return EINA_TRUE;
166}
167
168static void
169_on_keydown(void *data, Evas *e EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *event)
170{
171 App_Data *ad = data;
172 Evas_Event_Key_Down *ev = event;
173 switch (ev->key[0])
174 {
175 case 'a':
176 ad->alpha = !ad->alpha;
177 break;
178 case 's':
179 ad->smooth = !ad->smooth;
180 break;
181 case 'c':
182 ad->colors_index = (ad->colors_index + 1) % 6;
183 break;
184 case 'b':
185 ad->backface_culling = !ad->backface_culling;
186 break;
187 case 'p':
188 ad->apply_perspective = !ad->apply_perspective;
189 break;
190 case 'l':
191 ad->apply_lighting = !ad->apply_lighting;
192 break;
193 case 'h':
194 puts(help_string);
195 break;
196 default:
197 break;
198 }
199}
200
201static void
202_objs_fit(Evas *e)
203{
204 Evas_Object *o;
205 int w, h;
206
207 evas_output_size_get(e, &w, &h);
208 w /= 2;
209 h /= 2;
210
211 o = evas_object_name_find(e, "obj1");
212 evas_object_move(o, w / 4, h / 4);
213 evas_object_resize(o, w / 2, h / 2);
214
215 o = evas_object_name_find(e, "obj2");
216 evas_object_move(o, 5 * w / 4, h / 4);
217 evas_object_resize(o, w / 2, h / 2);
218
219 o = evas_object_name_find(e, "obj3");
220 evas_object_move(o, w / 4, 5 * h / 4);
221 evas_object_resize(o, w / 2, h / 2);
222
223 o = evas_object_name_find(e, "obj4_source");
224 evas_object_move(o, 5 * w / 4, 5 * h / 4);
225 evas_object_resize(o, w / 2, h / 2);
226
227 o = evas_object_name_find(e, "obj4");
228 evas_object_move(o, 5 * w / 4, 5 * h / 4);
229 evas_object_resize(o, w / 2, h / 2);
230}
231
232static void
233_on_resize(void *data EINA_UNUSED, Evas *e, Evas_Object *o EINA_UNUSED, void *event EINA_UNUSED)
234{
235 _objs_fit(e);
236}
237
238static void
239_on_free(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *event EINA_UNUSED)
240{
241 ecore_main_loop_quit();
242}
243
244int
245main(void)
246{
247 Evas_Object *bg, *o, *osrc;
248 static App_Data d = {
249 .ee = NULL,
250 .canvas = NULL,
251 .colors = {
252 { 255, 255, 255, 255 },
253 { 128, 128, 0, 128 },
254 { 255, 0, 0, 255 },
255 { 64, 128, 255, 255 },
256 { 11, 23, 58, 132 },
257 { 0, 0, 0, 255 }
258 },
259 .colors_index = 0,
260 .frame = 0,
261 .alpha = EINA_FALSE,
262 .smooth = EINA_FALSE,
263 .backface_culling = EINA_FALSE,
264 .apply_perspective = EINA_TRUE,
265 .apply_lighting = EINA_TRUE
266 };
267
268 if (!ecore_evas_init())
269 return EXIT_FAILURE;
270
271 d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
272 if (!d.ee)
273 goto error;
274
275 d.canvas = ecore_evas_get(d.ee);
276
277 bg = evas_object_image_filled_add(d.canvas);
278 evas_object_image_file_set(bg, img1_path, NULL);
279 ecore_evas_object_associate(d.ee, bg, 0);
280 evas_object_focus_set(bg, EINA_TRUE);
281 evas_object_move(bg, 0, 0);
282 evas_object_resize(bg, WIDTH, HEIGHT);
283 evas_object_show(bg);
284
285 o = evas_object_rectangle_add(d.canvas);
286 evas_object_name_set(o, "obj1");
287 evas_object_color_set(o, 128, 0, 200, 200);
288 evas_object_show(o);
289
290 o = evas_object_image_filled_add(d.canvas);
291 evas_object_name_set(o, "obj2");
292 evas_object_image_file_set(o, img2_path, NULL);
293 evas_object_show(o);
294
295 o = evas_object_image_filled_add(d.canvas);
296 evas_object_name_set(o, "obj3");
297 evas_object_image_file_set(o, img2_path, NULL);
298 evas_object_show(o);
299
300 osrc = evas_object_image_filled_add(d.canvas);
301 evas_object_image_file_set(osrc, img3_path, NULL);
302 evas_object_name_set(osrc, "obj4_source");
303 evas_object_show(osrc);
304
305 o = evas_object_image_filled_add(d.canvas);
306 evas_object_image_source_set(o, osrc);
307 evas_object_name_set(o, "obj4");
308 evas_object_show(o);
309
310 _objs_fit(d.canvas);
311
312 evas_object_event_callback_add(bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, &d);
313 evas_object_event_callback_add(bg, EVAS_CALLBACK_RESIZE, _on_resize, NULL);
314 evas_object_event_callback_add(bg, EVAS_CALLBACK_FREE, _on_free, NULL);
315
316 ecore_animator_add(_anim_cb, &d);
317
318 ecore_main_loop_begin();
319
320 ecore_evas_shutdown();
321 return 0;
322
323error:
324 fprintf(stderr, "you got to have at least one evas engine built and linked"
325 " up to ecore-evas for this example to run properly.\n");
326 ecore_evas_shutdown();
327 return -1;
328}