-
Notifications
You must be signed in to change notification settings - Fork 5
/
gamepad.v
109 lines (85 loc) · 2.58 KB
/
gamepad.v
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
module vraylib
enum GamepadPlayer {
player1 player2 player3 player4
}
enum GamepadButton {
unknown
// This is normally [A,B,X,Y]/[Circle,Triangle,Square,Cross]
// No support for 6 button controllers though..
left_face_up
left_face_right
left_face_down
left_face_left
// This is normally a DPAD
right_face_up
right_face_right
right_face_down
right_face_left
// Triggers
left_trigger_1
left_trigger_2
right_trigger_1
right_trigger_2
// These are buttons in the center of the gamepad
middle_left //PS3 Select
middle //PS Button/XBOX Button
middle_right //PS3 Start
// These are the joystick press in buttons
left_thumb
right_thumb
}
enum GamepadAxis {
// This is here just for error checking
unknown
// Left stick
left_x
left_y
// Right stick
right_x
right_y
// Pressure levels for the back triggers
left_trigger // [1..-1] (pressure-level)
right_trigger // [1..-1] (pressure-level)
}
// Input-related functions: gamepads
//
// Detect if a gamepad is available
[inline] pub fn is_gamepad_available(gamepad int) bool {
return C.IsGamepadAvailable(gamepad)
}
// Check gamepad name (if available)
[inline] pub fn is_gamepad_name(gamepad int, name string) bool {
return C.IsGamepadName(gamepad, name.str)
}
// Return gamepad internal name id
[inline] pub fn get_gamepad_name(gamepad int) string {
return string(byteptr(C.GetGamepadName(gamepad)))
}
// Detect if a gamepad button has been pressed once
[inline] pub fn is_gamepad_button_pressed(gamepad, button int) bool {
return C.IsGamepadButtonPressed(gamepad, button)
}
// Detect if a gamepad button is being pressed
[inline] pub fn is_gamepad_button_down(gamepad, button int) bool {
return C.IsGamepadButtonDown(gamepad, button)
}
// Detect if a gamepad button has been released once
[inline] pub fn is_gamepad_button_releaed(gamepad, button int) bool {
return C.IsGamepadButtonReleased(gamepad, button)
}
// Detect if a gamepad button is NOT being pressed
[inline] pub fn is_gamepad_button_up(gamepad, button int) bool {
return C.IsGamepadButtonUp(gamepad, button)
}
// Get the last gamepad button pressed
[inline] pub fn get_gamepad_button_pressed() int {
return C.GetGamepadButtonPressed()
}
// Return gamepad axis count for a gamepad
[inline] pub fn get_gamepad_axis_count(gamepad int) int {
return C.GetGamepadAxisCount(gamepad)
}
// Return axis movement value for a gamepad axis
[inline] pub fn get_gamepad_axis_movement(gamepad, axis int) f32 {
return C.GetGamepadAxisMovement(gamepad, axis)
}