From 6f11b42b7015646bcdc5f8bbec7da61e76655861 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 10 Sep 2020 20:40:17 +0200 Subject: Add ctrl+r keybind to show related videos menu --- src/Body.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/Body.cpp') diff --git a/src/Body.cpp b/src/Body.cpp index 6081028..61d100b 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -10,17 +10,17 @@ const sf::Color front_color(43, 45, 47); const sf::Color back_color(33, 35, 37); namespace QuickMedia { - Body::Body(Program *program, sf::Font &font, sf::Font &bold_font) : + Body::Body(Program *program, sf::Font *font, sf::Font *bold_font) : program(program), - title_text("", font, 14), - progress_text("", font, 14), - author_text("", bold_font, 14), - replies_text("", font, 14), + font(font), + bold_font(bold_font), + progress_text("", *font, 14), + author_text("", *bold_font, 14), + replies_text("", *font, 14), selected_item(0), draw_thumbnails(false), loading_thumbnail(false) { - title_text.setFillColor(sf::Color::White); progress_text.setFillColor(sf::Color::White); author_text.setFillColor(sf::Color::White); replies_text.setFillColor(sf::Color(129, 162, 190)); @@ -129,7 +129,6 @@ namespace QuickMedia { } // TODO: Use a render target for the whole body so all images can be put into one. - // TODO: Unload thumbnails once they are no longer visible on the screen. // TODO: Load thumbnails with more than one thread. // TODO: Show chapters (rows) that have been read differently to make it easier to see what hasn't been read yet. void Body::draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, const Json::Value &content_progress) { @@ -163,18 +162,14 @@ namespace QuickMedia { thumbnail_it.second.referenced = false; } - // TODO: Instead of generating a new hash everytime to access textures, cache the hash of the thumbnail url for(auto &body_item : items) { - // Intentionally create the item with the key item->thumbnail_url if it doesn't exist - item_thumbnail_textures[body_item->thumbnail_url].referenced = true; - if(body_item->dirty) { body_item->dirty = false; if(body_item->title_text) body_item->title_text->setString(body_item->title); else - body_item->title_text = std::make_unique(body_item->title, title_text.getFont(), 14, size.x - 50 - image_padding_x * 2.0f); - //body_item->title_text->updateGeometry(); + body_item->title_text = std::make_unique(body_item->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) } } @@ -211,7 +206,6 @@ namespace QuickMedia { for(int i = first_visible_item + 1; i < num_items; ++i) { const auto &item = items[i]; - auto &item_thumbnail = item_thumbnail_textures[item->thumbnail_url]; if(pos.y >= start_y + size.y) break; @@ -219,6 +213,11 @@ namespace QuickMedia { if(!item->visible) continue; + // TODO: Instead of generating a new hash everytime to access textures, cache the hash of the thumbnail url + // Intentionally create the item with the key item->thumbnail_url if it doesn't exist + item_thumbnail_textures[item->thumbnail_url].referenced = true; + auto &item_thumbnail = item_thumbnail_textures[item->thumbnail_url]; + float item_height = item->title_text->getHeight(); if(!item->author.empty()) { item_height += author_text.getCharacterSize() + 2.0f; -- cgit v1.2.3