From b3f473098b253739b245360569dc4e674220f66a Mon Sep 17 00:00:00 2001 From: ChunEon Park Date: Mon, 22 Nov 2010 10:44:05 +0900 Subject: [PATCH] [elm_animator.c] merged with up-to-date upstream --- src/lib/elm_animator.c | 114 ++++++++++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 48 deletions(-) diff --git a/src/lib/elm_animator.c b/src/lib/elm_animator.c index 363b729..20a1d1c 100644 --- a/src/lib/elm_animator.c +++ b/src/lib/elm_animator.c @@ -1,17 +1,36 @@ #include #include "elm_priv.h" +#define ELM_ANIMATOR_CHECK_OR_RETURN(animator, ...) \ + do { \ + if (!animator) { \ + CRITICAL("Elm_Animator " # animator " is NULL!"); \ + return __VA_ARGS__; \ + } \ + if (!EINA_MAGIC_CHECK(animator, ELM_ANIMATOR_MAGIC)) { \ + EINA_MAGIC_FAIL(animator, ELM_ANIMATOR_MAGIC); \ + return __VA_ARGS__; \ + } \ + } while (0) + + /** * @addtogroup Animator Animator * @ingroup Elementary * - * Support normalized frame value for animation. -*/ -#define MAGIC_OBJ_ANIMATOR 0x40777770 + * elm_animator is designed to provides animation frame. + * It is somewhat different with any others widgets however elm_animator + * might useful when your GUIs have animation. + * Basically, it computes normalized frame value for animation, + * provides additional functions to adjust this also. + * + */ struct _Elm_Animator { - int magic; +#define ELM_ANIMATOR_MAGIC 0x40777770 + EINA_MAGIC; + Evas_Object *parent; Ecore_Animator *animator; double begin_time; @@ -104,7 +123,7 @@ _animator_animate_cb(void *data) //Not end. Keep going. if (elapsed_time < animator->duration) return ECORE_CALLBACK_RENEW; - //Repeat and reverse and time done! + //Repeat and reverse and time done! if (!animator->cur_repeat_cnt) { animator->on_animating = EINA_FALSE; @@ -129,17 +148,17 @@ _animator_parent_del(void *data, Evas *evas __UNUSED__, } /** - * Get the value of reverse mode. + * Get the value of reverse mode. * * @param[in] animator Animator object - * @return EINA_TRUE is reverse mode + * @return EINA_TRUE is reverse mode * - * @ingroup Animator + * @ingroup Animator */ EAPI Eina_Bool elm_animator_auto_reverse_get(const Elm_Animator *animator) { - if ((!animator) || (animator->magic != MAGIC_OBJ_ANIMATOR)) return EINA_FALSE; + ELM_ANIMATOR_CHECK_OR_RETURN(animator, EINA_FALSE); return animator->auto_reverse; } @@ -149,27 +168,27 @@ elm_animator_auto_reverse_get(const Elm_Animator *animator) * @param[in] animator Animator object * @return Repeat count * - * @ingroup Animator + * @ingroup Animator */ EAPI unsigned int elm_animator_repeat_get(const Elm_Animator *animator) { - if ((!animator) || (animator->magic != MAGIC_OBJ_ANIMATOR)) return 0; + ELM_ANIMATOR_CHECK_OR_RETURN(animator, 0); return animator->repeat_cnt; } /** - * Set auto reverse function. + * Set auto reverse function. * * @param[in] animator Animator object * @param[in] reverse Reverse or not - * - * @ingroup Animator + * + * @ingroup Animator */ EAPI void elm_animator_auto_reverse_set(Elm_Animator *animator, Eina_Bool reverse) { - if ((!animator) || (animator->magic != MAGIC_OBJ_ANIMATOR)) return; + ELM_ANIMATOR_CHECK_OR_RETURN(animator); if (animator->auto_reverse == reverse) return; animator->auto_reverse = reverse; if (reverse) @@ -181,10 +200,10 @@ elm_animator_auto_reverse_set(Elm_Animator *animator, Eina_Bool reverse) } /** - * Set the animation acceleration style. + * Set the animation acceleration style. * * @param[in] animator Animator object - * @param[in] cs Curve style. Default is ELM_ANIMATOR_CURVE_LINEAR + * @param[in] cs Curve style. Default is ELM_ANIMATOR_CURVE_LINEAR * * @ingroup Animator */ @@ -192,7 +211,7 @@ EAPI void elm_animator_curve_style_set(Elm_Animator *animator, Elm_Animator_Curve_Style cs) { - if ((!animator) || (animator->magic != MAGIC_OBJ_ANIMATOR)) return; + ELM_ANIMATOR_CHECK_OR_RETURN(animator); switch (cs) { case ELM_ANIMATOR_CURVE_LINEAR: @@ -214,28 +233,28 @@ elm_animator_curve_style_set(Elm_Animator *animator, } /** - * Set the operation duration. + * Set the operation duration. * * @param[in] animator Animator object - * @param[in] duration Duration in second + * @param[in] duration Duration in second * * @ingroup Animator */ EAPI void elm_animator_duration_set(Elm_Animator *animator, double duration) { - if ((!animator) || (animator->magic != MAGIC_OBJ_ANIMATOR)) return; + ELM_ANIMATOR_CHECK_OR_RETURN(animator); if (animator->on_animating) return; animator->duration = duration; } /** - * Set the callback function for animator operation. + * Set the callback function for animator operation. * The range of callback function frame data is to 0 ~ 1 - * User can refer this frame value for one's animation frame data. + * User can refer this frame value for one's animation frame data. * @param[in] animator Animator object - * @param[in] func Callback function pointer - * @param[in] data Callback function user argument + * @param[in] func Callback function pointer + * @param[in] data Callback function user argument * * @ingroup Animator */ @@ -244,17 +263,17 @@ elm_animator_operation_callback_set(Elm_Animator *animator, Elm_Animator_Operation_Cb func, void *data) { - if ((!animator) || (animator->magic != MAGIC_OBJ_ANIMATOR)) return; + ELM_ANIMATOR_CHECK_OR_RETURN(animator); if (animator->on_animating) return; animator->animator_op = func; animator->animator_arg = data; } /** - * Add new animator. + * Add new animator. * * @param[in] parent Parent object - * @return animator object + * @return animator object * * @ingroup Animator */ @@ -263,58 +282,57 @@ elm_animator_add(Evas_Object *parent) { Elm_Animator *animator = ELM_NEW(Elm_Animator); if (!animator) return NULL; + EINA_MAGIC_SET(animator, ELM_ANIMATOR_MAGIC); animator->parent = parent; - animator->magic = MAGIC_OBJ_ANIMATOR; elm_animator_auto_reverse_set(animator, EINA_FALSE); elm_animator_curve_style_set(animator, ELM_ANIMATOR_CURVE_LINEAR); if (parent) evas_object_event_callback_add(parent, EVAS_CALLBACK_DEL, _animator_parent_del, animator); - return animator; } /** * Get the status for the animator operation. * - * @param[in] animator Animator object - * @return EINA_TRUE is animator is operating. + * @param[in] animator Animator object + * @return EINA_TRUE is animator is operating. * * @ingroup Animator */ EAPI Eina_Bool elm_animator_operating_get(const Elm_Animator *animator) { - if ((!animator) || (animator->magic != MAGIC_OBJ_ANIMATOR)) return EINA_FALSE; + ELM_ANIMATOR_CHECK_OR_RETURN(animator, EINA_FALSE); return animator->on_animating; } /** - * Delete animator. + * Delete animator. * - * @param[in] animator Animator object + * @param[in] animator Animator object * * @ingroup Animator */ EAPI void elm_animator_del(Elm_Animator *animator) { - if ((!animator) || (animator->magic != MAGIC_OBJ_ANIMATOR)) return; + ELM_ANIMATOR_CHECK_OR_RETURN(animator); _delete_animator(animator); if (animator->parent) evas_object_event_callback_del(animator->parent, EVAS_CALLBACK_DEL, _animator_parent_del); - memset(animator, 0x0, sizeof(Elm_Animator)); + EINA_MAGIC_SET(animator, EINA_MAGIC_NONE); free(animator); } /** - * Set the callback function for the animator end. + * Set the callback function for the animator end. * - * @param[in] animator Animator object - * @param[in] func Callback function pointer - * @param[in] data Callback function user argument + * @param[in] animator Animator object + * @param[in] func Callback function pointe + * @param[in] data Callback function user argument * * @ingroup Animator */ @@ -323,7 +341,7 @@ elm_animator_completion_callback_set(Elm_Animator *animator, Elm_Animator_Completion_Cb func, void *data) { - if (!animator || (animator->magic != MAGIC_OBJ_ANIMATOR)) return; + ELM_ANIMATOR_CHECK_OR_RETURN(animator); if (animator->on_animating) return; animator->completion_op = func; animator->completion_arg = data; @@ -339,7 +357,7 @@ elm_animator_completion_callback_set(Elm_Animator *animator, EAPI void elm_animator_pause(Elm_Animator *animator) { - if ((!animator) || (animator->magic != MAGIC_OBJ_ANIMATOR)) return; + ELM_ANIMATOR_CHECK_OR_RETURN(animator); if (!animator->on_animating) return; ecore_animator_freeze(animator->animator); } @@ -354,7 +372,7 @@ elm_animator_pause(Elm_Animator *animator) EAPI void elm_animator_resume(Elm_Animator *animator) { - if ((!animator) || (animator->magic != MAGIC_OBJ_ANIMATOR)) return; + ELM_ANIMATOR_CHECK_OR_RETURN(animator); if (!animator->on_animating) return; ecore_animator_thaw(animator->animator); } @@ -362,14 +380,14 @@ elm_animator_resume(Elm_Animator *animator) /** * Stop animator. * - * @param[in] animator Animator object + * @param[in] animator Animator object * * @ingroup Animator */ EAPI void elm_animator_stop(Elm_Animator *animator) { - if ((!animator) || (animator->magic != MAGIC_OBJ_ANIMATOR)) return; + ELM_ANIMATOR_CHECK_OR_RETURN(animator); animator->on_animating = EINA_FALSE; _delete_animator(animator); } @@ -385,7 +403,7 @@ elm_animator_stop(Elm_Animator *animator) EAPI void elm_animator_repeat_set(Elm_Animator *animator, unsigned int repeat_cnt) { - if ((!animator) || (animator->magic != MAGIC_OBJ_ANIMATOR)) return; + ELM_ANIMATOR_CHECK_OR_RETURN(animator); if (!animator->auto_reverse) animator->repeat_cnt = repeat_cnt; else animator->repeat_cnt = _animator_compute_reverse_repeat_count(repeat_cnt); @@ -401,7 +419,7 @@ elm_animator_repeat_set(Elm_Animator *animator, unsigned int repeat_cnt) EAPI void elm_animator_animate(Elm_Animator *animator) { - if ((!animator) || (animator->magic != MAGIC_OBJ_ANIMATOR)) return; + ELM_ANIMATOR_CHECK_OR_RETURN(animator); if (!animator->animator_op) return; animator->begin_time = ecore_loop_time_get(); animator->cur_repeat_cnt = animator->repeat_cnt; -- 2.7.4