diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Body.cpp | 66 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 22 |
2 files changed, 62 insertions, 26 deletions
diff --git a/src/Body.cpp b/src/Body.cpp index 6500e16..2233f92 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -20,39 +20,73 @@ namespace QuickMedia { replies_text("", *font, 14), selected_item(0), draw_thumbnails(false), - loading_thumbnail(false) + loading_thumbnail(false), + wrap_around(false) { progress_text.setFillColor(sf::Color::White); author_text.setFillColor(sf::Color::White); replies_text.setFillColor(sf::Color(129, 162, 190)); } - void Body::select_previous_item() { + bool Body::select_previous_item() { if(items.empty()) - return; + return false; + int new_selected_item = selected_item; int num_items = (int)items.size(); + for(int i = 0; i < num_items; ++i) { - --selected_item; - if(selected_item < 0) - selected_item = num_items - 1; - if(items[selected_item]->visible) - return; + if(new_selected_item - 1 < 0) { + if(wrap_around) + new_selected_item = num_items - 1; + else { + new_selected_item = selected_item; + break; + } + } else { + --new_selected_item; + } + if(items[new_selected_item]->visible) + break; } + + if(selected_item == new_selected_item) + return false; + selected_item = new_selected_item; + return true; } - void Body::select_next_item() { + bool Body::select_next_item() { if(items.empty()) - return; + return false; + int new_selected_item = selected_item; int num_items = (int)items.size(); + for(int i = 0; i < num_items; ++i) { - ++selected_item; - if(selected_item == num_items) - selected_item = 0; - if(items[selected_item]->visible) - return; + if(new_selected_item + 1 == num_items) { + if(wrap_around) { + new_selected_item = 0; + } else { + new_selected_item = selected_item; + break; + } + } else { + ++new_selected_item; + } + if(items[new_selected_item]->visible) + break; } + + if(selected_item == new_selected_item) + return false; + selected_item = new_selected_item; + return true; + } + + void Body::set_selected_item(int item) { + assert(item >= 0 && item < (int)items.size()); + selected_item = item; } void Body::select_first_item() { @@ -178,7 +212,7 @@ namespace QuickMedia { body_item->title_text->setString(body_item->get_title()); else body_item->title_text = std::make_unique<Text>(body_item->get_title(), font, 14, size.x - 50 - image_padding_x * 2.0f); - //body_item->title_text->updateGeometry(); // TODO: Call this to make getHeight work on first frame (called below) + body_item->title_text->updateGeometry(); } if(!body_item->get_description().empty() && !body_item->description_text) { diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 377729f..75bc027 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -2025,10 +2025,11 @@ namespace QuickMedia { if(image_index > 0) { --image_index; return; - } else if(image_index == 0 && body->selected_item < (int)body->items.size() - 1) { + } else if(image_index == 0 && body->get_selected_item() < (int)body->items.size() - 1) { // TODO: Make this work if the list is sorted differently than from newest to oldest. - body->selected_item++; - select_episode(body->items[body->selected_item].get(), true); + body->filter_search_fuzzy(""); + body->select_next_item(); + select_episode(body->items[body->get_selected_item()].get(), true); image_index = 99999; // Start at the page that shows we are at the end of the chapter return; } @@ -2036,10 +2037,11 @@ namespace QuickMedia { if(image_index < num_images) { ++image_index; return; - } else if(image_index == num_images && body->selected_item > 0) { + } else if(image_index == num_images && body->get_selected_item() > 0) { // TODO: Make this work if the list is sorted differently than from newest to oldest. - body->selected_item--; - select_episode(body->items[body->selected_item].get(), true); + body->filter_search_fuzzy(""); + body->select_previous_item(); + select_episode(body->items[body->get_selected_item()].get(), true); return; } } else if(event.key.code == sf::Keyboard::Escape) { @@ -2564,7 +2566,7 @@ namespace QuickMedia { } BodyItem *selected_item = body->get_selected(); - if(event.key.code == sf::Keyboard::Enter && selected_item && (comment_navigation_stack.empty() || body->selected_item != comment_navigation_stack.top()) && !selected_item->replies.empty()) { + if(event.key.code == sf::Keyboard::Enter && selected_item && (comment_navigation_stack.empty() || body->get_selected_item() != comment_navigation_stack.top()) && !selected_item->replies.empty()) { for(auto &body_item : body->items) { body_item->visible = false; } @@ -2572,7 +2574,7 @@ namespace QuickMedia { for(size_t reply_index : selected_item->replies) { body->items[reply_index]->visible = true; } - comment_navigation_stack.push(body->selected_item); + comment_navigation_stack.push(body->get_selected_item()); } else if(event.key.code == sf::Keyboard::BackSpace && !comment_navigation_stack.empty()) { size_t previous_selected = 0; if(!comment_navigation_stack.empty()) { @@ -2583,12 +2585,12 @@ namespace QuickMedia { for(auto &body_item : body->items) { body_item->visible = true; } - body->selected_item = previous_selected; + body->set_selected_item(previous_selected); } else { for(auto &body_item : body->items) { body_item->visible = false; } - body->selected_item = previous_selected; + body->set_selected_item(previous_selected); selected_item = body->items[comment_navigation_stack.top()].get(); selected_item->visible = true; for(size_t reply_index : selected_item->replies) { |