From f55a69f8cc9f8ede29183494c0b36a41c914f737 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Mon, 16 Mar 2020 17:14:57 +0100 Subject: notifications --- src/languages.h | 274 ----------------------------------------------------- src/notification.c | 57 +++++++++++ src/notification.h | 21 ++++ 3 files changed, 78 insertions(+), 274 deletions(-) delete mode 100644 src/languages.h create mode 100644 src/notification.c create mode 100644 src/notification.h diff --git a/src/languages.h b/src/languages.h deleted file mode 100644 index d4da9c7..0000000 --- a/src/languages.h +++ /dev/null @@ -1,274 +0,0 @@ -/* -* BSD 2-Clause “Simplified” License -* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com -* All rights reserved. -*/ - -#define LANGUAGE_CODE_SIZE 3 - -#if 0 -typedef struct t_language -{ - char code[3]; - char fullname[40]; -} language; - -language global_langues[] = { - {"AD","Andorra"}, - {"AE","United Arab Emirates"}, - {"AF","Afghanistan"}, - {"AG",""}, - {"AI",""}, - {"AL",""}, - {"AM",""}, - {"AN",""}, - {"AO",""}, - {"AQ",""}, - {"AR",""}, - {"AS",""}, - {"AT",""}, - {"AU",""}, - {"AW",""}, - {"AX",""}, - {"AZ",""}, - {"BA",""}, - {"BB",""}, - {"BD",""}, - {"BE",""}, - {"BF",""}, - {"BG",""}, - {"BH",""}, - {"BI",""}, - {"BJ",""}, - {"BL",""}, - {"BM",""}, - {"BN",""}, - {"BO",""}, - {"BQ",""}, - {"BR",""}, - {"BS",""}, - {"BT",""}, - {"BV",""}, - {"BW",""}, - {"BY",""}, - {"BZ",""}, - {"CA",""}, - {"CC",""}, - {"CD",""}, - {"CF",""}, - {"CG",""}, - {"CH",""}, - {"CI",""}, - {"CK",""}, - {"CL",""}, - {"CM",""}, - {"CN",""}, - {"CO",""}, - {"CR",""}, - {"CU",""}, - {"CV",""}, - {"CW",""}, - {"CX",""}, - {"CY",""}, - {"CZ",""}, - {"DE",""}, - {"DJ",""}, - {"DK",""}, - {"DM",""}, - {"DO",""}, - {"DZ",""}, - {"EC",""}, - {"EE",""}, - {"EG",""}, - {"EH",""}, - {"ER",""}, - {"ES",""}, - {"ET",""}, - {"EU",""}, // remove? - {"FI",""}, - {"FJ",""}, - {"FK",""}, - {"FM",""}, - {"FO",""}, - {"FR",""}, - {"GA",""}, - {"GB",""}, - {"GD",""}, - {"GE",""}, - {"GF",""}, - {"GG",""}, - {"GH",""}, - {"GI",""}, - {"GL",""}, - {"GM",""}, - {"GN",""}, - {"GP",""}, - {"GQ",""}, - {"GR",""}, - {"GS",""}, - {"GT",""}, - {"GU",""}, - {"GW",""}, - {"GY",""}, - {"HK",""}, - {"HM",""}, - {"HN",""}, - {"HR",""}, - {"HT",""}, - {"HU",""}, - {"IC",""}, - {"ID",""}, - {"IE",""}, - {"IL",""}, - {"IM",""}, - {"IN",""}, - {"IO",""}, - {"IQ",""}, - {"IR",""}, - {"IS",""}, - {"IT",""}, - {"JE",""}, - {"JM",""}, - {"JO",""}, - {"JP",""}, - {"KE",""}, - {"KG",""}, - {"KH",""}, - {"KI",""}, - {"KM",""}, - {"KN",""}, - {"KP",""}, - {"KR",""}, - {"KW",""}, - {"KY",""}, - {"KZ",""}, - {"LA",""}, - {"LB",""}, - {"LC",""}, - {"LI",""}, - {"LK",""}, - {"LR",""}, - {"LS",""}, - {"LT",""}, - {"LU",""}, - {"LV",""}, - {"LY",""}, - {"MA",""}, - {"MC",""}, - {"MD",""}, - {"ME",""}, - {"MF",""}, - {"MG",""}, - {"MH",""}, - {"MK",""}, - {"ML",""}, - {"MM",""}, - {"MN",""}, - {"MO",""}, - {"MP",""}, - {"MQ",""}, - {"MR",""}, - {"MS",""}, - {"MT",""}, - {"MU",""}, - {"MV",""}, - {"MW",""}, - {"MX",""}, - {"MY",""}, - {"MZ",""}, - {"NA",""}, - {"NC",""}, - {"NE",""}, - {"NF",""}, - {"NG",""}, - {"NI",""}, - {"NL",""}, - {"NO",""}, - {"NP",""}, - {"NR",""}, - {"NU",""}, - {"NZ",""}, - {"OM",""}, - {"PA",""}, - {"PE",""}, - {"PF",""}, - {"PG",""}, - {"PH",""}, - {"PK",""}, - {"PL",""}, - {"PM",""}, - {"PN",""}, - {"PR",""}, - {"PS",""}, - {"PT",""}, - {"PW",""}, - {"PY",""}, - {"QA",""}, - {"RE",""}, - {"RO",""}, - {"RS",""}, - {"RU",""}, - {"RW",""}, - {"SA",""}, - {"SB",""}, - {"SC",""}, - {"SD",""}, - {"SE",""}, - {"SG",""}, - {"SH",""}, - {"SI",""}, - {"SJ",""}, - {"SK",""}, - {"SL",""}, - {"SM",""}, - {"SN",""}, - {"SO",""}, - {"SR",""}, - {"SS",""}, - {"ST",""}, - {"SV",""}, - {"SX",""}, - {"SY",""}, - {"SZ",""}, - {"TC",""}, - {"TD",""}, - {"TF",""}, - {"TG",""}, - {"TH",""}, - {"TJ",""}, - {"TK",""}, - {"TL",""}, - {"TM",""}, - {"TN",""}, - {"TO",""}, - {"TR",""}, - {"TT",""}, - {"TV",""}, - {"TW",""}, - {"TZ",""}, - {"UA",""}, - {"UG",""}, - {"UM",""}, - {"US",""}, - {"UY",""}, - {"UZ",""}, - {"VA",""}, - {"VC",""}, - {"VE",""}, - {"VG",""}, - {"VI",""}, - {"VN",""}, - {"VU",""}, - {"WF",""}, - {"WS",""}, - {"XK",""}, - {"YE",""}, - {"YT",""}, - {"ZA",""}, - {"ZM",""}, - {"ZW",""}, -}; - -#define COUNTRY_CODE_COUNT (sizeof(global_langues)/sizeof(language)) - -#endif \ No newline at end of file diff --git a/src/notification.c b/src/notification.c new file mode 100644 index 0000000..f89ca48 --- /dev/null +++ b/src/notification.c @@ -0,0 +1,57 @@ +/* +* 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, &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++) + { + notification *n = array_at(&global_notifications, i); + float32 duration_ms = (float32)n->duration/TARGET_FRAMERATE; + s32 y = 0; + + if (duration_ms < fade_duration) + y = main_window->height - ((duration_ms/fade_duration)*(box_h + 30.0f)); + else if (duration_ms > show_duration) + y = main_window->height - ((box_h + 30.0f) - ((duration_ms-show_duration)/fade_duration)*(box_h + 30.0f)); + else + y = main_window->height - box_h - 30; + + s32 w = calculate_text_width(global_ui_context.font_small, n->message) + (padding*2); + s32 x = 30; + + render_rectangle(x+4, y+4, w,box_h, rgba(100,0,0, 100)); + render_rectangle(x, y, w,box_h, rgb(200,0,0)); + 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; + } +} diff --git a/src/notification.h b/src/notification.h new file mode 100644 index 0000000..752204d --- /dev/null +++ b/src/notification.h @@ -0,0 +1,21 @@ +/* +* BSD 2-Clause “Simplified” License +* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com +* All rights reserved. +*/ + +#ifndef INCLUDE_NOTIFICATION +#define INCLUDE_NOTIFICATION + +typedef struct t_notification +{ + char *message; + u16 duration; +} notification; + +array global_notifications; + +void push_notification(char *message); +void update_render_notifications(); + +#endif -- cgit v1.2.3-70-g09d2