diff options
author | vaxerski <[email protected]> | 2022-11-06 17:52:09 +0000 |
---|---|---|
committer | vaxerski <[email protected]> | 2022-11-06 17:52:09 +0000 |
commit | 57817f7252e3acbe48620b6764a77fecb6bb0ec1 (patch) | |
tree | 90235b12f926d50c0f3c1250e0aff8641f29614c /src/helpers/AnimatedVariable.hpp | |
parent | b4c45aa2e3af0e595a6276986290c78d11465746 (diff) | |
download | Hyprland-57817f7252e3acbe48620b6764a77fecb6bb0ec1.tar.gz Hyprland-57817f7252e3acbe48620b6764a77fecb6bb0ec1.zip |
Added resize transitions
Diffstat (limited to 'src/helpers/AnimatedVariable.hpp')
-rw-r--r-- | src/helpers/AnimatedVariable.hpp | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp index 7b5a6895..2c2c3ccf 100644 --- a/src/helpers/AnimatedVariable.hpp +++ b/src/helpers/AnimatedVariable.hpp @@ -21,6 +21,7 @@ class CAnimationManager; class CWorkspace; struct SLayerSurface; struct SAnimationPropertyConfig; +class CHyprRenderer; class CAnimatedVariable { public: @@ -68,18 +69,24 @@ public: m_vGoal = v; animationBegin = std::chrono::system_clock::now(); m_vBegun = m_vValue; + + onAnimationBegin(); } void operator=(const float& v) { m_fGoal = v; animationBegin = std::chrono::system_clock::now(); m_fBegun = m_fValue; + + onAnimationBegin(); } void operator=(const CColor& v) { m_cGoal = v; animationBegin = std::chrono::system_clock::now(); m_cBegun = m_cValue; + + onAnimationBegin(); } // Sets the actual stored value, without affecting the goal, but resets the timer @@ -87,6 +94,8 @@ public: m_vValue = v; animationBegin = std::chrono::system_clock::now(); m_vBegun = m_vValue; + + onAnimationBegin(); } // Sets the actual stored value, without affecting the goal, but resets the timer @@ -94,6 +103,8 @@ public: m_fValue = v; animationBegin = std::chrono::system_clock::now(); m_vBegun = m_vValue; + + onAnimationBegin(); } // Sets the actual stored value, without affecting the goal, but resets the timer @@ -101,6 +112,8 @@ public: m_cValue = v; animationBegin = std::chrono::system_clock::now(); m_vBegun = m_vValue; + + onAnimationBegin(); } // Sets the actual value and goal @@ -139,7 +152,7 @@ public: return false; // just so that the warning is suppressed } - void warp() { + void warp(bool endCallback = true) { switch (m_eVarType) { case AVARTYPE_FLOAT: { m_fValue = m_fGoal; @@ -156,6 +169,9 @@ public: default: UNREACHABLE(); } + + if (endCallback) + onAnimationEnd(); } void setConfig(SAnimationPropertyConfig* pConfig) { @@ -168,16 +184,27 @@ public: int getDurationLeftMs(); + /* returns the spent (completion) % */ + float getPercent(); + /* sets a function to be ran when the animation finishes. if an animation is not running, runs instantly. - will remove the callback when ran. */ - void setCallbackOnEnd(std::function<void(void* thisptr)> func) { + if "remove" is set to true, will remove the callback when ran. */ + void setCallbackOnEnd(std::function<void(void* thisptr)> func, bool remove = true) { m_fEndCallback = func; + m_bRemoveEndAfterRan = remove; if (!isBeingAnimated()) onAnimationEnd(); } + /* sets a function to be ran when an animation is started. + if "remove" is set to true, will remove the callback when ran. */ + void setCallbackOnBegin(std::function<void(void* thisptr)> func, bool remove = true) { + m_fBeginCallback = func; + m_bRemoveBeginAfterRan = remove; + } + private: Vector2D m_vValue = Vector2D(0,0); @@ -207,17 +234,30 @@ private: ANIMATEDVARTYPE m_eVarType = AVARTYPE_INVALID; AVARDAMAGEPOLICY m_eDamagePolicy = AVARDAMAGE_INVALID; + bool m_bRemoveEndAfterRan = true; + bool m_bRemoveBeginAfterRan = true; std::function<void(void* thisptr)> m_fEndCallback; + std::function<void(void* thisptr)> m_fBeginCallback; // methods void onAnimationEnd() { if (m_fEndCallback) { m_fEndCallback(this); - m_fEndCallback = nullptr; // reset + if (m_bRemoveEndAfterRan) + m_fEndCallback = nullptr; // reset + } + } + + void onAnimationBegin() { + if (m_fBeginCallback) { + m_fBeginCallback(this); + if (m_bRemoveBeginAfterRan) + m_fBeginCallback = nullptr; // reset } } friend class CAnimationManager; friend class CWorkspace; friend struct SLayerSurface; + friend class CHyprRenderer; }; |