com.threerings.media.animation
Class ScaleAnimation

java.lang.Object
  extended by com.threerings.media.AbstractMedia
      extended by com.threerings.media.animation.Animation
          extended by com.threerings.media.animation.ScaleAnimation
All Implemented Interfaces:
Shape

public class ScaleAnimation
extends Animation

Animates an image changing size about its center point.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.threerings.media.animation.Animation
Animation.AnimCompletedOp, Animation.AnimStartedOp
 
Field Summary
protected  BufferedImage _bufferedImage
          The image converted to a format Graphics2D likes, and cached.
protected  Point _center
          The center pixel to render the image around.
protected  float _endScale
          The amount to scale the image at the end of the animation.
protected  Mirage _image
          The image to scale.
protected  float _scale
          The current amount of scaling to render.
protected  TimeFunction _scaleFunc
          Computes the image scaling to use at the specified time.
protected  float _startScale
          The amount to scale the image at the start of the animation.
 
Fields inherited from class com.threerings.media.animation.Animation
_finished
 
Fields inherited from class com.threerings.media.AbstractMedia
_bounds, _firstTick, _mgr, _observers, _renderOrder, HUD_LAYER
 
Constructor Summary
ScaleAnimation(Mirage image, Point center, float startScale, float endScale, int duration)
          Creates a scale animation with the supplied image.
 
Method Summary
 void fastForward(long timeDelta)
          Called when the appropriate media manager has been paused for some length of time and is then unpaused.
 Rectangle getBounds()
          Returns a rectangle containing all the pixels rendered by this media.
static Rectangle getBounds(float scale, Point center, Mirage image)
          Java wants the first call in a constructor to be super() if it exists at all, so we have to trick it with this function.
static Point getCorner(Point center, Point size)
          Computes the upper left corner where the image should be drawn, given the center and dimensions to which the image should be scaled.
static Point getSize(float scale, Mirage image)
          Computes the width and height to which an image should be scaled.
 void paint(Graphics2D gfx)
          Called by the appropriate manager to request that the media render itself with the given graphics context.
 void tick(long tickStamp)
          Called periodically by this media's manager to give it a chance to do its thing.
 
Methods inherited from class com.threerings.media.animation.Animation
addAnimationObserver, didFinish, isFinished, removeAnimationObserver, reset, setLocation, willFinish, willStart
 
Methods inherited from class com.threerings.media.AbstractMedia
addObserver, contains, contains, contains, contains, getBounds2D, getPathIterator, getPathIterator, getRenderOrder, init, init, intersects, intersects, invalidate, invalidateAfterChange, naturalCompareTo, queueNotification, removeObserver, renderCompareTo, setRenderOrder, shutdown, toString, toString, viewLocationDidChange
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_image

protected Mirage _image
The image to scale.


_bufferedImage

protected BufferedImage _bufferedImage
The image converted to a format Graphics2D likes, and cached.


_center

protected Point _center
The center pixel to render the image around.


_startScale

protected float _startScale
The amount to scale the image at the start of the animation.


_endScale

protected float _endScale
The amount to scale the image at the end of the animation.


_scale

protected float _scale
The current amount of scaling to render.


_scaleFunc

protected TimeFunction _scaleFunc
Computes the image scaling to use at the specified time.

Constructor Detail

ScaleAnimation

public ScaleAnimation(Mirage image,
                      Point center,
                      float startScale,
                      float endScale,
                      int duration)
Creates a scale animation with the supplied image. If the image's size would ever be 0 or less, it is not drawn.

Parameters:
image - The image to paint.
center - The screen coordinates of the pixel upon which the image's center should always be rendered.
startScale - The amount to scale the image when it is rendered at time 0.
endScale - The amount to scale the image at the final frame of animation.
duration - The time in milliseconds the anim takes to complete.
Method Detail

getBounds

public static Rectangle getBounds(float scale,
                                  Point center,
                                  Mirage image)
Java wants the first call in a constructor to be super() if it exists at all, so we have to trick it with this function. Oh, and this function computes how big the bounding box needs to be to bound the inputted image scaled to the inputted size centered around the inputted center point.


getBounds

public Rectangle getBounds()
Description copied from class: AbstractMedia
Returns a rectangle containing all the pixels rendered by this media.

Specified by:
getBounds in interface Shape
Overrides:
getBounds in class AbstractMedia

getSize

public static Point getSize(float scale,
                            Mirage image)
Computes the width and height to which an image should be scaled.


getCorner

public static Point getCorner(Point center,
                              Point size)
Computes the upper left corner where the image should be drawn, given the center and dimensions to which the image should be scaled.


tick

public void tick(long tickStamp)
Description copied from class: AbstractMedia
Called periodically by this media's manager to give it a chance to do its thing.

Specified by:
tick in class AbstractMedia
Parameters:
tickStamp - a time stamp associated with this tick. Note: this is not obtained from a call to System.currentTimeMillis() and cannot be compared to timestamps obtained there from.

fastForward

public void fastForward(long timeDelta)
Description copied from class: AbstractMedia
Called when the appropriate media manager has been paused for some length of time and is then unpaused. Media should adjust any time stamps that are maintained internally forward by the delta so that time maintains the illusion of flowing smoothly forward.

Overrides:
fastForward in class AbstractMedia

paint

public void paint(Graphics2D gfx)
Description copied from class: AbstractMedia
Called by the appropriate manager to request that the media render itself with the given graphics context. The media may wish to inspect the clipping region that has been set on the graphics context to render itself more efficiently. This method will only be called after it has been established that this media's bounds intersect the clipping region.

Specified by:
paint in class AbstractMedia