aboutsummaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-24 16:55:18 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-06-26 20:00:27 +0200
commit7c75118429596dcfd86dbefb32e9ae79585c4da0 (patch)
treed06478b8e303d0e2729c57b079f481fbcf5b9adf /src/game
parentf17c76c4007563389188c147d4e1c766039fb686 (diff)
downloadrts-7c75118429596dcfd86dbefb32e9ae79585c4da0.tar.gz
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.
Diffstat (limited to 'src/game')
-rw-r--r--src/game/CMakeLists.txt1
-rw-r--r--src/game/src/res.c29
2 files changed, 15 insertions, 15 deletions
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 <game_private.h>
#include <building.h>
-#include <button.h>
#include <container.h>
#include <font.h>
#include <gfx.h>
-#include <gui.h>
+#include <gui/bar.h>
+#include <gui/button.h>
+#include <gui/rounded_rect.h>
#include <resource.h>
#include <terrain.h>
#include <unit.h>
@@ -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]
}
},
};