aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-06-30 13:10:07 +0200
committerdec05eba <dec05eba@protonmail.com>2023-06-30 13:10:07 +0200
commitb51468e440bb73371a430d0a0efe7658e8b7b80c (patch)
tree9036dd18aa3a79c26a8086ee6685240fdb15d02c /src
parent08e1a601e4aa13cdfb3bea836b89524cc13b07bf (diff)
Dont show spinning circle when thumbnail failed to load
Diffstat (limited to 'src')
-rw-r--r--src/AsyncImageLoader.cpp14
-rw-r--r--src/Body.cpp36
-rw-r--r--src/QuickMedia.cpp2
-rw-r--r--src/Text.cpp2
4 files changed, 33 insertions, 21 deletions
diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp
index 95bc9ca..d719480 100644
--- a/src/AsyncImageLoader.cpp
+++ b/src/AsyncImageLoader.cpp
@@ -132,7 +132,7 @@ namespace QuickMedia {
if(!file_analyzer.load_file(thumbnail_path.data.c_str(), false)) {
fprintf(stderr, "Failed to convert %s to a thumbnail\n", thumbnail_path.data.c_str());
thumbnail_data->image = std::make_unique<mgl::Image>();
- thumbnail_data->loading_state = LoadingState::FINISHED_LOADING;
+ thumbnail_data->loading_state = LoadingState::FAILED_TO_LOAD;
return;
}
@@ -142,7 +142,7 @@ namespace QuickMedia {
} else {
fprintf(stderr, "Failed to get video frame of %s\n", thumbnail_path.data.c_str());
thumbnail_data->image = std::make_unique<mgl::Image>();
- thumbnail_data->loading_state = LoadingState::FINISHED_LOADING;
+ thumbnail_data->loading_state = LoadingState::FAILED_TO_LOAD;
}
return;
}
@@ -152,7 +152,7 @@ namespace QuickMedia {
} else {
fprintf(stderr, "Failed to convert %s to a thumbnail\n", thumbnail_path.data.c_str());
thumbnail_data->image = std::make_unique<mgl::Image>();
- thumbnail_data->loading_state = LoadingState::FINISHED_LOADING;
+ thumbnail_data->loading_state = LoadingState::FAILED_TO_LOAD;
}
}
@@ -264,7 +264,7 @@ namespace QuickMedia {
if(url.empty()) {
thumbnail_data->image = std::make_unique<mgl::Image>();
- thumbnail_data->loading_state = LoadingState::FINISHED_LOADING;
+ thumbnail_data->loading_state = LoadingState::FAILED_TO_LOAD;
return false;
}
@@ -274,7 +274,7 @@ namespace QuickMedia {
if(stat(url.c_str(), &file_stat) != 0 || !S_ISREG(file_stat.st_mode)) {
fprintf(stderr, "Failed to load thumbnail %s: no such file\n", url.c_str());
thumbnail_data->image = std::make_unique<mgl::Image>();
- thumbnail_data->loading_state = LoadingState::FINISHED_LOADING;
+ thumbnail_data->loading_state = LoadingState::FAILED_TO_LOAD;
return false;
}
@@ -345,6 +345,8 @@ namespace QuickMedia {
image_thumbnail_create_queue.push(std::move(load_data));
} else {
fprintf(stderr, "Thumbnail download failed for %s\n", download.url.c_str());
+ download.thumbnail_data->image = std::make_unique<mgl::Image>();
+ download.thumbnail_data->loading_state = LoadingState::FAILED_TO_LOAD;
}
reset_download(download);
}
@@ -401,7 +403,7 @@ namespace QuickMedia {
download.read_program.read_fd = -1;
}
download.thumbnail_path.data.clear();
- download.url.c_str();
download.thumbnail_data = nullptr;
+ download.url.clear();
}
}
diff --git a/src/Body.cpp b/src/Body.cpp
index 2af12c3..3f8691a 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -1458,12 +1458,14 @@ namespace QuickMedia {
window.draw(image_fallback);
}
- mgl::vec2f loading_icon_size(loading_icon.get_texture()->get_size().x, loading_icon.get_texture()->get_size().y);
- auto new_loading_icon_size = clamp_to_size(loading_icon_size, content_size);
- loading_icon.set_position(item_pos + mgl::vec2f(body_spacing[body_theme].image_padding_x, padding_y) + (content_size * 0.5f));
- loading_icon.set_scale(get_ratio(loading_icon_size, new_loading_icon_size));
- loading_icon.set_rotation(elapsed_time_sec * 400.0);
- window.draw(loading_icon);
+ if(item_thumbnail->loading_state != LoadingState::FAILED_TO_LOAD) {
+ mgl::vec2f loading_icon_size(loading_icon.get_texture()->get_size().x, loading_icon.get_texture()->get_size().y);
+ auto new_loading_icon_size = clamp_to_size(loading_icon_size, content_size);
+ loading_icon.set_position(item_pos + mgl::vec2f(body_spacing[body_theme].image_padding_x, padding_y) + (content_size * 0.5f));
+ loading_icon.set_scale(get_ratio(loading_icon_size, new_loading_icon_size));
+ loading_icon.set_rotation(elapsed_time_sec * 400.0);
+ window.draw(loading_icon);
+ }
text_offset_x += body_spacing[body_theme].image_padding_x + item->loaded_image_size.x;
}
} else if(draw_thumbnails && item->thumbnail_size.x > 0) {
@@ -1586,12 +1588,20 @@ namespace QuickMedia {
thumbnail_drawn = true;
} else if(!item->thumbnail_url.empty()) {
mgl::vec2f content_size = thumbnail_size.to_vec2f();
- mgl::vec2f loading_icon_size(loading_icon.get_texture()->get_size().x, loading_icon.get_texture()->get_size().y);
- auto new_loading_icon_size = clamp_to_size(loading_icon_size, content_size);
- loading_icon.set_position(pos + pos_offset + mgl::vec2f(card_padding_x, card_padding_y) + mgl::vec2f(card_max_image_size.x, content_size.y) * 0.5f);
- loading_icon.set_scale(get_ratio(loading_icon_size, new_loading_icon_size));
- loading_icon.set_rotation(elapsed_time_sec * 400.0);
- window.draw(loading_icon);
+ image_fallback.set_size(content_size);
+ image_fallback.set_color(get_theme().image_loading_background_color);
+ image_fallback.set_position(pos + pos_offset + mgl::vec2f(card_padding_x, card_padding_y) + mgl::vec2f(card_max_image_size.x * 0.5f, 0.0f) - mgl::vec2f(content_size.x * 0.5f, 0.0f));
+ // TODO: Rounded corners
+ window.draw(image_fallback);
+
+ if(item_thumbnail->loading_state != LoadingState::FAILED_TO_LOAD) {
+ mgl::vec2f loading_icon_size(loading_icon.get_texture()->get_size().x, loading_icon.get_texture()->get_size().y);
+ auto new_loading_icon_size = clamp_to_size(loading_icon_size, content_size);
+ loading_icon.set_position(pos + pos_offset + mgl::vec2f(card_padding_x, card_padding_y) + mgl::vec2f(card_max_image_size.x, content_size.y) * 0.5f);
+ loading_icon.set_scale(get_ratio(loading_icon_size, new_loading_icon_size));
+ loading_icon.set_rotation(elapsed_time_sec * 400.0);
+ window.draw(loading_icon);
+ }
image_height = content_size.y;
}
@@ -1703,7 +1713,7 @@ namespace QuickMedia {
std::shared_ptr<ThumbnailData> item_thumbnail = AsyncImageLoader::get_instance().get_thumbnail(item->thumbnail_url, item->thumbnail_is_local, content_size);
content_size = clamp_to_size_x(content_size, width - (rendering_card_view ? 0.0f : body_spacing[body_theme].image_padding_x * 2.0f));
- if(item_thumbnail && item_thumbnail->loading_state == LoadingState::FINISHED_LOADING && item_thumbnail->image->get_size().x > 0 && item_thumbnail->image->get_size().y > 0) {
+ if(item_thumbnail && item_thumbnail->loading_state == LoadingState::FINISHED_LOADING) {
if(!item_thumbnail->texture.load_from_image(*item_thumbnail->image))
fprintf(stderr, "Warning: failed to load texture from image: %s\n", item->thumbnail_url.c_str());
//item_thumbnail->texture.generateMipmap();
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index a7d9f49..c4a55d0 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -5068,7 +5068,7 @@ namespace QuickMedia {
file_to_upload_thumbnail_data = AsyncImageLoader::get_instance().get_thumbnail(selected_file_for_upload, true, mgl::vec2i(logo_size.x, logo_size.y * 4));
}
- if(file_to_upload_thumbnail_data && file_to_upload_thumbnail_data->loading_state == LoadingState::FINISHED_LOADING && file_to_upload_thumbnail_data->image->get_size().x > 0 && file_to_upload_thumbnail_data->image->get_size().y > 0) {
+ if(file_to_upload_thumbnail_data && file_to_upload_thumbnail_data->loading_state == LoadingState::FINISHED_LOADING) {
if(!file_to_upload_thumbnail_data->texture.load_from_image(*file_to_upload_thumbnail_data->image))
fprintf(stderr, "Warning: failed to load texture for attached file\n");
//room_avatar_thumbnail_data->texture.generateMipmap();
diff --git a/src/Text.cpp b/src/Text.cpp
index 787c3a4..bf7ed6a 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -1605,7 +1605,7 @@ namespace QuickMedia
for(const TextElement &textElement : textElements) {
if(textElement.type == TextElement::Type::IMAGE) {
auto thumbnail_data = AsyncImageLoader::get_instance().get_thumbnail(textElement.url, textElement.local, textElement.size);
- if(thumbnail_data->loading_state == LoadingState::FINISHED_LOADING && thumbnail_data->image->get_size().x > 0 && thumbnail_data->image->get_size().y > 0) {
+ if(thumbnail_data->loading_state == LoadingState::FINISHED_LOADING) {
if(!thumbnail_data->texture.load_from_image(*thumbnail_data->image))
fprintf(stderr, "Warning: failed to load text image: %s\n", textElement.url.c_str());
thumbnail_data->image.reset();