efl_animation: Add parallel group animation and object

Efl.Animation.Group.Parallel is a class for animations started in
parallel.
Efl.Animation.Object.Group.Parallel is a class which provides methods
for an object of Efl.Animation.Group.Parallel.
The objects added into the parallel group animation object start in
parallel.
This commit is contained in:
Jaehyun Cho 2017-08-25 17:54:29 +09:00
parent 861a90415c
commit 923a5b02eb
13 changed files with 484 additions and 1 deletions

View File

@ -801,6 +801,7 @@ bin/elementary/test_efl_anim_alpha.c \
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_eio.c \
bin/elementary/test_entry.c \
bin/elementary/test_entry_anchor.c \

View File

@ -50,12 +50,14 @@ evas_eolian_pub_files = \
lib/evas/canvas/efl_animation_scale.eo \
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_object.eo \
lib/evas/canvas/efl_animation_object_alpha.eo \
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 \
lib/evas/canvas/efl_animation_object_group_parallel.eo \
$(NULL)
evas_eolian_legacy_files = \
@ -140,12 +142,14 @@ lib/evas/canvas/efl_animation_rotate_private.h \
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_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_private.h \
lib/evas/canvas/efl_animation_object_group_parallel_private.h
# Linebreak
@ -237,12 +241,14 @@ lib/evas/canvas/efl_animation_rotate.c \
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_object.c \
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 \
lib/evas/canvas/efl_animation_object_group_parallel.c \
$(NULL)
EXTRA_DIST2 += \

View File

@ -36,6 +36,7 @@ test_efl_anim_alpha.c \
test_efl_anim_rotate.c \
test_efl_anim_scale.c \
test_efl_anim_translate.c \
test_efl_anim_group_parallel.c \
test_application_server.c \
test_bg.c \
test_box.c \

View File

@ -331,6 +331,7 @@ void test_efl_anim_scale_relative(void *data, Evas_Object *obj, void *event_info
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);
Evas_Object *win, *tbx; // TODO: refactoring
void *tt;
@ -809,6 +810,7 @@ add_tests:
ADD_TEST(NULL, "Effects", "Efl Animation Scale Absolute", test_efl_anim_scale_absolute);
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, "Edje External", "ExtButton", test_external_button);

View File

@ -0,0 +1,167 @@
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#include <Elementary.h>
typedef struct _App_Data
{
Efl_Animation *parallel_show_anim;
Efl_Animation *parallel_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->parallel_show_anim);
elm_object_text_set(obj, "Start Parallel Group Animation to hide button");
}
else
{
//Create Animation Object from Animation
ad->anim_obj = efl_animation_object_create(ad->parallel_hide_anim);
elm_object_text_set(obj, "Start Parallel 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_parallel(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 Parallel", ELM_WIN_BASIC);
elm_win_title_set(win, "Efl Animation Group Parallel");
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);
//Show Animation
Efl_Animation *show_anim = efl_add(EFL_ANIMATION_ALPHA_CLASS, NULL);
efl_animation_alpha_set(show_anim, 0.0, 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, 45.0, 0.0, NULL, 0.5, 0.5);
//Scale Animation to zoom out
Efl_Animation *scale_half_anim = efl_add(EFL_ANIMATION_SCALE_CLASS, NULL);
efl_animation_scale_set(scale_half_anim, 2.0, 2.0, 1.0, 1.0, NULL, 0.5, 0.5);
//Show Parallel Group Animation
Efl_Animation *parallel_show_anim = efl_add(EFL_ANIMATION_GROUP_PARALLEL_CLASS, NULL);
efl_animation_duration_set(parallel_show_anim, 1.0);
efl_animation_target_set(parallel_show_anim, btn);
efl_animation_final_state_keep_set(parallel_show_anim, EINA_TRUE);
//Add animations to group animation
efl_animation_group_animation_add(parallel_show_anim, show_anim);
efl_animation_group_animation_add(parallel_show_anim, ccw_45_degrees_anim);
efl_animation_group_animation_add(parallel_show_anim, scale_half_anim);
//Hide Animation
Efl_Animation *hide_anim = efl_add(EFL_ANIMATION_ALPHA_CLASS, NULL);
efl_animation_alpha_set(hide_anim, 1.0, 0.0);
//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 Parallel Group Animation
Efl_Animation *parallel_hide_anim = efl_add(EFL_ANIMATION_GROUP_PARALLEL_CLASS, NULL);
efl_animation_duration_set(parallel_hide_anim, 1.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, hide_anim);
efl_animation_group_animation_add(parallel_hide_anim, cw_45_degrees_anim);
efl_animation_group_animation_add(parallel_hide_anim, scale_double_anim);
//Initialize App Data
ad->parallel_show_anim = parallel_show_anim;
ad->parallel_hide_anim = parallel_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 Parallel 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);
}

