summaryrefslogtreecommitdiff
path: root/src/examples/evas/evas-map-aa-eo.c
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/evas/evas-map-aa-eo.c
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/evas/evas-map-aa-eo.c')
-rw-r--r--src/examples/evas/evas-map-aa-eo.c362
1 files changed, 362 insertions, 0 deletions
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}