2
0
Эх сурвалжийг харах

Fix: [PolledInput.mod] Handle up to 5 mouse buttons.

Prior "WaitMouse" and "FlushMouse" ignored the last mouse button.
Ronny Otto 1 жил өмнө
parent
commit
5e86237a90

+ 18 - 16
polledinput.mod/polledinput.bmx

@@ -6,12 +6,14 @@ bbdoc: User input/Polled input
 End Rem
 End Rem
 Module BRL.PolledInput
 Module BRL.PolledInput
 
 
-ModuleInfo "Version: 1.04"
+ModuleInfo "Version: 1.05"
 ModuleInfo "Author: Mark Sibly, Simon Armstrong"
 ModuleInfo "Author: Mark Sibly, Simon Armstrong"
 ModuleInfo "License: zlib/libpng"
 ModuleInfo "License: zlib/libpng"
 ModuleInfo "Copyright: Blitz Research Ltd"
 ModuleInfo "Copyright: Blitz Research Ltd"
 ModuleInfo "Modserver: BRL"
 ModuleInfo "Modserver: BRL"
 
 
+ModuleInfo "History: 1.05"
+ModuleInfo "History: Fixed mouse functions not supporting 5 buttons."
 ModuleInfo "History: 1.04"
 ModuleInfo "History: 1.04"
 ModuleInfo "History: Support for 5 mouse buttons."
 ModuleInfo "History: Support for 5 mouse buttons."
 ModuleInfo "History: 1.03"
 ModuleInfo "History: 1.03"
@@ -33,8 +35,8 @@ Global suspended,terminate
 Global keyStates[256],keyHits[256]
 Global keyStates[256],keyHits[256]
 Global charGet,charPut,charQueue[256]
 Global charGet,charPut,charQueue[256]
 
 
-Global mouseStates[6],mouseHits[6]
-Global mouseLocation[4],lastMouseLocation[4]
+Global mouseStates[5],mouseHits[5]
+Global mouseLocation[3],lastMouseLocation[3]
 
 
 Function Hook:Object( id,data:Object,context:Object )
 Function Hook:Object( id,data:Object,context:Object )
 
 
@@ -59,12 +61,12 @@ Function Hook:Object( id,data:Object,context:Object )
 			charPut:+1
 			charPut:+1
 		EndIf
 		EndIf
 	Case EVENT_MOUSEDOWN
 	Case EVENT_MOUSEDOWN
-		If Not mouseStates[ev.data]
-			mouseStates[ev.data]=1
-			mouseHits[ev.data]:+1
+		If Not mouseStates[ev.data-1]
+			mouseStates[ev.data-1]=1
+			mouseHits[ev.data-1]:+1
 		EndIf
 		EndIf
 	Case EVENT_MOUSEUP
 	Case EVENT_MOUSEUP
-		mouseStates[ev.data]=0
+		mouseStates[ev.data-1]=0
 	Case EVENT_MOUSEMOVE
 	Case EVENT_MOUSEMOVE
 		mouseLocation[0]=ev.x
 		mouseLocation[0]=ev.x
 		mouseLocation[1]=ev.y
 		mouseLocation[1]=ev.y
@@ -190,12 +192,12 @@ Function FlushKeys(resetStates:Int = True)
 	charGet=0
 	charGet=0
 	charPut=0
 	charPut=0
 	If resetStates Then
 	If resetStates Then
-		For Local i=0 Until 256
+		For Local i:Int=0 Until keyStates.length
 			keyStates[i]=0
 			keyStates[i]=0
 			keyHits[i]=0
 			keyHits[i]=0
 		Next
 		Next
 	Else
 	Else
-		For Local i=0 Until 256
+		For Local i:Int=0 Until keyHits.length
 			keyHits[i]=0
 			keyHits[i]=0
 		Next
 		Next
 	End If
 	End If
@@ -275,7 +277,7 @@ about:
 End Rem
 End Rem
 Function FlushMouse()
 Function FlushMouse()
 	PollSystem
 	PollSystem
-	For Local i=0 Until 4
+	For Local i:Int=0 Until mouseStates.length
 		mouseStates[i]=0
 		mouseStates[i]=0
 		mouseHits[i]=0
 		mouseHits[i]=0
 	Next
 	Next
@@ -294,8 +296,8 @@ middle mouse button. Two further buttons, 4 and 5, are also available for mice t
 End Rem
 End Rem
 Function MouseHit( button )
 Function MouseHit( button )
 	If autoPoll PollSystem
 	If autoPoll PollSystem
-	Local n=mouseHits[button]
-	mouseHits[button]=0
+	Local n=mouseHits[button-1]
+	mouseHits[button-1]=0
 	Return n
 	Return n
 End Function
 End Function
 
 
@@ -308,7 +310,7 @@ middle mouse button. Two further buttons, 4 and 5, are also available for mice t
 End Rem
 End Rem
 Function MouseDown( button )
 Function MouseDown( button )
 	If autoPoll PollSystem
 	If autoPoll PollSystem
-	Return mouseStates[button]
+	Return mouseStates[button-1]
 End Function
 End Function
 
 
 Rem
 Rem
@@ -324,7 +326,7 @@ Function WaitKey()
 	FlushKeys
 	FlushKeys
 	Repeat
 	Repeat
 		WaitSystem
 		WaitSystem
-		For Local n=1 To 255
+		For Local n:Int = 1 To keyStates.length - 1
 			If KeyHit(n) Return n
 			If KeyHit(n) Return n
 		Next
 		Next
 	Forever
 	Forever
@@ -353,13 +355,13 @@ about:
 #WaitMouse suspends program execution until a mouse button is clicked.
 #WaitMouse suspends program execution until a mouse button is clicked.
 
 
 #WaitMouse returns 1 if the left mouse button was clicked, 2 if the right mouse button was
 #WaitMouse returns 1 if the left mouse button was clicked, 2 if the right mouse button was
-clicked or 3 if the middle mouse button was clicked.
+clicked or 3 if the middle mouse button was clicked. Further buttons (>3) are also checked for mice that support them. 
 End Rem
 End Rem
 Function WaitMouse()
 Function WaitMouse()
 	FlushMouse
 	FlushMouse
 	Repeat
 	Repeat
 		WaitSystem
 		WaitSystem
-		For Local n=1 To 3
+		For Local n:Int=1 To mouseHits.length
 			If MouseHit(n) Return n
 			If MouseHit(n) Return n
 		Next
 		Next
 	Forever
 	Forever