// // VROAnimation.h // ViroRenderer // // Created by Raj Advani on 12/15/15. // Copyright © 2015 Viro Media. All rights reserved. // #ifndef VROAnimation_h #define VROAnimation_h #include #include #include #include "VROAnimatable.h" /* Represents the animation of a property. Subclasses identify the type of the property (e.g. animating a floating point value, animating a VROVector3f, etc.). */ class VROAnimation { public: VROAnimation() {} VROAnimation(std::function finishCallback) : _finishCallback(finishCallback) {} virtual ~VROAnimation() {} /* Set the animatable. This is typically the object holding the property to be animated. It is stored by a weak_ptr so we can ensure it hasn't been deallocated before invoking the animation each frame. */ void setAnimatable(std::shared_ptr animatable) { _animatable = animatable; } /* Set a function to invoke when the animation completes. */ void setFinishCallback(std::function callback) { _finishCallback = callback; } /* Move the property to its value corresponding to t [0, 1]. */ virtual void processAnimationFrame(float t) = 0; /* Immediately finish this animation by moving its value to the end state. */ virtual void finish() = 0; /* Invoke after the animation is completed. */ void onTermination() { finish(); std::shared_ptr animatable = _animatable.lock(); if (animatable == nullptr){ return; } animatable->onAnimationFinished(); if (_finishCallback) { _finishCallback(animatable.get()); } } protected: std::weak_ptr _animatable; std::function _finishCallback; }; #endif /* VROAnimation_h */