[feat] use a list to show thumbnails of recent connections

This commit is contained in:
dijunkun
2024-11-07 16:58:25 +08:00
parent 963f1da1d8
commit de721ac6e3
6 changed files with 24 additions and 16 deletions

View File

@@ -75,8 +75,11 @@ int Render::MainWindow() {
} }
int Render::ShowRecentConnections() { int Render::ShowRecentConnections() {
ImGui::Image((ImTextureID)(intptr_t)recent_connection_texture_, 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_, ImVec2((float)recent_connection_image_width_,
(float)recent_connection_image_height_)); (float)recent_connection_image_height_));
ImGui::SameLine();
}
return 0; return 0;
} }

View File

@@ -912,7 +912,7 @@ int Render::Run() {
uint32_t now_time = SDL_GetTicks(); uint32_t now_time = SDL_GetTicks();
if (now_time - recent_connection_image_save_time_ >= 1000) { if (now_time - recent_connection_image_save_time_ >= 1000) {
int ret = thumbnail_.LoadThumbnail( int ret = thumbnail_.LoadThumbnail(
main_renderer_, &recent_connection_texture_, main_renderer_, recent_connection_textures_,
&recent_connection_image_width_, &recent_connection_image_height_); &recent_connection_image_width_, &recent_connection_image_height_);
if (!ret) { if (!ret) {
LOG_INFO("Load recent connection thumbnails"); LOG_INFO("Load recent connection thumbnails");

View File

@@ -225,7 +225,7 @@ class Render {
bool stream_window_inited_ = false; bool stream_window_inited_ = false;
// recent connections // recent connections
SDL_Texture *recent_connection_texture_ = nullptr; std::vector<SDL_Texture *> recent_connection_textures_;
int recent_connection_image_width_ = 128; int recent_connection_image_width_ = 128;
int recent_connection_image_height_ = 72; int recent_connection_image_height_ = 72;
uint32_t recent_connection_image_save_time_ = 0; uint32_t recent_connection_image_save_time_ = 0;

View File

@@ -268,6 +268,7 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char *user_id,
render->start_mouse_control_ = true; render->start_mouse_control_ = true;
} }
if (!render->hostname_sent_) { if (!render->hostname_sent_) {
// TODO: self and remote hostname
std::string host_name = GetHostName(); std::string host_name = GetHostName();
RemoteAction remote_action; RemoteAction remote_action;
remote_action.type = ControlType::host_infomation; remote_action.type = ControlType::host_infomation;

View File

@@ -161,27 +161,31 @@ std::vector<std::filesystem::path> Thumbnail::FindThumbnailPath(
if (entry.path().extension() == image_extensions) { if (entry.path().extension() == image_extensions) {
thumbnails_sorted_by_write_time_[last_write_time] = entry.path(); thumbnails_sorted_by_write_time_[last_write_time] = entry.path();
} }
}
}
for (const auto& pair : thumbnails_sorted_by_write_time_) { for (auto it = thumbnails_sorted_by_write_time_.rbegin();
thumbnails_path.push_back(pair.second); it != thumbnails_sorted_by_write_time_.rend(); ++it) {
} thumbnails_path.push_back(it->second);
}
} }
return thumbnails_path; return thumbnails_path;
} }
int Thumbnail::LoadThumbnail(SDL_Renderer* renderer, SDL_Texture** texture, int Thumbnail::LoadThumbnail(SDL_Renderer* renderer,
int* width, int* height) { std::vector<SDL_Texture*>& textures, int* width,
int* height) {
std::vector<std::filesystem::path> image_path = std::vector<std::filesystem::path> image_path =
FindThumbnailPath(image_path_); FindThumbnailPath(image_path_);
if (image_path.size() == 0) { if (image_path.size() == 0) {
LOG_INFO("No thumbnail saved", image_path_);
return -1; return -1;
} else { } else {
LoadTextureFromFile(image_path[0].string().c_str(), renderer, texture, for (int i = 0; i < image_path.size(); i++) {
width, height); textures.push_back(nullptr);
LoadTextureFromFile(image_path[i].string().c_str(), renderer,
&(textures[i]), width, height);
}
return 0; return 0;
} }
} }

View File

@@ -22,8 +22,8 @@ class Thumbnail {
const std::string& host_name, const std::string& host_name,
const std::string& remote_id); const std::string& remote_id);
int LoadThumbnail(SDL_Renderer* renderer, SDL_Texture** texture, int* width, int LoadThumbnail(SDL_Renderer* renderer, std::vector<SDL_Texture*>& textures,
int* height); int* width, int* height);
private: private:
std::vector<std::filesystem::path> FindThumbnailPath( std::vector<std::filesystem::path> FindThumbnailPath(