aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/examples/evas-map-utils.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-04 18:41:13 +1000
committerDavid Walter Seikel2012-01-04 18:41:13 +1000
commitdd7595a3475407a7fa96a97393bae8c5220e8762 (patch)
treee341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/evas/src/examples/evas-map-utils.c
parentAdd the skeleton. (diff)
downloadSledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to '')
-rw-r--r--libraries/evas/src/examples/evas-map-utils.c321
1 files changed, 321 insertions, 0 deletions
diff --git a/libraries/evas/src/examples/evas-map-utils.c b/libraries/evas/src/examples/evas-map-utils.c
new file mode 100644
index 0000000..2d15882
--- /dev/null
+++ b/libraries/evas/src/examples/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}