70 lines
1.9 KiB
C
70 lines
1.9 KiB
C
/**
|
|
* 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;
|
|
}
|
|
}
|
|
} |