diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Body.cpp | 30 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 11 | ||||
-rw-r--r-- | src/SearchBar.cpp | 2 |
3 files changed, 33 insertions, 10 deletions
diff --git a/src/Body.cpp b/src/Body.cpp index 9f27ed2..52f3105 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -13,6 +13,7 @@ namespace QuickMedia { title_text("", font, 14), progress_text("", font, 14), selected_item(0), + draw_thumbnails(false), loading_thumbnail(false) { title_text.setFillColor(sf::Color::White); @@ -134,24 +135,41 @@ namespace QuickMedia { const float selected_border_width = 5.0f; int num_items = items.size(); + if(num_items == 0) + return; + if((int)item_thumbnail_textures.size() != num_items) { // First unload all textures, then prepare to load new textures item_thumbnail_textures.resize(0); item_thumbnail_textures.resize(num_items); } - for(int i = 0; i < num_items; ++i) { + float row_height = font_height; + if(draw_thumbnails) + row_height = image_height; + const float total_row_height = row_height + 10.0f; + const int max_visible_rows = size.y / total_row_height - 1; + + // Find the starting row that can be drawn to make selected row visible as well + int visible_rows = 0; + int first_visible_item = selected_item; + for(; first_visible_item >= 0 && visible_rows < max_visible_rows; --first_visible_item) { + auto &item = items[first_visible_item]; + if(item->visible) + ++visible_rows; + } + + for(int i = first_visible_item + 1; i < num_items; ++i) { const auto &item = items[i]; assert(items.size() == item_thumbnail_textures.size()); auto &item_thumbnail = item_thumbnail_textures[i]; if(!item->visible) continue; - bool draw_thumbnail = !item->thumbnail_url.empty(); float row_height = font_height; - if(draw_thumbnail) { + if(draw_thumbnails) { row_height = image_height; - if(!item_thumbnail && !loading_thumbnail) + if(!item->thumbnail_url.empty() && !item_thumbnail && !loading_thumbnail) item_thumbnail = load_thumbnail_from_url(item->thumbnail_url); } @@ -173,7 +191,7 @@ namespace QuickMedia { window.draw(item_background); float text_offset_x = 0.0f; - if(draw_thumbnail) { + if(draw_thumbnails) { // TODO: Verify if this is safe. The thumbnail is being modified in another thread // and it might not be fully finished before the native handle is set? if(item_thumbnail && item_thumbnail->getNativeHandle() != 0) { @@ -211,7 +229,7 @@ namespace QuickMedia { } } - pos.y += row_height + 10.0f; + pos.y += total_row_height; } } diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index d6a369a..649b56c 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -89,18 +89,23 @@ namespace QuickMedia { window.close(); break; case Page::SEARCH_SUGGESTION: + body->draw_thumbnails = true; search_suggestion_page(); break; case Page::SEARCH_RESULT: + body->draw_thumbnails = true; search_result_page(); break; case Page::VIDEO_CONTENT: + body->draw_thumbnails = false; video_content_page(); break; case Page::EPISODE_LIST: + body->draw_thumbnails = false; episode_list_page(); break; case Page::IMAGES: { + body->draw_thumbnails = false; window.setKeyRepeatEnabled(false); image_page(); window.setKeyRepeatEnabled(true); @@ -216,7 +221,7 @@ namespace QuickMedia { float search_bottom = search_bar->getBottom(); body_pos = sf::Vector2f(body_padding_horizontal, search_bottom + body_padding_vertical); - body_size = sf::Vector2f(body_width, window_size.y); + body_size = sf::Vector2f(body_width, window_size.y - search_bottom); } search_bar->update(); @@ -265,7 +270,7 @@ namespace QuickMedia { float search_bottom = search_bar->getBottom(); body_pos = sf::Vector2f(body_padding_horizontal, search_bottom + body_padding_vertical); - body_size = sf::Vector2f(body_width, window_size.y); + body_size = sf::Vector2f(body_width, window_size.y - search_bottom); } search_bar->update(); @@ -409,7 +414,7 @@ namespace QuickMedia { float search_bottom = search_bar->getBottom(); body_pos = sf::Vector2f(body_padding_horizontal, search_bottom + body_padding_vertical); - body_size = sf::Vector2f(body_width, window_size.y); + body_size = sf::Vector2f(body_width, window_size.y - search_bottom); } search_bar->update(); diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp index 82ade2f..a5f2705 100644 --- a/src/SearchBar.cpp +++ b/src/SearchBar.cpp @@ -21,7 +21,7 @@ namespace QuickMedia { background.setFillColor(front_color); background.setPosition(padding_horizontal, padding_vertical); //background.setOutlineThickness(1.0f); - //background.setOutlineColor(sf::Color(63, 65, 67)); + //background.setOutlineColor(sf::Color(0, 85, 119)); } void SearchBar::draw(sf::RenderWindow &window) { |