mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 14:15:38 +00:00
Added cancelAnimation(slot) to GuiComponent.
Like stopAnimation, but does not call finishedCallback. All animations are now canceled when a GuiComponent is deleted (fixes a crash when closing ES while the "launch game" animation is playing).
This commit is contained in:
parent
fc5ca0019c
commit
8608ecc9eb
|
@ -16,11 +16,7 @@ GuiComponent::~GuiComponent()
|
||||||
{
|
{
|
||||||
mWindow->removeGui(this);
|
mWindow->removeGui(this);
|
||||||
|
|
||||||
for(unsigned char i = 0; i < MAX_ANIMATIONS; i++)
|
cancelAllAnimations();
|
||||||
{
|
|
||||||
if(mAnimationMap[i])
|
|
||||||
delete mAnimationMap[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mParent)
|
if(mParent)
|
||||||
mParent->removeChild(this);
|
mParent->removeChild(this);
|
||||||
|
@ -227,6 +223,29 @@ void GuiComponent::stopAnimation(unsigned char slot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GuiComponent::cancelAnimation(unsigned char slot)
|
||||||
|
{
|
||||||
|
assert(slot < MAX_ANIMATIONS);
|
||||||
|
if(mAnimationMap[slot])
|
||||||
|
{
|
||||||
|
mAnimationMap[slot]->removeFinishedCallback();
|
||||||
|
delete mAnimationMap[slot];
|
||||||
|
mAnimationMap[slot] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiComponent::stopAllAnimations()
|
||||||
|
{
|
||||||
|
for(unsigned char i = 0; i < MAX_ANIMATIONS; i++)
|
||||||
|
stopAnimation(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiComponent::cancelAllAnimations()
|
||||||
|
{
|
||||||
|
for(unsigned char i = 0; i < MAX_ANIMATIONS; i++)
|
||||||
|
cancelAnimation(i);
|
||||||
|
}
|
||||||
|
|
||||||
bool GuiComponent::isAnimationPlaying(unsigned char slot) const
|
bool GuiComponent::isAnimationPlaying(unsigned char slot) const
|
||||||
{
|
{
|
||||||
return mAnimationMap[slot] != NULL;
|
return mAnimationMap[slot] != NULL;
|
||||||
|
|
|
@ -60,6 +60,9 @@ public:
|
||||||
int getAnimationTime(unsigned char slot) const;
|
int getAnimationTime(unsigned char slot) const;
|
||||||
void setAnimation(Animation* animation, std::function<void()> finishedCallback = nullptr, bool reverse = false, unsigned char slot = 0);
|
void setAnimation(Animation* animation, std::function<void()> finishedCallback = nullptr, bool reverse = false, unsigned char slot = 0);
|
||||||
void stopAnimation(unsigned char slot);
|
void stopAnimation(unsigned char slot);
|
||||||
|
void cancelAnimation(unsigned char slot); // like stopAnimation, but doesn't call finishedCallback - only removes the animation, leaving things in their current state
|
||||||
|
void stopAllAnimations();
|
||||||
|
void cancelAllAnimations();
|
||||||
|
|
||||||
virtual unsigned char getOpacity() const;
|
virtual unsigned char getOpacity() const;
|
||||||
virtual void setOpacity(unsigned char opacity);
|
virtual void setOpacity(unsigned char opacity);
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
class AnimationController
|
class AnimationController
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// FinishedCallback is guaranteed to be called exactly once, even if the animation does not finish normally.
|
|
||||||
// Takes ownership of anim (will delete in destructor).
|
// Takes ownership of anim (will delete in destructor).
|
||||||
AnimationController(Animation* anim, std::function<void()> finishedCallback = nullptr, bool reverse = false);
|
AnimationController(Animation* anim, std::function<void()> finishedCallback = nullptr, bool reverse = false);
|
||||||
virtual ~AnimationController();
|
virtual ~AnimationController();
|
||||||
|
@ -17,6 +16,9 @@ public:
|
||||||
|
|
||||||
inline bool isReversed() const { return mReverse; }
|
inline bool isReversed() const { return mReverse; }
|
||||||
inline int getTime() const { return mTime; }
|
inline int getTime() const { return mTime; }
|
||||||
|
inline const std::function<void()>& getFinishedCallback() const { return mFinishedCallback; }
|
||||||
|
|
||||||
|
inline void removeFinishedCallback() { mFinishedCallback = nullptr; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Animation* mAnimation;
|
Animation* mAnimation;
|
||||||
|
|
Loading…
Reference in a new issue