From 2ab54baa2c1d27afdce5fe78eca9899e68b4de11 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 10 Jul 2025 14:39:52 +0200 Subject: [PATCH] fix: DPI scaling --- main/gui/source/window/win_window.cpp | 7 ++++++- plugins/builtin/source/content/events.cpp | 5 +++++ plugins/builtin/source/content/welcome_screen.cpp | 14 ++++++-------- plugins/fonts/source/library_fonts.cpp | 4 ++++ 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/main/gui/source/window/win_window.cpp b/main/gui/source/window/win_window.cpp index 0f91ed815..e200af697 100644 --- a/main/gui/source/window/win_window.cpp +++ b/main/gui/source/window/win_window.cpp @@ -78,7 +78,6 @@ namespace hex { ImHexApi::System::impl::setNativeScale(newScale); ThemeManager::reapplyCurrentTheme(); - ImGui::GetStyle().ScaleAllSizes(newScale); return TRUE; } @@ -153,6 +152,11 @@ namespace hex { // Custom window procedure for borderless window static LRESULT borderlessWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { + case WM_MOVE: { + auto imhexWindow = static_cast(glfwGetWindowUserPointer(ImHexApi::System::getMainWindowHandle())); + imhexWindow->fullFrame(); + break; + } case WM_MOUSELAST: break; case WM_NCACTIVATE: @@ -310,6 +314,7 @@ namespace hex { break; } + break; } default: diff --git a/plugins/builtin/source/content/events.cpp b/plugins/builtin/source/content/events.cpp index 732d55080..770c0020e 100644 --- a/plugins/builtin/source/content/events.cpp +++ b/plugins/builtin/source/content/events.cpp @@ -33,6 +33,7 @@ #include #include +#include namespace hex::plugin::builtin { @@ -322,6 +323,10 @@ namespace hex::plugin::builtin { } }); + RequestChangeTheme::subscribe([](const std::string &theme) { + ThemeManager::changeTheme(theme); + }); + fs::setFileBrowserErrorCallback([](const std::string& errMsg){ #if defined(NFD_PORTAL) ui::PopupError::open(hex::format("hex.builtin.popup.error.file_dialog.portal"_lang, errMsg)); diff --git a/plugins/builtin/source/content/welcome_screen.cpp b/plugins/builtin/source/content/welcome_screen.cpp index 0aa31feb0..dd2324e39 100644 --- a/plugins/builtin/source/content/welcome_screen.cpp +++ b/plugins/builtin/source/content/welcome_screen.cpp @@ -627,7 +627,7 @@ namespace hex::plugin::builtin { ImHexApi::System::setTargetFPS(static_cast(value.get(14))); }); - RequestChangeTheme::subscribe([](const std::string &theme) { + static auto updateTextures = [](float scale) { auto changeTexture = [&](const std::string &path) { return ImGuiExt::Texture::fromImage(romfs::get(path).span(), ImGuiExt::Texture::Filter::Nearest); }; @@ -636,15 +636,13 @@ namespace hex::plugin::builtin { return ImGuiExt::Texture::fromSVG(romfs::get(path).span(), width, 0, ImGuiExt::Texture::Filter::Linear); }; - ThemeManager::changeTheme(theme); - s_bannerTexture = changeTextureSvg(hex::format("assets/{}/banner.svg", ThemeManager::getImageTheme()), 300_scaled); - s_nightlyTexture = changeTextureSvg(hex::format("assets/{}/nightly.svg", "common"), 35_scaled); + s_bannerTexture = changeTextureSvg(hex::format("assets/{}/banner.svg", ThemeManager::getImageTheme()), 300 * scale); + s_nightlyTexture = changeTextureSvg(hex::format("assets/{}/nightly.svg", "common"), 35 * scale); s_backdropTexture = changeTexture(hex::format("assets/{}/backdrop.png", ThemeManager::getImageTheme())); + }; - if (!s_bannerTexture->isValid()) { - log::error("Failed to load banner texture!"); - } - }); + RequestChangeTheme::subscribe([]() { updateTextures(ImHexApi::System::getGlobalScale()); }); + EventDPIChanged::subscribe([](float, float newScale) { updateTextures(newScale); } ); // Clear project context if we go back to the welcome screen EventProviderChanged::subscribe([](const hex::prv::Provider *oldProvider, const hex::prv::Provider *newProvider) { diff --git a/plugins/fonts/source/library_fonts.cpp b/plugins/fonts/source/library_fonts.cpp index f024fa90b..8276de8a7 100644 --- a/plugins/fonts/source/library_fonts.cpp +++ b/plugins/fonts/source/library_fonts.cpp @@ -115,4 +115,8 @@ IMHEX_LIBRARY_SETUP("Fonts") { hex::fonts::setupFonts(); hex::ImHexApi::Fonts::setDefaultFont(hex::fonts::Default()); }); + + hex::EventDPIChanged::subscribe([](float, float newScale) { + ImGui::GetIO().ConfigDpiScaleFonts = newScale; + }); } \ No newline at end of file