Textbox example.

This commit is contained in:
2025-11-08 17:26:25 -06:00
parent 0a83175b66
commit db589b7d91
13 changed files with 184 additions and 18 deletions

View File

@@ -10,4 +10,5 @@ target_sources(${DUSK_TARGET_NAME}
uitext.c
uifps.c
uiframe.c
uitextbox.c
)

View File

@@ -11,6 +11,7 @@
#include "util/memory.h"
#include "display/tileset/tileset_minogram.h"
#include "display/screen.h"
#include "ui/uitextbox.h"
ui_t UI;
@@ -31,6 +32,8 @@ void uiUpdate(void) {
UI.camera.orthographic.right = SCREEN.width;
UI.camera.orthographic.top = 0;
UI.camera.orthographic.bottom = SCREEN.height;
uiTextboxUpdate();
}
void uiRender(void) {
@@ -39,6 +42,7 @@ void uiRender(void) {
// Render UI elements here
if(UI.fontTexture.width > 0) {
uiFPSRender(UI.fontTileset, &UI.fontTexture);
uiTextboxRender();
}
cameraPopMatrix();

45
src/ui/uitextbox.c Normal file
View File

@@ -0,0 +1,45 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "uitextbox.h"
#include "ui/ui.h"
#include "ui/uitext.h"
#include "rpg/rpgtextbox.h"
#include "display/screen.h"
#include "display/spritebatch.h"
#include "input/input.h"
void uiTextboxUpdate() {
if(!rpgTextboxIsVisible()) return;
if(inputPressed(INPUT_ACTION_ACCEPT)) {
rpgTextboxHide();
}
}
void uiTextboxRender() {
if(!rpgTextboxIsVisible()) return;
const char_t *text = RPG_TEXTBOX.text;
int32_t textWidth, textHeight;
uiTextMeasure(text, UI.fontTileset, &textWidth, &textHeight);
float_t y = 0;
if(RPG_TEXTBOX.position == RPG_TEXTBOX_POS_BOTTOM) {
y = SCREEN.height - (float_t)textHeight;
}
spriteBatchPush(
NULL,
0.0f, y,
(float_t)SCREEN.width, (float_t)(y + textHeight),
COLOR_BLACK,
0.0f, 0.0f, 1.0f, 1.0f
);
uiTextDraw(0, y, text, COLOR_RED, UI.fontTileset, &UI.fontTexture);
}

19
src/ui/uitextbox.h Normal file
View File

@@ -0,0 +1,19 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
/**
* Updates the RPG textbox state.
*/
void uiTextboxUpdate();
/**
* Draws the RPG textbox if it is visible.
*/
void uiTextboxRender();