summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/efl_canvas_animation_player.c
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-11-14 12:54:31 +0100
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-11-20 10:03:50 +0100
commitaef56b169e2588ee450e13b5f163c19bd65a330f (patch)
treeefcf0f3ced169b396b3a0554129ae79546f66198 /src/lib/evas/canvas/efl_canvas_animation_player.c
parent80e58dd79ad98267d2069a62661e6ae4db6bf11f (diff)
remove efl_canvas_animation_player
this now all migrated to Efl.Canvas.Object.Animation Reviewed-by: Cedric BAIL <cedric.bail@free.fr> Differential Revision: https://phab.enlightenment.org/D10667
Diffstat (limited to '')
-rw-r--r--src/lib/evas/canvas/efl_canvas_animation_player.c444
1 files changed, 0 insertions, 444 deletions
diff --git a/src/lib/evas/canvas/efl_canvas_animation_player.c b/src/lib/evas/canvas/efl_canvas_animation_player.c
deleted file mode 100644
index e8b57cb5b9..0000000000
--- a/src/lib/evas/canvas/efl_canvas_animation_player.c
+++ /dev/null
@@ -1,444 +0,0 @@
1#include "efl_canvas_animation_player_private.h"
2
3static void
4_target_del_cb(void *data, const Efl_Event *event EINA_UNUSED)
5{
6 Efl_Canvas_Animation_Player_Data *pd = data;
7 pd->target = NULL;
8}
9
10EOLIAN static void
11_efl_canvas_animation_player_target_set(Eo *eo_obj EINA_UNUSED,
12 Efl_Canvas_Animation_Player_Data *pd,
13 Efl_Canvas_Object *target)
14{
15 if (pd->target == target)
16 return;
17
18 if (pd->target)
19 efl_event_callback_del(pd->target, EFL_EVENT_DEL, _target_del_cb, pd);
20
21 efl_event_callback_add(target, EFL_EVENT_DEL, _target_del_cb, pd);
22
23 pd->target = target;
24}
25
26EOLIAN static Efl_Canvas_Object *
27_efl_canvas_animation_player_target_get(const Eo *eo_obj EINA_UNUSED, Efl_Canvas_Animation_Player_Data *pd)
28{
29 return pd->target;
30}
31
32EOLIAN static void
33_efl_canvas_animation_player_auto_del_set(Eo *eo_obj EINA_UNUSED,
34 Efl_Canvas_Animation_Player_Data *pd,
35 Eina_Bool auto_del)
36{
37 pd->auto_del = auto_del;
38}
39
40EOLIAN static Eina_Bool
41_efl_canvas_animation_player_auto_del_get(const Eo *eo_obj EINA_UNUSED,
42 Efl_Canvas_Animation_Player_Data *pd)
43{
44 return pd->auto_del;
45}
46
47EOLIAN static void
48_efl_canvas_animation_player_animation_set(Eo *eo_obj,
49 Efl_Canvas_Animation_Player_Data *pd,
50 Efl_Canvas_Animation *anim)
51{
52 if (anim == pd->animation)
53 return;
54
55 if (!efl_isa(anim, EFL_CANVAS_ANIMATION_CLASS))
56 {
57 ERR("Passed argument [%p]:[%s] is not an Efl.Animation",
58 anim, efl_class_name_get(efl_class_get(anim)));
59 return;
60 }
61
62 if (pd->animation)
63 {
64 efl_player_playing_set(eo_obj, EINA_FALSE);
65 efl_unref(pd->animation);
66 }
67 pd->animation = anim;
68 efl_ref(pd->animation);
69}
70
71EOLIAN static Efl_Canvas_Animation *
72_efl_canvas_animation_player_animation_get(const Eo *eo_obj EINA_UNUSED,
73 Efl_Canvas_Animation_Player_Data *pd)
74{
75 return pd->animation;
76}
77
78static Eina_Bool
79_animator_cb(void *data)
80{
81 Eo *eo_obj = data;
82 EFL_ANIMATION_PLAYER_DATA_GET(eo_obj, pd);
83 EFL_ANIMATION_PLAYER_ANIMATION_GET(eo_obj, anim);
84 double duration, elapsed_time, vector;
85
86 if (efl_playable_seekable_get(eo_obj))
87 {
88 pd->time.current = ecore_loop_time_get();
89
90 duration = efl_animation_duration_get(anim);
91 elapsed_time = pd->time.current - pd->time.prev;
92 vector = elapsed_time / duration;
93
94 /* When animation player starts, _animator_cb() is called immediately so
95 * both elapsed time and progress are 0.0.
96 * Since it is the beginning of the animation if progress is 0.0, the
97 * following codes for animation should be executed. */
98 if ((vector <= DBL_EPSILON) && (pd->progress != 0.0))
99 return ECORE_CALLBACK_RENEW; // There is no update.
100
101 //TODO: check negative play_speed.
102 if (!pd->is_direction_forward)
103 vector *= -1;
104 pd->progress += vector;
105
106 if (pd->progress > 1.0)
107 pd->progress = 1.0;
108 else if (pd->progress < 0.0)
109 pd->progress = 0.0;
110 }
111 else
112 {
113 pd->progress = (double)(pd->is_direction_forward);
114 }
115
116 /* The previously applied map effect should be reset before applying the
117 * current map effect. Otherwise, the incrementally added map effects
118 * increase numerical error. */
119 efl_gfx_mapping_reset(efl_animation_player_target_get(eo_obj));
120 efl_animation_apply(anim, pd->progress, efl_animation_player_target_get(eo_obj));
121
122 Efl_Canvas_Animation_Player_Event_Running event_running;
123 event_running.progress = pd->progress;
124 efl_event_callback_call(eo_obj, EFL_ANIMATION_PLAYER_EVENT_RUNNING,
125 &event_running);
126 pd->time.prev = pd->time.current;
127
128 //Not end. Keep going.
129 if (fabs((!!(pd->is_direction_forward)) - pd->progress) > DBL_EPSILON)
130 return ECORE_CALLBACK_RENEW;
131
132 //Repeat animation
133 if ((efl_animation_repeat_count_get(anim) == EFL_ANIMATION_REPEAT_INFINITE) ||
134 (pd->remaining_repeat_count > 0))
135 {
136 if (pd->remaining_repeat_count > 0)
137 pd->remaining_repeat_count--;
138
139 if (efl_animation_repeat_mode_get(anim) == EFL_CANVAS_ANIMATION_REPEAT_MODE_REVERSE)
140 {
141 pd->is_direction_forward = !pd->is_direction_forward;
142 }
143 else
144 {
145 pd->progress = 0.0;
146 }
147
148 return ECORE_CALLBACK_RENEW;
149 }
150 efl_player_playing_set(eo_obj, EINA_FALSE);
151
152 pd->animator = NULL;
153 return ECORE_CALLBACK_CANCEL;
154}
155
156static void
157_start(Eo *eo_obj, Efl_Canvas_Animation_Player_Data *pd)
158{
159 EFL_ANIMATION_PLAYER_ANIMATION_GET(eo_obj, anim);
160
161 pd->is_direction_forward = EINA_TRUE;
162
163 pd->remaining_repeat_count = efl_animation_repeat_count_get(anim);
164
165 ecore_animator_del(pd->animator);
166 pd->animator = NULL;
167 pd->time.prev = ecore_loop_time_get();
168
169 //pre started event is supported within class only (protected event)
170 efl_event_callback_call(eo_obj, EFL_ANIMATION_PLAYER_EVENT_PRE_STARTED,
171 NULL);
172 efl_event_callback_call(eo_obj, EFL_ANIMATION_PLAYER_EVENT_STARTED, NULL);
173
174 pd->animator = ecore_evas_animator_add(pd->target, _animator_cb, eo_obj);
175
176 _animator_cb(eo_obj);
177}
178
179static Eina_Bool
180_start_delay_timer_cb(void *data)
181{
182 Eo *eo_obj = data;
183 EFL_ANIMATION_PLAYER_DATA_GET(eo_obj, pd);
184
185 pd->start_delay_timer = NULL;
186
187 _start(eo_obj, pd);
188
189 return ECORE_CALLBACK_CANCEL;
190}
191
192static Eina_Bool
193_is_final_state(Efl_Canvas_Animation *anim, double progress)
194{
195 if (!anim) return EINA_FALSE;
196 if ((progress != 0.0) && (progress != 1.0)) return EINA_FALSE;
197
198 if (efl_animation_repeat_mode_get(anim) == EFL_CANVAS_ANIMATION_REPEAT_MODE_REVERSE)
199 {
200 if (efl_animation_repeat_count_get(anim) & 1)
201 {
202 if (progress == 0.0)
203 return EINA_TRUE;
204 }
205 else
206 {
207 if (progress == 1.0)
208 return EINA_TRUE;
209 }
210 }
211 else
212 {
213 if (progress == 1.0)
214 return EINA_TRUE;
215 }
216
217 return EINA_FALSE;
218}
219
220static void
221_player_stop(Eo *eo_obj, Efl_Canvas_Animation_Player_Data *pd, Efl_Canvas_Animation *anim)
222{
223 //Reset the state of the target to the initial state
224 efl_gfx_mapping_reset(efl_animation_player_target_get(eo_obj));
225
226 if (efl_animation_final_state_keep_get(anim))
227 {
228 if (_is_final_state(anim, pd->progress))
229 {
230 /* Keep the final state only if efl_player_playing_set(EINA_FALSE) is called at
231 * the end of _animator_cb. */
232 efl_animation_apply(anim, pd->progress,
233 efl_animation_player_target_get(eo_obj));
234 }
235 else
236 {
237 pd->progress = 0.0;
238 }
239 }
240 else
241 {
242 pd->progress = 0.0;
243 }
244 efl_event_callback_call(eo_obj, EFL_ANIMATION_PLAYER_EVENT_ENDED, NULL);
245 if (pd->auto_del) efl_del(eo_obj);
246}
247
248EOLIAN static Eina_Bool
249_efl_canvas_animation_player_efl_player_playing_set(Eo *eo_obj, Efl_Canvas_Animation_Player_Data *pd, Eina_Bool playing)
250{
251 double start_delay;
252 EFL_ANIMATION_PLAYER_ANIMATION_GET(eo_obj, anim);
253
254 if (!efl_playable_get(eo_obj)) return EINA_FALSE;
255 if ((!playing) && (!pd->is_play)) return EINA_TRUE;
256 if ((playing) && (pd->is_play)) return EINA_TRUE;
257 pd->is_play = !!playing;
258 if (!playing)
259 {
260 if (!pd->is_play) return EINA_TRUE;
261 pd->is_paused = EINA_FALSE;
262 _player_stop(eo_obj, pd, anim);
263 return EINA_TRUE;
264 }
265 //TODO: check this case is correct
266 if (pd->start_delay_timer) return EINA_TRUE;
267
268 pd->progress = 0.0;
269 start_delay = efl_animation_start_delay_get(anim);
270 if (start_delay > 0.0)
271 {
272 pd->start_delay_timer = ecore_timer_add(start_delay,
273 _start_delay_timer_cb, eo_obj);
274 }
275 else
276 _start(eo_obj, pd);
277 return EINA_TRUE;
278}
279
280EOLIAN static Eina_Bool
281_efl_canvas_animation_player_efl_player_playing_get(const Eo *eo_obj EINA_UNUSED, Efl_Canvas_Animation_Player_Data *pd)
282{
283 return pd->is_play;
284}
285
286EOLIAN static Eina_Bool
287_efl_canvas_animation_player_efl_player_paused_set(Eo *eo_obj,
288 Efl_Canvas_Animation_Player_Data *pd,
289 Eina_Bool paused)
290{
291 paused = !!paused;
292 /* can't pause if not playing */
293 if (!pd->is_play) return EINA_FALSE;
294 if (pd->is_paused == paused) return EINA_TRUE;
295 pd->is_paused = paused;
296 if (!paused)
297 {
298 //TODO: check this case is correct.
299 if (pd->start_delay_timer) return EINA_FALSE;
300
301 pd->time.prev = ecore_loop_time_get();
302 pd->animator = ecore_evas_animator_add(pd->target, _animator_cb, eo_obj);
303
304 _animator_cb(eo_obj);
305 }
306 else
307 {
308 ecore_timer_del(pd->start_delay_timer);
309 pd->start_delay_timer = NULL;
310 ecore_animator_del(pd->animator);
311 pd->animator = NULL;
312 }
313 return EINA_TRUE;
314}
315
316EOLIAN static Eina_Bool
317_efl_canvas_animation_player_efl_player_paused_get(const Eo *eo_obj EINA_UNUSED,
318 Efl_Canvas_Animation_Player_Data *pd)
319{
320 return pd->is_paused;
321}
322
323EOLIAN static Eina_Bool
324_efl_canvas_animation_player_efl_playable_playable_get(const Eo *eo_obj,
325 Efl_Canvas_Animation_Player_Data *pd EINA_UNUSED)
326{
327 Efl_Canvas_Animation *anim = efl_animation_player_animation_get(eo_obj);
328
329 return efl_playable_get(anim);
330}
331
332EOLIAN static double
333_efl_canvas_animation_player_efl_player_playback_position_get(const Eo *eo_obj,
334 Efl_Canvas_Animation_Player_Data *pd EINA_UNUSED)
335{
336 //TODO: this is not correct
337 Efl_Canvas_Animation *anim = efl_animation_player_animation_get(eo_obj);
338 double length = efl_animation_duration_get(anim);
339
340 return length * efl_player_playback_progress_get(eo_obj);
341}
342
343EOLIAN static void
344_efl_canvas_animation_player_efl_player_playback_position_set(Eo *eo_obj,
345 Efl_Canvas_Animation_Player_Data *pd EINA_UNUSED,
346 double sec)
347{
348 //TODO: this is not correct
349 if (!efl_playable_seekable_get(eo_obj))
350 return;
351
352 EFL_ANIMATION_PLAYER_ANIMATION_GET(eo_obj, anim);
353 double length = efl_animation_duration_get(anim);
354 pd->progress = sec / length;
355
356 /* The previously applied map effect should be reset before applying the
357 * current map effect. Otherwise, the incrementally added map effects
358 * increase numerical error. */
359 efl_gfx_mapping_reset(efl_animation_player_target_get(eo_obj));
360 efl_animation_apply(anim, pd->progress, efl_animation_player_target_get(eo_obj));
361}
362
363EOLIAN static double
364_efl_canvas_animation_player_efl_player_playback_progress_get(const Eo *eo_obj EINA_UNUSED,
365 Efl_Canvas_Animation_Player_Data *pd)
366{
367 return pd->progress;
368}
369
370EOLIAN static void
371_efl_canvas_animation_player_efl_player_playback_speed_set(Eo *eo_obj EINA_UNUSED,
372 Efl_Canvas_Animation_Player_Data *pd,
373 double play_speed)
374{
375 //TODO: check reverse play case.
376 if (play_speed < 0)
377 return;
378 pd->play_speed = play_speed;
379}
380
381EOLIAN static double
382_efl_canvas_animation_player_efl_player_playback_speed_get(const Eo *eo_obj EINA_UNUSED,
383 Efl_Canvas_Animation_Player_Data *pd)
384{
385 return pd->play_speed;
386}
387
388EOLIAN static double
389_efl_canvas_animation_player_efl_playable_length_get(const Eo *eo_obj,
390 Efl_Canvas_Animation_Player_Data *pd EINA_UNUSED)
391{
392 EFL_ANIMATION_PLAYER_ANIMATION_GET(eo_obj, anim);
393 return efl_playable_length_get(anim);
394}
395
396EOLIAN static Eina_Bool
397_efl_canvas_animation_player_efl_playable_seekable_get(const Eo *eo_obj EINA_UNUSED,
398 Efl_Canvas_Animation_Player_Data *pd EINA_UNUSED)
399{
400 EFL_ANIMATION_PLAYER_ANIMATION_GET(eo_obj, anim);
401 return efl_playable_seekable_get(anim);
402}
403
404EOLIAN static Efl_Object *
405_efl_canvas_animation_player_efl_object_constructor(Eo *eo_obj,
406 Efl_Canvas_Animation_Player_Data *pd)
407{
408 eo_obj = efl_constructor(efl_super(eo_obj, MY_CLASS));
409
410 pd->time.begin = 0.0;
411 pd->time.current = 0.0;
412
413 pd->animation = NULL;
414
415 pd->progress = 0.0;
416
417 //pd->auto_del = EINA_TRUE;
418
419 return eo_obj;
420}
421
422EOLIAN static void
423_efl_canvas_animation_player_efl_object_destructor(Eo *eo_obj,
424 Efl_Canvas_Animation_Player_Data *pd)
425{
426 if (pd->animator)
427 {
428 ecore_animator_del(pd->animator);
429 pd->animator = NULL;
430
431 //Reset the state of the target to the initial state
432 efl_player_playing_set(eo_obj, EINA_FALSE);
433
434 efl_event_callback_call(eo_obj, EFL_ANIMATION_PLAYER_EVENT_ENDED, NULL);
435 }
436 efl_unref(pd->animation);
437
438 efl_destructor(efl_super(eo_obj, MY_CLASS));
439}
440
441EWAPI const Efl_Event_Description _EFL_ANIMATION_PLAYER_EVENT_PRE_STARTED =
442 EFL_EVENT_DESCRIPTION("pre_started");
443
444#include "efl_canvas_animation_player.eo.c"