summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-11-06 17:52:09 +0000
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-11-06 17:52:09 +0000
commit57817f7252e3acbe48620b6764a77fecb6bb0ec1 (patch)
tree90235b12f926d50c0f3c1250e0aff8641f29614c /src/helpers
parentb4c45aa2e3af0e595a6276986290c78d11465746 (diff)
Added resize transitions
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/AnimatedVariable.cpp5
-rw-r--r--src/helpers/AnimatedVariable.hpp48
2 files changed, 49 insertions, 4 deletions
diff --git a/src/helpers/AnimatedVariable.cpp b/src/helpers/AnimatedVariable.cpp
index 77707349..18162c99 100644
--- a/src/helpers/AnimatedVariable.cpp
+++ b/src/helpers/AnimatedVariable.cpp
@@ -66,3 +66,8 @@ void CAnimatedVariable::registerVar() {
int CAnimatedVariable::getDurationLeftMs() {
return std::max((int)(m_pConfig->pValues->internalSpeed * 100) - (int)std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - animationBegin).count(), 0);
}
+
+float CAnimatedVariable::getPercent() {
+ const auto DURATIONPASSED = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - animationBegin).count();
+ return std::clamp((DURATIONPASSED / 100.f) / m_pConfig->pValues->internalSpeed, 0.f, 1.f);
+} \ No newline at end of file
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;
};