mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
[feat] use a list to show thumbnails of recent connections
This commit is contained in:
@@ -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++) {
|
||||||
ImVec2((float)recent_connection_image_width_,
|
ImGui::Image((ImTextureID)(intptr_t)recent_connection_textures_[i],
|
||||||
(float)recent_connection_image_height_));
|
ImVec2((float)recent_connection_image_width_,
|
||||||
|
(float)recent_connection_image_height_));
|
||||||
|
ImGui::SameLine();
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -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");
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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_) {
|
|
||||||
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;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user