1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

Improvement to support simplest sequential animations

- added a delay before animation start which provides a possibility to make a simple sequential animation. Moreover it gives an opportunity to animate the second comoponent in the middle of the first component animation
This commit is contained in:
Volodymyr Bagriy 2021-01-05 11:51:35 +02:00
parent 7c797c8105
commit d7416fab70
2 changed files with 62 additions and 2 deletions

View file

@ -38,11 +38,12 @@ public:
void reset (const Rectangle<int>& 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;
@ -76,6 +77,8 @@ public:
: component.get())
{
msElapsed += elapsed;
if (msElapsed < 0)
return true;
double newProgress = msElapsed / (double) msTotal;
if (newProgress >= 0 && newProgress < 1.0)
@ -229,6 +232,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<int>& 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);
@ -244,7 +259,8 @@ void ComponentAnimator::animateComponent (Component* const component,
sendChangeMessage();
}
at->reset (finalBounds, finalAlpha, millisecondsToSpendMoving,
at->reset (finalBounds, finalAlpha,
millisecondsBeforeStartMoving, millisecondsToSpendMoving,
useProxyComponent, startSpeed, endSpeed);
if (! isTimerRunning())

View file

@ -101,6 +101,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<int>& 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