aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-08-05 21:34:37 +0200
committerdec05eba <dec05eba@protonmail.com>2019-08-05 21:34:40 +0200
commit3d656ffb9d242ba42f87cd2ef7ac13b06c7a2043 (patch)
treed69877be91432fb9ef53b4cd2023111252841b1c
parent92a98c6525d42a967d66492ef7bd61c4a1d7edd1 (diff)
Only redraw image preview when needed, less cpu usage
-rw-r--r--README.md3
-rw-r--r--src/QuickMedia.cpp6
-rw-r--r--src/SearchBar.cpp7
3 files changed, 10 insertions, 6 deletions
diff --git a/README.md b/README.md
index 9937445..9f0ab5a 100644
--- a/README.md
+++ b/README.md
@@ -14,4 +14,5 @@ If a search returns no results, then "No results found for ..." should be shown
Keep track of content that has been viewed so the user can return to where they were last.
For manga, view the next chapter when reaching the end of a chapter.
Make network requests asynchronous to not freeze gui when navigating. Also have loading animation.
-Retain search text when navigating back. \ No newline at end of file
+Retain search text when navigating back.
+Resizing window doesn't always scale images correctly, they stay underscaled. \ No newline at end of file
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 5ea2c43..2e7647e 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -424,6 +424,8 @@ namespace QuickMedia {
image_size.y *= image_scale.y;
image.setPosition(std::floor(window_size.x * 0.5f - image_size.x * 0.5f), std::floor(window_size.y * 0.5f - image_size.y * 0.5f));
}
+ } else {
+ continue;
}
window.clear(back_color);
@@ -437,11 +439,11 @@ namespace QuickMedia {
float background_height = font_height + 20.0f;
chapter_text_background.setSize(sf::Vector2f(window_size.x, background_height));
- chapter_text_background.setPosition(0.0f, window_size.y - background_height);
+ chapter_text_background.setPosition(0.0f, std::floor(window_size.y - background_height));
window.draw(chapter_text_background);
auto text_bounds = chapter_text.getLocalBounds();
- chapter_text.setPosition(window_size.x * 0.5f - text_bounds.width * 0.5f, window_size.y - background_height * 0.5f - text_bounds.height * 0.5f);
+ chapter_text.setPosition(std::floor(window_size.x * 0.5f - text_bounds.width * 0.5f), std::floor(window_size.y - background_height * 0.5f - font_height * 0.5f));
window.draw(chapter_text);
}
window.display();
diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp
index dad9e7c..15777e5 100644
--- a/src/SearchBar.cpp
+++ b/src/SearchBar.cpp
@@ -1,4 +1,5 @@
#include "../include/SearchBar.hpp"
+#include <cmath>
const sf::Color text_placeholder_color(255, 255, 255, 100);
const sf::Color front_color(43, 45, 47);
@@ -39,9 +40,9 @@ namespace QuickMedia {
void SearchBar::onWindowResize(const sf::Vector2f &window_size) {
float font_height = text.getCharacterSize() + 8.0f;
- float rect_height = font_height + background_margin_vertical * 2.0f;
- background.setSize(sf::Vector2f(window_size.x - padding_horizontal * 2.0f, rect_height));
- text.setPosition(padding_horizontal + background_margin_horizontal, padding_vertical + background_margin_vertical);
+ float rect_height = std::floor(font_height + background_margin_vertical * 2.0f);
+ background.setSize(sf::Vector2f(std::floor(window_size.x - padding_horizontal * 2.0f), rect_height));
+ text.setPosition(std::floor(padding_horizontal + background_margin_horizontal), std::floor(padding_vertical + background_margin_vertical));
}
void SearchBar::onTextEntered(sf::Uint32 codepoint) {