Last active
January 3, 2016 09:29
-
-
Save nobuyukinyuu/8443525 to your computer and use it in GitHub Desktop.
Extra mouse states. (Untested on Xna)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class MouseState | |
Const MOUSE4 = 3 | |
Const MOUSE5 = 4 | |
Global wheelpos:Int | |
Function Down:Bool(button:Int) | |
#If TARGET="glfw" | |
If MouseButton(button) = 1 Then Return True | |
#ElseIf TARGET="xna" | |
Select button | |
Case MOUSE4 | |
If MouseBtn4() = 1 Then Return True | |
Case MOUSE5 | |
If MouseBtn5() = 1 Then Return True | |
End Select | |
#EndIf | |
Return False | |
End Function | |
'NOTE: You can only call this once per update loop. If you need to refer to the delta multiple times, | |
' I suggest storing it in a local var the first check. | |
Function WheelDelta:Int() | |
Local pos:Int = MouseWheel() | |
If pos <> wheelpos Then | |
Local oldpos:Int | |
oldpos = wheelpos | |
wheelpos = pos | |
Return pos - oldpos | |
End If | |
End Function | |
End Class | |
Private Extern | |
#If TARGET="glfw" | |
Function MouseButton:Int(button:Int) = "glfwGetMouseButton" | |
Function MouseWheel:Int() = "glfwGetMouseWheel" | |
#ElseIf TARGET="xna" | |
Function MouseBtn4:Int() = "Mouse.GetState().XButton1" | |
Function MouseBtn5:Int() = "Mouse.GetState().XButton2" | |
Function MouseWheel:Int() = "Mouse.GetState().ScrollWheelValue" | |
#EndIf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment