From 685f177f70415591c79e19f5da12cf6aa53ca63a Mon Sep 17 00:00:00 2001 From: ChunEon Park Date: Mon, 28 Jun 2010 17:22:43 +0900 Subject: [PATCH] [elm_animator.c] --- src/lib/elm_animator.c | 376 ++++++++++++++++++++++++++++--------------------- 1 file changed, 212 insertions(+), 164 deletions(-) diff --git a/src/lib/elm_animator.c b/src/lib/elm_animator.c index 67d21c2..e01a16e 100644 --- a/src/lib/elm_animator.c +++ b/src/lib/elm_animator.c @@ -18,7 +18,6 @@ static const float _in_out_table[181] = { 0.978681, 0.980323, 0.981894, 0.983397, 0.984832, 0.986198, 0.987498, 0.988731, 0.989898, 0.990999, 0.992035, 0.993007, 0.993914, 0.994756, 0.995536, 0.996251, 0.996904, 0.997494, 0.998021, 0.998485, 0.998888, 0.999228, 0.999506, 0.999722, 0.999877, 0.999969, 1 }; - static const float _in_table[181] = { 0, 1.54322e-05, 6.17303e-05, 0.000138899, 0.000246944, 0.000385877, 0.00055571, 0.000756459, 0.000988143, 0.00125078, 0.0015444, 0.00186903, 0.0022247, 0.00261143, 0.00302928, 0.00347827, 0.00395845, 0.00446987, 0.00501256, 0.00558659, 0.00619201, 0.00682887, 0.00749724, 0.00819718, 0.00892875, 0.00969203, 0.0104871, 0.011314, 0.0121729, 0.0130637, 0.0139867, 0.0149419, 0.0159293, 0.0169492, @@ -31,7 +30,6 @@ static const float _in_table[181] = { 0.438944, 0.447229, 0.455697, 0.464357, 0.473217, 0.482289, 0.491583, 0.501112, 0.51089, 0.520932, 0.531255, 0.541877, 0.552821, 0.56411, 0.575772, 0.587839, 0.600347, 0.61334, 0.626867, 0.640989, 0.65578, 0.671329, 0.68775, 0.705189, 0.723838, 0.743962, 0.76594, 0.790356, 0.818188, 0.851343, 0.894737, 1 }; - static const float _out_table[181] = { 0, 0.105263, 0.148657, 0.181812, 0.209644, 0.23406, 0.256038, 0.276162, 0.294811, 0.31225, 0.328671, 0.34422, 0.359011, 0.373133, 0.38666, 0.399653, 0.412161, 0.424228, 0.43589, 0.447179, 0.458123, 0.468745, 0.479068, 0.48911, 0.498888, 0.508417, 0.517711, 0.526783, 0.535643, 0.544303, 0.552771, 0.561056, 0.569167, 0.57711, 0.584892, 0.59252, 0.6, 0.607337, 0.614536, 0.621602, 0.628539, 0.635353, @@ -44,120 +42,132 @@ static const float _out_table[181] = { 0.994987, 0.99553, 0.996042, 0.996522, 0.996971, 0.997389, 0.997775, 0.998131, 0.998456, 0.998749, 0.999012, 0.999244, 0.999444, 0.999614, 0.999753, 0.999861, 0.999938, 0.999985, 1 }; */ -struct _Animator { - Evas_Object* parent; - Ecore_Animator* animator; - double begin_time; - double cur_time; - double duration; - unsigned int repeat_cnt; - unsigned int cur_repeat_cnt; - double (*curve_op)( const double ); - void (*animator_op)(void*, Elm_Animator*, const double); - void* animator_arg; - void (*completion_op)(void*); - void* completion_arg; - Eina_Bool auto_reverse :1; - Eina_Bool on_animating : 1; +struct _Animator +{ + Evas_Object *parent; + Ecore_Animator *animator; + double begin_time; + double cur_time; + double duration; + unsigned int repeat_cnt; + unsigned int cur_repeat_cnt; + double (*curve_op) (const double); + void (*animator_op) (void *, Elm_Animator *, const double); + void *animator_arg; + void (*completion_op) (void *); + void *completion_arg; + Eina_Bool auto_reverse:1; + Eina_Bool on_animating:1; }; static double _animator_curve_linear(const double frame); + static double _animator_curve_in_out(const double frame); + static double _animator_curve_in(const double frame); + static double _animator_curve_out(const double frame); + static unsigned int _animator_compute_reverse_repeat_count(unsigned int cnt); + static unsigned int _animator_compute_no_reverse_repeat_count(unsigned int cnt); -static int _animator_animate_cb(void* data); -static void _delete_animator(Elm_Animator* animator); -static unsigned int -_animator_compute_reverse_repeat_count(unsigned int cnt) +static int _animator_animate_cb(void *data); + +static void _delete_animator(Elm_Animator * animator); + +static unsigned int +_animator_compute_reverse_repeat_count(unsigned int cnt) { - return ( ( cnt + 1 ) * 2 ) - 1; + return ((cnt + 1) * 2) - 1; } -static unsigned int +static unsigned int _animator_compute_no_reverse_repeat_count(unsigned int cnt) { - return cnt / 2; + return cnt / 2; } static double _animator_curve_linear(const double frame) { - return frame; + return frame; } -static double +static double _animator_curve_in_out(const double frame) { - if(frame < 0.5) - return _animator_curve_out(frame * 2) * 0.5; - else - return _animator_curve_in(frame * 2 - 1) * 0.5 + 0.5; + if (frame < 0.5) + return _animator_curve_out(frame * 2) * 0.5; + else + return _animator_curve_in(frame * 2 - 1) * 0.5 + 0.5; } -static double +static double _animator_curve_in(const double frame) { - return sqrt(1 - pow(frame - 1, 2)); + return sqrt(1 - pow(frame - 1, 2)); } -static double +static double _animator_curve_out(const double frame) { - return 1 - sqrt(1 - pow(frame, 2)); + return 1 - sqrt(1 - pow(frame, 2)); } - -static void -_delete_animator(Elm_Animator* animator) +static void +_delete_animator(Elm_Animator * animator) { - if(animator->animator) - { - ecore_animator_del(animator->animator); - animator->animator = NULL; - } + if (animator->animator) + { + ecore_animator_del(animator->animator); + animator->animator = NULL; + } } -static int -_animator_animate_cb(void* data) +static int +_animator_animate_cb(void *data) { - Elm_Animator* animator = (Elm_Animator*) data; - animator->cur_time = ecore_loop_time_get(); - double elapsed_time = animator->cur_time - animator->begin_time; - - //TODO: HOW TO MAKE IT PRECIOUS TIME? -> Use Interpolation!! - if( elapsed_time > animator->duration ) elapsed_time = animator->duration; - - float frame = animator->curve_op(elapsed_time/animator->duration); - - //Reverse? - if(animator->auto_reverse == EINA_TRUE) - { - if( animator->cur_repeat_cnt % 2 == 0 ) frame = 1 - frame; - } - - if(animator->duration > 0) - animator->animator_op(animator->animator_arg, animator, frame); - - //Not end. Keep going. - if(elapsed_time < animator->duration) return ECORE_CALLBACK_RENEW; - - //Repeat and reverse and time done! - if(animator->cur_repeat_cnt == 0) - { - animator->on_animating = EINA_FALSE; - _delete_animator( animator ); - if(animator->completion_op) animator->completion_op(animator->completion_arg); - return ECORE_CALLBACK_CANCEL; - } - - //Repeat Case - --animator->cur_repeat_cnt; - animator->begin_time = ecore_loop_time_get(); - - return ECORE_CALLBACK_RENEW; + Elm_Animator *animator = (Elm_Animator *) data; + + animator->cur_time = ecore_loop_time_get(); + double elapsed_time = animator->cur_time - animator->begin_time; + + //TODO: HOW TO MAKE IT PRECIOUS TIME? -> Use Interpolation!! + if (elapsed_time > animator->duration) + elapsed_time = animator->duration; + + float frame = animator->curve_op(elapsed_time / animator->duration); + + //Reverse? + if (animator->auto_reverse == EINA_TRUE) + { + if (animator->cur_repeat_cnt % 2 == 0) + frame = 1 - frame; + } + + if (animator->duration > 0) + animator->animator_op(animator->animator_arg, animator, frame); + + //Not end. Keep going. + if (elapsed_time < animator->duration) + return ECORE_CALLBACK_RENEW; + + //Repeat and reverse and time done! + if (animator->cur_repeat_cnt == 0) + { + animator->on_animating = EINA_FALSE; + _delete_animator(animator); + if (animator->completion_op) + animator->completion_op(animator->completion_arg); + return ECORE_CALLBACK_CANCEL; + } + + //Repeat Case + --animator->cur_repeat_cnt; + animator->begin_time = ecore_loop_time_get(); + + return ECORE_CALLBACK_RENEW; } /** @@ -168,10 +178,12 @@ _animator_animate_cb(void* data) * * @ingroup Animator */ -EAPI Eina_Bool elm_animator_auto_reverse_get(Elm_Animator* animator) +EAPI Eina_Bool +elm_animator_auto_reverse_get(Elm_Animator * animator) { - if(!animator) return EINA_FALSE; - return animator->auto_reverse; + if (!animator) + return EINA_FALSE; + return animator->auto_reverse; } /** @@ -182,10 +194,12 @@ EAPI Eina_Bool elm_animator_auto_reverse_get(Elm_Animator* animator) * * @ingroup Animator */ -EAPI unsigned int elm_animator_repeat_get(Elm_Animator* animator) +EAPI unsigned int +elm_animator_repeat_get(Elm_Animator * animator) { - if(!animator) return EINA_FALSE; - return animator->repeat_cnt; + if (!animator) + return EINA_FALSE; + return animator->repeat_cnt; } /** @@ -196,15 +210,20 @@ EAPI unsigned int elm_animator_repeat_get(Elm_Animator* animator) * * @ingroup Animator */ -EAPI void elm_animator_auto_reverse_set(Elm_Animator* animator, Eina_Bool reverse) +EAPI void +elm_animator_auto_reverse_set(Elm_Animator * animator, Eina_Bool reverse) { - if(!animator) return ; - if( animator->auto_reverse == reverse ) return; - animator->auto_reverse = reverse; - if( reverse == EINA_TRUE ) - animator->repeat_cnt = _animator_compute_reverse_repeat_count(animator->repeat_cnt); - else - animator->repeat_cnt = _animator_compute_no_reverse_repeat_count(animator->repeat_cnt); + if (!animator) + return; + if (animator->auto_reverse == reverse) + return; + animator->auto_reverse = reverse; + if (reverse == EINA_TRUE) + animator->repeat_cnt = + _animator_compute_reverse_repeat_count(animator->repeat_cnt); + else + animator->repeat_cnt = + _animator_compute_no_reverse_repeat_count(animator->repeat_cnt); } /** @@ -215,28 +234,31 @@ EAPI void elm_animator_auto_reverse_set(Elm_Animator* animator, Eina_Bool revers * * @ingroup Animator */ -EAPI void elm_animator_curve_style_set(Elm_Animator* animator, Elm_Animator_Curve_Style cs) +EAPI void +elm_animator_curve_style_set(Elm_Animator * animator, + Elm_Animator_Curve_Style cs) { - if(!animator) return; - - switch(cs) - { - case ELM_ANIMATOR_CURVE_LINEAR: - animator->curve_op = _animator_curve_linear; - break; - case ELM_ANIMATOR_CURVE_IN_OUT: - animator->curve_op = _animator_curve_in_out; - break; - case ELM_ANIMATOR_CURVE_IN: - animator->curve_op = _animator_curve_in; - break; - case ELM_ANIMATOR_CURVE_OUT: - animator->curve_op = _animator_curve_out; - break; - default: - animator->curve_op = _animator_curve_linear; - break; - } + if (!animator) + return; + + switch (cs) + { + case ELM_ANIMATOR_CURVE_LINEAR: + animator->curve_op = _animator_curve_linear; + break; + case ELM_ANIMATOR_CURVE_IN_OUT: + animator->curve_op = _animator_curve_in_out; + break; + case ELM_ANIMATOR_CURVE_IN: + animator->curve_op = _animator_curve_in; + break; + case ELM_ANIMATOR_CURVE_OUT: + animator->curve_op = _animator_curve_out; + break; + default: + animator->curve_op = _animator_curve_linear; + break; + } } /** @@ -247,11 +269,14 @@ EAPI void elm_animator_curve_style_set(Elm_Animator* animator, Elm_Animator_Curv * * @ingroup Animator */ -EAPI void elm_animator_duration_set(Elm_Animator* animator, const double duration) +EAPI void +elm_animator_duration_set(Elm_Animator * animator, const double duration) { - if(!animator) return; - if(animator->on_animating == EINA_TRUE) return; - animator->duration = duration; + if (!animator) + return; + if (animator->on_animating == EINA_TRUE) + return; + animator->duration = duration; } /** @@ -263,12 +288,17 @@ EAPI void elm_animator_duration_set(Elm_Animator* animator, const double duratio * * @ingroup Animator */ -EAPI void elm_animator_operation_callback_set(Elm_Animator* animator, void (*op)(void*, Elm_Animator*, const double), void* data) +EAPI void +elm_animator_operation_callback_set(Elm_Animator * animator, + void (*op) (void *, Elm_Animator *, + const double), void *data) { - if(!animator) return; - if(animator->on_animating == EINA_TRUE) return; - animator->animator_op = op; - animator->animator_arg = data; + if (!animator) + return; + if (animator->on_animating == EINA_TRUE) + return; + animator->animator_op = op; + animator->animator_arg = data; } /** @@ -279,15 +309,19 @@ EAPI void elm_animator_operation_callback_set(Elm_Animator* animator, void (*op) * * @ingroup Animator */ -EAPI Elm_Animator* elm_animator_add(Evas_Object* parent) +EAPI Elm_Animator * +elm_animator_add(Evas_Object * parent) { - if(!parent) return NULL; - Elm_Animator* animator = calloc(1, sizeof(Elm_Animator)); - if(!animator) return NULL; - animator->parent = parent; - elm_animator_auto_reverse_set(animator, EINA_FALSE); - elm_animator_curve_style_set(animator, ELM_ANIMATOR_CURVE_LINEAR); - return animator; + if (!parent) + return NULL; + Elm_Animator *animator = calloc(1, sizeof(Elm_Animator)); + + if (!animator) + return NULL; + animator->parent = parent; + elm_animator_auto_reverse_set(animator, EINA_FALSE); + elm_animator_curve_style_set(animator, ELM_ANIMATOR_CURVE_LINEAR); + return animator; } /** @@ -298,10 +332,12 @@ EAPI Elm_Animator* elm_animator_add(Evas_Object* parent) * * @ingroup Animator */ -EAPI Eina_Bool elm_animator_operating_get(Elm_Animator* animator) +EAPI Eina_Bool +elm_animator_operating_get(Elm_Animator * animator) { - if(!animator) return EINA_FALSE; - return animator->on_animating; + if (!animator) + return EINA_FALSE; + return animator->on_animating; } /** @@ -311,11 +347,13 @@ EAPI Eina_Bool elm_animator_operating_get(Elm_Animator* animator) * * @ingroup Animator */ -EAPI void elm_animator_del(Elm_Animator* animator) +EAPI void +elm_animator_del(Elm_Animator * animator) { - if(!animator) return; - _delete_animator(animator); - free(animator); + if (!animator) + return; + _delete_animator(animator); + free(animator); } /** @@ -327,12 +365,16 @@ EAPI void elm_animator_del(Elm_Animator* animator) * * @ingroup Animator */ -EAPI void elm_animator_completion_callback_set(Elm_Animator* animator, void (*op)(void*), void* data) +EAPI void +elm_animator_completion_callback_set(Elm_Animator * animator, + void (*op) (void *), void *data) { - if(!animator) return NULL; - if(animator->on_animating == EINA_TRUE) return NULL; - animator->completion_op = op; - animator->completion_arg = data; + if (!animator) + return NULL; + if (animator->on_animating == EINA_TRUE) + return NULL; + animator->completion_op = op; + animator->completion_arg = data; } /** @@ -342,11 +384,13 @@ EAPI void elm_animator_completion_callback_set(Elm_Animator* animator, void (*op * * @ingroup Animator */ -EAPI void elm_animator_stop(Elm_Animator* animator) +EAPI void +elm_animator_stop(Elm_Animator * animator) { - if(!animator) return NULL; - animator->on_animating = EINA_FALSE; - _delete_animator(animator); + if (!animator) + return NULL; + animator->on_animating = EINA_FALSE; + _delete_animator(animator); } /** @@ -357,13 +401,15 @@ EAPI void elm_animator_stop(Elm_Animator* animator) * * @ingroup Animator */ -EAPI void elm_animator_repeat_set(Elm_Animator* animator, const unsigned int repeat_cnt) +EAPI void +elm_animator_repeat_set(Elm_Animator * animator, const unsigned int repeat_cnt) { - if(!animator) return NULL; - if( animator->auto_reverse == EINA_FALSE ) - animator->repeat_cnt = repeat_cnt; - else - animator->repeat_cnt = _animator_compute_reverse_repeat_count( repeat_cnt ); + if (!animator) + return NULL; + if (animator->auto_reverse == EINA_FALSE) + animator->repeat_cnt = repeat_cnt; + else + animator->repeat_cnt = _animator_compute_reverse_repeat_count(repeat_cnt); } /** @@ -373,16 +419,18 @@ EAPI void elm_animator_repeat_set(Elm_Animator* animator, const unsigned int rep * * @ingroup Animator */ -EAPI void elm_animator_animate(Elm_Animator* animator) +EAPI void +elm_animator_animate(Elm_Animator * animator) { - if(!animator) return NULL; - if(!animator->animator_op) return NULL; - animator->begin_time = ecore_loop_time_get(); - animator->on_animating = EINA_TRUE; - animator->cur_repeat_cnt = animator->repeat_cnt; - if(!animator->animator) - animator->animator = ecore_animator_add( _animator_animate_cb, animator ); - if(!animator->animator) animator->on_animating = EINA_FALSE; + if (!animator) + return NULL; + if (!animator->animator_op) + return NULL; + animator->begin_time = ecore_loop_time_get(); + animator->on_animating = EINA_TRUE; + animator->cur_repeat_cnt = animator->repeat_cnt; + if (!animator->animator) + animator->animator = ecore_animator_add(_animator_animate_cb, animator); + if (!animator->animator) + animator->on_animating = EINA_FALSE; } - - -- 2.7.4