View File

@ -3372,6 +3372,13 @@ typedef Eo Efl_Animation_Group;
#endif
#ifndef _EFL_ANIMATION_GROUP_PARALLEL_EO_CLASS_TYPE
#define _EFL_ANIMATION_GROUP_PARALLEL_EO_CLASS_TYPE
typedef Eo Efl_Animation_Group_Parallel;
#endif
#ifndef _EFL_ANIMATION_OBJECT_EO_CLASS_TYPE
#define _EFL_ANIMATION_OBJECT_EO_CLASS_TYPE
@ -3414,6 +3421,13 @@ typedef Eo Efl_Animation_Object_Group;
#endif
#ifndef _EFL_ANIMATION_GROUP_PARALLEL_EO_CLASS_TYPE
#define _EFL_ANIMATION_GROUP_PARALLEL_EO_CLASS_TYPE
typedef Eo Efl_Animation_Group_Parallel;
#endif
struct _Efl_Animation_Object_Running_Event_Info
{
double progress;

View File

@ -61,12 +61,14 @@
#include "canvas/efl_animation_scale.eo.h"
#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_object.eo.h"
#include "canvas/efl_animation_object_alpha.eo.h"
#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"
#include "canvas/efl_animation_object_group_parallel.eo.h"
#endif /* EFL_EO_API_SUPPORT */

View File

@ -0,0 +1,103 @@
#include "efl_animation_group_parallel_private.h"
EOLIAN static void
_efl_animation_group_parallel_efl_animation_group_animation_add(Eo *eo_obj,
Efl_Animation_Group_Parallel_Data *pd EINA_UNUSED,
Efl_Animation *animation)
{
EFL_ANIMATION_GROUP_PARALLEL_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_parallel_efl_animation_group_animation_del(Eo *eo_obj,
Efl_Animation_Group_Parallel_Data *pd EINA_UNUSED,
Efl_Animation *animation)
{
EFL_ANIMATION_GROUP_PARALLEL_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_parallel_efl_animation_total_duration_get(Eo *eo_obj,
Efl_Animation_Group_Parallel_Data *pd EINA_UNUSED)
{
EFL_ANIMATION_GROUP_PARALLEL_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);
if (child_total_duration > total_duration)
total_duration = child_total_duration;
}
return total_duration;
}
EOLIAN static Efl_Animation_Object *
_efl_animation_group_parallel_efl_animation_object_create(Eo *eo_obj,
Efl_Animation_Group_Parallel_Data *pd EINA_UNUSED)
{
EFL_ANIMATION_GROUP_PARALLEL_CHECK_OR_RETURN(eo_obj, NULL);
Efl_Animation_Object_Group_Parallel *group_anim_obj
= efl_add(EFL_ANIMATION_OBJECT_GROUP_PARALLEL_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_parallel.eo.c"

View File

@ -0,0 +1,15 @@
import efl_animation_types;
class Efl.Animation.Group.Parallel (Efl.Animation.Group)
{
[[Efl group parallel animation class]]
data: Efl_Animation_Group_Parallel_Data;
methods {
}
implements {
Efl.Animation.object_create;
Efl.Animation.Group.animation_add;
Efl.Animation.Group.animation_del;
Efl.Animation.total_duration { get; }
}
}

View File

@ -0,0 +1,25 @@
#define EFL_ANIMATION_PROTECTED
#include "evas_common_private.h"
#define MY_CLASS EFL_ANIMATION_GROUP_PARALLEL_CLASS
#define MY_CLASS_NAME efl_class_name_get(MY_CLASS)
#define EFL_ANIMATION_GROUP_PARALLEL_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_PARALLEL_DATA_GET(o, pd) \
Efl_Animation_Group_Parallel_Data *pd = efl_data_scope_get(o, EFL_ANIMATION_GROUP_PARALLEL_CLASS)
typedef struct _Efl_Animation_Group_Parallel_Data
{
} Efl_Animation_Group_Parallel_Data;

View File

@ -0,0 +1,110 @@
#include "efl_animation_object_group_parallel_private.h"
EOLIAN static void
_efl_animation_object_group_parallel_efl_animation_object_group_object_add(Eo *eo_obj,
Efl_Animation_Object_Group_Parallel_Data *pd EINA_UNUSED,
Efl_Animation_Object *anim_obj)
{
EFL_ANIMATION_OBJECT_GROUP_PARALLEL_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_parallel_efl_animation_object_group_object_del(Eo *eo_obj,
Efl_Animation_Object_Group_Parallel_Data *pd EINA_UNUSED,
Efl_Animation_Object *anim_obj)
{
EFL_ANIMATION_OBJECT_GROUP_PARALLEL_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_parallel_efl_animation_object_total_duration_get(Eo *eo_obj,
Efl_Animation_Object_Group_Parallel_Data *pd EINA_UNUSED)
{
EFL_ANIMATION_OBJECT_GROUP_PARALLEL_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)
{
double child_total_duration =
efl_animation_object_total_duration_get(anim_obj);
if (child_total_duration > total_duration)
total_duration = child_total_duration;
}
return total_duration;
}
EOLIAN static void
_efl_animation_object_group_parallel_efl_animation_object_progress_set(Eo *eo_obj,
Efl_Animation_Object_Group_Parallel_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;
Eina_List *l;
Efl_Animation_Object *anim_obj;
EINA_LIST_FOREACH(anim_objs, l, anim_obj)
{
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 / total_duration;
if (anim_obj_progress > 1.0)
anim_obj_progress = 1.0;
}
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_PARALLEL_EXTRA_OPS \
EFL_OBJECT_OP_FUNC(efl_animation_object_group_object_add, _efl_animation_object_group_parallel_efl_animation_object_group_object_add), \
EFL_OBJECT_OP_FUNC(efl_animation_object_group_object_del, _efl_animation_object_group_parallel_efl_animation_object_group_object_del), \
EFL_OBJECT_OP_FUNC(efl_animation_object_total_duration_get, _efl_animation_object_group_parallel_efl_animation_object_total_duration_get)
#include "efl_animation_object_group_parallel.eo.c"

View File

@ -0,0 +1,12 @@
import efl_animation_types;
class Efl.Animation.Object.Group.Parallel (Efl.Animation.Object.Group)
{
[[Efl group parallel animation object class]]
data: Efl_Animation_Object_Group_Parallel_Data;
methods {
}
implements {
Efl.Animation.Object.progress_set;
}
}

View File

@ -0,0 +1,25 @@
#define EFL_ANIMATION_OBJECT_PROTECTED
#include "evas_common_private.h"
#define MY_CLASS EFL_ANIMATION_OBJECT_GROUP_PARALLEL_CLASS
#define MY_CLASS_NAME efl_class_name_get(MY_CLASS)
#define EFL_ANIMATION_OBJECT_GROUP_PARALLEL_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_PARALLEL_DATA_GET(o, pd) \
Efl_Animation_Object_Group_Parallel_Data *pd = efl_data_scope_get(o, EFL_ANIMATION_OBJECT_GROUP_PARALLEL_CLASS)
typedef struct _Efl_Animation_Object_Group_Parallel_Data
{
} Efl_Animation_Object_Group_Parallel_Data;