aboutsummaryrefslogtreecommitdiff
path: root/src/menu
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-24 17:53:46 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-26 21:51:47 +0200
commit19d9a571afbce0e4d6db3234aeb4ccd221076997 (patch)
tree0d44937ecb8350f3ac9e1567d1cdb59f62a9d649 /src/menu
parentc0887a44fb3c716194ef8eacd27a9556fdfdfc00 (diff)
downloadjancity-19d9a571afbce0e4d6db3234aeb4ccd221076997.tar.gz
Implement main menu
Diffstat (limited to 'src/menu')
-rw-r--r--src/menu/CMakeLists.txt5
-rw-r--r--src/menu/inc/menu.h15
-rw-r--r--src/menu/src/menu.c71
3 files changed, 91 insertions, 0 deletions
diff --git a/src/menu/CMakeLists.txt b/src/menu/CMakeLists.txt
new file mode 100644
index 0000000..c4adb09
--- /dev/null
+++ b/src/menu/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_library(menu
+ "src/menu.c"
+)
+target_include_directories(menu PUBLIC "inc")
+target_link_libraries(menu PRIVATE camera game gfx gui system)
diff --git a/src/menu/inc/menu.h b/src/menu/inc/menu.h
new file mode 100644
index 0000000..4e92a3f
--- /dev/null
+++ b/src/menu/inc/menu.h
@@ -0,0 +1,15 @@
+#ifndef MENU_H
+#define MENU_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+int menu(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MENU_H */
diff --git a/src/menu/src/menu.c b/src/menu/src/menu.c
new file mode 100644
index 0000000..12da1a8
--- /dev/null
+++ b/src/menu/src/menu.c
@@ -0,0 +1,71 @@
+#include <menu.h>
+#include <camera.h>
+#include <game.h>
+#include <gfx.h>
+#include <gui.h>
+#include <gui/button.h>
+#include <system.h>
+#include <stdbool.h>
+
+static void on_pressed(void *const arg)
+{
+ *(bool *)arg = true;
+}
+
+int menu(void)
+{
+ struct camera cam = {0};
+ struct gui_button play;
+ union peripheral p;
+ bool start = false;
+
+ if (game_resinit())
+ return -1;
+
+ cursor_init(&cam.cursor);
+ gui_button_init(&play);
+ play.on_pressed = on_pressed;
+ play.arg = &start;
+ play.w = 140;
+ play.label.text = "Play";
+
+ {
+ const struct peripheral_cfg cfg =
+ {
+ .type = PERIPHERAL_TYPE_KEYBOARD_MOUSE
+ };
+
+ peripheral_init(&cfg, &p);
+ }
+
+ while (!start)
+ {
+ system_loop();
+ peripheral_update(&p);
+ camera_update(&cam, &p);
+
+ play.common.x = screen_w / 2 - play.w / 2;
+ play.common.y = screen_h / 2 - 20;
+ play.label.common.x = play.w / 2 - 20;
+ play.label.common.y = 4;
+
+ if (gui_update(&play.common, &p, &cam))
+ return -1;
+
+ rect_get_or_ret(r, -1);
+ rect_init(r);
+ r->w = screen_w;
+ r->h = screen_h;
+ rect_sort(r);
+
+ if (p.common.exit)
+ return 0;
+
+ if (gui_render(&play.common)
+ || cursor_render(&cam.cursor)
+ || gfx_draw())
+ return -1;
+ }
+
+ return game(NULL);
+}