Making a MaxGUI Application: StripAnimMakerLite Part 10 - Selecting an Animation Frame
(c) Assari Feb 5 2006

The next set of functionalities we are going to add are the abilities to select a frame on the Animation Strip, insert a new image after the selected frame , Cut and Paste frames at desired location on the Animation Strip.

Let us  first  put in the ability to  select a frame

New Additions to Part 1 - Variable Definitions

We need to know the mouse position on our Animation Strip. So we need to define Mx3 and My3 integer variables to do this.
    Global Mx3:Int, My3:Int '-----Mouse location on Canvas3

New Additions to Part 2 - Gadget Creation Block

We do not need any new gadget

New Additions to Part 3 - MAIN LOOP

We do not need anything new here

New Additions to Part 4 - Function Definitions

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

We need to add in the case statement to check for mouse movements on Canvas3, our Animation Strip canvas, and then store the mouse coordinates in the Mx3 and My3 variables
    Function Process_MouseMoveEvent:Int()

 Select EventSource()
    Case Canvas1
    If CursorResize=False
        mx1=EventX()
        my1=EventY()
    Else
        mx1a=EventX()
        my1a=EventY()
        xsize=EventX()-mx1_Old
        ysize=EventY()-my1_Old
    EndIf
    RedrawGadget(Canvas1)

    Case Canvas3
      mx3:Int=EventX()
      my3:Int=EventY()

 End Select

End Function


Function Process_MouseDownEvent

Once we receive a mousedown event from Canvas3, we then call the SelectFrame function to select it.
    Function Process_MouseDownEvent:Int()

    Select EventSource()
        Case Canvas1
               Select EventData()
                   Case MOUSE_LEFT
                    If CursorResize=False 'We are not normal mode
                          CursorResize=True    'user click left mouse
                        xsize_old=xsize
                        ysize_old=ysize
                          mx1_Old=mx1
                          my1_Old=my1
                          MoveMouse(mx1+xsize,my1+ysize)
                    Else 'We are in change size mode, so back out
                          CursorResize=False       
                        xsize=mx1a-mx1_Old
                          ysize=my1a-my1_Old
                        If xsize>MaxCursorSize Then xsize=MaxCursorSize
                        If ysize>MaxCursorSize Then ysize=MaxCursorSize
                          MoveMouse(mx1_Old,my1_Old)
                    EndIf
                Case MOUSE_RIGHT
                    CopyPixUnderCursorToAnimStrip()

            End Select
            RedrawGadget(Canvas1)
       
        Case Canvas3 'From Animstrip
            Select EventData()
                Case MOUSE_LEFT
                       SelectFrame()
               End Select
            RedrawGadget(Canvas3)
       
    End Select 'eventsource()

End Function



Function SelectFrame()

A fairly simple function. Just need to check that the mouse is within our frames with images then find the link which corresponds to this image

    Function SelectFrame:Int()

    If CountList(AnimList)=0 Then Return -1
    Local i:Int=Int(mx3/AnimSize)
    If i<CountList(AnimList) Then
        Local tmp:TPixmap=TPixmap(AnimList.ValueAtIndex(i))
        AnimListPtr=ListFindLink(AnimList,Tmp)
        RedrawGadget(Canvas3)
    EndIf
   
End Function

Function Process_GadgetPaintEvent

We want to be able to highlight the selected frame by having a different color for it.
        Case Canvas3
        SetGraphics CanvasGraphics(Canvas3)
        Cls
        If AnimListPtr<>Null Then
            Local j:Int=0
            For Local p:TPixMap=EachIn AnimList
                Local YOffset:Int=(AnimSize-PixmapHeight(p))/2
                Local XOffset:Int=(AnimSize-PixmapWidth(p))/2
                DrawPixmap p,j*AnimSize+XOffset,YOffset
                If p = (TPixmap(AnimListPtr.Value()))
                     SetColor 255,0,0
                Else
                    SetColor 255,255,255
                EndIf
                DrawCursor(j*AnimSize,0,AnimSize,AnimSize)
                j=j+1
            Next
        EndIf
        Flip


There we go, a fairly relaxed tutorial to set the scene for the next stage, which is adding all the functionalities that this part has made possible.

The source code can be downloaded here.

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