efl_animation: Add group animation

Efl.Animation.Group is an abstract class which provides methods for
group animations such as parallel and sequential group animations.
This commit is contained in:
Jaehyun Cho 2017-08-25 17:08:59 +09:00
parent 5a1147d643
commit e1a73fffb9
16 changed files with 323 additions and 10 deletions

View File

@ -49,6 +49,7 @@ evas_eolian_pub_files = \
lib/evas/canvas/efl_animation_rotate.eo \
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_object.eo \
lib/evas/canvas/efl_animation_object_alpha.eo \
lib/evas/canvas/efl_animation_object_rotate.eo \
@ -137,6 +138,7 @@ lib/evas/canvas/efl_animation_alpha_private.h \
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_object_private.h \
lib/evas/canvas/efl_animation_object_alpha_private.h \
lib/evas/canvas/efl_animation_object_rotate_private.h \
@ -232,6 +234,7 @@ lib/evas/canvas/efl_animation_alpha.c \
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_object.c \
lib/evas/canvas/efl_animation_object_alpha.c \
lib/evas/canvas/efl_animation_object_rotate.c \

View File

@ -3365,6 +3365,13 @@ typedef Eo Efl_Animation_Translate;
#endif
#ifndef _EFL_ANIMATION_GROUP_EO_CLASS_TYPE
#define _EFL_ANIMATION_GROUP_EO_CLASS_TYPE
typedef Eo Efl_Animation_Group;
#endif
#ifndef _EFL_ANIMATION_OBJECT_EO_CLASS_TYPE
#define _EFL_ANIMATION_OBJECT_EO_CLASS_TYPE
@ -3405,6 +3412,8 @@ struct _Efl_Animation_Object_Running_Event_Info
double progress;
};
#define EFL_ANIMATION_GROUP_DURATION_NONE -1
/**
* @}
*/

View File

@ -60,6 +60,7 @@
#include "canvas/efl_animation_rotate.eo.h"
#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_object.eo.h"
#include "canvas/efl_animation_object_alpha.eo.h"
#include "canvas/efl_animation_object_rotate.eo.h"

View File

@ -93,6 +93,11 @@ EOAPI Eina_Bool efl_animation_object_final_state_keep_get(const Eo *obj);
EOAPI void efl_animation_object_duration_set(Eo *obj, double duration);
EOAPI double efl_animation_object_duration_get(const Eo *obj);
EOAPI void efl_animation_object_duration_only_set(Eo *obj, double duration);
EOAPI void efl_animation_object_total_duration_set(Eo *obj, double total_duration);
EOAPI double efl_animation_object_total_duration_get(const Eo *obj);
EWAPI extern const Efl_Event_Description _EFL_ANIMATION_OBJECT_EVENT_PRE_STARTED;
#define EFL_ANIMATION_OBJECT_EVENT_PRE_STARTED (&(_EFL_ANIMATION_OBJECT_EVENT_PRE_STARTED))
/* Efl.Animation.Object END */

View File

@ -38,6 +38,8 @@ _efl_animation_duration_set(Eo *eo_obj,
{
EFL_ANIMATION_CHECK_OR_RETURN(eo_obj);
efl_animation_total_duration_set(eo_obj, duration);
pd->duration = duration;
}
@ -49,6 +51,34 @@ _efl_animation_duration_get(Eo *eo_obj, Efl_Animation_Data *pd)
return pd->duration;
}
EOLIAN static void
_efl_animation_duration_only_set(Eo *eo_obj,
Efl_Animation_Data *pd,
double duration)
{
EFL_ANIMATION_CHECK_OR_RETURN(eo_obj);
pd->duration = duration;
}
EOLIAN static void
_efl_animation_total_duration_set(Eo *eo_obj,
Efl_Animation_Data *pd,
double total_duration)
{
EFL_ANIMATION_CHECK_OR_RETURN(eo_obj);
pd->total_duration = total_duration;
}
EOLIAN static double
_efl_animation_total_duration_get(Eo *eo_obj, Efl_Animation_Data *pd)
{
EFL_ANIMATION_CHECK_OR_RETURN(eo_obj, 0.0);
return pd->total_duration;
}
EOLIAN static Eina_Bool
_efl_animation_is_deleted(Eo *eo_obj, Efl_Animation_Data *pd)
{
@ -94,6 +124,9 @@ _efl_animation_object_create(Eo *eo_obj, Efl_Animation_Data *pd EINA_UNUSED)
double duration = efl_animation_duration_get(eo_obj);
efl_animation_object_duration_set(anim_obj, duration);
double total_duration = efl_animation_total_duration_get(eo_obj);
efl_animation_object_total_duration_set(anim_obj, total_duration);
return anim_obj;
}

View File

