aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-12-01 01:13:19 +0100
committerdec05eba <dec05eba@protonmail.com>2019-12-01 01:13:19 +0100
commitf5c3fe255638aa9213209616d579060033d40926 (patch)
tree360fffe5b5544d087a5cc39b8edcb77b1bcc1415 /src
parent52528ca5980b5e8fe863ceee67067ac188c55a7a (diff)
Downscale images below default row height
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index ed4862b..2e653e5 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -127,12 +127,12 @@ namespace QuickMedia {
// hasn't been read yet.
void Body::draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, const Json::Value &content_progress) {
const float font_height = title_text.getCharacterSize() + 4.0f;
- const float image_height = 100.0f;
+ const float image_max_height = 100.0f;
const float spacing_y = 15.0f;
const float padding_y = 2.0f;
const float start_y = pos.y;
- sf::RectangleShape image_fallback(sf::Vector2f(50, image_height));
+ sf::RectangleShape image_fallback(sf::Vector2f(50, image_max_height));
image_fallback.setFillColor(sf::Color::White);
sf::Sprite image;
@@ -164,6 +164,12 @@ namespace QuickMedia {
if(item->visible) {
float item_height = font_height * std::max(1, item->num_lines);
if(draw_thumbnails && !item->thumbnail_url.empty()) {
+ auto &item_thumbnail = item_thumbnail_textures[first_visible_item];
+ float image_height = image_max_height;
+ if(item_thumbnail.texture && item_thumbnail.texture->getNativeHandle() != 0) {
+ auto image_size = item_thumbnail.texture->getSize();
+ image_height = std::min(image_max_height, (float)image_size.y);
+ }
item_height = std::max(item_height, image_height);
}
item_height += spacing_y + padding_y * 2.0f;
@@ -189,6 +195,11 @@ namespace QuickMedia {
float item_height = font_height * std::max(1, item->num_lines);
if(draw_thumbnails && !item->thumbnail_url.empty()) {
+ float image_height = image_max_height;
+ if(item_thumbnail.texture && item_thumbnail.texture->getNativeHandle() != 0) {
+ auto image_size = item_thumbnail.texture->getSize();
+ image_height = std::min(image_max_height, (float)image_size.y);
+ }
item_height = std::max(item_height, image_height);
}
item_height += (padding_y * 2.0f);
@@ -232,7 +243,7 @@ namespace QuickMedia {
if(item_thumbnail.texture && item_thumbnail.texture->getNativeHandle() != 0) {
image.setTexture(*item_thumbnail.texture, true);
auto image_size = image.getTexture()->getSize();
- auto height_ratio = image_height / image_size.y;
+ auto height_ratio = std::min(image_max_height, (float)image_size.y) / image_size.y;
auto scale = image.getScale();
auto image_scale_ratio = scale.x / scale.y;
const float width_ratio = height_ratio * image_scale_ratio;