aboutsummaryrefslogtreecommitdiff
path: root/src/Body.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Body.cpp')
-rw-r--r--src/Body.cpp60
1 files changed, 31 insertions, 29 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index d14a3c5..293f516 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -13,18 +13,18 @@
static const sf::Color front_color(32, 36, 42);
static const sf::Color back_color(33, 35, 37);
-static const float spacing_y = 15.0f * QuickMedia::get_ui_scale();
-static const float padding_x = 10.0f * QuickMedia::get_ui_scale();
-static const float image_padding_x = 5.0f * QuickMedia::get_ui_scale();
-static const float padding_y = 5.0f * QuickMedia::get_ui_scale();
-static const float embedded_item_padding_y = 0.0f * QuickMedia::get_ui_scale();
+static const float spacing_y = std::floor(15.0f * QuickMedia::get_ui_scale());
+static const float padding_x = std::floor(10.0f * QuickMedia::get_ui_scale());
+static const float image_padding_x = std::floor(5.0f * QuickMedia::get_ui_scale());
+static const float padding_y = std::floor(5.0f * QuickMedia::get_ui_scale());
+static const float embedded_item_padding_y = std::floor(0.0f * QuickMedia::get_ui_scale());
static const double thumbnail_fade_duration_sec = 0.1;
-static const float reaction_background_padding_x = 7.0f * QuickMedia::get_ui_scale();
-static const float reaction_background_padding_y = 3.0f * QuickMedia::get_ui_scale();
-static const float reaction_spacing_x = 5.0f * QuickMedia::get_ui_scale();
-static const float reaction_padding_y = 7.0f * QuickMedia::get_ui_scale();
-static const int embedded_item_font_size = 14 * QuickMedia::get_ui_scale();
+static const float reaction_background_padding_x = std::floor(7.0f * QuickMedia::get_ui_scale());
+static const float reaction_background_padding_y = std::floor(3.0f * QuickMedia::get_ui_scale());
+static const float reaction_spacing_x = std::floor(5.0f * QuickMedia::get_ui_scale());
+static const float reaction_padding_y = std::floor(7.0f * QuickMedia::get_ui_scale());
+static const int embedded_item_font_size = std::floor(14 * QuickMedia::get_ui_scale());
namespace QuickMedia {
BodyItem::BodyItem(std::string _title) :
@@ -104,14 +104,14 @@ namespace QuickMedia {
void BodyItem::add_reaction(std::string text, void *userdata) {
sf::String str = sf::String::fromUtf8(text.begin(), text.end());
Reaction reaction;
- reaction.text = std::make_unique<Text>(std::move(str), false, 14 * get_ui_scale(), 0.0f);
+ reaction.text = std::make_unique<Text>(std::move(str), false, std::floor(14 * get_ui_scale()), 0.0f);
reaction.userdata = userdata;
reactions.push_back(std::move(reaction));
}
Body::Body(Program *program, sf::Texture &loading_icon_texture) :
- progress_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 14 * get_ui_scale()),
- replies_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 14 * get_ui_scale()),
+ progress_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(14 * get_ui_scale())),
+ replies_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(14 * get_ui_scale())),
embedded_item_load_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), embedded_item_font_size),
draw_thumbnails(true),
wrap_around(false),
@@ -416,6 +416,7 @@ namespace QuickMedia {
const float start_y = pos.y;
elapsed_time_sec = draw_timer.getElapsedTime().asSeconds();
+#if 0
float frame_time = frame_timer.restart().asSeconds();
if(frame_time > 2.0f)
frame_time = 2.0f;
@@ -458,6 +459,7 @@ namespace QuickMedia {
select_previous_item(false);
}
}
+#endif
//item_background.setFillColor(front_color);
//item_background.setOutlineThickness(1.0f);
@@ -674,7 +676,7 @@ namespace QuickMedia {
if(body_item->title_text)
body_item->title_text->setString(std::move(str));
else
- body_item->title_text = std::make_unique<Text>(std::move(str), false, 16 * get_ui_scale(), width);
+ body_item->title_text = std::make_unique<Text>(std::move(str), false, std::floor(16 * get_ui_scale()), width);
body_item->title_text->setFillColor(body_item->get_title_color());
body_item->title_text->updateGeometry();
}
@@ -685,7 +687,7 @@ namespace QuickMedia {
if(body_item->description_text)
body_item->description_text->setString(std::move(str));
else
- body_item->description_text = std::make_unique<Text>(std::move(str), false, 14 * get_ui_scale(), width);
+ body_item->description_text = std::make_unique<Text>(std::move(str), false, std::floor(14 * get_ui_scale()), width);
body_item->description_text->setFillColor(body_item->get_description_color());
body_item->description_text->updateGeometry();
}
@@ -696,7 +698,7 @@ namespace QuickMedia {
if(body_item->author_text)
body_item->author_text->setString(std::move(str));
else
- body_item->author_text = std::make_unique<Text>(std::move(str), true, 14 * get_ui_scale(), width);
+ body_item->author_text = std::make_unique<Text>(std::move(str), true, std::floor(14 * get_ui_scale()), width);
body_item->author_text->setFillColor(body_item->get_author_color());
body_item->author_text->updateGeometry();
}
@@ -724,7 +726,7 @@ namespace QuickMedia {
if(body_item->timestamp_text)
body_item->timestamp_text->setString(time_str);
else
- body_item->timestamp_text = std::make_unique<sf::Text>(time_str, *FontLoader::get_font(FontLoader::FontType::LATIN), 10 * get_ui_scale());
+ body_item->timestamp_text = std::make_unique<sf::Text>(time_str, *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(10 * get_ui_scale()));
body_item->timestamp_text->setFillColor(sf::Color(185, 190, 198, 100));
}
@@ -751,9 +753,9 @@ namespace QuickMedia {
sf::Vector2i Body::get_item_thumbnail_size(BodyItem *item) const {
sf::Vector2i content_size;
- sf::Vector2i thumbnail_max_size_scaled(thumbnail_max_size.x * get_ui_scale(), thumbnail_max_size.y * get_ui_scale());
+ sf::Vector2i thumbnail_max_size_scaled(std::floor(thumbnail_max_size.x * get_ui_scale()), std::floor(thumbnail_max_size.y * get_ui_scale()));
if(item->thumbnail_size.x > 0 && item->thumbnail_size.y > 0)
- content_size = clamp_to_size(sf::Vector2i(item->thumbnail_size.x * get_ui_scale(), item->thumbnail_size.y * get_ui_scale()), thumbnail_max_size_scaled);
+ content_size = clamp_to_size(sf::Vector2i(std::floor(item->thumbnail_size.x * get_ui_scale()), std::floor(item->thumbnail_size.y * get_ui_scale())), thumbnail_max_size_scaled);
else
content_size = thumbnail_max_size_scaled;
return content_size;
@@ -883,7 +885,7 @@ namespace QuickMedia {
}
}
- const float timestamp_text_y = std::floor(item_pos.y + padding_y - 6.0f * get_ui_scale());
+ const float timestamp_text_y = std::floor(item_pos.y + padding_y - std::floor(6.0f * get_ui_scale()));
if(item->author_text) {
item->author_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 6.0f * get_ui_scale()));
item->author_text->setMaxWidth(size.x - text_offset_x - image_padding_x);
@@ -902,7 +904,7 @@ namespace QuickMedia {
replies_text.setString(std::move(replies_text_str));
window.draw(replies_text);
- item_pos.y += item->author_text->getHeight() - 2.0f + 3.0f * get_ui_scale();
+ item_pos.y += item->author_text->getHeight() - 2.0f + std::floor(3.0f * get_ui_scale());
}
if(include_embedded_item && item->embedded_item_status != FetchStatus::NONE) {
@@ -930,15 +932,15 @@ namespace QuickMedia {
//title_text.setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y));
//window.draw(title_text);
if(item->title_text) {
- item->title_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 6.0f * get_ui_scale()));
+ item->title_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - std::floor(6.0f * get_ui_scale())));
item->title_text->setMaxWidth(size.x - text_offset_x - image_padding_x);
item->title_text->draw(window);
- item_pos.y += item->title_text->getHeight() - 2.0f + 3.0f * get_ui_scale();
+ item_pos.y += item->title_text->getHeight() - 2.0f + std::floor(3.0f * get_ui_scale());
}
if(item->description_text) {
float height_offset = 0.0f;
- item->description_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 6.0f * get_ui_scale() + height_offset));
+ item->description_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - std::floor(6.0f * get_ui_scale()) + height_offset));
item->description_text->setMaxWidth(size.x - text_offset_x - image_padding_x);
item->description_text->draw(window);
item_pos.y += item->description_text->getHeight() - 2.0f;
@@ -964,7 +966,7 @@ namespace QuickMedia {
reaction.text->draw(window);
if(text_offset_x + reaction_offset_x + reaction.text->getWidth() + reaction_background_padding_x * 2.0f > size.x && i < (int)item->reactions.size() - 1) {
reaction_offset_x = 0.0f;
- item_pos.y += reaction.text->getHeight() + reaction_padding_y + 6.0f * get_ui_scale();
+ item_pos.y += reaction.text->getHeight() + reaction_padding_y + std::floor(6.0f * get_ui_scale());
reaction_max_height = reaction.text->getHeight();
}
}
@@ -988,7 +990,7 @@ namespace QuickMedia {
if(current_json.isNumeric() && total_json.isNumeric()) {
progress_text.setString(std::string("Page: ") + std::to_string(current_json.asInt()) + "/" + std::to_string(total_json.asInt()));
auto bounds = progress_text.getLocalBounds();
- progress_text.setPosition(std::floor(item_pos.x + size.x - bounds.width - padding_x), timestamp_text_y + 6.0f * get_ui_scale());
+ progress_text.setPosition(std::floor(item_pos.x + size.x - bounds.width - padding_x), timestamp_text_y + std::floor(6.0f * get_ui_scale()));
window.draw(progress_text);
}
}
@@ -1045,10 +1047,10 @@ namespace QuickMedia {
float item_height = 0.0f;
if(item->title_text) {
- item_height += item->title_text->getHeight() - 2.0f + 3.0f * get_ui_scale();
+ item_height += item->title_text->getHeight() - 2.0f + std::floor(3.0f * get_ui_scale());
}
if(item->author_text) {
- item_height += item->author_text->getHeight() - 2.0f + 3.0f * get_ui_scale();
+ item_height += item->author_text->getHeight() - 2.0f + std::floor(3.0f * get_ui_scale());
}
if(include_embedded_item && item->embedded_item_status != FetchStatus::NONE) {
if(item->embedded_item)
@@ -1072,7 +1074,7 @@ namespace QuickMedia {
reaction_offset_x += reaction.text->getWidth() + reaction_background_padding_x * 2.0f + reaction_spacing_x;
if(text_offset_x + reaction_offset_x + reaction.text->getWidth() + reaction_background_padding_x * 2.0f > width && i < (int)item->reactions.size() - 1) {
reaction_offset_x = 0.0f;
- item_height += reaction.text->getHeight() + reaction_padding_y + 6.0f;
+ item_height += reaction.text->getHeight() + reaction_padding_y + std::floor(6.0f * get_ui_scale());
reaction_max_height = reaction.text->getHeight();
}
}