diff --git a/client/constants.h b/client/constants.h index cabd43c6..dd591198 100644 --- a/client/constants.h +++ b/client/constants.h @@ -71,9 +71,6 @@ constexpr glm::vec3 popup_position = {0, 0, 0.05}; // world-space offset of a hover tooltip layer from the hovered item constexpr glm::vec3 tooltip_distance = {0, 0.004, 0.005}; -// scale/bias dimming the main GUI panel behind a popup -constexpr XrColor4f popup_dimming_scale = {0.5, 0.5, 0.5, 1}; -constexpr XrColor4f popup_dimming_bias = {0.25, 0.25, 0.25, 0}; } // namespace constants::gui namespace constants::lobby diff --git a/client/render/imgui_impl.cpp b/client/render/imgui_impl.cpp index 23cba1c8..7c772653 100644 --- a/client/render/imgui_impl.cpp +++ b/client/render/imgui_impl.cpp @@ -934,6 +934,28 @@ std::vector> imgui_context::end_frame() } } + if (auto modal_popup = ImGui::GetTopMostAndVisiblePopupModal(); modal_popup != nullptr) + { + ImDrawList * draw_list = ImGui::GetForegroundDrawList(); + for (ImGuiWindow * window: context->Windows) + { + if (window == modal_popup or window->ParentWindow != nullptr or not window->Active or window->Hidden or window->IsFallbackWindow) + continue; + + static const auto virtual_keyboard_id = ImHashStr("VirtualKeyboard"); + if (window->ID == virtual_keyboard_id) + continue; + + ImRect window_rect{ + window->Pos.x, + window->Pos.y, + window->Pos.x + window->Size.x, + window->Pos.y + window->Size.y}; + + draw_list->AddRectFilled(window_rect.Min, window_rect.Max, ImGui::ColorConvertFloat4ToU32(wivrn::ui::current().dimming), window->WindowRounding); + } + } + ImGui::Render(); current_command_buffer = (current_command_buffer + 1) % command_buffers.size(); diff --git a/client/render/ui_theme.cpp b/client/render/ui_theme.cpp index 77d92737..b39c95e7 100644 --- a/client/render/ui_theme.cpp +++ b/client/render/ui_theme.cpp @@ -53,6 +53,8 @@ static theme dark_default() t.success = rgb(52, 199, 123); t.warning = rgb(249, 115, 6); + t.dimming = rgb(128, 128, 128, 0.5f); + t.rounding = 8; t.card_rounding = 14; t.border_size = 1; diff --git a/client/render/ui_theme.h b/client/render/ui_theme.h index 52802f3b..41e598bd 100644 --- a/client/render/ui_theme.h +++ b/client/render/ui_theme.h @@ -55,6 +55,9 @@ struct theme ImVec4 success; ImVec4 warning; + // Dimming when a modal popup is visible + ImVec4 dimming; + // Shape, in pixels float rounding; // buttons, inputs, sliders float card_rounding; // cards diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index cdd500ec..c37191a5 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -1063,20 +1063,14 @@ void scenes::lobby::render(const XrFrameState & frame_state) if (composition_layer_depth_test_supported) set_depth_test(true, XR_COMPARE_OP_ALWAYS_FB); - bool dim_gui = imgui_ctx->is_modal_popup_shown() and composition_layer_color_scale_bias_supported; for (auto & [z_index, layer]: imgui_layers) { if (z_index < constants::lobby::zindex_recenter_tip) { add_quad_layer(layer.layerFlags, layer.space, layer.eyeVisibility, layer.subImage, layer.pose, layer.size); - if (dim_gui) - set_color_scale_bias(constants::gui::popup_dimming_scale, constants::gui::popup_dimming_bias); - if (composition_layer_depth_test_supported) set_depth_test(true, XR_COMPARE_OP_LESS_OR_EQUAL_FB); - - dim_gui = false; // Only dim the main window } } diff --git a/client/scenes/stream_gui.cpp b/client/scenes/stream_gui.cpp index 95c441ef..9d404498 100644 --- a/client/scenes/stream_gui.cpp +++ b/client/scenes/stream_gui.cpp @@ -1076,18 +1076,12 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte } } - // add the GUI layers, dim the main panel behind a modal popup, popup quad stays bright - bool dim_main = imgui_ctx->is_modal_popup_shown() and composition_layer_color_scale_bias_supported; for (auto [_, layer]: layers) { add_quad_layer(layer.layerFlags, layer.space, layer.eyeVisibility, layer.subImage, layer.pose, layer.size); if (composition_layer_depth_test_supported) set_depth_test(true, XR_COMPARE_OP_LESS_FB); - if (dim_main) - { - set_color_scale_bias(constants::gui::popup_dimming_scale, constants::gui::popup_dimming_bias); - dim_main = false; // only the main window dims, not the popup - } + else if (alpha < 1 and composition_layer_color_scale_bias_supported) set_color_scale_bias({alpha, alpha, alpha, alpha}, {}); }