diff --git a/lib/libimhex/include/hex/api/imhex_api.hpp b/lib/libimhex/include/hex/api/imhex_api.hpp index d522c4932..cff2a5f22 100644 --- a/lib/libimhex/include/hex/api/imhex_api.hpp +++ b/lib/libimhex/include/hex/api/imhex_api.hpp @@ -493,6 +493,7 @@ namespace hex { */ float getNativeScale(); + float getBackingScaleFactor(); /** * @brief Gets the current main window position diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index 530f19a5e..14de88af6 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -18,6 +18,8 @@ #include #include +#include + #if defined(OS_WINDOWS) #include #else @@ -25,6 +27,10 @@ #include #endif +#if defined(OS_WEB) + #include +#endif + namespace hex { @@ -608,6 +614,22 @@ namespace hex { return impl::s_nativeScale; } + float getBackingScaleFactor() { + #if defined(OS_WINDOWS) + return 1.0F; + #elif defined(OS_MACOS) + return ::getBackingScaleFactor(); + #elif defined(OS_LINUX) + return 1.0F; + #elif defined(OS_WEB) + return EM_ASM_INT({ + return window.devicePixelRatio; + }); + #else + return 1.0F; + #endif + } + ImVec2 getMainWindowPosition() { if ((ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) != ImGuiConfigFlags_None) diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index 2342b04e3..bab531909 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -223,11 +223,7 @@ namespace ImGuiExt { } Texture Texture::fromSVG(const char *path, int width, int height, Filter filter) { - #if defined(OS_MACOS) - const auto scaleFactor = getBackingScaleFactor(); - #else - const auto scaleFactor = 1.0F; - #endif + const auto scaleFactor = hex::ImHexApi::System::getBackingScaleFactor(); auto document = lunasvg::Document::loadFromFile(path); auto bitmap = document->renderToBitmap(width * scaleFactor, height * scaleFactor); @@ -247,11 +243,7 @@ namespace ImGuiExt { } Texture Texture::fromSVG(std::span buffer, int width, int height, Filter filter) { - #if defined(OS_MACOS) - const auto scaleFactor = getBackingScaleFactor(); - #else - const auto scaleFactor = 1.0F; - #endif + const auto scaleFactor = hex::ImHexApi::System::getBackingScaleFactor(); auto document = lunasvg::Document::loadFromData(reinterpret_cast(buffer.data()), buffer.size()); auto bitmap = document->renderToBitmap(width * scaleFactor, height * scaleFactor); diff --git a/main/gui/source/init/splash_window.cpp b/main/gui/source/init/splash_window.cpp index 2aa393e0b..cb76f9c17 100644 --- a/main/gui/source/init/splash_window.cpp +++ b/main/gui/source/init/splash_window.cpp @@ -469,11 +469,7 @@ namespace hex::init { if (meanScale <= 0.0F) meanScale = 1.0F; - #if defined(OS_MACOS) - meanScale /= getBackingScaleFactor(); - #elif defined(OS_WEB) - meanScale = 1.0F; - #endif + meanScale /= hex::ImHexApi::System::getBackingScaleFactor(); ImHexApi::System::impl::setGlobalScale(meanScale); ImHexApi::System::impl::setNativeScale(meanScale); diff --git a/main/gui/source/window/macos_window.cpp b/main/gui/source/window/macos_window.cpp index 61ec156a3..704ecf741 100644 --- a/main/gui/source/window/macos_window.cpp +++ b/main/gui/source/window/macos_window.cpp @@ -96,9 +96,6 @@ namespace hex { auto win = static_cast(glfwGetWindowUserPointer(window)); win->fullFrame(); }); - - // Done to get super crisp font rendering together with GLFW_COCOA_RETINA_FRAMEBUFFER - ImGui::GetIO().FontGlobalScale = 1.0F / getBackingScaleFactor(); } void Window::beginNativeWindowFrame() { diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index b1c173769..0703a410a 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -746,6 +746,8 @@ namespace hex { // NOTE: This needs to be done before a new frame is started, otherwise ImGui won't handle docking correctly LayoutManager::process(); WorkspaceManager::process(); + + ImGui::GetIO().FontGlobalScale = 1.0F / ImHexApi::System::getBackingScaleFactor(); } void Window::initGLFW() { diff --git a/plugins/fonts/source/font_loader.cpp b/plugins/fonts/source/font_loader.cpp index c20356ebf..12b440aaa 100644 --- a/plugins/fonts/source/font_loader.cpp +++ b/plugins/fonts/source/font_loader.cpp @@ -218,15 +218,11 @@ namespace hex::fonts { } private: - float getAdjustedFontSize(float fontSize) { + float getAdjustedFontSize(float fontSize) const { // Since macOS reports half the framebuffer size that's actually available, // we'll multiply all font sizes by that and then divide the global font scale // by the same amount to get super crisp font rendering. - #if defined(OS_MACOS) - return fontSize * getBackingScaleFactor(); - #else - return fontSize; - #endif + return fontSize * hex::ImHexApi::System::getBackingScaleFactor(); } private: