From 7c40cf943ff57f6a62149d8cc3f21678d74858fe Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:36:28 +0300 Subject: [PATCH] Animate category tab background from the center. --- UnleashedRecomp/ui/options_menu.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/UnleashedRecomp/ui/options_menu.cpp b/UnleashedRecomp/ui/options_menu.cpp index cbb1289c..5236cf01 100644 --- a/UnleashedRecomp/ui/options_menu.cpp +++ b/UnleashedRecomp/ui/options_menu.cpp @@ -293,7 +293,7 @@ static void DrawContainer(ImVec2 min, ImVec2 max) drawList->PushClipRect({ min.x + gridSize * 2.0f, min.y + gridSize * 2.0f }, { max.x - gridSize * 2.0f + 1.0f, max.y - gridSize * 2.0f + 1.0f }); } -static int32_t g_categoryCount = 4; +static constexpr int32_t g_categoryCount = 4; static int32_t g_categoryIndex; static ImVec2 g_categoryAnimMin; static ImVec2 g_categoryAnimMax; @@ -308,6 +308,8 @@ static std::string& GetCategory(int index) case 2: return Localise("Options_Category_Audio"); case 3: return Localise("Options_Category_Video"); } + + return g_localeMissing; } static int32_t g_firstVisibleRowIndex; @@ -421,8 +423,15 @@ static bool DrawCategories() animWidth = Lerp(animWidth, width, 1.0f - exp(-64.0f * ImGui::GetIO().DeltaTime)); - g_categoryAnimMin = Lerp(g_categoryAnimMin, min, 1.0f - exp(-16.0f * ImGui::GetIO().DeltaTime)); - g_categoryAnimMax = { g_categoryAnimMin.x + animWidth, g_categoryAnimMin.y + height }; + auto center = Lerp(min, max, 0.5f); + auto animCenter = Lerp(g_categoryAnimMin, g_categoryAnimMax, 0.5f); + auto animatedCenter = Lerp(animCenter, center, 1.0f - exp(-16.0f * ImGui::GetIO().DeltaTime)); + + float widthHalfExtent = width / 2.0f; + float heightHalfExtent = height / 2.0f; + + g_categoryAnimMin = { animatedCenter.x - widthHalfExtent, animatedCenter.y - heightHalfExtent }; + g_categoryAnimMax = { animatedCenter.x + widthHalfExtent, animatedCenter.y + heightHalfExtent }; } SetShaderModifier(IMGUI_SHADER_MODIFIER_SCANLINE_BUTTON);