From 305c090e316f28707c44a0bd6ba53f56529b4c38 Mon Sep 17 00:00:00 2001 From: Sheldon Lee Date: Sat, 11 Jul 2020 02:08:17 +0100 Subject: [PATCH] In progress for more type flexibilty for UI. --- game.c | 4 ++-- ui.c | 7 +++++-- ui.h | 13 ++++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/game.c b/game.c index 993b283..c86f46f 100644 --- a/game.c +++ b/game.c @@ -49,8 +49,8 @@ void initGame() // stdscr is screen created by initscr() getmaxyx(stdscr, height, width); - addLinei("x:", &cursor.x); - addLinei("y:", &cursor.y); + addLinei("x:", &cursor.x, 1, UI_INT); + addLinei("y:", &cursor.y, 1, UI_INT); grid = initGrid(width, height); //randomizeGrid(grid); diff --git a/ui.c b/ui.c index 294d92d..e2a9fcb 100644 --- a/ui.c +++ b/ui.c @@ -5,7 +5,10 @@ typedef struct { char* msg; - int* var; + void* var; + size_t size; + ui_type type; + }Linei; static unsigned int ln_count = 0; @@ -14,7 +17,7 @@ static Linei* lines = NULL; static void startUI(); -void addLinei(char* msg, int* var) +void addLinei(char* msg, void* var, int size, ui_type type) { if (!lines) startUI(); else lines = realloc(lines, sizeof(Linei) * ++ln_count); diff --git a/ui.h b/ui.h index 9f24b81..60f84ef 100644 --- a/ui.h +++ b/ui.h @@ -1,9 +1,20 @@ #ifndef UI_H #define UI_H +#define ui_type uint8_t + +#define ui_int int +#define ui_float float +#define ui_char char + +#define UI_NULL 0 +#define UI_INT 1 +#define UI_FLOAT 2 +#define UI_CHAR 3 + //void startUI(); -void addLinei(char* msg, int* var); +void addLinei(char* msg, void* var, int size, ui_type type); void drawUI();