diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-08-05 20:15:47 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2019-08-05 20:15:49 +0200 |
commit | 2b294258bbc89f1b49554468022a035782e49074 (patch) | |
tree | 33a5c0624d1bc4f9beef082988d84ab90a459f71 /src | |
parent | 5eb6e8a6ecd9907c422a052ed3fcd8381a375cd1 (diff) |
Show current image / number of images for manga
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 43 | ||||
-rw-r--r-- | src/plugins/Manganelo.cpp | 31 |
2 files changed, 59 insertions, 15 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 4a0a75d..5f65fdd 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -503,14 +503,14 @@ namespace QuickMedia { image_texture.setSmooth(true); image.setTexture(image_texture, true); } else { - error_message.setString(std::string("Failed to load image for page ") + std::to_string(image_index)); + error_message.setString(std::string("Failed to load image for page ") + std::to_string(image_index + 1)); } } else if(image_result == ImageResult::END) { - // TODO: Better error message, with chapter name + // TODO: Improve this message error_message.setString("End of chapter"); } else { // TODO: Convert ImageResult error to a string and show to user - error_message.setString(std::string("Network error, failed to get image for page ") + std::to_string(image_index)); + error_message.setString(std::string("Network error, failed to get image for page ") + std::to_string(image_index + 1)); } image_data.resize(0); @@ -518,8 +518,20 @@ namespace QuickMedia { bool resized = true; sf::Event event; - // TODO: Show current page / number of pages. - // TODO: Show to user if a certain page is missing (by checking page name (number) and checking if some is skipped) + int num_images = 0; + image_plugin->get_number_of_images(images_url, num_images); + + sf::Text chapter_text(std::string("Page ") + std::to_string(image_index + 1) + "/" + std::to_string(num_images), font, 18); + if(image_index == num_images) + chapter_text.setString("end"); + chapter_text.setFillColor(sf::Color::White); + sf::RectangleShape chapter_text_background; + chapter_text_background.setFillColor(sf::Color(0, 0, 0, 150)); + + sf::Clock window_last_focused; + bool focused = window.hasFocus(); + + // TODO: Show to user if a certain page is missing (by checking page name (number) and checking if some are skipped) while (current_page == Page::IMAGES) { while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { @@ -537,13 +549,20 @@ namespace QuickMedia { return; } } else if(event.key.code == sf::Keyboard::Down) { - if(!error) { + if(image_index < num_images) { ++image_index; return; } } else if(event.key.code == sf::Keyboard::Escape) { current_page = Page::EPISODE_LIST; } + } else if(event.type == sf::Event::MouseEntered) { + window_last_focused.restart(); + focused = true; + } else if(event.type == sf::Event::MouseLeft) { + focused = false; + } else if(event.type == sf::Event::MouseMoved && focused) { + window_last_focused.restart(); } } @@ -568,6 +587,18 @@ namespace QuickMedia { } else { window.draw(image); } + if(window_last_focused.getElapsedTime().asMilliseconds() < 4000) { + float font_height = chapter_text.getCharacterSize() + 8.0f; + float background_height = font_height + 20.0f; + + chapter_text_background.setSize(sf::Vector2f(window_size.x, background_height)); + chapter_text_background.setPosition(0.0f, window_size.y - background_height); + window.draw(chapter_text_background); + + auto text_bounds = chapter_text.getLocalBounds(); + chapter_text.setPosition(window_size.x * 0.5f - text_bounds.width * 0.5f, window_size.y - background_height * 0.5f - text_bounds.height * 0.5f); + window.draw(chapter_text); + } window.display(); } } diff --git a/src/plugins/Manganelo.cpp b/src/plugins/Manganelo.cpp index d69aab1..6dd4ec7 100644 --- a/src/plugins/Manganelo.cpp +++ b/src/plugins/Manganelo.cpp @@ -95,13 +95,9 @@ namespace QuickMedia { } ImageResult Manganelo::get_image_by_index(const std::string &url, int index, std::string &image_data) { - if(url != last_chapter_url) { - last_chapter_image_urls.clear(); - ImageResult image_result = get_image_urls_for_chapter(url, last_chapter_image_urls); - if(image_result != ImageResult::OK) - return image_result; - last_chapter_url = url; - } + ImageResult image_result = get_image_urls_for_chapter(url); + if(image_result != ImageResult::OK) + return image_result; int num_images = last_chapter_image_urls.size(); if(index < 0 || index >= num_images) @@ -120,7 +116,22 @@ namespace QuickMedia { } } - ImageResult Manganelo::get_image_urls_for_chapter(const std::string &url, std::vector<std::string> &urls) { + ImageResult Manganelo::get_number_of_images(const std::string &url, int &num_images) { + num_images = 0; + ImageResult image_result = get_image_urls_for_chapter(url); + if(image_result != ImageResult::OK) + return image_result; + + num_images = last_chapter_image_urls.size(); + return ImageResult::OK; + } + + ImageResult Manganelo::get_image_urls_for_chapter(const std::string &url) { + if(url == last_chapter_url) + return ImageResult::OK; + + last_chapter_image_urls.clear(); + std::string website_data; if(download_to_string(url, website_data) != DownloadResult::OK) return ImageResult::NET_ERR; @@ -136,10 +147,12 @@ namespace QuickMedia { const char *src = quickmedia_html_node_get_attribute_value(node, "src"); if(src) urls->push_back(src); - }, &urls); + }, &last_chapter_image_urls); cleanup: quickmedia_html_search_deinit(&html_search); + if(result == 0) + last_chapter_url = url; return result == 0 ? ImageResult::OK : ImageResult::ERR; } }
\ No newline at end of file |