summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik.ramaekers@protonmail.com>2020-03-16 17:14:57 +0100
committerAldrik Ramaekers <aldrik.ramaekers@protonmail.com>2020-03-16 17:14:57 +0100
commitf55a69f8cc9f8ede29183494c0b36a41c914f737 (patch)
tree815d1d26164db3498731b530dd4961bb44f76dc8 /src
parenta6f78aad38333e216ced74e6c51f3449c17dd7b7 (diff)
notifications
Diffstat (limited to 'src')
-rw-r--r--src/languages.h274
-rw-r--r--src/notification.c57
-rw-r--r--src/notification.h21
3 files changed, 78 insertions, 274 deletions
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