aboutsummaryrefslogtreecommitdiff
path: root/source/EditorUtils.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-04-18 17:54:29 -0700
committerrtk0c <[email protected]>2022-04-18 17:54:29 -0700
commit7af9992ca81c699bc1cf05eb691e284bf424f050 (patch)
tree0f9bf191270791d80a28d7df1f1ffd5223158124 /source/EditorUtils.cpp
parent5424a1d5434e3ddd911a504719918c2df027e2fd (diff)
Changeset: 9 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));
+}