diff --git a/SDL3-CS/SDL3/SDL_audio.cs b/SDL3-CS/SDL3/SDL_audio.cs index df24453..1a0fe41 100644 --- a/SDL3-CS/SDL3/SDL_audio.cs +++ b/SDL3-CS/SDL3/SDL_audio.cs @@ -58,5 +58,19 @@ namespace SDL [Macro] public static int SDL_AUDIO_FRAMESIZE(SDL_AudioSpec x) => SDL_AUDIO_BYTESIZE((x).format) * (x).channels; + + public static unsafe SDLArray? SDL_GetAudioOutputDevices() + { + int count; + var array = SDL_GetAudioOutputDevices(&count); + return SDLArray.Create(array, count); + } + + public static unsafe SDLArray? SDL_GetAudioCaptureDevices() + { + int count; + var array = SDL_GetAudioCaptureDevices(&count); + return SDLArray.Create(array, count); + } } } diff --git a/SDL3-CS/SDL3/SDL_camera.cs b/SDL3-CS/SDL3/SDL_camera.cs index f6f995a..b6a664e 100644 --- a/SDL3-CS/SDL3/SDL_camera.cs +++ b/SDL3-CS/SDL3/SDL_camera.cs @@ -7,4 +7,21 @@ namespace SDL { [Typedef] public enum SDL_CameraDeviceID : UInt32; + + public static partial class SDL3 + { + public static unsafe SDLArray? SDL_GetCameraDevices() + { + int count; + var array = SDL_GetCameraDevices(&count); + return SDLArray.Create(array, count); + } + + public static unsafe SDLArray? SDL_GetCameraDeviceSupportedFormats(SDL_CameraDeviceID devid) + { + int count; + var array = SDL_GetCameraDeviceSupportedFormats(devid, &count); + return SDLArray.Create(array, count); + } + } } diff --git a/SDL3-CS/SDL3/SDL_gamepad.cs b/SDL3-CS/SDL3/SDL_gamepad.cs new file mode 100644 index 0000000..f1c0a85 --- /dev/null +++ b/SDL3-CS/SDL3/SDL_gamepad.cs @@ -0,0 +1,35 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Runtime.InteropServices; + +namespace SDL +{ + public static partial class SDL3 + { + /// + /// An array of that can be passed to . + /// + public static unsafe SDLArray? SDL_GetGamepadMappings() + { + int count; + IntPtr* array = (IntPtr*)SDL_GetGamepadMappings(&count); + return SDLArray.Create(array, count); + } + + public static unsafe SDLArray? SDL_GetGamepads() + { + int count; + var array = SDL_GetGamepads(&count); + return SDLArray.Create(array, count); + } + + public static unsafe SDLPointerArray? SDL_GetGamepadBindings(SDL_Gamepad* gamepad) + { + int count; + var array = SDL_GetGamepadBindings(gamepad, &count); + return SDLArray.Create(array, count); + } + } +} diff --git a/SDL3-CS/SDL3/SDL_haptic.cs b/SDL3-CS/SDL3/SDL_haptic.cs index 0d82795..eede833 100644 --- a/SDL3-CS/SDL3/SDL_haptic.cs +++ b/SDL3-CS/SDL3/SDL_haptic.cs @@ -7,4 +7,14 @@ namespace SDL { [Typedef] public enum SDL_HapticID : UInt32; + + public static partial class SDL3 + { + public static unsafe SDLArray? SDL_GetHaptics() + { + int count; + var array = SDL_GetHaptics(&count); + return SDLArray.Create(array, count); + } + } } diff --git a/SDL3-CS/SDL3/SDL_joystick.cs b/SDL3-CS/SDL3/SDL_joystick.cs index 3e881d0..5dff357 100644 --- a/SDL3-CS/SDL3/SDL_joystick.cs +++ b/SDL3-CS/SDL3/SDL_joystick.cs @@ -7,4 +7,14 @@ namespace SDL { [Typedef] public enum SDL_JoystickID : UInt32; + + public static partial class SDL3 + { + public static unsafe SDLArray? SDL_GetJoysticks() + { + int count; + var array = SDL_GetJoysticks(&count); + return SDLArray.Create(array, count); + } + } } diff --git a/SDL3-CS/SDL3/SDL_keyboard.cs b/SDL3-CS/SDL3/SDL_keyboard.cs index 885fbc9..b5e32b3 100644 --- a/SDL3-CS/SDL3/SDL_keyboard.cs +++ b/SDL3-CS/SDL3/SDL_keyboard.cs @@ -12,4 +12,14 @@ namespace SDL { public SDL_Keymod Mod => (SDL_Keymod)mod; } + + public static partial class SDL3 + { + public static unsafe SDLArray? SDL_GetKeyboards() + { + int count; + var array = SDL_GetKeyboards(&count); + return SDLArray.Create(array, count); + } + } } diff --git a/SDL3-CS/SDL3/SDL_mouse.cs b/SDL3-CS/SDL3/SDL_mouse.cs index 85d61b9..62be8af 100644 --- a/SDL3-CS/SDL3/SDL_mouse.cs +++ b/SDL3-CS/SDL3/SDL_mouse.cs @@ -31,5 +31,12 @@ namespace SDL { [Macro] public static SDLButtonMask SDL_BUTTON(SDLButton button) => (SDLButtonMask)(1 << ((int)button - 1)); + + public static unsafe SDLArray? SDL_GetMice() + { + int count; + var array = SDL_GetMice(&count); + return SDLArray.Create(array, count); + } } } diff --git a/SDL3-CS/SDL3/SDL_pen.cs b/SDL3-CS/SDL3/SDL_pen.cs index 58436e8..06f064b 100644 --- a/SDL3-CS/SDL3/SDL_pen.cs +++ b/SDL3-CS/SDL3/SDL_pen.cs @@ -33,5 +33,12 @@ namespace SDL [Macro] public static SDL_PEN_CAPABILITIES SDL_PEN_AXIS_CAPABILITY(SDL_PenAxis axis) => SDL_PEN_CAPABILITY((int)axis + SDL_PEN_FLAG_AXIS_BIT_OFFSET); + + public static unsafe SDLArray? SDL_GetPens() + { + int count; + var array = SDL_GetPens(&count); + return SDLArray.Create(array, count); + } } } diff --git a/SDL3-CS/SDL3/SDL_sensor.cs b/SDL3-CS/SDL3/SDL_sensor.cs index 085a52b..2361554 100644 --- a/SDL3-CS/SDL3/SDL_sensor.cs +++ b/SDL3-CS/SDL3/SDL_sensor.cs @@ -7,4 +7,14 @@ namespace SDL { [Typedef] public enum SDL_SensorID : UInt32; + + public static partial class SDL3 + { + public static unsafe SDLArray? SDL_GetSensors() + { + int count; + var array = SDL_GetSensors(&count); + return SDLArray.Create(array, count); + } + } } diff --git a/SDL3-CS/SDL3/SDL_touch.cs b/SDL3-CS/SDL3/SDL_touch.cs index b07724f..772ac51 100644 --- a/SDL3-CS/SDL3/SDL_touch.cs +++ b/SDL3-CS/SDL3/SDL_touch.cs @@ -18,5 +18,12 @@ namespace SDL [Constant] public const SDL_TouchID SDL_MOUSE_TOUCHID = unchecked((SDL_TouchID)(-1)); + + public static unsafe SDLArray? SDL_GetTouchDevices() + { + int count; + var array = SDL_GetTouchDevices(&count); + return SDLArray.Create(array, count); + } } } diff --git a/SDL3-CS/SDL3/SDL_video.cs b/SDL3-CS/SDL3/SDL_video.cs index 61d8d63..83c02fe 100644 --- a/SDL3-CS/SDL3/SDL_video.cs +++ b/SDL3-CS/SDL3/SDL_video.cs @@ -53,5 +53,19 @@ namespace SDL [Macro] public static bool SDL_WINDOWPOS_ISCENTERED(int X) => (((X) & 0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK); + + public static unsafe SDLArray? SDL_GetDisplays() + { + int count; + var array = SDL_GetDisplays(&count); + return SDLArray.Create(array, count); + } + + public static unsafe SDLPointerArray? SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID) + { + int count; + var array = SDL_GetFullscreenDisplayModes(displayID, &count); + return SDLArray.Create(array, count); + } } } diff --git a/SDL3-CS/SDLArray.cs b/SDL3-CS/SDLArray.cs new file mode 100644 index 0000000..65858f5 --- /dev/null +++ b/SDL3-CS/SDLArray.cs @@ -0,0 +1,63 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; + +namespace SDL +{ + public sealed unsafe class SDLArray : IDisposable + where T : unmanaged + { + private readonly T* array; + public readonly int Count; + private bool isDisposed; + + internal SDLArray(T* array, int count) + { + this.array = array; + Count = count; + } + + public T this[int index] + { + get + { + ObjectDisposedException.ThrowIf(isDisposed, this); + ArgumentOutOfRangeException.ThrowIfNegative(index); + ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, Count); + return array[index]; + } + } + + public void Dispose() + { + if (isDisposed) + return; + + isDisposed = true; + SDL3.SDL_free(array); + } + } + + internal static unsafe class SDLArray + { + internal static SDLArray? Create(T* array, int count) + where T : unmanaged + { + if (array == null) + return null; + + return new SDLArray(array, count); + } + + internal static SDLPointerArray? Create(T** array, int count) + where T : unmanaged + { + if (array == null) + return null; + + return new SDLPointerArray(array, count); + } + + } +} diff --git a/SDL3-CS/SDLPointerArray.cs b/SDL3-CS/SDLPointerArray.cs new file mode 100644 index 0000000..806266b --- /dev/null +++ b/SDL3-CS/SDLPointerArray.cs @@ -0,0 +1,44 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Diagnostics; + +namespace SDL +{ + // T* can't be used as a type parameter, so this has to be a separate class + public sealed unsafe class SDLPointerArray : IDisposable + where T : unmanaged + { + private readonly T** array; + public readonly int Count; + private bool isDisposed; + + internal SDLPointerArray(T** array, int count) + { + this.array = array; + Count = count; + } + + public T this[int index] + { + get + { + ObjectDisposedException.ThrowIf(isDisposed, this); + ArgumentOutOfRangeException.ThrowIfNegative(index); + ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, Count); + Debug.Assert(array[index] != null); + return *array[index]; + } + } + + public void Dispose() + { + if (isDisposed) + return; + + isDisposed = true; + SDL3.SDL_free(array); + } + } +}