menu: implement main menu using new GUI improvements

This commit is contained in:
Xavier Del Campo Romero 2022-07-02 00:58:50 +02:00
parent e68c2fb4be
commit a71ce37929
1 changed files with 19 additions and 8 deletions

View File

@ -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;