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:
Aloshi 2014-04-14 21:03:11 -05:00
parent fc5ca0019c
commit 8608ecc9eb
3 changed files with 30 additions and 6 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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;