superwaba.ext.xplat.game
Class Animation

java.lang.Object
  |
  +--waba.ui.Control
        |
        +--superwaba.ext.xplat.game.Animation
Direct Known Subclasses:
AnimatedButton

public class Animation
extends Control

The Animation control class.

 This control displays an animation that can be loaded from indexed BMP files
 (one frame per image) or by a multi-frames BMP. This kind of BMP file contains a
 list of images having all the same size and that lay side by side.
 You may use the MakeMultiBmp in /superwaba/utils/xplat/MakeMultiBmp folder to
 convert animated gif or a sequence of bmp files into the convenient format.

 warning: multi-frames BMP files can't be larger than 64Kb (the palmOS record limit)
 

See Also:
superwaba.tools.makemultibmp.MakeMultiBmp

Field Summary
protected  Image background
          Background image.
protected  Graphics bgGfx
          Background graphic context.
protected  int curFrame
          Current frame of the animation.
 int drawOp
          drawOp drawing operation used when the animation images are copied to the screen buffer.
static int eventFinish
          notify animation endings
static int eventFrame
          notify animation frames
static int eventLoop
          notify animation loops
static int eventNone
          no notify at all
protected  int eventsMask
          Event notification mask, default value is eventFinish, that means that an event is posted only when the animation finishes.
 int framePeriod
          Delay between two frames.
protected  Image[] framesBuffer
          Frames buffer, all frames must have the same size.
protected  int insert
           
 boolean isPaused
          Reflects the animation pause state.
 boolean isPlaying
          Reflects the animation play state.
static int LOOPS_UNLIMITED
          start function "loops" argument special value to loop endlessly
protected  int maxFrames
          Maximum number of frames.
protected  Color transColor
          Transparency color.
 
Fields inherited from class waba.ui.Control
AFTER, appId, appObj, asContainer, asWindow, backColor, backDis, BEFORE, BOTTOM, CENTER, clearValueInt, clearValueStr, enabled, FILL, FIT, fm, fmH, focusLess, focusTraversable, font, foreColor, foreDis, height, highlightRectsCount, isHighlighting, LEFT, parent, PREFERRED, RANGE, RIGHT, SAME, TOP, uiCE, uiFlat, uiPalm, uiVista, visible, width, x, x2, y, y2
 
Constructor Summary
protected Animation()
          Animation constructor.
  Animation(Image frames, int frameWidth, Color transColor, int framePeriod)
          Animation constructor.
 
Method Summary
 void drawFrame(int frame)
          Display a given frame.
 void enableEvents(int mask)
          Enable the posting of events.
 int getPreferredHeight()
          Returns the prefered height of this control.
 int getPreferredWidth()
          Returns the prefered width of this control.
 void onPaint(Graphics gfx)
          Called by the system to draw the animation.
 void pause()
          Pauses a running animation. if the application is not playing, this call has no effect.
 void renew(int maxFrames)
          Clear the animation to add new frames.
 void resume()
          Resumes a paused animation. if the application is not playing, this call has no effect.
 int size()
          Number of frames in the animation.
static Image[] splitImage(Image original, int frameWidth)
          This is a static helper function that divides a multi-frames BMP into distinguished Images.
The original image size should be a multiple of the frame width.
 void start(int loops)
          Starts the animation.
 void start(int[] frameSequence, int loops)
          Starts the animation with a non standard frame sequence.
 void start(int sFrame, int eFrame, int step, int loops)
          Starts the animation with a frame range.
 void stop()
          Stops the animation. if the application is not playing, this call has no effect.
 
Methods inherited from class waba.ui.Control
addTimer, changeHighlighted, clear, contains, createGraphics, drawHighlight, getAbsoluteRect, getBackColor, getFont, getFontMetrics, getForeColor, getNext, getParent, getParentWindow, getPos, getRect, getSize, isDisplayed, isEnabled, isVisible, onBoundsChanged, onColorsChanged, onEvent, onFontChanged, onWindowPaintFinished, postEvent, removeTimer, repaint, repaintNow, requestFocus, setBackColor, setBackForeColors, setEnabled, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setVisible, translateFromOrigin, uiStyleChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

drawOp

