add server messages (with toasts!)
This commit is contained in:
+11
-1
@@ -134,14 +134,22 @@ private:
|
||||
application_launcher,
|
||||
};
|
||||
|
||||
struct gui_toast
|
||||
{
|
||||
std::string current_toast;
|
||||
bool is_urgent = false;
|
||||
};
|
||||
|
||||
bool is_gui_interactable() const;
|
||||
|
||||
std::atomic<gui_status> gui_status = gui_status::hidden;
|
||||
enum gui_status last_gui_status = gui_status::hidden;
|
||||
enum gui_status next_gui_status = gui_status::applications;
|
||||
XrTime gui_status_last_change;
|
||||
float dimming = 0;
|
||||
|
||||
thread_safe<std::optional<gui_toast>> gui_toast;
|
||||
std::atomic<XrTime> gui_status_last_change;
|
||||
|
||||
XrAction plots_toggle_1 = XR_NULL_HANDLE;
|
||||
XrAction plots_toggle_2 = XR_NULL_HANDLE;
|
||||
XrAction recenter_left = XR_NULL_HANDLE;
|
||||
@@ -198,6 +206,7 @@ public:
|
||||
void operator()(to_headset::pin_check_2 &&) {};
|
||||
void operator()(to_headset::pin_check_4 &&) {};
|
||||
void operator()(to_headset::handshake &&) {};
|
||||
void operator()(to_headset::server_message &&);
|
||||
void operator()(to_headset::video_stream_data_shard &&);
|
||||
void operator()(to_headset::haptics &&);
|
||||
void operator()(to_headset::timesync_query &&);
|
||||
@@ -312,6 +321,7 @@ private:
|
||||
void gui_bitrate_settings(float predicted_display_period);
|
||||
void gui_foveation_settings(float predicted_display_period);
|
||||
void gui_applications();
|
||||
void gui_toasts();
|
||||
void draw_gui(XrTime predicted_display_time, XrDuration predicted_display_period);
|
||||
};
|
||||
} // namespace scenes
|
||||
|
||||
@@ -729,6 +729,19 @@ void scenes::stream::gui_applications()
|
||||
ImGui::PopStyleVar(3);
|
||||
}
|
||||
|
||||
void scenes::stream::gui_toasts()
|
||||
{
|
||||
auto toast = gui_toast.lock();
|
||||
|
||||
if (!toast->has_value())
|
||||
{
|
||||
ImGui::Text("%s", _S("Press both thumbsticks to display the WiVRn window"));
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::Text("%s", (*toast)->current_toast.c_str());
|
||||
}
|
||||
|
||||
void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicted_display_period)
|
||||
{
|
||||
if (not(plots_toggle_1 and plots_toggle_2))
|
||||
@@ -788,14 +801,23 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
}
|
||||
|
||||
float alpha = 1;
|
||||
bool is_urgent = false;
|
||||
if (gui_status == gui_status::hidden)
|
||||
{
|
||||
float t = (predicted_display_time - gui_status_last_change) * 1.e-9f;
|
||||
auto toast = gui_toast.lock();
|
||||
if (toast->has_value())
|
||||
is_urgent = (*toast)->is_urgent;
|
||||
|
||||
alpha = std::clamp<float>(1 - (t - constants::stream::fade_delay) / constants::stream::fade_duration, 0, 1);
|
||||
float t = (predicted_display_time - gui_status_last_change) * 1.e-9f;
|
||||
float delay = is_urgent ? constants::stream::urgent_fade_delay : constants::stream::fade_delay;
|
||||
|
||||
alpha = std::clamp<float>(1 - (t - delay) / constants::stream::fade_duration, 0, 1);
|
||||
|
||||
if (alpha == 0)
|
||||
{
|
||||
toast->reset();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Lock the GUI position to the head, do it before displaying the GUI to avoid being off by one frame when gui_status changes
|
||||
@@ -879,6 +901,12 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_urgent)
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, constants::stream::urgent_border_color);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 4);
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0);
|
||||
if (always_auto_resize)
|
||||
{
|
||||
@@ -891,13 +919,19 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
ImGui::Begin("Stream settings", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
|
||||
}
|
||||
|
||||
if (is_urgent)
|
||||
{
|
||||
ImGui::PopStyleColor(1);
|
||||
ImGui::PopStyleVar(1);
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {8, 8});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10);
|
||||
|
||||
switch (gui_status)
|
||||
{
|
||||
case gui_status::hidden:
|
||||
ImGui::Text("%s", _S("Press both thumbsticks to display the WiVRn window"));
|
||||
gui_toasts();
|
||||
break;
|
||||
|
||||
case gui_status::overlay_only:
|
||||
|
||||
@@ -47,6 +47,20 @@ void scenes::stream::process_packets()
|
||||
}
|
||||
}
|
||||
|
||||
void scenes::stream::operator()(to_headset::server_message && message)
|
||||
{
|
||||
switch (message.kind)
|
||||
{
|
||||
case to_headset::server_message::kind::stream_toast:
|
||||
case to_headset::server_message::kind::stream_toast_urgent:
|
||||
auto toast = gui_toast.lock();
|
||||
toast->emplace(message.msg, message.kind == to_headset::server_message::kind::stream_toast_urgent);
|
||||
|
||||
gui_status_last_change = instance.now();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void scenes::stream::operator()(to_headset::video_stream_data_shard && shard)
|
||||
{
|
||||
std::shared_lock lock(decoder_mutex);
|
||||
|
||||
Reference in New Issue
Block a user