diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-11-23 22:33:43 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-11-23 22:33:43 +0100 |
| commit | b1e857cf1471d1871a9396696b22fa531da98249 (patch) | |
| tree | 3923008a8653057698cb339faf6dcfa92e18364b /project-base/src/notification.c | |
| parent | 106bb7fcadf637cec883648916cc8d19529d6199 (diff) | |
add projbase to repo
Diffstat (limited to 'project-base/src/notification.c')
| -rw-r--r-- | project-base/src/notification.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/project-base/src/notification.c b/project-base/src/notification.c new file mode 100644 index 0000000..78d81ff --- /dev/null +++ b/project-base/src/notification.c @@ -0,0 +1,59 @@ +/* +* BSD 2-Clause “Simplified” License +* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com +* All rights reserved. +*/ + +void push_notification(char *message) +{ + if (!global_notifications.data) + { + global_notifications = array_create(sizeof(notification)); + array_reserve(&global_notifications, 10); + } + + s32 len = strlen(message)+1; + + notification new_notification; + new_notification.message = mem_alloc(len); + new_notification.duration = 0; + string_copyn(new_notification.message, message, len); + array_push(&global_notifications, (uint8_t *)&new_notification); +} + +void update_render_notifications() +{ + const s32 padding = 10; + const s32 box_h = global_ui_context.font_small->px_h + (padding*2); + const float32 fade_duration = 0.1f; + const float32 show_duration = 1.0f; + + for (s32 i = 0; i < global_notifications.length; i++) + { + // global_ui_context.active_window->do_draw = true; // ?? + + notification *n = array_at(&global_notifications, i); + float32 duration_ms = (float32)n->duration/TARGET_FRAMERATE; + s32 y = 0; + + if (duration_ms < fade_duration) + y = global_ui_context.active_window->height - ((duration_ms/fade_duration)*(box_h + 30.0f)); + else if (duration_ms > show_duration) + y = global_ui_context.active_window->height - ((box_h + 30.0f) - ((duration_ms-show_duration)/fade_duration)*(box_h + 30.0f)); + else + y = global_ui_context.active_window->height - box_h - 30; + + s32 w = renderer->calculate_text_width(global_ui_context.font_small, n->message) + (padding*2); + s32 x = 30; + + renderer->render_rectangle(x+4, y+4, w,box_h, rgba(100,0,0, 100)); + renderer->render_rectangle(x, y, w,box_h, rgb(200,0,0)); + renderer->render_text(global_ui_context.font_small, x + padding, y + padding, n->message, rgb(255,255,255)); + + n->duration++; + + if (duration_ms > show_duration+fade_duration) + array_remove_at(&global_notifications, i); + break; + } +} |
