This commit is contained in:
2025-10-08 14:17:58 -05:00
parent 46f820690d
commit 67604eca8d
17 changed files with 230 additions and 165 deletions

View File

@@ -6,21 +6,59 @@
*/
#include "ui.h"
#include "ui/uiconsole.h"
#include "ui/uifps.h"
#include "util/memory.h"
#include "display/tileset/tileset_minogram.h"
#include "display/screen.h"
ui_t UI;
void uiInit(void) {
errorret_t uiInit(void) {
memoryZero(&UI, sizeof(ui_t));
cameraInitOrthographic(&UI.camera);
// Initialize UI components here
uiSetFont(&TILESET_MINOGRAM);
errorOk();
}
void uiUpdate(void) {
// Update UI state here
UI.camera.orthographic.left = 0;
UI.camera.orthographic.right = SCREEN.width;
UI.camera.orthographic.top = 0;
UI.camera.orthographic.bottom = SCREEN.height;
}
void uiRender(void) {
cameraPushMatrix(&UI.camera);
// Render UI elements here
if(UI.font) {
uiConsoleRender(0, 0, UI.fontTileset, &UI.font->alphaImage.texture);
uiFPSRender(UI.fontTileset, &UI.font->alphaImage.texture);
}
cameraPopMatrix();
}
errorret_t uiSetFont(const tileset_t *fontTileset) {
if(UI.font) {
assetUnlock(UI.font, UI.fontRef);
UI.font = NULL;
}
UI.fontTileset = fontTileset;
assetManagerLoadAsset(fontTileset->image, &UI.font, &UI.fontRef);
}
void uiDispose(void) {
// Clean up UI resources here
if(UI.font) {
assetUnlock(UI.font, UI.fontRef);
UI.font = NULL;
}
}

View File

@@ -7,17 +7,26 @@
#pragma once
#include "dusk.h"
#include "asset/assetmanager.h"
#include "display/tileset/tileset.h"
#include "display/camera.h"
typedef struct {
int32_t nothing;
camera_t camera;
ref_t fontRef;
asset_t *font;
const tileset_t *fontTileset;
} ui_t;
extern ui_t UI;
/**
* Initializes the UI system, loading necessary resources.
*
* @return An errorret_t indicating success or failure.
*/
void uiInit(void);
errorret_t uiInit(void);
/**
* Updates the UI state, handling user interactions and animations.
@@ -29,6 +38,15 @@ void uiUpdate(void);
*/
void uiRender(void);
/**
* Sets the font tileset for UI text rendering.
*
* @param fontTileset Pointer to the tileset to use for UI fonts.
*
* @return An errorret_t indicating success or failure.
*/
errorret_t uiSetFont(const tileset_t *fontTileset);
/**
* Cleans up and frees all UI resources.
*/

View File

@@ -26,7 +26,7 @@ void uiConsoleRender(
continue;
}
uiTextDraw(
x, y + (i * TILESET_MINOGRAM.tileHeight),
x, y + (i * tileset->tileHeight),
line, COLOR_WHITE,
tileset, texture
);

View File

@@ -10,7 +10,8 @@
#include "console/console.h"
#include "util/string.h"
#include "ui/uitext.h"
#include "display/framebuffer.h"
#include "display/screen.h"
#include "display/spritebatch.h"
void uiFPSRender(const tileset_t *tileset, texture_t *texture) {
if(stringCompare(consoleVarGet("fps")->value, "0") == 0) {
@@ -36,7 +37,8 @@ void uiFPSRender(const tileset_t *tileset, texture_t *texture) {
int32_t w, h;
uiTextMeasure(buffer, tileset, &w, &h);
uiTextDraw(
frameBufferGetWidth(FRAMEBUFFER_BOUND) - w, 0,
SCREEN.width - w, 0,
buffer, color, tileset, texture
);
spriteBatchFlush();
}