aboutsummaryrefslogtreecommitdiff
path: root/src/Body.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-09-04 02:31:10 +0200
committerdec05eba <dec05eba@protonmail.com>2021-09-04 02:31:10 +0200
commitfa815c3eee27cdae69b2e765b03de62a13f6379d (patch)
tree4244ae7b62e2c94d749f0b199dd620bdd251dad0 /src/Body.cpp
parentdd4573e05cdfa2d9b99ef7a49c99e27c201da3e9 (diff)
Make font sizes customizable with a config file, see example-config.json. Remove environment variables
Diffstat (limited to 'src/Body.cpp')
-rw-r--r--src/Body.cpp99
1 files changed, 50 insertions, 49 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index afa1dae..68e34e8 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -3,6 +3,7 @@
#include "../include/Scale.hpp"
#include "../include/ResourceLoader.hpp"
#include "../include/AsyncImageLoader.hpp"
+#include "../include/Config.hpp"
#include "../include/Utils.hpp"
#include "../include/Theme.hpp"
#include "../include/StringUtils.hpp"
@@ -31,13 +32,13 @@ struct BodySpacing {
};
namespace QuickMedia {
- static const int card_width = 250.0f * get_ui_scale() * get_font_scale();
- static const int card_height = 350.0f * get_ui_scale() * get_font_scale();
+ static const int card_width = 250.0f * get_config().scale * get_config().font_scale;
+ static const int card_height = 350.0f * get_config().scale * get_config().font_scale;
- static const int min_column_spacing = 10 * get_ui_scale();
- static const int card_padding_x = 20 * get_ui_scale();
- static const int card_padding_y = 20 * get_ui_scale();
- static const int card_image_text_padding = 10 * get_ui_scale();
+ static const int min_column_spacing = 10 * get_config().scale;
+ static const int card_padding_x = 20 * get_config().scale;
+ static const int card_padding_y = 20 * get_config().scale;
+ static const int card_image_text_padding = 10 * get_config().scale;
static const sf::Vector2i card_max_image_size(card_width - card_padding_x * 2, (card_height - card_padding_y * 2) / 2);
static const int num_columns_switch_to_list = 1;
static const int embedded_item_border_width = 4;
@@ -46,37 +47,37 @@ namespace QuickMedia {
static bool themes_initialized = false;
static void init_body_theme_minimal() {
- body_spacing[BODY_THEME_MINIMAL].spacing_y = std::floor(10.0f * get_ui_scale());
- body_spacing[BODY_THEME_MINIMAL].padding_x = std::floor(10.0f * get_ui_scale());
- body_spacing[BODY_THEME_MINIMAL].image_padding_x = std::floor(5.0f * get_ui_scale());
- body_spacing[BODY_THEME_MINIMAL].padding_y = std::floor(5.0f * get_ui_scale());
- body_spacing[BODY_THEME_MINIMAL].padding_y_text_only = std::floor(5.0f * get_ui_scale());
- body_spacing[BODY_THEME_MINIMAL].embedded_item_padding_y = std::floor(0.0f * get_ui_scale());
- body_spacing[BODY_THEME_MINIMAL].body_padding_horizontal = std::floor(10.0f * get_ui_scale());
- body_spacing[BODY_THEME_MINIMAL].body_padding_vertical = std::floor(10.0f * get_ui_scale());
-
- body_spacing[BODY_THEME_MINIMAL].reaction_background_padding_x = std::floor(7.0f * get_ui_scale());
- body_spacing[BODY_THEME_MINIMAL].reaction_background_padding_y = std::floor(3.0f * get_ui_scale());
- body_spacing[BODY_THEME_MINIMAL].reaction_spacing_x = std::floor(5.0f * get_ui_scale());
- body_spacing[BODY_THEME_MINIMAL].reaction_padding_y = std::floor(7.0f * get_ui_scale());
- body_spacing[BODY_THEME_MINIMAL].embedded_item_font_size = std::floor(14 * get_ui_scale());
+ body_spacing[BODY_THEME_MINIMAL].spacing_y = std::floor(10.0f * get_config().scale);
+ body_spacing[BODY_THEME_MINIMAL].padding_x = std::floor(10.0f * get_config().scale);
+ body_spacing[BODY_THEME_MINIMAL].image_padding_x = std::floor(5.0f * get_config().scale);
+ body_spacing[BODY_THEME_MINIMAL].padding_y = std::floor(5.0f * get_config().scale);
+ body_spacing[BODY_THEME_MINIMAL].padding_y_text_only = std::floor(5.0f * get_config().scale);
+ body_spacing[BODY_THEME_MINIMAL].embedded_item_padding_y = std::floor(0.0f * get_config().scale);
+ body_spacing[BODY_THEME_MINIMAL].body_padding_horizontal = std::floor(10.0f * get_config().scale);
+ body_spacing[BODY_THEME_MINIMAL].body_padding_vertical = std::floor(10.0f * get_config().scale);
+
+ body_spacing[BODY_THEME_MINIMAL].reaction_background_padding_x = std::floor(7.0f * get_config().scale);
+ body_spacing[BODY_THEME_MINIMAL].reaction_background_padding_y = std::floor(3.0f * get_config().scale);
+ body_spacing[BODY_THEME_MINIMAL].reaction_spacing_x = std::floor(5.0f * get_config().scale);
+ body_spacing[BODY_THEME_MINIMAL].reaction_padding_y = std::floor(7.0f * get_config().scale);
+ body_spacing[BODY_THEME_MINIMAL].embedded_item_font_size = std::floor(get_config().body.embedded_load_font_size * get_config().scale * get_config().font_scale);
}
static void init_body_theme_modern_spacious() {
- body_spacing[BODY_THEME_MODERN_SPACIOUS].spacing_y = std::floor(20.0f * get_ui_scale());
- body_spacing[BODY_THEME_MODERN_SPACIOUS].padding_x = std::floor(20.0f * get_ui_scale());
- body_spacing[BODY_THEME_MODERN_SPACIOUS].image_padding_x = std::floor(15.0f * get_ui_scale());
- body_spacing[BODY_THEME_MODERN_SPACIOUS].padding_y = std::floor(15.0f * get_ui_scale());
- body_spacing[BODY_THEME_MODERN_SPACIOUS].padding_y_text_only = std::floor(7.0f * get_ui_scale());
- body_spacing[BODY_THEME_MODERN_SPACIOUS].embedded_item_padding_y = std::floor(0.0f * get_ui_scale());
- body_spacing[BODY_THEME_MODERN_SPACIOUS].body_padding_horizontal = std::floor(20.0f * get_ui_scale());
- body_spacing[BODY_THEME_MODERN_SPACIOUS].body_padding_vertical = std::floor(20.0f * get_ui_scale());
-
- body_spacing[BODY_THEME_MODERN_SPACIOUS].reaction_background_padding_x = std::floor(7.0f * get_ui_scale());
- body_spacing[BODY_THEME_MODERN_SPACIOUS].reaction_background_padding_y = std::floor(3.0f * get_ui_scale());
- body_spacing[BODY_THEME_MODERN_SPACIOUS].reaction_spacing_x = std::floor(5.0f * get_ui_scale());
- body_spacing[BODY_THEME_MODERN_SPACIOUS].reaction_padding_y = std::floor(7.0f * get_ui_scale());
- body_spacing[BODY_THEME_MODERN_SPACIOUS].embedded_item_font_size = std::floor(14 * get_ui_scale());
+ body_spacing[BODY_THEME_MODERN_SPACIOUS].spacing_y = std::floor(20.0f * get_config().scale);
+ body_spacing[BODY_THEME_MODERN_SPACIOUS].padding_x = std::floor(20.0f * get_config().scale);
+ body_spacing[BODY_THEME_MODERN_SPACIOUS].image_padding_x = std::floor(15.0f * get_config().scale);
+ body_spacing[BODY_THEME_MODERN_SPACIOUS].padding_y = std::floor(15.0f * get_config().scale);
+ body_spacing[BODY_THEME_MODERN_SPACIOUS].padding_y_text_only = std::floor(7.0f * get_config().scale);
+ body_spacing[BODY_THEME_MODERN_SPACIOUS].embedded_item_padding_y = std::floor(0.0f * get_config().scale);
+ body_spacing[BODY_THEME_MODERN_SPACIOUS].body_padding_horizontal = std::floor(20.0f * get_config().scale);
+ body_spacing[BODY_THEME_MODERN_SPACIOUS].body_padding_vertical = std::floor(20.0f * get_config().scale);
+
+ body_spacing[BODY_THEME_MODERN_SPACIOUS].reaction_background_padding_x = std::floor(7.0f * get_config().scale);
+ body_spacing[BODY_THEME_MODERN_SPACIOUS].reaction_background_padding_y = std::floor(3.0f * get_config().scale);
+ body_spacing[BODY_THEME_MODERN_SPACIOUS].reaction_spacing_x = std::floor(5.0f * get_config().scale);
+ body_spacing[BODY_THEME_MODERN_SPACIOUS].reaction_padding_y = std::floor(7.0f * get_config().scale);
+ body_spacing[BODY_THEME_MODERN_SPACIOUS].embedded_item_font_size = std::floor(get_config().body.embedded_load_font_size * get_config().scale * get_config().font_scale);
}
static void init_body_themes() {
@@ -100,8 +101,8 @@ namespace QuickMedia {
selected_item(0),
prev_selected_item(0),
loading_icon(loading_icon_texture),
- progress_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(14 * get_ui_scale() * get_font_scale())),
- replies_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(14 * get_ui_scale() * get_font_scale())),
+ progress_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(get_config().body.progress_font_size * get_config().scale * get_config().font_scale)),
+ replies_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(get_config().body.replies_font_size * get_config().scale * get_config().font_scale)),
num_visible_items(0),
top_cut_off(false),
bottom_cut_off(false),
@@ -850,7 +851,7 @@ namespace QuickMedia {
body_item->title_text->setString(std::move(str));
body_item->title_text->setMaxWidth(width);
} else {
- body_item->title_text = std::make_unique<Text>(std::move(str), false, std::floor(16 * get_ui_scale() * get_font_scale()), width, title_mark_urls);
+ body_item->title_text = std::make_unique<Text>(std::move(str), false, std::floor(get_config().body.title_font_size * get_config().scale * get_config().font_scale), width, title_mark_urls);
}
body_item->title_text->setFillColor(body_item->get_title_color());
body_item->title_text->updateGeometry();
@@ -863,7 +864,7 @@ namespace QuickMedia {
body_item->description_text->setString(std::move(str));
body_item->description_text->setMaxWidth(width);
} else {
- body_item->description_text = std::make_unique<Text>(std::move(str), false, std::floor(14 * get_ui_scale() * get_font_scale()), width, true);
+ body_item->description_text = std::make_unique<Text>(std::move(str), false, std::floor(get_config().body.description_font_size * get_config().scale * get_config().font_scale), width, true);
}
body_item->description_text->setFillColor(body_item->get_description_color());
body_item->description_text->updateGeometry();
@@ -876,7 +877,7 @@ namespace QuickMedia {
body_item->author_text->setString(std::move(str));
body_item->author_text->setMaxWidth(width);
} else {
- body_item->author_text = std::make_unique<Text>(std::move(str), true, std::floor(14 * get_ui_scale() * get_font_scale()), width);
+ body_item->author_text = std::make_unique<Text>(std::move(str), true, std::floor(get_config().body.author_font_size * get_config().scale * get_config().font_scale), width);
}
body_item->author_text->setFillColor(body_item->get_author_color());
body_item->author_text->updateGeometry();
@@ -901,7 +902,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), std::floor(10 * get_ui_scale() * get_font_scale()));
+ body_item->timestamp_text = std::make_unique<sf::Text>(time_str, *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(get_config().body.timestamp_font_size * get_config().scale * get_config().font_scale));
}
body_item->timestamp_text->setFillColor(get_current_theme().timestamp_text_color);
@@ -932,11 +933,11 @@ namespace QuickMedia {
sf::Vector2i Body::get_item_thumbnail_size(BodyItem *item) const {
sf::Vector2i content_size;
- sf::Vector2i thumbnail_max_size_scaled = (card_view && card_view_enabled) ? card_max_image_size : sf::Vector2i(thumbnail_max_size.x * get_ui_scale(), thumbnail_max_size.y * get_ui_scale());
+ sf::Vector2i thumbnail_max_size_scaled = (card_view && card_view_enabled) ? card_max_image_size : sf::Vector2i(thumbnail_max_size.x * get_config().scale, thumbnail_max_size.y * get_config().scale);
if(item->thumbnail_size.x > 0 && item->thumbnail_size.y > 0)
- 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);
+ content_size = clamp_to_size(sf::Vector2i(std::floor(item->thumbnail_size.x * get_config().scale), std::floor(item->thumbnail_size.y * get_config().scale)), thumbnail_max_size_scaled);
else
- content_size = sf::Vector2i(250 * get_ui_scale(), 141 * get_ui_scale());
+ content_size = sf::Vector2i(250 * get_config().scale, 141 * get_config().scale);
return content_size;
}
@@ -1424,7 +1425,7 @@ namespace QuickMedia {
text_offset_x += body_spacing[body_theme].image_padding_x + item->loaded_image_size.x;
}
- const float text_offset_y = std::floor(6.0f * get_ui_scale() * get_font_scale());
+ const float text_offset_y = std::floor(6.0f * get_config().scale * get_config().font_scale);
const float timestamp_text_y = std::floor(item_pos.y + padding_y - text_offset_y);
if(item->author_text && !merge_with_previous) {
@@ -1444,7 +1445,7 @@ namespace QuickMedia {
replies_text.setString(std::move(replies_text_str));
window.draw(replies_text);
- item_pos.y += item->author_text->getHeight() - 2.0f + std::floor(3.0f * get_ui_scale());
+ item_pos.y += item->author_text->getHeight() - 2.0f + std::floor(3.0f * get_config().scale);
}
if(include_embedded_item && item->embedded_item_status != FetchStatus::NONE) {
@@ -1473,7 +1474,7 @@ namespace QuickMedia {
if(item->title_text) {
item->title_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - text_offset_y));
item->title_text->draw(window);
- item_pos.y += item->title_text->getHeight() - 2.0f + std::floor(3.0f * get_ui_scale());
+ item_pos.y += item->title_text->getHeight() - 2.0f + std::floor(3.0f * get_config().scale);
}
if(item->description_text) {
@@ -1574,11 +1575,11 @@ namespace QuickMedia {
float item_height = 0.0f;
bool has_loaded_text = false;
if(item->title_text) {
- item_height += item->title_text->getHeight() - 2.0f + std::floor(3.0f * get_ui_scale());
+ item_height += item->title_text->getHeight() - 2.0f + std::floor(3.0f * get_config().scale);
has_loaded_text = true;
}
if(item->author_text && !merge_with_previous) {
- item_height += item->author_text->getHeight() - 2.0f + std::floor(3.0f * get_ui_scale());
+ item_height += item->author_text->getHeight() - 2.0f + std::floor(3.0f * get_config().scale);
has_loaded_text = true;
}
if(include_embedded_item && item->embedded_item_status != FetchStatus::NONE) {
@@ -1607,7 +1608,7 @@ namespace QuickMedia {
reaction_offset_x += reaction.text->getWidth() + body_spacing[body_theme].reaction_background_padding_x * 2.0f + body_spacing[body_theme].reaction_spacing_x;
if(text_offset_x + reaction_offset_x + reaction.text->getWidth() + body_spacing[body_theme].reaction_background_padding_x * 2.0f > width && i < (int)item->reactions.size() - 1) {
reaction_offset_x = 0.0f;
- item_height += reaction.text->getHeight() + body_spacing[body_theme].reaction_padding_y + std::floor(6.0f * get_ui_scale());
+ item_height += reaction.text->getHeight() + body_spacing[body_theme].reaction_padding_y + std::floor(6.0f * get_config().scale);
reaction_max_height = reaction.text->getHeight();
}
}