From de721ac6e3372916a66bac8a8332f0096ac5f1af Mon Sep 17 00:00:00 2001 From: dijunkun Date: Thu, 7 Nov 2024 16:58:25 +0800 Subject: [PATCH] [feat] use a list to show thumbnails of recent connections --- src/single_window/main_window.cpp | 9 ++++++--- src/single_window/render.cpp | 2 +- src/single_window/render.h | 2 +- src/single_window/render_callback_func.cpp | 1 + src/single_window/thumbnail.cpp | 22 +++++++++++++--------- src/single_window/thumbnail.h | 4 ++-- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/single_window/main_window.cpp b/src/single_window/main_window.cpp index c893b94..00e5053 100644 --- a/src/single_window/main_window.cpp +++ b/src/single_window/main_window.cpp @@ -75,8 +75,11 @@ int Render::MainWindow() { } int Render::ShowRecentConnections() { - ImGui::Image((ImTextureID)(intptr_t)recent_connection_texture_, - ImVec2((float)recent_connection_image_width_, - (float)recent_connection_image_height_)); + for (int i = 0; i < recent_connection_textures_.size(); i++) { + ImGui::Image((ImTextureID)(intptr_t)recent_connection_textures_[i], + ImVec2((float)recent_connection_image_width_, + (float)recent_connection_image_height_)); + ImGui::SameLine(); + } return 0; } \ No newline at end of file diff --git a/src/single_window/render.cpp b/src/single_window/render.cpp index 7531b23..71a8ebc 100644 --- a/src/single_window/render.cpp +++ b/src/single_window/render.cpp @@ -912,7 +912,7 @@ int Render::Run() { uint32_t now_time = SDL_GetTicks(); if (now_time - recent_connection_image_save_time_ >= 1000) { int ret = thumbnail_.LoadThumbnail( - main_renderer_, &recent_connection_texture_, + main_renderer_, recent_connection_textures_, &recent_connection_image_width_, &recent_connection_image_height_); if (!ret) { LOG_INFO("Load recent connection thumbnails"); diff --git a/src/single_window/render.h b/src/single_window/render.h index 6b8cbfa..89d8a4c 100644 --- a/src/single_window/render.h +++ b/src/single_window/render.h @@ -225,7 +225,7 @@ class Render { bool stream_window_inited_ = false; // recent connections - SDL_Texture *recent_connection_texture_ = nullptr; + std::vector recent_connection_textures_; int recent_connection_image_width_ = 128; int recent_connection_image_height_ = 72; uint32_t recent_connection_image_save_time_ = 0; diff --git a/src/single_window/render_callback_func.cpp b/src/single_window/render_callback_func.cpp index 4bad822..b62d7aa 100644 --- a/src/single_window/render_callback_func.cpp +++ b/src/single_window/render_callback_func.cpp @@ -268,6 +268,7 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char *user_id, render->start_mouse_control_ = true; } if (!render->hostname_sent_) { + // TODO: self and remote hostname std::string host_name = GetHostName(); RemoteAction remote_action; remote_action.type = ControlType::host_infomation; diff --git a/src/single_window/thumbnail.cpp b/src/single_window/thumbnail.cpp index 7dec53c..df89a54 100644 --- a/src/single_window/thumbnail.cpp +++ b/src/single_window/thumbnail.cpp @@ -161,27 +161,31 @@ std::vector Thumbnail::FindThumbnailPath( if (entry.path().extension() == image_extensions) { thumbnails_sorted_by_write_time_[last_write_time] = entry.path(); } - - for (const auto& pair : thumbnails_sorted_by_write_time_) { - thumbnails_path.push_back(pair.second); - } } } + for (auto it = thumbnails_sorted_by_write_time_.rbegin(); + it != thumbnails_sorted_by_write_time_.rend(); ++it) { + thumbnails_path.push_back(it->second); + } + return thumbnails_path; } -int Thumbnail::LoadThumbnail(SDL_Renderer* renderer, SDL_Texture** texture, - int* width, int* height) { +int Thumbnail::LoadThumbnail(SDL_Renderer* renderer, + std::vector& textures, int* width, + int* height) { std::vector image_path = FindThumbnailPath(image_path_); if (image_path.size() == 0) { - LOG_INFO("No thumbnail saved", image_path_); return -1; } else { - LoadTextureFromFile(image_path[0].string().c_str(), renderer, texture, - width, height); + for (int i = 0; i < image_path.size(); i++) { + textures.push_back(nullptr); + LoadTextureFromFile(image_path[i].string().c_str(), renderer, + &(textures[i]), width, height); + } return 0; } } \ No newline at end of file diff --git a/src/single_window/thumbnail.h b/src/single_window/thumbnail.h index 58d654b..d5c1d52 100644 --- a/src/single_window/thumbnail.h +++ b/src/single_window/thumbnail.h @@ -22,8 +22,8 @@ class Thumbnail { const std::string& host_name, const std::string& remote_id); - int LoadThumbnail(SDL_Renderer* renderer, SDL_Texture** texture, int* width, - int* height); + int LoadThumbnail(SDL_Renderer* renderer, std::vector& textures, + int* width, int* height); private: std::vector FindThumbnailPath(