Package edu.umd.cs.piccolo.activities
Class PInterpolatingActivity
java.lang.Object
edu.umd.cs.piccolo.activities.PActivity
edu.umd.cs.piccolo.activities.PInterpolatingActivity
- Direct Known Subclasses:
PColorActivity,PTransformActivity
PInterpolatingActivity interpolates between two states (source and
destination) over the duration of the activity. The interpolation can be
either linear or slow- in, slow-out.
The mode determines how the activity interpolates between the two states. The default mode interpolates from source to destination, but you can also go from destination to source, and from source to destination to source.
A loopCount of greater then one will make the activity reschedule itself when it has finished. This makes the activity loop between the two states.
- Version:
- 1.0
- Author:
- Jesse Grosjean
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.umd.cs.piccolo.activities.PActivity
PActivity.PActivityDelegate -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intSpecifies that interpolation will be from the destination value to the source value.static final intSpecifies that interpolation will be from the source value to the destination value.static final intSpecifies that interpolation proceed from the source to the destination then back to the source.Fields inherited from class edu.umd.cs.piccolo.activities.PActivity
TERMINATE_AND_FINISH, TERMINATE_AND_FINISH_IF_STEPPING, TERMINATE_WITHOUT_FINISHING -
Constructor Summary
ConstructorsConstructorDescriptionPInterpolatingActivity(long duration) Constructs an interpolating activity that will last the duration given.PInterpolatingActivity(long duration, long stepRate) Constructs an interpolating activity that will last the duration given and will update its target at the given rate.PInterpolatingActivity(long duration, long stepRate, int loopCount, int mode) Constructs an interpolating activity that will last the duration given and will update its target at the given rate.PInterpolatingActivity(long duration, long stepRate, long startTime, int loopCount, int mode) Create a new PInterpolatingActivity. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCalled whenever the activity finishes.protected voidCalled when activity is started.protected voidactivityStep(long elapsedTime) Called at each step of the activity.floatcomputeSlowInSlowOut(float zeroToOne) Computes percent or linear interpolation to apply when taking acceleration into account.booleanReturn true if the activity is executing its first loop.intReturn the number of times the activity should automatically reschedule itself after it has finished.intgetMode()Return the mode used for interpolation.booleanReturns whether this interpolation accelerates and then decelerates as it interpolates.voidsetDuration(long duration) Set the amount of time that this activity should take to complete, after the startStepping method is called.voidsetFirstLoop(boolean firstLoop) Set if the activity is executing its first loop.voidsetLoopCount(int loopCount) Set the number of times the activity should automatically reschedule itself after it has finished.voidsetMode(int mode) Set the direction in which interpolation is going to occur.voidsetRelativeTargetValue(float zeroToOne) Subclasses should override this method and set the value on their target (the object that they are modifying) accordingly.protected voidsetRelativeTargetValueAdjustingForMode(float zeroToOne) Assigns relative target value taking the mode into account.voidsetSlowInSlowOut(boolean isSlowInSlowOut) Sets whether this interpolation accelerates and then decelerates as it interpolates.voidStop this activity immediately, and remove it from the activity scheduler.Methods inherited from class edu.umd.cs.piccolo.activities.PActivity
getActivityScheduler, getDelegate, getDuration, getNextStepTime, getStartTime, getStepRate, getStopTime, isAnimation, isStepping, paramString, processStep, setActivityScheduler, setDelegate, setStartTime, setStepRate, startAfter, terminate
-
Field Details
-
SOURCE_TO_DESTINATION
public static final int SOURCE_TO_DESTINATIONSpecifies that interpolation will be from the source value to the destination value.- See Also:
-
DESTINATION_TO_SOURCE
public static final int DESTINATION_TO_SOURCESpecifies that interpolation will be from the destination value to the source value.- See Also:
-
SOURCE_TO_DESTINATION_TO_SOURCE
public static final int SOURCE_TO_DESTINATION_TO_SOURCESpecifies that interpolation proceed from the source to the destination then back to the source. Can be used to perform flashes. source value.- See Also:
-
-
Constructor Details
-
PInterpolatingActivity
public PInterpolatingActivity(long duration) Constructs an interpolating activity that will last the duration given.- Parameters:
duration- duration in milliseconds of the entire activity- Since:
- 1.3
-
PInterpolatingActivity
public PInterpolatingActivity(long duration, long stepRate) Constructs an interpolating activity that will last the duration given and will update its target at the given rate.- Parameters:
duration- duration in milliseconds of the entire activitystepRate- interval in milliseconds between updates to target
-
PInterpolatingActivity
public PInterpolatingActivity(long duration, long stepRate, int loopCount, int mode) Constructs an interpolating activity that will last the duration given and will update its target at the given rate. Once done, it will repeat the loopCount times.- Parameters:
duration- duration in milliseconds of the entire activitystepRate- interval in milliseconds between updates to targetloopCount- # of times to repeat this activity.mode- controls the direction of the interpolation (source to destination, destination to source, or source to destination back to source)
-
PInterpolatingActivity
public PInterpolatingActivity(long duration, long stepRate, long startTime, int loopCount, int mode) Create a new PInterpolatingActivity.- Parameters:
duration- the length of one loop of the activitystepRate- the amount of time between steps of the activitystartTime- the time (relative to System.currentTimeMillis()) that this activity should start. This value can be in the future.loopCount- number of times the activity should reschedule itselfmode- defines how the activity interpolates between states
-
-
Method Details
-
setDuration
public void setDuration(long duration) Set the amount of time that this activity should take to complete, after the startStepping method is called. The duration must be greater then zero so that the interpolation value can be computed.- Overrides:
setDurationin classPActivity- Parameters:
duration- new duration of this activity
-
getMode
public int getMode()Return the mode used for interpolation. Acceptable values are: SOURCE_TO_DESTINATION, DESTINATION_TO_SOURCE and SOURCE_TO_DESTINATION_TO_SOURCE- Returns:
- current mode of this activity
-
setMode
public void setMode(int mode) Set the direction in which interpolation is going to occur. Acceptable values are: SOURCE_TO_DESTINATION, DESTINATION_TO_SOURCE and SOURCE_TO_DESTINATION_TO_SOURCE- Parameters:
mode- the new mode to use when interpolating
-
getLoopCount
public int getLoopCount()Return the number of times the activity should automatically reschedule itself after it has finished.- Returns:
- number of times to repeat this activity
-
setLoopCount
public void setLoopCount(int loopCount) Set the number of times the activity should automatically reschedule itself after it has finished.- Parameters:
loopCount- number of times to repeat this activity
-
getFirstLoop
public boolean getFirstLoop()Return true if the activity is executing its first loop. Subclasses normally initialize their source state on the first loop.- Returns:
- true if executing first loop
-
setFirstLoop
public void setFirstLoop(boolean firstLoop) Set if the activity is executing its first loop. Subclasses normally initialize their source state on the first loop. This method will rarely need to be called, unless your are reusing activities.- Parameters:
firstLoop- true if executing first loop
-
getSlowInSlowOut
public boolean getSlowInSlowOut()Returns whether this interpolation accelerates and then decelerates as it interpolates.- Returns:
- true if accelerations are being applied apply
-
setSlowInSlowOut
public void setSlowInSlowOut(boolean isSlowInSlowOut) Sets whether this interpolation accelerates and then decelerates as it interpolates.- Parameters:
isSlowInSlowOut- true if this interpolation inovolves some accelerations
-
activityStarted
protected void activityStarted()Called when activity is started. Makes sure target value is set properly for start of activity.- Overrides:
activityStartedin classPActivity
-
activityStep
protected void activityStep(long elapsedTime) Called at each step of the activity. Sets the current position taking mode into account.- Overrides:
activityStepin classPActivity- Parameters:
elapsedTime- number of milliseconds since the activity began
-
activityFinished
protected void activityFinished()Called whenever the activity finishes. Reschedules it if the value of loopCount is > 0.- Overrides:
activityFinishedin classPActivity
-
terminate
public void terminate()Stop this activity immediately, and remove it from the activity scheduler. If this activity is currently running then stoppedStepping will be called after it has been removed from the activity scheduler. -
setRelativeTargetValue
public void setRelativeTargetValue(float zeroToOne) Subclasses should override this method and set the value on their target (the object that they are modifying) accordingly.- Parameters:
zeroToOne- relative completion of task.
-
computeSlowInSlowOut
public float computeSlowInSlowOut(float zeroToOne) Computes percent or linear interpolation to apply when taking acceleration into account.- Parameters:
zeroToOne- Percentage of activity completed- Returns:
- strength of acceleration
-
setRelativeTargetValueAdjustingForMode
protected void setRelativeTargetValueAdjustingForMode(float zeroToOne) Assigns relative target value taking the mode into account.- Parameters:
zeroToOne- Percentage of activity completed
-