diff options
Diffstat (limited to 'include/Scale.hpp')
-rw-r--r-- | include/Scale.hpp | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/include/Scale.hpp b/include/Scale.hpp index eb902cd..daf1e75 100644 --- a/include/Scale.hpp +++ b/include/Scale.hpp @@ -1,10 +1,10 @@ #pragma once -#include <SFML/System/Vector2.hpp> +#include <mglpp/system/vec.hpp> namespace QuickMedia { - template<typename T> - static T wrap_to_size_x(const T &size, const T &clamp_size) { + template<typename T, typename A> + static T wrap_to_size_x(const T &size, A clamp_size) { T new_size; if(size.x == 0) { new_size.x = 0; @@ -12,13 +12,13 @@ namespace QuickMedia { return new_size; } float size_ratio = (float)size.y / (float)size.x; - new_size.x = clamp_size.x; + new_size.x = clamp_size; new_size.y = new_size.x * size_ratio; return new_size; } - template<typename T> - static T wrap_to_size_y(const T &size, const T &clamp_size) { + template<typename T, typename A> + static T wrap_to_size_y(const T &size, A clamp_size) { T new_size; if(size.y == 0) { new_size.x = 0; @@ -26,7 +26,7 @@ namespace QuickMedia { return new_size; } float size_ratio = (float)size.x / (float)size.y; - new_size.y = clamp_size.y; + new_size.y = clamp_size; new_size.x = new_size.y * size_ratio; return new_size; } @@ -34,20 +34,28 @@ namespace QuickMedia { template<typename T> static T wrap_to_size(const T &size, const T &clamp_size) { T new_size; - new_size = wrap_to_size_x(size, clamp_size); + new_size = wrap_to_size_x(size, clamp_size.x); if(new_size.y > clamp_size.y) - new_size = wrap_to_size_y(size, clamp_size); + new_size = wrap_to_size_y(size, clamp_size.y); return new_size; } - template<typename T> - static T clamp_to_size_x(const T &size, const T &clamp_size) { + template<typename T, typename A> + static T clamp_to_size_x(const T &size, A clamp_size) { T new_size = size; - if(size.x > clamp_size.x) + if(size.x > clamp_size) new_size = wrap_to_size_x(new_size, clamp_size); return new_size; } + template<typename T, typename A> + static T clamp_to_size_y(const T &size, const A clamp_size) { + T new_size = size; + if(size.y > clamp_size) + new_size = wrap_to_size_y(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; @@ -57,10 +65,10 @@ namespace QuickMedia { } template<typename T> - static sf::Vector2f get_ratio(const T &original_size, const T &new_size) { + static mgl::vec2f get_ratio(const T &original_size, const T &new_size) { if(original_size.x == 0 || original_size.y == 0) - return sf::Vector2f(0.0f, 0.0f); + return mgl::vec2f(0.0f, 0.0f); else - return sf::Vector2f((float)new_size.x / (float)original_size.x, (float)new_size.y / (float)original_size.y); + return mgl::vec2f((float)new_size.x / (float)original_size.x, (float)new_size.y / (float)original_size.y); } }
\ No newline at end of file |