aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-09-27 23:13:19 +0200
committerdec05eba <dec05eba@protonmail.com>2020-09-27 23:13:19 +0200
commitb3fb1615038e821fb9abf60788ccdead04dd005a (patch)
tree79812e32f2793bdc2c39fef871e5e0bb8a17ccab /src
parent9fb104f688213bf1f3a324d5d240c8ab3bbc4997 (diff)
Attempt 1 at fixing image scrolling (still messes up current page sometimes)
Diffstat (limited to 'src')
-rw-r--r--src/ImageViewer.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/ImageViewer.cpp b/src/ImageViewer.cpp
index 416f27f..c45e35d 100644
--- a/src/ImageViewer.cpp
+++ b/src/ImageViewer.cpp
@@ -76,6 +76,8 @@ namespace QuickMedia {
}
if(page_image_data) {
+ page_image_data->visible_on_screen = true;
+
if(page_image_data->image_status == ImageStatus::APPLIED_TO_TEXTURE) {
page_image_data->sprite.setPosition(render_pos.x, render_pos.y);
window.draw(page_image_data->sprite);
@@ -255,16 +257,26 @@ namespace QuickMedia {
int page_i = 0;
for(auto &page_data : image_data) {
- if(page_data && page_data->image_status == ImageStatus::LOADED) {
- if(page_data->texture.loadFromImage(*page_data->image)) {
- page_data->sprite.setTexture(page_data->texture, true);
- page_size[page_i].size = get_page_size(page_i);
- page_size[page_i].loaded = true;
- page_data->image_status = ImageStatus::APPLIED_TO_TEXTURE;
- } else {
- page_data->image_status = ImageStatus::FAILED_TO_LOAD;
+ if(page_data) {
+ if(page_data->image_status == ImageStatus::LOADED) {
+ if(page_data->texture.loadFromImage(*page_data->image)) {
+ double height_before = get_page_size(page_i).y;
+ page_data->image_status = ImageStatus::APPLIED_TO_TEXTURE;
+ page_data->sprite.setTexture(page_data->texture, true);
+ page_size[page_i].size = get_page_size(page_i);
+ page_size[page_i].loaded = true;
+ double height_after = page_size[page_i].size.y;
+
+ double height_diff = height_before - height_after;
+ if(scroll_speed <= 0.0 && page_i < current_page) {
+ scroll -= height_diff;
+ }
+ } else {
+ page_data->image_status = ImageStatus::FAILED_TO_LOAD;
+ }
+ page_data->image.reset();
}
- page_data->image.reset();
+ page_data->visible_on_screen = false;
}
++page_i;
}
@@ -345,7 +357,7 @@ namespace QuickMedia {
if(page_size[page].loaded)
return page_size[page].size;
- if(!image_data[page])
+ if(!image_data[page] || image_data[page]->image_status != ImageStatus::APPLIED_TO_TEXTURE)
return no_image_page_size;
sf::Vector2u texture_size = image_data[page]->texture.getSize();