diff --git a/CMakeLists.txt b/CMakeLists.txt index d0f12d9..d924dcb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,8 @@ set(SOURCES src/bar/update.c src/bar/draw.c src/bar/change.c + src/choice/init.c + src/choice/draw.c ) set(ASSETS diff --git a/include/choice.h b/include/choice.h new file mode 100644 index 0000000..25e1f5e --- /dev/null +++ b/include/choice.h @@ -0,0 +1,27 @@ +#pragma once + +#include "locale.h" +#include + +#ifdef LANG_FR +#define CHOICE_YES "OUI" +#define CHOICE_NO "NON" +#define CHOICE_OK "OK" +#endif + +#ifdef LANG_EN +#define CHOICE_YES "YES" +#define CHOICE_NO "NO" +#define CHOICE_OK "OK" +#endif + +#define BUTTON_WIDTH 52 +#define BUTTON_HEIGHT 32 +#define BUTTON_Y (DHEIGHT - BUTTON_HEIGHT * 1.7) + +struct Choice { + int cursor; +}; + +struct Choice choice_init(void); +void choice_draw(struct Choice choice); diff --git a/include/locale.h b/include/locale.h new file mode 100644 index 0000000..7f4a6d0 --- /dev/null +++ b/include/locale.h @@ -0,0 +1,4 @@ +#pragma once + +/* #define LANG_FR */ +#define LANG_EN diff --git a/src/choice/draw.c b/src/choice/draw.c new file mode 100644 index 0000000..11cfb9e --- /dev/null +++ b/src/choice/draw.c @@ -0,0 +1,33 @@ +#include "choice.h" +#include + +static char *yes = CHOICE_YES; +static char *no = CHOICE_NO; +/* static char *ok = CHOICE_OK; */ + +static void button_draw(int id, int highlight); + +void +choice_draw(struct Choice choice) +{ + int i; + + i = 2; + while (i-- > 0) + button_draw(i, choice.cursor == i); +} + +static void +button_draw(int id, int highlight) +{ + const int x = id ? (DWIDTH / 2 - BUTTON_WIDTH * 1.5) + : (DWIDTH / 2 + BUTTON_WIDTH * 0.5); + const int y = BUTTON_Y; + const int text_x = x + BUTTON_WIDTH / 2; + const int text_y = y + BUTTON_HEIGHT / 2; + const color_t color = highlight ? C_LIGHT : C_DARK; + + drect(x, y, x + BUTTON_WIDTH, y + BUTTON_HEIGHT, color); + dtext_opt(text_x, text_y, C_WHITE, C_NONE, DTEXT_CENTER, DTEXT_MIDDLE, + id ? no : yes); +} diff --git a/src/choice/init.c b/src/choice/init.c new file mode 100644 index 0000000..5ab0520 --- /dev/null +++ b/src/choice/init.c @@ -0,0 +1,7 @@ +#include "choice.h" + +struct Choice +choice_init(void) +{ + return (struct Choice){.cursor = 0}; +} diff --git a/src/main.c b/src/main.c index 8c80f02..e0cd8f2 100644 --- a/src/main.c +++ b/src/main.c @@ -1,8 +1,10 @@ #include "bar.h" +#include "choice.h" #include #include static struct Bar bars[BAR_TOTAL]; +static struct Choice choice; static void main_draw(void); @@ -14,6 +16,7 @@ main(void) /* init */ for (i = 0; i < BAR_TOTAL; i += 1) bars[i] = bar_init(i); + choice = choice_init(); bar_change(&bars[BAR_CASH], 0.2); bar_change(&bars[BAR_SMILE], 0.4); @@ -30,8 +33,6 @@ main_draw(void) extern bopti_image_t bimg_background; int i; - dclear(C_WHITE); - /* draw background */ dimage(0, 0, &bimg_background); @@ -39,5 +40,8 @@ main_draw(void) for (i = 0; i < BAR_TOTAL; i += 1) bar_draw(bars[i]); + /* draw choice */ + choice_draw(choice); + dupdate(); }