From ea6f1b425a6aa9b7145a00d81473ef9508279eec Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 21 Oct 2020 03:12:35 +0200 Subject: Fix thumbnail fallback size being incorrect, incorrect read marker for matrix --- include/Scale.hpp | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'include/Scale.hpp') diff --git a/include/Scale.hpp b/include/Scale.hpp index 4ab2882..e7e1b27 100644 --- a/include/Scale.hpp +++ b/include/Scale.hpp @@ -3,7 +3,43 @@ #include namespace QuickMedia { - sf::Vector2f wrap_to_size(const sf::Vector2f &size, const sf::Vector2f &clamp_size); - sf::Vector2f clamp_to_size(const sf::Vector2f &size, const sf::Vector2f &clamp_size); - sf::Vector2f get_ratio(const sf::Vector2f &original_size, const sf::Vector2f &new_size); + template + static T wrap_to_size_x(const T &size, const T &clamp_size) { + T new_size; + float size_ratio = (float)size.y / (float)size.x; + new_size.x = clamp_size.x; + new_size.y = new_size.x * size_ratio; + return new_size; + } + + template + static T wrap_to_size_y(const T &size, const T &clamp_size) { + T new_size; + float size_ratio = (float)size.x / (float)size.y; + new_size.y = clamp_size.y; + new_size.x = new_size.y * size_ratio; + return new_size; + } + + template + static T wrap_to_size(const T &size, const T &clamp_size) { + T 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; + } + + template + 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) + new_size = wrap_to_size(new_size, clamp_size); + return new_size; + } + + template + static sf::Vector2f get_ratio(const T &original_size, const T &new_size) { + return sf::Vector2f((float)new_size.x / (float)original_size.x, (float)new_size.y / (float)original_size.y); + } } \ No newline at end of file -- cgit v1.2.3