Computer Science Canada

[source] Mouse module

Author:  Catalyst [ Thu May 29, 2003 3:19 pm ]
Post subject:  [source] Mouse module

i made this for one of my games
it allows easy use of all the mouse related features


code:

%% Mouse Module

module MouseInfo


    export GetInfo, Left, Right, Middle, X, Y, OldX, OldY

    buttonchoose ("multibutton")

    var mX, mY : int := 0
    var oldX, oldY : int := 0
    var diffX, diffY : int
    var button : int
    var left, right, middle : int := 0


    proc GetInfo
        oldX := mX
        oldY := mY
        mousewhere (mX, mY, button)
        diffX := oldX - mX
        diffY := oldY - mY
        left := (button mod 10)
        middle := ((button - left) mod 100)
        right := (button - middle - left)
    end GetInfo

    function Left : boolean
        result left = 1
    end Left
    function Right : boolean
        result right = 100
    end Right
    function Middle : boolean
        result middle = 10
    end Middle
    function X : int
        result mX
    end X
    function Y : int
        result mY
    end Y
    function OldX : int
        result oldX
    end OldX
    function OldY : int
        result oldY
    end OldY



end MouseInfo

drawfillbox (0,0,maxx,maxy,7)

View.Set ("offscreenonly")

loop
    color (0)
    colorback(7)
    locate (1, 1)
    put MouseInfo.X, "][", MouseInfo.Y
    locate (2, 1)
    put MouseInfo.Left, " - ", MouseInfo.Middle, " - ", MouseInfo.Right
    MouseInfo.GetInfo

    if MouseInfo.Left then
        drawdot (MouseInfo.X, MouseInfo.Y, 9)
        drawline (MouseInfo.X, MouseInfo.Y,MouseInfo.OldX, MouseInfo.OldY,9)
    end if
    if MouseInfo.Middle then
        drawdot (MouseInfo.X, MouseInfo.Y, 10)
        drawline (MouseInfo.X, MouseInfo.Y,MouseInfo.OldX, MouseInfo.OldY,10)
    end if
    if MouseInfo.Right then
        drawdot (MouseInfo.X, MouseInfo.Y, 12)
        drawline (MouseInfo.X, MouseInfo.Y,MouseInfo.OldX, MouseInfo.OldY,12)
    end if

    View.Update

end loop

Author:  Martin [ Thu May 29, 2003 3:22 pm ]
Post subject: 

Umm...why do you need the View.Update?

Author:  Catalyst [ Thu May 29, 2003 3:40 pm ]
Post subject: 

the little flashes on the text was bothering me

Author:  Homer_simpson [ Thu May 29, 2003 4:37 pm ]
Post subject: 

i always put a delay(5) after View.Update if i'm using it in a loop ,or my the program will freeze after a short while for some reason


: