diff --git a/modules/juce_gui_basics/layout/juce_ComponentAnimator.cpp b/modules/juce_gui_basics/layout/juce_ComponentAnimator.cpp index 2abeb896d5..0daebc747b 100644 --- a/modules/juce_gui_basics/layout/juce_ComponentAnimator.cpp +++ b/modules/juce_gui_basics/layout/juce_ComponentAnimator.cpp @@ -47,11 +47,12 @@ public: void reset (const Rectangle& finalBounds, float finalAlpha, + int millisecondsBeforeStartMoving, int millisecondsToSpendMoving, bool useProxyComponent, double startSpd, double endSpd) { - msElapsed = 0; + msElapsed = -jmax (0, millisecondsBeforeStartMoving); msTotal = jmax (1, millisecondsToSpendMoving); lastProgress = 0; destination = finalBounds; @@ -85,6 +86,8 @@ public: : component.get()) { msElapsed += elapsed; + if (msElapsed < 0) + return true; double newProgress = msElapsed / (double) msTotal; if (newProgress >= 0 && newProgress < 1.0) @@ -243,6 +246,18 @@ void ComponentAnimator::animateComponent (Component* const component, const bool useProxyComponent, const double startSpeed, const double endSpeed) +{ + animateComponent(component, finalBounds, finalAlpha, 0, millisecondsToSpendMoving, useProxyComponent, startSpeed, endSpeed); +} + +void ComponentAnimator::animateComponent (Component* const component, + const Rectangle& finalBounds, + const float finalAlpha, + const int millisecondsBeforeStartMoving, + const int millisecondsToSpendMoving, + const bool useProxyComponent, + const double startSpeed, + const double endSpeed) { // the speeds must be 0 or greater! jassert (startSpeed >= 0 && endSpeed >= 0); @@ -258,7 +273,8 @@ void ComponentAnimator::animateComponent (Component* const component, sendChangeMessage(); } - at->reset (finalBounds, finalAlpha, millisecondsToSpendMoving, + at->reset (finalBounds, finalAlpha, + millisecondsBeforeStartMoving, millisecondsToSpendMoving, useProxyComponent, startSpeed, endSpeed); if (! isTimerRunning()) diff --git a/modules/juce_gui_basics/layout/juce_ComponentAnimator.h b/modules/juce_gui_basics/layout/juce_ComponentAnimator.h index e8a0f04b14..69d5ce0fe3 100644 --- a/modules/juce_gui_basics/layout/juce_ComponentAnimator.h +++ b/modules/juce_gui_basics/layout/juce_ComponentAnimator.h @@ -113,6 +113,50 @@ public: bool useProxyComponent, double startSpeed, double endSpeed); + + //============================================================================== + /** Starts a component moving from its current position to a specified position. + + If the component is already in the middle of an animation, that will be abandoned, + and a new animation will begin, moving the component from its current location. + + The start and end speed parameters let you apply some acceleration to the component's + movement. + + @param component the component to move + @param finalBounds the destination bounds to which the component should move. To leave the + component in the same place, just pass component->getBounds() for this value + @param finalAlpha the alpha value that the component should have at the end of the animation + @param delayBeforeAnimationMilliseconds how long the animation should wait before start, in milliseconds + @param animationDurationMilliseconds how long the animation should last, in milliseconds + @param useProxyComponent if true, this means the component should be replaced by an internally + managed temporary component which is a snapshot of the original component. + This avoids the component having to paint itself as it moves, so may + be more efficient. This option also allows you to delete the original + component immediately after starting the animation, because the animation + can proceed without it. If you use a proxy, the original component will be + made invisible by this call, and then will become visible again at the end + of the animation. It'll also mean that the proxy component will be temporarily + added to the component's parent, so avoid it if this might confuse the parent + component, or if there's a chance the parent might decide to delete its children. + @param startSpeed a value to indicate the relative start speed of the animation. If this is 0, + the component will start by accelerating from rest; higher values mean that it + will have an initial speed greater than zero. If the value is greater than 1, it + will decelerate towards the middle of its journey. To move the component at a + constant rate for its entire animation, set both the start and end speeds to 1.0 + @param endSpeed a relative speed at which the component should be moving when the animation finishes. + If this is 0, the component will decelerate to a standstill at its final position; + higher values mean the component will still be moving when it stops. To move the component + at a constant rate for its entire animation, set both the start and end speeds to 1.0 + */ + void animateComponent (Component* component, + const Rectangle& finalBounds, + float finalAlpha, + int delayBeforeAnimationMilliseconds, + int animationDurationMilliseconds, + bool useProxyComponent, + double startSpeed, + double endSpeed); /** Begins a fade-out of this components alpha level. This is a quick way of invoking animateComponent() with a target alpha value of 0.0f, using