(include "sci.sh")
(use "Main")
(use "Obj")
(script 933)



(class PseudoMouse of Code
    (properties
        cursorInc 2
        minInc 2
        maxInc 20
        prevDir 0
        joyInc 5
    )

    (method (doit)
        (var gPEventX, gPEventY)
        = gPEventX (send gPEvent:x)
        = gPEventY (send gPEvent:y)
        (switch (prevDir)
            (case 1
                (= gPEventY (- gPEventY cursorInc)  )
            )
            (case 2
                (= gPEventX (+ gPEventX cursorInc) = gPEventY (- gPEventY cursorInc)  )
            )
            (case 3
                (= gPEventX (+ gPEventX cursorInc)  )
            )
            (case 4
                (= gPEventX (+ gPEventX cursorInc) = gPEventY (+ gPEventY cursorInc)  )
            )
            (case 5
                (= gPEventY (+ gPEventY cursorInc)  )
            )
            (case 6
                (= gPEventX (- gPEventX cursorInc) = gPEventY (+ gPEventY cursorInc)  )
            )
            (case 7
                (= gPEventX (- gPEventX cursorInc)  )
            )
            (case 8
                (= gPEventX (- gPEventX cursorInc) = gPEventY (- gPEventY cursorInc) )
            )
        )
        (send gSQ5:setCursor(gSaveCursor 1 gPEventX gPEventY))
    )


    (method (handleEvent pEvent)
        (var pEventType, pEventMessage, pEventModifiers)
        = pEventType (send pEvent:type)
        = pEventMessage (send pEvent:message)
        = pEventModifiers (send pEvent:modifiers)
        (if (& pEventType $0040)
            = prevDir pEventMessage
            = cursorInc 
                (if (& pEventType $0004)
                    (if (& pEventModifiers $0003)
                        minInc
                    )(else
                        maxInc
                    )
                )(else
                    joyInc
                )
            (if (& pEventType $0004)
                (if (prevDir)
                    (self:doit())
                )(else
                    (send pEvent:claimed(0))
                    return 
                )
            )(else
                (if (prevDir)
                    (self:start())
                )(else
                    (self:stop())
                )
            )
            (send pEvent:claimed(1))
            return 
        )
    )


    (method (start thePrevDir)
        (if (paramTotal)
            = prevDir thePrevDir
        )
        (send gTheDoits:add(self))
    )


    (method (stop)
        = prevDir 0
        (send gTheDoits:delete(self))
    )

)
