-
Notifications
You must be signed in to change notification settings - Fork 2
/
touchcontroller.monkey
60 lines (46 loc) · 1.12 KB
/
touchcontroller.monkey
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
59
60
Strict
Import mojo.input
Import application
Class TouchController
Global instance:TouchController
Function GetInstance:TouchController()
If (Not instance) Then instance = New TouchController
Return instance
End
Field isDown?
Field wasDown?
Field startX%
Field startY%
Field dx%, dy%
Method Update:Void()
wasDown = isDown
If (TouchDown() And Not isDown)
isDown = True
startX = Application.GetInstance().VirtualMouseX()
startY = Application.GetInstance().VirtualMouseY()
End
If (Not TouchDown() And isDown)
isDown = False
dx = Application.GetInstance().VirtualMouseX() - startX
dy = Application.GetInstance().VirtualMouseY() - startY
End
End
Method GetDX#()
Return Application.GetInstance().VirtualMouseX() - startX
End
Method GetDY#()
Return Application.GetInstance().VirtualMouseY() - startY
End
Method IsTouchUp?()
Return (Not isDown And wasDown)
End
Method IsTouchDown?()
Return isDown
End
Method WasTouchedDown?()
Return wasDown
End
Method GetLastSlideDistance#()
Return (Sqrt(dx * dx + dy * dy))
End
End