mirror of
				https://github.com/kunkundi/crossdesk.git
				synced 2025-10-26 20:25:34 +08:00 
			
		
		
		
	[fix] fix control window position when stream window size changed
This commit is contained in:
		| @@ -139,11 +139,15 @@ int Render::ControlBar() { | ||||
|           fullscreen_button_pressed_ | ||||
|               ? localization::exit_fullscreen[localization_language_index_] | ||||
|               : localization::fullscreen[localization_language_index_]; | ||||
|       // save stream window last size | ||||
|       SDL_GetWindowSize(stream_window_, &stream_window_width_last_, | ||||
|                         &stream_window_height_last_); | ||||
|       if (fullscreen_button_pressed_) { | ||||
|         SDL_SetWindowFullscreen(main_window_, SDL_WINDOW_FULLSCREEN_DESKTOP); | ||||
|         SDL_SetWindowFullscreen(stream_window_, SDL_WINDOW_FULLSCREEN_DESKTOP); | ||||
|       } else { | ||||
|         SDL_SetWindowFullscreen(main_window_, SDL_FALSE); | ||||
|         SDL_SetWindowFullscreen(stream_window_, SDL_FALSE); | ||||
|       } | ||||
|       reset_control_bar_pos_ = true; | ||||
|     } | ||||
|  | ||||
|     ImGui::SameLine(); | ||||
|   | ||||
| @@ -41,20 +41,71 @@ int Render::ControlWindow() { | ||||
|  | ||||
|   ImGui::SetNextWindowSize( | ||||
|       ImVec2(control_window_width_, control_window_height_), ImGuiCond_Always); | ||||
|   ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_), ImGuiCond_Once); | ||||
|   if (ImGui::IsMouseReleased(ImGuiPopupFlags_MouseButtonLeft) || | ||||
|       control_window_width_is_changing_) { | ||||
|   ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_ + 1), ImGuiCond_Once); | ||||
|  | ||||
|   if (reset_control_bar_pos_) { | ||||
|     int new_control_window_pos_x, new_control_window_pos_y, new_cursor_pos_x, | ||||
|         new_cursor_pos_y; | ||||
|  | ||||
|     // set control window pos | ||||
|     new_control_window_pos_x = control_winodw_pos_.x; | ||||
|     if (control_winodw_pos_.y < stream_render_rect_last_.y) { | ||||
|       new_control_window_pos_y = | ||||
|           stream_render_rect_.y - | ||||
|           (stream_render_rect_last_.y - control_winodw_pos_.y); | ||||
|       if (fullscreen_button_pressed_ && new_control_window_pos_y < 0) { | ||||
|         new_control_window_pos_y = 0; | ||||
|       } else if (!fullscreen_button_pressed_ && | ||||
|                  new_control_window_pos_y < (title_bar_height_ + 1)) { | ||||
|         new_control_window_pos_y = title_bar_height_ + 1; | ||||
|       } | ||||
|     } else if (control_winodw_pos_.y + control_window_height_ > | ||||
|                stream_render_rect_last_.y + stream_render_rect_last_.h) { | ||||
|       new_control_window_pos_y = | ||||
|           stream_render_rect_.y + stream_render_rect_.h + | ||||
|           (control_winodw_pos_.y - stream_render_rect_last_.y - | ||||
|            stream_render_rect_last_.h); | ||||
|       if (new_control_window_pos_y > | ||||
|           stream_window_height_ - control_window_height_) { | ||||
|         new_control_window_pos_y = | ||||
|             stream_window_height_ - control_window_height_; | ||||
|       } | ||||
|     } else if (control_winodw_pos_.y + control_window_height_ == | ||||
|                stream_render_rect_last_.y + stream_render_rect_last_.h) { | ||||
|       new_control_window_pos_y = stream_render_rect_.y + stream_render_rect_.h - | ||||
|                                  control_window_height_; | ||||
|     } else { | ||||
|       new_control_window_pos_y = | ||||
|           (control_winodw_pos_.y - stream_render_rect_last_.y) / | ||||
|               (float)(stream_render_rect_last_.h) * stream_render_rect_.h + | ||||
|           stream_render_rect_.y; | ||||
|     } | ||||
|  | ||||
|     // set cursor pos | ||||
|     new_cursor_pos_x = new_control_window_pos_x + mouse_diff_control_bar_pos_x_; | ||||
|     new_cursor_pos_y = new_control_window_pos_y + mouse_diff_control_bar_pos_y_; | ||||
|  | ||||
|     ImGui::SetNextWindowPos( | ||||
|         ImVec2(new_control_window_pos_x, new_control_window_pos_y), | ||||
|         ImGuiCond_Always); | ||||
|     SDL_WarpMouseInWindow(stream_window_, new_cursor_pos_x, new_cursor_pos_y); | ||||
|     reset_control_bar_pos_ = false; | ||||
|   } else if (!reset_control_bar_pos_ && | ||||
|                  ImGui::IsMouseReleased(ImGuiPopupFlags_MouseButtonLeft) || | ||||
|              control_window_width_is_changing_) { | ||||
|     if (control_winodw_pos_.x <= stream_window_width_ / 2) { | ||||
|       int pos_x = 0; | ||||
|       int pos_y = | ||||
|           (control_winodw_pos_.y >= | ||||
|                (fullscreen_button_pressed_ ? 0 : title_bar_height_) && | ||||
|                (fullscreen_button_pressed_ ? 0 : (title_bar_height_ + 1)) && | ||||
|            control_winodw_pos_.y <= | ||||
|                stream_window_height_ - control_window_height_) | ||||
|               ? control_winodw_pos_.y | ||||
|               : (control_winodw_pos_.y < | ||||
|                          (fullscreen_button_pressed_ ? 0 : title_bar_height_) | ||||
|                      ? (fullscreen_button_pressed_ ? 0 : title_bar_height_) | ||||
|               : (control_winodw_pos_.y < (fullscreen_button_pressed_ | ||||
|                                               ? 0 | ||||
|                                               : (title_bar_height_ + 1)) | ||||
|                      ? (fullscreen_button_pressed_ ? 0 | ||||
|                                                    : (title_bar_height_ + 1)) | ||||
|                      : (stream_window_height_ - control_window_height_)); | ||||
|  | ||||
|       if (control_bar_expand_) { | ||||
| @@ -78,13 +129,15 @@ int Render::ControlWindow() { | ||||
|       int pos_x = 0; | ||||
|       int pos_y = | ||||
|           (control_winodw_pos_.y >= | ||||
|                (fullscreen_button_pressed_ ? 0 : title_bar_height_) && | ||||
|                (fullscreen_button_pressed_ ? 0 : (title_bar_height_ + 1)) && | ||||
|            control_winodw_pos_.y <= | ||||
|                stream_window_height_ - control_window_height_) | ||||
|               ? control_winodw_pos_.y | ||||
|               : (control_winodw_pos_.y < | ||||
|                          (fullscreen_button_pressed_ ? 0 : title_bar_height_) | ||||
|                      ? (fullscreen_button_pressed_ ? 0 : title_bar_height_) | ||||
|               : (control_winodw_pos_.y < (fullscreen_button_pressed_ | ||||
|                                               ? 0 | ||||
|                                               : (title_bar_height_ + 1)) | ||||
|                      ? (fullscreen_button_pressed_ ? 0 | ||||
|                                                    : (title_bar_height_ + 1)) | ||||
|                      : (stream_window_height_ - control_window_height_)); | ||||
|  | ||||
|       if (control_bar_expand_) { | ||||
| @@ -131,11 +184,14 @@ int Render::ControlWindow() { | ||||
|  | ||||
|   ImGui::Begin("ControlWindow", nullptr, | ||||
|                ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | | ||||
|                    ImGuiWindowFlags_NoScrollbar | | ||||
|                    ImGuiWindowFlags_NoBringToFrontOnFocus); | ||||
|                    ImGuiWindowFlags_NoScrollbar); | ||||
|   ImGui::PopStyleVar(); | ||||
|  | ||||
|   control_winodw_pos_ = ImGui::GetWindowPos(); | ||||
|   SDL_GetMouseState(&mouse_pos_x_, &mouse_pos_y_); | ||||
|   mouse_diff_control_bar_pos_x_ = mouse_pos_x_ - control_winodw_pos_.x; | ||||
|   mouse_diff_control_bar_pos_y_ = mouse_pos_y_ - control_winodw_pos_.y; | ||||
|  | ||||
|   ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); | ||||
|   static bool a, b, c, d, e; | ||||
|   ImGui::SetNextWindowPos( | ||||
| @@ -160,24 +216,5 @@ int Render::ControlWindow() { | ||||
|   ImGui::PopStyleVar(4); | ||||
|   ImGui::PopStyleColor(); | ||||
|  | ||||
|   ImGui::SetNextWindowPos( | ||||
|       ImVec2(0, fullscreen_button_pressed_ ? 0 : title_bar_height_), | ||||
|       ImGuiCond_Always); | ||||
|   ImGui::SetNextWindowSize( | ||||
|       ImVec2(stream_window_width_, | ||||
|              stream_window_height_ - | ||||
|                  (fullscreen_button_pressed_ ? 0 : title_bar_height_)), | ||||
|       ImGuiCond_Always); | ||||
|   ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0)); | ||||
|   ImGui::PushStyleColor(ImGuiCol_Border, | ||||
|                         ImVec4(178 / 255.0f, 178 / 255.0f, 178 / 255.0f, | ||||
|                                fullscreen_button_pressed_ ? 0 : 1.0f)); | ||||
|   ImGui::Begin("VideoBg", nullptr, | ||||
|                ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | | ||||
|                    ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | | ||||
|                    ImGuiWindowFlags_NoBringToFrontOnFocus); | ||||
|   ImGui::PopStyleColor(2); | ||||
|   ImGui::End(); | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
| @@ -657,22 +657,23 @@ int Render::DrawStreamWindow() { | ||||
|   ImGui_ImplSDL2_NewFrame(); | ||||
|   ImGui::NewFrame(); | ||||
|  | ||||
|   ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); | ||||
|   ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); | ||||
|   ImGui::SetNextWindowSize( | ||||
|       ImVec2(stream_window_width_, | ||||
|              fullscreen_button_pressed_ ? 0 : title_bar_height_), | ||||
|       ImGuiCond_Always); | ||||
|   ImGui::Begin("StreamRender", nullptr, | ||||
|                ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | | ||||
|                    ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | | ||||
|                    ImGuiWindowFlags_NoBringToFrontOnFocus); | ||||
|   ImGui::PopStyleColor(); | ||||
|   if (!fullscreen_button_pressed_) { | ||||
|     ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); | ||||
|     ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); | ||||
|     ImGui::SetNextWindowSize( | ||||
|         ImVec2(stream_window_width_, | ||||
|                fullscreen_button_pressed_ ? 0 : title_bar_height_), | ||||
|         ImGuiCond_Always); | ||||
|     ImGui::Begin("StreamRender", nullptr, | ||||
|                  ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | | ||||
|                      ImGuiWindowFlags_NoBringToFrontOnFocus); | ||||
|     ImGui::PopStyleColor(); | ||||
|  | ||||
|   TitleBar(false); | ||||
|   ControlWindow(); | ||||
|     TitleBar(false); | ||||
|     ImGui::End(); | ||||
|   } | ||||
|  | ||||
|   ImGui::End(); | ||||
|   StreamWindow(); | ||||
|  | ||||
|   // Rendering | ||||
|   ImGui::Render(); | ||||
| @@ -854,6 +855,7 @@ int Render::Run() { | ||||
|       } else if (event.window.event == SDL_WINDOWEVENT_RESTORED) { | ||||
|         window_maximized_ = false; | ||||
|       } else if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { | ||||
|         reset_control_bar_pos_ = true; | ||||
|         SDL_GetWindowSize(stream_window_, &stream_window_width_, | ||||
|                           &stream_window_height_); | ||||
|  | ||||
| @@ -865,6 +867,7 @@ int Render::Run() { | ||||
|             stream_window_height_ - | ||||
|             (fullscreen_button_pressed_ ? 0 : title_bar_height_); | ||||
|  | ||||
|         stream_render_rect_last_ = stream_render_rect_; | ||||
|         if (render_area_width < render_area_height * video_ratio) { | ||||
|           stream_render_rect_.x = 0; | ||||
|           stream_render_rect_.y = | ||||
|   | ||||
| @@ -37,6 +37,7 @@ class Render { | ||||
|   int CreateStreamRenderWindow(); | ||||
|   int TitleBar(bool main_window); | ||||
|   int MainWindow(); | ||||
|   int StreamWindow(); | ||||
|   int LocalWindow(); | ||||
|   int RemoteWindow(); | ||||
|   int RecentConnectionsWindow(); | ||||
| @@ -180,8 +181,8 @@ class Render { | ||||
|   int stream_window_height_ = 720; | ||||
|   int stream_window_width_last_ = 1280; | ||||
|   int stream_window_height_last_ = 720; | ||||
|   int main_window_width_before_maximized_ = 640; | ||||
|   int main_window_height_before_maximized_ = 480; | ||||
|   int stream_window_width_before_maximized_ = 1280; | ||||
|   int stream_window_height_before_maximized_ = 720; | ||||
|   int control_window_min_width_ = 20; | ||||
|   int control_window_max_width_ = 200; | ||||
|   int control_window_min_height_ = 40; | ||||
| @@ -209,6 +210,12 @@ class Render { | ||||
|  | ||||
|   int control_bar_pos_x_ = 0; | ||||
|   int control_bar_pos_y_ = 30; | ||||
|   int mouse_diff_control_bar_pos_x_ = 0; | ||||
|   int mouse_diff_control_bar_pos_y_ = 0; | ||||
|   int mouse_pos_x_ = 0; | ||||
|   int mouse_pos_y_ = 0; | ||||
|   int mouse_pos_x_last_ = 0; | ||||
|   int mouse_pos_y_last_ = 0; | ||||
|  | ||||
|   int main_window_width_real_ = 720; | ||||
|   int main_window_height_real_ = 540; | ||||
| @@ -246,6 +253,7 @@ class Render { | ||||
|   // video window | ||||
|   SDL_Texture *stream_texture_ = nullptr; | ||||
|   SDL_Rect stream_render_rect_; | ||||
|   SDL_Rect stream_render_rect_last_; | ||||
|   uint32_t stream_pixformat_ = 0; | ||||
|   std::string host_name_ = ""; | ||||
|  | ||||
| @@ -258,11 +266,9 @@ class Render { | ||||
|   bool exit_ = false; | ||||
|   bool exit_video_window_ = false; | ||||
|   bool connection_established_ = false; | ||||
|   bool control_bar_hovered_ = false; | ||||
|   bool connect_button_pressed_ = false; | ||||
|   bool password_validating_ = false; | ||||
|   uint32_t password_validating_time_ = 0; | ||||
|   bool control_bar_expand_ = true; | ||||
|   bool fullscreen_button_pressed_ = false; | ||||
|   bool net_traffic_stats_button_pressed_ = false; | ||||
|   bool mouse_control_button_pressed_ = false; | ||||
| @@ -288,6 +294,9 @@ class Render { | ||||
|   bool is_client_mode_ = false; | ||||
|   bool is_control_bar_in_left_ = true; | ||||
|   bool is_control_bar_in_top_ = true; | ||||
|   bool control_bar_hovered_ = false; | ||||
|   bool control_bar_expand_ = true; | ||||
|   bool reset_control_bar_pos_ = false; | ||||
|   bool control_window_width_is_changing_ = false; | ||||
|   bool control_window_height_is_changing_ = false; | ||||
|   bool reload_recent_connections_ = true; | ||||
|   | ||||
							
								
								
									
										26
									
								
								src/single_window/stream_window.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/single_window/stream_window.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| #include "localization.h" | ||||
| #include "rd_log.h" | ||||
| #include "render.h" | ||||
|  | ||||
| int Render::StreamWindow() { | ||||
|   ImGui::SetNextWindowPos( | ||||
|       ImVec2(0, fullscreen_button_pressed_ ? 0 : title_bar_height_), | ||||
|       ImGuiCond_Always); | ||||
|   ImGui::SetNextWindowSize( | ||||
|       ImVec2(stream_window_width_, stream_window_height_ - title_bar_height_), | ||||
|       ImGuiCond_Always); | ||||
|   ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1, 1, 1, 0)); | ||||
|   ImGui::PushStyleColor(ImGuiCol_Border, | ||||
|                         ImVec4(178 / 255.0f, 178 / 255.0f, 178 / 255.0f, | ||||
|                                fullscreen_button_pressed_ ? 0 : 1.0f)); | ||||
|   ImGui::Begin("VideoBg", nullptr, | ||||
|                ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | | ||||
|                    ImGuiWindowFlags_NoBringToFrontOnFocus); | ||||
|   ImGui::PopStyleColor(2); | ||||
|  | ||||
|   ControlWindow(); | ||||
|  | ||||
|   ImGui::End(); | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
| @@ -4,17 +4,19 @@ | ||||
| #define BUTTON_PADDING 36.0f | ||||
|  | ||||
| int Render::TitleBar(bool main_window) { | ||||
|   ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(1, 1, 1, 0.0f)); | ||||
|   ImGui::PushStyleColor(ImGuiCol_MenuBarBg, ImVec4(1.0f, 1.0f, 1.0f, 0.0f)); | ||||
|   ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); | ||||
|   ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); | ||||
|   ImGui::SetWindowFontScale(0.8f); | ||||
|   ImGui::BeginChild( | ||||
|       "TitleBar", | ||||
|       main_window ? "MainTitleBar" : "StreamTitleBar", | ||||
|       ImVec2(main_window ? main_window_width_ : stream_window_width_, | ||||
|              title_bar_height_), | ||||
|       ImGuiChildFlags_Border, | ||||
|       ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDecoration | | ||||
|           ImGuiWindowFlags_NoBringToFrontOnFocus); | ||||
|   ImGui::SetWindowFontScale(1.0f); | ||||
|   ImGui::PopStyleColor(); | ||||
|  | ||||
|   ImDrawList* draw_list = ImGui::GetWindowDrawList(); | ||||
|   if (ImGui::BeginMenuBar()) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user