mirror of
				https://github.com/kunkundi/crossdesk.git
				synced 2025-10-26 20:25:34 +08:00 
			
		
		
		
	[feat] use SubStreamWindowProperties to store sub stream properties
This commit is contained in:
		| @@ -3,7 +3,7 @@ | ||||
| #include "rd_log.h" | ||||
| #include "render.h" | ||||
|  | ||||
| int Render::ConnectionStatusWindow() { | ||||
| int Render::ConnectionStatusWindow(SubStreamWindowProperties &properties) { | ||||
|   if (show_connection_status_window_) { | ||||
|     const ImGuiViewport *viewport = ImGui::GetMainViewport(); | ||||
|  | ||||
| @@ -33,11 +33,11 @@ int Render::ConnectionStatusWindow() { | ||||
|     ImGui::SetWindowFontScale(0.5f); | ||||
|     std::string text; | ||||
|  | ||||
|     if (ConnectionStatus::Connecting == connection_status_) { | ||||
|     if (ConnectionStatus::Connecting == properties.connection_status_) { | ||||
|       text = localization::p2p_connecting[localization_language_index_]; | ||||
|       ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); | ||||
|       ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); | ||||
|     } else if (ConnectionStatus::Connected == connection_status_) { | ||||
|     } else if (ConnectionStatus::Connected == properties.connection_status_) { | ||||
|       text = localization::p2p_connected[localization_language_index_]; | ||||
|       ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); | ||||
|       ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); | ||||
| @@ -48,7 +48,8 @@ int Render::ConnectionStatusWindow() { | ||||
|           ImGui::IsKeyPressed(ImGuiKey_Escape)) { | ||||
|         show_connection_status_window_ = false; | ||||
|       } | ||||
|     } else if (ConnectionStatus::Disconnected == connection_status_) { | ||||
|     } else if (ConnectionStatus::Disconnected == | ||||
|                properties.connection_status_) { | ||||
|       text = localization::p2p_disconnected[localization_language_index_]; | ||||
|       ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); | ||||
|       ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); | ||||
| @@ -59,7 +60,7 @@ int Render::ConnectionStatusWindow() { | ||||
|           ImGui::IsKeyPressed(ImGuiKey_Escape)) { | ||||
|         show_connection_status_window_ = false; | ||||
|       } | ||||
|     } else if (ConnectionStatus::Failed == connection_status_) { | ||||
|     } else if (ConnectionStatus::Failed == properties.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); | ||||
| @@ -70,7 +71,7 @@ int Render::ConnectionStatusWindow() { | ||||
|           ImGui::IsKeyPressed(ImGuiKey_Escape)) { | ||||
|         show_connection_status_window_ = false; | ||||
|       } | ||||
|     } else if (ConnectionStatus::Closed == connection_status_) { | ||||
|     } else if (ConnectionStatus::Closed == properties.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); | ||||
| @@ -81,7 +82,8 @@ int Render::ConnectionStatusWindow() { | ||||
|           ImGui::IsKeyPressed(ImGuiKey_Escape)) { | ||||
|         show_connection_status_window_ = false; | ||||
|       } | ||||
|     } else if (ConnectionStatus::IncorrectPassword == connection_status_) { | ||||
|     } else if (ConnectionStatus::IncorrectPassword == | ||||
|                properties.connection_status_) { | ||||
|       if (!password_validating_) { | ||||
|         if (password_validating_time_ == 1) { | ||||
|           text = localization::input_password[localization_language_index_]; | ||||
| @@ -145,7 +147,8 @@ int Render::ConnectionStatusWindow() { | ||||
|         ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7); | ||||
|         ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3); | ||||
|       } | ||||
|     } else if (ConnectionStatus::NoSuchTransmissionId == connection_status_) { | ||||
|     } else if (ConnectionStatus::NoSuchTransmissionId == | ||||
|                properties.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); | ||||
|   | ||||
| @@ -29,42 +29,46 @@ int LossRateDisplay(float loss_rate) { | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
| int Render::ControlBar() { | ||||
| int Render::ControlBar(SubStreamWindowProperties& properties) { | ||||
|   ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); | ||||
|  | ||||
|   ImVec2 mouse_button_pos = ImVec2(0, 0); | ||||
|   if (control_bar_expand_) { | ||||
|     ImGui::SetCursorPosX( | ||||
|         is_control_bar_in_left_ ? (control_window_width_ + 5.0f) : 38.0f); | ||||
|   if (properties.control_bar_expand_) { | ||||
|     ImGui::SetCursorPosX(properties.is_control_bar_in_left_ | ||||
|                              ? (properties.control_window_width_ + 5.0f) | ||||
|                              : 38.0f); | ||||
|     // mouse control button | ||||
|     ImDrawList* draw_list = ImGui::GetWindowDrawList(); | ||||
|  | ||||
|     if (is_control_bar_in_left_) { | ||||
|       draw_list->AddLine( | ||||
|           ImVec2(ImGui::GetCursorScreenPos().x - 5.0f, | ||||
|     if (properties.is_control_bar_in_left_) { | ||||
|       draw_list->AddLine(ImVec2(ImGui::GetCursorScreenPos().x - 5.0f, | ||||
|                                 ImGui::GetCursorScreenPos().y - 7.0f), | ||||
|                          ImVec2(ImGui::GetCursorScreenPos().x - 5.0f, | ||||
|                  ImGui::GetCursorScreenPos().y - 7.0f + control_window_height_), | ||||
|                                 ImGui::GetCursorScreenPos().y - 7.0f + | ||||
|                                     properties.control_window_height_), | ||||
|                          IM_COL32(178, 178, 178, 255), 1.0f); | ||||
|     } | ||||
|  | ||||
|     mouse_button_pos = ImGui::GetCursorScreenPos(); | ||||
|     float disable_mouse_x = ImGui::GetCursorScreenPos().x + 4.0f; | ||||
|     float disable_mouse_y = ImGui::GetCursorScreenPos().y + 4.0f; | ||||
|     std::string mouse = mouse_control_button_pressed_ ? ICON_FA_COMPUTER_MOUSE | ||||
|     std::string mouse = properties.mouse_control_button_pressed_ | ||||
|                             ? ICON_FA_COMPUTER_MOUSE | ||||
|                             : ICON_FA_COMPUTER_MOUSE; | ||||
|     if (ImGui::Button(mouse.c_str(), ImVec2(25, 25))) { | ||||
|       if (connection_established_) { | ||||
|         control_mouse_ = !control_mouse_; | ||||
|         start_keyboard_capturer_ = !start_keyboard_capturer_; | ||||
|         mouse_control_button_pressed_ = !mouse_control_button_pressed_; | ||||
|         mouse_control_button_label_ = | ||||
|             mouse_control_button_pressed_ | ||||
|       if (properties.connection_established_) { | ||||
|         properties.control_mouse_ = !properties.control_mouse_; | ||||
|         properties.start_keyboard_capturer_ = | ||||
|             !properties.start_keyboard_capturer_; | ||||
|         properties.mouse_control_button_pressed_ = | ||||
|             !properties.mouse_control_button_pressed_; | ||||
|         properties.mouse_control_button_label_ = | ||||
|             properties.mouse_control_button_pressed_ | ||||
|                 ? localization::release_mouse[localization_language_index_] | ||||
|                 : localization::control_mouse[localization_language_index_]; | ||||
|       } | ||||
|     } | ||||
|     if (!mouse_control_button_pressed_) { | ||||
|     if (!properties.mouse_control_button_pressed_) { | ||||
|       draw_list->AddLine( | ||||
|           ImVec2(disable_mouse_x, disable_mouse_y), | ||||
|           ImVec2(disable_mouse_x + 16.0f, disable_mouse_y + 14.2f), | ||||
| @@ -83,25 +87,27 @@ int Render::ControlBar() { | ||||
|     float disable_audio_y = ImGui::GetCursorScreenPos().y + 4.0f; | ||||
|     // std::string audio = audio_capture_button_pressed_ ? ICON_FA_VOLUME_HIGH | ||||
|     //                                                   : ICON_FA_VOLUME_XMARK; | ||||
|     std::string audio = audio_capture_button_pressed_ ? ICON_FA_VOLUME_HIGH | ||||
|     std::string audio = properties.audio_capture_button_pressed_ | ||||
|                             ? ICON_FA_VOLUME_HIGH | ||||
|                             : ICON_FA_VOLUME_HIGH; | ||||
|     if (ImGui::Button(audio.c_str(), ImVec2(25, 25))) { | ||||
|       if (connection_established_) { | ||||
|         audio_capture_ = !audio_capture_; | ||||
|         audio_capture_button_pressed_ = !audio_capture_button_pressed_; | ||||
|         audio_capture_button_label_ = | ||||
|             audio_capture_button_pressed_ | ||||
|       if (properties.connection_established_) { | ||||
|         properties.audio_capture_ = !properties.audio_capture_; | ||||
|         properties.audio_capture_button_pressed_ = | ||||
|             !properties.audio_capture_button_pressed_; | ||||
|         properties.audio_capture_button_label_ = | ||||
|             properties.audio_capture_button_pressed_ | ||||
|                 ? localization::audio_capture[localization_language_index_] | ||||
|                 : localization::mute[localization_language_index_]; | ||||
|  | ||||
|         RemoteAction remote_action; | ||||
|         remote_action.type = ControlType::audio_capture; | ||||
|         remote_action.a = audio_capture_button_pressed_; | ||||
|         remote_action.a = properties.audio_capture_button_pressed_; | ||||
|         SendDataFrame(peer_, (const char*)&remote_action, | ||||
|                       sizeof(remote_action)); | ||||
|       } | ||||
|     } | ||||
|     if (!audio_capture_button_pressed_) { | ||||
|     if (!properties.audio_capture_button_pressed_) { | ||||
|       draw_list->AddLine( | ||||
|           ImVec2(disable_audio_x, disable_audio_y), | ||||
|           ImVec2(disable_audio_x + 16.0f, disable_audio_y + 14.2f), | ||||
| @@ -117,18 +123,19 @@ int Render::ControlBar() { | ||||
|     ImGui::SameLine(); | ||||
|     // net traffic stats button | ||||
|     bool button_color_style_pushed = false; | ||||
|     if (net_traffic_stats_button_pressed_) { | ||||
|     if (properties.net_traffic_stats_button_pressed_) { | ||||
|       ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(66 / 255.0f, 150 / 255.0f, | ||||
|                                                     250 / 255.0f, 1.0f)); | ||||
|       button_color_style_pushed = true; | ||||
|     } | ||||
|     std::string net_traffic_stats = ICON_FA_SIGNAL; | ||||
|     if (ImGui::Button(net_traffic_stats.c_str(), ImVec2(25, 25))) { | ||||
|       net_traffic_stats_button_pressed_ = !net_traffic_stats_button_pressed_; | ||||
|       control_window_height_is_changing_ = true; | ||||
|       net_traffic_stats_button_pressed_time_ = ImGui::GetTime(); | ||||
|       net_traffic_stats_button_label_ = | ||||
|           net_traffic_stats_button_pressed_ | ||||
|       properties.net_traffic_stats_button_pressed_ = | ||||
|           !properties.net_traffic_stats_button_pressed_; | ||||
|       properties.control_window_height_is_changing_ = true; | ||||
|       properties.net_traffic_stats_button_pressed_time_ = ImGui::GetTime(); | ||||
|       properties.net_traffic_stats_button_label_ = | ||||
|           properties.net_traffic_stats_button_pressed_ | ||||
|               ? localization::hide_net_traffic_stats | ||||
|                     [localization_language_index_] | ||||
|               : localization::show_net_traffic_stats | ||||
| @@ -145,19 +152,17 @@ int Render::ControlBar() { | ||||
|         fullscreen_button_pressed_ ? ICON_FA_COMPRESS : ICON_FA_EXPAND; | ||||
|     if (ImGui::Button(fullscreen.c_str(), ImVec2(25, 25))) { | ||||
|       fullscreen_button_pressed_ = !fullscreen_button_pressed_; | ||||
|       fullscreen_button_label_ = | ||||
|       properties.fullscreen_button_label_ = | ||||
|           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(stream_window_, SDL_WINDOW_FULLSCREEN_DESKTOP); | ||||
|       } else { | ||||
|         SDL_SetWindowFullscreen(stream_window_, SDL_FALSE); | ||||
|       } | ||||
|       reset_control_bar_pos_ = true; | ||||
|       properties.reset_control_bar_pos_ = true; | ||||
|     } | ||||
|  | ||||
|     ImGui::SameLine(); | ||||
| @@ -171,37 +176,40 @@ int Render::ControlBar() { | ||||
|  | ||||
|     ImGui::SameLine(); | ||||
|  | ||||
|     if (!is_control_bar_in_left_) { | ||||
|       draw_list->AddLine( | ||||
|           ImVec2(ImGui::GetCursorScreenPos().x - 3.0f, | ||||
|     if (!properties.is_control_bar_in_left_) { | ||||
|       draw_list->AddLine(ImVec2(ImGui::GetCursorScreenPos().x - 3.0f, | ||||
|                                 ImGui::GetCursorScreenPos().y - 7.0f), | ||||
|                          ImVec2(ImGui::GetCursorScreenPos().x - 3.0f, | ||||
|                  ImGui::GetCursorScreenPos().y - 7.0f + control_window_height_), | ||||
|                                 ImGui::GetCursorScreenPos().y - 7.0f + | ||||
|                                     properties.control_window_height_), | ||||
|                          IM_COL32(178, 178, 178, 255), 1.0f); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   ImGui::SetCursorPosX( | ||||
|       is_control_bar_in_left_ ? (control_window_width_ * 2 - 20.0f) : 5.0f); | ||||
|   ImGui::SetCursorPosX(properties.is_control_bar_in_left_ | ||||
|                            ? (properties.control_window_width_ * 2 - 20.0f) | ||||
|                            : 5.0f); | ||||
|  | ||||
|   std::string control_bar = | ||||
|       control_bar_expand_ | ||||
|           ? (is_control_bar_in_left_ ? ICON_FA_ANGLE_LEFT : ICON_FA_ANGLE_RIGHT) | ||||
|           : (is_control_bar_in_left_ ? ICON_FA_ANGLE_RIGHT | ||||
|       properties.control_bar_expand_ | ||||
|           ? (properties.is_control_bar_in_left_ ? ICON_FA_ANGLE_LEFT | ||||
|                                                 : ICON_FA_ANGLE_RIGHT) | ||||
|           : (properties.is_control_bar_in_left_ ? ICON_FA_ANGLE_RIGHT | ||||
|                                                 : ICON_FA_ANGLE_LEFT); | ||||
|   if (ImGui::Button(control_bar.c_str(), ImVec2(15, 25))) { | ||||
|     control_bar_expand_ = !control_bar_expand_; | ||||
|     control_bar_button_pressed_time_ = ImGui::GetTime(); | ||||
|     control_window_width_is_changing_ = true; | ||||
|     properties.control_bar_expand_ = !properties.control_bar_expand_; | ||||
|     properties.control_bar_button_pressed_time_ = ImGui::GetTime(); | ||||
|     properties.control_window_width_is_changing_ = true; | ||||
|  | ||||
|     if (!control_bar_expand_) { | ||||
|       control_window_height_ = 40; | ||||
|       net_traffic_stats_button_pressed_ = false; | ||||
|     if (!properties.control_bar_expand_) { | ||||
|       properties.control_window_height_ = 40; | ||||
|       properties.net_traffic_stats_button_pressed_ = false; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   if (net_traffic_stats_button_pressed_ && control_bar_expand_) { | ||||
|     NetTrafficStats(); | ||||
|   if (properties.net_traffic_stats_button_pressed_ && | ||||
|       properties.control_bar_expand_) { | ||||
|     NetTrafficStats(properties); | ||||
|   } | ||||
|  | ||||
|   ImGui::PopStyleVar(); | ||||
| @@ -209,13 +217,16 @@ int Render::ControlBar() { | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
| int Render::NetTrafficStats() { | ||||
|   ImGui::SetCursorPos(ImVec2( | ||||
|       is_control_bar_in_left_ ? (control_window_width_ + 5.0f) : 5.0f, 40.0f)); | ||||
| int Render::NetTrafficStats(SubStreamWindowProperties& properties) { | ||||
|   ImGui::SetCursorPos(ImVec2(properties.is_control_bar_in_left_ | ||||
|                                  ? (properties.control_window_width_ + 5.0f) | ||||
|                                  : 5.0f, | ||||
|                              40.0f)); | ||||
|  | ||||
|   if (ImGui::BeginTable("NetTrafficStats", 4, ImGuiTableFlags_BordersH, | ||||
|                         ImVec2(control_window_max_width_ - 10.0f, | ||||
|                                control_window_max_height_ - 40.0f))) { | ||||
|   if (ImGui::BeginTable( | ||||
|           "NetTrafficStats", 4, ImGuiTableFlags_BordersH, | ||||
|           ImVec2(properties.control_window_max_width_ - 10.0f, | ||||
|                  properties.control_window_max_height_ - 40.0f))) { | ||||
|     ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed); | ||||
|     ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch); | ||||
|     ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch); | ||||
| @@ -236,43 +247,54 @@ int Render::NetTrafficStats() { | ||||
|     ImGui::Text("%s", | ||||
|                 localization::video[localization_language_index_].c_str()); | ||||
|     ImGui::TableNextColumn(); | ||||
|     BitrateDisplay((int)net_traffic_stats_.video_inbound_stats.bitrate); | ||||
|     BitrateDisplay( | ||||
|         (int)properties.net_traffic_stats_.video_inbound_stats.bitrate); | ||||
|     ImGui::TableNextColumn(); | ||||
|     BitrateDisplay((int)net_traffic_stats_.video_outbound_stats.bitrate); | ||||
|     BitrateDisplay( | ||||
|         (int)properties.net_traffic_stats_.video_outbound_stats.bitrate); | ||||
|     ImGui::TableNextColumn(); | ||||
|     LossRateDisplay(net_traffic_stats_.video_inbound_stats.loss_rate); | ||||
|     LossRateDisplay( | ||||
|         properties.net_traffic_stats_.video_inbound_stats.loss_rate); | ||||
|  | ||||
|     ImGui::TableNextRow(); | ||||
|     ImGui::TableNextColumn(); | ||||
|     ImGui::Text("%s", | ||||
|                 localization::audio[localization_language_index_].c_str()); | ||||
|     ImGui::TableNextColumn(); | ||||
|     BitrateDisplay((int)net_traffic_stats_.audio_inbound_stats.bitrate); | ||||
|     BitrateDisplay( | ||||
|         (int)properties.net_traffic_stats_.audio_inbound_stats.bitrate); | ||||
|     ImGui::TableNextColumn(); | ||||
|     BitrateDisplay((int)net_traffic_stats_.audio_outbound_stats.bitrate); | ||||
|     BitrateDisplay( | ||||
|         (int)properties.net_traffic_stats_.audio_outbound_stats.bitrate); | ||||
|     ImGui::TableNextColumn(); | ||||
|     LossRateDisplay(net_traffic_stats_.audio_inbound_stats.loss_rate); | ||||
|     LossRateDisplay( | ||||
|         properties.net_traffic_stats_.audio_inbound_stats.loss_rate); | ||||
|  | ||||
|     ImGui::TableNextRow(); | ||||
|     ImGui::TableNextColumn(); | ||||
|     ImGui::Text("%s", localization::data[localization_language_index_].c_str()); | ||||
|     ImGui::TableNextColumn(); | ||||
|     BitrateDisplay((int)net_traffic_stats_.data_inbound_stats.bitrate); | ||||
|     BitrateDisplay( | ||||
|         (int)properties.net_traffic_stats_.data_inbound_stats.bitrate); | ||||
|     ImGui::TableNextColumn(); | ||||
|     BitrateDisplay((int)net_traffic_stats_.data_outbound_stats.bitrate); | ||||
|     BitrateDisplay( | ||||
|         (int)properties.net_traffic_stats_.data_outbound_stats.bitrate); | ||||
|     ImGui::TableNextColumn(); | ||||
|     LossRateDisplay(net_traffic_stats_.data_inbound_stats.loss_rate); | ||||
|     LossRateDisplay(properties.net_traffic_stats_.data_inbound_stats.loss_rate); | ||||
|  | ||||
|     ImGui::TableNextRow(); | ||||
|     ImGui::TableNextColumn(); | ||||
|     ImGui::Text("%s", | ||||
|                 localization::total[localization_language_index_].c_str()); | ||||
|     ImGui::TableNextColumn(); | ||||
|     BitrateDisplay((int)net_traffic_stats_.total_inbound_stats.bitrate); | ||||
|     BitrateDisplay( | ||||
|         (int)properties.net_traffic_stats_.total_inbound_stats.bitrate); | ||||
|     ImGui::TableNextColumn(); | ||||
|     BitrateDisplay((int)net_traffic_stats_.total_outbound_stats.bitrate); | ||||
|     BitrateDisplay( | ||||
|         (int)properties.net_traffic_stats_.total_outbound_stats.bitrate); | ||||
|     ImGui::TableNextColumn(); | ||||
|     LossRateDisplay(net_traffic_stats_.total_inbound_stats.loss_rate); | ||||
|     LossRateDisplay( | ||||
|         properties.net_traffic_stats_.total_inbound_stats.loss_rate); | ||||
|  | ||||
|     ImGui::EndTable(); | ||||
|   } | ||||
|   | ||||
| @@ -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 | ||||
|            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 | ||||
|            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), | ||||
|   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(); | ||||
|   | ||||
| @@ -28,7 +28,10 @@ int Render::MainWindow() { | ||||
|  | ||||
|   RecentConnectionsWindow(); | ||||
|   StatusBar(); | ||||
|   ConnectionStatusWindow(); | ||||
|  | ||||
|   for (auto& properties : connection_properties_) { | ||||
|     ConnectionStatusWindow(properties.second); | ||||
|   } | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
|   | ||||
| @@ -103,10 +103,10 @@ static int InputTextCallback(ImGuiInputTextCallbackData *data) { | ||||
| } | ||||
|  | ||||
| int Render::ConnectTo() { | ||||
|   connection_status_ = ConnectionStatus::Connecting; | ||||
|   // connection_status_ = ConnectionStatus::Connecting; | ||||
|   int ret = -1; | ||||
|   if (signal_connected_) { | ||||
|     if (!connection_established_) { | ||||
|     // if (!connection_established_) { | ||||
|     if (0 == strcmp(remote_id_.c_str(), client_id_) && !peer_reserved_) { | ||||
|       peer_reserved_ = CreatePeer(¶ms_); | ||||
|       if (peer_reserved_) { | ||||
| @@ -128,7 +128,7 @@ int Render::ConnectTo() { | ||||
|     } else { | ||||
|       rejoin_ = true; | ||||
|     } | ||||
|     } | ||||
|     // } | ||||
|   } | ||||
|  | ||||
|   return 0; | ||||
|   | ||||
| @@ -323,8 +323,6 @@ int Render::StopKeyboardCapturer() { | ||||
| } | ||||
|  | ||||
| int Render::CreateConnectionPeer() { | ||||
|   mac_addr_str_ = GetMac(); | ||||
|  | ||||
|   params_.use_cfg_file = false; | ||||
|   params_.signal_server_ip = "150.158.81.30"; | ||||
|   params_.signal_server_port = 9099; | ||||
| @@ -819,24 +817,6 @@ int Render::Run() { | ||||
|           connect_button_pressed_ | ||||
|               ? localization::disconnect[localization_language_index_] | ||||
|               : localization::connect[localization_language_index_]; | ||||
|  | ||||
|       mouse_control_button_label_ = | ||||
|           mouse_control_button_pressed_ | ||||
|               ? localization::release_mouse[localization_language_index_] | ||||
|               : localization::control_mouse[localization_language_index_]; | ||||
|  | ||||
|       audio_capture_button_label_ = | ||||
|           audio_capture_button_pressed_ | ||||
|               ? localization::mute[localization_language_index_] | ||||
|               : localization::audio_capture[localization_language_index_]; | ||||
|  | ||||
|       fullscreen_button_label_ = | ||||
|           fullscreen_button_pressed_ | ||||
|               ? localization::exit_fullscreen[localization_language_index_] | ||||
|               : localization::fullscreen[localization_language_index_]; | ||||
|  | ||||
|       settings_button_label_ = | ||||
|           localization::settings[localization_language_index_]; | ||||
|       label_inited_ = true; | ||||
|       localization_language_index_last_ = localization_language_index_; | ||||
|     } | ||||
| @@ -871,7 +851,7 @@ int Render::Run() { | ||||
|           if (dst_buffer_) { | ||||
|             thumbnail_->SaveToThumbnail( | ||||
|                 (char*)dst_buffer_, video_width_, video_height_, remote_id_, | ||||
|                 host_name_, remember_password_ ? remote_password_ : ""); | ||||
|                 remote_host_name_, remember_password_ ? remote_password_ : ""); | ||||
|             recent_connection_image_save_time_ = SDL_GetTicks(); | ||||
|           } | ||||
|  | ||||
| @@ -975,17 +955,13 @@ int Render::Run() { | ||||
|                 SDL_TEXTUREACCESS_STREAMING, texture_width_, texture_height_); | ||||
|           } | ||||
|         SDL_UpdateTexture(stream_texture_, NULL, dst_buffer_, texture_width_); | ||||
|       } else { | ||||
|         if (connection_established_) { | ||||
|           ProcessMouseKeyEvent(event); | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     if (reload_recent_connections_ && main_renderer_) { | ||||
|       // loal recent connection thumbnails after saving for 0.5 second | ||||
|       // loal recent connection thumbnails after saving for 0.05 second | ||||
|       uint32_t now_time = SDL_GetTicks(); | ||||
|       if (now_time - recent_connection_image_save_time_ >= 500) { | ||||
|       if (now_time - recent_connection_image_save_time_ >= 50) { | ||||
|         int ret = thumbnail_->LoadThumbnail( | ||||
|             main_renderer_, recent_connection_textures_, | ||||
|             &recent_connection_image_width_, &recent_connection_image_height_); | ||||
| @@ -1021,20 +997,6 @@ int Render::Run() { | ||||
|  | ||||
|     // create connection | ||||
|     CreateRtcConnection(); | ||||
|  | ||||
|     // frame_count_++; | ||||
|     // end_time_ = SDL_GetTicks(); | ||||
|     // elapsed_time_ = end_time_ - start_time_; | ||||
|     // if (elapsed_time_ >= 1000) { | ||||
|     //   fps_ = frame_count_ / (elapsed_time_ / 1000); | ||||
|     //   frame_count_ = 0; | ||||
|     //   window_title = "Remote Desk Client FPS [" + std::to_string(fps_) + | ||||
|     //                  "] status [" + connection_status_str_ + "|" + | ||||
|     //                  connection_status_str_ + "]"; | ||||
|     //   // For MacOS, UI frameworks can only be called from the main thread | ||||
|     //   SDL_SetWindowTitle(main_window_, window_title.c_str()); | ||||
|     //   start_time_ = end_time_; | ||||
|     // } | ||||
|   } | ||||
|  | ||||
|   delete[] argb_buffer_; | ||||
|   | ||||
| @@ -26,6 +26,68 @@ | ||||
| #include "thumbnail.h" | ||||
|  | ||||
| class Render { | ||||
|  public: | ||||
|   struct SubStreamWindowProperties { | ||||
|     bool exit_ = false; | ||||
|     bool connection_established_ = false; | ||||
|     bool net_traffic_stats_button_pressed_ = false; | ||||
|     bool mouse_control_button_pressed_ = false; | ||||
|     bool mouse_controller_is_started_ = false; | ||||
|     bool audio_capture_button_pressed_ = false; | ||||
|     bool audio_capture_ = true; | ||||
|     bool start_screen_capturer_ = false; | ||||
|     bool screen_capturer_is_started_ = false; | ||||
|     bool start_keyboard_capturer_ = false; | ||||
|     bool keyboard_capturer_is_started_ = false; | ||||
|     bool control_mouse_ = false; | ||||
|     bool stream_window_grabbed_ = false; | ||||
|     bool window_maximized_ = false; | ||||
|     bool streaming_ = false; | ||||
|     bool is_control_bar_in_left_ = 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 p2p_mode_ = true; | ||||
|     float sub_stream_window_width_ = 1280; | ||||
|     float sub_stream_window_height_ = 720; | ||||
|     float control_window_min_width_ = 20; | ||||
|     float control_window_max_width_ = 200; | ||||
|     float control_window_min_height_ = 40; | ||||
|     float control_window_max_height_ = 150; | ||||
|     float control_window_width_ = 200; | ||||
|     float control_window_height_ = 40; | ||||
|     float control_bar_pos_x_ = 0; | ||||
|     float control_bar_pos_y_ = 30; | ||||
|     float mouse_diff_control_bar_pos_x_ = 0; | ||||
|     float mouse_diff_control_bar_pos_y_ = 0; | ||||
|     double control_bar_button_pressed_time_ = 0; | ||||
|     double net_traffic_stats_button_pressed_time_ = 0; | ||||
|     unsigned char *dst_buffer_ = nullptr; | ||||
|     size_t dst_buffer_capacity_ = 0; | ||||
|     int mouse_pos_x_ = 0; | ||||
|     int mouse_pos_y_ = 0; | ||||
|     int mouse_pos_x_last_ = 0; | ||||
|     int mouse_pos_y_last_ = 0; | ||||
|     int texture_width_ = 1280; | ||||
|     int texture_height_ = 720; | ||||
|     int video_width_ = 1280; | ||||
|     int video_height_ = 720; | ||||
|     size_t video_size_ = 1280 * 720 * 3; | ||||
|     std::string fullscreen_button_label_ = "Fullscreen"; | ||||
|     std::string net_traffic_stats_button_label_ = "Show Net Traffic Stats"; | ||||
|     std::string mouse_control_button_label_ = "Mouse Control"; | ||||
|     std::string audio_capture_button_label_ = "Audio Capture"; | ||||
|     std::string remote_host_name_ = ""; | ||||
|     SDL_Rect stream_render_rect_; | ||||
|     SDL_Rect stream_render_rect_last_; | ||||
|     ImVec2 control_winodw_pos_; | ||||
|     ConnectionStatus connection_status_ = ConnectionStatus::Closed; | ||||
|     TraversalMode traversal_mode_ = TraversalMode::UnknownMode; | ||||
|     XNetTrafficStats net_traffic_stats_; | ||||
|   }; | ||||
|  | ||||
|  public: | ||||
|   Render(); | ||||
|   ~Render(); | ||||
| @@ -42,11 +104,11 @@ class Render { | ||||
|   int RemoteWindow(); | ||||
|   int RecentConnectionsWindow(); | ||||
|   int SettingWindow(); | ||||
|   int ControlWindow(); | ||||
|   int ControlBar(); | ||||
|   int ControlWindow(SubStreamWindowProperties &properties); | ||||
|   int ControlBar(SubStreamWindowProperties &properties); | ||||
|   int AboutWindow(); | ||||
|   int StatusBar(); | ||||
|   int ConnectionStatusWindow(); | ||||
|   int ConnectionStatusWindow(SubStreamWindowProperties &properties); | ||||
|   int LoadRecentConnections(); | ||||
|   int ShowRecentConnections(); | ||||
|  | ||||
| @@ -65,7 +127,7 @@ class Render { | ||||
|   int DrawMainWindow(); | ||||
|   int DrawStreamWindow(); | ||||
|   int ConfirmDeleteConnection(); | ||||
|   int NetTrafficStats(); | ||||
|   int NetTrafficStats(SubStreamWindowProperties &properties); | ||||
|  | ||||
|  public: | ||||
|   static void OnReceiveVideoBufferCb(const XVideoFrame *video_frame, | ||||
| @@ -94,9 +156,6 @@ class Render { | ||||
|                                            const SDL_Point *area, void *data); | ||||
|  | ||||
|  private: | ||||
|   int ProcessMouseKeyEvent(SDL_Event &event); | ||||
|   int ProcessMouseEvent(SDL_Event &event); | ||||
|  | ||||
|   int SendKeyEvent(int key_code, bool is_down); | ||||
|   int ProcessKeyEvent(int key_code, bool is_down); | ||||
|  | ||||
| @@ -125,7 +184,7 @@ class Render { | ||||
|   int AudioDeviceDestroy(); | ||||
|  | ||||
|  private: | ||||
|   typedef struct { | ||||
|   struct CDCache { | ||||
|     char client_id[10]; | ||||
|     char password[7]; | ||||
|     int language; | ||||
| @@ -136,64 +195,51 @@ class Render { | ||||
|  | ||||
|     unsigned char key[16]; | ||||
|     unsigned char iv[16]; | ||||
|   } CDCache; | ||||
|   }; | ||||
|  | ||||
|  private: | ||||
|   CDCache cd_cache_; | ||||
|   std::mutex cd_cache_mutex_; | ||||
|  | ||||
|   ConfigCenter config_center_; | ||||
|   ConfigCenter::LANGUAGE localization_language_ = | ||||
|       ConfigCenter::LANGUAGE::CHINESE; | ||||
|  | ||||
|   int localization_language_index_ = -1; | ||||
|   int localization_language_index_last_ = -1; | ||||
|  | ||||
|   bool modules_inited_ = false; | ||||
|  | ||||
|  private: | ||||
|   std::string window_title = "Remote Desk Client"; | ||||
|   std::string mac_addr_str_ = ""; | ||||
|   std::string connect_button_label_ = "Connect"; | ||||
|   std::string fullscreen_button_label_ = "Fullscreen"; | ||||
|   std::string net_traffic_stats_button_label_ = "Show Net Traffic Stats"; | ||||
|   std::string mouse_control_button_label_ = "Mouse Control"; | ||||
|   std::string audio_capture_button_label_ = "Audio Capture"; | ||||
|   std::string settings_button_label_ = "Setting"; | ||||
|   char input_password_tmp_[7] = ""; | ||||
|   char input_password_[7] = ""; | ||||
|   std::string random_password_ = ""; | ||||
|   char remote_password_[7] = ""; | ||||
|   char new_password_[7] = ""; | ||||
|   char remote_id_display_[12] = ""; | ||||
|   std::string remote_id_ = ""; | ||||
|   char client_password_[20] = ""; | ||||
|  | ||||
|  private: | ||||
|   /* ------ all windows property start ------ */ | ||||
|   float title_bar_width_ = 640; | ||||
|   float title_bar_height_ = 30; | ||||
|   int screen_width_ = 1280; | ||||
|   int screen_height_ = 720; | ||||
|   /* ------ all windows property end ------ */ | ||||
|  | ||||
|   /* ------ main window property start ------ */ | ||||
|   // thumbnail | ||||
|   unsigned char aes128_key_[16]; | ||||
|   unsigned char aes128_iv_[16]; | ||||
|   std::unique_ptr<Thumbnail> thumbnail_; | ||||
|  | ||||
|   // recent connections | ||||
|   std::map<std::string, SDL_Texture *> recent_connection_textures_; | ||||
|   int recent_connection_image_width_ = 160; | ||||
|   int recent_connection_image_height_ = 90; | ||||
|   uint32_t recent_connection_image_save_time_ = 0; | ||||
|  | ||||
|   // main window render | ||||
|   SDL_Window *main_window_ = nullptr; | ||||
|   SDL_Renderer *main_renderer_ = nullptr; | ||||
|   ImGuiContext *main_ctx_ = nullptr; | ||||
|  | ||||
|   // main window properties | ||||
|   int main_window_width_real_ = 720; | ||||
|   int main_window_height_real_ = 540; | ||||
|   float main_window_dpi_scaling_w_ = 1.0f; | ||||
|   float main_window_dpi_scaling_h_ = 1.0f; | ||||
|   float main_window_width_default_ = 640; | ||||
|   float main_window_height_default_ = 480; | ||||
|   float main_window_width_ = 640; | ||||
|   float main_window_height_ = 480; | ||||
|   float main_window_width_last_ = 640; | ||||
|   float main_window_height_last_ = 480; | ||||
|   int stream_window_width_default_ = 1280; | ||||
|   int stream_window_height_default_ = 720; | ||||
|   float stream_window_width_ = 1280; | ||||
|   float stream_window_height_ = 720; | ||||
|   int stream_window_width_last_ = 1280; | ||||
|   int stream_window_height_last_ = 720; | ||||
|   float stream_window_width_before_maximized_ = 1280; | ||||
|   float stream_window_height_before_maximized_ = 720; | ||||
|   float control_window_min_width_ = 20; | ||||
|   float control_window_max_width_ = 200; | ||||
|   float control_window_min_height_ = 40; | ||||
|   float control_window_max_height_ = 150; | ||||
|   float control_window_width_ = 200; | ||||
|   float control_window_height_ = 40; | ||||
|   float local_window_width_ = 320; | ||||
|   float local_window_height_ = 235; | ||||
|   float remote_window_width_ = 320; | ||||
| @@ -212,79 +258,46 @@ class Render { | ||||
|   float notification_window_height_ = 80; | ||||
|   float about_window_width_ = 200; | ||||
|   float about_window_height_ = 150; | ||||
|   int screen_width_ = 1280; | ||||
|   int screen_height_ = 720; | ||||
|   std::string connect_button_label_ = "Connect"; | ||||
|   char input_password_tmp_[7] = ""; | ||||
|   char input_password_[7] = ""; | ||||
|   std::string random_password_ = ""; | ||||
|   char remote_password_[7] = ""; | ||||
|   char new_password_[7] = ""; | ||||
|   char remote_id_display_[12] = ""; | ||||
|   std::string remote_id_ = ""; | ||||
|   unsigned char audio_buffer_[720]; | ||||
|   int audio_len_ = 0; | ||||
|   bool audio_buffer_fresh_ = false; | ||||
|  | ||||
|   float control_bar_pos_x_ = 0; | ||||
|   float control_bar_pos_y_ = 30; | ||||
|   float mouse_diff_control_bar_pos_x_ = 0; | ||||
|   float 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; | ||||
|   float main_window_dpi_scaling_w_ = 1.0f; | ||||
|   float main_window_dpi_scaling_h_ = 1.0f; | ||||
|   // stream window render | ||||
|   SDL_Window *stream_window_ = nullptr; | ||||
|   SDL_Renderer *stream_renderer_ = nullptr; | ||||
|   SDL_Texture *stream_texture_ = nullptr; | ||||
|   ImGuiContext *stream_ctx_ = nullptr; | ||||
|  | ||||
|   // stream window properties | ||||
|   bool stream_window_created_ = false; | ||||
|   bool stream_window_inited_ = false; | ||||
|   int stream_window_width_default_ = 1280; | ||||
|   int stream_window_height_default_ = 720; | ||||
|   float stream_window_width_ = 1280; | ||||
|   float stream_window_height_ = 720; | ||||
|   uint32_t stream_pixformat_ = 0; | ||||
|   int stream_window_width_real_ = 1280; | ||||
|   int stream_window_height_real_ = 720; | ||||
|   float stream_window_dpi_scaling_w_ = 1.0f; | ||||
|   float stream_window_dpi_scaling_h_ = 1.0f; | ||||
|  | ||||
|   int texture_width_ = 1280; | ||||
|   int texture_height_ = 720; | ||||
|  | ||||
|   int video_width_ = 1280; | ||||
|   int video_height_ = 720; | ||||
|   size_t video_size_ = 1280 * 720 * 3; | ||||
|  | ||||
|   SDL_Window *main_window_ = nullptr; | ||||
|   SDL_Renderer *main_renderer_ = nullptr; | ||||
|   ImGuiContext *main_ctx_ = nullptr; | ||||
|  | ||||
|   SDL_Window *stream_window_ = nullptr; | ||||
|   SDL_Renderer *stream_renderer_ = nullptr; | ||||
|   ImGuiContext *stream_ctx_ = nullptr; | ||||
|   bool stream_window_created_ = false; | ||||
|   bool stream_window_inited_ = false; | ||||
|  | ||||
|   // recent connections | ||||
|   std::map<std::string, SDL_Texture *> recent_connection_textures_; | ||||
|   int recent_connection_image_width_ = 160; | ||||
|   int recent_connection_image_height_ = 90; | ||||
|   uint32_t recent_connection_image_save_time_ = 0; | ||||
|  | ||||
|   // 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_ = ""; | ||||
|  | ||||
|   unsigned char aes128_key_[16]; | ||||
|   unsigned char aes128_iv_[16]; | ||||
|   std::unique_ptr<Thumbnail> thumbnail_; | ||||
|  | ||||
|   bool resizable_ = false; | ||||
|   bool label_inited_ = false; | ||||
|   bool exit_ = false; | ||||
|   bool exit_video_window_ = false; | ||||
|   bool connection_established_ = false; | ||||
|   bool connect_button_pressed_ = false; | ||||
|   bool password_validating_ = false; | ||||
|   uint32_t password_validating_time_ = 0; | ||||
|   bool fullscreen_button_pressed_ = false; | ||||
|   bool net_traffic_stats_button_pressed_ = false; | ||||
|   bool mouse_control_button_pressed_ = false; | ||||
|   bool audio_capture_button_pressed_ = false; | ||||
|   bool show_settings_window_ = false; | ||||
|   bool is_create_connection_ = false; | ||||
|   bool audio_buffer_fresh_ = false; | ||||
|   bool rejoin_ = false; | ||||
|   bool control_mouse_ = false; | ||||
|   bool stream_window_grabbed_ = false; | ||||
|   bool audio_capture_ = true; | ||||
|   bool local_id_copied_ = false; | ||||
|   bool show_password_ = true; | ||||
|   bool password_inited_ = false; | ||||
| @@ -292,61 +305,26 @@ class Render { | ||||
|   bool show_about_window_ = false; | ||||
|   bool show_connection_status_window_ = false; | ||||
|   bool show_reset_password_window_ = false; | ||||
|   bool fullscreen_button_pressed_ = false; | ||||
|   bool focus_on_input_widget_ = true; | ||||
|   bool window_maximized_ = false; | ||||
|   bool streaming_ = false; | ||||
|   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; | ||||
|   bool hostname_sent_ = false; | ||||
|   bool show_confirm_delete_connection_ = false; | ||||
|   bool delete_connection_ = false; | ||||
|   bool remember_password_ = false; | ||||
|   bool re_enter_remote_id_ = false; | ||||
|  | ||||
|   double copy_start_time_ = 0; | ||||
|   double regenerate_password_start_time_ = 0; | ||||
|   double control_bar_button_pressed_time_ = 0; | ||||
|   double net_traffic_stats_button_pressed_time_ = 0; | ||||
|  | ||||
|   ImVec2 control_winodw_pos_; | ||||
|  | ||||
|   int fps_ = 0; | ||||
|   uint32_t start_time_; | ||||
|   uint32_t end_time_; | ||||
|   uint32_t elapsed_time_; | ||||
|   uint32_t frame_count_ = 0; | ||||
|  | ||||
|  private: | ||||
|   ConnectionStatus connection_status_ = ConnectionStatus::Closed; | ||||
|   SignalStatus signal_status_ = SignalStatus::SignalClosed; | ||||
|   std::string signal_status_str_ = ""; | ||||
|   std::string connection_status_str_ = ""; | ||||
|   bool signal_connected_ = false; | ||||
|   bool p2p_mode_ = true; | ||||
|  | ||||
|  private: | ||||
|   PeerPtr *peer_ = nullptr; | ||||
|   PeerPtr *peer_reserved_ = nullptr; | ||||
|   Params params_; | ||||
|   TraversalMode traversal_mode_ = TraversalMode::UnknownMode; | ||||
|   XNetTrafficStats net_traffic_stats_; | ||||
|  | ||||
|  private: | ||||
|   SDL_AudioDeviceID input_dev_; | ||||
|   SDL_AudioDeviceID output_dev_; | ||||
|   unsigned char audio_buffer_[720]; | ||||
|   int audio_len_ = 0; | ||||
|   unsigned char *dst_buffer_ = nullptr; | ||||
|   size_t dst_buffer_capacity_ = 0; | ||||
|  | ||||
|  private: | ||||
|   ScreenCapturerFactory *screen_capturer_factory_ = nullptr; | ||||
|   ScreenCapturer *screen_capturer_ = nullptr; | ||||
|   SpeakerCapturerFactory *speaker_capturer_factory_ = nullptr; | ||||
| @@ -355,8 +333,6 @@ class Render { | ||||
|   MouseController *mouse_controller_ = nullptr; | ||||
|   KeyboardCapturer *keyboard_capturer_ = nullptr; | ||||
|   uint64_t last_frame_time_; | ||||
|  | ||||
|  private: | ||||
|   char client_id_[10] = ""; | ||||
|   char client_id_display_[12] = ""; | ||||
|   char password_saved_[7] = ""; | ||||
| @@ -365,23 +341,18 @@ class Render { | ||||
|   int video_encode_format_button_value_ = 0; | ||||
|   bool enable_hardware_video_codec_ = false; | ||||
|   bool enable_turn_ = false; | ||||
|  | ||||
|   int language_button_value_last_ = 0; | ||||
|   int video_quality_button_value_last_ = 0; | ||||
|   int video_encode_format_button_value_last_ = 0; | ||||
|   bool enable_hardware_video_codec_last_ = false; | ||||
|   bool enable_turn_last_ = false; | ||||
|  | ||||
|  private: | ||||
|   std::atomic<bool> start_screen_capturer_{false}; | ||||
|   std::atomic<bool> start_mouse_controller_{false}; | ||||
|   std::atomic<bool> start_keyboard_capturer_{false}; | ||||
|   std::atomic<bool> screen_capturer_is_started_{false}; | ||||
|   std::atomic<bool> mouse_controller_is_started_{false}; | ||||
|   std::atomic<bool> keyboard_capturer_is_started_{false}; | ||||
|  | ||||
|  private: | ||||
|   bool settings_window_pos_reset_ = true; | ||||
|   /* ------ main window property end ------ */ | ||||
|  | ||||
|   /* ------ sub stream window property start ------ */ | ||||
|   std::unordered_map<std::string, SubStreamWindowProperties> | ||||
|       connection_properties_; | ||||
|   /* ------ stream window property end ------ */ | ||||
| }; | ||||
|  | ||||
| #endif | ||||
| @@ -13,76 +13,6 @@ | ||||
| #define MOUSE_CONTROL 1 | ||||
| #endif | ||||
|  | ||||
| int Render::ProcessMouseKeyEvent(SDL_Event &event) { | ||||
|   if (!control_mouse_ || !connection_established_) { | ||||
|     return 0; | ||||
|   } | ||||
|  | ||||
|   if (SDL_KEYDOWN == event.type || SDL_KEYUP == event.type) { | ||||
|   } else { | ||||
|     ProcessMouseEvent(event); | ||||
|   } | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
| int Render::ProcessMouseEvent(SDL_Event &event) { | ||||
|   float ratio_x = (float)video_width_ / (float)stream_render_rect_.w; | ||||
|   float ratio_y = (float)video_height_ / (float)stream_render_rect_.h; | ||||
|  | ||||
|   if (event.button.x <= stream_render_rect_.x) { | ||||
|     event.button.x = 0; | ||||
|   } else if (event.button.x > stream_render_rect_.x && | ||||
|              event.button.x < stream_render_rect_.x + stream_render_rect_.w) { | ||||
|     event.button.x -= stream_render_rect_.x; | ||||
|   } else if (event.button.x >= stream_render_rect_.x + stream_render_rect_.w) { | ||||
|     event.button.x = stream_render_rect_.w; | ||||
|   } | ||||
|  | ||||
|   if (event.button.y <= stream_render_rect_.y) { | ||||
|     event.button.y = 0; | ||||
|   } else if (event.button.y > stream_render_rect_.y && | ||||
|              event.button.y < stream_render_rect_.y + stream_render_rect_.h) { | ||||
|     event.button.y -= stream_render_rect_.y; | ||||
|   } else if (event.button.y >= stream_render_rect_.y + stream_render_rect_.h) { | ||||
|     event.button.y = stream_render_rect_.h; | ||||
|   } | ||||
|  | ||||
|   RemoteAction remote_action; | ||||
|   remote_action.m.x = (size_t)(event.button.x * ratio_x); | ||||
|   remote_action.m.y = (size_t)(event.button.y * ratio_y); | ||||
|  | ||||
|   if (SDL_MOUSEBUTTONDOWN == event.type) { | ||||
|     remote_action.type = ControlType::mouse; | ||||
|     if (SDL_BUTTON_LEFT == event.button.button) { | ||||
|       remote_action.m.flag = MouseFlag::left_down; | ||||
|     } else if (SDL_BUTTON_RIGHT == event.button.button) { | ||||
|       remote_action.m.flag = MouseFlag::right_down; | ||||
|     } | ||||
|     if (control_bar_hovered_) { | ||||
|       remote_action.m.flag = MouseFlag::move; | ||||
|     } | ||||
|     SendDataFrame(peer_, (const char *)&remote_action, sizeof(remote_action)); | ||||
|   } else if (SDL_MOUSEBUTTONUP == event.type) { | ||||
|     remote_action.type = ControlType::mouse; | ||||
|     if (SDL_BUTTON_LEFT == event.button.button) { | ||||
|       remote_action.m.flag = MouseFlag::left_up; | ||||
|     } else if (SDL_BUTTON_RIGHT == event.button.button) { | ||||
|       remote_action.m.flag = MouseFlag::right_up; | ||||
|     } | ||||
|     if (control_bar_hovered_) { | ||||
|       remote_action.m.flag = MouseFlag::move; | ||||
|     } | ||||
|     SendDataFrame(peer_, (const char *)&remote_action, sizeof(remote_action)); | ||||
|   } else if (SDL_MOUSEMOTION == event.type) { | ||||
|     remote_action.type = ControlType::mouse; | ||||
|     remote_action.m.flag = MouseFlag::move; | ||||
|     SendDataFrame(peer_, (const char *)&remote_action, sizeof(remote_action)); | ||||
|   } | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
| int Render::SendKeyEvent(int key_code, bool is_down) { | ||||
|   RemoteAction remote_action; | ||||
|   remote_action.type = ControlType::keyboard; | ||||
| @@ -200,10 +130,12 @@ void Render::OnReceiveDataBufferCb(const char *data, size_t size, | ||||
|                                    void *user_data) { | ||||
|   Render *render = (Render *)user_data; | ||||
|   if (!render) { | ||||
|     LOG_ERROR("??????????????????"); | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|   std::string user(user_id, user_id_size); | ||||
|   LOG_INFO("Receive data from: {}", user); | ||||
|   RemoteAction remote_action; | ||||
|   memcpy(&remote_action, data, size); | ||||
|  | ||||
| @@ -219,9 +151,11 @@ void Render::OnReceiveDataBufferCb(const char *data, size_t size, | ||||
|     render->ProcessKeyEvent((int)remote_action.k.key_value, | ||||
|                             remote_action.k.flag == KeyFlag::key_down); | ||||
|   } else if (ControlType::host_infomation == remote_action.type) { | ||||
|     render->host_name_ = | ||||
|     render->remote_host_name_ = | ||||
|         std::string(remote_action.i.host_name, remote_action.i.host_name_size); | ||||
|     LOG_INFO("Remote hostname: [{}]", render->host_name_); | ||||
|     LOG_INFO("Remote hostname: [{}]", render->remote_host_name_); | ||||
|   } else { | ||||
|     LOG_ERROR("Unknown control type: {}", (int)remote_action.type); | ||||
|   } | ||||
| } | ||||
|  | ||||
| @@ -270,6 +204,8 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, | ||||
|   } else if (ConnectionStatus::Gathering == status) { | ||||
|     render->connection_status_str_ = "Gathering"; | ||||
|   } else if (ConnectionStatus::Connected == status) { | ||||
|     std::string remote_id(user_id, user_id_size); | ||||
|     render->connection_properties_[remote_id] = SubStreamWindowProperties(); | ||||
|     render->connection_status_str_ = "Connected"; | ||||
|     render->connection_established_ = true; | ||||
|     if (render->peer_reserved_ || !render->is_client_mode_) { | ||||
| @@ -288,6 +224,9 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, | ||||
|       if (0 == ret) { | ||||
|         render->hostname_sent_ = true; | ||||
|       } | ||||
|       LOG_ERROR("1111111111111111 [{}|{}]", ret, host_name); | ||||
|     } else { | ||||
|       LOG_ERROR("2222222222222222"); | ||||
|     } | ||||
|   } else if (ConnectionStatus::Disconnected == status) { | ||||
|     render->connection_status_str_ = "Disconnected"; | ||||
| @@ -310,7 +249,6 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, | ||||
|       render->audio_capture_ = false; | ||||
|       render->audio_capture_button_pressed_ = false; | ||||
|     } | ||||
|     render->exit_video_window_ = false; | ||||
|     if (!render->rejoin_) { | ||||
|       memset(render->remote_password_, 0, sizeof(render->remote_password_)); | ||||
|     } | ||||
|   | ||||
| @@ -18,7 +18,9 @@ int Render::StreamWindow() { | ||||
|                    ImGuiWindowFlags_NoBringToFrontOnFocus); | ||||
|   ImGui::PopStyleColor(2); | ||||
|  | ||||
|   ControlWindow(); | ||||
|   for (auto &properties : connection_properties_) { | ||||
|     ControlWindow(properties.second); | ||||
|   } | ||||
|  | ||||
|   ImGui::End(); | ||||
|  | ||||
|   | ||||
| @@ -96,6 +96,7 @@ int Thumbnail::SaveToThumbnail(const char* yuv420p, int width, int height, | ||||
|       image_name = remote_id + 'Y' + password + host_name; | ||||
|     } | ||||
|  | ||||
|     LOG_ERROR("1 image_path: [{}]", image_name); | ||||
|     std::string ciphertext = AES_encrypt(image_name, aes128_key_, aes128_iv_); | ||||
|     std::string file_path = image_path_ + ciphertext; | ||||
|     stbi_write_png(file_path.data(), thumbnail_width_, thumbnail_height_, 4, | ||||
| @@ -218,6 +219,7 @@ int Thumbnail::LoadThumbnail(SDL_Renderer* renderer, | ||||
|           AES_decrypt(cipher_image_name, aes128_key_, aes128_iv_); | ||||
|       std::string image_path = image_path_ + cipher_image_name; | ||||
|       textures[original_image_name] = nullptr; | ||||
|       LOG_ERROR("2 image_path: [{}]", original_image_name); | ||||
|       LoadTextureFromFile(image_path.c_str(), renderer, | ||||
|                           &(textures[original_image_name]), width, height); | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user