diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 9b523bd..8d231db 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -15,16 +15,16 @@ jobs:
name: Unit Tests & Coverage
strategy:
matrix:
- os: [ubuntu-22.04, windows-latest, macos-latest]
+ os: [ubuntu-24.04, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- - name: Setup .NET 9
+ - name: Setup .NET 10
uses: actions/setup-dotnet@v4
with:
- dotnet-version: '9.0.x'
+ dotnet-version: '10.0.x'
# --- SDL3 installation (Linux) ---
- name: Install build dependencies (Linux)
@@ -89,7 +89,7 @@ jobs:
$dll = Get-ChildItem "$env:TEMP\sdl3" -Recurse -Filter "SDL3.dll" | Select-Object -First 1
if (-not $dll) { throw "SDL3.dll not found in extracted archive" }
Write-Host "Found SDL3.dll at: $($dll.FullName)"
- $testBin = "tests\SharpSDL3.Tests\bin\Release\net9.0"
+ $testBin = "tests\SharpSDL3.Tests\bin\Release\net10.0"
New-Item -ItemType Directory -Path $testBin -Force | Out-Null
Copy-Item $dll.FullName -Destination $testBin -Force
@@ -112,11 +112,11 @@ jobs:
--collect:"XPlat Code Coverage"
- name: Install ReportGenerator
- if: matrix.os == 'ubuntu-22.04'
+ if: matrix.os == 'ubuntu-24.04'
run: dotnet tool install --global dotnet-reportgenerator-globaltool
- name: Generate coverage report
- if: matrix.os == 'ubuntu-22.04'
+ if: matrix.os == 'ubuntu-24.04'
shell: bash
run: |
COV=$(find ./TestResults -name "coverage.cobertura.xml" -type f | head -1)
@@ -133,7 +133,7 @@ jobs:
fi
- name: Post coverage summary to job
- if: matrix.os == 'ubuntu-22.04' && always()
+ if: matrix.os == 'ubuntu-24.04' && always()
shell: bash
run: |
if [ -f ./TestResults/CoverageReport/SummaryGithub.md ]; then
@@ -149,7 +149,7 @@ jobs:
./TestResults/**/*.trx
- name: Upload coverage report
- if: matrix.os == 'ubuntu-22.04' && always()
+ if: matrix.os == 'ubuntu-24.04' && always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
@@ -160,15 +160,15 @@ jobs:
package:
name: Build NuGet Package
needs: test
- runs-on: ubuntu-22.04
+ runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- - name: Setup .NET 9
+ - name: Setup .NET 10
uses: actions/setup-dotnet@v4
with:
- dotnet-version: '9.0.x'
+ dotnet-version: '10.0.x'
- name: Restore
run: dotnet restore SDL3/SharpSDL3.csproj
@@ -191,15 +191,15 @@ jobs:
fuzz:
name: Fuzz Tests
- runs-on: ubuntu-22.04
+ runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- - name: Setup .NET 9
+ - name: Setup .NET 10
uses: actions/setup-dotnet@v4
with:
- dotnet-version: '9.0.x'
+ dotnet-version: '10.0.x'
- name: Install build dependencies
run: |
diff --git a/SDL3/CallerOwnedStringMarshaller.cs b/SDL3/CallerOwnedStringMarshaller.cs
index fe720db..456a900 100644
--- a/SDL3/CallerOwnedStringMarshaller.cs
+++ b/SDL3/CallerOwnedStringMarshaller.cs
@@ -14,7 +14,7 @@ public static unsafe class CallerOwnedStringMarshaller {
///
/// A managed string.
public static string ConvertToManaged(nint unmanaged) {
- string? result = Marshal.PtrToStringUTF8(unmanaged);
+ var result = Marshal.PtrToStringUTF8(unmanaged);
return result ?? "";
}
diff --git a/SDL3/Enums/Colorspace.cs b/SDL3/Enums/Colorspace.cs
index 97fb9c2..c9679de 100644
--- a/SDL3/Enums/Colorspace.cs
+++ b/SDL3/Enums/Colorspace.cs
@@ -1,17 +1,78 @@
namespace SharpSDL3.Enums;
+///
+/// Colorspace definitions.
+///
public enum Colorspace {
- Unknown = 0,
- Srgb = 301991328,
- SrgbLinear = 301991168,
- Hdr10 = 301999616,
- Jpeg = 570426566,
- Bt601Limited = 554703046,
- Bt601Full = 571480262,
- Bt709Limited = 554697761,
- Bt709Full = 571474977,
- Bt2020Limited = 554706441,
- Bt2020Full = 571483657,
- RgbDefault = 301991328,
- YuvDefault = 570426566
+ ///
+ /// Unknown Colorspace
+ ///
+ Unknown = 0x0,
+
+ ///
+ /// sRGB is a gamma corrected colorspace, and the default colorspace for SDL rendering and 8-bit RGB surfaces
+ ///
+ Srgb = 0x120005A0,
+
+ ///
+ /// This is a linear colorspace and the default colorspace for floating point surfaces. On Windows this is the scRGB colorspace, and on Apple platforms this is kCGColorSpaceExtendedLinearSRGB for EDR content
+ ///
+ SrgbLinear = 0x12000500,
+
+ ///
+ /// HDR10 is a non-linear HDR colorspace and the default colorspace for 10-bit surfaces
+ ///
+ Hdr10 = 0x12002600,
+
+ ///
+ /// JPEG/JFIF YUV colorspace. Full range BT.601 matrix, used by JPEG images and many web/consumer formats.
+ /// Chroma is not subsampled (4:4:4).
+ ///
+ Jpeg = 0x220004C6,
+
+ ///
+ /// BT.601 limited range YUV colorspace. Standard definition TV colorspace (NTSC/PAL).
+ /// Limited range means luma is clamped to [16–235] and chroma to [16–240].
+ ///
+ Bt601Limited = 0x211018C6,
+
+ ///
+ /// BT.601 full range YUV colorspace. Standard definition TV primaries with full [0–255] luma and chroma range.
+ /// Commonly used in MJPEG and some webcam outputs.
+ ///
+ Bt601Full = 0x221018C6,
+
+ ///
+ /// BT.709 limited range YUV colorspace. High definition TV standard (1080p/720p broadcast).
+ /// Limited range luma [16–235], the dominant format for HD video delivery and Blu-ray.
+ ///
+ Bt709Limited = 0x21100421,
+
+ ///
+ /// BT.709 full range YUV colorspace. HD primaries with full [0–255] range.
+ /// Less common than limited range; sometimes seen in PC-captured HD content.
+ ///
+ Bt709Full = 0x22100421,
+
+ ///
+ /// BT.2020 limited range YUV colorspace. Ultra HD / 4K broadcast standard with a much wider color gamut
+ /// than BT.709. Limited range; used in HDR10 and HLG HDR video delivery.
+ ///
+ Bt2020Limited = 0x21102609,
+
+ ///
+ /// BT.2020 full range YUV colorspace. Same wide-gamut UHD primaries as BT.2020 Limited
+ /// but with full [0–255] range. Uncommon in broadcast; occasionally seen in professional/camera workflows.
+ ///
+ Bt2020Full = 0x22102609,
+
+ ///
+ /// The default colorspace for RGB surfaces if no colorspace is specified
+ ///
+ RgbDefault = Srgb,
+
+ ///
+ /// The default colorspace for YUV surfaces if no colorspace is specified
+ ///
+ YuvDefault = Jpeg
}
\ No newline at end of file
diff --git a/SDL3/Image/Sdl.cs b/SDL3/Image/Sdl.cs
index e20e34d..c345379 100644
--- a/SDL3/Image/Sdl.cs
+++ b/SDL3/Image/Sdl.cs
@@ -4,7 +4,8 @@
namespace SharpSDL3;
-public static unsafe partial class Sdl {
+public static unsafe partial class Sdl
+{
private const string ImageLibName = "SDL3_image";
/* WIKI CATEGORY: SDLImage */
@@ -15,23 +16,34 @@ public static unsafe partial class Sdl {
*
* A simple library to load images of various formats as SDL surfaces
*/
- /**
- * Printable format: "%d.%d.%d", MAJOR, MINOR, MICRO
- */
+
+ ///
+ /// The major version number of the SDL_image library.
+ ///
public const int ImageMajor = 3;
+ ///
+ /// The minor version number of the SDL_image library.
+ ///
public const int ImageMinor = 3;
- public const int ImageMicro = 0;
- /**
- * This is the version number macro for the current SDL_image version.
- */
+ ///
+ /// The micro (patch) version number of the SDL_image library.
+ ///
+ public const int ImageMicro = 0;
+ ///
+ /// Returns the SDL_image version as an integer.
+ ///
+ /// The SDL_image version as an integer.
public static int ImageVersion() => VersionNum(ImageMajor, ImageMinor, ImageMicro);
- /**
- * This macro will evaluate to if compiled with SDL_image at least X.Y.Z.
- */
-
+ ///
+ /// Returns if compiled with SDL_image at least X.Y.Z.
+ ///
+ /// The major version number to check against.
+ /// The minor version number to check against.
+ /// The patch version number to check against.
+ /// if compiled with SDL_image at least X.Y.Z, otherwise .
public static bool ImageVersionAtLeast(int major, int minor, int patch) =>
(ImageMajor >= major)
&& (ImageMajor > major || ImageMinor >= minor)
@@ -48,6 +60,10 @@ public static bool ImageVersionAtLeast(int major, int minor, int patch) =>
[LibraryImport(ImageLibName)]
private static partial int IMG_Version();
+ ///
+ /// Gets the version of the dynamically linked SDL_image library.
+ ///
+ /// The SDL_image version as an integer.
public static int GetImageVersion() => IMG_Version();
/**
@@ -91,7 +107,7 @@ public static bool ImageVersionAtLeast(int major, int minor, int patch) =>
* loading, much like passing a for type.
*
* If you are using SDL's 2D rendering API, there is an equivalent call to
- * load images directly into an Texture for use by the GPU without using a
+ * load images directly into a Texture for use by the GPU without using a
* software surface: call IMG_LoadTextureTyped_IO() instead.
*
* When done with the returned surface, the app should dispose of it with a
@@ -114,198 +130,257 @@ public static bool ImageVersionAtLeast(int major, int minor, int patch) =>
[LibraryImport(ImageLibName, StringMarshalling = Marshalling)]
private static partial nint IMG_LoadTyped_IO(nint src, [MarshalAs(BoolType)] bool closeio, string type);
- public static nint LoadTypedImage(nint src, bool closeio, string type) {
- if (src == nint.Zero) {
+ ///
+ /// Loads an image from an IOStream into a software surface.
+ ///
+ /// An IOStream that data will be read from.
+ /// to close/free the IOStream before returning, to leave it open.
+ /// A filename extension that represent this data ("BMP", "GIF", "PNG", etc).
+ ///
+ /// A Surface is a buffer of pixels in memory accessible by the CPU. Use
+ /// this if you plan to hand the data to something else or manipulate it
+ /// further in code.
+ ///
+ /// There are no guarantees about what format the new Surface data will be;
+ /// in many cases, SDL_image will attempt to supply a surface that exactly
+ /// matches the provided image, but in others it might have to convert (either
+ /// because the image is in a format that SDL doesn't directly support or
+ /// because it's compressed data that could reasonably uncompress to various
+ /// formats and SDL_image had to pick one). You can inspect a Surface for
+ /// its specifics, and use to then migrate to any supported
+ ///
+ ///
+ /// If the image format supports a transparent pixel, SDL will set the colorkey
+ /// for the surface. You can enable RLE acceleration on the surface afterwards
+ /// by calling: with (image, SDL_RLEACCEL, image->format->colorkey);
+ ///
+ /// If is , will be closed before returning, whether this
+ /// function succeeds or not. SDL_image reads everything it needs from
+ /// during this call in any case.
+ ///
+ /// Even though this function accepts a file type, SDL_image may still try
+ /// other decoders that are capable of detecting file type from the contents of
+ /// the image data, but may rely on the caller-provided type string for formats
+ /// If is , SDL_image will rely solely on
+ /// its ability to guess the format.
+ ///
+ /// There is a separate function to read files from disk without having to deal
+ /// with IOStream: IMG_Load("filename.jpg") will call this function and
+ /// manage those details for you, determining the file type from the filename's
+ /// extension.
+ ///
+ /// There is also IMG_Load_IO(), which is equivalent to this function except
+ /// that it will rely on SDL_image to determine what type of data it is
+ /// loading, much like passing for type.
+ ///
+ /// If you are using SDL's 2D rendering API, there is an equivalent call to
+ /// load images directly into a Texture for use by the GPU without using a
+ /// software surface: call IMG_LoadTextureTyped_IO() instead.
+ ///
+ /// When done with the returned surface, the app should dispose of it with a
+ /// call to .
+ /// Since: This function is available since SDL_image 3.0.0.
+ ///
+ /// A new SDL surface, or on error.
+ /// Thrown if is .
+ public static nint LoadTypedImageIo(nint src, bool closeio, string type)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadTyped_IO(src, closeio, type);
}
- /**
- * Load an image from a filesystem path into a software surface.
- *
- * An Surface is a buffer of pixels in memory accessible by the CPU. Use
- * this if you plan to hand the data to something else or manipulate it
- * further in code.
- *
- * There are no guarantees about what format the new Surface data will be;
- * in many cases, SDL_image will attempt to supply a surface that exactly
- * matches the provided image, but in others it might have to convert (either
- * because the image is in a format that SDL doesn't directly support or
- * because it's compressed data that could reasonably uncompress to various
- * formats and SDL_image had to pick one). You can inspect an Surface for
- * its specifics, and use SDL_ConvertSurface to then migrate to any supported
- * format.
- *
- * If the image format supports a transparent pixel, SDL will set the colorkey
- * for the surface. You can enable RLE acceleration on the surface afterwards
- * by calling: SDL_SetSurfaceColorKey(image, SDL_RLEACCEL,
- * image->format->colorkey);
- *
- * There is a separate function to read files from an IOStream, if you
- * need an i/o abstraction to provide data from anywhere instead of a simple
- * filesystem read; that function is IMG_Load_IO().
- *
- * If you are using SDL's 2D rendering API, there is an equivalent call to
- * load images directly into an Texture for use by the GPU without using a
- * software surface: call IMG_LoadTexture() instead.
- *
- * When done with the returned surface, the app should dispose of it with a
- * call to
- * [SDL_DestroySurface](https://wiki.libsdl.org/SDL3/SDL_DestroySurface)
- * ().
- *
- * \param file a path on the filesystem to load an image from.
- * \returns a new SDL surface, or on error.
- *
- * \since This function is available since SDL_image 3.0.0.
- *
- * \sa IMG_LoadTyped_IO
- * \sa IMG_Load_IO
- * \sa SDL_DestroySurface
- */
-
[LibraryImport(ImageLibName, StringMarshalling = Marshalling)]
private static partial nint IMG_Load(string file);
- public static nint LoadImage(string file) {
- if (string.IsNullOrWhiteSpace(file)) {
+ ///
+ /// Loads an image from a filesystem path into a software surface.
+ ///
+ /// A path on the filesystem to load an image from.
+ ///
+ ///
+ /// A Surface is a buffer of pixels in memory accessible by the CPU.
+ /// Use this if you plan to hand the data to something else or manipulate it
+ /// further in code.
+ ///
+ ///
+ /// There are no guarantees about what format the new Surface data will be;
+ /// in many cases, SDL_image will attempt to supply a surface that exactly
+ /// matches the provided image, but in others it might have to convert (either
+ /// because the image is in a format that SDL doesn't directly support or
+ /// because it's compressed data that could reasonably uncompress to various
+ /// formats and SDL_image had to pick one). You can inspect a Surface for its
+ /// specifics, and use to then migrate to any supported format.
+ ///
+ ///
+ /// If the image format supports a transparent pixel, SDL will set the colorkey
+ /// for the surface. You can enable RLE acceleration on the surface afterwards
+ /// by calling: SDL_SetSurfaceColorKey(image, SDL_RLEACCEL, image->format->colorkey);
+ ///
+ ///
+ /// There is a separate function to read files from an IOStream, if you
+ /// need an i/o abstraction to provide data from anywhere instead of a simple
+ /// filesystem read; that function is .
+ ///
+ ///
+ /// If you are using SDL's 2D rendering API, there is an equivalent call to
+ /// load images directly into a for use by the GPU without using a
+ /// software surface: call instead.
+ ///
+ ///
+ /// When done with the returned surface, the app should dispose of it with a
+ /// call to .
+ ///
+ ///
+ /// Since: This function is available since SDL_image 3.0.0.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// A new SDL surface, or on error.
+ /// Thrown if is or empty.
+ public static nint LoadImage(string file)
+ {
+ if (string.IsNullOrWhiteSpace(file))
+ {
throw new ArgumentException("File path cannot be null or empty.", nameof(file));
}
- nint surface = IMG_Load(file);
- if (surface == nint.Zero) {
+ var surface = IMG_Load(file);
+ if (surface == nint.Zero)
+ {
LogError(LogCategory.System, $"Failed to load image from file: {file}. SDL Error: {GetError()}");
}
return surface;
}
- /**
- * Load an image from an SDL data source into a software surface.
- *
- * An Surface is a buffer of pixels in memory accessible by the CPU. Use
- * this if you plan to hand the data to something else or manipulate it
- * further in code.
- *
- * There are no guarantees about what format the new Surface data will be;
- * in many cases, SDL_image will attempt to supply a surface that exactly
- * matches the provided image, but in others it might have to convert (either
- * because the image is in a format that SDL doesn't directly support or
- * because it's compressed data that could reasonably uncompress to various
- * formats and SDL_image had to pick one). You can inspect an Surface for
- * its specifics, and use SDL_ConvertSurface to then migrate to any supported
- * format.
- *
- * If the image format supports a transparent pixel, SDL will set the colorkey
- * for the surface. You can enable RLE acceleration on the surface afterwards
- * by calling: SDL_SetSurfaceColorKey(image, SDL_RLEACCEL,
- * image->format->colorkey);
- *
- * If `closeio` is , `src` will be closed before returning, whether this
- * function succeeds or not. SDL_image reads everything it needs from `src`
- * during this call in any case.
- *
- * There is a separate function to read files from disk without having to deal
- * with IOStream: `IMG_Load("filename.jpg")` will call this function and
- * manage those details for you, determining the file type from the filename's
- * extension.
- *
- * There is also IMG_LoadTyped_IO(), which is equivalent to this function
- * except a file extension (like "BMP", "JPG", etc) can be specified, in case
- * SDL_image cannot autodetect the file format.
- *
- * If you are using SDL's 2D rendering API, there is an equivalent call to
- * load images directly into an Texture for use by the GPU without using a
- * software surface: call IMG_LoadTexture_IO() instead.
- *
- * When done with the returned surface, the app should dispose of it with a
- * call to SDL_DestroySurface().
- *
- * \param src an IOStream that data will be read from.
- * \param closeio to close/free the IOStream before returning,
- * to leave it open.
- * \returns a new SDL surface, or on error.
- *
- * \since This function is available since SDL_image 3.0.0.
- *
- * \sa IMG_Load
- * \sa IMG_LoadTyped_IO
- * \sa SDL_DestroySurface
- */
-
[LibraryImport(ImageLibName, StringMarshalling = Marshalling)]
private static partial nint IMG_Load_IO(nint src, [MarshalAs(BoolType)] bool closeio);
- public static nint LoadImageIo(nint src, bool closeio) {
- if (src == nint.Zero) {
+ ///
+ /// Loads an image from an IOStream into a software surface.
+ ///
+ /// An IOStream that data will be read from.
+ /// to close/free the IOStream before returning, to leave it open.
+ ///
+ ///
+ /// A Surface is a buffer of pixels in memory accessible by the CPU. Use
+ /// this if you plan to hand the data to something else or manipulate it
+ /// further in code.
+ ///
+ ///
+ /// There are no guarantees about what format the new Surface data will be;
+ /// in many cases, SDL_image will attempt to supply a surface that exactly
+ /// matches the provided image, but in others it might have to convert (either
+ /// because the image is in a format that SDL doesn't directly support or
+ /// because it's compressed data that could reasonably uncompress to various
+ /// formats and SDL_image had to pick one). You can inspect a Surface for
+ /// its specifics, and use SDL_ConvertSurface to then migrate to any supported
+ /// format.
+ ///
+ ///
+ /// If the image format supports a transparent pixel, SDL will set the colorkey
+ /// for the surface. You can enable RLE acceleration on the surface afterwards
+ /// by calling: with (image, SDL_RLEACCEL, image->format->colorkey);
+ ///
+ ///
+ /// If is , will be closed before returning, whether this
+ /// function succeeds or not. SDL_image reads everything it needs from
+ /// during this call in any case.
+ ///
+ ///
+ /// There is a separate function to read files from disk without having to deal
+ /// with IOStream: `IMG_Load("filename.jpg")` will call this function and
+ /// manage those details for you, determining the file type from the filename's
+ /// extension.
+ ///
+ ///
+ /// There is also , which is equivalent to this function
+ /// except a file extension (like "BMP", "JPG", etc) can be specified, in case
+ /// SDL_image cannot autodetect the file format.
+ ///
+ ///
+ /// If you are using SDL's 2D rendering API, there is an equivalent call to
+ /// load images directly into a Texture for use by the GPU without using a
+ /// software surface: call instead.
+ ///
+ ///
+ /// When done with the returned surface, the app should dispose of it with a
+ /// call to .
+ ///
+ ///
+ /// Since: This function is available since SDL_image 3.0.0.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// A new SDL surface, or on error.
+ /// Thrown if is .
+ public static nint LoadImageIo(nint src, bool closeio)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
- nint surface = IMG_Load_IO(src, closeio);
- if (surface == nint.Zero) {
+ var surface = IMG_Load_IO(src, closeio);
+ if (surface == nint.Zero)
+ {
LogError(LogCategory.System, $"Failed to load image from IOStream. SDL Error: {GetError()}");
}
return surface;
}
- /**
- * Load an image from a filesystem path into a GPU texture.
- *
- * An Texture represents an image in GPU memory, usable by SDL's 2D Render
- * API. This can be significantly more efficient than using a CPU-bound
- * Surface if you don't need to manipulate the image directly after
- * loading it.
- *
- * If the loaded image has transparency or a colorkey, a texture with an alpha
- * channel will be created. Otherwise, SDL_image will attempt to create an
- * Texture in the most format that most reasonably represents the image
- * data (but in many cases, this will just end up being 32-bit RGB or 32-bit
- * RGBA).
- *
- * There is a separate function to read files from an IOStream, if you
- * need an i/o abstraction to provide data from anywhere instead of a simple
- * filesystem read; that function is IMG_LoadTexture_IO().
- *
- * If you would rather decode an image to an Surface (a buffer of pixels
- * in CPU memory), call IMG_Load() instead.
- *
- * When done with the returned texture, the app should dispose of it with a
- * call to SDL_DestroyTexture().
- *
- * \param renderer the SDL_Renderer to use to create the GPU texture.
- * \param file a path on the filesystem to load an image from.
- * \returns a new texture, or on error.
- *
- * \since This function is available since SDL_image 3.0.0.
- *
- * \sa IMG_LoadTextureTyped_IO
- * \sa IMG_LoadTexture_IO
- */
-
[LibraryImport(ImageLibName, StringMarshalling = Marshalling)]
private static partial nint IMG_LoadTexture(nint renderer, string file);
/// Load an image from a filesystem path into a GPU texture.
-
/// the SDL_Renderer to use to create the GPU texture.
/// a path on the filesystem to load an image from.
///
- /// An SDL_Texture represents an image in GPU memory, usable by SDL's 2D Render
+ ///
+ /// A Texture represents an image in GPU memory, usable by SDL's 2D Render
/// API. This can be significantly more efficient than using a CPU-bound
- /// SDL_Surface if you don't need to manipulate the image directly after
+ /// Surface if you don't need to manipulate the image directly after
/// loading it.
+ ///
+ ///
+ /// If the loaded image has transparency or a colorkey, a texture with an alpha
+ /// channel will be created. Otherwise, SDL_image will attempt to create an
+ /// Texture in the most appropriate format that most reasonably represents the image
+ /// data (but in many cases, this will just end up being 32-bit RGB or 32-bit RGBA).
+ ///
+ ///
+ /// There is a separate function to read files from an IOStream, , if you
+ /// need an i/o abstraction to provide data from anywhere instead of a simple
+ /// filesystem read.
+ ///
+ ///
+ /// If you would rather decode an image to an Surface (a buffer of pixels
+ /// in CPU memory), call instead.
+ ///
+ ///
+ /// When done with the returned texture, the app should dispose of it with a
+ /// call to .
+ ///
/// Version: This function is available since SDL_image 3.0.0.
///
///
///
/// (SDL_Texture *) Returns a new texture, or on error.
-
- public static nint LoadTexture(nint renderer, string file) {
- if (string.IsNullOrWhiteSpace(file)) {
+ public static nint LoadTexture(nint renderer, string file)
+ {
+ if (string.IsNullOrWhiteSpace(file))
+ {
throw new ArgumentException("File path cannot be null or empty.", nameof(file));
}
- nint texture = IMG_LoadTexture(renderer, file);
- if (texture == nint.Zero) {
+ var texture = IMG_LoadTexture(renderer, file);
+ if (texture == nint.Zero)
+ {
LogError(LogCategory.System, $"Failed to load texture from file: {file}. SDL Error: {GetError()}");
}
return texture;
@@ -360,12 +435,15 @@ public static nint LoadTexture(nint renderer, string file) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadTexture_IO(nint renderer, nint src, [MarshalAs(BoolType)] bool closeio);
- public static nint LoadTextureIo(nint renderer, nint src, bool closeio) {
- if (src == nint.Zero) {
+ public static nint LoadTextureIo(nint renderer, nint src, bool closeio)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
- nint texture = IMG_LoadTexture_IO(renderer, src, closeio);
- if (texture == nint.Zero) {
+ var texture = IMG_LoadTexture_IO(renderer, src, closeio);
+ if (texture == nint.Zero)
+ {
LogError(LogCategory.System, $"Failed to load texture from IOStream. SDL Error: {GetError()}");
}
return texture;
@@ -428,12 +506,15 @@ public static nint LoadTextureIo(nint renderer, nint src, bool closeio) {
[LibraryImport(ImageLibName, StringMarshalling = Marshalling)]
private static partial nint IMG_LoadTextureTyped_IO(nint renderer, nint src, [MarshalAs(BoolType)] bool closeio, string type);
- public static nint LoadTextureTypedIo(nint renderer, nint src, bool closeio, string type) {
- if (src == nint.Zero) {
+ public static nint LoadTextureTypedIo(nint renderer, nint src, bool closeio, string type)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
- nint texture = IMG_LoadTextureTyped_IO(renderer, src, closeio, type);
- if (texture == nint.Zero) {
+ var texture = IMG_LoadTextureTyped_IO(renderer, src, closeio, type);
+ if (texture == nint.Zero)
+ {
LogError(LogCategory.System, $"Failed to load texture from IOStream. SDL Error: {GetError()}");
}
return texture;
@@ -513,9 +594,10 @@ public static nint LoadTextureTypedIo(nint renderer, nint src, bool closeio, str
///
///
/// Returns non-zero if this is AVIF data, zero otherwise.
-
- public static bool IsAvif(nint src) {
- if (src == nint.Zero) {
+ public static bool IsAvif(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isAVIF(src);
@@ -594,8 +676,10 @@ public static bool IsAvif(nint src) {
///
/// Returns non-zero if this is ICO data, zero otherwise.
- public static bool IsIco(nint src) {
- if (src == nint.Zero) {
+ public static bool IsIco(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isICO(src);
@@ -674,8 +758,10 @@ public static bool IsIco(nint src) {
///
/// Returns non-zero if this is CUR data, zero otherwise.
- public static bool IsCur(nint src) {
- if (src == nint.Zero) {
+ public static bool IsCur(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isCUR(src);
@@ -754,8 +840,10 @@ public static bool IsCur(nint src) {
///
/// Returns non-zero if this is BMP data, zero otherwise.
- public static bool IsBmp(nint src) {
- if (src == nint.Zero) {
+ public static bool IsBmp(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isBMP(src);
@@ -834,8 +922,10 @@ public static bool IsBmp(nint src) {
///
/// Returns non-zero if this is GIF data, zero otherwise.
- public static bool IsGif(nint src) {
- if (src == nint.Zero) {
+ public static bool IsGif(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isGIF(src);
@@ -914,8 +1004,10 @@ public static bool IsGif(nint src) {
///
/// Returns non-zero if this is JPG data, zero otherwise.
- public static bool IsJpg(nint src) {
- if (src == nint.Zero) {
+ public static bool IsJpg(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isJPG(src);
@@ -994,8 +1086,10 @@ public static bool IsJpg(nint src) {
///
/// Returns non-zero if this is JXL data, zero otherwise.
- public static bool IsJxl(nint src) {
- if (src == nint.Zero) {
+ public static bool IsJxl(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isJXL(src);
@@ -1074,8 +1168,10 @@ public static bool IsJxl(nint src) {
///
/// Returns non-zero if this is LBM data, zero otherwise.
- public static bool IsLbm(nint src) {
- if (src == nint.Zero) {
+ public static bool IsLbm(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isLBM(src);
@@ -1154,8 +1250,10 @@ public static bool IsLbm(nint src) {
///
/// Returns non-zero if this is PCX data, zero otherwise.
- public static bool IsPcx(nint src) {
- if (src == nint.Zero) {
+ public static bool IsPcx(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isPCX(src);
@@ -1234,8 +1332,10 @@ public static bool IsPcx(nint src) {
///
/// Returns non-zero if this is PNG data, zero otherwise.
- public static bool IsPng(nint src) {
- if (src == nint.Zero) {
+ public static bool IsPng(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isPNG(src);
@@ -1314,8 +1414,10 @@ public static bool IsPng(nint src) {
///
/// Returns non-zero if this is PNM data, zero otherwise.
- public static bool IsPnm(nint src) {
- if (src == nint.Zero) {
+ public static bool IsPnm(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isPNM(src);
@@ -1394,8 +1496,10 @@ public static bool IsPnm(nint src) {
///
/// Returns non-zero if this is SVG data, zero otherwise.
- public static bool IsSvg(nint src) {
- if (src == nint.Zero) {
+ public static bool IsSvg(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isSVG(src);
@@ -1474,8 +1578,10 @@ public static bool IsSvg(nint src) {
///
/// Returns non-zero if this is QOI data, zero otherwise.
- public static bool IsQoi(nint src) {
- if (src == nint.Zero) {
+ public static bool IsQoi(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isQOI(src);
@@ -1554,8 +1660,10 @@ public static bool IsQoi(nint src) {
///
/// Returns non-zero if this is TIFF data, zero otherwise.
- public static bool IsTif(nint src) {
- if (src == nint.Zero) {
+ public static bool IsTif(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isTIF(src);
@@ -1634,8 +1742,10 @@ public static bool IsTif(nint src) {
///
/// Returns non-zero if this is XCF data, zero otherwise.
- public static bool IsXcf(nint src) {
- if (src == nint.Zero) {
+ public static bool IsXcf(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isXCF(src);
@@ -1714,8 +1824,10 @@ public static bool IsXcf(nint src) {
///
/// Returns non-zero if this is XPM data, zero otherwise.
- public static bool IsXpm(nint src) {
- if (src == nint.Zero) {
+ public static bool IsXpm(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isXPM(src);
@@ -1794,8 +1906,10 @@ public static bool IsXpm(nint src) {
///
/// Returns non-zero if this is XV data, zero otherwise.
- public static bool IsXv(nint src) {
- if (src == nint.Zero) {
+ public static bool IsXv(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isXV(src);
@@ -1874,8 +1988,10 @@ public static bool IsXv(nint src) {
///
/// Returns non-zero if this is WEBP data, zero otherwise.
- public static bool IsWebp(nint src) {
- if (src == nint.Zero) {
+ public static bool IsWebp(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_isWEBP(src);
@@ -1917,8 +2033,10 @@ public static bool IsWebp(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadAVIF_IO(nint src);
- public static nint LoadAvifIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadAvifIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadAVIF_IO(src);
@@ -1960,8 +2078,10 @@ public static nint LoadAvifIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadICO_IO(nint src);
- public static nint LoadIcoIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadIcoIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadICO_IO(src);
@@ -2003,8 +2123,10 @@ public static nint LoadIcoIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadCUR_IO(nint src);
- public static nint LoadCurIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadCurIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadCUR_IO(src);
@@ -2046,8 +2168,10 @@ public static nint LoadCurIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadBMP_IO(nint src);
- public static nint LoadBmpIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadBmpIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadBMP_IO(src);
@@ -2089,8 +2213,10 @@ public static nint LoadBmpIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadGIF_IO(nint src);
- public static nint LoadGifIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadGifIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadGIF_IO(src);
@@ -2132,8 +2258,10 @@ public static nint LoadGifIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadJPG_IO(nint src);
- public static nint LoadJpgIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadJpgIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadJPG_IO(src);
@@ -2175,8 +2303,10 @@ public static nint LoadJpgIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadJXL_IO(nint src);
- public static nint LoadJxlIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadJxlIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadJXL_IO(src);
@@ -2218,8 +2348,10 @@ public static nint LoadJxlIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadLBM_IO(nint src);
- public static nint LoadLbmIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadLbmIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadLBM_IO(src);
@@ -2261,8 +2393,10 @@ public static nint LoadLbmIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadPCX_IO(nint src);
- public static nint LoadPcxIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadPcxIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadPCX_IO(src);
@@ -2304,8 +2438,10 @@ public static nint LoadPcxIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadPNG_IO(nint src);
- public static nint LoadPngIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadPngIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadPNG_IO(src);
@@ -2347,8 +2483,10 @@ public static nint LoadPngIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadPNM_IO(nint src);
- public static nint LoadPnmIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadPnmIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadPNM_IO(src);
@@ -2390,8 +2528,10 @@ public static nint LoadPnmIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadSVG_IO(nint src);
- public static nint LoadSvgIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadSvgIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadSVG_IO(src);
@@ -2433,8 +2573,10 @@ public static nint LoadSvgIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadQOI_IO(nint src);
- public static nint LoadQoiIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadQoiIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadQOI_IO(src);
@@ -2476,8 +2618,10 @@ public static nint LoadQoiIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadTGA_IO(nint src);
- public static nint LoadTgaIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadTgaIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadTGA_IO(src);
@@ -2519,8 +2663,10 @@ public static nint LoadTgaIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadTIF_IO(nint src);
- public static nint LoadTifIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadTifIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadTIF_IO(src);
@@ -2562,8 +2708,10 @@ public static nint LoadTifIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadXCF_IO(nint src);
- public static nint LoadXcfIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadXcfIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadXCF_IO(src);
@@ -2605,8 +2753,10 @@ public static nint LoadXcfIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadXPM_IO(nint src);
- public static nint LoadXpmIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadXpmIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadXPM_IO(src);
@@ -2648,8 +2798,10 @@ public static nint LoadXpmIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadXV_IO(nint src);
- public static nint LoadXvIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadXvIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadXV_IO(src);
@@ -2691,8 +2843,10 @@ public static nint LoadXvIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadWEBP_IO(nint src);
- public static nint LoadWebpIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadWebpIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadWEBP_IO(src);
@@ -2721,8 +2875,10 @@ public static nint LoadWebpIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadSizedSVG_IO(nint src, int width, int height);
- public static nint LoadSizedSvgIo(nint src, int width, int height) {
- if (src == nint.Zero) {
+ public static nint LoadSizedSvgIo(nint src, int width, int height)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadSizedSVG_IO(src, width, height);
@@ -2761,8 +2917,10 @@ public static nint LoadSizedSvgIo(nint src, int width, int height) {
///
/// (SDL_Surface *) Returns a new SDL surface, or on error.
- public static nint ReadXpmFromArray(string[] xpm) {
- if (xpm == null) {
+ public static nint ReadXpmFromArray(string[] xpm)
+ {
+ if (xpm == null)
+ {
throw new ArgumentNullException(nameof(xpm), "XPM data cannot be null.");
}
return IMG_ReadXPMFromArray(xpm);
@@ -2801,8 +2959,10 @@ public static nint ReadXpmFromArray(string[] xpm) {
///
/// (SDL_Surface *) Returns a new SDL surface, or on error.
- public static nint ReadXpmFromArrayToRgb888(string[] xpm) {
- if (xpm == null) {
+ public static nint ReadXpmFromArrayToRgb888(string[] xpm)
+ {
+ if (xpm == null)
+ {
throw new ArgumentNullException(nameof(xpm), "XPM data cannot be null.");
}
return IMG_ReadXPMFromArrayToRGB888(xpm);
@@ -2841,11 +3001,14 @@ public static nint ReadXpmFromArrayToRgb888(string[] xpm) {
///
/// Returns on success or on failure; call for more information.
- public static bool SaveAvif(nint surface, string file, int quality) {
- if (surface == nint.Zero) {
+ public static bool SaveAvif(nint surface, string file, int quality)
+ {
+ if (surface == nint.Zero)
+ {
throw new ArgumentNullException(nameof(surface), "Surface cannot be null.");
}
- if (file == null) {
+ if (file == null)
+ {
throw new ArgumentNullException(nameof(file), "File path cannot be null.");
}
return IMG_SaveAVIF(surface, file, quality);
@@ -2877,11 +3040,14 @@ public static bool SaveAvif(nint surface, string file, int quality) {
[return: MarshalAs(BoolType)]
private static partial bool IMG_SaveAVIF_IO(nint surface, nint dst, [MarshalAs(BoolType)] bool closeio, int quality);
- public static bool SaveAvifIo(nint surface, nint dst, bool closeio, int quality) {
- if (surface == nint.Zero) {
+ public static bool SaveAvifIo(nint surface, nint dst, bool closeio, int quality)
+ {
+ if (surface == nint.Zero)
+ {
throw new ArgumentNullException(nameof(surface), "Surface cannot be null.");
}
- if (dst == nint.Zero) {
+ if (dst == nint.Zero)
+ {
throw new ArgumentNullException(nameof(dst), "IOStream cannot be null.");
}
return IMG_SaveAVIF_IO(surface, dst, closeio, quality);
@@ -2917,11 +3083,14 @@ public static bool SaveAvifIo(nint surface, nint dst, bool closeio, int quality)
///
/// Returns on success or on failure; call for more information.
- public static bool SavePng(nint surface, string file) {
- if (surface == nint.Zero) {
+ public static bool SavePng(nint surface, string file)
+ {
+ if (surface == nint.Zero)
+ {
throw new ArgumentNullException(nameof(surface), "Surface cannot be null.");
}
- if (file == null) {
+ if (file == null)
+ {
throw new ArgumentNullException(nameof(file), "File path cannot be null.");
}
return IMG_SavePNG(surface, file);
@@ -2951,11 +3120,14 @@ public static bool SavePng(nint surface, string file) {
[return: MarshalAs(BoolType)]
private static partial bool IMG_SavePNG_IO(nint surface, nint dst, [MarshalAs(BoolType)] bool closeio);
- public static bool SavePngIo(nint surface, nint dst, bool closeio) {
- if (surface == nint.Zero) {
+ public static bool SavePngIo(nint surface, nint dst, bool closeio)
+ {
+ if (surface == nint.Zero)
+ {
throw new ArgumentNullException(nameof(surface), "Surface cannot be null.");
}
- if (dst == nint.Zero) {
+ if (dst == nint.Zero)
+ {
throw new ArgumentNullException(nameof(dst), "IOStream cannot be null.");
}
return IMG_SavePNG_IO(surface, dst, closeio);
@@ -2994,11 +3166,14 @@ public static bool SavePngIo(nint surface, nint dst, bool closeio) {
///
/// Returns on success or on failure; call for more information.
- public static bool SaveJpg(nint surface, string file, int quality) {
- if (surface == nint.Zero) {
+ public static bool SaveJpg(nint surface, string file, int quality)
+ {
+ if (surface == nint.Zero)
+ {
throw new ArgumentNullException(nameof(surface), "Surface cannot be null.");
}
- if (file == null) {
+ if (file == null)
+ {
throw new ArgumentNullException(nameof(file), "File path cannot be null.");
}
return IMG_SaveJPG(surface, file, quality);
@@ -3030,11 +3205,14 @@ public static bool SaveJpg(nint surface, string file, int quality) {
[return: MarshalAs(BoolType)]
private static partial bool IMG_SaveJPG_IO(nint surface, nint dst, [MarshalAs(BoolType)] bool closeio, int quality);
- public static bool SaveJpgIo(nint surface, nint dst, bool closeio, int quality) {
- if (surface == nint.Zero) {
+ public static bool SaveJpgIo(nint surface, nint dst, bool closeio, int quality)
+ {
+ if (surface == nint.Zero)
+ {
throw new ArgumentNullException(nameof(surface), "Surface cannot be null.");
}
- if (dst == nint.Zero) {
+ if (dst == nint.Zero)
+ {
throw new ArgumentNullException(nameof(dst), "IOStream cannot be null.");
}
return IMG_SaveJPG_IO(surface, dst, closeio, quality);
@@ -3068,8 +3246,10 @@ public static bool SaveJpgIo(nint surface, nint dst, bool closeio, int quality)
///
/// (IMG_Animation *) Returns a newIMG_Animation, or on error.
- public static nint LoadAnimation(string file) {
- if (file == null) {
+ public static nint LoadAnimation(string file)
+ {
+ if (file == null)
+ {
throw new ArgumentNullException(nameof(file), "File path cannot be null.");
}
return IMG_LoadAnimation(file);
@@ -3098,8 +3278,10 @@ public static nint LoadAnimation(string file) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadAnimation_IO(nint src, [MarshalAs(BoolType)] bool closeio);
- public static nint LoadAnimationIo(nint src, bool closeio) {
- if (src == nint.Zero) {
+ public static nint LoadAnimationIo(nint src, bool closeio)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadAnimation_IO(src, closeio);
@@ -3137,11 +3319,14 @@ public static nint LoadAnimationIo(nint src, bool closeio) {
[LibraryImport(ImageLibName, StringMarshalling = Marshalling)]
private static partial nint IMG_LoadAnimationTyped_IO(nint src, [MarshalAs(BoolType)] bool closeio, string type);
- public static nint LoadAnimationTypedIo(nint src, bool closeio, string type) {
- if (src == nint.Zero) {
+ public static nint LoadAnimationTypedIo(nint src, bool closeio, string type)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
- if (type == null) {
+ if (type == null)
+ {
throw new ArgumentNullException(nameof(type), "Type cannot be null.");
}
return IMG_LoadAnimationTyped_IO(src, closeio, type);
@@ -3175,8 +3360,10 @@ public static nint LoadAnimationTypedIo(nint src, bool closeio, string type) {
///
///
- public static void FreeAnimation(nint anim) {
- if (anim == nint.Zero) {
+ public static void FreeAnimation(nint anim)
+ {
+ if (anim == nint.Zero)
+ {
throw new ArgumentNullException(nameof(anim), "Animation cannot be null.");
}
IMG_FreeAnimation(anim);
@@ -3204,8 +3391,10 @@ public static void FreeAnimation(nint anim) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadGIFAnimation_IO(nint src);
- public static nint LoadGifAnimationIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadGifAnimationIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadGIFAnimation_IO(src);
@@ -3233,8 +3422,10 @@ public static nint LoadGifAnimationIo(nint src) {
[LibraryImport(ImageLibName)]
private static partial nint IMG_LoadWEBPAnimation_IO(nint src);
- public static nint LoadWebpAnimationIo(nint src) {
- if (src == nint.Zero) {
+ public static nint LoadWebpAnimationIo(nint src)
+ {
+ if (src == nint.Zero)
+ {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
return IMG_LoadWEBPAnimation_IO(src);
diff --git a/SDL3/OwnedStringMarshaller.cs b/SDL3/OwnedStringMarshaller.cs
index a20523e..de5939d 100644
--- a/SDL3/OwnedStringMarshaller.cs
+++ b/SDL3/OwnedStringMarshaller.cs
@@ -14,7 +14,7 @@ public static class OwnedStringMarshaller {
///
/// A managed string.
public static string ConvertToManaged(nint unmanaged) {
- string? result = Marshal.PtrToStringUTF8(unmanaged);
+ var result = Marshal.PtrToStringUTF8(unmanaged);
return result ?? "";
}
}
\ No newline at end of file
diff --git a/SDL3/Assertion.cs b/SDL3/SDL/Assertion.cs
similarity index 93%
rename from SDL3/Assertion.cs
rename to SDL3/SDL/Assertion.cs
index 4654316..1ab1445 100644
--- a/SDL3/Assertion.cs
+++ b/SDL3/SDL/Assertion.cs
@@ -12,7 +12,6 @@ namespace SharpSDL3;
///
public static partial class Sdl {
/// Get the current assertion handler.
-
/// pointer which is filled with the "userdata" pointer that was passed to SDL_SetAssertionHandler().
///
/// This returns the function pointer that is called when an assertion is triggered.
@@ -24,7 +23,7 @@ public static partial class Sdl {
///
/// Returns the that is called when an assert triggers.
public static SdlAssertionHandler GetAssertionHandler(out nint pUserData) {
- SdlAssertionHandler? handler = SDL_GetAssertionHandler(out pUserData);
+ var handler = SDL_GetAssertionHandler(out pUserData);
return handler ?? throw new InvalidOperationException("Failed to get assertion handler.");
}
@@ -42,7 +41,7 @@ public static SdlAssertionHandler GetAssertionHandler(out nint pUserData) {
/// This memory should not be modified or freed by the application.
/// This pointer remains valid until the next call to or .
public static nint GetAssertionReport() {
- nint report = SDL_GetAssertionReport();
+ var report = SDL_GetAssertionReport();
return report == nint.Zero ? throw new InvalidOperationException("Failed to get assertion report.") : report;
}
@@ -58,9 +57,8 @@ public static nint GetAssertionReport() {
///
///
/// Returns the defaultSDL_AssertionHandler that is called when an assert triggers.
-
public static SdlAssertionHandler GetDefaultAssertionHandler() {
- SdlAssertionHandler handler = SDL_GetDefaultAssertionHandler() ?? throw new InvalidOperationException("Failed to get default assertion handler.");
+ var handler = SDL_GetDefaultAssertionHandler() ?? throw new InvalidOperationException("Failed to get default assertion handler.");
return handler;
}
@@ -82,7 +80,7 @@ public static AssertState ReportAssertion(ref AssertData data, string func, stri
}
// Call the native method
- AssertState result = SDL_ReportAssertion(ref data, func, file, line);
+ var result = SDL_ReportAssertion(ref data, func, file, line);
// Handle the result or add additional logic
switch (result) {
@@ -105,6 +103,8 @@ public static AssertState ReportAssertion(ref AssertData data, string func, stri
case AssertState.AlwaysIgnore:
LogWarn(LogCategory.System, "Always ignoring assertion...");
break;
+ default:
+ throw new ArgumentOutOfRangeException();
}
return result;
diff --git a/SDL3/AsyncIO.cs b/SDL3/SDL/AsyncIO.cs
similarity index 97%
rename from SDL3/AsyncIO.cs
rename to SDL3/SDL/AsyncIO.cs
index dc01664..7ab426c 100644
--- a/SDL3/AsyncIO.cs
+++ b/SDL3/SDL/AsyncIO.cs
@@ -29,7 +29,7 @@ public static nint AsyncIoFromFile(string file, string mode) {
throw new ArgumentException("Mode cannot be null or empty.", nameof(mode));
}
- nint result = SDL_AsyncIOFromFile(file, mode);
+ var result = SDL_AsyncIOFromFile(file, mode);
return result == nint.Zero
? throw new InvalidOperationException($"Failed to create AsyncIO from file: {file} with mode: {mode}")
@@ -64,7 +64,7 @@ public static SdlBool CloseAsyncIo(nint asyncio, SdlBool flush, nint queue, nint
///
/// (SDL_AsyncIOQueue *) Returns a new task queue object or if there was an error; call for more information.
public static nint CreateAsyncIoQueue() {
- nint result = SDL_CreateAsyncIOQueue();
+ var result = SDL_CreateAsyncIOQueue();
return result == nint.Zero
? throw new InvalidOperationException("Failed to create AsyncIO queue.")
: result;
@@ -105,7 +105,7 @@ public static SdlBool GetAsyncIoResult(nint queue, out AsyncIoOutcome outcome) {
if (queue == nint.Zero) {
throw new ArgumentException("Invalid queue handle.", nameof(queue));
}
- SdlBool result = SDL_GetAsyncIOResult(queue, out outcome);
+ var result = SDL_GetAsyncIOResult(queue, out outcome);
return !result ? throw new InvalidOperationException("Failed to get AsyncIO result.") : result;
}
@@ -209,7 +209,7 @@ public static SdlBool WaitAsyncIoResult(nint queue, out AsyncIoOutcome outcome,
if (queue == nint.Zero) {
throw new ArgumentException("Invalid queue handle.", nameof(queue));
}
- SdlBool result = SDL_WaitAsyncIOResult(queue, out outcome, timeoutMs);
+ var result = SDL_WaitAsyncIOResult(queue, out outcome, timeoutMs);
return !result ? throw new InvalidOperationException("Failed to wait for AsyncIO result.") : result;
}
diff --git a/SDL3/Atomic.cs b/SDL3/SDL/Atomic.cs
similarity index 100%
rename from SDL3/Atomic.cs
rename to SDL3/SDL/Atomic.cs
diff --git a/SDL3/Audio.cs b/SDL3/SDL/Audio.cs
similarity index 94%
rename from SDL3/Audio.cs
rename to SDL3/SDL/Audio.cs
index 88baea0..4337132 100644
--- a/SDL3/Audio.cs
+++ b/SDL3/SDL/Audio.cs
@@ -8,7 +8,7 @@
namespace SharpSDL3;
-public static unsafe partial class Sdl {
+public static partial class Sdl {
/// Use this function to query if an audio device is paused.
/// a device opened by .
@@ -166,7 +166,7 @@ public static bool ConvertAudioSamples(ref AudioSpec srcSpec, nint srcData, int
///
/// (SDL_AudioStream *) Returns a new audio stream on success or on failure; call for more information.
public static nint CreateAudioStream(ref AudioSpec srcSpec, ref AudioSpec dstSpec) {
- nint result = SDL_CreateAudioStream(ref srcSpec, ref dstSpec);
+ var result = SDL_CreateAudioStream(ref srcSpec, ref dstSpec);
if (result == nint.Zero) {
LogError(LogCategory.Error, "CreateAudioStream: Failed to create audio stream.");
}
@@ -218,7 +218,7 @@ public static bool FlushAudioStream(nint stream) {
///
/// (int *) Returns an array of the current channel mapping, with as many elements as the current output spec's channels, or if default. This should be freed with when it is no longer needed.
public static int[] GetAudioDeviceChannelMap(uint deviceId) {
- nint result = SDL_GetAudioDeviceChannelMap(deviceId, out int count);
+ var result = SDL_GetAudioDeviceChannelMap(deviceId, out var count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetAudioDeviceChannelMap: Failed to get audio device channel map.");
@@ -234,9 +234,9 @@ public static int[] GetAudioDeviceChannelMap(uint deviceId) {
return [];
}
- int[] map = new int[count];
+ var map = new int[count];
- for (int i = 0; i < count; i++) {
+ for (var i = 0; i < count; i++) {
map[i] = Marshal.ReadInt32(result, i * sizeof(int));
}
@@ -272,7 +272,7 @@ public static bool GetAudioDeviceFormat(uint deviceId, out AudioSpec spec, out i
///
/// Returns the gain of the device or -1.0f on failure; call for more information.
public static float GetAudioDeviceGain(uint deviceId) {
- float result = SDL_GetAudioDeviceGain(deviceId);
+ var result = SDL_GetAudioDeviceGain(deviceId);
if (result < 0) {
LogError(LogCategory.Error, "GetAudioDeviceGain: Failed to get audio device gain.");
}
@@ -289,7 +289,7 @@ public static float GetAudioDeviceGain(uint deviceId) {
///
/// Returns the name of the audio device, or on failure;call for more information.
public static string GetAudioDeviceName(uint deviceId) {
- string name = SDL_GetAudioDeviceName(deviceId);
+ var name = SDL_GetAudioDeviceName(deviceId);
if (string.IsNullOrEmpty(name)) {
LogError(LogCategory.Error, "GetAudioDeviceName: Failed to get audio device name.");
}
@@ -308,7 +308,7 @@ public static string GetAudioDeviceName(uint deviceId) {
///
/// Returns the name of the audio driver at the requested index, if an invalid index was specified.
public static string GetAudioDriver(int index) {
- string driver = SDL_GetAudioDriver(index);
+ var driver = SDL_GetAudioDriver(index);
if (string.IsNullOrEmpty(driver)) {
LogError(LogCategory.Error, "GetAudioDriver: Failed to get audio driver.");
}
@@ -323,7 +323,7 @@ public static string GetAudioDriver(int index) {
///
/// Returns the human-readable name of the specified audio format or "SDL_AUDIO_UNKNOWN" if the format isn't recognized.
public static string GetAudioFormatName(AudioFormat format) {
- string name = SDL_GetAudioFormatName(format);
+ var name = SDL_GetAudioFormatName(format);
if (string.IsNullOrEmpty(name)) {
LogError(LogCategory.Error, "GetAudioFormatName: Failed to get audio format name.");
}
@@ -344,7 +344,7 @@ public static string GetAudioFormatName(AudioFormat format) {
/// This should be freed with whenit is no longer needed.
///
public static uint[] GetAudioPlaybackDevices(out int count) {
- nint result = SDL_GetAudioPlaybackDevices(out count);
+ var result = SDL_GetAudioPlaybackDevices(out count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetAudioPlaybackDevices: Failed to get audio playback devices.");
throw new InvalidOperationException("GetAudioPlaybackDevices failed.");
@@ -355,9 +355,9 @@ public static uint[] GetAudioPlaybackDevices(out int count) {
return [];
}
- int[] playbackDevicesI = new int[count];
+ var playbackDevicesI = new int[count];
Marshal.Copy(result, playbackDevicesI, 0, count);
- uint[] playbackDevicesU = Array.ConvertAll(playbackDevicesI, x => (uint)x);
+ var playbackDevicesU = Array.ConvertAll(playbackDevicesI, x => (uint)x);
return playbackDevicesU;
}
@@ -376,7 +376,7 @@ public static uint[] GetAudioPlaybackDevices(out int count) {
/// This should be freed with when it is no longer needed.
///
public static uint[] GetAudioRecordingDevices(out int count) {
- nint result = SDL_GetAudioRecordingDevices(out count);
+ var result = SDL_GetAudioRecordingDevices(out count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetAudioRecordingDevices: Failed to get audio recording devices.");
}
@@ -386,9 +386,9 @@ public static uint[] GetAudioRecordingDevices(out int count) {
return [];
}
- int[] recordingDevicesI = new int[count];
+ var recordingDevicesI = new int[count];
Marshal.Copy(result, recordingDevicesI, 0, count);
- uint[] recordingDevices = Array.ConvertAll(recordingDevicesI, x => (uint)x);
+ var recordingDevices = Array.ConvertAll(recordingDevicesI, x => (uint)x);
return recordingDevices;
}
@@ -406,7 +406,7 @@ public static uint[] GetAudioRecordingDevices(out int count) {
///
/// Returns the number of converted/resampled bytes available or -1 on failure; call for more information.
public static int GetAudioStreamAvailable(nint stream) {
- int result = SDL_GetAudioStreamAvailable(stream);
+ var result = SDL_GetAudioStreamAvailable(stream);
if (result < 0) {
LogError(LogCategory.Error, "GetAudioStreamAvailable: Failed to get audio stream available.");
}
@@ -427,7 +427,7 @@ public static int GetAudioStreamAvailable(nint stream) {
///
/// Returns the number of bytes read from the stream or -1 on failure;call for more information.
public static int GetAudioStreamData(nint stream, nint buf, int len) {
- int result = SDL_GetAudioStreamData(stream, buf, len);
+ var result = SDL_GetAudioStreamData(stream, buf, len);
if (result < 0) {
LogError(LogCategory.Error, "GetAudioStreamData: Failed to get audio stream data.");
}
@@ -445,7 +445,7 @@ public static int GetAudioStreamData(nint stream, nint buf, int len) {
///
/// Returns the bound audio device, or 0 if not bound or invalid.
public static uint GetAudioStreamDevice(nint stream) {
- uint result = SDL_GetAudioStreamDevice(stream);
+ var result = SDL_GetAudioStreamDevice(stream);
if (result == 0) {
LogError(LogCategory.Error, "GetAudioStreamDevice: Failed to get audio stream device.");
}
@@ -479,7 +479,7 @@ public static bool GetAudioStreamFormat(nint stream, out AudioSpec srcSpec, out
///
/// Returns the frequency ratio of the stream or 0.0 on failure; call for more information.
public static float GetAudioStreamFrequencyRatio(nint stream) {
- float result = SDL_GetAudioStreamFrequencyRatio(stream);
+ var result = SDL_GetAudioStreamFrequencyRatio(stream);
if (result < 0) {
LogError(LogCategory.Error, "GetAudioStreamFrequencyRatio: Failed to get audio stream frequency ratio.");
}
@@ -496,7 +496,7 @@ public static float GetAudioStreamFrequencyRatio(nint stream) {
///
/// Returns the gain of the stream or -1.0f on failure; call for more information.
public static float GetAudioStreamGain(nint stream) {
- float result = SDL_GetAudioStreamGain(stream);
+ var result = SDL_GetAudioStreamGain(stream);
if (result < 0) {
LogError(LogCategory.Error, "GetAudioStreamGain: Failed to get audio stream gain.");
}
@@ -517,7 +517,7 @@ public static float GetAudioStreamGain(nint stream) {
/// This should be freed with when it is no longer needed.
///
public static int[] GetAudioStreamInputChannelMap(nint stream, out int count) {
- nint result = SDL_GetAudioStreamInputChannelMap(stream, out count);
+ var result = SDL_GetAudioStreamInputChannelMap(stream, out count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetAudioStreamInputChannelMap: Failed to get audio stream input channel map.");
@@ -528,9 +528,9 @@ public static int[] GetAudioStreamInputChannelMap(nint stream, out int count) {
LogError(LogCategory.Error, "GetAudioStreamInputChannelMap: Invalid channel map count.");
}
- int[] map = new int[count];
+ var map = new int[count];
- for (int i = 0; i < count; i++) {
+ for (var i = 0; i < count; i++) {
map[i] = Marshal.ReadInt32(result, i * sizeof(int));
}
@@ -551,7 +551,7 @@ public static int[] GetAudioStreamInputChannelMap(nint stream, out int count) {
/// This should be freed with when it is no longer needed.
///
public static int[] GetAudioStreamOutputChannelMap(nint stream, out int count) {
- nint result = SDL_GetAudioStreamOutputChannelMap(stream, out count);
+ var result = SDL_GetAudioStreamOutputChannelMap(stream, out count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetAudioStreamOutputChannelMap: Failed to get audio stream input channel map.");
return [];
@@ -561,9 +561,9 @@ public static int[] GetAudioStreamOutputChannelMap(nint stream, out int count) {
LogError(LogCategory.Error, "GetAudioStreamOutputChannelMap: Invalid channel map count.");
}
- int[] map = new int[count];
+ var map = new int[count];
- for (int i = 0; i < count; i++) {
+ for (var i = 0; i < count; i++) {
map[i] = Marshal.ReadInt32(result, i * sizeof(int));
}
@@ -578,7 +578,7 @@ public static int[] GetAudioStreamOutputChannelMap(nint stream, out int count) {
///
/// Returns a valid property ID on success or 0 on failure; call for more information.
public static uint GetAudioStreamProperties(nint stream) {
- uint result = SDL_GetAudioStreamProperties(stream);
+ var result = SDL_GetAudioStreamProperties(stream);
if (result == 0) {
LogError(LogCategory.Error, "GetAudioStreamProperties: Failed to get audio stream properties.");
}
@@ -598,7 +598,7 @@ public static uint GetAudioStreamProperties(nint stream) {
///
/// Returns the number of bytes queued or -1 on failure; call for more information.
public static int GetAudioStreamQueued(nint stream) {
- int result = SDL_GetAudioStreamQueued(stream);
+ var result = SDL_GetAudioStreamQueued(stream);
if (result < 0) {
LogError(LogCategory.Error, "GetAudioStreamQueued: Failed to get audio stream queued.");
}
@@ -614,7 +614,7 @@ public static int GetAudioStreamQueued(nint stream) {
///
/// Returns the name of the current audio driver or if no driver has been initialized.
public static string GetCurrentAudioDriver() {
- string driver = SDL_GetCurrentAudioDriver();
+ var driver = SDL_GetCurrentAudioDriver();
if (string.IsNullOrEmpty(driver)) {
LogError(LogCategory.Error, "GetCurrentAudioDriver: Failed to get current audio driver.");
}
@@ -633,7 +633,7 @@ public static string GetCurrentAudioDriver() {
///
/// Returns the number of built-in audio drivers.
public static int GetNumAudioDrivers() {
- int numDrivers = SDL_GetNumAudioDrivers();
+ var numDrivers = SDL_GetNumAudioDrivers();
if (numDrivers < 0) {
LogError(LogCategory.Error, "GetNumAudioDrivers: Failed to get number of audio drivers.");
}
@@ -649,7 +649,7 @@ public static int GetNumAudioDrivers() {
///
/// Returns a byte value that can be passed to memset.
public static int GetSilenceValueForFormat(AudioFormat format) {
- int silenceValue = SDL_GetSilenceValueForFormat(format);
+ var silenceValue = SDL_GetSilenceValueForFormat(format);
if (silenceValue < 0) {
LogError(LogCategory.Error, "GetSilenceValueForFormat: Failed to get silence value for format.");
}
@@ -666,7 +666,7 @@ public static int GetSilenceValueForFormat(AudioFormat format) {
///
/// Returns if is a physical device, if it is logical.
public static SdlBool IsAudioDevicePhysical(uint deviceId) {
- SdlBool result = SDL_IsAudioDevicePhysical(deviceId);
+ var result = SDL_IsAudioDevicePhysical(deviceId);
if (!result) {
LogError(LogCategory.Error, "IsAudioDevicePhysical: Failed to check if audio device is physical.");
}
@@ -682,7 +682,7 @@ public static SdlBool IsAudioDevicePhysical(uint deviceId) {
///
/// Returns if is a playback device, if it is recording.
public static SdlBool IsAudioDevicePlayback(uint deviceId) {
- SdlBool result = SDL_IsAudioDevicePlayback(deviceId);
+ var result = SDL_IsAudioDevicePlayback(deviceId);
if (!result) {
LogError(LogCategory.Error, "IsAudioDevicePlayback: Failed to check if audio device is playback.");
}
@@ -713,7 +713,7 @@ public static SdlBool IsAudioDevicePlayback(uint deviceId) {
///
public static SdlBool LoadWav(string path, out AudioSpec spec,
out nuint audioBuf, out uint audioLen) {
- SdlBool result = SDL_LoadWAV(path, out spec, out audioBuf, out audioLen);
+ var result = SDL_LoadWAV(path, out spec, out audioBuf, out audioLen);
if (!result) {
LogError(LogCategory.Error, "LoadWAV: Failed to load WAV.");
}
@@ -775,7 +775,7 @@ public static SdlBool LoadWav(string path, out AudioSpec spec,
///
public static SdlBool LoadWavIo(nint src, SdlBool closeIo, out AudioSpec spec,
out nuint audioBuf, out uint audioLen) {
- SdlBool result = SDL_LoadWAV_IO(src, closeIo, out spec, out audioBuf, out audioLen);
+ var result = SDL_LoadWAV_IO(src, closeIo, out spec, out audioBuf, out audioLen);
if (!result) {
LogError(LogCategory.Error, "LoadWAV_IO: Failed to load WAV IO.");
}
@@ -793,7 +793,7 @@ public static SdlBool LoadWavIo(nint src, SdlBool closeIo, out AudioSpec spec,
///
/// Returns on success or on failure; call for more information.
public static SdlBool LockAudioStream(nint stream) {
- SdlBool result = SDL_LockAudioStream(stream);
+ var result = SDL_LockAudioStream(stream);
if (!result) {
LogError(LogCategory.Error, "LockAudioStream: Failed to lock audio stream.");
}
@@ -815,7 +815,7 @@ public static SdlBool LockAudioStream(nint stream) {
///
/// Returns on success or on failure; call for more information.
public static SdlBool MixAudio(nint dst, nint src, AudioFormat format, uint len, float volume) {
- SdlBool result = SDL_MixAudio(dst, src, format, len, volume);
+ var result = SDL_MixAudio(dst, src, format, len, volume);
if (!result) {
LogError(LogCategory.Error, "MixAudio: Failed to mix audio.");
}
@@ -836,7 +836,7 @@ public static SdlBool MixAudio(nint dst, nint src, AudioFormat format, uint len,
///
/// Returns the device ID on successor 0 on failure; call for more information.
public static uint OpenAudioDevice(uint deviceId, ref AudioSpec spec) {
- uint result = SDL_OpenAudioDevice(deviceId, ref spec);
+ var result = SDL_OpenAudioDevice(deviceId, ref spec);
if (result == 0) {
LogError(LogCategory.Error, "OpenAudioDevice: Failed to open audio device.");
}
@@ -861,7 +861,7 @@ public static uint OpenAudioDevice(uint deviceId, ref AudioSpec spec) {
///
public static nint OpenAudioDeviceStream(uint deviceId, ref AudioSpec spec,
SdlAudioStreamCallback callback, nint userdata) {
- nint result = SDL_OpenAudioDeviceStream(deviceId, ref spec, callback, userdata);
+ var result = SDL_OpenAudioDeviceStream(deviceId, ref spec, callback, userdata);
if (result == nint.Zero) {
LogError(LogCategory.Error, "OpenAudioDeviceStream: Failed to open audio device stream.");
}
@@ -881,7 +881,7 @@ public static nint OpenAudioDeviceStream(uint deviceId, ref AudioSpec spec,
///
/// Returns on success or on failure; call for more information.
public static SdlBool PauseAudioDevice(uint deviceId) {
- SdlBool result = SDL_PauseAudioDevice(deviceId);
+ var result = SDL_PauseAudioDevice(deviceId);
if (!result) {
LogError(LogCategory.Error, "PauseAudioDevice: Failed to pause audio device.");
}
@@ -900,7 +900,7 @@ public static SdlBool PauseAudioDevice(uint deviceId) {
///
/// Returns on success or on failure; call for more information.
public static SdlBool PauseAudioStreamDevice(nint stream) {
- SdlBool result = SDL_PauseAudioStreamDevice(stream);
+ var result = SDL_PauseAudioStreamDevice(stream);
if (!result) {
LogError(LogCategory.Error, "PauseAudioStreamDevice: Failed to pause audio stream device.");
}
@@ -922,7 +922,7 @@ public static SdlBool PauseAudioStreamDevice(nint stream) {
///
/// Returns on success or on failure; call for more information.
public static SdlBool PutAudioStreamData(nint stream, nint buf, int len) {
- SdlBool result = SDL_PutAudioStreamData(stream, buf, len);
+ var result = SDL_PutAudioStreamData(stream, buf, len);
if (!result) {
LogError(LogCategory.Error, "PutAudioStreamData: Failed to put audio stream data.");
}
@@ -941,7 +941,7 @@ public static SdlBool PutAudioStreamData(nint stream, nint buf, int len) {
///
/// Returns on success or on failure; call for more information.
public static SdlBool ResumeAudioDevice(uint deviceId) {
- SdlBool result = SDL_ResumeAudioDevice(deviceId);
+ var result = SDL_ResumeAudioDevice(deviceId);
if (!result) {
LogError(LogCategory.Error, "ResumeAudioDevice: Failed to resume audio device.");
}
@@ -959,7 +959,7 @@ public static SdlBool ResumeAudioDevice(uint deviceId) {
///
/// Returns on success or on failure; call for more information.
public static SdlBool ResumeAudioStreamDevice(nint stream) {
- SdlBool result = SDL_ResumeAudioStreamDevice(stream);
+ var result = SDL_ResumeAudioStreamDevice(stream);
if (!result) {
LogError(LogCategory.Error, "ResumeAudioStreamDevice: Failed to resume audio stream device.");
}
@@ -977,7 +977,7 @@ public static SdlBool ResumeAudioStreamDevice(nint stream) {
///
/// Returns on success or on failure; call for more information.
public static SdlBool SetAudioDeviceGain(uint deviceId, float gain) {
- SdlBool result = SDL_SetAudioDeviceGain(deviceId, gain);
+ var result = SDL_SetAudioDeviceGain(deviceId, gain);
if (!result) {
LogError(LogCategory.Error, "SetAudioDeviceGain: Failed to set audio device gain.");
}
@@ -996,7 +996,7 @@ public static SdlBool SetAudioDeviceGain(uint deviceId, float gain) {
///
/// Returns on success or on failure; call for more information.
public static SdlBool SetAudioPostmixCallback(uint deviceId, SdlAudioPostmixCallback callback, nint userdata) {
- SdlBool result = SDL_SetAudioPostmixCallback(deviceId, callback, userdata);
+ var result = SDL_SetAudioPostmixCallback(deviceId, callback, userdata);
if (!result) {
LogError(LogCategory.Error, "SetAudioPostmixCallback: Failed to set audio postmix callback.");
}
@@ -1019,7 +1019,7 @@ public static SdlBool SetAudioPostmixCallback(uint deviceId, SdlAudioPostmixCall
/// Returns on success or on failure; call for more information.
public static SdlBool SetAudioStreamFormat(nint stream, ref AudioSpec srcSpec, ref AudioSpec dstSpec) {
- SdlBool result = SDL_SetAudioStreamFormat(stream, ref srcSpec, ref dstSpec);
+ var result = SDL_SetAudioStreamFormat(stream, ref srcSpec, ref dstSpec);
if (!result) {
LogError(LogCategory.Error, "SetAudioStreamFormat: Failed to set audio stream format.");
}
@@ -1041,7 +1041,7 @@ public static SdlBool SetAudioStreamFormat(nint stream, ref AudioSpec srcSpec, r
///
/// Returns on success or on failure; call for more information.
public static SdlBool SetAudioStreamFrequencyRatio(nint stream, float ratio) {
- SdlBool result = SDL_SetAudioStreamFrequencyRatio(stream, ratio);
+ var result = SDL_SetAudioStreamFrequencyRatio(stream, ratio);
if (!result) {
LogError(LogCategory.Error, "SetAudioStreamFrequencyRatio: Failed to set audio stream frequency ratio.");
}
@@ -1063,7 +1063,7 @@ public static SdlBool SetAudioStreamFrequencyRatio(nint stream, float ratio) {
///
/// Returns on success or on failure; call for more information.
public static SdlBool SetAudioStreamGain(nint stream, float gain) {
- SdlBool result = SDL_SetAudioStreamGain(stream, gain);
+ var result = SDL_SetAudioStreamGain(stream, gain);
if (!result) {
LogError(LogCategory.Error, "SetAudioStreamGain: Failed to set the audio stream gain.");
}
@@ -1083,7 +1083,7 @@ public static SdlBool SetAudioStreamGain(nint stream, float gain) {
///
/// Returns on success or on failure; call for more information. This only fails if stream is .
public static SdlBool SetAudioStreamGetCallback(nint stream, SdlAudioStreamCallback callback, nint userdata) {
- SdlBool result = SDL_SetAudioStreamGetCallback(stream, callback, userdata);
+ var result = SDL_SetAudioStreamGetCallback(stream, callback, userdata);
if (!result) {
LogError(LogCategory.Error, "SetAudioStreamGetCallback: Failed to set audio stream get callback.");
}
@@ -1104,7 +1104,7 @@ public static SdlBool SetAudioStreamGetCallback(nint stream, SdlAudioStreamCallb
///
/// Returns on success or on failure; call for more information.
public static SdlBool SetAudioStreamInputChannelMap(nint stream, Span channelMap, int count) {
- SdlBool result = SDL_SetAudioStreamInputChannelMap(stream, channelMap, count);
+ var result = SDL_SetAudioStreamInputChannelMap(stream, channelMap, count);
if (!result) {
LogError(LogCategory.Error, "SetAudioStreamInputChannelMap: Failed to set audio stream input channel map.");
}
@@ -1125,7 +1125,7 @@ public static SdlBool SetAudioStreamInputChannelMap(nint stream, Span chann
///
/// Returns on success or on failure; call for more information.
public static SdlBool SetAudioStreamOutputChannelMap(nint stream, Span channelMap, int count) {
- SdlBool result = SDL_SetAudioStreamOutputChannelMap(stream, channelMap, count);
+ var result = SDL_SetAudioStreamOutputChannelMap(stream, channelMap, count);
if (!result) {
LogError(LogCategory.Error, "SetAudioStreamOutputChannelMap: Failed to set audio stream output channel map.");
}
@@ -1144,7 +1144,7 @@ public static SdlBool SetAudioStreamOutputChannelMap(nint stream, Span chan
///
/// Returns on success or on failure; call for more information. This only fails if stream is .
public static SdlBool SetAudioStreamPutCallback(nint stream, SdlAudioStreamCallback callback, nint userdata) {
- SdlBool result = SDL_SetAudioStreamPutCallback(stream, callback, userdata);
+ var result = SDL_SetAudioStreamPutCallback(stream, callback, userdata);
if (!result) {
LogError(LogCategory.Error, "SetAudioStreamPutCallback: Failed to set audio stream put callback.");
}
@@ -1188,7 +1188,7 @@ public static void UnbindAudioStreams(Span streams) {
///
/// Returns on success or on failure; call for more information.
public static SdlBool UnlockAudioStream(nint stream) {
- SdlBool result = SDL_UnlockAudioStream(stream);
+ var result = SDL_UnlockAudioStream(stream);
if (!result) {
LogError(LogCategory.Error, "UnlockAudioStream: Failed to unlock audio stream.");
}
diff --git a/SDL3/SDL/Blit.cs b/SDL3/SDL/Blit.cs
new file mode 100644
index 0000000..841cfae
--- /dev/null
+++ b/SDL3/SDL/Blit.cs
@@ -0,0 +1,153 @@
+using SharpSDL3.Enums;
+using SharpSDL3.Structs;
+
+namespace SharpSDL3;
+
+public static partial class Sdl {
+
+ /// Performs a fast blit from the source surface to the destination surface with clipping.
+ /// the structure to be copied from.
+ /// the structure representing the rectangle to be copied, or to copy the entire surface.
+ /// the structure that is the blit target.
+ /// the structure representing the x and y position in the destination surface, or for (0,0). The width and height are ignored, and are copied from srcrect. If you want a specific width and height, you should use .
+ ///
+ /// If either srcrect or dstrect are , the entire surface (src or dst) is copied while ensuring clipping to dst->clip_rect.
+ /// Thread Safety: Only one thread should be using the src and dst surfaces at any given time.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool BlitSurface(nint src, nint srcrect, nint dst, nint dstrect) {
+ if (src != nint.Zero && dst != nint.Zero) return SDL_BlitSurface(src, srcrect, dst, dstrect);
+ LogWarn(LogCategory.System, "BlitSurface: Source or destination pointer is null.");
+ return false;
+ }
+
+ /// Perform a scaled blit using the 9-grid algorithm to a destination surface, which may be of a different format.
+ /// the structure to be copied from.
+ /// the structure representing the rectangle to be used for the 9-grid, or to use the entire surface.
+ /// the width, in pixels, of the left corners in srcrect.
+ /// the width, in pixels, of the right corners in srcrect.
+ /// the height, in pixels, of the top corners in srcrect.
+ /// the height, in pixels, of the bottom corners in srcrect.
+ /// the scale used to transform the corner of srcrect into the corner of dstrect, or 0.0f for an unscaled blit.
+ /// scale algorithm to be used.
+ /// the structure that is the blit target.
+ /// the structure representing the target rectangle in the destination surface, or to fill the entire surface.
+ ///
+ /// The pixels in the source surface are split into a 3x3 grid, using the
+ /// different corner sizes for each corner, and the sides and center making up
+ /// the remaining pixels. The corners are then scaled using scale and fit
+ /// into the corners of the destination rectangle. The sides and center are
+ /// then stretched into place to cover the remaining destination rectangle.
+ /// Thread Safety: Only one thread should be using the src and dst surfaces at any given time.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool BlitSurface9Grid(nint src, nint srcrect, int leftWidth, int rightWidth, int topHeight, int bottomHeight, float scale, ScaleMode scaleMode, nint dst, nint dstrect) {
+ if (src != nint.Zero && dst != nint.Zero)
+ return SDL_BlitSurface9Grid(src, srcrect, leftWidth, rightWidth, topHeight, bottomHeight, scale, scaleMode,
+ dst, dstrect);
+ LogWarn(LogCategory.System, "BlitSurface9Grid: Source or destination pointer is null.");
+ return false;
+ }
+
+ /// Perform a scaled blit to a destination surface, which may be of a different format.
+ /// the structure to be copied from.
+ /// the structure representing the rectangle to be copied, or to copy the entire surface.
+ /// the structure that is the blit target.
+ /// the structure representing the target rectangle in the destination surface, or to fill the entire destination surface.
+ /// the to be used.
+ ///
+ /// Thread Safety: Only one thread should be using the src and dst surfaces at any given time.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool BlitSurfaceScaled(nint src, nint srcrect, nint dst, nint dstrect, ScaleMode scaleMode) {
+ if (src != nint.Zero && dst != nint.Zero) return SDL_BlitSurfaceScaled(src, srcrect, dst, dstrect, scaleMode);
+ LogWarn(LogCategory.System, "BlitSurfaceScaled: Source or destination pointer is null.");
+ return false;
+ }
+
+ /// Perform a tiled blit to a destination surface, which may be of a different format.
+ /// the structure to be copied from.
+ /// the structure representing the rectangle to be copied, or to copy the entire surface.
+ /// the structure that is the blit target.
+ /// the structure representing the target rectangle in the destination surface, or to fill the entire surface.
+ ///
+ /// The pixels in srcrect will be repeated as many times as needed to completely fill dstrect.
+ /// Thread Safety: Only one thread should be using the src and dst surfaces at any given time.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool BlitSurfaceTiled(nint src, nint srcrect, nint dst, nint dstrect) {
+ if (src != nint.Zero && dst != nint.Zero) return SDL_BlitSurfaceTiled(src, srcrect, dst, dstrect);
+ LogWarn(LogCategory.System, "BlitSurfaceTiled: Source or destination pointer is null.");
+ return false;
+ }
+
+ /// Perform a scaled and tiled blit to a destination surface, which may be of a different format.
+ /// the structure to be copied from.
+ /// the structure representing the rectangle to be copied, or to copy the entire surface.
+ /// the scale used to transform srcrect into the destination rectangle, e.g. a 32x32 texture with a scale of 2 would fill 64x64 tiles.
+ /// scale algorithm to be used.
+ /// the structure that is the blit target.
+ /// the structure representing the target rectangle in the destination surface, or to fill the entire surface.
+ ///
+ /// The pixels in srcrect will be scaled and repeated as many times as needed
+ /// to completely fill dstrect.
+ /// Thread Safety: Only one thread should be using the src and dst surfaces at any given time.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool BlitSurfaceTiledWithScale(nint src, nint srcrect, float scale, ScaleMode scaleMode, nint dst, nint dstrect) {
+ if (src != nint.Zero && dst != nint.Zero)
+ return SDL_BlitSurfaceTiledWithScale(src, srcrect, scale, scaleMode, dst, dstrect);
+ LogWarn(LogCategory.System, "BlitSurfaceTiledWithScale: Source or destination pointer is null.");
+ return false;
+ }
+
+ /// Perform low-level surface blitting only.
+ /// the structure to be copied from.
+ /// the structure representing the rectangle to be copied, may not be .
+ /// the structure that is the blit target.
+ /// the structure representing the target rectangle in the destination surface, may not be .
+ ///
+ /// This is a semi-private blit function and it performs low-level surface
+ /// blitting, assuming the input rectangles have already been clipped.
+ /// Thread Safety: Only one thread should be using the src and dst surfaces at any given time.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool BlitSurfaceUnchecked(nint src, nint srcrect, nint dst, nint dstrect) {
+ if (src != nint.Zero && dst != nint.Zero) return SDL_BlitSurfaceUnchecked(src, srcrect, dst, dstrect);
+ LogWarn(LogCategory.System, "BlitSurfaceUnchecked: Source or destination pointer is null.");
+ return false;
+ }
+
+ /// Perform low-level surface scaled blitting only.
+ /// the structure to be copied from.
+ /// the structure representing the rectangle to be copied, may not be .
+ /// the structure that is the blit target.
+ /// the structure representing the target rectangle in the destination surface, may not be .
+ /// the to be used.
+ ///
+ /// This is a semi-private function and it performs low-level surface blitting,
+ /// assuming the input rectangles have already been clipped.
+ /// Thread Safety: Only one thread should be using the src and dst surfaces at any given time.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool BlitSurfaceUncheckedScaled(nint src, nint srcrect, nint dst, nint dstrect, ScaleMode scaleMode) {
+ if (src != nint.Zero && dst != nint.Zero)
+ return SDL_BlitSurfaceUncheckedScaled(src, srcrect, dst, dstrect, scaleMode);
+ LogWarn(LogCategory.System, "BlitSurfaceUncheckedScaled: Source or destination pointer is null.");
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/SDL3/Camera.cs b/SDL3/SDL/Camera.cs
similarity index 93%
rename from SDL3/Camera.cs
rename to SDL3/SDL/Camera.cs
index 3666d32..b23a161 100644
--- a/SDL3/Camera.cs
+++ b/SDL3/SDL/Camera.cs
@@ -23,7 +23,7 @@ public static nint AcquireCameraFrame(nint camera, out ulong timestampNs) {
if (camera == nint.Zero) {
throw new ArgumentNullException(nameof(camera), "Camera handle cannot be null.");
}
- nint frame = SDL_AcquireCameraFrame(camera, out timestampNs);
+ var frame = SDL_AcquireCameraFrame(camera, out timestampNs);
if (frame == nint.Zero) {
LogError(LogCategory.Error, "Failed to acquire camera frame. Camera handle may be invalid.");
}
@@ -60,7 +60,7 @@ public static string GetCameraDriver(int index) {
throw new ArgumentOutOfRangeException(nameof(index), "Index is out of range.");
}
- string driverName = SDL_GetCameraDriver(index);
+ var driverName = SDL_GetCameraDriver(index);
if (string.IsNullOrEmpty(driverName)) {
LogError(LogCategory.Error, $"Failed to retrieve camera driver at index {index}.");
}
@@ -84,7 +84,7 @@ public static SdlBool GetCameraFormat(nint camera, out CameraSpec spec) {
throw new ArgumentNullException(nameof(camera), "Camera handle cannot be null.");
}
- SdlBool result = SDL_GetCameraFormat(camera, out spec);
+ var result = SDL_GetCameraFormat(camera, out spec);
if (!result) {
LogError(LogCategory.Error, "Failed to get camera format. Camera handle may be invalid.");
}
@@ -105,7 +105,7 @@ public static uint GetCameraId(nint camera) {
throw new ArgumentNullException(nameof(camera), "Camera handle cannot be null.");
}
- uint cameraId = SDL_GetCameraID(camera);
+ var cameraId = SDL_GetCameraID(camera);
if (cameraId == 0) {
LogError(LogCategory.Error, $"Failed to get camera ID. Camera handle may be invalid.");
}
@@ -122,7 +122,7 @@ public static uint GetCameraId(nint camera) {
///
/// Returns a human-readable device name or on failure;call for more information.
public static string GetCameraName(uint instanceId) {
- string cameraName = SDL_GetCameraName(instanceId);
+ var cameraName = SDL_GetCameraName(instanceId);
if (string.IsNullOrEmpty(cameraName)) {
LogError(LogCategory.Error, $"Failed to retrieve camera name for instance ID {instanceId}.");
}
@@ -144,7 +144,7 @@ public static int GetCameraPermissionState(nint camera) {
if (camera == nint.Zero) {
throw new ArgumentNullException(nameof(camera), "Camera handle cannot be null.");
}
- int permissionState = SDL_GetCameraPermissionState(camera);
+ var permissionState = SDL_GetCameraPermissionState(camera);
if (permissionState < 0) {
LogError(LogCategory.Error, $"Failed to get camera permission state. Error code: {permissionState}");
}
@@ -163,7 +163,7 @@ public static int GetCameraPermissionState(nint camera) {
///
/// Returns the position of the camera on the system hardware.
public static CameraPosition GetCameraPosition(uint instanceId) {
- CameraPosition position = SDL_GetCameraPosition(instanceId);
+ var position = SDL_GetCameraPosition(instanceId);
// Add validation or additional logic to make the wrapper less trivial
if (!Enum.IsDefined(position)) {
@@ -184,7 +184,7 @@ public static uint GetCameraProperties(nint camera) {
if (camera == nint.Zero) {
throw new ArgumentNullException(nameof(camera), "Camera handle cannot be null.");
}
- uint properties = SDL_GetCameraProperties(camera);
+ var properties = SDL_GetCameraProperties(camera);
if (properties == 0) {
LogError(LogCategory.Error, "Failed to get camera properties. Camera handle may be invalid.");
}
@@ -203,7 +203,7 @@ public static uint GetCameraProperties(nint camera) {
/// This should be freed with when it is no longer needed.
///
public static Span GetCameras(out int count) {
- nint result = SDL_GetCameras(out count);
+ var result = SDL_GetCameras(out count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to retrieve camera list.");
@@ -215,13 +215,13 @@ public static Span GetCameras(out int count) {
return [];
}
- nint[] ptrArray = new nint[count];
+ var ptrArray = new nint[count];
- for (int i = 0; i < count; i++) {
+ for (var i = 0; i < count; i++) {
ptrArray[i] = Marshal.ReadIntPtr(result, i * sizeof(nint));
}
- Span cameras = new(ptrArray);
+ Span cameras = new Span(ptrArray);
return cameras.ToArray();
}
@@ -243,7 +243,7 @@ public static Span GetCameras(out int count) {
///
public static Span GetCameraSupportedFormats(uint instanceId, out int count) {
- nint result = SDL_GetCameraSupportedFormats(instanceId, out count);
+ var result = SDL_GetCameraSupportedFormats(instanceId, out count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to retrieve camera formats.");
return [];
@@ -254,13 +254,13 @@ public static Span GetCameraSupportedFormats(uint instanceId, out int coun
return [];
}
- nint[] ptrArray = new nint[count];
+ var ptrArray = new nint[count];
- for (int i = 0; i < count; i++) {
+ for (var i = 0; i < count; i++) {
ptrArray[i] = Marshal.ReadIntPtr(result, i * sizeof(nint));
}
- Span cameraFormats = new(ptrArray);
+ Span cameraFormats = new Span(ptrArray);
return cameraFormats.ToArray();
}
@@ -274,7 +274,7 @@ public static Span GetCameraSupportedFormats(uint instanceId, out int coun
///
/// Returns the name of the current camera driver or if no driver has been initialized.
public static string GetCurrentCameraDriver() {
- string driverName = SDL_GetCurrentCameraDriver();
+ var driverName = SDL_GetCurrentCameraDriver();
if (string.IsNullOrEmpty(driverName)) {
LogError(LogCategory.Error, "Failed to retrieve current camera driver.");
}
@@ -309,7 +309,7 @@ public static int GetNumCameraDrivers() {
///
/// (SDL_Camera *) Returns an SDL_Camera object or on failure; call for more information.
public static nint OpenCamera(uint instanceId, ref CameraSpec spec) {
- nint camera = SDL_OpenCamera(instanceId, ref spec);
+ var camera = SDL_OpenCamera(instanceId, ref spec);
if (camera == nint.Zero) {
LogError(LogCategory.Error, $"Failed to open camera with instance ID {instanceId}.");
}
diff --git a/SDL3/CpuInfo.cs b/SDL3/SDL/CpuInfo.cs
similarity index 100%
rename from SDL3/CpuInfo.cs
rename to SDL3/SDL/CpuInfo.cs
diff --git a/SDL3/Events.cs b/SDL3/SDL/Events.cs
similarity index 96%
rename from SDL3/Events.cs
rename to SDL3/SDL/Events.cs
index 5bea022..f55b441 100644
--- a/SDL3/Events.cs
+++ b/SDL3/SDL/Events.cs
@@ -28,7 +28,7 @@ public static bool AddEventWatch(SdlEventFilter filter, nint userdata) {
throw new ArgumentNullException(nameof(filter), "Filter function pointer cannot be null.");
}
// Call the native method and check the result
- SdlBool result = SDL_AddEventWatch(filter, userdata);
+ var result = SDL_AddEventWatch(filter, userdata);
return result;
}
@@ -126,7 +126,7 @@ public static void FlushEvents(uint minType, uint maxType) {
/// Returns on success or if there is no event filter set.
public static bool GetEventFilter(out SdlEventFilter filter, out nint userdata) {
// Call the native method and check the result
- SdlBool result = SDL_GetEventFilter(out filter, out userdata);
+ var result = SDL_GetEventFilter(out filter, out userdata);
return result;
}
@@ -148,7 +148,7 @@ public static nint GetWindowFromEvent(ref Event @event) {
try {
// Call the native method and check the result
- nint result = SDL_GetWindowFromEvent(ref @event);
+ var result = SDL_GetWindowFromEvent(ref @event);
// Perform additional validation or processing if needed
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to get window from event.");
@@ -225,7 +225,7 @@ public static int PeepEvents(ref Event[] events, int numEvents, EventAction acti
throw new ArgumentException("minType cannot be greater than maxType.", nameof(minType));
}
// Call the native method
- int result = SDL_PeepEvents(events, numEvents, action, (uint)minType, (uint)maxType);
+ var result = SDL_PeepEvents(events, numEvents, action, (uint)minType, (uint)maxType);
return result;
}
@@ -245,7 +245,7 @@ public static int PeepEvents(ref Event[] events, int numEvents, EventAction acti
/// Returns if this got an event or if there are none available.
public static bool PollEvent(out Event @event) {
// Call the native method and check the result
- SdlBool result = SDL_PollEvent(out @event);
+ var result = SDL_PollEvent(out @event);
if (!result) {
return false;
@@ -387,7 +387,7 @@ public static void SetEventFilter(SdlEventFilter filter, nint userdata) {
///
/// Returns on success or if there was an error while waiting for events; call for more information.
public static bool WaitEvent(out Event @event) {
- SdlBool result = SDL_WaitEvent(out @event);
+ var result = SDL_WaitEvent(out @event);
if (!result) {
LogError(LogCategory.Error, "Failed to wait for event.");
@@ -417,7 +417,7 @@ public static bool WaitEventTimeout(out Event @event, int timeoutMs) {
throw new ArgumentOutOfRangeException(nameof(timeoutMs), "Timeout value cannot be negative.");
}
- SdlBool result = SDL_WaitEventTimeout(out @event, timeoutMs);
+ var result = SDL_WaitEventTimeout(out @event, timeoutMs);
if (!result) {
LogError(LogCategory.Error, "Failed to wait for event with timeout.");
}
diff --git a/SDL3/FileDialog.cs b/SDL3/SDL/FileDialog.cs
similarity index 100%
rename from SDL3/FileDialog.cs
rename to SDL3/SDL/FileDialog.cs
diff --git a/SDL3/FileSystem.cs b/SDL3/SDL/FileSystem.cs
similarity index 100%
rename from SDL3/FileSystem.cs
rename to SDL3/SDL/FileSystem.cs
diff --git a/SDL3/GamePad.cs b/SDL3/SDL/GamePad.cs
similarity index 97%
rename from SDL3/GamePad.cs
rename to SDL3/SDL/GamePad.cs
index 9f8811c..c32a626 100644
--- a/SDL3/GamePad.cs
+++ b/SDL3/SDL/GamePad.cs
@@ -502,7 +502,7 @@ public static string GetGamepadMappingForGuid(SdlGuid guid) {
throw new ArgumentException("GUID data cannot be null.", nameof(guid));
}
- string mapping = SDL_GetGamepadMappingForGUID(guid);
+ var mapping = SDL_GetGamepadMappingForGUID(guid);
if (string.IsNullOrEmpty(mapping)) {
throw new InvalidOperationException("No mapping found for the provided GUID.");
}
@@ -860,7 +860,7 @@ public static bool GetGamepadTouchpadFinger(nint gamepad, int touchpad, int fing
if (gamepad == nint.Zero) {
throw new ArgumentException("Gamepad handle cannot be null.", nameof(gamepad));
}
- SdlBool result = SDL_GetGamepadTouchpadFinger(gamepad, touchpad, finger, out SdlBool sdlDown, out x, out y, out pressure);
+ var result = SDL_GetGamepadTouchpadFinger(gamepad, touchpad, finger, out var sdlDown, out x, out y, out pressure);
down = sdlDown;
return result;
}
diff --git a/SDL3/Gpu.cs b/SDL3/SDL/Gpu.cs
similarity index 100%
rename from SDL3/Gpu.cs
rename to SDL3/SDL/Gpu.cs
diff --git a/SDL3/Haptic.cs b/SDL3/SDL/Haptic.cs
similarity index 95%
rename from SDL3/Haptic.cs
rename to SDL3/SDL/Haptic.cs
index c7a84a9..19446b4 100644
--- a/SDL3/Haptic.cs
+++ b/SDL3/SDL/Haptic.cs
@@ -39,7 +39,7 @@ public static int CreateHapticEffect(nint haptic, ref HapticEffect effect) {
if (haptic == nint.Zero) {
throw new ArgumentException("Haptic handle cannot be null.", nameof(haptic));
}
- int effectId = SDL_CreateHapticEffect(haptic, ref effect);
+ var effectId = SDL_CreateHapticEffect(haptic, ref effect);
if (effectId < 0) {
LogError(LogCategory.Error, "Failed to create haptic effect.");
}
@@ -100,7 +100,7 @@ public static uint GetHapticFeatures(nint haptic) {
if (haptic == nint.Zero) {
throw new ArgumentException("Haptic handle cannot be null.", nameof(haptic));
}
- uint features = SDL_GetHapticFeatures(haptic);
+ var features = SDL_GetHapticFeatures(haptic);
if (features == 0) {
LogError(LogCategory.Error, "Failed to retrieve haptic features.");
}
@@ -119,7 +119,7 @@ public static nint GetHapticFromId(uint instanceId) {
if (instanceId == 0) {
throw new ArgumentException("Instance ID cannot be zero.", nameof(instanceId));
}
- nint haptic = SDL_GetHapticFromID(instanceId);
+ var haptic = SDL_GetHapticFromID(instanceId);
if (haptic == nint.Zero) {
LogError(LogCategory.Error, $"Failed to retrieve haptic device with ID: {instanceId}");
}
@@ -138,7 +138,7 @@ public static uint GetHapticId(nint haptic) {
if (haptic == nint.Zero) {
throw new ArgumentException("Haptic handle cannot be null.", nameof(haptic));
}
- uint id = SDL_GetHapticID(haptic);
+ var id = SDL_GetHapticID(haptic);
if (id == 0) {
LogError(LogCategory.Error, "Failed to retrieve haptic ID.");
}
@@ -158,7 +158,7 @@ public static string GetHapticName(nint haptic) {
if (haptic == nint.Zero) {
throw new ArgumentException("Haptic handle cannot be null.", nameof(haptic));
}
- string name = SDL_GetHapticName(haptic);
+ var name = SDL_GetHapticName(haptic);
if (string.IsNullOrEmpty(name)) {
LogError(LogCategory.Error, "Failed to retrieve haptic name.");
}
@@ -180,7 +180,7 @@ public static string GetHapticNameforId(uint instanceId) {
if (instanceId == 0) {
throw new ArgumentException("Instance ID cannot be zero.", nameof(instanceId));
}
- string name = SDL_GetHapticNameForID(instanceId);
+ var name = SDL_GetHapticNameForID(instanceId);
if (string.IsNullOrEmpty(name)) {
LogError(LogCategory.Error, $"Failed to retrieve haptic name for ID: {instanceId}");
return string.Empty;
@@ -198,7 +198,7 @@ public static string GetHapticNameforId(uint instanceId) {
/// (SDL_HapticID *) Returns a 0 terminated array of hapticdevice instance IDs or on failure; call for more information. This should be freed with whenit is no longer needed.
public static Span GetHaptics() {
- nint result = SDL_GetHaptics(out int count);
+ var result = SDL_GetHaptics(out var count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to retrieve haptic devices.");
return [];
@@ -207,8 +207,8 @@ public static Span GetHaptics() {
LogWarn(LogCategory.System, "No haptic devices found.");
return [];
}
- nint[] ptrs = new nint[count];
- for (int i = 0; i < count; i++) {
+ var ptrs = new nint[count];
+ for (var i = 0; i < count; i++) {
ptrs[i] = Marshal.ReadIntPtr(result, i * Marshal.SizeOf());
}
return new Span(ptrs);
@@ -232,7 +232,7 @@ public static int GetMaxHapticEffects(nint haptic) {
if (haptic == nint.Zero) {
throw new ArgumentException("Haptic handle cannot be null.", nameof(haptic));
}
- int maxEffects = SDL_GetMaxHapticEffects(haptic);
+ var maxEffects = SDL_GetMaxHapticEffects(haptic);
if (maxEffects < 0) {
LogError(LogCategory.Error, "Failed to retrieve maximum haptic effects.");
}
@@ -254,7 +254,7 @@ public static int GetMaxHapticEffectsPlaying(nint haptic) {
if (haptic == nint.Zero) {
throw new ArgumentException("Haptic handle cannot be null.", nameof(haptic));
}
- int maxEffectsPlaying = SDL_GetMaxHapticEffectsPlaying(haptic);
+ var maxEffectsPlaying = SDL_GetMaxHapticEffectsPlaying(haptic);
if (maxEffectsPlaying < 0) {
LogError(LogCategory.Error, "Failed to retrieve maximum haptic effects playing.");
}
@@ -275,7 +275,7 @@ public static int GetNumHapticAxes(nint haptic) {
if (haptic == nint.Zero) {
throw new ArgumentException("Haptic handle cannot be null.", nameof(haptic));
}
- int numAxes = SDL_GetNumHapticAxes(haptic);
+ var numAxes = SDL_GetNumHapticAxes(haptic);
if (numAxes < 0) {
LogError(LogCategory.Error, "Failed to retrieve number of haptic axes.");
}
@@ -382,7 +382,7 @@ public static nint OpenHaptic(uint instanceId) {
if (instanceId == 0) {
throw new ArgumentException("Instance ID cannot be zero.", nameof(instanceId));
}
- nint haptic = SDL_OpenHaptic(instanceId);
+ var haptic = SDL_OpenHaptic(instanceId);
if (haptic == nint.Zero) {
LogError(LogCategory.Error, $"Failed to open haptic device with ID: {instanceId}");
}
@@ -405,7 +405,7 @@ public static nint OpenHapticFromJoystick(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick handle cannot be null.", nameof(joystick));
}
- nint haptic = SDL_OpenHapticFromJoystick(joystick);
+ var haptic = SDL_OpenHapticFromJoystick(joystick);
if (haptic == nint.Zero) {
LogError(LogCategory.Error, "Failed to open haptic from joystick.");
}
@@ -421,7 +421,7 @@ public static nint OpenHapticFromJoystick(nint joystick) {
/// (SDL_Haptic *) Returns the haptic device identifier or on failure; call for more information.
public static nint OpenHapticFromMouse() {
- nint haptic = SDL_OpenHapticFromMouse();
+ var haptic = SDL_OpenHapticFromMouse();
if (haptic == nint.Zero) {
LogError(LogCategory.Error, "Failed to open haptic from mouse.");
}
diff --git a/SDL3/Hid.cs b/SDL3/SDL/Hid.cs
similarity index 87%
rename from SDL3/Hid.cs
rename to SDL3/SDL/Hid.cs
index e0b5ecc..4946b12 100644
--- a/SDL3/Hid.cs
+++ b/SDL3/SDL/Hid.cs
@@ -15,7 +15,7 @@ public static void BleScan(SdlBool active) {
}
public static int Close(nint dev) {
- int result = SDL_hid_close(dev);
+ var result = SDL_hid_close(dev);
if (result < 0) {
LogError(LogCategory.Error, $"Failed to close HID device: {GetError()}");
}
@@ -23,7 +23,7 @@ public static int Close(nint dev) {
}
public static uint DeviceChangeCount() {
- uint result = SDL_hid_device_change_count();
+ var result = SDL_hid_device_change_count();
if (result == 0) {
LogError(LogCategory.Error, $"Failed to get HID device change count: {GetError()}");
}
@@ -31,7 +31,7 @@ public static uint DeviceChangeCount() {
}
public static Span Enumerate(ushort vendorId, ushort productId) {
- nint result = SDL_hid_enumerate(vendorId, productId);
+ var result = SDL_hid_enumerate(vendorId, productId);
if (result == nint.Zero) {
LogError(LogCategory.Error, $"Failed to enumerate HID devices: {GetError()}");
return [];
@@ -51,7 +51,7 @@ public static Span Enumerate(ushort vendorId, ushort productId) {
}
public static int Exit() {
- int result = SDL_hid_exit();
+ var result = SDL_hid_exit();
if (result != 0) {
LogError(LogCategory.Error, $"Failed to exit HID API: {GetError()}");
}
@@ -69,7 +69,7 @@ public static void FreeEnumeration(nint devs) {
}
public static Span GetDeviceInfo(nint dev) {
- nint result = SDL_hid_get_device_info(dev);
+ var result = SDL_hid_get_device_info(dev);
if (result == nint.Zero) {
LogError(LogCategory.Error, $"Failed to get HID device info: {GetError()}");
return [];
@@ -89,7 +89,7 @@ public static Span GetDeviceInfo(nint dev) {
}
public static int GetFeatureReport(nint dev, nint data, nuint length) {
- int result = SDL_hid_get_feature_report(dev, data, length);
+ var result = SDL_hid_get_feature_report(dev, data, length);
if (result < 0) {
LogError(LogCategory.Error, $"Failed to get feature report from HID device: {GetError()}");
}
@@ -97,7 +97,7 @@ public static int GetFeatureReport(nint dev, nint data, nuint length) {
}
public static int GetIndexedString(nint dev, int stringIndex, string @string, nuint maxLen) {
- int result = SDL_hid_get_indexed_string(dev, stringIndex, @string, maxLen);
+ var result = SDL_hid_get_indexed_string(dev, stringIndex, @string, maxLen);
if (result < 0) {
LogError(LogCategory.Error, $"Failed to get indexed string from HID device: {GetError()}");
}
@@ -105,7 +105,7 @@ public static int GetIndexedString(nint dev, int stringIndex, string @string, nu
}
public static int GetInputReport(nint dev, nint data, nuint length) {
- int result = SDL_hid_get_input_report(dev, data, length);
+ var result = SDL_hid_get_input_report(dev, data, length);
if (result < 0) {
LogError(LogCategory.Error, $"Failed to get input report from HID device: {GetError()}");
}
@@ -113,7 +113,7 @@ public static int GetInputReport(nint dev, nint data, nuint length) {
}
public static int GetManufacturerString(nint dev, string @string, nuint maxLen) {
- int result = SDL_hid_get_manufacturer_string(dev, @string, maxLen);
+ var result = SDL_hid_get_manufacturer_string(dev, @string, maxLen);
if (result < 0) {
LogError(LogCategory.Error, $"Failed to get manufacturer string from HID device: {GetError()}");
}
@@ -121,7 +121,7 @@ public static int GetManufacturerString(nint dev, string @string, nuint maxLen)
}
public static int GetProductString(nint dev, string @string, nuint maxLen) {
- int result = SDL_hid_get_product_string(dev, @string, maxLen);
+ var result = SDL_hid_get_product_string(dev, @string, maxLen);
if (result < 0) {
LogError(LogCategory.Error, $"Failed to get product string from HID device: {GetError()}");
}
@@ -129,7 +129,7 @@ public static int GetProductString(nint dev, string @string, nuint maxLen) {
}
public static int GetReportDescriptor(nint dev, nint buf, nuint bufSize) {
- int result = SDL_hid_get_report_descriptor(dev, buf, bufSize);
+ var result = SDL_hid_get_report_descriptor(dev, buf, bufSize);
if (result < 0) {
LogError(LogCategory.Error, $"Failed to get report descriptor from HID device: {GetError()}");
}
@@ -137,7 +137,7 @@ public static int GetReportDescriptor(nint dev, nint buf, nuint bufSize) {
}
public static int GetSerialNumberString(nint dev, string @string, nuint maxLen) {
- int result = SDL_hid_get_serial_number_string(dev, @string, maxLen);
+ var result = SDL_hid_get_serial_number_string(dev, @string, maxLen);
if (result < 0) {
LogError(LogCategory.Error, $"Failed to get serial number string from HID device: {GetError()}");
}
@@ -145,7 +145,7 @@ public static int GetSerialNumberString(nint dev, string @string, nuint maxLen)
}
public static int Init() {
- int result = SDL_hid_init();
+ var result = SDL_hid_init();
if (result != 0) {
LogError(LogCategory.Error, $"Failed to initialize HID API: {GetError()}");
}
@@ -153,7 +153,7 @@ public static int Init() {
}
public static nint Open(ushort vendorId, ushort productId, string serialNumber) {
- nint result = SDL_hid_open(vendorId, productId, serialNumber);
+ var result = SDL_hid_open(vendorId, productId, serialNumber);
if (result == nint.Zero) {
LogError(LogCategory.Error, $"Failed to open HID device: {GetError()}");
}
@@ -161,7 +161,7 @@ public static nint Open(ushort vendorId, ushort productId, string serialNumber)
}
public static nint OpenPath(string path) {
- nint result = SDL_hid_open_path(path);
+ var result = SDL_hid_open_path(path);
if (result == nint.Zero) {
LogError(LogCategory.Error, $"Failed to open HID device at path {path}: {GetError()}");
}
@@ -169,7 +169,7 @@ public static nint OpenPath(string path) {
}
public static int Read(nint dev, nint data, nuint length) {
- int result = SDL_hid_read(dev, data, length);
+ var result = SDL_hid_read(dev, data, length);
if (result < 0) {
LogError(LogCategory.Error, $"Failed to read from HID device: {GetError()}");
}
@@ -177,7 +177,7 @@ public static int Read(nint dev, nint data, nuint length) {
}
public static int ReadTimeout(nint dev, nint data, nuint length, int milliseconds) {
- int result = SDL_hid_read_timeout(dev, data, length, milliseconds);
+ var result = SDL_hid_read_timeout(dev, data, length, milliseconds);
if (result < 0) {
LogError(LogCategory.Error, $"Failed to read from HID device: {GetError()}");
}
@@ -185,7 +185,7 @@ public static int ReadTimeout(nint dev, nint data, nuint length, int millisecond
}
public static int SendFeatureReport(nint dev, nint data, nuint length) {
- int result = SDL_hid_send_feature_report(dev, data, length);
+ var result = SDL_hid_send_feature_report(dev, data, length);
if (result < 0) {
LogError(LogCategory.Error, $"Failed to send feature report to HID device: {GetError()}");
}
@@ -193,7 +193,7 @@ public static int SendFeatureReport(nint dev, nint data, nuint length) {
}
public static int SetNonblocking(nint dev, int nonBlock) {
- int result = SDL_hid_set_nonblocking(dev, nonBlock);
+ var result = SDL_hid_set_nonblocking(dev, nonBlock);
if (result < 0) {
LogError(LogCategory.Error, $"Failed to set non-blocking mode for HID device: {GetError()}");
}
@@ -201,7 +201,7 @@ public static int SetNonblocking(nint dev, int nonBlock) {
}
public static int Write(nint dev, nint data, nuint length) {
- int result = SDL_hid_write(dev, data, length);
+ var result = SDL_hid_write(dev, data, length);
if (result < 0) {
LogError(LogCategory.Error, $"Failed to write to HID device: {GetError()}");
}
diff --git a/SDL3/IO.cs b/SDL3/SDL/IO.cs
similarity index 94%
rename from SDL3/IO.cs
rename to SDL3/SDL/IO.cs
index be2ae93..c49ada8 100644
--- a/SDL3/IO.cs
+++ b/SDL3/SDL/IO.cs
@@ -28,7 +28,7 @@ public static bool FlushIo(IoStream context) {
///
/// Returns a valid property ID on success or 0 on failure; call for more information.
public static uint GetIoProperties(IoStream context) {
- uint result = SDL_GetIOProperties(context.Handle);
+ var result = SDL_GetIOProperties(context.Handle);
return result == 0 ? throw new IOException($"GetIOProperties failed: {GetError()}") : result;
}
@@ -40,7 +40,7 @@ public static uint GetIoProperties(IoStream context) {
///
/// Returns the size of the data stream in the on success or a negative error code on failure; call for more information.
public static long GetIoSize(IoStream context) {
- long result = SDL_GetIOSize(context.Handle);
+ var result = SDL_GetIOSize(context.Handle);
return result == 0 ? throw new IOException($"GetIOSize failed: {GetError()}") : result;
}
@@ -55,7 +55,7 @@ public static long GetIoSize(IoStream context) {
///
/// Returns an enum with the current state.
public static IoStatus GetIoStatus(IoStream context) {
- IoStatus result = SDL_GetIOStatus(context.Handle);
+ var result = SDL_GetIOStatus(context.Handle);
return result == 0 ? throw new IOException($"GetIOStatus failed: {GetError()}") : result;
}
@@ -75,7 +75,7 @@ public static IoStatus GetIoStatus(IoStream context) {
///
/// (SDL_IOStream *) Returns a pointer to a new structure or on failure; call for more information.
public static IoStream IoFromConstMem(nint mem, nuint size) {
- nint result = SDL_IOFromConstMem(mem, size);
+ var result = SDL_IOFromConstMem(mem, size);
if (result == nint.Zero) {
throw new IOException($"IOFromConstMem failed: {GetError()}");
}
@@ -100,7 +100,7 @@ public static IoStream IoFromConstMem(nint mem, nuint size) {
///
/// (SDL_IOStream *) Returns a pointer to a new structure or on failure; call for more information.
public static IoStream IoFromDynamicMem() {
- nint result = SDL_IOFromDynamicMem();
+ var result = SDL_IOFromDynamicMem();
if (result == nint.Zero) {
throw new IOException($"IOFromDynamicMem failed: {GetError()}");
}
@@ -112,7 +112,7 @@ public static IoStream IoFromDynamicMem() {
}
public static IoStream IoFromFile(string file, string mode) {
- nint result = SDL_IOFromFile(file, mode);
+ var result = SDL_IOFromFile(file, mode);
if (result == nint.Zero) {
throw new IOException($"IOFromFile failed: {GetError()}");
}
@@ -140,7 +140,7 @@ public static IoStream IoFromFile(string file, string mode) {
///
/// (SDL_IOStream *) Returns a pointer to a new structure or on failure; call for more information.
public static IoStream IoFromMem(nint mem, nuint size) {
- nint result = SDL_IOFromMem(mem, size);
+ var result = SDL_IOFromMem(mem, size);
if (result == nint.Zero) {
throw new IOException($"IOFromMem failed: {GetError()}");
}
@@ -163,7 +163,7 @@ public static IoStream IoFromMem(nint mem, nuint size) {
///
/// Returns the number of bytes written or 0 on failure; call for more information.
public static nuint IoPrintf(IoStream context, string fmt) {
- nuint result = SDL_IOprintf(context.Handle, fmt);
+ var result = SDL_IOprintf(context.Handle, fmt);
return result == 0 ? throw new IOException($"IOprintf failed: {GetError()}") : result;
}
@@ -181,7 +181,7 @@ public static nuint IoPrintf(IoStream context, string fmt) {
/// (void *) Returns the data or on failure; call for more information.
public static nint LoadFile(string file, out nuint dataSize) {
// Initialize the variable to avoid CS0165
- nint result = SDL_LoadFile(file, out nuint ds);
+ var result = SDL_LoadFile(file, out var ds);
if (result == 0) {
throw new IOException($"LoadFile failed: {GetError()}");
}
@@ -191,7 +191,7 @@ public static nint LoadFile(string file, out nuint dataSize) {
public static nint LoadFileIo(IoStream src, out nuint dataSize, bool closeIo) {
// Initialize the variable to avoid CS0165
- nint result = SDL_LoadFile_IO(src.Handle, out nuint ds, closeIo);
+ var result = SDL_LoadFile_IO(src.Handle, out var ds, closeIo);
if (result == 0) {
throw new IOException($"LoadFile_IO failed: {GetError()}");
}
@@ -201,7 +201,7 @@ public static nint LoadFileIo(IoStream src, out nuint dataSize, bool closeIo) {
}
public static IoStream OpenIo(ref IoStreamInterface iFace, nint userdata) {
- nint result = SDL_OpenIO(ref iFace, userdata);
+ var result = SDL_OpenIO(ref iFace, userdata);
if (result == 0) {
throw new IOException($"OpenIO failed: {GetError()}");
}
@@ -214,7 +214,7 @@ public static IoStream OpenIo(ref IoStreamInterface iFace, nint userdata) {
}
public static nuint ReadIo(IoStream context, nint ptr, nuint size) {
- nuint result = SDL_ReadIO(context.Handle, ptr, size);
+ var result = SDL_ReadIO(context.Handle, ptr, size);
return result == 0 ? throw new IOException($"ReadIO failed: {GetError()}") : result;
}
@@ -230,7 +230,7 @@ public static nuint ReadIo(IoStream context, nint ptr, nuint size) {
/// Returns on successful write or on failure; call for more information.
public static bool ReadS16Be(IoStream src, out short value) {
// Initialize the variable to avoid CS0165
- bool result = SDL_ReadS16BE(src.Handle, out short v);
+ bool result = SDL_ReadS16BE(src.Handle, out var v);
if (!result) {
throw new IOException($"ReadS16BE failed: {GetError()}");
}
@@ -250,7 +250,7 @@ public static bool ReadS16Be(IoStream src, out short value) {
/// Returns on successful write or on failure; call for more information.
public static bool ReadS16Le(IoStream src, out short value) {
// Initialize the variable to avoid CS0165
- bool result = SDL_ReadS16LE(src.Handle, out short v);
+ bool result = SDL_ReadS16LE(src.Handle, out var v);
if (!result) {
throw new IOException($"ReadS16LE failed: {GetError()}");
}
@@ -270,7 +270,7 @@ public static bool ReadS16Le(IoStream src, out short value) {
/// Returns on successful write or on failure; call for more information.
public static bool ReadS32Be(IoStream src, out int value) {
// Initialize the variable to avoid CS0165
- bool result = SDL_ReadS32BE(src.Handle, out int v);
+ bool result = SDL_ReadS32BE(src.Handle, out var v);
if (!result) {
throw new IOException($"ReadS32BE failed: {GetError()}");
}
@@ -290,7 +290,7 @@ public static bool ReadS32Be(IoStream src, out int value) {
/// Returns on successful write or on failure; call for more information.
public static bool ReadS32Le(IoStream src, out int value) {
// Initialize the variable to avoid CS0165
- bool result = SDL_ReadS32LE(src.Handle, out int v);
+ bool result = SDL_ReadS32LE(src.Handle, out var v);
if (!result) {
throw new IOException($"ReadS32LE failed: {GetError()}");
}
@@ -310,7 +310,7 @@ public static bool ReadS32Le(IoStream src, out int value) {
/// Returns on successful write or on failure; call for more information.
public static bool ReadS64Be(IoStream src, out long value) {
// Initialize the variable to avoid CS0165
- bool result = SDL_ReadS64BE(src.Handle, out long v);
+ bool result = SDL_ReadS64BE(src.Handle, out var v);
if (!result) {
throw new IOException($"ReadS64BE failed: {GetError()}");
}
@@ -330,7 +330,7 @@ public static bool ReadS64Be(IoStream src, out long value) {
/// Returns on successful write or on failure; call for more information.
public static bool ReadS64Le(IoStream src, out long value) {
// Initialize the variable to avoid CS0165
- bool result = SDL_ReadS64LE(src.Handle, out long v);
+ bool result = SDL_ReadS64LE(src.Handle, out var v);
if (!result) {
throw new IOException($"ReadS64LE failed: {GetError()}");
}
@@ -353,7 +353,7 @@ public static bool ReadS64Le(IoStream src, out long value) {
/// Returns on success or on failure; call for more information.
public static bool ReadS8(IoStream src, out sbyte value) {
// Initialize the variable to avoid CS0165
- bool result = SDL_ReadS8(src.Handle, out sbyte v);
+ bool result = SDL_ReadS8(src.Handle, out var v);
if (!result) {
throw new IOException($"ReadS8 failed: {GetError()}");
}
@@ -373,7 +373,7 @@ public static bool ReadS8(IoStream src, out sbyte value) {
/// Returns on successful write or on failure; call for more information.
public static bool ReadU16Be(IoStream src, out ushort value) {
// Initialize the variable to avoid CS0165
- bool result = SDL_ReadU16BE(src.Handle, out ushort v);
+ bool result = SDL_ReadU16BE(src.Handle, out var v);
if (!result) {
throw new IOException($"ReadU16BE failed: {GetError()}");
}
@@ -393,7 +393,7 @@ public static bool ReadU16Be(IoStream src, out ushort value) {
/// Returns on successful write or on failure; call for more information.
public static bool ReadU16Le(IoStream src, out ushort value) {
// Initialize the variable to avoid CS0165
- bool result = SDL_ReadU16LE(src.Handle, out ushort v);
+ bool result = SDL_ReadU16LE(src.Handle, out var v);
if (!result) {
throw new IOException($"ReadU16LE failed: {GetError()}");
}
@@ -413,7 +413,7 @@ public static bool ReadU16Le(IoStream src, out ushort value) {
/// Returns on successful write or on failure; call for more information.
public static bool ReadU32Be(IoStream src, out uint value) {
// Initialize the variable to avoid CS0165
- bool result = SDL_ReadU32BE(src.Handle, out uint v);
+ bool result = SDL_ReadU32BE(src.Handle, out var v);
if (!result) {
throw new IOException($"ReadU32BE failed: {GetError()}");
}
@@ -433,7 +433,7 @@ public static bool ReadU32Be(IoStream src, out uint value) {
/// Returns on successful write or on failure; call for more information.
public static bool ReadU32Le(IoStream src, out uint value) {
// Initialize the variable to avoid CS0165
- bool result = SDL_ReadU32LE(src.Handle, out uint v);
+ bool result = SDL_ReadU32LE(src.Handle, out var v);
if (!result) {
throw new IOException($"ReadU32LE failed: {GetError()}");
}
@@ -453,7 +453,7 @@ public static bool ReadU32Le(IoStream src, out uint value) {
/// Returns on successful write or on failure; call for more information.
public static bool ReadU64Be(IoStream src, out ulong value) {
// Initialize the variable to avoid CS0165
- bool result = SDL_ReadU64BE(src.Handle, out ulong v);
+ bool result = SDL_ReadU64BE(src.Handle, out var v);
if (!result) {
throw new IOException($"ReadU64BE failed: {GetError()}");
}
@@ -473,7 +473,7 @@ public static bool ReadU64Be(IoStream src, out ulong value) {
/// Returns on successful write or on failure; call for more information.
public static bool ReadU64Le(IoStream src, out ulong value) {
// Initialize the variable to avoid CS0165
- bool result = SDL_ReadU64LE(src.Handle, out ulong v);
+ bool result = SDL_ReadU64LE(src.Handle, out var v);
if (!result) {
throw new IOException($"ReadU64LE failed: {GetError()}");
}
@@ -497,7 +497,7 @@ public static bool ReadU64Le(IoStream src, out ulong value) {
/// Returns on success or on failure or EOF; call for more information.
public static bool ReadU8(IoStream src, out byte value) {
// Initialize the variable to avoid CS0165
- bool result = SDL_ReadU8(src.Handle, out byte v);
+ bool result = SDL_ReadU8(src.Handle, out var v);
if (!result) {
throw new IOException($"ReadU8 failed: {GetError()}");
}
@@ -516,18 +516,18 @@ public static bool SaveFileIo(nint src, nint data, nuint dataSize, bool closeIo)
}
public static long SeekIo(IoStream context, long offset, IoWhence whence) {
- long result = SDL_SeekIO(context.Handle, offset, whence);
+ var result = SDL_SeekIO(context.Handle, offset, whence);
return result < 0 ? throw new IOException($"SeekIO failed: {GetError()}") : result;
}
public static long TellIo(IoStream context) {
- long result = SDL_TellIO(context.Handle);
+ var result = SDL_TellIO(context.Handle);
return result < 0 ? throw new IOException($"TellIO failed: {GetError()}") : result;
}
public static nuint WriteIo(IoStream context, nint ptr, nuint size) {
- nuint result = SDL_WriteIO(context.Handle, ptr, size);
+ var result = SDL_WriteIO(context.Handle, ptr, size);
return result < size ? throw new IOException($"WriteIO failed: {GetError()}") : result;
}
diff --git a/SDL3/JoySticks.cs b/SDL3/SDL/JoySticks.cs
similarity index 93%
rename from SDL3/JoySticks.cs
rename to SDL3/SDL/JoySticks.cs
index adb2616..a2de56f 100644
--- a/SDL3/JoySticks.cs
+++ b/SDL3/SDL/JoySticks.cs
@@ -24,7 +24,7 @@ public static uint AttachVirtualJoystick(ref VirtualJoystickDesc desc) {
if (desc.Name == nint.Zero) {
throw new ArgumentException("Virtual joystick description must have a valid name.", nameof(desc));
}
- uint instanceId = SDL_AttachVirtualJoystick(ref desc);
+ var instanceId = SDL_AttachVirtualJoystick(ref desc);
if (instanceId == 0) {
throw new InvalidOperationException("Failed to attach virtual joystick.");
}
@@ -59,7 +59,7 @@ public static SdlBool DetachVirtualJoystick(uint instanceId) {
if (instanceId == 0) {
throw new ArgumentException("Instance ID cannot be zero.", nameof(instanceId));
}
- SdlBool result = SDL_DetachVirtualJoystick(instanceId);
+ var result = SDL_DetachVirtualJoystick(instanceId);
if (!result) {
throw new InvalidOperationException($"Failed to detach virtual joystick with instance ID {instanceId}.");
}
@@ -88,7 +88,7 @@ public static short GetJoystickAxis(nint joystick, int axis) {
if (axis < 0) {
throw new ArgumentException("Axis cannot be negative.", nameof(axis));
}
- short axisValue = SDL_GetJoystickAxis(joystick, axis);
+ var axisValue = SDL_GetJoystickAxis(joystick, axis);
return axisValue;
}
@@ -110,7 +110,7 @@ public static SdlBool GetJoystickAxisInitialState(nint joystick, int axis, out s
if (axis < 0) {
throw new ArgumentException("Axis cannot be negative.", nameof(axis));
}
- SdlBool result = SDL_GetJoystickAxisInitialState(joystick, axis, out state);
+ var result = SDL_GetJoystickAxisInitialState(joystick, axis, out state);
return result;
}
@@ -136,7 +136,7 @@ public static SdlBool GetJoystickBall(nint joystick, int ball, out int dx, out i
if (ball < 0) {
throw new ArgumentException("Ball cannot be negative.", nameof(ball));
}
- SdlBool result = SDL_GetJoystickBall(joystick, ball, out dx, out dy);
+ var result = SDL_GetJoystickBall(joystick, ball, out dx, out dy);
return result;
}
@@ -157,7 +157,7 @@ public static SdlBool GetJoystickButton(nint joystick, int button) {
if (button < 0) {
throw new ArgumentException("Button cannot be negative.", nameof(button));
}
- SdlBool buttonState = SDL_GetJoystickButton(joystick, button);
+ var buttonState = SDL_GetJoystickButton(joystick, button);
return buttonState;
}
@@ -173,7 +173,7 @@ public static JoystickConnectionState GetJoystickConnectionState(nint joystick)
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- JoystickConnectionState connectionState = SDL_GetJoystickConnectionState(joystick);
+ var connectionState = SDL_GetJoystickConnectionState(joystick);
return connectionState;
}
@@ -190,7 +190,7 @@ public static ushort GetJoystickFirmwareVersion(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- ushort firmwareVersion = SDL_GetJoystickFirmwareVersion(joystick);
+ var firmwareVersion = SDL_GetJoystickFirmwareVersion(joystick);
return firmwareVersion;
}
@@ -206,7 +206,7 @@ public static nint GetJoystickFromId(uint instanceId) {
if (instanceId == 0) {
throw new ArgumentException("Instance ID cannot be zero.", nameof(instanceId));
}
- nint joystick = SDL_GetJoystickFromID(instanceId);
+ var joystick = SDL_GetJoystickFromID(instanceId);
if (joystick == nint.Zero) {
throw new InvalidOperationException($"Failed to get joystick from ID {instanceId}.");
}
@@ -227,7 +227,7 @@ public static nint GetJoystickFromPlayerIndex(int playerIndex) {
if (playerIndex < 0) {
throw new ArgumentException("Player index cannot be negative.", nameof(playerIndex));
}
- nint joystick = SDL_GetJoystickFromPlayerIndex(playerIndex);
+ var joystick = SDL_GetJoystickFromPlayerIndex(playerIndex);
if (joystick == nint.Zero) {
throw new InvalidOperationException($"Failed to get joystick from player index {playerIndex}.");
}
@@ -249,7 +249,7 @@ public static SdlGuid GetJoystickGuid(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- SdlGuid guid = SDL_GetJoystickGUID(joystick);
+ var guid = SDL_GetJoystickGUID(joystick);
if (guid.Data == null) {
throw new InvalidOperationException("Failed to get joystick GUID.");
}
@@ -311,7 +311,7 @@ public static byte GetJoystickHat(nint joystick, int hat) {
if (hat < 0) {
throw new ArgumentException("Hat cannot be negative.", nameof(hat));
}
- byte hatValue = SDL_GetJoystickHat(joystick, hat);
+ var hatValue = SDL_GetJoystickHat(joystick, hat);
return hatValue;
}
@@ -327,7 +327,7 @@ public static uint GetJoystickId(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- uint id = SDL_GetJoystickID(joystick);
+ var id = SDL_GetJoystickID(joystick);
return id;
}
@@ -344,7 +344,7 @@ public static string GetJoystickName(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- string joystickName = SDL_GetJoystickName(joystick);
+ var joystickName = SDL_GetJoystickName(joystick);
if (string.IsNullOrEmpty(joystickName)) {
throw new InvalidOperationException("Failed to get joystick name.");
}
@@ -367,7 +367,7 @@ public static string GetJoystickNameForId(uint instanceId) {
throw new ArgumentException("Instance ID cannot be zero.", nameof(instanceId));
}
- string joystickName = SDL_GetJoystickNameForID(instanceId);
+ var joystickName = SDL_GetJoystickNameForID(instanceId);
if (string.IsNullOrEmpty(joystickName)) {
throw new InvalidOperationException($"No joystick found for instance ID {instanceId}.");
}
@@ -388,7 +388,7 @@ public static string GetJoystickPath(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- string joystickPath = SDL_GetJoystickPath(joystick);
+ var joystickPath = SDL_GetJoystickPath(joystick);
if (string.IsNullOrEmpty(joystickPath)) {
throw new InvalidOperationException("Failed to get joystick path.");
}
@@ -410,7 +410,7 @@ public static string GetJoystickPathForId(uint instanceId) {
if (instanceId == 0) {
throw new ArgumentException("Instance ID cannot be zero.", nameof(instanceId));
}
- string joystickPath = SDL_GetJoystickPathForID(instanceId);
+ var joystickPath = SDL_GetJoystickPathForID(instanceId);
if (string.IsNullOrEmpty(joystickPath)) {
throw new InvalidOperationException($"No joystick found for instance ID {instanceId}.");
}
@@ -432,7 +432,7 @@ public static int GetJoystickPlayerIndex(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- int playerIndex = SDL_GetJoystickPlayerIndex(joystick);
+ var playerIndex = SDL_GetJoystickPlayerIndex(joystick);
if (playerIndex < 0) {
throw new InvalidOperationException("Failed to get joystick player index.");
}
@@ -475,7 +475,7 @@ public static PowerState GetJoystickPowerInfo(nint joystick, out int percent) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- PowerState powerState = SDL_GetJoystickPowerInfo(joystick, out percent);
+ var powerState = SDL_GetJoystickPowerInfo(joystick, out percent);
return powerState;
}
@@ -493,7 +493,7 @@ public static ushort GetJoystickProduct(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- ushort product = SDL_GetJoystickProduct(joystick);
+ var product = SDL_GetJoystickProduct(joystick);
return product;
}
@@ -530,7 +530,7 @@ public static ushort GetJoystickProductVersion(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- ushort productVersion = SDL_GetJoystickProductVersion(joystick);
+ var productVersion = SDL_GetJoystickProductVersion(joystick);
return productVersion;
}
@@ -566,7 +566,7 @@ public static uint GetJoystickProperties(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- uint properties = SDL_GetJoystickProperties(joystick);
+ var properties = SDL_GetJoystickProperties(joystick);
return properties;
}
@@ -581,13 +581,13 @@ public static uint GetJoystickProperties(nint joystick) {
/// (SDL_JoystickID *) Returns a 0 terminated array ofjoystick instance IDs or on failure; call for more information. This should be freedwith when it is no longer needed.
public static List GetJoysticks(out int count) {
- nint joystickArrayPtr = SDL_GetJoysticks(out count);
+ var joystickArrayPtr = SDL_GetJoysticks(out count);
if (joystickArrayPtr == 0 || count <= 0) {
return [];
}
- List joysticks = new(count);
- for (int i = 0; i < count; i++) {
+ List joysticks = new List(count);
+ for (var i = 0; i < count; i++) {
nint joystick = Marshal.ReadInt32(joystickArrayPtr, i * nint.Size);
joysticks.Add(joystick);
}
@@ -608,7 +608,7 @@ public static string GetJoystickSerial(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- string serial = SDL_GetJoystickSerial(joystick);
+ var serial = SDL_GetJoystickSerial(joystick);
if (string.IsNullOrEmpty(serial)) {
throw new InvalidOperationException("Failed to get joystick serial.");
}
@@ -628,7 +628,7 @@ public static JoystickType GetJoystickType(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- JoystickType joystickType = SDL_GetJoystickType(joystick);
+ var joystickType = SDL_GetJoystickType(joystick);
return joystickType;
}
@@ -664,7 +664,7 @@ public static ushort GetJoystickVendor(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- ushort vendor = SDL_GetJoystickVendor(joystick);
+ var vendor = SDL_GetJoystickVendor(joystick);
return vendor;
}
@@ -706,7 +706,7 @@ public static int GetNumJoystickAxes(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- int numAxes = SDL_GetNumJoystickAxes(joystick);
+ var numAxes = SDL_GetNumJoystickAxes(joystick);
return numAxes;
}
@@ -728,7 +728,7 @@ public static int GetNumJoystickBalls(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- int numBalls = SDL_GetNumJoystickBalls(joystick);
+ var numBalls = SDL_GetNumJoystickBalls(joystick);
return numBalls;
}
@@ -748,7 +748,7 @@ public static int GetNumJoystickButtons(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- int numButtons = SDL_GetNumJoystickButtons(joystick);
+ var numButtons = SDL_GetNumJoystickButtons(joystick);
return numButtons;
}
@@ -768,7 +768,7 @@ public static int GetNumJoystickHats(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- int numHats = SDL_GetNumJoystickHats(joystick);
+ var numHats = SDL_GetNumJoystickHats(joystick);
return numHats;
}
@@ -795,7 +795,7 @@ public static SdlBool IsJoystickVirtual(uint instanceId) {
if (instanceId == 0) {
throw new ArgumentException("Instance ID cannot be zero.", nameof(instanceId));
}
- SdlBool result = SDL_IsJoystickVirtual(instanceId);
+ var result = SDL_IsJoystickVirtual(instanceId);
return result;
}
@@ -811,7 +811,7 @@ public static SdlBool JoystickConnected(nint joystick) {
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- SdlBool connected = SDL_JoystickConnected(joystick);
+ var connected = SDL_JoystickConnected(joystick);
return connected;
}
@@ -853,7 +853,7 @@ public static void LockJoysticks() {
/// (SDL_Joystick *) Returns a joystick identifier or on failure; call for more information.
public static nint OpenJoystick(uint instanceId) {
- nint joystick = SDL_OpenJoystick(instanceId);
+ var joystick = SDL_OpenJoystick(instanceId);
if (joystick == nint.Zero) {
throw new SdlException($"Failed to open joystick with instance ID {instanceId}. {GetError()}");
}
@@ -880,7 +880,7 @@ public static SdlBool RumbleJoystick(nint joystick, ushort lowFrequencyRumble, u
if (lowFrequencyRumble < 0 || highFrequencyRumble < 0) {
throw new ArgumentException("Rumble values cannot be negative.");
}
- SdlBool result = SDL_RumbleJoystick(joystick, lowFrequencyRumble, highFrequencyRumble, durationMs);
+ var result = SDL_RumbleJoystick(joystick, lowFrequencyRumble, highFrequencyRumble, durationMs);
return result;
}
@@ -905,7 +905,7 @@ public static SdlBool RumbleJoystickTriggers(nint joystick, ushort leftRumble, u
if (leftRumble < 0 || rightRumble < 0) {
throw new ArgumentException("Rumble values cannot be negative.");
}
- SdlBool result = SDL_RumbleJoystickTriggers(joystick, leftRumble, rightRumble, durationMs);
+ var result = SDL_RumbleJoystickTriggers(joystick, leftRumble, rightRumble, durationMs);
return result;
}
@@ -929,7 +929,7 @@ public static SdlBool SendJoystickEffect(nint joystick, nint data, int size) {
if (size <= 0) {
throw new ArgumentException("Size must be positive.", nameof(size));
}
- SdlBool result = SDL_SendJoystickEffect(joystick, data, size);
+ var result = SDL_SendJoystickEffect(joystick, data, size);
return result;
}
@@ -962,7 +962,7 @@ public static SdlBool SendJoystickVirtualSensorData(nint joystick, SensorType ty
if (numValues <= 0) {
throw new ArgumentException("Number of values must be positive.", nameof(numValues));
}
- SdlBool result = SDL_SendJoystickVirtualSensorData(joystick, type, sensorTimestamp, data, numValues);
+ var result = SDL_SendJoystickVirtualSensorData(joystick, type, sensorTimestamp, data, numValues);
return result;
}
@@ -996,7 +996,7 @@ public static SdlBool SendJoystickVirtualSensorData(nint joystick, SensorType ty
throw new ArgumentException("Data array cannot be null or empty.", nameof(data));
}
- nint pData = Marshal.AllocHGlobal(data.Length * sizeof(float));
+ var pData = Marshal.AllocHGlobal(data.Length * sizeof(float));
bool result = SendJoystickVirtualSensorData(joystick, type, sensorTimestamp, pData, data.Length);
@@ -1042,7 +1042,7 @@ public static SdlBool SetJoystickLed(nint joystick, byte red, byte green, byte b
if (joystick == nint.Zero) {
throw new ArgumentException("Joystick cannot be null.", nameof(joystick));
}
- SdlBool result = SDL_SetJoystickLED(joystick, red, green, blue);
+ var result = SDL_SetJoystickLED(joystick, red, green, blue);
return result;
}
@@ -1063,7 +1063,7 @@ public static SdlBool SetJoystickPlayerIndex(nint joystick, int playerIndex) {
if (playerIndex < 0) {
throw new ArgumentException("Player index cannot be negative.", nameof(playerIndex));
}
- SdlBool result = SDL_SetJoystickPlayerIndex(joystick, playerIndex);
+ var result = SDL_SetJoystickPlayerIndex(joystick, playerIndex);
return result;
}
@@ -1091,7 +1091,7 @@ public static SdlBool SetJoystickVirtualAxis(nint joystick, int axis, short valu
if (axis < 0) {
throw new ArgumentException("Axis cannot be negative.", nameof(axis));
}
- SdlBool result = SDL_SetJoystickVirtualAxis(joystick, axis, value);
+ var result = SDL_SetJoystickVirtualAxis(joystick, axis, value);
return result;
}
@@ -1120,7 +1120,7 @@ public static SdlBool SetJoystickVirtualBall(nint joystick, int ball, short xrel
if (ball < 0) {
throw new ArgumentException("Ball cannot be negative.", nameof(ball));
}
- SdlBool result = SDL_SetJoystickVirtualBall(joystick, ball, xrel, yrel);
+ var result = SDL_SetJoystickVirtualBall(joystick, ball, xrel, yrel);
return result;
}
@@ -1148,7 +1148,7 @@ public static SdlBool SetJoystickVirtualButton(nint joystick, int button, SdlBoo
if (button < 0) {
throw new ArgumentException("Button cannot be negative.", nameof(button));
}
- SdlBool result = SDL_SetJoystickVirtualButton(joystick, button, down);
+ var result = SDL_SetJoystickVirtualButton(joystick, button, down);
return result;
}
@@ -1176,7 +1176,7 @@ public static SdlBool SetJoystickVirtualHat(nint joystick, int hat, byte value)
if (hat < 0) {
throw new ArgumentException("Hat cannot be negative.", nameof(hat));
}
- SdlBool result = SDL_SetJoystickVirtualHat(joystick, hat, value);
+ var result = SDL_SetJoystickVirtualHat(joystick, hat, value);
return result;
}
@@ -1211,7 +1211,7 @@ public static SdlBool SetJoystickVirtualTouchpad(nint joystick, int touchpad, in
if (finger < 0) {
throw new ArgumentException("Finger cannot be negative.", nameof(finger));
}
- SdlBool result = SDL_SetJoystickVirtualTouchpad(joystick, touchpad, finger, down, x, y, pressure);
+ var result = SDL_SetJoystickVirtualTouchpad(joystick, touchpad, finger, down, x, y, pressure);
return result;
}
diff --git a/SDL3/Logger.cs b/SDL3/SDL/Logger.cs
similarity index 97%
rename from SDL3/Logger.cs
rename to SDL3/SDL/Logger.cs
index fbed3d8..e529775 100644
--- a/SDL3/Logger.cs
+++ b/SDL3/SDL/Logger.cs
@@ -17,7 +17,7 @@ public static partial class Sdl {
///
/// Returns the default log output callback.
public static SdlLogOutputFunction GetDefaultLogOutputFunction() {
- SdlLogOutputFunction? callback = SDL_GetDefaultLogOutputFunction();
+ var callback = SDL_GetDefaultLogOutputFunction();
return callback ?? throw new InvalidOperationException("Failed to retrieve default log output function.");
}
diff --git a/SDL3/MessageBox.cs b/SDL3/SDL/MessageBox.cs
similarity index 94%
rename from SDL3/MessageBox.cs
rename to SDL3/SDL/MessageBox.cs
index a776a17..03dd0b8 100644
--- a/SDL3/MessageBox.cs
+++ b/SDL3/SDL/MessageBox.cs
@@ -16,7 +16,7 @@ public static unsafe bool ShowMessageBox(ref MessageBoxData messageboxdata, out
LogInfo(LogCategory.System, $"Showing message box with title: {Marshal.PtrToStringAnsi(messageboxdata.Title)}");
// Call the native method
- SdlBool result = SDL_ShowMessageBox(ref messageboxdata, out buttonid);
+ var result = SDL_ShowMessageBox(ref messageboxdata, out buttonid);
// Check the result and handle errors
if (!result) {
@@ -135,7 +135,7 @@ public static unsafe MessageBoxResult ShowMessageBox(nint windowOwner, string me
var buttonDataArray = new MessageBoxButtonData[buttonData.Length];
- for (int i = 0; i < buttonData.Length; i++) {
+ for (var i = 0; i < buttonData.Length; i++) {
buttonDataArray[i] = new MessageBoxButtonData {
Flags = accelerator == (MessageBoxDefaultButton)buttonData[i][2] ? accelerator : MessageBoxDefaultButton.EscapeKeyDefault,
ButtonID = (int)buttonData[i][1],
@@ -154,7 +154,7 @@ public static unsafe MessageBoxResult ShowMessageBox(nint windowOwner, string me
};
try {
- bool result = ShowMessageBox(ref messageboxdata, out int buttonid);
+ var result = ShowMessageBox(ref messageboxdata, out var buttonid);
if (!result) {
throw new InvalidOperationException("Failed to display the message box.");
@@ -163,7 +163,7 @@ public static unsafe MessageBoxResult ShowMessageBox(nint windowOwner, string me
return (MessageBoxResult)buttonid;
} finally {
// Ensure all unmanaged resources are freed
- foreach (MessageBoxButtonData button in buttonDataArray) {
+ foreach (var button in buttonDataArray) {
Marshal.FreeHGlobal(button.Text);
}
@@ -191,7 +191,7 @@ public static bool ShowSimpleMessageBox(MessageBoxFlags flags, string message, s
throw new ArgumentException("Title and message cannot be null or empty.");
}
- SdlBool result = SDL_ShowSimpleMessageBox(flags, title, message, window);
+ var result = SDL_ShowSimpleMessageBox(flags, title, message, window);
if (!result) {
throw new InvalidOperationException("Failed to display the simple message box.");
diff --git a/SDL3/Metal.cs b/SDL3/SDL/Metal.cs
similarity index 100%
rename from SDL3/Metal.cs
rename to SDL3/SDL/Metal.cs
diff --git a/SDL3/Misc.cs b/SDL3/SDL/Misc.cs
similarity index 95%
rename from SDL3/Misc.cs
rename to SDL3/SDL/Misc.cs
index e8524fe..50ed35c 100644
--- a/SDL3/Misc.cs
+++ b/SDL3/SDL/Misc.cs
@@ -29,7 +29,7 @@ public static bool OpenUrl(string url) {
throw new ArgumentException("URL is not well-formed.", nameof(url));
}
- SdlBool result = SDL_OpenURL(url);
+ var result = SDL_OpenURL(url);
if (!result) {
LogError(LogCategory.Error, $"Failed to open URL: {url}");
}
diff --git a/SDL3/Mouse.cs b/SDL3/SDL/Mouse.cs
similarity index 95%
rename from SDL3/Mouse.cs
rename to SDL3/SDL/Mouse.cs
index f8a1f7e..8bb410e 100644
--- a/SDL3/Mouse.cs
+++ b/SDL3/SDL/Mouse.cs
@@ -34,7 +34,7 @@ public static partial class Sdl {
/// (SDL_MouseID *) Returns a 0 terminated array of mouseinstance IDs or on failure; call for more information. This should be freed with when itis no longer needed.
public static nint GetMice(out int count) {
- nint result = SDL_GetMice(out count);
+ var result = SDL_GetMice(out count);
if (result == nint.Zero) {
throw new InvalidOperationException("Failed to get mice.");
}
@@ -58,7 +58,7 @@ public static string GetMouseNameForId(uint instanceId) {
throw new ArgumentException("Instance ID cannot be zero.", nameof(instanceId));
}
- string mouseName = SDL_GetMouseNameForID(instanceId);
+ var mouseName = SDL_GetMouseNameForID(instanceId);
if (string.IsNullOrEmpty(mouseName)) {
throw new InvalidOperationException($"Failed to retrieve mouse name for instance ID {instanceId}.");
}
@@ -124,7 +124,7 @@ public static MouseButtonFlags GetGlobalMouseState(out float x, out float y) {
///
/// Returns a 32-bit bitmask ofthe button state that can be bitwise-compared against theSDL_BUTTON_MASK(X) macro.
public static MouseButtonFlags GetRelativeMouseState(out float x, out float y) {
- MouseButtonFlags state = SDL_GetRelativeMouseState(out x, out y);
+ var state = SDL_GetRelativeMouseState(out x, out y);
if (x < -10000 || x > 10000 || y < -10000 || y > 10000) {
throw new InvalidOperationException("Relative mouse coordinates are out of expected range.");
@@ -186,7 +186,7 @@ public static bool WarpMouseGlobal(float x, float y) {
throw new ArgumentOutOfRangeException(nameof(y), "Mouse coordinates must be non-negative.");
}
- SdlBool result = SDL_WarpMouseGlobal(x, y);
+ var result = SDL_WarpMouseGlobal(x, y);
if (!result) {
LogError(LogCategory.Error, "Failed to warp mouse globally.");
}
@@ -214,7 +214,7 @@ public static bool SetWindowRelativeMouseMode(nint window, bool enabled) {
throw new ArgumentException("Window handle cannot be null.", nameof(window));
}
- SdlBool result = SDL_SetWindowRelativeMouseMode(window, enabled);
+ var result = SDL_SetWindowRelativeMouseMode(window, enabled);
if (!result) {
LogError(LogCategory.Error, $"Failed to set relative mouse mode for the specified window. {GetError()}");
}
@@ -237,7 +237,7 @@ public static bool GetWindowRelativeMouseMode(nint window) {
throw new ArgumentException("Window handle cannot be null.", nameof(window));
}
- SdlBool result = SDL_GetWindowRelativeMouseMode(window);
+ var result = SDL_GetWindowRelativeMouseMode(window);
if (!result) {
LogError(LogCategory.Error, $"Failed to retrieve relative mouse mode for the specified window. {GetError()}");
}
@@ -261,7 +261,7 @@ public static bool GetWindowRelativeMouseMode(nint window) {
/// Returns on success or on failure; call for more information.
public static bool CaptureMouse(bool enabled) {
- SdlBool result = SDL_CaptureMouse(enabled);
+ var result = SDL_CaptureMouse(enabled);
if (!result) {
LogError(LogCategory.Error, "Failed to capture mouse.");
}
@@ -313,7 +313,7 @@ public static nint CreateCursor(nint data, nint mask, int w, int h, int hotX, in
throw new ArgumentOutOfRangeException(nameof(hotY), "Hotspot Y coordinate must be within the cursor dimensions.");
}
- nint cursor = SDL_CreateCursor(data, mask, w, h, hotX, hotY);
+ var cursor = SDL_CreateCursor(data, mask, w, h, hotX, hotY);
if (cursor == nint.Zero) {
throw new InvalidOperationException("Failed to create cursor.");
}
@@ -359,7 +359,7 @@ public static nint CreateColorCursor(nint surface, int hotX, int hotY) {
throw new ArgumentOutOfRangeException(nameof(hotY), "Hotspot coordinates must be non-negative.");
}
- nint cursor = SDL_CreateColorCursor(surface, hotX, hotY);
+ var cursor = SDL_CreateColorCursor(surface, hotX, hotY);
if (cursor == nint.Zero) {
throw new InvalidOperationException("Failed to create color cursor.");
}
@@ -382,7 +382,7 @@ public static nint CreateSystemCursor(SystemCursor id) {
throw new ArgumentOutOfRangeException(nameof(id), "Invalid system cursor ID.");
}
- nint cursor = SDL_CreateSystemCursor(id);
+ var cursor = SDL_CreateSystemCursor(id);
if (cursor == nint.Zero) {
throw new InvalidOperationException("Failed to create system cursor.");
}
@@ -409,7 +409,7 @@ public static bool SetCursor(nint cursor) {
throw new ArgumentException("Cursor handle cannot be null.", nameof(cursor));
}
- SdlBool result = SDL_SetCursor(cursor);
+ var result = SDL_SetCursor(cursor);
if (!result) {
LogError(LogCategory.Error, "Failed to set the specified cursor.");
}
diff --git a/SDL3/Mutex.cs b/SDL3/SDL/Mutex.cs
similarity index 96%
rename from SDL3/Mutex.cs
rename to SDL3/SDL/Mutex.cs
index 90a377d..9780ec9 100644
--- a/SDL3/Mutex.cs
+++ b/SDL3/SDL/Mutex.cs
@@ -39,7 +39,7 @@ public static void BroadcastCondition(nint cond) {
/// (SDL_Condition *) Returns a new condition variable or on failure; call for more information.
public static nint CreateCondition() {
- nint cond = SDL_CreateCondition();
+ var cond = SDL_CreateCondition();
if (cond == nint.Zero) {
throw new InvalidOperationException($"Failed to create condition variable: {GetError()}");
}
@@ -58,7 +58,7 @@ public static nint CreateCondition() {
/// (SDL_Mutex *) Returns the initialized and unlocked mutex or on failure; call for more information.
public static nint CreateMutex() {
- nint mutex = SDL_CreateMutex();
+ var mutex = SDL_CreateMutex();
if (mutex == nint.Zero) {
throw new InvalidOperationException($"Failed to create mutex: {GetError()}");
}
@@ -85,7 +85,7 @@ public static nint CreateMutex() {
/// (SDL_RWLock *) Returns the initialized and unlockedread/write lock or on failure; call for more information.
public static nint CreateRwLock() {
- nint rwlock = SDL_CreateRWLock();
+ var rwlock = SDL_CreateRWLock();
if (rwlock == nint.Zero) {
throw new InvalidOperationException($"Failed to create RW lock: {GetError()}");
}
@@ -287,7 +287,7 @@ public static SdlBool ShouldQuit(ref InitState state) {
return false;
}
- SdlBool result = SDL_ShouldQuit(ref state);
+ var result = SDL_ShouldQuit(ref state);
if (!result.Equals(SdlBool.True)) {
LogInfo(LogCategory.System, "ShouldQuit: SDL_ShouldQuit returned false.");
} else {
@@ -478,10 +478,10 @@ public static SdlBool WaitConditionTimeout(nint cond, nint mutex, int timeoutMs)
throw new ArgumentOutOfRangeException(nameof(timeoutMs), "Timeout must be non-negative.");
}
- SdlBool result = SDL_WaitConditionTimeout(cond, mutex, timeoutMs);
+ var result = SDL_WaitConditionTimeout(cond, mutex, timeoutMs);
if (!result) {
- string error = GetError();
+ var error = GetError();
if (!string.IsNullOrEmpty(error)) {
throw new InvalidOperationException($"WaitConditionTimeout failed: {error}");
}
diff --git a/SDL3/OpenGL.cs b/SDL3/SDL/OpenGL.cs
similarity index 89%
rename from SDL3/OpenGL.cs
rename to SDL3/SDL/OpenGL.cs
index 61c85d7..d3ca7d5 100644
--- a/SDL3/OpenGL.cs
+++ b/SDL3/SDL/OpenGL.cs
@@ -10,7 +10,7 @@ namespace SharpSDL3;
public static partial class Sdl {
public static nint EglGetCurrentConfig() {
- nint result = SDL_EGL_GetCurrentConfig();
+ var result = SDL_EGL_GetCurrentConfig();
if (result == nint.Zero) {
throw new InvalidOperationException("Failed to get current EGL config.");
}
@@ -18,7 +18,7 @@ public static nint EglGetCurrentConfig() {
}
public static nint EglGetCurrentDisplay() {
- nint result = SDL_EGL_GetCurrentDisplay();
+ var result = SDL_EGL_GetCurrentDisplay();
if (result == nint.Zero) {
throw new InvalidOperationException("Failed to get current EGL display.");
}
@@ -29,7 +29,7 @@ public static nint EglGetProcAddress(string proc) {
if (string.IsNullOrWhiteSpace(proc)) {
throw new ArgumentException("Procedure name cannot be null, empty, or whitespace.", nameof(proc));
}
- nint result = SDL_EGL_GetProcAddress(proc);
+ var result = SDL_EGL_GetProcAddress(proc);
if (result == nint.Zero) {
throw new InvalidOperationException($"Failed to get EGL procedure address for: {proc}");
}
@@ -40,7 +40,7 @@ public static nint EglGetWindowSurface(nint window) {
if (window == nint.Zero) {
throw new ArgumentNullException(nameof(window), "Window cannot be null.");
}
- nint result = SDL_EGL_GetWindowSurface(window);
+ var result = SDL_EGL_GetWindowSurface(window);
if (result == nint.Zero) {
throw new InvalidOperationException("Failed to get EGL window surface.");
}
@@ -66,7 +66,7 @@ public static nint GlCreateContext(nint window) {
if (window == nint.Zero) {
throw new ArgumentNullException(nameof(window), "Window cannot be null.");
}
- nint result = SDL_GL_CreateContext(window);
+ var result = SDL_GL_CreateContext(window);
if (result == nint.Zero) {
throw new InvalidOperationException("Failed to create OpenGL context.");
}
@@ -77,7 +77,7 @@ public static SdlBool GlDestroyContext(nint context) {
if (context == nint.Zero) {
throw new ArgumentNullException(nameof(context), "Context cannot be null.");
}
- SdlBool result = SDL_GL_DestroyContext(context);
+ var result = SDL_GL_DestroyContext(context);
if (!result) {
throw new InvalidOperationException("Failed to destroy OpenGL context.");
}
@@ -88,7 +88,7 @@ public static SdlBool GlExtensionSupported(string extension) {
if (string.IsNullOrWhiteSpace(extension)) {
throw new ArgumentException("Extension name cannot be null, empty, or whitespace.", nameof(extension));
}
- SdlBool result = SDL_GL_ExtensionSupported(extension);
+ var result = SDL_GL_ExtensionSupported(extension);
if (!result) {
throw new InvalidOperationException($"OpenGL extension not supported: {extension}");
}
@@ -99,7 +99,7 @@ public static SdlBool GlGetAttribute(GlAttr attr, out int value) {
if (attr < 0 || attr > GlAttr.EglPlatform) {
throw new ArgumentOutOfRangeException(nameof(attr), "Invalid OpenGL attribute.");
}
- SdlBool result = SDL_GL_GetAttribute(attr, out value);
+ var result = SDL_GL_GetAttribute(attr, out value);
if (!result) {
throw new InvalidOperationException($"Failed to get OpenGL attribute: {attr}");
}
@@ -107,7 +107,7 @@ public static SdlBool GlGetAttribute(GlAttr attr, out int value) {
}
public static nint GlGetCurrentContext() {
- nint result = SDL_GL_GetCurrentContext();
+ var result = SDL_GL_GetCurrentContext();
if (result == nint.Zero) {
throw new InvalidOperationException("Failed to get current OpenGL context.");
}
@@ -115,7 +115,7 @@ public static nint GlGetCurrentContext() {
}
public static nint GlGetCurrentWindow() {
- nint result = SDL_GL_GetCurrentWindow();
+ var result = SDL_GL_GetCurrentWindow();
if (result == nint.Zero) {
throw new InvalidOperationException("Failed to get current OpenGL window.");
}
@@ -126,7 +126,7 @@ public static nint GlGetProcAddress(string proc) {
if (string.IsNullOrWhiteSpace(proc)) {
throw new ArgumentException("Procedure name cannot be null, empty, or whitespace.", nameof(proc));
}
- nint result = SDL_GL_GetProcAddress(proc);
+ var result = SDL_GL_GetProcAddress(proc);
if (result == nint.Zero) {
throw new InvalidOperationException($"Failed to get OpenGL procedure address for: {proc}");
}
@@ -134,7 +134,7 @@ public static nint GlGetProcAddress(string proc) {
}
public static SdlBool GlGetSwapInterval(out int interval) {
- SdlBool result = SDL_GL_GetSwapInterval(out interval);
+ var result = SDL_GL_GetSwapInterval(out interval);
if (!result) {
throw new InvalidOperationException("Failed to get OpenGL swap interval.");
}
@@ -146,7 +146,7 @@ public static SdlBool GlLoadLibrary(string path) {
throw new ArgumentException("Path cannot be null, empty, or whitespace.", nameof(path));
}
- SdlBool result = SDL_GL_LoadLibrary(path);
+ var result = SDL_GL_LoadLibrary(path);
if (!result) {
throw new InvalidOperationException($"Failed to load OpenGL library from path: {path}");
}
@@ -161,7 +161,7 @@ public static SdlBool GlMakeCurrent(nint window, nint context) {
if (context == nint.Zero) {
throw new ArgumentNullException(nameof(context), "Context cannot be null.");
}
- SdlBool result = SDL_GL_MakeCurrent(window, context);
+ var result = SDL_GL_MakeCurrent(window, context);
return !result ? throw new InvalidOperationException("Failed to make OpenGL context current.") : result;
}
@@ -176,7 +176,7 @@ public static SdlBool GlSetAttribute(GlAttr attr, int value) {
if (value < 0) {
throw new ArgumentOutOfRangeException(nameof(value), "Attribute value cannot be negative.");
}
- SdlBool result = SDL_GL_SetAttribute(attr, value);
+ var result = SDL_GL_SetAttribute(attr, value);
if (!result) {
throw new InvalidOperationException($"Failed to set OpenGL attribute: {attr}");
}
@@ -187,7 +187,7 @@ public static SdlBool GlSetSwapInterval(int interval) {
if (interval < 0) {
throw new ArgumentOutOfRangeException(nameof(interval), "Swap interval cannot be negative.");
}
- SdlBool result = SDL_GL_SetSwapInterval(interval);
+ var result = SDL_GL_SetSwapInterval(interval);
if (!result) {
throw new InvalidOperationException($"Failed to set OpenGL swap interval: {interval}");
}
@@ -198,7 +198,7 @@ public static SdlBool GlSwapWindow(nint window) {
if (window == nint.Zero) {
throw new ArgumentNullException(nameof(window), "Window cannot be null.");
}
- SdlBool result = SDL_GL_SwapWindow(window);
+ var result = SDL_GL_SwapWindow(window);
if (!result) {
throw new InvalidOperationException("Failed to swap OpenGL window.");
}
diff --git a/SDL3/Platform.cs b/SDL3/SDL/Platform.cs
similarity index 83%
rename from SDL3/Platform.cs
rename to SDL3/SDL/Platform.cs
index d377ced..95ad304 100644
--- a/SDL3/Platform.cs
+++ b/SDL3/SDL/Platform.cs
@@ -15,7 +15,6 @@ public static partial class Sdl {
/// Version: This function is available since SDL 3.2.0.
///
/// Returns the name of the platform. If the correct platformname is not available, returns a string beginning with the text "Unknown".
-
public static string GetPlatform() {
return SDL_GetPlatform();
}
@@ -23,7 +22,7 @@ public static string GetPlatform() {
/// Create a new process.
/// the path and arguments for the new process.
- /// to create pipes to the process's standard input and from the process's standard output, for the process to have no input and inherit the application's standard output.
+ /// to create pipes to the process's standard input and from the process's standard output, for the process to have no input and inherit the application's standard output.
///
/// The path to the executable is supplied in args[0]. args[1..N] are
/// additional arguments passed on the command line of the new process, and the
@@ -41,11 +40,11 @@ public static string GetPlatform() {
///
/// (SDL_Process *) Returns the newly created and runningprocess, or if the process couldn't be created.
- public static nint CreateProcess(nint args, SdlBool pipeStdio) {
- if (args == nint.Zero) {
- throw new ArgumentException("Arguments cannot be null.", nameof(args));
- }
- return SDL_CreateProcess(args, pipeStdio);
+ public static nint CreateProcess(nint args, SdlBool pipeStdio)
+ {
+ return args == nint.Zero
+ ? throw new ArgumentException("Arguments cannot be null.", nameof(args))
+ : SDL_CreateProcess(args, pipeStdio);
}
/// Create a new process with the specified properties.
@@ -71,13 +70,11 @@ public static nint CreateProcessWithProperties(uint props) {
throw new ArgumentException("Properties cannot be zero.", nameof(props));
}
- nint processHandle = SDL_CreateProcessWithProperties(props);
-
- if (processHandle == nint.Zero) {
- throw new InvalidOperationException("Failed to create process with the specified properties.");
- }
+ var processHandle = SDL_CreateProcessWithProperties(props);
- return processHandle;
+ return processHandle == nint.Zero
+ ? throw new InvalidOperationException("Failed to create process with the specified properties.")
+ : processHandle;
}
/// Get the properties associated with a process.
@@ -92,11 +89,11 @@ public static nint CreateProcessWithProperties(uint props) {
///
/// Returns a valid property ID on success or 0 on failure; call for more information.
- public static uint GetProcessProperties(nint process) {
- if (process == nint.Zero) {
- throw new ArgumentException("Process handle cannot be null.", nameof(process));
- }
- return SDL_GetProcessProperties(process);
+ public static uint GetProcessProperties(nint process)
+ {
+ return process == nint.Zero
+ ? throw new ArgumentException("Process handle cannot be null.", nameof(process))
+ : SDL_GetProcessProperties(process);
}
/// Read all the output from a process.
@@ -116,11 +113,11 @@ public static uint GetProcessProperties(nint process) {
///
/// (void *) Returns the data or on failure; call for more information.
- public static nint ReadProcess(nint process, out nuint datasize, out int exitcode) {
- if (process == nint.Zero) {
- throw new ArgumentException("Process handle cannot be null.", nameof(process));
- }
- return SDL_ReadProcess(process, out datasize, out exitcode);
+ public static nint ReadProcess(nint process, out nuint datasize, out int exitcode)
+ {
+ return process == nint.Zero
+ ? throw new ArgumentException("Process handle cannot be null.", nameof(process))
+ : SDL_ReadProcess(process, out datasize, out exitcode);
}
/// Get the SDL_IOStream associated with process standard input.
@@ -141,11 +138,11 @@ public static nint ReadProcess(nint process, out nuint datasize, out int exitcod
///
/// (SDL_IOStream *) Returns the input stream or on failure; call for more information.
- public static nint GetProcessInput(nint process) {
- if (process == nint.Zero) {
- throw new ArgumentException("Process handle cannot be null.", nameof(process));
- }
- return SDL_GetProcessInput(process);
+ public static nint GetProcessInput(nint process)
+ {
+ return process == nint.Zero
+ ? throw new ArgumentException("Process handle cannot be null.", nameof(process))
+ : SDL_GetProcessInput(process);
}
/// Get the SDL_IOStream associated with process standard output.
@@ -166,11 +163,11 @@ public static nint GetProcessInput(nint process) {
///
/// (SDL_IOStream *) Returns the output stream or on failure; call for more information.
- public static nint GetProcessOutput(nint process) {
- if (process == nint.Zero) {
- throw new ArgumentException("Process handle cannot be null.", nameof(process));
- }
- return SDL_GetProcessOutput(process);
+ public static nint GetProcessOutput(nint process)
+ {
+ return process == nint.Zero
+ ? throw new ArgumentException("Process handle cannot be null.", nameof(process))
+ : SDL_GetProcessOutput(process);
}
/// Stop a process.
@@ -187,11 +184,11 @@ public static nint GetProcessOutput(nint process) {
///
/// Returns on success or on failure; call for more information.
- public static SdlBool KillProcess(nint process, SdlBool force) {
- if (process == nint.Zero) {
- throw new ArgumentException("Process handle cannot be null.", nameof(process));
- }
- return SDL_KillProcess(process, force);
+ public static SdlBool KillProcess(nint process, SdlBool force)
+ {
+ return process == nint.Zero
+ ? throw new ArgumentException("Process handle cannot be null.", nameof(process))
+ : SDL_KillProcess(process, force);
}
/// Wait for a process to finish.
@@ -210,11 +207,11 @@ public static SdlBool KillProcess(nint process, SdlBool force) {
///
/// Returns if the process exited, otherwise.
- public static SdlBool WaitProcess(nint process, SdlBool block, out int exitcode) {
- if (process == nint.Zero) {
- throw new ArgumentException("Process handle cannot be null.", nameof(process));
- }
- return SDL_WaitProcess(process, block, out exitcode);
+ public static SdlBool WaitProcess(nint process, SdlBool block, out int exitcode)
+ {
+ return process == nint.Zero
+ ? throw new ArgumentException("Process handle cannot be null.", nameof(process))
+ : SDL_WaitProcess(process, block, out exitcode);
}
/// Destroy a previously created process object.
diff --git a/SDL3/Render.cs b/SDL3/SDL/Render.cs
similarity index 85%
rename from SDL3/Render.cs
rename to SDL3/SDL/Render.cs
index 1c4106e..8e89a4d 100644
--- a/SDL3/Render.cs
+++ b/SDL3/SDL/Render.cs
@@ -9,26 +9,24 @@ namespace SharpSDL3;
public static unsafe partial class Sdl {
/// Add a set of synchronization semaphores for the current frame.
-
/// the rendering context.
- /// the VkPipelineStageFlags for the wait.
- /// a VkSempahore to wait on before rendering the current frame, or 0 if not needed.
- /// a VkSempahore that SDL will signal when rendering for the current frame is complete, or 0 if not needed.
+ /// the VkPipelineStageFlags for the wait.
+ /// a VkSempahore to wait on before rendering the current frame, or 0 if not needed.
+ /// a VkSempahore that SDL will signal when rendering for the current frame is complete, or 0 if not needed.
///
- /// The Vulkan renderer will wait for wait_semaphore before submitting
- /// rendering commands and signal signal_semaphore after rendering commands
+ /// The Vulkan renderer will wait for before submitting
+ /// rendering commands and signal after rendering commands
/// are complete for this frame.
/// Thread Safety: It is NOT safe to call this function from two threads at once.
/// Version: This function is available since SDL 3.2.0.
///
/// Returns on success or on failure; call for more information.
-
public static bool AddVulkanRenderSemaphores(nint renderer, uint waitStageMask, long waitSemaphore,
long signalSemaphore) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_AddVulkanRenderSemaphores(renderer, waitStageMask, waitSemaphore, signalSemaphore);
+ var result = SDL_AddVulkanRenderSemaphores(renderer, waitStageMask, waitSemaphore, signalSemaphore);
if (!result) {
LogError(LogCategory.Error, "Failed to add Vulkan render semaphores");
}
@@ -36,14 +34,13 @@ public static bool AddVulkanRenderSemaphores(nint renderer, uint waitStageMask,
}
/// Convert the coordinates in an event to render coordinates.
-
/// the rendering context.
/// the event to modify.
///
/// This takes into account several states:
/// Thread Safety: This function should only be called on the main thread.
/// Version: This function is available since SDL 3.2.0.
- ///
+ ///
///
/// Returns on success or on failure; call for more information.
public static bool ConvertEventToRenderCoordinates(nint renderer, ref Event @event) {
@@ -51,7 +48,7 @@ public static bool ConvertEventToRenderCoordinates(nint renderer, ref Event @eve
throw new SdlException("Renderer is null");
}
- Event* eventPtr = (Event*)Marshal.AllocHGlobal(Marshal.SizeOf());
+ var eventPtr = (Event*)Marshal.AllocHGlobal(Marshal.SizeOf());
bool result = SDL_ConvertEventToRenderCoordinates(renderer, ref eventPtr);
if (!result) {
@@ -82,23 +79,20 @@ public static bool ConvertEventToRenderCoordinates(nint renderer, ref Event @eve
///
///
/// (SDL_Renderer *) Returns a valid rendering context or if there was an error; call for more information.
-
public static nint CreateRenderer(nint window, string? name) {
if (window == nint.Zero) {
LogError(LogCategory.Error, "Window is null");
return nint.Zero;
}
- nint result = SDL_CreateRenderer(window, name);
+ var result = SDL_CreateRenderer(window, name);
if (result == nint.Zero) {
LogError(LogCategory.Error, $"Failed to create renderer: {GetError()}");
}
return result;
}
- /// Create a 2D rendering context for a window, with the specified properties.
-
- /// the properties to use.
+ /// Create a 2D rendering context for a window, with the specified properties. /// the properties to use.
///
/// These are the supported properties:
/// Thread Safety: This function should only be called on the main thread.
@@ -110,18 +104,15 @@ public static nint CreateRenderer(nint window, string? name) {
///
///
/// (SDL_Renderer *) Returns a valid rendering context or if there was an error; call for more information.
-
public static nint CreateRendererWithProperties(uint props) {
- nint result = SDL_CreateRendererWithProperties(props);
+ var result = SDL_CreateRendererWithProperties(props);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to create renderer with properties");
}
return result;
}
- /// Create a 2D software rendering context for a surface.
-
- /// the structure representing the surface where rendering is done.
+ /// Create a 2D software rendering context for a surface. /// the structure representing the surface where rendering is done.
///
/// Two other API which can be used to create SDL_Renderer:
/// SDL_CreateRenderer() and
@@ -134,19 +125,32 @@ public static nint CreateRendererWithProperties(uint props) {
///
///
/// (SDL_Renderer *) Returns a valid rendering context or if there was an error; call for more information.
-
public static nint CreateSoftwareRenderer(nint surface) {
if (surface == nint.Zero) {
LogError(LogCategory.Error, "Surface is null");
return nint.Zero;
}
- nint result = SDL_CreateSoftwareRenderer(surface);
+ var result = SDL_CreateSoftwareRenderer(surface);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to create software renderer");
}
return result;
}
+ /// Create a window and default renderer.
+ /// the title of the window, in UTF-8 encoding.
+ /// the width of the window.
+ /// the height of the window.
+ /// the flags used to create the window (see SDL_CreateWindow()).
+ /// a pointer filled with the window, or on error.
+ /// a pointer filled with the renderer, or on error.
+ ///
+ /// Thread Safety: This function should only be called on the main thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
public static bool CreateWindowAndRenderer(string title, int width, int height, WindowFlags windowFlags,
out nint window, out nint renderer) {
if (string.IsNullOrEmpty(title)) {
@@ -155,7 +159,7 @@ public static bool CreateWindowAndRenderer(string title, int width, int height,
renderer = nint.Zero;
return false;
}
- SdlBool result = SDL_CreateWindowAndRenderer(title, width, height, windowFlags, out window, out renderer);
+ var result = SDL_CreateWindowAndRenderer(title, width, height, windowFlags, out window, out renderer);
if (!result) {
LogError(LogCategory.Error, "Failed to create window and renderer");
}
@@ -163,12 +167,10 @@ public static bool CreateWindowAndRenderer(string title, int width, int height,
}
/// Create a window and default renderer.
-
/// the title of the window, in UTF-8 encoding.
/// the width of the window.
/// the height of the window.
- /// the flags used to create the window (see SDL_CreateWindow()).
- /// a pointer filled with the window, or on error.
+ /// the flags used to create the window (see SDL_CreateWindow()).
/// a pointer filled with the renderer, or on error.
///
/// Thread Safety: This function should only be called on the main thread.
@@ -177,7 +179,6 @@ public static bool CreateWindowAndRenderer(string title, int width, int height,
///
///
/// Returns on success or on failure; call for more information.
-
public static nint CreateWindowAndRenderer(string title, int width, int height,
WindowFlags windowFlags, out nint renderer) {
if (string.IsNullOrEmpty(title)) {
@@ -185,7 +186,7 @@ public static nint CreateWindowAndRenderer(string title, int width, int height,
renderer = nint.Zero;
return nint.Zero;
}
- SdlBool result = CreateWindowAndRenderer(title, width, height, windowFlags, out nint window, out renderer);
+ SdlBool result = CreateWindowAndRenderer(title, width, height, windowFlags, out var window, out renderer);
if (!result) {
LogError(LogCategory.Error, "Failed to create window and renderer");
}
@@ -193,7 +194,6 @@ public static nint CreateWindowAndRenderer(string title, int width, int height,
}
/// Destroy the rendering context for a window and free all associated textures.
-
/// the rendering context.
///
/// This should be called before destroying the associated window.
@@ -201,7 +201,6 @@ public static nint CreateWindowAndRenderer(string title, int width, int height,
/// Version: This function is available since SDL 3.2.0.
///
///
-
public static void DestroyRenderer(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -210,7 +209,6 @@ public static void DestroyRenderer(nint renderer) {
}
/// Destroy the specified texture.
-
/// the texture to destroy.
///
/// Passing or an otherwise invalid texture will set the SDL error message
@@ -220,7 +218,6 @@ public static void DestroyRenderer(nint renderer) {
///
///
///
-
public static void DestroyTexture(nint texture) {
if (texture == nint.Zero) {
LogError(LogCategory.Error, "Texture is null");
@@ -230,7 +227,6 @@ public static void DestroyTexture(nint texture) {
}
/// Force the rendering context to flush any pending commands and state.
-
/// the rendering context.
///
/// You do not need to (and in fact, shouldn't) call this function unless you
@@ -240,23 +236,35 @@ public static void DestroyTexture(nint texture) {
/// Version: This function is available since SDL 3.2.0.
///
/// Returns on success or on failure; call for more information.
-
public static bool FlushRenderer(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_FlushRenderer(renderer);
+ var result = SDL_FlushRenderer(renderer);
if (!result) {
LogError(LogCategory.Error, "Failed to flush render");
}
return result;
}
+ /// Get the current output size in pixels of a rendering context.
+ /// the rendering context.
+ /// a pointer filled in with the current width.
+ /// a pointer filled in with the current height.
+ ///
+ /// If a rendering target is active, this will return the size of the rendering
+ /// target in pixels, otherwise return the value of
+ /// .
+ /// Thread Safety: This function should only be called on the main thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
public static bool GetCurrentRenderOutputSize(nint renderer, out int w, out int h) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_GetCurrentRenderOutputSize(renderer, out w, out h);
+ var result = SDL_GetCurrentRenderOutputSize(renderer, out w, out h);
if (!result) {
LogError(LogCategory.Error, "Failed to get current render output size");
}
@@ -264,26 +272,22 @@ public static bool GetCurrentRenderOutputSize(nint renderer, out int w, out int
}
/// Get the current output size in pixels of a rendering context.
-
/// the rendering context.
- /// a pointer filled in with the current width.
- /// a pointer filled in with the current height.
///
/// If a rendering target is active, this will return the size of the rendering
/// target in pixels, otherwise return the value of
- /// SDL_GetRenderOutputSize().
+ /// .
/// Thread Safety: This function should only be called on the main thread.
/// Version: This function is available since SDL 3.2.0.
- ///
+ ///
///
- /// Returns on success or on failure; call for more information.
-
+ /// Returns a filled with the Width and Height.
public static Rect GetCurrentRenderOutputSize(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- _ = GetCurrentRenderOutputSize(renderer, out int w, out int h);
- return new() { W = w, H = h };
+ _ = GetCurrentRenderOutputSize(renderer, out var w, out var h);
+ return new Rect { W = w, H = h };
}
/// Get the number of 2D rendering drivers available for the current display.
@@ -297,9 +301,8 @@ public static Rect GetCurrentRenderOutputSize(nint renderer) {
///
///
/// Returns the number of built in render drivers.
-
public static int GetNumRenderDrivers() {
- int result = SDL_GetNumRenderDrivers();
+ var result = SDL_GetNumRenderDrivers();
if (result < 0) {
LogError(LogCategory.Error, "Failed to get number of render drivers");
}
@@ -310,16 +313,14 @@ public static bool GetRenderClipRect(nint renderer, out Rect rect) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_GetRenderClipRect(renderer, out rect);
+ var result = SDL_GetRenderClipRect(renderer, out rect);
if (!result) {
LogError(LogCategory.Error, "Failed to get render clip rect");
}
return result;
}
- /// Get the clip rectangle for the current target.
-
- /// the rendering context.
+ /// Get the clip rectangle for the current target. /// the rendering context.
/// an structure filled in with the current clipping area or an empty rectangle if clipping is disabled.
///
/// Each render target has its own clip rectangle. This function gets the
@@ -330,12 +331,11 @@ public static bool GetRenderClipRect(nint renderer, out Rect rect) {
///
///
/// Returns on success or on failure; call for more information.
-
public static Rect GetRenderClipRect(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- _ = GetRenderClipRect(renderer, out Rect rect);
+ _ = GetRenderClipRect(renderer, out var rect);
return rect;
}
@@ -343,16 +343,14 @@ public static bool GetRenderColorScale(nint renderer, out float scale) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_GetRenderColorScale(renderer, out scale);
+ var result = SDL_GetRenderColorScale(renderer, out scale);
if (!result) {
LogError(LogCategory.Error, "Failed to get render color scale");
}
return result;
}
- /// Get the color scale used for render operations.
-
- /// the rendering context.
+ /// Get the color scale used for render operations. /// the rendering context.
/// a pointer filled in with the current color scale value.
///
/// Thread Safety: This function should only be called on the main thread.
@@ -360,18 +358,15 @@ public static bool GetRenderColorScale(nint renderer, out float scale) {
///
///
/// Returns on success or on failure; call for more information.
-
public static float GetRenderColorScale(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- _ = GetRenderColorScale(renderer, out float scale);
+ _ = GetRenderColorScale(renderer, out var scale);
return scale;
}
- /// Get the blend mode used for drawing operations.
-
- /// the rendering context.
+ /// Get the blend mode used for drawing operations. /// the rendering context.
/// a pointer filled in with the current .
///
/// Thread Safety: This function should only be called on the main thread.
@@ -379,12 +374,11 @@ public static float GetRenderColorScale(nint renderer) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool GetRenderDrawBlendMode(nint renderer, nint blendMode) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_GetRenderDrawBlendMode(renderer, blendMode);
+ var result = SDL_GetRenderDrawBlendMode(renderer, blendMode);
if (!result) {
LogError(LogCategory.Error, "Failed to get render draw blend mode");
}
@@ -408,7 +402,7 @@ public static bool GetRenderDrawColor(nint renderer, out byte r, out byte g, out
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_GetRenderDrawColor(renderer, out r, out g, out b, out a);
+ var result = SDL_GetRenderDrawColor(renderer, out r, out g, out b, out a);
if (!result) {
LogError(LogCategory.Error, "Failed to get render draw color");
}
@@ -428,24 +422,22 @@ public static Color GetRenderDrawColor(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- _ = GetRenderDrawColor(renderer, out byte r, out byte g, out byte b, out byte a);
- return new() { R = r, G = g, B = b, A = a };
+ _ = GetRenderDrawColor(renderer, out var r, out var g, out var b, out var a);
+ return new Color { R = r, G = g, B = b, A = a };
}
public static bool GetRenderDrawColorFloat(nint renderer, out float r, out float g, out float b, out float a) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_GetRenderDrawColorFloat(renderer, out r, out g, out b, out a);
+ var result = SDL_GetRenderDrawColorFloat(renderer, out r, out g, out b, out a);
if (!result) {
LogError(LogCategory.Error, "Failed to get render draw color float");
}
return result;
}
- /// Get the color used for drawing operations (Rect, Line and Clear).
-
- /// the rendering context.
+ /// Get the color used for drawing operations (Rect, Line and Clear). /// the rendering context.
/// a pointer filled in with the red value used to draw on the rendering target.
/// a pointer filled in with the green value used to draw on the rendering target.
/// a pointer filled in with the blue value used to draw on the rendering target.
@@ -457,18 +449,15 @@ public static bool GetRenderDrawColorFloat(nint renderer, out float r, out float
///
///
/// Returns on success or on failure; call for more information.
-
public static FColor GetRenderDrawColorFloat(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- _ = GetRenderDrawColorFloat(renderer, out float r, out float g, out float b, out float a);
- return new() { R = r, G = g, B = b, A = a };
+ _ = GetRenderDrawColorFloat(renderer, out var r, out var g, out var b, out var a);
+ return new FColor { R = r, G = g, B = b, A = a };
}
- /// Use this function to get the name of a built in 2D rendering driver.
-
- /// the index of the rendering driver; the value ranges from 0 to SDL_GetNumRenderDrivers() - 1.
+ /// Use this function to get the name of a built in 2D rendering driver. /// the index of the rendering driver; the value ranges from 0 to SDL_GetNumRenderDrivers() - 1.
///
/// The list of rendering drivers is given in the order that they are normally
/// initialized by default; the drivers that seem more reasonable to choose
@@ -478,64 +467,55 @@ public static FColor GetRenderDrawColorFloat(nint renderer) {
///
///
/// Returns the name of the rendering driver at the requestedindex, or if an invalid index was specified.
-
public static string GetRenderDriver(int index) {
if (index < 0) {
LogError(LogCategory.Error, "Index is negative");
return string.Empty;
}
- string result = SDL_GetRenderDriver(index);
+ var result = SDL_GetRenderDriver(index);
if (string.IsNullOrEmpty(result)) {
LogError(LogCategory.Error, "Failed to get render driver");
}
return result;
}
- /// Get the renderer associated with a window.
-
- /// the window to query.
+ /// Get the renderer associated with a window. /// the window to query.
///
/// Thread Safety: It is safe to call this function from any thread.
/// Version: This function is available since SDL 3.2.0.
///
/// (SDL_Renderer *) Returns the rendering context on successor on failure; call for more information.
-
public static nint GetRenderer(nint window) {
if (window == nint.Zero) {
LogError(LogCategory.Error, "Window is null");
return nint.Zero;
}
- nint result = SDL_GetRenderer(window);
+ var result = SDL_GetRenderer(window);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to get renderer");
}
return result;
}
- /// Get the renderer that created an SDL_Texture.
-
- /// the texture to query.
+ /// Get the renderer that created an SDL_Texture. /// the texture to query.
///
/// Thread Safety: It is safe to call this function from any thread.
/// Version: This function is available since SDL 3.2.0.
///
/// (SDL_Renderer *) Returns a pointer to theSDL_Renderer that created the texture, or on failure;call for more information.
-
public static nint GetRendererFromTexture(nint texture) {
if (texture == nint.Zero) {
LogError(LogCategory.Error, "Texture is null");
return nint.Zero;
}
- nint result = SDL_GetRendererFromTexture(texture);
+ var result = SDL_GetRendererFromTexture(texture);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to get renderer from texture");
}
return result;
}
- /// Get the name of a renderer.
-
- /// the rendering context.
+ /// Get the name of a renderer. /// the rendering context.
///
/// Thread Safety: It is safe to call this function from any thread.
/// Version: This function is available since SDL 3.2.0.
@@ -543,33 +523,29 @@ public static nint GetRendererFromTexture(nint texture) {
///
///
/// Returns the name of the selected renderer, or on failure; call for more information.
-
public static string GetRendererName(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- string result = SDL_GetRendererName(renderer);
+ var result = SDL_GetRendererName(renderer);
if (string.IsNullOrEmpty(result)) {
LogError(LogCategory.Error, "Failed to get renderer name");
}
return result;
}
- /// Get the properties associated with a renderer.
-
- /// the rendering context.
+ /// Get the properties associated with a renderer. /// the rendering context.
///
/// The following read-only properties are provided by SDL:
/// Thread Safety: It is safe to call this function from any thread.
/// Version: This function is available since SDL 3.2.0.
///
/// Returns a valid property ID on success or 0 on failure; call for more information.
-
public static uint GetRendererProperties(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- uint result = SDL_GetRendererProperties(renderer);
+ var result = SDL_GetRendererProperties(renderer);
if (result == 0) {
LogError(LogCategory.Error, "Failed to get renderer properties");
}
@@ -581,16 +557,14 @@ public static bool GetRenderLogicalPresentation(nint renderer, out int w, out in
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_GetRenderLogicalPresentation(renderer, out w, out h, out mode);
+ var result = SDL_GetRenderLogicalPresentation(renderer, out w, out h, out mode);
if (!result) {
LogError(LogCategory.Error, "Failed to get render logical presentation");
}
return result;
}
- /// Get device independent resolution and presentation mode for rendering.
-
- /// the rendering context.
+ /// Get device independent resolution and presentation mode for rendering. /// the rendering context.
/// an int to be filled with the width.
/// an int to be filled with the height.
/// the presentation mode used.
@@ -602,32 +576,29 @@ public static bool GetRenderLogicalPresentation(nint renderer, out int w, out in
///
///
/// Returns on success or on failure; call for more information.
-
public static Rect GetRenderLogicalPresentation(nint renderer, out RendererLogicalPresentation mode) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = GetRenderLogicalPresentation(renderer, out int w, out int h, out mode);
+ SdlBool result = GetRenderLogicalPresentation(renderer, out var w, out var h, out mode);
if (!result) {
LogError(LogCategory.Error, "Failed to get render logical presentation");
}
- return new() { W = w, H = h };
+ return new Rect { W = w, H = h };
}
public static bool GetRenderLogicalPresentationRect(nint renderer, out FRect rect) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_GetRenderLogicalPresentationRect(renderer, out rect);
+ var result = SDL_GetRenderLogicalPresentationRect(renderer, out rect);
if (!result) {
LogError(LogCategory.Error, "Failed to get render logical presentation rect");
}
return result;
}
- /// Get the final presentation rectangle for rendering.
-
- /// the rendering context.
+ /// Get the final presentation rectangle for rendering. /// the rendering context.
/// a pointer filled in with the final presentation rectangle, may be discarded.
///
/// This function returns the calculated rectangle used for logical
@@ -639,12 +610,11 @@ public static bool GetRenderLogicalPresentationRect(nint renderer, out FRect rec
///
///
/// Returns on success or on failure; call for more information.
-
public static FRect GetRenderLogicalPresentationRect(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_GetRenderLogicalPresentationRect(renderer, out FRect rect);
+ var result = SDL_GetRenderLogicalPresentationRect(renderer, out var rect);
if (!result) {
LogError(LogCategory.Error, "Failed to get render logical presentation rect");
}
@@ -652,7 +622,6 @@ public static FRect GetRenderLogicalPresentationRect(nint renderer) {
}
/// Get the Metal command encoder for the current frame.
-
/// the renderer to query.
///
/// This function returns void *, so SDL doesn't have to include Metal's
@@ -662,12 +631,11 @@ public static FRect GetRenderLogicalPresentationRect(nint renderer) {
///
///
/// (void *) Returns an id<MTLRenderCommandEncoder> on success, or ifthe renderer isn't a Metal renderer or there was an error.
-
public static nint GetRenderMetalCommandEncoder(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- nint result = SDL_GetRenderMetalCommandEncoder(renderer);
+ var result = SDL_GetRenderMetalCommandEncoder(renderer);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to get render metal command encoder");
}
@@ -675,7 +643,6 @@ public static nint GetRenderMetalCommandEncoder(nint renderer) {
}
/// Get the CAMetalLayer associated with the given Metal renderer.
-
/// the renderer to query.
///
/// This function returns void *, so SDL doesn't have to include Metal's
@@ -685,23 +652,34 @@ public static nint GetRenderMetalCommandEncoder(nint renderer) {
///
///
/// (void *) Returns a CAMetalLayer * on success, or if the rendererisn't a Metal renderer.
-
public static nint GetRenderMetalLayer(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- nint result = SDL_GetRenderMetalLayer(renderer);
+ var result = SDL_GetRenderMetalLayer(renderer);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to get render metal layer");
}
return result;
}
+ /// Get the output size in pixels of a rendering context.
+ /// the rendering context.
+ /// a pointer filled in with the width in pixels.
+ /// a pointer filled in with the height in pixels.
+ ///
+ /// This returns the output size in pixels, ignoring any render targets or
+ /// logical size and presentation.
+ /// Thread Safety: This function should only be called on the main thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
public static bool GetRenderOutputSize(nint renderer, out int w, out int h) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_GetRenderOutputSize(renderer, out w, out h);
+ var result = SDL_GetRenderOutputSize(renderer, out w, out h);
if (!result) {
LogError(LogCategory.Error, "Failed to get render output size");
}
@@ -709,32 +687,42 @@ public static bool GetRenderOutputSize(nint renderer, out int w, out int h) {
}
/// Get the output size in pixels of a rendering context.
-
/// the rendering context.
- /// a pointer filled in with the width in pixels.
- /// a pointer filled in with the height in pixels.
///
/// This returns the output size in pixels, ignoring any render targets or
/// logical size and presentation.
/// Thread Safety: This function should only be called on the main thread.
/// Version: This function is available since SDL 3.2.0.
- ///
+ ///
///
/// Returns on success or on failure; call for more information.
-
public static Rect GetRenderOutputSize(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- _ = GetRenderOutputSize(renderer, out int w, out int h);
- return new() { W = w, H = h };
+ _ = GetRenderOutputSize(renderer, out var w, out var h);
+ return new Rect { W = w, H = h };
}
+ /// Get the safe area for rendering within the current viewport.
+ /// the rendering context.
+ /// a pointer filled in with the area that is safe for interactive content.
+ ///
+ /// Some devices have portions of the screen which are partially obscured or
+ /// not interactive, possibly due to on-screen controls, curved edges, camera
+ /// notches, TV overscan, etc. This function provides the area of the current
+ /// viewport which is safe to have interactible content. You should continue
+ /// rendering into the rest of the render target, but it should not contain
+ /// visually important or interactible content.
+ /// Thread Safety: This function should only be called on the main thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
public static bool GetRenderSafeArea(nint renderer, out Rect rect) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_GetRenderSafeArea(renderer, out rect);
+ var result = SDL_GetRenderSafeArea(renderer, out rect);
if (!result) {
LogError(LogCategory.Error, "Failed to get render safe area");
}
@@ -742,9 +730,7 @@ public static bool GetRenderSafeArea(nint renderer, out Rect rect) {
}
/// Get the safe area for rendering within the current viewport.
-
/// the rendering context.
- /// a pointer filled in with the area that is safe for interactive content.
///
/// Some devices have portions of the screen which are partially obscured or
/// not interactive, possibly due to on-screen controls, curved edges, camera
@@ -756,20 +742,31 @@ public static bool GetRenderSafeArea(nint renderer, out Rect rect) {
/// Version: This function is available since SDL 3.2.0.
///
/// Returns on success or on failure; call for more information.
-
public static Rect GetRenderSafeArea(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- _ = GetRenderSafeArea(renderer, out Rect rect);
+ _ = GetRenderSafeArea(renderer, out var rect);
return rect;
}
+ /// Get the drawing scale for the current target.
+ /// the rendering context.
+ /// a pointer filled in with the horizontal scaling factor.
+ /// a pointer filled in with the vertical scaling factor.
+ ///
+ /// Each render target has its own scale. This function gets the scale for the
+ /// current render target.
+ /// Thread Safety: This function should only be called on the main thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
public static bool GetRenderScale(nint renderer, out float scaleX, out float scaleY) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_GetRenderScale(renderer, out scaleX, out scaleY);
+ var result = SDL_GetRenderScale(renderer, out scaleX, out scaleY);
if (!result) {
LogError(LogCategory.Error, "Failed to get render scale");
}
@@ -777,10 +774,7 @@ public static bool GetRenderScale(nint renderer, out float scaleX, out float sca
}
/// Get the drawing scale for the current target.
-
/// the rendering context.
- /// a pointer filled in with the horizontal scaling factor.
- /// a pointer filled in with the vertical scaling factor.
///
/// Each render target has its own scale. This function gets the scale for the
/// current render target.
@@ -789,17 +783,15 @@ public static bool GetRenderScale(nint renderer, out float scaleX, out float sca
///
///
/// Returns on success or on failure; call for more information.
-
public static FPoint GetRenderScale(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- _ = GetRenderScale(renderer, out float scaleX, out float scaleY);
- return new() { X = scaleX, Y = scaleY };
+ _ = GetRenderScale(renderer, out var scaleX, out var scaleY);
+ return new FPoint { X = scaleX, Y = scaleY };
}
/// Get the current render target.
-
/// the rendering context.
///
/// The default render target is the window for which the renderer was created,
@@ -809,12 +801,11 @@ public static FPoint GetRenderScale(nint renderer) {
///
///
/// (SDL_Texture *) Returns the current render target or for the default render target.
-
public static nint GetRenderTarget(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- nint result = SDL_GetRenderTarget(renderer);
+ var result = SDL_GetRenderTarget(renderer);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to get render target");
}
@@ -822,7 +813,6 @@ public static nint GetRenderTarget(nint renderer) {
}
/// Get the drawing area for the current target.
-
/// the rendering context.
/// an structure filled in with the current drawing area.
///
@@ -834,12 +824,11 @@ public static nint GetRenderTarget(nint renderer) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool GetRenderViewport(nint renderer, out Rect rect) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_GetRenderViewport(renderer, out rect);
+ var result = SDL_GetRenderViewport(renderer, out rect);
if (!result) {
LogError(LogCategory.Error, "Failed to get render viewport");
}
@@ -847,40 +836,35 @@ public static bool GetRenderViewport(nint renderer, out Rect rect) {
}
/// Get VSync of the given renderer.
-
/// the renderer to toggle.
- /// an int filled with the current vertical refresh sync interval. See SDL_SetRenderVSync() for the meaning of the value.
///
/// Thread Safety: This function should only be called on the main thread.
/// Version: This function is available since SDL 3.2.0.
///
///
/// Returns on success or on failure; call for more information.
-
public static int GetRenderVsync(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- _ = GetRenderVSync(renderer, out int vsync);
+ _ = GetRenderVSync(renderer, out var vsync);
return vsync;
}
/// Get VSync of the given renderer.
-
/// the renderer to toggle.
- /// an int filled with the current vertical refresh sync interval. See SDL_SetRenderVSync() for the meaning of the value.
+ /// an int filled with the current vertical refresh sync interval. See for the meaning of the value.
///
/// Thread Safety: This function should only be called on the main thread.
/// Version: This function is available since SDL 3.2.0.
///
///
/// Returns on success or on failure; call for more information.
-
public static bool GetRenderVSync(nint renderer, out int vsync) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_GetRenderVSync(renderer, out vsync);
+ var result = SDL_GetRenderVSync(renderer, out vsync);
if (!result) {
LogError(LogCategory.Error, "Failed to get render VSync");
}
@@ -888,19 +872,17 @@ public static bool GetRenderVSync(nint renderer, out int vsync) {
}
/// Get the window associated with a renderer.
-
/// the renderer to query.
///
/// Thread Safety: It is safe to call this function from any thread.
/// Version: This function is available since SDL 3.2.0.
///
/// (SDL_Window *) Returns the window on success or on failure; call for more information.
-
public static nint GetRenderWindow(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- nint result = SDL_GetRenderWindow(renderer);
+ var result = SDL_GetRenderWindow(renderer);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to get render window");
}
@@ -908,7 +890,6 @@ public static nint GetRenderWindow(nint renderer) {
}
/// Clear the current rendering target with the drawing color.
-
/// the rendering context.
///
/// This function clears the entire rendering target, ignoring the viewport and
@@ -917,15 +898,14 @@ public static nint GetRenderWindow(nint renderer) {
/// SDL_SetRenderDrawColor() when needed.
/// Thread Safety: This function should only be called on the main thread.
/// Version: This function is available since SDL 3.2.0.
- ///
+ ///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderClear(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderClear(renderer);
+ var result = SDL_RenderClear(renderer);
if (!result) {
LogError(LogCategory.Error, "Failed to clear render");
}
@@ -933,35 +913,45 @@ public static bool RenderClear(nint renderer) {
}
/// Get whether clipping is enabled on the given render target.
-
/// the rendering context.
///
/// Each render target has its own clip rectangle. This function checks the
/// cliprect for the current render target.
/// Thread Safety: This function should only be called on the main thread.
/// Version: This function is available since SDL 3.2.0.
- ///
+ ///
///
///
/// Returns if clipping is enabled or if not; call for more information.
-
public static bool RenderClipEnabled(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderClipEnabled(renderer);
+ var result = SDL_RenderClipEnabled(renderer);
if (!result) {
LogError(LogCategory.Error, "Failed to get render clip enabled");
}
return result;
}
+ /// Get a point in render coordinates when given a point in window coordinates.
+ /// the rendering context.
+ /// the x coordinate in window coordinates.
+ /// the y coordinate in window coordinates.
+ ///
+ /// This takes into account several states:
+ /// Thread Safety: This function should only be called on the main thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
public static SdlBool RenderCoordinatesFromWindow(nint renderer, float windowX, float windowY,
out float x, out float y) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderCoordinatesFromWindow(renderer, windowX, windowY, out x, out y);
+ var result = SDL_RenderCoordinatesFromWindow(renderer, windowX, windowY, out x, out y);
if (!result) {
LogError(LogCategory.Error, "Failed to convert coordinates from window");
}
@@ -969,12 +959,8 @@ public static SdlBool RenderCoordinatesFromWindow(nint renderer, float windowX,
}
/// Get a point in render coordinates when given a point in window coordinates.
-
/// the rendering context.
- /// the x coordinate in window coordinates.
- /// the y coordinate in window coordinates.
- /// a pointer filled with the x coordinate in render coordinates.
- /// a pointer filled with the y coordinate in render coordinates.
+ /// the window coordinates.
///
/// This takes into account several states:
/// Thread Safety: This function should only be called on the main thread.
@@ -983,16 +969,15 @@ public static SdlBool RenderCoordinatesFromWindow(nint renderer, float windowX,
///
///
/// Returns on success or on failure; call for more information.
-
public static FPoint RenderCoordinatesFromWindow(nint renderer, FPoint windowPoint) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderCoordinatesFromWindow(renderer, windowPoint.X, windowPoint.Y, out float x, out float y);
+ var result = SDL_RenderCoordinatesFromWindow(renderer, windowPoint.X, windowPoint.Y, out var x, out var y);
if (!result) {
LogError(LogCategory.Error, "Failed to convert coordinates from window");
}
- return new() { X = x, Y = y };
+ return new FPoint { X = x, Y = y };
}
public static bool RenderCoordinatesToWindow(nint renderer, float x, float y, out float windowX,
@@ -1000,16 +985,14 @@ public static bool RenderCoordinatesToWindow(nint renderer, float x, float y, ou
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderCoordinatesToWindow(renderer, x, y, out windowX, out windowY);
+ var result = SDL_RenderCoordinatesToWindow(renderer, x, y, out windowX, out windowY);
if (!result) {
LogError(LogCategory.Error, "Failed to convert coordinates to window");
}
return result;
}
- /// Get a point in window coordinates when given a point in render coordinates.
-
- /// the rendering context.
+ /// Get a point in window coordinates when given a point in render coordinates. /// the rendering context.
/// the x coordinate in render coordinates.
/// the y coordinate in render coordinates.
/// a pointer filled with the x coordinate in window coordinates.
@@ -1023,17 +1006,15 @@ public static bool RenderCoordinatesToWindow(nint renderer, float x, float y, ou
///
///
/// Returns on success or on failure; call for more information.
-
public static FPoint RenderCoordinatesToWindow(nint renderer, float x, float y) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- _ = RenderCoordinatesToWindow(renderer, x, y, out float windowX, out float windowY);
- return new() { X = windowX, Y = windowY };
+ _ = RenderCoordinatesToWindow(renderer, x, y, out var windowX, out var windowY);
+ return new FPoint { X = windowX, Y = windowY };
}
/// Get a point in window coordinates when given a point in render coordinates.
-
/// the rendering context.
/// the x coordinate in render coordinates.
/// the y coordinate in render coordinates.
@@ -1048,7 +1029,6 @@ public static FPoint RenderCoordinatesToWindow(nint renderer, float x, float y)
///
///
/// Returns on success or on failure; call for more information.
-
public static FPoint RenderCoordinatesToWindow(nint renderer, FPoint point) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -1056,9 +1036,7 @@ public static FPoint RenderCoordinatesToWindow(nint renderer, FPoint point) {
return RenderCoordinatesToWindow(renderer, point.X, point.Y);
}
- /// Draw debug text to an SDL_Renderer.
-
- /// the renderer which should draw a line of text.
+ /// Draw debug text to an SDL_Renderer. /// the renderer which should draw a line of text.
/// the x coordinate where the top-left corner of the text will draw.
/// the y coordinate where the top-left corner of the text will draw.
/// the string to render.
@@ -1073,21 +1051,18 @@ public static FPoint RenderCoordinatesToWindow(nint renderer, FPoint point) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderDebugText(nint renderer, float x, float y, string str) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderDebugText(renderer, x, y, str);
+ var result = SDL_RenderDebugText(renderer, x, y, str);
if (!result) {
LogError(LogCategory.Error, "Failed to render debug text");
}
return result;
}
- /// Draw debug text to an SDL_Renderer.
-
- /// the renderer which should draw a line of text.
+ /// Draw debug text to an SDL_Renderer. /// the renderer which should draw a line of text.
/// the x coordinate where the top-left corner of the text will draw.
/// the y coordinate where the top-left corner of the text will draw.
/// the string to render.
@@ -1102,7 +1077,6 @@ public static bool RenderDebugText(nint renderer, float x, float y, string str)
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderDebugText(nint renderer, FPoint location, string str) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -1110,9 +1084,7 @@ public static bool RenderDebugText(nint renderer, FPoint location, string str) {
return RenderDebugText(renderer, location.X, location.Y, str);
}
- /// Draw debug text to an SDL_Renderer.
-
- /// the renderer which should draw the text.
+ /// Draw debug text to an SDL_Renderer. /// the renderer which should draw the text.
/// the x coordinate where the top-left corner of the text will draw.
/// the y coordinate where the top-left corner of the text will draw.
/// the format string to draw.
@@ -1127,21 +1099,18 @@ public static bool RenderDebugText(nint renderer, FPoint location, string str) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderDebugTextFormat(nint renderer, float x, float y, string fmt) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderDebugTextFormat(renderer, x, y, fmt);
+ var result = SDL_RenderDebugTextFormat(renderer, x, y, fmt);
if (!result) {
LogError(LogCategory.Error, "Failed to render debug text format");
}
return result;
}
- /// Draw debug text to an SDL_Renderer.
-
- /// the renderer which should draw the text.
+ /// Draw debug text to an SDL_Renderer. /// the renderer which should draw the text.
/// the x coordinate where the top-left corner of the text will draw.
/// the y coordinate where the top-left corner of the text will draw.
/// the format string to draw.
@@ -1156,7 +1125,6 @@ public static bool RenderDebugTextFormat(nint renderer, float x, float y, string
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderDebugTextFormat(nint renderer, FPoint location, string fmt) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -1164,9 +1132,7 @@ public static bool RenderDebugTextFormat(nint renderer, FPoint location, string
return RenderDebugTextFormat(renderer, location.X, location.Y, fmt);
}
- /// Fill a rectangle on the current rendering target with the drawing color at subpixel precision.
-
- /// the renderer which should fill a rectangle.
+ /// Fill a rectangle on the current rendering target with the drawing color at subpixel precision. /// the renderer which should fill a rectangle.
/// a pointer to the destination rectangle, or for the entire rendering target.
///
/// Thread Safety: This function should only be called on the main thread.
@@ -1174,21 +1140,18 @@ public static bool RenderDebugTextFormat(nint renderer, FPoint location, string
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderFillRect(nint renderer, ref FRect rect) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderFillRect(renderer, ref rect);
+ var result = SDL_RenderFillRect(renderer, ref rect);
if (!result) {
LogError(LogCategory.Error, "Failed to render fill rect");
}
return result;
}
- /// Fill some number of rectangles on the current rendering target with the drawing color at subpixel precision.
-
- /// the renderer which should fill multiple rectangles.
+ /// Fill some number of rectangles on the current rendering target with the drawing color at subpixel precision. /// the renderer which should fill multiple rectangles.
/// a pointer to an array of destination rectangles.
/// the number of rectangles.
///
@@ -1197,21 +1160,18 @@ public static bool RenderFillRect(nint renderer, ref FRect rect) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderFillRects(nint renderer, Span rects) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderFillRects(renderer, rects, rects.Length);
+ var result = SDL_RenderFillRects(renderer, rects, rects.Length);
if (!result) {
LogError(LogCategory.Error, "Failed to render fill rects");
}
return result;
}
- /// Fill some number of rectangles on the current rendering target with the drawing color at subpixel precision.
-
- /// the renderer which should fill multiple rectangles.
+ /// Fill some number of rectangles on the current rendering target with the drawing color at subpixel precision. /// the renderer which should fill multiple rectangles.
/// a pointer to an array of destination rectangles.
/// the number of rectangles.
///
@@ -1220,7 +1180,6 @@ public static bool RenderFillRects(nint renderer, Span rects) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderFillRects(nint renderer, FRect[] rects) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -1228,9 +1187,7 @@ public static bool RenderFillRects(nint renderer, FRect[] rects) {
return RenderFillRects(renderer, rects.AsSpan());
}
- /// Render a list of triangles, optionally using a texture and indices into the vertex array Color and alpha modulation is done per vertex (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
-
- /// the rendering context.
+ /// Render a list of triangles, optionally using a texture and indices into the vertex array Color and alpha modulation is done per vertex (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored). /// the rendering context.
/// (optional) The SDL texture to use.
/// vertices.
/// number of vertices.
@@ -1243,12 +1200,11 @@ public static bool RenderFillRects(nint renderer, FRect[] rects) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderGeometry(nint renderer, nint texture, Span vertices, Span indices) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderGeometry(renderer, texture, vertices, vertices.Length, indices,
+ var result = SDL_RenderGeometry(renderer, texture, vertices, vertices.Length, indices,
indices.Length);
if (!result) {
LogError(LogCategory.Error, "Failed to render geometry");
@@ -1256,9 +1212,7 @@ public static bool RenderGeometry(nint renderer, nint texture, Span vert
return result;
}
- /// Render a list of triangles, optionally using a texture and indices into the vertex array Color and alpha modulation is done per vertex (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
-
- /// the rendering context.
+ /// Render a list of triangles, optionally using a texture and indices into the vertex array Color and alpha modulation is done per vertex (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored). /// the rendering context.
/// (optional) The SDL texture to use.
/// vertices.
/// number of vertices.
@@ -1271,7 +1225,6 @@ public static bool RenderGeometry(nint renderer, nint texture, Span vert
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderGeometry(nint renderer, nint texture, Vertex[] vertices, int[] indices) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -1279,9 +1232,7 @@ public static bool RenderGeometry(nint renderer, nint texture, Vertex[] vertices
return RenderGeometry(renderer, texture, vertices.AsSpan(), indices.AsSpan());
}
- /// Render a list of triangles, optionally using a texture and indices into the vertex array Color and alpha modulation is done per vertex (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
-
- /// the rendering context.
+ /// Render a list of triangles, optionally using a texture and indices into the vertex array Color and alpha modulation is done per vertex (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored). /// the rendering context.
/// (optional) The SDL texture to use.
/// vertices.
/// number of vertices.
@@ -1294,7 +1245,6 @@ public static bool RenderGeometry(nint renderer, nint texture, Vertex[] vertices
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderGeometry(nint renderer, nint texture, Span vertices, int[] indices) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -1302,9 +1252,7 @@ public static bool RenderGeometry(nint renderer, nint texture, Span vert
return RenderGeometry(renderer, texture, vertices, indices.AsSpan());
}
- /// Render a list of triangles, optionally using a texture and indices into the vertex array Color and alpha modulation is done per vertex (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
-
- /// the rendering context.
+ /// Render a list of triangles, optionally using a texture and indices into the vertex array Color and alpha modulation is done per vertex (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored). /// the rendering context.
/// (optional) The SDL texture to use.
/// vertices.
/// number of vertices.
@@ -1317,7 +1265,6 @@ public static bool RenderGeometry(nint renderer, nint texture, Span vert
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderGeometry(nint renderer, nint texture, Vertex[] vertices, Span indices) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -1325,9 +1272,7 @@ public static bool RenderGeometry(nint renderer, nint texture, Vertex[] vertices
return RenderGeometry(renderer, texture, vertices.AsSpan(), indices);
}
- /// Render a list of triangles, optionally using a texture and indices into the vertex arrays Color and alpha modulation is done per vertex (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
-
- /// the rendering context.
+ /// Render a list of triangles, optionally using a texture and indices into the vertex arrays Color and alpha modulation is done per vertex (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored). /// the rendering context.
/// (optional) The SDL texture to use.
/// vertex positions.
/// byte size to move from one element to the next element.
@@ -1346,13 +1291,12 @@ public static bool RenderGeometry(nint renderer, nint texture, Vertex[] vertices
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderGeometryRaw(nint renderer, nint texture, nint xy, int xyStride, nint color,
int colorStride, nint uv, int uvStride, int numVertices, nint indices, int numIndices, int sizeIndices) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderGeometryRaw(renderer, texture, xy, xyStride, color, colorStride, uv, uvStride,
+ var result = SDL_RenderGeometryRaw(renderer, texture, xy, xyStride, color, colorStride, uv, uvStride,
numVertices, indices, numIndices, sizeIndices);
if (!result) {
LogError(LogCategory.Error, "Failed to render geometry raw");
@@ -1360,9 +1304,7 @@ public static bool RenderGeometryRaw(nint renderer, nint texture, nint xy, int x
return result;
}
- /// Draw a line on the current rendering target at subpixel precision.
-
- /// the renderer which should draw a line.
+ /// Draw a line on the current rendering target at subpixel precision. /// the renderer which should draw a line.
/// the x coordinate of the start point.
/// the y coordinate of the start point.
/// the x coordinate of the end point.
@@ -1373,21 +1315,18 @@ public static bool RenderGeometryRaw(nint renderer, nint texture, nint xy, int x
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderLine(nint renderer, float x1, float y1, float x2, float y2) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderLine(renderer, x1, y1, x2, y2);
+ var result = SDL_RenderLine(renderer, x1, y1, x2, y2);
if (!result) {
LogError(LogCategory.Error, "Failed to render line");
}
return result;
}
- /// Draw a line on the current rendering target at subpixel precision.
-
- /// the renderer which should draw a line.
+ /// Draw a line on the current rendering target at subpixel precision. /// the renderer which should draw a line.
/// the x coordinate of the start point.
/// the y coordinate of the start point.
/// the x coordinate of the end point.
@@ -1398,7 +1337,6 @@ public static bool RenderLine(nint renderer, float x1, float y1, float x2, float
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderLine(nint renderer, FPoint point1, FPoint point2) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -1406,9 +1344,7 @@ public static bool RenderLine(nint renderer, FPoint point1, FPoint point2) {
return RenderLine(renderer, point1.X, point1.Y, point2.X, point2.Y);
}
- /// Draw a series of connected lines on the current rendering target at subpixel precision.
-
- /// the renderer which should draw multiple lines.
+ /// Draw a series of connected lines on the current rendering target at subpixel precision. /// the renderer which should draw multiple lines.
/// the points along the lines.
/// the number of points, drawing count-1 lines.
///
@@ -1417,21 +1353,18 @@ public static bool RenderLine(nint renderer, FPoint point1, FPoint point2) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderLines(nint renderer, Span points) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderLines(renderer, points, points.Length);
+ var result = SDL_RenderLines(renderer, points, points.Length);
if (!result) {
LogError(LogCategory.Error, "Failed to render lines");
}
return result;
}
- /// Draw a series of connected lines on the current rendering target at subpixel precision.
-
- /// the renderer which should draw multiple lines.
+ /// Draw a series of connected lines on the current rendering target at subpixel precision. /// the renderer which should draw multiple lines.
/// the points along the lines.
/// the number of points, drawing count-1 lines.
///
@@ -1440,7 +1373,6 @@ public static bool RenderLines(nint renderer, Span points) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderLines(nint renderer, FPoint[] points) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -1448,9 +1380,7 @@ public static bool RenderLines(nint renderer, FPoint[] points) {
return RenderLines(renderer, points.AsSpan());
}
- /// Draw a point on the current rendering target at subpixel precision.
-
- /// the renderer which should draw a point.
+ /// Draw a point on the current rendering target at subpixel precision. /// the renderer which should draw a point.
/// the x coordinate of the point.
/// the y coordinate of the point.
///
@@ -1459,21 +1389,18 @@ public static bool RenderLines(nint renderer, FPoint[] points) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderPoint(nint renderer, float x, float y) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderPoint(renderer, x, y);
+ var result = SDL_RenderPoint(renderer, x, y);
if (!result) {
LogError(LogCategory.Error, "Failed to render point");
}
return result;
}
- /// Draw a point on the current rendering target at subpixel precision.
-
- /// the renderer which should draw a point.
+ /// Draw a point on the current rendering target at subpixel precision. /// the renderer which should draw a point.
/// the x coordinate of the point.
/// the y coordinate of the point.
///
@@ -1482,7 +1409,6 @@ public static bool RenderPoint(nint renderer, float x, float y) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderPoint(nint renderer, FPoint point) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -1490,9 +1416,7 @@ public static bool RenderPoint(nint renderer, FPoint point) {
return RenderPoint(renderer, point.X, point.Y);
}
- /// Draw multiple points on the current rendering target at subpixel precision.
-
- /// the renderer which should draw multiple points.
+ /// Draw multiple points on the current rendering target at subpixel precision. /// the renderer which should draw multiple points.
/// the points to draw.
/// the number of points to draw.
///
@@ -1501,21 +1425,18 @@ public static bool RenderPoint(nint renderer, FPoint point) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderPoints(nint renderer, Span points) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderPoints(renderer, points, points.Length);
+ var result = SDL_RenderPoints(renderer, points, points.Length);
if (!result) {
LogError(LogCategory.Error, "Failed to render points");
}
return result;
}
- /// Draw multiple points on the current rendering target at subpixel precision.
-
- /// the renderer which should draw multiple points.
+ /// Draw multiple points on the current rendering target at subpixel precision. /// the renderer which should draw multiple points.
/// the points to draw.
/// the number of points to draw.
///
@@ -1524,7 +1445,6 @@ public static bool RenderPoints(nint renderer, Span points) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderPoints(nint renderer, FPoint[] points) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -1532,9 +1452,7 @@ public static bool RenderPoints(nint renderer, FPoint[] points) {
return RenderPoints(renderer, points.AsSpan());
}
- /// Update the screen with any rendering performed since the previous call.
-
- /// the rendering context.
+ /// Update the screen with any rendering performed since the previous call. /// the rendering context.
///
/// SDL's rendering functions operate on a backbuffer; that is, calling a
/// rendering function such as SDL_RenderLine() does not
@@ -1557,21 +1475,18 @@ public static bool RenderPoints(nint renderer, FPoint[] points) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderPresent(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderPresent(renderer);
+ var result = SDL_RenderPresent(renderer);
if (!result) {
LogError(LogCategory.Error, "Failed to present render");
}
return result;
}
- /// Read pixels from the current rendering target.
-
- /// the rendering context.
+ /// Read pixels from the current rendering target. /// the rendering context.
/// an structure representing the area to read, which will be clipped to the current viewport, or for the entire viewport.
///
/// The returned surface contains pixels inside the desired area clipped to the
@@ -1581,21 +1496,18 @@ public static bool RenderPresent(nint renderer) {
/// Version: This function is available since SDL 3.2.0.
///
/// (SDL_Surface *) Returns a new SDL_Surface on success or on failure; call for more information.
-
public static nint RenderReadPixels(nint renderer, ref Rect rect) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- nint result = SDL_RenderReadPixels(renderer, ref rect);
+ var result = SDL_RenderReadPixels(renderer, ref rect);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to read pixels from render");
}
return result;
}
- /// Draw a rectangle on the current rendering target at subpixel precision.
-
- /// the renderer which should draw a rectangle.
+ /// Draw a rectangle on the current rendering target at subpixel precision. /// the renderer which should draw a rectangle.
/// a pointer to the destination rectangle, or to outline the entire rendering target.
///
/// Thread Safety: This function should only be called on the main thread.
@@ -1603,21 +1515,18 @@ public static nint RenderReadPixels(nint renderer, ref Rect rect) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderRect(nint renderer, ref FRect rect) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderRect(renderer, ref rect);
+ var result = SDL_RenderRect(renderer, ref rect);
if (!result) {
LogError(LogCategory.Error, "Failed to render rect");
}
return result;
}
- /// Draw some number of rectangles on the current rendering target at subpixel precision.
-
- /// the renderer which should draw multiple rectangles.
+ /// Draw some number of rectangles on the current rendering target at subpixel precision. /// the renderer which should draw multiple rectangles.
/// a pointer to an array of destination rectangles.
/// the number of rectangles.
///
@@ -1626,21 +1535,18 @@ public static bool RenderRect(nint renderer, ref FRect rect) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderRects(nint renderer, Span rects) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderRects(renderer, rects, rects.Length);
+ var result = SDL_RenderRects(renderer, rects, rects.Length);
if (!result) {
LogError(LogCategory.Error, "Failed to render rects");
}
return result;
}
- /// Draw some number of rectangles on the current rendering target at subpixel precision.
-
- /// the renderer which should draw multiple rectangles.
+ /// Draw some number of rectangles on the current rendering target at subpixel precision. /// the renderer which should draw multiple rectangles.
/// a pointer to an array of destination rectangles.
/// the number of rectangles.
///
@@ -1649,7 +1555,6 @@ public static bool RenderRects(nint renderer, Span rects) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderRects(nint renderer, FRect[] rects) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -1657,9 +1562,7 @@ public static bool RenderRects(nint renderer, FRect[] rects) {
return RenderRects(renderer, rects.AsSpan());
}
- /// Copy a portion of the texture to the current rendering target at subpixel precision.
-
- /// the renderer which should copy parts of a texture.
+ /// Copy a portion of the texture to the current rendering target at subpixel precision. /// the renderer which should copy parts of a texture.
/// the source texture.
/// a pointer to the source rectangle, or for the entire texture.
/// a pointer to the destination rectangle, or for the entire rendering target.
@@ -1670,21 +1573,18 @@ public static bool RenderRects(nint renderer, FRect[] rects) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderTexture(nint renderer, nint texture, ref FRect srcrect, ref FRect dstrect) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderTexture(renderer, texture, ref srcrect, ref dstrect);
+ var result = SDL_RenderTexture(renderer, texture, ref srcrect, ref dstrect);
if (!result) {
LogError(LogCategory.Error, "Failed to render texture");
}
return result;
}
- /// Copy a portion of the texture to the current rendering target at subpixel precision.
-
- /// the renderer which should copy parts of a texture.
+ /// Copy a portion of the texture to the current rendering target at subpixel precision. /// the renderer which should copy parts of a texture.
/// the source texture.
/// a pointer to the source rectangle, or for the entire texture.
/// a pointer to the destination rectangle, or for the entire rendering target.
@@ -1695,10 +1595,9 @@ public static bool RenderTexture(nint renderer, nint texture, ref FRect srcrect,
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderTexture(nint renderer, nint texture, nint srcrect, nint dstrect) {
- FRect srect = new();
- FRect drect = new();
+ FRect srect = new FRect();
+ FRect drect = new FRect();
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
@@ -1713,9 +1612,7 @@ public static bool RenderTexture(nint renderer, nint texture, nint srcrect, nint
return RenderTexture(renderer, texture, ref srect, ref drect);
}
- /// Copy a portion of the texture to the current rendering target at subpixel precision.
-
- /// the renderer which should copy parts of a texture.
+ /// Copy a portion of the texture to the current rendering target at subpixel precision. /// the renderer which should copy parts of a texture.
/// the source texture.
/// a pointer to the source rectangle, or for the entire texture.
/// a pointer to the destination rectangle, or for the entire rendering target.
@@ -1726,9 +1623,8 @@ public static bool RenderTexture(nint renderer, nint texture, nint srcrect, nint
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderTexture(nint renderer, nint texture, ref FRect srcrect, nint dstrect) {
- FRect drect = new();
+ FRect drect = new FRect();
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
@@ -1739,9 +1635,7 @@ public static bool RenderTexture(nint renderer, nint texture, ref FRect srcrect,
return RenderTexture(renderer, texture, ref srcrect, ref drect);
}
- /// Copy a portion of the texture to the current rendering target at subpixel precision.
-
- /// the renderer which should copy parts of a texture.
+ /// Copy a portion of the texture to the current rendering target at subpixel precision. /// the renderer which should copy parts of a texture.
/// the source texture.
/// a pointer to the source rectangle, or for the entire texture.
/// a pointer to the destination rectangle, or for the entire rendering target.
@@ -1752,9 +1646,8 @@ public static bool RenderTexture(nint renderer, nint texture, ref FRect srcrect,
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderTexture(nint renderer, nint texture, nint srcrect, ref FRect dstrect) {
- FRect srect = new();
+ FRect srect = new FRect();
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
@@ -1765,9 +1658,7 @@ public static bool RenderTexture(nint renderer, nint texture, nint srcrect, ref
return RenderTexture(renderer, texture, ref srect, ref dstrect);
}
- /// Perform a scaled copy using the 9-grid algorithm to the current rendering target at subpixel precision.
-
- /// the renderer which should copy parts of a texture.
+ /// Perform a scaled copy using the 9-grid algorithm to the current rendering target at subpixel precision. /// the renderer which should copy parts of a texture.
/// the source texture.
/// the structure representing the rectangle to be used for the 9-grid, or to use the entire texture.
/// the width, in pixels, of the left corners in srcrect.
@@ -1787,13 +1678,12 @@ public static bool RenderTexture(nint renderer, nint texture, nint srcrect, ref
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderTexture9Grid(nint renderer, nint texture, ref FRect srcrect, float leftWidth,
float rightWidth, float topHeight, float bottomHeight, float scale, ref FRect dstrect) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderTexture9Grid(renderer, texture, ref srcrect, leftWidth, rightWidth,
+ var result = SDL_RenderTexture9Grid(renderer, texture, ref srcrect, leftWidth, rightWidth,
topHeight, bottomHeight, scale, ref dstrect);
if (!result) {
LogError(LogCategory.Error, "Failed to render texture 9 grid");
@@ -1801,9 +1691,7 @@ public static bool RenderTexture9Grid(nint renderer, nint texture, ref FRect src
return result;
}
- /// Copy a portion of the source texture to the current rendering target, with affine transform, at subpixel precision.
-
- /// the renderer which should copy parts of a texture.
+ /// Copy a portion of the source texture to the current rendering target, with affine transform, at subpixel precision. /// the renderer which should copy parts of a texture.
/// the source texture.
/// a pointer to the source rectangle, or for the entire texture.
/// a pointer to a point indicating where the top-left corner of srcrect should be mapped to, or for the rendering target's origin.
@@ -1815,13 +1703,12 @@ public static bool RenderTexture9Grid(nint renderer, nint texture, ref FRect src
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderTextureAffine(nint renderer, nint texture, in FRect srcrect, in FPoint origin,
in FPoint right, in FPoint down) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderTextureAffine(renderer, texture, in srcrect, in origin, in right, in down);
+ var result = SDL_RenderTextureAffine(renderer, texture, in srcrect, in origin, in right, in down);
if (!result) {
LogError(LogCategory.Error, "Failed to render texture affine");
}
@@ -1847,7 +1734,7 @@ public static bool RenderTextureRotated(nint renderer, nint texture, ref FRect s
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderTextureRotated(renderer, texture, ref srcrect, ref dstrect, angle, ref center,
+ var result = SDL_RenderTextureRotated(renderer, texture, ref srcrect, ref dstrect, angle, ref center,
flip);
if (!result) {
LogError(LogCategory.Error, "Failed to render texture rotated");
@@ -1870,7 +1757,7 @@ public static bool RenderTextureRotated(nint renderer, nint texture, ref FRect s
///
/// Returns on success or on failure; call for more information.
public static bool RenderTextureRotated(nint renderer, nint texture, nint srcrect, ref FRect dstrect, double angle, ref FPoint center, FlipMode flip) {
- FRect srect = new();
+ FRect srect = new FRect();
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
@@ -1895,7 +1782,7 @@ public static bool RenderTextureRotated(nint renderer, nint texture, nint srcrec
///
/// Returns on success or on failure; call for more information.
public static bool RenderTextureRotated(nint renderer, nint texture, ref FRect srcrect, nint dstrect, double angle, ref FPoint center, FlipMode flip) {
- FRect drect = new();
+ FRect drect = new FRect();
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
@@ -1920,8 +1807,8 @@ public static bool RenderTextureRotated(nint renderer, nint texture, ref FRect s
///
/// Returns on success or on failure; call for more information.
public static bool RenderTextureRotated(nint renderer, nint texture, nint srcrect, ref FRect dstrect, double angle, nint center, FlipMode flip) {
- FRect srect = new();
- FPoint centerPoint = new();
+ FRect srect = new FRect();
+ FPoint centerPoint = new FPoint();
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
@@ -1950,8 +1837,8 @@ public static bool RenderTextureRotated(nint renderer, nint texture, nint srcrec
///
/// Returns on success or on failure; call for more information.
public static bool RenderTextureRotated(nint renderer, nint texture, ref FRect srcrect, nint dstrect, double angle, nint center, FlipMode flip) {
- FRect drect = new();
- FPoint centerPoint = new();
+ FRect drect = new FRect();
+ FPoint centerPoint = new FPoint();
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
@@ -1981,22 +1868,19 @@ public static bool RenderTextureRotated(nint renderer, nint texture, ref FRect s
///
///
/// Returns on success or on failure; call for more information.
-
public static bool RenderTextureTiled(nint renderer, nint texture, ref FRect srcrect, float scale,
ref FRect dstrect) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderTextureTiled(renderer, texture, ref srcrect, scale, ref dstrect);
+ var result = SDL_RenderTextureTiled(renderer, texture, ref srcrect, scale, ref dstrect);
if (!result) {
LogError(LogCategory.Error, "Failed to render texture tiled");
}
return result;
}
- /// Return whether an explicit rectangle was set as the viewport.
-
- /// the rendering context.
+ /// Return whether an explicit rectangle was set as the viewport. /// the rendering context.
///
/// This is useful if you're saving and restoring the viewport and want to know
/// whether you should restore a specific rectangle or .
@@ -2006,21 +1890,18 @@ public static bool RenderTextureTiled(nint renderer, nint texture, ref FRect src
///
///
/// Returns if the viewport was set to a specific rectangle, or if it was set to (the entire target).
-
public static bool RenderViewportSet(nint renderer) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_RenderViewportSet(renderer);
+ var result = SDL_RenderViewportSet(renderer);
if (!result) {
LogError(LogCategory.Error, "Failed to set render viewport");
}
return result;
}
- /// Set the clip rectangle for rendering on the specified target.
-
- /// the rendering context.
+ /// Set the clip rectangle for rendering on the specified target. /// the rendering context.
/// an structure representing the clip area, relative to the viewport, or to disable clipping.
///
/// Each render target has its own clip rectangle. This function sets the
@@ -2031,21 +1912,18 @@ public static bool RenderViewportSet(nint renderer) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool SetRenderClipRect(nint renderer, ref Rect rect) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_SetRenderClipRect(renderer, ref rect);
+ var result = SDL_SetRenderClipRect(renderer, ref rect);
if (!result) {
LogError(LogCategory.Error, "Failed to set render clip rect");
}
return result;
}
- /// Set the color scale used for render operations.
-
- /// the rendering context.
+ /// Set the color scale used for render operations. /// the rendering context.
/// the color scale value.
///
/// The color scale is an additional scale multiplied into the pixel color
@@ -2057,21 +1935,18 @@ public static bool SetRenderClipRect(nint renderer, ref Rect rect) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool SetRenderColorScale(nint renderer, float scale) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_SetRenderColorScale(renderer, scale);
+ var result = SDL_SetRenderColorScale(renderer, scale);
if (!result) {
LogError(LogCategory.Error, "Failed to set render color scale");
}
return result;
}
- /// Set the blend mode used for drawing operations (Fill and Line).
-
- /// the rendering context.
+ /// Set the blend mode used for drawing operations (Fill and Line). /// the rendering context.
/// the to use for blending.
///
/// If the blend mode is not supported, the closest supported mode is chosen.
@@ -2080,21 +1955,18 @@ public static bool SetRenderColorScale(nint renderer, float scale) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool SetRenderDrawBlendMode(nint renderer, uint blendMode) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_SetRenderDrawBlendMode(renderer, blendMode);
+ var result = SDL_SetRenderDrawBlendMode(renderer, blendMode);
if (!result) {
LogError(LogCategory.Error, "Failed to set render draw blend mode");
}
return result;
}
- /// Set the blend mode used for drawing operations (Fill and Line).
-
- /// the rendering context.
+ /// Set the blend mode used for drawing operations (Fill and Line). /// the rendering context.
/// the to use for blending.
///
/// If the blend mode is not supported, the closest supported mode is chosen.
@@ -2103,21 +1975,18 @@ public static bool SetRenderDrawBlendMode(nint renderer, uint blendMode) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool SetRenderDrawBlendMode(nint renderer, BlendMode mode) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_SetRenderDrawBlendMode(renderer, (uint)mode);
+ var result = SDL_SetRenderDrawBlendMode(renderer, (uint)mode);
if (!result) {
LogError(LogCategory.Error, "Failed to set render draw blend mode");
}
return result;
}
- /// Set the color used for drawing operations.
-
- /// the rendering context.
+ /// Set the color used for drawing operations. /// the rendering context.
/// the red value used to draw on the rendering target.
/// the green value used to draw on the rendering target.
/// the blue value used to draw on the rendering target.
@@ -2131,21 +2000,18 @@ public static bool SetRenderDrawBlendMode(nint renderer, BlendMode mode) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool SetRenderDrawColor(nint renderer, byte r, byte g, byte b, byte a) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_SetRenderDrawColor(renderer, r, g, b, a);
+ var result = SDL_SetRenderDrawColor(renderer, r, g, b, a);
if (!result) {
LogError(LogCategory.Error, "Failed to set render draw color");
}
return result;
}
- /// Set the color used for drawing operations.
-
- /// the rendering context.
+ /// Set the color used for drawing operations. /// the rendering context.
/// the red value used to draw on the rendering target.
/// the green value used to draw on the rendering target.
/// the blue value used to draw on the rendering target.
@@ -2159,7 +2025,6 @@ public static bool SetRenderDrawColor(nint renderer, byte r, byte g, byte b, byt
///
///
/// Returns on success or on failure; call for more information.
-
public static bool SetRenderDrawColor(nint renderer, Color color) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -2167,9 +2032,7 @@ public static bool SetRenderDrawColor(nint renderer, Color color) {
return SetRenderDrawColor(renderer, color.R, color.G, color.B, color.A);
}
- /// Set the color used for drawing operations (Rect, Line and Clear).
-
- /// the rendering context.
+ /// Set the color used for drawing operations (Rect, Line and Clear). /// the rendering context.
/// the red value used to draw on the rendering target.
/// the green value used to draw on the rendering target.
/// the blue value used to draw on the rendering target.
@@ -2183,21 +2046,18 @@ public static bool SetRenderDrawColor(nint renderer, Color color) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool SetRenderDrawColorFloat(nint renderer, float r, float g, float b, float a) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_SetRenderDrawColorFloat(renderer, r, g, b, a);
+ var result = SDL_SetRenderDrawColorFloat(renderer, r, g, b, a);
if (!result) {
LogError(LogCategory.Error, "Failed to set render draw color float");
}
return result;
}
- /// Set the color used for drawing operations (Rect, Line and Clear).
-
- /// the rendering context.
+ /// Set the color used for drawing operations (Rect, Line and Clear). /// the rendering context.
/// the red value used to draw on the rendering target.
/// the green value used to draw on the rendering target.
/// the blue value used to draw on the rendering target.
@@ -2211,7 +2071,6 @@ public static bool SetRenderDrawColorFloat(nint renderer, float r, float g, floa
///
///
/// Returns on success or on failure; call for more information.
-
public static bool SetRenderDrawColorFloat(nint renderer, FColor color) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -2219,9 +2078,7 @@ public static bool SetRenderDrawColorFloat(nint renderer, FColor color) {
return SetRenderDrawColorFloat(renderer, color.R, color.G, color.B, color.A);
}
- /// Set a device-independent resolution and presentation mode for rendering.
-
- /// the rendering context.
+ /// Set a device-independent resolution and presentation mode for rendering. /// the rendering context.
/// the width of the logical resolution.
/// the height of the logical resolution.
/// the presentation mode used.
@@ -2236,22 +2093,19 @@ public static bool SetRenderDrawColorFloat(nint renderer, FColor color) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool SetRenderLogicalPresentation(nint renderer, int w, int h,
RendererLogicalPresentation mode) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_SetRenderLogicalPresentation(renderer, w, h, mode);
+ var result = SDL_SetRenderLogicalPresentation(renderer, w, h, mode);
if (!result) {
LogError(LogCategory.Error, "Failed to set render logical presentation");
}
return result;
}
- /// Set the drawing scale for rendering on the current target.
-
- /// the rendering context.
+ /// Set the drawing scale for rendering on the current target. /// the rendering context.
/// the horizontal scaling factor.
/// the vertical scaling factor.
///
@@ -2263,21 +2117,18 @@ public static bool SetRenderLogicalPresentation(nint renderer, int w, int h,
///
///
/// Returns on success or on failure; call for more information.
-
public static bool SetRenderScale(nint renderer, float scaleX, float scaleY) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_SetRenderScale(renderer, scaleX, scaleY);
+ var result = SDL_SetRenderScale(renderer, scaleX, scaleY);
if (!result) {
LogError(LogCategory.Error, "Failed to set render scale");
}
return result;
}
- /// Set a texture as the current rendering target.
-
- /// the rendering context.
+ /// Set a texture as the current rendering target. /// the rendering context.
/// the targeted texture, which must be created with the SDL_TEXTUREACCESS_TARGET flag, or to render to the window instead of a texture.
///
/// The default render target is the window for which the renderer was created.
@@ -2288,7 +2139,6 @@ public static bool SetRenderScale(nint renderer, float scaleX, float scaleY) {
///
///
/// Returns on success or on failure; call for more information.
-
public static SdlBool SetRenderTarget(nint renderer, nint texture) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
@@ -2299,7 +2149,7 @@ public static SdlBool SetRenderTarget(nint renderer, nint texture) {
return false;
}
- SdlBool result = SDL_SetRenderTarget(renderer, texture);
+ var result = SDL_SetRenderTarget(renderer, texture);
if (!result) {
LogError(LogCategory.Error, "Failed to set render target");
}
@@ -2307,9 +2157,7 @@ public static SdlBool SetRenderTarget(nint renderer, nint texture) {
return result;
}
- /// Set the drawing area for rendering on the current target.
-
- /// the rendering context.
+ /// Set the drawing area for rendering on the current target. /// the rendering context.
/// the structure representing the drawing area, or to set the viewport to the entire target.
///
/// Drawing will clip to this area (separately from any clipping done with
@@ -2321,21 +2169,18 @@ public static SdlBool SetRenderTarget(nint renderer, nint texture) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool SetRenderViewport(nint renderer, ref Rect rect) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_SetRenderViewport(renderer, ref rect);
+ var result = SDL_SetRenderViewport(renderer, ref rect);
if (!result) {
LogError(LogCategory.Error, "Failed to set render viewport");
}
return result;
}
- /// Toggle VSync of the given renderer.
-
- /// the renderer to toggle.
+ /// Toggle VSync of the given renderer. /// the renderer to toggle.
/// the vertical refresh sync interval.
///
/// When a renderer is created, vsync defaults to
@@ -2345,12 +2190,11 @@ public static bool SetRenderViewport(nint renderer, ref Rect rect) {
///
///
/// Returns on success or on failure; call for more information.
-
public static bool SetRenderVSync(nint renderer, int vsync) {
if (renderer == nint.Zero) {
throw new SdlException("Renderer is null");
}
- SdlBool result = SDL_SetRenderVSync(renderer, vsync);
+ var result = SDL_SetRenderVSync(renderer, vsync);
if (!result) {
LogError(LogCategory.Error, "Failed to set render VSync");
}
diff --git a/SDL3/Sdl.cs b/SDL3/SDL/Sdl.cs
similarity index 75%
rename from SDL3/Sdl.cs
rename to SDL3/SDL/Sdl.cs
index a8e44b7..0ee7ec7 100644
--- a/SDL3/Sdl.cs
+++ b/SDL3/SDL/Sdl.cs
@@ -33,8 +33,8 @@ public static unsafe partial class Sdl {
///
/// A pointer in memory to an object, else .
public static unsafe nint StructureToPointer(ref T str) where T : struct {
- int size = Marshal.SizeOf();
- nint ptr = Marshal.AllocHGlobal(size);
+ var size = Marshal.SizeOf();
+ var ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(str, ptr, false);
return ptr;
}
@@ -115,161 +115,6 @@ public static bool AddSurfaceAlternateImage(nint surface, nint image) {
return SDL_AddSurfaceAlternateImage(surface, image);
}
- /// Performs a fast blit from the source surface to the destination surface with clipping.
- /// the structure to be copied from.
- /// the structure representing the rectangle to be copied, or to copy the entire surface.
- /// the structure that is the blit target.
- /// the structure representing the x and y position in the destination surface, or for (0,0). The width and height are ignored, and are copied from srcrect. If you want a specific width and height, you should use .
- ///
- /// If either srcrect or dstrect are , the entire surface (src or dst) is copied while ensuring clipping to dst->clip_rect.
- /// Thread Safety: Only one thread should be using the src and dst surfaces at any given time.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool BlitSurface(nint src, nint srcrect, nint dst, nint dstrect) {
- if (src == nint.Zero || dst == nint.Zero) {
- LogWarn(LogCategory.System, "BlitSurface: Source or destination pointer is null.");
- return false;
- }
- return SDL_BlitSurface(src, srcrect, dst, dstrect);
- }
-
- /// Perform a scaled blit using the 9-grid algorithm to a destination surface, which may be of a different format.
- /// the structure to be copied from.
- /// the structure representing the rectangle to be used for the 9-grid, or to use the entire surface.
- /// the width, in pixels, of the left corners in srcrect.
- /// the width, in pixels, of the right corners in srcrect.
- /// the height, in pixels, of the top corners in srcrect.
- /// the height, in pixels, of the bottom corners in srcrect.
- /// the scale used to transform the corner of srcrect into the corner of dstrect, or 0.0f for an unscaled blit.
- /// scale algorithm to be used.
- /// the structure that is the blit target.
- /// the structure representing the target rectangle in the destination surface, or to fill the entire surface.
- ///
- /// The pixels in the source surface are split into a 3x3 grid, using the
- /// different corner sizes for each corner, and the sides and center making up
- /// the remaining pixels. The corners are then scaled using scale and fit
- /// into the corners of the destination rectangle. The sides and center are
- /// then stretched into place to cover the remaining destination rectangle.
- /// Thread Safety: Only one thread should be using the src and dst surfaces at any given time.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool BlitSurface9Grid(nint src, nint srcrect, int leftWidth, int rightWidth, int topHeight, int bottomHeight, float scale, ScaleMode scaleMode, nint dst, nint dstrect) {
- if (src == nint.Zero || dst == nint.Zero) {
- LogWarn(LogCategory.System, "BlitSurface9Grid: Source or destination pointer is null.");
- return false;
- }
- return SDL_BlitSurface9Grid(src, srcrect, leftWidth, rightWidth, topHeight, bottomHeight, scale, scaleMode, dst, dstrect);
- }
-
- /// Perform a scaled blit to a destination surface, which may be of a different format.
- /// the structure to be copied from.
- /// the structure representing the rectangle to be copied, or to copy the entire surface.
- /// the structure that is the blit target.
- /// the structure representing the target rectangle in the destination surface, or to fill the entire destination surface.
- /// the to be used.
- ///
- /// Thread Safety: Only one thread should be using the src and dst surfaces at any given time.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool BlitSurfaceScaled(nint src, nint srcrect, nint dst, nint dstrect, ScaleMode scaleMode) {
- if (src == nint.Zero || dst == nint.Zero) {
- LogWarn(LogCategory.System, "BlitSurfaceScaled: Source or destination pointer is null.");
- return false;
- }
- return SDL_BlitSurfaceScaled(src, srcrect, dst, dstrect, scaleMode);
- }
-
- /// Perform a tiled blit to a destination surface, which may be of a different format.
- /// the structure to be copied from.
- /// the structure representing the rectangle to be copied, or to copy the entire surface.
- /// the structure that is the blit target.
- /// the structure representing the target rectangle in the destination surface, or to fill the entire surface.
- ///
- /// The pixels in srcrect will be repeated as many times as needed to completely fill dstrect.
- /// Thread Safety: Only one thread should be using the src and dst surfaces at any given time.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool BlitSurfaceTiled(nint src, nint srcrect, nint dst, nint dstrect) {
- if (src == nint.Zero || dst == nint.Zero) {
- LogWarn(LogCategory.System, "BlitSurfaceTiled: Source or destination pointer is null.");
- return false;
- }
- return SDL_BlitSurfaceTiled(src, srcrect, dst, dstrect);
- }
-
- /// Perform a scaled and tiled blit to a destination surface, which may be of a different format.
- /// the structure to be copied from.
- /// the structure representing the rectangle to be copied, or to copy the entire surface.
- /// the scale used to transform srcrect into the destination rectangle, e.g. a 32x32 texture with a scale of 2 would fill 64x64 tiles.
- /// scale algorithm to be used.
- /// the structure that is the blit target.
- /// the structure representing the target rectangle in the destination surface, or to fill the entire surface.
- ///
- /// The pixels in srcrect will be scaled and repeated as many times as needed
- /// to completely fill dstrect.
- /// Thread Safety: Only one thread should be using the src and dst surfaces at any given time.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool BlitSurfaceTiledWithScale(nint src, nint srcrect, float scale, ScaleMode scaleMode, nint dst, nint dstrect) {
- if (src == nint.Zero || dst == nint.Zero) {
- LogWarn(LogCategory.System, "BlitSurfaceTiledWithScale: Source or destination pointer is null.");
- return false;
- }
- return SDL_BlitSurfaceTiledWithScale(src, srcrect, scale, scaleMode, dst, dstrect);
- }
-
- /// Perform low-level surface blitting only.
- /// the structure to be copied from.
- /// the structure representing the rectangle to be copied, may not be .
- /// the structure that is the blit target.
- /// the structure representing the target rectangle in the destination surface, may not be .
- ///
- /// This is a semi-private blit function and it performs low-level surface
- /// blitting, assuming the input rectangles have already been clipped.
- /// Thread Safety: Only one thread should be using the src and dst surfaces at any given time.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool BlitSurfaceUnchecked(nint src, nint srcrect, nint dst, nint dstrect) {
- if (src == nint.Zero || dst == nint.Zero) {
- LogWarn(LogCategory.System, "BlitSurfaceUnchecked: Source or destination pointer is null.");
- return false;
- }
- return SDL_BlitSurfaceUnchecked(src, srcrect, dst, dstrect);
- }
-
- /// Perform low-level surface scaled blitting only.
- /// the structure to be copied from.
- /// the structure representing the rectangle to be copied, may not be .
- /// the structure that is the blit target.
- /// the structure representing the target rectangle in the destination surface, may not be .
- /// the to be used.
- ///
- /// This is a semi-private function and it performs low-level surface blitting,
- /// assuming the input rectangles have already been clipped.
- /// Thread Safety: Only one thread should be using the src and dst surfaces at any given time.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool BlitSurfaceUncheckedScaled(nint src, nint srcrect, nint dst, nint dstrect, ScaleMode scaleMode) {
- if (src == nint.Zero || dst == nint.Zero) {
- LogWarn(LogCategory.System, "BlitSurfaceUncheckedScaled: Source or destination pointer is null.");
- return false;
- }
- return SDL_BlitSurfaceUncheckedScaled(src, srcrect, dst, dstrect, scaleMode);
- }
/// Cleanup all TLS data for this thread.
///
@@ -339,159 +184,6 @@ public static bool ClearProperty(uint props, string name) {
return SDL_ClearProperty(props, name);
}
- /// Clear a surface with a specific color, with floating point precision.
- /// the to clear.
- /// the red component of the pixel, normally in the range 0-1.
- /// the green component of the pixel, normally in the range 0-1.
- /// the blue component of the pixel, normally in the range 0-1.
- /// the alpha component of the pixel, normally in the range 0-1.
- ///
- /// This function handles all surface formats, and ignores any clip rectangle.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static bool ClearSurface(nint surface, float r, float g, float b, float a) {
- if (surface == nint.Zero) {
- LogWarn(LogCategory.System, "ClearSurface: Surface pointer is null.");
- return false;
- }
- return SDL_ClearSurface(surface, r, g, b, a);
- }
-
- /// Compose a custom blend mode for renderers.
- /// the applied to the red, green, and blue components of the source pixels.
- /// the applied to the red, green, and blue components of the destination pixels.
- /// the used to combine the red, green, and blue components of the source and destination pixels.
- /// the applied to the alpha component of the source pixels.
- /// the applied to the alpha component of the destination pixels.
- /// the used to combine the alpha component of the source and destination pixels.
- ///
- /// The functions and accept the returned by this function if the renderer supports it.
- /// Thread Safety: It is safe to call this function from any thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- ///
- ///
- /// Returns an that represents the chosen factors and operations.
- public static BlendMode ComposeCustomBlendMode(BlendFactor srcColorFactor, BlendFactor dstColorFactor, BlendOperation colorOperation, BlendFactor srcAlphaFactor, BlendFactor dstAlphaFactor, BlendOperation alphaOperation) {
- if (!Enum.IsDefined(srcColorFactor) ||
- !Enum.IsDefined(dstColorFactor) ||
- !Enum.IsDefined(colorOperation) ||
- !Enum.IsDefined(srcAlphaFactor) ||
- !Enum.IsDefined(dstAlphaFactor) ||
- !Enum.IsDefined(alphaOperation)) {
- LogError(LogCategory.Error, "ComposeCustomBlendMode: Invalid blend factors or operations provided.");
- throw new ArgumentException("Invalid blend factors or operations.");
- }
-
- uint blendMode = SDL_ComposeCustomBlendMode(srcColorFactor, dstColorFactor, colorOperation, srcAlphaFactor, dstAlphaFactor, alphaOperation);
- if (blendMode == 0) {
- LogError(LogCategory.Error, "ComposeCustomBlendMode: Failed to compose custom blend mode.");
- }
-
- return (BlendMode)blendMode;
- }
-
- /// Copy a block of pixels of one format to another format.
- /// the width of the block to copy, in pixels.
- /// the height of the block to copy, in pixels.
- /// an value of the src pixels format.
- /// a pointer to the source pixels.
- /// the pitch of the source pixels, in bytes.
- /// an value of the dst pixels format.
- /// a pointer to be filled in with new pixel data.
- /// the pitch of the destination pixels, in bytes.
- ///
- /// Thread Safety: The same destination pixels should not be used from two threads at once. It is safe to use the same source pixels from multiple threads.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool ConvertPixels(int width, int height, PixelFormat srcFormat, nint src, int srcPitch, PixelFormat dstFormat, nint dst, int dstPitch) {
- if (src == nint.Zero || dst == nint.Zero) {
- LogWarn(LogCategory.System, "ConvertPixels: Source or destination pointer is null.");
- return false;
- }
- return SDL_ConvertPixels(width, height, srcFormat, src, srcPitch, dstFormat, dst, dstPitch);
- }
-
- /// Copy a block of pixels of one format and colorspace to another format and colorspace.
- /// the width of the block to copy, in pixels.
- /// the height of the block to copy, in pixels.
- /// an value of the src pixels format.
- /// an value describing the colorspace of the src pixels.
- /// an SDL_PropertiesID with additional source color properties, or 0.
- /// a pointer to the source pixels.
- /// the pitch of the source pixels, in bytes.
- /// an value of the dst pixels format.
- /// an value describing the colorspace of the dst pixels.
- /// an SDL_PropertiesID with additional destination color properties, or 0.
- /// a pointer to be filled in with new pixel data.
- /// the pitch of the destination pixels, in bytes.
- ///
- /// Thread Safety: The same destination pixels should not be used from two threads at once. It is safe to use the same source pixels from multiple threads.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool ConvertPixelsAndColorspace(int width, int height, PixelFormat srcFormat, Colorspace srcColorspace, uint srcProperties, nint src, int srcPitch, PixelFormat dstFormat, Colorspace dstColorspace, uint dstProperties, nint dst, int dstPitch) {
- if (src == nint.Zero || dst == nint.Zero) {
- LogWarn(LogCategory.System, "ConvertPixelsAndColorspace: Source or destination pointer is null.");
- return false;
- }
- return SDL_ConvertPixelsAndColorspace(width, height, srcFormat, srcColorspace, srcProperties, src, srcPitch, dstFormat, dstColorspace, dstProperties, dst, dstPitch);
- }
-
- /// Copy an existing surface to a new surface of the specified format.
- /// the existing SDL_Surface structure to convert.
- /// the new pixel format.
- ///
- /// This function is used to optimize images for faster repeat blitting. This
- /// is accomplished by converting the original and storing the result as a new
- /// surface. The new, optimized surface can then be used as the source for
- /// future blits, making them faster.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- /// (SDL_Surface *) Returns the new SDL_Surfacestructure that is created or on failure; call for more information.
-
- public static nint ConvertSurface(nint surface, PixelFormat format) {
- if (surface == nint.Zero) {
- LogWarn(LogCategory.System, "ConvertSurface: Surface pointer is null.");
- return nint.Zero;
- }
- return SDL_ConvertSurface(surface, format);
- }
-
- /// Copy an existing surface to a new surface of the specified format and colorspace.
- /// the existing SDL_Surface structure to convert.
- /// the new pixel format.
- /// an optional palette to use for indexed formats, may be discarded.
- /// the new colorspace.
- /// an SDL_PropertiesID with additional color properties, or 0.
- ///
- /// This function converts an existing surface to a new format and colorspace
- /// and returns the new surface. This will perform any pixel format and
- /// colorspace conversion needed.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- /// (SDL_Surface *) Returns the new SDL_Surfacestructure that is created or on failure; call for more information.
-
- public static nint ConvertSurfaceAndColorspace(nint surface, PixelFormat format, nint palette, Colorspace colorspace, uint props) {
- if (surface == nint.Zero) {
- LogWarn(LogCategory.System, "ConvertSurfaceAndColorspace: Surface pointer is null.");
- return nint.Zero;
- }
- return SDL_ConvertSurfaceAndColorspace(surface, format, palette, colorspace, props);
- }
/// Copy a group of properties.
/// the properties to copy.
@@ -528,7 +220,7 @@ public static nint CreatePalette(int ncolors) {
LogError(LogCategory.Error, "CreatePalette: Number of colors must be greater than zero.");
}
- nint palette = SDL_CreatePalette(ncolors);
+ var palette = SDL_CreatePalette(ncolors);
if (palette == nint.Zero) {
LogError(LogCategory.Error, "CreatePalette: Failed to create palette.");
}
@@ -570,7 +262,7 @@ public static nint CreatePopupWindow(nint parent, int offsetX, int offsetY, int
return nint.Zero;
}
- nint popupWindow = SDL_CreatePopupWindow(parent, offsetX, offsetY, w, h, flags);
+ var popupWindow = SDL_CreatePopupWindow(parent, offsetX, offsetY, w, h, flags);
if (popupWindow == nint.Zero) {
LogError(LogCategory.Error, "CreatePopupWindow: Failed to create popup window.");
}
@@ -586,7 +278,7 @@ public static nint CreatePopupWindow(nint parent, int offsetX, int offsetY, int
///
/// Returns an ID for a new group of properties, or 0 on failure; call for more information.
public static uint CreateProperties() {
- uint props = SDL_CreateProperties();
+ var props = SDL_CreateProperties();
if (props == 0) {
LogError(LogCategory.Error, "CreateProperties: Failed to create properties.");
}
@@ -594,76 +286,6 @@ public static uint CreateProperties() {
return props;
}
- /// Allocate a new surface with a specific pixel format.
- /// the width of the surface.
- /// the height of the surface.
- /// the for the new surface's pixel format.
- ///
- /// The pixels of the new surface are initialized to zero.
- /// Thread Safety: It is safe to call this function from any thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- /// (SDL_Surface *) Returns the new SDL_Surfacestructure that is created or on failure; call for more information.
- public static nint CreateSurface(int width, int height, PixelFormat format) {
- if (width <= 0 || height <= 0) {
- LogError(LogCategory.Error, "CreateSurface: Invalid width or height.");
- return nint.Zero;
- }
-
- return SDL_CreateSurface(width, height, format);
- }
-
- /// Allocate a new surface with a specific pixel format and existing pixel data.
- /// the width of the surface.
- /// the height of the surface.
- /// the for the new surface's pixel format.
- /// a pointer to existing pixel data.
- /// the number of bytes between each row, including padding.
- ///
- /// No copy is made of the pixel data. Pixel data is not managed automatically;
- /// you must free the surface before you free the pixel data.
- /// Thread Safety: It is safe to call this function from any thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- /// (SDL_Surface *) Returns the new SDL_Surface structure that is created or on failure; call for more information.
- public static nint CreateSurfaceFrom(int width, int height, PixelFormat format, nint pixels, int pitch) {
- if (pixels == nint.Zero) {
- LogError(LogCategory.System, "CreateSurfaceFrom: Pixels pointer is null.");
- return nint.Zero;
- }
-
- if (!Enum.IsDefined(format)) {
- LogError(LogCategory.Error, "CreateSurfaceFrom: Invalid pixel format.");
- return nint.Zero;
- }
-
- return SDL_CreateSurfaceFrom(width, height, format, pixels, pitch);
- }
-
- /// Create a palette and associate it with a surface.
- /// the structure to update.
- ///
- /// This function creates a palette compatible with the provided surface. The
- /// palette is then returned for you to modify, and the surface will
- /// automatically use the new palette in future operations. You do not need to
- /// destroy the returned palette, it will be freed when the reference count
- /// reaches 0, usually when the surface is destroyed.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// (SDL_Palette *) Returns a new SDL_Palettestructure on success or on failure (e.g. if the surface didn't have anindex format); call for more information.
- public static nint CreateSurfacePalette(nint surface) {
- if (surface == nint.Zero) {
- LogError(LogCategory.System, "CreateSurfacePalette: Surface pointer is null.");
- return nint.Zero;
- }
- return SDL_CreateSurfacePalette(surface);
- }
public static nint CreateThreadRuntime(SdlThreadFunction fn, string name, nint data, nint pfnBeginThread, nint pfnEndThread) {
if (fn == null) {
@@ -683,7 +305,7 @@ public static nint CreateThreadWithPropertiesRuntime(uint props, nint pfnBeginTh
return nint.Zero;
}
- nint threadHandle = SDL_CreateThreadWithPropertiesRuntime(props, pfnBeginThread, pfnEndThread);
+ var threadHandle = SDL_CreateThreadWithPropertiesRuntime(props, pfnBeginThread, pfnEndThread);
if (threadHandle == nint.Zero) {
LogError(LogCategory.Error, "CreateThreadWithPropertiesRuntime: Failed to create thread with properties.");
}
@@ -735,7 +357,7 @@ public static nint CreateWindowWithProperties(uint props) {
return nint.Zero;
}
- nint windowHandle = SDL_CreateWindowWithProperties(props);
+ var windowHandle = SDL_CreateWindowWithProperties(props);
if (windowHandle == nint.Zero) {
LogError(LogCategory.Error, "CreateWindowWithProperties: Failed to create window with properties.");
throw new InvalidOperationException("CreateWindowWithProperties failed.");
@@ -775,22 +397,7 @@ public static void DestroyProperties(uint props) {
SDL_DestroyProperties(props);
}
- /// Free a surface.
- /// the to free.
- ///
- /// It is safe to pass to this function.
- /// Thread Safety: No other thread should be using the surface when it is freed.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- public static void DestroySurface(nint surface) {
- if (surface == nint.Zero) {
- LogInfo(LogCategory.System, "Will destroy nothing.");
- }
- SDL_DestroySurface(surface);
- }
/// Destroy a window.
/// the window to destroy.
@@ -860,22 +467,7 @@ public static bool DisableScreenSaver() {
return SDL_DisableScreenSaver();
}
- /// Creates a new surface identical to the existing surface.
- /// the surface to duplicate.
- ///
- /// If the original surface has alternate images, the new surface will have a reference to them as well.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// (SDL_Surface *) Returns a copy of the surface or on failure; call for more information.
- public static nint DuplicateSurface(nint surface) {
- if (surface == nint.Zero) {
- LogWarn(LogCategory.System, "DuplicateSurface: Surface pointer is null.");
- return nint.Zero;
- }
- return SDL_DuplicateSurface(surface);
- }
+
/// Allow the screen to be blanked by a screen saver.
///
@@ -935,64 +527,7 @@ public static bool EnumerateProperties(uint props, SdlEnumeratePropertiesCallbac
return SDL_EnumerateProperties(props, callback, userdata);
}
- /// Perform a fast fill of a rectangle with a specific color.
- /// the structure that is the drawing target.
- /// the structure representing the rectangle to fill, or to fill the entire surface.
- /// the color to fill with.
- ///
- /// color should be a pixel of the format used by the surface, and can be
- /// generated by or . If
- /// the color value contains an alpha component then the destination is simply
- /// filled with that alpha information, no blending takes place.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static unsafe bool FillSurfaceRect(nint dst, Rect rect, uint color) {
- if (dst == nint.Zero) {
- LogWarn(LogCategory.System, "FillSurfaceRect: Destination pointer is null.");
- return false;
- }
- nint rectPtr = Marshal.AllocHGlobal(sizeof(Rect));
- *(Rect*)rectPtr = rect;
- bool result = SDL_FillSurfaceRect(dst, rectPtr, color);
- if (!result) {
- LogError(LogCategory.Error, "FillSurfaceRect: Failed to fill surface rectangle.");
- }
- Marshal.FreeHGlobal(rectPtr);
- return result;
- }
- /// Perform a fast fill of a set of rectangles with a specific color.
- /// the structure that is the drawing target.
- /// an array of s representing the rectangles to fill.
- /// the color to fill with.
- ///
- /// color should be a pixel of the format used by the surface, and can be
- /// generated by or . If
- /// the color value contains an alpha component then the destination is simply
- /// filled with that alpha information, no blending takes place.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool FillSurfaceRects(nint dst, Span rects, uint color) {
- if (dst == nint.Zero) {
- LogWarn(LogCategory.System, "FillSurfaceRects: Destination pointer is null.");
- return false;
- }
- if (rects.IsEmpty) {
- LogWarn(LogCategory.System, "FillSurfaceRects: Rectangles span is empty.");
- return false;
- }
- bool result = SDL_FillSurfaceRects(dst, rects, rects.Length, color);
- if (!result) {
- LogError(LogCategory.Error, "FillSurfaceRects: Failed to fill surface rectangles.");
- }
- return result;
- }
/// Request a window to demand attention from the user.
/// the window to be flashed.
@@ -1020,21 +555,6 @@ public static bool FlashWindow(nint window, FlashOperation operation) {
return result;
}
- /// Flip a surface vertically or horizontally.
- /// the surface to flip.
- /// the direction to flip.
- ///
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static bool FlipSurface(nint surface, FlipMode flip) {
- if (surface == nint.Zero) {
- LogWarn(LogCategory.System, "FlipSurface: Surface pointer is null.");
- return false;
- }
- return SDL_FlipSurface(surface, flip);
- }
public static void Free(nint mem) {
if (mem == nint.Zero) {
@@ -1071,7 +591,7 @@ public static string GetAppMetadataProperty(string name) {
LogWarn(LogCategory.System, "GetAppMetadataProperty: Name is null or empty.");
return string.Empty;
}
- string result = SDL_GetAppMetadataProperty(name);
+ var result = SDL_GetAppMetadataProperty(name);
if (string.IsNullOrEmpty(result)) {
LogError(LogCategory.Error, "GetAppMetadataProperty: Failed to retrieve property.");
}
@@ -1118,7 +638,7 @@ public static Span GetClipboardData(string mimeType) {
LogWarn(LogCategory.System, "GetClipboardData: MimeType is null or empty.");
return [];
}
- nint result = SDL_GetClipboardData(mimeType, out nuint size);
+ var result = SDL_GetClipboardData(mimeType, out var size);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetClipboardData: Failed to retrieve clipboard data.");
return [];
@@ -1129,7 +649,7 @@ public static Span GetClipboardData(string mimeType) {
return [];
}
- nint[] data = new nint[size];
+ var data = new nint[size];
Marshal.Copy(result, data, 0, (int)size);
return new Span(data);
@@ -1143,13 +663,13 @@ public static Span GetClipboardData(string mimeType) {
///
/// (char **) Returns a null terminated array of strings with mime types, or on failure; call for more information.This should be freed with when it is no longer needed.
public static Span GetClipboardMimeTypes() {
- nint result = SDL_GetClipboardMimeTypes(out nuint numMimeTypes);
+ var result = SDL_GetClipboardMimeTypes(out var numMimeTypes);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetClipboardMimeTypes: Failed to retrieve clipboard mime types.");
return [];
}
- nint[] data = new nint[numMimeTypes];
+ var data = new nint[numMimeTypes];
Marshal.Copy(result, data, 0, (int)numMimeTypes);
return new Span(data);
@@ -1164,7 +684,7 @@ public static Span GetClipboardMimeTypes() {
///
/// (char **) Returns a null terminated array of strings with mime types, or on failure; call for more information.This should be freed with when it is no longer needed.
public static nint GetClipboardMimeTypes(out nuint numMimeTypes) {
- nint result = SDL_GetClipboardMimeTypes(out numMimeTypes);
+ var result = SDL_GetClipboardMimeTypes(out numMimeTypes);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetClipboardMimeTypes: Failed to retrieve clipboard mime types.");
return nint.Zero;
@@ -1182,7 +702,7 @@ public static nint GetClipboardMimeTypes(out nuint numMimeTypes) {
///
/// (char *) Returns the clipboard text on success or an empty string on failure; call for more information. Thisshould be freed with when it is no longer needed.
public static string GetClipboardText() {
- string result = SDL_GetClipboardText();
+ var result = SDL_GetClipboardText();
if (string.IsNullOrEmpty(result)) {
LogError(LogCategory.Error, "GetClipboardText: Failed to retrieve clipboard text.");
}
@@ -1242,7 +762,7 @@ public static nint GetCurrentDisplayMode(uint displayId) {
LogWarn(LogCategory.System, "GetCurrentDisplayMode: Display ID is zero.");
return nint.Zero;
}
- nint mode = SDL_GetCurrentDisplayMode(displayId);
+ var mode = SDL_GetCurrentDisplayMode(displayId);
if (mode == nint.Zero) {
LogError(LogCategory.Error, "GetCurrentDisplayMode: Failed to retrieve current mode.");
}
@@ -1268,7 +788,7 @@ public static unsafe void GetCurrentDisplayMode(uint displayId, out DisplayMode
mode = default;
return;
}
- nint modePtr = SDL_GetCurrentDisplayMode(displayId);
+ var modePtr = SDL_GetCurrentDisplayMode(displayId);
if (modePtr == nint.Zero) {
LogError(LogCategory.Error, "GetCurrentDisplayMode: Failed to retrieve current mode.");
mode = default;
@@ -1291,7 +811,7 @@ public static DisplayOrientation GetCurrentDisplayOrientation(uint displayId) {
LogWarn(LogCategory.System, "GetCurrentDisplayOrientation: Display ID is zero.");
return DisplayOrientation.Unknown;
}
- DisplayOrientation orientation = SDL_GetCurrentDisplayOrientation(displayId);
+ var orientation = SDL_GetCurrentDisplayOrientation(displayId);
if (orientation == DisplayOrientation.Unknown) {
LogError(LogCategory.Error, "GetCurrentDisplayOrientation: Failed to retrieve orientation.");
}
@@ -1308,7 +828,7 @@ public static DisplayOrientation GetCurrentDisplayOrientation(uint displayId) {
///
/// Returns the ID of the current thread.
public static ulong GetCurrentThreadId() {
- ulong threadId = SDL_GetCurrentThreadID();
+ var threadId = SDL_GetCurrentThreadID();
if (threadId == 0) {
LogError(LogCategory.Error, "GetCurrentThreadID: Failed to retrieve thread ID.");
}
@@ -1344,7 +864,7 @@ public static string GetCurrentVideoDriver() {
///
/// Returns a structure to the desktop display mode or on failure; call for more information.
public static DisplayMode GetDesktopDisplayMode(uint displayId) {
- GetDesktopDisplayMode(displayId, out DisplayMode mode);
+ GetDesktopDisplayMode(displayId, out var mode);
return mode;
}
@@ -1367,7 +887,7 @@ public static unsafe void GetDesktopDisplayMode(uint displayId, out DisplayMode
mode = default;
return;
}
- nint modePtr = SDL_GetDesktopDisplayMode(displayId);
+ var modePtr = SDL_GetDesktopDisplayMode(displayId);
if (modePtr == nint.Zero) {
LogError(LogCategory.Error, "GetDesktopDisplayMode: Failed to retrieve desktop mode.");
mode = default;
@@ -1419,7 +939,7 @@ public static float GetDisplayContentScale(uint displayId) {
LogWarn(LogCategory.System, "GetDisplayContentScale: Display ID is zero.");
return 0f;
}
- float scale = SDL_GetDisplayContentScale(displayId);
+ var scale = SDL_GetDisplayContentScale(displayId);
if (scale <= 0.01f) {
LogError(LogCategory.Error, "GetDisplayContentScale: Failed to retrieve content scale.");
}
@@ -1436,7 +956,7 @@ public static float GetDisplayContentScale(uint displayId) {
///
/// Returns the instance ID of the displaycontaining the point or 0 on failure; call for more information.
public static uint GetDisplayForPoint(ref Point point) {
- uint displayId = SDL_GetDisplayForPoint(ref point);
+ var displayId = SDL_GetDisplayForPoint(ref point);
if (displayId == 0) {
LogError(LogCategory.Error, "GetDisplayForPoint: Failed to retrieve display ID.");
}
@@ -1453,7 +973,7 @@ public static uint GetDisplayForPoint(ref Point point) {
///
/// Returns the instance ID of the display entirely containing the rect or closest to the center of the rect on success or 0 on failure; call for more information.
public static uint GetDisplayForRect(ref Rect rect) {
- uint displayId = SDL_GetDisplayForRect(ref rect);
+ var displayId = SDL_GetDisplayForRect(ref rect);
if (displayId == 0) {
LogError(LogCategory.Error, "GetDisplayForRect: Failed to retrieve display ID.");
}
@@ -1474,7 +994,7 @@ public static uint GetDisplayForWindow(nint window) {
LogError(LogCategory.Error, "GetDisplayForWindow: Window handle is null.");
return 0;
}
- uint displayId = SDL_GetDisplayForWindow(window);
+ var displayId = SDL_GetDisplayForWindow(window);
if (displayId == 0) {
LogError(LogCategory.Error, "GetDisplayForWindow: Failed to retrieve display ID.");
}
@@ -1494,7 +1014,7 @@ public static string GetDisplayName(uint displayId) {
LogWarn(LogCategory.System, "GetDisplayName: Display ID is zero.");
return string.Empty;
}
- string name = SDL_GetDisplayName(displayId);
+ var name = SDL_GetDisplayName(displayId);
if (string.IsNullOrEmpty(name)) {
LogError(LogCategory.Error, "GetDisplayName: Failed to retrieve display name.");
}
@@ -1514,7 +1034,7 @@ public static uint GetDisplayProperties(uint displayId) {
LogWarn(LogCategory.System, "GetDisplayProperties: Display ID is zero.");
return 0;
}
- uint props = SDL_GetDisplayProperties(displayId);
+ var props = SDL_GetDisplayProperties(displayId);
if (props == 0) {
LogError(LogCategory.Error, "GetDisplayProperties: Failed to retrieve display properties.");
}
@@ -1528,7 +1048,7 @@ public static uint GetDisplayProperties(uint displayId) {
///
/// (SDL_DisplayID *) Returns a 0 terminated array of display instance IDs or on failure; call for more information. This should be freed with when itis no longer needed.
public static Span GetDisplays() {
- Span result = GetDisplays(out int _);
+ var result = GetDisplays(out var _);
if (result == []) {
return [];
}
@@ -1543,13 +1063,13 @@ public static Span GetDisplays() {
///
/// (SDL_DisplayID *) Returns a 0 terminated array of display instance IDs or on failure; call for more information. This should be freed with when itis no longer needed.
public static Span GetDisplays(out int count) {
- nint result = SDL_GetDisplays(out count);
+ var result = SDL_GetDisplays(out count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetDisplays: Failed to retrieve display handles.");
return [];
}
- nint[] data = new nint[count];
+ var data = new nint[count];
Marshal.Copy(result, data, 0, count);
return data;
@@ -1591,7 +1111,7 @@ public static bool GetDisplayUsableBounds(uint displayId, out Rect rect) {
///
/// Returns a message with information about the specific error that occurred, or an empty string if there hasn't been an error message set since the last call to .
public static string GetError() {
- string error = SDL_GetError();
+ var error = SDL_GetError();
return string.IsNullOrEmpty(error) ? "No error." : error;
}
@@ -1614,7 +1134,7 @@ public static float GetFloatProperty(uint props, string name, float defaultValue
LogWarn(LogCategory.System, "GetFloatProperty: Properties handle is zero or name is null/empty.");
return defaultValue;
}
- float result = SDL_GetFloatProperty(props, name, defaultValue);
+ var result = SDL_GetFloatProperty(props, name, defaultValue);
if (result <= 0.1f) {
LogError(LogCategory.Error, "GetFloatProperty: Failed to retrieve float property.");
}
@@ -1632,7 +1152,7 @@ public static float GetFloatProperty(uint props, string name, float defaultValue
///
/// (SDL_DisplayMode **) Returns a terminated array of display mode pointers or on failure; call for more information. This is a singleallocation that should be freed with when it is nolonger needed.
public static Span GetFullscreenDisplayModes(uint displayId) {
- nint result = SDL_GetFullscreenDisplayModes(displayId, out int count);
+ var result = SDL_GetFullscreenDisplayModes(displayId, out var count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetFullscreenDisplayModes: Failed to retrieve fullscreen display modes.");
@@ -1644,7 +1164,7 @@ public static Span GetFullscreenDisplayModes(uint displayId) {
return [];
}
- int[] data = new int[count];
+ var data = new int[count];
Marshal.Copy(result, data, 0, count);
return data;
@@ -1661,7 +1181,7 @@ public static Span GetFullscreenDisplayModes(uint displayId) {
///
/// (SDL_DisplayMode **) Returns a terminated array of display mode pointers or on failure; call for more information. This is a single allocation that should be freed with when it is no longer needed.
public static Span GetFullscreenDisplayModes(uint displayId, out int count) {
- nint result = SDL_GetFullscreenDisplayModes(displayId, out count);
+ var result = SDL_GetFullscreenDisplayModes(displayId, out count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetFullscreenDisplayModes: Failed to retrieve fullscreen display modes.");
return [];
@@ -1672,7 +1192,7 @@ public static Span GetFullscreenDisplayModes(uint displayId, out int count
return [];
}
- nint[] data = new nint[count];
+ var data = new nint[count];
Marshal.Copy(result, data, 0, count);
return data;
@@ -1696,7 +1216,7 @@ public static uint GetGlobalProperties() {
///
/// (SDL_Window *) Returns the window if input is grabbed or otherwise.
public static nint GetGrabbedWindow() {
- nint window = SDL_GetGrabbedWindow();
+ var window = SDL_GetGrabbedWindow();
if (window == nint.Zero) {
LogError(LogCategory.Error, "GetGrabbedWindow: Failed to retrieve grabbed window.");
}
@@ -1717,7 +1237,7 @@ public static string GetHint(string name) {
LogWarn(LogCategory.System, "GetHint: Name is null or empty.");
return string.Empty;
}
- string result = SDL_GetHint(name);
+ var result = SDL_GetHint(name);
if (string.IsNullOrEmpty(result)) {
LogError(LogCategory.Error, "GetHint: Failed to retrieve hint.");
}
@@ -1759,7 +1279,7 @@ public static bool GetHintBoolean(string name, bool defaultValue) {
///
/// (SDL_KeyboardID *) Returns a 0 terminated array of keyboards instance IDs or on failure; call for more information. This should be freed with when it is no longer needed.
public static nint GetKeyboards(out int count) {
- nint result = SDL_GetKeyboards(out count);
+ var result = SDL_GetKeyboards(out count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetKeyboard: Failed to retrieve keyboard handles.");
return nint.Zero;
@@ -1778,7 +1298,7 @@ public static nint GetKeyboards(out int count) {
///
/// (SDL_KeyboardID *) Returns a 0 terminated array of keyboards instance IDs or on failure; call for more information. This should be freed with when it is no longer needed.
public static Span GetKeyboards() {
- nint result = GetKeyboards(out int count);
+ var result = GetKeyboards(out var count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetKeyboard: Failed to retrieve keyboard handles.");
return [];
@@ -1789,7 +1309,7 @@ public static Span GetKeyboards() {
return [];
}
- nint[] data = new nint[count];
+ var data = new nint[count];
Marshal.Copy(result, data, 0, count);
return data;
@@ -1802,7 +1322,7 @@ public static Span GetKeyboards() {
///
/// (SDL_Window *) Returns the window with keyboard focus.
public static nint GetKeyboardFocus() {
- nint window = SDL_GetKeyboardFocus();
+ var window = SDL_GetKeyboardFocus();
if (window == nint.Zero) {
LogError(LogCategory.Error, "GetKeyboardFocus: Failed to retrieve keyboard focus.");
}
@@ -1823,7 +1343,7 @@ public static string GetKeyboardNameForId(uint instanceId) {
LogWarn(LogCategory.System, "GetKeyboardNameForID: Instance ID is zero.");
return string.Empty;
}
- string name = SDL_GetKeyboardNameForID(instanceId);
+ var name = SDL_GetKeyboardNameForID(instanceId);
if (string.IsNullOrEmpty(name)) {
LogError(LogCategory.Error, "GetKeyboardNameForID: Failed to retrieve keyboard name.");
}
@@ -1842,7 +1362,7 @@ public static string GetKeyboardNameForId(uint instanceId) {
///
/// (const bool *) Returns a pointer to an array of key states.
public static Span GetKeyboardState(out int numKeys) {
- nint result = SDL_GetKeyboardState(out numKeys);
+ var result = SDL_GetKeyboardState(out numKeys);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetKeyboardState: Failed to retrieve keyboard state.");
@@ -1854,12 +1374,12 @@ public static Span GetKeyboardState(out int numKeys) {
return [];
}
- bool[] state = new bool[numKeys];
- for (int i = 0; i < numKeys; i++) {
+ var state = new bool[numKeys];
+ for (var i = 0; i < numKeys; i++) {
state[i] = Marshal.ReadByte(result, i) != 0;
}
- return new(state);
+ return new Span(state);
}
/// Get a key code from a human-readable name.
@@ -1877,7 +1397,7 @@ public static Keycode GetKeyFromName(string name) {
LogWarn(LogCategory.System, "GetKeyFromName: Name is null or empty.");
return 0;
}
- uint key = SDL_GetKeyFromName(name);
+ var key = SDL_GetKeyFromName(name);
if (key == 0) {
LogError(LogCategory.Error, "GetKeyFromName: Failed to retrieve key from name.");
}
@@ -1903,7 +1423,7 @@ public static uint GetKeyFromScancode(Scancode scanCode, KeyMod modstate, bool k
LogWarn(LogCategory.System, "GetKeyFromScancode: Scan code is unknown.");
return 0;
}
- uint key = SDL_GetKeyFromScancode(scanCode, modstate, keyEvent);
+ var key = SDL_GetKeyFromScancode(scanCode, modstate, keyEvent);
if (key == 0) {
LogError(LogCategory.Error, "GetKeyFromScancode: Failed to retrieve key from scan code.");
}
@@ -1926,7 +1446,7 @@ public static string GetKeyName(Keycode key) {
LogWarn(LogCategory.System, "GetKeyName: Key is zero.");
return string.Empty;
}
- string name = SDL_GetKeyName((uint)key);
+ var name = SDL_GetKeyName((uint)key);
if (string.IsNullOrEmpty(name)) {
LogError(LogCategory.Error, "GetKeyName: Failed to retrieve key name.");
}
@@ -1989,7 +1509,7 @@ public static DisplayOrientation GetNaturalDisplayOrientation(uint displayId) {
LogWarn(LogCategory.System, "GetNaturalDisplayOrientation: Display ID is zero.");
return DisplayOrientation.Unknown;
}
- DisplayOrientation orientation = SDL_GetNaturalDisplayOrientation(displayId);
+ var orientation = SDL_GetNaturalDisplayOrientation(displayId);
if (orientation == DisplayOrientation.Unknown) {
LogError(LogCategory.Error, "GetNaturalDisplayOrientation: Failed to retrieve orientation.");
}
@@ -2014,7 +1534,7 @@ public static long GetNumberProperty(uint props, string name, long defaultValue)
LogWarn(LogCategory.System, "GetNumberProperty: Properties handle is zero or name is null/empty.");
return defaultValue;
}
- long result = SDL_GetNumberProperty(props, name, defaultValue);
+ var result = SDL_GetNumberProperty(props, name, defaultValue);
if (result <= 0) {
LogError(LogCategory.Error, "GetNumberProperty: Failed to retrieve number property.");
}
@@ -2029,7 +1549,7 @@ public static long GetNumberProperty(uint props, string name, long defaultValue)
///
/// Returns the number of built in video drivers.
public static int GetNumVideoDrivers() {
- int numDrivers = SDL_GetNumVideoDrivers();
+ var numDrivers = SDL_GetNumVideoDrivers();
if (numDrivers <= 0) {
LogError(LogCategory.Error, "GetNumVideoDrivers: Failed to retrieve number of video drivers.");
}
@@ -2052,7 +1572,7 @@ public static nint GetPixelFormatDetails(PixelFormat format) {
LogWarn(LogCategory.System, "GetPixelFormatDetails: Format is unknown.");
return nint.Zero;
}
- nint details = SDL_GetPixelFormatDetails(format);
+ var details = SDL_GetPixelFormatDetails(format);
if (details == nint.Zero) {
LogError(LogCategory.Error, "GetPixelFormatDetails: Failed to retrieve pixel format details.");
}
@@ -2077,7 +1597,7 @@ public static PixelFormat GetPixelFormatForMasks(int bpp, uint rmask, uint gmask
LogWarn(LogCategory.System, "GetPixelFormatForMasks: Invalid parameters.");
return PixelFormat.Unknown;
}
- PixelFormat format = SDL_GetPixelFormatForMasks(bpp, rmask, gmask, bmask, amask);
+ var format = SDL_GetPixelFormatForMasks(bpp, rmask, gmask, bmask, amask);
if (format == PixelFormat.Unknown) {
LogError(LogCategory.Error, "GetPixelFormatForMasks: Failed to retrieve pixel format.");
}
@@ -2096,7 +1616,7 @@ public static string GetPixelFormatName(PixelFormat format) {
LogWarn(LogCategory.System, "GetPixelFormatName: Format is unknown.");
return string.Empty;
}
- string name = SDL_GetPixelFormatName(format);
+ var name = SDL_GetPixelFormatName(format);
if (string.IsNullOrEmpty(name)) {
LogError(LogCategory.Error, "GetPixelFormatName: Failed to retrieve pixel format name.");
}
@@ -2129,7 +1649,7 @@ public static nint GetPointerProperty(uint props, string name, nint defaultValue
LogWarn(LogCategory.System, "GetPointerProperty: Properties handle is zero or name is null/empty.");
return defaultValue;
}
- nint result = SDL_GetPointerProperty(props, name, defaultValue);
+ var result = SDL_GetPointerProperty(props, name, defaultValue);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetPointerProperty: Failed to retrieve pointer property.");
}
@@ -2149,7 +1669,7 @@ public static nint GetPointerProperty(uint props, string name, nint defaultValue
///
/// Returns the current battery state or on failure; call for more information.
public static PowerState GetPowerInfo(out int seconds, out int percent) {
- PowerState state = SDL_GetPowerInfo(out seconds, out percent);
+ var state = SDL_GetPowerInfo(out seconds, out percent);
if (state == PowerState.Unknown) {
LogError(LogCategory.Error, "GetPowerInfo: Failed to retrieve power info.");
}
@@ -2170,7 +1690,7 @@ public static PowerState GetPowerInfo(out int seconds, out int percent) {
///
/// (SDL_Locale **) Returns a terminated array of locale pointers, or on failure; call for more information. This is a single allocation that should be freed withSDL_free() when it is no longer needed.
public static Span GetPreferredLocales() {
- nint result = SDL_GetPreferredLocales(out int count);
+ var result = SDL_GetPreferredLocales(out var count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetPreferredLocales: Failed to retrieve preferred locales.");
return [];
@@ -2181,7 +1701,7 @@ public static Span GetPreferredLocales() {
return [];
}
- nint[] data = new nint[count];
+ var data = new nint[count];
Marshal.Copy(result, data, 0, count);
return data;
@@ -2195,7 +1715,7 @@ public static Span GetPreferredLocales() {
///
/// Returns the instance ID of the primary display on success or 0 on failure; call for more information.
public static uint GetPrimaryDisplay() {
- uint displayId = SDL_GetPrimaryDisplay();
+ var displayId = SDL_GetPrimaryDisplay();
if (displayId == 0) {
LogError(LogCategory.Error, "GetPrimaryDisplay: Failed to retrieve primary display ID.");
}
@@ -2213,7 +1733,7 @@ public static uint GetPrimaryDisplay() {
///
/// (char *) Returns the primary selection text on success or an empty string on failure; call for more information. This should be freed with when it is no longer needed.
public static string GetPrimarySelectionText() {
- string text = SDL_GetPrimarySelectionText();
+ var text = SDL_GetPrimarySelectionText();
if (string.IsNullOrEmpty(text)) {
LogError(LogCategory.Error, "GetPrimarySelectionText: Failed to retrieve primary selection text.");
}
@@ -2417,7 +1937,7 @@ public static Color GetRgb(uint pixel, nint format, nint palette) {
LogWarn(LogCategory.System, "GetRGB: Palette pointer is null. Defaulting to no palette.");
}
- SDL_GetRGB(pixel, format, palette, out byte r, out byte g, out byte b);
+ SDL_GetRGB(pixel, format, palette, out var r, out var g, out var b);
return new Color() { R = r, G = g, B = b, A = 255 };
}
@@ -2445,7 +1965,7 @@ public static Color GetRgba(uint pixel, nint format, nint palette) {
if (palette == nint.Zero) {
LogWarn(LogCategory.System, "GetRGBA: Palette pointer is null. Defaulting to no palette.");
}
- SDL_GetRGBA(pixel, format, palette, out byte r, out byte g, out byte b, out byte a);
+ SDL_GetRGBA(pixel, format, palette, out var r, out var g, out var b, out var a);
return new Color() { R = r, G = g, B = b, A = a };
}
@@ -2466,7 +1986,7 @@ public static Scancode GetScancodeFromKey(uint key, nint modstate) {
LogWarn(LogCategory.System, "GetScancodeFromKey: Key is zero.");
return Scancode.Unknown;
}
- Scancode scanCode = SDL_GetScancodeFromKey(key, modstate);
+ var scanCode = SDL_GetScancodeFromKey(key, modstate);
if (scanCode == Scancode.Unknown) {
LogError(LogCategory.Error, "GetScancodeFromKey: Failed to retrieve scan code from key.");
}
@@ -2488,7 +2008,7 @@ public static Scancode GetScancodeFromName(string name) {
LogWarn(LogCategory.System, "GetScancodeFromName: Name is null or empty.");
return Scancode.Unknown;
}
- Scancode scanCode = SDL_GetScancodeFromName(name);
+ var scanCode = SDL_GetScancodeFromName(name);
if (scanCode == Scancode.Unknown) {
LogError(LogCategory.Error, "GetScancodeFromName: Failed to retrieve scan code from name.");
}
@@ -2519,7 +2039,7 @@ public static string GetScancodeName(Scancode scanCode) {
LogWarn(LogCategory.System, "GetScancodeName: Scan code is unknown.");
return string.Empty;
}
- string name = SDL_GetScancodeName(scanCode);
+ var name = SDL_GetScancodeName(scanCode);
if (string.IsNullOrEmpty(name)) {
LogError(LogCategory.Error, "GetScancodeName: Failed to retrieve scan code name.");
}
@@ -2544,272 +2064,62 @@ public static string GetStringProperty(uint props, string name, string defaultVa
LogWarn(LogCategory.System, "GetStringProperty: Properties is zero or name is null/empty.");
return defaultValue;
}
- string result = SDL_GetStringProperty(props, name, defaultValue);
+ var result = SDL_GetStringProperty(props, name, defaultValue);
if (string.IsNullOrEmpty(result)) {
LogError(LogCategory.Error, "GetStringProperty: Failed to retrieve string property.");
}
return result;
}
- /// Get the additional alpha value used in blit operations.
- /// the structure to query.
- /// a pointer filled in with the current alpha value.
- ///
- /// Thread Safety: It is safe to call this function from any thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool GetSurfaceAlphaMod(nint surface, out byte alpha) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "GetSurfaceAlphaMod: Surface pointer is null.");
- alpha = 0;
- return false;
- }
- bool result = SDL_GetSurfaceAlphaMod(surface, out alpha);
- if (!result) {
- LogError(LogCategory.Error, "GetSurfaceAlphaMod: Failed to retrieve surface alpha mod.");
- }
- return result;
- }
+
- ///
- /// Get the palette used by a surface.
- ///
- /// the to query.
+ /// Get the current system theme.
///
- /// Thread Safety: It is safe to call this function from any thread.
+ /// Thread Safety: This function should only be called on the main thread.
/// Version: This function is available since SDL 3.2.0.
- ///
///
- /// (SDL_Palette *) Returns a pointer to the palette used by the surface, or if there is no palette used.
- public static nint GetSurfacePalette(nint surface) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "GetSurfacePalette: Surface pointer is null.");
- return nint.Zero;
- }
- nint palette = SDL_GetSurfacePalette(surface);
- if (palette == nint.Zero) {
- LogError(LogCategory.Error, "GetSurfacePalette: Failed to retrieve surface palette.");
+ /// Returns the current system theme,light, dark, or unknown.
+ public static SystemTheme GetSystemTheme() {
+ var theme = SDL_GetSystemTheme();
+ if (theme == SystemTheme.Unknown) {
+ LogError(LogCategory.Error, "GetSystemTheme: Failed to retrieve system theme.");
}
-
- return palette;
+ return theme;
}
- /// Get the blend mode used for blit operations.
- /// the structure to query.
- /// a pointer filled in with the current .
+ /// Get the area used to type Unicode text input.
+ /// the window for which to query the text input area.
+ /// a pointer to an filled in with the text input area, can bediscarded.
+ /// a pointer to the offset of the current cursor location relative to rect->x, may be discarded.
///
- /// Thread Safety: It is safe to call this function from any thread.
+ /// This returns the values previously set by .
+ /// Thread Safety: This function should only be called on the main thread.
/// Version: This function is available since SDL 3.2.0.
- ///
+ ///
///
/// Returns on success or on failure; call for more information.
- public static bool GetSurfaceBlendMode(nint surface, nint blendMode) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "GetSurfaceBlendMode: Surface pointer is null.");
+ public static bool GetTextInputArea(nint window, out Rect rect, out int cursor) {
+ if (window == nint.Zero) {
+ LogError(LogCategory.Error, "GetTextInputArea: Window pointer is null.");
+ rect = default;
+ cursor = 0;
return false;
}
- bool result = SDL_GetSurfaceBlendMode(surface, blendMode);
+ bool result = SDL_GetTextInputArea(window, out rect, out cursor);
if (!result) {
- LogError(LogCategory.Error, "GetSurfaceBlendMode: Failed to retrieve surface blend mode.");
+ LogError(LogCategory.Error, "GetTextInputArea: Failed to retrieve text input area.");
}
return result;
}
- /// Get the clipping rectangle for a surface.
- /// the structure representing the surface to be clipped.
- /// a structure filled in with the clipping rectangle for the surface.
+ /// Get the thread identifier for the specified thread.
+ /// the thread to query.
///
- /// When surface is the destination of a blit, only the area within the clip rectangle is drawn into.
- /// Thread Safety: This function is not thread safe.
+ /// This thread identifier is as reported by the underlying operating system.
+ /// If SDL is running on a platform that does not support threads the return
+ /// value will always be zero.
/// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool GetSurfaceClipRect(nint surface, out Rect rect) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "GetSurfaceClipRect: Surface pointer is null.");
- rect = default;
- return false;
- }
- bool result = SDL_GetSurfaceClipRect(surface, out rect);
- if (!result) {
- LogError(LogCategory.Error, "GetSurfaceClipRect: Failed to retrieve surface clip rect.");
- }
- return result;
- }
-
- /// Get the color key (transparent pixel) for a surface.
- /// the structure to query.
- /// a pointer filled in with the transparent pixel.
- ///
- /// The color key is a pixel of the format used by the surface, as generated by .
- /// Thread Safety: It is safe to call this function from any thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool GetSurfaceColorKey(nint surface, out uint key) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "GetSurfaceColorKey: Surface pointer is null.");
- key = 0;
- return false;
- }
- bool result = SDL_GetSurfaceColorKey(surface, out key);
- if (!result) {
- LogError(LogCategory.Error, "GetSurfaceColorKey: Failed to retrieve surface color key.");
- }
- return result;
- }
-
- /// Get the additional color value multiplied into blit operations.
- /// the structure to query.
- /// a pointer filled in with the current red color value.
- /// a pointer filled in with the current green color value.
- /// a pointer filled in with the current blue color value.
- ///
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool GetSurfaceColorMod(nint surface, out byte r, out byte g, out byte b) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "GetSurfaceColorMod: Surface pointer is null.");
- r = g = b = 0;
- return false;
- }
- bool result = SDL_GetSurfaceColorMod(surface, out r, out g, out b);
- if (!result) {
- LogError(LogCategory.Error, "GetSurfaceColorMod: Failed to retrieve surface color mod.");
- }
- return result;
- }
-
- /// Get an array including all versions of a surface.
- /// the structure to query.
- /// a pointer filled in with the number of surface pointers returned, may be discarded.
- ///
- /// This returns all versions of a surface, with the surface being queried as
- /// the first element in the returned array.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- ///
- /// (SDL_Surface **) Returns a terminated array ofSDL_Surface pointers or on failure; call for more information. This should be freedwith when it is no longer needed.
- public static Span GetSurfaceImages(nint surface, out int count) {
- nint result = SDL_GetSurfaceImages(surface, out count);
- if (result == nint.Zero) {
- LogError(LogCategory.Error, "GetSurfaceImages: Failed to retrieve surface images.");
- return [];
- }
-
- if (count <= 0) {
- LogError(LogCategory.Error, "GetSurfaceImages: No images found.");
- return [];
- }
-
- Span images = new(ref result);
- if (images == []) {
- LogError(LogCategory.Error, "GetSurfaceImages: Failed to create span for surface images.");
- return [];
- }
-
- if (images.Length != count) {
- LogError(LogCategory.Error, "GetSurfaceImages: Mismatch between count and span length.");
- return [];
- }
-
- for (int i = 0; i < count; i++) {
- if (images[i] == nint.Zero) {
- LogError(LogCategory.Error, $"GetSurfaceImages: Image at index {i} is null.");
- return [];
- }
- }
-
- return images.ToArray();
- }
-
- /// Get the properties associated with a surface.
- /// the structure to query.
- ///
- /// The following properties are understood by SDL:
- ///
- /// - SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT: for HDR10 and floating point surfaces, this defines the value of 100% diffuse white, with higher values being displayed in the High Dynamic Range headroom.This defaults to 203 for HDR10 surfaces and 1.0 for floating point surfaces.
- /// - SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT: for HDR10 and floating point surfaces, this defines the maximum dynamic range used by the content, in terms of the SDR white point.This defaults to 0.0, which disables tone mapping.
- /// - SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING: the tone mapping operator used when compressing from a surface with high dynamic range to another with lower dynamic range. Currently this supports "chrome", which uses the same tone mapping that Chrome uses for HDR content, the form "*=N", where N is a floating point scale factor applied in linear space, and "none", which disables tone mapping. This defaults to "chrome".
- /// - SDL_PROP_SURFACE_HOTSPOT_X_NUMBER: the hotspot pixel offset from the left edge of the image, if this surface is being used as a cursor.
- /// - SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER: the hotspot pixel offset from the top edge of the image, if this surface is being used as a cursor.
- ///
- /// Thread Safety: It is safe to call this function from any thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns a valid property ID on success or 0 on failure; call for more information.
- public static uint GetSurfaceProperties(nint surface) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "GetSurfaceProperties: Surface pointer is null.");
- return 0;
- }
- uint properties = SDL_GetSurfaceProperties(surface);
- if (properties == 0) {
- LogError(LogCategory.Error, "GetSurfaceProperties: Failed to retrieve surface properties.");
- }
- return properties;
- }
-
- /// Get the current system theme.
- ///
- /// Thread Safety: This function should only be called on the main thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns the current system theme,light, dark, or unknown.
- public static SystemTheme GetSystemTheme() {
- SystemTheme theme = SDL_GetSystemTheme();
- if (theme == SystemTheme.Unknown) {
- LogError(LogCategory.Error, "GetSystemTheme: Failed to retrieve system theme.");
- }
- return theme;
- }
-
- /// Get the area used to type Unicode text input.
- /// the window for which to query the text input area.
- /// a pointer to an filled in with the text input area, can bediscarded.
- /// a pointer to the offset of the current cursor location relative to rect->x, may be discarded.
- ///
- /// This returns the values previously set by .
- /// Thread Safety: This function should only be called on the main thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool GetTextInputArea(nint window, out Rect rect, out int cursor) {
- if (window == nint.Zero) {
- LogError(LogCategory.Error, "GetTextInputArea: Window pointer is null.");
- rect = default;
- cursor = 0;
- return false;
- }
- bool result = SDL_GetTextInputArea(window, out rect, out cursor);
- if (!result) {
- LogError(LogCategory.Error, "GetTextInputArea: Failed to retrieve text input area.");
- }
- return result;
- }
-
- /// Get the thread identifier for the specified thread.
- /// the thread to query.
- ///
- /// This thread identifier is as reported by the underlying operating system.
- /// If SDL is running on a platform that does not support threads the return
- /// value will always be zero.
- /// Version: This function is available since SDL 3.2.0.
- ///
+ ///
///
/// Returns the ID of the specified thread, orthe ID of the current thread if thread is .
public static ulong GetThreadId(nint thread) {
@@ -2817,7 +2127,7 @@ public static ulong GetThreadId(nint thread) {
LogError(LogCategory.Error, "GetThreadId: Thread pointer is null.");
return 0;
}
- ulong threadId = SDL_GetThreadID(thread);
+ var threadId = SDL_GetThreadID(thread);
if (threadId == 0) {
LogError(LogCategory.Error, "GetThreadId: Failed to retrieve thread ID.");
}
@@ -2835,7 +2145,7 @@ public static string GetThreadName(nint thread) {
LogError(LogCategory.Error, "GetThreadName: Thread pointer is null.");
return string.Empty;
}
- string name = SDL_GetThreadName(thread);
+ var name = SDL_GetThreadName(thread);
if (string.IsNullOrEmpty(name)) {
LogError(LogCategory.Error, "GetThreadName: Failed to retrieve thread name.");
}
@@ -2854,7 +2164,7 @@ public static SharpSDL3.Enums.ThreadState GetThreadState(nint thread) {
LogError(LogCategory.Error, "GetThreadState: Thread pointer is null.");
return ThreadState.Unknown;
}
- ThreadState state = SDL_GetThreadState(thread);
+ var state = SDL_GetThreadState(thread);
if (state == ThreadState.Unknown) {
LogError(LogCategory.Error, "GetThreadState: Failed to retrieve thread state.");
}
@@ -2874,7 +2184,7 @@ public static nint GetTls(nint id) {
LogError(LogCategory.Error, "GetTLS: ID is zero.");
return nint.Zero;
}
- nint tls = SDL_GetTLS(id);
+ var tls = SDL_GetTLS(id);
if (tls == nint.Zero) {
LogError(LogCategory.Error, "GetTLS: Failed to retrieve TLS value.");
}
@@ -2895,7 +2205,7 @@ public static string GetVideoDriver(int index) {
LogError(LogCategory.Error, "GetVideoDriver: Index is negative.");
return string.Empty;
}
- string driver = SDL_GetVideoDriver(index);
+ var driver = SDL_GetVideoDriver(index);
if (string.IsNullOrEmpty(driver)) {
LogError(LogCategory.Error, "GetVideoDriver: Failed to retrieve video driver.");
}
@@ -2975,7 +2285,7 @@ public static Rect GetWindowBordersSize(nint window) {
LogError(LogCategory.Error, "GetWindowBorderSize: Window pointer is null.");
return default;
}
- bool result = SDL_GetWindowBordersSize(window, out int top, out int left, out int bottom, out int right);
+ bool result = SDL_GetWindowBordersSize(window, out var top, out var left, out var bottom, out var right);
if (!result) {
LogError(LogCategory.Error, "GetWindowBorderSize: Failed to retrieve window border size.");
}
@@ -3000,7 +2310,7 @@ public static float GetWindowDisplayScale(nint window) {
LogError(LogCategory.Error, "GetWindowDisplayScale: Window pointer is null.");
return 0;
}
- float scale = SDL_GetWindowDisplayScale(window);
+ var scale = SDL_GetWindowDisplayScale(window);
if (scale <= 0) {
LogError(LogCategory.Error, "GetWindowDisplayScale: Failed to retrieve window display scale.");
}
@@ -3026,7 +2336,7 @@ public static WindowFlags GetWindowFlags(nint window) {
LogError(LogCategory.Error, "GetWindowFlags: Window handle is null.");
return 0;
}
- WindowFlags flags = SDL_GetWindowFlags(window);
+ var flags = SDL_GetWindowFlags(window);
if (flags == 0) {
LogWarn(LogCategory.System, "GetWindowFlags: Failed to retrieve window flags.");
}
@@ -3049,7 +2359,7 @@ public static nint GetWindowFromId(uint id) {
LogError(LogCategory.Error, "GetWindowFromId: Window ID is zero.");
return nint.Zero;
}
- nint windowHandle = SDL_GetWindowFromID(id);
+ var windowHandle = SDL_GetWindowFromID(id);
if (windowHandle == nint.Zero) {
LogWarn(LogCategory.System, "GetWindowFromId: Failed to retrieve window handle.");
}
@@ -3070,7 +2380,7 @@ public static nint GetWindowFullscreenMode(nint window) {
LogError(LogCategory.Error, "GetWindowFullscreenMode: Window pointer is null.");
return nint.Zero;
}
- nint mode = SDL_GetWindowFullscreenMode(window);
+ var mode = SDL_GetWindowFullscreenMode(window);
if (mode == nint.Zero) {
LogError(LogCategory.Error, "GetWindowFullscreenMode: Failed to retrieve window fullscreen mode.");
}
@@ -3091,7 +2401,7 @@ public static unsafe DisplayMode GetWindowFullScreenMode(nint window) {
LogError(LogCategory.Error, "GetWindowFullScreenMode: Window pointer is null.");
return default;
}
- DisplayMode mode = *(DisplayMode*)SDL_GetWindowFullscreenMode(window);
+ var mode = *(DisplayMode*)SDL_GetWindowFullscreenMode(window);
if (mode.DisplayId == 0) {
LogError(LogCategory.Error, "GetWindowFullScreenMode: Failed to retrieve window fullscreen mode.");
}
@@ -3112,7 +2422,7 @@ public static nint GetWindowIccProfile(nint window, out nuint size) {
size = 0;
return nint.Zero;
}
- nint profile = SDL_GetWindowICCProfile(window, out size);
+ var profile = SDL_GetWindowICCProfile(window, out size);
if (profile == nint.Zero) {
LogError(LogCategory.Error, "GetWindowICCProfile: Failed to retrieve window ICC profile.");
}
@@ -3136,7 +2446,7 @@ public static uint GetWindowId(nint window) {
return 0;
}
- uint windowId = SDL_GetWindowID(window);
+ var windowId = SDL_GetWindowID(window);
if (windowId == 0) {
LogWarn(LogCategory.System, "GetWindowId: Failed to retrieve window ID.");
}
@@ -3202,7 +2512,7 @@ public static Rect GetWindowMaximumSize(nint window) {
return default;
}
- bool result = SDL_GetWindowMaximumSize(window, out int w, out int h);
+ bool result = SDL_GetWindowMaximumSize(window, out var w, out var h);
if (!result) {
LogError(LogCategory.Error, "GetWindowMaximumSize: Failed to retrieve window maximum size.");
return default;
@@ -3247,7 +2557,7 @@ public static Rect GetWindowMinimumSize(nint window) {
if (window == nint.Zero) {
return default;
}
- bool result = SDL_GetWindowMinimumSize(window, out int w, out int h);
+ bool result = SDL_GetWindowMinimumSize(window, out var w, out var h);
if (!result) {
LogError(LogCategory.Error, "GetWindowMinimumSize: Failed to retrieve window minimum size.");
return default;
@@ -3295,7 +2605,7 @@ public static nint GetWindowMouseRectPtr(nint window) {
LogError(LogCategory.Error, "GetWindowMouseRect: Window pointer is null.");
return nint.Zero;
}
- nint rect = SDL_GetWindowMouseRect(window);
+ var rect = SDL_GetWindowMouseRect(window);
if (rect == nint.Zero) {
LogError(LogCategory.Error, "GetWindowMouseRect: Failed to retrieve window mouse rect.");
}
@@ -3313,13 +2623,13 @@ public static nint GetWindowMouseRectPtr(nint window) {
///
/// (const *) Returns a pointer to the mouse confinement rectangle of a window, or if there isn't one.
public static unsafe Rect GetWindowMouseRect(nint window) {
- nint result = GetWindowMouseRectPtr(window);
+ var result = GetWindowMouseRectPtr(window);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetWindowMouseRect: Failed to retrieve window mouse rect.");
- return new();
+ return new Rect();
}
- Rect rect = *(Rect*)result;
+ var rect = *(Rect*)result;
return rect;
}
@@ -3338,7 +2648,7 @@ public static float GetWindowOpacity(nint window) {
LogError(LogCategory.Error, "GetWindowOpacity: Window pointer is null.");
return 0;
}
- float opacity = SDL_GetWindowOpacity(window);
+ var opacity = SDL_GetWindowOpacity(window);
if (opacity < 0) {
LogError(LogCategory.Error, "GetWindowOpacity: Failed to retrieve window opacity.");
}
@@ -3358,7 +2668,7 @@ public static nint GetWindowParent(nint window) {
LogError(LogCategory.Error, "GetWindowParent: Window handle is null.");
return nint.Zero;
}
- nint parentHandle = SDL_GetWindowParent(window);
+ var parentHandle = SDL_GetWindowParent(window);
if (parentHandle == nint.Zero) {
LogWarn(LogCategory.System, "GetWindowParent: Failed to retrieve parent window handle.");
}
@@ -3381,7 +2691,7 @@ public static float GetWindowPixelDensity(nint window) {
LogError(LogCategory.Error, "GetWindowPixelDensity: Window pointer is null.");
return 0;
}
- float pixelDensity = SDL_GetWindowPixelDensity(window);
+ var pixelDensity = SDL_GetWindowPixelDensity(window);
if (pixelDensity < 0) {
LogError(LogCategory.Error, "GetWindowPixelDensity: Failed to retrieve window pixel density.");
}
@@ -3400,7 +2710,7 @@ public static PixelFormat GetWindowPixelFormat(nint window) {
LogError(LogCategory.Error, "GetWindowPixelFormat: Window pointer is null.");
return PixelFormat.Unknown;
}
- PixelFormat pixelFormat = SDL_GetWindowPixelFormat(window);
+ var pixelFormat = SDL_GetWindowPixelFormat(window);
if (pixelFormat == PixelFormat.Unknown) {
LogError(LogCategory.Error, "GetWindowPixelFormat: Failed to retrieve window pixel format.");
}
@@ -3445,7 +2755,7 @@ public static Point GetWindowPosition(nint window) {
if (window == nint.Zero) {
return default;
}
- bool result = SDL_GetWindowPosition(window, out int x, out int y);
+ bool result = SDL_GetWindowPosition(window, out var x, out var y);
if (!result) {
LogError(LogCategory.Error, "GetWindowPosition: Failed to retrieve window position.");
return default;
@@ -3466,7 +2776,7 @@ public static uint GetWindowProperties(nint window) {
LogError(LogCategory.Error, "GetWindowProperties: Window handle is null.");
return 0;
}
- uint properties = SDL_GetWindowProperties(window);
+ var properties = SDL_GetWindowProperties(window);
if (properties == 0) {
LogWarn(LogCategory.System, "GetWindowProperties: Failed to retrieve window properties.");
}
@@ -3481,7 +2791,7 @@ public static uint GetWindowProperties(nint window) {
///
/// (SDL_Window **) Returns a terminated array of SDL_Window pointers or on failure; call for more information. This is a single allocation that should be freed with when it is nol onger needed.
public static Span GetWindows(out int count) {
- nint result = SDL_GetWindows(out count);
+ var result = SDL_GetWindows(out count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "GetWindows: Failed to retrieve windows.");
@@ -3489,14 +2799,14 @@ public static Span GetWindows(out int count) {
return [];
}
- nint[] windows = new nint[count];
+ var windows = new nint[count];
if (windows == null) {
LogError(LogCategory.Error, "GetWindows: Failed to create array for windows.");
count = 0;
return [];
}
- Span windowSpan = new(windows);
+ Span windowSpan = new Span(windows);
return windowSpan.ToArray();
}
@@ -3555,7 +2865,7 @@ public static Rect GetWindowSafeArea(nint window) {
if (window == nint.Zero) {
return default;
}
- bool result = SDL_GetWindowSafeArea(window, out Rect rect);
+ bool result = SDL_GetWindowSafeArea(window, out var rect);
if (!result) {
LogError(LogCategory.Error, "GetWindowSafeArea: Failed to retrieve window safe area.");
return default;
@@ -3606,7 +2916,7 @@ public static Rect GetWindowSize(nint window) {
if (window == nint.Zero) {
return default;
}
- bool result = SDL_GetWindowSize(window, out int w, out int h);
+ bool result = SDL_GetWindowSize(window, out var w, out var h);
if (!result) {
LogError(LogCategory.Error, "GetWindowSize: Failed to retrieve window size.");
return default;
@@ -3651,7 +2961,7 @@ public static Rect GetWindowSizeInPixels(nint window) {
if (window == nint.Zero) {
return default;
}
- bool result = SDL_GetWindowSizeInPixels(window, out int w, out int h);
+ bool result = SDL_GetWindowSizeInPixels(window, out var w, out var h);
if (!result) {
LogError(LogCategory.Error, "GetWindowSizeInPixels: Failed to retrieve window size in pixels.");
return default;
@@ -3681,7 +2991,7 @@ public static nint GetWindowSurface(nint window) {
LogError(LogCategory.Error, "GetWindowSurface: Window pointer is null.");
return nint.Zero;
}
- nint surface = SDL_GetWindowSurface(window);
+ var surface = SDL_GetWindowSurface(window);
if (surface == nint.Zero) {
LogError(LogCategory.Error, "GetWindowSurface: Failed to retrieve window surface.");
}
@@ -3722,7 +3032,7 @@ public static int GetWindowSurfaceVSync(nint window) {
if (window == nint.Zero) {
return 0;
}
- bool result = SDL_GetWindowSurfaceVSync(window, out int vsync);
+ bool result = SDL_GetWindowSurfaceVSync(window, out var vsync);
if (!result) {
LogError(LogCategory.Error, "GetWindowSurfaceVSync: Failed to retrieve window surface VSync.");
return 0;
@@ -3743,7 +3053,7 @@ public static string GetWindowTitle(nint window) {
LogError(LogCategory.Error, "GetWindowTitle: Window handle is null.");
return string.Empty;
}
- string title = SDL_GetWindowTitle(window);
+ var title = SDL_GetWindowTitle(window);
if (string.IsNullOrEmpty(title)) {
LogWarn(LogCategory.System, "GetWindowTitle: Failed to retrieve window title.");
}
@@ -4027,7 +3337,7 @@ public static nint LoadBmp(string file) {
LogError(LogCategory.Error, "LoadBmp: File path is null or empty.");
return nint.Zero;
}
- nint surface = SDL_LoadBMP(file);
+ var surface = SDL_LoadBMP(file);
if (surface == nint.Zero) {
LogError(LogCategory.Error, "LoadBmp: Failed to load BMP file.");
}
@@ -4053,7 +3363,7 @@ public static nint LoadBmpIo(nint src, bool closeIo) {
LogError(LogCategory.Error, "LoadBmpIo: Source pointer is null.");
return nint.Zero;
}
- nint surface = SDL_LoadBMP_IO(src, closeIo);
+ var surface = SDL_LoadBMP_IO(src, closeIo);
if (surface == nint.Zero) {
LogError(LogCategory.Error, "LoadBmpIo: Failed to load BMP from IO source.");
}
@@ -4079,7 +3389,7 @@ public static nint LoadFunction(nint handle, string name) {
LogError(LogCategory.Error, "LoadFunction: Function name is null or empty.");
return nint.Zero;
}
- nint function = SDL_LoadFunction(handle, name);
+ var function = SDL_LoadFunction(handle, name);
if (function == nint.Zero) {
LogError(LogCategory.Error, "LoadFunction: Failed to load function.");
}
@@ -4100,7 +3410,7 @@ public static nint LoadObject(string sofile) {
LogError(LogCategory.Error, "LoadObject: Shared object file path is null or empty.");
return nint.Zero;
}
- nint handle = SDL_LoadObject(sofile);
+ var handle = SDL_LoadObject(sofile);
if (handle == nint.Zero) {
LogError(LogCategory.Error, "LoadObject: Failed to load shared object.");
}
@@ -4130,31 +3440,6 @@ public static bool LockProperties(uint props) {
return result;
}
- /// Set up a surface for directly accessing the pixels.
- /// the structure to be locked.
- ///
- /// Between calls to /
- /// , you can write to and read from
- /// surface->pixels, using the pixel format stored in surface->format. Once
- /// you are done accessing the surface, you should use
- /// to release it.
- /// Thread Safety: This function is not thread safe. The locking referred to by this function is making the pixels available for direct access, not thread-safe locking.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool LockSurface(nint surface) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "LockSurface: Surface pointer is null.");
- return false;
- }
- bool result = SDL_LockSurface(surface);
- if (!result) {
- LogError(LogCategory.Error, "LockSurface: Failed to lock surface.");
- }
- return result;
- }
/// Allocate uninitialized memory.
/// the size to allocate.
@@ -4174,7 +3459,7 @@ public static nint Malloc(nuint size) {
return nint.Zero;
}
- nint res = SDL_malloc(size);
+ var res = SDL_malloc(size);
if (res == nint.Zero) {
LogError(LogCategory.Error, "Malloc: Memory allocation failed.");
SDL_OutOfMemory();
@@ -4184,169 +3469,9 @@ public static nint Malloc(nuint size) {
return res;
}
- /// Map an RGB triple to an opaque pixel value for a given pixel format.
- /// a pointer to Details describing the pixel format.
- /// an optional palette for indexed formats, may be discarded.
- /// the red component of the pixel in the range 0-255.
- /// the green component of the pixel in the range 0-255.
- /// the blue component of the pixel in the range 0-255.
- ///
- /// This function maps the RGB color value to the specified pixel format and
- /// returns the pixel value best approximating the given RGB color value for
- /// the given pixel format.
- /// Thread Safety: It is safe to call this function from any thread, as long as the palette is not modified.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- ///
- ///
- /// Returns a pixel value.
- public static uint MapRgb(nint format, nint palette, byte r, byte g, byte b) {
- if (format == nint.Zero || palette == nint.Zero) {
- LogError(LogCategory.Error, "MapRgb: Format or palette pointer is null.");
- return 0;
- }
- uint color = SDL_MapRGB(format, palette, r, g, b);
- if (color == 0) {
- LogError(LogCategory.Error, "MapRgb: Failed to map RGB color.");
- }
- return color;
- }
-
- /// Map an RGBA quadruple to a pixel value for a given pixel format.
- /// a pointer to Details describing the pixel format.
- /// an optional palette for indexed formats, may be discarded.
- /// the red component of the pixel in the range 0-255.
- /// the green component of the pixel in the range 0-255.
- /// the blue component of the pixel in the range 0-255.
- /// the alpha component of the pixel in the range 0-255.
- ///
- /// This function maps the RGBA color value to the specified pixel format and
- /// returns the pixel value best approximating the given RGBA color value for
- /// the given pixel format.
- /// Thread Safety: It is safe to call this function from any thread, as long as the palette is not modified.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- ///
- ///
- /// Returns a pixel value.
- public static uint MapRgba(nint format, nint palette, byte r, byte g, byte b, byte a) {
- if (format == nint.Zero || palette == nint.Zero) {
- LogError(LogCategory.Error, "MapRgba: Format or palette pointer is null.");
- return 0;
- }
- uint color = SDL_MapRGBA(format, palette, r, g, b, a);
- if (color == 0) {
- LogError(LogCategory.Error, "MapRgba: Failed to map RGBA color.");
- }
- return color;
- }
-
- /// Map an RGB triple to an opaque pixel value for a surface.
- /// the surface to use for the pixel format and palette.
- /// the red component of the pixel in the range 0-255.
- /// the green component of the pixel in the range 0-255.
- /// the blue component of the pixel in the range 0-255.
- ///
- /// This function maps the RGB color value to the specified pixel format and
- /// returns the pixel value best approximating the given RGB color value for
- /// the given pixel format.
- /// Thread Safety: It is safe to call this function from any thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns a pixel value.
- public static uint MapSurfaceRgb(nint surface, byte r, byte g, byte b) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "MapSurfaceRgb: Surface pointer is null.");
- return 0;
- }
- uint color = SDL_MapSurfaceRGB(surface, r, g, b);
- if (color == 0) {
- LogError(LogCategory.Error, "MapSurfaceRgb: Failed to map surface RGB color.");
- }
- return color;
- }
-
- /// Map an RGB triple to an opaque pixel value for a surface.
- /// the surface to use for the pixel format and palette.
- /// the representing RGB ranging from 0-255.
- ///
- /// This function maps the RGB color value to the specified pixel format and
- /// returns the pixel value best approximating the given RGB color value for
- /// the given pixel format.
- /// Thread Safety: It is safe to call this function from any thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns a pixel value.
- public static uint MapSurfaceRgb(nint surface, Color color) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "MapSurfaceRgb: Surface pointer is null.");
- return 0;
- }
-
- uint colorValue = SDL_MapSurfaceRGB(surface, color.R, color.G, color.B);
- if (colorValue == 0) {
- LogError(LogCategory.Error, "MapSurfaceRgb: Failed to map surface RGB color.");
- }
- return colorValue;
- }
-
- /// Map an RGBA quadruple to a pixel value for a surface.
- /// the surface to use for the pixel format and palette.
- /// the red component of the pixel in the range 0-255.
- /// the green component of the pixel in the range 0-255.
- /// the blue component of the pixel in the range 0-255.
- /// the alpha component of the pixel in the range 0-255.
- ///
- /// This function maps the RGBA color value to the specified pixel format and
- /// returns the pixel value best approximating the given RGBA color value for
- /// the given pixel format.
- /// Thread Safety: It is safe to call this function from any thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns a pixel value.
- public static uint MapSurfaceRgba(nint surface, byte r, byte g, byte b, byte a) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "MapSurfaceRgba: Surface pointer is null.");
- return 0;
- }
- uint color = SDL_MapSurfaceRGBA(surface, r, g, b, a);
- if (color == 0) {
- LogError(LogCategory.Error, "MapSurfaceRgba: Failed to map surface RGBA color.");
- }
- return color;
- }
-
- /// Map an RGBA quadruple to a pixel value for a surface.
- /// the surface to use for the pixel format and palette.
- /// the representing RGB ranging from 0-255.
- ///
- /// This function maps the RGBA color value to the specified pixel format and
- /// returns the pixel value best approximating the given RGBA color value for
- /// the given pixel format.
- /// Thread Safety: It is safe to call this function from any thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns a pixel value.
- public static uint MapSurfaceRgba(nint surface, Color color) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "MapSurfaceRgba: Surface pointer is null.");
- return 0;
- }
- uint colorValue = SDL_MapSurfaceRGBA(surface, color.R, color.G, color.B, color.A);
- if (colorValue == 0) {
- LogError(LogCategory.Error, "MapSurfaceRgba: Failed to map surface RGBA color.");
- }
- return colorValue;
- }
+
+
/// Request that the window be made as large as possible.
/// the window to maximize.
///
@@ -4524,165 +3649,6 @@ public static bool RaiseWindow(nint window) {
return result;
}
- /// Retrieves a single pixel from a surface.
- /// the surface to read.
- /// the horizontal coordinate, 0 <= x < width.
- /// the vertical coordinate, 0 <= y < height.
- /// a pointer filled in with the red channel, 0-255, or discard to ignore this channel.
- /// a pointer filled in with the green channel, 0-255, or discard to ignore this channel.
- /// a pointer filled in with the blue channel, 0-255, or discard to ignore this channel.
- /// a pointer filled in with the alpha channel, 0-255, or discard to ignore this channel.
- ///
- /// This function prioritizes correctness over speed: it is suitable for unit
- /// tests, but is not intended for use in a game engine.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static bool ReadSurfacePixel(nint surface, int x, int y, out byte r, out byte g, out byte b, out byte a) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "ReadSurfacePixel: Surface pointer is null.");
- r = g = b = a = 0;
- return false;
- }
- bool result = SDL_ReadSurfacePixel(surface, x, y, out r, out g, out b, out a);
- if (!result) {
- LogError(LogCategory.Error, "ReadSurfacePixel: Failed to read surface pixel.");
- }
- return result;
- }
-
- /// Retrieves a single pixel from a surface.
- /// the surface to read.
- /// the horizontal coordinate, 0 <= x < width.
- /// the vertical coordinate, 0 <= y < height.
- ///
- /// This function prioritizes correctness over speed: it is suitable for unit
- /// tests, but is not intended for use in a game engine.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static bool ReadSurfacePixel(nint surface, int x, int y, out Color color) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "ReadSurfacePixel: Surface pointer is null.");
- color = default;
- return false;
- }
- bool result = SDL_ReadSurfacePixel(surface, x, y, out byte r, out byte g, out byte b, out byte a);
- if (!result) {
- LogError(LogCategory.Error, "ReadSurfacePixel: Failed to read surface pixel.");
- color = default;
- return false;
- }
- color = new Color() { R = r, G = g, B = b, A = a };
- return true;
- }
-
- /// Retrieves a single pixel from a surface.
- /// the surface to read.
- /// the horizontal coordinate, 0 <= x < width.
- /// the vertical coordinate, 0 <= y < height.
- ///
- /// This function prioritizes correctness over speed: it is suitable for unit
- /// tests, but is not intended for use in a game engine.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static Color ReadSurfacePixel(nint surface, int x, int y) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "ReadSurfacePixel: Surface pointer is null.");
- return default;
- }
- bool result = SDL_ReadSurfacePixel(surface, x, y, out byte r, out byte g, out byte b, out byte a);
- if (!result) {
- LogError(LogCategory.Error, "ReadSurfacePixel: Failed to read surface pixel.");
- return default;
- }
- return new Color() { R = r, G = g, B = b, A = a };
- }
-
- /// Retrieves a single pixel from a surface.
- /// the surface to read.
- /// the horizontal coordinate, 0 <= x < width.
- /// the vertical coordinate, 0 <= y < height.
- /// a pointer filled in with the red channel, normally in the range 0-1, or discard to ignore this channel.
- /// a pointer filled in with the green channel, normally in the range 0-1, or discard to ignore this channel.
- /// a pointer filled in with the blue channel, normally in the range 0-1, or discard to ignore this channel.
- /// a pointer filled in with the alpha channel, normally in the range 0-1, or discard to ignore this channel.
- ///
- /// This function prioritizes correctness over speed: it is suitable for unit
- /// tests, but is not intended for use in a game engine.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static bool ReadSurfacePixelFloat(nint surface, int x, int y, out float r, out float g, out float b, out float a) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "ReadSurfacePixelFloat: Surface pointer is null.");
- r = g = b = a = 0;
- return false;
- }
- bool result = SDL_ReadSurfacePixelFloat(surface, x, y, out r, out g, out b, out a);
- if (!result) {
- LogError(LogCategory.Error, "ReadSurfacePixelFloat: Failed to read surface pixel.");
- }
- return result;
- }
-
- /// Retrieves a single pixel from a surface.
- /// the surface to read.
- /// the horizontal coordinate, 0 <= x < width.
- /// the vertical coordinate, 0 <= y < height.
- /// the structure filled with color data, or discard to ignore.
- ///
- /// This function prioritizes correctness over speed: it is suitable for unit
- /// tests, but is not intended for use in a game engine.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static bool ReadSurfacePixelFloat(nint surface, int x, int y, out FColor color) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "ReadSurfacePixelFloat: Surface pointer is null.");
- color = default;
- return false;
- }
- bool result = SDL_ReadSurfacePixelFloat(surface, x, y, out float r, out float g, out float b, out float a);
- if (!result) {
- LogError(LogCategory.Error, "ReadSurfacePixelFloat: Failed to read surface pixel.");
- color = default;
- return false;
- }
- color = new FColor() { R = r, G = g, B = b, A = a };
- return true;
- }
-
- /// Retrieves a single pixel from a surface.
- /// the surface to read.
- /// the horizontal coordinate, 0 <= x < width.
- /// the vertical coordinate, 0 <= y < height.
- ///
- /// This function prioritizes correctness over speed: it is suitable for unit
- /// tests, but is not intended for use in a game engine.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static FColor ReadSurfacePixelFloat(nint surface, int x, int y) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "ReadSurfacePixelFloat: Surface pointer is null.");
- return default;
- }
- bool result = SDL_ReadSurfacePixelFloat(surface, x, y, out float r, out float g, out float b, out float a);
- if (!result) {
- LogError(LogCategory.Error, "ReadSurfacePixelFloat: Failed to read surface pixel.");
- return default;
- }
- return new FColor() { R = r, G = g, B = b, A = a };
- }
-
/// Remove a function watching a particular hint.
/// the hint being watched.
/// an function that will be called when the hint value changes.
@@ -4810,7 +3776,7 @@ public static int RunApp(int argc, nint argv, SdlMainFunc mainFunction, nint res
SetMainReady();
- int result = SDL_RunApp(argc, argv, mainFunction, reserved);
+ var result = SDL_RunApp(argc, argv, mainFunction, reserved);
LogDebug(LogCategory.System, $"RunApp completed with result: {result}");
@@ -4905,61 +3871,7 @@ public static bool SaveBmpIo(nint surface, nint dst, bool closeIo) {
return result;
}
- /// Creates a new surface identical to the existing surface, scaled to the desired size.
- /// the surface to duplicate and scale.
- /// the width of the new surface.
- /// the height of the new surface.
- /// the to be used.
- ///
- /// The returned surface should be freed with
- /// .
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// (SDL_Surface *) Returns a copy of the surface or on failure; call for more information.
- public static nint ScaleSurface(nint surface, int width, int height, ScaleMode scaleMode) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "ScaleSurface: Surface pointer is null.");
- return nint.Zero;
- }
-
- if (!Enum.IsDefined(scaleMode)) {
- LogError(LogCategory.Error, "ScaleSurface: Invalid scale mode.");
- return nint.Zero;
- }
-
- if (width <= 0 || height <= 0) {
- LogError(LogCategory.Error, "ScaleSurface: Invalid width or height.");
- return nint.Zero;
- }
-
- // System.EngineExecutionException thrown here, why?
- nint scaledSurface = SDL_ScaleSurface(surface, width, height, (int)scaleMode);
- if (scaledSurface == nint.Zero) {
- LogError(LogCategory.Error, $"ScaleSurface: Failed to scale surface. {Sdl.GetError()}");
- }
- return scaledSurface;
- }
-
- /// Creates a new surface identical to the existing surface, scaled to the desired size.
- /// the surface to duplicate and scale.
- /// the width of the new surface.
- /// the height of the new surface.
- /// the to be used.
- ///
- /// The returned surface should be freed with .
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// (SDL_Surface *) Returns a copy of the surface or on failure; call for more information.
- public static Surface ScaleSurface(ref Surface surface, int width, int height, ScaleMode scaleMode) {
- nint oSurface = StructureToPointer(ref surface);
- nint newSurface = ScaleSurface(oSurface, width, height, scaleMode);
- var rSurface = PointerToStructure(newSurface);
- return rSurface;
- }
+
/// Check whether the screen keyboard is shown for given window.
/// the window for which screen keyboard should be queried.
@@ -5158,7 +4070,7 @@ public static bool SetError(string fmt, params object[] args) {
return false;
}
- string formatted = args.Length > 0 ? string.Format(fmt, args) : fmt;
+ var formatted = args.Length > 0 ? string.Format(fmt, args) : fmt;
return SDL_SetError(formatted);
}
@@ -5434,232 +4346,6 @@ public static bool SetStringProperty(uint props, string name, string value) {
return result;
}
- /// Set an additional alpha value used in blit operations.
- /// the structure to update.
- /// the alpha value multiplied into blit operations.
- ///
- /// When this surface is blitted, during the blit operation the source alpha
- /// value is modulated by this alpha value according to the following formula:
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool SetSurfaceAlphaMod(nint surface, byte alpha) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "SetSurfaceAlphaMod: Surface pointer is null.");
- return false;
- }
- bool result = SDL_SetSurfaceAlphaMod(surface, alpha);
- if (!result) {
- LogError(LogCategory.Error, "SetSurfaceAlphaMod: Failed to set surface alpha mod.");
- }
- return result;
- }
-
- /// Set the blend mode used for blit operations.
- /// the structure to update.
- /// the to use for blit blending.
- ///
- /// To copy a surface to another surface (or texture) without blending with the
- /// existing data, the blendmode of the SOURCE surface should be set to
- /// SDL_BLENDMODE_NONE.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool SetSurfaceBlendMode(nint surface, uint blendMode) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "SetSurfaceBlendMode: Surface pointer is null.");
- return false;
- }
- bool result = SDL_SetSurfaceBlendMode(surface, blendMode);
- if (!result) {
- LogError(LogCategory.Error, "SetSurfaceBlendMode: Failed to set surface blend mode.");
- }
- return result;
- }
-
- /// Set the clipping rectangle for a surface.
- /// the structure to be clipped.
- /// the structure representing the clipping rectangle, or to disable clipping.
- ///
- /// When surface is the destination of a blit, only the area within the clip
- /// rectangle is drawn into.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns if the rectangle intersects the surface, otherwise and blits will be completely clipped.
- public static bool SetSurfaceClipRect(nint surface, ref Rect rect) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "SetSurfaceClipRect: Surface pointer is null.");
- return false;
- }
- bool result = SDL_SetSurfaceClipRect(surface, ref rect);
- if (!result) {
- LogError(LogCategory.Error, "SetSurfaceClipRect: Failed to set surface clip rect.");
- }
- return result;
- }
-
- /// Set the color key (transparent pixel) in a surface.
- /// the structure to update.
- /// to enable color key, to disable color key.
- /// the transparent pixel.
- ///
- /// The color key defines a pixel value that will be treated as transparent in
- /// a blit. For example, one can use this to specify that cyan pixels should be
- /// considered transparent, and therefore not rendered.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool SetSurfaceColorKey(nint surface, bool enabled, uint key) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "SetSurfaceColorKey: Surface pointer is null.");
- return false;
- }
- bool result = SDL_SetSurfaceColorKey(surface, enabled, key);
- if (!result) {
- LogError(LogCategory.Error, "SetSurfaceColorKey: Failed to set surface color key.");
- }
- return result;
- }
-
- /// Set an additional color value multiplied into blit operations.
- /// the structure to update.
- /// the red color value multiplied into blit operations.
- /// the green color value multiplied into blit operations.
- /// the blue color value multiplied into blit operations.
- ///
- /// When this surface is blitted, during the blit operation each source color
- /// channel is modulated by the appropriate color value according to the
- /// following formula:
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool SetSurfaceColorMod(nint surface, byte r, byte g, byte b) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "SetSurfaceColorMod: Surface pointer is null.");
- return false;
- }
- bool result = SDL_SetSurfaceColorMod(surface, r, g, b);
- if (!result) {
- LogError(LogCategory.Error, "SetSurfaceColorMod: Failed to set surface color mod.");
- }
- return result;
- }
-
- /// Set an additional color value multiplied into blit operations.
- /// the structure to update.
- /// the red color value multiplied into blit operations.
- /// the green color value multiplied into blit operations.
- /// the blue color value multiplied into blit operations.
- ///
- /// When this surface is blitted, during the blit operation each source color
- /// channel is modulated by the appropriate color value according to the
- /// following formula:
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool SetSurfaceColorMod(nint surface, Color color) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "SetSurfaceColorMod: Surface pointer is null.");
- return false;
- }
- bool result = SDL_SetSurfaceColorMod(surface, color.R, color.G, color.B);
- if (!result) {
- LogError(LogCategory.Error, "SetSurfaceColorMod: Failed to set surface color mod.");
- }
- return result;
- }
-
- /// Set the colorspace used by a surface.
- /// the structure to update.
- /// an value describing the surface colorspace.
- ///
- /// Setting the colorspace doesn't change the pixels, only how they are
- /// interpreted in color operations.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool SetSurfaceColorspace(nint surface, Colorspace colorspace) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "SetSurfaceColorspace: Surface pointer is null.");
- return false;
- }
- bool result = SDL_SetSurfaceColorspace(surface, colorspace);
- if (!result) {
- LogError(LogCategory.Error, "SetSurfaceColorspace: Failed to set surface colorspace.");
- }
- return result;
- }
-
- /// Set the palette used by a surface.
- /// the structure to update.
- /// the SDL_Palette structure to use.
- ///
- /// A single palette can be shared with many surfaces.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool SetSurfacePalette(nint surface, nint palette) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "SetSurfacePalette: Surface pointer is null.");
- return false;
- }
- if (palette == nint.Zero) {
- LogError(LogCategory.Error, "SetSurfacePalette: Palette pointer is null.");
- return false;
- }
- bool result = SDL_SetSurfacePalette(surface, palette);
- if (!result) {
- LogError(LogCategory.Error, "SetSurfacePalette: Failed to set surface palette.");
- }
- return result;
- }
-
- /// Set the RLE acceleration hint for a surface.
- /// the structure to optimize.
- /// to enable RLE acceleration, to disable it.
- ///
- /// If RLE is enabled, color key and alpha blending blits are much faster, but
- /// the surface must be locked before directly accessing the pixels.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- ///
- /// Returns on success or on failure; call for more information.
- public static bool SetSurfaceRle(nint surface, bool enabled) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "SetSurfaceRLE: Surface pointer is null.");
- return false;
- }
- bool result = SDL_SetSurfaceRLE(surface, enabled);
- if (!result) {
- LogError(LogCategory.Error, "SetSurfaceRLE: Failed to set surface RLE.");
- }
- return result;
- }
/// Set the area used to type Unicode text input.
/// the window for which to set the text input area.
@@ -6484,77 +5170,13 @@ public static SdlGuid StringToGuid(string pchGuid) {
LogError(LogCategory.Error, "StringToGUID: GUID string is null or empty.");
return default;
}
- SdlGuid result = SDL_StringToGUID(pchGuid);
+ var result = SDL_StringToGUID(pchGuid);
if (result.Data == null) {
LogError(LogCategory.Error, "StringToGUID: Failed to convert string to GUID.");
}
return result;
}
- /// Return whether a surface has alternate versions available.
- /// the structure to query.
- ///
- /// Thread Safety: It is safe to call this function from any thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- ///
- /// Returns if alternate versions are available or otherwise.
- public static bool SurfaceHasAlternateImages(nint surface) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "SurfaceHasAlternateImages: Surface pointer is null.");
- return false;
- }
- bool result = SDL_SurfaceHasAlternateImages(surface);
- if (!result) {
- LogError(LogCategory.Error, "SurfaceHasAlternateImages: Failed to check surface alternate images.");
- }
- return result;
- }
-
- /// Returns whether the surface has a color key.
- /// the structure to query.
- ///
- /// It is safe to pass a surface here; it will return false.
- /// Thread Safety: It is safe to call this function from any thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- ///
- /// Returns if the surface has a color key, otherwise.
- public static bool SurfaceHasColorKey(nint surface) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "SurfaceHasColorKey: Surface pointer is null.");
- return false;
- }
- bool result = SDL_SurfaceHasColorKey(surface);
- if (!result) {
- LogError(LogCategory.Error, "SurfaceHasColorKey: Failed to check surface color key.");
- }
- return result;
- }
-
- /// Returns whether the surface is RLE enabled.
- /// the structure to query.
- ///
- /// It is safe to pass a surface here; it will return false.
- /// Thread Safety: It is safe to call this function from any thread.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- /// Returns if the surface is RLE enabled, otherwise.
- public static bool SurfaceHasRle(nint surface) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "SurfaceHasRLE: Surface pointer is null.");
- return false;
- }
- bool result = SDL_SurfaceHasRLE(surface);
- if (!result) {
- LogError(LogCategory.Error, "SurfaceHasRLE: Failed to check surface RLE.");
- }
- return result;
- }
/// Block until any pending window state is finalized.
/// the window for which to wait for the pending state to be applied.
@@ -6640,21 +5262,6 @@ public static void UnlockProperties(uint props) {
SDL_UnlockProperties(props);
}
- /// Release a surface after directly accessing the pixels.
- /// the structure to be unlocked.
- ///
- /// Thread Safety: This function is not thread safe. The locking referred to by this functionis making the pixels available for direct access, not thread-safe locking.
- /// Version: This function is available since SDL 3.2.0.
- ///
- ///
- public static void UnlockSurface(nint surface) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "UnlockSurface: Surface pointer is null.");
- return;
- }
- SDL_UnlockSurface(surface);
- }
-
/// Copy the window surface to the screen.
/// the window to update.
///
@@ -6772,7 +5379,7 @@ public static InitFlags WasInit(InitFlags flags) {
LogError(LogCategory.Error, "WasInit: Flags are zero.");
return 0;
}
- InitFlags result = SDL_WasInit(flags);
+ var result = SDL_WasInit(flags);
if (result == 0) {
LogError(LogCategory.Error, "WasInit: Failed to check SDL initialization.");
}
@@ -6799,166 +5406,6 @@ public static bool WindowHasSurface(nint window) {
return result;
}
- /// Writes a single pixel to a surface.
- /// the surface to write.
- /// the horizontal coordinate, 0 <= x < width.
- /// the vertical coordinate, 0 <= y < height.
- /// the red channel value, 0-255.
- /// the green channel value, 0-255.
- /// the blue channel value, 0-255.
- /// the alpha channel value, 0-255.
- ///
- /// This function prioritizes correctness over speed: it is suitable for unit
- /// tests, but is not intended for use in a game engine.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static bool WriteSurfacePixel(nint surface, int x, int y, byte r, byte g, byte b, byte a) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "WriteSurfacePixel: Surface pointer is null.");
- return false;
- }
- bool result = SDL_WriteSurfacePixel(surface, x, y, r, g, b, a);
- if (!result) {
- LogError(LogCategory.Error, "WriteSurfacePixel: Failed to write surface pixel.");
- }
- return result;
- }
-
- /// Writes a single pixel to a surface.
- /// the surface to write.
- /// the horizontal coordinate, 0 <= x < width.
- /// the vertical coordinate, 0 <= y < height.
- /// the struct filled with data
- ///
- /// This function prioritizes correctness over speed: it is suitable for unit
- /// tests, but is not intended for use in a game engine.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static bool WriteSurfacePixel(nint surface, int x, int y, Color color) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "WriteSurfacePixel: Surface pointer is null.");
- return false;
- }
- bool result = SDL_WriteSurfacePixel(surface, x, y, color.R, color.G, color.B, color.A);
- if (!result) {
- LogError(LogCategory.Error, "WriteSurfacePixel: Failed to write surface pixel.");
- }
- return result;
- }
-
- /// Writes a single pixel to a surface.
- /// the surface to write.
- /// the struct that provides xy coordinates
- /// the struct filled with data
- ///
- /// This function prioritizes correctness over speed: it is suitable for unit
- /// tests, but is not intended for use in a game engine.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static bool WriteSurfacePixel(nint surface, Point location, Color color) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "WriteSurfacePixel: Surface pointer is null.");
- return false;
- }
- return WriteSurfacePixel(surface, location.X, location.Y, color.R, color.G, color.B, color.A);
- }
-
- /// Writes a single pixel to a surface.
- /// the surface to write.
- /// the struct that provides xy coordinates
- /// the red channel value, 0-255.
- /// the green channel value, 0-255.
- /// the blue channel value, 0-255.
- /// the alpha channel value, 0-255.
- ///
- /// This function prioritizes correctness over speed: it is suitable for unit
- /// tests, but is not intended for use in a game engine.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static bool WriteSurfacePixel(nint surface, Point location, byte r, byte g, byte b, byte a) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "WriteSurfacePixel: Surface pointer is null.");
- return false;
- }
- return WriteSurfacePixel(surface, location.X, location.Y, r, g, b, a);
- }
-
- /// Writes a single pixel to a surface.
- /// the surface to write.
- /// the horizontal coordinate, 0 <= x < width.
- /// the vertical coordinate, 0 <= y < height.
- /// the red channel value, normally in the range 0-1.
- /// the green channel value, normally in the range 0-1.
- /// the blue channel value, normally in the range 0-1.
- /// the alpha channel value, normally in the range 0-1.
- ///
- /// This function prioritizes correctness over speed: it is suitable for unit
- /// tests, but is not intended for use in a game engine.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static bool WriteSurfacePixelFloat(nint surface, int x, int y, float r, float g, float b, float a) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "WriteSurfacePixelFloat: Surface pointer is null.");
- return false;
- }
- bool result = SDL_WriteSurfacePixelFloat(surface, x, y, r, g, b, a);
- if (!result) {
- LogError(LogCategory.Error, "WriteSurfacePixelFloat: Failed to write surface pixel float.");
- }
- return result;
- }
-
- /// Writes a single pixel to a surface.
- /// the surface to write.
- /// the struct that provides xy coordinates
- /// the struct filled with data
- ///
- /// This function prioritizes correctness over speed: it is suitable for unit
- /// tests, but is not intended for use in a game engine.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static bool WriteSurfacePixelFloat(nint surface, Point location, FColor color) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "WriteSurfacePixelFloat: Window pointer is null.");
- return false;
- }
- return WriteSurfacePixelFloat(surface, location.X, location.Y, color.R, color.G, color.B,
- color.A);
- }
-
- /// Writes a single pixel to a surface.
- /// the surface to write.
- /// the struct that provides xy coordinates
- /// the red channel value, normally in the range 0-1.
- /// the green channel value, normally in the range 0-1.
- /// the blue channel value, normally in the range 0-1.
- /// the alpha channel value, normally in the range 0-1.
- ///
- /// This function prioritizes correctness over speed: it is suitable for unit
- /// tests, but is not intended for use in a game engine.
- /// Thread Safety: This function is not thread safe.
- /// Version: This function is available since SDL 3.2.0.
- ///
- /// Returns on success or on failure; call for more information.
- public static bool WriteSurfacePixelFloat(nint surface, Point location, float r, float g, float b, float a) {
- if (surface == nint.Zero) {
- LogError(LogCategory.Error, "WriteSurfacePixelFloat: Window pointer is null.");
- return false;
- }
- return WriteSurfacePixelFloat(surface, location.X, location.Y, r, g, b, a);
- }
[LibraryImport(NativeLibName, StringMarshalling = Marshalling),
UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
diff --git a/SDL3/SdlException.cs b/SDL3/SDL/SdlException.cs
similarity index 100%
rename from SDL3/SdlException.cs
rename to SDL3/SDL/SdlException.cs
diff --git a/SDL3/SDL/SdlSurface.cs b/SDL3/SDL/SdlSurface.cs
new file mode 100644
index 0000000..5ca7bd5
--- /dev/null
+++ b/SDL3/SDL/SdlSurface.cs
@@ -0,0 +1,1431 @@
+using System;
+using System.Runtime.InteropServices;
+using SharpSDL3.Enums;
+using SharpSDL3.Structs;
+
+namespace SharpSDL3;
+
+public static partial class Sdl
+{
+
+ /// Clear a surface with a specific color, with floating point precision.
+ /// the to clear.
+ /// the red component of the pixel, normally in the range 0-1.
+ /// the green component of the pixel, normally in the range 0-1.
+ /// the blue component of the pixel, normally in the range 0-1.
+ /// the alpha component of the pixel, normally in the range 0-1.
+ ///
+ /// This function handles all surface formats, and ignores any clip rectangle.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool ClearSurface(nint surface, float r, float g, float b, float a) {
+ if (surface != nint.Zero) return SDL_ClearSurface(surface, r, g, b, a);
+ LogWarn(LogCategory.System, "ClearSurface: Surface pointer is null.");
+ return false;
+ }
+
+ /// Compose a custom blend mode for renderers.
+ /// the applied to the red, green, and blue components of the source pixels.
+ /// the applied to the red, green, and blue components of the destination pixels.
+ /// the used to combine the red, green, and blue components of the source and destination pixels.
+ /// the applied to the alpha component of the source pixels.
+ /// the applied to the alpha component of the destination pixels.
+ /// the used to combine the alpha component of the source and destination pixels.
+ ///
+ /// The functions and accept the returned by this function if the renderer supports it.
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// Returns an that represents the chosen factors and operations.
+ public static BlendMode ComposeCustomBlendMode(BlendFactor srcColorFactor, BlendFactor dstColorFactor, BlendOperation colorOperation, BlendFactor srcAlphaFactor, BlendFactor dstAlphaFactor, BlendOperation alphaOperation) {
+ if (!Enum.IsDefined(srcColorFactor) ||
+ !Enum.IsDefined(dstColorFactor) ||
+ !Enum.IsDefined(colorOperation) ||
+ !Enum.IsDefined(srcAlphaFactor) ||
+ !Enum.IsDefined(dstAlphaFactor) ||
+ !Enum.IsDefined(alphaOperation)) {
+ LogError(LogCategory.Error, "ComposeCustomBlendMode: Invalid blend factors or operations provided.");
+ throw new ArgumentException("Invalid blend factors or operations.");
+ }
+
+ var blendMode = SDL_ComposeCustomBlendMode(srcColorFactor, dstColorFactor, colorOperation, srcAlphaFactor, dstAlphaFactor, alphaOperation);
+ if (blendMode == 0) {
+ LogError(LogCategory.Error, "ComposeCustomBlendMode: Failed to compose custom blend mode.");
+ }
+
+ return (BlendMode)blendMode;
+ }
+
+ /// Copy a block of pixels of one format to another format.
+ /// the width of the block to copy, in pixels.
+ /// the height of the block to copy, in pixels.
+ /// an value of the src pixels format.
+ /// a pointer to the source pixels.
+ /// the pitch of the source pixels, in bytes.
+ /// an value of the dst pixels format.
+ /// a pointer to be filled in with new pixel data.
+ /// the pitch of the destination pixels, in bytes.
+ ///
+ /// Thread Safety: The same destination pixels should not be used from two threads at once. It is safe to use the same source pixels from multiple threads.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool ConvertPixels(int width, int height, PixelFormat srcFormat, nint src, int srcPitch, PixelFormat dstFormat, nint dst, int dstPitch) {
+ if (src != nint.Zero && dst != nint.Zero)
+ return SDL_ConvertPixels(width, height, srcFormat, src, srcPitch, dstFormat, dst, dstPitch);
+ LogWarn(LogCategory.System, "ConvertPixels: Source or destination pointer is null.");
+ return false;
+ }
+
+ /// Copy a block of pixels of one format and colorspace to another format and colorspace.
+ /// the width of the block to copy, in pixels.
+ /// the height of the block to copy, in pixels.
+ /// an value of the src pixels format.
+ /// an value describing the colorspace of the src pixels.
+ /// an SDL_PropertiesID with additional source color properties, or 0.
+ /// a pointer to the source pixels.
+ /// the pitch of the source pixels, in bytes.
+ /// an value of the dst pixels format.
+ /// an value describing the colorspace of the dst pixels.
+ /// an SDL_PropertiesID with additional destination color properties, or 0.
+ /// a pointer to be filled in with new pixel data.
+ /// the pitch of the destination pixels, in bytes.
+ ///
+ /// Thread Safety: The same destination pixels should not be used from two threads at once. It is safe to use the same source pixels from multiple threads.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool ConvertPixelsAndColorspace(int width, int height, PixelFormat srcFormat, Colorspace srcColorspace, uint srcProperties, nint src, int srcPitch, PixelFormat dstFormat, Colorspace dstColorspace, uint dstProperties, nint dst, int dstPitch) {
+ if (src != nint.Zero && dst != nint.Zero)
+ return SDL_ConvertPixelsAndColorspace(width, height, srcFormat, srcColorspace, srcProperties, src, srcPitch,
+ dstFormat, dstColorspace, dstProperties, dst, dstPitch);
+ LogWarn(LogCategory.System, "ConvertPixelsAndColorspace: Source or destination pointer is null.");
+ return false;
+ }
+
+ /// Copy an existing surface to a new surface of the specified format.
+ /// the existing SDL_Surface structure to convert.
+ /// the new pixel format.
+ ///
+ /// This function is used to optimize images for faster repeat blitting. This
+ /// is accomplished by converting the original and storing the result as a new
+ /// surface. The new, optimized surface can then be used as the source for
+ /// future blits, making them faster.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// (SDL_Surface *) Returns the new SDL_Surfacestructure that is created or on failure; call for more information.
+ public static nint ConvertSurface(nint surface, PixelFormat format) {
+ if (surface != nint.Zero) return SDL_ConvertSurface(surface, format);
+ LogWarn(LogCategory.System, "ConvertSurface: Surface pointer is null.");
+ return nint.Zero;
+ }
+
+ /// Copy an existing surface to a new surface of the specified format and colorspace.
+ /// the existing SDL_Surface structure to convert.
+ /// the new pixel format.
+ /// an optional palette to use for indexed formats, may be discarded.
+ /// the new colorspace.
+ /// an SDL_PropertiesID with additional color properties, or 0.
+ ///
+ /// This function converts an existing surface to a new format and colorspace
+ /// and returns the new surface. This will perform any pixel format and
+ /// colorspace conversion needed.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// (SDL_Surface *) Returns the new SDL_Surfacestructure that is created or on failure; call for more information.
+
+ public static nint ConvertSurfaceAndColorspace(nint surface, PixelFormat format, nint palette, Colorspace colorspace, uint props) {
+ if (surface != nint.Zero) return SDL_ConvertSurfaceAndColorspace(surface, format, palette, colorspace, props);
+ LogWarn(LogCategory.System, "ConvertSurfaceAndColorspace: Surface pointer is null.");
+ return nint.Zero;
+ }
+
+ /// Allocate a new surface with a specific pixel format.
+ /// the width of the surface.
+ /// the height of the surface.
+ /// the for the new surface's pixel format.
+ ///
+ /// The pixels of the new surface are initialized to zero.
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// (SDL_Surface *) Returns the new SDL_Surfacestructure that is created or on failure; call for more information.
+ public static nint CreateSurface(int width, int height, PixelFormat format) {
+ if (width > 0 && height > 0) return SDL_CreateSurface(width, height, format);
+ LogError(LogCategory.Error, "CreateSurface: Invalid width or height.");
+ return nint.Zero;
+
+ }
+
+ /// Allocate a new surface with a specific pixel format and existing pixel data.
+ /// the width of the surface.
+ /// the height of the surface.
+ /// the for the new surface's pixel format.
+ /// a pointer to existing pixel data.
+ /// the number of bytes between each row, including padding.
+ ///
+ /// No copy is made of the pixel data. Pixel data is not managed automatically;
+ /// you must free the surface before you free the pixel data.
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// (SDL_Surface *) Returns the new SDL_Surface structure that is created or on failure; call for more information.
+ public static nint CreateSurfaceFrom(int width, int height, PixelFormat format, nint pixels, int pitch) {
+ if (pixels == nint.Zero) {
+ LogError(LogCategory.System, "CreateSurfaceFrom: Pixels pointer is null.");
+ return nint.Zero;
+ }
+
+ if (Enum.IsDefined(format)) return SDL_CreateSurfaceFrom(width, height, format, pixels, pitch);
+ LogError(LogCategory.Error, "CreateSurfaceFrom: Invalid pixel format.");
+ return nint.Zero;
+
+ }
+
+ /// Create a palette and associate it with a surface.
+ /// the structure to update.
+ ///
+ /// This function creates a palette compatible with the provided surface. The
+ /// palette is then returned for you to modify, and the surface will
+ /// automatically use the new palette in future operations. You do not need to
+ /// destroy the returned palette, it will be freed when the reference count
+ /// reaches 0, usually when the surface is destroyed.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// (SDL_Palette *) Returns a new SDL_Palettestructure on success or on failure (e.g. if the surface didn't have anindex format); call for more information.
+ public static nint CreateSurfacePalette(nint surface) {
+ if (surface != nint.Zero) return SDL_CreateSurfacePalette(surface);
+ LogError(LogCategory.System, "CreateSurfacePalette: Surface pointer is null.");
+ return nint.Zero;
+ }
+
+ /// Free a surface.
+ /// the to free.
+ ///
+ /// It is safe to pass to this function.
+ /// Thread Safety: No other thread should be using the surface when it is freed.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ public static void DestroySurface(nint surface) {
+ if (surface == nint.Zero) {
+ LogInfo(LogCategory.System, "Will destroy nothing.");
+ }
+
+ SDL_DestroySurface(surface);
+ }
+
+ /// Creates a new surface identical to the existing surface.
+ /// the surface to duplicate.
+ ///
+ /// If the original surface has alternate images, the new surface will have a reference to them as well.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// (SDL_Surface *) Returns a copy of the surface or on failure; call for more information.
+ public static nint DuplicateSurface(nint surface) {
+ if (surface != nint.Zero) return SDL_DuplicateSurface(surface);
+ LogWarn(LogCategory.System, "DuplicateSurface: Surface pointer is null.");
+ return nint.Zero;
+ }
+
+ /// Perform a fast fill of a rectangle with a specific color.
+ /// the structure that is the drawing target.
+ /// the structure representing the rectangle to fill, or to fill the entire surface.
+ /// the color to fill with.
+ ///
+ /// color should be a pixel of the format used by the surface, and can be
+ /// generated by or . If
+ /// the color value contains an alpha component then the destination is simply
+ /// filled with that alpha information, no blending takes place.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static unsafe bool FillSurfaceRect(nint dst, Rect rect, uint color) {
+ if (dst == nint.Zero) {
+ LogWarn(LogCategory.System, "FillSurfaceRect: Destination pointer is null.");
+ return false;
+ }
+ var rectPtr = Marshal.AllocHGlobal(sizeof(Rect));
+ *(Rect*)rectPtr = rect;
+ bool result = SDL_FillSurfaceRect(dst, rectPtr, color);
+ if (!result) {
+ LogError(LogCategory.Error, "FillSurfaceRect: Failed to fill surface rectangle.");
+ }
+ Marshal.FreeHGlobal(rectPtr);
+ return result;
+ }
+
+ /// Perform a fast fill of a set of rectangles with a specific color.
+ /// the structure that is the drawing target.
+ /// an array of s representing the rectangles to fill.
+ /// the color to fill with.
+ ///
+ /// color should be a pixel of the format used by the surface, and can be
+ /// generated by or . If
+ /// the color value contains an alpha component then the destination is simply
+ /// filled with that alpha information, no blending takes place.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool FillSurfaceRects(nint dst, Span rects, uint color) {
+ if (dst == nint.Zero) {
+ LogWarn(LogCategory.System, "FillSurfaceRects: Destination pointer is null.");
+ return false;
+ }
+ if (rects.IsEmpty) {
+ LogWarn(LogCategory.System, "FillSurfaceRects: Rectangles span is empty.");
+ return false;
+ }
+ bool result = SDL_FillSurfaceRects(dst, rects, rects.Length, color);
+ if (!result) {
+ LogError(LogCategory.Error, "FillSurfaceRects: Failed to fill surface rectangles.");
+ }
+ return result;
+ }
+
+ /// Flip a surface vertically or horizontally.
+ /// the surface to flip.
+ /// the direction to flip.
+ ///
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool FlipSurface(nint surface, FlipMode flip) {
+ if (surface == nint.Zero) {
+ LogWarn(LogCategory.System, "FlipSurface: Surface pointer is null.");
+ return false;
+ }
+ return SDL_FlipSurface(surface, flip);
+ }
+ /// Get the additional alpha value used in blit operations.
+ /// the structure to query.
+ /// a pointer filled in with the current alpha value.
+ ///
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool GetSurfaceAlphaMod(nint surface, out byte alpha) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "GetSurfaceAlphaMod: Surface pointer is null.");
+ alpha = 0;
+ return false;
+ }
+ bool result = SDL_GetSurfaceAlphaMod(surface, out alpha);
+ if (!result) {
+ LogError(LogCategory.Error, "GetSurfaceAlphaMod: Failed to retrieve surface alpha mod.");
+ }
+ return result;
+ }
+
+ ///
+ /// Get the palette used by a surface.
+ ///
+ /// the to query.
+ ///
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// (SDL_Palette *) Returns a pointer to the palette used by the surface, or if there is no palette used.
+ public static nint GetSurfacePalette(nint surface) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "GetSurfacePalette: Surface pointer is null.");
+ return nint.Zero;
+ }
+ var palette = SDL_GetSurfacePalette(surface);
+ if (palette == nint.Zero) {
+ LogError(LogCategory.Error, "GetSurfacePalette: Failed to retrieve surface palette.");
+ }
+
+ return palette;
+ }
+
+ /// Get the blend mode used for blit operations.
+ /// the structure to query.
+ /// a pointer filled in with the current .
+ ///
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool GetSurfaceBlendMode(nint surface, nint blendMode) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "GetSurfaceBlendMode: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_GetSurfaceBlendMode(surface, blendMode);
+ if (!result) {
+ LogError(LogCategory.Error, "GetSurfaceBlendMode: Failed to retrieve surface blend mode.");
+ }
+ return result;
+ }
+
+ /// Get the clipping rectangle for a surface.
+ /// the structure representing the surface to be clipped.
+ /// a structure filled in with the clipping rectangle for the surface.
+ ///
+ /// When surface is the destination of a blit, only the area within the clip rectangle is drawn into.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool GetSurfaceClipRect(nint surface, out Rect rect) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "GetSurfaceClipRect: Surface pointer is null.");
+ rect = default;
+ return false;
+ }
+ bool result = SDL_GetSurfaceClipRect(surface, out rect);
+ if (!result) {
+ LogError(LogCategory.Error, "GetSurfaceClipRect: Failed to retrieve surface clip rect.");
+ }
+ return result;
+ }
+
+ /// Get the color key (transparent pixel) for a surface.
+ /// the structure to query.
+ /// a pointer filled in with the transparent pixel.
+ ///
+ /// The color key is a pixel of the format used by the surface, as generated by .
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool GetSurfaceColorKey(nint surface, out uint key) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "GetSurfaceColorKey: Surface pointer is null.");
+ key = 0;
+ return false;
+ }
+ bool result = SDL_GetSurfaceColorKey(surface, out key);
+ if (!result) {
+ LogError(LogCategory.Error, "GetSurfaceColorKey: Failed to retrieve surface color key.");
+ }
+ return result;
+ }
+
+ /// Get the additional color value multiplied into blit operations.
+ /// the structure to query.
+ /// a pointer filled in with the current red color value.
+ /// a pointer filled in with the current green color value.
+ /// a pointer filled in with the current blue color value.
+ ///
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool GetSurfaceColorMod(nint surface, out byte r, out byte g, out byte b) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "GetSurfaceColorMod: Surface pointer is null.");
+ r = g = b = 0;
+ return false;
+ }
+ bool result = SDL_GetSurfaceColorMod(surface, out r, out g, out b);
+ if (!result) {
+ LogError(LogCategory.Error, "GetSurfaceColorMod: Failed to retrieve surface color mod.");
+ }
+ return result;
+ }
+
+ ///
+ /// Get the colorspace used by a surface.
+ ///
+ /// the structure to query.
+ ///
+ /// The colorspace defaults to for floating point formats,
+ /// for 10-bit formats, for other RGB surfaces and
+ /// for YUV textures.
+ ///
+ /// Thread Safety: This function can be called on different threads with different surfaces.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// (SDL_Colorspace) Returns the colorspace used by the surface, or if the surface is .
+ public static Colorspace GetSurfaceColorspace(nint surface)
+ {
+ return SDL_GetSurfaceColorspace(surface);
+ }
+
+ /// Get an array including all versions of a surface.
+ /// the structure to query.
+ /// a pointer filled in with the number of surface pointers returned, may be discarded.
+ ///
+ /// This returns all versions of a surface, with the surface being queried as
+ /// the first element in the returned array.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ ///
+ /// (SDL_Surface **) Returns a terminated array ofSDL_Surface pointers or on failure; call for more information. This should be freedwith when it is no longer needed.
+ public static Span GetSurfaceImages(nint surface, out int count) {
+ var result = SDL_GetSurfaceImages(surface, out count);
+ if (result == nint.Zero) {
+ LogError(LogCategory.Error, "GetSurfaceImages: Failed to retrieve surface images.");
+ return [];
+ }
+
+ if (count <= 0) {
+ LogError(LogCategory.Error, "GetSurfaceImages: No images found.");
+ return [];
+ }
+
+ Span images = new Span(ref result);
+ if (images == []) {
+ LogError(LogCategory.Error, "GetSurfaceImages: Failed to create span for surface images.");
+ return [];
+ }
+
+ if (images.Length != count) {
+ LogError(LogCategory.Error, "GetSurfaceImages: Mismatch between count and span length.");
+ return [];
+ }
+
+ for (var i = 0; i < count; i++)
+ {
+ if (images[i] != nint.Zero) continue;
+ LogError(LogCategory.Error, $"GetSurfaceImages: Image at index {i} is null.");
+ return [];
+ }
+
+ return images.ToArray();
+ }
+
+ /// Get the properties associated with a surface.
+ /// the structure to query.
+ ///
+ /// The following properties are understood by SDL:
+ ///
+ /// - SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT: for HDR10 and floating point surfaces, this defines the value of 100% diffuse white, with higher values being displayed in the High Dynamic Range headroom.This defaults to 203 for HDR10 surfaces and 1.0 for floating point surfaces.
+ /// - SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT: for HDR10 and floating point surfaces, this defines the maximum dynamic range used by the content, in terms of the SDR white point.This defaults to 0.0, which disables tone mapping.
+ /// - SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING: the tone mapping operator used when compressing from a surface with high dynamic range to another with lower dynamic range. Currently this supports "chrome", which uses the same tone mapping that Chrome uses for HDR content, the form "*=N", where N is a floating point scale factor applied in linear space, and "none", which disables tone mapping. This defaults to "chrome".
+ /// - SDL_PROP_SURFACE_HOTSPOT_X_NUMBER: the hotspot pixel offset from the left edge of the image, if this surface is being used as a cursor.
+ /// - SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER: the hotspot pixel offset from the top edge of the image, if this surface is being used as a cursor.
+ ///
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns a valid property ID on success or 0 on failure; call for more information.
+ public static uint GetSurfaceProperties(nint surface) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "GetSurfaceProperties: Surface pointer is null.");
+ return 0;
+ }
+ var properties = SDL_GetSurfaceProperties(surface);
+ if (properties == 0) {
+ LogError(LogCategory.Error, "GetSurfaceProperties: Failed to retrieve surface properties.");
+ }
+ return properties;
+ }
+
+ /// Set up a surface for directly accessing the pixels.
+ /// the structure to be locked.
+ ///
+ /// Between calls to /
+ /// , you can write to and read from
+ /// surface->pixels, using the pixel format stored in surface->format. Once
+ /// you are done accessing the surface, you should use
+ /// to release it.
+ /// Thread Safety: This function is not thread safe. The locking referred to by this function is making the pixels available for direct access, not thread-safe locking.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool LockSurface(nint surface) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "LockSurface: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_LockSurface(surface);
+ if (!result) {
+ LogError(LogCategory.Error, "LockSurface: Failed to lock surface.");
+ }
+ return result;
+ }
+
+ /// Map an RGB triple to an opaque pixel value for a given pixel format.
+ /// a pointer to Details describing the pixel format.
+ /// an optional palette for indexed formats, may be discarded.
+ /// the red component of the pixel in the range 0-255.
+ /// the green component of the pixel in the range 0-255.
+ /// the blue component of the pixel in the range 0-255.
+ ///
+ /// This function maps the RGB color value to the specified pixel format and
+ /// returns the pixel value best approximating the given RGB color value for
+ /// the given pixel format.
+ /// Thread Safety: It is safe to call this function from any thread, as long as the palette is not modified.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// Returns a pixel value.
+ public static uint MapRgb(nint format, nint palette, byte r, byte g, byte b) {
+ if (format == nint.Zero || palette == nint.Zero) {
+ LogError(LogCategory.Error, "MapRgb: Format or palette pointer is null.");
+ return 0;
+ }
+ var color = SDL_MapRGB(format, palette, r, g, b);
+ if (color == 0) {
+ LogError(LogCategory.Error, "MapRgb: Failed to map RGB color.");
+ }
+ return color;
+ }
+
+ /// Map an RGBA quadruple to a pixel value for a given pixel format.
+ /// a pointer to Details describing the pixel format.
+ /// an optional palette for indexed formats, may be discarded.
+ /// the red component of the pixel in the range 0-255.
+ /// the green component of the pixel in the range 0-255.
+ /// the blue component of the pixel in the range 0-255.
+ /// the alpha component of the pixel in the range 0-255.
+ ///
+ /// This function maps the RGBA color value to the specified pixel format and
+ /// returns the pixel value best approximating the given RGBA color value for
+ /// the given pixel format.
+ /// Thread Safety: It is safe to call this function from any thread, as long as the palette is not modified.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// Returns a pixel value.
+ public static uint MapRgba(nint format, nint palette, byte r, byte g, byte b, byte a) {
+ if (format == nint.Zero || palette == nint.Zero) {
+ LogError(LogCategory.Error, "MapRgba: Format or palette pointer is null.");
+ return 0;
+ }
+ var color = SDL_MapRGBA(format, palette, r, g, b, a);
+ if (color == 0) {
+ LogError(LogCategory.Error, "MapRgba: Failed to map RGBA color.");
+ }
+ return color;
+ }
+
+ /// Map an RGB triple to an opaque pixel value for a surface.
+ /// the surface to use for the pixel format and palette.
+ /// the red component of the pixel in the range 0-255.
+ /// the green component of the pixel in the range 0-255.
+ /// the blue component of the pixel in the range 0-255.
+ ///
+ /// This function maps the RGB color value to the specified pixel format and
+ /// returns the pixel value best approximating the given RGB color value for
+ /// the given pixel format.
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns a pixel value.
+ public static uint MapSurfaceRgb(nint surface, byte r, byte g, byte b) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "MapSurfaceRgb: Surface pointer is null.");
+ return 0;
+ }
+ var color = SDL_MapSurfaceRGB(surface, r, g, b);
+ if (color == 0) {
+ LogError(LogCategory.Error, "MapSurfaceRgb: Failed to map surface RGB color.");
+ }
+ return color;
+ }
+
+ /// Map an RGB triple to an opaque pixel value for a surface.
+ /// the surface to use for the pixel format and palette.
+ /// the representing RGB ranging from 0-255.
+ ///
+ /// This function maps the RGB color value to the specified pixel format and
+ /// returns the pixel value best approximating the given RGB color value for
+ /// the given pixel format.
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns a pixel value.
+ public static uint MapSurfaceRgb(nint surface, Color color) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "MapSurfaceRgb: Surface pointer is null.");
+ return 0;
+ }
+
+ var colorValue = SDL_MapSurfaceRGB(surface, color.R, color.G, color.B);
+ if (colorValue == 0) {
+ LogError(LogCategory.Error, "MapSurfaceRgb: Failed to map surface RGB color.");
+ }
+ return colorValue;
+ }
+
+ /// Map an RGBA quadruple to a pixel value for a surface.
+ /// the surface to use for the pixel format and palette.
+ /// the red component of the pixel in the range 0-255.
+ /// the green component of the pixel in the range 0-255.
+ /// the blue component of the pixel in the range 0-255.
+ /// the alpha component of the pixel in the range 0-255.
+ ///
+ /// This function maps the RGBA color value to the specified pixel format and
+ /// returns the pixel value best approximating the given RGBA color value for
+ /// the given pixel format.
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns a pixel value.
+ public static uint MapSurfaceRgba(nint surface, byte r, byte g, byte b, byte a) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "MapSurfaceRgba: Surface pointer is null.");
+ return 0;
+ }
+ var color = SDL_MapSurfaceRGBA(surface, r, g, b, a);
+ if (color == 0) {
+ LogError(LogCategory.Error, "MapSurfaceRgba: Failed to map surface RGBA color.");
+ }
+ return color;
+ }
+
+ /// Map an RGBA quadruple to a pixel value for a surface.
+ /// the surface to use for the pixel format and palette.
+ /// the representing RGB ranging from 0-255.
+ ///
+ /// This function maps the RGBA color value to the specified pixel format and
+ /// returns the pixel value best approximating the given RGBA color value for
+ /// the given pixel format.
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns a pixel value.
+ public static uint MapSurfaceRgba(nint surface, Color color) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "MapSurfaceRgba: Surface pointer is null.");
+ return 0;
+ }
+ var colorValue = SDL_MapSurfaceRGBA(surface, color.R, color.G, color.B, color.A);
+ if (colorValue == 0) {
+ LogError(LogCategory.Error, "MapSurfaceRgba: Failed to map surface RGBA color.");
+ }
+ return colorValue;
+ }
+ /// Retrieves a single pixel from a surface.
+ /// the surface to read.
+ /// the horizontal coordinate, 0 <= x < width.
+ /// the vertical coordinate, 0 <= y < height.
+ /// a pointer filled in with the red channel, 0-255, or discard to ignore this channel.
+ /// a pointer filled in with the green channel, 0-255, or discard to ignore this channel.
+ /// a pointer filled in with the blue channel, 0-255, or discard to ignore this channel.
+ /// a pointer filled in with the alpha channel, 0-255, or discard to ignore this channel.
+ ///
+ /// This function prioritizes correctness over speed: it is suitable for unit
+ /// tests, but is not intended for use in a game engine.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool ReadSurfacePixel(nint surface, int x, int y, out byte r, out byte g, out byte b, out byte a) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "ReadSurfacePixel: Surface pointer is null.");
+ r = g = b = a = 0;
+ return false;
+ }
+ bool result = SDL_ReadSurfacePixel(surface, x, y, out r, out g, out b, out a);
+ if (!result) {
+ LogError(LogCategory.Error, "ReadSurfacePixel: Failed to read surface pixel.");
+ }
+ return result;
+ }
+
+ /// Retrieves a single pixel from a surface.
+ /// the surface to read.
+ /// the horizontal coordinate, 0 <= x < width.
+ /// the vertical coordinate, 0 <= y < height.
+ /// the color that is read from the at and coordinates.
+ ///
+ /// This function prioritizes correctness over speed: it is suitable for unit
+ /// tests, but is not intended for use in a game engine.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool ReadSurfacePixel(nint surface, int x, int y, out Color color) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "ReadSurfacePixel: Surface pointer is null.");
+ color = default;
+ return false;
+ }
+ bool result = SDL_ReadSurfacePixel(surface, x, y, out var r, out var g, out var b, out var a);
+ if (!result) {
+ LogError(LogCategory.Error, "ReadSurfacePixel: Failed to read surface pixel.");
+ color = default;
+ return false;
+ }
+ color = new Color() { R = r, G = g, B = b, A = a };
+ return true;
+ }
+
+ /// Retrieves a single pixel from a surface.
+ /// the surface to read.
+ /// the horizontal coordinate, 0 <= x < width.
+ /// the vertical coordinate, 0 <= y < height.
+ ///
+ /// This function prioritizes correctness over speed: it is suitable for unit
+ /// tests, but is not intended for use in a game engine.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static Color ReadSurfacePixel(nint surface, int x, int y) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "ReadSurfacePixel: Surface pointer is null.");
+ return default;
+ }
+ bool result = SDL_ReadSurfacePixel(surface, x, y, out var r, out var g, out var b, out var a);
+ if (!result) {
+ LogError(LogCategory.Error, "ReadSurfacePixel: Failed to read surface pixel.");
+ return default;
+ }
+ return new Color() { R = r, G = g, B = b, A = a };
+ }
+
+ /// Retrieves a single pixel from a surface.
+ /// the surface to read.
+ /// the horizontal coordinate, 0 <= x < width.
+ /// the vertical coordinate, 0 <= y < height.
+ /// a pointer filled in with the red channel, normally in the range 0-1, or discard to ignore this channel.
+ /// a pointer filled in with the green channel, normally in the range 0-1, or discard to ignore this channel.
+ /// a pointer filled in with the blue channel, normally in the range 0-1, or discard to ignore this channel.
+ /// a pointer filled in with the alpha channel, normally in the range 0-1, or discard to ignore this channel.
+ ///
+ /// This function prioritizes correctness over speed: it is suitable for unit
+ /// tests, but is not intended for use in a game engine.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool ReadSurfacePixelFloat(nint surface, int x, int y, out float r, out float g, out float b, out float a) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "ReadSurfacePixelFloat: Surface pointer is null.");
+ r = g = b = a = 0;
+ return false;
+ }
+ bool result = SDL_ReadSurfacePixelFloat(surface, x, y, out r, out g, out b, out a);
+ if (!result) {
+ LogError(LogCategory.Error, "ReadSurfacePixelFloat: Failed to read surface pixel.");
+ }
+ return result;
+ }
+
+ /// Retrieves a single pixel from a surface.
+ /// the surface to read.
+ /// the horizontal coordinate, 0 <= x < width.
+ /// the vertical coordinate, 0 <= y < height.
+ /// the structure filled with color data, or discard to ignore.
+ ///
+ /// This function prioritizes correctness over speed: it is suitable for unit
+ /// tests, but is not intended for use in a game engine.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool ReadSurfacePixelFloat(nint surface, int x, int y, out FColor color) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "ReadSurfacePixelFloat: Surface pointer is null.");
+ color = default;
+ return false;
+ }
+ bool result = SDL_ReadSurfacePixelFloat(surface, x, y, out var r, out var g, out var b, out var a);
+ if (!result) {
+ LogError(LogCategory.Error, "ReadSurfacePixelFloat: Failed to read surface pixel.");
+ color = default;
+ return false;
+ }
+ color = new FColor() { R = r, G = g, B = b, A = a };
+ return true;
+ }
+
+ /// Retrieves a single pixel from a surface.
+ /// the surface to read.
+ /// the horizontal coordinate, 0 <= x < width.
+ /// the vertical coordinate, 0 <= y < height.
+ ///
+ /// This function prioritizes correctness over speed: it is suitable for unit
+ /// tests, but is not intended for use in a game engine.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static FColor ReadSurfacePixelFloat(nint surface, int x, int y) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "ReadSurfacePixelFloat: Surface pointer is null.");
+ return default;
+ }
+ bool result = SDL_ReadSurfacePixelFloat(surface, x, y, out var r, out var g, out var b, out var a);
+ if (!result) {
+ LogError(LogCategory.Error, "ReadSurfacePixelFloat: Failed to read surface pixel.");
+ return default;
+ }
+ return new FColor() { R = r, G = g, B = b, A = a };
+ }
+
+ /// Creates a new surface identical to the existing surface, scaled to the desired size.
+ /// the surface to duplicate and scale.
+ /// the width of the new surface.
+ /// the height of the new surface.
+ /// the to be used.
+ ///
+ /// The returned surface should be freed with
+ /// .
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// (SDL_Surface *) Returns a copy of the surface or on failure; call for more information.
+ public static nint ScaleSurface(nint surface, int width, int height, ScaleMode scaleMode) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "ScaleSurface: Surface pointer is null.");
+ return nint.Zero;
+ }
+
+ if (!Enum.IsDefined(scaleMode)) {
+ LogError(LogCategory.Error, "ScaleSurface: Invalid scale mode.");
+ return nint.Zero;
+ }
+
+ if (width <= 0 || height <= 0) {
+ LogError(LogCategory.Error, "ScaleSurface: Invalid width or height.");
+ return nint.Zero;
+ }
+
+ // System.EngineExecutionException thrown here, why?
+ var scaledSurface = SDL_ScaleSurface(surface, width, height, (int)scaleMode);
+ if (scaledSurface == nint.Zero) {
+ LogError(LogCategory.Error, $"ScaleSurface: Failed to scale surface. {Sdl.GetError()}");
+ }
+ return scaledSurface;
+ }
+
+ /// Creates a new surface identical to the existing surface, scaled to the desired size.
+ /// the surface to duplicate and scale.
+ /// the width of the new surface.
+ /// the height of the new surface.
+ /// the to be used.
+ ///
+ /// The returned surface should be freed with .
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// (SDL_Surface *) Returns a copy of the surface or on failure; call for more information.
+ public static Surface ScaleSurface(ref Surface surface, int width, int height, ScaleMode scaleMode) {
+ var oSurface = StructureToPointer(ref surface);
+ var newSurface = ScaleSurface(oSurface, width, height, scaleMode);
+ var rSurface = PointerToStructure(newSurface);
+ return rSurface;
+ }
+
+
+ /// Set an additional alpha value used in blit operations.
+ /// the structure to update.
+ /// the alpha value multiplied into blit operations.
+ ///
+ /// When this surface is blitted, during the blit operation the source alpha
+ /// value is modulated by this alpha value according to the following formula:
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool SetSurfaceAlphaMod(nint surface, byte alpha) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "SetSurfaceAlphaMod: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_SetSurfaceAlphaMod(surface, alpha);
+ if (!result) {
+ LogError(LogCategory.Error, "SetSurfaceAlphaMod: Failed to set surface alpha mod.");
+ }
+ return result;
+ }
+
+ /// Set the blend mode used for blit operations.
+ /// the structure to update.
+ /// the to use for blit blending.
+ ///
+ /// To copy a surface to another surface (or texture) without blending with the
+ /// existing data, the blendmode of the SOURCE surface should be set to
+ /// SDL_BLENDMODE_NONE.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool SetSurfaceBlendMode(nint surface, uint blendMode) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "SetSurfaceBlendMode: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_SetSurfaceBlendMode(surface, blendMode);
+ if (!result) {
+ LogError(LogCategory.Error, "SetSurfaceBlendMode: Failed to set surface blend mode.");
+ }
+ return result;
+ }
+
+ /// Set the clipping rectangle for a surface.
+ /// the structure to be clipped.
+ /// the structure representing the clipping rectangle, or to disable clipping.
+ ///
+ /// When surface is the destination of a blit, only the area within the clip
+ /// rectangle is drawn into.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns if the rectangle intersects the surface, otherwise and blits will be completely clipped.
+ public static bool SetSurfaceClipRect(nint surface, ref Rect rect) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "SetSurfaceClipRect: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_SetSurfaceClipRect(surface, ref rect);
+ if (!result) {
+ LogError(LogCategory.Error, "SetSurfaceClipRect: Failed to set surface clip rect.");
+ }
+ return result;
+ }
+
+ /// Set the color key (transparent pixel) in a surface.
+ /// the structure to update.
+ /// to enable color key, to disable color key.
+ /// the transparent pixel.
+ ///
+ /// The color key defines a pixel value that will be treated as transparent in
+ /// a blit. For example, one can use this to specify that cyan pixels should be
+ /// considered transparent, and therefore not rendered.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool SetSurfaceColorKey(nint surface, bool enabled, uint key) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "SetSurfaceColorKey: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_SetSurfaceColorKey(surface, enabled, key);
+ if (!result) {
+ LogError(LogCategory.Error, "SetSurfaceColorKey: Failed to set surface color key.");
+ }
+ return result;
+ }
+
+ /// Set an additional color value multiplied into blit operations.
+ /// the structure to update.
+ /// the red color value multiplied into blit operations.
+ /// the green color value multiplied into blit operations.
+ /// the blue color value multiplied into blit operations.
+ ///
+ /// When this surface is blitted, during the blit operation each source color
+ /// channel is modulated by the appropriate color value according to the
+ /// following formula:
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool SetSurfaceColorMod(nint surface, byte r, byte g, byte b) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "SetSurfaceColorMod: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_SetSurfaceColorMod(surface, r, g, b);
+ if (!result) {
+ LogError(LogCategory.Error, "SetSurfaceColorMod: Failed to set surface color mod.");
+ }
+ return result;
+ }
+
+ /// Set an additional color value multiplied into blit operations.
+ /// the structure to update.
+ /// the color value.
+ ///
+ /// When this surface is blitted, during the blit operation each source color
+ /// channel is modulated by the appropriate color value according to the
+ /// following formula:
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool SetSurfaceColorMod(nint surface, Color color) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "SetSurfaceColorMod: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_SetSurfaceColorMod(surface, color.R, color.G, color.B);
+ if (!result) {
+ LogError(LogCategory.Error, "SetSurfaceColorMod: Failed to set surface color mod.");
+ }
+ return result;
+ }
+
+ /// Set the colorspace used by a surface.
+ /// the structure to update.
+ /// an value describing the surface colorspace.
+ ///
+ /// Setting the colorspace doesn't change the pixels, only how they are
+ /// interpreted in color operations.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool SetSurfaceColorspace(nint surface, Colorspace colorspace) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "SetSurfaceColorspace: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_SetSurfaceColorspace(surface, colorspace);
+ if (!result) {
+ LogError(LogCategory.Error, "SetSurfaceColorspace: Failed to set surface colorspace.");
+ }
+ return result;
+ }
+
+ /// Set the palette used by a surface.
+ /// the structure to update.
+ /// the SDL_Palette structure to use.
+ ///
+ /// A single palette can be shared with many surfaces.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool SetSurfacePalette(nint surface, nint palette) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "SetSurfacePalette: Surface pointer is null.");
+ return false;
+ }
+ if (palette == nint.Zero) {
+ LogError(LogCategory.Error, "SetSurfacePalette: Palette pointer is null.");
+ return false;
+ }
+ bool result = SDL_SetSurfacePalette(surface, palette);
+ if (!result) {
+ LogError(LogCategory.Error, "SetSurfacePalette: Failed to set surface palette.");
+ }
+ return result;
+ }
+
+ /// Set the RLE acceleration hint for a surface.
+ /// the structure to optimize.
+ /// to enable RLE acceleration, to disable it.
+ ///
+ /// If RLE is enabled, color key and alpha blending blits are much faster, but
+ /// the surface must be locked before directly accessing the pixels.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool SetSurfaceRle(nint surface, bool enabled) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "SetSurfaceRLE: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_SetSurfaceRLE(surface, enabled);
+ if (!result) {
+ LogError(LogCategory.Error, "SetSurfaceRLE: Failed to set surface RLE.");
+ }
+ return result;
+ }
+
+ /// Return whether a surface has alternate versions available.
+ /// the structure to query.
+ ///
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ ///
+ /// Returns if alternate versions are available or otherwise.
+ public static bool SurfaceHasAlternateImages(nint surface) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "SurfaceHasAlternateImages: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_SurfaceHasAlternateImages(surface);
+ if (!result) {
+ LogError(LogCategory.Error, "SurfaceHasAlternateImages: Failed to check surface alternate images.");
+ }
+ return result;
+ }
+
+ /// Returns whether the surface has a color key.
+ /// the structure to query.
+ ///
+ /// It is safe to pass a surface here; it will return false.
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ ///
+ /// Returns if the surface has a color key, otherwise.
+ public static bool SurfaceHasColorKey(nint surface) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "SurfaceHasColorKey: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_SurfaceHasColorKey(surface);
+ if (!result) {
+ LogError(LogCategory.Error, "SurfaceHasColorKey: Failed to check surface color key.");
+ }
+ return result;
+ }
+
+ /// Returns whether the surface is RLE enabled.
+ /// the structure to query.
+ ///
+ /// It is safe to pass a surface here; it will return false.
+ /// Thread Safety: It is safe to call this function from any thread.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ /// Returns if the surface is RLE enabled, otherwise.
+ public static bool SurfaceHasRle(nint surface) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "SurfaceHasRLE: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_SurfaceHasRLE(surface);
+ if (!result) {
+ LogError(LogCategory.Error, "SurfaceHasRLE: Failed to check surface RLE.");
+ }
+ return result;
+ }
+
+ /// Release a surface after directly accessing the pixels.
+ /// the structure to be unlocked.
+ ///
+ /// Thread Safety: This function is not thread safe. The locking referred to by this functionis making the pixels available for direct access, not thread-safe locking.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ ///
+ public static void UnlockSurface(nint surface) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "UnlockSurface: Surface pointer is null.");
+ return;
+ }
+ SDL_UnlockSurface(surface);
+ }
+
+
+ /// Writes a single pixel to a surface.
+ /// the surface to write.
+ /// the horizontal coordinate, 0 <= x < width.
+ /// the vertical coordinate, 0 <= y < height.
+ /// the red channel value, 0-255.
+ /// the green channel value, 0-255.
+ /// the blue channel value, 0-255.
+ /// the alpha channel value, 0-255.
+ ///
+ /// This function prioritizes correctness over speed: it is suitable for unit
+ /// tests, but is not intended for use in a game engine.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool WriteSurfacePixel(nint surface, int x, int y, byte r, byte g, byte b, byte a) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "WriteSurfacePixel: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_WriteSurfacePixel(surface, x, y, r, g, b, a);
+ if (!result) {
+ LogError(LogCategory.Error, "WriteSurfacePixel: Failed to write surface pixel.");
+ }
+ return result;
+ }
+
+ /// Writes a single pixel to a surface.
+ /// the surface to write.
+ /// the horizontal coordinate, 0 <= x < width.
+ /// the vertical coordinate, 0 <= y < height.
+ /// the struct filled with data
+ ///
+ /// This function prioritizes correctness over speed: it is suitable for unit
+ /// tests, but is not intended for use in a game engine.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool WriteSurfacePixel(nint surface, int x, int y, Color color) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "WriteSurfacePixel: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_WriteSurfacePixel(surface, x, y, color.R, color.G, color.B, color.A);
+ if (!result) {
+ LogError(LogCategory.Error, "WriteSurfacePixel: Failed to write surface pixel.");
+ }
+ return result;
+ }
+
+ /// Writes a single pixel to a surface.
+ /// the surface to write.
+ /// the struct that provides xy coordinates
+ /// the struct filled with data
+ ///
+ /// This function prioritizes correctness over speed: it is suitable for unit
+ /// tests, but is not intended for use in a game engine.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool WriteSurfacePixel(nint surface, Point location, Color color) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "WriteSurfacePixel: Surface pointer is null.");
+ return false;
+ }
+ return WriteSurfacePixel(surface, location.X, location.Y, color.R, color.G, color.B, color.A);
+ }
+
+ /// Writes a single pixel to a surface.
+ /// the surface to write.
+ /// the struct that provides xy coordinates
+ /// the red channel value, 0-255.
+ /// the green channel value, 0-255.
+ /// the blue channel value, 0-255.
+ /// the alpha channel value, 0-255.
+ ///
+ /// This function prioritizes correctness over speed: it is suitable for unit
+ /// tests, but is not intended for use in a game engine.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool WriteSurfacePixel(nint surface, Point location, byte r, byte g, byte b, byte a) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "WriteSurfacePixel: Surface pointer is null.");
+ return false;
+ }
+ return WriteSurfacePixel(surface, location.X, location.Y, r, g, b, a);
+ }
+
+ /// Writes a single pixel to a surface.
+ /// the surface to write.
+ /// the horizontal coordinate, 0 <= x < width.
+ /// the vertical coordinate, 0 <= y < height.
+ /// the red channel value, normally in the range 0-1.
+ /// the green channel value, normally in the range 0-1.
+ /// the blue channel value, normally in the range 0-1.
+ /// the alpha channel value, normally in the range 0-1.
+ ///
+ /// This function prioritizes correctness over speed: it is suitable for unit
+ /// tests, but is not intended for use in a game engine.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool WriteSurfacePixelFloat(nint surface, int x, int y, float r, float g, float b, float a) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "WriteSurfacePixelFloat: Surface pointer is null.");
+ return false;
+ }
+ bool result = SDL_WriteSurfacePixelFloat(surface, x, y, r, g, b, a);
+ if (!result) {
+ LogError(LogCategory.Error, "WriteSurfacePixelFloat: Failed to write surface pixel float.");
+ }
+ return result;
+ }
+
+ /// Writes a single pixel to a surface.
+ /// the surface to write.
+ /// the struct that provides xy coordinates
+ /// the struct filled with data
+ ///
+ /// This function prioritizes correctness over speed: it is suitable for unit
+ /// tests, but is not intended for use in a game engine.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool WriteSurfacePixelFloat(nint surface, Point location, FColor color) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "WriteSurfacePixelFloat: Window pointer is null.");
+ return false;
+ }
+ return WriteSurfacePixelFloat(surface, location.X, location.Y, color.R, color.G, color.B,
+ color.A);
+ }
+
+ /// Writes a single pixel to a surface.
+ /// the surface to write.
+ /// the struct that provides xy coordinates
+ /// the red channel value, normally in the range 0-1.
+ /// the green channel value, normally in the range 0-1.
+ /// the blue channel value, normally in the range 0-1.
+ /// the alpha channel value, normally in the range 0-1.
+ ///
+ /// This function prioritizes correctness over speed: it is suitable for unit
+ /// tests, but is not intended for use in a game engine.
+ /// Thread Safety: This function is not thread safe.
+ /// Version: This function is available since SDL 3.2.0.
+ ///
+ /// Returns on success or on failure; call for more information.
+ public static bool WriteSurfacePixelFloat(nint surface, Point location, float r, float g, float b, float a) {
+ if (surface == nint.Zero) {
+ LogError(LogCategory.Error, "WriteSurfacePixelFloat: Window pointer is null.");
+ return false;
+ }
+ return WriteSurfacePixelFloat(surface, location.X, location.Y, r, g, b, a);
+ }
+
+}
\ No newline at end of file
diff --git a/SDL3/Semaphore.cs b/SDL3/SDL/Semaphore.cs
similarity index 95%
rename from SDL3/Semaphore.cs
rename to SDL3/SDL/Semaphore.cs
index dfe41b7..d957cb1 100644
--- a/SDL3/Semaphore.cs
+++ b/SDL3/SDL/Semaphore.cs
@@ -8,7 +8,7 @@ namespace SharpSDL3;
public static partial class Sdl {
public static nint Create(uint initialValue) {
- nint sem = SDL_CreateSemaphore(initialValue);
+ var sem = SDL_CreateSemaphore(initialValue);
if (sem == 0) {
throw new InvalidOperationException("CreateSemaphore failed");
}
diff --git a/SDL3/Sensors.cs b/SDL3/SDL/Sensors.cs
similarity index 92%
rename from SDL3/Sensors.cs
rename to SDL3/SDL/Sensors.cs
index 87ebd47..3f5a9aa 100644
--- a/SDL3/Sensors.cs
+++ b/SDL3/SDL/Sensors.cs
@@ -39,7 +39,7 @@ public static void CloseSensor(nint sensor) {
/// Returns on success or on failure; call for more information.
public static bool GetSensorData(nint sensor, nint data, int numValues) {
- SdlBool result = SDL_GetSensorData(sensor, data, numValues);
+ var result = SDL_GetSensorData(sensor, data, numValues);
if (!result) {
throw new InvalidOperationException("GetSensorData failed");
}
@@ -55,7 +55,7 @@ public static bool GetSensorData(nint sensor, nint data, int numValues) {
/// (SDL_Sensor *) Returns an SDL_Sensor object or on failure; call for more information.
public static nint GetSensorFromId(uint instanceId) {
- nint sensor = SDL_GetSensorFromID(instanceId);
+ var sensor = SDL_GetSensorFromID(instanceId);
if (sensor == nint.Zero) {
throw new InvalidOperationException("GetSensorFromID failed");
}
@@ -71,7 +71,7 @@ public static nint GetSensorFromId(uint instanceId) {
/// Returns the sensor instance ID, or 0 on failure; call for more information.
public static uint GetSensorId(nint sensor) {
- uint id = SDL_GetSensorID(sensor);
+ var id = SDL_GetSensorID(sensor);
if (id == 0) {
throw new InvalidOperationException("GetSensorID failed");
}
@@ -87,7 +87,7 @@ public static uint GetSensorId(nint sensor) {
/// Returns the sensor name or on failure; call for more information.
public static string GetSensorName(nint sensor) {
- string name = SDL_GetSensorName(sensor);
+ var name = SDL_GetSensorName(sensor);
if (name == null) {
throw new InvalidOperationException("GetSensorName failed");
}
@@ -104,7 +104,7 @@ public static string GetSensorName(nint sensor) {
/// Returns the sensor name, or if instance_id is notvalid.
public static string GetSensorNameForId(uint instanceId) {
- string name = SDL_GetSensorNameForID(instanceId);
+ var name = SDL_GetSensorNameForID(instanceId);
if (name == null) {
throw new InvalidOperationException("GetSensorNameForID failed");
}
@@ -120,7 +120,7 @@ public static string GetSensorNameForId(uint instanceId) {
/// Returns the sensor platform dependent type, or -1 if sensor is.
public static int GetSensorNonPortableType(nint sensor) {
- int type = SDL_GetSensorNonPortableType(sensor);
+ var type = SDL_GetSensorNonPortableType(sensor);
if (type == -1) {
throw new InvalidOperationException("GetSensorNonPortableType failed");
}
@@ -137,7 +137,7 @@ public static int GetSensorNonPortableType(nint sensor) {
/// Returns the sensor platform dependent type, or -1 if instance_id is not valid.
public static int GetSensorNonPortableTypeForId(uint instanceId) {
- int type = SDL_GetSensorNonPortableTypeForID(instanceId);
+ var type = SDL_GetSensorNonPortableTypeForID(instanceId);
if (type == -1) {
throw new InvalidOperationException("GetSensorNonPortableTypeForID failed");
}
@@ -153,7 +153,7 @@ public static int GetSensorNonPortableTypeForId(uint instanceId) {
/// Returns a valid property ID on success or 0 on failure; call for more information.
public static uint GetSensorProperties(nint sensor) {
- uint properties = SDL_GetSensorProperties(sensor);
+ var properties = SDL_GetSensorProperties(sensor);
if (properties == 0) {
throw new InvalidOperationException("GetSensorProperties failed");
}
@@ -169,7 +169,7 @@ public static uint GetSensorProperties(nint sensor) {
/// (SDL_SensorID *) Returns a 0 terminated array of sensorinstance IDs or on failure; call for more information. This should be freed with when itis no longer needed.
public static nint GetSensors(out int count) {
- nint sensors = SDL_GetSensors(out count);
+ var sensors = SDL_GetSensors(out count);
if (sensors == nint.Zero) {
throw new InvalidOperationException("GetSensors failed");
}
@@ -185,7 +185,7 @@ public static nint GetSensors(out int count) {
/// Returns theSDL_SensorType type, orSDL_SENSOR_INVALID if sensor is .
public static SensorType GetSensorType(nint sensor) {
- SensorType type = SDL_GetSensorType(sensor);
+ var type = SDL_GetSensorType(sensor);
if (type == SensorType.Unknown) {
throw new InvalidOperationException("GetSensorType failed");
}
@@ -202,7 +202,7 @@ public static SensorType GetSensorType(nint sensor) {
/// Returns theSDL_SensorType, orSDL_SENSOR_INVALID if instance_id is not valid.
public static SensorType GetSensorTypeForId(uint instanceId) {
- SensorType type = SDL_GetSensorTypeForID(instanceId);
+ var type = SDL_GetSensorTypeForID(instanceId);
if (type == SensorType.Unknown) {
throw new InvalidOperationException("GetSensorTypeForID failed");
}
@@ -218,7 +218,7 @@ public static SensorType GetSensorTypeForId(uint instanceId) {
/// (SDL_Sensor *) Returns an SDL_Sensor object or on failure; call for more information.
public static nint OpenSensor(uint instanceId) {
- nint sensor = SDL_OpenSensor(instanceId);
+ var sensor = SDL_OpenSensor(instanceId);
if (sensor == nint.Zero) {
throw new InvalidOperationException("OpenSensor failed");
}
diff --git a/SDL3/Storage.cs b/SDL3/SDL/Storage.cs
similarity index 96%
rename from SDL3/Storage.cs
rename to SDL3/SDL/Storage.cs
index d47a388..63c505d 100644
--- a/SDL3/Storage.cs
+++ b/SDL3/SDL/Storage.cs
@@ -24,7 +24,7 @@ public static void CloseStorage(nint storage) {
if (storage == nint.Zero) {
throw new ArgumentException("Storage handle must not be null.", nameof(storage));
}
- SdlBool result = SDL_CloseStorage(storage);
+ var result = SDL_CloseStorage(storage);
if (!result) {
throw new InvalidOperationException("Failed to close storage.");
}
@@ -123,7 +123,7 @@ public static ulong GetStorageFileSize(nint storage, string path) {
if (string.IsNullOrEmpty(path)) {
throw new ArgumentException("Path must not be null or empty.", nameof(path));
}
- SdlBool result = SDL_GetStorageFileSize(storage, path, out ulong length);
+ var result = SDL_GetStorageFileSize(storage, path, out var length);
if (!result) {
throw new InvalidOperationException($"Failed to get file size for path: {path}");
}
@@ -148,7 +148,7 @@ public static PathInfo GetStoragePathInfo(nint storage, string path) {
if (string.IsNullOrEmpty(path)) {
throw new ArgumentException("Path must not be null or empty.", nameof(path));
}
- SdlBool result = SDL_GetStoragePathInfo(storage, path, out PathInfo info);
+ var result = SDL_GetStoragePathInfo(storage, path, out var info);
if (!result) {
throw new InvalidOperationException($"Failed to get path info for: {path}");
}
@@ -201,7 +201,7 @@ public static nint GlobStorageDirectory(nint storage, string path, string patter
if (string.IsNullOrEmpty(pattern)) {
throw new ArgumentException("Pattern must not be null or empty.", nameof(pattern));
}
- nint result = SDL_GlobStorageDirectory(storage, path, pattern, flags, out count);
+ var result = SDL_GlobStorageDirectory(storage, path, pattern, flags, out count);
if (result == nint.Zero) {
throw new InvalidOperationException($"Failed to glob storage directory: {path}");
}
diff --git a/SDL3/System.cs b/SDL3/SDL/System.cs
similarity index 97%
rename from SDL3/System.cs
rename to SDL3/SDL/System.cs
index 6f47c46..fffb471 100644
--- a/SDL3/System.cs
+++ b/SDL3/SDL/System.cs
@@ -113,7 +113,7 @@ public static string GetMonth(int month, bool shortCode = false) {
"November",
"December"
];
- string selectedMonth = months[month - 1];
+ var selectedMonth = months[month - 1];
return shortCode ? selectedMonth[..3] : selectedMonth;
}
diff --git a/SDL3/Textures.cs b/SDL3/SDL/Textures.cs
similarity index 96%
rename from SDL3/Textures.cs
rename to SDL3/SDL/Textures.cs
index ff61b57..8dc1e4a 100644
--- a/SDL3/Textures.cs
+++ b/SDL3/SDL/Textures.cs
@@ -115,7 +115,7 @@ public static byte GetTextureAlphaMod(nint texture) {
if (texture == nint.Zero) {
LogError(LogCategory.Render, "Texture is null");
}
- SDL_GetTextureAlphaMod(texture, out byte alpha);
+ SDL_GetTextureAlphaMod(texture, out var alpha);
return alpha;
}
@@ -143,7 +143,7 @@ public static float GetTextureAlphaModFloat(nint texture) {
if (texture == nint.Zero) {
LogError(LogCategory.Render, "Texture is null");
}
- SDL_GetTextureAlphaModFloat(texture, out float alpha);
+ SDL_GetTextureAlphaModFloat(texture, out var alpha);
return alpha;
}
@@ -191,7 +191,7 @@ public static Color GetTextureColorMod(nint texture) {
if (texture == nint.Zero) {
LogError(LogCategory.Render, "Texture is null");
}
- SDL_GetTextureColorMod(texture, out byte r, out byte g, out byte b);
+ SDL_GetTextureColorMod(texture, out var r, out var g, out var b);
return new Color() { R = r, G = g, B = b };
}
@@ -221,7 +221,7 @@ public static FColor GetTextureColorModFloat(nint texture) {
if (texture == nint.Zero) {
LogError(LogCategory.Render, "Texture is null");
}
- SDL_GetTextureColorModFloat(texture, out float r, out float g, out float b);
+ SDL_GetTextureColorModFloat(texture, out var r, out var g, out var b);
return new FColor() { R = r, G = g, B = b };
}
@@ -264,7 +264,7 @@ public static ScaleMode GetTextureScaleMode(nint texture) {
if (texture == nint.Zero) {
LogError(LogCategory.Render, "Texture is null");
}
- SDL_GetTextureScaleMode(texture, out ScaleMode scaleMode);
+ SDL_GetTextureScaleMode(texture, out var scaleMode);
return scaleMode;
}
@@ -290,8 +290,8 @@ public static Vector2 GetTextureSize(nint texture) {
if (texture == nint.Zero) {
LogError(LogCategory.Render, "Texture is null");
}
- SDL_GetTextureSize(texture, out float w, out float h);
- return new(w, h);
+ SDL_GetTextureSize(texture, out var w, out var h);
+ return new Vector2(w, h);
}
/// Lock a portion of the texture for write-only pixel access.
@@ -343,7 +343,7 @@ public static bool LockTexture(nint texture, nint rect, out nint pixels,
if (texture == nint.Zero) {
LogError(LogCategory.Render, "Texture is null");
}
- Rect trect = Marshal.PtrToStructure(rect);
+ var trect = Marshal.PtrToStructure(rect);
return SDL_LockTexture(texture, ref trect, out pixels, out pitch);
}
diff --git a/SDL3/Timer.cs b/SDL3/SDL/Timer.cs
similarity index 95%
rename from SDL3/Timer.cs
rename to SDL3/SDL/Timer.cs
index 9d7bf7f..8b159f2 100644
--- a/SDL3/Timer.cs
+++ b/SDL3/SDL/Timer.cs
@@ -33,7 +33,7 @@ public static uint AddTimer(uint interval, SdlTimerCallback callback, nint userd
throw new ArgumentException("Interval must be greater than zero.", nameof(interval));
}
- uint timerId = SDL_AddTimer(interval, callback, userdata);
+ var timerId = SDL_AddTimer(interval, callback, userdata);
return timerId == 0 ? throw new InvalidOperationException("Failed to add timer. SDL_AddTimer returned 0.") : timerId;
}
@@ -62,7 +62,7 @@ public static uint AddTimerNs(ulong interval, SdlNsTimerCallback callback, nint
throw new ArgumentException("Interval must be greater than zero.", nameof(interval));
}
- uint timerId = SDL_AddTimerNS(interval, callback, userdata);
+ var timerId = SDL_AddTimerNS(interval, callback, userdata);
return timerId == 0 ? throw new InvalidOperationException("Failed to add timer. SDL_AddTimerNS returned 0.") : timerId;
}
@@ -84,9 +84,9 @@ public static void Delay(uint ms) {
throw new ArgumentException("Delay duration must be greater than zero.", nameof(ms));
}
- ulong start = GetTicks();
+ var start = GetTicks();
SDL_Delay(ms);
- ulong end = GetTicks();
+ var end = GetTicks();
if (end - start < ms) {
throw new InvalidOperationException("Delay did not delay for the expected duration.");
@@ -109,9 +109,9 @@ public static void DelayNs(ulong ns) {
throw new ArgumentException("Delay duration must be greater than zero.", nameof(ns));
}
- ulong start = GetTicksNs();
+ var start = GetTicksNs();
SDL_DelayNS(ns);
- ulong end = GetTicksNs();
+ var end = GetTicksNs();
if (end - start < ns) {
throw new InvalidOperationException("DelayNS did not delay for the expected duration.");
@@ -135,9 +135,9 @@ public static void DelayPrecise(ulong ns) {
throw new ArgumentException("Delay duration must be greater than zero.", nameof(ns));
}
- ulong start = GetTicksNs();
+ var start = GetTicksNs();
SDL_DelayPrecise(ns);
- ulong end = GetTicksNs();
+ var end = GetTicksNs();
if (end - start < ns) {
throw new InvalidOperationException("DelayPrecise did not delay for the expected duration.");
diff --git a/SDL3/Touch.cs b/SDL3/SDL/Touch.cs
similarity index 86%
rename from SDL3/Touch.cs
rename to SDL3/SDL/Touch.cs
index 740a577..ce0a313 100644
--- a/SDL3/Touch.cs
+++ b/SDL3/SDL/Touch.cs
@@ -6,10 +6,9 @@
namespace SharpSDL3;
-public static unsafe partial class Sdl {
+public static partial class Sdl {
/// Get the touch device name as reported from the driver.
-
- /// the touch device instance ID.
+ /// the touch device instance ID.
///
/// Version: This function is available since SDL 3.2.0.
///
@@ -20,7 +19,7 @@ public static string GetTouchDeviceName(ulong touchId) {
throw new ArgumentException("Touch ID cannot be zero.", nameof(touchId));
}
- string deviceName = SDL_GetTouchDeviceName(touchId);
+ var deviceName = SDL_GetTouchDeviceName(touchId);
if (string.IsNullOrEmpty(deviceName)) {
throw new InvalidOperationException($"Failed to retrieve the name for touch device with ID {touchId}.");
@@ -30,8 +29,6 @@ public static string GetTouchDeviceName(ulong touchId) {
}
/// Get a list of registered touch devices.
-
- /// a pointer filled in with the number of devices returned, may be discarded.
///
/// On some platforms SDL first sees the touch device if it was actually used.
/// Therefore the returned list might be empty, although devices are available.
@@ -41,21 +38,20 @@ public static string GetTouchDeviceName(ulong touchId) {
/// (SDL_TouchID *) Returns a 0 terminated array of touch deviceIDs or on failure; call for more information. This should be freed with when it is no longer needed.
public static Span GetTouchDevices() {
- nint result = SDL_GetTouchDevices(out int count);
+ var result = SDL_GetTouchDevices(out var count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to retrieve touch devices.");
}
- nint[] data = new nint[count];
+ var data = new nint[count];
Marshal.Copy(result, data, 0, count);
return data;
}
/// Get the type of the given touch device.
-
- /// the ID of a touch device.
+ /// the ID of a touch device.
///
/// Version: This function is available since SDL 3.2.0.
///
@@ -65,7 +61,7 @@ public static TouchDeviceType GetTouchDeviceType(ulong touchId) {
if (touchId == 0) {
throw new ArgumentException("Touch ID cannot be zero.", nameof(touchId));
}
- TouchDeviceType deviceType = SDL_GetTouchDeviceType(touchId);
+ var deviceType = SDL_GetTouchDeviceType(touchId);
if (deviceType == TouchDeviceType.Invalid) {
throw new InvalidOperationException($"Failed to retrieve the type for touch device with ID {touchId}.");
}
@@ -82,12 +78,12 @@ public static TouchDeviceType GetTouchDeviceType(ulong touchId) {
/// (SDL_Finger **) Returns a terminated array ofSDL_Finger pointers or on failure; call for more information. This is a single allocation that should be freed with when it is no longer needed.
public static Span GetTouchFingers(ulong touchId) {
- nint result = SDL_GetTouchFingers(touchId, out int count);
+ var result = SDL_GetTouchFingers(touchId, out var count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to retrieve touch devices.");
}
- nint[] data = new nint[count];
+ var data = new nint[count];
Marshal.Copy(result, data, 0, count);
return data;
@@ -103,12 +99,12 @@ public static Span GetTouchFingers(ulong touchId) {
/// (SDL_Finger **) Returns a terminated array ofSDL_Finger pointers or on failure; call for more information. This is a single allocation that should be freed with when it is no longer needed.
public static Span GetTouchFingers(ulong touchId, out int count) {
- nint result = SDL_GetTouchFingers(touchId, out count);
+ var result = SDL_GetTouchFingers(touchId, out count);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to retrieve touch devices.");
}
- nint[] data = new nint[count];
+ var data = new nint[count];
Marshal.Copy(result, data, 0, count);
return data;
diff --git a/SDL3/Tray.cs b/SDL3/SDL/Tray.cs
similarity index 93%
rename from SDL3/Tray.cs
rename to SDL3/SDL/Tray.cs
index 5fb178a..7b9e109 100644
--- a/SDL3/Tray.cs
+++ b/SDL3/SDL/Tray.cs
@@ -8,15 +8,14 @@
namespace SharpSDL3;
-public static unsafe partial class Sdl {
- /// Simulate a click on a tray entry.
+public static partial class Sdl {
+ /// Simulate a click on a tray entry.
/// The entry to activate.
///
/// Thread Safety: This function should be called on the thread that created the tray.
/// Version: This function is available since SDL 3.2.0.
///
-
public static void ClickTrayEntry(nint entry) {
if (entry == nint.Zero) {
throw new ArgumentNullException(nameof(entry), "Entry cannot be null.");
@@ -25,7 +24,6 @@ public static void ClickTrayEntry(nint entry) {
}
/// Create an icon to be placed in the operating system's tray, or equivalent.
-
/// a surface to be used as icon. May be .
/// a tooltip to be displayed when the mouse hovers the icon in UTF-8 encoding. Not supported on all platforms. May be .
///
@@ -39,7 +37,6 @@ public static void ClickTrayEntry(nint entry) {
///
///
/// (SDL_Tray *) Returns The newly created system tray icon.
-
public static nint CreateTray(nint icon, string tooltip) {
if (icon == nint.Zero) {
throw new ArgumentNullException(nameof(icon), "Icon cannot be null.");
@@ -47,7 +44,7 @@ public static nint CreateTray(nint icon, string tooltip) {
if (string.IsNullOrWhiteSpace(tooltip)) {
throw new ArgumentException("Tooltip cannot be null or empty.", nameof(tooltip));
}
- nint tray = SDL_CreateTray(icon, tooltip);
+ var tray = SDL_CreateTray(icon, tooltip);
if (tray == nint.Zero) {
LogError(LogCategory.Error, "Failed to create tray.");
}
@@ -55,7 +52,6 @@ public static nint CreateTray(nint icon, string tooltip) {
}
/// Create a menu for a system tray.
-
/// the tray to bind the menu to.
///
/// This should be called at most once per tray icon.
@@ -66,12 +62,11 @@ public static nint CreateTray(nint icon, string tooltip) {
///
///
/// (SDL_TrayMenu *) Returns the newly created menu.
-
public static nint CreateTrayMenu(nint tray) {
if (tray == nint.Zero) {
throw new ArgumentNullException(nameof(tray), "Tray cannot be null.");
}
- nint menu = SDL_CreateTrayMenu(tray);
+ var menu = SDL_CreateTrayMenu(tray);
if (menu == nint.Zero) {
LogError(LogCategory.Error, "Failed to create tray menu.");
}
@@ -79,7 +74,6 @@ public static nint CreateTrayMenu(nint tray) {
}
/// Create a submenu for a system tray entry.
-
/// the tray entry to bind the menu to.
///
/// This should be called at most once per tray entry.
@@ -90,12 +84,11 @@ public static nint CreateTrayMenu(nint tray) {
///
///
/// (SDL_TrayMenu *) Returns the newly created menu.
-
public static nint CreateTraySubmenu(nint entry) {
if (entry == nint.Zero) {
throw new ArgumentNullException(nameof(entry), "Entry cannot be null.");
}
- nint submenu = SDL_CreateTraySubmenu(entry);
+ var submenu = SDL_CreateTraySubmenu(entry);
if (submenu == nint.Zero) {
LogError(LogCategory.Error, "Failed to create tray submenu.");
}
@@ -103,7 +96,6 @@ public static nint CreateTraySubmenu(nint entry) {
}
/// Destroys a tray object.
-
/// the tray icon to be destroyed.
///
/// This also destroys all associated menus and entries.
@@ -120,9 +112,7 @@ public static void DestroyTray(nint tray) {
}
/// Returns a list of entries in the menu, in order.
-
/// The menu to get entries from.
- /// An optional pointer to obtain the number of entries in the menu.
///
/// Thread Safety: This function should be called on the thread that created the tray.
/// Version: This function is available since SDL 3.2.0.
@@ -130,34 +120,33 @@ public static void DestroyTray(nint tray) {
///
///
/// (const SDL_TrayEntry **) Returns a -terminated list ofentries within the given menu. The pointer becomes invalid when anyfunction that inserts or deletes entries in the menu is called.
-
public static Span GetTrayEntries(nint menu) {
- nint result = SDL_GetTrayEntries(menu, out int size);
+ var result = SDL_GetTrayEntries(menu, out var size);
if (result == nint.Zero) {
LogError(LogCategory.Error, "Failed to get tray entries.");
return [];
}
- if (size < 0) {
- LogError(LogCategory.Error, "Invalid size returned for tray entries.");
- return [];
- }
- if (size == 0) {
- return [];
+ switch (size)
+ {
+ case < 0:
+ LogError(LogCategory.Error, "Invalid size returned for tray entries.");
+ return [];
+ case 0:
+ return [];
}
- nint[] entries = new nint[size];
+ var entries = new nint[size];
Marshal.Copy(result, entries, 0, size);
- Span array = new(ref result);
+ Span array = new Span(ref result);
return array.ToArray();
}
/// Gets whether or not an entry is checked.
-
/// the entry to be read.
///
/// The entry must have been created with the
@@ -169,7 +158,6 @@ public static Span GetTrayEntries(nint menu) {
///
///
/// Returns if the entry is checked; otherwise.
-
public static bool GetTrayEntryChecked(nint entry) {
if (entry == nint.Zero) {
throw new ArgumentNullException(nameof(entry), "Entry cannot be null.");
@@ -182,7 +170,6 @@ public static bool GetTrayEntryChecked(nint entry) {
}
/// Gets whether or not an entry is enabled.
-
/// the entry to be read.
///
/// Thread Safety: This function should be called on the thread that created the tray.
@@ -192,7 +179,6 @@ public static bool GetTrayEntryChecked(nint entry) {
///
///
/// Returns if the entry is enabled; otherwise.
-
public static bool GetTrayEntryEnabled(nint entry) {
if (entry == nint.Zero) {
throw new ArgumentNullException(nameof(entry), "Entry cannot be null.");
@@ -205,7 +191,6 @@ public static bool GetTrayEntryEnabled(nint entry) {
}
/// Gets the label of an entry.
-
/// the entry to be read.
///
/// If the returned value is , the entry is a separator.
@@ -216,12 +201,11 @@ public static bool GetTrayEntryEnabled(nint entry) {
///
///
/// Returns the label of the entry in UTF-8 encoding.
-
public static string GetTrayEntryLabel(nint entry) {
if (entry == nint.Zero) {
throw new ArgumentNullException(nameof(entry), "Entry cannot be null.");
}
- string label = SDL_GetTrayEntryLabel(entry);
+ var label = SDL_GetTrayEntryLabel(entry);
if (string.IsNullOrEmpty(label)) {
LogError(LogCategory.Error, "Failed to get tray entry label.");
}
@@ -229,7 +213,6 @@ public static string GetTrayEntryLabel(nint entry) {
}
/// Gets the menu containing a certain tray entry.
-
/// the entry for which to get the parent menu.
///
/// Thread Safety: This function should be called on the thread that created the tray.
@@ -237,12 +220,11 @@ public static string GetTrayEntryLabel(nint entry) {
///
///
/// (SDL_TrayMenu *) Returns the parent menu.
-
public static nint GetTrayEntryParent(nint entry) {
if (entry == nint.Zero) {
throw new ArgumentNullException(nameof(entry), "Entry cannot be null.");
}
- nint parent = SDL_GetTrayEntryParent(entry);
+ var parent = SDL_GetTrayEntryParent(entry);
if (parent == nint.Zero) {
LogError(LogCategory.Error, "Failed to get tray entry parent.");
}
@@ -250,7 +232,6 @@ public static nint GetTrayEntryParent(nint entry) {
}
/// Gets a previously created tray menu.
-
/// the tray entry to bind the menu to.
///
/// You should have called SDL_CreateTrayMenu() on the
@@ -261,12 +242,11 @@ public static nint GetTrayEntryParent(nint entry) {
///
///
/// (SDL_TrayMenu *) Returns the newly created menu.
-
public static nint GetTrayMenu(nint tray) {
if (tray == nint.Zero) {
throw new ArgumentNullException(nameof(tray), "Tray cannot be null.");
}
- nint menu = SDL_GetTrayMenu(tray);
+ var menu = SDL_GetTrayMenu(tray);
if (menu == nint.Zero) {
LogError(LogCategory.Error, "Failed to get tray menu.");
}
@@ -274,7 +254,6 @@ public static nint GetTrayMenu(nint tray) {
}
/// Gets the entry for which the menu is a submenu, if the current menu is a submenu.
-
/// the menu for which to get the parent entry.
///
/// Either this function or
@@ -286,12 +265,11 @@ public static nint GetTrayMenu(nint tray) {
///
///
/// (SDL_TrayEntry *) Returns the parent entry, or ifthis menu is not a submenu.
-
public static nint GetTrayMenuParentEntry(nint menu) {
if (menu == nint.Zero) {
throw new ArgumentNullException(nameof(menu), "Menu cannot be null.");
}
- nint parentEntry = SDL_GetTrayMenuParentEntry(menu);
+ var parentEntry = SDL_GetTrayMenuParentEntry(menu);
if (parentEntry == nint.Zero) {
LogError(LogCategory.Error, "Failed to get tray menu parent entry.");
}
@@ -299,7 +277,6 @@ public static nint GetTrayMenuParentEntry(nint menu) {
}
/// Gets the tray for which this menu is the first-level menu, if the current menu isn't a submenu.
-
/// the menu for which to get the parent enttrayry.
///
/// Either this function or
@@ -311,12 +288,11 @@ public static nint GetTrayMenuParentEntry(nint menu) {
///
///
/// (SDL_Tray *) Returns the parent tray, or if this menu is asubmenu.
-
public static nint GetTrayMenuParentTray(nint menu) {
if (menu == nint.Zero) {
throw new ArgumentNullException(nameof(menu), "Menu cannot be null.");
}
- nint parentTray = SDL_GetTrayMenuParentTray(menu);
+ var parentTray = SDL_GetTrayMenuParentTray(menu);
if (parentTray == nint.Zero) {
LogError(LogCategory.Error, "Failed to get tray menu parent tray.");
}
@@ -324,7 +300,6 @@ public static nint GetTrayMenuParentTray(nint menu) {
}
/// Gets a previously created tray entry submenu.
-
/// the tray entry to bind the menu to.
///
/// You should have called SDL_CreateTraySubmenu() on
@@ -335,12 +310,11 @@ public static nint GetTrayMenuParentTray(nint menu) {
///
///
/// (SDL_TrayMenu *) Returns the newly created menu.
-
public static nint GetTraySubmenu(nint entry) {
if (entry == nint.Zero) {
throw new ArgumentNullException(nameof(entry), "Entry cannot be null.");
}
- nint submenu = SDL_GetTraySubmenu(entry);
+ var submenu = SDL_GetTraySubmenu(entry);
if (submenu == nint.Zero) {
LogError(LogCategory.Error, "Failed to get tray submenu.");
}
@@ -348,7 +322,6 @@ public static nint GetTraySubmenu(nint entry) {
}
/// Insert a tray entry at a given position.
-
/// the menu to append the entry to.
/// the desired position for the new entry. Entries at or following this place will be moved. If pos is -1, the entry is appended.
/// the text to be displayed on the entry, in UTF-8 encoding, or for a separator.
@@ -364,7 +337,6 @@ public static nint GetTraySubmenu(nint entry) {
///
///
/// (SDL_TrayEntry *) Returns the newly created entry, or if pos is out of bounds.
-
public static nint InsertTrayEntryAt(nint menu, int pos, string label, TrayEntryFlags flags) {
if (menu == nint.Zero) {
throw new ArgumentNullException(nameof(menu), "Menu cannot be null.");
@@ -372,7 +344,7 @@ public static nint InsertTrayEntryAt(nint menu, int pos, string label, TrayEntry
if (string.IsNullOrWhiteSpace(label)) {
throw new ArgumentException("Label cannot be null or empty.", nameof(label));
}
- nint entry = SDL_InsertTrayEntryAt(menu, pos, label, flags);
+ var entry = SDL_InsertTrayEntryAt(menu, pos, label, flags);
if (entry == nint.Zero) {
LogError(LogCategory.Error, $"Failed to insert tray entry at position {pos}.");
}
@@ -380,7 +352,6 @@ public static nint InsertTrayEntryAt(nint menu, int pos, string label, TrayEntry
}
/// Removes a tray entry.
-
/// The entry to be deleted.
///
/// Thread Safety: This function should be called on the thread that created the tray.
@@ -388,7 +359,6 @@ public static nint InsertTrayEntryAt(nint menu, int pos, string label, TrayEntry
///
///
///
-
public static void RemoveTrayEntry(nint entry) {
if (entry == nint.Zero) {
throw new ArgumentNullException(nameof(entry), "Entry cannot be null.");
@@ -397,7 +367,6 @@ public static void RemoveTrayEntry(nint entry) {
}
/// Sets a callback to be invoked when the entry is selected.
-
/// the entry to be updated.
/// a callback to be invoked when the entry is selected.
/// an optional pointer to pass extra data to the callback when it will be invoked.
@@ -407,7 +376,6 @@ public static void RemoveTrayEntry(nint entry) {
///
///
///
-
public static void SetTrayEntryCallback(nint entry, SdlTrayCallback callback, nint userdata) {
if (entry == nint.Zero) {
throw new ArgumentNullException(nameof(entry), "Entry cannot be null.");
@@ -419,9 +387,8 @@ public static void SetTrayEntryCallback(nint entry, SdlTrayCallback callback, ni
}
/// Sets whether or not an entry is checked.
-
/// the entry to be updated.
- /// if the entry should be checked; otherwise.
+ /// if the entry should be checked; otherwise.
///
/// The entry must have been created with the
/// SDL_TRAYENTRY_CHECKBOX flag.
@@ -431,7 +398,6 @@ public static void SetTrayEntryCallback(nint entry, SdlTrayCallback callback, ni
///
///
///
-
public static void SetTrayEntryChecked(nint entry, bool check) {
if (entry == nint.Zero) {
throw new ArgumentNullException(nameof(entry), "Entry cannot be null.");
@@ -440,7 +406,6 @@ public static void SetTrayEntryChecked(nint entry, bool check) {
}
/// Sets whether or not an entry is enabled.
-
/// the entry to be updated.
/// if the entry should be enabled; otherwise.
///
@@ -450,16 +415,14 @@ public static void SetTrayEntryChecked(nint entry, bool check) {
///
///
///
-
public static void SetTrayEntryEnabled(nint entry, bool enabled) {
if (entry == nint.Zero) {
throw new ArgumentNullException(nameof(entry), "Entry cannot be null.");
}
SDL_SetTrayEntryEnabled(entry, enabled);
}
-
+
/// Sets the label of an entry.
-
/// the entry to be updated.
/// the new label for the entry in UTF-8 encoding.
///
@@ -473,7 +436,6 @@ public static void SetTrayEntryEnabled(nint entry, bool enabled) {
///
///
///
-
public static void SetTrayEntryLabel(nint entry, string label) {
if (entry == nint.Zero) {
throw new ArgumentNullException(nameof(entry), "Entry cannot be null.");
@@ -485,7 +447,6 @@ public static void SetTrayEntryLabel(nint entry, string label) {
}
/// Updates the system tray icon's icon.
-
/// the tray icon to be updated.
/// the new icon. May be .
///
@@ -493,7 +454,6 @@ public static void SetTrayEntryLabel(nint entry, string label) {
/// Version: This function is available since SDL 3.2.0.
///
///
-
public static void SetTrayIcon(nint tray, nint icon) {
if (tray == nint.Zero) {
throw new ArgumentNullException(nameof(tray), "Tray cannot be null.");
@@ -505,7 +465,6 @@ public static void SetTrayIcon(nint tray, nint icon) {
}
/// Updates the system tray icon's tooltip.
-
/// the tray icon to be updated.
/// the new tooltip in UTF-8 encoding. May be .
///
@@ -513,7 +472,6 @@ public static void SetTrayIcon(nint tray, nint icon) {
/// Version: This function is available since SDL 3.2.0.
///
///
-
public static void SetTrayTooltip(nint tray, string tooltip) {
if (tray == nint.Zero) {
throw new ArgumentNullException(nameof(tray), "Tray cannot be null.");
diff --git a/SDL3/Version.cs b/SDL3/SDL/Version.cs
similarity index 97%
rename from SDL3/Version.cs
rename to SDL3/SDL/Version.cs
index 7598e9a..e0d88d6 100644
--- a/SDL3/Version.cs
+++ b/SDL3/SDL/Version.cs
@@ -16,7 +16,6 @@ public static partial class Sdl {
///
///
/// Returns an arbitrary string, uniquely identifying the exactrevision of the SDL library in use.
-
public static string GetRevision() {
return SDL_GetRevision();
}
diff --git a/SDL3/SharpSDL3.csproj b/SDL3/SharpSDL3.csproj
index f2b7ac7..318236c 100644
--- a/SDL3/SharpSDL3.csproj
+++ b/SDL3/SharpSDL3.csproj
@@ -1,7 +1,7 @@
- net9.0
+ net10.0
True
AnyCPU;x64
diff --git a/SDL3/TTF/Ttf.cs b/SDL3/TTF/Ttf.cs
index 2a71f08..7eaebe6 100644
--- a/SDL3/TTF/Ttf.cs
+++ b/SDL3/TTF/Ttf.cs
@@ -143,7 +143,7 @@ public static void CloseFont(Font font) {
///
/// (TTF_Font *) Returns a valid TTF_Font, or on failure; call for more information.
public static Font CopyFont(Font existingFont) {
- Font font = TTF_CopyFont(existingFont.Handle);
+ var font = TTF_CopyFont(existingFont.Handle);
return font;
}
@@ -163,11 +163,11 @@ public static TextEngine CreateGpuTextEngine(nint device) {
if (device == nint.Zero) {
throw new ArgumentNullException(nameof(device), "Device cannot be null.");
}
- nint tePtr = TTF_CreateGPUTextEngine(device);
+ var tePtr = TTF_CreateGPUTextEngine(device);
if (tePtr == nint.Zero) {
throw new InvalidOperationException($"Failed to create renderer text engine. SDL Error: {Sdl.GetError()}");
}
- TextEngine engine = *(TextEngine*)tePtr;
+ var engine = *(TextEngine*)tePtr;
engine.Handle = tePtr;
return engine;
}
@@ -208,11 +208,11 @@ public static unsafe TextEngine CreateRendererTextEngine(nint renderer) {
if (renderer == nint.Zero) {
throw new ArgumentNullException(nameof(renderer), "Renderer cannot be null.");
}
- nint tePtr = TTF_CreateRendererTextEngine(renderer);
+ var tePtr = TTF_CreateRendererTextEngine(renderer);
if (tePtr == nint.Zero) {
throw new InvalidOperationException($"Failed to create renderer text engine. SDL Error: {Sdl.GetError()}");
}
- TextEngine engine = *(TextEngine*)tePtr;
+ var engine = *(TextEngine*)tePtr;
engine.Handle = tePtr;
return engine;
}
@@ -234,12 +234,12 @@ public static unsafe TextEngine CreateRendererTextEngineWithProperties(int props
if (props == 0) {
throw new ArgumentNullException(nameof(props), "Properties cannot be null.");
}
- nint tePtr = TTF_CreateRendererTextEngineWithProperties(props);
+ var tePtr = TTF_CreateRendererTextEngineWithProperties(props);
if (tePtr == nint.Zero) {
throw new InvalidOperationException($"Failed to create renderer text engine. SDL Error: {Sdl.GetError()}");
}
- TextEngine engine = *(TextEngine*)tePtr;
+ var engine = *(TextEngine*)tePtr;
engine.Handle = tePtr;
return engine;
@@ -255,11 +255,11 @@ public static unsafe TextEngine CreateRendererTextEngineWithProperties(int props
/// (TTF_TextEngine *) Returns aTTF_TextEngine object or on failure; call for more information.
public static unsafe TextEngine CreateSurfaceTextEngine() {
- nint tePtr = TTF_CreateSurfaceTextEngine();
+ var tePtr = TTF_CreateSurfaceTextEngine();
if (tePtr == nint.Zero) {
throw new InvalidOperationException($"Failed to create surface text engine. SDL Error: {Sdl.GetError()}");
}
- TextEngine engine = *(TextEngine*)tePtr;
+ var engine = *(TextEngine*)tePtr;
engine.Handle = tePtr;
return engine;
}
@@ -277,7 +277,7 @@ public static unsafe TextEngine CreateSurfaceTextEngine() {
/// (TTF_Text *) Returns a object or on failure; call for more information.
public static Text CreateText(TextEngine engine, Font font, string text, int length) {
ArgumentException.ThrowIfNullOrEmpty(text);
- nint tPtr = TTF_CreateText(engine.Handle, font.Handle, text, (nuint)length);
+ var tPtr = TTF_CreateText(engine.Handle, font.Handle, text, (nuint)length);
if (tPtr == nint.Zero) {
throw new InvalidOperationException($"Failed to create text. SDL Error: {Sdl.GetError()}");
}
@@ -477,7 +477,7 @@ public static bool FontHasGlyph(Font font, int ch) {
/// Returns the font's ascent.
public static int GetFontAscent(Font font) {
- int result = TTF_GetFontAscent(font.Handle);
+ var result = TTF_GetFontAscent(font.Handle);
if (result < 0) {
Sdl.LogError(LogCategory.Error, $"Failed to get font ascent. SDL Error: {Sdl.GetError()}");
return 0;
@@ -515,8 +515,8 @@ public static Direction GetFontDirection(Font font) {
}
public static bool GetFontDpi(Font font, out int hdpi, out int vdpi) {
- nint pHdpi = Sdl.Malloc(4);
- nint pVdpi = Sdl.Malloc(4);
+ var pHdpi = Sdl.Malloc(4);
+ var pVdpi = Sdl.Malloc(4);
bool result = TTF_GetFontDPI(font.Handle, pHdpi, pVdpi);
@@ -550,11 +550,11 @@ public static bool GetFontDpi(Font font, out int hdpi, out int vdpi) {
/// Returns on success or on failure; call for more information.
public static Size GetFontDpi(Font font) {
- if (GetFontDpi(font, out int hdpi, out int vdpi)) {
+ if (GetFontDpi(font, out var hdpi, out var vdpi)) {
return new Size(hdpi, vdpi);
}
- return new();
+ return new Size();
}
/// Query a font's family name.
@@ -568,7 +568,7 @@ public static Size GetFontDpi(Font font) {
/// Returns the font's family name.
public static string GetFontFamilyName(Font font) {
- string result = TTF_GetFontFamilyName(font.Handle);
+ var result = TTF_GetFontFamilyName(font.Handle);
if (string.IsNullOrEmpty(result)) {
Sdl.LogError(LogCategory.System, $"Failed to get font family name. SDL Error: {Sdl.GetError()}");
}
@@ -587,7 +587,7 @@ public static string GetFontFamilyName(Font font) {
/// Returns the font generation or 0 on failure; call for more information.
public static int GetFontGeneration(Font font) {
- int generation = TTF_GetFontGeneration(font.Handle);
+ var generation = TTF_GetFontGeneration(font.Handle);
if (generation == 0) {
Sdl.LogError(LogCategory.Error, $"Failed to get font generation. SDL Error: {Sdl.GetError()}");
}
@@ -605,7 +605,7 @@ public static int GetFontGeneration(Font font) {
/// Returns the font's height.
public static int GetFontHeight(Font font) {
- int result = TTF_GetFontHeight(font.Handle);
+ var result = TTF_GetFontHeight(font.Handle);
if (result < 0) {
Sdl.LogError(LogCategory.Error, $"Failed to get font height. SDL Error: {Sdl.GetError()}");
return 0;
@@ -671,7 +671,7 @@ public static int GetFontLineSkip(Font font) {
/// Returns the font's current outline value.
public static int GetFontOutline(Font font) {
- int result = TTF_GetFontOutline(font.Handle);
+ var result = TTF_GetFontOutline(font.Handle);
if (result < 0) {
Sdl.LogError(LogCategory.Error, $"Failed to get font outline. SDL Error: {Sdl.GetError()}");
return 0;
@@ -690,7 +690,7 @@ public static int GetFontOutline(Font font) {
/// Returns a valid property ID on success or 0 on failure;call for more information.
public static int GetFontProperties(Font font) {
- int props = TTF_GetFontProperties(font.Handle);
+ var props = TTF_GetFontProperties(font.Handle);
if (props == 0) {
throw new InvalidOperationException($"Failed to get font properties. SDL Error: {Sdl.GetError()}");
}
@@ -735,7 +735,7 @@ public static bool GetFontSdf(Font font) {
///
/// Returns the size of the font, or 0.0f on failure; call for more information.
public static float GetFontSize(Font font) {
- float size = TTF_GetFontSize(font.Handle);
+ var size = TTF_GetFontSize(font.Handle);
if (size <= 0.01f) {
Sdl.LogError(LogCategory.Error, $"Failed to get font size. SDL Error: {Sdl.GetError()}");
}
@@ -768,7 +768,7 @@ public static FontStyle GetFontStyle(Font font) {
/// Returns the font's style name.
public static string GetFontStyleName(Font font) {
- string result = TTF_GetFontStyleName(font.Handle);
+ var result = TTF_GetFontStyleName(font.Handle);
if (string.IsNullOrEmpty(result)) {
Sdl.LogError(LogCategory.System, $"Failed to get font style name. SDL Error: {Sdl.GetError()}");
}
@@ -815,9 +815,9 @@ public static HorizontalAlignment GetFontWrapAlignment(Font font) {
///
public static void GetFreeTypeVersion(out int major, out int minor, out int patch) {
- nint ma = Sdl.Malloc(4);
- nint mi = Sdl.Malloc(4);
- nint pa = Sdl.Malloc(4);
+ var ma = Sdl.Malloc(4);
+ var mi = Sdl.Malloc(4);
+ var pa = Sdl.Malloc(4);
TTF_GetFreeTypeVersion(ma, mi, pa);
major = Marshal.ReadInt32(ma);
@@ -928,7 +928,7 @@ public static int GetGlyphScript(int ch) {
throw new ArgumentOutOfRangeException(nameof(ch), "The character code must be a valid Unicode code point.");
}
- int script = TTF_GetGlyphScript(ch);
+ var script = TTF_GetGlyphScript(ch);
if (script == 0) {
Sdl.LogError(LogCategory.Error, $"Failed to get glyph script for character {ch}. SDL Error: {Sdl.GetError()}");
@@ -986,9 +986,9 @@ public static GpuTextEngineWinding GetGpuTextEngineWinding(nint engine) {
///
public static void GetHarfBuzzVersion(out int major, out int minor, out int patch) {
- nint ma = Sdl.Malloc(4);
- nint mi = Sdl.Malloc(4);
- nint pa = Sdl.Malloc(4);
+ var ma = Sdl.Malloc(4);
+ var mi = Sdl.Malloc(4);
+ var pa = Sdl.Malloc(4);
major = Marshal.ReadInt32(ma);
minor = Marshal.ReadInt32(mi);
patch = Marshal.ReadInt32(pa);
@@ -1016,16 +1016,16 @@ public static void GetHarfBuzzVersion(out int major, out int minor, out int patc
public static unsafe bool GetNextTextSubString(Text text, SubString substring, out SubString next) {
if (text.Handle == nint.Zero) {
Sdl.LogError(LogCategory.Error, "Text cannot be null.");
- next = new();
+ next = new SubString();
return false;
}
if (substring.Handle == nint.Zero) {
Sdl.LogError(LogCategory.Error, "Substring cannot be null.");
- next = new();
+ next = new SubString();
return false;
}
- nint pNext = Sdl.Malloc(Sdl.SizeOf());
+ var pNext = Sdl.Malloc(Sdl.SizeOf());
try {
bool result = TTF_GetNextTextSubString(text.Handle, substring.Handle, pNext);
@@ -1054,7 +1054,7 @@ public static unsafe bool GetNextTextSubString(Text text, SubString substring, o
/// Returns on success or on failure; call for more information.
public static SubString GetNextTextSubString(Text text, SubString substring) {
- _ = GetNextTextSubString(text, substring, out SubString next);
+ _ = GetNextTextSubString(text, substring, out var next);
return next;
}
@@ -1068,7 +1068,7 @@ public static SubString GetNextTextSubString(Text text, SubString substring) {
/// Returns the number of FreeType font faces.
public static int GetNumFontFaces(Font font) {
- int result = TTF_GetNumFontFaces(font.Handle);
+ var result = TTF_GetNumFontFaces(font.Handle);
if (result < 0) {
Sdl.LogError(LogCategory.Error, $"Failed to get number of font faces. SDL Error: {Sdl.GetError()}");
return 0;
@@ -1092,17 +1092,17 @@ public static int GetNumFontFaces(Font font) {
public static unsafe bool GetPreviousTextSubString(Text text, SubString substring, out SubString previous) {
if (text.Handle == nint.Zero) {
Sdl.LogError(LogCategory.Error, "Text cannot be null.");
- previous = new();
+ previous = new SubString();
return false;
}
if (substring.Handle == nint.Zero) {
Sdl.LogError(LogCategory.Error, "Substring cannot be null.");
- previous = new();
+ previous = new SubString();
return false;
}
- nint pPrevious = Sdl.Malloc(Sdl.SizeOf());
+ var pPrevious = Sdl.Malloc(Sdl.SizeOf());
try {
bool result = TTF_GetPreviousTextSubString(text.Handle, substring.Handle, pPrevious);
if (!result) {
@@ -1129,7 +1129,7 @@ public static unsafe bool GetPreviousTextSubString(Text text, SubString substrin
/// Returns on success or on failure; call for more information.
public static SubString GetPreviousTextSubString(Text text, SubString substring) {
- _ = GetPreviousTextSubString(text, substring, out SubString previous);
+ _ = GetPreviousTextSubString(text, substring, out var previous);
return previous;
}
@@ -1216,10 +1216,10 @@ public static bool GetTextColor(Text text, out byte r, out byte g, out byte b, o
if (text.Handle == nint.Zero) {
throw new ArgumentNullException(nameof(text), "Text cannot be null.");
}
- nint pr = Sdl.Malloc(1);
- nint pg = Sdl.Malloc(1);
- nint pb = Sdl.Malloc(1);
- nint pa = Sdl.Malloc(1);
+ var pr = Sdl.Malloc(1);
+ var pg = Sdl.Malloc(1);
+ var pb = Sdl.Malloc(1);
+ var pa = Sdl.Malloc(1);
try {
bool result = TTF_GetTextColor(text.Handle, pr, pg, pb, pa);
if (!result) {
@@ -1256,7 +1256,7 @@ public static bool GetTextColor(Text text, out byte r, out byte g, out byte b, o
/// Returns on success or on failure; call for more information.
public static Color GetTextColor(Text text) {
- GetTextColor(text, out byte r, out byte g, out byte b, out byte a);
+ GetTextColor(text, out var r, out var g, out var b, out var a);
return new Color() { R = r, G = g, B = b, A = a };
}
@@ -1264,10 +1264,10 @@ public static unsafe bool GetTextColorFloat(Text text, out float r, out float g,
if (text.Handle == nint.Zero) {
throw new ArgumentNullException(nameof(text), "Text cannot be null.");
}
- nint pr = Sdl.Malloc(sizeof(float));
- nint pg = Sdl.Malloc(sizeof(float));
- nint pb = Sdl.Malloc(sizeof(float));
- nint pa = Sdl.Malloc(sizeof(float));
+ var pr = Sdl.Malloc(sizeof(float));
+ var pg = Sdl.Malloc(sizeof(float));
+ var pb = Sdl.Malloc(sizeof(float));
+ var pa = Sdl.Malloc(sizeof(float));
try {
bool result = TTF_GetTextColorFloat(text.Handle, pr, pg, pb, pa);
@@ -1306,7 +1306,7 @@ public static unsafe bool GetTextColorFloat(Text text, out float r, out float g,
/// Returns on success or on failure; call for more information.
public static bool GetTextColorFloat(Text text, out FColor color) {
- bool result = GetTextColorFloat(text, out float r, out float g, out float b, out float a);
+ var result = GetTextColorFloat(text, out var r, out var g, out var b, out var a);
color = new FColor() { R = r, G = g, B = b, A = a };
return result;
}
@@ -1342,11 +1342,11 @@ public static unsafe TextEngine GetTextEngine(Text text) {
if (text.Handle == nint.Zero) {
throw new ArgumentNullException(nameof(text), "Text cannot be null.");
}
- nint tePtr = TTF_GetTextEngine(text.Handle);
+ var tePtr = TTF_GetTextEngine(text.Handle);
if (tePtr == nint.Zero) {
throw new InvalidOperationException($"Failed to get text engine. SDL Error: {Sdl.GetError()}");
}
- TextEngine engine = *(TextEngine*)tePtr;
+ var engine = *(TextEngine*)tePtr;
engine.Handle = tePtr;
return engine;
}
@@ -1365,12 +1365,12 @@ public static Font GetTextFont(Text text) {
if (text.Handle == nint.Zero) {
throw new ArgumentNullException(nameof(text), "Text cannot be null.");
}
- nint fPtr = TTF_GetTextFont(text.Handle);
+ var fPtr = TTF_GetTextFont(text.Handle);
if (fPtr == nint.Zero) {
throw new InvalidOperationException($"Failed to get text font. SDL Error: {Sdl.GetError()}");
}
#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type
- Font font = *(Font*)fPtr;
+ var font = *(Font*)fPtr;
#pragma warning restore CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type
font.Handle = fPtr;
return font;
@@ -1380,8 +1380,8 @@ public static bool GetTextPosition(Text text, out int x, out int y) {
if (text.Handle == nint.Zero) {
throw new ArgumentNullException(nameof(text), "Text cannot be null.");
}
- nint px = Sdl.Malloc(sizeof(int));
- nint py = Sdl.Malloc(sizeof(int));
+ var px = Sdl.Malloc(sizeof(int));
+ var py = Sdl.Malloc(sizeof(int));
bool result = TTF_GetTextPosition(text.Handle, px, py);
@@ -1406,7 +1406,7 @@ public static bool GetTextPosition(Text text, out int x, out int y) {
///
public static Point GetTextPosition(Text text) {
- GetTextPosition(text, out int x, out int y);
+ GetTextPosition(text, out var x, out var y);
return new Point() { X = x, Y = y };
}
@@ -1449,8 +1449,8 @@ public static bool GetTextSize(Text text, out int w, out int h) {
throw new ArgumentNullException(nameof(text), "Text cannot be null.");
}
- nint pw = Sdl.Malloc(sizeof(int));
- nint ph = Sdl.Malloc(sizeof(int));
+ var pw = Sdl.Malloc(sizeof(int));
+ var ph = Sdl.Malloc(sizeof(int));
bool result = TTF_GetTextSize(text.Handle, pw, ph);
@@ -1477,7 +1477,7 @@ public static bool GetTextSize(Text text, out int w, out int h) {
/// Returns on success or on failure; call for more information.
public static Size GetTextSize(Text text) {
- GetTextSize(text, out int w, out int h);
+ GetTextSize(text, out var w, out var h);
return new Size() { Width = w, Height = h };
}
@@ -1530,7 +1530,7 @@ public static unsafe bool GetTextSubStringForLine(Text text, int line, out SubSt
throw new ArgumentOutOfRangeException(nameof(line), "Line index cannot be negative.");
}
- nint pSubstring = Sdl.Malloc(Sdl.SizeOf());
+ var pSubstring = Sdl.Malloc(Sdl.SizeOf());
try {
bool result = TTF_GetTextSubStringForLine(text.Handle, line, pSubstring);
@@ -1565,7 +1565,7 @@ public static unsafe bool GetTextSubStringForLine(Text text, int line, out SubSt
/// Returns on success or on failure; call for more information.
public static SubString GetTextSubStringForLine(Text text, int line) {
- bool result = GetTextSubStringForLine(text, line, out SubString substring);
+ var result = GetTextSubStringForLine(text, line, out var substring);
if (!result) {
Sdl.LogError(LogCategory.Error, "Failed to get text substring for line.");
return new SubString();
@@ -1588,7 +1588,7 @@ public static unsafe bool GetTextSubStringForPoint(Text text, int x, int y, out
if (text.Handle == nint.Zero) {
throw new ArgumentNullException(nameof(text), "Text cannot be null.");
}
- nint pSubstring = Sdl.Malloc(Sdl.SizeOf());
+ var pSubstring = Sdl.Malloc(Sdl.SizeOf());
bool result = TTF_GetTextSubStringForPoint(text.Handle, x, y, pSubstring);
if (!result) {
@@ -1626,7 +1626,7 @@ public static bool GetTextSubStringForPoint(Text text, Point point, out SubStrin
/// Returns on success or on failure; call for more information.
public static SubString GetTextSubStringForPoint(Text text, int x, int y) {
- bool result = GetTextSubStringForPoint(text, x, y, out SubString substring);
+ var result = GetTextSubStringForPoint(text, x, y, out var substring);
if (!result) {
Sdl.LogError(LogCategory.Error, "Failed to get text substring for point.");
return new SubString();
@@ -1644,7 +1644,7 @@ public static SubString GetTextSubStringForPoint(Text text, int x, int y) {
///
/// Returns on success or on failure; call for more information.
public static SubString GetTextSubStringForPoint(Text text, Point point) {
- bool result = GetTextSubStringForPoint(text, point, out SubString substring);
+ var result = GetTextSubStringForPoint(text, point, out var substring);
if (!result) {
Sdl.LogError(LogCategory.Error, "Failed to get text substring for point.");
return new SubString();
@@ -1671,17 +1671,17 @@ public static unsafe SubString[] GetTextSubStringsForRange(Text text, int offset
throw new ArgumentOutOfRangeException(nameof(offset), "Offset cannot be negative.");
}
- nint pCount = Sdl.Malloc(sizeof(int));
+ var pCount = Sdl.Malloc(sizeof(int));
- nint pSubStrings = TTF_GetTextSubStringsForRange(text.Handle, offset, length, pCount);
+ var pSubStrings = TTF_GetTextSubStringsForRange(text.Handle, offset, length, pCount);
count = Marshal.ReadInt32(pCount);
if (pSubStrings == nint.Zero) {
Sdl.LogError(LogCategory.Error, "Failed to get text substrings for range.");
}
- SubString[] substrings = new SubString[count];
- for (int i = 0; i < count; i++) {
+ var substrings = new SubString[count];
+ for (var i = 0; i < count; i++) {
// Issue: might be a problem with PtrToStructure
substrings[i] = *(SubString*)(pSubStrings + i * (int)Sdl.SizeOf());
}
@@ -1706,7 +1706,7 @@ public static bool GetTextWrapWidth(Text text, out int wrapWidth) {
throw new ArgumentNullException(nameof(text), "Text cannot be null.");
}
- nint pWrapWidth = Sdl.Malloc(sizeof(int));
+ var pWrapWidth = Sdl.Malloc(sizeof(int));
bool result = TTF_GetTextWrapWidth(text.Handle, pWrapWidth);
@@ -1789,7 +1789,7 @@ public static bool IsScalable(Font font) {
/// Returns on success or on failure; call for more information.
public static bool MeasureString(Font font, string text, nuint length, int maxWidth, out int measuredWidth, out int measuredLength) {
ArgumentException.ThrowIfNullOrEmpty(text);
- bool result = TTF_MeasureString(font.Handle, text, length, maxWidth, out int mW, out nuint mL);
+ bool result = TTF_MeasureString(font.Handle, text, length, maxWidth, out var mW, out var mL);
if (!result) {
Sdl.LogError(LogCategory.Error, $"Failed to measure string '{text}'. SDL Error: {Sdl.GetError()}");
@@ -1814,7 +1814,7 @@ public static bool MeasureString(Font font, string text, nuint length, int maxWi
/// Returns on success or on failure; call for more information.
public static bool MeasureString(Font font, string text, int maxWidth, out int measuredWidth, out int measuredLength) {
ArgumentException.ThrowIfNullOrEmpty(text);
- bool result = MeasureString(font, text, (nuint)text.Length, maxWidth, out int mW, out int mL);
+ var result = MeasureString(font, text, (nuint)text.Length, maxWidth, out var mW, out var mL);
if (!result) {
Sdl.LogError(LogCategory.Error, $"Failed to measure string '{text}'. SDL Error: {Sdl.GetError()}");
@@ -1837,7 +1837,7 @@ public static bool MeasureString(Font font, string text, int maxWidth, out int m
/// Returns on success or on failure; call for more information.
public static bool MeasureString(Font font, string text, int maxWidth, out Size measuredSize) {
- bool result = MeasureString(font, text, maxWidth, out int mW, out int mL);
+ var result = MeasureString(font, text, maxWidth, out var mW, out var mL);
measuredSize = new Size(mW, mL);
return result;
@@ -1855,7 +1855,7 @@ public static bool MeasureString(Font font, string text, int maxWidth, out Size
///
/// Returns on success or on failure; call for more information.
public static Size MeasureString(Font font, string text, int maxWidth) {
- MeasureString(font, text, maxWidth, out Size measuredSize);
+ MeasureString(font, text, maxWidth, out var measuredSize);
return measuredSize;
}
@@ -1909,7 +1909,7 @@ public static Font OpenFont(string file, float ptSize) {
throw new FileNotFoundException($"Font file not found: {file}", file);
}
- Font fontPtr = TTF_OpenFont(file, ptSize);
+ var fontPtr = TTF_OpenFont(file, ptSize);
return fontPtr;
}
@@ -1918,7 +1918,7 @@ public static Font OpenFontIo(IoStream src, bool closeIo, float ptSize) {
if (src.Handle == nint.Zero) {
throw new ArgumentNullException(nameof(src), "IOStream cannot be null.");
}
- Font font = TTF_OpenFontIO(src.Handle, closeIo, ptSize);
+ var font = TTF_OpenFontIO(src.Handle, closeIo, ptSize);
return font;
}
@@ -1932,7 +1932,7 @@ public static Font OpenFontIo(IoStream src, bool closeIo, float ptSize) {
///
/// (TTF_Font *) Returns a valid TTF_Font, or on failure; call for more information.
public static Font OpenFontWithProperties(int props) {
- Font font = TTF_OpenFontWithProperties(props);
+ var font = TTF_OpenFontWithProperties(props);
return font;
}
@@ -1966,11 +1966,11 @@ public static Surface RenderGlyphLcd(Font font, int ch, Color fg, Color bg) {
throw new ArgumentException("Both foreground and background colors cannot be fully transparent.");
}
- nint result = TTF_RenderGlyph_LCD(font.Handle, ch, fg, bg);
+ var result = TTF_RenderGlyph_LCD(font.Handle, ch, fg, bg);
if (result == nint.Zero) {
Sdl.LogError(LogCategory.Error, $"Failed to render glyph {ch} with LCD quality. SDL Error: {Sdl.GetError()}");
}
- Surface surface = *(Surface*)result;
+ var surface = *(Surface*)result;
return surface;
}
@@ -2536,7 +2536,7 @@ public static int StringToTag(string str) {
if (str.Length != 4) {
throw new ArgumentException("String must be exactly 4 characters long.", nameof(str));
}
- for(int i = 0; i < 4; i++) {
+ for(var i = 0; i < 4; i++) {
if (str[i] == '\0') {
throw new ArgumentException("String must not contain null characters.", nameof(str));
}
@@ -2555,7 +2555,7 @@ public static int StringToTag(string str) {
/// a pointer filled in with the 4 character representation of the tag.
/// Thrown if the length of characters exceeds 5: 4 tag characters and one null-terminated character.
public static string TagToString(int tag, ulong size) {
- TTF_TagToString(tag, out string str, size);
+ TTF_TagToString(tag, out var str, size);
return str.Length > 5 ? throw new ArgumentException("String must be at most 4 characters long with a null-terminated character '\\0'.", nameof(tag)) : str[..4];
}
diff --git a/tests/SharpSDL3.Tests/SharpSDL3.Tests.csproj b/tests/SharpSDL3.Tests/SharpSDL3.Tests.csproj
index 5d72f59..f84fa83 100644
--- a/tests/SharpSDL3.Tests/SharpSDL3.Tests.csproj
+++ b/tests/SharpSDL3.Tests/SharpSDL3.Tests.csproj
@@ -1,7 +1,7 @@
- net9.0
+ net10.0
True
enable
false