// // Generated by Brutal.Sdl.Generate; do not edit by hand. #nullable enable namespace Brutal.SdlApi { public static unsafe partial class Sdl { public static unsafe partial class Joystick { /// /// Locking for atomic access to the joystick API. /// /// /// /// The SDL joystick functions are thread-safe, however you can lock the /// joysticks while processing to guarantee that the joystick list won't change /// and joystick and gamepad events will not be delivered. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// public static void LockJoysticks() => PInvoke.LockJoysticks(); /// /// Unlocking for atomic access to the joystick API. /// /// /// This should be called from the same thread that called /// SDL_LockJoysticks(). /// /// /// This function is available since SDL 3.2.0. /// public static void UnlockJoysticks() => PInvoke.UnlockJoysticks(); /// /// Return whether a joystick is currently connected. /// /// true if a joystick is connected, false otherwise. /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static bool HasJoystick() => PInvoke.HasJoystick() != 0; /// /// Ergonomic wrapper over SDL_GetJoysticks. /// /// The SDL call failed; the message carries the /// SDL_GetError text. /// /// SDL returns a freshly SDL_malloc'd buffer for this call; the returned array is a managed copy, /// and the native buffer is freed with SDL_free before this method returns. /// public static uint[] GetJoysticks() { int count; var ptr = PInvoke.GetJoysticks(&count); if (ptr is null) throw SdlException.FromError("SDL_GetJoysticks failed"); try { return new ReadOnlySpan(ptr, count).ToArray(); } finally { PInvoke.Free(ptr); } } /// /// Get the implementation dependent name of a joystick. /// /// the joystick instance ID. /// /// the name of the selected joystick. If no name can be found, this /// function returns NULL; call SDL_GetError() for more information. /// /// /// /// This can be called before any joysticks are opened. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static string? GetJoystickNameForID(uint instance_id) => PInvoke.GetJoystickNameForID(instance_id); /// /// Get the implementation dependent path of a joystick. /// /// the joystick instance ID. /// /// the path of the selected joystick. If no path can be found, this /// function returns NULL; call SDL_GetError() for more information. /// /// /// /// This can be called before any joysticks are opened. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static string? GetJoystickPathForID(uint instance_id) => PInvoke.GetJoystickPathForID(instance_id); /// /// Get the player index of a joystick. /// /// the joystick instance ID. /// the player index of a joystick, or -1 if it's not available. /// /// /// This can be called before any joysticks are opened. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static int GetJoystickPlayerIndexForID(uint instance_id) => PInvoke.GetJoystickPlayerIndexForID(instance_id); /// /// Get the implementation-dependent GUID of a joystick. /// /// the joystick instance ID. /// /// the GUID of the selected joystick. If called with an invalid /// instance_id, this function returns a zero GUID. /// /// /// /// This can be called before any joysticks are opened. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static SdlGuid GetJoystickGuidForID(uint instance_id) => PInvoke.GetJoystickGuidForID(instance_id); /// /// Get the USB vendor ID of a joystick, if available. /// /// the joystick instance ID. /// /// the USB vendor ID of the selected joystick. If called with an /// invalid instance_id, this function returns 0. /// /// /// /// This can be called before any joysticks are opened. If the vendor ID isn't /// available this function returns 0. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static ushort GetJoystickVendorForID(uint instance_id) => PInvoke.GetJoystickVendorForID(instance_id); /// /// Get the USB product ID of a joystick, if available. /// /// the joystick instance ID. /// /// the USB product ID of the selected joystick. If called with an /// invalid instance_id, this function returns 0. /// /// /// /// This can be called before any joysticks are opened. If the product ID isn't /// available this function returns 0. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static ushort GetJoystickProductForID(uint instance_id) => PInvoke.GetJoystickProductForID(instance_id); /// /// Get the product version of a joystick, if available. /// /// the joystick instance ID. /// /// the product version of the selected joystick. If called with an /// invalid instance_id, this function returns 0. /// /// /// /// This can be called before any joysticks are opened. If the product version /// isn't available this function returns 0. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static ushort GetJoystickProductVersionForID(uint instance_id) => PInvoke.GetJoystickProductVersionForID(instance_id); /// /// Get the type of a joystick, if available. /// /// the joystick instance ID. /// /// the SDL_JoystickType of the selected joystick. If called with an /// invalid instance_id, this function returns /// SDL_JOYSTICK_TYPE_UNKNOWN. /// /// /// /// This can be called before any joysticks are opened. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static SdlJoystickType GetJoystickTypeForID(uint instance_id) => PInvoke.GetJoystickTypeForID(instance_id); /// /// Ergonomic wrapper over SDL_OpenJoystick. Throws instead of returning a null handle on failure. /// /// the joystick instance ID. /// The created handle (never a null handle). /// The SDL call failed; the message carries the /// SDL_GetError text. public static SdlJoystick OpenJoystick(uint instance_id) { SdlJoystick result = PInvoke.OpenJoystick(instance_id); if (result.IsNull()) { throw SdlException.FromError("SDL_OpenJoystick failed"); } return result; } /// /// Ergonomic wrapper over SDL_GetJoystickFromID. /// /// the instance ID to get the SDL_Joystick for. /// /// Borrowed handle: the returned handle is owned by SDL (or by another object) and must not be /// disposed. Do not call on it; doing so would free a resource /// this call does not own. A null handle is returned on failure. /// public static SdlJoystick GetJoystickFromID(uint instance_id) => PInvoke.GetJoystickFromID(instance_id); /// /// Ergonomic wrapper over SDL_GetJoystickFromPlayerIndex. /// /// the player index to get the SDL_Joystick for. /// /// Borrowed handle: the returned handle is owned by SDL (or by another object) and must not be /// disposed. Do not call on it; doing so would free a resource /// this call does not own. A null handle is returned on failure. /// public static SdlJoystick GetJoystickFromPlayerIndex(int player_index) => PInvoke.GetJoystickFromPlayerIndex(player_index); /// /// Attach a new virtual joystick. /// /// joystick description, initialized using SDL_INIT_INTERFACE(). /// /// the joystick instance ID, or 0 on failure; call SDL_GetError() for /// more information. /// /// /// /// Apps can create virtual joysticks, that exist without hardware directly /// backing them, and have program-supplied inputs. Once attached, a virtual /// joystick looks like any other joystick that SDL can access. These can be /// used to make other things look like joysticks, or provide pre-recorded /// input, etc. /// /// /// Once attached, the app can send joystick inputs to the new virtual joystick /// using SDL_SetJoystickVirtualAxis(), etc. /// /// /// When no longer needed, the virtual joystick can be removed by calling /// SDL_DetachVirtualJoystick(). /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// /// /// /// public static uint AttachVirtualJoystick(SdlVirtualJoystickDesc* desc) => PInvoke.AttachVirtualJoystick(desc); /// /// Detach a virtual joystick. /// /// /// the joystick instance ID, previously returned from /// SDL_AttachVirtualJoystick(). /// /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static bool DetachVirtualJoystick(uint instance_id) => PInvoke.DetachVirtualJoystick(instance_id) != 0; /// /// Query whether or not a joystick is virtual. /// /// the joystick instance ID. /// true if the joystick is virtual, false otherwise. /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// public static bool IsJoystickVirtual(uint instance_id) => PInvoke.IsJoystickVirtual(instance_id) != 0; /// /// Set the state of an axis on an opened virtual joystick. /// /// the virtual joystick on which to set state. /// the index of the axis on the virtual joystick to update. /// the new value for the specified axis. /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// /// Please note that values set here will not be applied until the next call to /// SDL_UpdateJoysticks, which can either be called directly, or can be called /// indirectly through various other SDL APIs, including, but not limited to /// the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, /// SDL_WaitEvent. /// /// /// Note that when sending trigger axes, you should scale the value to the full /// range of Sint16. For example, a trigger at rest would have the value of /// SDL_JOYSTICK_AXIS_MIN. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// /// public static bool SetJoystickVirtualAxis(SdlJoystick joystick, int axis, short value) => PInvoke.SetJoystickVirtualAxis(joystick, axis, value) != 0; /// /// Generate ball motion on an opened virtual joystick. /// /// the virtual joystick on which to set state. /// the index of the ball on the virtual joystick to update. /// the relative motion on the X axis. /// the relative motion on the Y axis. /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// /// Please note that values set here will not be applied until the next call to /// SDL_UpdateJoysticks, which can either be called directly, or can be called /// indirectly through various other SDL APIs, including, but not limited to /// the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, /// SDL_WaitEvent. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// /// public static bool SetJoystickVirtualBall(SdlJoystick joystick, int ball, short xrel, short yrel) => PInvoke.SetJoystickVirtualBall(joystick, ball, xrel, yrel) != 0; /// /// Set the state of a button on an opened virtual joystick. /// /// the virtual joystick on which to set state. /// the index of the button on the virtual joystick to update. /// true if the button is pressed, false otherwise. /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// /// Please note that values set here will not be applied until the next call to /// SDL_UpdateJoysticks, which can either be called directly, or can be called /// indirectly through various other SDL APIs, including, but not limited to /// the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, /// SDL_WaitEvent. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// /// public static bool SetJoystickVirtualButton(SdlJoystick joystick, int button, bool down) => PInvoke.SetJoystickVirtualButton(joystick, button, down ? (byte)1 : (byte)0) != 0; /// /// Set the state of a hat on an opened virtual joystick. /// /// the virtual joystick on which to set state. /// the index of the hat on the virtual joystick to update. /// the new value for the specified hat. /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// /// Please note that values set here will not be applied until the next call to /// SDL_UpdateJoysticks, which can either be called directly, or can be called /// indirectly through various other SDL APIs, including, but not limited to /// the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, /// SDL_WaitEvent. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// /// public static bool SetJoystickVirtualHat(SdlJoystick joystick, int hat, byte value) => PInvoke.SetJoystickVirtualHat(joystick, hat, value) != 0; /// /// Set touchpad finger state on an opened virtual joystick. /// /// the virtual joystick on which to set state. /// /// the index of the touchpad on the virtual joystick to /// update. /// /// the index of the finger on the touchpad to set. /// true if the finger is pressed, false if the finger is released. /// /// the x coordinate of the finger on the touchpad, normalized 0 to 1, /// with the origin in the upper left. /// /// /// the y coordinate of the finger on the touchpad, normalized 0 to 1, /// with the origin in the upper left. /// /// the pressure of the finger. /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// /// Please note that values set here will not be applied until the next call to /// SDL_UpdateJoysticks, which can either be called directly, or can be called /// indirectly through various other SDL APIs, including, but not limited to /// the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, /// SDL_WaitEvent. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// /// public static bool SetJoystickVirtualTouchpad( SdlJoystick joystick, int touchpad, int finger, bool down, float x, float y, float pressure ) => PInvoke.SetJoystickVirtualTouchpad(joystick, touchpad, finger, down ? (byte)1 : (byte)0, x, y, pressure) != 0; /// /// Send a sensor update for an opened virtual joystick. /// /// the virtual joystick on which to set state. /// the type of the sensor on the virtual joystick to update. /// /// a 64-bit timestamp in nanoseconds associated with /// the sensor reading. /// /// the data associated with the sensor reading. /// the number of values pointed to by data. /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// /// Please note that values set here will not be applied until the next call to /// SDL_UpdateJoysticks, which can either be called directly, or can be called /// indirectly through various other SDL APIs, including, but not limited to /// the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, /// SDL_WaitEvent. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// /// /// public static bool SendJoystickVirtualSensorData( SdlJoystick joystick, SdlSensorType type, ulong sensor_timestamp, float* data, int num_values ) => PInvoke.SendJoystickVirtualSensorData(joystick, type, sensor_timestamp, data, num_values) != 0; /// /// Get the properties associated with a joystick. /// /// the SDL_Joystick obtained from SDL_OpenJoystick(). /// /// a valid property ID on success or 0 on failure; call /// SDL_GetError() for more information. /// /// /// /// The following read-only properties are provided by SDL: /// /// /// - SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN: true if this joystick has an /// LED that has adjustable brightness /// - SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN: true if this joystick has an LED /// that has adjustable color /// - SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN: true if this joystick has a /// player LED /// - SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN: true if this joystick has /// left/right rumble /// - SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN: true if this joystick has /// simple trigger rumble /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// public static uint GetJoystickProperties(SdlJoystick joystick) => PInvoke.GetJoystickProperties(joystick); /// /// Get the implementation dependent name of a joystick. /// /// the SDL_Joystick obtained from SDL_OpenJoystick(). /// /// the name of the selected joystick. If no name can be found, this /// function returns NULL; call SDL_GetError() for more information. /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static string? GetJoystickName(SdlJoystick joystick) => PInvoke.GetJoystickName(joystick); /// /// Get the implementation dependent path of a joystick. /// /// the SDL_Joystick obtained from SDL_OpenJoystick(). /// /// the path of the selected joystick. If no path can be found, this /// function returns NULL; call SDL_GetError() for more information. /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static string? GetJoystickPath(SdlJoystick joystick) => PInvoke.GetJoystickPath(joystick); /// /// Get the player index of an opened joystick. /// /// the SDL_Joystick obtained from SDL_OpenJoystick(). /// the player index, or -1 if it's not available. /// /// /// For XInput controllers this returns the XInput user index. Many joysticks /// will not be able to supply this information. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static int GetJoystickPlayerIndex(SdlJoystick joystick) => PInvoke.GetJoystickPlayerIndex(joystick); /// /// Set the player index of an opened joystick. /// /// the SDL_Joystick obtained from SDL_OpenJoystick(). /// /// player index to assign to this joystick, or -1 to clear /// the player index and turn off player LEDs. /// /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static bool SetJoystickPlayerIndex(SdlJoystick joystick, int player_index) => PInvoke.SetJoystickPlayerIndex(joystick, player_index) != 0; /// /// Get the implementation-dependent GUID for the joystick. /// /// the SDL_Joystick obtained from SDL_OpenJoystick(). /// /// the GUID of the given joystick. If called on an invalid index, /// this function returns a zero GUID; call SDL_GetError() for more /// information. /// /// /// /// This function requires an open joystick. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static SdlGuid GetJoystickGuid(SdlJoystick joystick) => PInvoke.GetJoystickGuid(joystick); /// /// Get the USB vendor ID of an opened joystick, if available. /// /// the SDL_Joystick obtained from SDL_OpenJoystick(). /// the USB vendor ID of the selected joystick, or 0 if unavailable. /// /// /// If the vendor ID isn't available this function returns 0. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static ushort GetJoystickVendor(SdlJoystick joystick) => PInvoke.GetJoystickVendor(joystick); /// /// Get the USB product ID of an opened joystick, if available. /// /// the SDL_Joystick obtained from SDL_OpenJoystick(). /// the USB product ID of the selected joystick, or 0 if unavailable. /// /// /// If the product ID isn't available this function returns 0. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static ushort GetJoystickProduct(SdlJoystick joystick) => PInvoke.GetJoystickProduct(joystick); /// /// Get the product version of an opened joystick, if available. /// /// the SDL_Joystick obtained from SDL_OpenJoystick(). /// the product version of the selected joystick, or 0 if unavailable. /// /// /// If the product version isn't available this function returns 0. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static ushort GetJoystickProductVersion(SdlJoystick joystick) => PInvoke.GetJoystickProductVersion(joystick); /// /// Get the firmware version of an opened joystick, if available. /// /// the SDL_Joystick obtained from SDL_OpenJoystick(). /// /// the firmware version of the selected joystick, or 0 if /// unavailable. /// /// /// /// If the firmware version isn't available this function returns 0. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// public static ushort GetJoystickFirmwareVersion(SdlJoystick joystick) => PInvoke.GetJoystickFirmwareVersion(joystick); /// /// Get the serial number of an opened joystick, if available. /// /// the SDL_Joystick obtained from SDL_OpenJoystick(). /// /// the serial number of the selected joystick, or NULL if /// unavailable. /// /// /// /// Returns the serial number of the joystick, or NULL if it is not available. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// public static string? GetJoystickSerial(SdlJoystick joystick) => PInvoke.GetJoystickSerial(joystick); /// /// Get the type of an opened joystick. /// /// the SDL_Joystick obtained from SDL_OpenJoystick(). /// the SDL_JoystickType of the selected joystick. /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static SdlJoystickType GetJoystickType(SdlJoystick joystick) => PInvoke.GetJoystickType(joystick); /// /// Get the device information encoded in a SDL_GUID structure. /// /// the SDL_GUID you wish to get info about. /// /// a pointer filled in with the device VID, or 0 if not /// available. /// /// /// a pointer filled in with the device PID, or 0 if not /// available. /// /// /// a pointer filled in with the device version, or 0 if not /// available. /// /// /// a pointer filled in with a CRC used to distinguish different /// products with the same VID/PID, or 0 if not available. /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static void GetJoystickGuidInfo( SdlGuid guid, out ushort vendor, out ushort product, out ushort version, out ushort crc16 ) { vendor = default; product = default; version = default; crc16 = default; fixed (ushort* vendorPtr = &vendor) { fixed (ushort* productPtr = &product) { fixed (ushort* versionPtr = &version) { fixed (ushort* crc16Ptr = &crc16) { PInvoke.GetJoystickGuidInfo(guid, vendorPtr, productPtr, versionPtr, crc16Ptr); } } } } } /// /// Get the status of a specified joystick. /// /// the joystick to query. /// /// true if the joystick has been opened, false if it has not; call /// SDL_GetError() for more information. /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// public static bool JoystickConnected(SdlJoystick joystick) => PInvoke.JoystickConnected(joystick) != 0; /// /// Get the instance ID of an opened joystick. /// /// an SDL_Joystick structure containing joystick information. /// /// the instance ID of the specified joystick on success or 0 on /// failure; call SDL_GetError() for more information. /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// public static uint GetJoystickID(SdlJoystick joystick) => PInvoke.GetJoystickID(joystick); /// /// Get the number of general axis controls on a joystick. /// /// an SDL_Joystick structure containing joystick information. /// /// the number of axis controls/number of axes on success or -1 on /// failure; call SDL_GetError() for more information. /// /// /// /// Often, the directional pad on a game controller will either look like 4 /// separate buttons or a POV hat, and not axes, but all of this is up to the /// device and platform. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// /// public static int GetNumJoystickAxes(SdlJoystick joystick) => PInvoke.GetNumJoystickAxes(joystick); /// /// Get the number of trackballs on a joystick. /// /// an SDL_Joystick structure containing joystick information. /// /// the number of trackballs on success or -1 on failure; call /// SDL_GetError() for more information. /// /// /// /// Joystick trackballs have only relative motion events associated with them /// and their state cannot be polled. /// /// /// Most joysticks do not have trackballs. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// /// public static int GetNumJoystickBalls(SdlJoystick joystick) => PInvoke.GetNumJoystickBalls(joystick); /// /// Get the number of POV hats on a joystick. /// /// an SDL_Joystick structure containing joystick information. /// /// the number of POV hats on success or -1 on failure; call /// SDL_GetError() for more information. /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// /// public static int GetNumJoystickHats(SdlJoystick joystick) => PInvoke.GetNumJoystickHats(joystick); /// /// Get the number of buttons on a joystick. /// /// an SDL_Joystick structure containing joystick information. /// /// the number of buttons on success or -1 on failure; call /// SDL_GetError() for more information. /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// /// /// public static int GetNumJoystickButtons(SdlJoystick joystick) => PInvoke.GetNumJoystickButtons(joystick); /// /// Set the state of joystick event processing. /// /// whether to process joystick events or not. /// /// /// If joystick events are disabled, you must call SDL_UpdateJoysticks() /// yourself and check the state of the joystick when you want joystick /// information. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// /// public static void SetJoystickEventsEnabled(bool enabled) => PInvoke.SetJoystickEventsEnabled(enabled ? (byte)1 : (byte)0); /// /// Query the state of joystick event processing. /// /// true if joystick events are being processed, false otherwise. /// /// /// If joystick events are disabled, you must call SDL_UpdateJoysticks() /// yourself and check the state of the joystick when you want joystick /// information. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static bool JoystickEventsEnabled() => PInvoke.JoystickEventsEnabled() != 0; /// /// Update the current state of the open joysticks. /// /// /// /// This is called automatically by the event loop if any joystick events are /// enabled. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// public static void UpdateJoysticks() => PInvoke.UpdateJoysticks(); /// /// Get the current state of an axis control on a joystick. /// /// an SDL_Joystick structure containing joystick information. /// the axis to query; the axis indices start at index 0. /// /// a 16-bit signed integer representing the current position of the /// axis or 0 on failure; call SDL_GetError() for more information. /// /// /// /// SDL makes no promises about what part of the joystick any given axis refers /// to. Your game should have some sort of configuration UI to let users /// specify what each axis should be bound to. Alternately, SDL's higher-level /// Game Controller API makes a great effort to apply order to this lower-level /// interface, so you know that a specific axis is the "left thumb stick," etc. /// /// /// The value returned by SDL_GetJoystickAxis() is a signed integer (-32768 to /// 32767) representing the current position of the axis. It may be necessary /// to impose certain tolerances on these values to account for jitter. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static short GetJoystickAxis(SdlJoystick joystick, int axis) => PInvoke.GetJoystickAxis(joystick, axis); /// /// Get the initial state of an axis control on a joystick. /// /// an SDL_Joystick structure containing joystick information. /// the axis to query; the axis indices start at index 0. /// upon return, the initial value is supplied here. /// true if this axis has any initial value, or false if not. /// /// /// The state is a value ranging from -32768 to 32767. /// /// /// The axis indices start at index 0. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// public static bool GetJoystickAxisInitialState(SdlJoystick joystick, int axis, out short state) { state = default; fixed (short* statePtr = &state) { return PInvoke.GetJoystickAxisInitialState(joystick, axis, statePtr) != 0; } } /// /// Get the ball axis change since the last poll. /// /// the SDL_Joystick to query. /// the ball index to query; ball indices start at index 0. /// stores the difference in the x axis position since the last poll. /// stores the difference in the y axis position since the last poll. /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// /// Trackballs can only return relative motion since the last call to /// SDL_GetJoystickBall(), these motion deltas are placed into dx and dy. /// /// /// Most joysticks do not have trackballs. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static bool GetJoystickBall(SdlJoystick joystick, int ball, out int dx, out int dy) { dx = default; dy = default; fixed (int* dxPtr = &dx) { fixed (int* dyPtr = &dy) { return PInvoke.GetJoystickBall(joystick, ball, dxPtr, dyPtr) != 0; } } } /// /// Get the current state of a POV hat on a joystick. /// /// an SDL_Joystick structure containing joystick information. /// the hat index to get the state from; indices start at index 0. /// the current hat position. /// /// /// The returned value will be one of the SDL_HAT_* values. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static byte GetJoystickHat(SdlJoystick joystick, int hat) => PInvoke.GetJoystickHat(joystick, hat); /// /// Get the current state of a button on a joystick. /// /// an SDL_Joystick structure containing joystick information. /// /// the button index to get the state from; indices start at /// index 0. /// /// true if the button is pressed, false otherwise. /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static bool GetJoystickButton(SdlJoystick joystick, int button) => PInvoke.GetJoystickButton(joystick, button) != 0; /// /// Start a rumble effect. /// /// the joystick to vibrate. /// /// the intensity of the low frequency (left) /// rumble motor, from 0 to 0xFFFF. /// /// /// the intensity of the high frequency (right) /// rumble motor, from 0 to 0xFFFF. /// /// the duration of the rumble effect, in milliseconds. /// true, or false if rumble isn't supported on this joystick. /// /// /// Each call to this function cancels any previous rumble effect, and calling /// it with 0 intensity stops any rumbling. /// /// /// This function requires you to process SDL events or call /// SDL_UpdateJoysticks() to update rumble state. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// public static bool RumbleJoystick( SdlJoystick joystick, ushort low_frequency_rumble, ushort high_frequency_rumble, uint duration_ms ) => PInvoke.RumbleJoystick(joystick, low_frequency_rumble, high_frequency_rumble, duration_ms) != 0; /// /// Start a rumble effect in the joystick's triggers. /// /// the joystick to vibrate. /// /// the intensity of the left trigger rumble motor, from 0 /// to 0xFFFF. /// /// /// the intensity of the right trigger rumble motor, from 0 /// to 0xFFFF. /// /// the duration of the rumble effect, in milliseconds. /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// /// Each call to this function cancels any previous trigger rumble effect, and /// calling it with 0 intensity stops any rumbling. /// /// /// Note that this is rumbling of the triggers and not the game controller as /// a whole. This is currently only supported on Xbox One controllers. If you /// want the (more common) whole-controller rumble, use SDL_RumbleJoystick() /// instead. /// /// /// This function requires you to process SDL events or call /// SDL_UpdateJoysticks() to update rumble state. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static bool RumbleJoystickTriggers( SdlJoystick joystick, ushort left_rumble, ushort right_rumble, uint duration_ms ) => PInvoke.RumbleJoystickTriggers(joystick, left_rumble, right_rumble, duration_ms) != 0; /// /// Update a joystick's LED color. /// /// the joystick to update. /// the intensity of the red LED. /// the intensity of the green LED. /// the intensity of the blue LED. /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// /// An example of a joystick LED is the light on the back of a PlayStation 4's /// DualShock 4 controller. /// /// /// For joysticks with a single color LED, the maximum of the RGB values will /// be used as the LED brightness. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// public static bool SetJoystickLED(SdlJoystick joystick, byte red, byte green, byte blue) => PInvoke.SetJoystickLED(joystick, red, green, blue) != 0; /// /// Send a joystick specific effect packet. /// /// the joystick to affect. /// the data to send to the joystick. /// the size of the data to send to the joystick. /// /// true on success or false on failure; call SDL_GetError() for more /// information. /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// public static bool SendJoystickEffect(SdlJoystick joystick, void* data, int size) => PInvoke.SendJoystickEffect(joystick, data, size) != 0; /// /// Close a joystick previously opened with SDL_OpenJoystick(). /// /// the joystick device to close. /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// /// public static void CloseJoystick(SdlJoystick joystick) => PInvoke.CloseJoystick(joystick); /// /// Get the connection state of a joystick. /// /// the joystick to query. /// /// the connection state on success or /// SDL_JOYSTICK_CONNECTION_INVALID on failure; call SDL_GetError() /// for more information. /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// public static SdlJoystickConnectionState GetJoystickConnectionState(SdlJoystick joystick) => PInvoke.GetJoystickConnectionState(joystick); /// /// Get the battery state of a joystick. /// /// the joystick to query. /// /// a pointer filled in with the percentage of battery life /// left, between 0 and 100, or NULL to ignore. This will be /// filled in with -1 we can't determine a value or there is no /// battery. /// /// /// the current battery state or SDL_POWERSTATE_ERROR on failure; /// call SDL_GetError() for more information. /// /// /// /// You should never take a battery status as absolute truth. Batteries /// (especially failing batteries) are delicate hardware, and the values /// reported here are best estimates based on what that hardware reports. It's /// not uncommon for older batteries to lose stored power much faster than it /// reports, or completely drain when reporting it has 20 percent left, etc. /// /// /// /// It is safe to call this function from any thread. /// /// /// This function is available since SDL 3.2.0. /// public static SdlPowerState GetJoystickPowerInfo(SdlJoystick joystick, out int percent) { percent = default; fixed (int* percentPtr = &percent) { return PInvoke.GetJoystickPowerInfo(joystick, percentPtr); } } } } }