sdl3.c3l/sdl3_joystick.c3i

156 lines
9.3 KiB
Plaintext

module sdl3::sdl;
typedef Joystick = void;
typedef JoystickID = uint;
enum JoystickType : inline CInt {
JOYSTICK_TYPE_UNKNOWN,
JOYSTICK_TYPE_GAMEPAD,
JOYSTICK_TYPE_WHEEL,
JOYSTICK_TYPE_ARCADE_STICK,
JOYSTICK_TYPE_FLIGHT_STICK,
JOYSTICK_TYPE_DANCE_PAD,
JOYSTICK_TYPE_GUITAR,
JOYSTICK_TYPE_DRUM_KIT,
JOYSTICK_TYPE_ARCADE_PAD,
JOYSTICK_TYPE_THROTTLE,
JOYSTICK_TYPE_COUNT
}
typedef JoystickConnectionState = CInt;
const JoystickConnectionState JOYSTICK_CONNECTION_INVALID @builtin = -1;
const JoystickConnectionState JOYSTICK_CONNECTION_UNKNOWN @builtin = 0;
const JoystickConnectionState JOYSTICK_CONNECTION_WIRED @builtin = 1;
const JoystickConnectionState JOYSTICK_CONNECTION_WIRELESS @builtin = 2;
const int JOYSTICK_AXIS_MAX @builtin = 32767;
const int JOYSTICK_AXIS_MIN @builtin = -32768;
extern fn void lock_joysticks() @extern("SDL_LockJoysticks");
extern fn void unlock_joysticks() @extern("SDL_UnlockJoysticks");
extern fn bool has_joystick() @extern("SDL_HasJoystick");
extern fn JoystickID* get_joysticks(int *count) @extern("SDL_GetJoysticks");
extern fn ZString get_joystick_name_for_id(JoystickID instance_id) @extern("SDL_GetJoystickNameForID");
extern fn ZString get_joystick_path_for_id(JoystickID instance_id) @extern("SDL_GetJoystickPathForID");
extern fn int get_joystick_player_index_for_id(JoystickID instance_id) @extern("SDL_GetJoystickPlayerIndexForID");
// extern fn SDL_GUID get_joystick_guid_for_id(JoystickID instance_id) @extern("SDL_GetJoystickGUIDForID");
extern fn ushort get_joystick_vendor_for_id(JoystickID instance_id) @extern("SDL_GetJoystickVendorForID");
extern fn ushort get_joystick_product_for_id(JoystickID instance_id) @extern("SDL_GetJoystickProductForID");
extern fn ushort get_joystick_product_version_for_id(JoystickID instance_id) @extern("SDL_GetJoystickProductVersionForID");
extern fn JoystickType get_joystick_type_for_id(JoystickID instance_id) @extern("SDL_GetJoystickTypeForID");
extern fn Joystick* open_joystick(JoystickID instance_id) @extern("SDL_OpenJoystick");
extern fn Joystick* get_joystick_from_id(JoystickID instance_id) @extern("SDL_GetJoystickFromID");
extern fn Joystick* get_joystick_from_player_index(int player_index) @extern("SDL_GetJoystickFromPlayerIndex");
struct VirtualJoystickTouchpadDesc {
ushort nfingers;
ushort[3] padding;
}
struct VirtualJoystickSensorDesc {
SensorType type;
float rate;
}
alias VirtualJoystickUpdate = fn void(void *userdata);
alias VirtualJoystickSetPlayerIndex = fn void(void *userdata, int player_index);
alias VirtualJoystickRumble = fn bool(void *userdata, ushort low_frequency_rumble, ushort high_frequency_rumble);
alias VirtualJoystickRumbleTriggers = fn bool(void *userdata, ushort left_rumble, ushort right_rumble);
alias VirtualJoystickSetLED = fn bool(void *userdata, char red, char green, char blue);
alias VirtualJoystickSendEffect = fn bool(void *userdata, void *data, int size);
alias VirtualJoystickSetSensorsEnabled = fn bool(void *userdata, bool enabled);
alias VirtualJoystickCleanup = fn void(void *userdata);
struct VirtualJoystickDesc {
uint version;
ushort type;
ushort padding;
ushort vendor_id;
ushort product_id;
ushort naxes;
ushort nbuttons;
ushort nballs;
ushort nhats;
ushort ntouchpads;
ushort nsensors;
ushort[2] padding2;
uint button_mask;
uint axis_mask;
ZString name;
VirtualJoystickTouchpadDesc* touchpads;
VirtualJoystickSensorDesc* sensors;
void *userdata;
VirtualJoystickUpdate update;
VirtualJoystickSetPlayerIndex set_player_index;
VirtualJoystickRumble rumble;
VirtualJoystickRumbleTriggers rumble_triggers;
VirtualJoystickSetLED set_led;
VirtualJoystickSendEffect send_effect;
VirtualJoystickSetSensorsEnabled set_sensors_enabled;
VirtualJoystickCleanup cleanup;
}
extern fn JoystickID attach_virtual_joystick(VirtualJoystickDesc *desc) @extern("SDL_AttachVirtualJoystick");
extern fn bool detach_virtual_joystick(JoystickID instance_id) @extern("SDL_DetachVirtualJoystick");
extern fn bool is_joystick_virtual(JoystickID instance_id) @extern("SDL_IsJoystickVirtual");
extern fn bool set_joystick_virtual_axis(Joystick* joystick, int axis, short value) @extern("SDL_SetJoystickVirtualAxis");
extern fn bool set_joystick_virtual_ball(Joystick* joystick, int ball, short xrel, short yrel) @extern("SDL_SetJoystickVirtualBall");
extern fn bool set_joystick_virtual_button(Joystick* joystick, int button, bool down) @extern("SDL_SetJoystickVirtualButton");
extern fn bool set_joystick_virtual_hat(Joystick* joystick, int hat, char value) @extern("SDL_SetJoystickVirtualHat");
extern fn bool set_joystick_virtual_touchpad(Joystick* joystick, int touchpad, int finger, bool down, float x, float y, float pressure) @extern("SDL_SetJoystickVirtualTouchpad");
extern fn bool send_joystick_virtual_sensor_data(Joystick* joystick, SensorType type, ulong sensor_timestamp, float *data, int num_values) @extern("SDL_SendJoystickVirtualSensorData");
extern fn PropertiesID get_joystick_properties(Joystick* joystick) @extern("SDL_GetJoystickProperties");
const ZString PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN @builtin = "SDL.joystick.cap.mono_led";
const ZString PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN @builtin = "SDL.joystick.cap.rgb_led";
const ZString PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN @builtin = "SDL.joystick.cap.player_led";
const ZString PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN @builtin = "SDL.joystick.cap.rumble";
const ZString PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN @builtin = "SDL.joystick.cap.trigger_rumble";
extern fn ZString get_joystick_name(Joystick* joystick) @extern("SDL_GetJoystickName");
extern fn ZString get_joystick_path(Joystick* joystick) @extern("SDL_GetJoystickPath");
extern fn int get_joystick_player_index(Joystick* joystick) @extern("SDL_GetJoystickPlayerIndex");
extern fn bool set_joystick_player_index(Joystick* joystick, int player_index) @extern("SDL_SetJoystickPlayerIndex");
//extern fn SDL_GUID get_joystick_guid(Joystick* joystick) @extern("SDL_GetJoystickGUID");
extern fn ushort get_joystick_vendor(Joystick* joystick) @extern("SDL_GetJoystickVendor");
extern fn ushort get_joystick_product(Joystick* joystick) @extern("SDL_GetJoystickProduct");
extern fn ushort get_joystick_product_version(Joystick* joystick) @extern("SDL_GetJoystickProductVersion");
extern fn ushort get_joystick_firmware_version(Joystick* joystick) @extern("SDL_GetJoystickFirmwareVersion");
extern fn ZString get_joystick_serial(Joystick* joystick) @extern("SDL_GetJoystickSerial");
extern fn JoystickType get_joystick_type(Joystick* joystick) @extern("SDL_GetJoystickType");
//extern fn void get_joystick_guid_info(SDL_GUID guid, ushort *vendor, ushort *product, ushort *version, ushort *crc16) @extern("SDL_GetJoystickGUIDInfo");
extern fn bool joystick_connected(Joystick* joystick) @extern("SDL_JoystickConnected");
extern fn JoystickID get_joystick_id(Joystick* joystick) @extern("SDL_GetJoystickID");
extern fn int get_num_joystick_axes(Joystick* joystick) @extern("SDL_GetNumJoystickAxes");
extern fn int get_num_joystick_balls(Joystick* joystick) @extern("SDL_GetNumJoystickBalls");
extern fn int get_num_joystick_hats(Joystick* joystick) @extern("SDL_GetNumJoystickHats");
extern fn int get_num_joystick_buttons(Joystick* joystick) @extern("SDL_GetNumJoystickButtons");
extern fn void set_joystick_events_enabled(bool enabled) @extern("SDL_SetJoystickEventsEnabled");
extern fn bool joystick_events_enabled() @extern("SDL_JoystickEventsEnabled");
extern fn void update_joysticks() @extern("SDL_UpdateJoysticks");
extern fn short get_joystick_axis(Joystick* joystick, int axis) @extern("SDL_GetJoystickAxis");
extern fn bool get_joystick_axis_initial_state(Joystick* joystick, int axis, short *state) @extern("SDL_GetJoystickAxisInitialState");
extern fn bool get_joystick_ball(Joystick* joystick, int ball, int *dx, int *dy) @extern("SDL_GetJoystickBall");
extern fn char get_joystick_hat(Joystick* joystick, int hat) @extern("SDL_GetJoystickHat");
const ushort HAT_CENTERED @builtin = 0x00;
const ushort HAT_UP @builtin = 0x01;
const ushort HAT_RIGHT @builtin = 0x02;
const ushort HAT_DOWN @builtin = 0x04;
const ushort HAT_LEFT @builtin = 0x08;
const ushort HAT_RIGHTUP @builtin = (HAT_RIGHT|HAT_UP);
const ushort HAT_RIGHTDOWN @builtin = (HAT_RIGHT|HAT_DOWN);
const ushort HAT_LEFTUP @builtin = (HAT_LEFT|HAT_UP);
const ushort HAT_LEFTDOWN @builtin = (HAT_LEFT|HAT_DOWN);
extern fn bool get_joystick_button(Joystick* joystick, int button) @extern("SDL_GetJoystickButton");
extern fn bool rumble_joystick(Joystick* joystick, ushort low_frequency_rumble, ushort high_frequency_rumble, uint duration_ms) @extern("SDL_RumbleJoystick");
extern fn bool rumble_joystick_triggers(Joystick* joystick, ushort left_rumble, ushort right_rumble, uint duration_ms) @extern("SDL_RumbleJoystickTriggers");
extern fn bool set_joystick_led(Joystick* joystick, char red, char green, char blue) @extern("SDL_SetJoystickLED");
extern fn bool send_joystick_effect(Joystick* joystick, void *data, int size) @extern("SDL_SendJoystickEffect");
extern fn void close_joystick(Joystick* joystick) @extern("SDL_CloseJoystick");
extern fn JoystickConnectionState get_joystick_connection_state(Joystick* joystick) @extern("SDL_GetJoystickConnectionState");
extern fn PowerState get_joystick_power_info(Joystick* joystick, int *percent) @extern("SDL_GetJoystickPowerInfo");