aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO2
-rw-r--r--include/ImageViewer.hpp5
-rw-r--r--include/Scale.hpp8
-rw-r--r--src/ImageViewer.cpp58
-rw-r--r--src/QuickMedia.cpp4
5 files changed, 66 insertions, 11 deletions
diff --git a/TODO b/TODO
index c1d6fc9..7b9508b 100644
--- a/TODO
+++ b/TODO
@@ -134,4 +134,4 @@ When ui is scaled then the predicted thumbnail size will be wrong since its scal
Check if get_page handlers in pages need to check if next batch is valid. If the server returns empty next batch we shouldn't fetch the first page...
Cloudflare kicks in when downloading manga on manganelo.. figure out a way to bypass it. This doesn't seem to happen when using python requests as is done in AutoMedia.
Replace cppcodec with another library for base64 url encoding/decoding. Its way too large for what it does.
-Add a combined manga plugin that allows you to search for manga across all manga plugins. \ No newline at end of file
+Revert back to old fuzzy search code or use levenshtein distance, then reorder items by best match. This could be done by having a second vector of indices and use that vector everywhere body items by index is accessed (including selected_item). Also perform the search in Body::draw when search term has been modified. This allows us to automatically update that new vector. \ No newline at end of file
diff --git a/include/ImageViewer.hpp b/include/ImageViewer.hpp
index c29ea13..74d93c1 100644
--- a/include/ImageViewer.hpp
+++ b/include/ImageViewer.hpp
@@ -29,6 +29,7 @@ namespace QuickMedia {
ImageStatus image_status;
std::unique_ptr<sf::Image> image;
bool visible_on_screen;
+ float prev_height = 0.0f;
};
struct PageSize {
@@ -44,7 +45,7 @@ namespace QuickMedia {
class ImageViewer {
public:
- ImageViewer(sf::RenderWindow *window, int num_pages, const std::string &content_title, const std::string &chapter_title, int current_page, const Path &chapter_cache_dir);
+ ImageViewer(sf::RenderWindow *window, int num_pages, const std::string &content_title, const std::string &chapter_title, int current_page, const Path &chapter_cache_dir, bool *fit_image_to_window);
~ImageViewer();
ImageViewerAction draw();
// Returns page as 1 indexed
@@ -95,5 +96,7 @@ namespace QuickMedia {
std::thread image_loader_thread;
bool loading_image = false;
+
+ bool *fit_image_to_window;
};
} \ No newline at end of file
diff --git a/include/Scale.hpp b/include/Scale.hpp
index 375ddff..e458894 100644
--- a/include/Scale.hpp
+++ b/include/Scale.hpp
@@ -33,6 +33,14 @@ namespace QuickMedia {
}
template<typename T>
+ static T clamp_to_size_x(const T &size, const T &clamp_size) {
+ T new_size = size;
+ if(size.x > clamp_size.x)
+ new_size = wrap_to_size_x(new_size, clamp_size);
+ return new_size;
+ }
+
+ template<typename T>
static T clamp_to_size(const T &size, const T &clamp_size) {
T new_size = size;
if(size.x > clamp_size.x || size.y > clamp_size.y)
diff --git a/src/ImageViewer.cpp b/src/ImageViewer.cpp
index 271d69f..dbd2284 100644
--- a/src/ImageViewer.cpp
+++ b/src/ImageViewer.cpp
@@ -3,6 +3,7 @@
#include "../include/Storage.hpp"
#include "../include/SfmlFixes.hpp"
#include "../include/ResourceLoader.hpp"
+#include "../include/Scale.hpp"
#include <cmath>
#include <malloc.h>
#include <SFML/Window/Event.hpp>
@@ -10,7 +11,23 @@
#include <SFML/Graphics/RectangleShape.hpp>
namespace QuickMedia {
- ImageViewer::ImageViewer(sf::RenderWindow *window, int num_pages, const std::string &content_title, const std::string &chapter_title, int current_page, const Path &chapter_cache_dir) :
+ static sf::Vector2<double> get_no_image_size_scaled(sf::Vector2<double> window_size, bool fit_image_to_window) {
+ sf::Vector2<double> no_image_page_size(720.0, 1280.0);
+ sf::Vector2f no_image_page_size_f(no_image_page_size.x, no_image_page_size.y);
+ sf::Vector2f content_size(window_size.x, window_size.y);
+
+ sf::Vector2f image_scale;
+ if(fit_image_to_window)
+ image_scale = get_ratio(no_image_page_size_f, wrap_to_size_x(no_image_page_size_f, content_size));
+ else
+ image_scale = get_ratio(no_image_page_size_f, clamp_to_size_x(no_image_page_size_f, content_size));
+
+ no_image_page_size.x *= image_scale.x;
+ no_image_page_size.y *= image_scale.y;
+ return no_image_page_size;
+ }
+
+ ImageViewer::ImageViewer(sf::RenderWindow *window, int num_pages, const std::string &content_title, const std::string &chapter_title, int current_page, const Path &chapter_cache_dir, bool *fit_image_to_window) :
window(window),
current_page(current_page),
num_pages(num_pages),
@@ -19,7 +36,8 @@ namespace QuickMedia {
chapter_cache_dir(chapter_cache_dir),
focused_page(current_page),
font(FontLoader::get_font(FontLoader::FontType::LATIN)),
- page_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 14)
+ page_text("", *FontLoader::get_font(FontLoader::FontType::LATIN), 14),
+ fit_image_to_window(fit_image_to_window)
{
current_page = std::min(current_page, num_pages);
image_data.resize(num_pages);
@@ -87,6 +105,17 @@ namespace QuickMedia {
page_image_data->visible_on_screen = true;
if(page_image_data->image_status == ImageStatus::APPLIED_TO_TEXTURE) {
+ auto texture_size = page_image_data->sprite.getTexture()->getSize();
+ sf::Vector2f texture_size_f(texture_size.x, texture_size.y);
+ sf::Vector2f content_size(window_size.x, window_size.y);
+
+ sf::Vector2f image_scale;
+ if(*fit_image_to_window)
+ image_scale = get_ratio(texture_size_f, wrap_to_size_x(texture_size_f, content_size));
+ else
+ image_scale = get_ratio(texture_size_f, clamp_to_size_x(texture_size_f, content_size));
+
+ page_image_data->sprite.setScale(image_scale);
page_image_data->sprite.setPosition(render_pos.x, render_pos.y);
window.draw(page_image_data->sprite);
} else {
@@ -198,6 +227,9 @@ namespace QuickMedia {
if(event.key.code == sf::Keyboard::I)
return ImageViewerAction::SWITCH_TO_SINGLE_IMAGE_MODE;
+
+ if(event.key.code == sf::Keyboard::F)
+ *fit_image_to_window = !*fit_image_to_window;
} else if(event.type == sf::Event::KeyReleased) {
if(event.key.code == sf::Keyboard::Up || (event.key.control && event.key.code == sf::Keyboard::K))
up_pressed = false;
@@ -267,9 +299,10 @@ namespace QuickMedia {
double height_before = get_page_size(page_i).y;
page_data->image_status = ImageStatus::APPLIED_TO_TEXTURE;
page_data->sprite.setTexture(page_data->texture, true);
- page_size[page_i].size = get_page_size(page_i);
+ sf::Vector2u texture_size = image_data[page_i]->texture.getSize();
+ page_size[page_i].size = sf::Vector2<double>(texture_size.x, texture_size.y);
page_size[page_i].loaded = true;
- double height_after = page_size[page_i].size.y;
+ double height_after = get_page_size(page_i).y;
double height_diff = height_before - height_after;
if(scroll_speed <= 0.0 && page_i < current_page) {
@@ -358,17 +391,28 @@ namespace QuickMedia {
}
sf::Vector2<double> ImageViewer::get_page_size(int page) {
- const sf::Vector2<double> no_image_page_size(720.0, 1280.0);
+ sf::Vector2<double> no_image_page_size = get_no_image_size_scaled(window_size, *fit_image_to_window);
if(page < 0 || page >= (int)image_data.size())
return no_image_page_size;
- if(page_size[page].loaded)
- return page_size[page].size;
+ if(page_size[page].loaded) {
+ sf::Vector2f texture_size_f(page_size[page].size.x, page_size[page].size.y);
+ sf::Vector2f content_size(window_size.x, window_size.y);
+
+ sf::Vector2f image_scale;
+ if(*fit_image_to_window)
+ image_scale = get_ratio(texture_size_f, wrap_to_size_x(texture_size_f, content_size));
+ else
+ image_scale = get_ratio(texture_size_f, clamp_to_size_x(texture_size_f, content_size));
+
+ return sf::Vector2<double>(page_size[page].size.x * image_scale.x, page_size[page].size.y * image_scale.y);
+ }
if(!image_data[page] || image_data[page]->image_status != ImageStatus::APPLIED_TO_TEXTURE)
return no_image_page_size;
+ // Do not scale here, because this will be used to set page_size[page].size
sf::Vector2u texture_size = image_data[page]->texture.getSize();
return sf::Vector2<double>(texture_size.x, texture_size.y);
}
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 0f69f85..44901e8 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -548,7 +548,7 @@ namespace QuickMedia {
tmp_file.append(".tmp.png");
fprintf(stderr, "Upscaling %s\n", copy_op.source.data.c_str());
- const char *args[] = { "waifu2x-ncnn-vulkan", "-i", copy_op.source.data.c_str(), "-o", tmp_file.data.c_str(), nullptr };
+ const char *args[] = { "waifu2x-ncnn-vulkan", "-n", "3", "-i", copy_op.source.data.c_str(), "-o", tmp_file.data.c_str(), nullptr };
if(exec_program(args, nullptr, nullptr) != 0) {
fprintf(stderr, "Warning: failed to upscale %s with waifu2x-ncnn-vulkan\n", copy_op.source.data.c_str());
// No conversion, but we need the file to have the destination name to see that the operation completed (and read it)
@@ -2784,7 +2784,7 @@ namespace QuickMedia {
json_chapter = Json::Value(Json::objectValue);
}
- ImageViewer image_viewer(&window, num_manga_pages, images_page->manga_name, images_page->get_chapter_name(), image_index, content_cache_dir);
+ ImageViewer image_viewer(&window, num_manga_pages, images_page->manga_name, images_page->get_chapter_name(), image_index, content_cache_dir, &fit_image_to_window);
json_chapter["current"] = std::min(latest_read, image_viewer.get_num_pages());
json_chapter["total"] = image_viewer.get_num_pages();