From d35f747b5a09a7a6cb8c430999c9e567a13005ef Mon Sep 17 00:00:00 2001 From: natinusala Date: Tue, 13 Nov 2018 14:33:32 +0100 Subject: [PATCH] menu_animation: add menu_timer system --- .vscode/settings.json | 3 ++- menu/menu_animation.c | 27 +++++++++++++++++++++++++++ menu/menu_animation.h | 13 +++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 97b14ee97e..0d11e3b03f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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, } \ No newline at end of file diff --git a/menu/menu_animation.c b/menu/menu_animation.c index 68c6260fbb..d2b2b0f72f 100644 --- a/menu/menu_animation.c +++ b/menu/menu_animation.c @@ -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); +} diff --git a/menu/menu_animation.h b/menu/menu_animation.h index 6983237719..d1bc513489 100644 --- a/menu/menu_animation.h +++ b/menu/menu_animation.h @@ -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);