diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-07-02 00:58:50 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-07-02 00:58:50 +0200 |
| commit | f4357485e6febf90be34524824b15f771b6cd310 (patch) | |
| tree | b49ed843b798093163b771a1f32109076caac18b /src/menu | |
| parent | c10ca65109c02f239e95ebaf20fde708bcf3dc38 (diff) | |
| download | jancity-f4357485e6febf90be34524824b15f771b6cd310.tar.gz | |
menu: implement main menu using new GUI improvements
Diffstat (limited to 'src/menu')
| -rw-r--r-- | src/menu/src/menu.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/menu/src/menu.c b/src/menu/src/menu.c index 41adbb5..38f8632 100644 --- a/src/menu/src/menu.c +++ b/src/menu/src/menu.c @@ -4,6 +4,7 @@ #include <gfx.h> #include <gui.h> #include <gui/button.h> +#include <gui/container.h> #include <system.h> #include <stdbool.h> @@ -15,22 +16,35 @@ static void on_pressed(void *const arg) int menu(void) { struct camera cam = {0}; - struct gui_button play; + struct gui_button play, exit_btn; + struct gui_container cnt; union peripheral p; - bool start = false; + bool start = false, exit = false; if (game_resinit()) return -1; cursor_init(&cam.cursor); + gui_container_init(&cnt); + cnt.mode = GUI_CONTAINER_MODE_V; + cnt.common.hcentered = true; + cnt.common.vcentered = true; gui_button_init(&play); + gui_button_init(&exit_btn); play.on_pressed = on_pressed; play.arg = &start; play.w = 140; play.common.hcentered = true; - play.common.vcentered = true; play.label.text = "Play"; + exit_btn.arg = &exit; + exit_btn.w = 140; + exit_btn.common.hcentered = true; + exit_btn.label.text = "Exit"; + exit_btn.on_pressed = on_pressed; + gui_add_child(&cnt.common, &play.common); + gui_add_child(&cnt.common, &exit_btn.common); + { const struct peripheral_cfg cfg = { @@ -46,9 +60,6 @@ int menu(void) peripheral_update(&p); camera_update(&cam, &p); - play.label.common.x = play.w / 2 - 20; - play.label.common.y = 4; - if (gui_update(&play.common, &p, &cam)) return -1; @@ -58,10 +69,10 @@ int menu(void) r->h = screen_h; rect_sort(r); - if (p.common.exit) + if (p.common.exit || exit) return 0; - if (gui_render(&play.common) + if (gui_render(&cnt.common) || cursor_render(&cam.cursor) || gfx_draw()) return -1; |
