efl_animation: Support event animation

Register an animation for an event.
Start the animation when the event happens.
This commit is contained in:
Jaehyun Cho 2017-08-30 16:16:18 +09:00
parent 4112a68e32
commit a6e03da5f0
9 changed files with 475 additions and 1 deletions

View File

@ -803,6 +803,7 @@ 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_efl_anim_event_anim.c \
bin/elementary/test_eio.c \
bin/elementary/test_entry.c \
bin/elementary/test_entry_anchor.c \

View File

@ -38,6 +38,7 @@ test_efl_anim_scale.c \
test_efl_anim_translate.c \
test_efl_anim_group_parallel.c \
test_efl_anim_group_sequential.c \
test_efl_anim_event_anim.c \
test_application_server.c \
test_bg.c \
test_box.c \

View File

@ -333,6 +333,7 @@ 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);
void test_efl_anim_event_anim(void *data, Evas_Object *obj, void *event_info);
Evas_Object *win, *tbx; // TODO: refactoring
void *tt;
@ -813,6 +814,7 @@ add_tests:
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, "Effects", "Efl Animation Event Animation", test_efl_anim_event_anim);
//------------------------------//
ADD_TEST(NULL, "Edje External", "ExtButton", test_external_button);

View File

@ -0,0 +1,91 @@
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#include <Elementary.h>
typedef struct _App_Data
{
Efl_Animation_Object *target;
Eina_Bool is_btn_visible;
} App_Data;
static void
_btn_clicked_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
App_Data *ad = data;
ad->is_btn_visible = !(ad->is_btn_visible);
if (ad->is_btn_visible)
{
//Start animtion by showing button
evas_object_show(ad->target);
elm_object_text_set(obj, "Hide Button");
}
else
{
//Start animtion by hiding button
evas_object_hide(ad->target);
elm_object_text_set(obj, "Show Button");
}
}
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_event_anim(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 Event Animation", ELM_WIN_BASIC);
elm_win_title_set(win, "Efl Animation Event Animation");
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, "Button");
evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_resize(btn, 200, 200);
evas_object_move(btn, 100, 50);
//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);
efl_animation_target_set(show_anim, btn);
efl_canvas_object_event_animation_set(btn, EFL_ANIMATION_EVENT_TYPE_SHOW, show_anim);
//Show button after setting event animation to show animation for show event
evas_object_show(btn);
//Hide Animation
Efl_Animation *hide_anim = efl_add(EFL_ANIMATION_ALPHA_CLASS, NULL);
efl_animation_alpha_set(hide_anim, 1.0, 0.0);
efl_animation_duration_set(hide_anim, 1.0);
efl_animation_target_set(hide_anim, btn);
efl_canvas_object_event_animation_set(btn, EFL_ANIMATION_EVENT_TYPE_HIDE, hide_anim);
//Initialize App Data
ad->target = btn;
ad->is_btn_visible = EINA_TRUE;
//Button to start animation
Evas_Object *btn2 = elm_button_add(win);
elm_object_text_set(btn2, "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, 200, 50);
evas_object_move(btn2, 100, 300);
evas_object_show(btn2);
evas_object_resize(win, 400, 400);
evas_object_show(win);
}

View File

@ -2,3 +2,12 @@
// All the below types are for Efl Animation
struct Efl.Animation.Object.Running_Event_Info; [[Information of running event]]
enum Efl.Animation.Event_Type
{
[[Animation event type]]
show = 0, [["show" event type]]
hide = 1, [["hide" event type]]
clicked = 2 [["clicked" event type]]
}

View File

