From a71ce379297384df42e720641d39a4d2ade6bbd9 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sat, 2 Jul 2022 00:58:50 +0200 Subject: menu: implement main menu using new GUI improvements --- src/menu/src/menu.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src') 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 #include #include +#include #include #include @@ -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; -- cgit v1.2.3