From 3b4d6d465bf8aaa4cc39646a5d292127ec640763 Mon Sep 17 00:00:00 2001 From: Lukas Cone Date: Sat, 19 Feb 2022 00:35:07 +0100 Subject: [PATCH] fix: Welcome screen corrupted banner when settings are open (#447) --- .../builtin/source/content/welcome_screen.cpp | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/plugins/builtin/source/content/welcome_screen.cpp b/plugins/builtin/source/content/welcome_screen.cpp index 0009d0530..ef8bd68ed 100644 --- a/plugins/builtin/source/content/welcome_screen.cpp +++ b/plugins/builtin/source/content/welcome_screen.cpp @@ -27,6 +27,7 @@ namespace hex::plugin::builtin { static bool s_layoutConfigured = false; static ImGui::Texture s_bannerTexture; + static std::string s_bannerTextureName; static std::list s_recentFilePaths; static fs::path s_safetyBackupPath; @@ -288,8 +289,14 @@ namespace hex::plugin::builtin { { auto theme = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.color"); - if (theme.is_number()) - EventManager::post(theme.get()); + if (theme.is_number()) { + static int lastTheme = theme.get(); + + if (const int thisTheme = theme.get(); thisTheme != lastTheme) { + EventManager::post(thisTheme); + lastTheme = thisTheme; + } + } } { @@ -319,8 +326,18 @@ namespace hex::plugin::builtin { }); (void)EventManager::subscribe([](u32 theme) { - if (s_bannerTexture.valid()) - ImGui::UnloadImage(s_bannerTexture); + auto changeBannerTexture = [&](const char newTexture[]) { + if (s_bannerTextureName == newTexture) { + return; + } + + s_bannerTextureName = newTexture; + auto banner = romfs::get(newTexture); + auto oldBannerTexture = s_bannerTexture; + s_bannerTexture = ImGui::LoadImageFromMemory(reinterpret_cast(banner.data()), banner.size()); + + if (oldBannerTexture.valid()) { ImGui::UnloadImage(oldBannerTexture); } + }; switch (theme) { default: @@ -329,9 +346,7 @@ namespace hex::plugin::builtin { ImGui::StyleColorsDark(); ImGui::StyleCustomColorsDark(); ImPlot::StyleColorsDark(); - - auto banner = romfs::get("banner_dark.png"); - s_bannerTexture = ImGui::LoadImageFromMemory(reinterpret_cast(banner.data()), banner.size()); + changeBannerTexture("banner_dark.png"); break; } @@ -340,9 +355,7 @@ namespace hex::plugin::builtin { ImGui::StyleColorsLight(); ImGui::StyleCustomColorsLight(); ImPlot::StyleColorsLight(); - - auto banner = romfs::get("banner_light.png"); - s_bannerTexture = ImGui::LoadImageFromMemory(reinterpret_cast(banner.data()), banner.size()); + changeBannerTexture("banner_light.png"); break; } @@ -351,9 +364,7 @@ namespace hex::plugin::builtin { ImGui::StyleColorsClassic(); ImGui::StyleCustomColorsClassic(); ImPlot::StyleColorsClassic(); - - auto banner = romfs::get("banner_dark.png"); - s_bannerTexture = ImGui::LoadImageFromMemory(reinterpret_cast(banner.data()), banner.size()); + changeBannerTexture("banner_dark.png"); break; } @@ -469,4 +480,4 @@ namespace hex::plugin::builtin { } } -} \ No newline at end of file +}