From 64e80991ca335c4ef7da736bb5582747caca284a Mon Sep 17 00:00:00 2001 From: vaxerski Date: Sat, 6 Aug 2022 22:11:08 +0200 Subject: [PATCH] added popin anim minimum % --- src/managers/AnimationManager.cpp | 36 +++++++++++++++++++++++++------ src/managers/AnimationManager.hpp | 2 +- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 54c4ab30..052daff8 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -262,16 +262,16 @@ bool CAnimationManager::deltazero(const CColor& a, const CColor& b) { // // -void CAnimationManager::animationPopin(CWindow* pWindow, bool close) { +void CAnimationManager::animationPopin(CWindow* pWindow, bool close, float minPerc) { const auto GOALPOS = pWindow->m_vRealPosition.goalv(); const auto GOALSIZE = pWindow->m_vRealSize.goalv(); if (!close) { - pWindow->m_vRealPosition.setValue(GOALPOS + GOALSIZE / 2.f); - pWindow->m_vRealSize.setValue(Vector2D(5, 5)); + pWindow->m_vRealSize.setValue((GOALSIZE * minPerc).clamp({5, 5}, {GOALSIZE.x, GOALSIZE.y})); + pWindow->m_vRealPosition.setValue(GOALPOS + GOALSIZE / 2.f - pWindow->m_vRealSize.m_vValue / 2.f); } else { - pWindow->m_vRealPosition = GOALPOS + GOALSIZE / 2.f; - pWindow->m_vRealSize = Vector2D(5, 5); + pWindow->m_vRealSize = (GOALSIZE * minPerc).clamp({5, 5}, {GOALSIZE.x, GOALSIZE.y}); + pWindow->m_vRealPosition = GOALPOS + GOALSIZE / 2.f - pWindow->m_vRealSize.m_vGoal / 2.f; } } @@ -361,14 +361,36 @@ void CAnimationManager::onWindowPostCreateClose(CWindow* pWindow, bool close) { } } else { // anim popin, fallback - animationPopin(pWindow, close); + + float minPerc = 0.f; + if (pWindow->m_sAdditionalConfigData.animationStyle.find("%") != 0) { + try { + auto percstr = pWindow->m_sAdditionalConfigData.animationStyle.substr(pWindow->m_sAdditionalConfigData.animationStyle.find_last_of(' ')); + minPerc = std::stoi(percstr.substr(0, percstr.length() - 1)); + } catch (std::exception& e) { + ; // oops + } + } + + animationPopin(pWindow, close, minPerc / 100.f); } } else { if (ANIMSTYLE == "slide") { animationSlide(pWindow, "", close); } else { // anim popin, fallback - animationPopin(pWindow, close); + + float minPerc = 0.f; + if (ANIMSTYLE.find("%") != 0) { + try { + auto percstr = ANIMSTYLE.substr(ANIMSTYLE.find_last_of(' ')); + minPerc = std::stoi(percstr.substr(0, percstr.length() - 1)); + } catch (std::exception& e) { + ; // oops + } + } + + animationPopin(pWindow, close, minPerc / 100.f); } } } \ No newline at end of file diff --git a/src/managers/AnimationManager.hpp b/src/managers/AnimationManager.hpp index bfcd5d69..9b422da7 100644 --- a/src/managers/AnimationManager.hpp +++ b/src/managers/AnimationManager.hpp @@ -31,7 +31,7 @@ private: std::unordered_map m_mBezierCurves; // Anim stuff - void animationPopin(CWindow*, bool close = false); + void animationPopin(CWindow*, bool close = false, float minPerc = 0.f); void animationSlide(CWindow*, std::string force = "", bool close = false); };