@ -1,4 +1,5 @@
import efl_text_types;
import efl_animation_types;
abstract Efl.Canvas.Object (Efl.Object, Efl.Gfx, Efl.Gfx.Stack, Efl.Animator,
Efl.Input.Interface, Efl.Gfx.Size.Hint,
@ -656,6 +657,22 @@ abstract Efl.Canvas.Object (Efl.Object, Efl.Gfx, Efl.Gfx.Stack, Efl.Animator,
}
return: bool @warn_unused; [[$true if the coords are inside the object, $false otherwise]]
}
event_animation_set {
[[Set the $animation which starts when the given $event_name happens to the object.]]
params {
@in event_type: Efl.Animation.Event_Type; [[The event type the given $animation is set for.]]
@in animation: Efl.Animation; [[The animation which starts when the given $event_name happens to the object.]]
}
legacy: null;
}
event_animation_get {
[[Get the $animation which starts when the given $event happens to the object.]]
params {
@in event_type: Efl.Animation.Event_Type; [[The event type the given $animation is set for.]]
}
legacy: null;
return: Efl.Animation @warn_unused;
}
}
implements {
Efl.Object.constructor;

View File

@ -101,7 +101,18 @@ _evas_object_intercept_call_internal(Evas_Object *eo_obj,
case EVAS_OBJECT_INTERCEPT_CB_VISIBLE:
i = !!va_arg(args, int);
if (!obj->legacy.visible_set) obj->legacy.visible_set = 1;
if (i == obj->cur->visible) return 1;
if (i == obj->cur->visible)
{
/* If show is called during hide animation is running, then the
* current hide animation is cancelled and show operation is
* proceeded. */
if (i &&
_efl_canvas_object_event_animation_is_running(eo_obj,
EFL_ANIMATION_EVENT_TYPE_HIDE))
_efl_canvas_object_event_animation_cancel(eo_obj);
else
return 1;
}
if (!obj->interceptors) return 0;
if (i) blocked = evas_object_intercept_call_show(eo_obj, obj);
else blocked = evas_object_intercept_call_hide(eo_obj, obj);

View File

@ -46,6 +46,19 @@ Eina_Cow *evas_object_3d_cow = NULL;
Eina_Cow *evas_object_mask_cow = NULL;
Eina_Cow *evas_object_events_cow = NULL;
typedef struct _Event_Animation
{
Efl_Animation *anim;
Efl_Animation_Object *anim_obj;
} Event_Animation;
typedef struct _Hide_Anim_Data
{
Efl_Canvas_Object *target;
Eina_Bool anim_started;
Eina_Bool anim_ended;
} Hide_Anim_Data;
static Eina_Bool
_init_cow(void)
{
@ -164,6 +177,33 @@ _evas_object_pointer_data_get(Evas_Pointer_Data *evas_pdata,
return pdata;
}
static void
_init_event_anims(Evas_Object_Protected_Data *obj)
{
obj->event_anims = eina_array_new(EFL_ANIMATION_EVENT_TYPE_COUNT);
int i;
for (i = 0; i < EFL_ANIMATION_EVENT_TYPE_COUNT; i++)
{
Event_Animation *event_anims = calloc(1, sizeof(Event_Animation));
eina_array_push(obj->event_anims, event_anims);
}
}
static void
_free_event_anims(Evas_Object_Protected_Data *obj)
{
int i;
for (i = 0; i < EFL_ANIMATION_EVENT_TYPE_COUNT; i++)
{
Event_Animation *event_anims = eina_array_pop(obj->event_anims);
if (event_anims) free(event_anims);
}
eina_array_free(obj->event_anims);
obj->event_anims = NULL;
}
EOLIAN static Eo *
_efl_canvas_object_efl_object_constructor(Eo *eo_obj, Evas_Object_Protected_Data *obj)
{
@ -192,6 +232,7 @@ _efl_canvas_object_efl_object_constructor(Eo *eo_obj, Evas_Object_Protected_Data
obj->data_3d = eina_cow_alloc(evas_object_3d_cow);
obj->mask = eina_cow_alloc(evas_object_mask_cow);
obj->events = eina_cow_alloc(evas_object_events_cow);
_init_event_anims(obj);
evas_object_inject(eo_obj, obj, evas);
evas_object_callback_init(eo_obj, obj);
@ -502,6 +543,7 @@ evas_object_free(Evas_Object *eo_obj, Eina_Bool clean_layer)
eina_cow_free(evas_object_3d_cow, (const Eina_Cow_Data**) &obj->data_3d);
eina_cow_free(evas_object_mask_cow, (const Eina_Cow_Data**) &obj->mask);
eina_cow_free(evas_object_events_cow, (const Eina_Cow_Data**) &obj->events);
_free_event_anims(obj);
efl_data_unref(eo_obj, obj->private_data);
obj->private_data = NULL;
@ -1028,6 +1070,81 @@ _is_event_blocked(Eo *eo_obj, const Efl_Event_Description *desc,
return EINA_FALSE;
}
static Eina_Bool
_efl_animation_event_type_is_inform_call(Efl_Animation_Event_Type event)
{
if ((event == EFL_ANIMATION_EVENT_TYPE_SHOW) ||
(event == EFL_ANIMATION_EVENT_TYPE_HIDE))
return EINA_TRUE;
return EINA_FALSE;
}
//These macros are matched to Efl_Animation_Event_Type enum values.
#define EFL_ANIMATION_EVENT_TYPE_SHOW_STR "show"
#define EFL_ANIMATION_EVENT_TYPE_HIDE_STR "hide"
#define EFL_ANIMATION_EVENT_TYPE_CLICKED_STR "clicked"
static Efl_Animation_Event_Type
_efl_animation_event_type_get(const char *event_str)
{
if (!event_str) return -1;
if (!strncmp(event_str, EFL_ANIMATION_EVENT_TYPE_SHOW_STR,
strlen(EFL_ANIMATION_EVENT_TYPE_SHOW_STR)))
return EFL_ANIMATION_EVENT_TYPE_SHOW;
else if (!strncmp(event_str, EFL_ANIMATION_EVENT_TYPE_HIDE_STR,
strlen(EFL_ANIMATION_EVENT_TYPE_HIDE_STR)))
return EFL_ANIMATION_EVENT_TYPE_HIDE;
else if (!strncmp(event_str, EFL_ANIMATION_EVENT_TYPE_CLICKED_STR,
strlen(EFL_ANIMATION_EVENT_TYPE_CLICKED_STR)))
return EFL_ANIMATION_EVENT_TYPE_CLICKED;
return -1;
}
static Eina_Bool
_efl_animation_event_type_is_valid(Efl_Animation_Event_Type event)
{
if ((event < 0) || (event >= EFL_ANIMATION_EVENT_TYPE_COUNT))
return EINA_FALSE;
return EINA_TRUE;
}
static Efl_Animation_Object *
_event_animation_object_get(Eo *eo_obj, Efl_Animation_Event_Type event_type)
{
Evas_Object_Protected_Data *pd = efl_data_scope_get(eo_obj, MY_CLASS);
if (!pd) return NULL;
if (!_efl_animation_event_type_is_valid(event_type))
return NULL;
Event_Animation *event_anim = eina_array_data_get(pd->event_anims,
event_type);
if (event_anim && event_anim->anim_obj)
return event_anim->anim_obj;
return NULL;
}
static void
_all_animation_objects_cancel(Eo *eo_obj)
{
Efl_Animation_Event_Type event_type;
for (event_type = EFL_ANIMATION_EVENT_TYPE_SHOW;
event_type < EFL_ANIMATION_EVENT_TYPE_COUNT; event_type++)
{
Efl_Animation_Object *anim_obj =
_event_animation_object_get(eo_obj, event_type);
if (anim_obj)
efl_animation_object_cancel(anim_obj);
}
}
EOLIAN static Eina_Bool
_efl_canvas_object_efl_object_event_callback_call(Eo *eo_obj,
Evas_Object_Protected_Data *obj EINA_UNUSED,
@ -1035,6 +1152,25 @@ _efl_canvas_object_efl_object_event_callback_call(Eo *eo_obj,
void *event_info)
{
if (_is_event_blocked(eo_obj, desc, event_info)) return EINA_FALSE;
//Start animation corresponding to the current event
if (desc && desc->name)
{
Efl_Animation_Event_Type event_type =
_efl_animation_event_type_get(desc->name);
if (!_efl_animation_event_type_is_inform_call(event_type))
{
Efl_Animation_Object *anim_obj =
_event_animation_object_get(eo_obj, event_type);
if (anim_obj)
{
_all_animation_objects_cancel(eo_obj);
efl_animation_object_start(anim_obj);
}
}
}
return efl_event_callback_call(efl_super(eo_obj, MY_CLASS),
desc, event_info);
}
@ -1046,6 +1182,25 @@ _efl_canvas_object_efl_object_event_callback_legacy_call(Eo *eo_obj,
void *event_info)
{
if (_is_event_blocked(eo_obj, desc, event_info)) return EINA_FALSE;
//Start animation corresponding to the current event
if (desc && desc->name)
{
Efl_Animation_Event_Type event_type =
_efl_animation_event_type_get(desc->name);
if (!_efl_animation_event_type_is_inform_call(event_type))
{
Efl_Animation_Object *anim_obj =
_event_animation_object_get(eo_obj, event_type);
if (anim_obj)
{
_all_animation_objects_cancel(eo_obj);
efl_animation_object_start(anim_obj);
}
}
}
return efl_event_callback_legacy_call(efl_super(eo_obj, MY_CLASS),
desc, event_info);
}
@ -1065,6 +1220,15 @@ _efl_canvas_object_efl_object_destructor(Eo *eo_obj, Evas_Object_Protected_Data
int event_id;
edata = efl_data_scope_get(evas_object_evas_get(eo_obj), EVAS_CANVAS_CLASS);
//Unset event animations
efl_canvas_object_event_animation_set(eo_obj, EFL_ANIMATION_EVENT_TYPE_SHOW,
NULL);
efl_canvas_object_event_animation_set(eo_obj, EFL_ANIMATION_EVENT_TYPE_HIDE,
NULL);
efl_canvas_object_event_animation_set(eo_obj,
EFL_ANIMATION_EVENT_TYPE_CLICKED,
NULL);
evas_object_hide(eo_obj);
if (obj->events) EINA_COW_WRITE_BEGIN(evas_object_events_cow, obj->events, Evas_Object_Events_Data, events)
@ -1689,6 +1853,39 @@ evas_object_hide(Evas_Object *eo_obj)
efl_gfx_visible_set(eo_obj, EINA_FALSE);
}
static void _animation_intercept_hide(void *data, Evas_Object *eo_obj);
static void
_animation_hide_end_cb(void *data, const Efl_Event *event EINA_UNUSED)
{
Hide_Anim_Data *hide_anim_data = data;
hide_anim_data->anim_ended = EINA_TRUE;
_animation_intercept_hide(hide_anim_data, hide_anim_data->target);
hide_anim_data->anim_started = EINA_FALSE;
hide_anim_data->anim_ended = EINA_FALSE;
}
static void
_animation_intercept_hide(void *data, Evas_Object *eo_obj)
{
Hide_Anim_Data *hide_anim_data = data;
Efl_Animation_Object *anim_obj =
_event_animation_object_get(eo_obj, EFL_ANIMATION_EVENT_TYPE_HIDE);
if (anim_obj && !hide_anim_data->anim_started && !hide_anim_data->anim_ended)
{
hide_anim_data->anim_started = EINA_TRUE;
_all_animation_objects_cancel(eo_obj);
efl_animation_object_start(anim_obj);
}
else
efl_gfx_visible_set(eo_obj, EINA_FALSE);
}
EAPI Eina_Bool
evas_object_visible_get(const Evas_Object *obj)
{
@ -1730,6 +1927,15 @@ _show(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj)
}
evas_object_update_bounding_box(eo_obj, obj, NULL);
evas_object_inform_call_show(eo_obj);
//Start animation
Efl_Animation_Object *anim_obj =
_event_animation_object_get(eo_obj, EFL_ANIMATION_EVENT_TYPE_SHOW);
if (anim_obj)
{
_all_animation_objects_cancel(eo_obj);
efl_animation_object_start(anim_obj);
}
}
static void
@ -2524,6 +2730,133 @@ _efl_canvas_object_legacy_ctor(Eo *eo_obj, Evas_Object_Protected_Data *obj)
obj->legacy.ctor = EINA_TRUE;
}
EOLIAN void
_efl_canvas_object_event_animation_set(Eo *eo_obj,
Evas_Object_Protected_Data *pd,
Efl_Animation_Event_Type event_type,
Efl_Animation *animation)
{
if (!_efl_animation_event_type_is_valid(event_type))
return;
Event_Animation *event_anim =
eina_array_data_get(pd->event_anims, event_type);
if (!event_anim) return;
Efl_Animation *cur_anim = event_anim->anim;
Efl_Animation_Object *cur_anim_obj = event_anim->anim_obj;
//Unset for current event animation
if (cur_anim)
{
Efl_Canvas_Object *prev_target = efl_animation_target_get(cur_anim);
//Deallocate memory and Unset callbacks for Hide event
if (event_type == EFL_ANIMATION_EVENT_TYPE_HIDE)
{
Hide_Anim_Data *hide_anim_data
= evas_object_intercept_hide_callback_del(prev_target,
_animation_intercept_hide);
if (hide_anim_data)
{
efl_event_callback_del(cur_anim_obj,
EFL_ANIMATION_OBJECT_EVENT_ENDED,
_animation_hide_end_cb,
hide_anim_data);
if (hide_anim_data->anim_started &&
!hide_anim_data->anim_ended)
efl_gfx_visible_set(prev_target, EINA_FALSE);
free(hide_anim_data);
}
}
//Stop animation
efl_animation_object_cancel(cur_anim_obj);
/* Delete current animation object because animation object is
* created in efl_canvas_object_event_animation_set(). */
efl_del(cur_anim_obj);
}
Efl_Animation *new_anim = animation;
Efl_Animation_Object *new_anim_obj = NULL;
//Set for new event animation
if (new_anim)
{
//Set target object for the given animation
Efl_Canvas_Object *target = efl_animation_target_get(new_anim);
if (!target)
target = eo_obj;
efl_animation_target_set(new_anim, target);
new_anim_obj = efl_animation_object_create(new_anim);
/* Event animation object should not be deleted after animation is
* cancelled or finished */
efl_animation_object_auto_del_set(new_anim_obj, EINA_FALSE);
//Allocate memory and Set callbacks for Hide event
if (event_type == EFL_ANIMATION_EVENT_TYPE_HIDE)
{
Hide_Anim_Data *hide_anim_data = calloc(1, sizeof(Hide_Anim_Data));
hide_anim_data->target = target;
hide_anim_data->anim_started = EINA_FALSE;
hide_anim_data->anim_ended = EINA_FALSE;
evas_object_intercept_hide_callback_add(target,
_animation_intercept_hide,
hide_anim_data);
efl_event_callback_add(new_anim_obj,
EFL_ANIMATION_OBJECT_EVENT_ENDED,
_animation_hide_end_cb,
hide_anim_data);
}
}
//Replace current event animation with new event animation
event_anim->anim = new_anim;
event_anim->anim_obj = new_anim_obj;
}
EOLIAN Efl_Animation *
_efl_canvas_object_event_animation_get(Eo *eo_obj EINA_UNUSED,
Evas_Object_Protected_Data *pd,
Efl_Animation_Event_Type event_type)
{
if (!_efl_animation_event_type_is_valid(event_type))
return NULL;
Event_Animation *event_anim = eina_array_data_get(pd->event_anims,
event_type);
if (event_anim && event_anim->anim)
return event_anim->anim;
return NULL;
}
/* This function is to show object if show is called during hide animation.
* If show is called during hide animation is running, then the running hide
* animation is cancelled and show operation is proceeded. */
Eina_Bool
_efl_canvas_object_event_animation_is_running(Eo *eo_obj,
Efl_Animation_Event_Type event)
{
if (_event_animation_object_get(eo_obj, event))
return EINA_TRUE;
return EINA_FALSE;
}
void
_efl_canvas_object_event_animation_cancel(Eo *eo_obj)
{
_all_animation_objects_cancel(eo_obj);
}
/* legacy */

View File

@ -1209,6 +1209,8 @@ struct _Evas_Object_Protected_Data
unsigned char no_change_render;
unsigned char delete_me;
Eina_Array *event_anims; //Array of Efl_Animation
Eina_Bool render_pre : 1;
Eina_Bool rect_del : 1;
@ -1985,6 +1987,13 @@ void _evas_touch_point_remove(Evas *e, int id);
void _evas_device_cleanup(Evas *e);
Evas_Device *_evas_device_top_get(const Evas *e);
/* for animation event count */
#define EFL_ANIMATION_EVENT_TYPE_COUNT 3
/* to show object if show is called during hide animation */
Eina_Bool _efl_canvas_object_event_animation_is_running(Eo *eo_obj, Efl_Animation_Event_Type event);
void _efl_canvas_object_event_animation_cancel(Eo *eo_obj);
/* legacy/eo events */
void *efl_input_pointer_legacy_info_fill(Evas *eo_evas, Efl_Input_Key *eo_ev, Evas_Callback_Type type, Evas_Event_Flags **pflags);
void *efl_input_key_legacy_info_fill(Efl_Input_Key *evt, Evas_Event_Flags **pflags);