Skip to content

Commit 0eac23b

Browse files
committed
add idiomatic gamepad bindings
1 parent d47f909 commit 0eac23b

File tree

5 files changed

+36
-35
lines changed

5 files changed

+36
-35
lines changed

bindings.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -1714,12 +1714,12 @@
17141714
},
17151715
{
17161716
"name": "button",
1717-
"typ": "i32"
1717+
"typ": "GamepadButton"
17181718
}
17191719
],
17201720
"returnType": "bool",
17211721
"description": "Check if a gamepad button has been pressed once",
1722-
"custom": false
1722+
"custom": true
17231723
},
17241724
{
17251725
"name": "IsGamepadButtonDown",
@@ -1730,12 +1730,12 @@
17301730
},
17311731
{
17321732
"name": "button",
1733-
"typ": "i32"
1733+
"typ": "GamepadButton"
17341734
}
17351735
],
17361736
"returnType": "bool",
17371737
"description": "Check if a gamepad button is being pressed",
1738-
"custom": false
1738+
"custom": true
17391739
},
17401740
{
17411741
"name": "IsGamepadButtonReleased",
@@ -1746,12 +1746,12 @@
17461746
},
17471747
{
17481748
"name": "button",
1749-
"typ": "i32"
1749+
"typ": "GamepadButton"
17501750
}
17511751
],
17521752
"returnType": "bool",
17531753
"description": "Check if a gamepad button has been released once",
1754-
"custom": false
1754+
"custom": true
17551755
},
17561756
{
17571757
"name": "IsGamepadButtonUp",
@@ -1762,19 +1762,19 @@
17621762
},
17631763
{
17641764
"name": "button",
1765-
"typ": "i32"
1765+
"typ": "GamepadButton"
17661766
}
17671767
],
17681768
"returnType": "bool",
17691769
"description": "Check if a gamepad button is NOT being pressed",
1770-
"custom": false
1770+
"custom": true
17711771
},
17721772
{
17731773
"name": "GetGamepadButtonPressed",
17741774
"params": [],
1775-
"returnType": "i32",
1775+
"returnType": "GamepadButton",
17761776
"description": "Get the last gamepad button pressed",
1777-
"custom": false
1777+
"custom": true
17781778
},
17791779
{
17801780
"name": "GetGamepadAxisCount",
@@ -1797,12 +1797,12 @@
17971797
},
17981798
{
17991799
"name": "axis",
1800-
"typ": "i32"
1800+
"typ": "GamepadAxis"
18011801
}
18021802
],
18031803
"returnType": "f32",
18041804
"description": "Get axis movement value for a gamepad axis",
1805-
"custom": false
1805+
"custom": true
18061806
},
18071807
{
18081808
"name": "SetGamepadMappings",

inject.zig

+7
Original file line numberDiff line numberDiff line change
@@ -956,3 +956,10 @@ pub fn rlDisableStatePointer(
956956
vertexAttribType,
957957
);
958958
}
959+
960+
/// Get the last gamepad button pressed
961+
pub fn GetGamepadButtonPressed() ?GamepadButton {
962+
if (raylib.GetGamepadButtonPressed() == -1) return null;
963+
964+
return @intToEnum(GamepadButton, raylib.GetGamepadButtonPressed());
965+
}

marshal.c

-5
Original file line numberDiff line numberDiff line change
@@ -713,11 +713,6 @@ bool mIsGamepadButtonUp(int gamepad, int button)
713713
return IsGamepadButtonUp(gamepad, button);
714714
}
715715

716-
int mGetGamepadButtonPressed(void)
717-
{
718-
return GetGamepadButtonPressed();
719-
}
720-
721716
int mGetGamepadAxisCount(int gamepad)
722717
{
723718
return GetGamepadAxisCount(gamepad);

marshal.h

-3
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,6 @@ bool mIsGamepadButtonReleased(int gamepad, int button);
435435
// Check if a gamepad button is NOT being pressed
436436
bool mIsGamepadButtonUp(int gamepad, int button);
437437

438-
// Get the last gamepad button pressed
439-
int mGetGamepadButtonPressed(void);
440-
441438
// Get gamepad axis count for a gamepad
442439
int mGetGamepadAxisCount(int gamepad);
443440

raylib.zig

+17-15
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,13 @@ pub fn rlDisableStatePointer(
957957
);
958958
}
959959

960+
/// Get the last gamepad button pressed
961+
pub fn GetGamepadButtonPressed() ?GamepadButton {
962+
if (raylib.GetGamepadButtonPressed() == -1) return null;
963+
964+
return @intToEnum(GamepadButton, raylib.GetGamepadButtonPressed());
965+
}
966+
960967
/// Initialize window and OpenGL context
961968
pub fn InitWindow(
962969
width: i32,
@@ -2190,52 +2197,47 @@ pub fn GetGamepadName(
21902197
/// Check if a gamepad button has been pressed once
21912198
pub fn IsGamepadButtonPressed(
21922199
gamepad: i32,
2193-
button: i32,
2200+
button: GamepadButton,
21942201
) bool {
21952202
return raylib.mIsGamepadButtonPressed(
21962203
gamepad,
2197-
button,
2204+
@enumToInt(button),
21982205
);
21992206
}
22002207

22012208
/// Check if a gamepad button is being pressed
22022209
pub fn IsGamepadButtonDown(
22032210
gamepad: i32,
2204-
button: i32,
2211+
button: GamepadButton,
22052212
) bool {
22062213
return raylib.mIsGamepadButtonDown(
22072214
gamepad,
2208-
button,
2215+
@enumToInt(button),
22092216
);
22102217
}
22112218

22122219
/// Check if a gamepad button has been released once
22132220
pub fn IsGamepadButtonReleased(
22142221
gamepad: i32,
2215-
button: i32,
2222+
button: GamepadButton,
22162223
) bool {
22172224
return raylib.mIsGamepadButtonReleased(
22182225
gamepad,
2219-
button,
2226+
@enumToInt(button),
22202227
);
22212228
}
22222229

22232230
/// Check if a gamepad button is NOT being pressed
22242231
pub fn IsGamepadButtonUp(
22252232
gamepad: i32,
2226-
button: i32,
2233+
button: GamepadButton,
22272234
) bool {
22282235
return raylib.mIsGamepadButtonUp(
22292236
gamepad,
2230-
button,
2237+
@enumToInt(button),
22312238
);
22322239
}
22332240

2234-
/// Get the last gamepad button pressed
2235-
pub fn GetGamepadButtonPressed() i32 {
2236-
return raylib.mGetGamepadButtonPressed();
2237-
}
2238-
22392241
/// Get gamepad axis count for a gamepad
22402242
pub fn GetGamepadAxisCount(
22412243
gamepad: i32,
@@ -2248,11 +2250,11 @@ pub fn GetGamepadAxisCount(
22482250
/// Get axis movement value for a gamepad axis
22492251
pub fn GetGamepadAxisMovement(
22502252
gamepad: i32,
2251-
axis: i32,
2253+
axis: GamepadAxis,
22522254
) f32 {
22532255
return raylib.mGetGamepadAxisMovement(
22542256
gamepad,
2255-
axis,
2257+
@enumToInt(axis),
22562258
);
22572259
}
22582260

0 commit comments

Comments
 (0)