From 1e9d84e9af9fc185fc7b56f596affca247dac591 Mon Sep 17 00:00:00 2001 From: Caillou15 Date: Thu, 13 Jan 2022 11:02:23 +0100 Subject: [PATCH] =?UTF-8?q?cr=C3=A9ation=20de=20l'=C3=A9cran=20d'accueil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui.c | 37 +++++++++++++++++++++++++++++++ src/gui.h | 12 ++++++++++ src/main.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 src/gui.c create mode 100644 src/gui.h create mode 100644 src/main.c diff --git a/src/gui.c b/src/gui.c new file mode 100644 index 0000000..e42ce96 --- /dev/null +++ b/src/gui.c @@ -0,0 +1,37 @@ +#define BUTTON_HEIGHT 39 +#define TEXTURE_POSITION_BUTTON_NORMAL 132 +#define TEXTURE_POSITION_BUTTON_HIGHLIGHTED 172 +#define TEXTURE_POSITION_BUTTON_DESACTIVATED 92 + +#include + +/* shows a button + @state : + 0 : desactivated + 1 : normal + 2 : highlighted +*/ +void show_button(int x, int y, int size, char const *text, bopti_image_t *img_widgets, int state) { + if (size > 300) { + size = 300; + } + + int texture_position = 0; + + if (state == 0) { + texture_position = TEXTURE_POSITION_BUTTON_DESACTIVATED; + } else if (state == 1) { + texture_position = TEXTURE_POSITION_BUTTON_NORMAL; + } else { + texture_position = TEXTURE_POSITION_BUTTON_HIGHLIGHTED; + } + + // left border + dsubimage(x, y, img_widgets, 0, texture_position, 4, BUTTON_HEIGHT, 0x01); + // middle + dsubimage(x + 4, y, img_widgets, 4, texture_position, size - 8, BUTTON_HEIGHT, 0x01); + // right border + dsubimage(x + size - 4, y, img_widgets, 296, texture_position, 4, BUTTON_HEIGHT, 0x01); + //text + dtext_opt(x + (size / 2), y + (BUTTON_HEIGHT / 2) - 3, C_WHITE, -1, 1, 0, text, 14); +} diff --git a/src/gui.h b/src/gui.h new file mode 100644 index 0000000..fe1f32d --- /dev/null +++ b/src/gui.h @@ -0,0 +1,12 @@ +#ifndef GUI_H +#define GUI_H + +/* shows a button + @state : + 0 : desactivated + 1 : normal + 2 : highlighted +*/ +void show_button(int x, int y, int size, char const *text, bopti_image_t *img_widgets, int state); + +#endif \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..db72c9e --- /dev/null +++ b/src/main.c @@ -0,0 +1,65 @@ +#include +#include +#include "gui.h" + +void draw_menu(int selected) +{ + //TODO : corriger le problème des string + + extern bopti_image_t img_logo; + extern bopti_image_t img_widgets; + + //dclear(C_RGB(17,9,2)); + dclear(C_RGB(21,9,5)); + //dimage(72,20, &img_logo); + dimage(40,10,&img_logo); + + for(int i = 1; i <= 2; i++) + { + int x = 100; + int y = 100 + 45*(i-1); + char *text = ""; + + if (i==1) + text = "Jouer"; + else + text = "Paramètre"; + + if (i==selected) + show_button(x, y, 200, text, &img_widgets, 2); + else + show_button(x, y, 200, text, &img_widgets, 1); + + } +} + +int main(void) +{ + + extern bopti_image_t img_widgets; + + //dtext(1, 1, C_WHITE, "Sample fxSDK add-in."); + + //dimage(40, 10, &img_widgets); + show_button(100, 100, 200, "Jouer", &img_widgets, 1); + dupdate(); + + int selected = 1; + int key = 0; + + while (key != KEY_EXE) + { + draw_menu(selected); + dupdate(); + + key = getkey().key; + + if (key == KEY_UP && selected == 2) + selected--; + if (key == KEY_DOWN && selected == 1) + selected++; + } + + getkey(); + return 1; +}