summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/efl_canvas_animation_group_parallel.c
blob: 9960e4105e6ab055ac13db7e49d5da002fed0a33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "efl_canvas_animation_group_parallel_private.h"

#define MY_CLASS EFL_CANVAS_ANIMATION_GROUP_PARALLEL_CLASS

EOLIAN static double
_efl_canvas_animation_group_parallel_efl_canvas_animation_animation_apply(Eo *eo_obj,
                                                            void *_pd EINA_UNUSED,
                                                            double progress,
                                                            Efl_Canvas_Object *target)
{
   double group_length, group_elapsed_time;
   double anim_length, anim_duration, anim_start_delay, anim_progress, anim_elapsed_time;
   int anim_repeated_count;

   progress = efl_animation_apply(efl_super(eo_obj, MY_CLASS), progress, target);
   Eina_Iterator *group_anim = efl_animation_group_animations_get(eo_obj);
   if (!group_anim) return progress;

   group_length = efl_playable_length_get(eo_obj);
   group_elapsed_time = group_length * progress;

   Efl_Canvas_Animation *anim;
   EINA_ITERATOR_FOREACH(group_anim, anim)
     {
        anim_length = efl_playable_length_get(anim);
        anim_duration = efl_animation_duration_get(anim);
        anim_start_delay = efl_animation_start_delay_get(anim);

        anim_repeated_count = (int)(group_elapsed_time / anim_length);

        if ((anim_length + anim_start_delay) <= group_elapsed_time)
          {
             if (efl_animation_final_state_keep_get(anim) && (!FINAL_STATE_IS_REVERSE(anim)))
               anim_progress = 1.0;
             else
               anim_progress = 0.0;
             efl_animation_apply(anim, anim_progress, target);

             continue;
          }

        anim_elapsed_time =
           MAX(((group_elapsed_time - (anim_length * anim_repeated_count)) - anim_start_delay), 0.0);
        anim_progress = MIN((anim_elapsed_time / anim_duration), 1.0);
        if (FINAL_STATE_IS_REVERSE(anim))
          anim_progress = 1.0 - anim_progress;

        efl_animation_apply(anim, anim_progress, target);
     }
   eina_iterator_free(group_anim);

   return progress;
}

EOLIAN static double
_efl_canvas_animation_group_parallel_efl_canvas_animation_duration_get(const Eo *eo_obj, void *_pd EINA_UNUSED)
{
   double child_total_duration;
   double total_duration = 0.0;

   Eina_Iterator *group_anim = efl_animation_group_animations_get(eo_obj);
   if (!group_anim) return 0.0;

   Efl_Canvas_Animation *anim;
   EINA_ITERATOR_FOREACH(group_anim, anim)
     {
        child_total_duration = efl_playable_length_get(anim);
        child_total_duration += efl_animation_start_delay_get(anim);
        if (child_total_duration > total_duration)
          total_duration = child_total_duration;
     }
   eina_iterator_free(group_anim);

   return total_duration;
}

#include "efl_canvas_animation_group_parallel.eo.c"