6constexpr uint16_t
nds_rgb(uint8_t r, uint8_t g, uint8_t b)
8 return static_cast<uint16_t
>((r >> 3) | (((g) >> 3) << 5) | (((b) >> 3) << 10) | BIT(15));
13 ARGB16(1, 31, 31, 31),
33 ARGB16(1, 15, 15, 15),
43 auto font = std::make_unique<Font>();
44 std::string fullPath =
"fonts/" + *name +
"/size-" + std::to_string(size);
46 std::string fontBitmapPath = fullPath +
".img.bin";
53 std::string fontMetadataPath = fullPath +
".fnt";
59 std::string fontBitmapBoldPath = fullPath +
"-bold.img.bin";
60 std::string fontMetadataBoldPath = fullPath +
"-bold.fnt";
62 if (!font->bitmapBold || !
loadFontMetadata(&fontMetadataBoldPath, font.get(),
true))
64 font->boldLoaded =
false;
65 free(font->bitmapBold);
66 font->bitmapBold =
nullptr;
70 font->boldLoaded =
true;
78 dmaCopy(
customPalette, BG_PALETTE + 235, 21 *
sizeof(uint16_t));
79 dmaCopy(
customPalette, BG_PALETTE_SUB + 235, 21 *
sizeof(uint16_t));
90 if (buffer.
get() ==
nullptr)
96 std::uint16_t* fontPalette =
reinterpret_cast<std::uint16_t*
>(buffer.
get());
99 dmaCopy(fontPalette, BG_PALETTE_SUB, 256 *
sizeof(uint16_t));
103 dmaCopy(fontPalette, BG_PALETTE, 256 *
sizeof(uint16_t));
111 dmaFillHalfWords(0, BG_PALETTE, 256 *
sizeof(uint16_t));
112 dmaFillHalfWords(0, BG_PALETTE_SUB, 256 *
sizeof(uint16_t));
123 if (buffer.
get() ==
nullptr)
129 return reinterpret_cast<std::uint8_t*
>(buffer.
release());
146 if (buffer.
get() ==
nullptr)
152 std::string content(
reinterpret_cast<char*
>(buffer.
get()), buffer.
length());
154 std::istringstream iss(content);
156 while (std::getline(iss, line))
158 if (line.starts_with(
"common ") && !forBoldBitmap)
167 if (!line.starts_with(
"char "))
173 if (charID < 0 || charID >= 256)
191 font->
glyphs[charID] = glyph;
200 if (videoBuffer ==
nullptr)
205 dmaFillHalfWords(0, videoBuffer, 256 * 256 *
sizeof(uint8_t));
210 std::size_t keyPos = line.find(key);
211 if (keyPos == std::string::npos)
216 const std::size_t dataStart = keyPos + key.size();
217 if (dataStart >= line.size())
222 char* endPtr =
nullptr;
223 long val = std::strtol(line.c_str() + dataStart, &endPtr, 10);
224 if (endPtr == line.c_str() + dataStart)
230 return static_cast<int>(val);
static const uint16_t customPalette[21]
constexpr uint16_t nds_rgb(uint8_t r, uint8_t g, uint8_t b)
Manager for text loading.
Owns a heap-allocated file buffer and its length.
void * release()
Releases the file data to the caller.
void * get() const
Gets the owned file data without transferring ownership.
u32 length() const
Gets the file data length.
void unloadPalette()
Unload the current palettes.
int extractIntValue(const std::string &line, const std::string &key)
Extract an integer value from a line of text based on a specified key.
void loadDefaultPalette()
Loads the predefined default palette.
bool loadPalette(std::string *paletteFilePath, bool sub=false)
Load a palette from a file.
std::unique_ptr< Font > loadFont(std::string *name, int size)
Load a font from a file.
void clearScreen(uint16_t *videoBuffer)
Clear the text layer by filling the video buffer with black.
bool loadFontMetadata(std::string *path, Font *font, bool forBoldBitmap=false)
Load the font metadata from a file.
std::uint8_t * loadFontBitmap(std::string *path)
Load the font bitmap from a file.
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.
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.