mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 21:18:24 +01:00
1448 lines
70 KiB
C#
1448 lines
70 KiB
C#
// <auto-generated/>
|
|
// 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
|
|
{
|
|
/// <summary>
|
|
/// Locking for atomic access to the joystick API.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
public static void LockJoysticks() => PInvoke.LockJoysticks();
|
|
|
|
/// <summary>
|
|
/// Unlocking for atomic access to the joystick API.
|
|
/// </summary>
|
|
/// <threadsafety>
|
|
/// This should be called from the same thread that called
|
|
/// SDL_LockJoysticks().
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
public static void UnlockJoysticks() => PInvoke.UnlockJoysticks();
|
|
|
|
/// <summary>
|
|
/// Return whether a joystick is currently connected.
|
|
/// </summary>
|
|
/// <returns>true if a joystick is connected, false otherwise.</returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoysticks"/>
|
|
public static bool HasJoystick() => PInvoke.HasJoystick() != 0;
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>SDL_GetJoysticks</c>.
|
|
/// </summary>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the
|
|
/// <c>SDL_GetError</c> text.</exception>
|
|
/// <remarks>
|
|
/// SDL returns a freshly <c>SDL_malloc</c>'d buffer for this call; the returned array is a managed copy,
|
|
/// and the native buffer is freed with <c>SDL_free</c> before this method returns.
|
|
/// </remarks>
|
|
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<uint>(ptr, count).ToArray();
|
|
}
|
|
finally
|
|
{
|
|
PInvoke.Free(ptr);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the implementation dependent name of a joystick.
|
|
/// </summary>
|
|
/// <param name="instance_id">the joystick instance ID.</param>
|
|
/// <returns>
|
|
/// the name of the selected joystick. If no name can be found, this
|
|
/// function returns NULL; call SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This can be called before any joysticks are opened.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickName"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoysticks"/>
|
|
public static string? GetJoystickNameForID(uint instance_id) => PInvoke.GetJoystickNameForID(instance_id);
|
|
|
|
/// <summary>
|
|
/// Get the implementation dependent path of a joystick.
|
|
/// </summary>
|
|
/// <param name="instance_id">the joystick instance ID.</param>
|
|
/// <returns>
|
|
/// the path of the selected joystick. If no path can be found, this
|
|
/// function returns NULL; call SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This can be called before any joysticks are opened.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickPath"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoysticks"/>
|
|
public static string? GetJoystickPathForID(uint instance_id) => PInvoke.GetJoystickPathForID(instance_id);
|
|
|
|
/// <summary>
|
|
/// Get the player index of a joystick.
|
|
/// </summary>
|
|
/// <param name="instance_id">the joystick instance ID.</param>
|
|
/// <returns>the player index of a joystick, or -1 if it's not available.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This can be called before any joysticks are opened.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickPlayerIndex"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoysticks"/>
|
|
public static int GetJoystickPlayerIndexForID(uint instance_id) =>
|
|
PInvoke.GetJoystickPlayerIndexForID(instance_id);
|
|
|
|
/// <summary>
|
|
/// Get the implementation-dependent GUID of a joystick.
|
|
/// </summary>
|
|
/// <param name="instance_id">the joystick instance ID.</param>
|
|
/// <returns>
|
|
/// the GUID of the selected joystick. If called with an invalid
|
|
/// instance_id, this function returns a zero GUID.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This can be called before any joysticks are opened.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickGuid"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GuidToString"/>
|
|
public static SdlGuid GetJoystickGuidForID(uint instance_id) => PInvoke.GetJoystickGuidForID(instance_id);
|
|
|
|
/// <summary>
|
|
/// Get the USB vendor ID of a joystick, if available.
|
|
/// </summary>
|
|
/// <param name="instance_id">the joystick instance ID.</param>
|
|
/// <returns>
|
|
/// the USB vendor ID of the selected joystick. If called with an
|
|
/// invalid instance_id, this function returns 0.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This can be called before any joysticks are opened. If the vendor ID isn't
|
|
/// available this function returns 0.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickVendor"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoysticks"/>
|
|
public static ushort GetJoystickVendorForID(uint instance_id) =>
|
|
PInvoke.GetJoystickVendorForID(instance_id);
|
|
|
|
/// <summary>
|
|
/// Get the USB product ID of a joystick, if available.
|
|
/// </summary>
|
|
/// <param name="instance_id">the joystick instance ID.</param>
|
|
/// <returns>
|
|
/// the USB product ID of the selected joystick. If called with an
|
|
/// invalid instance_id, this function returns 0.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This can be called before any joysticks are opened. If the product ID isn't
|
|
/// available this function returns 0.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickProduct"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoysticks"/>
|
|
public static ushort GetJoystickProductForID(uint instance_id) =>
|
|
PInvoke.GetJoystickProductForID(instance_id);
|
|
|
|
/// <summary>
|
|
/// Get the product version of a joystick, if available.
|
|
/// </summary>
|
|
/// <param name="instance_id">the joystick instance ID.</param>
|
|
/// <returns>
|
|
/// the product version of the selected joystick. If called with an
|
|
/// invalid instance_id, this function returns 0.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This can be called before any joysticks are opened. If the product version
|
|
/// isn't available this function returns 0.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickProductVersion"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoysticks"/>
|
|
public static ushort GetJoystickProductVersionForID(uint instance_id) =>
|
|
PInvoke.GetJoystickProductVersionForID(instance_id);
|
|
|
|
/// <summary>
|
|
/// Get the type of a joystick, if available.
|
|
/// </summary>
|
|
/// <param name="instance_id">the joystick instance ID.</param>
|
|
/// <returns>
|
|
/// the SDL_JoystickType of the selected joystick. If called with an
|
|
/// invalid instance_id, this function returns
|
|
/// <c>SDL_JOYSTICK_TYPE_UNKNOWN</c>.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This can be called before any joysticks are opened.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickType"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoysticks"/>
|
|
public static SdlJoystickType GetJoystickTypeForID(uint instance_id) =>
|
|
PInvoke.GetJoystickTypeForID(instance_id);
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>SDL_OpenJoystick</c>. Throws instead of returning a null handle on failure.
|
|
/// </summary>
|
|
/// <param name="instance_id">the joystick instance ID.</param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the
|
|
/// <c>SDL_GetError</c> text.</exception>
|
|
public static SdlJoystick OpenJoystick(uint instance_id)
|
|
{
|
|
SdlJoystick result = PInvoke.OpenJoystick(instance_id);
|
|
if (result.IsNull())
|
|
{
|
|
throw SdlException.FromError("SDL_OpenJoystick failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>SDL_GetJoystickFromID</c>.
|
|
/// </summary>
|
|
/// <param name="instance_id">the instance ID to get the SDL_Joystick for.</param>
|
|
/// <remarks>
|
|
/// <b>Borrowed handle:</b> the returned handle is owned by SDL (or by another object) and must not be
|
|
/// disposed. Do not call <see cref="System.IDisposable.Dispose"/> on it; doing so would free a resource
|
|
/// this call does not own. A null handle is returned on failure.
|
|
/// </remarks>
|
|
public static SdlJoystick GetJoystickFromID(uint instance_id) => PInvoke.GetJoystickFromID(instance_id);
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>SDL_GetJoystickFromPlayerIndex</c>.
|
|
/// </summary>
|
|
/// <param name="player_index">the player index to get the SDL_Joystick for.</param>
|
|
/// <remarks>
|
|
/// <b>Borrowed handle:</b> the returned handle is owned by SDL (or by another object) and must not be
|
|
/// disposed. Do not call <see cref="System.IDisposable.Dispose"/> on it; doing so would free a resource
|
|
/// this call does not own. A null handle is returned on failure.
|
|
/// </remarks>
|
|
public static SdlJoystick GetJoystickFromPlayerIndex(int player_index) =>
|
|
PInvoke.GetJoystickFromPlayerIndex(player_index);
|
|
|
|
/// <summary>
|
|
/// Attach a new virtual joystick.
|
|
/// </summary>
|
|
/// <param name="desc">joystick description, initialized using SDL_INIT_INTERFACE().</param>
|
|
/// <returns>
|
|
/// the joystick instance ID, or 0 on failure; call SDL_GetError() for
|
|
/// more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// Once attached, the app can send joystick inputs to the new virtual joystick
|
|
/// using SDL_SetJoystickVirtualAxis(), etc.
|
|
/// </para>
|
|
/// <para>
|
|
/// When no longer needed, the virtual joystick can be removed by calling
|
|
/// SDL_DetachVirtualJoystick().
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.DetachVirtualJoystick"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualAxis"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualButton"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualBall"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualHat"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualTouchpad"/>
|
|
public static uint AttachVirtualJoystick(SdlVirtualJoystickDesc* desc) =>
|
|
PInvoke.AttachVirtualJoystick(desc);
|
|
|
|
/// <summary>
|
|
/// Detach a virtual joystick.
|
|
/// </summary>
|
|
/// <param name="instance_id">
|
|
/// the joystick instance ID, previously returned from
|
|
/// SDL_AttachVirtualJoystick().
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.AttachVirtualJoystick"/>
|
|
public static bool DetachVirtualJoystick(uint instance_id) =>
|
|
PInvoke.DetachVirtualJoystick(instance_id) != 0;
|
|
|
|
/// <summary>
|
|
/// Query whether or not a joystick is virtual.
|
|
/// </summary>
|
|
/// <param name="instance_id">the joystick instance ID.</param>
|
|
/// <returns>true if the joystick is virtual, false otherwise.</returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
public static bool IsJoystickVirtual(uint instance_id) => PInvoke.IsJoystickVirtual(instance_id) != 0;
|
|
|
|
/// <summary>
|
|
/// Set the state of an axis on an opened virtual joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the virtual joystick on which to set state.</param>
|
|
/// <param name="axis">the index of the axis on the virtual joystick to update.</param>
|
|
/// <param name="value">the new value for the specified axis.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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
|
|
/// <c>SDL_JOYSTICK_AXIS_MIN</c>.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualButton"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualBall"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualHat"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualTouchpad"/>
|
|
public static bool SetJoystickVirtualAxis(SdlJoystick joystick, int axis, short value) =>
|
|
PInvoke.SetJoystickVirtualAxis(joystick, axis, value) != 0;
|
|
|
|
/// <summary>
|
|
/// Generate ball motion on an opened virtual joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the virtual joystick on which to set state.</param>
|
|
/// <param name="ball">the index of the ball on the virtual joystick to update.</param>
|
|
/// <param name="xrel">the relative motion on the X axis.</param>
|
|
/// <param name="yrel">the relative motion on the Y axis.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualAxis"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualButton"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualHat"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualTouchpad"/>
|
|
public static bool SetJoystickVirtualBall(SdlJoystick joystick, int ball, short xrel, short yrel) =>
|
|
PInvoke.SetJoystickVirtualBall(joystick, ball, xrel, yrel) != 0;
|
|
|
|
/// <summary>
|
|
/// Set the state of a button on an opened virtual joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the virtual joystick on which to set state.</param>
|
|
/// <param name="button">the index of the button on the virtual joystick to update.</param>
|
|
/// <param name="down">true if the button is pressed, false otherwise.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualAxis"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualBall"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualHat"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualTouchpad"/>
|
|
public static bool SetJoystickVirtualButton(SdlJoystick joystick, int button, bool down) =>
|
|
PInvoke.SetJoystickVirtualButton(joystick, button, down ? (byte)1 : (byte)0) != 0;
|
|
|
|
/// <summary>
|
|
/// Set the state of a hat on an opened virtual joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the virtual joystick on which to set state.</param>
|
|
/// <param name="hat">the index of the hat on the virtual joystick to update.</param>
|
|
/// <param name="value">the new value for the specified hat.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualAxis"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualButton"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualBall"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualTouchpad"/>
|
|
public static bool SetJoystickVirtualHat(SdlJoystick joystick, int hat, byte value) =>
|
|
PInvoke.SetJoystickVirtualHat(joystick, hat, value) != 0;
|
|
|
|
/// <summary>
|
|
/// Set touchpad finger state on an opened virtual joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the virtual joystick on which to set state.</param>
|
|
/// <param name="touchpad">
|
|
/// the index of the touchpad on the virtual joystick to
|
|
/// update.
|
|
/// </param>
|
|
/// <param name="finger">the index of the finger on the touchpad to set.</param>
|
|
/// <param name="down">true if the finger is pressed, false if the finger is released.</param>
|
|
/// <param name="x">
|
|
/// the x coordinate of the finger on the touchpad, normalized 0 to 1,
|
|
/// with the origin in the upper left.
|
|
/// </param>
|
|
/// <param name="y">
|
|
/// the y coordinate of the finger on the touchpad, normalized 0 to 1,
|
|
/// with the origin in the upper left.
|
|
/// </param>
|
|
/// <param name="pressure">the pressure of the finger.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualAxis"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualButton"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualBall"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualHat"/>
|
|
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;
|
|
|
|
/// <summary>
|
|
/// Send a sensor update for an opened virtual joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the virtual joystick on which to set state.</param>
|
|
/// <param name="type">the type of the sensor on the virtual joystick to update.</param>
|
|
/// <param name="sensor_timestamp">
|
|
/// a 64-bit timestamp in nanoseconds associated with
|
|
/// the sensor reading.
|
|
/// </param>
|
|
/// <param name="data">the data associated with the sensor reading.</param>
|
|
/// <param name="num_values">the number of values pointed to by <c>data</c>.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualAxis"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualButton"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualBall"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualHat"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickVirtualTouchpad"/>
|
|
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;
|
|
|
|
/// <summary>
|
|
/// Get the properties associated with a joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the SDL_Joystick obtained from SDL_OpenJoystick().</param>
|
|
/// <returns>
|
|
/// a valid property ID on success or 0 on failure; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The following read-only properties are provided by SDL:
|
|
/// </para>
|
|
/// <para>
|
|
/// - <c>SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN</c>: true if this joystick has an
|
|
/// LED that has adjustable brightness
|
|
/// - <c>SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN</c>: true if this joystick has an LED
|
|
/// that has adjustable color
|
|
/// - <c>SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN</c>: true if this joystick has a
|
|
/// player LED
|
|
/// - <c>SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN</c>: true if this joystick has
|
|
/// left/right rumble
|
|
/// - <c>SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN</c>: true if this joystick has
|
|
/// simple trigger rumble
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
public static uint GetJoystickProperties(SdlJoystick joystick) => PInvoke.GetJoystickProperties(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the implementation dependent name of a joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the SDL_Joystick obtained from SDL_OpenJoystick().</param>
|
|
/// <returns>
|
|
/// the name of the selected joystick. If no name can be found, this
|
|
/// function returns NULL; call SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickNameForID"/>
|
|
public static string? GetJoystickName(SdlJoystick joystick) => PInvoke.GetJoystickName(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the implementation dependent path of a joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the SDL_Joystick obtained from SDL_OpenJoystick().</param>
|
|
/// <returns>
|
|
/// the path of the selected joystick. If no path can be found, this
|
|
/// function returns NULL; call SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickPathForID"/>
|
|
public static string? GetJoystickPath(SdlJoystick joystick) => PInvoke.GetJoystickPath(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the player index of an opened joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the SDL_Joystick obtained from SDL_OpenJoystick().</param>
|
|
/// <returns>the player index, or -1 if it's not available.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// For XInput controllers this returns the XInput user index. Many joysticks
|
|
/// will not be able to supply this information.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickPlayerIndex"/>
|
|
public static int GetJoystickPlayerIndex(SdlJoystick joystick) => PInvoke.GetJoystickPlayerIndex(joystick);
|
|
|
|
/// <summary>
|
|
/// Set the player index of an opened joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the SDL_Joystick obtained from SDL_OpenJoystick().</param>
|
|
/// <param name="player_index">
|
|
/// player index to assign to this joystick, or -1 to clear
|
|
/// the player index and turn off player LEDs.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickPlayerIndex"/>
|
|
public static bool SetJoystickPlayerIndex(SdlJoystick joystick, int player_index) =>
|
|
PInvoke.SetJoystickPlayerIndex(joystick, player_index) != 0;
|
|
|
|
/// <summary>
|
|
/// Get the implementation-dependent GUID for the joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the SDL_Joystick obtained from SDL_OpenJoystick().</param>
|
|
/// <returns>
|
|
/// the GUID of the given joystick. If called on an invalid index,
|
|
/// this function returns a zero GUID; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This function requires an open joystick.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickGuidForID"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GuidToString"/>
|
|
public static SdlGuid GetJoystickGuid(SdlJoystick joystick) => PInvoke.GetJoystickGuid(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the USB vendor ID of an opened joystick, if available.
|
|
/// </summary>
|
|
/// <param name="joystick">the SDL_Joystick obtained from SDL_OpenJoystick().</param>
|
|
/// <returns>the USB vendor ID of the selected joystick, or 0 if unavailable.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If the vendor ID isn't available this function returns 0.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickVendorForID"/>
|
|
public static ushort GetJoystickVendor(SdlJoystick joystick) => PInvoke.GetJoystickVendor(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the USB product ID of an opened joystick, if available.
|
|
/// </summary>
|
|
/// <param name="joystick">the SDL_Joystick obtained from SDL_OpenJoystick().</param>
|
|
/// <returns>the USB product ID of the selected joystick, or 0 if unavailable.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If the product ID isn't available this function returns 0.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickProductForID"/>
|
|
public static ushort GetJoystickProduct(SdlJoystick joystick) => PInvoke.GetJoystickProduct(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the product version of an opened joystick, if available.
|
|
/// </summary>
|
|
/// <param name="joystick">the SDL_Joystick obtained from SDL_OpenJoystick().</param>
|
|
/// <returns>the product version of the selected joystick, or 0 if unavailable.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If the product version isn't available this function returns 0.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickProductVersionForID"/>
|
|
public static ushort GetJoystickProductVersion(SdlJoystick joystick) =>
|
|
PInvoke.GetJoystickProductVersion(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the firmware version of an opened joystick, if available.
|
|
/// </summary>
|
|
/// <param name="joystick">the SDL_Joystick obtained from SDL_OpenJoystick().</param>
|
|
/// <returns>
|
|
/// the firmware version of the selected joystick, or 0 if
|
|
/// unavailable.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If the firmware version isn't available this function returns 0.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
public static ushort GetJoystickFirmwareVersion(SdlJoystick joystick) =>
|
|
PInvoke.GetJoystickFirmwareVersion(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the serial number of an opened joystick, if available.
|
|
/// </summary>
|
|
/// <param name="joystick">the SDL_Joystick obtained from SDL_OpenJoystick().</param>
|
|
/// <returns>
|
|
/// the serial number of the selected joystick, or NULL if
|
|
/// unavailable.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Returns the serial number of the joystick, or NULL if it is not available.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
public static string? GetJoystickSerial(SdlJoystick joystick) => PInvoke.GetJoystickSerial(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the type of an opened joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the SDL_Joystick obtained from SDL_OpenJoystick().</param>
|
|
/// <returns>the SDL_JoystickType of the selected joystick.</returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickTypeForID"/>
|
|
public static SdlJoystickType GetJoystickType(SdlJoystick joystick) => PInvoke.GetJoystickType(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the device information encoded in a SDL_GUID structure.
|
|
/// </summary>
|
|
/// <param name="guid">the SDL_GUID you wish to get info about.</param>
|
|
/// <param name="vendor">
|
|
/// a pointer filled in with the device VID, or 0 if not
|
|
/// available.
|
|
/// </param>
|
|
/// <param name="product">
|
|
/// a pointer filled in with the device PID, or 0 if not
|
|
/// available.
|
|
/// </param>
|
|
/// <param name="version">
|
|
/// a pointer filled in with the device version, or 0 if not
|
|
/// available.
|
|
/// </param>
|
|
/// <param name="crc16">
|
|
/// a pointer filled in with a CRC used to distinguish different
|
|
/// products with the same VID/PID, or 0 if not available.
|
|
/// </param>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickGuidForID"/>
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the status of a specified joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the joystick to query.</param>
|
|
/// <returns>
|
|
/// true if the joystick has been opened, false if it has not; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
public static bool JoystickConnected(SdlJoystick joystick) => PInvoke.JoystickConnected(joystick) != 0;
|
|
|
|
/// <summary>
|
|
/// Get the instance ID of an opened joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">an SDL_Joystick structure containing joystick information.</param>
|
|
/// <returns>
|
|
/// the instance ID of the specified joystick on success or 0 on
|
|
/// failure; call SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
public static uint GetJoystickID(SdlJoystick joystick) => PInvoke.GetJoystickID(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the number of general axis controls on a joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">an SDL_Joystick structure containing joystick information.</param>
|
|
/// <returns>
|
|
/// the number of axis controls/number of axes on success or -1 on
|
|
/// failure; call SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickAxis"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickBalls"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickButtons"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickHats"/>
|
|
public static int GetNumJoystickAxes(SdlJoystick joystick) => PInvoke.GetNumJoystickAxes(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the number of trackballs on a joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">an SDL_Joystick structure containing joystick information.</param>
|
|
/// <returns>
|
|
/// the number of trackballs on success or -1 on failure; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Joystick trackballs have only relative motion events associated with them
|
|
/// and their state cannot be polled.
|
|
/// </para>
|
|
/// <para>
|
|
/// Most joysticks do not have trackballs.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickBall"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickAxes"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickButtons"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickHats"/>
|
|
public static int GetNumJoystickBalls(SdlJoystick joystick) => PInvoke.GetNumJoystickBalls(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the number of POV hats on a joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">an SDL_Joystick structure containing joystick information.</param>
|
|
/// <returns>
|
|
/// the number of POV hats on success or -1 on failure; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickHat"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickAxes"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickBalls"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickButtons"/>
|
|
public static int GetNumJoystickHats(SdlJoystick joystick) => PInvoke.GetNumJoystickHats(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the number of buttons on a joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">an SDL_Joystick structure containing joystick information.</param>
|
|
/// <returns>
|
|
/// the number of buttons on success or -1 on failure; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetJoystickButton"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickAxes"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickBalls"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickHats"/>
|
|
public static int GetNumJoystickButtons(SdlJoystick joystick) => PInvoke.GetNumJoystickButtons(joystick);
|
|
|
|
/// <summary>
|
|
/// Set the state of joystick event processing.
|
|
/// </summary>
|
|
/// <param name="enabled">whether to process joystick events or not.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If joystick events are disabled, you must call SDL_UpdateJoysticks()
|
|
/// yourself and check the state of the joystick when you want joystick
|
|
/// information.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.JoystickEventsEnabled"/>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.UpdateJoysticks"/>
|
|
public static void SetJoystickEventsEnabled(bool enabled) =>
|
|
PInvoke.SetJoystickEventsEnabled(enabled ? (byte)1 : (byte)0);
|
|
|
|
/// <summary>
|
|
/// Query the state of joystick event processing.
|
|
/// </summary>
|
|
/// <returns>true if joystick events are being processed, false otherwise.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If joystick events are disabled, you must call SDL_UpdateJoysticks()
|
|
/// yourself and check the state of the joystick when you want joystick
|
|
/// information.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.SetJoystickEventsEnabled"/>
|
|
public static bool JoystickEventsEnabled() => PInvoke.JoystickEventsEnabled() != 0;
|
|
|
|
/// <summary>
|
|
/// Update the current state of the open joysticks.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This is called automatically by the event loop if any joystick events are
|
|
/// enabled.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
public static void UpdateJoysticks() => PInvoke.UpdateJoysticks();
|
|
|
|
/// <summary>
|
|
/// Get the current state of an axis control on a joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">an SDL_Joystick structure containing joystick information.</param>
|
|
/// <param name="axis">the axis to query; the axis indices start at index 0.</param>
|
|
/// <returns>
|
|
/// a 16-bit signed integer representing the current position of the
|
|
/// axis or 0 on failure; call SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickAxes"/>
|
|
public static short GetJoystickAxis(SdlJoystick joystick, int axis) =>
|
|
PInvoke.GetJoystickAxis(joystick, axis);
|
|
|
|
/// <summary>
|
|
/// Get the initial state of an axis control on a joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">an SDL_Joystick structure containing joystick information.</param>
|
|
/// <param name="axis">the axis to query; the axis indices start at index 0.</param>
|
|
/// <param name="state">upon return, the initial value is supplied here.</param>
|
|
/// <returns>true if this axis has any initial value, or false if not.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The state is a value ranging from -32768 to 32767.
|
|
/// </para>
|
|
/// <para>
|
|
/// The axis indices start at index 0.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
public static bool GetJoystickAxisInitialState(SdlJoystick joystick, int axis, out short state)
|
|
{
|
|
state = default;
|
|
fixed (short* statePtr = &state)
|
|
{
|
|
return PInvoke.GetJoystickAxisInitialState(joystick, axis, statePtr) != 0;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the ball axis change since the last poll.
|
|
/// </summary>
|
|
/// <param name="joystick">the SDL_Joystick to query.</param>
|
|
/// <param name="ball">the ball index to query; ball indices start at index 0.</param>
|
|
/// <param name="dx">stores the difference in the x axis position since the last poll.</param>
|
|
/// <param name="dy">stores the difference in the y axis position since the last poll.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Trackballs can only return relative motion since the last call to
|
|
/// SDL_GetJoystickBall(), these motion deltas are placed into <c>dx</c> and <c>dy</c>.
|
|
/// </para>
|
|
/// <para>
|
|
/// Most joysticks do not have trackballs.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickBalls"/>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the current state of a POV hat on a joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">an SDL_Joystick structure containing joystick information.</param>
|
|
/// <param name="hat">the hat index to get the state from; indices start at index 0.</param>
|
|
/// <returns>the current hat position.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The returned value will be one of the <c>SDL_HAT_*</c> values.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickHats"/>
|
|
public static byte GetJoystickHat(SdlJoystick joystick, int hat) => PInvoke.GetJoystickHat(joystick, hat);
|
|
|
|
/// <summary>
|
|
/// Get the current state of a button on a joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">an SDL_Joystick structure containing joystick information.</param>
|
|
/// <param name="button">
|
|
/// the button index to get the state from; indices start at
|
|
/// index 0.
|
|
/// </param>
|
|
/// <returns>true if the button is pressed, false otherwise.</returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.GetNumJoystickButtons"/>
|
|
public static bool GetJoystickButton(SdlJoystick joystick, int button) =>
|
|
PInvoke.GetJoystickButton(joystick, button) != 0;
|
|
|
|
/// <summary>
|
|
/// Start a rumble effect.
|
|
/// </summary>
|
|
/// <param name="joystick">the joystick to vibrate.</param>
|
|
/// <param name="low_frequency_rumble">
|
|
/// the intensity of the low frequency (left)
|
|
/// rumble motor, from 0 to 0xFFFF.
|
|
/// </param>
|
|
/// <param name="high_frequency_rumble">
|
|
/// the intensity of the high frequency (right)
|
|
/// rumble motor, from 0 to 0xFFFF.
|
|
/// </param>
|
|
/// <param name="duration_ms">the duration of the rumble effect, in milliseconds.</param>
|
|
/// <returns>true, or false if rumble isn't supported on this joystick.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Each call to this function cancels any previous rumble effect, and calling
|
|
/// it with 0 intensity stops any rumbling.
|
|
/// </para>
|
|
/// <para>
|
|
/// This function requires you to process SDL events or call
|
|
/// SDL_UpdateJoysticks() to update rumble state.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
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;
|
|
|
|
/// <summary>
|
|
/// Start a rumble effect in the joystick's triggers.
|
|
/// </summary>
|
|
/// <param name="joystick">the joystick to vibrate.</param>
|
|
/// <param name="left_rumble">
|
|
/// the intensity of the left trigger rumble motor, from 0
|
|
/// to 0xFFFF.
|
|
/// </param>
|
|
/// <param name="right_rumble">
|
|
/// the intensity of the right trigger rumble motor, from 0
|
|
/// to 0xFFFF.
|
|
/// </param>
|
|
/// <param name="duration_ms">the duration of the rumble effect, in milliseconds.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Each call to this function cancels any previous trigger rumble effect, and
|
|
/// calling it with 0 intensity stops any rumbling.
|
|
/// </para>
|
|
/// <para>
|
|
/// Note that this is rumbling of the <em>triggers</em> 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// This function requires you to process SDL events or call
|
|
/// SDL_UpdateJoysticks() to update rumble state.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.RumbleJoystick"/>
|
|
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;
|
|
|
|
/// <summary>
|
|
/// Update a joystick's LED color.
|
|
/// </summary>
|
|
/// <param name="joystick">the joystick to update.</param>
|
|
/// <param name="red">the intensity of the red LED.</param>
|
|
/// <param name="green">the intensity of the green LED.</param>
|
|
/// <param name="blue">the intensity of the blue LED.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// An example of a joystick LED is the light on the back of a PlayStation 4's
|
|
/// DualShock 4 controller.
|
|
/// </para>
|
|
/// <para>
|
|
/// For joysticks with a single color LED, the maximum of the RGB values will
|
|
/// be used as the LED brightness.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
public static bool SetJoystickLED(SdlJoystick joystick, byte red, byte green, byte blue) =>
|
|
PInvoke.SetJoystickLED(joystick, red, green, blue) != 0;
|
|
|
|
/// <summary>
|
|
/// Send a joystick specific effect packet.
|
|
/// </summary>
|
|
/// <param name="joystick">the joystick to affect.</param>
|
|
/// <param name="data">the data to send to the joystick.</param>
|
|
/// <param name="size">the size of the data to send to the joystick.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
public static bool SendJoystickEffect(SdlJoystick joystick, void* data, int size) =>
|
|
PInvoke.SendJoystickEffect(joystick, data, size) != 0;
|
|
|
|
/// <summary>
|
|
/// Close a joystick previously opened with SDL_OpenJoystick().
|
|
/// </summary>
|
|
/// <param name="joystick">the joystick device to close.</param>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Sdl.PInvoke.OpenJoystick"/>
|
|
public static void CloseJoystick(SdlJoystick joystick) => PInvoke.CloseJoystick(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the connection state of a joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the joystick to query.</param>
|
|
/// <returns>
|
|
/// the connection state on success or
|
|
/// <c>SDL_JOYSTICK_CONNECTION_INVALID</c> on failure; call SDL_GetError()
|
|
/// for more information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
public static SdlJoystickConnectionState GetJoystickConnectionState(SdlJoystick joystick) =>
|
|
PInvoke.GetJoystickConnectionState(joystick);
|
|
|
|
/// <summary>
|
|
/// Get the battery state of a joystick.
|
|
/// </summary>
|
|
/// <param name="joystick">the joystick to query.</param>
|
|
/// <param name="percent">
|
|
/// 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.
|
|
/// </param>
|
|
/// <returns>
|
|
/// the current battery state or <c>SDL_POWERSTATE_ERROR</c> on failure;
|
|
/// call SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL 3.2.0.
|
|
/// </since>
|
|
public static SdlPowerState GetJoystickPowerInfo(SdlJoystick joystick, out int percent)
|
|
{
|
|
percent = default;
|
|
fixed (int* percentPtr = &percent)
|
|
{
|
|
return PInvoke.GetJoystickPowerInfo(joystick, percentPtr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|