Skip to content
Permalink
Browse files

8237975: Non-embedded Animations do not play backwards after being pa…

…used

Reviewed-by: kcr, arapte
  • Loading branch information
Nir Lisker
Nir Lisker committed Feb 3, 2020
1 parent 2ab40c1 commit 1749e8547aea5f666229c9b7c0ab22ec5e1558dd
@@ -110,6 +110,10 @@ public void abortCurrentPulse() {

protected abstract double calculateCurrentRate();

protected void setInternalCurrentRate(double currentRate) {
this.currentRate = currentRate;
}

protected void setCurrentRate(double currentRate) {
this.currentRate = currentRate;
AnimationAccessor.getDefault().setCurrentRate(animation, currentRate);
@@ -82,9 +82,7 @@ public void setRate(double rate) {
final long newTicks = toggled? totalTicks - ticks : ticks;
final Status status = animation.getStatus();
if (status != Status.STOPPED) {
if (status == Status.RUNNING) {
setCurrentRate((Math.abs(currentRate - this.rate) < EPSILON) ? rate : -rate);
}
setInternalCurrentRate((Math.abs(currentRate - this.rate) < EPSILON) ? rate : -rate);
deltaTicks = newTicks - Math.round((ticks - deltaTicks) * Math.abs(rate / this.rate));
abortCurrentPulse();
}
@@ -70,9 +70,7 @@ public ClipEnvelope setCycleCount(int cycleCount) {
public void setRate(double rate) {
final Status status = animation.getStatus();
if (status != Status.STOPPED) {
if (status == Status.RUNNING) {
setCurrentRate((Math.abs(currentRate - this.rate) < EPSILON) ? rate : -rate);
}
setInternalCurrentRate((Math.abs(currentRate - this.rate) < EPSILON) ? rate : -rate);
deltaTicks = ticks - Math.round((ticks - deltaTicks) * Math.abs(rate / this.rate));
if (rate * this.rate < 0) {
final long delta = 2 * cycleTicks - pos;
@@ -37,9 +37,7 @@
public void setRate(double rate) {
final Status status = animation.getStatus();
if (status != Status.STOPPED) {
if (status == Status.RUNNING) {
setCurrentRate((Math.abs(currentRate - this.rate) < EPSILON) ? rate : -rate);
}
setInternalCurrentRate((Math.abs(currentRate - this.rate) < EPSILON) ? rate : -rate);
deltaTicks = ticks - Math.round((ticks - deltaTicks) * rate / this.rate);
abortCurrentPulse();
}
@@ -32,4 +32,7 @@ public SingleLoopClipEnvelopeShim(Animation animation) {
super(animation);
}

public long getTicks() {
return ticks;
}
}
@@ -48,6 +48,10 @@ public ClipEnvelope get_clipEnvelope() {
return clipEnvelope;
}

public void setClipEnvelope(ClipEnvelope clipEnvelope) {
this.clipEnvelope= clipEnvelope;
}

@Override
public void doPause() {
super.doPause();
@@ -32,6 +32,8 @@
import org.junit.Before;
import org.junit.Test;

import com.sun.scenario.animation.shared.SingleLoopClipEnvelopeShim;

import static org.junit.Assert.*;

public class AnimationSetRateTest {
@@ -371,4 +373,22 @@ public void testSetRateToZeroForPausedAnimation() {
animation.play();
assertAnimation(0.5, -0.5, Status.RUNNING, true);
}

@Test
public void testFlipRateAndPlayForPausedNonEmbeddedAnimation() {
var clip = new SingleLoopClipEnvelopeShim(animation);
animation.setClipEnvelope(clip);
animation.setRate(0.2);
animation.play();
clip.timePulse(10);
animation.pause();
long timeBefore = clip.getTicks();
animation.setRate(-0.2);
animation.play();
clip.timePulse(5);
animation.pause();
long timeAfter = clip.getTicks();
assertEquals("A pulse to 10 at rate 0.2 with deltaTicks = 0 should reach 10 * 0.2 = 2", 2, timeBefore);
assertEquals("A pulse to 5 at rate -0.2 with deltaTicks = 4 should reach 4 + 5 * (-0.2) = 3", 3, timeAfter);
}
}

0 comments on commit 1749e85

Please sign in to comment.
You can’t perform that action at this time.