aboutsummaryrefslogtreecommitdiff
path: root/src/Body.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-21 03:12:35 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-21 03:12:35 +0200
commitea6f1b425a6aa9b7145a00d81473ef9508279eec (patch)
tree61f3d59aa277b889ed149cf6ccd5fc9dc2b836c8 /src/Body.cpp
parentf126659965425ee5f5a3851fbe83ae532e48c478 (diff)
Fix thumbnail fallback size being incorrect, incorrect read marker for matrix
Diffstat (limited to 'src/Body.cpp')
-rw-r--r--src/Body.cpp43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index 1d06559..a7d772b 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -59,8 +59,8 @@ namespace QuickMedia {
{
progress_text.setFillColor(sf::Color::White);
replies_text.setFillColor(sf::Color(129, 162, 190));
- thumbnail_resize_target_size.x = 120;
- thumbnail_resize_target_size.y = 120;
+ thumbnail_resize_target_size.x = 250;
+ thumbnail_resize_target_size.y = 141;
item_background.setFillColor(sf::Color(55, 60, 68));
sf::Vector2f loading_icon_size(loading_icon.getTexture()->getSize().x, loading_icon.getTexture()->getSize().y);
loading_icon.setOrigin(loading_icon_size.x * 0.5f, loading_icon_size.y * 0.5f);
@@ -381,8 +381,10 @@ namespace QuickMedia {
if(!item->visible)
continue;
- if(after_pos.y - start_y >= size.y)
+ if(after_pos.y - start_y >= size.y) {
+ last_item_fully_visible = false;
break;
+ }
update_dirty_state(item.get(), size);
float item_height = get_item_height(item.get());
@@ -504,6 +506,19 @@ namespace QuickMedia {
}
}
+ sf::Vector2i Body::get_item_thumbnail_size(BodyItem *item) const {
+ sf::Vector2i content_size;
+ if(item->thumbnail_size.x > 0 && item->thumbnail_size.y > 0)
+ content_size = clamp_to_size(item->thumbnail_size, thumbnail_resize_target_size);
+ else
+ content_size = thumbnail_resize_target_size;
+ return content_size;
+ }
+
+ static sf::Vector2f to_vec2f(const sf::Vector2i &vec) {
+ return sf::Vector2f(vec.x, vec.y);
+ }
+
void Body::draw_item(sf::RenderWindow &window, BodyItem *item, sf::Vector2f pos, sf::Vector2f size, bool include_embedded_item) {
update_dirty_state(item, size);
item->last_drawn_time = draw_timer.getElapsedTime().asMilliseconds();
@@ -579,9 +594,7 @@ namespace QuickMedia {
image.setTexture(item_thumbnail->texture, true);
auto image_size = image.getTexture()->getSize();
sf::Vector2f image_size_f(image_size.x, image_size.y);
- 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);
+ sf::Vector2f content_size = to_vec2f(get_item_thumbnail_size(item));
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));
@@ -595,12 +608,8 @@ namespace QuickMedia {
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));
- }
-
- 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);
+ } else if(!item->thumbnail_url.empty() && !only_show_thumbnail) {
+ sf::Vector2f content_size = to_vec2f(get_item_thumbnail_size(item));
sf::Uint8 fallback_fade_alpha = (1.0 - thumbnail_fade_progress) * 255;
sf::Color fallback_color(52, 58, 70, fallback_fade_alpha);
@@ -733,9 +742,8 @@ namespace QuickMedia {
item_height += item->description_text->getHeight() - 2.0f;
}
if(draw_thumbnails && !item->thumbnail_url.empty()) {
- float image_height = thumbnail_resize_target_size.y;
- if(item->thumbnail_size.x > 0 && item->thumbnail_size.y > 0)
- image_height = item->thumbnail_size.y;
+ sf::Vector2i content_size = get_item_thumbnail_size(item);
+ float image_height = content_size.y;
std::shared_ptr<ThumbnailData> item_thumbnail;
auto item_thumbnail_it = item_thumbnail_textures.find(item->thumbnail_url);
@@ -772,10 +780,7 @@ namespace QuickMedia {
if(item_thumbnail && item_thumbnail->loading_state == LoadingState::APPLIED_TO_TEXTURE && item_thumbnail->texture.getNativeHandle() != 0) {
auto image_size = item_thumbnail->texture.getSize();
sf::Vector2f image_size_f(image_size.x, image_size.y);
- 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);
- auto new_image_size = clamp_to_size(image_size_f, content_size);
+ auto new_image_size = clamp_to_size(image_size_f, to_vec2f(content_size));
image_height = new_image_size.y;
}