From 7af9992ca81c699bc1cf05eb691e284bf424f050 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Mon, 18 Apr 2022 17:54:29 -0700 Subject: Changeset: 9 Implement IresSpritesheet --- source/EditorUtils.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source/EditorUtils.cpp') 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)); +} -- cgit v1.2.3-70-g09d2