summaryrefslogtreecommitdiff
path: root/unsorted/evas/evas-vg-simple.c
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2018-08-09 16:21:58 -0400
committerMike Blumenkrantz <zmike@samsung.com>2018-08-09 16:21:58 -0400
commitd9bc92888a11c400320c2058b3500a248e220363 (patch)
tree223be84ba5f8c1c7a725c4cca7c96488090d29bd /unsorted/evas/evas-vg-simple.c
parent471e5a2e5ce40d56d4989a9f0d6b78e5a3df71f0 (diff)
examples
Diffstat (limited to 'unsorted/evas/evas-vg-simple.c')
-rw-r--r--unsorted/evas/evas-vg-simple.c594
1 files changed, 0 insertions, 594 deletions
diff --git a/unsorted/evas/evas-vg-simple.c b/unsorted/evas/evas-vg-simple.c
deleted file mode 100644
index 36b8baa..0000000
--- a/unsorted/evas/evas-vg-simple.c
+++ /dev/null
@@ -1,594 +0,0 @@
1/**
2 * Example of Evas' vector graphics object and API.
3 *
4 * Vector graphics describe an image with distinct shapes - lines,
5 * rectangles, circles, curves; this distinguishes it from raster
6 * graphics where the image is comprised of a grid of colored pixels.
7 *
8 * Just as there are many different file and data formats for raster
9 * graphics, there are also many data formats for vector graphics. A
10 * well-known one is Scalable Vector Graphics (SVG). This example uses
11 * SVG-like path definitions to create a shape in evas_vg and then
12 * modify and animate it using the evas_vg API; there is a second test
13 * mode to demonstrate a timeline animation of morphing between two
14 * shapes using evas_vg's interpolation API.
15 *
16 * Internally, evas_vg uses EFL's Ector component to interface with the
17 * underlying graphics rendering subsystems in a two step process.
18 * First is a 'prepare' phase where CPU intensive operations are
19 * performed (ideally spawned on a separate thread), second is the
20 * 'render' phase where memory intensive work is done. The reason for
21 * this split is to enable pushing work to the GPU in order to attain
22 * higher performance. Ector currently supports use of Cairo, GL, and a
23 * software backend renderer.
24 *
25 * You'll need at least one engine built for this example (excluding the
26 * buffer one). See stdout/stderr for output.
27 *
28 * @verbatim
29 * gcc -o evas_vg_simple evas-vg-simple.c `pkg-config --libs --cflags evas ecore ecore-evas eina ector eo efl` -lm
30 * @endverbatim
31 */
32
33#ifdef HAVE_CONFIG_H
34#include "config.h"
35#else
36#define PACKAGE_EXAMPLES_DIR "."
37#endif
38
39#define WIDTH 600
40#define HEIGHT 600
41
42#ifndef EFL_BETA_API_SUPPORT
43#define EFL_BETA_API_SUPPORT
44#endif
45
46#ifndef EFL_EO_API_SUPPORT
47#define EFL_EO_API_SUPPORT
48#endif
49
50#include <Eo.h>
51#include <Efl.h>
52#include <Evas.h>
53#include <Ecore.h>
54#include <Ecore_Evas.h>
55#include <Eina.h>
56
57struct example_data
58{
59 Ecore_Evas *ee;
60 Evas *evas;
61 Evas_Object *bg;
62 Evas_Object *vg;
63 Eina_List *shape_list;
64
65};
66
67static struct example_data d;
68Ecore_Animator *animator;
69
70/* These data strings follows an SVG-like convention for describing the
71 * nodes of a path. 'M x,y' indicates a move-to operation that sets
72 * where to start drawing. 'L x,y' draws a straight line that ends at
73 * the given point. 'C x1,y1 x2,y2 x,y' defines a Bezier curve's two
74 * control points and the x,y coordinate where the curve ends. 'Z' marks
75 * the end of the path.
76 */
77static const char *batman = "M 256,213 C 245,181 206,187 234,262 147,181 169,71.2 233,18 220,56 235,81 283,88 285,78.7 286,69.3 288,60 289,61.3 290,62.7 291,64 291,64 297,63 300,63 303,63 309,64 309,64 310,62.7 311,61.3 312,60 314,69.3 315,78.7 317,88 365,82 380,56 367,18 431,71 453,181 366,262 394,187 356,181 344,213 328,185 309,184 300,284 291,184 272,185 256,213 Z";
78static const char *morph1[2] = {"M 0,0 L 0,0 L 100,0 L 100,0 L 100,100 L 100,100 L 0,100 L 0,100 L 0,0",
79 "M 0,0 L 50,-80 L 100,0 L 180,50 L 100,100 L 50,180 L 0,100 L -80,50 L 0,0"};
80
81static void _main_menu();
82static void _main_menu_key_handle(void *data, Evas *evas, Evas_Object *o, void *einfo);
83
84static const char *main_menu = \
85 "Main Menu:\n"
86 "\t1 - Basic Shape test\n"
87 "\t2 - Interpolation\n"
88 "\te - Exit\n"
89 "\th - Print help\n";
90
91static const char *basic_shape_menu = \
92 "Basic Shape Menu:\n"
93 "\tup - Increase Stroke Width by 0.5\n"
94 "\tdown - Decrease Stroke Width by 0.5\n"
95 "\tr - +10 degree rotation\n"
96 "\tR - -10 degree rotation\n"
97 "\ts - +(.1, .1) scale\n"
98 "\tS - -(.1, .1) scale\n"
99 "\tt - +(10,10) translation\n"
100 "\tT - +(10,10) translation\n"
101 "\td - Reset path data\n"
102 "\te - Exit\n"
103 "\tb - Back to Main Menu\n"
104 "\th - Print help\n";
105
106static const char *interpolation_menu = \
107 "Interpolation Menu:\n"
108 "\te - Exit\n"
109 "\tb - Back to Main Menu\n"
110 "\th - print help\n";
111
112static void
113_on_delete(Ecore_Evas *ee EINA_UNUSED)
114{
115 if (animator) ecore_animator_del(animator);
116 ecore_main_loop_quit();
117}
118
119static void
120_canvas_resize_cb(Ecore_Evas *ee)
121{
122 int w, h;
123
124 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
125 evas_object_resize(d.bg, w, h);
126 evas_object_resize(d.vg, w, h);
127}
128
129static void
130reset_test()
131{
132 if(d.vg) evas_object_del(d.vg);
133 d.shape_list = eina_list_free(d.shape_list);
134
135 d.vg = evas_object_vg_add(d.evas);
136 evas_object_show(d.vg);
137 evas_object_focus_set(d.vg, 1);
138 _canvas_resize_cb(d.ee);
139}
140
141
142
143// 2. Basic shape Test Case START
144
145/* Applies a matrix transformation to a shape. If there is already a
146 * matrix transformation applied, the new tranformation is matrix
147 * multiplied with the existing one so both transformations are used.
148 */
149static void
150_added_transformation(Efl_VG *shape, Eina_Matrix3 *m)
151{
152 Eina_Matrix3 new_m;
153 const Eina_Matrix3 *old_m;
154
155 old_m = evas_vg_node_transformation_get(shape);
156 if (old_m)
157 {
158 eina_matrix3_compose(m, old_m, &new_m);
159 evas_vg_node_transformation_set(shape, &new_m);
160 }
161 else
162 {
163 evas_vg_node_transformation_set(shape, m);
164 }
165}
166
167/*
168 * Applies various modifications to the canvas objects as directed by
169 * the user.
170 */
171static void
172_basic_shape_key_handle(void *data EINA_UNUSED,
173 Evas *evas EINA_UNUSED,
174 Evas_Object *o EINA_UNUSED,
175 void *einfo)
176{
177 Evas_Event_Key_Down *ev = einfo;
178 Efl_VG *shape;
179 Eina_List *l;
180 Eina_Matrix3 m;
181 double stroke_w;
182
183 if (strcmp(ev->key, "h") == 0)
184 {
185 /* h - Print help */
186 puts(basic_shape_menu);
187 return;
188 }
189 if (strcmp(ev->key, "e") == 0)
190 {
191 /* e - Exit */
192 _on_delete(d.ee);
193 return;
194 }
195
196 if (strcmp(ev->key, "b") == 0)
197 {
198 /* b - Back to Main Menu */
199 _main_menu();
200 return;
201 }
202 if (strcmp(ev->key, "Up") == 0)
203 {
204 /* up - Increase Stroke Width by 0.5 */
205 EINA_LIST_FOREACH(d.shape_list, l, shape)
206 {
207 stroke_w = evas_vg_shape_stroke_width_get(shape);
208 evas_vg_shape_stroke_width_set(shape, stroke_w + 0.5);
209 }
210 return;
211 }
212 if (strcmp(ev->key, "Down") == 0)
213 {
214 /* down - Decrease Stroke Width by 0.5 */
215 EINA_LIST_FOREACH(d.shape_list, l, shape)
216 {
217 stroke_w = evas_vg_shape_stroke_width_get(shape);
218 if (stroke_w <= 0.5) stroke_w = 1;
219 evas_vg_shape_stroke_width_set(shape, stroke_w - 0.5);
220 }
221 return;
222 }
223 if (strcmp(ev->key, "r") == 0)
224 {
225 /* r - Rotate the shapes +10 degrees */
226 eina_matrix3_identity(&m);
227 eina_matrix3_rotate(&m, 10.0 * 2 * 3.141 / 360.0);
228 EINA_LIST_FOREACH(d.shape_list, l, shape)
229 {
230 _added_transformation(shape, &m);
231 }
232 return;
233 }
234 if (strcmp(ev->key, "R") == 0)
235 {
236 /* R - Rotate the shapes -10 degrees */
237 eina_matrix3_identity(&m);
238 eina_matrix3_rotate(&m, -10.0 * 2 * 3.141 / 360.0);
239 EINA_LIST_FOREACH(d.shape_list, l, shape)
240 {
241 _added_transformation(shape, &m);
242 }
243 return;
244 }
245 if (strcmp(ev->key, "s") == 0)
246 {
247 /* s - Scale the shapes +(.1, .1) */
248 eina_matrix3_identity(&m);
249 eina_matrix3_scale(&m, 1.1, 1.1);
250 EINA_LIST_FOREACH(d.shape_list, l, shape)
251 {
252 _added_transformation(shape, &m);
253 }
254 return;
255 }
256 if (strcmp(ev->key, "S") == 0)
257 {
258 /* S - Scale the shapes -(.1, .1) */
259 eina_matrix3_identity(&m);
260 eina_matrix3_scale(&m, .9, .9);
261 EINA_LIST_FOREACH(d.shape_list, l, shape)
262 {
263 _added_transformation(shape, &m);
264 }
265 return;
266 }
267 if (strcmp(ev->key, "t") == 0)
268 {
269 /* t - Translate the shapes +(10,10) */
270 eina_matrix3_identity(&m);
271 eina_matrix3_translate(&m, 10, 10);
272 EINA_LIST_FOREACH(d.shape_list, l, shape)
273 {
274 _added_transformation(shape, &m);
275 }
276 return;
277 }
278 if (strcmp(ev->key, "T") == 0)
279 {
280 /* T - Translate the shapes +(10,10) */
281 eina_matrix3_identity(&m);
282 eina_matrix3_translate(&m, -10, -10);
283 EINA_LIST_FOREACH(d.shape_list, l, shape)
284 {
285 _added_transformation(shape, &m);
286 }
287 return;
288 }
289 if (strcmp(ev->key, "d") == 0)
290 {
291 /* d - Reset path data */
292 EINA_LIST_FOREACH(d.shape_list, l, shape)
293 {
294 evas_vg_shape_reset(shape);
295 }
296 return;
297 }
298}
299
300/* Create several different geometric objects - a line, rectangle,
301 * circle, and arc, each with distinct style and placement.
302 */
303static void
304_1_basic_shape_test()
305{
306 Efl_VG *container, *shape, *new_shape;
307
308 reset_test();
309 evas_object_event_callback_add(d.vg, EVAS_CALLBACK_KEY_DOWN, _basic_shape_key_handle, NULL);
310 puts(basic_shape_menu);
311
312 container = evas_vg_container_add(d.vg);
313
314 // Line
315 shape = evas_vg_shape_add(container);
316 evas_vg_shape_append_move_to(shape, 0, 0);
317 evas_vg_shape_append_line_to(shape, 100, 0);
318 evas_vg_shape_stroke_color_set(shape, 255, 0, 0, 255);
319 evas_vg_shape_stroke_width_set(shape, 5);
320 evas_vg_node_origin_set(shape, 50, 50);
321 evas_vg_shape_stroke_cap_set(shape, EFL_GFX_CAP_ROUND);
322 d.shape_list = eina_list_append(d.shape_list, shape);
323
324 new_shape = evas_vg_shape_add(container);
325 evas_vg_shape_dup(new_shape, shape);
326 evas_vg_shape_stroke_color_set(new_shape, 0, 100, 0, 100);
327 evas_vg_shape_append_line_to(new_shape, 100, 50);
328 evas_vg_node_origin_set(new_shape, 200, 50);
329 evas_vg_shape_stroke_cap_set(new_shape, EFL_GFX_CAP_SQUARE);
330 d.shape_list = eina_list_append(d.shape_list, new_shape);
331
332 new_shape = evas_vg_shape_add(container);
333 evas_vg_shape_dup(new_shape, shape);
334 evas_vg_shape_stroke_color_set(new_shape, 0, 0, 255, 255);
335 evas_vg_shape_append_line_to(new_shape, 50, 50);
336 evas_vg_node_origin_set(new_shape, 350, 50);
337 evas_vg_shape_stroke_cap_set(new_shape, EFL_GFX_CAP_ROUND);
338 evas_vg_shape_stroke_join_set(new_shape, EFL_GFX_JOIN_ROUND);
339 d.shape_list = eina_list_append(d.shape_list, new_shape);
340
341 // Rect
342 shape = evas_vg_shape_add(container);
343 evas_vg_shape_append_rect(shape, 0, 0, 100 , 100, 10, 10);
344 evas_vg_shape_stroke_color_set(shape, 255, 0, 0, 255);
345 evas_vg_shape_stroke_width_set(shape, 5);
346 evas_vg_node_origin_set(shape, 50, 150);
347 d.shape_list = eina_list_append(d.shape_list, shape);
348
349 new_shape = evas_vg_shape_add(container);
350 evas_vg_shape_dup(new_shape, shape);
351 evas_vg_shape_stroke_color_set(new_shape, 0, 0, 0, 0);
352 evas_vg_node_color_set(new_shape, 0, 0, 100, 100);
353 evas_vg_node_origin_set(new_shape, 200, 150);
354 d.shape_list = eina_list_append(d.shape_list, new_shape);
355
356 new_shape = evas_vg_shape_add(container);
357 evas_vg_shape_dup(new_shape, shape);
358 evas_vg_shape_stroke_color_set(new_shape, 100, 0, 0, 100);
359 evas_vg_node_color_set(new_shape, 0, 100, 100, 100);
360 evas_vg_node_origin_set(new_shape, 350, 150);
361 d.shape_list = eina_list_append(d.shape_list, new_shape);
362
363 // Circle
364 shape = evas_vg_shape_add(container);
365 evas_vg_shape_append_circle(shape, 50, 50, 50);
366 evas_vg_shape_stroke_color_set(shape, 255, 0, 0, 255);
367 evas_vg_shape_stroke_width_set(shape, 5);
368 evas_vg_node_origin_set(shape, 50, 300);
369 d.shape_list = eina_list_append(d.shape_list, shape);
370
371 new_shape = evas_vg_shape_add(container);
372 evas_vg_shape_dup(new_shape, shape);
373 evas_vg_shape_stroke_color_set(new_shape, 0, 0, 0, 0);
374 evas_vg_node_color_set(new_shape, 0, 0, 255, 255);
375 evas_vg_node_origin_set(new_shape, 200, 300);
376 d.shape_list = eina_list_append(d.shape_list, new_shape);
377
378 new_shape = evas_vg_shape_add(container);
379 evas_vg_shape_dup(new_shape, shape);
380 evas_vg_shape_stroke_color_set(new_shape, 150, 0, 0, 150);
381 evas_vg_node_color_set(new_shape, 0, 0, 200, 200);
382 evas_vg_node_origin_set(new_shape, 350, 300);
383 d.shape_list = eina_list_append(d.shape_list, new_shape);
384
385 // Arc
386 shape = evas_vg_shape_add(container);
387 evas_vg_shape_append_arc(shape, 0, 0, 100, 100, 45, -200);
388 evas_vg_shape_append_line_to(shape, 50, 50);
389 evas_vg_shape_stroke_cap_set(shape, EFL_GFX_CAP_ROUND);
390 evas_vg_shape_stroke_color_set(shape, 255, 0, 0, 255);
391 evas_vg_shape_stroke_width_set(shape, 5);
392 evas_vg_node_origin_set(shape, 50, 450);
393 d.shape_list = eina_list_append(d.shape_list, shape);
394
395 new_shape = evas_vg_shape_add(container);
396 evas_vg_shape_append_arc(new_shape, 0, 0, 100, 100, 90, 200);
397 evas_vg_shape_stroke_color_set(new_shape, 0, 0, 0, 0);
398 evas_vg_node_color_set(new_shape, 0, 0, 200, 200);
399 evas_vg_node_origin_set(new_shape, 200, 450);
400 d.shape_list = eina_list_append(d.shape_list, new_shape);
401
402 new_shape = evas_vg_shape_add(container);
403 evas_vg_shape_append_arc(new_shape, 0, 0, 100, 100, 90, 200);
404 evas_vg_shape_append_line_to(new_shape, 50, 50);
405 evas_vg_shape_stroke_color_set(new_shape, 0, 0, 0, 0);
406 evas_vg_node_color_set(new_shape, 0, 0, 200, 200);
407 evas_vg_node_origin_set(new_shape, 350, 450);
408 d.shape_list = eina_list_append(d.shape_list, new_shape);
409
410 evas_object_vg_root_node_set(d.vg, container);
411}
412
413// 2. Basic shape Test Case END
414
415// 2. Interpolation Test Case START
416
417static void
418_interpolation_key_handle(void *data EINA_UNUSED,
419 Evas *evas EINA_UNUSED,
420 Evas_Object *o EINA_UNUSED,
421 void *einfo)
422{
423 Evas_Event_Key_Down *ev = einfo;
424
425 if (strcmp(ev->key, "h") == 0)
426 {
427 /* h - Print help */
428 puts(basic_shape_menu);
429 return;
430 }
431 if (strcmp(ev->key, "e") == 0)
432 {
433 /* e - Exit */
434 _on_delete(d.ee);
435 return;
436 }
437
438 if (strcmp(ev->key, "b") == 0)
439 {
440 /* b - Back to main menu */
441 _main_menu();
442 return;
443 }
444}
445
446static int anim_index = 0;
447static Eina_Bool
448_interpolation_keyframe(void *data EINA_UNUSED, double pos)
449{
450 int next = (anim_index == 1) ? 0 : 1;
451
452 evas_vg_shape_reset(eina_list_nth(d.shape_list, 2));
453 evas_vg_shape_interpolate(eina_list_nth(d.shape_list, 2),
454 eina_list_nth(d.shape_list, anim_index),
455 eina_list_nth(d.shape_list, next),
456 ecore_animator_pos_map(pos, ECORE_POS_MAP_SINUSOIDAL, 0.0, 0.0));
457
458 if (pos == 1.0)
459 {
460 anim_index = (anim_index == 1) ? 0 : 1;
461 animator = ecore_animator_timeline_add(1, _interpolation_keyframe, NULL);
462 }
463 return EINA_TRUE;
464}
465
466static void
467_2_interpolation_test()
468{
469 anim_index = 0;
470
471 Efl_VG *shape;
472
473 reset_test();
474
475 evas_object_event_callback_add(d.vg, EVAS_CALLBACK_KEY_DOWN, _interpolation_key_handle, NULL);
476 animator = ecore_animator_timeline_add(1, _interpolation_keyframe, NULL);
477 puts(interpolation_menu);
478
479 shape = evas_vg_shape_add(d.vg);
480 evas_vg_shape_append_svg_path(shape, morph1[0]);
481 evas_vg_shape_stroke_color_set(shape, 255, 0, 0, 255);
482 evas_vg_shape_stroke_width_set(shape, 5);
483 evas_vg_node_origin_set(shape, 100, 100);
484 d.shape_list = eina_list_append(d.shape_list, shape);
485
486 shape = evas_vg_shape_add(d.vg);
487 evas_vg_shape_append_svg_path(shape, morph1[1]);
488 evas_vg_shape_stroke_color_set(shape, 0, 0, 255, 255);
489 evas_vg_shape_stroke_width_set(shape, 10);
490 evas_vg_node_origin_set(shape, 150, 150);
491 d.shape_list = eina_list_append(d.shape_list, shape);
492
493 shape = evas_vg_shape_add(d.vg);
494 evas_vg_node_origin_set(shape, 150, 150);
495 d.shape_list = eina_list_append(d.shape_list, shape);
496
497 evas_object_vg_root_node_set(d.vg, shape);
498}
499
500// 2. Interpolation Test Case END
501
502// Main Menu START
503
504static void
505_main_menu()
506{
507 Efl_VG *shape;
508 if (animator) ecore_animator_del(animator);
509 animator = NULL;
510 if(d.vg) evas_object_del(d.vg);
511 if(d.bg) evas_object_del(d.bg);
512 d.bg = evas_object_rectangle_add(d.evas);
513 evas_object_color_set(d.bg, 255, 255, 255, 255);
514 evas_object_focus_set(d.bg, 1);
515 evas_object_show(d.bg);
516 evas_object_event_callback_add(d.bg, EVAS_CALLBACK_KEY_DOWN, _main_menu_key_handle, NULL);
517
518 // create the initial screen
519 d.vg = evas_object_vg_add(d.evas);
520 evas_object_show(d.vg);
521
522 shape = evas_vg_shape_add(d.vg);
523 evas_vg_shape_append_svg_path(shape, batman);
524 evas_vg_node_color_set(shape, 10, 0, 0, 10);
525 evas_vg_node_origin_set(shape, 0, 100);
526
527 evas_object_vg_root_node_set(d.vg, shape);
528
529 _canvas_resize_cb(d.ee);
530 puts(main_menu);
531}
532
533static void
534_main_menu_key_handle(void *data EINA_UNUSED,
535 Evas *evas EINA_UNUSED,
536 Evas_Object *o EINA_UNUSED,
537 void *einfo)
538{
539 Evas_Event_Key_Down *ev = einfo;
540
541 if (strcmp(ev->key, "h") == 0)
542 {
543 /* h - Help menu */
544 puts(main_menu);
545 return;
546 }
547 if (strcmp(ev->key, "e") == 0)
548 {
549 /* e - Exit */
550 _on_delete(d.ee);
551 return;
552 }
553 if (strcmp(ev->key, "1") == 0)
554 {
555 /* 1 - Basic Shape test */
556 _1_basic_shape_test();
557 return;
558 }
559 if (strcmp(ev->key, "2") == 0)
560 {
561 /* 2 - Interpolation */
562 _2_interpolation_test();
563 return;
564 }
565}
566
567// Main Menu END
568
569int
570main(void)
571{
572 if (!ecore_evas_init())
573 return EXIT_FAILURE;
574
575 d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
576 if (!d.ee)
577 goto error;
578
579 ecore_evas_callback_delete_request_set(d.ee, _on_delete);
580 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
581 ecore_evas_show(d.ee);
582
583 d.evas = ecore_evas_get(d.ee);
584
585 _main_menu();
586
587 ecore_main_loop_begin();
588 ecore_evas_shutdown();
589 return 0;
590
591error:
592 ecore_evas_shutdown();
593 return -1;
594}