From 58481b46a2c64fda4f506e15ee94dd97f527d552 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 6 Aug 2019 03:12:16 +0200 Subject: Save and show progress in manga and return to last page" --- src/Body.cpp | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'src/Body.cpp') diff --git a/src/Body.cpp b/src/Body.cpp index d391e87..68acaad 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -9,8 +9,14 @@ const sf::Color front_color(43, 45, 47); const sf::Color back_color(33, 35, 37); namespace QuickMedia { - Body::Body(sf::Font &font) : title_text("", font, 14), selected_item(0), loading_thumbnail(false) { + Body::Body(sf::Font &font) : + title_text("", font, 14), + progress_text("", font, 14), + selected_item(0), + loading_thumbnail(false) + { title_text.setFillColor(sf::Color::White); + progress_text.setFillColor(sf::Color::White); } void Body::select_previous_item() { @@ -98,11 +104,19 @@ namespace QuickMedia { return result; } + void Body::draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size) { + Json::Value empty_object(Json::objectValue); + draw(window, pos, size, empty_object); + } + // TODO: Skip drawing the rows that are outside the window. // TODO: Use a render target for the whole body so all images can be put into one. // TODO: Only load images once they are visible on the screen. // TODO: Load thumbnails with more than one thread. - void Body::draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size) { + // TODO: Show chapters (rows) that have been read differently to make it easier to see what + // needs hasn't been read yet. + void Body::draw(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, const Json::Value &content_progress) { + assert(content_progress.isObject()); const float font_height = title_text.getCharacterSize() + 8.0f; const float image_height = 100.0f; @@ -113,16 +127,19 @@ namespace QuickMedia { sf::RectangleShape item_background; item_background.setFillColor(front_color); - item_background.setOutlineThickness(1.0f); - item_background.setOutlineColor(sf::Color(63, 65, 67)); + //item_background.setOutlineThickness(1.0f); + //item_background.setOutlineColor(sf::Color(63, 65, 67)); sf::RectangleShape selected_border; selected_border.setFillColor(sf::Color::Red); const float selected_border_width = 5.0f; int num_items = items.size(); - if((int)item_thumbnail_textures.size() != num_items) + 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) { const auto &item = items[i]; @@ -182,6 +199,17 @@ namespace QuickMedia { title_text.setPosition(std::floor(item_pos.x + text_offset_x + 10.0f), std::floor(item_pos.y)); window.draw(title_text); + // TODO: Do the same for non-manga content + const Json::Value &item_progress = content_progress[item->title]; + const Json::Value ¤t_json = item_progress["current"]; + const Json::Value &total_json = item_progress["total"]; + if(current_json.isNumeric() && total_json.isNumeric()) { + progress_text.setString(std::string("Progress: ") + std::to_string(current_json.asInt()) + "/" + std::to_string(total_json.asInt())); + auto bounds = progress_text.getLocalBounds(); + progress_text.setPosition(std::floor(item_pos.x + size.x - bounds.width - 10.0f), std::floor(item_pos.y)); + window.draw(progress_text); + } + pos.y += row_height + 10.0f; } } -- cgit v1.2.3