mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 23:55: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);
|
||||
|
||||
for(unsigned char i = 0; i < MAX_ANIMATIONS; i++)
|
||||
{
|
||||
if(mAnimationMap[i])
|
||||
delete mAnimationMap[i];
|
||||
}
|
||||
cancelAllAnimations();
|
||||
|
||||
if(mParent)
|
||||
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
|
||||
{
|
||||
return mAnimationMap[slot] != NULL;
|
||||
|
|
|
@ -60,6 +60,9 @@ public:
|
|||
int getAnimationTime(unsigned char slot) const;
|
||||
void setAnimation(Animation* animation, std::function<void()> finishedCallback = nullptr, bool reverse = false, unsigned char slot = 0);
|
||||
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 void setOpacity(unsigned char opacity);
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
class AnimationController
|
||||
{
|
||||
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).
|
||||
AnimationController(Animation* anim, std::function<void()> finishedCallback = nullptr, bool reverse = false);
|
||||
virtual ~AnimationController();
|
||||
|
@ -17,6 +16,9 @@ public:
|
|||
|
||||
inline bool isReversed() const { return mReverse; }
|
||||
inline int getTime() const { return mTime; }
|
||||
inline const std::function<void()>& getFinishedCallback() const { return mFinishedCallback; }
|
||||
|
||||
inline void removeFinishedCallback() { mFinishedCallback = nullptr; }
|
||||
|
||||
private:
|
||||
Animation* mAnimation;
|
||||
|
|
Loading…
Reference in a new issue