Improve text rendering API, add ams version.

This commit is contained in:
Michael Scire 2018-11-13 13:11:41 -08:00
parent 2838e41819
commit 560d899a9b
4 changed files with 28 additions and 9 deletions

View file

@ -31,6 +31,7 @@
static u16 *g_fb = nullptr; static u16 *g_fb = nullptr;
static u32 (*g_unswizzle_func)(u32, u32) = nullptr; static u32 (*g_unswizzle_func)(u32, u32) = nullptr;
static u16 g_font_color = 0xFFFF; static u16 g_font_color = 0xFFFF;
static u32 g_cur_x = 0, g_cur_y = 0;
static PlFontData g_font; static PlFontData g_font;
static PlFontData g_fonts[PlSharedFontType_Total]; static PlFontData g_fonts[PlSharedFontType_Total];
@ -68,13 +69,18 @@ static void DrawGlyph(FT_Bitmap *bitmap, u32 x, u32 y) {
} }
} }
void FontManager::DrawString(u32 x, u32 y, const char *str) { void FontManager::PrintLine(const char *str) {
FT_UInt glyph_index; FT_UInt glyph_index;
FT_GlyphSlot slot = g_face->glyph; FT_GlyphSlot slot = g_face->glyph;
const size_t len = strlen(str); const size_t len = strlen(str);
u32 cur_x = x, cur_y = y; u32 cur_x = g_cur_x, cur_y = g_cur_y;
ON_SCOPE_EXIT {
/* Advance to next line. */
/* g_cur_x = g_cur_x; */
g_cur_y = cur_y + (g_face->size->metrics.height >> 6);
};
for (u32 i = 0; i < len; ) { for (u32 i = 0; i < len; ) {
u32 cur_char; u32 cur_char;
@ -83,7 +89,7 @@ void FontManager::DrawString(u32 x, u32 y, const char *str) {
i += unit_count; i += unit_count;
if (cur_char == '\n') { if (cur_char == '\n') {
cur_x = x; cur_x = g_cur_x;
cur_y += g_face->size->metrics.height >> 6; cur_y += g_face->size->metrics.height >> 6;
continue; continue;
} }
@ -107,20 +113,25 @@ void FontManager::DrawString(u32 x, u32 y, const char *str) {
} }
} }
void FontManager::DrawFormat(u32 x, u32 y, const char *format, ...) { void FontManager::PrintFormatLine(const char *format, ...) {
va_list va_arg; va_list va_arg;
va_start(va_arg, format); va_start(va_arg, format);
char char_buf[0x400]; char char_buf[0x400];
vsnprintf(char_buf, sizeof(char_buf), format, va_arg); vsnprintf(char_buf, sizeof(char_buf), format, va_arg);
DrawString(x, y, char_buf); PrintLine(char_buf);
} }
void FontManager::SetFontColor(u16 color) { void FontManager::SetFontColor(u16 color) {
g_font_color = color; g_font_color = color;
} }
void FontManager::SetPosition(u32 x, u32 y) {
g_cur_x = x;
g_cur_y = y;
}
void FontManager::ConfigureFontFramebuffer(u16 *fb, u32 (*unswizzle_func)(u32, u32)) { void FontManager::ConfigureFontFramebuffer(u16 *fb, u32 (*unswizzle_func)(u32, u32)) {
g_fb = fb; g_fb = fb;
g_unswizzle_func = unswizzle_func; g_unswizzle_func = unswizzle_func;

View file

@ -30,6 +30,7 @@ class FontManager {
static void ConfigureFontFramebuffer(u16 *fb, u32 (*unswizzle_func)(u32, u32)); static void ConfigureFontFramebuffer(u16 *fb, u32 (*unswizzle_func)(u32, u32));
static void SetFontColor(u16 color); static void SetFontColor(u16 color);
static void DrawString(u32 x, u32 y, const char *str); static void SetPosition(u32 x, u32 y);
static void DrawFormat(u32 x, u32 y, const char *format, ...); static void PrintLine(const char *str);
static void PrintFormatLine(const char *format, ...);
}; };

View file

@ -15,6 +15,9 @@
*/ */
#include <switch.h> #include <switch.h>
#include <atmosphere/version.h>
#include "fatal_task_screen.hpp" #include "fatal_task_screen.hpp"
#include "fatal_config.hpp" #include "fatal_config.hpp"
#include "fatal_font.hpp" #include "fatal_font.hpp"
@ -198,7 +201,11 @@ Result ShowFatalTask::ShowFatal() {
} }
/* TODO: Actually draw meaningful shit here. */ /* TODO: Actually draw meaningful shit here. */
FontManager::DrawFormat(32, 64, u8"A fatal error occurred: 2%03d-%04d\n", R_MODULE(this->ctx->error_code), R_DESCRIPTION(this->ctx->error_code)); FontManager::SetPosition(32, 64);
FontManager::PrintFormatLine(u8"A fatal error occurred: 2%03d-%04d", R_MODULE(this->ctx->error_code), R_DESCRIPTION(this->ctx->error_code));
FontManager::PrintFormatLine(u8"Firmware: %s (AMS %u.%u.%u-%s)", GetFatalConfig()->firmware_version.display_version,
CURRENT_ATMOSPHERE_VERSION, GetAtmosphereGitRevision());
/* Enqueue the buffer. */ /* Enqueue the buffer. */
framebufferEnd(&fb); framebufferEnd(&fb);

@ -1 +1 @@
Subproject commit 6a6eedeacd69a4bddb1e43e31a642a1249a8eb88 Subproject commit 0fb33e9c094bffde737c7a73cd5ccce4d7cbae33