From 7c75118429596dcfd86dbefb32e9ae79585c4da0 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Fri, 24 Jun 2022 16:55:18 +0200 Subject: Revamp gui component `gui` was tighly coupled to game logic, and could not be extended for other purposes. Therefore, a generic GUI implementation, loosely inspired by well-known GUI frameworks such as GTK, is now provided, with the following properties: - Does not depend on dynamic or static memory allocation, only automatic (i.e., stack) memory allocation required. - Portable among existing implementations. - Simple to extend. - Tiny memory footprint. `gui` is now composed by GUI elements that can be chained to form a tree structure. This is useful e.g.: to calculate X/Y coordinates for a given GUI element given its parent(s). This commit also refactors the older implementation, moving game-specific logic into `player` and making use of the new component. --- src/game/CMakeLists.txt | 1 - src/game/src/res.c | 29 +++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/game') diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt index 3eeef87..0c21b0c 100644 --- a/src/game/CMakeLists.txt +++ b/src/game/CMakeLists.txt @@ -2,7 +2,6 @@ add_library(game "src/game.c" "src/res.c") target_include_directories(game PUBLIC "inc" PRIVATE "privinc") target_link_libraries(game PRIVATE building - button container font gfx diff --git a/src/game/src/res.c b/src/game/src/res.c index 093fc45..c41af47 100644 --- a/src/game/src/res.c +++ b/src/game/src/res.c @@ -1,10 +1,11 @@ #include #include -#include #include #include #include -#include +#include +#include +#include #include #include #include @@ -89,7 +90,7 @@ static const struct container c[] = .type = CONTAINER_TYPE_SPRITE, .data = { - .sprite = &gui_sprites[GUI_BAR_LEFT] + .sprite = &gui_bar_sprites[GUI_BAR_LEFT] } }, @@ -98,7 +99,7 @@ static const struct container c[] = .type = CONTAINER_TYPE_SPRITE, .data = { - .sprite = &gui_sprites[GUI_BAR_MID] + .sprite = &gui_bar_sprites[GUI_BAR_MID] } }, @@ -107,7 +108,7 @@ static const struct container c[] = .type = CONTAINER_TYPE_SPRITE, .data = { - .sprite = &gui_sprites[GUI_BAR_RIGHT] + .sprite = &gui_bar_sprites[GUI_BAR_RIGHT] } }, @@ -116,7 +117,7 @@ static const struct container c[] = .type = CONTAINER_TYPE_SPRITE, .data = { - .sprite = &gui_sprites[GUI_SELECTION_UP_LEFT] + .sprite = &gui_rounded_rect_sprites[GUI_ROUNDED_RECT_UP_LEFT] } }, @@ -125,7 +126,7 @@ static const struct container c[] = .type = CONTAINER_TYPE_SPRITE, .data = { - .sprite = &gui_sprites[GUI_SELECTION_UP_RIGHT] + .sprite = &gui_rounded_rect_sprites[GUI_ROUNDED_RECT_UP_RIGHT] } }, @@ -134,7 +135,7 @@ static const struct container c[] = .type = CONTAINER_TYPE_SPRITE, .data = { - .sprite = &gui_sprites[GUI_SELECTION_DOWN_LEFT] + .sprite = &gui_rounded_rect_sprites[GUI_ROUNDED_RECT_DOWN_LEFT] } }, @@ -143,7 +144,7 @@ static const struct container c[] = .type = CONTAINER_TYPE_SPRITE, .data = { - .sprite = &gui_sprites[GUI_SELECTION_DOWN_RIGHT] + .sprite = &gui_rounded_rect_sprites[GUI_ROUNDED_RECT_DOWN_RIGHT] } }, @@ -152,7 +153,7 @@ static const struct container c[] = .type = CONTAINER_TYPE_SPRITE, .data = { - .sprite = &gui_sprites[GUI_SELECTION_MID] + .sprite = &gui_rounded_rect_sprites[GUI_ROUNDED_RECT_MID] } }, @@ -161,7 +162,7 @@ static const struct container c[] = .type = CONTAINER_TYPE_SPRITE, .data = { - .sprite = &gui_sprites[GUI_SELECTION_MID_VERT] + .sprite = &gui_rounded_rect_sprites[GUI_ROUNDED_RECT_MID_VERT] } }, @@ -224,7 +225,7 @@ static const struct container c[] = .type = CONTAINER_TYPE_SPRITE, .data = { - .sprite = &button_sprites[BUTTON_LEFT] + .sprite = &gui_button_sprites[GUI_BUTTON_LEFT] } }, @@ -233,7 +234,7 @@ static const struct container c[] = .type = CONTAINER_TYPE_SPRITE, .data = { - .sprite = &button_sprites[BUTTON_MID] + .sprite = &gui_button_sprites[GUI_BUTTON_MID] } }, @@ -242,7 +243,7 @@ static const struct container c[] = .type = CONTAINER_TYPE_SPRITE, .data = { - .sprite = &button_sprites[BUTTON_RIGHT] + .sprite = &gui_button_sprites[GUI_BUTTON_RIGHT] } }, }; -- cgit v1.2.3