aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Body.hpp1
-rw-r--r--include/Scale.hpp42
2 files changed, 40 insertions, 3 deletions
diff --git a/include/Body.hpp b/include/Body.hpp
index ce61811..7bf89e2 100644
--- a/include/Body.hpp
+++ b/include/Body.hpp
@@ -217,6 +217,7 @@ namespace QuickMedia {
void draw_item(sf::RenderWindow &window, BodyItem *item, const sf::Vector2f &pos, const sf::Vector2f &size, const float item_height, const int item_index, const Json::Value &content_progress, bool include_embedded_item = true);
void update_dirty_state(BodyItem *body_item, sf::Vector2f size);
void clear_body_item_cache(BodyItem *body_item);
+ sf::Vector2i get_item_thumbnail_size(BodyItem *item) const;
private:
Program *program;
std::unordered_map<std::string, std::shared_ptr<ThumbnailData>> item_thumbnail_textures;
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 <SFML/System/Vector2.hpp>
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<typename T>
+ 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<typename T>
+ 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<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);
+ if(new_size.y > clamp_size.y)
+ new_size = wrap_to_size_y(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)
+ new_size = wrap_to_size(new_size, clamp_size);
+ return new_size;
+ }
+
+ template<typename T>
+ 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