mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[feat] use tab bar to manage stream windows
This commit is contained in:
@@ -163,15 +163,6 @@ int Render::ControlBar(std::shared_ptr<SubStreamWindowProperties>& props) {
|
||||
props->reset_control_bar_pos_ = true;
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
// close button
|
||||
std::string close_button = ICON_FA_XMARK;
|
||||
if (ImGui::Button(close_button.c_str(), ImVec2(25, 25))) {
|
||||
SDL_Event event;
|
||||
event.type = SDL_QUIT;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if (!props->is_control_bar_in_left_) {
|
||||
|
||||
@@ -36,7 +36,8 @@ SDL_HitTestResult Render::HitTestCallback(SDL_Window* window,
|
||||
SDL_GetWindowSize(window, &window_width, &window_height);
|
||||
|
||||
if (area->y < 30 && area->y > MOUSE_GRAB_PADDING &&
|
||||
area->x < window_width - 120 && area->x > MOUSE_GRAB_PADDING) {
|
||||
area->x < window_width - 120 && area->x > MOUSE_GRAB_PADDING &&
|
||||
!render->is_tab_bar_hovered_) {
|
||||
return SDL_HITTEST_DRAGGABLE;
|
||||
}
|
||||
|
||||
@@ -706,6 +707,8 @@ int Render::DrawStreamWindow() {
|
||||
ImGui_ImplSDL2_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
StreamWindow();
|
||||
|
||||
if (!fullscreen_button_pressed_) {
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
||||
@@ -715,23 +718,25 @@ int Render::DrawStreamWindow() {
|
||||
ImGuiCond_Always);
|
||||
ImGui::Begin("StreamWindowTitleBar", nullptr,
|
||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration |
|
||||
ImGuiWindowFlags_NoBringToFrontOnFocus);
|
||||
ImGuiWindowFlags_NoBringToFrontOnFocus |
|
||||
ImGuiWindowFlags_NoDocking);
|
||||
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
TitleBar(false);
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
StreamWindow();
|
||||
|
||||
// Rendering
|
||||
ImGui::Render();
|
||||
SDL_RenderClear(stream_renderer_);
|
||||
|
||||
for (auto& it : client_properties_) {
|
||||
auto props = it.second;
|
||||
SDL_RenderCopy(stream_renderer_, props->stream_texture_, NULL,
|
||||
&(props->stream_render_rect_));
|
||||
if (props->tab_selected_) {
|
||||
SDL_RenderCopy(stream_renderer_, props->stream_texture_, NULL,
|
||||
&(props->stream_render_rect_));
|
||||
}
|
||||
}
|
||||
ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData(), stream_renderer_);
|
||||
SDL_RenderPresent(stream_renderer_);
|
||||
@@ -955,14 +960,6 @@ void Render::CleanupPeer(std::string host_name,
|
||||
LOG_INFO("Destroy peer [{}]", client_id);
|
||||
DestroyPeer(&peer_client);
|
||||
}
|
||||
|
||||
client_properties_.erase(host_name);
|
||||
|
||||
if (client_properties_.empty()) {
|
||||
SDL_Event event;
|
||||
event.type = SDL_QUIT;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void Render::CleanupPeers() {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "../../thirdparty/projectx/src/interface/x.h"
|
||||
@@ -21,6 +22,7 @@
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl2.h"
|
||||
#include "imgui_impl_sdlrenderer2.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "screen_capturer_factory.h"
|
||||
#include "speaker_capturer_factory.h"
|
||||
#include "thumbnail.h"
|
||||
@@ -55,10 +57,10 @@ class Render {
|
||||
float sub_stream_window_width_ = 1280;
|
||||
float sub_stream_window_height_ = 720;
|
||||
float control_window_min_width_ = 20;
|
||||
float control_window_max_width_ = 200;
|
||||
float control_window_max_width_ = 170;
|
||||
float control_window_min_height_ = 40;
|
||||
float control_window_max_height_ = 150;
|
||||
float control_window_width_ = 200;
|
||||
float control_window_width_ = 170;
|
||||
float control_window_height_ = 40;
|
||||
float control_bar_pos_x_ = 0;
|
||||
float control_bar_pos_y_ = 30;
|
||||
@@ -79,6 +81,8 @@ class Render {
|
||||
size_t video_size_ = 0;
|
||||
bool tab_selected_ = false;
|
||||
bool tab_opened_ = true;
|
||||
std::optional<float> pos_x_before_docked_;
|
||||
std::optional<float> pos_y_before_docked_;
|
||||
float render_window_x_ = 0;
|
||||
float render_window_y_ = 0;
|
||||
float render_window_width_ = 0;
|
||||
@@ -357,6 +361,7 @@ class Render {
|
||||
bool reload_recent_connections_ = true;
|
||||
bool show_confirm_delete_connection_ = false;
|
||||
bool delete_connection_ = false;
|
||||
bool is_tab_bar_hovered_ = false;
|
||||
std::string delete_connection_name_ = "";
|
||||
bool re_enter_remote_id_ = false;
|
||||
double copy_start_time_ = 0;
|
||||
|
||||
@@ -11,49 +11,90 @@ int Render::StreamWindow() {
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0));
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
|
||||
ImGui::PushStyleColor(ImGuiCol_DockingEmptyBg, ImVec4(0, 0, 0, 0));
|
||||
ImGui::Begin("VideoBg", nullptr,
|
||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration |
|
||||
ImGuiWindowFlags_NoBringToFrontOnFocus);
|
||||
ImGuiWindowFlags_NoBringToFrontOnFocus |
|
||||
ImGuiWindowFlags_NoDocking);
|
||||
|
||||
ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
|
||||
ImGui::DockSpace(
|
||||
dockspace_id, ImVec2(stream_window_width_, stream_window_height_),
|
||||
ImGuiDockNodeFlags_AutoHideTabBar | ImGuiDockNodeFlags_KeepAliveOnly);
|
||||
|
||||
ImGui::PopStyleColor(3);
|
||||
ImGui::PopStyleColor(2);
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
for (auto& it : client_properties_) {
|
||||
auto& props = it.second;
|
||||
ImGuiTabBarFlags tab_bar_flags =
|
||||
ImGuiTabBarFlags_Reorderable | ImGuiTabBarFlags_AutoSelectNewTabs;
|
||||
ImGuiWindowFlags stream_window_flag =
|
||||
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoDecoration |
|
||||
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoMove;
|
||||
|
||||
// ImGui::SetNextWindowPos(
|
||||
// ImVec2(0, fullscreen_button_pressed_ ? 0 : title_bar_height_),
|
||||
// ImGuiCond_Once);
|
||||
ImGui::SetNextWindowSize(
|
||||
ImVec2(stream_window_width_, stream_window_height_), ImGuiCond_Once);
|
||||
ImGui::SetWindowFontScale(0.5f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0));
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
|
||||
ImGui::Begin(props->remote_id_.c_str(), nullptr,
|
||||
ImGuiWindowFlags_NoTitleBar);
|
||||
ImGui::PopStyleColor(2);
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
ImGui::SetNextWindowPos(ImVec2(20, 0), ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2(0, 20), ImGuiCond_Always);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 8.0f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0.0f));
|
||||
ImGui::Begin("TabBar", nullptr,
|
||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration |
|
||||
ImGuiWindowFlags_NoBringToFrontOnFocus |
|
||||
ImGuiWindowFlags_NoDocking);
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::PopStyleVar(2);
|
||||
if (ImGui::BeginTabBar("StreamTabBar", tab_bar_flags)) {
|
||||
if (ImGui::IsWindowHovered()) {
|
||||
is_tab_bar_hovered_ = true;
|
||||
} else {
|
||||
is_tab_bar_hovered_ = false;
|
||||
}
|
||||
|
||||
ImVec2 stream_window_pos = ImGui::GetWindowPos();
|
||||
ImGuiViewport* viewport = ImGui::GetWindowViewport();
|
||||
ImVec2 stream_window_size = ImGui::GetWindowSize();
|
||||
props->render_window_x_ = stream_window_pos.x;
|
||||
props->render_window_y_ = stream_window_pos.y;
|
||||
props->render_window_width_ = stream_window_size.x;
|
||||
props->render_window_height_ = stream_window_size.y;
|
||||
for (auto it = client_properties_.begin(); it != client_properties_.end();
|
||||
++it) {
|
||||
auto& props = it->second;
|
||||
|
||||
ControlWindow(props);
|
||||
ImGui::SetWindowFontScale(0.6f);
|
||||
if (props->tab_opened_) {
|
||||
if (ImGui::BeginTabItem(props->remote_id_.c_str(), &props->tab_opened_,
|
||||
ImGuiTabItemFlags_None)) {
|
||||
props->tab_selected_ = true;
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
ImGui::SetNextWindowSize(
|
||||
ImVec2(stream_window_width_, stream_window_height_),
|
||||
ImGuiCond_Once);
|
||||
ImGui::SetNextWindowPos(
|
||||
ImVec2(0, fullscreen_button_pressed_ ? 0 : title_bar_height_),
|
||||
ImGuiCond_Appearing);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0.0f));
|
||||
ImGui::Begin(props->remote_id_.c_str(), nullptr, stream_window_flag);
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::PopStyleVar(2);
|
||||
|
||||
ImGui::End();
|
||||
ImVec2 stream_window_pos = ImGui::GetWindowPos();
|
||||
ImGuiViewport* viewport = ImGui::GetWindowViewport();
|
||||
ImVec2 stream_window_size = ImGui::GetWindowSize();
|
||||
props->render_window_x_ = stream_window_pos.x;
|
||||
props->render_window_y_ = stream_window_pos.y;
|
||||
props->render_window_width_ = stream_window_size.x;
|
||||
props->render_window_height_ = stream_window_size.y;
|
||||
|
||||
ControlWindow(props);
|
||||
|
||||
ImGui::End();
|
||||
ImGui::EndTabItem();
|
||||
} else {
|
||||
props->tab_selected_ = false;
|
||||
}
|
||||
} else {
|
||||
CleanupPeer(it->first, props);
|
||||
it = client_properties_.erase(it);
|
||||
if (client_properties_.empty()) {
|
||||
SDL_Event event;
|
||||
event.type = SDL_QUIT;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
UpdateRenderRect();
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "localization.h"
|
||||
#include "rd_log.h"
|
||||
#include "render.h"
|
||||
|
||||
#define BUTTON_PADDING 36.0f
|
||||
|
||||
Reference in New Issue
Block a user