summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/efl_animation_group_sequential.c
blob: b29599bd256dfcb85a8786af8318995c3d6a1927 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "efl_animation_group_sequential_private.h"

EOLIAN static void
_efl_animation_group_sequential_efl_animation_group_animation_add(Eo *eo_obj,
                                                                  Efl_Animation_Group_Sequential_Data *pd EINA_UNUSED,
                                                                  Efl_Animation *animation)
{
   EFL_ANIMATION_GROUP_SEQUENTIAL_CHECK_OR_RETURN(eo_obj);

   if (!animation) return;

   efl_animation_group_animation_add(efl_super(eo_obj, MY_CLASS), animation);

   /* Total duration is calculated in efl_animation_total_duration_get() based
    * on the current group animation list.
    * Therefore, the calculated total duration should be set to update total
    * duration. */
   double total_duration = efl_animation_total_duration_get(eo_obj);
   efl_animation_total_duration_set(eo_obj, total_duration);
}

EOLIAN static void
_efl_animation_group_sequential_efl_animation_group_animation_del(Eo *eo_obj,
                                                                  Efl_Animation_Group_Sequential_Data *pd EINA_UNUSED,
                                                                  Efl_Animation *animation)
{
   EFL_ANIMATION_GROUP_SEQUENTIAL_CHECK_OR_RETURN(eo_obj);

   if (!animation) return;

   efl_animation_group_animation_del(efl_super(eo_obj, MY_CLASS), animation);

   /* Total duration is calculated in efl_animation_total_duration_get() based
    * on the current group animation list.
    * Therefore, the calculated total duration should be set to update total
    * duration. */
   double total_duration = efl_animation_total_duration_get(eo_obj);
   efl_animation_total_duration_set(eo_obj, total_duration);
}

EOLIAN static double
_efl_animation_group_sequential_efl_animation_total_duration_get(Eo *eo_obj,
                                                                 Efl_Animation_Group_Sequential_Data *pd EINA_UNUSED)
{
   EFL_ANIMATION_GROUP_SEQUENTIAL_CHECK_OR_RETURN(eo_obj, 0.0);

   Eina_List *animations = efl_animation_group_animations_get(eo_obj);
   if (!animations) return 0.0;

   double total_duration = 0.0;
   Eina_List *l;
   Efl_Animation *anim;
   EINA_LIST_FOREACH(animations, l, anim)
     {
        double child_total_duration = efl_animation_total_duration_get(anim);

        int child_repeat_count = efl_animation_repeat_count_get(anim);
        if (child_repeat_count > 0)
          child_total_duration *= (child_repeat_count + 1);

        total_duration += child_total_duration;
     }
   return total_duration;
}

EOLIAN static Efl_Animation_Object *
_efl_animation_group_sequential_efl_animation_object_create(Eo *eo_obj,
                                                            Efl_Animation_Group_Sequential_Data *pd EINA_UNUSED)
{
   EFL_ANIMATION_GROUP_SEQUENTIAL_CHECK_OR_RETURN(eo_obj, NULL);

   Efl_Animation_Object_Group_Sequential *group_anim_obj
      = efl_add(EFL_ANIMATION_OBJECT_GROUP_SEQUENTIAL_CLASS, NULL);

   Eina_List *animations = efl_animation_group_animations_get(eo_obj);
   Eina_List *l;
   Efl_Animation *child_anim;
   Efl_Animation_Object *child_anim_obj;

   EINA_LIST_FOREACH(animations, l, child_anim)
     {
        child_anim_obj = efl_animation_object_create(child_anim);
        efl_animation_object_group_object_add(group_anim_obj, child_anim_obj);
     }

   Efl_Canvas_Object *target = efl_animation_target_get(eo_obj);
   if (target)
     efl_animation_object_target_set(group_anim_obj, target);

   Eina_Bool state_keep = efl_animation_final_state_keep_get(eo_obj);
   efl_animation_object_final_state_keep_set(group_anim_obj, state_keep);

   double duration = efl_animation_duration_get(eo_obj);
   efl_animation_object_duration_set(group_anim_obj, duration);

   double total_duration = efl_animation_total_duration_get(eo_obj);
   efl_animation_object_total_duration_set(group_anim_obj, total_duration);

   int repeat_count = efl_animation_repeat_count_get(eo_obj);
   efl_animation_object_repeat_count_set(group_anim_obj, repeat_count);

   return group_anim_obj;
}

#include "efl_animation_group_sequential.eo.c"