aboutsummaryrefslogtreecommitdiff
path: root/src/Body.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Body.cpp')
-rw-r--r--src/Body.cpp51
1 files changed, 38 insertions, 13 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index 73c3932..ab68a61 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -11,7 +11,7 @@ const sf::Color front_color(43, 45, 47);
const sf::Color back_color(33, 35, 37);
namespace QuickMedia {
- BodyItem::BodyItem(std::string _title): visible(true), dirty(true), background_color(front_color) {
+ BodyItem::BodyItem(std::string _title): visible(true), dirty(false), dirty_description(false), background_color(front_color) {
set_title(std::move(_title));
}
@@ -24,6 +24,7 @@ namespace QuickMedia {
author = other.author;
visible = other.visible;
dirty = other.dirty;
+ dirty_description = other.dirty_description;
if(other.title_text)
title_text = std::make_unique<Text>(*other.title_text);
else
@@ -37,16 +38,16 @@ namespace QuickMedia {
}
Body::Body(Program *program, sf::Font *font, sf::Font *bold_font) :
- program(program),
font(font),
bold_font(bold_font),
progress_text("", *font, 14),
author_text("", *bold_font, 16),
replies_text("", *font, 14),
- selected_item(0),
draw_thumbnails(false),
+ wrap_around(false),
+ program(program),
loading_thumbnail(false),
- wrap_around(false)
+ selected_item(0)
{
progress_text.setFillColor(sf::Color::White);
author_text.setFillColor(sf::Color::White);
@@ -134,6 +135,12 @@ namespace QuickMedia {
selected_item = 0;
}
+ void Body::append_items(BodyItems new_items) {
+ for(auto &body_item : new_items) {
+ items.push_back(std::move(body_item));
+ }
+ }
+
void Body::clear_thumbnails() {
item_thumbnail_textures.clear();
}
@@ -230,6 +237,7 @@ namespace QuickMedia {
thumbnail_it.second.referenced = false;
}
+ // TODO: Change font size. Currently it doesn't work because it glitches out. Why does that happen??
for(auto &body_item : items) {
if(body_item->dirty) {
body_item->dirty = false;
@@ -240,8 +248,12 @@ namespace QuickMedia {
body_item->title_text->updateGeometry();
}
- if(!body_item->get_description().empty() && !body_item->description_text) {
- body_item->description_text = std::make_unique<Text>(body_item->get_description(), font, 14, size.x - 50 - image_padding_x * 2.0f);
+ if(body_item->dirty_description) {
+ body_item->dirty_description = true;
+ if(body_item->description_text)
+ body_item->description_text->setString(body_item->get_description());
+ else
+ body_item->description_text = std::make_unique<Text>(body_item->get_description(), font, 14, size.x - 50 - image_padding_x * 2.0f);
body_item->description_text->updateGeometry();
}
}
@@ -253,7 +265,10 @@ namespace QuickMedia {
for(; first_visible_item >= 0; --first_visible_item) {
auto &item = items[first_visible_item];
if(item->visible) {
- float item_height = item->title_text->getHeight();
+ float item_height = 0.0f;
+ if(!item->get_title().empty()) {
+ item_height += item->title_text->getHeight();
+ }
if(!item->author.empty()) {
item_height += author_text.getCharacterSize() + 2.0f;
}
@@ -299,7 +314,10 @@ namespace QuickMedia {
item_thumbnail_textures[item->thumbnail_url].referenced = true;
auto &item_thumbnail = item_thumbnail_textures[item->thumbnail_url];
- float item_height = item->title_text->getHeight();
+ float item_height = 0.0f;
+ if(!item->get_title().empty()) {
+ item_height += item->title_text->getHeight();
+ }
if(!item->author.empty()) {
item_height += author_text.getCharacterSize() + 2.0f;
}
@@ -371,6 +389,7 @@ namespace QuickMedia {
}
if(!item->author.empty()) {
+ // TODO: Remove this call, should not be called every frame
author_text.setString(item->author);
author_text.setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y));
window.draw(author_text);
@@ -390,12 +409,18 @@ namespace QuickMedia {
//title_text.setString(item->title);
//title_text.setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y));
//window.draw(title_text);
- item->title_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 4.0f));
- item->title_text->setMaxWidth(size.x - text_offset_x - image_padding_x * 2.0f);
- item->title_text->draw(window);
+ if(!item->get_title().empty()) {
+ item->title_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 4.0f));
+ item->title_text->setMaxWidth(size.x - text_offset_x - image_padding_x * 2.0f);
+ item->title_text->draw(window);
+ }
- if(item->description_text) {
- item->description_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 4.0f + item->title_text->getHeight()));
+ if(!item->get_description().empty()) {
+ float height_offset = 0.0f;
+ if(!item->get_title().empty()) {
+ height_offset = item->title_text->getHeight();
+ }
+ item->description_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 4.0f + height_offset));
item->description_text->setMaxWidth(size.x - text_offset_x - image_padding_x * 2.0f);
item->description_text->draw(window);
}