18 if (!font || !videoBuffer)
25 createText(text, font, videoBuffer, startX, startY, color, letterSpacing, lineSpacing, spaceWidth, xBoundary);
27 while (textObj->cursorPos < (
int)textObj->content.size())
35 const std::string& content,
37 uint16_t* videoBuffer,
48 if (!font || !videoBuffer)
54 if (appearingText !=
nullptr)
56 appearingText.reset();
59 content, font, videoBuffer, startX, startY, color, letterSpacing, lineSpacing, spaceWidth, maxX, maxY);
60 appearingText->hyphenate = hyphenate;
65 if (appearingText !=
nullptr)
80 return appearingText !=
nullptr && appearingText->
pageBreak;
103 if (appearingText ==
nullptr)
108 (
int)appearingText->
content.size())
117 uint16_t* videoBuffer,
125 if (!font || !videoBuffer)
131 for (
int y = 0; y < glyph.
height; y++)
133 int distY = italic ? glyph.
height - 1 - y : 0;
136 for (
int x = 0; x < glyph.
width; x++)
138 int bitmapX = glyph.
xPos + x;
139 int bitmapY = glyph.
yPos + y;
140 int bitmapIndex = bitmapY * font->
bitmapWidth + bitmapX;
148 int pixelValue = bold ? font->
bitmapBold[bitmapIndex] : font->
bitmap[bitmapIndex];
151 int screenX = cursorX + x + italicOffset;
152 int screenY = cursorY + glyph.
yOffset + y;
153 if (screenX >= 0 && screenX < 256 && screenY >= 0 && screenY < 192)
155 drawPixel(videoBuffer, screenX, screenY, color);
162 int underlineY = cursorY + font->
lineHeight - 2;
163 for (
int x = 0; x < glyph.
width; x++)
165 int screenX = cursorX + x;
166 if (screenX >= 0 && screenX < 256 && underlineY >= 0 && underlineY < 192)
168 drawPixel(videoBuffer, screenX, underlineY, color);
182 for (
int row = 0; row < height; ++row)
185 int rowEnd = x + width;
186 int pixelY = y + row;
188 if (pixelY < 0 || pixelY >= 192)
193 rowStart = std::max(rowStart, 0);
194 rowEnd = std::min(rowEnd, 256);
195 if (rowStart < rowEnd)
198 if (rowStart % 2 != 0)
209 dmaFillHalfWords(0, videoBuffer + (pixelY * 256 + rowStart) / 2,
static_cast<uint32_t
>(rowEnd - rowStart));
283 const int oldX = text->
cursorX;
284 const int oldY = text->
cursorY;
326 uint16_t* videoBuffer,
336 auto newText = std::make_unique<Text>();
337 newText->cursorX = startX;
338 newText->cursorY = startY;
339 newText->startX = startX;
340 newText->startY = startY;
341 newText->content = text;
342 newText->baseColor = color;
343 newText->activeColor = color;
344 newText->font = font;
345 newText->videoBuffer = videoBuffer;
346 newText->cursorPos = 0;
347 newText->bold =
false;
348 newText->italic =
false;
349 newText->underline =
false;
350 newText->letterSpacing = letterSpacing;
351 newText->lineSpacing = lineSpacing;
352 newText->spaceWidth = spaceWidth;
353 newText->maxX = maxX;
354 newText->maxY = maxY;
355 newText->pageBreak =
false;
370 int wordIndex = (y * 256 + x) / 2;
371 u16 currentWord = videoBuffer[wordIndex];
374 videoBuffer[wordIndex] = (currentWord & 0xFF00) | (paletteValue & 0xFF);
378 videoBuffer[wordIndex] = (currentWord & 0x00FF) | ((paletteValue & 0xFF) << 8);
384 for (
int x = 0; x < width; x++)
386 int screenX = startX + x;
387 if (screenX >= 0 && screenX < 256 && y >= 0 && y < 192)
389 drawPixel(videoBuffer, screenX, y, color);
396 for (
int y = 0; y < 256; y++)
398 for (
int x = 0; x < 256; x++)
401 int pixelValue = font->
bitmap[index];
412 for (
int i = 0; i < 128; i += 2)
414 for (
int y = 0; y < 50; y++)
420 for (
int i = 0; i < 128; i += 2)
422 for (
int y = 0; y < 50; y++)
424 drawPixel(videoBuffer, i, y + 50, i + 128);
425 drawPixel(videoBuffer, i + 1, y + 50, i + 128);
Provides text layout utilities for measuring and positioning text.
Manages rendering text from a bitmap.
constexpr unsigned char TextInstructionMarker
char getNextChar(Text *text)
Get the next character from a given Text object.
bool appearTextDone(Text *appearingText)
Check if the text being rendered with appearText has finished appearing.
void clearArea(uint16_t *videoBuffer, int x, int y, int width, int height)
Clear a rectangular area of the text video buffer.
void underlineGap(int startX, int y, int width, uint16_t *videoBuffer, int color)
Underline a specificed area.
void drawText(const std::string &text, Font *font, uint16_t *videoBuffer, int x, int y, int color, int letterSpacing, int lineSpacing, int spaceWidth, int xBoundary)
Draw text to the screen.
void drawPixel(uint16_t *videoBuffer, int x, int y, int paletteValue)
Draw a single pixel to the video buffer.
void appearTextNextPage(Text *appearingText)
Clear the text area and continue the paused text from the top of it.
void appearText(std::unique_ptr< Text > &appearingText, const std::string &text, Font *font, uint16_t *videoBuffer, int x, int y, int color, int letterSpacing, int lineSpacing, int spaceWidth, int maxX=256, int maxY=0, bool hyphenate=false)
Create a Text object and renders each character with a delay to simulate typing effect.
std::unique_ptr< Text > createText(const std::string &text, Font *font, uint16_t *videoBuffer, int startX, int startY, int color, int letterSpacing, int lineSpacing, int spaceWidth, int maxX=256, int maxY=0)
Create a Text object and initialize its properties.
void testPalette(uint16_t *videoBuffer)
Test function to draw the currently loaded palette to the screen.
void drawGlyph(const Glyph &glyph, Font *font, uint16_t *videoBuffer, int x, int y, int color, bool bold, bool italic, bool underline)
Draw a single glyph to the screen.
void appearTextSkip(Text *appearingText)
If a text is currently being rendered with appearText, this function will immediately render the rest...
void testBitmap(Font *font, uint16_t *videoBuffer)
Test function to draw the font bitmap to the screen.
bool appearTextPaused(Text *appearingText)
Check if the text being rendered with appearText is waiting for the next page.
int SLANT_FACTOR
128 = 1 pixel shift every 2 rows, 64 = 1 pixel shift every 4 rows
void drawNextFromText(Text *text)
Draw the next character from the text struct to the screen.
void logMessage(LogSeverity severity, std::string_view message, std::source_location location)
Logs a diagnostic message and halts only for fatal messages.
Util to handle error logging.
bool pageFull(Text &text)
void applyStyle(Font &font, unsigned char flags, bool &bold, bool &italic, bool &underline)
bool prepareGlyph(Text &text, const Glyph &glyph)
bool shouldWrapWord(const Text &text)
std::uint8_t * bitmapBold
Stores data for a single glyph (character) in a font.
int height
Used to check if the glyph was read in correctly. Setting it to 0 here wipes any old data.
A struct that represents a block of text being rendered on the screen.
int maxY
Bottom edge used for pagination. 0 disables pagination.
bool pageBreak
Set when the next glyph would not fit above maxY. Output pauses until the next page is requested.
int maxX
Right edge (exclusive) used for word wrapping.