aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--include/Body.hpp1
-rw-r--r--src/Body.cpp30
-rw-r--r--src/QuickMedia.cpp11
-rw-r--r--src/SearchBar.cpp2
5 files changed, 37 insertions, 11 deletions
diff --git a/README.md b/README.md
index a618000..af4fe69 100644
--- a/README.md
+++ b/README.md
@@ -19,4 +19,6 @@ Make network requests asynchronous to not freeze gui when navigating. Also have
Retain search text when navigating back.
Disable ytdl_hook subtitles. If a video has subtitles for many languages, then it will stall video playback for several seconds
until all subtitles have been downloaded and loaded.
-Figure out why memory usage doesn't drop much when killing the video player. Is it a bug in proprietary nvidia drivers on gnu/linux? \ No newline at end of file
+Figure out why memory usage doesn't drop much when killing the video player. Is it a bug in proprietary nvidia drivers on gnu/linux?
+Add grid-view when thumbnails are visible.
+Add scrollbar. \ No newline at end of file
diff --git a/include/Body.hpp b/include/Body.hpp
index e854e76..65aae8d 100644
--- a/include/Body.hpp
+++ b/include/Body.hpp
@@ -49,6 +49,7 @@ namespace QuickMedia {
std::vector<std::unique_ptr<BodyItem>> items;
std::vector<std::shared_ptr<sf::Texture>> item_thumbnail_textures;
std::thread thumbnail_load_thread;
+ bool draw_thumbnails;
private:
std::shared_ptr<sf::Texture> load_thumbnail_from_url(const std::string &url);
bool loading_thumbnail;
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) {