public int drawOp
drawOp drawing operation used when the animation images are copied to the screen buffer.
See Also:
Graphics

framePeriod

public int framePeriod
Delay between two frames.

curFrame

protected int curFrame
Current frame of the animation.

isPlaying

public boolean isPlaying
Reflects the animation play state.

isPaused

public boolean isPaused
Reflects the animation pause state.

transColor

protected Color transColor
Transparency color.

maxFrames

protected int maxFrames
Maximum number of frames.

framesBuffer

protected Image[] framesBuffer
Frames buffer, all frames must have the same size.

insert

protected int insert

eventsMask

protected int eventsMask
Event notification mask, default value is eventFinish, that means that an event is posted only when the animation finishes.

eventNone

public static final int eventNone
no notify at all

eventFinish

public static final int eventFinish
notify animation endings

eventLoop

public static final int eventLoop
notify animation loops

eventFrame

public static final int eventFrame
notify animation frames

LOOPS_UNLIMITED

public static final int LOOPS_UNLIMITED
start function "loops" argument special value to loop endlessly

background

protected Image background
Background image.

bgGfx

protected Graphics bgGfx
Background graphic context.
Constructor Detail

Animation

protected Animation()
Animation constructor. This constructor may be used by deriving classes.

Animation

public Animation(Image frames,
                 int frameWidth,
                 Color transColor,
                 int framePeriod)
Animation constructor.
Parameters:
frames - single image containing all frames in mlti-frames BMP format.
frameWidth - width in pixels of one frame.
transColor - the transparency color
framePeriod - delay in millisecconds between two frames
See Also:
superwaba.tools.makemultibmp.MakeMultiBmp
Method Detail

renew

public void renew(int maxFrames)
           throws GameEngineException
Clear the animation to add new frames.

size

public int size()
Number of frames in the animation.
Returns:
frames amount

getPreferredWidth

public int getPreferredWidth()
Returns the prefered width of this control.
Overrides:
getPreferredWidth in class Control

getPreferredHeight

public int getPreferredHeight()
Returns the prefered height of this control.
Overrides:
getPreferredHeight in class Control

drawFrame

public void drawFrame(int frame)
Display a given frame.
Parameters:
frame - index to display.

onPaint

public void onPaint(Graphics gfx)
Called by the system to draw the animation.
Overrides:
onPaint in class Control
Tags copied from class: Control
Parameters:
g - the graphics object for drawing
See Also:
Graphics

enableEvents

public void enableEvents(int mask)
Enable the posting of events. By default the posting of events are disabled.

pause

public void pause()
Pauses a running animation. if the application is not playing, this call has no effect.

resume

public void resume()
Resumes a paused animation. if the application is not playing, this call has no effect.

stop

public void stop()
Stops the animation. if the application is not playing, this call has no effect.

start

public void start(int sFrame,
                  int eFrame,
                  int step,
                  int loops)
Starts the animation with a frame range. This function starts an animation by specifying the frame range and a loop flag. If the application is playing, this call has no effect.
Parameters:
sFrame - start frame
eFrame - end frame
step - frame increment
loops - number of animation iterations

start

public void start(int loops)
Starts the animation. This function starts the animation and loops the specified amount of time. If the application is playing, this call has no effect.
Parameters:
loops - integer value specifying the number of loops or LOOPS_UNLIMITED.
See Also:
LOOPS_UNLIMITED

start

public void start(int[] frameSequence,
                  int loops)
Starts the animation with a non standard frame sequence. You can provide a different frame sequence than the standard 0,1,2,3,4..n frame order. Use this function when you have an animation that has some identical frames. In such case, just keep one unique frame and recreate the original frame sequence by referencing the originaly identical frames several times. If the application is playing, this call has no effect.
Parameters:
frameSequence - frame numbers array which defines the frames sequence
loops - integer value specifying the number of loops or LOOPS_UNLIMITED.
See Also:
LOOPS_UNLIMITED

splitImage

public static Image[] splitImage(Image original,
                                 int frameWidth)
This is a static helper function that divides a multi-frames BMP into distinguished Images.
The original image size should be a multiple of the frame width.
Parameters:
original - multi-frames image.
frameWidth - the width of a single frame.
Returns:
An array of images.