[feat] use SubStreamWindowProperties to store sub stream properties

This commit is contained in:
dijunkun
2024-12-02 17:30:51 +08:00
parent 418ab7a1d2
commit 011919d0e7
10 changed files with 447 additions and 499 deletions

View File

@@ -1,33 +1,41 @@
#include "rd_log.h"
#include "render.h"
int Render::ControlWindow() {
double time_duration = ImGui::GetTime() - control_bar_button_pressed_time_;
if (control_window_width_is_changing_) {
if (control_bar_expand_) {
control_window_width_ =
(float)(control_window_min_width_ +
(control_window_max_width_ - control_window_min_width_) * 4 *
time_duration);
int Render::ControlWindow(SubStreamWindowProperties &properties) {
double time_duration =
ImGui::GetTime() - properties.control_bar_button_pressed_time_;
if (properties.control_window_width_is_changing_) {
if (properties.control_bar_expand_) {
properties.control_window_width_ =
(float)(properties.control_window_min_width_ +
(properties.control_window_max_width_ -
properties.control_window_min_width_) *
4 * time_duration);
} else {
control_window_width_ =
(float)(control_window_max_width_ -
(control_window_max_width_ - control_window_min_width_) * 4 *
time_duration);
properties.control_window_width_ =
(float)(properties.control_window_max_width_ -
(properties.control_window_max_width_ -
properties.control_window_min_width_) *
4 * time_duration);
}
}
time_duration = ImGui::GetTime() - net_traffic_stats_button_pressed_time_;
if (control_window_height_is_changing_) {
if (control_bar_expand_ && net_traffic_stats_button_pressed_) {
control_window_height_ =
(float)(control_window_min_height_ +
(control_window_max_height_ - control_window_min_height_) *
time_duration =
ImGui::GetTime() - properties.net_traffic_stats_button_pressed_time_;
if (properties.control_window_height_is_changing_) {
if (properties.control_bar_expand_ &&
properties.net_traffic_stats_button_pressed_) {
properties.control_window_height_ =
(float)(properties.control_window_min_height_ +
(properties.control_window_max_height_ -
properties.control_window_min_height_) *
4 * time_duration);
} else if (control_bar_expand_ && !net_traffic_stats_button_pressed_) {
control_window_height_ =
(float)(control_window_max_height_ -
(control_window_max_height_ - control_window_min_height_) *
} else if (properties.control_bar_expand_ &&
!properties.net_traffic_stats_button_pressed_) {
properties.control_window_height_ =
(float)(properties.control_window_max_height_ -
(properties.control_window_max_height_ -
properties.control_window_min_height_) *
4 * time_duration);
}
}
@@ -39,155 +47,189 @@ int Render::ControlWindow() {
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 10.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
ImGui::SetNextWindowSize(
ImVec2(control_window_width_, control_window_height_), ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(properties.control_window_width_,
properties.control_window_height_),
ImGuiCond_Always);
if (0 == control_winodw_pos_.x && 0 == control_winodw_pos_.y) {
if (0 == properties.control_winodw_pos_.x &&
0 == properties.control_winodw_pos_.y) {
ImGui::SetNextWindowPos(ImVec2(0, title_bar_height_ + 1), ImGuiCond_Once);
}
if (reset_control_bar_pos_) {
if (properties.reset_control_bar_pos_) {
float 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);
new_control_window_pos_x = properties.control_winodw_pos_.x;
if (properties.control_winodw_pos_.y <
properties.stream_render_rect_last_.y) {
new_control_window_pos_y = properties.stream_render_rect_.y -
(properties.stream_render_rect_last_.y -
properties.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 (properties.control_winodw_pos_.y +
properties.control_window_height_ >
properties.stream_render_rect_last_.y +
properties.stream_render_rect_last_.h) {
new_control_window_pos_y = properties.stream_render_rect_.y +
properties.stream_render_rect_.h +
(properties.control_winodw_pos_.y -
properties.stream_render_rect_last_.y -
properties.stream_render_rect_last_.h);
if (new_control_window_pos_y > properties.sub_stream_window_height_ -
properties.control_window_height_) {
new_control_window_pos_y = properties.sub_stream_window_height_ -
properties.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 if (properties.control_winodw_pos_.y +
properties.control_window_height_ ==
properties.stream_render_rect_last_.y +
properties.stream_render_rect_last_.h) {
new_control_window_pos_y = properties.stream_render_rect_.y +
properties.stream_render_rect_.h -
properties.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;
(properties.control_winodw_pos_.y -
properties.stream_render_rect_last_.y) /
(float)(properties.stream_render_rect_last_.h) *
properties.stream_render_rect_.h +
properties.stream_render_rect_.y;
}
ImGui::SetNextWindowPos(
ImVec2(new_control_window_pos_x, new_control_window_pos_y),
ImGuiCond_Always);
if (0 != mouse_diff_control_bar_pos_x_ &&
0 != mouse_diff_control_bar_pos_y_) {
if (0 != properties.mouse_diff_control_bar_pos_x_ &&
0 != properties.mouse_diff_control_bar_pos_y_) {
// set cursor pos
new_cursor_pos_x =
new_control_window_pos_x + mouse_diff_control_bar_pos_x_;
new_control_window_pos_x + properties.mouse_diff_control_bar_pos_x_;
new_cursor_pos_y =
new_control_window_pos_y + mouse_diff_control_bar_pos_y_;
new_control_window_pos_y + properties.mouse_diff_control_bar_pos_y_;
SDL_WarpMouseInWindow(stream_window_, (int)new_cursor_pos_x,
(int)new_cursor_pos_y);
}
reset_control_bar_pos_ = false;
} else if (!reset_control_bar_pos_ &&
properties.reset_control_bar_pos_ = false;
} else if (!properties.reset_control_bar_pos_ &&
ImGui::IsMouseReleased(ImGuiPopupFlags_MouseButtonLeft) ||
control_window_width_is_changing_) {
if (control_winodw_pos_.x <= stream_window_width_ / 2) {
properties.control_window_width_is_changing_) {
if (properties.control_winodw_pos_.x <=
properties.sub_stream_window_width_ / 2) {
float pos_x = 0;
float pos_y =
(control_winodw_pos_.y >=
(properties.control_winodw_pos_.y >=
(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_ + 1))
properties.control_winodw_pos_.y <=
properties.sub_stream_window_height_ -
properties.control_window_height_)
? properties.control_winodw_pos_.y
: (properties.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_));
: (properties.sub_stream_window_height_ -
properties.control_window_height_));
if (control_bar_expand_) {
if (control_window_width_ >= control_window_max_width_) {
control_window_width_ = control_window_max_width_;
control_window_width_is_changing_ = false;
if (properties.control_bar_expand_) {
if (properties.control_window_width_ >=
properties.control_window_max_width_) {
properties.control_window_width_ =
properties.control_window_max_width_;
properties.control_window_width_is_changing_ = false;
} else {
control_window_width_is_changing_ = true;
properties.control_window_width_is_changing_ = true;
}
} else {
if (control_window_width_ <= control_window_min_width_) {
control_window_width_ = control_window_min_width_;
control_window_width_is_changing_ = false;
if (properties.control_window_width_ <=
properties.control_window_min_width_) {
properties.control_window_width_ =
properties.control_window_min_width_;
properties.control_window_width_is_changing_ = false;
} else {
control_window_width_is_changing_ = true;
properties.control_window_width_is_changing_ = true;
}
}
ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y), ImGuiCond_Always);
is_control_bar_in_left_ = true;
} else if (control_winodw_pos_.x > stream_window_width_ / 2) {
properties.is_control_bar_in_left_ = true;
} else if (properties.control_winodw_pos_.x >
properties.sub_stream_window_width_ / 2) {
float pos_x = 0;
float pos_y =
(control_winodw_pos_.y >=
(properties.control_winodw_pos_.y >=
(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_ + 1))
properties.control_winodw_pos_.y <=
properties.sub_stream_window_height_ -
properties.control_window_height_)
? properties.control_winodw_pos_.y
: (properties.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_));
: (properties.sub_stream_window_height_ -
properties.control_window_height_));
if (control_bar_expand_) {
if (control_window_width_ >= control_window_max_width_) {
control_window_width_ = control_window_max_width_;
control_window_width_is_changing_ = false;
pos_x = stream_window_width_ - control_window_max_width_;
if (properties.control_bar_expand_) {
if (properties.control_window_width_ >=
properties.control_window_max_width_) {
properties.control_window_width_ =
properties.control_window_max_width_;
properties.control_window_width_is_changing_ = false;
pos_x = properties.sub_stream_window_width_ -
properties.control_window_max_width_;
} else {
control_window_width_is_changing_ = true;
pos_x = stream_window_width_ - control_window_width_;
properties.control_window_width_is_changing_ = true;
pos_x = properties.sub_stream_window_width_ -
properties.control_window_width_;
}
} else {
if (control_window_width_ <= control_window_min_width_) {
control_window_width_ = control_window_min_width_;
control_window_width_is_changing_ = false;
pos_x = stream_window_width_ - control_window_min_width_;
if (properties.control_window_width_ <=
properties.control_window_min_width_) {
properties.control_window_width_ =
properties.control_window_min_width_;
properties.control_window_width_is_changing_ = false;
pos_x = properties.sub_stream_window_width_ -
properties.control_window_min_width_;
} else {
control_window_width_is_changing_ = true;
pos_x = stream_window_width_ - control_window_width_;
properties.control_window_width_is_changing_ = true;
pos_x = properties.sub_stream_window_width_ -
properties.control_window_width_;
}
}
ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y), ImGuiCond_Always);
is_control_bar_in_left_ = false;
properties.is_control_bar_in_left_ = false;
}
}
if (control_bar_expand_ && control_window_height_is_changing_) {
if (net_traffic_stats_button_pressed_) {
if (control_window_height_ >= control_window_max_height_) {
control_window_height_ = control_window_max_height_;
control_window_height_is_changing_ = false;
if (properties.control_bar_expand_ &&
properties.control_window_height_is_changing_) {
if (properties.net_traffic_stats_button_pressed_) {
if (properties.control_window_height_ >=
properties.control_window_max_height_) {
properties.control_window_height_ =
properties.control_window_max_height_;
properties.control_window_height_is_changing_ = false;
} else {
control_window_height_is_changing_ = true;
properties.control_window_height_is_changing_ = true;
}
} else {
if (control_window_height_ <= control_window_min_height_) {
control_window_height_ = control_window_min_height_;
control_window_height_is_changing_ = false;
if (properties.control_window_height_ <=
properties.control_window_min_height_) {
properties.control_window_height_ =
properties.control_window_min_height_;
properties.control_window_height_is_changing_ = false;
} else {
control_window_height_is_changing_ = true;
properties.control_window_height_is_changing_ = true;
}
}
}
@@ -197,29 +239,32 @@ int Render::ControlWindow() {
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;
properties.control_winodw_pos_ = ImGui::GetWindowPos();
SDL_GetMouseState(&properties.mouse_pos_x_, &properties.mouse_pos_y_);
properties.mouse_diff_control_bar_pos_x_ =
properties.mouse_pos_x_ - properties.control_winodw_pos_.x;
properties.mouse_diff_control_bar_pos_y_ =
properties.mouse_pos_y_ - properties.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(
ImVec2(is_control_bar_in_left_
? control_winodw_pos_.x - control_window_width_
: control_winodw_pos_.x,
control_winodw_pos_.y),
ImGuiCond_Always);
ImGui::SetNextWindowPos(ImVec2(properties.is_control_bar_in_left_
? properties.control_winodw_pos_.x -
properties.control_window_width_
: properties.control_winodw_pos_.x,
properties.control_winodw_pos_.y),
ImGuiCond_Always);
ImGui::SetWindowFontScale(0.5f);
ImGui::BeginChild("ControlBar",
ImVec2(control_window_width_ * 2, control_window_height_),
ImVec2(properties.control_window_width_ * 2,
properties.control_window_height_),
ImGuiChildFlags_Border, ImGuiWindowFlags_NoDecoration);
ImGui::SetWindowFontScale(1.0f);
ImGui::PopStyleColor();
ControlBar();
control_bar_hovered_ = ImGui::IsWindowHovered();
ControlBar(properties);
properties.control_bar_hovered_ = ImGui::IsWindowHovered();
ImGui::EndChild();
ImGui::End();