Dim rounded windows correctly
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -934,6 +934,28 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> 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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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}, {});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user