diff --git a/engine/menu_impl.c b/engine/menu_impl.c index 629850e..3680676 100644 --- a/engine/menu_impl.c +++ b/engine/menu_impl.c @@ -1,25 +1,12 @@ #include "menu_impl.h" -#include "gui.h" -static UIComp_t buttons[2] = -{ - { - .bbox = {25,255,125,30}, - .state = STATE_NORMAL, - .alpha = 1.0 - }, - { - .bbox = {25,300,125,30}, - .state = STATE_NORMAL, - .alpha = 1.0 - } -}; static void menu_scene_render_func(Scene_t *scene) { + MenuSceneData_t *data = (MenuSceneData_t *)scene->scene_data; DrawText("This is a game", 25, 220, 12, BLACK); - UI_button(buttons, "Start"); - UI_button(buttons + 1, "Exit"); + UI_button(data->buttons, "Start"); + UI_button(data->buttons + 1, "Exit"); } static void menu_do_action(Scene_t *scene, ActionType_t action, bool pressed) @@ -28,23 +15,24 @@ static void menu_do_action(Scene_t *scene, ActionType_t action, bool pressed) static void gui_loop(Scene_t* scene) { + MenuSceneData_t *data = (MenuSceneData_t *)scene->scene_data; for (size_t i=0;i<2;i++) { - if ((buttons[i].state != STATE_DISABLED)) + if ((data->buttons[i].state != STATE_DISABLED)) { Vector2 mousePoint = GetMousePosition(); // Check button state - if (CheckCollisionPointRec(mousePoint, buttons[i].bbox)) + if (CheckCollisionPointRec(mousePoint, data->buttons[i].bbox)) { - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) buttons[i].state = STATE_PRESSED; - else buttons[i].state = STATE_FOCUSED; + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) data->buttons[i].state = STATE_PRESSED; + else data->buttons[i].state = STATE_FOCUSED; - if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) buttons[i].pressed = true; + if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) data->buttons[i].pressed = true; } else { - buttons[i].state = STATE_NORMAL; + data->buttons[i].state = STATE_NORMAL; } } } @@ -57,6 +45,19 @@ void init_menu_scene(MenuScene_t *scene) sc_array_add(&scene->scene.systems, &gui_loop); + scene->data.buttons[0] = (UIComp_t) + { + .bbox = {25,255,125,30}, + .state = STATE_NORMAL, + .alpha = 1.0 + }; + + scene->data.buttons[1] = (UIComp_t) + { + .bbox = {25,300,125,30}, + .state = STATE_NORMAL, + .alpha = 1.0 + }; } void free_menu_scene(MenuScene_t *scene) diff --git a/engine/menu_impl.h b/engine/menu_impl.h index 7fcac89..d327363 100644 --- a/engine/menu_impl.h +++ b/engine/menu_impl.h @@ -1,11 +1,11 @@ #ifndef __MENU_IMPL_H #define __MENU_IMPL_H #include "scene.h" +#include "gui.h" typedef struct MenuSceneData { - Entity_t *menus[8]; - Entity_t *menu_opts[32]; + UIComp_t buttons[2]; }MenuSceneData_t; typedef struct MenuScene