jaehyun pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=4112a68e321a4f65a6c867251192f2095a29208d
commit 4112a68e321a4f65a6c867251192f2095a29208d Author: Jaehyun Cho <jae_hyun....@samsung.com> Date: Wed Aug 30 12:08:41 2017 +0900 efl_animation: Add sequential group animation and object Efl.Animation.Group.Sequential is a class for animations started in sequence. Efl.Animation.Object.Group.Sequential is a class which provides methods for an object of Efl.Animation.Group.Sequential. The objects added into the sequential group animation object start in sequence. --- src/Makefile_Elementary.am | 1 + src/Makefile_Evas.am | 8 +- src/bin/elementary/Makefile.am | 1 + src/bin/elementary/test.c | 2 + .../elementary/test_efl_anim_group_sequential.c | 194 +++++++++++++++++++++ src/lib/evas/Evas_Common.h | 14 ++ src/lib/evas/Evas_Eo.h | 2 + .../evas/canvas/efl_animation_group_sequential.c | 96 ++++++++++ .../evas/canvas/efl_animation_group_sequential.eo | 15 ++ .../efl_animation_group_sequential_private.h | 25 +++ .../canvas/efl_animation_object_group_sequential.c | 121 +++++++++++++ .../efl_animation_object_group_sequential.eo | 12 ++ ...efl_animation_object_group_sequential_private.h | 25 +++ 13 files changed, 515 insertions(+), 1 deletion(-) diff --git a/src/Makefile_Elementary.am b/src/Makefile_Elementary.am index 8607082f02..1977b2ed48 100644 --- a/src/Makefile_Elementary.am +++ b/src/Makefile_Elementary.am @@ -802,6 +802,7 @@ bin/elementary/test_efl_anim_rotate.c \ bin/elementary/test_efl_anim_scale.c \ bin/elementary/test_efl_anim_translate.c \ bin/elementary/test_efl_anim_group_parallel.c \ +bin/elementary/test_efl_anim_group_sequential.c \ bin/elementary/test_eio.c \ bin/elementary/test_entry.c \ bin/elementary/test_entry_anchor.c \ diff --git a/src/Makefile_Evas.am b/src/Makefile_Evas.am index 5744fbebf0..6393381f11 100644 --- a/src/Makefile_Evas.am +++ b/src/Makefile_Evas.am @@ -51,6 +51,7 @@ evas_eolian_pub_files = \ lib/evas/canvas/efl_animation_translate.eo \ lib/evas/canvas/efl_animation_group.eo \ lib/evas/canvas/efl_animation_group_parallel.eo \ + lib/evas/canvas/efl_animation_group_sequential.eo \ lib/evas/canvas/efl_animation_object.eo \ lib/evas/canvas/efl_animation_object_alpha.eo \ lib/evas/canvas/efl_animation_object_rotate.eo \ @@ -58,6 +59,7 @@ evas_eolian_pub_files = \ lib/evas/canvas/efl_animation_object_translate.eo \ lib/evas/canvas/efl_animation_object_group.eo \ lib/evas/canvas/efl_animation_object_group_parallel.eo \ + lib/evas/canvas/efl_animation_object_group_sequential.eo \ $(NULL) evas_eolian_legacy_files = \ @@ -143,13 +145,15 @@ lib/evas/canvas/efl_animation_scale_private.h \ lib/evas/canvas/efl_animation_translate_private.h \ lib/evas/canvas/efl_animation_group_private.h \ lib/evas/canvas/efl_animation_group_parallel_private.h \ +lib/evas/canvas/efl_animation_group_sequential_private.h \ 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_group_private.h \ -lib/evas/canvas/efl_animation_object_group_parallel_private.h +lib/evas/canvas/efl_animation_object_group_parallel_private.h \ +lib/evas/canvas/efl_animation_object_group_sequential_private.h # Linebreak @@ -242,6 +246,7 @@ lib/evas/canvas/efl_animation_scale.c \ lib/evas/canvas/efl_animation_translate.c \ lib/evas/canvas/efl_animation_group.c \ lib/evas/canvas/efl_animation_group_parallel.c \ +lib/evas/canvas/efl_animation_group_sequential.c \ lib/evas/canvas/efl_animation_object.c \ lib/evas/canvas/efl_animation_object_alpha.c \ lib/evas/canvas/efl_animation_object_rotate.c \ @@ -249,6 +254,7 @@ lib/evas/canvas/efl_animation_object_scale.c \ lib/evas/canvas/efl_animation_object_translate.c \ lib/evas/canvas/efl_animation_object_group.c \ lib/evas/canvas/efl_animation_object_group_parallel.c \ +lib/evas/canvas/efl_animation_object_group_sequential.c \ $(NULL) EXTRA_DIST2 += \ diff --git a/src/bin/elementary/Makefile.am b/src/bin/elementary/Makefile.am index e23cab951e..ae7e381c5e 100644 --- a/src/bin/elementary/Makefile.am +++ b/src/bin/elementary/Makefile.am @@ -37,6 +37,7 @@ test_efl_anim_rotate.c \ test_efl_anim_scale.c \ test_efl_anim_translate.c \ test_efl_anim_group_parallel.c \ +test_efl_anim_group_sequential.c \ test_application_server.c \ test_bg.c \ test_box.c \ diff --git a/src/bin/elementary/test.c b/src/bin/elementary/test.c index 4d343fc4e9..dc1404a350 100644 --- a/src/bin/elementary/test.c +++ b/src/bin/elementary/test.c @@ -332,6 +332,7 @@ void test_efl_anim_scale_absolute(void *data, Evas_Object *obj, void *event_info void test_efl_anim_translate(void *data, Evas_Object *obj, void *event_info); void test_efl_anim_translate_absolute(void *data, Evas_Object *obj, void *event_info); void test_efl_anim_group_parallel(void *data, Evas_Object *obj, void *event_info); +void test_efl_anim_group_sequential(void *data, Evas_Object *obj, void *event_info); Evas_Object *win, *tbx; // TODO: refactoring void *tt; @@ -811,6 +812,7 @@ add_tests: ADD_TEST(NULL, "Effects", "Efl Animation Translate", test_efl_anim_translate); ADD_TEST(NULL, "Effects", "Efl Animation Translate Absolute", test_efl_anim_translate_absolute); ADD_TEST(NULL, "Effects", "Efl Animation Group Parallel", test_efl_anim_group_parallel); + ADD_TEST(NULL, "Effects", "Efl Animation Group Sequential", test_efl_anim_group_sequential); //------------------------------// ADD_TEST(NULL, "Edje External", "ExtButton", test_external_button); diff --git a/src/bin/elementary/test_efl_anim_group_sequential.c b/src/bin/elementary/test_efl_anim_group_sequential.c new file mode 100644 index 0000000000..219cd6df29 --- /dev/null +++ b/src/bin/elementary/test_efl_anim_group_sequential.c @@ -0,0 +1,194 @@ +#ifdef HAVE_CONFIG_H +# include "elementary_config.h" +#endif +#include <Elementary.h> + +typedef struct _App_Data +{ + Efl_Animation *sequential_show_anim; + Efl_Animation *sequential_hide_anim; + Efl_Animation_Object *anim_obj; + + Eina_Bool is_btn_visible; +} App_Data; + +static void +_anim_started_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED) +{ + printf("Animation has been started!\n"); +} + +static void +_anim_ended_cb(void *data, const Efl_Event *event EINA_UNUSED) +{ + App_Data *ad = data; + + printf("Animation has been ended!\n"); + + ad->anim_obj = NULL; +} + +static void +_anim_running_cb(void *data EINA_UNUSED, const Efl_Event *event) +{ + Efl_Animation_Object_Running_Event_Info *event_info = event->info; + double progress = event_info->progress; + printf("Animation is running! Current progress(%lf)\n", progress); +} + +static void +_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) +{ + App_Data *ad = data; + + if (ad->anim_obj) + efl_animation_object_cancel(ad->anim_obj); + + ad->is_btn_visible = !(ad->is_btn_visible); + + if (ad->is_btn_visible) + { + //Create Animation Object from Animation + ad->anim_obj = efl_animation_object_create(ad->sequential_show_anim); + elm_object_text_set(obj, "Start Sequential Group Animation to hide button"); + } + else + { + //Create Animation Object from Animation + ad->anim_obj = efl_animation_object_create(ad->sequential_hide_anim); + elm_object_text_set(obj, "Start Sequential Group Animation to show button"); + } + + //Register callback called when animation starts + efl_event_callback_add(ad->anim_obj, EFL_ANIMATION_OBJECT_EVENT_STARTED, _anim_started_cb, NULL); + + //Register callback called when animation ends + efl_event_callback_add(ad->anim_obj, EFL_ANIMATION_OBJECT_EVENT_ENDED, _anim_ended_cb, ad); + + //Register callback called while animation is executed + efl_event_callback_add(ad->anim_obj, EFL_ANIMATION_OBJECT_EVENT_RUNNING, _anim_running_cb, NULL); + + //Let Animation Object start animation + efl_animation_object_start(ad->anim_obj); +} + +static void +_win_del_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + App_Data *ad = data; + free(ad); +} + +void +test_efl_anim_group_sequential(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + App_Data *ad = calloc(1, sizeof(App_Data)); + if (!ad) return; + + Evas_Object *win = elm_win_add(NULL, "Efl Animation Group Sequential", ELM_WIN_BASIC); + elm_win_title_set(win, "Efl Animation Group Sequential"); + elm_win_autodel_set(win, EINA_TRUE); + evas_object_smart_callback_add(win, "delete,request", _win_del_cb, ad); + + //Button to be animated + Evas_Object *btn = elm_button_add(win); + elm_object_text_set(btn, "Target"); + evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_resize(btn, 150, 150); + evas_object_move(btn, 125, 100); + evas_object_show(btn); + + + /* Animations to hide button */ + //Rotate from 0 to 45 degrees Animation + Efl_Animation *cw_45_degrees_anim = efl_add(EFL_ANIMATION_ROTATE_CLASS, NULL); + efl_animation_rotate_set(cw_45_degrees_anim, 0.0, 45.0, NULL, 0.5, 0.5); + + //Scale Animation to zoom in + Efl_Animation *scale_double_anim = efl_add(EFL_ANIMATION_SCALE_CLASS, NULL); + efl_animation_scale_set(scale_double_anim, 1.0, 1.0, 2.0, 2.0, NULL, 0.5, 0.5); + + //Hide Animation + Efl_Animation *hide_anim = efl_add(EFL_ANIMATION_ALPHA_CLASS, NULL); + efl_animation_alpha_set(hide_anim, 1.0, 0.0); + + //Hide Sequential Group Animation + Efl_Animation *sequential_hide_anim = efl_add(EFL_ANIMATION_GROUP_SEQUENTIAL_CLASS, NULL); + efl_animation_duration_set(sequential_hide_anim, 1.0); + efl_animation_target_set(sequential_hide_anim, btn); + efl_animation_final_state_keep_set(sequential_hide_anim, EINA_TRUE); + + //Add animations to group animation + efl_animation_group_animation_add(sequential_hide_anim, cw_45_degrees_anim); + efl_animation_group_animation_add(sequential_hide_anim, scale_double_anim); + efl_animation_group_animation_add(sequential_hide_anim, hide_anim); + + + /* Animations of initial state to show button */ + //Rotate from 0 to 45 degrees Animation + Efl_Animation *cw_45_degrees_anim2 = efl_add(EFL_ANIMATION_ROTATE_CLASS, NULL); + efl_animation_rotate_set(cw_45_degrees_anim2, 0.0, 45.0, NULL, 0.5, 0.5); + + //Scale Animation to zoom in + Efl_Animation *scale_double_anim2 = efl_add(EFL_ANIMATION_SCALE_CLASS, NULL); + efl_animation_scale_set(scale_double_anim2, 1.0, 1.0, 2.0, 2.0, NULL, 0.5, 0.5); + + //Hide Parallel Group Animation + Efl_Animation *parallel_hide_anim = efl_add(EFL_ANIMATION_GROUP_PARALLEL_CLASS, NULL); + efl_animation_duration_set(parallel_hide_anim, 0.0); + efl_animation_target_set(parallel_hide_anim, btn); + efl_animation_final_state_keep_set(parallel_hide_anim, EINA_TRUE); + + //Add animations to group animation + efl_animation_group_animation_add(parallel_hide_anim, cw_45_degrees_anim2); + efl_animation_group_animation_add(parallel_hide_anim, scale_double_anim2); + + + /* Animations to show button */ + //Show Animation + Efl_Animation *show_anim = efl_add(EFL_ANIMATION_ALPHA_CLASS, NULL); + efl_animation_alpha_set(show_anim, 0.0, 1.0); + efl_animation_duration_set(show_anim, 1.0); + + //Scale Animation to zoom out + Efl_Animation *scale_half_anim = efl_add(EFL_ANIMATION_SCALE_CLASS, NULL); + efl_animation_scale_set(scale_half_anim, 1.0, 1.0, 0.5, 0.5, NULL, 0.5, 0.5); + efl_animation_duration_set(scale_half_anim, 1.0); + + //Rotate from 45 to 0 degrees Animation + Efl_Animation *ccw_45_degrees_anim = efl_add(EFL_ANIMATION_ROTATE_CLASS, NULL); + efl_animation_rotate_set(ccw_45_degrees_anim, 0.0, -45.0, NULL, 0.5, 0.5); + efl_animation_duration_set(ccw_45_degrees_anim, 1.0); + + //Show Sequential Group Animation + Efl_Animation *sequential_show_anim = efl_add(EFL_ANIMATION_GROUP_SEQUENTIAL_CLASS, NULL); + efl_animation_target_set(sequential_show_anim, btn); + efl_animation_final_state_keep_set(sequential_show_anim, EINA_TRUE); + //efl_animation_duration_set() is called for each animation not to set the same duration + + //Add animations to group animation + //First, parallel_hide_anim is added with duration 0 to set the initial state + efl_animation_group_animation_add(sequential_show_anim, parallel_hide_anim); + efl_animation_group_animation_add(sequential_show_anim, show_anim); + efl_animation_group_animation_add(sequential_show_anim, scale_half_anim); + efl_animation_group_animation_add(sequential_show_anim, ccw_45_degrees_anim); + + + //Initialize App Data + ad->sequential_show_anim = sequential_show_anim; + ad->sequential_hide_anim = sequential_hide_anim; + ad->anim_obj = NULL; + ad->is_btn_visible = EINA_TRUE; + + //Button to start animation + Evas_Object *btn2 = elm_button_add(win); + elm_object_text_set(btn2, "Start Sequential Group Animation to hide button"); + evas_object_smart_callback_add(btn2, "clicked", _btn_clicked_cb, ad); + evas_object_size_hint_weight_set(btn2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_resize(btn2, 300, 50); + evas_object_move(btn2, 50, 300); + evas_object_show(btn2); + + evas_object_resize(win, 400, 400); + evas_object_show(win); +} diff --git a/src/lib/evas/Evas_Common.h b/src/lib/evas/Evas_Common.h index 9b6734b9c0..704ef8136c 100644 --- a/src/lib/evas/Evas_Common.h +++ b/src/lib/evas/Evas_Common.h @@ -3379,6 +3379,13 @@ typedef Eo Efl_Animation_Group_Parallel; #endif +#ifndef _EFL_ANIMATION_GROUP_SEQUENTIAL_EO_CLASS_TYPE +#define _EFL_ANIMATION_GROUP_SEQUENTIAL_EO_CLASS_TYPE + +typedef Eo Efl_Animation_Group_Sequential; + +#endif + #ifndef _EFL_ANIMATION_OBJECT_EO_CLASS_TYPE #define _EFL_ANIMATION_OBJECT_EO_CLASS_TYPE @@ -3428,6 +3435,13 @@ typedef Eo Efl_Animation_Group_Parallel; #endif +#ifndef _EFL_ANIMATION_GROUP_SEQUENTIAL_EO_CLASS_TYPE +#define _EFL_ANIMATION_GROUP_SEQUENTIAL_EO_CLASS_TYPE + +typedef Eo Efl_Animation_Group_Sequential; + +#endif + struct _Efl_Animation_Object_Running_Event_Info { double progress; diff --git a/src/lib/evas/Evas_Eo.h b/src/lib/evas/Evas_Eo.h index ad4eed9c6e..44b9fcd5f4 100644 --- a/src/lib/evas/Evas_Eo.h +++ b/src/lib/evas/Evas_Eo.h @@ -62,6 +62,7 @@ #include "canvas/efl_animation_translate.eo.h" #include "canvas/efl_animation_group.eo.h" #include "canvas/efl_animation_group_parallel.eo.h" +#include "canvas/efl_animation_group_sequential.eo.h" #include "canvas/efl_animation_object.eo.h" #include "canvas/efl_animation_object_alpha.eo.h" #include "canvas/efl_animation_object_rotate.eo.h" @@ -69,6 +70,7 @@ #include "canvas/efl_animation_object_translate.eo.h" #include "canvas/efl_animation_object_group.eo.h" #include "canvas/efl_animation_object_group_parallel.eo.h" +#include "canvas/efl_animation_object_group_sequential.eo.h" #endif /* EFL_EO_API_SUPPORT */ diff --git a/src/lib/evas/canvas/efl_animation_group_sequential.c b/src/lib/evas/canvas/efl_animation_group_sequential.c new file mode 100644 index 0000000000..de09fcf703 --- /dev/null +++ b/src/lib/evas/canvas/efl_animation_group_sequential.c @@ -0,0 +1,96 @@ +#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) + { + total_duration += efl_animation_total_duration_get(anim); + } + 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); + + return group_anim_obj; +} + +#include "efl_animation_group_sequential.eo.c" diff --git a/src/lib/evas/canvas/efl_animation_group_sequential.eo b/src/lib/evas/canvas/efl_animation_group_sequential.eo new file mode 100644 index 0000000000..650b017b71 --- /dev/null +++ b/src/lib/evas/canvas/efl_animation_group_sequential.eo @@ -0,0 +1,15 @@ +import efl_animation_types; + +class Efl.Animation.Group.Sequential (Efl.Animation.Group) +{ + [[Efl group sequential animation class]] + data: Efl_Animation_Group_Sequential_Data; + methods { + } + implements { + Efl.Animation.object_create; + Efl.Animation.Group.animation_add; + Efl.Animation.Group.animation_del; + Efl.Animation.total_duration { get; } + } +} diff --git a/src/lib/evas/canvas/efl_animation_group_sequential_private.h b/src/lib/evas/canvas/efl_animation_group_sequential_private.h new file mode 100644 index 0000000000..e944ffdcb0 --- /dev/null +++ b/src/lib/evas/canvas/efl_animation_group_sequential_private.h @@ -0,0 +1,25 @@ +#define EFL_ANIMATION_PROTECTED + +#include "evas_common_private.h" + +#define MY_CLASS EFL_ANIMATION_GROUP_SEQUENTIAL_CLASS +#define MY_CLASS_NAME efl_class_name_get(MY_CLASS) + +#define EFL_ANIMATION_GROUP_SEQUENTIAL_CHECK_OR_RETURN(anim, ...) \ + do { \ + if (!anim) { \ + CRI("Efl_Animation " # anim " is NULL!"); \ + return __VA_ARGS__; \ + } \ + if (efl_animation_is_deleted(anim)) { \ + ERR("Efl_Animation " # anim " has already been deleted!"); \ + return __VA_ARGS__; \ + } \ + } while (0) + +#define EFL_ANIMATION_GROUP_SEQUENTIAL_DATA_GET(o, pd) \ + Efl_Animation_Group_Sequential_Data *pd = efl_data_scope_get(o, EFL_ANIMATION_GROUP_SEQUENTIAL_CLASS) + +typedef struct _Efl_Animation_Group_Sequential_Data +{ +} Efl_Animation_Group_Sequential_Data; diff --git a/src/lib/evas/canvas/efl_animation_object_group_sequential.c b/src/lib/evas/canvas/efl_animation_object_group_sequential.c new file mode 100644 index 0000000000..98f6b1362c --- /dev/null +++ b/src/lib/evas/canvas/efl_animation_object_group_sequential.c @@ -0,0 +1,121 @@ +#include "efl_animation_object_group_sequential_private.h" + +EOLIAN static void +_efl_animation_object_group_sequential_efl_animation_object_group_object_add(Eo *eo_obj, + Efl_Animation_Object_Group_Sequential_Data *pd EINA_UNUSED, + Efl_Animation_Object *anim_obj) +{ + EFL_ANIMATION_OBJECT_GROUP_SEQUENTIAL_CHECK_OR_RETURN(eo_obj); + + if (!anim_obj) return; + + efl_animation_object_group_object_add(efl_super(eo_obj, MY_CLASS), anim_obj); + + /* Total duration is calculated in + * efl_animation_object_total_duration_get() based on the current group + * animation object list. + * Therefore, the calculated total duration should be set to update 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_sequential_efl_animation_object_group_object_del(Eo *eo_obj, + Efl_Animation_Object_Group_Sequential_Data *pd EINA_UNUSED, + Efl_Animation_Object *anim_obj) +{ + EFL_ANIMATION_OBJECT_GROUP_SEQUENTIAL_CHECK_OR_RETURN(eo_obj); + + if (!anim_obj) return; + + efl_animation_object_group_object_del(efl_super(eo_obj, MY_CLASS), anim_obj); + + /* Total duration is calculated in + * efl_animation_object_total_duration_get() based on the current group + * animation object list. + * Therefore, the calculated total duration should be set to update 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 double +_efl_animation_object_group_sequential_efl_animation_object_total_duration_get(Eo *eo_obj, + Efl_Animation_Object_Group_Sequential_Data *pd EINA_UNUSED) +{ + EFL_ANIMATION_OBJECT_GROUP_SEQUENTIAL_CHECK_OR_RETURN(eo_obj, 0.0); + + Eina_List *anim_objs = efl_animation_object_group_objects_get(eo_obj); + if (!anim_objs) return 0.0; + + double total_duration = 0.0; + Eina_List *l; + Efl_Animation *anim_obj; + EINA_LIST_FOREACH(anim_objs, l, anim_obj) + { + total_duration += efl_animation_object_total_duration_get(anim_obj); + } + return total_duration; +} + +EOLIAN static void +_efl_animation_object_group_sequential_efl_animation_object_progress_set(Eo *eo_obj, + Efl_Animation_Object_Group_Sequential_Data *pd EINA_UNUSED, + double progress) +{ + if ((progress < 0.0) || (progress > 1.0)) return; + + Eina_List *anim_objs = efl_animation_object_group_objects_get(eo_obj); + if (!anim_objs) return; + + double group_total_duration = + efl_animation_object_total_duration_get(eo_obj); + + double elapsed_time = progress * group_total_duration; + + double sum_prev_total_duration = 0.0; + + Eina_List *l; + Efl_Animation_Object *anim_obj; + EINA_LIST_FOREACH(anim_objs, l, anim_obj) + { + //Current animation object does not start + if (sum_prev_total_duration > elapsed_time) break; + + //Sum the current total duration + double total_duration = + efl_animation_object_total_duration_get(anim_obj); + double anim_obj_progress; + + if (total_duration == 0.0) + anim_obj_progress = 1.0; + else + { + anim_obj_progress = + (elapsed_time - sum_prev_total_duration) / total_duration; + if (anim_obj_progress > 1.0) + anim_obj_progress = 1.0; + } + + //Update the sum of the previous objects' total durations + sum_prev_total_duration += total_duration; + + if ((anim_obj_progress == 1.0) && + !efl_animation_object_final_state_keep_get(anim_obj)) + continue; + + efl_animation_object_progress_set(anim_obj, anim_obj_progress); + } + + efl_animation_object_progress_set(efl_super(eo_obj, MY_CLASS), progress); +} + +/* Internal EO APIs */ + +#define EFL_ANIMATION_OBJECT_GROUP_SEQUENTIAL_EXTRA_OPS \ + EFL_OBJECT_OP_FUNC(efl_animation_object_group_object_add, _efl_animation_object_group_sequential_efl_animation_object_group_object_add), \ + EFL_OBJECT_OP_FUNC(efl_animation_object_group_object_del, _efl_animation_object_group_sequential_efl_animation_object_group_object_del), \ + EFL_OBJECT_OP_FUNC(efl_animation_object_total_duration_get, _efl_animation_object_group_sequential_efl_animation_object_total_duration_get) + +#include "efl_animation_object_group_sequential.eo.c" diff --git a/src/lib/evas/canvas/efl_animation_object_group_sequential.eo b/src/lib/evas/canvas/efl_animation_object_group_sequential.eo new file mode 100644 index 0000000000..d32841bfb9 --- /dev/null +++ b/src/lib/evas/canvas/efl_animation_object_group_sequential.eo @@ -0,0 +1,12 @@ +import efl_animation_types; + +class Efl.Animation.Object.Group.Sequential (Efl.Animation.Object.Group) +{ + [[Efl group sequential animation object class]] + data: Efl_Animation_Object_Group_Sequential_Data; + methods { + } + implements { + Efl.Animation.Object.progress_set; + } +} diff --git a/src/lib/evas/canvas/efl_animation_object_group_sequential_private.h b/src/lib/evas/canvas/efl_animation_object_group_sequential_private.h new file mode 100644 index 0000000000..fc68a14c0d --- /dev/null +++ b/src/lib/evas/canvas/efl_animation_object_group_sequential_private.h @@ -0,0 +1,25 @@ +#define EFL_ANIMATION_OBJECT_PROTECTED + +#include "evas_common_private.h" + +#define MY_CLASS EFL_ANIMATION_OBJECT_GROUP_SEQUENTIAL_CLASS +#define MY_CLASS_NAME efl_class_name_get(MY_CLASS) + +#define EFL_ANIMATION_OBJECT_GROUP_SEQUENTIAL_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_SEQUENTIAL_DATA_GET(o, pd) \ + Efl_Animation_Object_Group_Sequential_Data *pd = efl_data_scope_get(o, EFL_ANIMATION_OBJECT_GROUP_SEQUENTIAL_CLASS) + +typedef struct _Efl_Animation_Object_Group_Sequential_Data +{ +} Efl_Animation_Object_Group_Sequential_Data; --