Chapter 12. AnimatedButton Class

The AnimatedButton class provides the methods to implement an animated button within a dialog. The attributes and methods are only described briefly in this document. An example program, oowalker.rex, is provided with the OODialog sample programs.

ParentDlg

Attribute holding the handle of the parent dialog

Stopped

Animation ends when set to 1 (see Stop method)

Init

Initialize the animation parameters:

but = .AnimatedButton~new(buttonid,from,to, ,
                          movex,movey,sizex,sizey,delay, ,
                          startx,starty,parentdialog)

The values are stored in a stem variable:

sprite.buttonid

ID of animation button

sprite.from

Array of in-memory bitmap handles, or a bitmap resource ID in a DLL, or the name of an array in the .local directory containing handles to bitmaps loaded with LoadBitmap. The array has to start with 1 and continue in increments by 1.

sprite.to

0 if sprite.from is an array, or the name of an array stored in .local, or a bitmap resource ID in a DLL

sprite.movex

Size of one move horizontally (pixels)

sprite.movey

Size of one move vertically

sprite.sizex

Horizontal size of all bitmaps (pixels)

sprite.sizey

Vertical size of all bitmaps

sprite.delay

Time delay between moves (ms)

Startx and starty are the initial bitmap position, and parentdialog is stored in the ParentDlg attribute.

Two more values are initialized in the stem variable:

sprite.smooth

Set to 1 for smooth edge change (can be changed to 0 for a bouncy edge change)

sprite.step

Set to 1 as the step size between sprite.from and sprite.to for bitmaps in a DLL

SetSprite

Set all the sprite. animation values using a stem:

mysprite.from = .array~of(bmp1,bmp2,...)
mysprite.to = 0
mysprite.movex = ...
...
self~setSprite(mysprite.)

GetSprite

Retrieve the animation values into a stem:

self~getSprite(mysprite.)

SetFromTo

Set bitmap information (sprite.from and sprite.to):

self~setFromTo(bmpfrom,bmpto)

SetMove

Set size of one move (sprite.movex and sprite.movey):

self~setMove(movex,movey)

SetDelay

Set delay between moves in milliseconds (sprite.delay):

self~setDelay(delay)

SetSmooth

Set smooth (1) or bouncy (0) edges (sprite.smooth):

self~setSmooth(smooth)  /* 1 or 0 */

SetStep

Set the step size (sprite.step) between sprite.from and sprite.to for bitmaps in a DLL, for example, if bitmap resources are numbered 202, 204, 206, etc:

self~setFromTo(202,210)
self~setStep(2)

Run

Run the animation by going through all the bitmaps repetitively until dialog is stopped; invokes MoveSeq:

self~run

MoveSeq

Animate one sequence through all the bitmaps in the given move steps; invokes MovePos:

self~moveSeq

MovePos

Move the bitmaps by the arguments:

self~movePos(movex,movey)

MoveTo

Move the bitmaps in the predefined steps to the given position; invokes MoveSeq:

self~moveTo(posx,posy)

SetPos

Set the new starting position of the bitmaps:

self~setPos(newx,newy)

GetPos

Retrieve the current position into a stem:

self~getPos(pos.)
say "pos=" pos.x pos.y

ParentStopped

Check the parent dialog window and return its finished attribute (1 means finished)

Stop

Stop animation by setting the stopped attribute to 1

HitRight

Invoked by run when the bitmap hits the right edge (returns 1 and bitmap starts at left again; you can return 0 and set the new position yourself)

HitLeft

Invoked when the bitmap hits the left edge (default action is to start at right again)

HitBottom

Invoked when the bitmap hits the bottom edge (default action is to start at top again)

HitTop

Invoked when the bitmap hits the top edge (default action is to start at bottom again)

To use an animated button a dialog has to:

The dialog may also dynamically change the parameters (for example, the size of a move, or the speed) and override actions, such as hitting an edge.

See the oowalker.rex and oowalk2.rex examples in OODIALOG\SAMPLES.

For further information see ConnectAnimatedButton.