aboutsummaryrefslogtreecommitdiff
path: root/src/gui/inc/gui.h
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/gui/inc/gui.h
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/gui/inc/gui.h')
-rw-r--r--src/gui/inc/gui.h31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/gui/inc/gui.h b/src/gui/inc/gui.h
index 254fd47..ec87f45 100644
--- a/src/gui/inc/gui.h
+++ b/src/gui/inc/gui.h
@@ -1,33 +1,30 @@
#ifndef GUI_H
#define GUI_H
+#include <camera.h>
#include <gfx.h>
-#include <human_player.h>
+#include <peripheral.h>
#ifdef __cplusplus
extern "C"
{
#endif
-enum
+struct gui_common
{
- GUI_BAR_LEFT,
- GUI_BAR_MID,
- GUI_BAR_RIGHT,
- GUI_SELECTION_UP_LEFT,
- GUI_SELECTION_UP_RIGHT,
- GUI_SELECTION_MID_VERT,
- GUI_SELECTION_DOWN_LEFT,
- GUI_SELECTION_DOWN_RIGHT,
- GUI_SELECTION_MID,
-
- MAX_GUI_SPRITES
+ int (*update)(struct gui_common *, const union peripheral *,
+ const struct camera *);
+ int (*render)(const struct gui_common *);
+ short x, y;
+ bool centered;
+ struct gui_common *parent, *child, *sibling;
};
-void gui_update(struct human_player *h);
-int gui_render(const struct human_player *h);
-
-extern struct sprite gui_sprites[MAX_GUI_SPRITES];
+void gui_add_child(struct gui_common *parent, struct gui_common *child);
+void gui_add_sibling(struct gui_common *g, struct gui_common *sibling);
+int gui_update(struct gui_common *g, const union peripheral *p,
+ const struct camera *c);
+int gui_render(const struct gui_common *g);
#ifdef __cplusplus
}