From 23ce2ec2713a0e59ec5ed4561ea1422671e5092d Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 8 Nov 2022 18:09:48 +0100 Subject: [PATCH] ui: Fixed some more macOS scaling issues --- main/source/init/splash_window.cpp | 8 ++++++-- main/source/init/tasks.cpp | 24 +++++++++++------------- main/source/window/window.cpp | 1 + 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/main/source/init/splash_window.cpp b/main/source/init/splash_window.cpp index 4f301bc28..1b3d5ad06 100644 --- a/main/source/init/splash_window.cpp +++ b/main/source/init/splash_window.cpp @@ -200,8 +200,12 @@ namespace hex::init { glfwGetWindowContentScale(this->m_window, &xScale, &yScale); auto meanScale = std::midpoint(xScale, yScale); - if (meanScale <= 0.0) - meanScale = 1.0; + if (meanScale <= 0.0F) + meanScale = 1.0F; + + #if defined(OS_MACOS) + meanScale /= 2.0F; + #endif ImHexApi::System::impl::setGlobalScale(meanScale); ImHexApi::System::impl::setNativeScale(meanScale); diff --git a/main/source/init/tasks.cpp b/main/source/init/tasks.cpp index a230554e6..2a80b42a0 100644 --- a/main/source/init/tasks.cpp +++ b/main/source/init/tasks.cpp @@ -83,8 +83,15 @@ namespace hex::init { } bool loadFonts() { + const auto scale = ImHexApi::System::getNativeScale(); + float fontSize = ImHexApi::System::getFontSize(); + + const auto &fontFile = ImHexApi::System::getCustomFontPath(); + auto fonts = IM_NEW(ImFontAtlas)(); ImFontConfig cfg = {}; + cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true; + cfg.SizePixels = fontSize * scale; ImVector ranges; { @@ -111,33 +118,24 @@ namespace hex::init { 0x0100, 0xFFF0, 0 }; - const auto &fontFile = ImHexApi::System::getCustomFontPath(); - float fontSize = ImHexApi::System::getFontSize(); if (fontFile.empty()) { // Load default font if no custom one has been specified fonts->Clear(); - - cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true; - cfg.SizePixels = fontSize; fonts->AddFontDefault(&cfg); } else { // Load custom font - - cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true; - cfg.SizePixels = fontSize; - - fonts->AddFontFromFileTTF(hex::toUTF8String(fontFile).c_str(), std::floor(fontSize), &cfg, ranges.Data); // Needs conversion to char for Windows + fonts->AddFontFromFileTTF(hex::toUTF8String(fontFile).c_str(), std::floor(fontSize * scale), &cfg, ranges.Data); // Needs conversion to char for Windows } cfg.MergeMode = true; - fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, fontSize, &cfg, fontAwesomeRange); - fonts->AddFontFromMemoryCompressedTTF(codicons_compressed_data, codicons_compressed_size, fontSize, &cfg, codiconsRange); + fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, fontSize * scale, &cfg, fontAwesomeRange); + fonts->AddFontFromMemoryCompressedTTF(codicons_compressed_data, codicons_compressed_size, fontSize * scale, &cfg, codiconsRange); bool enableUnicode = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.enable_unicode", true); if (enableUnicode) - fonts->AddFontFromMemoryCompressedTTF(unifont_compressed_data, unifont_compressed_size, fontSize, &cfg, unifontRange); + fonts->AddFontFromMemoryCompressedTTF(unifont_compressed_data, unifont_compressed_size, fontSize * scale, &cfg, unifontRange); fonts->Build(); diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index 391696744..2cdb50e6e 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -693,6 +693,7 @@ namespace hex { io.ConfigFlags |= ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_NavEnableKeyboard; io.ConfigWindowsMoveFromTitleBarOnly = true; + io.FontGlobalScale = 1.0F / ImHexApi::System::getNativeScale(); if (glfwGetPrimaryMonitor() != nullptr) { auto sessionType = hex::getEnvironmentVariable("XDG_SESSION_TYPE");