From 7dc93bee7e6929aa5a13e68831f3943500295b05 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 31 Dec 2023 02:43:06 +1000 Subject: [PATCH] ImGuiFullscreen: Add LayoutUnscale() --- pcsx2/ImGui/ImGuiFullscreen.cpp | 3 +++ pcsx2/ImGui/ImGuiFullscreen.h | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pcsx2/ImGui/ImGuiFullscreen.cpp b/pcsx2/ImGui/ImGuiFullscreen.cpp index 058182c303..5311df7f59 100644 --- a/pcsx2/ImGui/ImGuiFullscreen.cpp +++ b/pcsx2/ImGui/ImGuiFullscreen.cpp @@ -61,6 +61,7 @@ namespace ImGuiFullscreen ImFont* g_icon_font = nullptr; float g_layout_scale = 1.0f; + float g_rcp_layout_scale = 1.0f; float g_layout_padding_left = 0.0f; float g_layout_padding_top = 0.0f; @@ -429,6 +430,8 @@ bool ImGuiFullscreen::UpdateLayoutScale() g_layout_padding_left = 0.0f; } + g_rcp_layout_scale = 1.0f / g_layout_scale; + return g_layout_scale != old_scale; } diff --git a/pcsx2/ImGui/ImGuiFullscreen.h b/pcsx2/ImGui/ImGuiFullscreen.h index 0df7872442..058255b0f3 100644 --- a/pcsx2/ImGui/ImGuiFullscreen.h +++ b/pcsx2/ImGui/ImGuiFullscreen.h @@ -36,6 +36,7 @@ namespace ImGuiFullscreen extern ImFont* g_large_font; extern float g_layout_scale; + extern float g_rcp_layout_scale; extern float g_layout_padding_left; extern float g_layout_padding_top; @@ -56,7 +57,6 @@ namespace ImGuiFullscreen extern ImVec4 UISecondaryTextColor; static __fi float DPIScale(float v) { return ImGui::GetIO().DisplayFramebufferScale.x * v; } - static __fi float DPIScale(int v) { return ImGui::GetIO().DisplayFramebufferScale.x * static_cast(v); } static __fi ImVec2 DPIScale(const ImVec2& v) @@ -66,13 +66,10 @@ namespace ImGuiFullscreen } static __fi float WindowWidthScale(float v) { return ImGui::GetWindowWidth() * v; } - static __fi float WindowHeightScale(float v) { return ImGui::GetWindowHeight() * v; } static __fi float LayoutScale(float v) { return g_layout_scale * v; } - static __fi ImVec2 LayoutScale(const ImVec2& v) { return ImVec2(v.x * g_layout_scale, v.y * g_layout_scale); } - static __fi ImVec2 LayoutScale(float x, float y) { return ImVec2(x * g_layout_scale, y * g_layout_scale); } static __fi ImVec2 LayoutScaleAndOffset(float x, float y) @@ -80,6 +77,10 @@ namespace ImGuiFullscreen return ImVec2(g_layout_padding_left + x * g_layout_scale, g_layout_padding_top + y * g_layout_scale); } + static __fi float LayoutUnscale(float v) { return g_rcp_layout_scale * v; } + static __fi ImVec2 LayoutUnscale(const ImVec2& v) { return ImVec2(v.x * g_rcp_layout_scale, v.y * g_rcp_layout_scale); } + static __fi ImVec2 LayoutUnscale(float x, float y) { return ImVec2(x * g_rcp_layout_scale, y * g_rcp_layout_scale); } + static __fi ImVec4 ModAlpha(const ImVec4& v, float a) { return ImVec4(v.x, v.y, v.z, a); } static __fi ImVec4 MulAlpha(const ImVec4& v, float a) { return ImVec4(v.x, v.y, v.z, v.w * a); }