mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
improve widget animator fix issue #184
This commit is contained in:
parent
29bd388985
commit
ce90a61e19
@ -2,6 +2,7 @@
|
||||
* 2019/07/19
|
||||
* Slider的图标用ICON方式绘制。
|
||||
* 增加属性with\_focus\_state,如果希望控件具有焦点状态,有不希望焦点停留,可以用本属性代替focusable属性。
|
||||
* 完善控件动画。
|
||||
|
||||
* 2019/07/18
|
||||
* gles的canvas画直线和画矩形边框的线宽问题,gles统一和agge一样为1线宽(感谢智明提供补丁)。
|
||||
|
@ -170,6 +170,7 @@ struct _widget_animator_t {
|
||||
widget_animator_destroy_t destroy;
|
||||
|
||||
/*private*/
|
||||
bool_t to_dispatch;
|
||||
struct _widget_animator_t* next;
|
||||
widget_animator_manager_t* widget_animator_manager;
|
||||
};
|
||||
|
@ -24,18 +24,42 @@
|
||||
|
||||
static widget_animator_manager_t* s_animator_manager;
|
||||
|
||||
static ret_t widget_animator_manager_set_to_dispatch(widget_animator_manager_t* am) {
|
||||
widget_animator_t* iter = am->first;
|
||||
|
||||
while (iter != NULL) {
|
||||
iter->to_dispatch = TRUE;
|
||||
iter = iter->next;
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static widget_animator_t* widget_animator_manager_get_to_dispatch(widget_animator_manager_t* am) {
|
||||
widget_animator_t* iter = am->first;
|
||||
|
||||
while (iter != NULL) {
|
||||
if (iter->to_dispatch) {
|
||||
return iter;
|
||||
}
|
||||
iter = iter->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret_t widget_animator_manager_time_elapse(widget_animator_manager_t* am, uint32_t delta_time) {
|
||||
widget_animator_t* iter = NULL;
|
||||
return_value_if_fail(am != NULL, RET_BAD_PARAMS);
|
||||
|
||||
delta_time = delta_time * am->time_scale;
|
||||
widget_animator_manager_set_to_dispatch(am);
|
||||
|
||||
iter = am->first;
|
||||
iter = widget_animator_manager_get_to_dispatch(am);
|
||||
while (iter != NULL) {
|
||||
widget_animator_t* next = iter->next;
|
||||
|
||||
iter->to_dispatch = FALSE;
|
||||
widget_animator_time_elapse(iter, delta_time);
|
||||
iter = next;
|
||||
iter = widget_animator_manager_get_to_dispatch(am);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
|
@ -13,7 +13,6 @@ TEST(AnimatorManager, basic) {
|
||||
widget_t* widget = WIDGET(image);
|
||||
|
||||
ASSERT_EQ(widget_animator_set_name(wa, "foo"), RET_OK);
|
||||
;
|
||||
ASSERT_EQ(widget_animator_manager_count(am), 1);
|
||||
|
||||
widget_animator_destroy(wa);
|
||||
@ -21,7 +20,6 @@ TEST(AnimatorManager, basic) {
|
||||
|
||||
wa = widget_animator_rotation_create(WIDGET(image), 1000, 0, EASING_LINEAR);
|
||||
ASSERT_EQ(widget_animator_set_name(wa, "foo"), RET_OK);
|
||||
;
|
||||
|
||||
ASSERT_EQ(wa->state, ANIMATOR_CREATED);
|
||||
ASSERT_EQ(widget_animator_manager_start(am, NULL, NULL), RET_OK);
|
||||
@ -43,3 +41,27 @@ TEST(AnimatorManager, basic) {
|
||||
widget_destroy(WIDGET(image));
|
||||
ASSERT_EQ(widget_animator_manager_count(am), 0);
|
||||
}
|
||||
|
||||
static ret_t on_anim_done(void* ctx, event_t* e) {
|
||||
widget_animator_manager_remove_all(widget_animator_manager(), NULL, NULL);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
TEST(AnimatorManager, elapse) {
|
||||
image_t* image = IMAGE(image_create(NULL, 0, 0, 100, 30));
|
||||
widget_animator_t* wa1 = widget_animator_rotation_create(WIDGET(image), 1000, 0, EASING_LINEAR);
|
||||
widget_animator_t* wa2 = widget_animator_rotation_create(WIDGET(image), 2000, 0, EASING_LINEAR);
|
||||
widget_animator_rotation_set_params(wa1, 0, 100);
|
||||
widget_animator_rotation_set_params(wa2, 0, 100);
|
||||
|
||||
widget_animator_manager_t* am = widget_animator_manager();
|
||||
|
||||
ASSERT_EQ(widget_animator_manager_count(am), 2);
|
||||
ASSERT_EQ(widget_animator_manager_start(am, NULL, NULL), RET_OK);
|
||||
|
||||
emitter_on(&(wa1->emitter), EVT_ANIM_END, on_anim_done, NULL);
|
||||
widget_animator_manager_time_elapse(am, 1000);
|
||||
|
||||
ASSERT_EQ(widget_animator_manager_count(am), 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user