From 3ff1ea33cfb67f72c9bb6822b30cb2c0fd22c023 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 31 Dec 2025 14:30:22 +1000 Subject: [PATCH] ImGuiManager: Extract out gradient rect function --- src/core/fullscreenui_widgets.cpp | 10 ++++++++++ src/core/fullscreenui_widgets.h | 3 +++ src/util/imgui_manager.cpp | 21 ++++++++------------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/core/fullscreenui_widgets.cpp b/src/core/fullscreenui_widgets.cpp index 36a2d6383..f5fa3e864 100644 --- a/src/core/fullscreenui_widgets.cpp +++ b/src/core/fullscreenui_widgets.cpp @@ -1317,6 +1317,16 @@ void FullscreenUI::PopPrimaryColor() ImGui::PopStyleColor(5); } +void FullscreenUI::DrawRoundedGradientRect(ImDrawList* const dl, const ImVec2& pos_min, const ImVec2& pos_max, + ImU32 col_left, ImU32 col_right, float rounding) +{ + dl->AddRectFilled(pos_min, ImVec2(pos_min.x + rounding, pos_max.y), col_left, rounding, ImDrawFlags_RoundCornersLeft); + dl->AddRectFilledMultiColor(ImVec2(pos_min.x + rounding, pos_min.y), ImVec2(pos_max.x - rounding, pos_max.y), + col_left, col_right, col_right, col_left); + dl->AddRectFilled(ImVec2(pos_max.x - rounding, pos_min.y), pos_max, col_right, rounding, + ImDrawFlags_RoundCornersRight); +} + bool FullscreenUI::BeginFullscreenColumns(const char* title, float pos_y, bool expand_to_screen_width, bool footer) { ImGui::SetNextWindowPos(ImVec2(expand_to_screen_width ? 0.0f : UIStyle.LayoutPaddingLeft, pos_y)); diff --git a/src/core/fullscreenui_widgets.h b/src/core/fullscreenui_widgets.h index 25c938b21..eea75d56b 100644 --- a/src/core/fullscreenui_widgets.h +++ b/src/core/fullscreenui_widgets.h @@ -308,6 +308,9 @@ void CancelPendingMenuClose(); void PushPrimaryColor(); void PopPrimaryColor(); +void DrawRoundedGradientRect(ImDrawList* const dl, const ImVec2& pos_min, const ImVec2& pos_max, ImU32 col_left, + ImU32 col_right, float rounding); + void DrawWindowTitle(std::string_view title); bool BeginFullscreenColumns(const char* title = nullptr, float pos_y = 0.0f, bool expand_to_screen_width = false, diff --git a/src/util/imgui_manager.cpp b/src/util/imgui_manager.cpp index 07425aa81..99450b214 100644 --- a/src/util/imgui_manager.cpp +++ b/src/util/imgui_manager.cpp @@ -958,6 +958,7 @@ void ImGuiManager::AcquirePendingOSDMessages(Timer::Value current_time) void ImGuiManager::DrawOSDMessages(Timer::Value current_time) { using FullscreenUI::DarkerColor; + using FullscreenUI::DrawRoundedGradientRect; using FullscreenUI::ModAlpha; using FullscreenUI::RenderShadowedTextClipped; using FullscreenUI::UIStyle; @@ -1105,19 +1106,13 @@ void ImGuiManager::DrawOSDMessages(Timer::Value current_time) ImDrawList* const dl = ImGui::GetForegroundDrawList(); const float background_opacity = opacity * 0.95f; - const u32 left_background_color32 = ImGui::GetColorU32(ModAlpha(left_background_color, background_opacity)); - const u32 right_background_color32 = ImGui::GetColorU32( - ModAlpha(ImLerp(left_background_color, right_background_color, - std::min((box_width - min_rounded_width) / (max_width_for_color - min_rounded_width), 1.0f)), - background_opacity)); - - dl->AddRectFilled(pos, ImVec2(pos.x + rounding, pos_max.y), left_background_color32, rounding, - ImDrawFlags_RoundCornersLeft); - dl->AddRectFilledMultiColor(ImVec2(pos.x + rounding, pos.y), ImVec2(pos_max.x - rounding, pos_max.y), - left_background_color32, right_background_color32, right_background_color32, - left_background_color32); - dl->AddRectFilled(ImVec2(pos_max.x - rounding, pos.y), pos_max, right_background_color32, rounding, - ImDrawFlags_RoundCornersRight); + DrawRoundedGradientRect( + dl, pos, pos_max, ImGui::GetColorU32(ModAlpha(left_background_color, background_opacity)), + ImGui::GetColorU32( + ModAlpha(ImLerp(left_background_color, right_background_color, + std::min((box_width - min_rounded_width) / (max_width_for_color - min_rounded_width), 1.0f)), + background_opacity)), + rounding); const ImVec2 base_pos = ImVec2(pos.x + padding, pos.y + padding); const ImU32 color = ImGui::GetColorU32(ModAlpha(text_color, opacity));