scale undersized plugin images without losing dimensions

This commit is contained in:
Raymond 2021-09-23 11:56:05 -04:00
parent 4a4aa2d85c
commit da6ee0252d

View file

@ -665,7 +665,21 @@ namespace Dalamud.Interface.Internal.Windows
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, Vector2.Zero); 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.OpenPopup(popupId);
ImGui.PopStyleVar(); ImGui.PopStyleVar();
@ -1560,7 +1574,21 @@ namespace Dalamud.Interface.Internal.Windows
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, Vector2.Zero); 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.OpenPopup(popupId);
ImGui.PopStyleVar(); ImGui.PopStyleVar();