summaryrefslogtreecommitdiff
path: root/unsorted/evas/evas-vg-simple.c
diff options
context:
space:
mode:
authorBryce Harrington <bryce@osg.samsung.com>2017-09-18 10:40:46 -0700
committerCedric BAIL <cedric@osg.samsung.com>2017-09-18 11:18:43 -0700
commit8e1f446efc60a2e775972955a797626d543d2959 (patch)
tree5156675d8ebe52e2048033f2021d618c11c42caa /unsorted/evas/evas-vg-simple.c
parent25cd37fdca300b20c32109d4263a9ed618d2434f (diff)
examples: document the evas-vg-simple example
Summary: Fill in the intro section and the first test mode. (Docs for second mode will be forthcoming.) Also drop some of the generic comments that are already explained better in some of the basic examples. Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> Reviewers: cedric Subscribers: jpeg Differential Revision: https://phab.enlightenment.org/D5201 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'unsorted/evas/evas-vg-simple.c')
-rw-r--r--unsorted/evas/evas-vg-simple.c103
1 files changed, 76 insertions, 27 deletions
diff --git a/unsorted/evas/evas-vg-simple.c b/unsorted/evas/evas-vg-simple.c
index 8783f24..3414970 100644
--- a/unsorted/evas/evas-vg-simple.c
+++ b/unsorted/evas/evas-vg-simple.c
@@ -1,8 +1,29 @@
1/** 1/**
2 * Example of basic nodes in Evas_VG. 2 * Example of Evas' vector graphics object and API.
3 * 3 *
4 * You'll need at least one engine built for it (excluding the buffer 4 * Vector graphics describe an image with distinct shapes - lines,
5 * one). See stdout/stderr for output. 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.
6 * 27 *
7 * @verbatim 28 * @verbatim
8 * gcc -o evas_vg_simple evas-vg-simple.c `pkg-config --libs --cflags evas ecore ecore-evas eina ector eo efl` -lm 29 * gcc -o evas_vg_simple evas-vg-simple.c `pkg-config --libs --cflags evas ecore ecore-evas eina ector eo efl` -lm
@@ -45,8 +66,15 @@ struct example_data
45 66
46static struct example_data d; 67static struct example_data d;
47Ecore_Animator *animator; 68Ecore_Animator *animator;
48static 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";
49 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";
50static 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", 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",
51 "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"}; 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"};
52 80
@@ -55,10 +83,10 @@ static void _main_menu_key_handle(void *data, Evas *evas, Evas_Object *o, void *
55 83
56static const char *main_menu = \ 84static const char *main_menu = \
57 "Main Menu:\n" 85 "Main Menu:\n"
58 "\t1 - Basic Shape test\n" 86 "\t1 - Basic Shape test\n"
59 "\t2 - Interpolation\n" 87 "\t2 - Interpolation\n"
60 "\te - Exit\n" 88 "\te - Exit\n"
61 "\th - print help\n"; 89 "\th - Print help\n";
62 90
63static const char *basic_shape_menu = \ 91static const char *basic_shape_menu = \
64 "Basic Shape Menu:\n" 92 "Basic Shape Menu:\n"
@@ -73,7 +101,7 @@ static const char *basic_shape_menu = \
73 "\td - Reset path data\n" 101 "\td - Reset path data\n"
74 "\te - Exit\n" 102 "\te - Exit\n"
75 "\tb - Back to Main Menu\n" 103 "\tb - Back to Main Menu\n"
76 "\th - print help\n"; 104 "\th - Print help\n";
77 105
78static const char *interpolation_menu = \ 106static const char *interpolation_menu = \
79 "Interpolation Menu:\n" 107 "Interpolation Menu:\n"
@@ -88,7 +116,7 @@ _on_delete(Ecore_Evas *ee EINA_UNUSED)
88 ecore_main_loop_quit(); 116 ecore_main_loop_quit();
89} 117}
90 118
91static void /* adjust canvas' contents on resizes */ 119static void
92_canvas_resize_cb(Ecore_Evas *ee) 120_canvas_resize_cb(Ecore_Evas *ee)
93{ 121{
94 int w, h; 122 int w, h;
@@ -104,7 +132,6 @@ reset_test()
104 if(d.vg) evas_object_del(d.vg); 132 if(d.vg) evas_object_del(d.vg);
105 d.shape_list = eina_list_free(d.shape_list); 133 d.shape_list = eina_list_free(d.shape_list);
106 134
107
108 d.vg = evas_object_vg_add(d.evas); 135 d.vg = evas_object_vg_add(d.evas);
109 evas_object_show(d.vg); 136 evas_object_show(d.vg);
110 evas_object_focus_set(d.vg, 1); 137 evas_object_focus_set(d.vg, 1);
@@ -113,8 +140,12 @@ reset_test()
113 140
114 141
115 142
116// 2.Basic shape Test Case START 143// 2. Basic shape Test Case START
117 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 */
118static void 149static void
119_added_transformation(Efl_VG *shape, Eina_Matrix3 *m) 150_added_transformation(Efl_VG *shape, Eina_Matrix3 *m)
120{ 151{
@@ -133,6 +164,10 @@ _added_transformation(Efl_VG *shape, Eina_Matrix3 *m)
133 } 164 }
134} 165}
135 166
167/*
168 * Applies various modifications to the canvas objects as directed by
169 * the user.
170 */
136static void 171static void
137_basic_shape_key_handle(void *data EINA_UNUSED, 172_basic_shape_key_handle(void *data EINA_UNUSED,
138 Evas *evas EINA_UNUSED, 173 Evas *evas EINA_UNUSED,
@@ -145,25 +180,28 @@ _basic_shape_key_handle(void *data EINA_UNUSED,
145 Eina_Matrix3 m; 180 Eina_Matrix3 m;
146 double stroke_w; 181 double stroke_w;
147 182
148 if (strcmp(ev->key, "h") == 0) /* print help */ 183 if (strcmp(ev->key, "h") == 0)
149 { 184 {
185 /* h - Print help */
150 puts(basic_shape_menu); 186 puts(basic_shape_menu);
151 return; 187 return;
152 } 188 }
153 if (strcmp(ev->key, "e") == 0) 189 if (strcmp(ev->key, "e") == 0)
154 { 190 {
191 /* e - Exit */
155 _on_delete(d.ee); 192 _on_delete(d.ee);
156 return; 193 return;
157 } 194 }
158 195
159 if (strcmp(ev->key, "b") == 0) 196 if (strcmp(ev->key, "b") == 0)
160 { 197 {
198 /* b - Back to Main Menu */
161 _main_menu(); 199 _main_menu();
162 return; 200 return;
163 } 201 }
164 if (strcmp(ev->key, "Up") == 0) 202 if (strcmp(ev->key, "Up") == 0)
165 { 203 {
166 204 /* up - Increase Stroke Width by 0.5 */
167 EINA_LIST_FOREACH(d.shape_list, l, shape) 205 EINA_LIST_FOREACH(d.shape_list, l, shape)
168 { 206 {
169 stroke_w = evas_vg_shape_stroke_width_get(shape); 207 stroke_w = evas_vg_shape_stroke_width_get(shape);
@@ -173,6 +211,7 @@ _basic_shape_key_handle(void *data EINA_UNUSED,
173 } 211 }
174 if (strcmp(ev->key, "Down") == 0) 212 if (strcmp(ev->key, "Down") == 0)
175 { 213 {
214 /* down - Decrease Stroke Width by 0.5 */
176 EINA_LIST_FOREACH(d.shape_list, l, shape) 215 EINA_LIST_FOREACH(d.shape_list, l, shape)
177 { 216 {
178 stroke_w = evas_vg_shape_stroke_width_get(shape); 217 stroke_w = evas_vg_shape_stroke_width_get(shape);
@@ -183,6 +222,7 @@ _basic_shape_key_handle(void *data EINA_UNUSED,
183 } 222 }
184 if (strcmp(ev->key, "r") == 0) 223 if (strcmp(ev->key, "r") == 0)
185 { 224 {
225 /* r - Rotate the shapes +10 degrees */
186 eina_matrix3_identity(&m); 226 eina_matrix3_identity(&m);
187 eina_matrix3_rotate(&m, 10.0 * 2 * 3.141 / 360.0); 227 eina_matrix3_rotate(&m, 10.0 * 2 * 3.141 / 360.0);
188 EINA_LIST_FOREACH(d.shape_list, l, shape) 228 EINA_LIST_FOREACH(d.shape_list, l, shape)
@@ -193,6 +233,7 @@ _basic_shape_key_handle(void *data EINA_UNUSED,
193 } 233 }
194 if (strcmp(ev->key, "R") == 0) 234 if (strcmp(ev->key, "R") == 0)
195 { 235 {
236 /* R - Rotate the shapes -10 degrees */
196 eina_matrix3_identity(&m); 237 eina_matrix3_identity(&m);
197 eina_matrix3_rotate(&m, -10.0 * 2 * 3.141 / 360.0); 238 eina_matrix3_rotate(&m, -10.0 * 2 * 3.141 / 360.0);
198 EINA_LIST_FOREACH(d.shape_list, l, shape) 239 EINA_LIST_FOREACH(d.shape_list, l, shape)
@@ -203,6 +244,7 @@ _basic_shape_key_handle(void *data EINA_UNUSED,
203 } 244 }
204 if (strcmp(ev->key, "s") == 0) 245 if (strcmp(ev->key, "s") == 0)
205 { 246 {
247 /* s - Scale the shapes +(.1, .1) */
206 eina_matrix3_identity(&m); 248 eina_matrix3_identity(&m);
207 eina_matrix3_scale(&m, 1.1, 1.1); 249 eina_matrix3_scale(&m, 1.1, 1.1);
208 EINA_LIST_FOREACH(d.shape_list, l, shape) 250 EINA_LIST_FOREACH(d.shape_list, l, shape)
@@ -213,6 +255,7 @@ _basic_shape_key_handle(void *data EINA_UNUSED,
213 } 255 }
214 if (strcmp(ev->key, "S") == 0) 256 if (strcmp(ev->key, "S") == 0)
215 { 257 {
258 /* S - Scale the shapes -(.1, .1) */
216 eina_matrix3_identity(&m); 259 eina_matrix3_identity(&m);
217 eina_matrix3_scale(&m, .9, .9); 260 eina_matrix3_scale(&m, .9, .9);
218 EINA_LIST_FOREACH(d.shape_list, l, shape) 261 EINA_LIST_FOREACH(d.shape_list, l, shape)
@@ -223,6 +266,7 @@ _basic_shape_key_handle(void *data EINA_UNUSED,
223 } 266 }
224 if (strcmp(ev->key, "t") == 0) 267 if (strcmp(ev->key, "t") == 0)
225 { 268 {
269 /* t - Translate the shapes +(10,10) */
226 eina_matrix3_identity(&m); 270 eina_matrix3_identity(&m);
227 eina_matrix3_translate(&m, 10, 10); 271 eina_matrix3_translate(&m, 10, 10);
228 EINA_LIST_FOREACH(d.shape_list, l, shape) 272 EINA_LIST_FOREACH(d.shape_list, l, shape)
@@ -233,6 +277,7 @@ _basic_shape_key_handle(void *data EINA_UNUSED,
233 } 277 }
234 if (strcmp(ev->key, "T") == 0) 278 if (strcmp(ev->key, "T") == 0)
235 { 279 {
280 /* T - Translate the shapes +(10,10) */
236 eina_matrix3_identity(&m); 281 eina_matrix3_identity(&m);
237 eina_matrix3_translate(&m, -10, -10); 282 eina_matrix3_translate(&m, -10, -10);
238 EINA_LIST_FOREACH(d.shape_list, l, shape) 283 EINA_LIST_FOREACH(d.shape_list, l, shape)
@@ -243,6 +288,7 @@ _basic_shape_key_handle(void *data EINA_UNUSED,
243 } 288 }
244 if (strcmp(ev->key, "d") == 0) 289 if (strcmp(ev->key, "d") == 0)
245 { 290 {
291 /* d - Reset path data */
246 EINA_LIST_FOREACH(d.shape_list, l, shape) 292 EINA_LIST_FOREACH(d.shape_list, l, shape)
247 { 293 {
248 evas_vg_shape_reset(shape); 294 evas_vg_shape_reset(shape);
@@ -251,6 +297,9 @@ _basic_shape_key_handle(void *data EINA_UNUSED,
251 } 297 }
252} 298}
253 299
300/* Create several different geometric objects - a line, rectangle,
301 * circle, and arc, each with distinct style and placement.
302 */
254static void 303static void
255_1_basic_shape_test() 304_1_basic_shape_test()
256{ 305{
@@ -280,7 +329,6 @@ _1_basic_shape_test()
280 evas_vg_shape_stroke_cap_set(new_shape, EFL_GFX_CAP_SQUARE); 329 evas_vg_shape_stroke_cap_set(new_shape, EFL_GFX_CAP_SQUARE);
281 d.shape_list = eina_list_append(d.shape_list, new_shape); 330 d.shape_list = eina_list_append(d.shape_list, new_shape);
282 331
283
284 new_shape = evas_vg_shape_add(container); 332 new_shape = evas_vg_shape_add(container);
285 evas_vg_shape_dup(new_shape, shape); 333 evas_vg_shape_dup(new_shape, shape);
286 evas_vg_shape_stroke_color_set(new_shape, 0, 0, 255, 255); 334 evas_vg_shape_stroke_color_set(new_shape, 0, 0, 255, 255);
@@ -358,12 +406,11 @@ _1_basic_shape_test()
358 evas_vg_node_color_set(new_shape, 0, 0, 200, 200); 406 evas_vg_node_color_set(new_shape, 0, 0, 200, 200);
359 evas_vg_node_origin_set(new_shape, 350, 450); 407 evas_vg_node_origin_set(new_shape, 350, 450);
360 d.shape_list = eina_list_append(d.shape_list, new_shape); 408 d.shape_list = eina_list_append(d.shape_list, new_shape);
361
362} 409}
363 410
364// 2.Basic shape Test Case END 411// 2. Basic shape Test Case END
365 412
366// 2.Interpolation Test Case START 413// 2. Interpolation Test Case START
367 414
368static void 415static void
369_interpolation_key_handle(void *data EINA_UNUSED, 416_interpolation_key_handle(void *data EINA_UNUSED,
@@ -373,19 +420,22 @@ _interpolation_key_handle(void *data EINA_UNUSED,
373{ 420{
374 Evas_Event_Key_Down *ev = einfo; 421 Evas_Event_Key_Down *ev = einfo;
375 422
376 if (strcmp(ev->key, "h") == 0) /* print help */ 423 if (strcmp(ev->key, "h") == 0)
377 { 424 {
425 /* h - Print help */
378 puts(basic_shape_menu); 426 puts(basic_shape_menu);
379 return; 427 return;
380 } 428 }
381 if (strcmp(ev->key, "e") == 0) /* exit */ 429 if (strcmp(ev->key, "e") == 0)
382 { 430 {
431 /* e - Exit */
383 _on_delete(d.ee); 432 _on_delete(d.ee);
384 return; 433 return;
385 } 434 }
386 435
387 if (strcmp(ev->key, "b") == 0) /* back to main menu */ 436 if (strcmp(ev->key, "b") == 0)
388 { 437 {
438 /* b - Back to main menu */
389 _main_menu(); 439 _main_menu();
390 return; 440 return;
391 } 441 }
@@ -440,11 +490,9 @@ _2_interpolation_test()
440 shape = evas_vg_shape_add(evas_object_vg_root_node_get(d.vg)); 490 shape = evas_vg_shape_add(evas_object_vg_root_node_get(d.vg));
441 evas_vg_node_origin_set(shape, 150, 150); 491 evas_vg_node_origin_set(shape, 150, 150);
442 d.shape_list = eina_list_append(d.shape_list, shape); 492 d.shape_list = eina_list_append(d.shape_list, shape);
443
444
445} 493}
446 494
447// 2.Interpolation Test Case END 495// 2. Interpolation Test Case END
448 496
449// Main Menu START 497// Main Menu START
450 498
@@ -484,22 +532,25 @@ _main_menu_key_handle(void *data EINA_UNUSED,
484 532
485 if (strcmp(ev->key, "h") == 0) 533 if (strcmp(ev->key, "h") == 0)
486 { 534 {
535 /* h - Help menu */
487 puts(main_menu); 536 puts(main_menu);
488 return; 537 return;
489 } 538 }
490 if (strcmp(ev->key, "e") == 0) 539 if (strcmp(ev->key, "e") == 0)
491 { 540 {
541 /* e - Exit */
492 _on_delete(d.ee); 542 _on_delete(d.ee);
493 return; 543 return;
494 } 544 }
495
496 if (strcmp(ev->key, "1") == 0) 545 if (strcmp(ev->key, "1") == 0)
497 { 546 {
547 /* 1 - Basic Shape test */
498 _1_basic_shape_test(); 548 _1_basic_shape_test();
499 return; 549 return;
500 } 550 }
501 if (strcmp(ev->key, "2") == 0) 551 if (strcmp(ev->key, "2") == 0)
502 { 552 {
553 /* 2 - Interpolation */
503 _2_interpolation_test(); 554 _2_interpolation_test();
504 return; 555 return;
505 } 556 }
@@ -513,8 +564,6 @@ main(void)
513 if (!ecore_evas_init()) 564 if (!ecore_evas_init())
514 return EXIT_FAILURE; 565 return EXIT_FAILURE;
515 566
516 /* this will give you a window with an Evas canvas under the first
517 * engine available */
518 d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL); 567 d.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
519 if (!d.ee) 568 if (!d.ee)
520 goto error; 569 goto error;