diff options
| author | Polesznyák Márk <contact@pml68.dev> | 2026-04-06 23:44:45 +0200 |
|---|---|---|
| committer | Polesznyák Márk <contact@pml68.dev> | 2026-04-06 23:44:45 +0200 |
| commit | 6637fdded6f3c5fba7e7a378ca7e30d0db11f27d (patch) | |
| tree | 40f8868ae2140680645b1f90f4a1fc2a378920b3 /vendor/hare-sdl2/sdl2/gamecontroller.ha | |
| parent | docs: add README (diff) | |
| parent | Add ! after c::fromstr calls to handle nomem (diff) | |
| download | hare-chip8-6637fdded6f3c5fba7e7a378ca7e30d0db11f27d.tar.gz | |
Add 'vendor/hare-sdl2/' from commit 'fb6008be0b79a2a24b1ac960316a83f7873b4f39'
git-subtree-dir: vendor/hare-sdl2
git-subtree-mainline: ed088aa81ac23fa48d5ae48ee739c97e0fcb4490
git-subtree-split: fb6008be0b79a2a24b1ac960316a83f7873b4f39
Diffstat (limited to 'vendor/hare-sdl2/sdl2/gamecontroller.ha')
| -rw-r--r-- | vendor/hare-sdl2/sdl2/gamecontroller.ha | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/vendor/hare-sdl2/sdl2/gamecontroller.ha b/vendor/hare-sdl2/sdl2/gamecontroller.ha new file mode 100644 index 0000000..4cab9ce --- /dev/null +++ b/vendor/hare-sdl2/sdl2/gamecontroller.ha @@ -0,0 +1,99 @@ +// TODO: Flesh me out + +// The SDL_GameController structure used to identify an SDL game controller. +// (Opaque) +export type SDL_GameController = opaque; + +// The list of axes available from a controller +// +// Thumbstick axis values range from [[SDL_JOYSTICK_AXIS_MIN]] to +// [[SDL_JOYSTICK_AXIS_MAX]], and are centered within ~8000 of zero, though advanced +// UI will allow users to set or autodetect the dead zone, which varies between +// controllers. +// +// Trigger axis values range from 0 to [[SDL_JOYSTICK_AXIS_MAX]]. +export type SDL_GameControllerAxis = enum u8 { + LEFTX, + LEFTY, + RIGHTX, + RIGHTY, + TRIGGERLEFT, + TRIGGERRIGHT, + INVALID = 255, +}; + +// The list of buttons available from a controller +export type SDL_GameControllerButton = enum u8 { + INVALID = 255, + A = 0, + B, + X, + Y, + BACK, + GUIDE, + START, + LEFTSTICK, + RIGHTSTICK, + LEFTSHOULDER, + RIGHTSHOULDER, + DPAD_UP, + DPAD_DOWN, + DPAD_LEFT, + DPAD_RIGHT, + MISC1, + PADDLE1, + PADDLE2, + PADDLE3, + PADDLE4, + TOUCHPAD, +}; + +// Check if the given joystick is supported by the game controller interface. +// +// 'joystick_index' is the same as the 'device_index' passed to +// [[joystick_open]]. +// +// Returns true if the given joystick is supported by the game controller +// interface, false if it isn't or it's an invalid index. +export @symbol("SDL_IsGameController") fn SDL_IsGameController( + joystick_index: int) bool; + +@symbol("SDL_GameControllerOpen") fn _game_controller_open( + joystick_index: int) nullable *SDL_GameController; + +// Get the SDL_GameController associated with an instance id. +export fn SDL_GameControllerOpen( + joystick_index: int, +) (*SDL_GameController | error) = { + return wrapptr(_game_controller_open(joystick_index))?: *SDL_GameController; +}; + +// Close a game controller previously opened with [[game_controller_open]]. +export @symbol("SDL_GameControllerClose") fn SDL_GameControllerClose( + gamecontroller: *SDL_GameController) void; + +@symbol("SDL_GameControllerRumble") fn _SDL_GameControllerRumble( + gamecontroller: *SDL_GameController, + low_frequency_rumble: u16, + high_frequency_rumble: u16, + duration_ms: u32) int; + +// Start a rumble effect on a game controller. +// +// Each call to this function cancels any previous rumble effect, and calling +// it with 0 intensity stops any rumbling. +// +// The low-frequency motor is generally on the left, and the high-frequency +// motor is generally on the right. +export fn SDL_GameControllerRumble( + gamecontroller: *SDL_GameController, + low_frequency_rumble: u16, + high_frequency_rumble: u16, + duration_ms: u32, +) (void | error) = { + return wrapvoid(_SDL_GameControllerRumble( + gamecontroller, + low_frequency_rumble, + high_frequency_rumble, + duration_ms)); +}; |
