aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-03-19 12:55:55 +0100
committerdec05eba <dec05eba@protonmail.com>2021-03-19 12:55:55 +0100
commit62bbf0daacdd110509f8166e9a1bf162ecb23138 (patch)
tree15c75254514f47bc6c6f7c4be515a107449050c2 /src/QuickMedia.cpp
parentc207201a4a5a47e4ad286ba7371e4176c8ed5056 (diff)
Fix glitching when using fractional scaling
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp58
1 files changed, 29 insertions, 29 deletions
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;
}