From 5ea6f1e3a7f1c5e30271bebb8d8ebc273f514155 Mon Sep 17 00:00:00 2001 From: William JCM Date: Fri, 25 Nov 2022 11:46:14 +0100 Subject: [PATCH] SaveToo: add HiDPI support to ImGui. I... kinda forgot to do that. --- src/SaveTool/SaveTool.cpp | 3 ++- src/SaveTool/SaveTool_Initialisation.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/SaveTool/SaveTool.cpp b/src/SaveTool/SaveTool.cpp index e5d2410..0f85774 100644 --- a/src/SaveTool/SaveTool.cpp +++ b/src/SaveTool/SaveTool.cpp @@ -203,7 +203,8 @@ void SaveTool::drawEvent() { void SaveTool::viewportEvent(ViewportEvent& event) { GL::defaultFramebuffer.setViewport({{}, event.framebufferSize()}); - _imgui.relayout(event.windowSize()); + const Vector2 size = Vector2{windowSize()}/dpiScaling(); + _imgui.relayout(size, windowSize(), framebufferSize()); } void SaveTool::keyPressEvent(KeyEvent& event) { diff --git a/src/SaveTool/SaveTool_Initialisation.cpp b/src/SaveTool/SaveTool_Initialisation.cpp index dc41068..e5021e9 100644 --- a/src/SaveTool/SaveTool_Initialisation.cpp +++ b/src/SaveTool/SaveTool_Initialisation.cpp @@ -95,12 +95,14 @@ void SaveTool::initialiseGui() { ImGuiIO& io = ImGui::GetIO(); + const auto size = Vector2{windowSize()}/dpiScaling(); + auto reg_font = _rs.getRaw("SourceSansPro-Regular.ttf"_s); ImFontConfig font_config; font_config.FontDataOwnedByAtlas = false; std::strcpy(font_config.Name, "Source Sans Pro"); io.Fonts->AddFontFromMemoryTTF(const_cast(reg_font.data()), int(reg_font.size()), - 20.0f, &font_config); + 20.0f * Float(framebufferSize().x()) / size.x(), &font_config); auto icon_font = _rs.getRaw(FONT_ICON_FILE_NAME_FAS); static const ImWchar icon_range[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; @@ -111,12 +113,12 @@ void SaveTool::initialiseGui() { icon_config.OversampleH = icon_config.OversampleV = 1; icon_config.GlyphMinAdvanceX = 18.0f; io.Fonts->AddFontFromMemoryTTF(const_cast(icon_font.data()), int(icon_font.size()), - 16.0f, &icon_config, icon_range); + 16.0f * Float(framebufferSize().x()) / size.x(), &icon_config, icon_range); auto brand_font = _rs.getRaw(FONT_ICON_FILE_NAME_FAB); static const ImWchar brand_range[] = { ICON_MIN_FAB, ICON_MAX_FAB, 0 }; io.Fonts->AddFontFromMemoryTTF(const_cast(brand_font.data()), int(brand_font.size()), - 16.0f, &icon_config, brand_range); + 16.0f * Float(framebufferSize().x()) / size.x(), &icon_config, brand_range); auto mono_font = _rs.getRaw("SourceCodePro-Regular.ttf"_s); ImVector range; @@ -125,7 +127,7 @@ void SaveTool::initialiseGui() { builder.AddChar(u'š'); // This allows displaying Vladimír Vondruš' name in Corrade's and Magnum's licences. builder.BuildRanges(&range); io.Fonts->AddFontFromMemoryTTF(const_cast(mono_font.data()), int(mono_font.size()), - 18.0f, &font_config, range.Data); + 18.0f * Float(framebufferSize().x()) / size.x(), &font_config, range.Data); _imgui = ImGuiIntegration::Context(*ImGui::GetCurrentContext(), windowSize());