rts/src/menu/src/menu.c

76 lines
1.4 KiB
C
Raw Normal View History

2022-06-24 17:53:46 +02:00
#include <menu.h>
2022-07-07 02:13:14 +02:00
#include <menu_private.h>
2022-06-24 17:53:46 +02:00
#include <camera.h>
#include <game.h>
#include <gfx.h>
2022-07-07 02:13:14 +02:00
#include <peripheral.h>
2022-06-24 17:53:46 +02:00
#include <system.h>
#include <stdbool.h>
2022-07-07 02:13:14 +02:00
void menu_on_pressed(void *const arg)
2022-06-24 17:53:46 +02:00
{
*(bool *)arg = true;
}
2022-07-07 02:13:14 +02:00
int menu_update(struct menu_common *const c,
int (*update)(struct menu_common *, void *),
int (*render)(const struct menu_common *, void *),
void *const arg)
2022-06-24 17:53:46 +02:00
{
2022-07-07 02:13:14 +02:00
system_loop();
peripheral_update(&c->p);
camera_update(&c->cam, &c->p);
2022-06-24 17:53:46 +02:00
2022-07-07 02:13:14 +02:00
if (update && update(c, arg))
2022-06-24 17:53:46 +02:00
return -1;
2022-07-07 02:13:14 +02:00
rect_get_or_ret(r, -1);
rect_init(r);
r->w = screen_w;
r->h = screen_h;
rect_sort(r);
2022-07-07 02:13:14 +02:00
if (render && render(c, arg))
return -1;
2022-06-24 17:53:46 +02:00
2022-07-07 02:13:14 +02:00
switch (c->p.common.type)
2022-06-24 17:53:46 +02:00
{
2022-07-07 02:13:14 +02:00
case PERIPHERAL_TYPE_PAD:
/* Fall through. */
case PERIPHERAL_TYPE_KEYBOARD_MOUSE:
if (cursor_render(&c->cam.cursor))
return -1;
2022-06-24 17:53:46 +02:00
2022-07-07 02:13:14 +02:00
break;
2022-06-24 17:53:46 +02:00
2022-07-07 02:13:14 +02:00
case PERIPHERAL_TYPE_TOUCH:
break;
2022-06-24 17:53:46 +02:00
2022-07-07 02:13:14 +02:00
default:
2022-07-06 23:46:59 +02:00
return -1;
2022-07-07 02:13:14 +02:00
}
2022-07-06 23:46:59 +02:00
2022-07-07 02:13:14 +02:00
if (gfx_draw())
return -1;
2022-07-06 23:46:59 +02:00
2022-07-07 02:13:14 +02:00
return 0;
}
2022-07-06 23:46:59 +02:00
2022-07-07 02:13:14 +02:00
int menu(void)
{
const struct peripheral_cfg cfg =
{
.type = PERIPHERAL_TYPE_KEYBOARD_MOUSE
};
2022-07-06 23:46:59 +02:00
2022-07-07 02:13:14 +02:00
struct menu_common c = {0};
2022-07-06 23:46:59 +02:00
2022-07-07 02:13:14 +02:00
if (game_resinit())
2022-09-20 13:51:08 +02:00
return -1;
2022-06-24 17:53:46 +02:00
2022-07-07 02:13:14 +02:00
cursor_init(&c.cam.cursor);
peripheral_init(&cfg, &c.p);
return menu_main(&c);
2022-06-24 17:53:46 +02:00
}