aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-08-05 19:05:31 +0200
committerdec05eba <dec05eba@protonmail.com>2019-08-05 19:05:34 +0200
commit5eb6e8a6ecd9907c422a052ed3fcd8381a375cd1 (patch)
tree1be661c7f86453750fc2a88cacdac7b64064af05
parent657edb8eb9ab2fdef60d9c5d23a4c3093a64d859 (diff)
Scale image/video
-rw-r--r--README.md8
-rw-r--r--src/QuickMedia.cpp27
-rw-r--r--src/VideoPlayer.cpp43
-rw-r--r--src/plugins/Manganelo.cpp1
4 files changed, 61 insertions, 18 deletions
diff --git a/README.md b/README.md
index 9da4b12..7de0d75 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,13 @@
# QuickMedia
Native clients of websites with fast access to what you want to see
# Dependencies
-See project.conf \[dependencies]. youtube-dl also needs to be installed to play videos from youtube.
+## Compile
+See project.conf \[dependencies].
+## Runtime
+### Required
+curl needs to be downloaded for network requests.
+### Optional
+youtube-dl needs to be installed to play videos from youtube.
# TODO
Fix x11 freeze that sometimes happens when playing video.
If a search returns no results, then "No results found for ..." should be shown and navigation should go back to searching with suggestions.
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index e6c7077..4a0a75d 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -458,6 +458,31 @@ namespace QuickMedia {
}
}
+ // TODO: Add option to scale image to window size.
+ // TODO: Fix scaling, it'ss a bit broken
+ static void clamp_sprite_to_size(sf::Sprite &sprite, const sf::Vector2f &size) {
+ auto texture_size = sprite.getTexture()->getSize();
+ auto image_size = sf::Vector2f(texture_size.x, texture_size.y);
+
+ double overflow_x = image_size.x - size.x;
+ double overflow_y = image_size.y - size.y;
+ if(overflow_x <= 0.0f && overflow_y <= 0.0f)
+ return;
+
+ auto scale = sprite.getScale();
+ float scale_ratio = scale.x / scale.y;
+
+ if(overflow_x * scale_ratio > overflow_y) {
+ float overflow_ratio = overflow_x / image_size.x;
+ float scale_x = 1.0f - overflow_ratio;
+ sprite.setScale(scale_x, scale_x * scale_ratio);
+ } else {
+ float overflow_ratio = overflow_y / image_size.y;
+ float scale_y = 1.0f - overflow_ratio;
+ sprite.setScale(scale_y * scale_ratio, scale_y);
+ }
+ }
+
void Program::image_page() {
search_bar->onTextUpdateCallback = nullptr;
search_bar->onTextSubmitCallback = nullptr;
@@ -527,12 +552,12 @@ namespace QuickMedia {
auto bounds = error_message.getLocalBounds();
error_message.setPosition(window_size.x * 0.5f - bounds.width * 0.5f, window_size.y * 0.5f - bounds.height);
} else {
+ clamp_sprite_to_size(image, window_size);
auto texture_size = image.getTexture()->getSize();
auto image_scale = image.getScale();
auto image_size = sf::Vector2f(texture_size.x, texture_size.y);
image_size.x *= image_scale.x;
image_size.y *= image_scale.y;
-
image.setPosition(window_size.x * 0.5f - image_size.x * 0.5f, window_size.y * 0.5f - image_size.y * 0.5f);
}
}
diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp
index ee4c715..88e2340 100644
--- a/src/VideoPlayer.cpp
+++ b/src/VideoPlayer.cpp
@@ -93,25 +93,38 @@ namespace QuickMedia {
sprite.setPosition(x, y);
}
+ // TODO: Fix this, it's incorrect
+ static void wrap_sprite_to_size(sf::Sprite &sprite, sf::Vector2i texture_size, const sf::Vector2f &size) {
+ auto image_size = sf::Vector2f(texture_size.x, texture_size.y);
+
+ double overflow_x = image_size.x - size.x;
+ double overflow_y = image_size.y - size.y;
+
+ auto scale = sprite.getScale();
+ float scale_ratio = scale.x / scale.y;
+ bool reverse = overflow_x < 0.0f && overflow_y < 0.0f;
+
+ if((reverse && overflow_x * scale_ratio < overflow_y) || overflow_x * scale_ratio > overflow_y) {
+ float overflow_ratio = overflow_x / image_size.x;
+ float scale_x = 1.0f - overflow_ratio;
+ sprite.setScale(scale_x, scale_x * scale_ratio);
+ } else {
+ float overflow_ratio = overflow_y / image_size.y;
+ float scale_y = 1.0f - overflow_ratio;
+ sprite.setScale(scale_y * scale_ratio, scale_y);
+ }
+ }
+
void VideoPlayer::resize(const sf::Vector2i &size) {
desired_size = size;
if(!textureBuffer)
return;
- float video_ratio = (double)video_size.x / (double)video_size.y;
- float scale_x = 1.0f;
- float scale_y = 1.0f;
- if(video_ratio >= 0.0f) {
- double ratio_x = (double)size.x / (double)video_size.x;
- scale_x = ratio_x;
- scale_y = ratio_x;
- sprite.setPosition(0.0f, size.y * 0.5f - video_size.y * scale_y * 0.5f);
- } else {
- double ratio_y = (double)size.y / (double)video_size.y;
- scale_x = ratio_y;
- scale_y = ratio_y;
- sprite.setPosition(size.x * 0.5f - video_size.x * scale_x * 0.5f, 0.0f);
- }
- sprite.setScale(scale_x, scale_y);
+ wrap_sprite_to_size(sprite, video_size, sf::Vector2f(desired_size.x, desired_size.y));
+ auto image_scale = sprite.getScale();
+ auto image_size = sf::Vector2f(video_size.x, video_size.y);
+ image_size.x *= image_scale.x;
+ image_size.y *= image_scale.y;
+ sprite.setPosition(desired_size.x * 0.5f - image_size.x * 0.5f, desired_size.y * 0.5f - image_size.y * 0.5f);
}
void VideoPlayer::draw(sf::RenderWindow &window) {
diff --git a/src/plugins/Manganelo.cpp b/src/plugins/Manganelo.cpp
index bc99387..d69aab1 100644
--- a/src/plugins/Manganelo.cpp
+++ b/src/plugins/Manganelo.cpp
@@ -96,7 +96,6 @@ namespace QuickMedia {
ImageResult Manganelo::get_image_by_index(const std::string &url, int index, std::string &image_data) {
if(url != last_chapter_url) {
- printf("Get list of image urls for chapter: %s\n", url.c_str());
last_chapter_image_urls.clear();
ImageResult image_result = get_image_urls_for_chapter(url, last_chapter_image_urls);
if(image_result != ImageResult::OK)