aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp60
-rw-r--r--src/Entry.cpp14
-rw-r--r--src/QuickMedia.cpp58
-rw-r--r--src/SearchBar.cpp16
-rw-r--r--src/Text.cpp12
5 files changed, 81 insertions, 79 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();
}
}
diff --git a/src/Entry.cpp b/src/Entry.cpp
index facb615..fdd7225 100644
--- a/src/Entry.cpp
+++ b/src/Entry.cpp
@@ -6,18 +6,18 @@
#include <SFML/Window/Event.hpp>
#include <cmath>
-const float background_margin_horizontal = 5.0f * QuickMedia::get_ui_scale();
-const float padding_vertical = 3.0f * QuickMedia::get_ui_scale();
-const float background_margin_vertical = 0.0f * QuickMedia::get_ui_scale();
+const float background_margin_horizontal = std::floor(5.0f * QuickMedia::get_ui_scale());
+const float padding_vertical = std::floor(3.0f * QuickMedia::get_ui_scale());
+const float background_margin_vertical = std::floor(0.0f * QuickMedia::get_ui_scale());
namespace QuickMedia {
Entry::Entry(const std::string &placeholder_text) :
on_submit_callback(nullptr),
draw_background(true),
- text("", false, 16 * get_ui_scale(), 0.0f),
+ text("", false, std::floor(16 * get_ui_scale()), 0.0f),
width(0.0f),
background(sf::Vector2f(1.0f, 1.0f), 7.0f, 10),
- placeholder(placeholder_text, *FontLoader::get_font(FontLoader::FontType::LATIN), 16 * get_ui_scale())
+ placeholder(placeholder_text, *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(16 * get_ui_scale()))
{
text.setEditable(true);
background.setFillColor(sf::Color(55, 60, 68));
@@ -75,8 +75,8 @@ namespace QuickMedia {
void Entry::set_position(const sf::Vector2f &pos) {
background.setPosition(pos);
- text.setPosition(pos + sf::Vector2f(background_margin_horizontal, background_margin_vertical - 3.0f * get_ui_scale()));
- placeholder.setPosition(pos + sf::Vector2f(background_margin_horizontal, background_margin_vertical + 3.0f * get_ui_scale()));
+ text.setPosition(pos + sf::Vector2f(background_margin_horizontal, background_margin_vertical - std::floor(3.0f * get_ui_scale())));
+ placeholder.setPosition(pos + sf::Vector2f(background_margin_horizontal, background_margin_vertical + std::floor(3.0f * get_ui_scale())));
}
void Entry::set_max_width(float width) {
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index e080cbc..d54229f 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -47,10 +47,10 @@
static const sf::Color back_color(21, 25, 30);
static const std::string fourchan_google_captcha_api_key = "6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc";
-static const float tab_text_size = 16.0f * QuickMedia::get_ui_scale();
-static const float tab_height = tab_text_size + 10.0f * QuickMedia::get_ui_scale();
+static const float tab_text_size = std::floor(16.0f * QuickMedia::get_ui_scale());
+static const float tab_height = tab_text_size + std::floor(10.0f * QuickMedia::get_ui_scale());
static const sf::Color tab_selected_color(55, 60, 68);
-static const float tab_margin_x = 10.0f * QuickMedia::get_ui_scale();
+static const float tab_margin_x = std::floor(10.0f * QuickMedia::get_ui_scale());
static int FPS_IDLE = 2;
static const double IDLE_TIMEOUT_SEC = 2.0;
@@ -929,12 +929,12 @@ namespace QuickMedia {
static void get_body_dimensions(const sf::Vector2f &window_size, SearchBar *search_bar, sf::Vector2f &body_pos, sf::Vector2f &body_size, bool has_tabs = false) {
float body_padding_horizontal = 25.0f;
- float body_padding_vertical = 25.0f * get_ui_scale();
+ float body_padding_vertical = std::floor(25.0f * get_ui_scale());
float body_width = window_size.x - body_padding_horizontal * 2.0f;
if(body_width <= 480.0f) {
body_width = window_size.x;
body_padding_horizontal = 0.0f;
- body_padding_vertical = 10.0f * get_ui_scale();
+ body_padding_vertical = std::floor(10.0f * get_ui_scale());
}
float tab_h = tab_height;
@@ -1001,17 +1001,17 @@ namespace QuickMedia {
{
float shade_extra_height = 0.0f;
if(!tabs[selected_tab].search_bar)
- shade_extra_height = 10.0f * get_ui_scale();
+ shade_extra_height = std::floor(10.0f * get_ui_scale());
const float width_per_tab = window_size.x / tabs.size();
tab_background.setSize(sf::Vector2f(std::floor(width_per_tab - tab_margin_x * 2.0f), tab_height));
float tab_vertical_offset = tabs[selected_tab].search_bar ? tabs[selected_tab].search_bar->getBottomWithoutShadow() : 0.0f;
tabs[selected_tab].body->draw(window, body_pos, body_size, *json_chapters);
- const float tab_y = std::floor(tab_vertical_offset + tab_height * 0.5f - (tab_text_size + 5.0f * get_ui_scale()) * 0.5f) + shade_extra_height;
+ const float tab_y = std::floor(tab_vertical_offset + tab_height * 0.5f - (tab_text_size + std::floor(5.0f * get_ui_scale())) * 0.5f) + shade_extra_height;
tab_shade.setPosition(0.0f, std::floor(tab_vertical_offset));
- tab_shade.setSize(sf::Vector2f(window_size.x, shade_extra_height + tab_height + 10.0f * get_ui_scale()));
+ tab_shade.setSize(sf::Vector2f(window_size.x, shade_extra_height + tab_height + std::floor(10.0f * get_ui_scale())));
window.draw(tab_shade);
int i = 0;
@@ -1024,7 +1024,7 @@ namespace QuickMedia {
const float center = (i * width_per_tab) + (width_per_tab * 0.5f);
// TODO: Optimize. Only set once for each tab!
tab_text.setString(tab.page->get_title());
- tab_text.setPosition(std::floor(center - tab_text.getLocalBounds().width * 0.5f), tab_y);
+ tab_text.setPosition(std::floor(center - tab_text.getLocalBounds().width * 0.5f), std::floor(tab_y));
window.draw(tab_text);
++i;
}
@@ -1080,7 +1080,7 @@ namespace QuickMedia {
std::vector<TabAssociatedData> tab_associated_data;
for(size_t i = 0; i < tabs.size(); ++i) {
TabAssociatedData data;
- data.search_result_text = sf::Text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 30 * get_ui_scale());
+ data.search_result_text = sf::Text("", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(30 * get_ui_scale()));
tab_associated_data.push_back(std::move(data));
}
@@ -2266,7 +2266,7 @@ namespace QuickMedia {
sf::Texture image_texture;
sf::Sprite image;
- sf::Text error_message("", *FontLoader::get_font(FontLoader::FontType::LATIN), 30 * get_ui_scale());
+ sf::Text error_message("", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(30 * get_ui_scale()));
error_message.setFillColor(sf::Color::White);
bool download_in_progress = false;
@@ -2330,7 +2330,7 @@ namespace QuickMedia {
bool error = !error_message.getString().isEmpty();
bool redraw = true;
- sf::Text chapter_text(images_page->manga_name + " | " + images_page->get_chapter_name() + " | Page " + std::to_string(image_index + 1) + "/" + std::to_string(num_images), *FontLoader::get_font(FontLoader::FontType::LATIN), 14 * get_ui_scale());
+ sf::Text chapter_text(images_page->manga_name + " | " + images_page->get_chapter_name() + " | Page " + std::to_string(image_index + 1) + "/" + std::to_string(num_images), *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(14 * get_ui_scale()));
if(image_index == num_images)
chapter_text.setString(images_page->manga_name + " | " + images_page->get_chapter_name() + " | End");
chapter_text.setFillColor(sf::Color::White);
@@ -2599,7 +2599,7 @@ namespace QuickMedia {
sf::Sprite attached_image_sprite;
GoogleCaptchaChallengeInfo challenge_info;
- sf::Text challenge_description_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 24 * get_ui_scale());
+ sf::Text challenge_description_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(24 * get_ui_scale()));
challenge_description_text.setFillColor(sf::Color::White);
const size_t captcha_num_columns = 3;
const size_t captcha_num_rows = 3;
@@ -2726,9 +2726,9 @@ namespace QuickMedia {
float prev_chat_height = comment_input.get_height();
float chat_input_height_full = 0.0f;
- const float logo_padding_x = 15.0f * get_ui_scale();
- const float chat_input_padding_x = 10.0f * get_ui_scale();
- const float chat_input_padding_y = 10.0f * get_ui_scale();
+ const float logo_padding_x = std::floor(15.0f * get_ui_scale());
+ const float chat_input_padding_x = std::floor(10.0f * get_ui_scale());
+ const float chat_input_padding_y = std::floor(10.0f * get_ui_scale());
sf::Vector2f body_pos;
sf::Vector2f body_size;
@@ -2940,7 +2940,7 @@ namespace QuickMedia {
comment_input.set_position(sf::Vector2f(std::floor(logo_padding_x + logo_size.x + chat_input_padding_x), chat_input_padding_y));
float body_padding_horizontal = 25.0f;
- float body_padding_vertical = 5.0f * get_ui_scale();
+ float body_padding_vertical = std::floor(5.0f * get_ui_scale());
float body_width = window_size.x - body_padding_horizontal * 2.0f;
if(body_width <= 480.0f) {
body_width = window_size.x;
@@ -3069,7 +3069,7 @@ namespace QuickMedia {
SearchBar password_input(nullptr, "Password", true);
SearchBar homeserver_input(nullptr, "Homeserver");
- sf::Text status_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 18 * get_ui_scale());
+ sf::Text status_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(18 * get_ui_scale()));
const int num_inputs = 3;
SearchBar *inputs[num_inputs] = { &login_input, &password_input, &homeserver_input };
@@ -3287,15 +3287,15 @@ namespace QuickMedia {
ChatState chat_state = ChatState::NAVIGATING;
std::shared_ptr<BodyItem> currently_operating_on_item;
- sf::Text replying_to_text("Replying to:", *FontLoader::get_font(FontLoader::FontType::LATIN), 18 * get_ui_scale());
+ sf::Text replying_to_text("Replying to:", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(18 * get_ui_scale()));
sf::Sprite logo_sprite(plugin_logo);
logo_sprite.setScale(0.8f * get_ui_scale(), 0.8f * get_ui_scale());
sf::Vector2f logo_size(plugin_logo.getSize().x * logo_sprite.getScale().x, plugin_logo.getSize().y * logo_sprite.getScale().y);
- sf::Text room_name_text("", *FontLoader::get_font(FontLoader::FontType::LATIN_BOLD), 18 * get_ui_scale());
- const float room_name_text_height = 18.0f * get_ui_scale();
- const float room_name_text_padding_y = 10.0f * get_ui_scale();
+ sf::Text room_name_text("", *FontLoader::get_font(FontLoader::FontType::LATIN_BOLD), std::floor(18 * get_ui_scale()));
+ const float room_name_text_height = std::floor(18.0f * get_ui_scale());
+ const float room_name_text_padding_y = std::floor(10.0f * get_ui_scale());
const float room_name_total_height = room_name_text_height + room_name_text_padding_y * 2.0f;
const float room_avatar_height = 32.0f;
@@ -4032,9 +4032,9 @@ namespace QuickMedia {
float prev_chat_height = chat_input.get_height();
float chat_input_height_full = 0.0f;
- const float logo_padding_x = 15.0f * get_ui_scale();
- const float chat_input_padding_x = 10.0f * get_ui_scale();
- const float chat_input_padding_y = 10.0f * get_ui_scale();
+ const float logo_padding_x = std::floor(15.0f * get_ui_scale());
+ const float chat_input_padding_x = std::floor(10.0f * get_ui_scale());
+ const float chat_input_padding_y = std::floor(10.0f * get_ui_scale());
auto launch_url = [this, &video_page, &redraw](const std::string &url) mutable {
if(url.empty())
@@ -4672,13 +4672,13 @@ namespace QuickMedia {
float padding_bottom = 0.0f;
if(selected_tab == MESSAGES_TAB_INDEX || selected_tab == PINNED_TAB_INDEX) {
room_name_padding_y = 10.0f + room_name_total_height;
- tab_vertical_offset = 10.0f * get_ui_scale();
+ tab_vertical_offset = std::floor(10.0f * get_ui_scale());
}
tab_shade_height = tab_spacer_height + std::floor(tab_vertical_offset) + tab_height + room_name_padding_y + padding_bottom;
float body_padding_horizontal = 25.0f;
- float body_padding_vertical = 5.0f * get_ui_scale();
+ float body_padding_vertical = std::floor(5.0f * get_ui_scale());
float body_width = window_size.x - body_padding_horizontal * 2.0f;
if(body_width <= 480.0f) {
body_width = window_size.x;
@@ -4687,7 +4687,7 @@ namespace QuickMedia {
this->body_pos = sf::Vector2f(0.0f, tab_shade_height);
if(window_size.x > 900.0f && show_room_side_panel) {
- this->body_size = sf::Vector2f(300.0f * get_ui_scale(), window_size.y - tab_shade_height);
+ this->body_size = sf::Vector2f(std::floor(300.0f * get_ui_scale()), window_size.y - tab_shade_height);
draw_room_list = true;
} else {
this->body_size = sf::Vector2f(0.0f, 0.0f);
@@ -4849,7 +4849,7 @@ namespace QuickMedia {
window.draw(tab_background);
}
const float center = body_pos.x + (i * width_per_tab) + (width_per_tab * 0.5f);
- tab.text.setPosition(std::floor(center - tab.text.getLocalBounds().width * 0.5f), tab_y);
+ tab.text.setPosition(std::floor(center - tab.text.getLocalBounds().width * 0.5f), std::floor(tab_y));
window.draw(tab.text);
++i;
}
diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp
index 8232033..26b00a4 100644
--- a/src/SearchBar.cpp
+++ b/src/SearchBar.cpp
@@ -12,11 +12,11 @@
static const sf::Color text_placeholder_color(255, 255, 255, 100);
static const sf::Color front_color(55, 60, 68);
-static const float background_margin_horizontal = 10.0f + 5.0f * QuickMedia::get_ui_scale();
-static const float PADDING_HORIZONTAL = 25.0f * QuickMedia::get_ui_scale();
-static const float padding_top = 10.0f * QuickMedia::get_ui_scale();
-static const float padding_bottom = 15.0f * QuickMedia::get_ui_scale();
-static const float background_margin_vertical = 4.0f * QuickMedia::get_ui_scale();
+static const float background_margin_horizontal = 10.0f + std::floor(5.0f * QuickMedia::get_ui_scale());
+static const float PADDING_HORIZONTAL = std::floor(25.0f * QuickMedia::get_ui_scale());
+static const float padding_top = std::floor(10.0f * QuickMedia::get_ui_scale());
+static const float padding_bottom = std::floor(15.0f * QuickMedia::get_ui_scale());
+static const float background_margin_vertical = std::floor(4.0f * QuickMedia::get_ui_scale());
namespace QuickMedia {
SearchBar::SearchBar(sf::Texture *plugin_logo, const std::string &placeholder, bool input_masked) :
@@ -27,8 +27,8 @@ namespace QuickMedia {
text_autosearch_delay(0),
autocomplete_search_delay(0),
caret_visible(true),
- text(placeholder, *FontLoader::get_font(FontLoader::FontType::LATIN), 16 * get_ui_scale()),
- autocomplete_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 16 * get_ui_scale()),
+ text(placeholder, *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(16 * get_ui_scale())),
+ autocomplete_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), std::floor(16 * get_ui_scale())),
background(sf::Vector2f(1.0f, 1.0f), 10.0f, 10),
placeholder_str(placeholder),
show_placeholder(true),
@@ -152,7 +152,7 @@ namespace QuickMedia {
background.setSize(sf::Vector2f(width, rect_height));
shade.setSize(sf::Vector2f(window_size.x, padding_top + rect_height + padding_bottom));
- caret.setSize(sf::Vector2f(2.0f * get_ui_scale(), text.getCharacterSize() + 2.0f * get_ui_scale()));
+ caret.setSize(sf::Vector2f(std::floor(2.0f * get_ui_scale()), text.getCharacterSize() + std::floor(2.0f * get_ui_scale())));
background_shadow.setSize(sf::Vector2f(window_size.x, 5.0f));
background.setPosition(offset_x, padding_top + vertical_pos);
diff --git a/src/Text.cpp b/src/Text.cpp
index a84a824..32ba360 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -366,10 +366,10 @@ namespace QuickMedia
EmojiRectangle emoji_rec = emoji_get_extents(codePoint);
const float font_height_offset = -latin_font_height * 1.2f;
- sf::Vector2f vertexTopLeft(glyphPos.x, glyphPos.y + font_height_offset - emoji_rec.height * get_ui_scale() * 0.5f);
- sf::Vector2f vertexTopRight(glyphPos.x + emoji_rec.width * get_ui_scale(), glyphPos.y + font_height_offset - emoji_rec.height * get_ui_scale() * 0.5f);
+ sf::Vector2f vertexTopLeft(glyphPos.x, glyphPos.y + font_height_offset - std::floor(emoji_rec.height * get_ui_scale()) * 0.5f);
+ sf::Vector2f vertexTopRight(glyphPos.x + std::floor(emoji_rec.width * get_ui_scale()), glyphPos.y + font_height_offset - std::floor(emoji_rec.height * get_ui_scale()) * 0.5f);
sf::Vector2f vertexBottomLeft(glyphPos.x, glyphPos.y + font_height_offset + emoji_rec.height * get_ui_scale() * 0.5f);
- sf::Vector2f vertexBottomRight(glyphPos.x + emoji_rec.width * get_ui_scale(), glyphPos.y + font_height_offset + emoji_rec.height * get_ui_scale() * 0.5f);
+ sf::Vector2f vertexBottomRight(glyphPos.x + std::floor(emoji_rec.width * get_ui_scale()), glyphPos.y + font_height_offset + std::floor(emoji_rec.height * get_ui_scale()) * 0.5f);
sf::Vector2f textureTopLeft(emoji_rec.x, emoji_rec.y);
sf::Vector2f textureTopRight(emoji_rec.x + emoji_rec.width, emoji_rec.y);
@@ -888,10 +888,10 @@ namespace QuickMedia
if(!editable) return true;
pos.y -= floor(vspace * 2.0f);
- const float caret_margin = 2.0f * get_ui_scale();
+ const float caret_margin = std::floor(2.0f * get_ui_scale());
- sf::RectangleShape caretRect(sf::Vector2f(2.0f * get_ui_scale(), floor(vspace - caret_margin * 2.0f)));
- caretRect.setPosition(floor(pos.x + caretPosition.x), floor(pos.y + caretPosition.y + caret_margin + 4.0f * get_ui_scale()));
+ sf::RectangleShape caretRect(sf::Vector2f(std::floor(2.0f * get_ui_scale()), floor(vspace - caret_margin * 2.0f)));
+ caretRect.setPosition(floor(pos.x + caretPosition.x), floor(pos.y + caretPosition.y + caret_margin + std::floor(4.0f * get_ui_scale())));
target.draw(caretRect);
return true;
}