-
Notifications
You must be signed in to change notification settings - Fork 136
/
input.go
92 lines (79 loc) · 2.64 KB
/
input.go
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package engo
const (
// AxisMax is the maximum value a joystick or keypress axis will reach
AxisMax float32 = 1
// AxisNeutral is the value an axis returns if there has been to state change.
AxisNeutral float32 = 0
// AxisMin is the minimum value a joystick or keypress axis will reach
AxisMin float32 = -1
)
// NewInputManager holds onto anything input related for engo
func NewInputManager() *InputManager {
return &InputManager{
Touches: make(map[int]Point),
axes: make(map[string]Axis),
buttons: make(map[string]Button),
keys: NewKeyManager(),
gamepads: NewGamepadManager(),
}
}
// InputManager contains information about all forms of input.
type InputManager struct {
// Mouse is InputManager's reference to the mouse. It is recommended to use the
// Axis and Button system if at all possible.
Mouse Mouse
// Modifier represents a special key pressed along with another key
Modifier Modifier
// Touches is the touches on the screen. There can be up to 5 recorded in Android,
// and up to 4 on iOS. GLFW can also keep track of the touches. The latest touch is also
// recorded in the Mouse so that touches readily work with the common.MouseSystem
Touches map[int]Point
axes map[string]Axis
buttons map[string]Button
keys *KeyManager
gamepads *GamepadManager
}
func (im *InputManager) update() {
im.keys.update()
im.gamepads.update()
}
// RegisterAxis registers a new axis which can be used to retrieve inputs which are spectrums.
func (im *InputManager) RegisterAxis(name string, pairs ...AxisPair) {
im.axes[name] = Axis{
Name: name,
Pairs: pairs,
}
}
// RegisterButton registers a new button input.
func (im *InputManager) RegisterButton(name string, keys ...Key) {
im.buttons[name] = Button{
Triggers: keys,
Name: name,
}
}
// RegisterGamepad registers a new gamepad for use. It starts with joystick0
// and continues until it finds one that can be used. If it does not find a
// suitable gamepad, an error will be returned.
func (im *InputManager) RegisterGamepad(name string) error {
return im.gamepads.Register(name)
}
// Axis retrieves an Axis with a specified name.
func (im *InputManager) Axis(name string) Axis {
return im.axes[name]
}
// Button retrieves a Button with a specified name.
func (im *InputManager) Button(name string) Button {
return im.buttons[name]
}
// Gamepad retrieves a Gamepad with a specified name.
func (im *InputManager) Gamepad(name string) *Gamepad {
return im.gamepads.GetGamepad(name)
}
// Mouse represents the mouse
type Mouse struct {
X, Y float32
ScrollX, ScrollY float32
Action Action
Button MouseButton
Modifer Modifier
}