391 lines
16 KiB
Zig
391 lines
16 KiB
Zig
const std = @import("std");
|
|
pub const c = @import("c.zig").c;
|
|
const joystick_api = @import("joystick.zig");
|
|
const guid_api = @import("guid.zig");
|
|
const properties_api = @import("properties.zig");
|
|
const iostream_api = @import("iostream.zig");
|
|
const sensor_api = @import("sensor.zig");
|
|
const power_api = @import("power.zig");
|
|
|
|
pub const JoystickConnectionState = joystick_api.JoystickConnectionState;
|
|
pub const GUID = guid_api.GUID;
|
|
pub const PropertiesID = properties_api.PropertiesID;
|
|
pub const IOStream = iostream_api.IOStream;
|
|
pub const JoystickID = joystick_api.JoystickID;
|
|
pub const SensorType = sensor_api.SensorType;
|
|
pub const PowerState = power_api.PowerState;
|
|
pub const Joystick = joystick_api.Joystick;
|
|
|
|
pub const Gamepad = opaque {
|
|
pub inline fn getGamepadMapping(gamepad: *Gamepad) [*c]u8 {
|
|
return c.SDL_GetGamepadMapping(@ptrCast(@alignCast(gamepad)));
|
|
}
|
|
|
|
pub inline fn getGamepadProperties(gamepad: *Gamepad) PropertiesID {
|
|
return c.SDL_GetGamepadProperties(@ptrCast(@alignCast(gamepad)));
|
|
}
|
|
|
|
pub inline fn getGamepadID(gamepad: *Gamepad) JoystickID {
|
|
return c.SDL_GetGamepadID(@ptrCast(@alignCast(gamepad)));
|
|
}
|
|
|
|
pub inline fn getGamepadName(gamepad: *Gamepad) [*c]const u8 {
|
|
return c.SDL_GetGamepadName(@ptrCast(@alignCast(gamepad)));
|
|
}
|
|
|
|
pub inline fn getGamepadPath(gamepad: *Gamepad) [*c]const u8 {
|
|
return c.SDL_GetGamepadPath(@ptrCast(@alignCast(gamepad)));
|
|
}
|
|
|
|
pub inline fn getGamepadType(gamepad: *Gamepad) GamepadType {
|
|
return @fromBackingInt(@intCast(c.SDL_GetGamepadType(@ptrCast(@alignCast(gamepad)))));
|
|
}
|
|
|
|
pub inline fn getRealGamepadType(gamepad: *Gamepad) GamepadType {
|
|
return @fromBackingInt(@intCast(c.SDL_GetRealGamepadType(@ptrCast(@alignCast(gamepad)))));
|
|
}
|
|
|
|
pub inline fn getGamepadPlayerIndex(gamepad: *Gamepad) c_int {
|
|
return c.SDL_GetGamepadPlayerIndex(@ptrCast(@alignCast(gamepad)));
|
|
}
|
|
|
|
pub inline fn setGamepadPlayerIndex(gamepad: *Gamepad, player_index: c_int) bool {
|
|
return @bitCast(c.SDL_SetGamepadPlayerIndex(@ptrCast(@alignCast(gamepad)), player_index));
|
|
}
|
|
|
|
pub inline fn getGamepadVendor(gamepad: *Gamepad) u16 {
|
|
return c.SDL_GetGamepadVendor(@ptrCast(@alignCast(gamepad)));
|
|
}
|
|
|
|
pub inline fn getGamepadProduct(gamepad: *Gamepad) u16 {
|
|
return c.SDL_GetGamepadProduct(@ptrCast(@alignCast(gamepad)));
|
|
}
|
|
|
|
pub inline fn getGamepadProductVersion(gamepad: *Gamepad) u16 {
|
|
return c.SDL_GetGamepadProductVersion(@ptrCast(@alignCast(gamepad)));
|
|
}
|
|
|
|
pub inline fn getGamepadFirmwareVersion(gamepad: *Gamepad) u16 {
|
|
return c.SDL_GetGamepadFirmwareVersion(@ptrCast(@alignCast(gamepad)));
|
|
}
|
|
|
|
pub inline fn getGamepadSerial(gamepad: *Gamepad) [*c]const u8 {
|
|
return c.SDL_GetGamepadSerial(@ptrCast(@alignCast(gamepad)));
|
|
}
|
|
|
|
pub inline fn getGamepadSteamHandle(gamepad: *Gamepad) u64 {
|
|
return c.SDL_GetGamepadSteamHandle(@ptrCast(@alignCast(gamepad)));
|
|
}
|
|
|
|
pub inline fn getGamepadConnectionState(gamepad: *Gamepad) JoystickConnectionState {
|
|
return @fromBackingInt(@intCast(c.SDL_GetGamepadConnectionState(@ptrCast(@alignCast(gamepad)))));
|
|
}
|
|
|
|
pub inline fn getGamepadPowerInfo(gamepad: *Gamepad, percent: ?*c_int) PowerState {
|
|
return @fromBackingInt(@intCast(c.SDL_GetGamepadPowerInfo(@ptrCast(@alignCast(gamepad)), percent)));
|
|
}
|
|
|
|
pub inline fn gamepadConnected(gamepad: *Gamepad) bool {
|
|
return @bitCast(c.SDL_GamepadConnected(@ptrCast(@alignCast(gamepad))));
|
|
}
|
|
|
|
pub inline fn getGamepadJoystick(gamepad: *Gamepad) ?*Joystick {
|
|
return @ptrCast(@alignCast(c.SDL_GetGamepadJoystick(@ptrCast(@alignCast(gamepad)))));
|
|
}
|
|
|
|
pub inline fn getGamepadBindings(gamepad: *Gamepad, count: ?*c_int) [*c]?*GamepadBinding {
|
|
return @ptrCast(@alignCast(c.SDL_GetGamepadBindings(@ptrCast(@alignCast(gamepad)), count)));
|
|
}
|
|
|
|
pub inline fn gamepadHasAxis(gamepad: *Gamepad, axis: GamepadAxis) bool {
|
|
return @bitCast(c.SDL_GamepadHasAxis(@ptrCast(@alignCast(gamepad)), @intCast(@backingInt(axis))));
|
|
}
|
|
|
|
pub inline fn getGamepadAxis(gamepad: *Gamepad, axis: GamepadAxis) i16 {
|
|
return c.SDL_GetGamepadAxis(@ptrCast(@alignCast(gamepad)), @intCast(@backingInt(axis)));
|
|
}
|
|
|
|
pub inline fn gamepadHasButton(gamepad: *Gamepad, button: GamepadButton) bool {
|
|
return @bitCast(c.SDL_GamepadHasButton(@ptrCast(@alignCast(gamepad)), @intCast(@backingInt(button))));
|
|
}
|
|
|
|
pub inline fn getGamepadButton(gamepad: *Gamepad, button: GamepadButton) bool {
|
|
return @bitCast(c.SDL_GetGamepadButton(@ptrCast(@alignCast(gamepad)), @intCast(@backingInt(button))));
|
|
}
|
|
|
|
pub inline fn getGamepadButtonLabel(gamepad: *Gamepad, button: GamepadButton) GamepadButtonLabel {
|
|
return @fromBackingInt(@intCast(c.SDL_GetGamepadButtonLabel(@ptrCast(@alignCast(gamepad)), @intCast(@backingInt(button)))));
|
|
}
|
|
|
|
pub inline fn getNumGamepadTouchpads(gamepad: *Gamepad) c_int {
|
|
return c.SDL_GetNumGamepadTouchpads(@ptrCast(@alignCast(gamepad)));
|
|
}
|
|
|
|
pub inline fn getNumGamepadTouchpadFingers(gamepad: *Gamepad, touchpad: c_int) c_int {
|
|
return c.SDL_GetNumGamepadTouchpadFingers(@ptrCast(@alignCast(gamepad)), touchpad);
|
|
}
|
|
|
|
pub inline fn getGamepadTouchpadFinger(gamepad: *Gamepad, touchpad: c_int, finger: c_int, down: ?*bool, x: ?*f32, y: ?*f32, pressure: ?*f32) bool {
|
|
return @bitCast(c.SDL_GetGamepadTouchpadFinger(@ptrCast(@alignCast(gamepad)), touchpad, finger, @ptrCast(@alignCast(down)), x, y, pressure));
|
|
}
|
|
|
|
pub inline fn gamepadHasSensor(gamepad: *Gamepad, _type: SensorType) bool {
|
|
return @bitCast(c.SDL_GamepadHasSensor(@ptrCast(@alignCast(gamepad)), @intCast(@backingInt(_type))));
|
|
}
|
|
|
|
pub inline fn setGamepadSensorEnabled(gamepad: *Gamepad, _type: SensorType, enabled: bool) bool {
|
|
return @bitCast(c.SDL_SetGamepadSensorEnabled(@ptrCast(@alignCast(gamepad)), @intCast(@backingInt(_type)), @bitCast(enabled)));
|
|
}
|
|
|
|
pub inline fn gamepadSensorEnabled(gamepad: *Gamepad, _type: SensorType) bool {
|
|
return @bitCast(c.SDL_GamepadSensorEnabled(@ptrCast(@alignCast(gamepad)), @intCast(@backingInt(_type))));
|
|
}
|
|
|
|
pub inline fn getGamepadSensorDataRate(gamepad: *Gamepad, _type: SensorType) f32 {
|
|
return c.SDL_GetGamepadSensorDataRate(@ptrCast(@alignCast(gamepad)), @intCast(@backingInt(_type)));
|
|
}
|
|
|
|
pub inline fn getGamepadSensorData(gamepad: *Gamepad, _type: SensorType, data: ?*f32, num_values: c_int) bool {
|
|
return @bitCast(c.SDL_GetGamepadSensorData(@ptrCast(@alignCast(gamepad)), @intCast(@backingInt(_type)), data, num_values));
|
|
}
|
|
|
|
pub inline fn rumbleGamepad(gamepad: *Gamepad, low_frequency_rumble: u16, high_frequency_rumble: u16, duration_ms: u32) bool {
|
|
return @bitCast(c.SDL_RumbleGamepad(@ptrCast(@alignCast(gamepad)), low_frequency_rumble, high_frequency_rumble, duration_ms));
|
|
}
|
|
|
|
pub inline fn rumbleGamepadTriggers(gamepad: *Gamepad, left_rumble: u16, right_rumble: u16, duration_ms: u32) bool {
|
|
return @bitCast(c.SDL_RumbleGamepadTriggers(@ptrCast(@alignCast(gamepad)), left_rumble, right_rumble, duration_ms));
|
|
}
|
|
|
|
pub inline fn setGamepadLED(gamepad: *Gamepad, red: u8, green: u8, blue: u8) bool {
|
|
return @bitCast(c.SDL_SetGamepadLED(@ptrCast(@alignCast(gamepad)), red, green, blue));
|
|
}
|
|
|
|
pub inline fn sendGamepadEffect(gamepad: *Gamepad, data: ?*const anyopaque, size: c_int) bool {
|
|
return @bitCast(c.SDL_SendGamepadEffect(@ptrCast(@alignCast(gamepad)), data, size));
|
|
}
|
|
|
|
pub inline fn closeGamepad(gamepad: *Gamepad) void {
|
|
return c.SDL_CloseGamepad(@ptrCast(@alignCast(gamepad)));
|
|
}
|
|
|
|
pub inline fn getGamepadAppleSFSymbolsNameForButton(gamepad: *Gamepad, button: GamepadButton) [*c]const u8 {
|
|
return c.SDL_GetGamepadAppleSFSymbolsNameForButton(@ptrCast(@alignCast(gamepad)), @intCast(@backingInt(button)));
|
|
}
|
|
|
|
pub inline fn getGamepadAppleSFSymbolsNameForAxis(gamepad: *Gamepad, axis: GamepadAxis) [*c]const u8 {
|
|
return c.SDL_GetGamepadAppleSFSymbolsNameForAxis(@ptrCast(@alignCast(gamepad)), @intCast(@backingInt(axis)));
|
|
}
|
|
};
|
|
|
|
pub const GamepadType = enum(c_int) {
|
|
gamepadTypeUnknown = 0,
|
|
gamepadTypeStandard,
|
|
gamepadTypeXbox360,
|
|
gamepadTypeXboxone,
|
|
gamepadTypePs3,
|
|
gamepadTypePs4,
|
|
gamepadTypePs5,
|
|
gamepadTypeNintendoSwitchPro,
|
|
gamepadTypeNintendoSwitchJoyconLeft,
|
|
gamepadTypeNintendoSwitchJoyconRight,
|
|
gamepadTypeNintendoSwitchJoyconPair,
|
|
gamepadTypeGamecube,
|
|
gamepadTypeCount,
|
|
};
|
|
|
|
pub const GamepadButton = enum(c_int) {
|
|
gamepadButtonInvalid = -1,
|
|
gamepadButtonSouth, //Bottom face button (e.g. Xbox A button)
|
|
gamepadButtonEast, //Right face button (e.g. Xbox B button)
|
|
gamepadButtonWest, //Left face button (e.g. Xbox X button)
|
|
gamepadButtonNorth, //Top face button (e.g. Xbox Y button)
|
|
gamepadButtonBack,
|
|
gamepadButtonGuide,
|
|
gamepadButtonStart,
|
|
gamepadButtonLeftStick,
|
|
gamepadButtonRightStick,
|
|
gamepadButtonLeftShoulder,
|
|
gamepadButtonRightShoulder,
|
|
gamepadButtonDpadUp,
|
|
gamepadButtonDpadDown,
|
|
gamepadButtonDpadLeft,
|
|
gamepadButtonDpadRight,
|
|
gamepadButtonMisc1, //Additional button (e.g. Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Steam Controller QAM button, Amazon Luna microphone button, Google Stadia capture button)
|
|
gamepadButtonRightPaddle1, //Upper or primary paddle, under your right hand (e.g. Xbox Elite paddle P1, DualSense Edge RB button, Right Joy-Con SR button, Steam Controller R4 button)
|
|
gamepadButtonLeftPaddle1, //Upper or primary paddle, under your left hand (e.g. Xbox Elite paddle P3, DualSense Edge LB button, Left Joy-Con SL button, Steam Controller L4 button)
|
|
gamepadButtonRightPaddle2, //Lower or secondary paddle, under your right hand (e.g. Xbox Elite paddle P2, DualSense Edge right Fn button, Right Joy-Con SL button, Steam Controller R5 button)
|
|
gamepadButtonLeftPaddle2, //Lower or secondary paddle, under your left hand (e.g. Xbox Elite paddle P4, DualSense Edge left Fn button, Left Joy-Con SR button, Steam Controller L5 button)
|
|
gamepadButtonTouchpad, //PS4/PS5 touchpad button
|
|
gamepadButtonMisc2, //Additional button
|
|
gamepadButtonMisc3, //Additional button (e.g. Nintendo GameCube left trigger click)
|
|
gamepadButtonMisc4, //Additional button (e.g. Nintendo GameCube right trigger click)
|
|
gamepadButtonMisc5, //Additional button
|
|
gamepadButtonMisc6, //Additional button
|
|
gamepadButtonCount,
|
|
};
|
|
|
|
pub const GamepadButtonLabel = enum(c_int) {
|
|
gamepadButtonLabelUnknown,
|
|
gamepadButtonLabelA,
|
|
gamepadButtonLabelB,
|
|
gamepadButtonLabelX,
|
|
gamepadButtonLabelY,
|
|
gamepadButtonLabelCross,
|
|
gamepadButtonLabelCircle,
|
|
gamepadButtonLabelSquare,
|
|
gamepadButtonLabelTriangle,
|
|
};
|
|
|
|
pub const GamepadAxis = enum(c_int) {
|
|
gamepadAxisInvalid = -1,
|
|
gamepadAxisLeftx,
|
|
gamepadAxisLefty,
|
|
gamepadAxisRightx,
|
|
gamepadAxisRighty,
|
|
gamepadAxisLeftTrigger,
|
|
gamepadAxisRightTrigger,
|
|
gamepadAxisCount,
|
|
};
|
|
|
|
pub const GamepadBindingType = enum(c_int) {
|
|
gamepadBindtypeNone = 0,
|
|
gamepadBindtypeButton,
|
|
gamepadBindtypeAxis,
|
|
gamepadBindtypeHat,
|
|
};
|
|
|
|
pub const GamepadBinding = opaque {};
|
|
|
|
pub inline fn addGamepadMapping(mapping: [*c]const u8) c_int {
|
|
return c.SDL_AddGamepadMapping(mapping);
|
|
}
|
|
|
|
pub inline fn addGamepadMappingsFromIO(src: ?*IOStream, closeio: bool) c_int {
|
|
return c.SDL_AddGamepadMappingsFromIO(@ptrCast(@alignCast(src)), @bitCast(closeio));
|
|
}
|
|
|
|
pub inline fn addGamepadMappingsFromFile(file: [*c]const u8) c_int {
|
|
return c.SDL_AddGamepadMappingsFromFile(file);
|
|
}
|
|
|
|
pub inline fn reloadGamepadMappings() bool {
|
|
return @bitCast(c.SDL_ReloadGamepadMappings());
|
|
}
|
|
|
|
pub inline fn getGamepadMappings(count: ?*c_int) [*c][*c]u8 {
|
|
return c.SDL_GetGamepadMappings(count);
|
|
}
|
|
|
|
pub inline fn getGamepadMappingForGUID(guid: GUID) [*c]u8 {
|
|
return c.SDL_GetGamepadMappingForGUID(@as(*const c.SDL_GUID, @ptrCast(@alignCast(&guid))).*);
|
|
}
|
|
|
|
pub inline fn setGamepadMapping(instance_id: JoystickID, mapping: [*c]const u8) bool {
|
|
return @bitCast(c.SDL_SetGamepadMapping(instance_id, mapping));
|
|
}
|
|
|
|
pub inline fn hasGamepad() bool {
|
|
return @bitCast(c.SDL_HasGamepad());
|
|
}
|
|
|
|
pub inline fn getGamepads(count: ?*c_int) ?*JoystickID {
|
|
return c.SDL_GetGamepads(count);
|
|
}
|
|
|
|
pub inline fn isGamepad(instance_id: JoystickID) bool {
|
|
return @bitCast(c.SDL_IsGamepad(instance_id));
|
|
}
|
|
|
|
pub inline fn getGamepadNameForID(instance_id: JoystickID) [*c]const u8 {
|
|
return c.SDL_GetGamepadNameForID(instance_id);
|
|
}
|
|
|
|
pub inline fn getGamepadPathForID(instance_id: JoystickID) [*c]const u8 {
|
|
return c.SDL_GetGamepadPathForID(instance_id);
|
|
}
|
|
|
|
pub inline fn getGamepadPlayerIndexForID(instance_id: JoystickID) c_int {
|
|
return c.SDL_GetGamepadPlayerIndexForID(instance_id);
|
|
}
|
|
|
|
pub inline fn getGamepadGUIDForID(instance_id: JoystickID) GUID {
|
|
return @as(*const GUID, @ptrCast(@alignCast(&c.SDL_GetGamepadGUIDForID(instance_id)))).*;
|
|
}
|
|
|
|
pub inline fn getGamepadVendorForID(instance_id: JoystickID) u16 {
|
|
return c.SDL_GetGamepadVendorForID(instance_id);
|
|
}
|
|
|
|
pub inline fn getGamepadProductForID(instance_id: JoystickID) u16 {
|
|
return c.SDL_GetGamepadProductForID(instance_id);
|
|
}
|
|
|
|
pub inline fn getGamepadProductVersionForID(instance_id: JoystickID) u16 {
|
|
return c.SDL_GetGamepadProductVersionForID(instance_id);
|
|
}
|
|
|
|
pub inline fn getGamepadTypeForID(instance_id: JoystickID) GamepadType {
|
|
return @fromBackingInt(@intCast(c.SDL_GetGamepadTypeForID(instance_id)));
|
|
}
|
|
|
|
pub inline fn getRealGamepadTypeForID(instance_id: JoystickID) GamepadType {
|
|
return @fromBackingInt(@intCast(c.SDL_GetRealGamepadTypeForID(instance_id)));
|
|
}
|
|
|
|
pub inline fn getGamepadMappingForID(instance_id: JoystickID) [*c]u8 {
|
|
return c.SDL_GetGamepadMappingForID(instance_id);
|
|
}
|
|
|
|
pub inline fn openGamepad(instance_id: JoystickID) ?*Gamepad {
|
|
return @ptrCast(@alignCast(c.SDL_OpenGamepad(instance_id)));
|
|
}
|
|
|
|
pub inline fn getGamepadFromID(instance_id: JoystickID) ?*Gamepad {
|
|
return @ptrCast(@alignCast(c.SDL_GetGamepadFromID(instance_id)));
|
|
}
|
|
|
|
pub inline fn getGamepadFromPlayerIndex(player_index: c_int) ?*Gamepad {
|
|
return @ptrCast(@alignCast(c.SDL_GetGamepadFromPlayerIndex(player_index)));
|
|
}
|
|
|
|
pub inline fn setGamepadEventsEnabled(enabled: bool) void {
|
|
return c.SDL_SetGamepadEventsEnabled(@bitCast(enabled));
|
|
}
|
|
|
|
pub inline fn gamepadEventsEnabled() bool {
|
|
return @bitCast(c.SDL_GamepadEventsEnabled());
|
|
}
|
|
|
|
pub inline fn updateGamepads() void {
|
|
return c.SDL_UpdateGamepads();
|
|
}
|
|
|
|
pub inline fn getGamepadTypeFromString(str: [*c]const u8) GamepadType {
|
|
return @fromBackingInt(@intCast(c.SDL_GetGamepadTypeFromString(str)));
|
|
}
|
|
|
|
pub inline fn getGamepadStringForType(_type: GamepadType) [*c]const u8 {
|
|
return c.SDL_GetGamepadStringForType(@intCast(@backingInt(_type)));
|
|
}
|
|
|
|
pub inline fn getGamepadAxisFromString(str: [*c]const u8) GamepadAxis {
|
|
return @fromBackingInt(@intCast(c.SDL_GetGamepadAxisFromString(str)));
|
|
}
|
|
|
|
pub inline fn getGamepadStringForAxis(axis: GamepadAxis) [*c]const u8 {
|
|
return c.SDL_GetGamepadStringForAxis(@intCast(@backingInt(axis)));
|
|
}
|
|
|
|
pub inline fn getGamepadButtonFromString(str: [*c]const u8) GamepadButton {
|
|
return @fromBackingInt(@intCast(c.SDL_GetGamepadButtonFromString(str)));
|
|
}
|
|
|
|
pub inline fn getGamepadStringForButton(button: GamepadButton) [*c]const u8 {
|
|
return c.SDL_GetGamepadStringForButton(@intCast(@backingInt(button)));
|
|
}
|
|
|
|
pub inline fn getGamepadButtonLabelForType(_type: GamepadType, button: GamepadButton) GamepadButtonLabel {
|
|
return @fromBackingInt(@intCast(c.SDL_GetGamepadButtonLabelForType(@intCast(@backingInt(_type)), @intCast(@backingInt(button)))));
|
|
}
|