diff --git a/UnleashedRecomp/ui/achievement_menu.cpp b/UnleashedRecomp/ui/achievement_menu.cpp index b72efde1..7008eefe 100644 --- a/UnleashedRecomp/ui/achievement_menu.cpp +++ b/UnleashedRecomp/ui/achievement_menu.cpp @@ -134,8 +134,8 @@ static void DrawHeaderContainer(const char* text) ? Lerp(1, 0, colourMotion) : Lerp(0, 1, colourMotion); - ImVec2 min = { Scale(containerMarginX), Scale(136) }; - ImVec2 max = { min.x + textMarginX * 2 + textSize.x + Scale(5), Scale(196) }; + ImVec2 min = { Scale(g_aspectRatioOffsetX + containerMarginX), Scale(g_aspectRatioOffsetY + 136) }; + ImVec2 max = { min.x + textMarginX * 2 + textSize.x + Scale(5), Scale(g_aspectRatioOffsetY + 196) }; DrawPauseHeaderContainer(g_upWindow.get(), min, max, alpha); @@ -568,8 +568,8 @@ static void DrawContentContainer() ? Hermite(604, 573, motion) : Hermite(573, 604, motion); - ImVec2 min = { Scale(minX), Scale(minY) }; - ImVec2 max = { Scale(maxX), Scale(maxY) }; + ImVec2 min = { Scale(g_aspectRatioOffsetX + minX), Scale(g_aspectRatioOffsetY + minY) }; + ImVec2 max = { Scale(g_aspectRatioOffsetX + maxX), Scale(g_aspectRatioOffsetY + maxY) }; // Transparency fade animation. auto alpha = g_isClosing diff --git a/UnleashedRecomp/ui/imgui_utils.h b/UnleashedRecomp/ui/imgui_utils.h index 99c72fe6..48f0caed 100644 --- a/UnleashedRecomp/ui/imgui_utils.h +++ b/UnleashedRecomp/ui/imgui_utils.h @@ -4,6 +4,7 @@ #include #include #include +#include #define PIXELS_TO_UV_COORDS(textureWidth, textureHeight, x, y, width, height) \ std::make_tuple(ImVec2((float)x / (float)textureWidth, (float)y / (float)textureHeight), \ @@ -95,34 +96,16 @@ inline void ResetOutline() SetOutline(0.0f); } -// Aspect ratio aware. inline float Scale(float size) { auto& io = ImGui::GetIO(); - constexpr float ORIGINAL_ASPECT_RATIO = 4.0f / 3.0f; - float aspectRatio = io.DisplaySize.x / io.DisplaySize.y; - - if (aspectRatio >= ORIGINAL_ASPECT_RATIO) + if (g_aspectRatio >= NARROW_ASPECT_RATIO) return size * (io.DisplaySize.y / 720.0f); else return size * (io.DisplaySize.x / 960.0f); } -// Not aspect ratio aware. Will stretch. -inline float ScaleX(float x) -{ - auto& io = ImGui::GetIO(); - return x * io.DisplaySize.x / 1280.0f; -} - -// Not aspect ratio aware. Will stretch. -inline float ScaleY(float y) -{ - auto& io = ImGui::GetIO(); - return y * io.DisplaySize.y / 720.0f; -} - inline double ComputeMotion(double duration, double offset, double total) { return sqrt(std::clamp((ImGui::GetTime() - duration - offset / 60.0) / total * 60.0, 0.0, 1.0));