diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-09-27 11:02:06 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-09-27 11:08:09 +0200 |
commit | 888fba907eba13ee6a30bf7169d4d96af5b443a5 (patch) | |
tree | 1703ab0dd0d52e80bde4bc44dae6a22156f36755 | |
parent | b07cca0bb59300fe193015f1a8361448af72d05b (diff) |
Implement pgup/pgdown/home/end keys
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | include/Body.hpp | 7 | ||||
-rw-r--r-- | src/Body.cpp | 38 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 71 |
5 files changed, 111 insertions, 12 deletions
@@ -26,7 +26,10 @@ echo -e "hello\nworld" | QuickMedia dmenu ## Installation If you are running arch linux then you can install QuickMedia from aur (https://aur.archlinux.org/packages/quickmedia-git/), otherwise you will need to use [sibs](https://git.dec05eba.com/sibs/) to build QuickMedia manually.\ ## Controls -Press `arrow up` and `arrow down` to navigate the menu and also to scroll to the previous/next image when viewing manga in scorll mode. Alternatively you can use the mouse scroll to scroll to the previous/next manga in scroll mode.\ +Press `Arrow up` or `Arrow down` to navigate the menu and also to scroll to the previous/next image when viewing manga in scroll mode. Alternatively you can use the mouse scroll to scroll to the previous/next manga in scroll mode.\ +Press `Arrow left` or `Arrow right` to switch tab.\ +Press `Page up` to scroll up and entire page or `Page down` to scroll down an entire page.\ +Press `Home` to scroll to the top or `End` to scroll to the bottom.\ Press `Enter` (aka `Return`) to select the item.\ Press `ESC` to go back to the previous menu.\ Press `Ctrl + F` to switch between window mode and fullscreen mode when watching a video.\ @@ -27,8 +27,6 @@ Resize text vertex arrays to 0 when not visible on screen to reduce memory usage Speed up thumbnail creating (image resizing). Extract thumbnail from images that are being downloaded, while its downloading and show that while the full image is downloading (upscaled, or with blurhash). Use one special thread to load cached files. Right now if there are multiple images on the screen and 1 needs to download while the others are cached, then the cached images wont load until that 1 image has downloaded. -Press pgup/pgdown to scroll and entire page. -Press home/end to scroll to top/bottom. Scrolling past page causes the page to jump up and down very fast because the new thumbnail is loaded. Fix this somehow. In youtube this can be fixed by setting the thumbnail image fallback size to the same size and thumbnail images, but that doesn't work for matrix with different image sizes! Add setting to disable sending typing events to the server (matrix). Support emoji (mainly for matrix), by readding Text code from dchat. Also do the same but for inline images, text editing and url colors and clicking (also clicking on inline images). diff --git a/include/Body.hpp b/include/Body.hpp index 9f7c2d8..4887582 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -85,6 +85,11 @@ namespace QuickMedia { Body(Program *program, sf::Font *font, sf::Font *bold_font, sf::Font *cjk_font); ~Body(); + // Select previous page, ignoring invisible items. Returns true if the item was changed. This can be used to check if the top was hit when wrap_around is set to false + bool select_previous_page(); + // Select next page, ignoring invisible items. Returns true if the item was changed. This can be used to check if the bottom was hit when wrap_around is set to false + bool select_next_page(); + // Select previous item, ignoring invisible items. Returns true if the item was changed. This can be used to check if the top was hit when wrap_around is set to false bool select_previous_item(); @@ -93,6 +98,7 @@ namespace QuickMedia { void set_selected_item(int item); void select_first_item(); + void select_last_item(); void reset_selected(); void clear_items(); void prepend_items(BodyItems new_items); @@ -161,5 +167,6 @@ namespace QuickMedia { sf::RoundedRectangleShape item_background; sf::Sprite image; std::future<void> load_thumbnail_future; + int num_visible_items; }; }
\ No newline at end of file diff --git a/src/Body.cpp b/src/Body.cpp index 477591e..c52f8ad 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -74,7 +74,8 @@ namespace QuickMedia { selected_item(0), prev_selected_item(0), page_scroll(0.0f), - item_background(sf::Vector2f(1.0f, 1.0f), 10.0f, 10) + item_background(sf::Vector2f(1.0f, 1.0f), 10.0f, 10), + num_visible_items(0) { progress_text.setFillColor(sf::Color::White); replies_text.setFillColor(sf::Color(129, 162, 190)); @@ -91,6 +92,26 @@ namespace QuickMedia { load_thumbnail_future.get(); } + // TODO: Make this work with wraparound enabled? + // TODO: For plugins with different sized body items this can be weird, because after scrolling down thumbnails could load and they could move items up/down until we see items we haven't seen + bool Body::select_previous_page() { + for(int i = 0; i < num_visible_items - 1; ++i) { + if(!select_previous_item()) + return false; + } + return true; + } + + // TODO: Make this work with wraparound enabled? + // TODO: For plugins with different sized body items this can be weird, because after scrolling down thumbnails could load and they could move items up/down until we see items we haven't seen + bool Body::select_next_page() { + for(int i = 0; i < num_visible_items - 1; ++i) { + if(!select_next_item()) + return false; + } + return true; + } + bool Body::select_previous_item() { if(items.empty()) return false; @@ -161,6 +182,13 @@ namespace QuickMedia { clamp_selection(); } + void Body::select_last_item() { + selected_item = std::max(0, (int)items.size() - 1); + //prev_selected_item = selected_item; + //page_scroll = 0.0f; + clamp_selection(); + } + void Body::reset_selected() { for(size_t i = 0; i < items.size(); ++i) { if(items[i]->visible) { @@ -229,8 +257,9 @@ namespace QuickMedia { } reset_scroll: - prev_selected_item = selected_item; - page_scroll = 0.0f; + {} + //prev_selected_item = selected_item; + //page_scroll = 0.0f; } static sf::Vector2f to_vec2f(const sf::Vector2u &vec) { @@ -364,6 +393,7 @@ namespace QuickMedia { //item_background.setOutlineColor(sf::Color(13, 15, 17)); image_fallback.setSize(thumbnail_fallback_size); item_background_shadow.setFillColor(line_seperator_color); + num_visible_items = 0; if(loading_thumbnail && load_thumbnail_future.valid() && load_thumbnail_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) { load_thumbnail_future.get(); @@ -476,6 +506,7 @@ namespace QuickMedia { break; draw_item(window, item.get(), prev_pos, size, item_height, i, content_progress); + ++num_visible_items; } sf::Vector2f after_pos = pos; @@ -492,6 +523,7 @@ namespace QuickMedia { float item_height = get_item_height(item.get()); draw_item(window, item.get(), after_pos, size, item_height, i, content_progress); after_pos.y += item_height + spacing_y; + ++num_visible_items; } glDisable(GL_SCISSOR_TEST); diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index b596b06..f793559 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -592,6 +592,14 @@ namespace QuickMedia { body->select_previous_item(); } else if(event.key.code == sf::Keyboard::Down) { body->select_next_item(); + } else if(event.key.code == sf::Keyboard::PageUp) { + body->select_previous_page(); + } else if(event.key.code == sf::Keyboard::PageDown) { + body->select_next_page(); + } else if(event.key.code == sf::Keyboard::Home) { + body->select_first_item(); + } else if(event.key.code == sf::Keyboard::End) { + body->select_last_item(); } else if(event.key.code == sf::Keyboard::Escape) { current_page = previous_page; if(clear_on_escape) { @@ -1101,6 +1109,14 @@ namespace QuickMedia { if(tabs[selected_tab].body) tabs[selected_tab].body->select_previous_item(); } else if(event.key.code == sf::Keyboard::Down) { if(tabs[selected_tab].body) tabs[selected_tab].body->select_next_item(); + } else if(event.key.code == sf::Keyboard::PageUp) { + if(tabs[selected_tab].body) tabs[selected_tab].body->select_previous_page(); + } else if(event.key.code == sf::Keyboard::PageDown) { + if(tabs[selected_tab].body) tabs[selected_tab].body->select_next_page(); + } else if(event.key.code == sf::Keyboard::Home) { + if(tabs[selected_tab].body) tabs[selected_tab].body->select_first_item(); + } else if(event.key.code == sf::Keyboard::End) { + if(tabs[selected_tab].body) tabs[selected_tab].body->select_last_item(); } else if(event.key.code == sf::Keyboard::Escape) { current_page = Page::EXIT; exit_code = 1; @@ -1166,7 +1182,7 @@ namespace QuickMedia { if(search_running && search_suggestion_future.valid() && search_suggestion_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) { if(!search_text_updated) { body->items = search_suggestion_future.get(); - body->clamp_selection(); + body->select_first_item(); } else { search_suggestion_future.get(); } @@ -1620,6 +1636,14 @@ namespace QuickMedia { related_media_body->select_previous_item(); } else if(event.key.code == sf::Keyboard::Down) { related_media_body->select_next_item(); + } else if(event.key.code == sf::Keyboard::PageUp) { + related_media_body->select_previous_page(); + } else if(event.key.code == sf::Keyboard::PageDown) { + related_media_body->select_next_page(); + } else if(event.key.code == sf::Keyboard::Home) { + related_media_body->select_first_item(); + } else if(event.key.code == sf::Keyboard::End) { + related_media_body->select_last_item(); } else if(event.key.code == sf::Keyboard::Escape) { related_media_window_visible = false; related_media_window->setVisible(false); @@ -1895,6 +1919,14 @@ namespace QuickMedia { tabs[selected_tab].body->select_previous_item(); } else if(event.key.code == sf::Keyboard::Down) { tabs[selected_tab].body->select_next_item(); + } else if(event.key.code == sf::Keyboard::PageUp) { + tabs[selected_tab].body->select_previous_page(); + } else if(event.key.code == sf::Keyboard::PageDown) { + tabs[selected_tab].body->select_next_page(); + } else if(event.key.code == sf::Keyboard::Home) { + tabs[selected_tab].body->select_first_item(); + } else if(event.key.code == sf::Keyboard::End) { + tabs[selected_tab].body->select_last_item(); } else if(event.key.code == sf::Keyboard::Escape) { current_page = Page::SEARCH_SUGGESTION; body->clear_items(); @@ -2734,7 +2766,7 @@ namespace QuickMedia { } sf::RectangleShape captcha_selection_rect; captcha_selection_rect.setOutlineThickness(5.0f); - captcha_selection_rect.setOutlineColor(sf::Color(55, 60, 68)); + captcha_selection_rect.setOutlineColor(sf::Color::Red); // TODO: Draw only the outline instead of a transparent rectangle captcha_selection_rect.setFillColor(sf::Color::Transparent); @@ -2869,6 +2901,14 @@ namespace QuickMedia { body->select_previous_item(); } else if(event.key.code == sf::Keyboard::Down) { body->select_next_item(); + } else if(event.key.code == sf::Keyboard::PageUp) { + body->select_previous_page(); + } else if(event.key.code == sf::Keyboard::PageDown) { + body->select_next_page(); + } else if(event.key.code == sf::Keyboard::Home) { + body->select_first_item(); + } else if(event.key.code == sf::Keyboard::End) { + body->select_last_item(); } else if(event.key.code == sf::Keyboard::Escape) { current_page = Page::IMAGE_BOARD_THREAD_LIST; body->clear_items(); @@ -2918,6 +2958,7 @@ namespace QuickMedia { comment_navigation_stack.push(body->get_selected_item()); comment_page_scroll_stack.push(body->get_page_scroll()); body->clamp_selection(); + body->set_page_scroll(0.0f); } else if(event.key.code == sf::Keyboard::BackSpace && !comment_navigation_stack.empty()) { size_t previous_selected = comment_navigation_stack.top(); float previous_page_scroll = comment_page_scroll_stack.top(); @@ -3414,10 +3455,24 @@ namespace QuickMedia { if(event.type == sf::Event::Resized || event.type == sf::Event::GainedFocus) { redraw = true; } else if(event.type == sf::Event::KeyPressed) { - if(event.key.code == sf::Keyboard::Up) { - bool item_changed = tabs[selected_tab].body->select_previous_item(); - // Top hit - if(!item_changed && !fetching_previous_messages_running && tabs[selected_tab].type == ChatTabType::MESSAGES) { + if(event.key.code == sf::Keyboard::Up || event.key.code == sf::Keyboard::PageUp || event.key.code == sf::Keyboard::Home) { + bool hit_top = false; + switch(event.key.code) { + case sf::Keyboard::Up: + hit_top = !tabs[selected_tab].body->select_previous_item(); + break; + case sf::Keyboard::PageUp: + hit_top = !tabs[selected_tab].body->select_previous_page(); + break; + case sf::Keyboard::Home: + tabs[selected_tab].body->select_first_item(); + hit_top = true; + break; + default: + hit_top = false; + break; + } + if(hit_top && !fetching_previous_messages_running && tabs[selected_tab].type == ChatTabType::MESSAGES) { gradient_inc = 0; fetching_previous_messages_running = true; previous_messages_future_room_id = current_room_id; @@ -3431,6 +3486,10 @@ namespace QuickMedia { } } else if(event.key.code == sf::Keyboard::Down) { tabs[selected_tab].body->select_next_item(); + } else if(event.key.code == sf::Keyboard::PageDown) { + tabs[selected_tab].body->select_next_page(); + } else if(event.key.code == sf::Keyboard::End) { + tabs[selected_tab].body->select_last_item(); } else if(event.key.code == sf::Keyboard::Escape) { current_page = Page::EXIT; body->clear_items(); |