menu_animation: add menu_timer system

This commit is contained in:
natinusala 2018-11-13 14:33:32 +01:00
parent 2c628860c8
commit d35f747b5a
3 changed files with 42 additions and 1 deletions

View File

@ -27,7 +27,8 @@
"menu_driver.h": "c",
"file_path.h": "c",
"unordered_map": "c",
"unordered_set": "c"
"unordered_set": "c",
"sstream": "cpp"
},
"C_Cpp.dimInactiveRegions": false,
}

View File

@ -711,3 +711,30 @@ bool menu_animation_ctl(enum menu_animation_ctl_state state, void *data)
return true;
}
void menu_timer_start(menu_timer_t *timer, menu_timer_ctx_entry_t *timer_entry)
{
menu_animation_ctx_tag tag = (uintptr_t) timer;
menu_timer_kill(timer);
*timer = 0.0f;
menu_animation_ctx_entry_t entry;
entry.easing_enum = EASING_LINEAR;
entry.tag = tag;
entry.duration = timer_entry->duration;
entry.target_value = 1.0f;
entry.subject = timer;
entry.cb = timer_entry->cb;
entry.userdata = timer_entry->userdata;
menu_animation_push(&entry);
}
void menu_timer_kill(menu_timer_t *timer)
{
menu_animation_ctx_tag tag = (uintptr_t) timer;
menu_animation_kill_by_tag(&tag);
}

View File

@ -118,6 +118,19 @@ typedef struct menu_animation_ctx_ticker
const char *str;
} menu_animation_ctx_ticker_t;
typedef float menu_timer_t;
typedef struct menu_timer_ctx_entry
{
float duration;
tween_cb cb;
void *userdata;
} menu_timer_ctx_entry_t;
void menu_timer_start(menu_timer_t *timer, menu_timer_ctx_entry_t *timer_entry);
void menu_timer_kill(menu_timer_t *timer);
bool menu_animation_update(float delta_time);
bool menu_animation_get_ideal_delta_time(menu_animation_ctx_delta_t *delta);