From b486665e9470ff3477c97a70e7982dd587b4c7d6 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 6 Aug 2020 03:18:43 +0200 Subject: Disable key repeat for infinite image mode --- src/ImageViewer.cpp | 34 ++++++++++++++++++++++++++-------- src/QuickMedia.cpp | 3 +++ 2 files changed, 29 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ImageViewer.cpp b/src/ImageViewer.cpp index 0773f80..d2b1a95 100644 --- a/src/ImageViewer.cpp +++ b/src/ImageViewer.cpp @@ -133,7 +133,7 @@ namespace QuickMedia { ImageViewerAction ImageViewer::draw(sf::RenderWindow &window) { const double frame_delta = frame_timer.restart().asSeconds(); - const double scroll_speed_key_input = 450.0; + const double scroll_speed_key_input = 50.0; const double scroll_speed_mouse_wheel = 600.0; const double scroll_speed_autoscroll = 10.0; const double scroll_deaccel = 0.96; @@ -162,17 +162,24 @@ namespace QuickMedia { } else if(event.type == sf::Event::GainedFocus) { //redraw = true; } else if(event.type == sf::Event::KeyPressed) { - if(event.key.code == sf::Keyboard::Up) { - scroll_speed += scroll_speed_key_input * frame_delta; - } 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(event.key.code == sf::Keyboard::Up) + up_pressed = true; + if(event.key.code == sf::Keyboard::Down) + down_pressed = true; + + 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; } + + if(event.key.code == sf::Keyboard::I) + return ImageViewerAction::SWITCH_TO_SINGLE_IMAGE_MODE; + } else if(event.type == sf::Event::KeyReleased) { + if(event.key.code == sf::Keyboard::Up) + up_pressed = false; + if(event.key.code == sf::Keyboard::Down) + down_pressed = false; } 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) { @@ -189,6 +196,11 @@ namespace QuickMedia { } } + if(up_pressed) + scroll_speed += scroll_speed_key_input * frame_delta; + if(down_pressed) + scroll_speed -= scroll_speed_key_input * frame_delta; + if(middle_mouse_scrolling) { double distance_to_start_y = (double)sf::Mouse::getPosition(window).y - autoscroll_start_y; double dist_abs = std::abs(distance_to_start_y); @@ -203,6 +215,12 @@ namespace QuickMedia { scroll_speed = -max_speed; scroll += scroll_speed; } else { + 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_speed *= scroll_deaccel; if(std::abs(scroll_speed) < 0.01) { scroll_speed = 0.0; diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 85c6695..a7fca2d 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -251,8 +251,10 @@ namespace QuickMedia { } case Page::IMAGES_CONTINUOUS: { body->draw_thumbnails = false; + window.setKeyRepeatEnabled(false); image_continuous_page(); body->filter_search_fuzzy(""); + window.setKeyRepeatEnabled(true); break; } case Page::CONTENT_LIST: { @@ -872,6 +874,7 @@ namespace QuickMedia { const int max_fallbacks = 3; /* itags from: https://gist.github.com/sidneys/7095afe4da4ae58694d128b1034e01e2 */ /* 1080p, 720p, 360p */ + /* TODO: Use invidious api instead (/api/v1/videos/, formatStreams) https://github.com/iv-org/invidious/wiki/API */ const char *fallback_itags[max_fallbacks] = { "37", "22", "18" }; Page previous_page = pop_page_stack(); -- cgit v1.2.3