textbox renders.
This commit is contained in:
@@ -19,7 +19,6 @@ void npcLoad(entity_t *entity, const entity_t *source) {
|
||||
}
|
||||
|
||||
void npcUpdate(entity_t *entity) {
|
||||
|
||||
}
|
||||
|
||||
void npcInteract(entity_t *player, entity_t *self) {
|
||||
|
@@ -10,4 +10,5 @@ target_sources(${DUSK_TARGET_NAME}
|
||||
renderfps.c
|
||||
rendertext.c
|
||||
renderui.c
|
||||
rendertextbox.c
|
||||
)
|
70
src/dusksdl2/display/ui/rendertextbox.c
Normal file
70
src/dusksdl2/display/ui/rendertextbox.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "rendertextbox.h"
|
||||
#include "ui/uitextbox.h"
|
||||
#include "display/ui/rendertext.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
void renderTextboxDraw(void) {
|
||||
if(!UI_TEXTBOX.visible) return;
|
||||
|
||||
// Background
|
||||
spriteBatchPush(
|
||||
NULL,
|
||||
0, RENDER_HEIGHT - UI_TEXTBOX_HEIGHT,
|
||||
RENDER_WIDTH, RENDER_HEIGHT,
|
||||
0x00, 0x00, 0x00, 0xFF,
|
||||
0.0f, 0.0f, 1.0f, 1.0f
|
||||
);
|
||||
|
||||
uint32_t x = 0;
|
||||
uint32_t y = RENDER_HEIGHT - UI_TEXTBOX_HEIGHT;
|
||||
|
||||
if(UI_TEXTBOX.charsRevealed > 0) {
|
||||
uint8_t charsRendered = 0;
|
||||
|
||||
// For each line
|
||||
for(uint8_t i = 0; i < UI_TEXTBOX_LINES_PER_PAGE; i++) {
|
||||
// Get count of chars in the line
|
||||
uint8_t lineLength = UI_TEXTBOX.lineLengths[
|
||||
i + (UI_TEXTBOX.page * UI_TEXTBOX_LINES_PER_PAGE)
|
||||
];
|
||||
if(lineLength == 0) continue;
|
||||
|
||||
// Determine how many chars left to render
|
||||
uint8_t lineChars = UI_TEXTBOX.charsRevealed - charsRendered;
|
||||
|
||||
// Don't render more than in line
|
||||
if(lineChars > lineLength) lineChars = lineLength;
|
||||
assertTrue(lineChars > 0, "Line chars must be greater than 0");
|
||||
|
||||
// Update how many rendered
|
||||
charsRendered += lineChars;
|
||||
|
||||
for(uint8_t j = 0; j < lineChars; j++) {
|
||||
renderTextDrawChar(
|
||||
x + UI_TEXTBOX_PADDING_X + UI_TEXTBOX_BORDER_WIDTH + (
|
||||
j * FONT_TILE_WIDTH
|
||||
),
|
||||
y + UI_TEXTBOX_PADDING_Y + UI_TEXTBOX_BORDER_HEIGHT + (
|
||||
i * FONT_TILE_HEIGHT
|
||||
),
|
||||
UI_TEXTBOX.text[
|
||||
(i * UI_TEXTBOX_CHARS_PER_LINE) + j +
|
||||
(UI_TEXTBOX.page * UI_TEXTBOX_CHARS_PER_PAGE)
|
||||
],
|
||||
0xFF, 0xFF, 0xFF
|
||||
);
|
||||
}
|
||||
|
||||
// Check if we're done rendering text
|
||||
if(UI_TEXTBOX.charsRevealed - charsRendered == 0) break;
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,4 +5,6 @@
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
void renderTextboxDraw(void);
|
@@ -9,6 +9,7 @@
|
||||
#include "display/ui/rendertext.h"
|
||||
#include "display/ui/renderconsole.h"
|
||||
#include "display/ui/renderfps.h"
|
||||
#include "display/ui/rendertextbox.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "display/camera/camera.h"
|
||||
|
||||
@@ -18,6 +19,10 @@ renderuicallback_t RENDER_UI_CALLBACKS[] = {
|
||||
.dispose = renderTextDispose
|
||||
},
|
||||
|
||||
{
|
||||
.draw = renderTextboxDraw,
|
||||
},
|
||||
|
||||
{
|
||||
.draw = renderConsoleDraw,
|
||||
},
|
||||
@@ -46,6 +51,7 @@ void renderUIDraw(void) {
|
||||
RENDER_UI_CALLBACKS[i].draw();
|
||||
}
|
||||
|
||||
spriteBatchFlush();
|
||||
cameraUIPop();
|
||||
}
|
||||
|
||||
|
@@ -52,6 +52,7 @@
|
||||
{ SDL_SCANCODE_DOWN, INPUT_BIND_DOWN },
|
||||
{ SDL_SCANCODE_RETURN, INPUT_BIND_ACTION },
|
||||
{ SDL_SCANCODE_SPACE, INPUT_BIND_ACTION },
|
||||
{ SDL_SCANCODE_E, INPUT_BIND_ACTION },
|
||||
{ SDL_SCANCODE_ESCAPE, INPUT_BIND_CANCEL },
|
||||
{ SDL_SCANCODE_BACKSPACE, INPUT_BIND_CANCEL },
|
||||
{ SDL_SCANCODE_TAB, INPUT_BIND_CONSOLE },
|
||||
|
Reference in New Issue
Block a user