forked from EngoEngine/engo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.go
More file actions
68 lines (58 loc) · 1.69 KB
/
input.go
File metadata and controls
68 lines (58 loc) · 1.69 KB
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
package engo
const (
// AxisMax is the maximum value a joystick or keypress axis will reach
AxisMax float32 = 1
// AxisMin 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{
axes: make(map[string]Axis),
buttons: make(map[string]Button),
keys: NewKeyManager(),
}
}
// 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
axes map[string]Axis
buttons map[string]Button
keys *KeyManager
}
func (im *InputManager) update() {
im.keys.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,
}
}
// 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]
}
type Mouse struct {
X, Y float32
ScrollX, ScrollY float32
Action Action
Button MouseButton
Modifer Modifier
}