(include "sci.sh")
(use "Main")
(use "User")
(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 gGame:setCursor(global19 1 gPEventX gPEventY))
    )


    (method (handleEvent pEvent)
        (if ((User:canInput()) and (& (send pEvent:type) $0040))
            = prevDir 
                (if (not gIconBar or (<> (send ((send gIconBar:curIcon)):message) 0))
(                    = prevDir (send pEvent:message)
)                )(else
                    return 
                )
            = cursorInc 
                (if (& (send pEvent:type) $0004)
                    (if (& (send pEvent:modifiers) $0003)
                        minInc
                    )(else
                        maxInc
                    )
                )(else
                    joyInc
                )
            (if (& (send pEvent:type) $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))
    )

)
