From e4c05e1f4d7896a9b9f00729986a86ea66e1a361 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Fri, 2 Aug 2024 12:30:50 +0800 Subject: [PATCH] [feat] enable movement for control bar --- src/single_window/control_bar.cpp | 8 +----- src/single_window/control_window.cpp | 39 ++++++++++++++++++++-------- src/single_window/render.cpp | 12 ++++++--- src/single_window/render.h | 3 +-- src/single_window/title_bar.cpp | 6 ++--- 5 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/single_window/control_bar.cpp b/src/single_window/control_bar.cpp index bf8b07e..f48f094 100644 --- a/src/single_window/control_bar.cpp +++ b/src/single_window/control_bar.cpp @@ -33,20 +33,14 @@ int Render::ControlBar() { if (ImGui::Button(fullscreen.c_str(), ImVec2(25, 25))) { fullscreen_button_pressed_ = !fullscreen_button_pressed_; if (fullscreen_button_pressed_) { - main_window_width_before_fullscreen_ = main_window_width_; - main_window_height_before_fullscreen_ = main_window_height_; SDL_SetWindowFullscreen(main_window_, SDL_WINDOW_FULLSCREEN_DESKTOP); } else { SDL_SetWindowFullscreen(main_window_, SDL_FALSE); - SDL_SetWindowSize(main_window_, main_window_width_before_fullscreen_, - main_window_height_before_fullscreen_); - main_window_width_ = main_window_width_before_fullscreen_; - main_window_height_ = main_window_height_before_fullscreen_; } } ImGui::SameLine(); - ImGui::SetCursorPosX(main_window_width_ - 35); + ImGui::SetCursorPosX(control_window_max_width_ - 35); } std::string control_bar = diff --git a/src/single_window/control_window.cpp b/src/single_window/control_window.cpp index 0aa5256..d6caf13 100644 --- a/src/single_window/control_window.cpp +++ b/src/single_window/control_window.cpp @@ -1,25 +1,38 @@ #include "render.h" int Render::ControlWindow() { - ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); - static bool a, b, c, d, e; - ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_ + 2), ImGuiCond_Always); - ImGui::SetWindowFontScale(0.5f); - auto time_duration = ImGui::GetTime() - control_bar_button_pressed_time_; auto control_window_width = !control_bar_button_pressed_ ? time_duration < 0.25f - ? main_window_width_ - - (main_window_width_ - control_window_min_width_) * 4 * - time_duration + ? control_window_max_width_ - + (control_window_max_width_ - control_window_min_width_) * + 4 * time_duration : control_window_min_width_ : time_duration < 0.25f ? control_window_min_width_ + - (main_window_width_ - control_window_min_width_) * 4 * + (control_window_max_width_ - control_window_min_width_) * 4 * time_duration - : main_window_width_; - ImGui::BeginChild("ControlWindow", + : control_window_max_width_; + + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0)); + // ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0); + // ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0); + ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_), ImGuiCond_Once); + ImGui::SetNextWindowSize( + ImVec2(control_window_width + 10, control_window_height_ + 10), + ImGuiCond_Always); + ImGui::Begin("ControlWindow", nullptr, + ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | + ImGuiWindowFlags_NoScrollbar | + ImGuiWindowFlags_NoBringToFrontOnFocus); + + ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); + static bool a, b, c, d, e; + ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_), ImGuiCond_Once); + ImGui::SetWindowFontScale(0.5f); + + ImGui::BeginChild("ControlBar", ImVec2(control_window_width, control_window_height_), ImGuiChildFlags_Border, ImGuiWindowFlags_NoDecoration); ImGui::SetWindowFontScale(1.0f); @@ -29,5 +42,9 @@ int Render::ControlWindow() { ImGui::EndChild(); + ImGui::End(); + // ImGui::PopStyleVar(); + ImGui::PopStyleColor(); + return 0; } \ No newline at end of file diff --git a/src/single_window/render.cpp b/src/single_window/render.cpp index b849456..5331fd8 100644 --- a/src/single_window/render.cpp +++ b/src/single_window/render.cpp @@ -438,12 +438,14 @@ int Render::Run() { ImGui_ImplSDL2_NewFrame(); ImGui::NewFrame(); - ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0)); + ImGui::PushStyleColor( + ImGuiCol_WindowBg, + ImVec4(1.0f, 1.0f, 1.0f, fullscreen_button_pressed_ ? 0 : 1.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0); ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); ImGui::SetNextWindowSize( ImVec2(main_window_width_, - streaming_ ? title_bar_height_ + control_window_height_ + streaming_ ? (fullscreen_button_pressed_ ? 0 : title_bar_height_) : main_window_height_default_), ImGuiCond_Always); ImGui::Begin("Render", nullptr, @@ -453,7 +455,9 @@ int Render::Run() { ImGui::PopStyleVar(); ImGui::PopStyleColor(); - TitleBar(); + if (!fullscreen_button_pressed_) { + TitleBar(); + } if (streaming_ && is_client_mode_) { if (!resizable_) { @@ -536,8 +540,8 @@ int Render::Run() { // Rendering ImGui::Render(); + SDL_RenderClear(main_renderer_); if (connection_established_ && received_frame_ && streaming_) { - SDL_RenderClear(main_renderer_); SDL_RenderCopy(main_renderer_, stream_texture_, NULL, &stream_render_rect_); } diff --git a/src/single_window/render.h b/src/single_window/render.h index 345c6f2..490a756 100644 --- a/src/single_window/render.h +++ b/src/single_window/render.h @@ -140,11 +140,10 @@ class Render { int stream_window_height_ = 720; int stream_window_width_last_ = 1280; int stream_window_height_last_ = 720; - int main_window_width_before_fullscreen_ = 1280; - int main_window_height_before_fullscreen_ = 720; int main_window_width_before_maximized_ = 960; int main_window_height_before_maximized_ = 570; int control_window_min_width_ = 40; + int control_window_max_width_ = 150; int control_window_height_ = 40; int local_window_width_ = 350; int status_bar_height_ = 20; diff --git a/src/single_window/title_bar.cpp b/src/single_window/title_bar.cpp index 9f06a4c..f74a907 100644 --- a/src/single_window/title_bar.cpp +++ b/src/single_window/title_bar.cpp @@ -5,9 +5,9 @@ #define BUTTON_PADDING 36.0f int Render::TitleBar() { - ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0); + // ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1); - ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(1, 1, 1, 1.0f)); + ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(1, 1, 1, 0.0f)); ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); ImGui::SetWindowFontScale(0.8f); ImGui::BeginChild("TitleBar", ImVec2(main_window_width_, title_bar_height_), @@ -97,6 +97,6 @@ int Render::TitleBar() { ImGui::EndChild(); ImGui::PopStyleColor(2); - ImGui::PopStyleVar(); + // ImGui::PopStyleVar(); return 0; } \ No newline at end of file