From da6ee0252d43a72dad4989c2ed19848da6d80937 Mon Sep 17 00:00:00 2001 From: Raymond Date: Thu, 23 Sep 2021 11:56:05 -0400 Subject: [PATCH] scale undersized plugin images without losing dimensions --- .../Internal/Windows/PluginInstallerWindow.cs | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs index b793139a9..7b0a64384 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs @@ -665,7 +665,21 @@ namespace Dalamud.Interface.Internal.Windows ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, Vector2.Zero); - if (ImGui.ImageButton(image.ImGuiHandle, ImGuiHelpers.ScaledVector2(image.Width / thumbFactor, image.Height / thumbFactor))) + float xAct = image.Width; + float yAct = image.Height; + float xMax = PluginImageWidth; + float yMax = PluginImageHeight; + + // scale image if undersized + if (xAct < xMax && yAct < yMax) + { + var scale = Math.Min(xMax / xAct, yMax / yAct); + xAct *= scale; + yAct *= scale; + } + + var size = ImGuiHelpers.ScaledVector2(xAct / thumbFactor, yAct / thumbFactor); + if (ImGui.ImageButton(image.ImGuiHandle, size)) ImGui.OpenPopup(popupId); ImGui.PopStyleVar(); @@ -1560,7 +1574,21 @@ namespace Dalamud.Interface.Internal.Windows ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, Vector2.Zero); - if (ImGui.ImageButton(image.ImGuiHandle, ImGuiHelpers.ScaledVector2(image.Width / thumbFactor, image.Height / thumbFactor))) + float xAct = image.Width; + float yAct = image.Height; + float xMax = PluginImageWidth; + float yMax = PluginImageHeight; + + // scale image if undersized + if (xAct < xMax && yAct < yMax) + { + var scale = Math.Min(xMax / xAct, yMax / yAct); + xAct *= scale; + yAct *= scale; + } + + var size = ImGuiHelpers.ScaledVector2(xAct / thumbFactor, yAct / thumbFactor); + if (ImGui.ImageButton(image.ImGuiHandle, size)) ImGui.OpenPopup(popupId); ImGui.PopStyleVar();