From 13681189d41f3d5c6c132d92b7451fea151fb713 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 3 Jul 2020 03:10:50 +0200 Subject: bind I to switching between single image and scroll mode --- src/ImageViewer.cpp | 10 ++++++---- src/QuickMedia.cpp | 29 +++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ImageViewer.cpp b/src/ImageViewer.cpp index b567e1b..41993ad 100644 --- a/src/ImageViewer.cpp +++ b/src/ImageViewer.cpp @@ -115,7 +115,7 @@ namespace QuickMedia { return true; } - bool ImageViewer::draw(sf::RenderWindow &window) { + 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_mouse_wheel = 450.0; @@ -134,7 +134,7 @@ namespace QuickMedia { if (event.type == sf::Event::Closed) { //current_page = Page::EXIT; window.close(); - return false; + return ImageViewerAction::RETURN; } else if(event.type == sf::Event::Resized) { window_size.x = event.size.width; window_size.y = event.size.height; @@ -149,7 +149,9 @@ 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) { - return false; + 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; @@ -224,7 +226,7 @@ namespace QuickMedia { ++i; } - return true; + return ImageViewerAction::NONE; } int ImageViewer::get_focused_page() const { diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 400603b..15e345b 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -802,7 +802,15 @@ namespace QuickMedia { images_url = item->url; chapter_title = item->title; image_index = 0; - current_page = Page::IMAGES_CONTINUOUS; + switch(image_view_mode) { + case ImageViewMode::SINGLE: + current_page = Page::IMAGES; + break; + case ImageViewMode::SCROLL: + current_page = Page::IMAGES_CONTINUOUS; + break; + } + if(start_from_beginning) return; @@ -1123,6 +1131,9 @@ namespace QuickMedia { } } else if(event.key.code == sf::Keyboard::Escape) { current_page = Page::EPISODE_LIST; + } else if(event.key.code == sf::Keyboard::I) { + current_page = Page::IMAGES_CONTINUOUS; + image_view_mode = ImageViewMode::SCROLL; } } } @@ -1230,14 +1241,24 @@ namespace QuickMedia { while(current_page == Page::IMAGES_CONTINUOUS) { window.clear(back_color); - if(!image_viewer.draw(window)) - current_page = Page::EPISODE_LIST; + ImageViewerAction action = image_viewer.draw(window); + switch(action) { + case ImageViewerAction::NONE: + break; + case ImageViewerAction::RETURN: + current_page = Page::EPISODE_LIST; + break; + case ImageViewerAction::SWITCH_TO_SINGLE_IMAGE_MODE: + image_view_mode = ImageViewMode::SINGLE; + current_page = Page::IMAGES; + break; + } window.display(); int focused_page = image_viewer.get_focused_page(); + image_index = focused_page - 1; if(focused_page > latest_read) { latest_read = focused_page; - image_index = latest_read - 1; json_chapter["current"] = latest_read; json_chapters[chapter_title] = json_chapter; if(!save_manga_progress_json(content_storage_file, content_storage_json)) { -- cgit v1.2.3