[fix] fix connection status window gui display

This commit is contained in:
dijunkun
2025-08-19 17:47:09 +08:00
parent 6f8fd6a030
commit 374453775f
5 changed files with 161 additions and 158 deletions

View File

@@ -5,175 +5,167 @@
bool Render::ConnectionStatusWindow( bool Render::ConnectionStatusWindow(
std::shared_ptr<SubStreamWindowProperties> &props) { std::shared_ptr<SubStreamWindowProperties> &props) {
if (show_connection_status_window_) { const ImGuiViewport *viewport = ImGui::GetMainViewport();
const ImGuiViewport *viewport = ImGui::GetMainViewport(); bool ret_flag = false;
ImGui::SetNextWindowPos(ImVec2((viewport->WorkSize.x - viewport->WorkPos.x -
connection_status_window_width_) /
2,
(viewport->WorkSize.y - viewport->WorkPos.y -
connection_status_window_height_) /
2));
ImGui::SetNextWindowPos(ImVec2((viewport->WorkSize.x - viewport->WorkPos.x - ImGui::SetNextWindowSize(ImVec2(connection_status_window_width_,
connection_status_window_width_) / connection_status_window_height_));
2,
(viewport->WorkSize.y - viewport->WorkPos.y -
connection_status_window_height_) /
2));
ImGui::SetNextWindowSize(ImVec2(connection_status_window_width_, ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
connection_status_window_height_));
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0, 1.0, 1.0, 1.0));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0, 1.0, 1.0, 1.0)); ImGui::Begin("ConnectionStatusWindow", nullptr,
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f); ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f); ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoSavedSettings);
ImGui::PopStyleVar(2);
ImGui::PopStyleColor();
ImGui::Begin("ConnectionStatusWindow", nullptr, ImGui::SetWindowFontScale(0.5f);
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | std::string text;
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoSavedSettings);
ImGui::PopStyleVar(2);
ImGui::PopStyleColor();
ImGui::SetWindowFontScale(0.5f); if (ConnectionStatus::Connecting == props->connection_status_) {
std::string text; text = localization::p2p_connecting[localization_language_index_];
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
if (ConnectionStatus::Connecting == props->connection_status_) { ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
text = localization::p2p_connecting[localization_language_index_]; } else if (ConnectionStatus::Connected == props->connection_status_) {
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); text = localization::p2p_connected[localization_language_index_];
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
} else if (ConnectionStatus::Connected == props->connection_status_) { ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
text = localization::p2p_connected[localization_language_index_]; // ok
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); if (ImGui::Button(localization::ok[localization_language_index_].c_str()) ||
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); ImGui::IsKeyPressed(ImGuiKey_Enter) ||
// ok ImGui::IsKeyPressed(ImGuiKey_Escape)) {
if (ImGui::Button( show_connection_status_window_ = false;
localization::ok[localization_language_index_].c_str()) || }
ImGui::IsKeyPressed(ImGuiKey_Enter) || } else if (ConnectionStatus::Disconnected == props->connection_status_) {
ImGui::IsKeyPressed(ImGuiKey_Escape)) { text = localization::p2p_disconnected[localization_language_index_];
show_connection_status_window_ = false; ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// ok
if (ImGui::Button(localization::ok[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Enter) ||
ImGui::IsKeyPressed(ImGuiKey_Escape)) {
show_connection_status_window_ = false;
}
} else if (ConnectionStatus::Failed == props->connection_status_) {
text = localization::p2p_failed[localization_language_index_];
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// ok
if (ImGui::Button(localization::ok[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Enter) ||
ImGui::IsKeyPressed(ImGuiKey_Escape)) {
show_connection_status_window_ = false;
}
} else if (ConnectionStatus::Closed == props->connection_status_) {
text = localization::p2p_closed[localization_language_index_];
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// ok
if (ImGui::Button(localization::ok[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Enter) ||
ImGui::IsKeyPressed(ImGuiKey_Escape)) {
show_connection_status_window_ = false;
}
} else if (ConnectionStatus::IncorrectPassword == props->connection_status_) {
if (!password_validating_) {
if (password_validating_time_ == 1) {
text = localization::input_password[localization_language_index_];
} else {
text = localization::reinput_password[localization_language_index_];
} }
} else if (ConnectionStatus::Disconnected == props->connection_status_) {
text = localization::p2p_disconnected[localization_language_index_]; auto window_width = ImGui::GetWindowSize().x;
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); auto window_height = ImGui::GetWindowSize().y;
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); ImGui::SetCursorPosX((window_width - IPUT_WINDOW_WIDTH / 2) * 0.5f);
// ok ImGui::SetCursorPosY(window_height * 0.4f);
if (ImGui::Button( ImGui::SetNextItemWidth(IPUT_WINDOW_WIDTH / 2);
localization::ok[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f);
ImGui::IsKeyPressed(ImGuiKey_Escape)) {
show_connection_status_window_ = false; if (focus_on_input_widget_) {
ImGui::SetKeyboardFocusHere();
focus_on_input_widget_ = false;
} }
} else if (ConnectionStatus::Failed == props->connection_status_) {
text = localization::p2p_failed[localization_language_index_];
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// ok
if (ImGui::Button(
localization::ok[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Enter) ||
ImGui::IsKeyPressed(ImGuiKey_Escape)) {
show_connection_status_window_ = false;
}
} else if (ConnectionStatus::Closed == props->connection_status_) {
text = localization::p2p_closed[localization_language_index_];
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// ok
if (ImGui::Button(
localization::ok[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Enter) ||
ImGui::IsKeyPressed(ImGuiKey_Escape)) {
show_connection_status_window_ = false;
}
} else if (ConnectionStatus::IncorrectPassword ==
props->connection_status_) {
if (!password_validating_) {
if (password_validating_time_ == 1) {
text = localization::input_password[localization_language_index_];
} else {
text = localization::reinput_password[localization_language_index_];
}
auto window_width = ImGui::GetWindowSize().x; ImGui::InputText("##password", props->remote_password_,
auto window_height = ImGui::GetWindowSize().y; IM_ARRAYSIZE(props->remote_password_),
ImGui::SetCursorPosX((window_width - IPUT_WINDOW_WIDTH / 2) * 0.5f); ImGuiInputTextFlags_CharsNoBlank);
ImGui::SetCursorPosY(window_height * 0.4f);
ImGui::SetNextItemWidth(IPUT_WINDOW_WIDTH / 2);
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); ImGui::SetWindowFontScale(0.4f);
if (focus_on_input_widget_) { ImVec2 text_size = ImGui::CalcTextSize(
ImGui::SetKeyboardFocusHere(); localization::remember_password[localization_language_index_]
focus_on_input_widget_ = false; .c_str());
} ImGui::SetCursorPosX((window_width - text_size.x) * 0.5f - 13.0f);
ImGui::Checkbox(
localization::remember_password[localization_language_index_].c_str(),
&(props->remember_password_));
ImGui::SetWindowFontScale(0.5f);
ImGui::PopStyleVar();
ImGui::InputText("##password", props->remote_password_, ImGui::SetCursorPosX(window_width * 0.315f);
IM_ARRAYSIZE(props->remote_password_), ImGui::SetCursorPosY(window_height * 0.75f);
ImGuiInputTextFlags_CharsNoBlank);
ImGui::SetWindowFontScale(0.4f);
ImVec2 text_size = ImGui::CalcTextSize(
localization::remember_password[localization_language_index_]
.c_str());
ImGui::SetCursorPosX((window_width - text_size.x) * 0.5f - 13.0f);
ImGui::Checkbox(
localization::remember_password[localization_language_index_]
.c_str(),
&(props->remember_password_));
ImGui::SetWindowFontScale(0.5f);
ImGui::PopStyleVar();
ImGui::SetCursorPosX(window_width * 0.315f);
ImGui::SetCursorPosY(window_height * 0.75f);
// ok
if (ImGui::Button(
localization::ok[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Enter)) {
show_connection_status_window_ = true;
password_validating_ = true;
props->rejoin_ = true;
need_to_rejoin_ = true;
focus_on_input_widget_ = true;
}
ImGui::SameLine();
// cancel
if (ImGui::Button(
localization::cancel[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Escape)) {
memset(props->remote_password_, 0, sizeof(props->remote_password_));
show_connection_status_window_ = false;
focus_on_input_widget_ = true;
}
} else if (password_validating_) {
text = localization::validate_password[localization_language_index_];
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
}
} else if (ConnectionStatus::NoSuchTransmissionId ==
props->connection_status_) {
text = localization::no_such_id[localization_language_index_];
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// ok // ok
if (ImGui::Button( if (ImGui::Button(
localization::ok[localization_language_index_].c_str()) || localization::ok[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Enter)) { ImGui::IsKeyPressed(ImGuiKey_Enter)) {
show_connection_status_window_ = false; show_connection_status_window_ = true;
re_enter_remote_id_ = true; password_validating_ = true;
DestroyPeer(&props->peer_); props->rejoin_ = true;
return true; need_to_rejoin_ = true;
focus_on_input_widget_ = true;
} }
ImGui::SameLine();
// cancel
if (ImGui::Button(
localization::cancel[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Escape)) {
memset(props->remote_password_, 0, sizeof(props->remote_password_));
show_connection_status_window_ = false;
focus_on_input_widget_ = true;
}
} else if (password_validating_) {
text = localization::validate_password[localization_language_index_];
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
}
} else if (ConnectionStatus::NoSuchTransmissionId ==
props->connection_status_) {
text = localization::no_such_id[localization_language_index_];
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// ok
if (ImGui::Button(localization::ok[localization_language_index_].c_str()) ||
ImGui::IsKeyPressed(ImGuiKey_Enter)) {
show_connection_status_window_ = false;
re_enter_remote_id_ = true;
DestroyPeer(&props->peer_);
ret_flag = true;
} }
auto window_width = ImGui::GetWindowSize().x;
auto window_height = ImGui::GetWindowSize().y;
auto text_width = ImGui::CalcTextSize(text.c_str()).x;
ImGui::SetCursorPosX((window_width - text_width) * 0.5f);
ImGui::SetCursorPosY(window_height * 0.2f);
ImGui::Text("%s", text.c_str());
ImGui::SetWindowFontScale(1.0f);
ImGui::End();
ImGui::PopStyleVar();
} }
return false;
auto window_width = ImGui::GetWindowSize().x;
auto window_height = ImGui::GetWindowSize().y;
auto text_width = ImGui::CalcTextSize(text.c_str()).x;
ImGui::SetCursorPosX((window_width - text_width) * 0.5f);
ImGui::SetCursorPosY(window_height * 0.2f);
ImGui::Text("%s", text.c_str());
ImGui::SetWindowFontScale(1.0f);
ImGui::End();
ImGui::PopStyleVar();
return ret_flag;
} }

View File

@@ -29,12 +29,19 @@ int Render::MainWindow() {
RecentConnectionsWindow(); RecentConnectionsWindow();
StatusBar(); StatusBar();
for (auto it = client_properties_.begin(); it != client_properties_.end();) { if (show_connection_status_window_) {
auto& props = it->second; for (auto it = client_properties_.begin();
if (ConnectionStatusWindow(props)) { it != client_properties_.end();) {
it = client_properties_.erase(it); auto& props = it->second;
} else { if (focused_remote_id_ == props->remote_id_) {
++it; if (ConnectionStatusWindow(props)) {
it = client_properties_.erase(it);
} else {
++it;
}
} else {
++it;
}
} }
} }

View File

@@ -132,6 +132,7 @@ static int InputTextCallback(ImGuiInputTextCallbackData *data) {
int Render::ConnectTo(const std::string &remote_id, const char *password, int Render::ConnectTo(const std::string &remote_id, const char *password,
bool remember_password) { bool remember_password) {
LOG_INFO("Connect to [{}]", remote_id); LOG_INFO("Connect to [{}]", remote_id);
focused_remote_id_ = remote_id;
if (client_properties_.find(remote_id) == client_properties_.end()) { if (client_properties_.find(remote_id) == client_properties_.end()) {
client_properties_[remote_id] = client_properties_[remote_id] =

View File

@@ -343,6 +343,7 @@ class Render {
bool need_to_rejoin_ = false; bool need_to_rejoin_ = false;
bool just_created_ = false; bool just_created_ = false;
std::string controlled_remote_id_ = ""; std::string controlled_remote_id_ = "";
std::string focused_remote_id_ = "";
bool need_to_send_host_info_ = false; bool need_to_send_host_info_ = false;
SDL_Event last_mouse_event; SDL_Event last_mouse_event;

View File

@@ -114,6 +114,8 @@ int Render::StreamWindow() {
ControlWindow(props); ControlWindow(props);
focused_remote_id_ = props->remote_id_;
if (!props->peer_) { if (!props->peer_) {
it = client_properties_.erase(it); it = client_properties_.erase(it);
if (client_properties_.empty()) { if (client_properties_.empty()) {