@ -32,6 +32,21 @@ class Efl.Animation (Efl.Object)
duration: double; [[Duration value.]]
}
}
duration_only_set @protected {
[[Set duration only without setting total duration.]]
params {
@in duration: double; [[Duration value.]]
}
}
@property total_duration {
set @protected {
}
get {
}
values {
total_duration: double; [[Total duration value.]]
}
}
is_deleted @protected {
return: bool; [[$true if animation is deleted, $false otherwise.]]
}

View File

@ -44,6 +44,9 @@ _efl_animation_alpha_efl_animation_object_create(Eo *eo_obj,
double duration = efl_animation_duration_get(eo_obj);
efl_animation_object_duration_set(anim_obj, duration);
double total_duration = efl_animation_total_duration_get(eo_obj);
efl_animation_object_total_duration_set(anim_obj, total_duration);
efl_animation_object_alpha_set(anim_obj, pd->from.alpha, pd->to.alpha);
return anim_obj;

View File

@ -0,0 +1,136 @@
#include "efl_animation_group_private.h"
EOLIAN static void
_efl_animation_group_animation_add(Eo *eo_obj,
Efl_Animation_Group_Data *pd,
Efl_Animation *animation)
{
EFL_ANIMATION_GROUP_CHECK_OR_RETURN(eo_obj);
if (!animation) return;
Efl_Canvas_Object *target = efl_animation_target_get(eo_obj);
if (target)
efl_animation_target_set(animation, target);
double duration = efl_animation_duration_get(eo_obj);
/* if group animation duration is available value, then the duration is
* propagated to its child. */
if (duration != EFL_ANIMATION_GROUP_DURATION_NONE)
efl_animation_duration_set(animation, duration);
Eina_Bool keep_final_state = efl_animation_final_state_keep_get(eo_obj);
efl_animation_final_state_keep_set(animation, keep_final_state);
pd->animations = eina_list_append(pd->animations, animation);
}
EOLIAN static void
_efl_animation_group_animation_del(Eo *eo_obj,
Efl_Animation_Group_Data *pd,
Efl_Animation*animation)
{
EFL_ANIMATION_GROUP_CHECK_OR_RETURN(eo_obj);
if (!animation) return;
pd->animations = eina_list_remove(pd->animations, animation);
}
EOLIAN static Eina_List *
_efl_animation_group_animations_get(Eo *eo_obj,
Efl_Animation_Group_Data *pd)
{
EFL_ANIMATION_GROUP_CHECK_OR_RETURN(eo_obj, NULL);
return pd->animations;
}
EOLIAN static void
_efl_animation_group_efl_animation_target_set(Eo *eo_obj,
Efl_Animation_Group_Data *pd,
Efl_Canvas_Object *target)
{
EFL_ANIMATION_GROUP_CHECK_OR_RETURN(eo_obj);
Eina_List *l;
Efl_Animation *anim;
EINA_LIST_FOREACH(pd->animations, l, anim)
{
efl_animation_target_set(anim, target);
}
efl_animation_target_set(efl_super(eo_obj, MY_CLASS), target);
}
EOLIAN static void
_efl_animation_group_efl_animation_duration_set(Eo *eo_obj,
Efl_Animation_Group_Data *pd,
double duration)
{
EFL_ANIMATION_GROUP_CHECK_OR_RETURN(eo_obj);
if (duration == EFL_ANIMATION_GROUP_DURATION_NONE) goto end;
if (duration < 0.0) return;
Eina_List *l;
Efl_Animation *anim;
EINA_LIST_FOREACH(pd->animations, l, anim)
{
efl_animation_duration_set(anim, duration);
}
end:
efl_animation_duration_only_set(efl_super(eo_obj, MY_CLASS), duration);
//efl_animation_total_duration_get() should calculate the new 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_efl_animation_final_state_keep_set(Eo *eo_obj,
Efl_Animation_Group_Data *pd,
Eina_Bool keep_final_state)
{
EFL_ANIMATION_GROUP_CHECK_OR_RETURN(eo_obj);
Eina_List *l;
Efl_Animation *anim;
EINA_LIST_FOREACH(pd->animations, l, anim)
{
efl_animation_final_state_keep_set(anim, keep_final_state);
}
efl_animation_final_state_keep_set(efl_super(eo_obj, MY_CLASS), keep_final_state);
}
EOLIAN static Efl_Object *
_efl_animation_group_efl_object_constructor(Eo *eo_obj,
Efl_Animation_Group_Data *pd)
{
eo_obj = efl_constructor(efl_super(eo_obj, MY_CLASS));
pd->animations = NULL;
//group animation does not affect its child duration by default.
efl_animation_duration_only_set(efl_super(eo_obj, MY_CLASS),
EFL_ANIMATION_GROUP_DURATION_NONE);
return eo_obj;
}
EOLIAN static void
_efl_animation_group_efl_object_destructor(Eo *eo_obj,
Efl_Animation_Group_Data *pd)
{
Efl_Animation *anim;
EINA_LIST_FREE(pd->animations, anim)
efl_del(anim);
efl_destructor(efl_super(eo_obj, MY_CLASS));
}
#include "efl_animation_group.eo.c"

View File

@ -0,0 +1,32 @@
import efl_animation_types;
abstract Efl.Animation.Group (Efl.Animation)
{
[[Efl group animation abstract class]]
data: Efl_Animation_Group_Data;
methods {
animation_add {
[[Add the given animation to the animation group.]]
params {
@in animation: Efl.Animation; [[The animation which needs to be added to the animation group]]
}
}
animation_del {
[[Delete the given animation from the animation group.]]
params {
@in animation: Efl.Animation; [[The animation which needs to be deleted from the animation group]]
}
}
animations_get {
[[Get the animations of the animation group.]]
return: list<Efl.Animation>; [[The animations of the animation group]]
}
}
implements {
Efl.Object.constructor;
Efl.Object.destructor;
Efl.Animation.target { set; }
Efl.Animation.duration { set; }
Efl.Animation.final_state_keep { set; }
}
}

View File

@ -0,0 +1,26 @@
#define EFL_ANIMATION_PROTECTED
#include "evas_common_private.h"
#define MY_CLASS EFL_ANIMATION_GROUP_CLASS
#define MY_CLASS_NAME efl_class_name_get(MY_CLASS)
#define EFL_ANIMATION_GROUP_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_DATA_GET(o, pd) \
Efl_Animation_Group_Data *pd = efl_data_scope_get(o, EFL_ANIMATION_GROUP_CLASS)
typedef struct _Efl_Animation_Group_Data
{
Eina_List *animations;
} Efl_Animation_Group_Data;

View File

@ -63,6 +63,8 @@ _efl_animation_object_duration_set(Eo *eo_obj,
{
EFL_ANIMATION_OBJECT_CHECK_OR_RETURN(eo_obj);
efl_animation_object_total_duration_set(eo_obj, duration);
pd->duration = duration;
}
@ -75,6 +77,34 @@ _efl_animation_object_duration_get(Eo *eo_obj,
return pd->duration;
}
EOLIAN static void
_efl_animation_object_duration_only_set(Eo *eo_obj,
Efl_Animation_Object_Data *pd,
double duration)
{
EFL_ANIMATION_OBJECT_CHECK_OR_RETURN(eo_obj);
pd->duration = duration;
}
EOLIAN static void
_efl_animation_object_total_duration_set(Eo *eo_obj,
Efl_Animation_Object_Data *pd,
double total_duration)
{
EFL_ANIMATION_OBJECT_CHECK_OR_RETURN(eo_obj);
pd->total_duration = total_duration;
}
EOLIAN static double
_efl_animation_object_total_duration_get(Eo *eo_obj, Efl_Animation_Object_Data *pd)
{
EFL_ANIMATION_OBJECT_CHECK_OR_RETURN(eo_obj, 0.0);
return pd->total_duration;
}
EOLIAN static Eina_Bool
_efl_animation_object_is_deleted(Eo *eo_obj,
Efl_Animation_Object_Data *pd)
@ -181,17 +211,17 @@ _animator_cb(void *data)
if (pd->is_cancelled) goto end;
double elapsed_time, duration;
double elapsed_time, total_duration;
pd->time.current = ecore_loop_time_get();
elapsed_time = pd->time.current - pd->time.begin;
duration = pd->duration;
if (elapsed_time > duration)
elapsed_time = duration;
total_duration = pd->total_duration;
if (elapsed_time > total_duration)
elapsed_time = total_duration;
if (duration < 0.0) goto end;
if (total_duration < 0.0) goto end;
if (duration == 0.0)
if (total_duration == 0.0)
{
ecore_animator_del(pd->animator);
pd->animator = NULL;
@ -199,7 +229,7 @@ _animator_cb(void *data)
pd->progress = 1.0;
}
else
pd->progress = elapsed_time / duration;
pd->progress = elapsed_time / total_duration;
//Reset previous animation effect before applying animation effect
efl_animation_object_target_state_reset(eo_obj);
@ -207,7 +237,7 @@ _animator_cb(void *data)
efl_animation_object_progress_set(eo_obj, pd->progress);
//Not end. Keep going.
if (elapsed_time < duration) return ECORE_CALLBACK_RENEW;
if (elapsed_time < total_duration) return ECORE_CALLBACK_RENEW;
end:
pd->animator = NULL;
@ -226,7 +256,7 @@ end:
static void
_start(Eo *eo_obj, Efl_Animation_Object_Data *pd)
{
if (pd->duration < 0.0) return;
if (pd->total_duration < 0.0) return;
//Save the current state of the target
efl_animation_object_target_state_save(eo_obj);
@ -311,6 +341,7 @@ _efl_animation_object_efl_object_constructor(Eo *eo_obj,
pd->progress = 0.0;
pd->duration = 0.0;
pd->total_duration = 0.0;
pd->auto_del = EINA_TRUE;
pd->is_deleted = EINA_FALSE;
@ -358,13 +389,21 @@ EOAPI EFL_FUNC_BODY_CONST(efl_animation_object_final_state_keep_get, Eina_Bool,
EOAPI EFL_VOID_FUNC_BODYV(efl_animation_object_duration_set, EFL_FUNC_CALL(duration), double duration);
EOAPI EFL_FUNC_BODY_CONST(efl_animation_object_duration_get, double, 0);
EOAPI EFL_VOID_FUNC_BODYV(efl_animation_object_duration_only_set, EFL_FUNC_CALL(duration), double duration);
EOAPI EFL_VOID_FUNC_BODYV(efl_animation_object_total_duration_set, EFL_FUNC_CALL(total_duration), double total_duration);
EOAPI EFL_FUNC_BODY_CONST(efl_animation_object_total_duration_get, double, 0);
#define EFL_ANIMATION_OBJECT_EXTRA_OPS \
EFL_OBJECT_OP_FUNC(efl_animation_object_target_set, _efl_animation_object_target_set), \
EFL_OBJECT_OP_FUNC(efl_animation_object_target_get, _efl_animation_object_target_get), \
EFL_OBJECT_OP_FUNC(efl_animation_object_final_state_keep_set, _efl_animation_object_final_state_keep_set), \
EFL_OBJECT_OP_FUNC(efl_animation_object_final_state_keep_get, _efl_animation_object_final_state_keep_get), \
EFL_OBJECT_OP_FUNC(efl_animation_object_duration_set, _efl_animation_object_duration_set), \
EFL_OBJECT_OP_FUNC(efl_animation_object_duration_get, _efl_animation_object_duration_get)
EFL_OBJECT_OP_FUNC(efl_animation_object_duration_get, _efl_animation_object_duration_get), \
EFL_OBJECT_OP_FUNC(efl_animation_object_duration_only_set, _efl_animation_object_duration_only_set), \
EFL_OBJECT_OP_FUNC(efl_animation_object_total_duration_set, _efl_animation_object_total_duration_set), \
EFL_OBJECT_OP_FUNC(efl_animation_object_total_duration_get, _efl_animation_object_total_duration_get)
EWAPI const Efl_Event_Description _EFL_ANIMATION_OBJECT_EVENT_PRE_STARTED =
EFL_EVENT_DESCRIPTION("pre_started");

View File

@ -30,6 +30,7 @@ typedef struct _Efl_Animation_Object_Data
double progress;
double duration;
double total_duration;
Eina_Bool auto_del : 1;
Eina_Bool is_deleted : 1;

View File

@ -10,6 +10,7 @@ typedef struct _Efl_Animation_Data
Efl_Canvas_Object *target;
double duration;
double total_duration;
Eina_Bool is_deleted : 1;
Eina_Bool keep_final_state : 1;

View File

@ -192,6 +192,9 @@ _efl_animation_rotate_efl_animation_object_create(Eo *eo_obj,
double duration = efl_animation_duration_get(eo_obj);
efl_animation_object_duration_set(anim_obj, duration);
double total_duration = efl_animation_total_duration_get(eo_obj);
efl_animation_object_total_duration_set(anim_obj, total_duration);
if (pd->use_rel_pivot)
{
efl_animation_object_rotate_set(anim_obj,

View File

@ -218,6 +218,9 @@ _efl_animation_scale_efl_animation_object_create(Eo *eo_obj,
double duration = efl_animation_duration_get(eo_obj);
efl_animation_object_duration_set(anim_obj, duration);
double total_duration = efl_animation_total_duration_get(eo_obj);
efl_animation_object_total_duration_set(anim_obj, total_duration);
if (pd->use_rel_pivot)
{
efl_animation_object_scale_set(anim_obj,

View File

@ -160,6 +160,9 @@ _efl_animation_translate_efl_animation_object_create(Eo *eo_obj,
double duration = efl_animation_duration_get(eo_obj);
efl_animation_object_duration_set(anim_obj, duration);
double total_duration = efl_animation_total_duration_get(eo_obj);
efl_animation_object_total_duration_set(anim_obj, total_duration);
if (pd->use_rel_move)
{
efl_animation_object_translate_set(anim_obj,