1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4 #include <Elementary.h>
5 #include <Efl_Ui.h>
6
7 #ifndef EFL_BETA_API_SUPPORT
8 #define EFL_BETA_API_SUPPORT
9 #endif
10
11 #ifndef EFL_EO_API_SUPPORT
12 #define EFL_EO_API_SUPPORT
13 #endif
14
15 #ifdef BUILD_VG_LOADER_JSON
16
17 typedef struct _App_Data
18 {
19 Eo *label;
20 Eo *slider;
21 } App_Data;
22
23 static void
btn_clicked_cb(void * data,const Efl_Event * ev)24 btn_clicked_cb(void *data , const Efl_Event *ev )
25 {
26 Evas_Object *anim_view = data;
27 const char *text = efl_text_get(ev->object);
28
29 if (!text) return;
30
31 if (!strcmp("Play", text))
32 {
33 double speed = efl_player_playback_speed_get(anim_view);
34 efl_player_playback_speed_set(anim_view, speed < 0 ? speed * -1 : speed);
35 efl_player_playing_set(anim_view, EINA_TRUE);
36 }
37 else if (!strcmp("Pause", text))
38 efl_player_paused_set(anim_view, EINA_TRUE);
39 else if (!strcmp("Resume", text))
40 efl_player_paused_set(anim_view, EINA_FALSE);
41 else if (!strcmp("Play Backwards", text))
42 {
43 double speed = efl_player_playback_speed_get(anim_view);
44 efl_player_playback_speed_set(anim_view, speed > 0 ? speed * -1 : speed);
45 efl_player_playing_set(anim_view, EINA_TRUE);
46 }
47 else if (!strcmp("Stop", text))
48 efl_player_playing_set(anim_view, EINA_FALSE);
49 }
50
51 static void
check_changed_cb(void * data,const Efl_Event * event)52 check_changed_cb(void *data, const Efl_Event *event)
53 {
54 Evas_Object *anim_view = data;
55 efl_player_playback_loop_set(anim_view, efl_ui_selectable_selected_get(event->object));
56 }
57
58 static void
speed_changed_cb(void * data,const Efl_Event * event)59 speed_changed_cb(void *data, const Efl_Event *event)
60 {
61 Evas_Object *anim_view = data;
62 double speed = 1;
63 if (efl_ui_selectable_selected_get(event->object)) speed = 0.25;
64 efl_player_playback_speed_set(anim_view, speed);
65 }
66
67 static void
limit_frame_cb(void * data,const Efl_Event * event)68 limit_frame_cb(void *data, const Efl_Event *event)
69 {
70 Evas_Object *anim_view = data;
71 int frame_count = efl_ui_vg_animation_frame_count_get(anim_view);
72 printf("Total Frame Count : %d\n", frame_count);
73 if (efl_ui_selectable_selected_get(event->object))
74 {
75 efl_ui_vg_animation_min_frame_set(anim_view, 5);
76 efl_ui_vg_animation_max_frame_set(anim_view, 10);
77 printf("Frames to show 5-10 only\n");
78 }
79 else
80 {
81 efl_ui_vg_animation_min_frame_set(anim_view, 0);
82 efl_ui_vg_animation_max_frame_set(anim_view, frame_count);
83 printf("Showing all frames now\n");
84 }
85 }
86
87 static void
_slider_changed_cb(void * data,const Efl_Event * ev)88 _slider_changed_cb(void *data, const Efl_Event *ev)
89 {
90 Evas_Object *anim_view = data;
91 efl_player_playback_progress_set(anim_view, efl_ui_range_value_get(ev->object));
92 }
93
94 static void
update_anim_view_state(Evas_Object * anim_view,Evas_Object * label)95 update_anim_view_state(Evas_Object *anim_view, Evas_Object *label)
96 {
97 Efl_Ui_Vg_Animation_State state = efl_ui_vg_animation_state_get(anim_view);
98
99 switch (state)
100 {
101 case EFL_UI_VG_ANIMATION_STATE_NOT_READY:
102 efl_text_set(label, "State = Not Ready");
103 break;
104 case EFL_UI_VG_ANIMATION_STATE_PLAYING:
105 efl_text_set(label, "State = Playing");
106 break;
107 case EFL_UI_VG_ANIMATION_STATE_PLAYING_BACKWARDS:
108 efl_text_set(label, "State = Playing Backwards");
109 break;
110 case EFL_UI_VG_ANIMATION_STATE_PAUSED:
111 efl_text_set(label, "State = Paused");
112 break;
113 case EFL_UI_VG_ANIMATION_STATE_STOPPED:
114 efl_text_set(label, "State = Stopped");
115 break;
116 }
117 }
118
119 static void
_animation_playing_changed_cb(void * data,const Efl_Event * event)120 _animation_playing_changed_cb(void *data, const Efl_Event *event)
121 {
122 Eina_Bool playing = *(Eina_Bool*)event->info;
123 App_Data *ad = data;
124 update_anim_view_state(event->object, ad->label);
125 //Stopped
126 if (!playing)
127 efl_ui_range_value_set(ad->slider, 0);
128 }
129
130 static void
_animation_paused_changed_cb(void * data,const Efl_Event * event)131 _animation_paused_changed_cb(void *data, const Efl_Event *event)
132 {
133 App_Data *ad = data;
134 update_anim_view_state(event->object, ad->label);
135 }
136
137 static void
_animation_playback_progress_changed_cb(void * data,const Efl_Event * event)138 _animation_playback_progress_changed_cb(void *data, const Efl_Event *event)
139 {
140 double progress = *(double*)event->info;
141 App_Data *ad = data;
142 efl_ui_range_value_set(ad->slider, progress);
143 }
144
145 static void
_animation_playback_repeated_changed_cb(void * data EINA_UNUSED,const Efl_Event * event)146 _animation_playback_repeated_changed_cb(void *data EINA_UNUSED, const Efl_Event *event)
147 {
148 int repeated_times = *(int*)event->info;
149 printf("repeated! (times: %d)\n", repeated_times);
150 }
151
152 static void
_animation_playback_finished_changed_cb(void * data EINA_UNUSED,const Efl_Event * event EINA_UNUSED)153 _animation_playback_finished_changed_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
154 {
155 printf("done!\n");
156 }
157
158 EFL_CALLBACKS_ARRAY_DEFINE(animation_stats_cb,
159 {EFL_PLAYER_EVENT_PLAYING_CHANGED, _animation_playing_changed_cb },
160 {EFL_PLAYER_EVENT_PAUSED_CHANGED, _animation_paused_changed_cb },
161 {EFL_PLAYER_EVENT_PLAYBACK_PROGRESS_CHANGED, _animation_playback_progress_changed_cb },
162 {EFL_PLAYER_EVENT_PLAYBACK_REPEATED, _animation_playback_repeated_changed_cb },
163 {EFL_PLAYER_EVENT_PLAYBACK_FINISHED, _animation_playback_finished_changed_cb },
164 )
165
166 static void
_win_del_cb(void * data,const Efl_Event * ev EINA_UNUSED)167 _win_del_cb(void *data, const Efl_Event *ev EINA_UNUSED)
168 {
169 App_Data *ad = data;
170 free(ad);
171 }
172
173 void
test_efl_ui_vg_animation(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)174 test_efl_ui_vg_animation(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
175 {
176 Eo *win, *box, *box2, *box3, *box4, *label, *anim_view, *check, *slider;
177 char buf[255];
178 App_Data *ad = calloc(1, sizeof(App_Data));
179 if (!ad) return;
180
181 win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
182 efl_text_set(efl_added, "Efl_Ui_Vg_Animation demo"),
183 efl_ui_win_autodel_set(efl_added, EINA_TRUE),
184 efl_event_callback_add(efl_added, EFL_EVENT_DEL, _win_del_cb, ad));
185
186 // Create a box in Canvas
187 box = efl_add(EFL_UI_BOX_CLASS, win,
188 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, EFL_GFX_HINT_EXPAND),
189 efl_content_set(win, efl_added));
190
191 //Create a label to show state of animation
192 label = efl_add(EFL_UI_TEXTBOX_CLASS, win,
193 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0.1),
194 efl_gfx_hint_fill_set(efl_added, EINA_FALSE, EINA_FALSE),
195 efl_pack(box, efl_added));
196
197 //Create Animation View to play animation directly from JSON file
198 snprintf(buf, sizeof(buf), "%s/images/emoji_wink.json", elm_app_data_dir_get());
199 anim_view = efl_add(EFL_UI_VG_ANIMATION_CLASS, win,
200 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, EFL_GFX_HINT_EXPAND),
201 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, EVAS_HINT_FILL),
202 efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(600, 600)),
203 efl_file_set(efl_added, buf),
204 efl_pack(box, efl_added));
205
206 // Controller Set : 0
207 box2 = efl_add(EFL_UI_BOX_CLASS, box,
208 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0.1),
209 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL),
210 efl_pack(box, efl_added));
211
212 //Loop
213 check = efl_add(EFL_UI_CHECK_CLASS, box2,
214 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0),
215 efl_gfx_hint_fill_set(efl_added, EINA_FALSE, EINA_FALSE),
216 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, EVAS_HINT_FILL),
217 efl_pack(box2, efl_added));
218 efl_text_set(check, "Loop");
219 efl_event_callback_add(check, EFL_UI_EVENT_SELECTED_CHANGED, check_changed_cb, anim_view);
220
221 //Speed: 0.5x
222 check = efl_add(EFL_UI_CHECK_CLASS, box2,
223 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0),
224 efl_gfx_hint_fill_set(efl_added, EINA_FALSE, EINA_FALSE),
225 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, EVAS_HINT_FILL),
226 efl_pack(box2, efl_added));
227 efl_text_set(check, "Speed: 0.25x");
228 efl_event_callback_add(check, EFL_UI_EVENT_SELECTED_CHANGED, speed_changed_cb, anim_view);
229
230 //Limit Frames
231 check = efl_add(EFL_UI_CHECK_CLASS, box2,
232 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0),
233 efl_gfx_hint_fill_set(efl_added, EINA_FALSE, EINA_FALSE),
234 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, EVAS_HINT_FILL),
235 efl_pack(box2, efl_added));
236 efl_text_set(check, "Limit Frames");
237 efl_event_callback_add(check, EFL_UI_EVENT_SELECTED_CHANGED, limit_frame_cb, anim_view);
238
239
240 //Duration Text
241 snprintf(buf, sizeof(buf), "Duration(Length): %1.2fs", efl_playable_length_get(anim_view));
242 efl_add(EFL_UI_TEXTBOX_CLASS, box2,
243 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0),
244 efl_gfx_hint_fill_set(efl_added, EINA_FALSE, EINA_FALSE),
245 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, EVAS_HINT_FILL),
246 efl_text_set(efl_added, buf),
247 efl_pack(box2, efl_added));
248
249 //Slider
250 slider = efl_add(EFL_UI_SLIDER_CLASS, box,
251 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0.1),
252 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, EVAS_HINT_FILL),
253 efl_ui_range_limits_set(efl_added, 0, 1),
254 efl_event_callback_add(efl_added, EFL_UI_RANGE_EVENT_CHANGED, _slider_changed_cb, anim_view),
255 efl_pack(box, efl_added));
256
257 //Controller Set: 1
258 box3 = efl_add(EFL_UI_BOX_CLASS, box,
259 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0),
260 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, 1),
261 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL),
262 efl_pack(box, efl_added));
263
264 //Play Button
265 efl_add(EFL_UI_BUTTON_CLASS, box3,
266 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0),
267 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, EVAS_HINT_FILL),
268 efl_text_set(efl_added, "Play"),
269 efl_pack(box3, efl_added),
270 efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED, btn_clicked_cb, anim_view));
271
272
273 //Play Back Button
274 efl_add(EFL_UI_BUTTON_CLASS, box3,
275 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0),
276 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, EVAS_HINT_FILL),
277 efl_text_set(efl_added, "Play Backwards"),
278 efl_pack(box3, efl_added),
279 efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED, btn_clicked_cb, anim_view));
280
281 //Stop Button
282 efl_add(EFL_UI_BUTTON_CLASS, box3,
283 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0),
284 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, EVAS_HINT_FILL),
285 efl_text_set(efl_added, "Stop"),
286 efl_pack(box3, efl_added),
287 efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED, btn_clicked_cb, anim_view));
288
289 //Controller Set: 2
290 box4 = efl_add(EFL_UI_BOX_CLASS, box,
291 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0),
292 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, 1),
293 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL),
294 efl_pack(box, efl_added));
295
296 //Pause Button
297 efl_add(EFL_UI_BUTTON_CLASS, box3,
298 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0),
299 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, EVAS_HINT_FILL),
300 efl_text_set(efl_added, "Pause"),
301 efl_pack(box4, efl_added),
302 efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED, btn_clicked_cb, anim_view));
303
304 //Resume Button
305 efl_add(EFL_UI_BUTTON_CLASS, box3,
306 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0),
307 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, EVAS_HINT_FILL),
308 efl_text_set(efl_added, "Resume"),
309 efl_pack(box4, efl_added),
310 efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED, btn_clicked_cb, anim_view));
311
312 efl_event_callback_array_add(anim_view, animation_stats_cb(), ad);
313
314 update_anim_view_state(anim_view, label);
315
316 ad->label = label;
317 ad->slider = slider;
318
319 efl_gfx_entity_size_set(win, EINA_SIZE2D(600, 730));
320 }
321
322 #else
323
324 void
test_efl_ui_vg_animation(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)325 test_efl_ui_vg_animation(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
326 {
327 Eo *win, *box;
328 char buf[255];
329
330 win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
331 efl_text_set(efl_added, "Efl_Ui_Vg_Animation demo"),
332 efl_ui_win_autodel_set(efl_added, EINA_TRUE));
333
334 // Create a box
335 box = efl_add(EFL_UI_BOX_CLASS, win,
336 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, EFL_GFX_HINT_EXPAND),
337 efl_content_set(win, efl_added));
338
339 efl_add(EFL_UI_TEXTBOX_CLASS, win,
340 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, 0.1),
341 efl_gfx_hint_fill_set(efl_added, EINA_FALSE, EINA_FALSE),
342 efl_text_set(efl_added, "Evas Vg Json (Lottie) Loader is not supported, Only Static Vector Image is available!"),
343 efl_pack(box, efl_added));
344
345 //Create Vector object.
346 snprintf(buf, sizeof(buf), "%s/images/tiger.svg", elm_app_data_dir_get());
347 efl_add(EFL_CANVAS_VG_OBJECT_CLASS, win,
348 efl_gfx_hint_weight_set(efl_added, EFL_GFX_HINT_EXPAND, EFL_GFX_HINT_EXPAND),
349 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, EVAS_HINT_FILL),
350 efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(600, 600)),
351 efl_file_simple_load(efl_added, buf, NULL),
352 efl_gfx_entity_visible_set(efl_added, EINA_TRUE),
353 efl_pack(box, efl_added));
354
355 efl_gfx_entity_size_set(win, EINA_SIZE2D(600, 730));
356 }
357
358 #endif
359