forked from enlightenment/efl
efl_canvas_object_animation: support duration 0
The duration of animation means how long the animation is executed. Therefore, if duration is 0, then the final state of animation should be applied to the target object immediately. In this case, if final_state_keep is true, then the final state of animation is preserved. Otherwise, the final state of animation is not preserved. ref T8436, T8513 Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D10812
This commit is contained in:
parent
4398ec7b3b
commit
cb817caa80
|
@ -9,7 +9,7 @@ _efl_canvas_animation_duration_set(Eo *eo_obj EINA_UNUSED,
|
|||
Efl_Canvas_Animation_Data *pd,
|
||||
double sec)
|
||||
{
|
||||
EINA_SAFETY_ON_FALSE_RETURN(sec > 0.0);
|
||||
EINA_SAFETY_ON_FALSE_RETURN(sec >= 0.0);
|
||||
pd->duration = sec;
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ _efl_canvas_animation_efl_object_constructor(Eo *obj, Efl_Canvas_Animation_Data
|
|||
EOLIAN static void
|
||||
_efl_canvas_animation_default_duration_set(double animation_time)
|
||||
{
|
||||
EINA_SAFETY_ON_FALSE_RETURN(animation_time > 0.0);
|
||||
EINA_SAFETY_ON_FALSE_RETURN(animation_time >= 0.0);
|
||||
_default_animation_time = animation_time;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,15 @@ _animator_cb(void *data, const Efl_Event *ev EINA_UNUSED)
|
|||
|
||||
duration = efl_animation_duration_get(pd->in->animation) / pd->in->speed;
|
||||
elapsed_time = current - pd->in->run_start_time;
|
||||
vector = elapsed_time / duration;
|
||||
if (EINA_DBL_EQ(duration, 0))
|
||||
{
|
||||
if (pd->in->speed < 0.0)
|
||||
vector = -1.0;
|
||||
else
|
||||
vector = 1.0;
|
||||
}
|
||||
else
|
||||
vector = elapsed_time / duration;
|
||||
|
||||
/* When animation player starts, _animator_cb() is called immediately so
|
||||
* both elapsed time and progress are 0.0.
|
||||
|
|
|
@ -42,8 +42,50 @@ EFL_START_TEST(efl_canvas_animation_default_value)
|
|||
}
|
||||
EFL_END_TEST
|
||||
|
||||
static void
|
||||
_duration_zero_anim_running_cb(void *data, const Efl_Event *event)
|
||||
{
|
||||
double animation_speed = *((double*) data);
|
||||
double animation_running_position = *((double*) event->info);
|
||||
|
||||
if (animation_speed > 0.0)
|
||||
ck_assert(EINA_DBL_EQ(animation_running_position, 1.0));
|
||||
else
|
||||
ck_assert(EINA_DBL_EQ(animation_running_position, 0.0));
|
||||
}
|
||||
|
||||
static void
|
||||
helper_inc_int(void *data, const Efl_Event *event EINA_UNUSED)
|
||||
{
|
||||
int *called = (int*) data;
|
||||
*called+=1;
|
||||
}
|
||||
|
||||
EFL_START_TEST(efl_canvas_animation_duration_zero)
|
||||
{
|
||||
int running = 0;
|
||||
Evas *evas = EVAS_TEST_INIT_EVAS();
|
||||
Efl_Canvas_Rectangle *obj = efl_add(EFL_CANVAS_RECTANGLE_CLASS, evas);
|
||||
Efl_Canvas_Animation *animation = efl_add(EFL_CANVAS_ANIMATION_CLASS, evas, efl_animation_duration_set(efl_added, 0.0));
|
||||
|
||||
double animation_speed = 1.0;
|
||||
efl_event_callback_add(obj, EFL_CANVAS_OBJECT_ANIMATION_EVENT_ANIMATION_PROGRESS_UPDATED, _duration_zero_anim_running_cb, &animation_speed);
|
||||
efl_event_callback_add(obj, EFL_CANVAS_OBJECT_ANIMATION_EVENT_ANIMATION_PROGRESS_UPDATED, helper_inc_int , &running);
|
||||
efl_canvas_object_animation_start(obj, animation, animation_speed, 0.0);
|
||||
ck_assert(EINA_DBL_EQ(efl_canvas_object_animation_progress_get(obj), -1.0));
|
||||
ck_assert_int_eq(running, 1);
|
||||
|
||||
running = 0;
|
||||
animation_speed = -1.0;
|
||||
efl_canvas_object_animation_start(obj, animation, animation_speed, 0.0);
|
||||
ck_assert(EINA_DBL_EQ(efl_canvas_object_animation_progress_get(obj), -1.0));
|
||||
ck_assert_int_eq(running, 1);
|
||||
}
|
||||
EFL_END_TEST
|
||||
|
||||
void efl_test_canvas_animation(TCase *tc)
|
||||
{
|
||||
tcase_add_test(tc, efl_canvas_animation_negative_double_checking);
|
||||
tcase_add_test(tc, efl_canvas_animation_default_value);
|
||||
tcase_add_test(tc, efl_canvas_animation_duration_zero);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue