summaryrefslogtreecommitdiff
path: root/src/examples/evas/evas-vg-json.c
diff options
context:
space:
mode:
authorHermet Park <hermetpark@gmail.com>2019-06-21 17:36:16 +0900
committerHermet Park <hermetpark@gmail.com>2019-06-21 17:36:17 +0900
commit431b5e817c5652d39560fc2a416f87b948cc8d64 (patch)
tree5026163b7d9bc2fd5a8dcd45e040e1de69ea349a /src/examples/evas/evas-vg-json.c
parent625e11f584fa00c6a2adc160ed20d96f3763d130 (diff)
evas vector: add a lottie animation example.
Summary: Depends on {D8941} Reviewers: #committers, jsuya Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8944
Diffstat (limited to 'src/examples/evas/evas-vg-json.c')
-rw-r--r--src/examples/evas/evas-vg-json.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/examples/evas/evas-vg-json.c b/src/examples/evas/evas-vg-json.c
new file mode 100644
index 0000000000..42047292ea
--- /dev/null
+++ b/src/examples/evas/evas-vg-json.c
@@ -0,0 +1,130 @@
1/**
2 * Example of lottie animation using Evas_VG.
3 *
4 * This example show how to play lottie files(json).
5 *
6 * @verbatim
7 * gcc -o evas_vg_json evas-vg-json.c `pkg-config --libs --cflags evas ecore ecore-evas eina ector eo efl`
8 * @endverbatim
9 */
10
11#ifdef HAVE_CONFIG_H
12#include "config.h"
13#endif
14
15#ifndef PACKAGE_EXAMPLES_DIR
16#define PACKAGE_EXAMPLES_DIR "."
17#endif
18
19#ifndef EFL_BETA_API_SUPPORT
20#define EFL_BETA_API_SUPPORT
21#endif
22
23#ifndef EFL_EO_API_SUPPORT
24#define EFL_EO_API_SUPPORT
25#endif
26
27
28#include <Ecore.h>
29#include <Ecore_Evas.h>
30#include "evas-common.h"
31
32#define WIDTH 400
33#define HEIGHT 400
34
35static Eo *gvg[4];
36
37static void
38running_cb(void *data EINA_UNUSED, const Efl_Event *event)
39{
40 Efl_Canvas_Animation_Player_Event_Running *event_running = event->info;
41 double progress = event_running->progress;
42
43 int i;
44 for (i = 0; i < 4; i++)
45 {
46 double frameCnt = (double) (efl_gfx_frame_controller_frame_count_get(gvg[i]) - 1);
47 int frame = (int) (frameCnt * progress);
48 efl_gfx_frame_controller_frame_set(gvg[i], frame);
49 }
50}
51
52static void
53_on_delete(Ecore_Evas *ee EINA_UNUSED)
54{
55 ecore_main_loop_quit();
56}
57
58int
59main(void)
60{
61 if (!ecore_evas_init())
62 return EXIT_FAILURE;
63
64 Ecore_Evas *ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
65 if (!ee)
66 goto panic;
67
68 ecore_evas_callback_delete_request_set(ee, _on_delete);
69 ecore_evas_show(ee);
70
71 Eo *evas = ecore_evas_get(ee);
72
73 Eo *bg = efl_add(EFL_CANVAS_RECTANGLE_CLASS, evas);
74 efl_gfx_entity_size_set(bg, EINA_SIZE2D(WIDTH, HEIGHT));
75 efl_gfx_color_set(bg, 255, 255, 255, 255);
76 efl_gfx_entity_visible_set(bg, EINA_TRUE);
77
78 char buf[PATH_MAX];
79
80 //1
81 Eo *vg = gvg[0] = efl_add(EFL_CANVAS_VG_OBJECT_CLASS, evas);
82
83 snprintf(buf, sizeof(buf), "%s/browser.json", PACKAGE_EXAMPLES_DIR EVAS_VG_FOLDER);
84 efl_file_simple_load(vg, buf, NULL);
85 efl_gfx_entity_size_set(vg, EINA_SIZE2D(200, 200));
86 efl_gfx_entity_visible_set(vg, EINA_TRUE);
87
88 //2
89 Eo *vg2 = gvg[1] = efl_add(EFL_CANVAS_VG_OBJECT_CLASS, evas);
90 snprintf(buf, sizeof(buf), "%s/jolly_walker.json", PACKAGE_EXAMPLES_DIR EVAS_VG_FOLDER);
91 efl_file_simple_load(vg2, buf, NULL);
92 efl_gfx_entity_position_set(vg2, EINA_POSITION2D(200, 200));
93 efl_gfx_entity_size_set(vg2, EINA_SIZE2D(200, 200));
94 efl_gfx_entity_visible_set(vg2, EINA_TRUE);
95
96 //3
97 Eo *vg3 = gvg[2] = efl_add(EFL_CANVAS_VG_OBJECT_CLASS, evas);
98 snprintf(buf, sizeof(buf), "%s/windmill.json", PACKAGE_EXAMPLES_DIR EVAS_VG_FOLDER);
99 efl_file_simple_load(vg3, buf, NULL);
100 efl_gfx_entity_position_set(vg3, EINA_POSITION2D(0, 200));
101 efl_gfx_entity_size_set(vg3, EINA_SIZE2D(200, 200));
102 efl_gfx_entity_visible_set(vg3, EINA_TRUE);
103
104 //4
105 Eo* vg4 = gvg[3] = efl_add(EFL_CANVAS_VG_OBJECT_CLASS, evas);
106 snprintf(buf, sizeof(buf), "%s/emoji_wink.json", PACKAGE_EXAMPLES_DIR EVAS_VG_FOLDER);
107 efl_file_simple_load(vg4, buf, NULL);
108 efl_gfx_entity_position_set(vg4, EINA_POSITION2D(200, 0));
109 efl_gfx_entity_size_set(vg4, EINA_SIZE2D(200, 200));
110 efl_gfx_entity_visible_set(vg4, EINA_TRUE);
111
112 //Play custom animation
113 Eo *anim = efl_add(EFL_CANVAS_ANIMATION_CLASS, evas);
114 efl_animation_duration_set(anim, efl_gfx_frame_controller_frame_duration_get(vg, 0, 0));
115
116 Eo *player = efl_add(EFL_CANVAS_ANIMATION_PLAYER_CLASS, evas);
117 efl_animation_player_animation_set(player, anim);
118 efl_event_callback_add(player, EFL_ANIMATION_PLAYER_EVENT_RUNNING, running_cb, NULL);
119 efl_player_start(player);
120
121 ecore_main_loop_begin();
122 ecore_evas_shutdown();
123
124 return 0;
125
126panic:
127 fprintf(stderr, "error: Requires at least one Evas engine built and linked"
128 " to ecore-evas for this example to run properly.\n");
129 return -2;
130}