fix(anim): add lv_anim_get_playtime (#2745)
and migrate lv_anim_timeline_get_playtime to lv_anim_get_playtime Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
@@ -116,6 +116,27 @@ lv_anim_t * lv_anim_start(const lv_anim_t * a)
|
|||||||
return new_anim;
|
return new_anim;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t lv_anim_get_playtime(lv_anim_t * a)
|
||||||
|
{
|
||||||
|
uint32_t playtime = LV_ANIM_PLAYTIME_INFINITE;
|
||||||
|
|
||||||
|
if(a->repeat_cnt == LV_ANIM_REPEAT_INFINITE)
|
||||||
|
return playtime;
|
||||||
|
|
||||||
|
playtime = a->time - a->act_time;
|
||||||
|
if(a->playback_now == 0)
|
||||||
|
playtime += a->playback_delay + a->playback_time;
|
||||||
|
|
||||||
|
if(a->repeat_cnt <= 1)
|
||||||
|
return playtime;
|
||||||
|
|
||||||
|
playtime += (a->repeat_delay + a->time +
|
||||||
|
a->playback_delay + a->playback_time) *
|
||||||
|
(a->repeat_cnt - 1);
|
||||||
|
|
||||||
|
return playtime;
|
||||||
|
}
|
||||||
|
|
||||||
bool lv_anim_del(void * var, lv_anim_exec_xcb_t exec_cb)
|
bool lv_anim_del(void * var, lv_anim_exec_xcb_t exec_cb)
|
||||||
{
|
{
|
||||||
lv_anim_t * a;
|
lv_anim_t * a;
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ extern "C" {
|
|||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
|
|
||||||
|
#define LV_ANIM_REPEAT_INFINITE 0xFFFF
|
||||||
|
#define LV_ANIM_PLAYTIME_INFINITE 0xFFFFFFFF
|
||||||
|
|
||||||
|
LV_EXPORT_CONST_INT(LV_ANIM_REPEAT_INFINITE);
|
||||||
|
LV_EXPORT_CONST_INT(LV_ANIM_PLAYTIME_INFINITE);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
**********************/
|
**********************/
|
||||||
@@ -33,9 +39,6 @@ typedef enum {
|
|||||||
LV_ANIM_ON,
|
LV_ANIM_ON,
|
||||||
} lv_anim_enable_t;
|
} lv_anim_enable_t;
|
||||||
|
|
||||||
#define LV_ANIM_REPEAT_INFINITE 0xFFFF
|
|
||||||
LV_EXPORT_CONST_INT(LV_ANIM_REPEAT_INFINITE);
|
|
||||||
|
|
||||||
struct _lv_anim_t;
|
struct _lv_anim_t;
|
||||||
|
|
||||||
/** Get the current value during an animation*/
|
/** Get the current value during an animation*/
|
||||||
@@ -300,6 +303,13 @@ static inline uint32_t lv_anim_get_delay(lv_anim_t * a)
|
|||||||
return -a->act_time;
|
return -a->act_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the time used to play the animation.
|
||||||
|
* @param a pointer to an animation.
|
||||||
|
* @return the play time in milliseconds.
|
||||||
|
*/
|
||||||
|
uint32_t lv_anim_get_playtime(lv_anim_t * a);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the user_data field of the animation
|
* Get the user_data field of the animation
|
||||||
* @param a pointer to an initialized `lv_anim_t` variable
|
* @param a pointer to an initialized `lv_anim_t` variable
|
||||||
|
|||||||
@@ -169,7 +169,10 @@ uint32_t lv_anim_timeline_get_playtime(lv_anim_timeline_t * at)
|
|||||||
|
|
||||||
uint32_t playtime = 0;
|
uint32_t playtime = 0;
|
||||||
for(uint32_t i = 0; i < at->anim_dsc_cnt; i++) {
|
for(uint32_t i = 0; i < at->anim_dsc_cnt; i++) {
|
||||||
uint32_t end = at->anim_dsc[i].start_time + at->anim_dsc[i].anim.time;
|
uint32_t end = lv_anim_get_playtime(&at->anim_dsc[i].anim);
|
||||||
|
if (end == LV_ANIM_PLAYTIME_INFINITE)
|
||||||
|
return end;
|
||||||
|
end += at->anim_dsc[i].start_time;
|
||||||
if(end > playtime) {
|
if(end > playtime) {
|
||||||
playtime = end;
|
playtime = end;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user