From: Jérémy Zurcher Date: Thu, 3 Jul 2014 20:33:15 +0000 (+0200) Subject: ecore: animator use eo_add() instead of eo_add_custom() X-Git-Tag: upstream/1.10.0+1149+ga3a15b1~376 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec4ffb86d6bc9a3d4e4e81b80359abd7bbdb8f22;p=platform%2Fupstream%2Fefl.git ecore: animator use eo_add() instead of eo_add_custom() Summary: - use defauld constructor instead of custom one. - we don't allow construction of an animator with a NULL callback function, this is checked in overriden eo_finalize. - we don't support changing this callback once the object is created, such calls will call ERR() and return. see 46a78e8c and f92e5d50 for eo_add_custom() -> eo_add() details Reviewers: tasn Reviewed By: tasn CC: cedric Differential Revision: https://phab.enlightenment.org/D1113 --- diff --git a/src/lib/ecore/ecore_anim.c b/src/lib/ecore/ecore_anim.c index 892359f..0ff0169 100644 --- a/src/lib/ecore/ecore_anim.c +++ b/src/lib/ecore/ecore_anim.c @@ -154,42 +154,35 @@ _do_tick(void) return ECORE_CALLBACK_RENEW; } -static Eina_Bool -_ecore_animator_add(Ecore_Animator *obj, - Ecore_Animator_Data *animator, - Ecore_Task_Cb func, - const void *data) +EOLIAN static Eo * +_ecore_animator_eo_base_finalize(Eo *obj, Ecore_Animator_Data *animator) { - if (EINA_UNLIKELY(!eina_main_loop_is())) - { - eo_error_set(obj); - EINA_MAIN_LOOP_CHECK_RETURN_VAL(EINA_FALSE); - } - - animator->obj = obj; - eo_do_super(obj, MY_CLASS, eo_constructor()); - eo_manual_free_set(obj, EINA_TRUE); - - if (!func) + if (!animator->func) { eo_error_set(obj); ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME); - return EINA_FALSE; + goto finalize; } - animator->func = func; - animator->data = (void *)data; + if (EINA_UNLIKELY(!eina_main_loop_is())) + { + eo_error_set(obj); + EINA_MAIN_LOOP_CHECK_RETURN_VAL( + eo_do_super(obj, MY_CLASS, eo_finalize())); + goto finalize; + } + + _ecore_lock(); + + eo_manual_free_set(obj, EINA_TRUE); animator->just_added = EINA_TRUE; animators = (Ecore_Animator_Data *)eina_inlist_append(EINA_INLIST_GET(animators), EINA_INLIST_GET(animator)); + _begin_tick(); - return EINA_TRUE; -} + _ecore_unlock(); -EOLIAN static void -_ecore_animator_eo_base_constructor(Eo *obj, Ecore_Animator_Data *_pd EINA_UNUSED) -{ - eo_error_set(obj); - ERR("only custom constructor can be used with '%s' class", MY_CLASS_NAME); +finalize: + return eo_do_super(obj, MY_CLASS, eo_finalize()); } EAPI Ecore_Animator * @@ -198,17 +191,27 @@ ecore_animator_add(Ecore_Task_Cb func, { Ecore_Animator *animator = NULL; - animator = eo_add_custom(MY_CLASS, _ecore_parent, - ecore_animator_constructor(func, data)); + animator = eo_add(MY_CLASS, _ecore_parent, + ecore_obj_animator_init(func, data)); eo_unref(animator); return animator; } EOLIAN static void -_ecore_animator_constructor(Eo *obj, Ecore_Animator_Data *animator, Ecore_Task_Cb func, const void *data) +_ecore_animator_init(Eo *obj, Ecore_Animator_Data *animator, Ecore_Task_Cb func, const void *data) { + if (animator->func != NULL) + { + ERR("do not call this function out of '%s' object construction", MY_CLASS_NAME); + return; + } + _ecore_lock(); - _ecore_animator_add(obj, animator, func, data); + + animator->obj = obj; + animator->func = func; + animator->data = (void *)data; + _ecore_unlock(); } @@ -218,27 +221,32 @@ ecore_animator_timeline_add(double runtime, const void *data) { Ecore_Animator *animator; - animator = eo_add_custom(MY_CLASS, _ecore_parent, - ecore_animator_timeline_constructor(runtime, func, data)); + animator = eo_add(MY_CLASS, _ecore_parent, + ecore_obj_animator_timeline_init(runtime, func, data)); eo_unref(animator); return animator; } EOLIAN static void -_ecore_animator_timeline_constructor(Eo *obj, Ecore_Animator_Data *animator, double runtime, Ecore_Timeline_Cb func, const void *data) +_ecore_animator_timeline_init(Eo *obj, Ecore_Animator_Data *animator, double runtime, Ecore_Timeline_Cb func, const void *data) { - _ecore_lock(); - if (runtime <= 0.0) runtime = 0.0; + if (animator->func != NULL) + { + ERR("do not call this function out of '%s' object construction", MY_CLASS_NAME); + return; + } + if (runtime < 0.0) runtime = 0.0; - if (!_ecore_animator_add(obj, animator, _ecore_animator_run, NULL)) goto unlock; + _ecore_lock(); + animator->obj = obj; + animator->func = _ecore_animator_run; animator->data = obj; animator->run_func = func; animator->run_data = (void *)data; animator->start = ecore_loop_time_get(); animator->run = runtime; -unlock: _ecore_unlock(); } @@ -687,4 +695,4 @@ _ecore_animator(void *data EINA_UNUSED) return r; } -#include "ecore_animator.eo.c" \ No newline at end of file +#include "ecore_animator.eo.c" diff --git a/src/lib/ecore/ecore_animator.eo b/src/lib/ecore/ecore_animator.eo index e9a3999..213dcd3 100644 --- a/src/lib/ecore/ecore_animator.eo +++ b/src/lib/ecore/ecore_animator.eo @@ -1,25 +1,65 @@ class Ecore.Animator (Eo.Base) { - eo_prefix: ecore_animator; - constructors { - timeline_constructor { - /*@ Contructor. */ + legacy_prefix: null; + eo_prefix: ecore_obj_animator; + methods { + init { + /*@ + Set the @p func to be called at every animation tick during main loop execution. + + The function @p func will be called every N seconds where N is + the @p frametime interval set by ecore_animator_frametime_set(). The + function will be passed the @p data pointer as its parameter. + + When the animator @p func is called, it must return a boolean value. + If it returns EINA_TRUE (or ECORE_CALLBACK_RENEW), it will be called again at + the next tick, or if it returns EINA_FALSE (or ECORE_CALLBACK_CANCEL) it will be + deleted automatically making any references/handles for it invalid. + + @note Do NOT call this method outside of object constructor. + + @note The default @p frametime value is 1/30th of a second. + + @see ecore_obj_animator_timeline_set() + @see ecore_animator_frametime_set() */ params { - @in double runtime; - @in Ecore_Timeline_Cb func; - @in const(void)* data; + @in Ecore_Task_Cb func; /*@ The function to call when it ticks off */ + @in const(void)* data; /*@ The data to pass to the function */ } } - constructor { - /*@ Contructor. */ + timeline_init { + /*@ + Set the @p func to be called at every animation tick during main loop execution, that runs for a limited time + + This function is just like ecore_obj_animator_task_set() except the animator only + runs for a limited time specified in seconds by @p runtime. Once the + runtime the animator has elapsed (animator finished) it will automatically + be deleted. The callback function @p func can return ECORE_CALLBACK_RENEW + to keep the animator running or ECORE_CALLBACK_CANCEL ro stop it and have + it be deleted automatically at any time. + + The @p func will ALSO be passed a position parameter that will be in value + from 0.0 to 1.0 to indicate where along the timeline (0.0 start, 1.0 end) + the animator run is at. If the callback wishes not to have a linear + transition it can "map" this value to one of several curves and mappings + via ecore_animator_pos_map(). + + @note Do NOT call this method outside of object constructor. + + @note The default @p frametime value is 1/30th of a second. + + @see ecore_obj_animator_task_set() + @see ecore_animator_pos_map() + @since 1.1.0 */ params { - @in Ecore_Task_Cb func; - @in const(void)* data; + @in double runtime; /*@ The time to run in seconds */ + @in Ecore_Timeline_Cb func; /*@ The function to call when it ticks off */ + @in const(void)* data; /*@ The data to pass to the function */ } } } implements { - Eo.Base.constructor; + Eo.Base.finalize; Eo.Base.destructor; Eo.Base.event_freeze; Eo.Base.event_thaw; diff --git a/src/tests/ecore/ecore_test_animator.c b/src/tests/ecore/ecore_test_animator.c index 852e8b5..170379b 100644 --- a/src/tests/ecore/ecore_test_animator.c +++ b/src/tests/ecore/ecore_test_animator.c @@ -29,15 +29,18 @@ START_TEST(ecore_test_animators) fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n"); ecore_animator_frametime_set(interval1); - animator = eo_add_custom(ECORE_ANIMATOR_CLASS, NULL, ecore_animator_timeline_constructor(1, _anim_cb, &interval1)); + animator = eo_add(ECORE_ANIMATOR_CLASS, NULL); + fail_if(animator); + + animator = eo_add(ECORE_ANIMATOR_CLASS, NULL, ecore_obj_animator_timeline_init(1, _anim_cb, &interval1)); fail_if(!animator); ecore_main_loop_begin(); ecore_animator_frametime_set(interval2); prev = 0; - animator = eo_add_custom(ECORE_ANIMATOR_CLASS, NULL, ecore_animator_timeline_constructor(1, _anim_cb, &interval2)); + animator = eo_add(ECORE_ANIMATOR_CLASS, NULL, ecore_obj_animator_timeline_init(1, _anim_cb, &interval2)); fail_if(!animator); ecore_main_loop_begin();