diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-08-07 23:46:24 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2019-08-07 23:46:27 +0200 |
commit | e745c2239b8bcd30e75af27de5067dbcb1707ac1 (patch) | |
tree | aa15d0452b8d26fd255880defb056c4bb13add52 /src/Scale.cpp | |
parent | 852c6bc48b7044c54923b722ab5d9363a27ceb6c (diff) |
Correctly scale images and video to window size
Diffstat (limited to 'src/Scale.cpp')
-rw-r--r-- | src/Scale.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/Scale.cpp b/src/Scale.cpp new file mode 100644 index 0000000..ab7ea2e --- /dev/null +++ b/src/Scale.cpp @@ -0,0 +1,38 @@ +#include "../include/Scale.hpp" + +namespace QuickMedia { + static sf::Vector2f wrap_to_size_x(const sf::Vector2f &size, const sf::Vector2f &clamp_size) { + sf::Vector2f new_size; + auto size_ratio = size.y / size.x; + new_size.x = clamp_size.x; + new_size.y = new_size.x * size_ratio; + return new_size; + } + + static sf::Vector2f wrap_to_size_y(const sf::Vector2f &size, const sf::Vector2f &clamp_size) { + sf::Vector2f new_size; + auto size_ratio = size.x / size.y; + new_size.y = clamp_size.y; + new_size.x = new_size.y * size_ratio; + return new_size; + } + + sf::Vector2f wrap_to_size(const sf::Vector2f &size, const sf::Vector2f &clamp_size) { + sf::Vector2f new_size; + new_size = wrap_to_size_x(size, clamp_size); + if(new_size.y > clamp_size.y) + new_size = wrap_to_size_y(size, clamp_size); + return new_size; + } + + sf::Vector2f clamp_to_size(const sf::Vector2f &size, const sf::Vector2f &clamp_size) { + sf::Vector2f new_size = size; + if(size.x > clamp_size.x || size.y > clamp_size.y) + new_size = wrap_to_size(new_size, clamp_size); + return new_size; + } + + sf::Vector2f get_ratio(const sf::Vector2f &original_size, const sf::Vector2f &new_size) { + return sf::Vector2f(new_size.x / original_size.x, new_size.y / original_size.y); + } +}
\ No newline at end of file |