aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-07-23 19:17:00 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-23 19:17:00 +0200
commit6c6bc3daf872787f8ceca2e9452ae50a0010dbfa (patch)
treeacacbe784d56fbd2346d1aa999e9920837303836
parentb7fadd729d278e8daccac12c5268928c2ced1ad0 (diff)
Better image quality for infinite image mode
-rw-r--r--src/ImageViewer.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/ImageViewer.cpp b/src/ImageViewer.cpp
index 8ce9b30..0773f80 100644
--- a/src/ImageViewer.cpp
+++ b/src/ImageViewer.cpp
@@ -39,13 +39,17 @@ namespace QuickMedia {
const sf::Vector2<double> image_size = get_page_size(page);
std::unique_ptr<ImageData> &page_image_data = image_data[page];
- sf::Vector2<double> render_pos(window_size.x * 0.5 - image_size.x * 0.5, - image_size.y * 0.5 + scroll + offset_y);
+ sf::Vector2<double> render_pos(std::floor(window_size.x * 0.5 - image_size.x * 0.5), - image_size.y * 0.5 + scroll + offset_y);
if(render_pos.y + image_size.y <= 0.0 || render_pos.y >= window_size.y) {
if(page_image_data)
page_image_data->visible_on_screen = false;
return true;
}
+ bool scrolling = (std::abs(scroll_speed) > 0.01f);
+ if(!scrolling)
+ render_pos.y = std::floor(render_pos.y);
+
double center_dist = std::abs(window_size.y * 0.5 - (render_pos.y + image_size.y * 0.5));
if(center_dist < min_page_center_dist) {
min_page_center_dist = center_dist;
@@ -57,7 +61,10 @@ namespace QuickMedia {
sf::Text error_message("Failed to load image for page " + std::to_string(1 + page), *font, 30);
auto text_bounds = error_message.getLocalBounds();
error_message.setFillColor(sf::Color::Black);
- sf::Vector2<double> render_pos_text(window_size.x * 0.5 - text_bounds.width * 0.5, - text_bounds.height * 0.5 + scroll + offset_y);
+ sf::Vector2<double> render_pos_text(std::floor(window_size.x * 0.5 - text_bounds.width * 0.5), - text_bounds.height * 0.5 + scroll + offset_y);
+
+ if(!scrolling)
+ render_pos_text.y = std::floor(render_pos_text.y);
sf::RectangleShape background(sf::Vector2f(image_size.x, image_size.y));
background.setFillColor(sf::Color::White);
@@ -76,7 +83,10 @@ namespace QuickMedia {
sf::Text error_message("Downloading page " + page_str, *font, 30);
auto text_bounds = error_message.getLocalBounds();
error_message.setFillColor(sf::Color::Black);
- sf::Vector2<double> render_pos_text(window_size.x * 0.5 - text_bounds.width * 0.5, - text_bounds.height * 0.5 + scroll + offset_y);
+ sf::Vector2<double> render_pos_text(std::floor(window_size.x * 0.5 - text_bounds.width * 0.5), - text_bounds.height * 0.5 + scroll + offset_y);
+
+ if(!scrolling)
+ render_pos_text.y = std::floor(render_pos_text.y);
sf::RectangleShape background(sf::Vector2f(image_size.x, image_size.y));
background.setFillColor(sf::Color::White);
@@ -194,9 +204,12 @@ namespace QuickMedia {
scroll += scroll_speed;
} else {
scroll_speed *= scroll_deaccel;
- if(std::abs(scroll_speed) < 0.01)
+ if(std::abs(scroll_speed) < 0.01) {
scroll_speed = 0.0;
- scroll += scroll_speed;
+ scroll = std::round(scroll); /* Better image quality! */
+ } else {
+ scroll += scroll_speed;
+ }
}
min_page_center_dist = 9999999.0;