Skip to content

Commit 738dcf9

Browse files
introduce create2 to avoid breaking the API
1 parent 7b54f66 commit 738dcf9

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

include/hyprutils/animation/AnimatedVariable.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ namespace Hyprutils {
2121
; // m_bDummy = true;
2222
};
2323

24-
void create(CAnimationManager*, int, Memory::CWeakPointer<CBaseAnimatedVariable>);
24+
void create(CAnimationManager*, int, Memory::CSharedPointer<CBaseAnimatedVariable>);
25+
void create2(CAnimationManager*, int, Memory::CWeakPointer<CBaseAnimatedVariable>);
2526
void connectToActive();
2627
void disconnectFromActive();
2728

@@ -136,7 +137,8 @@ namespace Hyprutils {
136137
public:
137138
CGenericAnimatedVariable() = default;
138139

139-
void create(const int typeInfo, CAnimationManager* pAnimationManager, Memory::CWeakPointer<CGenericAnimatedVariable<VarType, AnimationContext>> pSelf,
140+
/* Deprecated: use create2 */
141+
void create(const int typeInfo, CAnimationManager* pAnimationManager, Memory::CSharedPointer<CGenericAnimatedVariable<VarType, AnimationContext>> pSelf,
140142
const VarType& initialValue) {
141143
m_Begun = initialValue;
142144
m_Value = initialValue;
@@ -145,6 +147,16 @@ namespace Hyprutils {
145147
CBaseAnimatedVariable::create(pAnimationManager, typeInfo, pSelf);
146148
}
147149

150+
/* Equivalent to create, except that it allows animated variables to be UP's */
151+
void create2(const int typeInfo, CAnimationManager* pAnimationManager, Memory::CWeakPointer<CGenericAnimatedVariable<VarType, AnimationContext>> pSelf,
152+
const VarType& initialValue) {
153+
m_Begun = initialValue;
154+
m_Value = initialValue;
155+
m_Goal = initialValue;
156+
157+
CBaseAnimatedVariable::create2(pAnimationManager, typeInfo, pSelf);
158+
}
159+
148160
CGenericAnimatedVariable(const CGenericAnimatedVariable&) = delete;
149161
CGenericAnimatedVariable(CGenericAnimatedVariable&&) = delete;
150162
CGenericAnimatedVariable& operator=(const CGenericAnimatedVariable&) = delete;

src/animation/AnimatedVariable.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ static const std::string DEFAULTSTYLE = "";
1111
#define SP CSharedPointer
1212
#define WP CWeakPointer
1313

14-
void CBaseAnimatedVariable::create(CAnimationManager* pManager, int typeInfo, WP<CBaseAnimatedVariable> pSelf) {
14+
void CBaseAnimatedVariable::create(CAnimationManager* pManager, int typeInfo, SP<CBaseAnimatedVariable> pSelf) {
15+
m_Type = typeInfo;
16+
m_pSelf = std::move(pSelf);
17+
18+
m_pAnimationManager = pManager;
19+
m_pSignals = pManager->getSignals();
20+
m_bDummy = false;
21+
}
22+
23+
void CBaseAnimatedVariable::create2(CAnimationManager* pManager, int typeInfo, WP<CBaseAnimatedVariable> pSelf) {
1524
m_Type = typeInfo;
1625
m_pSelf = std::move(pSelf);
1726

tests/animation/Animation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class CMyAnimationManager : public CAnimationManager {
9494
constexpr const eAVTypes EAVTYPE = std::is_same_v<VarType, int> ? eAVTypes::INT : eAVTypes::TEST;
9595
av = makeUnique<CGenericAnimatedVariable<VarType, EmtpyContext>>();
9696

97-
av->create(EAVTYPE, sc<CAnimationManager*>(this), av, v);
97+
av->create2(EAVTYPE, sc<CAnimationManager*>(this), av, v);
9898
av->setConfig(animationTree.getConfig(animationConfigName));
9999
}
100100

@@ -392,4 +392,4 @@ TEST(Animation, animation) {
392392
} // a gets destroyed
393393

394394
EXPECT_EQ(pAnimationManager.get(), nullptr);
395-
}
395+
}

0 commit comments

Comments
 (0)