Making a MaxGUI Application: StripAnimMakerLite Part 4 - The Selection Cursor
(c) Assari Jan 16 2005

The selection cursor is a pre-cursor (pun intended) to our zoomed window and sprite selection capability.
The idea is to be able to select a rectangular piece of the displayed image and capture it to our animation strip.

So this part does not do much but is necessary I'm afraid. Once we are done with this tutorial, our program will be able to
Simple, but we need to add it quite a few new functionalities to enable this to happen.

New Additions to Part 1 - Variable Definitions

We need 5 new variables, Mx1 and My1 to hold our mouse x,y position on the canvas, xsize and ysize to hold the size of our cursor and a MouseInCanvas1 variable to flag whether we are in or out of the Main Canvas

    Global MouseInCanvas1:Int=True '-Flag For Mouse whereabout
Global Mx1:Int '-----------------MouseX location For Main Canvas (Canvas1)
Global My1:Int '-----------------MouseY location For Main Canvas (Canvas1)

Global xsize:Int=48 '------------width of Cursor in Canvas1
Global ysize:Int=48 '------------height of Cursor in Canvas1


New Additions to Part 2 - Gadget Creation Block

No new gadget is involved here

New Additions to Part 3 - MAIN LOOP

We need three new functions to process the Mouse Enter, Mouse Leave and Mouse Move events.

          Case EVENT_MOUSEENTER
        Process_MouseEnterEvent

      Case EVENT_MOUSELEAVE
        Process_MouseLeaveEvent
   
     Case EVENT_MOUSEMOVE
        Process_MouseMoveEvent


New Additions to Part 4 - Function Definitions

In this block we need to do the following
DrawCursor(x,y, xs,ys)

This is probably one of the simplest function that we need to write. Given the x,y coordinate of the cursor and its x,y size, we use the drawline command to draw the rectangular cursor on the canvas
    Function DrawCursor(x:Int,y:Int,xs:Int, ys:Int)

 DrawLine x,y,x+xs,y
 DrawLine x,y,x,y+ys
 DrawLine x+xs,y,x+xs,y+ys
 DrawLine x,y+ys,x+xs,y+ys

End Function


The Process EVENT_MOUSEENTER function

First we need to check that the mouse is entering the Main Canvas (Canvas1). We then hide the system cursor, set the flag to indicate that the mouse is now in canvas1, then redraw the canvas.
    Function Process_MouseEnterEvent:Int()

 Select EventSource()
    Case Canvas1
        HideMouse()
        MouseInCanvas1=True
        RedrawGadget(Canvas1)
       
 End Select

End Function



The Process EVENT_MOUSELEAVE function

This function is very similar to the above except now we again show the system cursor and then set our MouseInCanvas1 flag to false to indicate that our mouse has now left us.
    Function Process_MouseLeaveEvent:Int()

 Select EventSource()
    Case Canvas1
        ShowMouse()
        MouseInCanvas1=False
        RedrawGadget(Canvas1)
       
 End Select

End Function


The Process EVENT_MOUSEMOVE function

This is another very simple function. When a mouse move event occurs, the EventX and EventY MaxGUI function will have the mouse coordinates. We store these in our Mx1 and My1 variables

    Function Process_MouseMoveEvent:Int()

 Select EventSource()
    Case Canvas1
        mx1=EventX()
        my1=EventY()
        RedrawGadget(Canvas1)

 End Select

End Function


Function Process_GadgetPaintEvent:Int()

We now need to modify the Process_GadgetPaintEvent function to add in the code to draw our cursor.

    Function Process_GadgetPaintEvent:Int()

    SetGraphics CanvasGraphics (Canvas1)
    Cls
    DrawPixmap Pix,0,0
    If MouseInCanvas1 Then
        DrawCursor(mx1,my1,xsize, ysize)
    EndIf
    Flip

End Function


Having done all that, we can now see our rectangular cursor wheezing around our canvas following our mouse movements. Download the full source code here, compile and run to see the actual program.

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