aboutsummaryrefslogtreecommitdiff
path: root/src/Body.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Body.cpp')
-rw-r--r--src/Body.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index a779c09..a22f3ff 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -14,6 +14,7 @@ static const float padding_x = 10.0f;
static const float image_padding_x = 5.0f;
static const float padding_y = 5.0f;
static const float embedded_item_padding_y = 0.0f;
+static const double thumbnail_fade_duration_sec = 0.25;
namespace QuickMedia {
BodyItem::BodyItem(std::string _title) :
@@ -59,7 +60,6 @@ namespace QuickMedia {
replies_text.setFillColor(sf::Color(129, 162, 190));
thumbnail_resize_target_size.x = 120;
thumbnail_resize_target_size.y = 120;
- image_fallback.setFillColor(sf::Color::White);
item_background.setFillColor(sf::Color(55, 60, 68));
}
@@ -560,8 +560,19 @@ namespace QuickMedia {
float text_offset_x = padding_x;
if(draw_thumbnails) {
+ double elapsed_time_thumbnail = 0.0;
+ if(item_thumbnail->loading_state == LoadingState::APPLIED_TO_TEXTURE)
+ elapsed_time_thumbnail = item_thumbnail->texture_applied_time.getElapsedTime().asSeconds(); //thumbnail_fade_duration_sec
+
+ bool only_show_thumbnail = false;
+ double thumbnail_fade_progress = elapsed_time_thumbnail / thumbnail_fade_duration_sec;
+ if(thumbnail_fade_progress > 1.0) {
+ thumbnail_fade_progress = 1.0;
+ only_show_thumbnail = true;
+ }
+
+ bool has_thumbnail_texture = false;
// TODO: Verify if this is safe. The thumbnail is being modified in another thread
- // and it might not be fully finished before the native handle is set?
if(item_thumbnail->loading_state == LoadingState::APPLIED_TO_TEXTURE && item_thumbnail->texture.getNativeHandle() != 0) {
image.setTexture(item_thumbnail->texture, true);
auto image_size = image.getTexture()->getSize();
@@ -571,6 +582,7 @@ namespace QuickMedia {
content_size = sf::Vector2f(item->thumbnail_size.x, item->thumbnail_size.y);
auto new_image_size = clamp_to_size(image_size_f, content_size);
auto image_scale = get_ratio(image_size_f, new_image_size);
+ image.setColor(sf::Color(255, 255, 255, thumbnail_fade_progress * 255));
image.setScale(image_scale);
image.setPosition(item_pos + sf::Vector2f(image_padding_x, padding_y));
if(thumbnail_mask_shader && item->thumbnail_mask_type == ThumbnailMaskType::CIRCLE)
@@ -578,27 +590,34 @@ namespace QuickMedia {
else
window.draw(image);
text_offset_x += image_padding_x + new_image_size.x;
+ has_thumbnail_texture = true;
// We want the next image fallback to have the same size as the successful image rendering, because its likely the image fallback will have the same size (for example thumbnails on youtube)
//image_fallback.setSize(sf::Vector2f(width_ratio * image_size.x, height_ratio * image_size.y));
- } else if(!item->thumbnail_url.empty()) {
+ }
+
+ if(!item->thumbnail_url.empty() && !only_show_thumbnail) {
sf::Vector2f content_size(thumbnail_resize_target_size.x, thumbnail_resize_target_size.y);
if(item->thumbnail_size.x > 0 && item->thumbnail_size.y > 0)
content_size = sf::Vector2f(item->thumbnail_size.x, item->thumbnail_size.y);
- image_fallback.setSize(content_size);
+ sf::Color fallback_color(52, 58, 70, (1.0 - thumbnail_fade_progress) * 255);
if(thumbnail_mask_shader && item->thumbnail_mask_type == ThumbnailMaskType::CIRCLE) {
// TODO: Use the mask shader instead, but a vertex shader is also needed for that to pass the vertex coordinates since
// shapes dont have texture coordinates.
// TODO: Cache circle shape
sf::CircleShape circle_shape(content_size.x * 0.5f);
- circle_shape.setFillColor(sf::Color::White);
+ circle_shape.setFillColor(fallback_color);
circle_shape.setPosition(item_pos + sf::Vector2f(image_padding_x, padding_y));
window.draw(circle_shape);
} else {
+ image_fallback.setSize(content_size);
+ image_fallback.setFillColor(fallback_color);
image_fallback.setPosition(item_pos + sf::Vector2f(image_padding_x, padding_y));
window.draw(image_fallback);
}
- text_offset_x += image_padding_x + content_size.x;
+
+ if(!has_thumbnail_texture)
+ text_offset_x += image_padding_x + content_size.x;
}
}
@@ -735,6 +754,7 @@ namespace QuickMedia {
//item_thumbnail->texture.generateMipmap();
item_thumbnail->image.reset();
item_thumbnail->loading_state = LoadingState::APPLIED_TO_TEXTURE;
+ item_thumbnail->texture_applied_time.restart();
}
}