Slider widget and some cleanup

This commit is contained in:
2026-07-07 09:58:10 -05:00
parent 3bad03afb3
commit 6dee37d8c1
34 changed files with 1502 additions and 152 deletions
+85
View File
@@ -0,0 +1,85 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "uigamemenu.h"
#include "ui/frame/uiframe.h"
#include "ui/frame/settings/uisettings.h"
#include "util/memory.h"
#include "display/spritebatch/spritebatch.h"
#include "display/screen/screen.h"
#include "assert/assert.h"
#define UI_GAME_MENU_INDEX_CHARACTERS 0
#define UI_GAME_MENU_INDEX_SETTINGS 1
uigamemenu_t UI_GAME_MENU;
void uiGameMenuSelected(
const uimenu_t *menu,
const uint8_t index,
const uimenuitem_t *item
) {
if(index == UI_GAME_MENU_INDEX_SETTINGS) uiSettingsOpen();
}
errorret_t uiGameMenuInit(void) {
memoryZero(&UI_GAME_MENU, sizeof(uigamemenu_t));
uimenu_t *menu = &UI_GAME_MENU.menu;
uiMenuInit(menu, uiGameMenuSelected, NULL, NULL);
menu->items = UI_GAME_MENU.items;
MENU_BEGIN
MENU_BUTTON("Characters");
MENU_BUTTON("Settings");
assertTrue(
menuIndex <= UI_GAME_MENU_ITEM_COUNT,
"Game menu item count mismatch"
);
uiMenuSetItems(menu, UI_GAME_MENU.items, menuIndex, 1);
errorOk();
}
errorret_t uiGameMenuDraw(void) {
if(!uiMenuIsActive(&UI_GAME_MENU.menu)) errorOk();
const float_t width = UI_GAME_MENU_WIDTH;
const float_t height = (float_t)SCREEN.scanHeight;
const float_t x = (float_t)(SCREEN.scanX + SCREEN.scanWidth) - width;
const float_t y = (float_t)SCREEN.scanY;
errorChain(uiFrameDraw(x, y, width, height));
errorChain(uiMenuDraw(
&UI_GAME_MENU.menu,
x + UI_FRAME_START_X,
y + UI_FRAME_START_Y,
width - (UI_FRAME_START_X * 2),
height - (UI_FRAME_START_Y * 2)
));
errorChain(spriteBatchFlush());
errorOk();
}
bool_t uiGameMenuIsOpen(void) {
return uiMenuIsActive(&UI_GAME_MENU.menu);
}
void uiGameMenuOpen() {
uiMenuOpen(&UI_GAME_MENU.menu);
}
void uiGameMenuClose() {
uiMenuClose(&UI_GAME_MENU.menu);
}
errorret_t uiGameMenuDispose(void) {
errorOk();
}