ComponentAnimator notification


#1

Hi Jules,

Is there a way of telling if the animator finished with all of the animations? If not, perhaps it could simply inherit from ChangeBroadcaster, so we could use a callback to get notified. While at it, maybe an isAnimating() would also be useful for someone.

Thanks!


#2

Yes, an isAnimating method is certainly something that it should have!


#3

In fact, it would be even better if, each step of the animation, the animator tries to dynamic_cast the component to an “AnimationCallback”.
If the cast works, then the animator should call the virtual method AnimationCallback::animationStep(const int currentStep, const int totalStep, const Rectangle & currentPos)

That way, the component could actually perform painting actions while animated depending on the current step of the animation (à la copy file in microsoft windows)…

It isn’t that hard to add, I’ll give it a shot


#4

Here it is (add to juce_ComponentAnimator.h):

//==============================================================================
/**
    If your component implements this interface, then it'll be informed
    each step of the animation.
*/
class JUCE_API AnimationCallback
{
public:
    //==============================================================================
    /** Main callback called each step of the animation
        
        @param animationProgress    This is a value between 0.0 (animation starting) 
                                    to 1.0 (animation ending)
        @param currentBounds        The current component bound */
    virtual void animationStep(const double animationProgress, 
                               const Rectangle & currentBounds) = 0;

    /** Destructor. */
    virtual ~AnimationCallback() {}
};

and in the cpp (only one liner does it well, in useTimeslice()):

                                           roundDoubleToInt (top),
                                           roundDoubleToInt (right - left),
                                           roundDoubleToInt (bottom - top));

+                AnimationCallback * step = dynamic_cast<AnimationCallback*>(component);
+                if (step) step->animationStep(newProgress, newBounds);

                if (newBounds != destination)
                {

BTW, you can use this code as-is, it’s public domain