diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-02-11 02:04:20 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-02-11 02:04:20 +0100 |
commit | 6f2648422107c8760b3e7717fc9b6693e37fcd92 (patch) | |
tree | feaa2045e755ebffa291d0334a34203dbc94bef2 /src | |
parent | ce947e27e50f5439c3f41526998e0f4dee197d86 (diff) |
ImageViewer: make closest image the top of the image and limit first/last image to bottom/top of the image instead of center
Diffstat (limited to 'src')
-rw-r--r-- | src/ImageViewer.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/ImageViewer.cpp b/src/ImageViewer.cpp index f568402..2b40c1f 100644 --- a/src/ImageViewer.cpp +++ b/src/ImageViewer.cpp @@ -99,10 +99,10 @@ namespace QuickMedia { 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; - page_closest_to_center = page; + double top_dist = std::abs(0.0 - render_pos.y); + if(top_dist < min_page_top_dist) { + min_page_top_dist = top_dist; + page_closest_to_top = page; } if(page_image_data) { @@ -298,8 +298,8 @@ namespace QuickMedia { } } - min_page_center_dist = 9999999.0; - page_closest_to_center = -1; + min_page_top_dist = 9999999.0; + page_closest_to_top = -1; bool loaded_textures_changed = false; int page_i = 0; @@ -340,19 +340,18 @@ namespace QuickMedia { const double first_image_height = get_page_size(0).y; const double last_image_height = get_page_size((int)image_data.size() - 1).y; - // TODO: Limit bottom scroll if page_offset is smaller than window height + // TODO: Do not allow scrolling if all images height (page_offset) is smaller than window height - const double top_scroll = std::max(0.0, -first_image_height * 0.5 + window_size.y * 0.5); - const double bottom_scroll = std::min(window_size.y, window_size.y + last_image_height * 0.5 - window_size.y * 0.5); + const double top_scroll = std::max(0.0, -first_image_height + window_size.y); + const double bottom_scroll = std::min(window_size.y, window_size.y + last_image_height - window_size.y); if(scroll > top_scroll) { scroll = top_scroll; } else if(scroll + page_offset < bottom_scroll && page_offset > window_size.y) { scroll = -page_offset + bottom_scroll; } - if(page_closest_to_center != -1) { - focused_page = page_closest_to_center; - } + if(page_closest_to_top != -1) + focused_page = page_closest_to_top; if(focused_page != prev_focused_page) { prev_focused_page = focused_page; |