From 8eaf5e1a0f674ed835240e216b0773b67e9e0f2e Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 24 Jan 2019 01:13:05 +0100 Subject: [PATCH] imgui: allow a client application to invalidate fonts. --- src/lolimgui.cpp | 27 ++++++++++++++++++--------- src/lolimgui.h | 2 ++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/lolimgui.cpp b/src/lolimgui.cpp index 4b41c6db..bf9e807f 100644 --- a/src/lolimgui.cpp +++ b/src/lolimgui.cpp @@ -181,6 +181,23 @@ const char* LolImGui::GetClipboardCallback(void *data) return clipboard->c_str(); } +void LolImGui::refresh_fonts() +{ + if (g_lolimgui->m_font) + Ticker::Unref(g_lolimgui->m_font); + + // Build texture + unsigned char* pixels; + ivec2 size; + ImGuiIO& io = ImGui::GetIO(); + io.Fonts->GetTexDataAsRGBA32(&pixels, &size.x, &size.y); + + Image* image = new Image(); + image->Copy(pixels, size, PixelFormat::RGBA_8); + + Ticker::Ref(g_lolimgui->m_font = new TextureImage("", image)); +} + //----------------------------------------------------------------------------- void LolImGui::tick_game(float seconds) { @@ -191,15 +208,7 @@ void LolImGui::tick_game(float seconds) // Init Texture if (!m_font) { - // Build texture - unsigned char* pixels; - ivec2 size; - io.Fonts->GetTexDataAsRGBA32(&pixels, &size.x, &size.y); - - Image* image = new Image(); - image->Copy(pixels, size, PixelFormat::RGBA_8); - - Ticker::Ref(m_font = new TextureImage("", image)); + refresh_fonts(); } // Texture has been created diff --git a/src/lolimgui.h b/src/lolimgui.h index fcaf1f88..0ecf089c 100644 --- a/src/lolimgui.h +++ b/src/lolimgui.h @@ -160,6 +160,8 @@ public: //------------------------------------------------------------------------- static std::string GetClipboard(); + static void refresh_fonts(); + protected: virtual void tick_game(float seconds); virtual void tick_draw(float seconds, Scene &scene);