Making a MaxGUI Application: StripAnimMakerLite Part 9 - Previewing Animations
(c) Assari Jan 29 2006

Now that we can capture a series of images onto our Animation Strip, lets add the capaility to preview the animation.

For now the animations will be displayed whenever we move the mouse  outside the  main canvas  (provided we have some images in the Animation Strip of course)

New Additions to Part 1 - Variable Definitions

We need three new variables; The first one to indicate the status of our animation AnimFlag (true or false) and the other, to hold the speed of our animation, AnimFrequency, which we are defaulting to 5. The last variable we need is AnimFrame, to hold the current frame to display
    Global AnimFlag:Int=True '----Animation Flag
Global AnimFrequency:Int=5
Global AnimFrame:Int=0


New Additions to Part 2 - Gadget Creation Block

We need to add a new gadget, the timer gadget
    '==========================================================
'GADGET CREATION BLOCK
'==========================================================

'Main Window and Main Canvas
CreateMainWindow(800,600)

'Create the required Canvases
CreateCanvases()

'Create Required Menus
CreateMenus()

'--------------------------------------------------------
'Create Vertical and Horizontal Scrollers for Main Canvas
'--------------------------------------------------------
CreateScrollers()

'--------------------------------------------------------
'load Image for Canvas
LoadCanvasImage("1945.bmp")

Local AnimTimer:TTimer=CreateTimer(AnimFrequency)



New Additions to Part 3 - MAIN LOOP

We also need to add a new Process_TimerTickEvent function to handle the event triggered by our AnimTimer
        Case EVENT_TIMERTICK
        Process_TimerTickEvent



New Additions to Part 4 - Function Definitions

In this block we need to do the following
Function Process_TimerTickEvent()

The timertick event is going to happen once every 1/5 secs, we will only perform the animation if the mouse is not in the main canvas and the Animation flag is true
    Function Process_TimerTickEvent:Int()

     If AnimFlag=True And MouseInCanvas1=False
        AnimFrame:Int=AnimFrame+1
        If AnimFrame>=AnimList.Count() Then AnimFrame=0
        RedrawGadget(canvas2)
     EndIf

End Function


Function Process_GadgetPaintEvent

When the above timertick event function finishes, the Redrawgadget(canvas2) statement at the end of the above timertick event fucntion will cause the gadgetpaint event to be triggered.

We need to modify the GadgetPaintEvent function to add the case to call the DisplayAnim Function when the mouse is not in the main canvas and the animation flag is set to true.
        Case Canvas2
        SetGraphics CanvasGraphics(Canvas2)
        Cls
        If MouseInCanvas1=True Then
            If CursorResize=False Then DrawPixUnderCursor(Canvas2,Pix,mx1,my1)
            If CursorResize=True Then DrawPixUnderCursor(Canvas2,Pix,mx1_Old,my1_Old)
        Else
            If AnimFlag=True Then DisplayAnim(AnimFrame:Int)
        EndIf
        Flip


  

Function DisplayAnim

The DisplayAnim function will draw on Canvas2 each and every pixmap in the Animation Strip.
    Function DisplayAnim:Int(i:Int)
 
  If CountList(AnimList)>0
    Local XOffset:Int=(128-AnimSize)/2
    Local YOffset:Int=(128-AnimSize)/2
    DrawPixmap TPixmap(AnimList.ValueAtIndex(i)),XOffset,YOffset
  EndIf

End Function

So that is all we need to do to get the preview animation going. Download the source here, capture some images to the Animation Strip and move the cursor outside the Main Canvas to see the animation.
  

That's all for now. Return to Main Index.