--- /dev/null
+#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);
+}
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)
{
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)
{
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);
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;
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,
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);
}
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);
}
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)
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)
{
}
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
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 */