aboutsummaryrefslogtreecommitdiff
path: root/source/EditorUtils.cpp
diff options
context:
space:
mode:
authorhnOsmium0001 <[email protected]>2022-04-18 17:54:29 -0700
committerhnOsmium0001 <[email protected]>2022-04-18 17:54:29 -0700
commit4b57fe1fb1401bab9439a639bd842ca61386fe22 (patch)
treece06c1fc38b65e8f74acf36d1e3ecfa7e56b367a /source/EditorUtils.cpp
parentd43508ba4843801cbbf1f42a27af260d4eef5701 (diff)
Implement IresSpritesheet
Diffstat (limited to 'source/EditorUtils.cpp')
-rw-r--r--source/EditorUtils.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/source/EditorUtils.cpp b/source/EditorUtils.cpp
index a0d2fc7..4863301 100644
--- a/source/EditorUtils.cpp
+++ b/source/EditorUtils.cpp
@@ -160,3 +160,20 @@ bool ImGui::Splitter(bool splitVertically, float thickness, float* size1, float*
return held;
}
+
+float Utils::CalcImageHeight(glm::vec2 original, int targetWidth) {
+ // Xorig / Yorig = Xnew / Ynew
+ // Ynew = Xnew * Yorig / Xorig
+ return targetWidth * original.y / original.x;
+}
+
+float Utils::CalcImageWidth(glm::vec2 original, float targetHeight) {
+ // Xorig / Yorig = Xnew / Ynew
+ // Xnew = Xorig / Yorig * Ynew
+ return original.x / original.y * targetHeight;
+}
+
+ImVec2 Utils::FitImage(glm::vec2 original) {
+ float newWidth = ImGui::GetContentRegionAvail().x;
+ return ImVec2(newWidth, CalcImageHeight(original, newWidth));
+}