Move app launcher out of lobby_gui
This commit is contained in:
+112
-32
@@ -16,6 +16,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
#include "imgui_impl.h"
|
#include "imgui_impl.h"
|
||||||
#include "implot.h"
|
#include "implot.h"
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@
|
|||||||
#include "image_loader.h"
|
#include "image_loader.h"
|
||||||
#include "openxr/openxr.h"
|
#include "openxr/openxr.h"
|
||||||
#include "utils/ranges.h"
|
#include "utils/ranges.h"
|
||||||
|
#include "utils/strings.h"
|
||||||
#include "vulkan/vulkan_enums.hpp"
|
#include "vulkan/vulkan_enums.hpp"
|
||||||
#include "vulkan/vulkan_handles.hpp"
|
#include "vulkan/vulkan_handles.hpp"
|
||||||
#include "vulkan/vulkan_to_string.hpp"
|
#include "vulkan/vulkan_to_string.hpp"
|
||||||
@@ -43,8 +45,6 @@
|
|||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
#include "IconsFontAwesome6.h"
|
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
#include <android/font.h>
|
#include <android/font.h>
|
||||||
#include <android/font_matcher.h>
|
#include <android/font_matcher.h>
|
||||||
@@ -178,6 +178,31 @@ static float distance_to_window(ImGuiWindow * window, ImVec2 position)
|
|||||||
return std::hypot(dx, dy);
|
return std::hypot(dx, dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const std::array layout_bindings = {
|
||||||
|
vk::DescriptorSetLayoutBinding{
|
||||||
|
.binding = 0,
|
||||||
|
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||||
|
.descriptorCount = 1,
|
||||||
|
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||||
|
}};
|
||||||
|
|
||||||
|
imgui_textures::imgui_textures(
|
||||||
|
vk::raii::PhysicalDevice physical_device,
|
||||||
|
vk::raii::Device & device,
|
||||||
|
uint32_t queue_family_index,
|
||||||
|
thread_safe<vk::raii::Queue> & queue) :
|
||||||
|
physical_device(physical_device),
|
||||||
|
device(device),
|
||||||
|
queue(queue),
|
||||||
|
ds_layout(device, vk::DescriptorSetLayoutCreateInfo{.bindingCount = layout_bindings.size(), .pBindings = layout_bindings.data()}),
|
||||||
|
command_pool(device,
|
||||||
|
vk::CommandPoolCreateInfo{
|
||||||
|
.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer | vk::CommandPoolCreateFlagBits::eTransient,
|
||||||
|
.queueFamilyIndex = queue_family_index,
|
||||||
|
}),
|
||||||
|
descriptor_pool(device, ds_layout, layout_bindings)
|
||||||
|
{}
|
||||||
|
|
||||||
std::vector<std::pair<ImVec2, float>> imgui_context::ray_plane_intersection(const imgui_context::controller_state & in) const
|
std::vector<std::pair<ImVec2, float>> imgui_context::ray_plane_intersection(const imgui_context::controller_state & in) const
|
||||||
{
|
{
|
||||||
if (!in.active)
|
if (!in.active)
|
||||||
@@ -289,14 +314,6 @@ imgui_context::imgui_frame & imgui_context::get_frame(vk::Image destination)
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::array layout_bindings = {
|
|
||||||
vk::DescriptorSetLayoutBinding{
|
|
||||||
.binding = 0,
|
|
||||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
|
||||||
.descriptorCount = 1,
|
|
||||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
|
||||||
}};
|
|
||||||
|
|
||||||
imgui_context::imgui_context(
|
imgui_context::imgui_context(
|
||||||
vk::raii::PhysicalDevice physical_device,
|
vk::raii::PhysicalDevice physical_device,
|
||||||
vk::raii::Device & device,
|
vk::raii::Device & device,
|
||||||
@@ -305,18 +322,13 @@ imgui_context::imgui_context(
|
|||||||
std::span<controller> controllers_,
|
std::span<controller> controllers_,
|
||||||
xr::swapchain & swapchain,
|
xr::swapchain & swapchain,
|
||||||
std::vector<viewport> layers) :
|
std::vector<viewport> layers) :
|
||||||
physical_device(physical_device),
|
imgui_textures(
|
||||||
device(device),
|
physical_device,
|
||||||
|
device,
|
||||||
|
queue_family_index,
|
||||||
|
queue),
|
||||||
queue_family_index(queue_family_index),
|
queue_family_index(queue_family_index),
|
||||||
queue(queue),
|
|
||||||
ds_layout(device, vk::DescriptorSetLayoutCreateInfo{.bindingCount = layout_bindings.size(), .pBindings = layout_bindings.data()}),
|
|
||||||
descriptor_pool(device, ds_layout, layout_bindings),
|
|
||||||
renderpass(create_renderpass(device, swapchain.format(), true)),
|
renderpass(create_renderpass(device, swapchain.format(), true)),
|
||||||
command_pool(device,
|
|
||||||
vk::CommandPoolCreateInfo{
|
|
||||||
.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer | vk::CommandPoolCreateFlagBits::eTransient,
|
|
||||||
.queueFamilyIndex = queue_family_index,
|
|
||||||
}),
|
|
||||||
command_buffers(swapchain.images().size()),
|
command_buffers(swapchain.images().size()),
|
||||||
size(swapchain.extent().width, swapchain.extent().height),
|
size(swapchain.extent().width, swapchain.extent().height),
|
||||||
format(swapchain.format()),
|
format(swapchain.format()),
|
||||||
@@ -1020,12 +1032,12 @@ imgui_context::~imgui_context()
|
|||||||
ImGui::DestroyContext(context);
|
ImGui::DestroyContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImTextureID imgui_context::load_texture(const std::string & filename, vk::raii::Sampler && sampler)
|
ImTextureID imgui_textures::load_texture(const std::string & filename, vk::raii::Sampler && sampler)
|
||||||
{
|
{
|
||||||
return load_texture(std::span<const std::byte>{asset{filename}}, std::move(sampler));
|
return load_texture(std::span<const std::byte>{asset{filename}}, std::move(sampler));
|
||||||
}
|
}
|
||||||
|
|
||||||
ImTextureID imgui_context::load_texture(const std::span<const std::byte> & bytes, vk::raii::Sampler && sampler)
|
ImTextureID imgui_textures::load_texture(const std::span<const std::byte> & bytes, vk::raii::Sampler && sampler)
|
||||||
{
|
{
|
||||||
bool srgb = true;
|
bool srgb = true;
|
||||||
image_loader loader(physical_device, device, queue, command_pool);
|
image_loader loader(physical_device, device, queue, command_pool);
|
||||||
@@ -1061,7 +1073,7 @@ ImTextureID imgui_context::load_texture(const std::span<const std::byte> & bytes
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImTextureID imgui_context::load_texture(const std::span<const std::byte> & bytes)
|
ImTextureID imgui_textures::load_texture(const std::span<const std::byte> & bytes)
|
||||||
{
|
{
|
||||||
return load_texture(
|
return load_texture(
|
||||||
bytes,
|
bytes,
|
||||||
@@ -1079,7 +1091,7 @@ ImTextureID imgui_context::load_texture(const std::span<const std::byte> & bytes
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ImTextureID imgui_context::load_texture(const std::string & filename)
|
ImTextureID imgui_textures::load_texture(const std::string & filename)
|
||||||
{
|
{
|
||||||
return load_texture(
|
return load_texture(
|
||||||
filename,
|
filename,
|
||||||
@@ -1097,15 +1109,8 @@ ImTextureID imgui_context::load_texture(const std::string & filename)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void imgui_context::free_texture(ImTextureID texture)
|
void imgui_textures::free_texture(ImTextureID texture)
|
||||||
{
|
{
|
||||||
// Make sure we are done using the texture
|
|
||||||
std::vector<vk::Fence> fences;
|
|
||||||
for (auto & f: command_buffers)
|
|
||||||
fences.push_back(*f.fence);
|
|
||||||
if (auto result = device.waitForFences(fences, true, 1'000'000'000); result != vk::Result::eSuccess)
|
|
||||||
spdlog::error("vkWaitForfences: {}", vk::to_string(result));
|
|
||||||
|
|
||||||
textures.erase(texture);
|
textures.erase(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1182,3 +1187,78 @@ void imgui_context::tooltip(std::string_view text)
|
|||||||
viewport->Pos = pos_backup;
|
viewport->Pos = pos_backup;
|
||||||
viewport->Size = size_backup;
|
viewport->Size = size_backup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/ocornut/imgui/issues/3379#issuecomment-2943903877
|
||||||
|
void ScrollWhenDragging()
|
||||||
|
{
|
||||||
|
ImVec2 delta{0.0f, -ImGui::GetIO().MouseDelta.y};
|
||||||
|
const ImGuiMouseButton mouse_button = ImGuiMouseButton_Left;
|
||||||
|
|
||||||
|
ImGuiContext & g = *ImGui::GetCurrentContext();
|
||||||
|
ImGuiWindow * window = g.CurrentWindow;
|
||||||
|
ImGuiID id = window->GetID("##scrolldraggingoverlay");
|
||||||
|
ImGui::KeepAliveID(id);
|
||||||
|
|
||||||
|
static int active_id;
|
||||||
|
static ImVec2 cumulated_delta;
|
||||||
|
|
||||||
|
bool HoveredIdAllowOverlap_backup = std::exchange(g.HoveredIdAllowOverlap, true);
|
||||||
|
bool ActiveIdAllowOverlap_backup = std::exchange(g.ActiveIdAllowOverlap, true);
|
||||||
|
if (active_id == 0 and ImGui::ItemHoverable(window->Rect(), 0, g.CurrentItemFlags) and ImGui::IsMouseClicked(mouse_button, ImGuiInputFlags_None, /*id*/ ImGuiKeyOwner_Any))
|
||||||
|
{
|
||||||
|
active_id = id;
|
||||||
|
|
||||||
|
// Don't scroll on the first step, in case the active controller just changed
|
||||||
|
delta = {};
|
||||||
|
cumulated_delta = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not g.IO.MouseDown[mouse_button])
|
||||||
|
active_id = 0;
|
||||||
|
|
||||||
|
if (active_id == id)
|
||||||
|
{
|
||||||
|
if (delta.x != 0.0f)
|
||||||
|
ImGui::SetScrollX(window, window->Scroll.x + delta.x);
|
||||||
|
if (delta.y != 0.0f)
|
||||||
|
ImGui::SetScrollY(window, window->Scroll.y + delta.y);
|
||||||
|
|
||||||
|
cumulated_delta += delta;
|
||||||
|
if (std::max(std::abs(cumulated_delta.x), std::abs(cumulated_delta.y)) > 50)
|
||||||
|
ImGui::ClearActiveID();
|
||||||
|
}
|
||||||
|
|
||||||
|
g.HoveredIdAllowOverlap = HoveredIdAllowOverlap_backup;
|
||||||
|
g.ActiveIdAllowOverlap = ActiveIdAllowOverlap_backup;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CenterTextH(const std::string & text)
|
||||||
|
{
|
||||||
|
float win_width = ImGui::GetWindowSize().x;
|
||||||
|
float text_width = ImGui::CalcTextSize(text.c_str()).x;
|
||||||
|
ImGui::SetCursorPosX((win_width - text_width) / 2);
|
||||||
|
|
||||||
|
ImGui::Text("%s", text.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CenterTextHV(const std::string & text)
|
||||||
|
{
|
||||||
|
ImVec2 size = ImGui::GetWindowSize();
|
||||||
|
|
||||||
|
std::vector<std::string> lines = utils::split(text);
|
||||||
|
|
||||||
|
float text_height = 0;
|
||||||
|
for (const auto & i: lines)
|
||||||
|
text_height += ImGui::CalcTextSize(i.c_str()).y;
|
||||||
|
|
||||||
|
ImGui::SetCursorPosY((size.y - text_height) / 2);
|
||||||
|
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {0, 0});
|
||||||
|
for (const auto & i: lines)
|
||||||
|
{
|
||||||
|
float text_width = ImGui::CalcTextSize(i.c_str()).x;
|
||||||
|
ImGui::SetCursorPosX((size.x - text_width) / 2);
|
||||||
|
ImGui::Text("%s", i.c_str());
|
||||||
|
}
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
}
|
||||||
|
|||||||
+37
-20
@@ -36,14 +36,8 @@
|
|||||||
#include <vulkan/vulkan_raii.hpp>
|
#include <vulkan/vulkan_raii.hpp>
|
||||||
#include <openxr/openxr.h>
|
#include <openxr/openxr.h>
|
||||||
|
|
||||||
class imgui_context
|
class imgui_textures
|
||||||
{
|
{
|
||||||
struct command_buffer
|
|
||||||
{
|
|
||||||
vk::raii::CommandBuffer command_buffer = nullptr;
|
|
||||||
vk::raii::Fence fence = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct texture_data
|
struct texture_data
|
||||||
{
|
{
|
||||||
vk::raii::Sampler sampler;
|
vk::raii::Sampler sampler;
|
||||||
@@ -51,6 +45,38 @@ class imgui_context
|
|||||||
std::shared_ptr<vk::raii::DescriptorSet> descriptor_set;
|
std::shared_ptr<vk::raii::DescriptorSet> descriptor_set;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
vk::raii::PhysicalDevice physical_device;
|
||||||
|
vk::raii::Device & device;
|
||||||
|
thread_safe<vk::raii::Queue> & queue;
|
||||||
|
vk::raii::DescriptorSetLayout ds_layout;
|
||||||
|
vk::raii::CommandPool command_pool;
|
||||||
|
|
||||||
|
private:
|
||||||
|
growable_descriptor_pool descriptor_pool;
|
||||||
|
std::unordered_map<ImTextureID, texture_data> textures;
|
||||||
|
|
||||||
|
public:
|
||||||
|
imgui_textures(
|
||||||
|
vk::raii::PhysicalDevice physical_device,
|
||||||
|
vk::raii::Device & device,
|
||||||
|
uint32_t queue_family_index,
|
||||||
|
thread_safe<vk::raii::Queue> & queue);
|
||||||
|
ImTextureID load_texture(const std::string & filename, vk::raii::Sampler && sampler);
|
||||||
|
ImTextureID load_texture(const std::string & filename);
|
||||||
|
ImTextureID load_texture(const std::span<const std::byte> & bytes, vk::raii::Sampler && sampler);
|
||||||
|
ImTextureID load_texture(const std::span<const std::byte> & bytes);
|
||||||
|
void free_texture(ImTextureID);
|
||||||
|
};
|
||||||
|
|
||||||
|
class imgui_context : public imgui_textures
|
||||||
|
{
|
||||||
|
struct command_buffer
|
||||||
|
{
|
||||||
|
vk::raii::CommandBuffer command_buffer = nullptr;
|
||||||
|
vk::raii::Fence fence = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct imgui_frame
|
struct imgui_frame
|
||||||
{
|
{
|
||||||
@@ -117,18 +143,10 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vk::raii::PhysicalDevice physical_device;
|
|
||||||
vk::raii::Device & device;
|
|
||||||
uint32_t queue_family_index;
|
uint32_t queue_family_index;
|
||||||
thread_safe<vk::raii::Queue> & queue;
|
|
||||||
|
|
||||||
vk::raii::Pipeline pipeline = nullptr;
|
vk::raii::Pipeline pipeline = nullptr;
|
||||||
vk::raii::DescriptorSetLayout ds_layout;
|
|
||||||
growable_descriptor_pool descriptor_pool;
|
|
||||||
vk::raii::RenderPass renderpass;
|
vk::raii::RenderPass renderpass;
|
||||||
vk::raii::CommandPool command_pool;
|
|
||||||
|
|
||||||
std::unordered_map<ImTextureID, texture_data> textures;
|
|
||||||
|
|
||||||
std::vector<imgui_frame> frames;
|
std::vector<imgui_frame> frames;
|
||||||
imgui_frame & get_frame(vk::Image destination);
|
imgui_frame & get_frame(vk::Image destination);
|
||||||
@@ -207,11 +225,6 @@ public:
|
|||||||
// Convert position from viewport coordinates to real-world
|
// Convert position from viewport coordinates to real-world
|
||||||
glm::vec3 rw_from_vp(const ImVec2 & position);
|
glm::vec3 rw_from_vp(const ImVec2 & position);
|
||||||
|
|
||||||
ImTextureID load_texture(const std::string & filename, vk::raii::Sampler && sampler);
|
|
||||||
ImTextureID load_texture(const std::string & filename);
|
|
||||||
ImTextureID load_texture(const std::span<const std::byte> & bytes, vk::raii::Sampler && sampler);
|
|
||||||
ImTextureID load_texture(const std::span<const std::byte> & bytes);
|
|
||||||
void free_texture(ImTextureID);
|
|
||||||
void set_current();
|
void set_current();
|
||||||
|
|
||||||
bool is_modal_popup_shown() const;
|
bool is_modal_popup_shown() const;
|
||||||
@@ -221,3 +234,7 @@ public:
|
|||||||
void set_controllers_enabled(bool value);
|
void set_controllers_enabled(bool value);
|
||||||
void tooltip(std::string_view text);
|
void tooltip(std::string_view text);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void ScrollWhenDragging();
|
||||||
|
void CenterTextH(const std::string & text);
|
||||||
|
void CenterTextHV(const std::string & text);
|
||||||
|
|||||||
+1
-1
@@ -47,8 +47,8 @@ scene::scene(key, const meta & current_meta, std::span<const vk::Format> support
|
|||||||
device(application::instance().vk_device),
|
device(application::instance().vk_device),
|
||||||
physical_device(application::instance().vk_physical_device),
|
physical_device(application::instance().vk_physical_device),
|
||||||
queue(application::instance().vk_queue),
|
queue(application::instance().vk_queue),
|
||||||
commandpool(application::instance().vk_cmdpool),
|
|
||||||
queue_family_index(application::instance().vk_queue_family_index),
|
queue_family_index(application::instance().vk_queue_family_index),
|
||||||
|
commandpool(application::instance().vk_cmdpool),
|
||||||
current_meta(current_meta)
|
current_meta(current_meta)
|
||||||
{
|
{
|
||||||
swapchain_format = vk::Format::eUndefined;
|
swapchain_format = vk::Format::eUndefined;
|
||||||
|
|||||||
+4
-1
@@ -86,13 +86,16 @@ protected:
|
|||||||
XrViewConfigurationType viewconfig;
|
XrViewConfigurationType viewconfig;
|
||||||
bool focused = false;
|
bool focused = false;
|
||||||
|
|
||||||
|
public:
|
||||||
vk::raii::Instance & vk_instance;
|
vk::raii::Instance & vk_instance;
|
||||||
vk::raii::Device & device;
|
vk::raii::Device & device;
|
||||||
vk::raii::PhysicalDevice & physical_device;
|
vk::raii::PhysicalDevice & physical_device;
|
||||||
thread_safe<vk::raii::Queue> & queue;
|
thread_safe<vk::raii::Queue> & queue;
|
||||||
vk::raii::CommandPool & commandpool;
|
|
||||||
uint32_t queue_family_index;
|
uint32_t queue_family_index;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
vk::raii::CommandPool & commandpool;
|
||||||
|
|
||||||
const meta & current_meta;
|
const meta & current_meta;
|
||||||
|
|
||||||
std::optional<scene_renderer> renderer;
|
std::optional<scene_renderer> renderer;
|
||||||
|
|||||||
@@ -0,0 +1,279 @@
|
|||||||
|
/*
|
||||||
|
* WiVRn VR streaming
|
||||||
|
* Copyright (C) 2025 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||||
|
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
#include "app_launcher.h"
|
||||||
|
|
||||||
|
#include "constants.h"
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_internal.h"
|
||||||
|
#include "scenes/stream.h"
|
||||||
|
#include "utils/i18n.h"
|
||||||
|
#include "utils/ranges.h"
|
||||||
|
|
||||||
|
#include <imspinner.h>
|
||||||
|
#include <spdlog/fmt/fmt.h>
|
||||||
|
#include <uni_algo/case.h>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
// Display a button with an image and a text centred horizontally
|
||||||
|
static bool icon(
|
||||||
|
const std::string & text,
|
||||||
|
ImTextureRef tex_ref,
|
||||||
|
const ImVec2 & image_size,
|
||||||
|
ImGuiButtonFlags flags = 0,
|
||||||
|
const ImVec2 & size_arg = ImVec2(0, 0),
|
||||||
|
const ImVec2 & uv0 = ImVec2(0, 0),
|
||||||
|
const ImVec2 & uv1 = ImVec2(1, 1),
|
||||||
|
const ImVec4 & tint_col = ImVec4(1, 1, 1, 1))
|
||||||
|
{
|
||||||
|
// Based on ImGui::ButtonEx and ImGui::ImageButtonEx
|
||||||
|
ImGuiWindow * window = ImGui::GetCurrentWindow();
|
||||||
|
const ImGuiStyle & style = ImGui::GetStyle();
|
||||||
|
|
||||||
|
if (window->SkipItems)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const ImVec2 label_size = ImGui::CalcTextSize(text.c_str(), nullptr, true);
|
||||||
|
|
||||||
|
ImVec2 size = ImGui::CalcItemSize(
|
||||||
|
size_arg,
|
||||||
|
std::max(image_size.x, label_size.x) + style.FramePadding.x * 2.0f,
|
||||||
|
image_size.y + style.ItemInnerSpacing.y + label_size.y + style.FramePadding.y * 2.0f);
|
||||||
|
|
||||||
|
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
|
||||||
|
|
||||||
|
ImRect image_pos(
|
||||||
|
{(bb.Min.x + bb.Max.x - image_size.x) / 2, bb.Min.y + style.FramePadding.y},
|
||||||
|
{(bb.Min.x + bb.Max.x + image_size.x) / 2, bb.Min.y + style.FramePadding.y + image_size.y});
|
||||||
|
|
||||||
|
ImRect label_pos(
|
||||||
|
{bb.Min.x + style.FramePadding.x, image_pos.Max.y + style.ItemInnerSpacing.y},
|
||||||
|
{bb.Max.x - style.FramePadding.x, bb.Max.y - style.FramePadding.y});
|
||||||
|
|
||||||
|
ImGui::ItemSize(bb);
|
||||||
|
|
||||||
|
ImGuiID id = window->GetID(text.c_str());
|
||||||
|
if (!ImGui::ItemAdd(bb, id))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool hovered, held;
|
||||||
|
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held, flags);
|
||||||
|
|
||||||
|
// Render
|
||||||
|
const ImU32 col = ImGui::GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered
|
||||||
|
: ImGuiCol_Button);
|
||||||
|
ImGui::RenderNavCursor(bb, id);
|
||||||
|
ImGui::RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
|
||||||
|
|
||||||
|
window->DrawList->AddImage(tex_ref, image_pos.Min, image_pos.Max, uv0, uv1, ImGui::GetColorU32(tint_col));
|
||||||
|
ImGui::RenderTextClipped(label_pos.Min, label_pos.Max, text.c_str(), NULL, &label_size, style.ButtonTextAlign, &bb);
|
||||||
|
|
||||||
|
return pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
app_launcher::app_launcher(
|
||||||
|
scenes::stream & stream,
|
||||||
|
std::string server_name) :
|
||||||
|
server_name(std::move(server_name)),
|
||||||
|
stream(stream),
|
||||||
|
textures(
|
||||||
|
stream.physical_device,
|
||||||
|
stream.device,
|
||||||
|
stream.queue_family_index,
|
||||||
|
stream.queue)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
default_icon = textures.load_texture("default_icon.ktx2");
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
default_icon = textures.load_texture("default_icon.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app_launcher::~app_launcher()
|
||||||
|
{
|
||||||
|
stream.device.waitIdle();
|
||||||
|
for (const auto & [app_id, app_icon]: app_icons)
|
||||||
|
textures.free_texture(app_icon);
|
||||||
|
textures.free_texture(default_icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
app_launcher::clicked app_launcher::draw_gui(imgui_context & imgui_ctx, const std::string & cancel)
|
||||||
|
{
|
||||||
|
auto res = clicked::None;
|
||||||
|
auto t0 = std::chrono::steady_clock::now();
|
||||||
|
bool app_starting = start_time != std::chrono::steady_clock::time_point{} and t0 - start_time < 10s;
|
||||||
|
|
||||||
|
auto cancel_size = ImGui::CalcTextSize(cancel.c_str());
|
||||||
|
|
||||||
|
auto apps = applications.lock();
|
||||||
|
|
||||||
|
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
||||||
|
if (server_name.empty())
|
||||||
|
CenterTextH(_("Connected to WiVRn server"));
|
||||||
|
else
|
||||||
|
CenterTextH(fmt::format(_F("Connected to {}"), server_name));
|
||||||
|
ImGui::PopFont();
|
||||||
|
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20});
|
||||||
|
if (apps->empty())
|
||||||
|
{
|
||||||
|
CenterTextHV(_("Start an application on the server to start streaming."));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 0});
|
||||||
|
ImGui::BeginDisabled(app_starting);
|
||||||
|
ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, cancel_size.y + 80), 0, app_starting ? ImGuiWindowFlags_NoScrollWithMouse : 0);
|
||||||
|
|
||||||
|
ImGui::Indent(20);
|
||||||
|
if (server_name.empty())
|
||||||
|
ImGui::Text("%s", _S("Start an application on your computer or select one to start streaming."));
|
||||||
|
else
|
||||||
|
ImGui::Text("%s", fmt::format(_F("Start an application on {} or select one to start streaming."), server_name).c_str());
|
||||||
|
ImGui::Unindent();
|
||||||
|
|
||||||
|
float icon_width = 400;
|
||||||
|
float icon_spacing = ImGui::GetStyle().ItemSpacing.x;
|
||||||
|
float usable_window_width = ImGui::GetWindowSize().x - ImGui::GetCurrentWindow()->ScrollbarSizes.x;
|
||||||
|
|
||||||
|
int icons_per_line = (usable_window_width + icon_spacing) / (icon_width + icon_spacing);
|
||||||
|
float icon_line_width = icons_per_line * icon_width + (icons_per_line - 1) * icon_spacing;
|
||||||
|
|
||||||
|
ImGui::Indent((usable_window_width - icon_line_width) / 2);
|
||||||
|
|
||||||
|
for (const auto [index, app]: utils::enumerate(*apps))
|
||||||
|
{
|
||||||
|
ImTextureID texture = [&]() -> ImTextureID {
|
||||||
|
if (app.image.empty())
|
||||||
|
return default_icon;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto it = app_icons.find(app.id);
|
||||||
|
if (it == app_icons.end())
|
||||||
|
{
|
||||||
|
// Don't load too many textures at the same time to keep the GUI responsive
|
||||||
|
if (std::chrono::steady_clock::now() - t0 > 10ms)
|
||||||
|
return default_icon;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
it = app_icons.emplace(app.id, textures.load_texture(app.image)).first;
|
||||||
|
}
|
||||||
|
catch (std::exception & e)
|
||||||
|
{
|
||||||
|
spdlog::warn("Unable to load icon for \"{}\": {}", app.id, e.what());
|
||||||
|
|
||||||
|
app.image.clear();
|
||||||
|
return default_icon;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, 0);
|
||||||
|
if (icon(app.name + "##" + app.id, texture, {256, 256}, ImGuiButtonFlags_PressedOnClickRelease, {icon_width, 0}))
|
||||||
|
{
|
||||||
|
res = clicked::Start;
|
||||||
|
start_time = t0;
|
||||||
|
stream.start_application(app.id);
|
||||||
|
}
|
||||||
|
imgui_ctx.vibrate_on_hover();
|
||||||
|
ImGui::PopStyleColor(); // ImGuiCol_Button
|
||||||
|
|
||||||
|
if ((index + 1) % icons_per_line)
|
||||||
|
ImGui::SameLine();
|
||||||
|
}
|
||||||
|
ImGui::Unindent();
|
||||||
|
|
||||||
|
std::vector<std::pair<std::string, ImTextureID>> to_be_removed;
|
||||||
|
for (const auto & [app_id, app_icon]: app_icons)
|
||||||
|
{
|
||||||
|
if (not std::ranges::contains(*apps, app_id, &app::id))
|
||||||
|
to_be_removed.emplace_back(app_id, app_icon);
|
||||||
|
}
|
||||||
|
for (const auto & [app_id, app_icon]: to_be_removed)
|
||||||
|
{
|
||||||
|
imgui_ctx.free_texture(app_icon);
|
||||||
|
app_icons.erase(app_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScrollWhenDragging();
|
||||||
|
ImGui::EndChild();
|
||||||
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
|
if (app_starting)
|
||||||
|
{
|
||||||
|
ImGui::SetCursorPos(ImGui::GetWindowSize() / 2 - ImVec2{200, 200} - ImGui::GetStyle().FramePadding);
|
||||||
|
ImSpinner::SpinnerAng("App starting spinner",
|
||||||
|
200, // Radius
|
||||||
|
40, // Thickness
|
||||||
|
ImColor{1.f, 1.f, 1.f, 1.f}, // Colour
|
||||||
|
ImColor{1.f, 1.f, 1.f, 0.f}, // Background
|
||||||
|
6, // Velocity
|
||||||
|
0.75f * 2 * M_PI // Angle
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding
|
||||||
|
}
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
|
ImGui::SetCursorPos(ImGui::GetWindowSize() - cancel_size - ImVec2{50, 50});
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
|
||||||
|
if (ImGui::Button(cancel.c_str()))
|
||||||
|
res = clicked::Cancel;
|
||||||
|
imgui_ctx.vibrate_on_hover();
|
||||||
|
ImGui::PopStyleColor(3); // ImGuiCol_Button, ImGuiCol_ButtonHovered, ImGuiCol_ButtonActive
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void app_launcher::operator()(to_headset::application_list && apps)
|
||||||
|
{
|
||||||
|
std::ranges::sort(apps.applications, [](auto & l, auto & r) {
|
||||||
|
return una::casesens::collate_utf8(l.name, r.name) < 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
auto locked = applications.lock();
|
||||||
|
|
||||||
|
locked->clear();
|
||||||
|
locked->reserve(apps.applications.size());
|
||||||
|
for (const auto & i: apps.applications)
|
||||||
|
{
|
||||||
|
locked->push_back(app{
|
||||||
|
.id = std::move(i.id),
|
||||||
|
.name = std::move(i.name),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void app_launcher::operator()(to_headset::application_icon && icon)
|
||||||
|
{
|
||||||
|
auto locked = applications.lock();
|
||||||
|
if (auto it = std::ranges::find(*locked, icon.id, &app::id); it != locked->end())
|
||||||
|
it->image = std::move(icon.image);
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* WiVRn VR streaming
|
||||||
|
* Copyright (C) 2025 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||||
|
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "render/imgui_impl.h"
|
||||||
|
#include "wivrn_packets.h"
|
||||||
|
#include <chrono>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace scenes
|
||||||
|
{
|
||||||
|
class stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
class app_launcher
|
||||||
|
{
|
||||||
|
struct app
|
||||||
|
{
|
||||||
|
std::string id;
|
||||||
|
std::string name;
|
||||||
|
std::vector<std::byte> image;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::chrono::steady_clock::time_point start_time{};
|
||||||
|
std::string server_name;
|
||||||
|
scenes::stream & stream;
|
||||||
|
imgui_textures textures;
|
||||||
|
ImTextureID default_icon;
|
||||||
|
std::unordered_map<std::string, ImTextureID> app_icons;
|
||||||
|
// Last application list received from server
|
||||||
|
thread_safe<std::vector<app>> applications;
|
||||||
|
|
||||||
|
public:
|
||||||
|
app_launcher(scenes::stream &, std::string server_name);
|
||||||
|
~app_launcher();
|
||||||
|
enum clicked
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Cancel,
|
||||||
|
Start,
|
||||||
|
};
|
||||||
|
// cancel: text to display on the quit/disconnect/cancel button
|
||||||
|
clicked draw_gui(imgui_context &, const std::string & cancel);
|
||||||
|
|
||||||
|
void operator()(wivrn::to_headset::application_list && apps);
|
||||||
|
void operator()(wivrn::to_headset::application_icon && icon);
|
||||||
|
};
|
||||||
+1
-12
@@ -572,7 +572,7 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
|||||||
{
|
{
|
||||||
auto session = async_session.get();
|
auto session = async_session.get();
|
||||||
if (session)
|
if (session)
|
||||||
next_scene = stream::create(std::move(session), 1'000'000'000.f / frame_state.predictedDisplayPeriod);
|
next_scene = stream::create(std::move(session), 1'000'000'000.f / frame_state.predictedDisplayPeriod, server_name);
|
||||||
|
|
||||||
async_session.reset();
|
async_session.reset();
|
||||||
}
|
}
|
||||||
@@ -923,15 +923,6 @@ void scenes::lobby::on_focused()
|
|||||||
about_picture = imgui_ctx->load_texture(image + ".png");
|
about_picture = imgui_ctx->load_texture(image + ".png");
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
default_icon = imgui_ctx->load_texture("default_icon.ktx2");
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
default_icon = imgui_ctx->load_texture("default_icon.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_passthrough();
|
setup_passthrough();
|
||||||
session.set_refresh_rate(application::get_config().preferred_refresh_rate.value_or(0));
|
session.set_refresh_rate(application::get_config().preferred_refresh_rate.value_or(0));
|
||||||
multicast = application::get_wifi_lock().get_multicast_lock();
|
multicast = application::get_wifi_lock().get_multicast_lock();
|
||||||
@@ -952,8 +943,6 @@ void scenes::lobby::on_unfocused()
|
|||||||
renderer->wait_idle(); // Must be before the scene data because the renderer uses its descriptor sets
|
renderer->wait_idle(); // Must be before the scene data because the renderer uses its descriptor sets
|
||||||
|
|
||||||
about_picture = 0;
|
about_picture = 0;
|
||||||
default_icon = 0;
|
|
||||||
app_icons.clear();
|
|
||||||
imgui_ctx.reset();
|
imgui_ctx.reset();
|
||||||
world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools
|
world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools
|
||||||
|
|
||||||
|
|||||||
@@ -127,9 +127,6 @@ class lobby : public scene_impl<lobby>
|
|||||||
tab last_current_tab = tab::server_list;
|
tab last_current_tab = tab::server_list;
|
||||||
int optional_feature_index = 0; // Which step of the first run screen are we in
|
int optional_feature_index = 0; // Which step of the first run screen are we in
|
||||||
ImTextureID about_picture;
|
ImTextureID about_picture;
|
||||||
ImTextureID default_icon;
|
|
||||||
std::unordered_map<std::string, ImTextureID> app_icons;
|
|
||||||
std::optional<XrTime> timestamp_start_application;
|
|
||||||
|
|
||||||
virtual_keyboard keyboard;
|
virtual_keyboard keyboard;
|
||||||
|
|
||||||
|
|||||||
+2
-258
@@ -30,15 +30,13 @@
|
|||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "imgui_internal.h"
|
#include "imgui_internal.h"
|
||||||
#include "lobby.h"
|
#include "lobby.h"
|
||||||
#include "stream.h"
|
#include "scenes/stream.h"
|
||||||
#include "utils/i18n.h"
|
#include "utils/i18n.h"
|
||||||
#include "utils/overloaded.h"
|
#include "utils/overloaded.h"
|
||||||
#include "utils/ranges.h"
|
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "xr/body_tracker.h"
|
#include "xr/body_tracker.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <chrono>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
#include <imspinner.h>
|
#include <imspinner.h>
|
||||||
@@ -52,81 +50,6 @@
|
|||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
// https://github.com/ocornut/imgui/issues/3379#issuecomment-2943903877
|
|
||||||
static void ScrollWhenDragging()
|
|
||||||
{
|
|
||||||
ImVec2 delta{0.0f, -ImGui::GetIO().MouseDelta.y};
|
|
||||||
const ImGuiMouseButton mouse_button = ImGuiMouseButton_Left;
|
|
||||||
|
|
||||||
ImGuiContext & g = *ImGui::GetCurrentContext();
|
|
||||||
ImGuiWindow * window = g.CurrentWindow;
|
|
||||||
ImGuiID id = window->GetID("##scrolldraggingoverlay");
|
|
||||||
ImGui::KeepAliveID(id);
|
|
||||||
|
|
||||||
static int active_id;
|
|
||||||
static ImVec2 cumulated_delta;
|
|
||||||
|
|
||||||
bool HoveredIdAllowOverlap_backup = std::exchange(g.HoveredIdAllowOverlap, true);
|
|
||||||
bool ActiveIdAllowOverlap_backup = std::exchange(g.ActiveIdAllowOverlap, true);
|
|
||||||
if (active_id == 0 and ImGui::ItemHoverable(window->Rect(), 0, g.CurrentItemFlags) and ImGui::IsMouseClicked(mouse_button, ImGuiInputFlags_None, /*id*/ ImGuiKeyOwner_Any))
|
|
||||||
{
|
|
||||||
active_id = id;
|
|
||||||
|
|
||||||
// Don't scroll on the first step, in case the active controller just changed
|
|
||||||
delta = {};
|
|
||||||
cumulated_delta = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not g.IO.MouseDown[mouse_button])
|
|
||||||
active_id = 0;
|
|
||||||
|
|
||||||
if (active_id == id)
|
|
||||||
{
|
|
||||||
if (delta.x != 0.0f)
|
|
||||||
ImGui::SetScrollX(window, window->Scroll.x + delta.x);
|
|
||||||
if (delta.y != 0.0f)
|
|
||||||
ImGui::SetScrollY(window, window->Scroll.y + delta.y);
|
|
||||||
|
|
||||||
cumulated_delta += delta;
|
|
||||||
if (std::max(std::abs(cumulated_delta.x), std::abs(cumulated_delta.y)) > 50)
|
|
||||||
ImGui::ClearActiveID();
|
|
||||||
}
|
|
||||||
|
|
||||||
g.HoveredIdAllowOverlap = HoveredIdAllowOverlap_backup;
|
|
||||||
g.ActiveIdAllowOverlap = ActiveIdAllowOverlap_backup;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CenterTextH(const std::string & text)
|
|
||||||
{
|
|
||||||
float win_width = ImGui::GetWindowSize().x;
|
|
||||||
float text_width = ImGui::CalcTextSize(text.c_str()).x;
|
|
||||||
ImGui::SetCursorPosX((win_width - text_width) / 2);
|
|
||||||
|
|
||||||
ImGui::Text("%s", text.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CenterTextHV(const std::string & text)
|
|
||||||
{
|
|
||||||
ImVec2 size = ImGui::GetWindowSize();
|
|
||||||
|
|
||||||
std::vector<std::string> lines = utils::split(text);
|
|
||||||
|
|
||||||
float text_height = 0;
|
|
||||||
for (const auto & i: lines)
|
|
||||||
text_height += ImGui::CalcTextSize(i.c_str()).y;
|
|
||||||
|
|
||||||
ImGui::SetCursorPosY((size.y - text_height) / 2);
|
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {0, 0});
|
|
||||||
for (const auto & i: lines)
|
|
||||||
{
|
|
||||||
float text_width = ImGui::CalcTextSize(i.c_str()).x;
|
|
||||||
ImGui::SetCursorPosX((size.x - text_width) / 2);
|
|
||||||
ImGui::Text("%s", i.c_str());
|
|
||||||
}
|
|
||||||
ImGui::PopStyleVar();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void InputText(const char * label, std::string & text, const ImVec2 & size, ImGuiInputTextFlags flags)
|
static void InputText(const char * label, std::string & text, const ImVec2 & size, ImGuiInputTextFlags flags)
|
||||||
{
|
{
|
||||||
auto callback = [](ImGuiInputTextCallbackData * data) -> int {
|
auto callback = [](ImGuiInputTextCallbackData * data) -> int {
|
||||||
@@ -175,54 +98,6 @@ static void display_recentering_tip(imgui_context & ctx, const std::string & tip
|
|||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display a button with an image and a text centred horizontally
|
|
||||||
static bool icon(const std::string & text, ImTextureRef tex_ref, const ImVec2 & image_size, ImGuiButtonFlags flags = 0, const ImVec2 & size_arg = ImVec2(0, 0), const ImVec2 & uv0 = ImVec2(0, 0), const ImVec2 & uv1 = ImVec2(1, 1), const ImVec4 & tint_col = ImVec4(1, 1, 1, 1))
|
|
||||||
{
|
|
||||||
// Based on ImGui::ButtonEx and ImGui::ImageButtonEx
|
|
||||||
ImGuiWindow * window = ImGui::GetCurrentWindow();
|
|
||||||
const ImGuiStyle & style = ImGui::GetStyle();
|
|
||||||
|
|
||||||
if (window->SkipItems)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const ImVec2 label_size = ImGui::CalcTextSize(text.c_str(), nullptr, true);
|
|
||||||
|
|
||||||
ImVec2 size = ImGui::CalcItemSize(
|
|
||||||
size_arg,
|
|
||||||
std::max(image_size.x, label_size.x) + style.FramePadding.x * 2.0f,
|
|
||||||
image_size.y + style.ItemInnerSpacing.y + label_size.y + style.FramePadding.y * 2.0f);
|
|
||||||
|
|
||||||
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
|
|
||||||
|
|
||||||
ImRect image_pos(
|
|
||||||
{(bb.Min.x + bb.Max.x - image_size.x) / 2, bb.Min.y + style.FramePadding.y},
|
|
||||||
{(bb.Min.x + bb.Max.x + image_size.x) / 2, bb.Min.y + style.FramePadding.y + image_size.y});
|
|
||||||
|
|
||||||
ImRect label_pos(
|
|
||||||
{bb.Min.x + style.FramePadding.x, image_pos.Max.y + style.ItemInnerSpacing.y},
|
|
||||||
{bb.Max.x - style.FramePadding.x, bb.Max.y - style.FramePadding.y});
|
|
||||||
|
|
||||||
ImGui::ItemSize(bb);
|
|
||||||
|
|
||||||
ImGuiID id = window->GetID(text.c_str());
|
|
||||||
if (!ImGui::ItemAdd(bb, id))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
bool hovered, held;
|
|
||||||
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held, flags);
|
|
||||||
|
|
||||||
// Render
|
|
||||||
const ImU32 col = ImGui::GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered
|
|
||||||
: ImGuiCol_Button);
|
|
||||||
ImGui::RenderNavCursor(bb, id);
|
|
||||||
ImGui::RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
|
|
||||||
|
|
||||||
window->DrawList->AddImage(tex_ref, image_pos.Min, image_pos.Max, uv0, uv1, ImGui::GetColorU32(tint_col));
|
|
||||||
ImGui::RenderTextClipped(label_pos.Min, label_pos.Max, text.c_str(), NULL, &label_size, style.ButtonTextAlign, &bb);
|
|
||||||
|
|
||||||
return pressed;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string openxr_post_processing_flag_name(XrCompositionLayerSettingsFlagsFB flag)
|
std::string openxr_post_processing_flag_name(XrCompositionLayerSettingsFlagsFB flag)
|
||||||
{
|
{
|
||||||
switch (flag)
|
switch (flag)
|
||||||
@@ -248,7 +123,6 @@ void scenes::lobby::gui_connecting(locked_notifiable<pin_request_data> & pin_req
|
|||||||
if (next_scene)
|
if (next_scene)
|
||||||
{
|
{
|
||||||
current_tab = tab::connected;
|
current_tab = tab::connected;
|
||||||
timestamp_start_application.reset();
|
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -384,144 +258,14 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time)
|
|||||||
if (not next_scene)
|
if (not next_scene)
|
||||||
{
|
{
|
||||||
current_tab = tab::server_list;
|
current_tab = tab::server_list;
|
||||||
|
|
||||||
for (const auto & [app_id, app_icon]: app_icons)
|
|
||||||
imgui_ctx->free_texture(app_icon);
|
|
||||||
app_icons.clear();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
if (next_scene->apps.draw_gui(*imgui_ctx, _("Disconnect")) == app_launcher::Cancel)
|
||||||
if (server_name.empty())
|
|
||||||
CenterTextH(_("Connected to WiVRn server"));
|
|
||||||
else
|
|
||||||
CenterTextH(fmt::format(_F("Connected to {}"), server_name));
|
|
||||||
ImGui::PopFont();
|
|
||||||
|
|
||||||
auto disconnect = _("Disconnect");
|
|
||||||
auto disconnect_size = ImGui::CalcTextSize(disconnect.c_str());
|
|
||||||
|
|
||||||
auto apps = next_scene->get_applications();
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20});
|
|
||||||
if (apps->empty())
|
|
||||||
{
|
|
||||||
CenterTextHV(_("Start an application on the server to start streaming."));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool app_starting = timestamp_start_application and (predicted_display_time - *timestamp_start_application < 10'000'000'000);
|
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 0});
|
|
||||||
ImGui::BeginDisabled(app_starting);
|
|
||||||
ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, disconnect_size.y + 80), 0, app_starting ? ImGuiWindowFlags_NoScrollWithMouse : 0);
|
|
||||||
|
|
||||||
ImGui::Indent(20);
|
|
||||||
if (server_name.empty())
|
|
||||||
ImGui::Text("%s", _S("Start an application on your computer or select one to start streaming."));
|
|
||||||
else
|
|
||||||
ImGui::Text("%s", fmt::format(_F("Start an application on {} or select one to start streaming."), server_name).c_str());
|
|
||||||
ImGui::Unindent();
|
|
||||||
|
|
||||||
float icon_width = 400;
|
|
||||||
float icon_spacing = ImGui::GetStyle().ItemSpacing.x;
|
|
||||||
float usable_window_width = ImGui::GetWindowSize().x - ImGui::GetCurrentWindow()->ScrollbarSizes.x;
|
|
||||||
|
|
||||||
int icons_per_line = (usable_window_width + icon_spacing) / (icon_width + icon_spacing);
|
|
||||||
float icon_line_width = icons_per_line * icon_width + (icons_per_line - 1) * icon_spacing;
|
|
||||||
|
|
||||||
ImGui::Indent((usable_window_width - icon_line_width) / 2);
|
|
||||||
|
|
||||||
auto t0 = std::chrono::steady_clock::now();
|
|
||||||
for (const auto [index, app]: utils::enumerate(*apps))
|
|
||||||
{
|
|
||||||
ImTextureID texture = [&]() -> ImTextureID {
|
|
||||||
if (app.image.empty())
|
|
||||||
return default_icon;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto it = app_icons.find(app.id);
|
|
||||||
if (it == app_icons.end())
|
|
||||||
{
|
|
||||||
// Don't load too many textures at the same time to keep the GUI responsive
|
|
||||||
if (std::chrono::steady_clock::now() - t0 > 10ms)
|
|
||||||
return default_icon;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
it = app_icons.emplace(app.id, imgui_ctx->load_texture(app.image)).first;
|
|
||||||
}
|
|
||||||
catch (std::exception & e)
|
|
||||||
{
|
|
||||||
spdlog::warn("Unable to load icon for \"{}\": {}", app.id, e.what());
|
|
||||||
|
|
||||||
app.image.clear();
|
|
||||||
return default_icon;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button, 0);
|
|
||||||
if (icon(app.name + "##" + app.id, texture, {256, 256}, ImGuiButtonFlags_PressedOnClickRelease, {icon_width, 0}))
|
|
||||||
{
|
|
||||||
timestamp_start_application = predicted_display_time;
|
|
||||||
next_scene->start_application(app.id);
|
|
||||||
}
|
|
||||||
imgui_ctx->vibrate_on_hover();
|
|
||||||
ImGui::PopStyleColor(); // ImGuiCol_Button
|
|
||||||
|
|
||||||
if (index % 3 != 2)
|
|
||||||
ImGui::SameLine();
|
|
||||||
}
|
|
||||||
ImGui::Unindent();
|
|
||||||
|
|
||||||
std::vector<std::pair<std::string, ImTextureID>> to_be_removed;
|
|
||||||
for (const auto & [app_id, app_icon]: app_icons)
|
|
||||||
{
|
|
||||||
if (not std::ranges::contains(*apps, app_id, &scenes::stream::app::id))
|
|
||||||
to_be_removed.emplace_back(app_id, app_icon);
|
|
||||||
}
|
|
||||||
for (const auto & [app_id, app_icon]: to_be_removed)
|
|
||||||
{
|
|
||||||
imgui_ctx->free_texture(app_icon);
|
|
||||||
app_icons.erase(app_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScrollWhenDragging();
|
|
||||||
ImGui::EndChild();
|
|
||||||
ImGui::EndDisabled();
|
|
||||||
|
|
||||||
if (app_starting)
|
|
||||||
{
|
|
||||||
ImGui::SetCursorPos(ImGui::GetWindowSize() / 2 - ImVec2{200, 200} - ImGui::GetStyle().FramePadding);
|
|
||||||
ImSpinner::SpinnerAng("App starting spinner",
|
|
||||||
200, // Radius
|
|
||||||
40, // Thickness
|
|
||||||
ImColor{1.f, 1.f, 1.f, 1.f}, // Colour
|
|
||||||
ImColor{1.f, 1.f, 1.f, 0.f}, // Background
|
|
||||||
6, // Velocity
|
|
||||||
0.75f * 2 * M_PI // Angle
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding
|
|
||||||
}
|
|
||||||
ImGui::PopStyleVar();
|
|
||||||
|
|
||||||
ImGui::SetCursorPos(ImGui::GetWindowSize() - disconnect_size - ImVec2{50, 50});
|
|
||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
|
|
||||||
if (ImGui::Button(disconnect.c_str()))
|
|
||||||
{
|
{
|
||||||
next_scene.reset();
|
next_scene.reset();
|
||||||
current_tab = tab::server_list;
|
current_tab = tab::server_list;
|
||||||
}
|
}
|
||||||
imgui_ctx->vibrate_on_hover();
|
|
||||||
ImGui::PopStyleColor(3); // ImGuiCol_Button, ImGuiCol_ButtonHovered, ImGuiCol_ButtonActive
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void scenes::lobby::gui_new_server()
|
void scenes::lobby::gui_new_server()
|
||||||
|
|||||||
@@ -151,8 +151,9 @@ static const std::array supported_depth_formats{
|
|||||||
vk::Format::eX8D24UnormPack32,
|
vk::Format::eX8D24UnormPack32,
|
||||||
};
|
};
|
||||||
|
|
||||||
scenes::stream::stream() :
|
scenes::stream::stream(std::string server_name) :
|
||||||
scene_impl<stream>(supported_color_formats, supported_depth_formats),
|
scene_impl<stream>(supported_color_formats, supported_depth_formats),
|
||||||
|
apps{*this, std::move(server_name)},
|
||||||
blitters{blitter(device, 0), blitter(device, 1)}
|
blitters{blitter(device, 0), blitter(device, 1)}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -185,9 +186,9 @@ static from_headset::visibility_mask_changed::masks get_visibility_mask(xr::inst
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_session> network_session, float guessed_fps)
|
std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_session> network_session, float guessed_fps, std::string server_name)
|
||||||
{
|
{
|
||||||
std::shared_ptr<stream> self{new stream};
|
std::shared_ptr<stream> self{new stream{std::move(server_name)}};
|
||||||
self->network_session = std::move(network_session);
|
self->network_session = std::move(network_session);
|
||||||
|
|
||||||
self->network_session->send_control([&]() {
|
self->network_session->send_control([&]() {
|
||||||
|
|||||||
+7
-16
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "app_launcher.h"
|
||||||
#include "audio/audio.h"
|
#include "audio/audio.h"
|
||||||
#include "decoder/shard_accumulator.h"
|
#include "decoder/shard_accumulator.h"
|
||||||
#include "render/imgui_impl.h"
|
#include "render/imgui_impl.h"
|
||||||
@@ -49,12 +50,7 @@ public:
|
|||||||
};
|
};
|
||||||
static const size_t image_buffer_size = 3;
|
static const size_t image_buffer_size = 3;
|
||||||
|
|
||||||
struct app
|
app_launcher apps;
|
||||||
{
|
|
||||||
std::string id;
|
|
||||||
std::string name;
|
|
||||||
std::vector<std::byte> image;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const size_t view_count = 2;
|
static const size_t view_count = 2;
|
||||||
@@ -172,18 +168,18 @@ private:
|
|||||||
// Keep a reference to the resources needed to blit the images until vkWaitForFences
|
// Keep a reference to the resources needed to blit the images until vkWaitForFences
|
||||||
std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> current_blit_handles;
|
std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> current_blit_handles;
|
||||||
|
|
||||||
// Last application list received from server
|
|
||||||
thread_safe<std::vector<app>> applications;
|
|
||||||
|
|
||||||
XrTime running_application_req = 0;
|
XrTime running_application_req = 0;
|
||||||
thread_safe<to_headset::running_applications> running_applications;
|
thread_safe<to_headset::running_applications> running_applications;
|
||||||
|
|
||||||
stream();
|
stream(std::string server_name);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~stream();
|
~stream();
|
||||||
|
|
||||||
static std::shared_ptr<stream> create(std::unique_ptr<wivrn_session> session, float guessed_fps);
|
static std::shared_ptr<stream> create(
|
||||||
|
std::unique_ptr<wivrn_session> session,
|
||||||
|
float guessed_fps,
|
||||||
|
std::string server_name);
|
||||||
|
|
||||||
void render(const XrFrameState &) override;
|
void render(const XrFrameState &) override;
|
||||||
void on_focused() override;
|
void on_focused() override;
|
||||||
@@ -220,11 +216,6 @@ public:
|
|||||||
return !exiting;
|
return !exiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto get_applications()
|
|
||||||
{
|
|
||||||
return applications.lock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void start_application(std::string appid);
|
void start_application(std::string appid);
|
||||||
|
|
||||||
static meta & get_meta_scene();
|
static meta & get_meta_scene();
|
||||||
|
|||||||
@@ -83,15 +83,6 @@ ImPlotPoint getter(int index, void * data_)
|
|||||||
|
|
||||||
return ImPlotPoint(index, *(float *)(data.data + index * data.stride) * data.multiplier);
|
return ImPlotPoint(index, *(float *)(data.data + index * data.stride) * data.multiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CenterTextH(const std::string & text)
|
|
||||||
{
|
|
||||||
float win_width = ImGui::GetWindowSize().x;
|
|
||||||
float text_width = ImGui::CalcTextSize(text.c_str()).x;
|
|
||||||
ImGui::SetCursorPosX((win_width - text_width) / 2);
|
|
||||||
|
|
||||||
ImGui::Text("%s", text.c_str());
|
|
||||||
}
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void scenes::stream::accumulate_metrics(XrTime predicted_display_time, const std::vector<std::shared_ptr<shard_accumulator::blit_handle>> & blit_handles, const gpu_timestamps & timestamps)
|
void scenes::stream::accumulate_metrics(XrTime predicted_display_time, const std::vector<std::shared_ptr<shard_accumulator::blit_handle>> & blit_handles, const gpu_timestamps & timestamps)
|
||||||
|
|||||||
@@ -106,31 +106,14 @@ void scenes::stream::send_feedback(const wivrn::from_headset::feedback & feedbac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scenes::stream::operator()(to_headset::application_list && apps)
|
void scenes::stream::operator()(to_headset::application_list && l)
|
||||||
{
|
{
|
||||||
std::ranges::sort(apps.applications, [](auto & l, auto & r) {
|
apps(std::move(l));
|
||||||
return una::casesens::collate_utf8(l.name, r.name) < 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
auto locked = applications.lock();
|
|
||||||
|
|
||||||
locked->clear();
|
|
||||||
locked->reserve(apps.applications.size());
|
|
||||||
for (const auto & i: apps.applications)
|
|
||||||
{
|
|
||||||
locked->push_back(app{
|
|
||||||
.id = std::move(i.id),
|
|
||||||
.name = std::move(i.name),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void scenes::stream::operator()(to_headset::application_icon && icon)
|
void scenes::stream::operator()(to_headset::application_icon && icon)
|
||||||
{
|
{
|
||||||
auto locked = applications.lock();
|
apps(std::move(icon));
|
||||||
|
|
||||||
if (auto it = std::ranges::find(*locked, icon.id, &app::id); it != locked->end())
|
|
||||||
it->image = std::move(icon.image);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void scenes::stream::operator()(to_headset::running_applications && apps)
|
void scenes::stream::operator()(to_headset::running_applications && apps)
|
||||||
|
|||||||
Reference in New Issue
Block a user