From a9677084ea61dfb43af7f26ff297343d81fd0314 Mon Sep 17 00:00:00 2001 From: "Skyth (Asilkan)" <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Mon, 27 Jan 2025 01:24:05 +0300 Subject: [PATCH] Fix faulty ImGui clip rect usage. (#211) --- UnleashedRecomp/gpu/video.cpp | 3 +- UnleashedRecomp/ui/achievement_menu.cpp | 2 + UnleashedRecomp/ui/achievement_overlay.cpp | 87 ++++++++++++---------- UnleashedRecomp/ui/message_window.cpp | 8 +- 4 files changed, 56 insertions(+), 44 deletions(-) diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index 64f6ca7..e2501e6 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -2098,8 +2098,9 @@ static void DrawImGui() ButtonGuide::Draw(); Fader::Draw(); - DrawProfiler(); + assert(ImGui::GetForegroundDrawList()->_ClipRectStack.Size == 1 && "Some clip rects were not removed from the stack!"); + DrawProfiler(); ImGui::Render(); auto drawData = ImGui::GetDrawData(); diff --git a/UnleashedRecomp/ui/achievement_menu.cpp b/UnleashedRecomp/ui/achievement_menu.cpp index 3ebd147..bae8ba9 100644 --- a/UnleashedRecomp/ui/achievement_menu.cpp +++ b/UnleashedRecomp/ui/achievement_menu.cpp @@ -580,11 +580,13 @@ static void DrawContentContainer() if (motion < 1.0f) { + drawList->PopClipRect(); return; } else if (g_isClosing) { AchievementMenu::s_isVisible = false; + drawList->PopClipRect(); return; } diff --git a/UnleashedRecomp/ui/achievement_overlay.cpp b/UnleashedRecomp/ui/achievement_overlay.cpp index d841423..626533e 100644 --- a/UnleashedRecomp/ui/achievement_overlay.cpp +++ b/UnleashedRecomp/ui/achievement_overlay.cpp @@ -67,9 +67,13 @@ static bool DrawContainer(ImVec2 min, ImVec2 max, float cornerRadius = 25) DrawPauseContainer(g_upWindow.get(), min, max, alpha); - drawList->PushClipRect(min, max); + if (containerMotion >= 1.0f) + { + drawList->PushClipRect(min, max); + return true; + } - return containerMotion >= 1.0f; + return false; } void AchievementOverlay::Init() @@ -117,49 +121,50 @@ void AchievementOverlay::Draw() if (DrawContainer(min, max)) { - if (g_isClosing) + if (!g_isClosing) + { + // Draw achievement icon. + drawList->AddImage + ( + g_xdbfTextureCache[g_achievement.ID], // user_texture_id + { /* X */ min.x + imageMarginX, /* Y */ min.y + imageMarginY }, // p_min + { /* X */ min.x + imageMarginX + imageSize, /* Y */ min.y + imageMarginY + imageSize }, // p_max + { 0, 0 }, // uv_min + { 1, 1 }, // uv_max + IM_COL32(255, 255, 255, 255) // col + ); + + // Draw header text. + DrawTextWithShadow + ( + g_fntSeurat, // font + fontSize, // fontSize + { /* X */ min.x + textMarginX + (maxSize - headerSize.x) / 2, /* Y */ min.y + textMarginY }, // pos + IM_COL32(252, 243, 5, 255), // colour + strAchievementUnlocked, // text + 2, // offset + 1.0f, // radius + IM_COL32(0, 0, 0, 255) // shadowColour + ); + + // Draw achievement name. + DrawTextWithShadow + ( + g_fntSeurat, // font + fontSize, // fontSize + { /* X */ min.x + textMarginX + (maxSize - bodySize.x) / 2, /* Y */ min.y + textMarginY + bodySize.y + Scale(6) }, // pos + IM_COL32(255, 255, 255, 255), // colour + strAchievementName, // text + 2, // offset + 1.0f, // radius + IM_COL32(0, 0, 0, 255) // shadowColour + ); + } + else { s_isVisible = false; - return; } - // Draw achievement icon. - drawList->AddImage - ( - g_xdbfTextureCache[g_achievement.ID], // user_texture_id - { /* X */ min.x + imageMarginX, /* Y */ min.y + imageMarginY }, // p_min - { /* X */ min.x + imageMarginX + imageSize, /* Y */ min.y + imageMarginY + imageSize }, // p_max - { 0, 0 }, // uv_min - { 1, 1 }, // uv_max - IM_COL32(255, 255, 255, 255) // col - ); - - // Draw header text. - DrawTextWithShadow - ( - g_fntSeurat, // font - fontSize, // fontSize - { /* X */ min.x + textMarginX + (maxSize - headerSize.x) / 2, /* Y */ min.y + textMarginY }, // pos - IM_COL32(252, 243, 5, 255), // colour - strAchievementUnlocked, // text - 2, // offset - 1.0f, // radius - IM_COL32(0, 0, 0, 255) // shadowColour - ); - - // Draw achievement name. - DrawTextWithShadow - ( - g_fntSeurat, // font - fontSize, // fontSize - { /* X */ min.x + textMarginX + (maxSize - bodySize.x) / 2, /* Y */ min.y + textMarginY + bodySize.y + Scale(6) }, // pos - IM_COL32(255, 255, 255, 255), // colour - strAchievementName, // text - 2, // offset - 1.0f, // radius - IM_COL32(0, 0, 0, 255) // shadowColour - ); - // Pop clip rect from DrawContainer. drawList->PopClipRect(); } diff --git a/UnleashedRecomp/ui/message_window.cpp b/UnleashedRecomp/ui/message_window.cpp index c7e454e..6769873 100644 --- a/UnleashedRecomp/ui/message_window.cpp +++ b/UnleashedRecomp/ui/message_window.cpp @@ -192,9 +192,13 @@ bool DrawContainer(float appearTime, ImVec2 centre, ImVec2 max, bool isForegroun DrawPauseContainer(g_upWindow.get(), _min, _max, alpha); - drawList->PushClipRect(_min, _max); + if (containerMotion >= 1.0f && !g_isClosing) + { + drawList->PushClipRect(_min, _max); + return true; + } - return containerMotion >= 1.0f && !g_isClosing; + return false; } void DrawButton(int rowIndex, float yOffset, float width, float height, std::string& text)