GLBasic forum

Codesnippets => 2D-snippets => Topic started by: Schranz0r on 2010-Feb-14

Title: Mousehit events
Post by: Schranz0r on 2010-Feb-14
Code: (glbasic) [Select]
FUNCTION InitMousehit: SYSTEM_POINTER = FALSE // Init Mousehits, please call before the While-Wend !
SYSTEMPOINTER SYSTEM_POINTER
GLOBAL __mx, __my, __b1, __b2
GLOBAL __Mhit[]
DIM __Mhit[2][1]
ENDFUNCTION

FUNCTION Mousehit_left: //returns status: 0 = unpressed, 1 = Hit, 2 = Down, -1 = release

IF __Mhit[0][0] = 0 AND MOUSEAXIS(3)
__Mhit[0][0] = 1
ENDIF

RETURN __Mhit[0][0]
ENDFUNCTION

FUNCTION Mousehit_right: //returns status: 0 = unpressed, 1 = Hit, 2 = Down, -1 = release

IF __Mhit[1][0] = 0 AND MOUSEAXIS(4)
__Mhit[1][0] = 1
ENDIF

RETURN __Mhit[1][0]
ENDFUNCTION


FUNCTION MouseX:
RETURN __mx
ENDFUNCTION

FUNCTION MouseY:
RETURN __my
ENDFUNCTION

FUNCTION UpdateMousehit: // Update Mousehits, call befor SHOWSCREEN


MOUSESTATE __mx, __my, __b1, __b2

FOR i = 0 TO 1
IF __Mhit[i][0] = 1 AND MOUSEAXIS(3+i)
__Mhit[i][0] = 2
ENDIF
IF __Mhit[i][0] = -1
__Mhit[i][0] = 0
ENDIF
IF __Mhit[i][0] = 2 AND MOUSEAXIS(3+i) = 0
__Mhit[i][0] = -1
ENDIF
NEXT

ENDFUNCTION
Title: Re: Mousehit events
Post by: Moru on 2010-Feb-14
Nice, the keyhit return codes are slightly different though, mabe make them a bit normalized? :-)
//  0 = not pressed
//  2 = just pressed (hit)
//  1 = pressed (down)
// -1 = release event
Title: Re: Mousehit events
Post by: Schranz0r on 2010-Feb-14
Nice, the keyhit return codes are slightly different though, mabe make them a bit normalized? :-)
//  0 = not pressed
//  2 = just pressed (hit)
//  1 = pressed (down)
// -1 = release event


you can change it however you want :)