aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-07-16 15:11:28 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-16 15:11:28 +0200
commitcfc9e41222111ba0d87f0777b10091befda3e84a (patch)
tree925a6063d38815308b67d709df568c11aec6e3a1 /src
parent170d2e7b14fcdbd88fd2839bbd3dffd00df5196b (diff)
Add middle-mouse-scroll (aka autoscroll) for infinite image view mode
Diffstat (limited to 'src')
-rw-r--r--src/ImageViewer.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/ImageViewer.cpp b/src/ImageViewer.cpp
index 574bf94..9777611 100644
--- a/src/ImageViewer.cpp
+++ b/src/ImageViewer.cpp
@@ -28,6 +28,9 @@ namespace QuickMedia {
page_size[i].loaded = false;
}
page_text.setFillColor(sf::Color::White);
+
+ has_default_cursor = default_cursor.loadFromSystem(sf::Cursor::Arrow);
+ has_size_vertical_cursor = size_vertical_cursor.loadFromSystem(sf::Cursor::SizeVertical);
}
bool ImageViewer::render_page(sf::RenderWindow &window, int page, double offset_y) {
@@ -118,6 +121,7 @@ namespace QuickMedia {
const double frame_delta = frame_timer.restart().asSeconds();
const double scroll_speed_key_input = 450.0;
const double scroll_speed_mouse_wheel = 600.0;
+ const double scroll_speed_autoscroll = 10.0;
const double scroll_deaccel = 0.96;
if(!window_size_set) {
@@ -131,7 +135,8 @@ namespace QuickMedia {
sf::Event event;
while(window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
- //current_page = Page::EXIT;
+ if(has_default_cursor)
+ window.setMouseCursor(default_cursor);
window.close();
return ImageViewerAction::RETURN;
} else if(event.type == sf::Event::Resized) {
@@ -148,19 +153,43 @@ namespace QuickMedia {
} else if(event.key.code == sf::Keyboard::Down) {
scroll_speed -= scroll_speed_key_input * frame_delta;
} else if(event.key.code == sf::Keyboard::Escape) {
+ if(has_default_cursor)
+ window.setMouseCursor(default_cursor);
return ImageViewerAction::RETURN;
} else if(event.key.code == sf::Keyboard::I) {
return ImageViewerAction::SWITCH_TO_SINGLE_IMAGE_MODE;
}
} else if(event.type == sf::Event::MouseWheelScrolled && event.mouseWheelScroll.wheel == sf::Mouse::VerticalWheel) {
scroll_speed += scroll_speed_mouse_wheel * event.mouseWheelScroll.delta * frame_delta;
+ } else if(event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Button::Middle) {
+ middle_mouse_scrolling = true;
+ autoscroll_start_y = sf::Mouse::getPosition(window).y;
+ if(has_size_vertical_cursor)
+ window.setMouseCursor(size_vertical_cursor);
+
+ } else if(event.type == sf::Event::MouseButtonReleased && event.mouseButton.button == sf::Mouse::Button::Middle) {
+ middle_mouse_scrolling = false;
+ scroll_speed = 0.0;
+ if(has_default_cursor)
+ window.setMouseCursor(default_cursor);
}
}
- scroll += scroll_speed;
- scroll *= scroll_deaccel;
- if(std::abs(scroll) < 0.1)
- scroll = 0.0;
+ if(middle_mouse_scrolling) {
+ double distance_to_start_y = (double)sf::Mouse::getPosition(window).y - autoscroll_start_y;
+ scroll_speed = -distance_to_start_y * scroll_speed_autoscroll * frame_delta;
+ const double max_speed = 100.0;
+ if(scroll_speed > max_speed)
+ scroll_speed = max_speed;
+ if(scroll_speed < -max_speed)
+ scroll_speed = -max_speed;
+ scroll += scroll_speed;
+ } else {
+ scroll_speed *= scroll_deaccel;
+ if(std::abs(scroll_speed) < 0.01)
+ scroll_speed = 0.0;
+ scroll += scroll_speed;
+ }
min_page_center_dist = 9999999.0;
page_closest_to_center = -1;