From bb168fdab1cb6a8aee1bd7fbd6e2c29ed3f87a1b Mon Sep 17 00:00:00 2001 From: Pk11 Date: Sat, 20 Mar 2021 17:49:32 -0500 Subject: [PATCH] Add separate function to load a system font The other fonts are smaller, so when printing they're multiplied to be about the same as the standard --- gui.cpp | 35 ++++++++++++++++++++++++++++++++++- gui.hpp | 11 +++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/gui.cpp b/gui.cpp index b4c69a9..b99cc69 100644 --- a/gui.cpp +++ b/gui.cpp @@ -42,6 +42,7 @@ bool currentScreen = false; bool fadeout = false, fadein = false, fadeout2 = false, fadein2 = false; int fadealpha = 0; int fadecolor = 0; +CFG_Region loadedSystemFont = (CFG_Region)-1; /* Clear the Text Buffer. @@ -73,6 +74,8 @@ void Gui::DrawSprite(C2D_SpriteSheet sheet, size_t imgindex, int x, int y, float Contains initializing Citro2D, Citro3D and the screen targets. Call this when initing the app. + + fontRegion: The region to use for the system font. */ Result Gui::init(CFG_Region fontRegion) { C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); @@ -86,10 +89,22 @@ Result Gui::init(CFG_Region fontRegion) { /* Load Textbuffer. */ TextBuf = C2D_TextBufNew(4096); - Font = C2D_FontLoadSystem(fontRegion); // Load System font. + loadSystemFont(fontRegion); return 0; } +/* + Load a system font. + + fontRegion: The region to use for the system font. +*/ +void Gui::loadSystemFont(CFG_Region fontRegion) { + if(loadedSystemFont != fontRegion) { + Font = C2D_FontLoadSystem(fontRegion); + loadedSystemFont = fontRegion; + } +} + /* Load a bcfnt font. @@ -151,6 +166,8 @@ void Gui::exit(void) { /* Reinitialize the GUI. + + fontRegion: The region to use for the system font. */ Result Gui::reinit(CFG_Region fontRegion) { C2D_TextBufDelete(TextBuf); @@ -198,6 +215,22 @@ void Gui::DrawString(float x, float y, float size, u32 color, std::string Text, C2D_TextOptimize(&c2d_text); + if(!fnt) { + switch(loadedSystemFont) { + case CFG_REGION_CHN: + size *= 1.13f; + break; + case CFG_REGION_TWN: + size *= 1.5f; + break; + case CFG_REGION_KOR: + size *= 1.1f; + break; + default: + break; + } + } + float heightScale; if (maxHeight == 0) { diff --git a/gui.hpp b/gui.hpp index 6093889..020be54 100644 --- a/gui.hpp +++ b/gui.hpp @@ -53,9 +53,18 @@ namespace Gui { /* Initialize the GUI with Citro2D & Citro3D and initialize the Textbuffer. call this when initializing. + + fontRegion: The region to use for the system font. */ Result init(CFG_Region fontRegion = CFG_REGION_USA); + /* + Load a system font. + + fontRegion: The region to use for the system font. + */ + void loadSystemFont(CFG_Region fontRegion = CFG_REGION_USA); + /* Load a Font. (BCFNT) @@ -95,6 +104,8 @@ namespace Gui { /* Reinit the GUI. + + fontRegion: The region to use for the system font. */ Result reinit(CFG_Region fontRegion = CFG_REGION_USA);