[fix] fix control window position when stream window size changed

This commit is contained in:
dijunkun
2024-11-20 19:17:33 +08:00
parent 0ba12f3ccf
commit 2d2a578800
6 changed files with 135 additions and 54 deletions

View File

@@ -139,11 +139,15 @@ int Render::ControlBar() {
fullscreen_button_pressed_ fullscreen_button_pressed_
? localization::exit_fullscreen[localization_language_index_] ? localization::exit_fullscreen[localization_language_index_]
: localization::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_) { if (fullscreen_button_pressed_) {
SDL_SetWindowFullscreen(main_window_, SDL_WINDOW_FULLSCREEN_DESKTOP); SDL_SetWindowFullscreen(stream_window_, SDL_WINDOW_FULLSCREEN_DESKTOP);
} else { } else {
SDL_SetWindowFullscreen(main_window_, SDL_FALSE); SDL_SetWindowFullscreen(stream_window_, SDL_FALSE);
} }
reset_control_bar_pos_ = true;
} }
ImGui::SameLine(); ImGui::SameLine();

View File

@@ -41,20 +41,71 @@ int Render::ControlWindow() {
ImGui::SetNextWindowSize( ImGui::SetNextWindowSize(
ImVec2(control_window_width_, control_window_height_), ImGuiCond_Always); ImVec2(control_window_width_, control_window_height_), ImGuiCond_Always);
ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_), ImGuiCond_Once); ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_ + 1), ImGuiCond_Once);
if (ImGui::IsMouseReleased(ImGuiPopupFlags_MouseButtonLeft) ||
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_) { control_window_width_is_changing_) {
if (control_winodw_pos_.x <= stream_window_width_ / 2) { if (control_winodw_pos_.x <= stream_window_width_ / 2) {
int pos_x = 0; int pos_x = 0;
int pos_y = int pos_y =
(control_winodw_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 <= control_winodw_pos_.y <=
stream_window_height_ - control_window_height_) stream_window_height_ - control_window_height_)
? control_winodw_pos_.y ? control_winodw_pos_.y
: (control_winodw_pos_.y < : (control_winodw_pos_.y < (fullscreen_button_pressed_
(fullscreen_button_pressed_ ? 0 : title_bar_height_) ? 0
? (fullscreen_button_pressed_ ? 0 : title_bar_height_) : (title_bar_height_ + 1))
? (fullscreen_button_pressed_ ? 0
: (title_bar_height_ + 1))
: (stream_window_height_ - control_window_height_)); : (stream_window_height_ - control_window_height_));
if (control_bar_expand_) { if (control_bar_expand_) {
@@ -78,13 +129,15 @@ int Render::ControlWindow() {
int pos_x = 0; int pos_x = 0;
int pos_y = int pos_y =
(control_winodw_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 <= control_winodw_pos_.y <=
stream_window_height_ - control_window_height_) stream_window_height_ - control_window_height_)
? control_winodw_pos_.y ? control_winodw_pos_.y
: (control_winodw_pos_.y < : (control_winodw_pos_.y < (fullscreen_button_pressed_
(fullscreen_button_pressed_ ? 0 : title_bar_height_) ? 0
? (fullscreen_button_pressed_ ? 0 : title_bar_height_) : (title_bar_height_ + 1))
? (fullscreen_button_pressed_ ? 0
: (title_bar_height_ + 1))
: (stream_window_height_ - control_window_height_)); : (stream_window_height_ - control_window_height_));
if (control_bar_expand_) { if (control_bar_expand_) {
@@ -131,11 +184,14 @@ int Render::ControlWindow() {
ImGui::Begin("ControlWindow", nullptr, ImGui::Begin("ControlWindow", nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollbar);
ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopStyleVar(); ImGui::PopStyleVar();
control_winodw_pos_ = ImGui::GetWindowPos(); 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)); ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
static bool a, b, c, d, e; static bool a, b, c, d, e;
ImGui::SetNextWindowPos( ImGui::SetNextWindowPos(
@@ -160,24 +216,5 @@ int Render::ControlWindow() {
ImGui::PopStyleVar(4); ImGui::PopStyleVar(4);
ImGui::PopStyleColor(); 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; return 0;
} }

View File

@@ -657,6 +657,7 @@ int Render::DrawStreamWindow() {
ImGui_ImplSDL2_NewFrame(); ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
if (!fullscreen_button_pressed_) {
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always); ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
ImGui::SetNextWindowSize( ImGui::SetNextWindowSize(
@@ -664,15 +665,15 @@ int Render::DrawStreamWindow() {
fullscreen_button_pressed_ ? 0 : title_bar_height_), fullscreen_button_pressed_ ? 0 : title_bar_height_),
ImGuiCond_Always); ImGuiCond_Always);
ImGui::Begin("StreamRender", nullptr, ImGui::Begin("StreamRender", nullptr,
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoBringToFrontOnFocus); ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PopStyleColor(); ImGui::PopStyleColor();
TitleBar(false); TitleBar(false);
ControlWindow();
ImGui::End(); ImGui::End();
}
StreamWindow();
// Rendering // Rendering
ImGui::Render(); ImGui::Render();
@@ -854,6 +855,7 @@ int Render::Run() {
} else if (event.window.event == SDL_WINDOWEVENT_RESTORED) { } else if (event.window.event == SDL_WINDOWEVENT_RESTORED) {
window_maximized_ = false; window_maximized_ = false;
} else if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { } else if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
reset_control_bar_pos_ = true;
SDL_GetWindowSize(stream_window_, &stream_window_width_, SDL_GetWindowSize(stream_window_, &stream_window_width_,
&stream_window_height_); &stream_window_height_);
@@ -865,6 +867,7 @@ int Render::Run() {
stream_window_height_ - stream_window_height_ -
(fullscreen_button_pressed_ ? 0 : title_bar_height_); (fullscreen_button_pressed_ ? 0 : title_bar_height_);
stream_render_rect_last_ = stream_render_rect_;
if (render_area_width < render_area_height * video_ratio) { if (render_area_width < render_area_height * video_ratio) {
stream_render_rect_.x = 0; stream_render_rect_.x = 0;
stream_render_rect_.y = stream_render_rect_.y =

View File

@@ -37,6 +37,7 @@ class Render {
int CreateStreamRenderWindow(); int CreateStreamRenderWindow();
int TitleBar(bool main_window); int TitleBar(bool main_window);
int MainWindow(); int MainWindow();
int StreamWindow();
int LocalWindow(); int LocalWindow();
int RemoteWindow(); int RemoteWindow();
int RecentConnectionsWindow(); int RecentConnectionsWindow();
@@ -180,8 +181,8 @@ class Render {
int stream_window_height_ = 720; int stream_window_height_ = 720;
int stream_window_width_last_ = 1280; int stream_window_width_last_ = 1280;
int stream_window_height_last_ = 720; int stream_window_height_last_ = 720;
int main_window_width_before_maximized_ = 640; int stream_window_width_before_maximized_ = 1280;
int main_window_height_before_maximized_ = 480; int stream_window_height_before_maximized_ = 720;
int control_window_min_width_ = 20; int control_window_min_width_ = 20;
int control_window_max_width_ = 200; int control_window_max_width_ = 200;
int control_window_min_height_ = 40; int control_window_min_height_ = 40;
@@ -209,6 +210,12 @@ class Render {
int control_bar_pos_x_ = 0; int control_bar_pos_x_ = 0;
int control_bar_pos_y_ = 30; 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_width_real_ = 720;
int main_window_height_real_ = 540; int main_window_height_real_ = 540;
@@ -246,6 +253,7 @@ class Render {
// video window // video window
SDL_Texture *stream_texture_ = nullptr; SDL_Texture *stream_texture_ = nullptr;
SDL_Rect stream_render_rect_; SDL_Rect stream_render_rect_;
SDL_Rect stream_render_rect_last_;
uint32_t stream_pixformat_ = 0; uint32_t stream_pixformat_ = 0;
std::string host_name_ = ""; std::string host_name_ = "";
@@ -258,11 +266,9 @@ class Render {
bool exit_ = false; bool exit_ = false;
bool exit_video_window_ = false; bool exit_video_window_ = false;
bool connection_established_ = false; bool connection_established_ = false;
bool control_bar_hovered_ = false;
bool connect_button_pressed_ = false; bool connect_button_pressed_ = false;
bool password_validating_ = false; bool password_validating_ = false;
uint32_t password_validating_time_ = 0; uint32_t password_validating_time_ = 0;
bool control_bar_expand_ = true;
bool fullscreen_button_pressed_ = false; bool fullscreen_button_pressed_ = false;
bool net_traffic_stats_button_pressed_ = false; bool net_traffic_stats_button_pressed_ = false;
bool mouse_control_button_pressed_ = false; bool mouse_control_button_pressed_ = false;
@@ -288,6 +294,9 @@ class Render {
bool is_client_mode_ = false; bool is_client_mode_ = false;
bool is_control_bar_in_left_ = true; bool is_control_bar_in_left_ = true;
bool is_control_bar_in_top_ = 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_width_is_changing_ = false;
bool control_window_height_is_changing_ = false; bool control_window_height_is_changing_ = false;
bool reload_recent_connections_ = true; bool reload_recent_connections_ = true;

View 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;
}

View File

@@ -4,17 +4,19 @@
#define BUTTON_PADDING 36.0f #define BUTTON_PADDING 36.0f
int Render::TitleBar(bool main_window) { 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::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
ImGui::SetWindowFontScale(0.8f); ImGui::SetWindowFontScale(0.8f);
ImGui::BeginChild( ImGui::BeginChild(
"TitleBar", main_window ? "MainTitleBar" : "StreamTitleBar",
ImVec2(main_window ? main_window_width_ : stream_window_width_, ImVec2(main_window ? main_window_width_ : stream_window_width_,
title_bar_height_), title_bar_height_),
ImGuiChildFlags_Border, ImGuiChildFlags_Border,
ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_NoBringToFrontOnFocus); ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::SetWindowFontScale(1.0f); ImGui::SetWindowFontScale(1.0f);
ImGui::PopStyleColor();
ImDrawList* draw_list = ImGui::GetWindowDrawList(); ImDrawList* draw_list = ImGui::GetWindowDrawList();
if (ImGui::BeginMenuBar()) { if (ImGui::BeginMenuBar()) {