From b04578afeeff3371e49f766973fa0a1840e1a9f9 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 14 Dec 2023 23:55:44 +1000 Subject: [PATCH] ImGuiFullscreen: Fix menu background obscuring text --- src/util/imgui_fullscreen.cpp | 36 ++++++++++++++++++++++++--- src/util/imgui_fullscreen.h | 1 + src/util/postprocessing_shader_fx.cpp | 1 + 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/util/imgui_fullscreen.cpp b/src/util/imgui_fullscreen.cpp index 547f575ba..047d01456 100644 --- a/src/util/imgui_fullscreen.cpp +++ b/src/util/imgui_fullscreen.cpp @@ -39,7 +39,7 @@ Log_SetChannel(ImGuiFullscreen); namespace ImGuiFullscreen { using MessageDialogCallbackVariant = std::variant; -static constexpr float MENU_BACKGROUND_ANIMATION_TIME = 0.25f; +static constexpr float MENU_BACKGROUND_ANIMATION_TIME = 0.5f; static std::optional LoadTextureImage(const char* path); static std::shared_ptr UploadTexture(const char* path, const Common::RGBA8Image& image); @@ -124,6 +124,7 @@ static ImAnimatedVec2 s_menu_button_frame_min_animated; static ImAnimatedVec2 s_menu_button_frame_max_animated; static bool s_had_hovered_menu_item = false; static bool s_has_hovered_menu_item = false; +static bool s_rendered_menu_item_border = false; namespace { struct FileSelectorItem @@ -492,6 +493,7 @@ void ImGuiFullscreen::EndLayout() PopResetLayout(); + s_rendered_menu_item_border = false; s_had_hovered_menu_item = std::exchange(s_has_hovered_menu_item, false); } @@ -685,6 +687,26 @@ void ImGuiFullscreen::EndFullscreenWindow() ImGui::PopStyleColor(); } +void ImGuiFullscreen::PrerenderMenuButtonBorder() +{ + if (!s_had_hovered_menu_item) + return; + + // updating might finish the animation + const ImVec2 min = s_menu_button_frame_min_animated.UpdateAndGetValue(); + const ImVec2 max = s_menu_button_frame_max_animated.UpdateAndGetValue(); + const ImU32 col = ImGui::GetColorU32(ImGuiCol_ButtonHovered); + + const float t = static_cast(std::min(std::abs(std::sin(ImGui::GetTime() * 0.75) * 1.1), 1.0)); + ImGui::PushStyleColor(ImGuiCol_Border, ImGui::GetColorU32(ImGuiCol_Border, t)); + + ImGui::RenderFrame(min, max, col, true, 0.0f); + + ImGui::PopStyleColor(); + + s_rendered_menu_item_border = true; +} + void ImGuiFullscreen::BeginMenuButtons(u32 num_items, float y_align, float x_padding, float y_padding, float item_height) { @@ -703,6 +725,8 @@ void ImGuiFullscreen::BeginMenuButtons(u32 num_items, float y_align, float x_pad if (window_height > total_size) ImGui::SetCursorPosY((window_height - total_size) * y_align); } + + PrerenderMenuButtonBorder(); } void ImGuiFullscreen::EndMenuButtons() @@ -814,7 +838,7 @@ void ImGuiFullscreen::DrawMenuButtonFrame(const ImVec2& p_min, const ImVec2& p_m ImVec2 frame_min = p_min; ImVec2 frame_max = p_max; - if (ImGui::GetIO().NavVisible) + if (ImGui::GetIO().NavVisible && ImGui::GetHoveredID() != ImGui::GetItemID()) { if (!s_had_hovered_menu_item) { @@ -842,7 +866,11 @@ void ImGuiFullscreen::DrawMenuButtonFrame(const ImVec2& p_min, const ImVec2& p_m } } - ImGui::RenderFrame(frame_min, frame_max, fill_col, border, rounding); + if (!s_rendered_menu_item_border) + { + s_rendered_menu_item_border = true; + ImGui::RenderFrame(frame_min, frame_max, fill_col, border, rounding); + } } bool ImGuiFullscreen::MenuButtonFrame(const char* str_id, bool enabled, float height, bool* visible, bool* hovered, @@ -934,7 +962,7 @@ bool ImGuiFullscreen::ActiveButton(const char* title, bool is_active, bool enabl { ImVec2 pos, size; GetMenuButtonFrameBounds(height, &pos, &size); - DrawMenuButtonFrame(pos, pos + size, ImGui::GetColorU32(UIPrimaryColor), false); + ImGui::RenderFrame(pos, pos + size, ImGui::GetColorU32(UIPrimaryColor), false); } ImRect bb; diff --git a/src/util/imgui_fullscreen.h b/src/util/imgui_fullscreen.h index b7863ca5a..57ed2ae2b 100644 --- a/src/util/imgui_fullscreen.h +++ b/src/util/imgui_fullscreen.h @@ -171,6 +171,7 @@ bool BeginFullscreenWindow(const ImVec2& position, const ImVec2& size, const cha float padding = 0.0f, ImGuiWindowFlags flags = 0); void EndFullscreenWindow(); +void PrerenderMenuButtonBorder(); void BeginMenuButtons(u32 num_items = 0, float y_align = 0.0f, float x_padding = LAYOUT_MENU_BUTTON_X_PADDING, float y_padding = LAYOUT_MENU_BUTTON_Y_PADDING, float item_height = LAYOUT_MENU_BUTTON_HEIGHT); void EndMenuButtons(); diff --git a/src/util/postprocessing_shader_fx.cpp b/src/util/postprocessing_shader_fx.cpp index fb00f4f6c..73701ce4d 100644 --- a/src/util/postprocessing_shader_fx.cpp +++ b/src/util/postprocessing_shader_fx.cpp @@ -316,6 +316,7 @@ bool PostProcessing::ReShadeFXShader::LoadFromString(std::string name, std::stri if (!CreateOptions(temp_module, error)) return false; + // check limits if (!temp_module.techniques.empty()) { bool has_passes = false;