/** * Copyright (c) 2025 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #include "ui.h" #include "assert/assert.h" #include "ui/uifps.h" #include "util/memory.h" #include "display/tileset/tileset_minogram.h" #include "display/screen.h" #include "ui/uitextbox.h" ui_t UI; 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; uiTextboxUpdate(); } void uiRender(void) { cameraPushMatrix(&UI.camera); // Render UI elements here if(UI.fontTexture.width > 0) { uiFPSRender(UI.fontTileset, &UI.fontTexture); uiTextboxRender(); } cameraPopMatrix(); } errorret_t uiSetFont(const tileset_t *fontTileset) { if(UI.fontTexture.width > 0) { textureDispose(&UI.fontTexture); UI.fontTexture.width = -1; } assertNotNull(fontTileset, "Font tileset cannot be NULL."); UI.fontTileset = fontTileset; errorChain(assetLoad(UI.fontTileset->image, &UI.fontTexture)); errorOk(); } void uiDispose(void) { if(UI.fontTexture.width > 0) { textureDispose(&UI.fontTexture); UI.fontTexture.width = -1; } }