From bc06a3fee84b676bb2b46ddca34c4732764283d2 Mon Sep 17 00:00:00 2001 From: TobiD7 Date: Thu, 26 Mar 2026 21:01:43 +0100 Subject: [PATCH] implement font deletion --- include/pd/lithium/drawlist.hpp | 1 + include/pd/lithium/font.hpp | 7 ++++++- source/common.cpp | 4 +--- source/lithium/font.cpp | 10 ++++++++++ tests/gfx/include/os-ctx.hpp | 2 ++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/pd/lithium/drawlist.hpp b/include/pd/lithium/drawlist.hpp index d9bc470..d7444fa 100644 --- a/include/pd/lithium/drawlist.hpp +++ b/include/pd/lithium/drawlist.hpp @@ -70,6 +70,7 @@ class PD_API Drawlist { /** Font Handling */ void SetFont(Font* font) { pFont = font; } void SetFontscale(float fontscale = 1.f) { pFontScale = fontscale; } + const float& GetFontScale() const { return pFontScale; } /** Data geters */ const Pool& Data() const { return pCommands; } diff --git a/include/pd/lithium/font.hpp b/include/pd/lithium/font.hpp index 2b31052..6a1284f 100644 --- a/include/pd/lithium/font.hpp +++ b/include/pd/lithium/font.hpp @@ -64,6 +64,11 @@ class PD_API Font { void CmdTextEx(Drawlist& dl, const fvec2& pos, u32 color, float scale, const char* text, LiTextFlags flags = 0, const fvec2& box = 0); + /** + * Cleanup Font and unload Textures + */ + void Delete(); + /** * Garbage collection for TextMapSystem */ @@ -80,7 +85,7 @@ class PD_API Font { /** Data Section */ int PixelHeight = 0; - int DefaultPixelHeight = 24; + int DefaultPixelHeight = 32; std::vector Textures; /** * 32Bit Codepoint Dataholder reference map diff --git a/source/common.cpp b/source/common.cpp index eec128d..74f4d27 100644 --- a/source/common.cpp +++ b/source/common.cpp @@ -7,9 +7,7 @@ constexpr const char* pColorYellow = "\033[33m"; constexpr const char* pColorRed = "\033[31m"; static LogLevel pFilter = LogLevel::Info; -PD_API void LogFilter(LogLevel lvl) { - pFilter = lvl; -} +PD_API void LogFilter(LogLevel lvl) { pFilter = lvl; } PD_API void Log(const std::string& txt, LogLevel lvl) { if ((int)lvl < (int)pFilter) return; diff --git a/source/lithium/font.cpp b/source/lithium/font.cpp index ab66ae6..5727937 100644 --- a/source/lithium/font.cpp +++ b/source/lithium/font.cpp @@ -271,5 +271,15 @@ PD_API std::string Font::pShortText(const std::string& txt, float scale, return ""; } +PD_API void Font::Delete() { + for (auto& it : Textures) { + // Creating a tmp fake Li tex for deletion + PD::Gfx::DeleteTexture(PD::Li::Texture(it, 0)); + } + pCurrentTex = 0; + PixelHeight = 0; + pTMS.clear(); + CodeMap.clear(); +} } // namespace Li } // namespace PD \ No newline at end of file diff --git a/tests/gfx/include/os-ctx.hpp b/tests/gfx/include/os-ctx.hpp index 97c648f..e017b60 100644 --- a/tests/gfx/include/os-ctx.hpp +++ b/tests/gfx/include/os-ctx.hpp @@ -29,6 +29,8 @@ class OsCtx { return fvec2(in.x * pViewPort.y, in.y * pViewPort.y); } + const PD::ivec2& GetViewport() const { return pViewPort; } + protected: PD::ivec2 pViewPort; const Driver pDriver;