-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mouse.fs
59 lines (40 loc) · 1.9 KB
/
Mouse.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module Mouse
open Microsoft.Xna.Framework
open Microsoft.Xna.Framework.Input
// compiler no longer allows this to be a static member as of 1.9.9.9
let mutable mouseState = Unchecked.defaultof<MouseState>
type Mouse() =
static let mutable first = true
static let move = new Event<_>()
static let leftButton = new Event<_>()
static let rightButton = new Event<_>()
static let middleButton = new Event<_>()
static let scrollWheelValue = new Event<_>()
static member Position
with get() = Vector2(float32 mouseState.X, float32 mouseState.Y)
static member Update() =
let newState = Mouse.GetState()
if first then
mouseState <- newState
first <- false
if newState.X <> mouseState.X || newState.Y <> mouseState.Y then
move.Trigger(Mouse.Position)
if newState.LeftButton = ButtonState.Pressed && mouseState.LeftButton = ButtonState.Released then
leftButton.Trigger(Mouse.Position)
if newState.RightButton = ButtonState.Pressed && mouseState.RightButton = ButtonState.Released then
rightButton.Trigger(Mouse.Position)
if newState.MiddleButton = ButtonState.Pressed && mouseState.MiddleButton = ButtonState.Released then
middleButton.Trigger(Mouse.Position)
if newState.ScrollWheelValue <> mouseState.ScrollWheelValue then
scrollWheelValue.Trigger(mouseState.ScrollWheelValue)
mouseState <- newState
static member Move
with get() = move.Publish
static member LeftButton
with get() = leftButton.Publish
static member RightButton
with get() = rightButton.Publish
static member MiddleButton
with get() = middleButton.Publish
static member ScrollWheelValue
with get() = scrollWheelValue.Publish