Making a MaxGUI Application: StripAnimMakerLite Part 6 - Adding a Resizable Cursor
(c) Assari Jan 16 2005

The next bit of functionality we want to add is the ability to resize our cursor. For the moment, all our user interaction will be via the mouse.

We will now introduce two modes

  1. A normal mode where moving the mouse moves the cursor
  2. A resize mode where moving the mouse will change the size of the cursor accordingly
The mode change will be toggled via a left mouse click, one click to goto resize mode and another click to revert to normal mode

New Additions to Part 1 - Variable Definitions

We will need several new varibles. mx1a and my1a will monitor our mouse positions while in resize mode. mx1_old and my1_old will remember our cursor position when we entered resize mode and xsize_old and ysize_old retains our cursor size when we entered resize mode.

We also need to restrict our cursor so that the user does not get overboard with the size. We are going to set the max to 128

The variable CursorResize is the flag for us to indicate what mode we are in.

    Global mx1a:Int, my1a:Int
Global mx1_old:Int, my1_old:Int
Global xsize_old:Int, ysize_old:Int
Global MaxCursorSize:Int=128
Global CursorResize:int=false

New Additions to Part 2 - Gadget Creation Block

No changes required for this block :)

New Additions to Part 3 - MAIN LOOP

We need to process the mouse down event to catch when the user clicks the left mouse button

        Case EVENT_MOUSEDOWN
        Process_MouseDownEvent


New Additions to Part 4 - Function Definitions

In this block we need to do the following
Process Mouse Down Event

If the mouse click event came from our Main Canvas and it was a left click, we will react based on what mode we are in.
    Function Process_MouseDownvent: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 xsize>MaxCursorSize Then xsize=MaxCursorSize
                        MoveMouse(mx1_Old,my1_Old)
                    EndIf
               End Select 'eventdata() 
       RedrawGadget(Canvas1)
    End Select 'eventsource()

End Function



    Function Process_GadgetPaintEvent:Int()

    Select EventSource()
    Case Canvas1
        SetGraphics CanvasGraphics (Canvas1)
        Cls
        DrawPixmap Pix,0,0
        If MouseInCanvas1 Then
            DrawCursor(mx1,my1,xsize, ysize)
            If CursorResize=True
                SetColor 255,0,0
                DrawCursor(mx1_old,my1_old,xsize_old, ysize_old)
                SetColor 0,0,0
            EndIf
            RedrawGadget(Canvas2)
        EndIf
        Flip

    Case Canvas2
        SetGraphics CanvasGraphics(Canvas2)
        Cls
        If MouseInCanvas1=True Then
            If CursorResize=False Then
                DrawPixUnderCursor(Canvas2,Pix,mx1,my1)

            Else
                DrawPixUnderCursor(Canvas2,Pix,mx1_Old,my1_Old)

            EndIf
        EndIf
        Flip
      
    End Select 'EventSource()

End Function

Our Process_MouseMoveEvent function now needs to know about the CursorResize mode and act accordingly.
    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)

 End Select

End Function


We also need to Modify the Process_MouseEnterEvent function to ensure we are always not in CursorResize mode when entering the canvas.
    Function Process_MouseEnterEvent:Int()

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

End Function


Download source code here. That's all for now. Return to Main Index.