efl_animation: Add group animation object
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Fri, 25 Aug 2017 08:17:24 +0000 (17:17 +0900)
committerJaehyun Cho <jae_hyun.cho@samsung.com>
Thu, 12 Oct 2017 12:03:49 +0000 (21:03 +0900)
src/Makefile_Evas.am
src/lib/evas/Evas_Common.h
src/lib/evas/Evas_Eo.h
src/lib/evas/Evas_Internal.h
src/lib/evas/canvas/efl_animation_object_group.c [new file with mode: 0644]
src/lib/evas/canvas/efl_animation_object_group.eo [new file with mode: 0644]
src/lib/evas/canvas/efl_animation_object_group_private.h [new file with mode: 0644]

index 68c1b18..96f133e 100644 (file)
@@ -55,6 +55,7 @@ evas_eolian_pub_files = \
        lib/evas/canvas/efl_animation_object_rotate.eo \
        lib/evas/canvas/efl_animation_object_scale.eo \
        lib/evas/canvas/efl_animation_object_translate.eo \
+       lib/evas/canvas/efl_animation_object_group.eo \
        $(NULL)
 
 evas_eolian_legacy_files = \
@@ -143,7 +144,8 @@ lib/evas/canvas/efl_animation_object_private.h \
 lib/evas/canvas/efl_animation_object_alpha_private.h \
 lib/evas/canvas/efl_animation_object_rotate_private.h \
 lib/evas/canvas/efl_animation_object_scale_private.h \
-lib/evas/canvas/efl_animation_object_translate_private.h
+lib/evas/canvas/efl_animation_object_translate_private.h \
+lib/evas/canvas/efl_animation_object_group_private.h
 
 # Linebreak
 
@@ -240,6 +242,7 @@ lib/evas/canvas/efl_animation_object_alpha.c \
 lib/evas/canvas/efl_animation_object_rotate.c \
 lib/evas/canvas/efl_animation_object_scale.c \
 lib/evas/canvas/efl_animation_object_translate.c \
+lib/evas/canvas/efl_animation_object_group.c \
 $(NULL)
 
 EXTRA_DIST2 += \
index 7c39fb2..79f2f4c 100644 (file)
@@ -3407,12 +3407,20 @@ typedef Eo Efl_Animation_Object_Translate;
 
 #endif
 
+#ifndef _EFL_ANIMATION_OBJECT_GROUP_EO_CLASS_TYPE
+#define _EFL_ANIMATION_OBJECT_GROUP_EO_CLASS_TYPE
+
+typedef Eo Efl_Animation_Object_Group;
+
+#endif
+
 struct _Efl_Animation_Object_Running_Event_Info
 {
    double progress;
 };
 
 #define EFL_ANIMATION_GROUP_DURATION_NONE -1
+#define EFL_ANIMATION_OBJECT_GROUP_DURATION_NONE -1
 
 /**
  * @}
index 6f52e0c..b0a2d25 100644 (file)
@@ -66,6 +66,7 @@
 #include "canvas/efl_animation_object_rotate.eo.h"
 #include "canvas/efl_animation_object_scale.eo.h"
 #include "canvas/efl_animation_object_translate.eo.h"
+#include "canvas/efl_animation_object_group.eo.h"
 
 #endif /* EFL_EO_API_SUPPORT */
 
