aboutsummaryrefslogtreecommitdiff
path: root/src/gui/Utils.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-12-09 16:29:36 +0100
committerdec05eba <dec05eba@protonmail.com>2024-12-09 16:29:36 +0100
commitf38661593795e51e45e2dc2ead8a7bf897d226f6 (patch)
treeb0fa0fbf02ec8fc0c624f1de4197350571677100 /src/gui/Utils.cpp
parentf3565fdd77fb480575feec5de252466b093daf86 (diff)
Start on global settings, add tint color setting
Diffstat (limited to 'src/gui/Utils.cpp')
-rw-r--r--src/gui/Utils.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/gui/Utils.cpp b/src/gui/Utils.cpp
index e000b7a..d1643f2 100644
--- a/src/gui/Utils.cpp
+++ b/src/gui/Utils.cpp
@@ -50,4 +50,21 @@ namespace gsr {
void set_frame_delta_seconds(double frame_delta) {
frame_delta_seconds = frame_delta;
}
+
+ mgl::vec2f scale_keep_aspect_ratio(mgl::vec2f from, mgl::vec2f to) {
+ if(std::abs(from.x) <= 0.0001f || std::abs(from.y) <= 0.0001f)
+ return {0.0f, 0.0f};
+
+ const double height_to_width_ratio = (double)from.y / (double)from.x;
+ from.x = to.x;
+ from.y = from.x * height_to_width_ratio;
+
+ if(from.y > to.y) {
+ const double width_height_ratio = (double)from.x / (double)from.y;
+ from.y = to.y;
+ from.x = from.y * width_height_ratio;
+ }
+
+ return from;
+ }
} \ No newline at end of file