aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp38
-rw-r--r--src/QuickMedia.cpp71
2 files changed, 100 insertions, 9 deletions
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();