index a406abc..721eba6 100644 (file)
@@ -131,6 +131,13 @@ EOAPI void efl_animation_object_translate_absolute_set(Eo *obj, int from_x, int
 EOAPI void efl_animation_object_translate_absolute_get(const Eo *obj, int *from_x, int *from_y, int *to_x, int *to_y);
 /* Efl.Animation.Object.Translate END */
 
+/* Efl.Animation.Object.Group */
+EOAPI void efl_animation_object_group_object_add(Eo *obj, Efl_Animation_Object *anim_obj);
+EOAPI void efl_animation_object_group_object_del(Eo *obj, Efl_Animation_Object *anim_obj);
+
+EOAPI Eina_List *efl_animation_object_group_objects_get(Eo *obj);
+/* Efl.Animation.Object.Group END */
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/lib/evas/canvas/efl_animation_object_group.c b/src/lib/evas/canvas/efl_animation_object_group.c
new file mode 100644 (file)
index 0000000..d3799b4
--- /dev/null
@@ -0,0 +1,188 @@
+#include "efl_animation_object_group_private.h"
+
+EOLIAN static void
+_efl_animation_object_group_object_add(Eo *eo_obj,
+                                       Efl_Animation_Object_Group_Data *pd,
+                                       Efl_Animation_Object *anim_obj)
+{
+   EFL_ANIMATION_OBJECT_GROUP_CHECK_OR_RETURN(eo_obj);
+
+   if (!anim_obj) return;
+
+   Efl_Canvas_Object *target = efl_animation_object_target_get(eo_obj);
+   if (target)
+     efl_animation_object_target_set(anim_obj, target);
+
+   double duration = efl_animation_object_duration_get(eo_obj);
+   /* if group animation object duration is available value, then the duration
+    * is propagated to its child. */
+   if (duration != EFL_ANIMATION_OBJECT_GROUP_DURATION_NONE)
+     efl_animation_object_duration_set(anim_obj, duration);
+
+   Eina_Bool state_keep = efl_animation_object_final_state_keep_get(eo_obj);
+   efl_animation_object_final_state_keep_set(anim_obj, state_keep);
+
+   pd->anim_objs = eina_list_append(pd->anim_objs, anim_obj);
+}
+
+EOLIAN static void
+_efl_animation_object_group_object_del(Eo *eo_obj,
+                                       Efl_Animation_Object_Group_Data *pd,
+                                       Efl_Animation_Object *anim_obj)
+{
+   EFL_ANIMATION_OBJECT_GROUP_CHECK_OR_RETURN(eo_obj);
+
+   if (!anim_obj) return;
+
+   pd->anim_objs = eina_list_remove(pd->anim_objs, anim_obj);
+}
+
+EOLIAN static Eina_List *
+_efl_animation_object_group_objects_get(Eo *eo_obj,
+                                        Efl_Animation_Object_Group_Data *pd)
+{
+   EFL_ANIMATION_OBJECT_GROUP_CHECK_OR_RETURN(eo_obj, NULL);
+
+   return pd->anim_objs;
+}
+
+EOLIAN static void
+_efl_animation_object_group_efl_animation_object_target_set(Eo *eo_obj,
+                                                            Efl_Animation_Object_Group_Data *pd,
+                                                            Efl_Canvas_Object *target)
+{
+   EFL_ANIMATION_OBJECT_GROUP_CHECK_OR_RETURN(eo_obj);
+
+   Eina_List *l;
+   Efl_Animation_Object *anim_obj;
+
+   EINA_LIST_FOREACH(pd->anim_objs, l, anim_obj)
+     {
+        efl_animation_object_target_set(anim_obj, target);
+     }
+
+   efl_animation_object_target_set(efl_super(eo_obj, MY_CLASS), target);
+}
+
+EOLIAN static void
+_efl_animation_object_group_efl_animation_object_duration_set(Eo *eo_obj,
+                                                              Efl_Animation_Object_Group_Data *pd,
+                                                              double duration)
+{
+   EFL_ANIMATION_OBJECT_GROUP_CHECK_OR_RETURN(eo_obj);
+
+   if (duration == EFL_ANIMATION_OBJECT_GROUP_DURATION_NONE) goto end;
+
+   if (duration < 0.0) return;
+
+   Eina_List *l;
+   Efl_Animation_Object *anim_obj;
+
+   EINA_LIST_FOREACH(pd->anim_objs, l, anim_obj)
+     {
+        efl_animation_object_duration_set(anim_obj, duration);
+     }
+
+end:
+   efl_animation_object_duration_only_set(efl_super(eo_obj, MY_CLASS),
+                                          duration);
+
+   /* efl_animation_object_total_duration_get() should calculate the new total
+    * duration. */
+   double total_duration = efl_animation_object_total_duration_get(eo_obj);
+   efl_animation_object_total_duration_set(eo_obj, total_duration);
+}
+
+EOLIAN static void
+_efl_animation_object_group_efl_animation_object_final_state_keep_set(Eo *eo_obj,
+                                                                      Efl_Animation_Object_Group_Data *pd,
+                                                                      Eina_Bool state_keep)
+{
+   EFL_ANIMATION_OBJECT_GROUP_CHECK_OR_RETURN(eo_obj);
+
+   Eina_List *l;
+   Efl_Animation_Object *anim_obj;
+
+   EINA_LIST_FOREACH(pd->anim_objs, l, anim_obj)
+     {
+        efl_animation_object_final_state_keep_set(anim_obj, state_keep);
+     }
+
+   efl_animation_object_final_state_keep_set(efl_super(eo_obj, MY_CLASS),
+                                             state_keep);
+}
+
+EOLIAN static Efl_Object *
+_efl_animation_object_group_efl_object_constructor(Eo *eo_obj,
+                                                   Efl_Animation_Object_Group_Data *pd)
+{
+   eo_obj = efl_constructor(efl_super(eo_obj, MY_CLASS));
+
+   pd->anim_objs = NULL;
+
+   //group animation object does not affect its child duration by default.
+   efl_animation_object_duration_only_set(efl_super(eo_obj, MY_CLASS),
+                                          EFL_ANIMATION_OBJECT_GROUP_DURATION_NONE);
+
+   return eo_obj;
+}
+
+EOLIAN static void
+_efl_animation_object_group_efl_object_destructor(Eo *eo_obj,
+                                                  Efl_Animation_Object_Group_Data *pd)
+{
+   Efl_Animation_Object *anim_obj;
+
+   EINA_LIST_FREE(pd->anim_objs, anim_obj)
+      efl_del(anim_obj);
+
+   efl_destructor(efl_super(eo_obj, MY_CLASS));
+}
+
+EOLIAN static void
+_efl_animation_object_group_efl_animation_object_target_state_save(Eo *eo_obj,
+                                                                   Efl_Animation_Object_Group_Data *pd)
+{
+   EFL_ANIMATION_OBJECT_GROUP_CHECK_OR_RETURN(eo_obj);
+
+   Eina_List *l;
+   Efl_Animation_Object *anim_obj;
+
+   EINA_LIST_FOREACH(pd->anim_objs, l, anim_obj)
+     {
+        efl_animation_object_target_state_save(anim_obj);
+     }
+}
+
+EOLIAN static void
+_efl_animation_object_group_efl_animation_object_target_state_reset(Eo *eo_obj,
+                                                                    Efl_Animation_Object_Group_Data *pd)
+{
+   EFL_ANIMATION_OBJECT_GROUP_CHECK_OR_RETURN(eo_obj);
+
+   Eina_List *l;
+   Efl_Animation_Object *anim_obj;
+
+   EINA_LIST_FOREACH(pd->anim_objs, l, anim_obj)
+     {
+        efl_animation_object_target_state_reset(anim_obj);
+     }
+}
+
+/* Internal EO APIs */
+
+EOAPI EFL_VOID_FUNC_BODYV(efl_animation_object_group_object_add, EFL_FUNC_CALL(anim_obj), Efl_Animation_Object *anim_obj);
+
+EOAPI EFL_VOID_FUNC_BODYV(efl_animation_object_group_object_del, EFL_FUNC_CALL(anim_obj), Efl_Animation_Object *anim_obj);
+
+EOAPI EFL_FUNC_BODY(efl_animation_object_group_objects_get, Eina_List *, NULL);
+
+#define EFL_ANIMATION_OBJECT_GROUP_EXTRA_OPS \
+   EFL_OBJECT_OP_FUNC(efl_animation_object_group_object_add, _efl_animation_object_group_object_add), \
+   EFL_OBJECT_OP_FUNC(efl_animation_object_group_object_del, _efl_animation_object_group_object_del), \
+   EFL_OBJECT_OP_FUNC(efl_animation_object_group_objects_get, _efl_animation_object_group_objects_get), \
+   EFL_OBJECT_OP_FUNC(efl_animation_object_target_set, _efl_animation_object_group_efl_animation_object_target_set), \
+   EFL_OBJECT_OP_FUNC(efl_animation_object_duration_set, _efl_animation_object_group_efl_animation_object_duration_set), \
+   EFL_OBJECT_OP_FUNC(efl_animation_object_final_state_keep_set, _efl_animation_object_group_efl_animation_object_final_state_keep_set)
+
+#include "efl_animation_object_group.eo.c"
diff --git a/src/lib/evas/canvas/efl_animation_object_group.eo b/src/lib/evas/canvas/efl_animation_object_group.eo
new file mode 100644 (file)
index 0000000..cdde1ec
--- /dev/null
@@ -0,0 +1,13 @@
+import efl_animation_types;
+
+abstract Efl.Animation.Object.Group (Efl.Animation.Object)
+{
+   [[Efl group animation object abstract class]]
+   data: Efl_Animation_Object_Group_Data;
+   implements {
+      Efl.Object.constructor;
+      Efl.Object.destructor;
+      Efl.Animation.Object.target_state_save;
+      Efl.Animation.Object.target_state_reset;
+   }
+}
diff --git a/src/lib/evas/canvas/efl_animation_object_group_private.h b/src/lib/evas/canvas/efl_animation_object_group_private.h
new file mode 100644 (file)
index 0000000..a710b46
--- /dev/null
@@ -0,0 +1,26 @@
+#define EFL_ANIMATION_OBJECT_PROTECTED
+
+#include "evas_common_private.h"
+
+#define MY_CLASS EFL_ANIMATION_OBJECT_GROUP_CLASS
+#define MY_CLASS_NAME efl_class_name_get(MY_CLASS)
+
+#define EFL_ANIMATION_OBJECT_GROUP_CHECK_OR_RETURN(anim_obj, ...) \
+   do { \
+      if (!anim_obj) { \
+         CRI("Efl_Animation_Object " # anim_obj " is NULL!"); \
+         return __VA_ARGS__; \
+      } \
+      if (efl_animation_object_is_deleted(anim_obj)) { \
+         ERR("Efl_Animation_Object " # anim_obj " has already been deleted!"); \
+         return __VA_ARGS__; \
+      } \
+   } while (0)
+
+#define EFL_ANIMATION_OBJECT_GROUP_DATA_GET(o, pd) \
+   Efl_Animation_Object_Group_Data *pd = efl_data_scope_get(o, EFL_ANIMATION_OBJECT_GROUP_CLASS)
+
+typedef struct _Efl_Animation_Object_Group_Data
+{
+   Eina_List *anim_objs;
+} Efl_Animation_Object_Group_Data;