From d612b0afe60bd58fbeee6a6d30670d8ac4dac891 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquemin Date: Sat, 2 Sep 2023 14:28:28 +0200 Subject: [PATCH] SaveTool: various fixes for HiDPI screens. --- src/SaveTool/SaveTool.cpp | 8 ++++++-- src/SaveTool/SaveTool_Initialisation.cpp | 11 +++-------- src/SaveTool/SaveTool_MainManager.cpp | 4 +++- src/SaveTool/SaveTool_MassViewer.cpp | 2 +- src/SaveTool/SaveTool_MassViewer_Frame.cpp | 11 +++++++++-- src/SaveTool/SaveTool_MassViewer_Weapons.cpp | 10 ++++------ src/SaveTool/SaveTool_ProfileManager.cpp | 4 ++-- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/SaveTool/SaveTool.cpp b/src/SaveTool/SaveTool.cpp index 7fd17bf..6d31180 100644 --- a/src/SaveTool/SaveTool.cpp +++ b/src/SaveTool/SaveTool.cpp @@ -55,6 +55,10 @@ SaveTool::SaveTool(const Arguments& arguments): tweak.enable("", "../../"); #endif + LOG_INFO_FORMAT("Framebuffer size: {}x{}", framebufferSize().x(), framebufferSize().y()); + LOG_INFO_FORMAT("Window size: {}x{}", windowSize().x(), windowSize().y()); + LOG_INFO_FORMAT("DPI scaling: {}x{}", dpiScaling().x(), dpiScaling().y()); + LOG_INFO("Configuring OpenGL renderer."); GL::Renderer::enable(GL::Renderer::Feature::Blending); GL::Renderer::enable(GL::Renderer::Feature::ScissorTest); @@ -306,7 +310,7 @@ SaveTool::drawGui() { void SaveTool::drawDisclaimer() { - ImGui::SetNextWindowPos(ImVec2{Vector2{windowSize() / 2.0f}}, ImGuiCond_Always, center_pivot); + ImGui::SetNextWindowPos(ImVec2{Vector2{windowSize() / 2.0f} / dpiScaling()}, ImGuiCond_Always, center_pivot); if(ImGui::Begin("Disclaimer##DisclaimerWindow", nullptr, ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoBringToFrontOnFocus| @@ -374,7 +378,7 @@ SaveTool::drawDisclaimer() { void SaveTool::drawInitialisation() { - ImGui::SetNextWindowPos(ImVec2{Vector2{windowSize() / 2.0f}}, ImGuiCond_Always, center_pivot); + ImGui::SetNextWindowPos(ImVec2{Vector2{windowSize() / 2.0f} / dpiScaling()}, ImGuiCond_Always, center_pivot); if(ImGui::BeginPopupModal("##InitPopup", nullptr, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar)) diff --git a/src/SaveTool/SaveTool_Initialisation.cpp b/src/SaveTool/SaveTool_Initialisation.cpp index ba0441a..2473242 100644 --- a/src/SaveTool/SaveTool_Initialisation.cpp +++ b/src/SaveTool/SaveTool_Initialisation.cpp @@ -62,7 +62,7 @@ void SaveTool::initialiseGui() { LOG_INFO("Initialising Dear ImGui."); - ImGui::CreateContext(); + auto ctx = ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); @@ -92,15 +92,10 @@ SaveTool::initialiseGui() { 16.0f * float(framebufferSize().x()) / size.x(), &icon_config, brand_range); auto mono_font = _rs.getRaw("SourceCodePro-Regular.ttf"_s); - ImVector range; - ImFontGlyphRangesBuilder builder; - builder.AddRanges(io.Fonts->GetGlyphRangesDefault()); - 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 * float(framebufferSize().x()) / size.x(), &font_config, range.Data); + 18.0f * float(framebufferSize().x()) / size.x(), &font_config); - _imgui = ImGuiIntegration::Context(*ImGui::GetCurrentContext(), windowSize()); + _imgui = ImGuiIntegration::Context(*ctx, Vector2{windowSize()}/dpiScaling(), windowSize(), framebufferSize()); io.IniFilename = nullptr; diff --git a/src/SaveTool/SaveTool_MainManager.cpp b/src/SaveTool/SaveTool_MainManager.cpp index 93ec331..82759f9 100644 --- a/src/SaveTool/SaveTool_MainManager.cpp +++ b/src/SaveTool/SaveTool_MainManager.cpp @@ -19,6 +19,8 @@ #include #include +#include + #include #include "../Configuration/Configuration.h" @@ -31,7 +33,7 @@ void SaveTool::drawManager() { ImGui::SetNextWindowPos({0.0f, ImGui::GetItemRectSize().y}, ImGuiCond_Always); - ImGui::SetNextWindowSize({float(windowSize().x()), float(windowSize().y()) - ImGui::GetItemRectSize().y}, + ImGui::SetNextWindowSize(ImVec2{Vector2{float(windowSize().x()), float(windowSize().y()) - ImGui::GetItemRectSize().y} / dpiScaling()}, ImGuiCond_Always); if(!ImGui::Begin("##MainWindow", nullptr, ImGuiWindowFlags_NoDecoration|ImGuiWindowFlags_NoMove| diff --git a/src/SaveTool/SaveTool_MassViewer.cpp b/src/SaveTool/SaveTool_MassViewer.cpp index 5ec3f0c..3fa25e8 100644 --- a/src/SaveTool/SaveTool_MassViewer.cpp +++ b/src/SaveTool/SaveTool_MassViewer.cpp @@ -38,7 +38,7 @@ SaveTool::drawMassViewer() { } ImGui::SetNextWindowPos({0.0f, ImGui::GetItemRectSize().y}, ImGuiCond_Always); - ImGui::SetNextWindowSize({float(windowSize().x()), float(windowSize().y()) - ImGui::GetItemRectSize().y}, + ImGui::SetNextWindowSize(ImVec2{Vector2{float(windowSize().x()), float(windowSize().y()) - ImGui::GetItemRectSize().y} / dpiScaling()}, ImGuiCond_Always); if(!ImGui::Begin("##MassViewer", nullptr, ImGuiWindowFlags_NoDecoration|ImGuiWindowFlags_NoMove| diff --git a/src/SaveTool/SaveTool_MassViewer_Frame.cpp b/src/SaveTool/SaveTool_MassViewer_Frame.cpp index 61948b6..c670599 100644 --- a/src/SaveTool/SaveTool_MassViewer_Frame.cpp +++ b/src/SaveTool/SaveTool_MassViewer_Frame.cpp @@ -32,7 +32,11 @@ SaveTool::drawFrameInfo() { ImGui::BeginGroup(); - if(ImGui::BeginChild("##JointSliders", {(ImGui::GetContentRegionAvail().x / 2.0f) - (ImGui::GetStyle().WindowPadding.x / 2.0f), 300.0f}, true, ImGuiWindowFlags_MenuBar)) { + if(ImGui::BeginChild("##JointSliders", + {(ImGui::GetContentRegionAvail().x / 2.0f) - (ImGui::GetStyle().WindowPadding.x / 2.0f), + (ImGui::GetContentRegionAvail().y / 1.75f) - (ImGui::GetStyle().WindowPadding.y / 2.0f)}, + true, ImGuiWindowFlags_MenuBar)) + { if(ImGui::BeginMenuBar()) { ImGui::TextUnformatted("Joint sliders"); @@ -43,7 +47,10 @@ SaveTool::drawFrameInfo() { } ImGui::EndChild(); - if(ImGui::BeginChild("##FrameStyles", {(ImGui::GetContentRegionAvail().x / 2.0f) - (ImGui::GetStyle().WindowPadding.x / 2.0f), 0.0f}, true, ImGuiWindowFlags_MenuBar)) { + if(ImGui::BeginChild("##FrameStyles", + {(ImGui::GetContentRegionAvail().x / 2.0f) - (ImGui::GetStyle().WindowPadding.x / 2.0f), 0.0f}, + true, ImGuiWindowFlags_MenuBar)) + { if(ImGui::BeginMenuBar()) { ImGui::TextUnformatted("Frame styles"); diff --git a/src/SaveTool/SaveTool_MassViewer_Weapons.cpp b/src/SaveTool/SaveTool_MassViewer_Weapons.cpp index 7e48de1..f98e31e 100644 --- a/src/SaveTool/SaveTool_MassViewer_Weapons.cpp +++ b/src/SaveTool/SaveTool_MassViewer_Weapons.cpp @@ -51,11 +51,11 @@ SaveTool::drawWeapons() { ImGui::EndTable(); + ImGui::Separator(); + bool dirty = _meleeDirty || _shieldsDirty || _bShootersDirty || _eShootersDirty || _bLaunchersDirty || _eLaunchersDirty; - if(!dirty) { - ImGui::BeginDisabled(); - } + ImGui::BeginDisabled(!dirty); if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) { if(_meleeDirty) { @@ -154,9 +154,7 @@ SaveTool::drawWeapons() { } } - if(!dirty) { - ImGui::EndDisabled(); - } + ImGui::EndDisabled(); ImGui::EndGroup(); diff --git a/src/SaveTool/SaveTool_ProfileManager.cpp b/src/SaveTool/SaveTool_ProfileManager.cpp index 0ce5262..c47f684 100644 --- a/src/SaveTool/SaveTool_ProfileManager.cpp +++ b/src/SaveTool/SaveTool_ProfileManager.cpp @@ -28,7 +28,7 @@ void SaveTool::drawProfileManager() { static std::size_t profile_index = 0; - ImGui::SetNextWindowPos(ImVec2{Vector2{windowSize() / 2.0f}}, ImGuiCond_Always, center_pivot); + ImGui::SetNextWindowPos(ImVec2{Vector2{windowSize() / 2.0f} / dpiScaling()}, ImGuiCond_Always, center_pivot); if(ImGui::Begin("Profile management##ProfileManager", nullptr, ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoBringToFrontOnFocus| ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_MenuBar)) @@ -128,7 +128,7 @@ SaveTool::drawProfileManager() { ImGuiID SaveTool::drawBackupListPopup() { - ImGui::SetNextWindowPos(ImVec2{Vector2{windowSize() / 2.0f}}, ImGuiCond_Always, center_pivot); + ImGui::SetNextWindowPos(ImVec2{Vector2{windowSize() / 2.0f} / dpiScaling()}, ImGuiCond_Always, center_pivot); if(!ImGui::BeginPopupModal("Backups##BackupsModal", nullptr, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove)) {