diff --git a/.editorconfig b/.editorconfig index f0bb9fcf..fba98153 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,7 +16,7 @@ charset = utf-8-bom # XML project files [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] -indent_size = 4 +indent_size = 2 # XML config files [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] @@ -96,16 +96,16 @@ dotnet_naming_symbols.constants.required_modifiers = const dotnet_naming_style.constant_style.capitalization = pascal_case -# Static fields are camelCase and start with s_ +# Static fields are camelCase and start with _ dotnet_naming_rule.static_fields_should_be_camel_case.severity = suggestion dotnet_naming_rule.static_fields_should_be_camel_case.symbols = static_fields -dotnet_naming_rule.static_fields_should_be_camel_case.style = static_field_style +dotnet_naming_rule.static_fields_should_be_camel_case.style = instance_field_style dotnet_naming_symbols.static_fields.applicable_kinds = field dotnet_naming_symbols.static_fields.required_modifiers = static dotnet_naming_style.static_field_style.capitalization = camel_case -dotnet_naming_style.static_field_style.required_prefix = s_ +dotnet_naming_style.static_field_style.required_prefix = _ # Instance fields are camelCase and start with _ dotnet_naming_rule.instance_fields_should_be_camel_case.severity = suggestion @@ -321,3 +321,16 @@ dotnet_diagnostic.IDE2004.severity = warning # Not enforced as a build 'warning' for 'VisualStudio' layer due to large number of false positives from https://github.com/dotnet/roslyn-analyzers/issues/3857 and https://github.com/dotnet/roslyn-analyzers/issues/3858 # Additionally, there is a risk of accidentally breaking an internal API that partners rely on though IVT. dotnet_diagnostic.CA1822.severity = suggestion + +############################################################################### +# Set dotnet analyzer rules to: +# disable CA1401: P/Invoke method '*' should not be visible +# disable SYSLIB1054: Mark the method '*' with 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time +############################################################################### +[*.cs] +dotnet_diagnostic.CA1401.severity = silent +dotnet_diagnostic.SYSLIB1054.severity = silent +csharp_style_prefer_top_level_statements = true:silent +csharp_style_prefer_primary_constructors = true:suggestion + +dotnet_diagnostic.IDE0130.severity = silent diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 944325d2..eabaa20c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,11 +33,11 @@ jobs: name: windows-latest runs-on: windows-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: 'Cache: .nuke/temp, ~/.nuget/packages' - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | .nuke/temp @@ -49,27 +49,27 @@ jobs: AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: 'Publish: log' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: log path: artifacts/log - name: 'Publish: bin' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: bin path: artifacts/bin - name: 'Publish: obj' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: obj path: artifacts/obj - name: 'Publish: tst' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: tst path: artifacts/tst - name: 'Publish: pkg' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: pkg path: artifacts/pkg diff --git a/.github/workflows/test-ubuntu.yml b/.github/workflows/test-ubuntu.yml index 655f00f0..f118f908 100644 --- a/.github/workflows/test-ubuntu.yml +++ b/.github/workflows/test-ubuntu.yml @@ -33,11 +33,11 @@ jobs: name: ubuntu-latest runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: 'Cache: .nuke/temp, ~/.nuget/packages' - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | .nuke/temp @@ -49,22 +49,22 @@ jobs: AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: 'Publish: log' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: log path: artifacts/log - name: 'Publish: bin' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: bin path: artifacts/bin - name: 'Publish: obj' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: obj path: artifacts/obj - name: 'Publish: tst' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: tst path: artifacts/tst diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index 18c0984c..6d9331ab 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -33,11 +33,11 @@ jobs: name: windows-latest runs-on: windows-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: 'Cache: .nuke/temp, ~/.nuget/packages' - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | .nuke/temp @@ -49,22 +49,22 @@ jobs: AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: 'Publish: log' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: log path: artifacts/log - name: 'Publish: bin' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: bin path: artifacts/bin - name: 'Publish: obj' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: obj path: artifacts/obj - name: 'Publish: tst' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: tst path: artifacts/tst diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index b9b464a1..27831484 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -1,23 +1,51 @@ { "$schema": "http://json-schema.org/draft-04/schema#", - "$ref": "#/definitions/build", - "title": "Build Schema", "definitions": { - "build": { - "type": "object", + "Host": { + "type": "string", + "enum": [ + "AppVeyor", + "AzurePipelines", + "Bamboo", + "Bitbucket", + "Bitrise", + "GitHubActions", + "GitLab", + "Jenkins", + "Rider", + "SpaceAutomation", + "TeamCity", + "Terminal", + "TravisCI", + "VisualStudio", + "VSCode" + ] + }, + "ExecutableTarget": { + "type": "string", + "enum": [ + "Clean", + "Compile", + "Generate", + "Pack", + "Release", + "Restore", + "Setup", + "Test" + ] + }, + "Verbosity": { + "type": "string", + "description": "", + "enum": [ + "Verbose", + "Normal", + "Minimal", + "Quiet" + ] + }, + "NukeBuild": { "properties": { - "Architecture": { - "type": "string", - "description": "Platform architecture to use for testing. Default is the processor architecture of the underlying operating system" - }, - "Configuration": { - "type": "string", - "description": "Configuration to build. Default is 'Debug' (local) or 'Release' (server)", - "enum": [ - "Debug", - "Release" - ] - }, "Continue": { "type": "boolean", "description": "Indicates to continue a previously failed build attempt" @@ -27,25 +55,8 @@ "description": "Shows the help text for this build assembly" }, "Host": { - "type": "string", "description": "Host for execution. Default is 'automatic'", - "enum": [ - "AppVeyor", - "AzurePipelines", - "Bamboo", - "Bitbucket", - "Bitrise", - "GitHubActions", - "GitLab", - "Jenkins", - "Rider", - "SpaceAutomation", - "TeamCity", - "Terminal", - "TravisCI", - "VisualStudio", - "VSCode" - ] + "$ref": "#/definitions/Host" }, "NoLogo": { "type": "boolean", @@ -74,51 +85,46 @@ "type": "array", "description": "List of targets to be skipped. Empty list skips all dependencies", "items": { - "type": "string", - "enum": [ - "Clean", - "Compile", - "Generate", - "Pack", - "Release", - "Restore", - "Setup", - "Test" - ] + "$ref": "#/definitions/ExecutableTarget" } }, - "Solution": { - "type": "string", - "description": "Path to a solution file that is automatically loaded" - }, "Target": { "type": "array", "description": "List of targets to be invoked. Default is '{default_target}'", "items": { - "type": "string", - "enum": [ - "Clean", - "Compile", - "Generate", - "Pack", - "Release", - "Restore", - "Setup", - "Test" - ] + "$ref": "#/definitions/ExecutableTarget" } }, "Verbosity": { - "type": "string", "description": "Logging verbosity during build execution. Default is 'Normal'", + "$ref": "#/definitions/Verbosity" + } + } + } + }, + "allOf": [ + { + "properties": { + "Architecture": { + "type": "string", + "description": "Platform architecture to use for testing. Default is the processor architecture of the underlying operating system" + }, + "Configuration": { + "type": "string", + "description": "Configuration to build. Default is 'Debug' (local) or 'Release' (server)", "enum": [ - "Minimal", - "Normal", - "Quiet", - "Verbose" + "Debug", + "Release" ] + }, + "Solution": { + "type": "string", + "description": "Path to a solution file that is automatically loaded" } } + }, + { + "$ref": "#/definitions/NukeBuild" } - } + ] } diff --git a/.vscode/launch.json b/.vscode/launch.json index 5d580050..207788fe 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,9 +18,9 @@ "name": "Launch AverageFrameRate", "type": "coreclr", "request": "launch", - "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/AverageFrameRate/Debug/net6.0/AverageFrameRate", + "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/AverageFrameRate/${input:Configuration}/${input:CoreClrFramework}/AverageFrameRate", "args": [], - "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/AverageFrameRate/Debug/net6.0", + "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/AverageFrameRate/${input:Configuration}/${input:CoreClrFramework}", "stopAtEntry": false, "console": "internalConsole" }, @@ -28,9 +28,9 @@ "name": "Launch BitmapViewer", "type": "coreclr", "request": "launch", - "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/BitmapViewer/Debug/net6.0/BitmapViewer", - "args": ["Sample.bmp"], - "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/BitmapViewer/Debug/net6.0", + "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/BitmapViewer/${input:Configuration}/${input:CoreClrFramework}/BitmapViewer", + "args": ["${input:BitMapViewerArg}"], + "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/BitmapViewer/${input:Configuration}/${input:CoreClrFramework}", "stopAtEntry": false, "console": "internalConsole" }, @@ -38,9 +38,9 @@ "name": "Launch ParticleSystem", "type": "coreclr", "request": "launch", - "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/ParticleSystem/Debug/net6.0/ParticleSystem", + "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/ParticleSystem/${input:Configuration}/${input:CoreClrFramework}/ParticleSystem", "args": [], - "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/ParticleSystem/Debug/net6.0", + "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/ParticleSystem/${input:Configuration}/${input:CoreClrFramework}", "stopAtEntry": false, "console": "internalConsole" }, @@ -48,9 +48,9 @@ "name": "Launch PlasmaFractal", "type": "coreclr", "request": "launch", - "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/PlasmaFractal/Debug/net6.0/PlasmaFractal", + "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/PlasmaFractal/${input:Configuration}/${input:CoreClrFramework}/PlasmaFractal", "args": [], - "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/PlasmaFractal/Debug/net6.0", + "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/PlasmaFractal/${input:Configuration}/${input:CoreClrFramework}", "stopAtEntry": false, "console": "internalConsole" }, @@ -58,9 +58,9 @@ "name": "Launch RayTracer", "type": "coreclr", "request": "launch", - "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/RayTracer/Debug/net6.0/RayTracer", + "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/RayTracer/${input:Configuration}/${input:CoreClrFramework}/RayTracer", "args": [], - "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/RayTracer/Debug/net6.0", + "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/RayTracer/${input:Configuration}/${input:CoreClrFramework}", "stopAtEntry": false, "console": "internalConsole" }, @@ -68,9 +68,9 @@ "name": "Launch SwirlStars", "type": "coreclr", "request": "launch", - "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/SwirlStars/Debug/net6.0/SwirlStars", + "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/SwirlStars/${input:Configuration}/${input:CoreClrFramework}/SwirlStars", "args": [], - "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/SwirlStars/Debug/net6.0", + "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/SwirlStars/${input:Configuration}/${input:CoreClrFramework}", "stopAtEntry": false, "console": "internalConsole" }, @@ -78,9 +78,9 @@ "name": "Launch TunnelEffect", "type": "coreclr", "request": "launch", - "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/TunnelEffect/Debug/net6.0/TunnelEffect", + "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/TunnelEffect/${input:Configuration}/${input:CoreClrFramework}/TunnelEffect", "args": [], - "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/TunnelEffect/Debug/net6.0", + "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/TunnelEffect/${input:Configuration}/${input:CoreClrFramework}", "stopAtEntry": false, "console": "internalConsole" }, @@ -88,14 +88,43 @@ "name": "Launch WavePlayer", "type": "coreclr", "request": "launch", - "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/WavePlayer/Debug/net6.0/WavePlayer", - "args": [], - "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/WavePlayer/Debug/net6.0", + "program": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/WavePlayer/${input:Configuration}/${input:CoreClrFramework}/WavePlayer", + "args": ["${input:WavePlayerArg}"], + "cwd": "${workspaceFolder:SDL2Sharp}/artifacts/bin/samples/WavePlayer/${input:Configuration}/${input:CoreClrFramework}", "stopAtEntry": false, "console": "internalConsole" } ], "inputs": [ + { + "id": "Configuration", + "description": "Choose which configuration should be used.", + "default": "Debug", + "type": "pickString", + "options": [ + "Debug", + "Release" + ] + }, + { + "id": "Architecture", + "description": "Choose which architecture should be used.", + "default": "x64", + "type": "pickString", + "options": [ + "x86", + "x64" + ] + }, + { + "id": "CoreClrFramework", + "description": "Choose which .NET target framework should be used.", + "default": "net8.0", + "type": "pickString", + "options": [ + "net8.0" + ] + }, { "id": "NukeBuildTargets", "description": "Choose which target to build", @@ -110,6 +139,18 @@ "Test", "Pack", ] + }, + { + "id": "BitMapViewerArg", + "description": "Specify the filename of the bitmap to view", + "default": "Sample.bmp", + "type": "promptString" + }, + { + "id": "WavePlayerArg", + "description": "Specify the filename of the WAVE file to play.", + "default": "Roland-GR-1-Trumpet-C5.wav", + "type": "promptString" } ] } \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index 50e9bc71..80f2397c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -70,5 +70,4 @@ $(DefaultItemExcludes);obj\** - \ No newline at end of file diff --git a/Directory.Build.targets b/Directory.Build.targets index 4995884e..d6959465 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -35,17 +35,16 @@ - + all - runtime; build; native; contentfiles; analyzers; buildtransitive - + all - + all - + all diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 00000000..44bde376 --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,24 @@ + + + true + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/GitVersion.yml b/GitVersion.yml index d43e1d22..2009e3d1 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1,4 +1,5 @@ mode: ContinuousDeployment +next-version: 0.4.0 branches: {} ignore: sha: [] diff --git a/SDL2Sharp.sln b/SDL2Sharp.sln index 05bb3947..23c11dd4 100644 --- a/SDL2Sharp.sln +++ b/SDL2Sharp.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 17.1.32319.34 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL2Sharp", "sources\SDL2Sharp\SDL2Sharp.csproj", "{648556E3-AFD4-4432-8424-89EED2126F82}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL2Sharp.UnitTests", "tests\SDL2Sharp.UnitTests\SDL2Sharp.UnitTests.csproj", "{0EA1CB52-0E1E-4EEC-80B5-5EA37F436EAF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL2Sharp.Tests", "tests\SDL2Sharp.Tests\SDL2Sharp.Tests.csproj", "{0EA1CB52-0E1E-4EEC-80B5-5EA37F436EAF}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sources", "sources", "{1CCF39F1-02DD-4E9C-B1C2-614715E9EDB0}" ProjectSection(SolutionItems) = preProject @@ -29,7 +29,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{3B30 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL2Sharp.Interop", "sources\SDL2Sharp.Interop\SDL2Sharp.Interop.csproj", "{A03FB552-F079-4852-8E1A-6ADD6C1BD3A8}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL2Sharp.Interop.UnitTests", "tests\SDL2Sharp.Interop.UnitTests\SDL2Sharp.Interop.UnitTests.csproj", "{C4E13408-B833-4B51-BC7B-BABBC759FB1B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL2Sharp.Interop.Tests", "tests\SDL2Sharp.Interop.Tests\SDL2Sharp.Interop.Tests.csproj", "{C4E13408-B833-4B51-BC7B-BABBC759FB1B}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".root", ".root", "{5E4EF724-335F-42C6-A2ED-4DFECD530B7F}" ProjectSection(SolutionItems) = preProject @@ -75,8 +75,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".config", ".config", "{8869 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RayTracer", "samples\RayTracer\RayTracer.csproj", "{A39F687C-F374-461F-A949-FA7BFFB6ADFC}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SDL2Sharp.Extensions", "sources\SDL2Sharp.Extensions\SDL2Sharp.Extensions.csproj", "{AEA6EAFA-AB09-4B19-A103-DDD7E672D506}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SwirlStars", "samples\SwirlStars\SwirlStars.csproj", "{B8107CDD-068A-451A-86A3-0C33BCEB4F99}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Build", "build\Build\Build.csproj", "{6B61E97E-DF1B-4AE2-A52D-47034759F00E}" @@ -133,10 +131,6 @@ Global {A39F687C-F374-461F-A949-FA7BFFB6ADFC}.Debug|Any CPU.Build.0 = Debug|Any CPU {A39F687C-F374-461F-A949-FA7BFFB6ADFC}.Release|Any CPU.ActiveCfg = Release|Any CPU {A39F687C-F374-461F-A949-FA7BFFB6ADFC}.Release|Any CPU.Build.0 = Release|Any CPU - {AEA6EAFA-AB09-4B19-A103-DDD7E672D506}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AEA6EAFA-AB09-4B19-A103-DDD7E672D506}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AEA6EAFA-AB09-4B19-A103-DDD7E672D506}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AEA6EAFA-AB09-4B19-A103-DDD7E672D506}.Release|Any CPU.Build.0 = Release|Any CPU {B8107CDD-068A-451A-86A3-0C33BCEB4F99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B8107CDD-068A-451A-86A3-0C33BCEB4F99}.Debug|Any CPU.Build.0 = Debug|Any CPU {B8107CDD-068A-451A-86A3-0C33BCEB4F99}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -160,7 +154,6 @@ Global {73FBFF5C-8D51-48C6-9321-0A9532864E32} = {3B3053A4-91F3-4C66-A6A9-773B6CEEE34C} {629C4F2E-29C2-417A-BB3C-E52EA33CD365} = {3B3053A4-91F3-4C66-A6A9-773B6CEEE34C} {A39F687C-F374-461F-A949-FA7BFFB6ADFC} = {3B3053A4-91F3-4C66-A6A9-773B6CEEE34C} - {AEA6EAFA-AB09-4B19-A103-DDD7E672D506} = {1CCF39F1-02DD-4E9C-B1C2-614715E9EDB0} {B8107CDD-068A-451A-86A3-0C33BCEB4F99} = {3B3053A4-91F3-4C66-A6A9-773B6CEEE34C} {6B61E97E-DF1B-4AE2-A52D-47034759F00E} = {9966EF4F-44DE-48FF-964C-B2A7DD157128} EndGlobalSection diff --git a/build.ps1 b/build.ps1 index 92f7b642..05176f18 100644 --- a/build.ps1 +++ b/build.ps1 @@ -18,7 +18,7 @@ $TempDirectory = "$PSScriptRoot\\.nuke\temp" $DotNetGlobalFile = "$PSScriptRoot\\global.json" $DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1" -$DotNetChannel = "LTS" +$DotNetChannel = "STS" $env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 $env:DOTNET_NOLOGO = 1 @@ -65,11 +65,6 @@ else { Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)" -# Install the Azure Artifacts Credential Provider for non-server builds -if ($null -eq $env:GITHUB_ACTIONS -and $null -eq $env:TF_BUILD) { - Invoke-Expression "& { $(Invoke-RestMethod https://aka.ms/install-artifacts-credprovider.ps1) } -AddNetfx" -} - if (Test-Path env:NUKE_ENTERPRISE_TOKEN) { & $env:DOTNET_EXE nuget remove source "nuke-enterprise" > $null & $env:DOTNET_EXE nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password $env:NUKE_ENTERPRISE_TOKEN > $null diff --git a/build.sh b/build.sh index 84615897..57d4d159 100755 --- a/build.sh +++ b/build.sh @@ -14,11 +14,9 @@ TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp" DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json" DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh" -DOTNET_CHANNEL="LTS" +DOTNET_CHANNEL="STS" export DOTNET_CLI_TELEMETRY_OPTOUT=1 -export DOTNET_MULTILEVEL_LOOKUP=1 -export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 export DOTNET_NOLOGO=1 ########################################################################### @@ -60,24 +58,10 @@ fi echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)" -# Install the Azure Artifacts Credential Provider for non-server builds -if [[ ! -v GITHUB_ACTIONS && ! -v TF_BUILD ]]; then - sh -c "$(curl -fsSL https://aka.ms/install-artifacts-credprovider.sh)" -fi - if [[ ! -z ${NUKE_ENTERPRISE_TOKEN+x} && "$NUKE_ENTERPRISE_TOKEN" != "" ]]; then "$DOTNET_EXE" nuget remove source "nuke-enterprise" &>/dev/null || true "$DOTNET_EXE" nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password "$NUKE_ENTERPRISE_TOKEN" --store-password-in-clear-text &>/dev/null || true fi -# Install Mono -#sudo apt install ca-certificates gnupg -#sudo gpg --homedir /tmp --no-default-keyring --keyring /usr/share/keyrings/mono-official-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF -#echo "deb [signed-by=/usr/share/keyrings/mono-official-archive-keyring.gpg] https://download.mono-project.com/repo/ubuntu stable-focal main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list -#sudo apt update -#sudo apt install mono-devel - -# Restore, build, and run! -"$DOTNET_EXE" restore --interactive "$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet "$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@" diff --git a/build/Build/Build.csproj b/build/Build/Build.csproj index ea468012..af81ffe0 100644 --- a/build/Build/Build.csproj +++ b/build/Build/Build.csproj @@ -12,11 +12,11 @@ - + - + diff --git a/build/Build/ClangSharpPInvokeGenerator.Generated.cs b/build/Build/ClangSharpPInvokeGenerator.Generated.cs index 898ec121..2d59a6c1 100644 --- a/build/Build/ClangSharpPInvokeGenerator.Generated.cs +++ b/build/Build/ClangSharpPInvokeGenerator.Generated.cs @@ -17,2742 +17,784 @@ namespace Nuke.Common.Tools.ClangSharpPInvokeGenerator; -/// -///

ClangSharp P/Invoke Binding Generator is a tool for generating strongly-typed safe bindings written in C# for .NET and Mono.

-///

For more details, visit the official website.

-///
+///

ClangSharp P/Invoke Binding Generator is a tool for generating strongly-typed safe bindings written in C# for .NET and Mono.

For more details, visit the official website.

[PublicAPI] [ExcludeFromCodeCoverage] -[NuGetPackageRequirement(ClangSharpPInvokeGeneratorPackageId)] -public partial class ClangSharpPInvokeGeneratorTasks - : IRequireNuGetPackage +[NuGetTool(Id = PackageId, Executable = PackageExecutable)] +public partial class ClangSharpPInvokeGeneratorTasks : ToolTasks, IRequireNuGetPackage { - public const string ClangSharpPInvokeGeneratorPackageId = "ClangSharpPInvokeGenerator"; - /// - /// Path to the ClangSharpPInvokeGenerator executable. - /// - public static string ClangSharpPInvokeGeneratorPath => - ToolPathResolver.TryGetEnvironmentExecutable("CLANGSHARPPINVOKEGENERATOR_EXE") ?? - NuGetToolPathResolver.GetPackageExecutable("ClangSharpPInvokeGenerator", "ClangSharpPInvokeGenerator.dll"); - public static Action ClangSharpPInvokeGeneratorLogger { get; set; } = ProcessTasks.DefaultLogger; - public static Action ClangSharpPInvokeGeneratorExitHandler { get; set; } = CustomExitHandler; - /// - ///

ClangSharp P/Invoke Binding Generator is a tool for generating strongly-typed safe bindings written in C# for .NET and Mono.

- ///

For more details, visit the official website.

- ///
- public static IReadOnlyCollection ClangSharpPInvokeGenerator(ArgumentStringHandler arguments, string workingDirectory = null, IReadOnlyDictionary environmentVariables = null, int? timeout = null, bool? logOutput = null, bool? logInvocation = null, Action logger = null, Action exitHandler = null) - { - using var process = ProcessTasks.StartProcess(ClangSharpPInvokeGeneratorPath, arguments, workingDirectory, environmentVariables, timeout, logOutput, logInvocation, logger ?? ClangSharpPInvokeGeneratorLogger); - (exitHandler ?? (p => ClangSharpPInvokeGeneratorExitHandler.Invoke(null, p))).Invoke(process.AssertWaitForExit()); - return process.Output; - } - /// - ///

ClangSharp P/Invoke Binding Generator is a tool for generating strongly-typed safe bindings written in C# for .NET and Mono.

- ///

For more details, visit the official website.

- ///
- /// - ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

- ///
    - ///
  • --additional via
  • - ///
  • --config via
  • - ///
  • --define-macro via
  • - ///
  • --exclude via
  • - ///
  • --file via
  • - ///
  • --file-directory via
  • - ///
  • --headerFile via
  • - ///
  • --include via
  • - ///
  • --include-directory via
  • - ///
  • --language via
  • - ///
  • --libraryPath via
  • - ///
  • --methodClassName via
  • - ///
  • --namespace via
  • - ///
  • --nativeTypeNamesToStrip via
  • - ///
  • --output via
  • - ///
  • --output-mode via
  • - ///
  • --prefixStrip via
  • - ///
  • --remap via
  • - ///
  • --std via
  • - ///
  • --test-output via
  • - ///
  • --traverse via
  • - ///
  • --with-access-specifier via
  • - ///
  • --with-attribute via
  • - ///
  • --with-callconv via
  • - ///
  • --with-class via
  • - ///
  • --with-guid via
  • - ///
  • --with-librarypath via
  • - ///
  • --with-manual-import via
  • - ///
  • --with-namespace via
  • - ///
  • --with-packing via
  • - ///
  • --with-setlasterror via
  • - ///
  • --with-suppressgctransition via
  • - ///
  • --with-transparent-struct via
  • - ///
  • --with-type via
  • - ///
  • --with-using via
  • - ///
- ///
- public static IReadOnlyCollection ClangSharpPInvokeGenerator(ClangSharpPInvokeGeneratorSettings toolSettings = null) - { - toolSettings = toolSettings ?? new ClangSharpPInvokeGeneratorSettings(); - using var process = ProcessTasks.StartProcess(toolSettings); - toolSettings.ProcessExitHandler.Invoke(toolSettings, process.AssertWaitForExit()); - return process.Output; - } - /// - ///

ClangSharp P/Invoke Binding Generator is a tool for generating strongly-typed safe bindings written in C# for .NET and Mono.

- ///

For more details, visit the official website.

- ///
- /// - ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

- ///
    - ///
  • --additional via
  • - ///
  • --config via
  • - ///
  • --define-macro via
  • - ///
  • --exclude via
  • - ///
  • --file via
  • - ///
  • --file-directory via
  • - ///
  • --headerFile via
  • - ///
  • --include via
  • - ///
  • --include-directory via
  • - ///
  • --language via
  • - ///
  • --libraryPath via
  • - ///
  • --methodClassName via
  • - ///
  • --namespace via
  • - ///
  • --nativeTypeNamesToStrip via
  • - ///
  • --output via
  • - ///
  • --output-mode via
  • - ///
  • --prefixStrip via
  • - ///
  • --remap via
  • - ///
  • --std via
  • - ///
  • --test-output via
  • - ///
  • --traverse via
  • - ///
  • --with-access-specifier via
  • - ///
  • --with-attribute via
  • - ///
  • --with-callconv via
  • - ///
  • --with-class via
  • - ///
  • --with-guid via
  • - ///
  • --with-librarypath via
  • - ///
  • --with-manual-import via
  • - ///
  • --with-namespace via
  • - ///
  • --with-packing via
  • - ///
  • --with-setlasterror via
  • - ///
  • --with-suppressgctransition via
  • - ///
  • --with-transparent-struct via
  • - ///
  • --with-type via
  • - ///
  • --with-using via
  • - ///
- ///
- public static IReadOnlyCollection ClangSharpPInvokeGenerator(Configure configurator) - { - return ClangSharpPInvokeGenerator(configurator(new ClangSharpPInvokeGeneratorSettings())); - } - /// - ///

ClangSharp P/Invoke Binding Generator is a tool for generating strongly-typed safe bindings written in C# for .NET and Mono.

- ///

For more details, visit the official website.

- ///
- /// - ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

- ///
    - ///
  • --additional via
  • - ///
  • --config via
  • - ///
  • --define-macro via
  • - ///
  • --exclude via
  • - ///
  • --file via
  • - ///
  • --file-directory via
  • - ///
  • --headerFile via
  • - ///
  • --include via
  • - ///
  • --include-directory via
  • - ///
  • --language via
  • - ///
  • --libraryPath via
  • - ///
  • --methodClassName via
  • - ///
  • --namespace via
  • - ///
  • --nativeTypeNamesToStrip via
  • - ///
  • --output via
  • - ///
  • --output-mode via
  • - ///
  • --prefixStrip via
  • - ///
  • --remap via
  • - ///
  • --std via
  • - ///
  • --test-output via
  • - ///
  • --traverse via
  • - ///
  • --with-access-specifier via
  • - ///
  • --with-attribute via
  • - ///
  • --with-callconv via
  • - ///
  • --with-class via
  • - ///
  • --with-guid via
  • - ///
  • --with-librarypath via
  • - ///
  • --with-manual-import via
  • - ///
  • --with-namespace via
  • - ///
  • --with-packing via
  • - ///
  • --with-setlasterror via
  • - ///
  • --with-suppressgctransition via
  • - ///
  • --with-transparent-struct via
  • - ///
  • --with-type via
  • - ///
  • --with-using via
  • - ///
- ///
- public static IEnumerable<(ClangSharpPInvokeGeneratorSettings Settings, IReadOnlyCollection Output)> ClangSharpPInvokeGenerator(CombinatorialConfigure configurator, int degreeOfParallelism = 1, bool completeOnFailure = false) - { - return configurator.Invoke(ClangSharpPInvokeGenerator, ClangSharpPInvokeGeneratorLogger, degreeOfParallelism, completeOnFailure); - } + public static string ClangSharpPInvokeGeneratorPath { get => new ClangSharpPInvokeGeneratorTasks().GetToolPathInternal(); set => new ClangSharpPInvokeGeneratorTasks().SetToolPath(value); } + public const string PackageId = "ClangSharpPInvokeGenerator"; + public const string PackageExecutable = "ClangSharpPInvokeGenerator.dll"; + ///

ClangSharp P/Invoke Binding Generator is a tool for generating strongly-typed safe bindings written in C# for .NET and Mono.

For more details, visit the official website.

+ public static IReadOnlyCollection ClangSharpPInvokeGenerator(ArgumentStringHandler arguments, string workingDirectory = null, IReadOnlyDictionary environmentVariables = null, int? timeout = null, bool? logOutput = null, bool? logInvocation = null, Action logger = null, Func exitHandler = null) => new ClangSharpPInvokeGeneratorTasks().Run(arguments, workingDirectory, environmentVariables, timeout, logOutput, logInvocation, logger, exitHandler); + ///

ClangSharp P/Invoke Binding Generator is a tool for generating strongly-typed safe bindings written in C# for .NET and Mono.

For more details, visit the official website.

+ ///

This is a CLI wrapper with fluent API that allows to modify the following arguments:

  • --additional via
  • --config via
  • --define-macro via
  • --exclude via
  • --file via
  • --file-directory via
  • --headerFile via
  • --include via
  • --include-directory via
  • --language via
  • --libraryPath via
  • --methodClassName via
  • --namespace via
  • --nativeTypeNamesToStrip via
  • --output via
  • --output-mode via
  • --prefixStrip via
  • --remap via
  • --std via
  • --test-output via
  • --traverse via
  • --with-access-specifier via
  • --with-attribute via
  • --with-callconv via
  • --with-class via
  • --with-guid via
  • --with-librarypath via
  • --with-manual-import via
  • --with-namespace via
  • --with-packing via
  • --with-setlasterror via
  • --with-suppressgctransition via
  • --with-transparent-struct via
  • --with-type via
  • --with-using via
+ public static IReadOnlyCollection ClangSharpPInvokeGenerator(ClangSharpPInvokeGeneratorSettings options = null) => new ClangSharpPInvokeGeneratorTasks().Run(options); + /// + public static IReadOnlyCollection ClangSharpPInvokeGenerator(Configure configurator) => new ClangSharpPInvokeGeneratorTasks().Run(configurator.Invoke(new ClangSharpPInvokeGeneratorSettings())); + /// + public static IEnumerable<(ClangSharpPInvokeGeneratorSettings Settings, IReadOnlyCollection Output)> ClangSharpPInvokeGenerator(CombinatorialConfigure configurator, int degreeOfParallelism = 1, bool completeOnFailure = false) => configurator.Invoke(ClangSharpPInvokeGenerator, degreeOfParallelism, completeOnFailure); } #region ClangSharpPInvokeGeneratorSettings -/// -/// Used within . -/// +/// [PublicAPI] [ExcludeFromCodeCoverage] -[Serializable] -public partial class ClangSharpPInvokeGeneratorSettings : ToolSettings +[Command(Type = typeof(ClangSharpPInvokeGeneratorTasks), Command = nameof(ClangSharpPInvokeGeneratorTasks.ClangSharpPInvokeGenerator))] +public partial class ClangSharpPInvokeGeneratorSettings : ToolOptions { - /// - /// Path to the ClangSharpPInvokeGenerator executable. - /// - public override string ProcessToolPath => base.ProcessToolPath ?? ClangSharpPInvokeGeneratorTasks.ClangSharpPInvokeGeneratorPath; - public override Action ProcessLogger => base.ProcessLogger ?? ClangSharpPInvokeGeneratorTasks.ClangSharpPInvokeGeneratorLogger; - public override Action ProcessExitHandler => base.ProcessExitHandler ?? ClangSharpPInvokeGeneratorTasks.ClangSharpPInvokeGeneratorExitHandler; - /// - /// An argument to pass to Clang when parsing the input files. - /// - public virtual IReadOnlyList Additional => AdditionalInternal.AsReadOnly(); - internal List AdditionalInternal { get; set; } = new List(); - /// - /// A configuration option that controls how the bindings are generated. - /// - public virtual IReadOnlyList Config => ConfigInternal.AsReadOnly(); - internal List ConfigInternal { get; set; } = new List(); - /// - /// Define to (or 1 if omitted). - /// - public virtual IReadOnlyList DefineMacro => DefineMacroInternal.AsReadOnly(); - internal List DefineMacroInternal { get; set; } = new List(); - /// - /// A declaration name to exclude from binding generation. - /// - public virtual IReadOnlyList Exclude => ExcludeInternal.AsReadOnly(); - internal List ExcludeInternal { get; set; } = new List(); - /// - /// A file to parse and generate bindings for. - /// - public virtual IReadOnlyList File => FileInternal.AsReadOnly(); - internal List FileInternal { get; set; } = new List(); - /// - /// The base path for files to parse. - /// - public virtual IReadOnlyList FileDirectory => FileDirectoryInternal.AsReadOnly(); - internal List FileDirectoryInternal { get; set; } = new List(); - /// - /// A file which contains the header to prefix every generated file with. - /// - public virtual IReadOnlyList HeaderFile => HeaderFileInternal.AsReadOnly(); - internal List HeaderFileInternal { get; set; } = new List(); - /// - /// A declaration name to include in binding generation. - /// - public virtual IReadOnlyList Include => IncludeInternal.AsReadOnly(); - internal List IncludeInternal { get; set; } = new List(); - /// - /// Add directory to include search path. - /// - public virtual IReadOnlyList IncludeDirectory => IncludeDirectoryInternal.AsReadOnly(); - internal List IncludeDirectoryInternal { get; set; } = new List(); - /// - /// Treat subsequent input files as having type . - /// - public virtual string Language { get; internal set; } - /// - /// The string to use in the DllImport attribute used when generating bindings. - /// - public virtual string LibraryPath { get; internal set; } - /// - /// The name of the static class that will contain the generated method bindings. - /// - public virtual string MethodClassName { get; internal set; } - /// - /// The namespace in which to place the generated bindings. - /// - public virtual string Namespace { get; internal set; } - /// - /// The contents to strip from the generated NativeTypeName attributes. - /// - public virtual string NativeTypeNamesToStrip { get; internal set; } - /// - /// The mode describing how the information collected from the headers are presented in the resultant bindings. - /// - public virtual ClangSharpPInvokeGeneratorOutputMode OutputMode { get; internal set; } - /// - /// The output location to write the generated bindings to. - /// - public virtual string Output { get; internal set; } - /// - /// The prefix to strip from the generated method bindings. - /// - public virtual IReadOnlyList PrefixStrip => PrefixStripInternal.AsReadOnly(); - internal List PrefixStripInternal { get; set; } = new List(); - /// - /// A declaration name to be remapped to another name during binding generation. - /// - public virtual IReadOnlyList Remap => RemapInternal.AsReadOnly(); - internal List RemapInternal { get; set; } = new List(); - /// - /// Language standard to compile for. - /// - public virtual string Std { get; internal set; } - /// - /// The output location to write the generated tests to. - /// - public virtual string TestOutput { get; internal set; } - /// - /// A file name included either directly or indirectly by -f that should be traversed during binding generation. - /// - public virtual IReadOnlyList Traverse => TraverseInternal.AsReadOnly(); - internal List TraverseInternal { get; set; } = new List(); - /// - /// An access specifier to be used with the given qualified or remapped declaration name during binding generation. Supports wildcards. - /// - public virtual IReadOnlyList WithAccessSpecifier => WithAccessSpecifierInternal.AsReadOnly(); - internal List WithAccessSpecifierInternal { get; set; } = new List(); - /// - /// An attribute to be added to the given remapped declaration name during binding generation. Supports wildcards. - /// - public virtual IReadOnlyList WithAttribute => WithAttributeInternal.AsReadOnly(); - internal List WithAttributeInternal { get; set; } = new List(); - /// - /// A calling convention to be used for the given declaration during binding generation. Supports wildcards. - /// - public virtual IReadOnlyList WithCallConv => WithCallConvInternal.AsReadOnly(); - internal List WithCallConvInternal { get; set; } = new List(); - /// - /// A class to be used for the given remapped constant or function declaration name during binding generation. Supports wildcards. - /// - public virtual IReadOnlyList WithClass => WithClassInternal.AsReadOnly(); - internal List WithClassInternal { get; set; } = new List(); - /// - /// A GUID to be used for the given declaration during binding generation. Supports wildcards. - /// - public virtual IReadOnlyList WithGuid => WithGuidInternal.AsReadOnly(); - internal List WithGuidInternal { get; set; } = new List(); - /// - /// A library path to be used for the given declaration during binding generation. Supports wildcards. - /// - public virtual IReadOnlyList WithLibraryPath => WithLibraryPathInternal.AsReadOnly(); - internal List WithLibraryPathInternal { get; set; } = new List(); - /// - /// A remapped function name to be treated as a manual import during binding generation. Supports wildcards. - /// - public virtual IReadOnlyList WithManualImport => WithManualImportInternal.AsReadOnly(); - internal List WithManualImportInternal { get; set; } = new List(); - /// - /// A namespace to be used for the given remapped declaration name during binding generation. Supports wildcards. - /// - public virtual IReadOnlyList WithNamespace => WithNamespaceInternal.AsReadOnly(); - internal List WithNamespaceInternal { get; set; } = new List(); - /// - /// Overrides the StructLayoutAttribute.Pack property for the given type. Supports wildcards. - /// - public virtual IReadOnlyList WithPacking => WithPackingInternal.AsReadOnly(); - internal List WithPackingInternal { get; set; } = new List(); - /// - /// Add the SetLastError=true modifier to a given DllImport or UnmanagedFunctionPointer. Supports wildcards. - /// - public virtual IReadOnlyList WithSetLastError => WithSetLastErrorInternal.AsReadOnly(); - internal List WithSetLastErrorInternal { get; set; } = new List(); - /// - /// Add the SuppressGCTransition calling convention to a given DllImport or UnmanagedFunctionPointer. Supports wildcards. - /// - public virtual IReadOnlyList WithSuppressGCTransition => WithSuppressGCTransitionInternal.AsReadOnly(); - internal List WithSuppressGCTransitionInternal { get; set; } = new List(); - /// - /// A remapped type name to be treated as a transparent wrapper during binding generation. Supports wildcards. - /// - public virtual IReadOnlyList WithTransparentStruct => WithTransparentStructInternal.AsReadOnly(); - internal List WithTransparentStructInternal { get; set; } = new List(); - /// - /// A type to be used for the given enum declaration during binding generation. Supports wildcards. - /// - public virtual IReadOnlyList WithType => WithTypeInternal.AsReadOnly(); - internal List WithTypeInternal { get; set; } = new List(); - /// - /// A using directive to be included for the given remapped declaration name during binding generation. Supports wildcards. - /// - public virtual IReadOnlyList WithUsing => WithUsingInternal.AsReadOnly(); - internal List WithUsingInternal { get; set; } = new List(); - protected override Arguments ConfigureProcessArguments(Arguments arguments) - { - arguments - .Add("--additional {value}", Additional) - .Add("--config {value}", Config) - .Add("--define-macro {value}", DefineMacro) - .Add("--exclude {value}", Exclude) - .Add("--file {value}", File) - .Add("--file-directory {value}", FileDirectory) - .Add("--headerFile {value}", HeaderFile) - .Add("--include {value}", Include) - .Add("--include-directory {value}", IncludeDirectory) - .Add("--language {value}", Language) - .Add("--libraryPath {value}", LibraryPath) - .Add("--methodClassName {value}", MethodClassName) - .Add("--namespace {value}", Namespace) - .Add("--nativeTypeNamesToStrip {value}", NativeTypeNamesToStrip) - .Add("--output-mode {value}", OutputMode) - .Add("--output {value}", Output) - .Add("--prefixStrip {value}", PrefixStrip) - .Add("--remap {value}", Remap) - .Add("--std {value}", Std) - .Add("--test-output {value}", TestOutput) - .Add("--traverse {value}", Traverse) - .Add("--with-access-specifier {value}", WithAccessSpecifier) - .Add("--with-attribute {value}", WithAttribute) - .Add("--with-callconv {value}", WithCallConv) - .Add("--with-class {value}", WithClass) - .Add("--with-guid {value}", WithGuid) - .Add("--with-librarypath {value}", WithLibraryPath) - .Add("--with-manual-import {value}", WithManualImport) - .Add("--with-namespace {value}", WithNamespace) - .Add("--with-packing {value}", WithPacking) - .Add("--with-setlasterror {value}", WithSetLastError) - .Add("--with-suppressgctransition {value}", WithSuppressGCTransition) - .Add("--with-transparent-struct {value}", WithTransparentStruct) - .Add("--with-type {value}", WithType) - .Add("--with-using {value}", WithUsing); - return base.ConfigureProcessArguments(arguments); - } + /// An argument to pass to Clang when parsing the input files. + [Argument(Format = "--additional {value}")] public IReadOnlyList Additional => Get>(() => Additional); + /// A configuration option that controls how the bindings are generated. + [Argument(Format = "--config {value}")] public IReadOnlyList Config => Get>(() => Config); + /// Define to (or 1 if omitted). + [Argument(Format = "--define-macro {value}")] public IReadOnlyList DefineMacro => Get>(() => DefineMacro); + /// A declaration name to exclude from binding generation. + [Argument(Format = "--exclude {value}")] public IReadOnlyList Exclude => Get>(() => Exclude); + /// A file to parse and generate bindings for. + [Argument(Format = "--file {value}")] public IReadOnlyList File => Get>(() => File); + /// The base path for files to parse. + [Argument(Format = "--file-directory {value}")] public IReadOnlyList FileDirectories => Get>(() => FileDirectories); + /// A file which contains the header to prefix every generated file with. + [Argument(Format = "--headerFile {value}")] public IReadOnlyList HeaderFiles => Get>(() => HeaderFiles); + /// A declaration name to include in binding generation. + [Argument(Format = "--include {value}")] public IReadOnlyList Include => Get>(() => Include); + /// Add directory to include search path. + [Argument(Format = "--include-directory {value}")] public IReadOnlyList IncludeDirectory => Get>(() => IncludeDirectory); + /// Treat subsequent input files as having type . + [Argument(Format = "--language {value}")] public string Language => Get(() => Language); + /// The string to use in the DllImport attribute used when generating bindings. + [Argument(Format = "--libraryPath {value}")] public string LibraryPath => Get(() => LibraryPath); + /// The name of the static class that will contain the generated method bindings. + [Argument(Format = "--methodClassName {value}")] public string MethodClassName => Get(() => MethodClassName); + /// The namespace in which to place the generated bindings. + [Argument(Format = "--namespace {value}")] public string Namespace => Get(() => Namespace); + /// The contents to strip from the generated NativeTypeName attributes. + [Argument(Format = "--nativeTypeNamesToStrip {value}")] public string NativeTypeNamesToStrip => Get(() => NativeTypeNamesToStrip); + /// The mode describing how the information collected from the headers are presented in the resultant bindings. + [Argument(Format = "--output-mode {value}")] public ClangSharpPInvokeGeneratorOutputMode OutputMode => Get(() => OutputMode); + /// The output location to write the generated bindings to. + [Argument(Format = "--output {value}")] public string Output => Get(() => Output); + /// The prefix to strip from the generated method bindings. + [Argument(Format = "--prefixStrip {value}")] public IReadOnlyList PrefixStrip => Get>(() => PrefixStrip); + /// A declaration name to be remapped to another name during binding generation. + [Argument(Format = "--remap {value}")] public IReadOnlyList Remap => Get>(() => Remap); + /// Language standard to compile for. + [Argument(Format = "--std {value}")] public string Std => Get(() => Std); + /// The output location to write the generated tests to. + [Argument(Format = "--test-output {value}")] public string TestOutput => Get(() => TestOutput); + /// A file name included either directly or indirectly by -f that should be traversed during binding generation. + [Argument(Format = "--traverse {value}")] public IReadOnlyList Traverse => Get>(() => Traverse); + /// An access specifier to be used with the given qualified or remapped declaration name during binding generation. Supports wildcards. + [Argument(Format = "--with-access-specifier {value}")] public IReadOnlyList WithAccessSpecifier => Get>(() => WithAccessSpecifier); + /// An attribute to be added to the given remapped declaration name during binding generation. Supports wildcards. + [Argument(Format = "--with-attribute {value}")] public IReadOnlyList WithAttribute => Get>(() => WithAttribute); + /// A calling convention to be used for the given declaration during binding generation. Supports wildcards. + [Argument(Format = "--with-callconv {value}")] public IReadOnlyList WithCallConv => Get>(() => WithCallConv); + /// A class to be used for the given remapped constant or function declaration name during binding generation. Supports wildcards. + [Argument(Format = "--with-class {value}")] public IReadOnlyList WithClass => Get>(() => WithClass); + /// A GUID to be used for the given declaration during binding generation. Supports wildcards. + [Argument(Format = "--with-guid {value}")] public IReadOnlyList WithGuid => Get>(() => WithGuid); + /// A library path to be used for the given declaration during binding generation. Supports wildcards. + [Argument(Format = "--with-librarypath {value}")] public IReadOnlyList WithLibraryPath => Get>(() => WithLibraryPath); + /// A remapped function name to be treated as a manual import during binding generation. Supports wildcards. + [Argument(Format = "--with-manual-import {value}")] public IReadOnlyList WithManualImport => Get>(() => WithManualImport); + /// A namespace to be used for the given remapped declaration name during binding generation. Supports wildcards. + [Argument(Format = "--with-namespace {value}")] public IReadOnlyList WithNamespace => Get>(() => WithNamespace); + /// Overrides the StructLayoutAttribute.Pack property for the given type. Supports wildcards. + [Argument(Format = "--with-packing {value}")] public IReadOnlyList WithPacking => Get>(() => WithPacking); + /// Add the SetLastError=true modifier to a given DllImport or UnmanagedFunctionPointer. Supports wildcards. + [Argument(Format = "--with-setlasterror {value}")] public IReadOnlyList WithSetLastError => Get>(() => WithSetLastError); + /// Add the SuppressGCTransition calling convention to a given DllImport or UnmanagedFunctionPointer. Supports wildcards. + [Argument(Format = "--with-suppressgctransition {value}")] public IReadOnlyList WithSuppressGCTransition => Get>(() => WithSuppressGCTransition); + /// A remapped type name to be treated as a transparent wrapper during binding generation. Supports wildcards. + [Argument(Format = "--with-transparent-struct {value}")] public IReadOnlyList WithTransparentStruct => Get>(() => WithTransparentStruct); + /// A type to be used for the given enum declaration during binding generation. Supports wildcards. + [Argument(Format = "--with-type {value}")] public IReadOnlyList WithType => Get>(() => WithType); + /// A using directive to be included for the given remapped declaration name during binding generation. Supports wildcards. + [Argument(Format = "--with-using {value}")] public IReadOnlyList WithUsing => Get>(() => WithUsing); } #endregion #region ClangSharpPInvokeGeneratorSettingsExtensions -/// -/// Used within . -/// +/// [PublicAPI] [ExcludeFromCodeCoverage] public static partial class ClangSharpPInvokeGeneratorSettingsExtensions { #region Additional - /// - ///

Sets to a new list

- ///

An argument to pass to Clang when parsing the input files.

- ///
- [Pure] - public static T SetAdditional(this T toolSettings, params string[] additional) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.AdditionalInternal = additional.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

An argument to pass to Clang when parsing the input files.

- ///
- [Pure] - public static T SetAdditional(this T toolSettings, IEnumerable additional) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.AdditionalInternal = additional.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

An argument to pass to Clang when parsing the input files.

- ///
- [Pure] - public static T AddAdditional(this T toolSettings, params string[] additional) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.AdditionalInternal.AddRange(additional); - return toolSettings; - } - /// - ///

Adds values to

- ///

An argument to pass to Clang when parsing the input files.

- ///
- [Pure] - public static T AddAdditional(this T toolSettings, IEnumerable additional) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.AdditionalInternal.AddRange(additional); - return toolSettings; - } - /// - ///

Clears

- ///

An argument to pass to Clang when parsing the input files.

- ///
- [Pure] - public static T ClearAdditional(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.AdditionalInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

An argument to pass to Clang when parsing the input files.

- ///
- [Pure] - public static T RemoveAdditional(this T toolSettings, params string[] additional) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(additional); - toolSettings.AdditionalInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

An argument to pass to Clang when parsing the input files.

- ///
- [Pure] - public static T RemoveAdditional(this T toolSettings, IEnumerable additional) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(additional); - toolSettings.AdditionalInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Additional))] + public static T SetAdditional(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Additional, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Additional))] + public static T SetAdditional(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Additional, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Additional))] + public static T AddAdditional(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.Additional, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Additional))] + public static T AddAdditional(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.Additional, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Additional))] + public static T RemoveAdditional(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.Additional, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Additional))] + public static T RemoveAdditional(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.Additional, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Additional))] + public static T ClearAdditional(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.Additional)); #endregion #region Config - /// - ///

Sets to a new list

- ///

A configuration option that controls how the bindings are generated.

- ///
- [Pure] - public static T SetConfig(this T toolSettings, params ClangSharpPInvokeGeneratorConfigOption[] config) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.ConfigInternal = config.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A configuration option that controls how the bindings are generated.

- ///
- [Pure] - public static T SetConfig(this T toolSettings, IEnumerable config) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.ConfigInternal = config.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A configuration option that controls how the bindings are generated.

- ///
- [Pure] - public static T AddConfig(this T toolSettings, params ClangSharpPInvokeGeneratorConfigOption[] config) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.ConfigInternal.AddRange(config); - return toolSettings; - } - /// - ///

Adds values to

- ///

A configuration option that controls how the bindings are generated.

- ///
- [Pure] - public static T AddConfig(this T toolSettings, IEnumerable config) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.ConfigInternal.AddRange(config); - return toolSettings; - } - /// - ///

Clears

- ///

A configuration option that controls how the bindings are generated.

- ///
- [Pure] - public static T ClearConfig(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.ConfigInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A configuration option that controls how the bindings are generated.

- ///
- [Pure] - public static T RemoveConfig(this T toolSettings, params ClangSharpPInvokeGeneratorConfigOption[] config) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(config); - toolSettings.ConfigInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A configuration option that controls how the bindings are generated.

- ///
- [Pure] - public static T RemoveConfig(this T toolSettings, IEnumerable config) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(config); - toolSettings.ConfigInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Config))] + public static T SetConfig(this T o, params ClangSharpPInvokeGeneratorConfigOption[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Config, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Config))] + public static T SetConfig(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Config, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Config))] + public static T AddConfig(this T o, params ClangSharpPInvokeGeneratorConfigOption[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.Config, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Config))] + public static T AddConfig(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.Config, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Config))] + public static T RemoveConfig(this T o, params ClangSharpPInvokeGeneratorConfigOption[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.Config, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Config))] + public static T RemoveConfig(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.Config, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Config))] + public static T ClearConfig(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.Config)); #endregion #region DefineMacro - /// - ///

Sets to a new list

- ///

Define to (or 1 if omitted).

- ///
- [Pure] - public static T SetDefineMacro(this T toolSettings, params string[] defineMacro) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.DefineMacroInternal = defineMacro.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

Define to (or 1 if omitted).

- ///
- [Pure] - public static T SetDefineMacro(this T toolSettings, IEnumerable defineMacro) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.DefineMacroInternal = defineMacro.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

Define to (or 1 if omitted).

- ///
- [Pure] - public static T AddDefineMacro(this T toolSettings, params string[] defineMacro) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.DefineMacroInternal.AddRange(defineMacro); - return toolSettings; - } - /// - ///

Adds values to

- ///

Define to (or 1 if omitted).

- ///
- [Pure] - public static T AddDefineMacro(this T toolSettings, IEnumerable defineMacro) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.DefineMacroInternal.AddRange(defineMacro); - return toolSettings; - } - /// - ///

Clears

- ///

Define to (or 1 if omitted).

- ///
- [Pure] - public static T ClearDefineMacro(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.DefineMacroInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

Define to (or 1 if omitted).

- ///
- [Pure] - public static T RemoveDefineMacro(this T toolSettings, params string[] defineMacro) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(defineMacro); - toolSettings.DefineMacroInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

Define to (or 1 if omitted).

- ///
- [Pure] - public static T RemoveDefineMacro(this T toolSettings, IEnumerable defineMacro) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(defineMacro); - toolSettings.DefineMacroInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.DefineMacro))] + public static T SetDefineMacro(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.DefineMacro, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.DefineMacro))] + public static T SetDefineMacro(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.DefineMacro, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.DefineMacro))] + public static T AddDefineMacro(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.DefineMacro, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.DefineMacro))] + public static T AddDefineMacro(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.DefineMacro, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.DefineMacro))] + public static T RemoveDefineMacro(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.DefineMacro, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.DefineMacro))] + public static T RemoveDefineMacro(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.DefineMacro, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.DefineMacro))] + public static T ClearDefineMacro(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.DefineMacro)); #endregion #region Exclude - /// - ///

Sets to a new list

- ///

A declaration name to exclude from binding generation.

- ///
- [Pure] - public static T SetExclude(this T toolSettings, params string[] exclude) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.ExcludeInternal = exclude.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A declaration name to exclude from binding generation.

- ///
- [Pure] - public static T SetExclude(this T toolSettings, IEnumerable exclude) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.ExcludeInternal = exclude.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A declaration name to exclude from binding generation.

- ///
- [Pure] - public static T AddExclude(this T toolSettings, params string[] exclude) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.ExcludeInternal.AddRange(exclude); - return toolSettings; - } - /// - ///

Adds values to

- ///

A declaration name to exclude from binding generation.

- ///
- [Pure] - public static T AddExclude(this T toolSettings, IEnumerable exclude) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.ExcludeInternal.AddRange(exclude); - return toolSettings; - } - /// - ///

Clears

- ///

A declaration name to exclude from binding generation.

- ///
- [Pure] - public static T ClearExclude(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.ExcludeInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A declaration name to exclude from binding generation.

- ///
- [Pure] - public static T RemoveExclude(this T toolSettings, params string[] exclude) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(exclude); - toolSettings.ExcludeInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A declaration name to exclude from binding generation.

- ///
- [Pure] - public static T RemoveExclude(this T toolSettings, IEnumerable exclude) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(exclude); - toolSettings.ExcludeInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Exclude))] + public static T SetExclude(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Exclude, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Exclude))] + public static T SetExclude(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Exclude, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Exclude))] + public static T AddExclude(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.Exclude, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Exclude))] + public static T AddExclude(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.Exclude, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Exclude))] + public static T RemoveExclude(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.Exclude, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Exclude))] + public static T RemoveExclude(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.Exclude, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Exclude))] + public static T ClearExclude(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.Exclude)); #endregion #region File - /// - ///

Sets to a new list

- ///

A file to parse and generate bindings for.

- ///
- [Pure] - public static T SetFile(this T toolSettings, params string[] file) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.FileInternal = file.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A file to parse and generate bindings for.

- ///
- [Pure] - public static T SetFile(this T toolSettings, IEnumerable file) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.FileInternal = file.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A file to parse and generate bindings for.

- ///
- [Pure] - public static T AddFile(this T toolSettings, params string[] file) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.FileInternal.AddRange(file); - return toolSettings; - } - /// - ///

Adds values to

- ///

A file to parse and generate bindings for.

- ///
- [Pure] - public static T AddFile(this T toolSettings, IEnumerable file) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.FileInternal.AddRange(file); - return toolSettings; - } - /// - ///

Clears

- ///

A file to parse and generate bindings for.

- ///
- [Pure] - public static T ClearFile(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.FileInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A file to parse and generate bindings for.

- ///
- [Pure] - public static T RemoveFile(this T toolSettings, params string[] file) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(file); - toolSettings.FileInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A file to parse and generate bindings for.

- ///
- [Pure] - public static T RemoveFile(this T toolSettings, IEnumerable file) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(file); - toolSettings.FileInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - #endregion - #region FileDirectory - /// - ///

Sets to a new list

- ///

The base path for files to parse.

- ///
- [Pure] - public static T SetFileDirectory(this T toolSettings, params string[] fileDirectory) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.FileDirectoryInternal = fileDirectory.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

The base path for files to parse.

- ///
- [Pure] - public static T SetFileDirectory(this T toolSettings, IEnumerable fileDirectory) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.FileDirectoryInternal = fileDirectory.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

The base path for files to parse.

- ///
- [Pure] - public static T AddFileDirectory(this T toolSettings, params string[] fileDirectory) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.FileDirectoryInternal.AddRange(fileDirectory); - return toolSettings; - } - /// - ///

Adds values to

- ///

The base path for files to parse.

- ///
- [Pure] - public static T AddFileDirectory(this T toolSettings, IEnumerable fileDirectory) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.FileDirectoryInternal.AddRange(fileDirectory); - return toolSettings; - } - /// - ///

Clears

- ///

The base path for files to parse.

- ///
- [Pure] - public static T ClearFileDirectory(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.FileDirectoryInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

The base path for files to parse.

- ///
- [Pure] - public static T RemoveFileDirectory(this T toolSettings, params string[] fileDirectory) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(fileDirectory); - toolSettings.FileDirectoryInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

The base path for files to parse.

- ///
- [Pure] - public static T RemoveFileDirectory(this T toolSettings, IEnumerable fileDirectory) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(fileDirectory); - toolSettings.FileDirectoryInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - #endregion - #region HeaderFile - /// - ///

Sets to a new list

- ///

A file which contains the header to prefix every generated file with.

- ///
- [Pure] - public static T SetHeaderFile(this T toolSettings, params string[] headerFile) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.HeaderFileInternal = headerFile.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A file which contains the header to prefix every generated file with.

- ///
- [Pure] - public static T SetHeaderFile(this T toolSettings, IEnumerable headerFile) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.HeaderFileInternal = headerFile.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A file which contains the header to prefix every generated file with.

- ///
- [Pure] - public static T AddHeaderFile(this T toolSettings, params string[] headerFile) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.HeaderFileInternal.AddRange(headerFile); - return toolSettings; - } - /// - ///

Adds values to

- ///

A file which contains the header to prefix every generated file with.

- ///
- [Pure] - public static T AddHeaderFile(this T toolSettings, IEnumerable headerFile) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.HeaderFileInternal.AddRange(headerFile); - return toolSettings; - } - /// - ///

Clears

- ///

A file which contains the header to prefix every generated file with.

- ///
- [Pure] - public static T ClearHeaderFile(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.HeaderFileInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A file which contains the header to prefix every generated file with.

- ///
- [Pure] - public static T RemoveHeaderFile(this T toolSettings, params string[] headerFile) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(headerFile); - toolSettings.HeaderFileInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A file which contains the header to prefix every generated file with.

- ///
- [Pure] - public static T RemoveHeaderFile(this T toolSettings, IEnumerable headerFile) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(headerFile); - toolSettings.HeaderFileInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.File))] + public static T SetFile(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.File, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.File))] + public static T SetFile(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.File, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.File))] + public static T AddFile(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.File, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.File))] + public static T AddFile(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.File, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.File))] + public static T RemoveFile(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.File, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.File))] + public static T RemoveFile(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.File, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.File))] + public static T ClearFile(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.File)); + #endregion + #region FileDirectories + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.FileDirectories))] + public static T SetFileDirectories(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.FileDirectories, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.FileDirectories))] + public static T SetFileDirectories(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.FileDirectories, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.FileDirectories))] + public static T AddFileDirectories(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.FileDirectories, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.FileDirectories))] + public static T AddFileDirectories(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.FileDirectories, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.FileDirectories))] + public static T RemoveFileDirectories(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.FileDirectories, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.FileDirectories))] + public static T RemoveFileDirectories(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.FileDirectories, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.FileDirectories))] + public static T ClearFileDirectories(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.FileDirectories)); + #endregion + #region HeaderFiles + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.HeaderFiles))] + public static T SetHeaderFiles(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.HeaderFiles, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.HeaderFiles))] + public static T SetHeaderFiles(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.HeaderFiles, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.HeaderFiles))] + public static T AddHeaderFiles(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.HeaderFiles, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.HeaderFiles))] + public static T AddHeaderFiles(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.HeaderFiles, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.HeaderFiles))] + public static T RemoveHeaderFiles(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.HeaderFiles, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.HeaderFiles))] + public static T RemoveHeaderFiles(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.HeaderFiles, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.HeaderFiles))] + public static T ClearHeaderFiles(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.HeaderFiles)); #endregion #region Include - /// - ///

Sets to a new list

- ///

A declaration name to include in binding generation.

- ///
- [Pure] - public static T SetInclude(this T toolSettings, params string[] include) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.IncludeInternal = include.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A declaration name to include in binding generation.

- ///
- [Pure] - public static T SetInclude(this T toolSettings, IEnumerable include) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.IncludeInternal = include.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A declaration name to include in binding generation.

- ///
- [Pure] - public static T AddInclude(this T toolSettings, params string[] include) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.IncludeInternal.AddRange(include); - return toolSettings; - } - /// - ///

Adds values to

- ///

A declaration name to include in binding generation.

- ///
- [Pure] - public static T AddInclude(this T toolSettings, IEnumerable include) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.IncludeInternal.AddRange(include); - return toolSettings; - } - /// - ///

Clears

- ///

A declaration name to include in binding generation.

- ///
- [Pure] - public static T ClearInclude(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.IncludeInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A declaration name to include in binding generation.

- ///
- [Pure] - public static T RemoveInclude(this T toolSettings, params string[] include) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(include); - toolSettings.IncludeInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A declaration name to include in binding generation.

- ///
- [Pure] - public static T RemoveInclude(this T toolSettings, IEnumerable include) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(include); - toolSettings.IncludeInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Include))] + public static T SetInclude(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Include, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Include))] + public static T SetInclude(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Include, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Include))] + public static T AddInclude(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.Include, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Include))] + public static T AddInclude(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.Include, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Include))] + public static T RemoveInclude(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.Include, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Include))] + public static T RemoveInclude(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.Include, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Include))] + public static T ClearInclude(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.Include)); #endregion #region IncludeDirectory - /// - ///

Sets to a new list

- ///

Add directory to include search path.

- ///
- [Pure] - public static T SetIncludeDirectory(this T toolSettings, params string[] includeDirectory) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.IncludeDirectoryInternal = includeDirectory.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

Add directory to include search path.

- ///
- [Pure] - public static T SetIncludeDirectory(this T toolSettings, IEnumerable includeDirectory) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.IncludeDirectoryInternal = includeDirectory.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

Add directory to include search path.

- ///
- [Pure] - public static T AddIncludeDirectory(this T toolSettings, params string[] includeDirectory) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.IncludeDirectoryInternal.AddRange(includeDirectory); - return toolSettings; - } - /// - ///

Adds values to

- ///

Add directory to include search path.

- ///
- [Pure] - public static T AddIncludeDirectory(this T toolSettings, IEnumerable includeDirectory) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.IncludeDirectoryInternal.AddRange(includeDirectory); - return toolSettings; - } - /// - ///

Clears

- ///

Add directory to include search path.

- ///
- [Pure] - public static T ClearIncludeDirectory(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.IncludeDirectoryInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

Add directory to include search path.

- ///
- [Pure] - public static T RemoveIncludeDirectory(this T toolSettings, params string[] includeDirectory) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(includeDirectory); - toolSettings.IncludeDirectoryInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

Add directory to include search path.

- ///
- [Pure] - public static T RemoveIncludeDirectory(this T toolSettings, IEnumerable includeDirectory) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(includeDirectory); - toolSettings.IncludeDirectoryInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.IncludeDirectory))] + public static T SetIncludeDirectory(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.IncludeDirectory, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.IncludeDirectory))] + public static T SetIncludeDirectory(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.IncludeDirectory, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.IncludeDirectory))] + public static T AddIncludeDirectory(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.IncludeDirectory, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.IncludeDirectory))] + public static T AddIncludeDirectory(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.IncludeDirectory, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.IncludeDirectory))] + public static T RemoveIncludeDirectory(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.IncludeDirectory, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.IncludeDirectory))] + public static T RemoveIncludeDirectory(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.IncludeDirectory, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.IncludeDirectory))] + public static T ClearIncludeDirectory(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.IncludeDirectory)); #endregion #region Language - /// - ///

Sets

- ///

Treat subsequent input files as having type .

- ///
- [Pure] - public static T SetLanguage(this T toolSettings, string language) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.Language = language; - return toolSettings; - } - /// - ///

Resets

- ///

Treat subsequent input files as having type .

- ///
- [Pure] - public static T ResetLanguage(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.Language = null; - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Language))] + public static T SetLanguage(this T o, string v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Language, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Language))] + public static T ResetLanguage(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Remove(() => o.Language)); #endregion #region LibraryPath - /// - ///

Sets

- ///

The string to use in the DllImport attribute used when generating bindings.

- ///
- [Pure] - public static T SetLibraryPath(this T toolSettings, string libraryPath) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.LibraryPath = libraryPath; - return toolSettings; - } - /// - ///

Resets

- ///

The string to use in the DllImport attribute used when generating bindings.

- ///
- [Pure] - public static T ResetLibraryPath(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.LibraryPath = null; - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.LibraryPath))] + public static T SetLibraryPath(this T o, string v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.LibraryPath, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.LibraryPath))] + public static T ResetLibraryPath(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Remove(() => o.LibraryPath)); #endregion #region MethodClassName - /// - ///

Sets

- ///

The name of the static class that will contain the generated method bindings.

- ///
- [Pure] - public static T SetMethodClassName(this T toolSettings, string methodClassName) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.MethodClassName = methodClassName; - return toolSettings; - } - /// - ///

Resets

- ///

The name of the static class that will contain the generated method bindings.

- ///
- [Pure] - public static T ResetMethodClassName(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.MethodClassName = null; - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.MethodClassName))] + public static T SetMethodClassName(this T o, string v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.MethodClassName, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.MethodClassName))] + public static T ResetMethodClassName(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Remove(() => o.MethodClassName)); #endregion #region Namespace - /// - ///

Sets

- ///

The namespace in which to place the generated bindings.

- ///
- [Pure] - public static T SetNamespace(this T toolSettings, string @namespace) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.Namespace = @namespace; - return toolSettings; - } - /// - ///

Resets

- ///

The namespace in which to place the generated bindings.

- ///
- [Pure] - public static T ResetNamespace(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.Namespace = null; - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Namespace))] + public static T SetNamespace(this T o, string v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Namespace, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Namespace))] + public static T ResetNamespace(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Remove(() => o.Namespace)); #endregion #region NativeTypeNamesToStrip - /// - ///

Sets

- ///

The contents to strip from the generated NativeTypeName attributes.

- ///
- [Pure] - public static T SetNativeTypeNamesToStrip(this T toolSettings, string nativeTypeNamesToStrip) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.NativeTypeNamesToStrip = nativeTypeNamesToStrip; - return toolSettings; - } - /// - ///

Resets

- ///

The contents to strip from the generated NativeTypeName attributes.

- ///
- [Pure] - public static T ResetNativeTypeNamesToStrip(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.NativeTypeNamesToStrip = null; - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.NativeTypeNamesToStrip))] + public static T SetNativeTypeNamesToStrip(this T o, string v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.NativeTypeNamesToStrip, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.NativeTypeNamesToStrip))] + public static T ResetNativeTypeNamesToStrip(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Remove(() => o.NativeTypeNamesToStrip)); #endregion #region OutputMode - /// - ///

Sets

- ///

The mode describing how the information collected from the headers are presented in the resultant bindings.

- ///
- [Pure] - public static T SetOutputMode(this T toolSettings, ClangSharpPInvokeGeneratorOutputMode outputMode) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.OutputMode = outputMode; - return toolSettings; - } - /// - ///

Resets

- ///

The mode describing how the information collected from the headers are presented in the resultant bindings.

- ///
- [Pure] - public static T ResetOutputMode(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.OutputMode = null; - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.OutputMode))] + public static T SetOutputMode(this T o, ClangSharpPInvokeGeneratorOutputMode v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.OutputMode, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.OutputMode))] + public static T ResetOutputMode(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Remove(() => o.OutputMode)); #endregion #region Output - /// - ///

Sets

- ///

The output location to write the generated bindings to.

- ///
- [Pure] - public static T SetOutput(this T toolSettings, string output) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.Output = output; - return toolSettings; - } - /// - ///

Resets

- ///

The output location to write the generated bindings to.

- ///
- [Pure] - public static T ResetOutput(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.Output = null; - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Output))] + public static T SetOutput(this T o, string v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Output, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Output))] + public static T ResetOutput(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Remove(() => o.Output)); #endregion #region PrefixStrip - /// - ///

Sets to a new list

- ///

The prefix to strip from the generated method bindings.

- ///
- [Pure] - public static T SetPrefixStrip(this T toolSettings, params string[] prefixStrip) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.PrefixStripInternal = prefixStrip.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

The prefix to strip from the generated method bindings.

- ///
- [Pure] - public static T SetPrefixStrip(this T toolSettings, IEnumerable prefixStrip) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.PrefixStripInternal = prefixStrip.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

The prefix to strip from the generated method bindings.

- ///
- [Pure] - public static T AddPrefixStrip(this T toolSettings, params string[] prefixStrip) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.PrefixStripInternal.AddRange(prefixStrip); - return toolSettings; - } - /// - ///

Adds values to

- ///

The prefix to strip from the generated method bindings.

- ///
- [Pure] - public static T AddPrefixStrip(this T toolSettings, IEnumerable prefixStrip) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.PrefixStripInternal.AddRange(prefixStrip); - return toolSettings; - } - /// - ///

Clears

- ///

The prefix to strip from the generated method bindings.

- ///
- [Pure] - public static T ClearPrefixStrip(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.PrefixStripInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

The prefix to strip from the generated method bindings.

- ///
- [Pure] - public static T RemovePrefixStrip(this T toolSettings, params string[] prefixStrip) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(prefixStrip); - toolSettings.PrefixStripInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

The prefix to strip from the generated method bindings.

- ///
- [Pure] - public static T RemovePrefixStrip(this T toolSettings, IEnumerable prefixStrip) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(prefixStrip); - toolSettings.PrefixStripInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.PrefixStrip))] + public static T SetPrefixStrip(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.PrefixStrip, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.PrefixStrip))] + public static T SetPrefixStrip(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.PrefixStrip, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.PrefixStrip))] + public static T AddPrefixStrip(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.PrefixStrip, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.PrefixStrip))] + public static T AddPrefixStrip(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.PrefixStrip, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.PrefixStrip))] + public static T RemovePrefixStrip(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.PrefixStrip, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.PrefixStrip))] + public static T RemovePrefixStrip(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.PrefixStrip, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.PrefixStrip))] + public static T ClearPrefixStrip(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.PrefixStrip)); #endregion #region Remap - /// - ///

Sets to a new list

- ///

A declaration name to be remapped to another name during binding generation.

- ///
- [Pure] - public static T SetRemap(this T toolSettings, params string[] remap) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.RemapInternal = remap.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A declaration name to be remapped to another name during binding generation.

- ///
- [Pure] - public static T SetRemap(this T toolSettings, IEnumerable remap) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.RemapInternal = remap.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A declaration name to be remapped to another name during binding generation.

- ///
- [Pure] - public static T AddRemap(this T toolSettings, params string[] remap) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.RemapInternal.AddRange(remap); - return toolSettings; - } - /// - ///

Adds values to

- ///

A declaration name to be remapped to another name during binding generation.

- ///
- [Pure] - public static T AddRemap(this T toolSettings, IEnumerable remap) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.RemapInternal.AddRange(remap); - return toolSettings; - } - /// - ///

Clears

- ///

A declaration name to be remapped to another name during binding generation.

- ///
- [Pure] - public static T ClearRemap(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.RemapInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A declaration name to be remapped to another name during binding generation.

- ///
- [Pure] - public static T RemoveRemap(this T toolSettings, params string[] remap) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(remap); - toolSettings.RemapInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A declaration name to be remapped to another name during binding generation.

- ///
- [Pure] - public static T RemoveRemap(this T toolSettings, IEnumerable remap) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(remap); - toolSettings.RemapInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Remap))] + public static T SetRemap(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Remap, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Remap))] + public static T SetRemap(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Remap, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Remap))] + public static T AddRemap(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.Remap, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Remap))] + public static T AddRemap(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.Remap, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Remap))] + public static T RemoveRemap(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.Remap, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Remap))] + public static T RemoveRemap(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.Remap, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Remap))] + public static T ClearRemap(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.Remap)); #endregion #region Std - /// - ///

Sets

- ///

Language standard to compile for.

- ///
- [Pure] - public static T SetStd(this T toolSettings, string std) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.Std = std; - return toolSettings; - } - /// - ///

Resets

- ///

Language standard to compile for.

- ///
- [Pure] - public static T ResetStd(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.Std = null; - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Std))] + public static T SetStd(this T o, string v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Std, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Std))] + public static T ResetStd(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Remove(() => o.Std)); #endregion #region TestOutput - /// - ///

Sets

- ///

The output location to write the generated tests to.

- ///
- [Pure] - public static T SetTestOutput(this T toolSettings, string testOutput) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.TestOutput = testOutput; - return toolSettings; - } - /// - ///

Resets

- ///

The output location to write the generated tests to.

- ///
- [Pure] - public static T ResetTestOutput(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.TestOutput = null; - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.TestOutput))] + public static T SetTestOutput(this T o, string v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.TestOutput, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.TestOutput))] + public static T ResetTestOutput(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Remove(() => o.TestOutput)); #endregion #region Traverse - /// - ///

Sets to a new list

- ///

A file name included either directly or indirectly by -f that should be traversed during binding generation.

- ///
- [Pure] - public static T SetTraverse(this T toolSettings, params string[] traverse) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.TraverseInternal = traverse.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A file name included either directly or indirectly by -f that should be traversed during binding generation.

- ///
- [Pure] - public static T SetTraverse(this T toolSettings, IEnumerable traverse) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.TraverseInternal = traverse.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A file name included either directly or indirectly by -f that should be traversed during binding generation.

- ///
- [Pure] - public static T AddTraverse(this T toolSettings, params string[] traverse) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.TraverseInternal.AddRange(traverse); - return toolSettings; - } - /// - ///

Adds values to

- ///

A file name included either directly or indirectly by -f that should be traversed during binding generation.

- ///
- [Pure] - public static T AddTraverse(this T toolSettings, IEnumerable traverse) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.TraverseInternal.AddRange(traverse); - return toolSettings; - } - /// - ///

Clears

- ///

A file name included either directly or indirectly by -f that should be traversed during binding generation.

- ///
- [Pure] - public static T ClearTraverse(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.TraverseInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A file name included either directly or indirectly by -f that should be traversed during binding generation.

- ///
- [Pure] - public static T RemoveTraverse(this T toolSettings, params string[] traverse) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(traverse); - toolSettings.TraverseInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A file name included either directly or indirectly by -f that should be traversed during binding generation.

- ///
- [Pure] - public static T RemoveTraverse(this T toolSettings, IEnumerable traverse) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(traverse); - toolSettings.TraverseInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Traverse))] + public static T SetTraverse(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Traverse, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Traverse))] + public static T SetTraverse(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.Traverse, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Traverse))] + public static T AddTraverse(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.Traverse, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Traverse))] + public static T AddTraverse(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.Traverse, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Traverse))] + public static T RemoveTraverse(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.Traverse, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Traverse))] + public static T RemoveTraverse(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.Traverse, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.Traverse))] + public static T ClearTraverse(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.Traverse)); #endregion #region WithAccessSpecifier - /// - ///

Sets to a new list

- ///

An access specifier to be used with the given qualified or remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithAccessSpecifier(this T toolSettings, params string[] withAccessSpecifier) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithAccessSpecifierInternal = withAccessSpecifier.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

An access specifier to be used with the given qualified or remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithAccessSpecifier(this T toolSettings, IEnumerable withAccessSpecifier) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithAccessSpecifierInternal = withAccessSpecifier.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

An access specifier to be used with the given qualified or remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithAccessSpecifier(this T toolSettings, params string[] withAccessSpecifier) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithAccessSpecifierInternal.AddRange(withAccessSpecifier); - return toolSettings; - } - /// - ///

Adds values to

- ///

An access specifier to be used with the given qualified or remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithAccessSpecifier(this T toolSettings, IEnumerable withAccessSpecifier) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithAccessSpecifierInternal.AddRange(withAccessSpecifier); - return toolSettings; - } - /// - ///

Clears

- ///

An access specifier to be used with the given qualified or remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T ClearWithAccessSpecifier(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithAccessSpecifierInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

An access specifier to be used with the given qualified or remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithAccessSpecifier(this T toolSettings, params string[] withAccessSpecifier) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withAccessSpecifier); - toolSettings.WithAccessSpecifierInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

An access specifier to be used with the given qualified or remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithAccessSpecifier(this T toolSettings, IEnumerable withAccessSpecifier) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withAccessSpecifier); - toolSettings.WithAccessSpecifierInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithAccessSpecifier))] + public static T SetWithAccessSpecifier(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithAccessSpecifier, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithAccessSpecifier))] + public static T SetWithAccessSpecifier(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithAccessSpecifier, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithAccessSpecifier))] + public static T AddWithAccessSpecifier(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithAccessSpecifier, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithAccessSpecifier))] + public static T AddWithAccessSpecifier(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithAccessSpecifier, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithAccessSpecifier))] + public static T RemoveWithAccessSpecifier(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithAccessSpecifier, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithAccessSpecifier))] + public static T RemoveWithAccessSpecifier(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithAccessSpecifier, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithAccessSpecifier))] + public static T ClearWithAccessSpecifier(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.WithAccessSpecifier)); #endregion #region WithAttribute - /// - ///

Sets to a new list

- ///

An attribute to be added to the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithAttribute(this T toolSettings, params string[] withAttribute) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithAttributeInternal = withAttribute.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

An attribute to be added to the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithAttribute(this T toolSettings, IEnumerable withAttribute) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithAttributeInternal = withAttribute.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

An attribute to be added to the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithAttribute(this T toolSettings, params string[] withAttribute) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithAttributeInternal.AddRange(withAttribute); - return toolSettings; - } - /// - ///

Adds values to

- ///

An attribute to be added to the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithAttribute(this T toolSettings, IEnumerable withAttribute) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithAttributeInternal.AddRange(withAttribute); - return toolSettings; - } - /// - ///

Clears

- ///

An attribute to be added to the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T ClearWithAttribute(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithAttributeInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

An attribute to be added to the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithAttribute(this T toolSettings, params string[] withAttribute) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withAttribute); - toolSettings.WithAttributeInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

An attribute to be added to the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithAttribute(this T toolSettings, IEnumerable withAttribute) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withAttribute); - toolSettings.WithAttributeInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithAttribute))] + public static T SetWithAttribute(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithAttribute, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithAttribute))] + public static T SetWithAttribute(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithAttribute, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithAttribute))] + public static T AddWithAttribute(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithAttribute, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithAttribute))] + public static T AddWithAttribute(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithAttribute, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithAttribute))] + public static T RemoveWithAttribute(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithAttribute, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithAttribute))] + public static T RemoveWithAttribute(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithAttribute, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithAttribute))] + public static T ClearWithAttribute(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.WithAttribute)); #endregion #region WithCallConv - /// - ///

Sets to a new list

- ///

A calling convention to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithCallConv(this T toolSettings, params string[] withCallConv) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithCallConvInternal = withCallConv.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A calling convention to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithCallConv(this T toolSettings, IEnumerable withCallConv) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithCallConvInternal = withCallConv.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A calling convention to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithCallConv(this T toolSettings, params string[] withCallConv) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithCallConvInternal.AddRange(withCallConv); - return toolSettings; - } - /// - ///

Adds values to

- ///

A calling convention to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithCallConv(this T toolSettings, IEnumerable withCallConv) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithCallConvInternal.AddRange(withCallConv); - return toolSettings; - } - /// - ///

Clears

- ///

A calling convention to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T ClearWithCallConv(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithCallConvInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A calling convention to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithCallConv(this T toolSettings, params string[] withCallConv) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withCallConv); - toolSettings.WithCallConvInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A calling convention to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithCallConv(this T toolSettings, IEnumerable withCallConv) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withCallConv); - toolSettings.WithCallConvInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithCallConv))] + public static T SetWithCallConv(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithCallConv, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithCallConv))] + public static T SetWithCallConv(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithCallConv, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithCallConv))] + public static T AddWithCallConv(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithCallConv, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithCallConv))] + public static T AddWithCallConv(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithCallConv, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithCallConv))] + public static T RemoveWithCallConv(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithCallConv, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithCallConv))] + public static T RemoveWithCallConv(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithCallConv, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithCallConv))] + public static T ClearWithCallConv(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.WithCallConv)); #endregion #region WithClass - /// - ///

Sets to a new list

- ///

A class to be used for the given remapped constant or function declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithClass(this T toolSettings, params string[] withClass) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithClassInternal = withClass.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A class to be used for the given remapped constant or function declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithClass(this T toolSettings, IEnumerable withClass) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithClassInternal = withClass.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A class to be used for the given remapped constant or function declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithClass(this T toolSettings, params string[] withClass) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithClassInternal.AddRange(withClass); - return toolSettings; - } - /// - ///

Adds values to

- ///

A class to be used for the given remapped constant or function declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithClass(this T toolSettings, IEnumerable withClass) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithClassInternal.AddRange(withClass); - return toolSettings; - } - /// - ///

Clears

- ///

A class to be used for the given remapped constant or function declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T ClearWithClass(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithClassInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A class to be used for the given remapped constant or function declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithClass(this T toolSettings, params string[] withClass) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withClass); - toolSettings.WithClassInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A class to be used for the given remapped constant or function declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithClass(this T toolSettings, IEnumerable withClass) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withClass); - toolSettings.WithClassInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithClass))] + public static T SetWithClass(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithClass, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithClass))] + public static T SetWithClass(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithClass, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithClass))] + public static T AddWithClass(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithClass, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithClass))] + public static T AddWithClass(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithClass, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithClass))] + public static T RemoveWithClass(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithClass, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithClass))] + public static T RemoveWithClass(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithClass, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithClass))] + public static T ClearWithClass(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.WithClass)); #endregion #region WithGuid - /// - ///

Sets to a new list

- ///

A GUID to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithGuid(this T toolSettings, params string[] withGuid) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithGuidInternal = withGuid.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A GUID to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithGuid(this T toolSettings, IEnumerable withGuid) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithGuidInternal = withGuid.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A GUID to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithGuid(this T toolSettings, params string[] withGuid) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithGuidInternal.AddRange(withGuid); - return toolSettings; - } - /// - ///

Adds values to

- ///

A GUID to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithGuid(this T toolSettings, IEnumerable withGuid) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithGuidInternal.AddRange(withGuid); - return toolSettings; - } - /// - ///

Clears

- ///

A GUID to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T ClearWithGuid(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithGuidInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A GUID to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithGuid(this T toolSettings, params string[] withGuid) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withGuid); - toolSettings.WithGuidInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A GUID to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithGuid(this T toolSettings, IEnumerable withGuid) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withGuid); - toolSettings.WithGuidInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithGuid))] + public static T SetWithGuid(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithGuid, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithGuid))] + public static T SetWithGuid(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithGuid, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithGuid))] + public static T AddWithGuid(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithGuid, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithGuid))] + public static T AddWithGuid(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithGuid, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithGuid))] + public static T RemoveWithGuid(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithGuid, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithGuid))] + public static T RemoveWithGuid(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithGuid, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithGuid))] + public static T ClearWithGuid(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.WithGuid)); #endregion #region WithLibraryPath - /// - ///

Sets to a new list

- ///

A library path to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithLibraryPath(this T toolSettings, params string[] withLibraryPath) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithLibraryPathInternal = withLibraryPath.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A library path to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithLibraryPath(this T toolSettings, IEnumerable withLibraryPath) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithLibraryPathInternal = withLibraryPath.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A library path to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithLibraryPath(this T toolSettings, params string[] withLibraryPath) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithLibraryPathInternal.AddRange(withLibraryPath); - return toolSettings; - } - /// - ///

Adds values to

- ///

A library path to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithLibraryPath(this T toolSettings, IEnumerable withLibraryPath) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithLibraryPathInternal.AddRange(withLibraryPath); - return toolSettings; - } - /// - ///

Clears

- ///

A library path to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T ClearWithLibraryPath(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithLibraryPathInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A library path to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithLibraryPath(this T toolSettings, params string[] withLibraryPath) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withLibraryPath); - toolSettings.WithLibraryPathInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A library path to be used for the given declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithLibraryPath(this T toolSettings, IEnumerable withLibraryPath) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withLibraryPath); - toolSettings.WithLibraryPathInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithLibraryPath))] + public static T SetWithLibraryPath(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithLibraryPath, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithLibraryPath))] + public static T SetWithLibraryPath(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithLibraryPath, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithLibraryPath))] + public static T AddWithLibraryPath(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithLibraryPath, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithLibraryPath))] + public static T AddWithLibraryPath(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithLibraryPath, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithLibraryPath))] + public static T RemoveWithLibraryPath(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithLibraryPath, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithLibraryPath))] + public static T RemoveWithLibraryPath(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithLibraryPath, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithLibraryPath))] + public static T ClearWithLibraryPath(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.WithLibraryPath)); #endregion #region WithManualImport - /// - ///

Sets to a new list

- ///

A remapped function name to be treated as a manual import during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithManualImport(this T toolSettings, params string[] withManualImport) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithManualImportInternal = withManualImport.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A remapped function name to be treated as a manual import during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithManualImport(this T toolSettings, IEnumerable withManualImport) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithManualImportInternal = withManualImport.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A remapped function name to be treated as a manual import during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithManualImport(this T toolSettings, params string[] withManualImport) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithManualImportInternal.AddRange(withManualImport); - return toolSettings; - } - /// - ///

Adds values to

- ///

A remapped function name to be treated as a manual import during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithManualImport(this T toolSettings, IEnumerable withManualImport) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithManualImportInternal.AddRange(withManualImport); - return toolSettings; - } - /// - ///

Clears

- ///

A remapped function name to be treated as a manual import during binding generation. Supports wildcards.

- ///
- [Pure] - public static T ClearWithManualImport(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithManualImportInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A remapped function name to be treated as a manual import during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithManualImport(this T toolSettings, params string[] withManualImport) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withManualImport); - toolSettings.WithManualImportInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A remapped function name to be treated as a manual import during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithManualImport(this T toolSettings, IEnumerable withManualImport) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withManualImport); - toolSettings.WithManualImportInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithManualImport))] + public static T SetWithManualImport(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithManualImport, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithManualImport))] + public static T SetWithManualImport(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithManualImport, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithManualImport))] + public static T AddWithManualImport(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithManualImport, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithManualImport))] + public static T AddWithManualImport(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithManualImport, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithManualImport))] + public static T RemoveWithManualImport(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithManualImport, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithManualImport))] + public static T RemoveWithManualImport(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithManualImport, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithManualImport))] + public static T ClearWithManualImport(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.WithManualImport)); #endregion #region WithNamespace - /// - ///

Sets to a new list

- ///

A namespace to be used for the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithNamespace(this T toolSettings, params string[] withNamespace) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithNamespaceInternal = withNamespace.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A namespace to be used for the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithNamespace(this T toolSettings, IEnumerable withNamespace) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithNamespaceInternal = withNamespace.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A namespace to be used for the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithNamespace(this T toolSettings, params string[] withNamespace) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithNamespaceInternal.AddRange(withNamespace); - return toolSettings; - } - /// - ///

Adds values to

- ///

A namespace to be used for the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithNamespace(this T toolSettings, IEnumerable withNamespace) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithNamespaceInternal.AddRange(withNamespace); - return toolSettings; - } - /// - ///

Clears

- ///

A namespace to be used for the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T ClearWithNamespace(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithNamespaceInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A namespace to be used for the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithNamespace(this T toolSettings, params string[] withNamespace) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withNamespace); - toolSettings.WithNamespaceInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A namespace to be used for the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithNamespace(this T toolSettings, IEnumerable withNamespace) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withNamespace); - toolSettings.WithNamespaceInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithNamespace))] + public static T SetWithNamespace(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithNamespace, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithNamespace))] + public static T SetWithNamespace(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithNamespace, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithNamespace))] + public static T AddWithNamespace(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithNamespace, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithNamespace))] + public static T AddWithNamespace(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithNamespace, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithNamespace))] + public static T RemoveWithNamespace(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithNamespace, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithNamespace))] + public static T RemoveWithNamespace(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithNamespace, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithNamespace))] + public static T ClearWithNamespace(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.WithNamespace)); #endregion #region WithPacking - /// - ///

Sets to a new list

- ///

Overrides the StructLayoutAttribute.Pack property for the given type. Supports wildcards.

- ///
- [Pure] - public static T SetWithPacking(this T toolSettings, params string[] withPacking) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithPackingInternal = withPacking.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

Overrides the StructLayoutAttribute.Pack property for the given type. Supports wildcards.

- ///
- [Pure] - public static T SetWithPacking(this T toolSettings, IEnumerable withPacking) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithPackingInternal = withPacking.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

Overrides the StructLayoutAttribute.Pack property for the given type. Supports wildcards.

- ///
- [Pure] - public static T AddWithPacking(this T toolSettings, params string[] withPacking) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithPackingInternal.AddRange(withPacking); - return toolSettings; - } - /// - ///

Adds values to

- ///

Overrides the StructLayoutAttribute.Pack property for the given type. Supports wildcards.

- ///
- [Pure] - public static T AddWithPacking(this T toolSettings, IEnumerable withPacking) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithPackingInternal.AddRange(withPacking); - return toolSettings; - } - /// - ///

Clears

- ///

Overrides the StructLayoutAttribute.Pack property for the given type. Supports wildcards.

- ///
- [Pure] - public static T ClearWithPacking(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithPackingInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

Overrides the StructLayoutAttribute.Pack property for the given type. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithPacking(this T toolSettings, params string[] withPacking) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withPacking); - toolSettings.WithPackingInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

Overrides the StructLayoutAttribute.Pack property for the given type. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithPacking(this T toolSettings, IEnumerable withPacking) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withPacking); - toolSettings.WithPackingInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithPacking))] + public static T SetWithPacking(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithPacking, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithPacking))] + public static T SetWithPacking(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithPacking, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithPacking))] + public static T AddWithPacking(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithPacking, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithPacking))] + public static T AddWithPacking(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithPacking, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithPacking))] + public static T RemoveWithPacking(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithPacking, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithPacking))] + public static T RemoveWithPacking(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithPacking, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithPacking))] + public static T ClearWithPacking(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.WithPacking)); #endregion #region WithSetLastError - /// - ///

Sets to a new list

- ///

Add the SetLastError=true modifier to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.

- ///
- [Pure] - public static T SetWithSetLastError(this T toolSettings, params string[] withSetLastError) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithSetLastErrorInternal = withSetLastError.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

Add the SetLastError=true modifier to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.

- ///
- [Pure] - public static T SetWithSetLastError(this T toolSettings, IEnumerable withSetLastError) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithSetLastErrorInternal = withSetLastError.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

Add the SetLastError=true modifier to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.

- ///
- [Pure] - public static T AddWithSetLastError(this T toolSettings, params string[] withSetLastError) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithSetLastErrorInternal.AddRange(withSetLastError); - return toolSettings; - } - /// - ///

Adds values to

- ///

Add the SetLastError=true modifier to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.

- ///
- [Pure] - public static T AddWithSetLastError(this T toolSettings, IEnumerable withSetLastError) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithSetLastErrorInternal.AddRange(withSetLastError); - return toolSettings; - } - /// - ///

Clears

- ///

Add the SetLastError=true modifier to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.

- ///
- [Pure] - public static T ClearWithSetLastError(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithSetLastErrorInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

Add the SetLastError=true modifier to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithSetLastError(this T toolSettings, params string[] withSetLastError) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withSetLastError); - toolSettings.WithSetLastErrorInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

Add the SetLastError=true modifier to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithSetLastError(this T toolSettings, IEnumerable withSetLastError) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withSetLastError); - toolSettings.WithSetLastErrorInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithSetLastError))] + public static T SetWithSetLastError(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithSetLastError, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithSetLastError))] + public static T SetWithSetLastError(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithSetLastError, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithSetLastError))] + public static T AddWithSetLastError(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithSetLastError, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithSetLastError))] + public static T AddWithSetLastError(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithSetLastError, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithSetLastError))] + public static T RemoveWithSetLastError(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithSetLastError, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithSetLastError))] + public static T RemoveWithSetLastError(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithSetLastError, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithSetLastError))] + public static T ClearWithSetLastError(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.WithSetLastError)); #endregion #region WithSuppressGCTransition - /// - ///

Sets to a new list

- ///

Add the SuppressGCTransition calling convention to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.

- ///
- [Pure] - public static T SetWithSuppressGCTransition(this T toolSettings, params string[] withSuppressGCTransition) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithSuppressGCTransitionInternal = withSuppressGCTransition.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

Add the SuppressGCTransition calling convention to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.

- ///
- [Pure] - public static T SetWithSuppressGCTransition(this T toolSettings, IEnumerable withSuppressGCTransition) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithSuppressGCTransitionInternal = withSuppressGCTransition.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

Add the SuppressGCTransition calling convention to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.

- ///
- [Pure] - public static T AddWithSuppressGCTransition(this T toolSettings, params string[] withSuppressGCTransition) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithSuppressGCTransitionInternal.AddRange(withSuppressGCTransition); - return toolSettings; - } - /// - ///

Adds values to

- ///

Add the SuppressGCTransition calling convention to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.

- ///
- [Pure] - public static T AddWithSuppressGCTransition(this T toolSettings, IEnumerable withSuppressGCTransition) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithSuppressGCTransitionInternal.AddRange(withSuppressGCTransition); - return toolSettings; - } - /// - ///

Clears

- ///

Add the SuppressGCTransition calling convention to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.

- ///
- [Pure] - public static T ClearWithSuppressGCTransition(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithSuppressGCTransitionInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

Add the SuppressGCTransition calling convention to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithSuppressGCTransition(this T toolSettings, params string[] withSuppressGCTransition) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withSuppressGCTransition); - toolSettings.WithSuppressGCTransitionInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

Add the SuppressGCTransition calling convention to a given DllImport or UnmanagedFunctionPointer. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithSuppressGCTransition(this T toolSettings, IEnumerable withSuppressGCTransition) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withSuppressGCTransition); - toolSettings.WithSuppressGCTransitionInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithSuppressGCTransition))] + public static T SetWithSuppressGCTransition(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithSuppressGCTransition, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithSuppressGCTransition))] + public static T SetWithSuppressGCTransition(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithSuppressGCTransition, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithSuppressGCTransition))] + public static T AddWithSuppressGCTransition(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithSuppressGCTransition, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithSuppressGCTransition))] + public static T AddWithSuppressGCTransition(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithSuppressGCTransition, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithSuppressGCTransition))] + public static T RemoveWithSuppressGCTransition(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithSuppressGCTransition, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithSuppressGCTransition))] + public static T RemoveWithSuppressGCTransition(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithSuppressGCTransition, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithSuppressGCTransition))] + public static T ClearWithSuppressGCTransition(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.WithSuppressGCTransition)); #endregion #region WithTransparentStruct - /// - ///

Sets to a new list

- ///

A remapped type name to be treated as a transparent wrapper during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithTransparentStruct(this T toolSettings, params string[] withTransparentStruct) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithTransparentStructInternal = withTransparentStruct.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A remapped type name to be treated as a transparent wrapper during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithTransparentStruct(this T toolSettings, IEnumerable withTransparentStruct) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithTransparentStructInternal = withTransparentStruct.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A remapped type name to be treated as a transparent wrapper during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithTransparentStruct(this T toolSettings, params string[] withTransparentStruct) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithTransparentStructInternal.AddRange(withTransparentStruct); - return toolSettings; - } - /// - ///

Adds values to

- ///

A remapped type name to be treated as a transparent wrapper during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithTransparentStruct(this T toolSettings, IEnumerable withTransparentStruct) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithTransparentStructInternal.AddRange(withTransparentStruct); - return toolSettings; - } - /// - ///

Clears

- ///

A remapped type name to be treated as a transparent wrapper during binding generation. Supports wildcards.

- ///
- [Pure] - public static T ClearWithTransparentStruct(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithTransparentStructInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A remapped type name to be treated as a transparent wrapper during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithTransparentStruct(this T toolSettings, params string[] withTransparentStruct) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withTransparentStruct); - toolSettings.WithTransparentStructInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A remapped type name to be treated as a transparent wrapper during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithTransparentStruct(this T toolSettings, IEnumerable withTransparentStruct) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withTransparentStruct); - toolSettings.WithTransparentStructInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithTransparentStruct))] + public static T SetWithTransparentStruct(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithTransparentStruct, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithTransparentStruct))] + public static T SetWithTransparentStruct(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithTransparentStruct, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithTransparentStruct))] + public static T AddWithTransparentStruct(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithTransparentStruct, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithTransparentStruct))] + public static T AddWithTransparentStruct(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithTransparentStruct, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithTransparentStruct))] + public static T RemoveWithTransparentStruct(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithTransparentStruct, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithTransparentStruct))] + public static T RemoveWithTransparentStruct(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithTransparentStruct, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithTransparentStruct))] + public static T ClearWithTransparentStruct(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.WithTransparentStruct)); #endregion #region WithType - /// - ///

Sets to a new list

- ///

A type to be used for the given enum declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithType(this T toolSettings, params string[] withType) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithTypeInternal = withType.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A type to be used for the given enum declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithType(this T toolSettings, IEnumerable withType) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithTypeInternal = withType.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A type to be used for the given enum declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithType(this T toolSettings, params string[] withType) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithTypeInternal.AddRange(withType); - return toolSettings; - } - /// - ///

Adds values to

- ///

A type to be used for the given enum declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithType(this T toolSettings, IEnumerable withType) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithTypeInternal.AddRange(withType); - return toolSettings; - } - /// - ///

Clears

- ///

A type to be used for the given enum declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T ClearWithType(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithTypeInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A type to be used for the given enum declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithType(this T toolSettings, params string[] withType) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withType); - toolSettings.WithTypeInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A type to be used for the given enum declaration during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithType(this T toolSettings, IEnumerable withType) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withType); - toolSettings.WithTypeInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithType))] + public static T SetWithType(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithType, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithType))] + public static T SetWithType(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithType, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithType))] + public static T AddWithType(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithType, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithType))] + public static T AddWithType(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithType, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithType))] + public static T RemoveWithType(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithType, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithType))] + public static T RemoveWithType(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithType, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithType))] + public static T ClearWithType(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.WithType)); #endregion #region WithUsing - /// - ///

Sets to a new list

- ///

A using directive to be included for the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithUsing(this T toolSettings, params string[] withUsing) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithUsingInternal = withUsing.ToList(); - return toolSettings; - } - /// - ///

Sets to a new list

- ///

A using directive to be included for the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T SetWithUsing(this T toolSettings, IEnumerable withUsing) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithUsingInternal = withUsing.ToList(); - return toolSettings; - } - /// - ///

Adds values to

- ///

A using directive to be included for the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithUsing(this T toolSettings, params string[] withUsing) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithUsingInternal.AddRange(withUsing); - return toolSettings; - } - /// - ///

Adds values to

- ///

A using directive to be included for the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T AddWithUsing(this T toolSettings, IEnumerable withUsing) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithUsingInternal.AddRange(withUsing); - return toolSettings; - } - /// - ///

Clears

- ///

A using directive to be included for the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T ClearWithUsing(this T toolSettings) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - toolSettings.WithUsingInternal.Clear(); - return toolSettings; - } - /// - ///

Removes values from

- ///

A using directive to be included for the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithUsing(this T toolSettings, params string[] withUsing) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withUsing); - toolSettings.WithUsingInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } - /// - ///

Removes values from

- ///

A using directive to be included for the given remapped declaration name during binding generation. Supports wildcards.

- ///
- [Pure] - public static T RemoveWithUsing(this T toolSettings, IEnumerable withUsing) where T : ClangSharpPInvokeGeneratorSettings - { - toolSettings = toolSettings.NewInstance(); - var hashSet = new HashSet(withUsing); - toolSettings.WithUsingInternal.RemoveAll(x => hashSet.Contains(x)); - return toolSettings; - } + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithUsing))] + public static T SetWithUsing(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithUsing, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithUsing))] + public static T SetWithUsing(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.Set(() => o.WithUsing, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithUsing))] + public static T AddWithUsing(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithUsing, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithUsing))] + public static T AddWithUsing(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.AddCollection(() => o.WithUsing, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithUsing))] + public static T RemoveWithUsing(this T o, params string[] v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithUsing, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithUsing))] + public static T RemoveWithUsing(this T o, IEnumerable v) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.RemoveCollection(() => o.WithUsing, v)); + /// + [Pure] [Builder(Type = typeof(ClangSharpPInvokeGeneratorSettings), Property = nameof(ClangSharpPInvokeGeneratorSettings.WithUsing))] + public static T ClearWithUsing(this T o) where T : ClangSharpPInvokeGeneratorSettings => o.Modify(b => b.ClearCollection(() => o.WithUsing)); #endregion } #endregion #region ClangSharpPInvokeGeneratorConfigOption -/// -/// Used within . -/// +/// Used within . [PublicAPI] [Serializable] [ExcludeFromCodeCoverage] @@ -2806,9 +848,7 @@ public static implicit operator ClangSharpPInvokeGeneratorConfigOption(string va } #endregion #region ClangSharpPInvokeGeneratorOutputMode -/// -/// Used within . -/// +/// Used within . [PublicAPI] [Serializable] [ExcludeFromCodeCoverage] diff --git a/build/Build/ClangSharpPInvokeGeneratorTasks.cs b/build/Build/ClangSharpPInvokeGeneratorTasks.cs deleted file mode 100644 index facce97c..00000000 --- a/build/Build/ClangSharpPInvokeGeneratorTasks.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2023 Maintainers of NUKE. -// Distributed under the MIT License. -// https://github.com/nuke-build/nuke/blob/master/LICENSE - -using Nuke.Common.Tooling; - -namespace Nuke.Common.Tools.ClangSharpPInvokeGenerator -{ - public partial class ClangSharpPInvokeGeneratorTasks - { - public static void CustomExitHandler(ToolSettings toolSettings, IProcess process) - { - process.AssertNonNegativeExitCode(); - } - } -} diff --git a/build/Build/IBuild.cs b/build/Build/IBuild.cs index b6c6f715..46c1bfc7 100644 --- a/build/Build/IBuild.cs +++ b/build/Build/IBuild.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // @@ -39,7 +39,7 @@ partial interface IBuild : INukeBuild [GitVersion] public GitVersion GitVersion => TryGetValue(() => GitVersion); - + [Parameter("Configuration to build. Default is 'Debug' (local) or 'Release' (server).")] public Configuration Configuration => TryGetValue(() => Configuration) ?? GetDefaultConfiguration(); @@ -94,15 +94,9 @@ private static string GetDefaultArchitecture() } protected IReadOnlyCollection GetTargetFrameworks() - { - return GetTargetFrameworks(_ => true); - } - - protected IReadOnlyCollection GetTargetFrameworks(Func predicate) { var targetFrameworkRegex = GetTargetFrameworkRegex(); return Solution.AllProjects - .Where(predicate) .SelectMany((project) => project.GetTargetFrameworks()) .Distinct() .Order() diff --git a/build/Build/IGenerate.cs b/build/Build/IGenerate.cs index 455c0c93..35d3cf40 100644 --- a/build/Build/IGenerate.cs +++ b/build/Build/IGenerate.cs @@ -26,6 +26,7 @@ using static System.Runtime.InteropServices.RuntimeInformation; using static Nuke.Common.Tools.ClangSharpPInvokeGenerator.ClangSharpPInvokeGeneratorTasks; using static Nuke.Common.Tools.ClangSharpPInvokeGenerator.ClangSharpPInvokeGeneratorConfigOption; +using Nuke.Common.IO; interface IGenerate : IBuild { @@ -36,38 +37,26 @@ interface IGenerate : IBuild .Produces(ArtifactsDirectory / "log" / "*.*") .Executes(() => { - GenerateBindingsForSDL2(); - GenerateBindingsForSDL2Image(); - GenerateBindingsForSDL2TTF(); + GenerateBindingsForSDL2(latest_codegen); + GenerateBindingsForSDL2Image(latest_codegen); + GenerateBindingsForSDL2TTF(latest_codegen); }); - private void GenerateBindingsForSDL2() + private void GenerateBindingsForSDL2(ClangSharpPInvokeGeneratorConfigOption codegen) { - var headerFile = RootDirectory / "sources" / "Build" / "Header.txt"; - var outputDirectory = RootDirectory / "sources" / "SDL2Sharp.Interop"; - var testOutputDirectory = RootDirectory / "tests" / "SDL2Sharp.Interop.UnitTests"; - - const string packageId = "SDL2"; - var packageFolder = packageId.ToLower(); - var packageReferenceVersion = Solution.AllProjects - .Where(e => e.Name.Equals("SDL2Sharp.Interop")) - .Select(e => e.GetPackageReferenceVersion(packageId)) - .Single(e => e is not null); - var fileDirectory = GlobalPackagesFolder / packageFolder / packageReferenceVersion / "lib" / "native" / "include"; - ClangSharpPInvokeGenerator(settings => settings .SetConfig ( - compatible_codegen, + codegen, generate_aggressive_inlining, generate_macro_bindings, generate_tests_xunit, multi_file ) - .SetHeaderFile(headerFile) + .SetHeaderFiles(RootDirectory / "build" / "Build" / "Header.txt") .SetNamespace("SDL2Sharp.Interop") - .SetOutput(outputDirectory) - .SetTestOutput(testOutputDirectory) + .SetOutput(OutputPath) + .SetTestOutput(TestOutputPath) .SetWithType ( "SDL_EventType=uint", @@ -328,43 +317,25 @@ private void GenerateBindingsForSDL2() .SetLibraryPath("SDL2") .SetMethodClassName("SDL") .SetPrefixStrip("SDL_") - .SetFileDirectory(fileDirectory) + .SetFileDirectories(GetFileDirectory("SDL2")) ); } - private void GenerateBindingsForSDL2Image() + private void GenerateBindingsForSDL2Image(ClangSharpPInvokeGeneratorConfigOption codegen) { - var headerFile = RootDirectory / "sources" / "Build" / "Header.txt"; - var outputDirectory = RootDirectory / "sources" / "SDL2Sharp.Interop"; - var testOutputDirectory = RootDirectory / "tests" / "SDL2Sharp.Interop.UnitTests"; - - const string basePackageId = "SDL2"; - var basePackageFolder = basePackageId.ToLower(); - var basePackageReferenceVersion = Solution.AllProjects - .Where(e => e.Name.Equals("SDL2Sharp.Interop")) - .Select(e => e.GetPackageReferenceVersion(basePackageId)) - .Single(e => e is not null); - var includeDirectory = GlobalPackagesFolder / basePackageFolder / basePackageReferenceVersion / "lib" / "native" / "include"; - - const string packageId = "SDL2_image"; - var packageFolder = packageId.ToLower(); - var packageReferenceVersion = Solution.AllProjects - .Select(e => e.GetPackageReferenceVersion(packageId)) - .Single(e => e is not null); - var fileDirectory = GlobalPackagesFolder / packageFolder / packageReferenceVersion / "lib" / "native" / "include"; - ClangSharpPInvokeGenerator(settings => settings .SetConfig ( - compatible_codegen, + codegen, generate_aggressive_inlining, generate_macro_bindings, - generate_tests_xunit, multi_file + generate_tests_xunit, + multi_file ) - .SetHeaderFile(headerFile) + .SetHeaderFiles(RootDirectory / "build" / "Build" / "Header.txt") .SetNamespace("SDL2Sharp.Interop") - .SetOutput(outputDirectory) - .SetTestOutput(testOutputDirectory) + .SetOutput(OutputPath) + .SetTestOutput(TestOutputPath) .SetWithType ( "SDL_EventType=uint", @@ -382,44 +353,25 @@ private void GenerateBindingsForSDL2Image() .SetLibraryPath("SDL2_image") .SetMethodClassName("IMG") .SetPrefixStrip("IMG_") - .SetFileDirectory(fileDirectory) - .SetIncludeDirectory(includeDirectory) + .SetFileDirectories(GetFileDirectory("SDL2_image")) + .SetIncludeDirectory(GetIncludeDirectory("SDL2")) ); } - private void GenerateBindingsForSDL2TTF() + private void GenerateBindingsForSDL2TTF(ClangSharpPInvokeGeneratorConfigOption codegen) { - var headerFile = RootDirectory / "sources" / "Build" / "Header.txt"; - var outputDirectory = RootDirectory / "sources" / "SDL2Sharp.Interop"; - var testOutputDirectory = RootDirectory / "tests" / "SDL2Sharp.Interop.UnitTests"; - - const string basePackageId = "SDL2"; - var basePackageFolder = basePackageId.ToLower(); - var basePackageReferenceVersion = Solution.AllProjects - .Where(e => e.Name.Equals("SDL2Sharp.Interop")) - .Select(e => e.GetPackageReferenceVersion(basePackageId)) - .Single(e => e is not null); - var includeDirectory = GlobalPackagesFolder / basePackageFolder / basePackageReferenceVersion / "lib" / "native" / "include"; - - const string packageId = "SDL2_ttf"; - var packageFolder = packageId.ToLower(); - var packageReferenceVersion = Solution.AllProjects - .Select(e => e.GetPackageReferenceVersion(packageId)) - .Single(e => e is not null); - var fileDirectory = GlobalPackagesFolder / packageFolder / packageReferenceVersion / "lib" / "native" / "include"; - ClangSharpPInvokeGenerator(settings => settings .SetConfig ( - compatible_codegen, + codegen, generate_aggressive_inlining, generate_macro_bindings, generate_tests_xunit, multi_file ) - .SetHeaderFile(headerFile) + .SetHeaderFiles(RootDirectory / "build" / "Build" / "Header.txt") .SetNamespace("SDL2Sharp.Interop") - .SetOutput(outputDirectory) - .SetTestOutput(testOutputDirectory) + .SetOutput(OutputPath) + .SetTestOutput(TestOutputPath) .SetWithType ( "SDL_EventType=uint", @@ -441,8 +393,25 @@ private void GenerateBindingsForSDL2TTF() .SetLibraryPath("SDL2_ttf") .SetMethodClassName("TTF") .SetPrefixStrip("TTF_") - .SetFileDirectory(fileDirectory) - .SetIncludeDirectory(includeDirectory) + .SetFileDirectories(GetFileDirectory("SDL2_ttf")) + .SetIncludeDirectory(GetIncludeDirectory("SDL2")) ); } + + private AbsolutePath OutputPath => RootDirectory / "sources" / "SDL2Sharp.Interop" / "codegen"; + + private AbsolutePath TestOutputPath => RootDirectory / "tests" / "SDL2Sharp.Interop.Tests" / "codegen"; + + private AbsolutePath GetFileDirectory(string packageId) => GetIncludeDirectory(packageId); + + private AbsolutePath GetIncludeDirectory(string packageId) + { + var packageFolder = packageId.ToLower(); + var packageReferenceVersion = Solution.AllProjects + .Where(e => e.Name.Equals("SDL2Sharp.Interop")) + .Select(e => e.GetPackageReferenceVersion(packageId)) + .Single(e => e is not null); + var fileDirectory = GlobalPackagesFolder / packageFolder / packageReferenceVersion / "lib" / "native" / "include"; + return fileDirectory; + } } diff --git a/build/Build/IRelease.cs b/build/Build/IRelease.cs index 622f3703..2622d631 100644 --- a/build/Build/IRelease.cs +++ b/build/Build/IRelease.cs @@ -47,7 +47,7 @@ void PublishOnAzure(AbsolutePath packagePath) .SetSource("https://pkgs.dev.azure.com/ronaldvanmanen/_packaging/ronaldvanmanen/nuget/v3/index.json") .SetApiKey("AzureDevOps") .SetNonInteractive(IsServerBuild) - .SetProcessArgumentConfigurator(arguments => arguments.Add("-SkipDuplicate")) + .SetProcessAdditionalArguments("-SkipDuplicate") ); } @@ -58,7 +58,7 @@ void PublishOnGitHub(AbsolutePath packagePath) .SetSource("https://nuget.pkg.github.com/ronaldvanmanen/index.json") .SetApiKey(GitHubActions.Token) .SetNonInteractive(IsServerBuild) - .SetProcessArgumentConfigurator(arguments => arguments.Add("-SkipDuplicate")) + .SetProcessAdditionalArguments("-SkipDuplicate") ); } } diff --git a/build/Build/IRestore.cs b/build/Build/IRestore.cs index 25fd4994..fc7d90e8 100644 --- a/build/Build/IRestore.cs +++ b/build/Build/IRestore.cs @@ -19,7 +19,6 @@ // 3. This notice may not be removed or altered from any source distribution. using Nuke.Common; -using Nuke.Common.Tooling; using Nuke.Common.Tools.DotNet; using Nuke.Common.Tools.GitVersion; using static Nuke.Common.Tools.DotNet.DotNetTasks; @@ -31,13 +30,12 @@ interface IRestore : IBuild .Produces(ArtifactsDirectory / "log" / "*.*") .Executes(() => { - DotNetRestore(settings => settings - .SetProjectFile(Solution) - .SetVerbosity(Verbosity.ToDotNetVerbosity()) - .SetProcessArgumentConfigurator(arguments => arguments - .Add("--interactive", IsLocalBuild) - .Add("/property:NuGetInteractive=false", IsLocalBuild) - ) - ); + DotNetRestore(settings => + { + return settings.SetProjectFile(Solution) + .SetVerbosity(Verbosity.ToDotNetVerbosity()) + .AddProcessAdditionalArguments(IsLocalBuild, "--interactive") + .AddProcessAdditionalArguments(IsLocalBuild, "/property:NuGetInteractive=true"); + }); }); } diff --git a/build/Build/ISetup.cs b/build/Build/ISetup.cs index e976b1ba..95b4f3bc 100644 --- a/build/Build/ISetup.cs +++ b/build/Build/ISetup.cs @@ -20,10 +20,8 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Net.Http; using System.Runtime.InteropServices; -using Microsoft.Win32; using Nuke.Common; using Nuke.Common.Tooling; using Nuke.Common.Tools.PowerShell; @@ -35,28 +33,10 @@ partial interface ISetup : IBuild { - private static readonly Dictionary _downloadUris = new() - { - { new Version(4, 5, 1), "https://go.microsoft.com/fwlink/?linkid=321335&clcid=0x409" }, - { new Version(4, 5, 2), "https://go.microsoft.com/fwlink/?linkid=397673&clcid=0x409" }, - { new Version(4, 6), "https://go.microsoft.com/fwlink/?linkid=2099469" }, - { new Version(4, 6, 1), "https://go.microsoft.com/fwlink/?linkid=2099470" }, - { new Version(4, 6, 2), "https://go.microsoft.com/fwlink/?linkid=2099466" }, - { new Version(4, 7), "https://go.microsoft.com/fwlink/?linkid=2099465" }, - { new Version(4, 7, 1), "https://go.microsoft.com/fwlink/?linkid=2099382" }, - { new Version(4, 7, 2), "https://go.microsoft.com/fwlink/?linkid=874338" }, - { new Version(4, 8), "https://go.microsoft.com/fwlink/?linkid=2088517" }, - { new Version(4, 8, 1), "https://go.microsoft.com/fwlink/?linkid=2203306" } - }; - private Tool Bash => ToolResolver.GetPathTool("bash"); private Tool Chmod => ToolResolver.GetPathTool("chmod"); - private Tool Echo => ToolResolver.GetPathTool("echo"); - - private Tool Sudo => ToolResolver.GetPathTool("sudo"); - public Target Setup => _ => _ .After(target => target.Clean) .Produces(ArtifactsDirectory / "log" / "*.*") @@ -68,24 +48,11 @@ partial interface ISetup : IBuild private void InstallDotNet() { - var targetFrameworkVersions = GetTargetFrameworkVersions(); - foreach (var version in targetFrameworkVersions.Where(version => version.Major >= 5)) + var versions = GetTargetFrameworkVersions(); + foreach (var version in versions) { InstallDotNet(version); } - - if (IsOSPlatform(OSPlatform.Windows)) - { - foreach (var version in targetFrameworkVersions.Where(version => version.Major < 5)) - { - InstallDotNetFramework(version); - } - } - - if (IsOSPlatform(OSPlatform.Linux)) - { - InstallMono(); - } } private void InstallDotNet(Version version) @@ -98,7 +65,6 @@ private void InstallDotNet(Version version) Serilog.Log.Information($"Install latest release of .NET {version}."); PowerShell(settings => settings - .SetExecutionPolicy("ByPass") .SetFile(script) .SetFileArguments("-Architecture", Architecture, "-Channel", version.ToString(2), "-InstallDir", installDirectory, "-NoPath", "-Version", "latest") .SetProcessEnvironmentVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1") @@ -133,89 +99,12 @@ private void InstallDotNet(Version version) } } - private void InstallDotNetFramework(Version version) - { - if (IsDotNetFrameworkInstalled(version)) - { - Serilog.Log.Information($"Microsoft .NET Framework {version} Developer Pack or Targeting Pack is already installed."); - } - else - { - Serilog.Log.Information($"Download Microsoft .NET Framework {version} Developer Pack."); - if (!_downloadUris.TryGetValue(version, out var downloadUri)) - { - throw new PlatformNotSupportedException($"Microsoft .NET Framework {version} Developer Pack configuration is missing."); - } - var downloadPath = TemporaryDirectory / $"NDP{version}-DevPack-ENU.exe"; - HttpDownloadFile(downloadUri, downloadPath, clientConfigurator: ConfigureHttpClient); - Serilog.Log.Information($"Install Microsoft .NET Framework {version} Developer Pack."); - StartProcess(downloadPath, "/quiet /norestart").WaitForExit(); - } - } - private HttpClient ConfigureHttpClient(HttpClient client) { client.Timeout = TimeSpan.FromMinutes(1); return client; } -#pragma warning disable CA1416 // Validate platform compatibility - private bool IsDotNetFrameworkInstalled(Version version) - { - var uninstallKeyPaths = new[] { - @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", - @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" - }; - foreach (var uninstallKeyPath in uninstallKeyPaths) - { - using var uninstallKey = Registry.LocalMachine.OpenSubKey(uninstallKeyPath); - var uninstallSubKeyNames = uninstallKey.GetSubKeyNames(); - foreach (var uninstallSubKeyName in uninstallSubKeyNames) - { - using var uninstallSubKey = uninstallKey.OpenSubKey(uninstallSubKeyName); - var displayName = (string)uninstallSubKey.GetValue("DisplayName"); - if (displayName == $"Microsoft .NET Framework {version} Developer Pack" || - displayName == $"Microsoft .NET Framework {version} Multi-Targeting Pack" || - displayName == $"Microsoft .NET Framework {version} Targeting Pack") - { - return true; - } - } - } - return false; - } -#pragma warning restore CA1416 // Validate platform compatibility - - private void InstallMono() - { - if (Linux.IsUbuntu1604OrHigher) - { - if (Linux.IsUbuntu2004) - { - Sudo("apt-get install ca-certificates gnupg"); - Sudo("gpg --homedir /tmp --no-default-keyring --keyring /usr/share/keyrings/mono-official-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"); - Echo("'deb [signed-by=/usr/share/keyrings/mono-official-archive-keyring.gpg] https://download.mono-project.com/repo/ubuntu stable-focal main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list"); - } - else if (Linux.IsUbuntu1804) - { - Sudo("apt-get install ca-certificates gnupg"); - Sudo("gpg --homedir /tmp --no-default-keyring --keyring /usr/share/keyrings/mono-official-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"); - Echo("'deb [signed-by=/usr/share/keyrings/mono-official-archive-keyring.gpg] https://download.mono-project.com/repo/ubuntu stable-bionic main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list"); - } - else if (Linux.IsUbuntu1604) - { - Sudo("apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"); - Sudo("apt-get install apt-transport-https ca-certificates"); - Echo("'deb https://download.mono-project.com/repo/ubuntu stable-xenial main' | sudo tee /etc/apt/sources.list.d/mono-official-stable.list"); - } - - Sudo("apt-get update"); - - Sudo("apt-get install mono-devel"); - } - } - - private void InstallAzureArtifactsCredentialProvider() { if (IsOSPlatform(OSPlatform.Windows)) @@ -227,6 +116,6 @@ private void InstallAzureArtifactsCredentialProvider() { Serilog.Log.Information($"Install Azure Artifacts Credential Provider"); StartShell("sh -c \"$(curl -fsSL https://aka.ms/install-artifacts-credprovider.sh)\""); - }; + } } } diff --git a/build/Build/ITest.cs b/build/Build/ITest.cs index 1024b41e..92d98e98 100644 --- a/build/Build/ITest.cs +++ b/build/Build/ITest.cs @@ -18,7 +18,9 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +using System.Linq; using Nuke.Common; +using Nuke.Common.ProjectModel; using Nuke.Common.Tooling; using Nuke.Common.Tools.DotNet; using Nuke.Common.Tools.GitVersion; @@ -31,17 +33,20 @@ interface ITest : IBuild .Produces(ArtifactsDirectory / "tst" / "*.*", ArtifactsDirectory / "log" / "*.*") .Executes(() => { - foreach (var targetFramework in GetTargetFrameworks(project => project.Name.EndsWith(".UnitTests"))) + foreach (var project in Solution.AllProjects.Where(e => e.Name.EndsWith(".Tests"))) { - DotNetTest(settings => settings - .SetProjectFile(Solution) - .SetConfiguration(Configuration) - .SetNoRestore(true) - .SetNoBuild(true) - .SetVerbosity(Verbosity.ToDotNetVerbosity()) - .SetFramework(targetFramework) - .SetProcessArgumentConfigurator(_ => _.Add("-- RunConfiguration.DisableAppDomain=true")) - ); + foreach (var targetFramework in project.GetTargetFrameworks()) + { + DotNetTest(settings => settings + .SetProjectFile(project) + .SetConfiguration(Configuration) + .SetNoRestore(true) + .SetNoBuild(true) + .SetVerbosity(Verbosity.ToDotNetVerbosity()) + .SetFramework(targetFramework) + .SetProcessAdditionalArguments("-- RunConfiguration.DisableAppDomain=true") + ); + } } }); } diff --git a/build/Build/Linux.cs b/build/Build/Linux.cs deleted file mode 100644 index 28adcb59..00000000 --- a/build/Build/Linux.cs +++ /dev/null @@ -1,136 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.IO; -using System.Runtime.InteropServices; - -static partial class Linux -{ - private static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); - - public static bool IsUbuntu => IsDistroAndVersion("ubuntu"); - - public static bool IsUbuntu1604 => IsDistroAndVersion("ubuntu", 16, 4); - - public static bool IsUbuntu1604OrHigher => IsDistroAndVersionOrHigher("ubuntu", 16, 4); - - public static bool IsUbuntu1804 => IsDistroAndVersion("ubuntu", 18, 04); - - public static bool IsUbuntu2004 => IsDistroAndVersion("ubuntu", 20, 04); - - private static Version ToVersion(string versionString) - { - // In some distros/versions we cannot discover the distro version; return something valid. - // Pick a high version number, since this seems to happen on newer distros. - if (string.IsNullOrEmpty(versionString)) - { - versionString = new Version(int.MaxValue, int.MaxValue).ToString(); - } - - try - { - if (versionString.Contains('.')) - { - return new Version(versionString); - } - - // minor version is required by Version - // let's default it to 0 - return new Version(int.Parse(versionString), 0); - } - catch (Exception exc) - { - throw new FormatException($"Failed to parse version string: '{versionString}'", exc); - } - } - - private static DistroInfo GetDistroInfo() - { - var result = new DistroInfo(); - - if (File.Exists("/etc/os-release")) - { - foreach (var line in File.ReadAllLines("/etc/os-release")) - { - if (line.StartsWith("ID=", StringComparison.Ordinal)) - { - result.Id = line[3..].Trim('"', '\''); - } - else if (line.StartsWith("VERSION_ID=", StringComparison.Ordinal)) - { - result.VersionId = ToVersion(line[11..].Trim('"', '\'')); - } - } - } - - result.Id ??= "Linux"; - result.VersionId ??= ToVersion(string.Empty); - return result; - } - - private static bool IsDistroAndVersion(string distroId, int major = -1, int minor = -1, int build = -1, int revision = -1) - { - return IsDistroAndVersion(distro => distro == distroId, major, minor, build, revision); - } - - private static bool IsDistroAndVersionOrHigher(string distroId, int major = -1, int minor = -1, int build = -1, int revision = -1) - { - return IsDistroAndVersionOrHigher(distro => distro == distroId, major, minor, build, revision); - } - - private static bool IsDistroAndVersion(Predicate distroPredicate, int major = -1, int minor = -1, int build = -1, int revision = -1) - { - if (IsLinux) - { - var distroInfo = GetDistroInfo(); - if (distroPredicate(distroInfo.Id) && VersionEquivalentTo(major, minor, build, revision, distroInfo.VersionId)) - { - return true; - } - } - - return false; - } - - private static bool IsDistroAndVersionOrHigher(Predicate distroPredicate, int major = -1, int minor = -1, int build = -1, int revision = -1) - { - if (IsLinux) - { - var distroInfo = GetDistroInfo(); - if (distroPredicate(distroInfo.Id) && VersionEquivalentToOrHigher(major, minor, build, revision, distroInfo.VersionId)) - { - return true; - } - } - - return false; - } - - private static bool VersionEquivalentTo(int major, int minor, int build, int revision, Version actualVersionId) - { - return (major == -1 || major == actualVersionId.Major) - && (minor == -1 || minor == actualVersionId.Minor) - && (build == -1 || build == actualVersionId.Build) - && (revision == -1 || revision == actualVersionId.Revision); - } - - private static bool VersionEquivalentToOrHigher(int major, int minor, int build, int revision, Version actualVersionId) - { - return - VersionEquivalentTo(major, minor, build, revision, actualVersionId) || - actualVersionId.Major > major || - (actualVersionId.Major == major && (actualVersionId.Minor > minor || - (actualVersionId.Minor == minor && (actualVersionId.Build > build || - (actualVersionId.Build == build && (actualVersionId.Revision > revision || - (actualVersionId.Revision == revision))))))); - } - - private struct DistroInfo - { - public string Id { get; set; } - - public Version VersionId { get; set; } - } -} diff --git a/build/Build/ToolOptionsExtensions.cs b/build/Build/ToolOptionsExtensions.cs new file mode 100644 index 00000000..d06b13ae --- /dev/null +++ b/build/Build/ToolOptionsExtensions.cs @@ -0,0 +1,34 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using Nuke.Common.Tooling; + +public static class ToolOptionsExtensions +{ + public static T AddProcessAdditionalArguments(this T options, bool condition, params string[] arguments) + where T : ToolOptions + { + if (condition) + { + return options.AddProcessAdditionalArguments(arguments); + } + return options; + } +} \ No newline at end of file diff --git a/global.json b/global.json new file mode 100644 index 00000000..95c86a0b --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "8.0.20", + "rollForward": "latestFeature" + } +} diff --git a/nuget.config b/nuget.config index ec291272..bf8830d6 100644 --- a/nuget.config +++ b/nuget.config @@ -7,13 +7,21 @@ - + - + + + + + + + + + \ No newline at end of file diff --git a/samples/AverageFrameRate/App.cs b/samples/AverageFrameRate/App.cs deleted file mode 100644 index d45ee49b..00000000 --- a/samples/AverageFrameRate/App.cs +++ /dev/null @@ -1,129 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Threading; -using SDL2Sharp; - -namespace AverageFrameRate -{ - internal sealed class App : Application - { - private static readonly Color _drawColor = new(255, 255, 255, 0); - - private static readonly Color _textColor = new(0, 0, 0, 255); - - private Window _window = null!; - - private Thread _renderingThread = null!; - - private volatile bool _rendererInvalidated = false; - - private volatile bool _rendering = false; - - protected override void OnInitializing() - { - Subsystems = Subsystems.Video; - } - - protected override void OnInitialized() - { - _window = new Window("Average Frame Rate", 640, 480, WindowFlags.Shown | WindowFlags.Resizable); - _window.SizeChanged += OnWindowSizeChanged; - _renderingThread = new Thread(Render); - _rendererInvalidated = true; - _rendering = true; - _renderingThread.Start(); - } - - protected override void OnQuiting() - { - _rendererInvalidated = false; - _rendering = false; - _renderingThread?.Join(); - _window?.Dispose(); - } - - private void Render() - { - Font font = new Font("lazy.ttf", 28); - Renderer renderer = null!; - DateTime lastUpdateTime = DateTime.UtcNow; - TimeSpan updateInterval = TimeSpan.FromMilliseconds(500d); - int frameCount = 0; - - try - { - while (_rendering) - { - var currentTime = DateTime.UtcNow; - var elapsedTime = currentTime - lastUpdateTime; - if (_rendererInvalidated || elapsedTime > updateInterval) - { - if (_rendererInvalidated) - { - renderer?.Dispose(); - renderer = _window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); - renderer.DrawColor = _drawColor; - _rendererInvalidated = false; - } - - renderer.Clear(); - - var frameRate = frameCount / elapsedTime.TotalSeconds; - var text = $"Average frame rate = {frameRate:0.00}"; - using (var textSurface = font.RenderBlended(text, _textColor)) - using (var textTexture = renderer.CreateTextureFromSurface(textSurface)) - { - var outputSize = renderer.OutputSize; - var x = Math.Abs(outputSize.Width - textTexture.Width) / 2; - var y = Math.Abs(outputSize.Height - textTexture.Height) / 2; - var dest = new Rectangle(x, y, textTexture.Width, textTexture.Height); - renderer.Copy(textTexture, dest); - } - - lastUpdateTime = currentTime; - frameCount = 0; - } - - renderer.Present(); - frameCount++; - } - } - finally - { - renderer?.Dispose(); - font?.Dispose(); - } - } - - private void OnWindowSizeChanged(object? sender, WindowSizeChangedEventArgs e) - { - _rendererInvalidated = true; - } - - private static int Main(string[] args) - { - var app = new App(); - var exitCode = app.Run(args); - return exitCode; - } - } -} diff --git a/samples/AverageFrameRate/AverageFrameRate.csproj b/samples/AverageFrameRate/AverageFrameRate.csproj index 7b1f32cf..2a8fa539 100644 --- a/samples/AverageFrameRate/AverageFrameRate.csproj +++ b/samples/AverageFrameRate/AverageFrameRate.csproj @@ -2,7 +2,7 @@ WinExe - net8.0;net7.0;net6.0;net462;net47;net471;net472;net48;net481 + net8.0 AnyCPU false diff --git a/samples/AverageFrameRate/Program.cs b/samples/AverageFrameRate/Program.cs new file mode 100644 index 00000000..76d19598 --- /dev/null +++ b/samples/AverageFrameRate/Program.cs @@ -0,0 +1,92 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Diagnostics; +using SDL2Sharp; + +internal static class Program +{ + public static void Main() + { +#pragma warning disable IDE1006 // Naming Styles + using var SDL = new SDL(); +#pragma warning restore IDE1006 // Naming Styles + + using var window = SDL.Video.CreateWindow("Average Frame Rate", 640, 480, WindowFlags.Shown | WindowFlags.Resizable); + using var renderer = window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); + using var lazyFont = SDL.Fonts.OpenFont("lazy.ttf", 28); + + var lastFrameTime = TimeSpan.Zero; + var accumulatedFrameTime = TimeSpan.Zero; + var frameCounter = 0; + var frameRate = 0d; + + var programClock = Stopwatch.StartNew(); + + while (true) + { + var @event = SDL.Events.PollEvent(); + if (@event is not null) + { + switch (@event) + { + case QuitEvent: + return; + + case KeyUpEvent keyEvent when !keyEvent.Repeat: + switch (keyEvent.KeyCode) + { + case KeyCode.Return when keyEvent.Modifiers.HasFlag(KeyModifiers.Alt): + case KeyCode.F11: + window.IsFullScreenDesktop = !window.IsFullScreenDesktop; + break; + } + break; + } + } + else + { + var currentFrameTime = programClock.Elapsed; + var elapsedFrameTime = currentFrameTime - lastFrameTime; + accumulatedFrameTime += elapsedFrameTime; + + renderer.DrawColor = Color.White; + renderer.Clear(); + renderer.DrawColor = Color.Black; + renderer.DrawTextBlendedCentered(lazyFont, $"Average Frames Per Second: {frameRate:0.0}"); + renderer.Present(); + + if (accumulatedFrameTime >= TimeSpan.FromSeconds(1)) + { + frameRate = frameCounter / accumulatedFrameTime.TotalSeconds; + accumulatedFrameTime = TimeSpan.Zero; + frameCounter = 0; + } + else + { + ++frameCounter; + } + + lastFrameTime = currentFrameTime; + } + } + } +} diff --git a/samples/BitmapViewer/App.cs b/samples/BitmapViewer/App.cs deleted file mode 100644 index 6b263790..00000000 --- a/samples/BitmapViewer/App.cs +++ /dev/null @@ -1,88 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using SDL2Sharp; -using SDL2Sharp.Extensions; - -namespace BitmapViewer -{ - internal sealed class App : Application - { - private Window _window = null!; - - private Renderer _renderer = null!; - - private Texture _bitmapTexture = null!; - - protected override void OnInitializing() - { - Subsystems = Subsystems.Video; - } - - protected override void OnInitialized() - { - try - { - _window = new Window("Bitmap Viewer", 640, 480, WindowFlags.Resizable); - _renderer = _window.CreateRenderer(RendererFlags.Accelerated); - _bitmapTexture = _renderer.CreateTextureFromBitmap(CommandLineArgs[0]); - _window.SizeChanged += OnSizeChanged; - } - catch (Exception e) - { - Console.Error.WriteLine($"Could not run sample: {e.Message}"); - Quit(1); - } - } - - protected override void OnQuiting() - { - _window.SizeChanged -= OnSizeChanged; - _bitmapTexture?.Dispose(); - _renderer?.Dispose(); - _window?.Dispose(); - } - - protected override void OnIdle() - { - Render(); - } - - private void OnSizeChanged(object? sender, WindowSizeChangedEventArgs e) - { - Render(); - } - - private void Render() - { - _renderer.Clear(); - _renderer.Copy(_bitmapTexture); - _renderer.Present(); - } - - private static int Main(string[] args) - { - var app = new App(); - var exitCode = app.Run(args); - return exitCode; - } - } -} diff --git a/samples/BitmapViewer/BitmapViewer.csproj b/samples/BitmapViewer/BitmapViewer.csproj index e6b70818..0b46e178 100644 --- a/samples/BitmapViewer/BitmapViewer.csproj +++ b/samples/BitmapViewer/BitmapViewer.csproj @@ -2,7 +2,7 @@ WinExe - net8.0;net7.0;net6.0;net462;net47;net471;net472;net48;net481 + net8.0 AnyCPU false @@ -15,13 +15,15 @@ + + PreserveNewest + PreserveNewest - diff --git a/samples/BitmapViewer/Program.cs b/samples/BitmapViewer/Program.cs new file mode 100644 index 00000000..ac0e9182 --- /dev/null +++ b/samples/BitmapViewer/Program.cs @@ -0,0 +1,94 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Diagnostics; +using SDL2Sharp; + +internal static class Program +{ + public static void Main() + { +#pragma warning disable IDE1006 // Naming Styles + using var SDL = new SDL(); +#pragma warning restore IDE1006 // Naming Styles + + using var window = SDL.Video.CreateWindow("Bitmap Viewer", 640, 480, WindowFlags.Shown | WindowFlags.Resizable); + using var renderer = window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); + using var bitmapTexture = renderer.CreateTextureFromBitmap(Environment.GetCommandLineArgs()[1]); + using var lazyFont = SDL.Fonts.OpenFont("lazy.ttf", 28); + + var lastFrameTime = TimeSpan.Zero; + var accumulatedFrameTime = TimeSpan.Zero; + var frameCounter = 0; + var frameRate = 0d; + + var programClock = Stopwatch.StartNew(); + + while (true) + { + var @event = SDL.Events.PollEvent(); + if (@event is not null) + { + switch (@event) + { + case QuitEvent: + return; + + case KeyUpEvent keyEvent when !keyEvent.Repeat: + switch (keyEvent.KeyCode) + { + case KeyCode.Return when keyEvent.Modifiers.HasFlag(KeyModifiers.Alt): + case KeyCode.F11: + window.IsFullScreenDesktop = !window.IsFullScreenDesktop; + break; + } + break; + } + } + else + { + var currentFrameTime = programClock.Elapsed; + var elapsedFrameTime = currentFrameTime - lastFrameTime; + accumulatedFrameTime += elapsedFrameTime; + + renderer.DrawColor = Color.Black; + renderer.Clear(); + renderer.Copy(bitmapTexture); + renderer.DrawColor = Color.White; + renderer.DrawTextBlended(8, 8, lazyFont, $"FPS: {frameRate:0.0}"); + renderer.Present(); + + if (accumulatedFrameTime >= TimeSpan.FromSeconds(1)) + { + frameRate = frameCounter / accumulatedFrameTime.TotalSeconds; + accumulatedFrameTime = TimeSpan.Zero; + frameCounter = 0; + } + else + { + ++frameCounter; + } + + lastFrameTime = currentFrameTime; + } + } + } +} diff --git a/samples/BitmapViewer/lazy.ttf b/samples/BitmapViewer/lazy.ttf new file mode 100644 index 00000000..eb1000bc Binary files /dev/null and b/samples/BitmapViewer/lazy.ttf differ diff --git a/samples/ParticleSystem/App.cs b/samples/ParticleSystem/App.cs deleted file mode 100644 index ed97e4d6..00000000 --- a/samples/ParticleSystem/App.cs +++ /dev/null @@ -1,170 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Threading; -using SDL2Sharp; -using SDL2Sharp.Extensions; - -namespace ParticleSystem -{ - internal sealed class App : Application - { - private static readonly Font _frameRateFont = new("lazy.ttf", 28); - - private static readonly Color _frameRateColor = new(255, 255, 255, 255); - - private static readonly Color _backgroundColor = new(0, 0, 0, 255); - - private Window _window = null!; - - private Thread _renderingThread = null!; - - private volatile bool _rendererInvalidated = false; - - private volatile bool _rendering = false; - - private volatile int _mouseX; - - private volatile int _mouseY; - - protected override void OnInitializing() - { - Subsystems = Subsystems.Video; - } - - protected override void OnInitialized() - { - _window = new Window("Particle System", 640, 480, WindowFlags.Shown | WindowFlags.Resizable); - _window.KeyDown += OnWindowKeyDown; - _window.MouseMotion += OnWindowMouseMotion; - _window.SizeChanged += OnWindowSizeChanged; - _window.MouseMotion += OnWindowMouseMotion; - _renderingThread = new Thread(Render); - _rendererInvalidated = true; - _rendering = true; - _renderingThread.Start(); - } - - protected override void OnQuiting() - { - _rendererInvalidated = false; - _rendering = false; - _renderingThread?.Join(); - _window?.Dispose(); - } - - private void Render() - { - Renderer renderer = null!; - var lastFrameTime = DateTime.UtcNow; - var lastFrameRateUpdateTime = DateTime.UtcNow; - var frameRateUpdateInterval = TimeSpan.FromMilliseconds(500d); - var frameRate = 0d; - var frameRateText = $"FPS: {frameRate:0.00}"; - var frameCounter = 0; - var particleEmitterColor = new Color(255, 0, 0, 255); - var particleEmmiterPosition = new Point(_window.Width / 2, _window.Height / 2); - var particleEmitter = new ParticleEmitter(particleEmitterColor, particleEmmiterPosition, 15); - - try - { - if (Cursor.Shown) - { - Cursor.Hide(); - } - - while (_rendering) - { - if (_rendererInvalidated) - { - renderer?.Dispose(); - renderer = _window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); - _rendererInvalidated = false; - } - - var currentFrameTime = DateTime.UtcNow; - var elapsedTime = currentFrameTime - lastFrameTime; - particleEmitter.MoveTo(_mouseX, _mouseY); - particleEmitter.Update(currentFrameTime, elapsedTime); - - renderer.DrawColor = _backgroundColor; - renderer.BlendMode = BlendMode.None; - renderer.Clear(); - - particleEmitter.Render(renderer); - - var elapsedFrameRateTime = currentFrameTime - lastFrameRateUpdateTime; - if (elapsedFrameRateTime > frameRateUpdateInterval) - { - frameRate = frameCounter / elapsedFrameRateTime.TotalSeconds; - frameRateText = $"FPS: {frameRate:0.00}"; - lastFrameRateUpdateTime = currentFrameTime; - frameCounter = 0; - } - - renderer.DrawColor = _frameRateColor; - renderer.DrawTextBlended(8, 8, _frameRateFont, frameRateText); - renderer.Present(); - frameCounter++; - lastFrameTime = currentFrameTime; - } - } - finally - { - renderer?.Dispose(); - - if (Cursor.Hidden) - { - Cursor.Show(); - } - } - } - - private void OnWindowKeyDown(object? sender, KeyEventArgs e) - { - if (sender is Window window) - { - if (e.KeyCode == KeyCode.F11 || (e.KeyCode == KeyCode.Return && e.Alt)) - { - window.IsFullScreenDesktop = !window.IsFullScreenDesktop; - } - } - } - - private void OnWindowMouseMotion(object? sender, MouseMotionEventArgs e) - { - _mouseX = e.X; - _mouseY = e.Y; - } - - private void OnWindowSizeChanged(object? sender, WindowSizeChangedEventArgs e) - { - _rendererInvalidated = true; - } - - private static int Main(string[] args) - { - var app = new App(); - var exitCode = app.Run(args); - return exitCode; - } - } -} diff --git a/samples/ParticleSystem/Particle.cs b/samples/ParticleSystem/Particle.cs index 0fab0705..32aa2e14 100644 --- a/samples/ParticleSystem/Particle.cs +++ b/samples/ParticleSystem/Particle.cs @@ -19,62 +19,56 @@ // 3. This notice may not be removed or altered from any source distribution. using System; +using static System.Math; using SDL2Sharp; -using SDL2Sharp.Extensions; -namespace ParticleSystem +internal sealed class Particle { - internal sealed class Particle + public Particle() { - public Particle() - { - Lifespan = TimeSpan.Zero; - Age = TimeSpan.Zero; - Color = new Color(0, 0, 0, 0); - Position = new Point(0, 0); - Radius = 0; - } + Lifespan = TimeSpan.Zero; + Age = TimeSpan.Zero; + Color = new Color(0, 0, 0, 0); + Position = new Point(0, 0); + Radius = 0; + } - public void Respawn(TimeSpan lifespan, Color color, Point position, double radius) - { - Lifespan = lifespan; - Age = TimeSpan.Zero; - Color = color; - Position = position; - Radius = radius; - } + public void Respawn(TimeSpan lifespan, Color color, Point position, double radius) + { + Lifespan = lifespan; + Age = TimeSpan.Zero; + Color = color; + Position = position; + Radius = radius; + } - public TimeSpan Lifespan { get; private set; } + public TimeSpan Lifespan { get; private set; } - public TimeSpan Age { get; private set; } + public TimeSpan Age { get; private set; } - public bool IsDead => Age >= Lifespan; + public bool IsDead => Age >= Lifespan; - public Color Color { get; private set; } + public Color Color { get; private set; } - public Point Position { get; private set; } + public Point Position { get; private set; } - public double Radius { get; private set; } + public double Radius { get; private set; } - public void Update(DateTime realTime, TimeSpan elapsedTime) - { - var lifetime = Lifespan - Age; - var ratio = Math.Clamp(1.0 - elapsedTime / lifetime, 0.0, 1.0); - Age += elapsedTime; - Radius = ratio * Radius; - Color = new Color(Color.R, Color.G, Color.B, (byte)Math.Ceiling(ratio * Color.A)); - } + public void Update(TimeSpan elapsedTime) + { + var lifetime = Lifespan - Age; + var ratio = Clamp(1.0 - elapsedTime / lifetime, 0.0, 1.0); + Age += elapsedTime; + Radius = ratio * Radius; + Color = new Color(Color.R, Color.G, Color.B, (byte)Ceiling(ratio * Color.A)); + } - public void Render(Renderer renderer) - { - if (renderer is null) - { - throw new ArgumentNullException(nameof(renderer)); - } + public void Render(Renderer renderer) + { + ArgumentNullException.ThrowIfNull(renderer); - renderer.DrawColor = Color; - renderer.BlendMode = BlendMode.Blend; - renderer.FillCircle(Position.X, Position.Y, (int)Math.Ceiling(Radius)); - } + renderer.DrawColor = Color; + renderer.BlendMode = BlendMode.Blend; + renderer.FillCircle(Position.X, Position.Y, (int)Ceiling(Radius)); } } diff --git a/samples/ParticleSystem/ParticleEmitter.cs b/samples/ParticleSystem/ParticleEmitter.cs index e4fe2ea8..bc0666f4 100644 --- a/samples/ParticleSystem/ParticleEmitter.cs +++ b/samples/ParticleSystem/ParticleEmitter.cs @@ -21,88 +21,82 @@ using System; using System.Collections.Generic; using SDL2Sharp; -using SDL2Sharp.Extensions; +using static System.Math; -namespace ParticleSystem +internal sealed class ParticleEmitter { - internal sealed class ParticleEmitter + public ParticleEmitter(Color color, Point position, int radius) { - public ParticleEmitter(Color color, Point position, int radius) - { - Color = color; - Position = position; - Radius = radius; - Particles = new List(GenerateParticles(250)); - } + Color = color; + Position = position; + Radius = radius; + Particles = new List(GenerateParticles(250)); + } - public Color Color { get; } + public Color Color { get; } - public Point Position { get; private set; } + public Point Position { get; private set; } - public int Radius { get; } + public int Radius { get; } - private List Particles { get; } + private List Particles { get; } - public void MoveTo(int mouseX, int mouseY) - { - Position = new Point(mouseX, mouseY); - } + public void MoveTo(int mouseX, int mouseY) + { + Position = new Point(mouseX, mouseY); + } - public void Update(DateTime realTime, TimeSpan elapsedTime) + public void Update(TimeSpan elapsedTime) + { + foreach (var particle in Particles) { - foreach (var particle in Particles) + if (particle.IsDead) { - if (particle.IsDead) - { - var angle = _randomizer.NextDouble() * Math.PI * 2; - var x = Position.X + Math.Cos(angle) * Radius * 2; - var y = Position.Y + Math.Sin(angle) * Radius * 2; - var position = new Point((int)x, (int)y); - - var r = (byte)(_randomizer.NextDouble() * byte.MaxValue); - var g = (byte)(_randomizer.NextDouble() * byte.MaxValue); - var b = (byte)(_randomizer.NextDouble() * byte.MaxValue); - var color = new Color(r, g, b, byte.MaxValue); + var angle = _randomizer.NextDouble() * PI * 2; + var x = Position.X + Cos(angle) * Radius * 2; + var y = Position.Y + Sin(angle) * Radius * 2; + var position = new Point((int)x, (int)y); - var lifespan = TimeSpan.FromSeconds(_randomizer.NextDouble()); + var r = (byte)(_randomizer.NextDouble() * byte.MaxValue); + var g = (byte)(_randomizer.NextDouble() * byte.MaxValue); + var b = (byte)(_randomizer.NextDouble() * byte.MaxValue); + var color = new Color(r, g, b, byte.MaxValue); - particle.Respawn(lifespan, color, position, 7); - } - - particle.Update(realTime, elapsedTime); - } - } - - public void Render(Renderer renderer) - { - if (renderer is null) - { - throw new ArgumentNullException(nameof(renderer)); - } + var lifespan = TimeSpan.FromSeconds(_randomizer.NextDouble()); - foreach (var particle in Particles) - { - particle.Render(renderer); + particle.Respawn(lifespan, color, position, 7); } - renderer.DrawColor = Color; - renderer.BlendMode = BlendMode.Blend; - renderer.FillCircle(Position.X, Position.Y, Radius); + particle.Update(elapsedTime); } + } - private static readonly Random _randomizer = new(); + public void Render(Renderer renderer) + { + ArgumentNullException.ThrowIfNull(renderer); - private static Particle GenerateParticle() + foreach (var particle in Particles) { - return new Particle(); + particle.Render(renderer); } - private static IEnumerable GenerateParticles(int max) + renderer.DrawColor = Color; + renderer.BlendMode = BlendMode.Blend; + renderer.FillCircle(Position.X, Position.Y, Radius); + } + + private static readonly Random _randomizer = new(); + + private static Particle GenerateParticle() + { + return new Particle(); + } + + private static IEnumerable GenerateParticles(int max) + { + for (var i = 0; i < max; ++i) { - for (var i = 0; i < max; ++i) - { - yield return GenerateParticle(); - } + yield return GenerateParticle(); } } } diff --git a/samples/ParticleSystem/ParticleSystem.csproj b/samples/ParticleSystem/ParticleSystem.csproj index c63d3ebd..26956d4a 100644 --- a/samples/ParticleSystem/ParticleSystem.csproj +++ b/samples/ParticleSystem/ParticleSystem.csproj @@ -2,7 +2,7 @@ WinExe - net6.0 + net8.0 AnyCPU false @@ -21,7 +21,6 @@ - diff --git a/samples/ParticleSystem/Program.cs b/samples/ParticleSystem/Program.cs new file mode 100644 index 00000000..8a5fc704 --- /dev/null +++ b/samples/ParticleSystem/Program.cs @@ -0,0 +1,103 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Diagnostics; +using SDL2Sharp; + +internal static class Program +{ + public static void Main() + { +#pragma warning disable IDE1006 // Naming Styles + using var SDL = new SDL(); +#pragma warning restore IDE1006 // Naming Styles + + using var window = SDL.Video.CreateWindow("Particle System", 640, 480, WindowFlags.Shown | WindowFlags.Resizable); + using var renderer = window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); + using var lazyFont = SDL.Fonts.OpenFont("lazy.ttf", 28); + + var particleEmitterColor = new Color(255, 0, 0, 255); + var particleEmmiterPosition = new Point(window.Width / 2, window.Height / 2); + var particleEmitter = new ParticleEmitter(particleEmitterColor, particleEmmiterPosition, 15); + + var lastFrameTime = TimeSpan.Zero; + var accumulatedFrameTime = TimeSpan.Zero; + var frameCounter = 0; + var frameRate = 0d; + + var programClock = Stopwatch.StartNew(); + + while (true) + { + var @event = SDL.Events.PollEvent(); + if (@event is not null) + { + switch (@event) + { + case QuitEvent: + return; + + case KeyUpEvent keyEvent when !keyEvent.Repeat: + switch (keyEvent.KeyCode) + { + case KeyCode.Return when keyEvent.Modifiers.HasFlag(KeyModifiers.Alt): + case KeyCode.F11: + window.IsFullScreenDesktop = !window.IsFullScreenDesktop; + break; + } + break; + + case MouseMotionEvent motionEvent: + particleEmitter.MoveTo(motionEvent.X, motionEvent.Y); + break; + } + } + else + { + var currentFrameTime = programClock.Elapsed; + var elapsedFrameTime = currentFrameTime - lastFrameTime; + accumulatedFrameTime += elapsedFrameTime; + + renderer.DrawColor = Color.Black; + renderer.BlendMode = BlendMode.None; + renderer.Clear(); + particleEmitter.Update(elapsedFrameTime); + particleEmitter.Render(renderer); + renderer.DrawColor = Color.White; + renderer.DrawTextBlended(8, 8, lazyFont, $"FPS: {frameRate:0.0}"); + renderer.Present(); + + if (accumulatedFrameTime >= TimeSpan.FromSeconds(1)) + { + frameRate = frameCounter / accumulatedFrameTime.TotalSeconds; + accumulatedFrameTime = TimeSpan.Zero; + frameCounter = 0; + } + else + { + ++frameCounter; + } + + lastFrameTime = currentFrameTime; + } + } + } +} diff --git a/samples/PlasmaFractal/App.cs b/samples/PlasmaFractal/App.cs deleted file mode 100644 index 673bcb50..00000000 --- a/samples/PlasmaFractal/App.cs +++ /dev/null @@ -1,346 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Diagnostics; -using SDL2Sharp; -using SDL2Sharp.Colors; -using SDL2Sharp.Extensions; -using static System.Math; -using static SDL2Sharp.Extensions.MathExtensions; - -namespace PlasmaFractal -{ - internal sealed class App : Application - { - private static readonly TimeSpan HideCursorDelay = TimeSpan.FromSeconds(1); - - private static readonly Font _frameRateFont = new("lazy.ttf", 28); - - private static readonly Color _frameRateColor = new(255, 255, 255, 255); - - private static readonly Color _backgroundColor = new(0, 0, 0, 255); - - private Window _window = null!; - - private Renderer _renderer = null!; - - private PackedTexture _screenImage = null!; - - private PackedMemoryImage _sourceImage = null!; - - private Palette _palette = null!; - - private Stopwatch _realTime = null!; - - private Stopwatch _frameTime = null!; - - private int _frameCount; - - private double _frameRate; - - private volatile bool _reversePaletteRotation = false; - - private DateTime _cursorLastActive = DateTime.UtcNow; - - protected override void OnInitializing() - { - Subsystems = Subsystems.Video; - } - - protected override void OnInitialized() - { - _window = new Window("Plasma Fractal", 512, 512, WindowFlags.Shown | WindowFlags.Resizable); - _window.KeyDown += OnWindowKeyDown; - _window.SizeChanged += OnWindowSizeChanged; - _window.MouseMotion += OnWindowMouseMotion; - _renderer = _window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); - _screenImage = _renderer.CreateTexture(TextureAccess.Streaming, _renderer.OutputSize); - _sourceImage = GenerateDiamondSquareImage(_renderer.OutputSize); - _palette = GeneratePalette(); - _realTime = new Stopwatch(); - _frameTime = new Stopwatch(); - _frameCount = 0; - _frameRate = double.NaN; - _realTime.Start(); - } - - protected override void OnQuiting() - { - _realTime.Stop(); - _renderer?.Dispose(); - _window?.Dispose(); - } - - protected override void OnIdle() - { - if (Cursor.Shown) - { - var cursorInactivity = DateTime.UtcNow - _cursorLastActive; - if (cursorInactivity >= HideCursorDelay) - { - Cursor.Hide(); - } - } - - _frameTime.Start(); - Render(_realTime.Elapsed); - _frameTime.Stop(); - _frameCount++; - - if (_frameTime.ElapsedMilliseconds >= 1000d) - { - _frameRate = _frameCount * 1000d / _frameTime.ElapsedMilliseconds; - _frameCount = 0; - _frameTime.Reset(); - } - } - - private void Render(TimeSpan realTime) - { - _screenImage.WithLock(screenImage => - { - for (var y = 0; y < screenImage.Height; ++y) - { - for (var x = 0; x < screenImage.Width; ++x) - { - screenImage[y, x] = _palette[_sourceImage[y, x]]; - } - } - }); - - _renderer.BlendMode = BlendMode.None; - _renderer.DrawColor = _backgroundColor; - _renderer.Clear(); - _renderer.Copy(_screenImage); - _renderer.DrawColor = _frameRateColor; - _renderer.DrawTextBlended(8, 8, _frameRateFont, $"FPS: {_frameRate:0.0}"); - _renderer.Present(); - - if (_reversePaletteRotation) - { - _palette.RotateRight(); - } - else - { - _palette.RotateLeft(); - } - } - - private void OnWindowKeyDown(object? sender, KeyEventArgs e) - { - if (sender is Window window) - { - if (e.KeyCode == KeyCode.F11 || (e.KeyCode == KeyCode.Return && e.Alt)) - { - window.IsFullScreenDesktop = !window.IsFullScreenDesktop; - } - - if (e.KeyCode == KeyCode.R) - { - _reversePaletteRotation = !_reversePaletteRotation; - } - } - } - - private void OnWindowSizeChanged(object? sender, WindowSizeChangedEventArgs e) - { - _screenImage?.Dispose(); - _renderer?.Dispose(); - _renderer = _window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); - _screenImage = _renderer.CreateTexture(TextureAccess.Streaming, _renderer.OutputSize); - _sourceImage = GenerateDiamondSquareImage(_renderer.OutputSize); - } - - private void OnWindowMouseMotion(object? sender, MouseMotionEventArgs e) - { - if (Cursor.Hidden) - { - Cursor.Show(); - } - - _cursorLastActive = DateTime.UtcNow; - } - - private static readonly Random _random = new(); - - private static Palette GeneratePalette() - { - var palette = new Palette(256); - for (var i = 0; i < 32; ++i) - { - var lo = (byte)(i * 255 / 31); - var hi = (byte)(255 - lo); - palette[i] = new Argb8888(0xFF, lo, 0, 0); - palette[i + 32] = new Argb8888(0xFF, hi, 0, 0); - palette[i + 64] = new Argb8888(0xFF, 0, lo, 0); - palette[i + 96] = new Argb8888(0xFF, 0, hi, 0); - palette[i + 128] = new Argb8888(0xFF, 0, 0, lo); - palette[i + 160] = new Argb8888(0xFF, 0, 0, hi); - palette[i + 192] = new Argb8888(0xFF, lo, 0, lo); - palette[i + 224] = new Argb8888(0xFF, hi, 0, hi); - } - return palette; - } - - private static PackedMemoryImage GenerateDiamondSquareImage(Size size) - { - return GenerateDiamondSquareImage(size.Width, size.Height); - } - - private static PackedMemoryImage GenerateDiamondSquareImage(int width, int height) - { - var size = NextPowerOfTwo(Max(width, height)) + 1; - var image = GenerateDiamondSquareImage(size); - return image.Crop(0, 0, height, width); - } - - private static PackedMemoryImage GenerateDiamondSquareImage(int size) - { - var image = new PackedMemoryImage(size, size); - - var randomness = 256; - - image[0, 0] = (byte)_random.Next(0, randomness); - image[0, size - 1] = (byte)_random.Next(0, randomness); - image[size - 1, 0] = (byte)_random.Next(0, randomness); - image[size - 1, size - 1] = (byte)_random.Next(0, randomness); - - randomness /= 2; - - for (var stepSize = size - 1; stepSize > 1; stepSize /= 2) - { - var halfStepSize = stepSize / 2; - - for (var y = halfStepSize; y < image.Height; y += stepSize) - { - for (var x = halfStepSize; x < image.Width; x += stepSize) - { - Diamond(image, x, y, halfStepSize, randomness); - } - } - - for (var y = 0; y < image.Height; y += halfStepSize) - { - for (var x = (y % stepSize) == 0 ? halfStepSize : 0; x < image.Width; x += stepSize) - { - Square(image, x, y, halfStepSize, randomness); - } - } - - randomness /= 2; - } - return image; - } - - private static void Diamond(PackedMemoryImage map, int centerX, int centerY, int distance, int randomness) - { - var sum = 0; - var count = 0; - var top = centerY - distance; - if (top >= 0 && top < map.Height) - { - var left = centerX - distance; - if (left >= 0 && left < map.Width) - { - sum += map[top, left]; - count++; - } - - var right = centerX + distance; - if (right >= 0 && right < map.Height) - { - sum += map[top, right]; - count++; - } - } - - var bottom = centerY + distance; - if (bottom >= 0 && bottom < map.Height) - { - var left = centerX - distance; - if (left >= 0 && left < map.Width) - { - sum += map[bottom, left]; - count++; - } - - var right = centerX + distance; - if (right >= 0 && right < map.Height) - { - sum += map[bottom, right]; - count++; - } - } - - var average = sum / count; - var random = _random.Next(-randomness, randomness); - var value = Clamp(average + random, 0, 255); - - map[centerY, centerX] = (byte)value; - } - - private static void Square(PackedMemoryImage map, int centerX, int centerY, int distance, int randomness) - { - var sum = 0; - var count = 0; - var top = centerY - distance; - if (top >= 0 && top < map.Height) - { - sum += map[top, centerX]; - count++; - } - - var left = centerX - distance; - if (left >= 0 && left < map.Width) - { - sum += map[centerY, left]; - count++; - } - - var bottom = centerY + distance; - if (bottom >= 0 && bottom < map.Height) - { - sum += map[bottom, centerX]; - count++; - } - - var right = centerX + distance; - if (right >= 0 && right < map.Height) - { - sum += map[centerY, right]; - count++; - } - - var average = sum / count; - var random = _random.Next(-randomness, randomness); - var value = Clamp(average + random, 0, 255); - - map[centerY, centerX] = (byte)value; - } - - private static int Main(string[] args) - { - var app = new App(); - var exitCode = app.Run(args); - return exitCode; - } - } -} diff --git a/samples/PlasmaFractal/Palette.cs b/samples/PlasmaFractal/Palette.cs new file mode 100644 index 00000000..9f3b5c9d --- /dev/null +++ b/samples/PlasmaFractal/Palette.cs @@ -0,0 +1,106 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; + +internal sealed class Palette where TColor : struct +{ + private readonly TColor[] _colors; + + private int _offset; + + public int Count => _colors.Length; + + public TColor this[int index] + { + get + { + if (index < 0) + { + throw new ArgumentOutOfRangeException(nameof(index), index, "The specified index cannot be less than zero."); + } + + if (index >= _colors.Length) + { + throw new ArgumentOutOfRangeException(nameof(index), index, "The specified index cannot be greater than or equal to the number of colors in the palette."); + } + + var shiftedIndex = _offset + index; + if (shiftedIndex >= _colors.Length) + { + shiftedIndex -= _colors.Length; + } + + return _colors[shiftedIndex]; + } + set + { + if (index < 0) + { + throw new ArgumentOutOfRangeException(nameof(index), index, "The specified index cannot be less than zero."); + } + + if (index >= _colors.Length) + { + throw new ArgumentOutOfRangeException(nameof(index), index, "The specified index cannot be greater than or equal to the number of colors in the palette."); + } + + var shiftedIndex = _offset + index; + if (shiftedIndex >= _colors.Length) + { + shiftedIndex -= _colors.Length; + } + + _colors[shiftedIndex] = value; + } + } + + public Palette(int size) + { + if (size < 0) + { + throw new ArgumentOutOfRangeException(nameof(size), size, "The size of a palette cannot be less than zero"); + } + + _colors = new TColor[size]; + _offset = 0; + } + + public void RotateLeft() + { + --_offset; + + if (_offset < 0) + { + _offset += _colors.Length; + } + } + + public void RotateRight() + { + ++_offset; + + if (_offset >= _colors.Length) + { + _offset -= _colors.Length; + } + } +} + diff --git a/samples/PlasmaFractal/PlasmaFractal.csproj b/samples/PlasmaFractal/PlasmaFractal.csproj index c63d3ebd..26956d4a 100644 --- a/samples/PlasmaFractal/PlasmaFractal.csproj +++ b/samples/PlasmaFractal/PlasmaFractal.csproj @@ -2,7 +2,7 @@ WinExe - net6.0 + net8.0 AnyCPU false @@ -21,7 +21,6 @@ - diff --git a/samples/PlasmaFractal/Program.cs b/samples/PlasmaFractal/Program.cs new file mode 100644 index 00000000..2acd7eb6 --- /dev/null +++ b/samples/PlasmaFractal/Program.cs @@ -0,0 +1,293 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Diagnostics; +using SDL2Sharp; +using static System.Math; + +internal static class Program +{ + public static void Main() + { +#pragma warning disable IDE1006 // Naming Styles + using var SDL = new SDL(); +#pragma warning restore IDE1006 // Naming Styles + + using var window = SDL.Video.CreateWindow("Plasma Fractal", 640, 480, WindowFlags.Shown | WindowFlags.Resizable); + using var renderer = window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); + using var screenTexture = renderer.CreatePackedTexture(TextureAccess.Streaming, renderer.OutputSize); + using var lazyFont = SDL.Fonts.OpenFont("lazy.ttf", 28); + + var screenImage = new PackedMemoryImage(renderer.OutputSize); + var sourceImage = GenerateDiamondSquareImage(renderer.OutputSize); + var palette = GeneratePalette(); + var reversePaletteRotation = false; + + var lastFrameTime = TimeSpan.Zero; + var accumulatedFrameTime = TimeSpan.Zero; + var frameCounter = 0; + var frameRate = 0d; + + var programClock = Stopwatch.StartNew(); + + while (true) + { + var @event = SDL.Events.PollEvent(); + if (@event is not null) + { + switch (@event) + { + case QuitEvent: + return; + + case KeyUpEvent keyEvent when !keyEvent.Repeat: + switch (keyEvent.KeyCode) + { + case KeyCode.Return when keyEvent.Modifiers.HasFlag(KeyModifiers.Alt): + case KeyCode.F11: + window.IsFullScreenDesktop = !window.IsFullScreenDesktop; + break; + + case KeyCode.R: + reversePaletteRotation = !reversePaletteRotation; + break; + } + break; + } + } + else + { + var currentFrameTime = programClock.Elapsed; + var elapsedFrameTime = currentFrameTime - lastFrameTime; + accumulatedFrameTime += elapsedFrameTime; + + for (var y = 0; y < screenImage.Height; ++y) + { + for (var x = 0; x < screenImage.Width; ++x) + { + screenImage[x, y] = palette[sourceImage[x, y]]; + } + } + + screenTexture.Update(screenImage); + + renderer.BlendMode = BlendMode.None; + renderer.DrawColor = Color.Black; + renderer.Clear(); + renderer.Copy(screenTexture); + renderer.DrawColor = Color.White; + renderer.DrawTextBlended(8, 8, lazyFont, $"FPS: {frameRate:0.0}"); + renderer.Present(); + + if (reversePaletteRotation) + { + palette.RotateRight(); + } + else + { + palette.RotateLeft(); + } + + if (accumulatedFrameTime >= TimeSpan.FromSeconds(1)) + { + frameRate = frameCounter / accumulatedFrameTime.TotalSeconds; + accumulatedFrameTime = TimeSpan.Zero; + frameCounter = 0; + } + else + { + ++frameCounter; + } + + lastFrameTime = currentFrameTime; + } + } + } + + private static readonly Random _random = new(); + + private static Palette GeneratePalette() + { + var palette = new Palette(256); + for (var i = 0; i < 32; ++i) + { + var lo = (byte)(i * 255 / 31); + var hi = (byte)(255 - lo); + palette[i] = new ARGB8888(0xFF, lo, 0, 0); + palette[i + 32] = new ARGB8888(0xFF, hi, 0, 0); + palette[i + 64] = new ARGB8888(0xFF, 0, lo, 0); + palette[i + 96] = new ARGB8888(0xFF, 0, hi, 0); + palette[i + 128] = new ARGB8888(0xFF, 0, 0, lo); + palette[i + 160] = new ARGB8888(0xFF, 0, 0, hi); + palette[i + 192] = new ARGB8888(0xFF, lo, 0, lo); + palette[i + 224] = new ARGB8888(0xFF, hi, 0, hi); + } + return palette; + } + + private static PackedMemoryImage GenerateDiamondSquareImage(Size size) + { + return GenerateDiamondSquareImage(size.Width, size.Height); + } + + private static PackedMemoryImage GenerateDiamondSquareImage(int width, int height) + { + var size = NextPowerOfTwo(Max(width, height)) + 1; + var image = GenerateDiamondSquareImage(size); + return image.Crop(0, 0, height, width); + } + + private static PackedMemoryImage GenerateDiamondSquareImage(int size) + { + var image = new PackedMemoryImage(size, size); + + var randomness = 256; + + image[0, 0] = (byte)_random.Next(0, randomness); + image[size - 1, 0] = (byte)_random.Next(0, randomness); + image[0, size - 1] = (byte)_random.Next(0, randomness); + image[size - 1, size - 1] = (byte)_random.Next(0, randomness); + + randomness /= 2; + + for (var stepSize = size - 1; stepSize > 1; stepSize /= 2) + { + var halfStepSize = stepSize / 2; + + for (var y = halfStepSize; y < image.Height; y += stepSize) + { + for (var x = halfStepSize; x < image.Width; x += stepSize) + { + Diamond(image, x, y, halfStepSize, randomness); + } + } + + for (var y = 0; y < image.Height; y += halfStepSize) + { + for (var x = (y % stepSize) == 0 ? halfStepSize : 0; x < image.Width; x += stepSize) + { + Square(image, x, y, halfStepSize, randomness); + } + } + + randomness /= 2; + } + return image; + } + + private static void Diamond(PackedMemoryImage map, int centerX, int centerY, int distance, int randomness) + { + var sum = 0; + var count = 0; + var top = centerY - distance; + if (top >= 0 && top < map.Height) + { + var left = centerX - distance; + if (left >= 0 && left < map.Width) + { + sum += map[left, top]; + count++; + } + + var right = centerX + distance; + if (right >= 0 && right < map.Height) + { + sum += map[right, top]; + count++; + } + } + + var bottom = centerY + distance; + if (bottom >= 0 && bottom < map.Height) + { + var left = centerX - distance; + if (left >= 0 && left < map.Width) + { + sum += map[left, bottom]; + count++; + } + + var right = centerX + distance; + if (right >= 0 && right < map.Height) + { + sum += map[right, bottom]; + count++; + } + } + + var average = sum / count; + var random = _random.Next(-randomness, randomness); + var value = Clamp(average + random, 0, 255); + + map[centerX, centerY] = (byte)value; + } + + private static void Square(PackedMemoryImage map, int centerX, int centerY, int distance, int randomness) + { + var sum = 0; + var count = 0; + var top = centerY - distance; + if (top >= 0 && top < map.Height) + { + sum += map[centerX, top]; + count++; + } + + var left = centerX - distance; + if (left >= 0 && left < map.Width) + { + sum += map[left, centerY]; + count++; + } + + var bottom = centerY + distance; + if (bottom >= 0 && bottom < map.Height) + { + sum += map[centerX, bottom]; + count++; + } + + var right = centerX + distance; + if (right >= 0 && right < map.Height) + { + sum += map[right, centerY]; + count++; + } + + var average = sum / count; + var random = _random.Next(-randomness, randomness); + var value = Clamp(average + random, 0, 255); + + map[centerX, centerY] = (byte)value; + } + + private static int NextPowerOfTwo(int value) + { + --value; + value |= value >> 1; + value |= value >> 2; + value |= value >> 4; + value |= value >> 8; + value |= value >> 16; + ++value; + return value; + } +} diff --git a/samples/RayTracer/App.cs b/samples/RayTracer/App.cs deleted file mode 100644 index 3c7f1464..00000000 --- a/samples/RayTracer/App.cs +++ /dev/null @@ -1,310 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Diagnostics; -using System.Numerics; -using SDL2Sharp; -using SDL2Sharp.Colors; -using SDL2Sharp.Extensions; - -namespace RayTracer -{ - internal sealed class App : Application - { - private static readonly Font _frameRateFont = new("lazy.ttf", 28); - - private static readonly Color _frameRateTextColor = new(255, 255, 255, 255); - - private static readonly Color _backgroundColor = new(0, 0, 0, 255); - - private Window _window = null!; - - private Renderer _renderer = null!; - - private PackedTexture _screenTexture = null!; - - private PackedMemoryImage _screenImage = null!; - - private Stopwatch _frameTime = null!; - - private int _framesCounted = 0; - - private double _framesPerSecond = double.NaN; - - private World _world = null!; - - private Camera _camera = null!; - - protected override void OnInitializing() - { - Subsystems = Subsystems.Video; - } - - protected override void OnInitialized() - { - _window = new Window("Ray Tracer", 640, 480, WindowFlags.Resizable); - _window.KeyDown += OnWindowKeyDown; - _window.SizeChanged += OnWindowSizeChanged; - _window.MouseWheel += OnMouseWheel; - _renderer = _window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); - _screenTexture = _renderer.CreateTexture(TextureAccess.Streaming, _renderer.OutputSize); - _screenImage = new PackedMemoryImage(_renderer.OutputSize); - _frameTime = new Stopwatch(); - _world = new World - { - Ambient = new Rgb32f(0.55f, 0.44f, 0.47f), - Objects = - { - // Backdrop Plane - new Plane - { - Position = new Vector3(0f, 0f, 0f), - Normal = new Vector3(0f, 1f, 0f), - Surface = new MatteSurface - { - DiffuseColor = new Rgb32f(1f, 1f, 1f), - } - }, - // Large center orange Sphere - new Sphere - { - Position = new Vector3(0f, 5.25f, 0f), - Radius = 10.5f / 2f, - Surface = new MatteSurface - { - DiffuseColor = new Rgb32f(0.89f, 0.48f, 0.42f) - } - }, - // Small center yellow Sphere - new Sphere - { - Position = new Vector3(-3.5f, 1.6f, -6.7f), - Radius = 3.2f / 2f, - Surface = new MatteSurface - { - DiffuseColor = new Rgb32f(0.95f, 0.93f, 0.31f) - } - }, - //// Large back right pink Sphere - //new Sphere - //{ - // Position = new Vector3(14f, 7f, 6.5f), - // Radius = 14f / 2f, - // Surface = new MatteSurface - // { - // DiffuseColor = new Rgb32f(1f, 0.44f, 0.64f) - // } - //}, - //// Small front right orange Sphere - //new Sphere - //{ - // Position = new Vector3(8.2f, 3.5f, -6.5f), - // Radius = 7f / 2f, - // Surface = new MatteSurface - // { - // DiffuseColor = new Rgb32f(0.89f, 0.48f, 0.42f) - // } - //}, - //// Large back left pink Sphere - //new Sphere - //{ - // Position = new Vector3(-16.6f, 6.5f, 0f), - // Radius = 13f / 2f, - // Surface = new MatteSurface - // { - // DiffuseColor = new Rgb32f(1f, 0.44f, 0.64f) - // } - //}, - //// Medium front back left pink Sphere - //new Sphere - //{ - // Position = new Vector3(-9.5f, 3f, -6f), - // Radius = 6f / 2f, - // Surface = new MatteSurface - // { - // DiffuseColor = new Rgb32f(1f, 0.44f, 0.64f) - // } - //}, - //// Back left yellow Sphere - //new Sphere - //{ - // Position = new Vector3(-15f, 3f, 12f), - // Radius = 6f / 2f, - // Surface = new MatteSurface - // { - // DiffuseColor = new Rgb32f(0.95f, 0.93f, 0.31f) - // } - //}, - //// Far Back right blue Sphere - //new Sphere - //{ - // Position = new Vector3(40f, 10f, 175f), - // Radius = 20f / 2f, - // Surface = new MatteSurface - // { - // DiffuseColor = new Rgb32f(0.18f, 0.31f, 0.68f) - // } - //}, - }, - Lights = - { - new PointLight - { - Position = new Vector3(-300f, 350f, 10f), - Color = new Rgb32f(0.70f, 0.689f, 0.6885f) - }, - }, - }; - - _camera = new Camera(); - _camera.Rotate( - -6f * MathF.PI / 180f, - 180f * MathF.PI / 180f, - 0f - ); - _camera.Move(0f, 8.5f, -26f); - } - - protected override void OnQuiting() - { - _window?.Dispose(); - } - - protected override void OnIdle() - { - _frameTime.Start(); - Render(); - _frameTime.Stop(); - _framesCounted++; - - if (_frameTime.ElapsedMilliseconds >= 1000) - { - _framesPerSecond = _framesCounted / _frameTime.Elapsed.TotalMilliseconds * 1000; - _framesCounted = 0; - _frameTime.Reset(); - } - } - - private void Render() - { - _camera.Shoot(_world, _screenImage); - _screenTexture.Update(_screenImage); - _renderer.BlendMode = BlendMode.None; - _renderer.DrawColor = _backgroundColor; - _renderer.Clear(); - _renderer.Copy(_screenTexture); - _renderer.DrawColor = _frameRateTextColor; - _renderer.DrawTextBlended(8, 8, _frameRateFont, $"FPS: {_framesPerSecond:0.0}"); - _renderer.Present(); - } - - private void OnWindowKeyDown(object? sender, KeyEventArgs e) - { - if (sender is not Window window) - { - return; - } - - switch (e.KeyCode) - { - case KeyCode.F11: - window.IsFullScreenDesktop = !window.IsFullScreenDesktop; - break; - - case KeyCode.Return: - if (e.Alt) - { - window.IsFullScreenDesktop = !window.IsFullScreenDesktop; - } - break; - - case KeyCode.W: - { - _camera.Move(0, 0, 1); - break; - } - - case KeyCode.S: - { - _camera.Move(0, 0, -1); - break; - } - - case KeyCode.A: - { - _camera.Move(-1, 0, 0); - break; - } - - case KeyCode.D: - { - _camera.Move(1, 0, 0); - break; - } - - case KeyCode.Up: - { - _camera.RotateX(1f * MathF.PI / 180f); - break; - } - - case KeyCode.Down: - { - _camera.RotateX(-1f * MathF.PI / 180f); - break; - } - - case KeyCode.Left: - { - _camera.RotateY(1f * MathF.PI / 180f); - break; - } - - case KeyCode.Right: - { - _camera.RotateY(-1f * MathF.PI / 180f); - break; - } - } - } - - private void OnWindowSizeChanged(object? sender, WindowSizeChangedEventArgs e) - { - _screenTexture?.Dispose(); - _renderer?.Dispose(); - _renderer = _window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); - _screenTexture = _renderer.CreateTexture(TextureAccess.Streaming, _renderer.OutputSize); - _screenImage = new PackedMemoryImage(_renderer.OutputSize); - } - - private void OnMouseWheel(object? sender, MouseWheelEventArgs e) - { - _camera.FieldOfView -= e.Y; - } - - private static int Main(string[] args) - { - var app = new App(); - var exitCode = app.Run(args); - return exitCode; - } - } -} diff --git a/samples/RayTracer/Camera.cs b/samples/RayTracer/Camera.cs index ae6eba94..0fd2cd30 100644 --- a/samples/RayTracer/Camera.cs +++ b/samples/RayTracer/Camera.cs @@ -19,160 +19,134 @@ // 3. This notice may not be removed or altered from any source distribution. using System; -using System.Linq; using System.Numerics; +using System.Threading.Tasks; using SDL2Sharp; -using SDL2Sharp.Colors; -using SDL2Sharp.Extensions; -namespace RayTracer +internal sealed class Camera { - internal sealed class Camera - { - private Matrix4x4 _viewMatrix = Matrix4x4.Identity; - - private float _fieldOfView; + private Vector3 _position = Vector3.Zero; - public Vector3 Position => _viewMatrix.Translation; + private Quaternion _orientation = Quaternion.Identity; - public Quaternion Orientation => Quaternion.CreateFromRotationMatrix(_viewMatrix); + public Resolution Resolution { get; } - public Resolution Resolution { get; } + public float PixelAspectRatio { get; } - public float PixelAspectRatio { get; } + public Frustum Frustum { get; } - public Frustum Frustum { get; } + public float FieldOfView { get; } - public float FieldOfView - { - get - { - return _fieldOfView; - } - set - { - _fieldOfView = value; - FocalLength = (float)(Resolution.Width / Resolution.Height / MathF.Tan(FieldOfView * MathF.PI / 180f / 2f)); - } - } + public float FocalLength { get; private set; } - public float FocalLength { get; private set; } + public PackedMemoryImage Snapshot { get; } - public Camera() - { - Resolution = new Resolution(640, 480); - PixelAspectRatio = 1f; - Frustum = new Frustum(-4f / 3f, 4f / 3f, -1f, +1f, float.Epsilon, float.PositiveInfinity); - FieldOfView = 90f; - FocalLength = (float)(Resolution.Width / Resolution.Height / MathF.Tan(FieldOfView * MathF.PI / 180f / 2f)); - } - - public void LookAt(Vector3 position, Vector3 target, Vector3 up) - { - _viewMatrix = Matrix4x4.CreateLookAt(position, target, up); - } - - public void Move(Vector3 distance) - { - _viewMatrix *= Matrix4x4.CreateTranslation(distance); - } + public Camera() + { + Resolution = new Resolution(640, 480); + PixelAspectRatio = 1f; + Frustum = new Frustum(-4f / 3f, 4f / 3f, -1f, +1f, float.Epsilon, float.PositiveInfinity); + FieldOfView = 90f; + FocalLength = (float)(Resolution.Width / Resolution.Height / MathF.Tan(FieldOfView * MathF.PI / 180f / 2f)); + Snapshot = new PackedMemoryImage(Resolution.Width, Resolution.Height); + } - public void Move(float x, float y, float z) - { - _viewMatrix *= Matrix4x4.CreateTranslation(x, y, z); - } + public void LookAt(Vector3 position, Vector3 target, Vector3 up) + { + var lookAtMatrix = Matrix4x4.CreateLookAt(position, target, up); + _position = lookAtMatrix.Translation; + _orientation = Quaternion.CreateFromRotationMatrix(lookAtMatrix); + } - public void RotateX(float radians) - { - _viewMatrix *= Matrix4x4.CreateRotationX(radians); - } + public void MoveForward(float distance) + { + var forwardVector = Vector3.Transform(Vector3.UnitZ, _orientation); + var translation = forwardVector * distance; + _position += translation; + } - public void RotateY(float radians) - { - _viewMatrix *= Matrix4x4.CreateRotationY(radians); - } + public void MoveBackward(float distance) + { + var forwardVector = Vector3.Transform(Vector3.UnitZ, _orientation); + var translation = forwardVector * -distance; + _position += translation; + } - public void RotateZ(float radians) - { - _viewMatrix *= Matrix4x4.CreateRotationZ(radians); - } + public void MoveLeft(float distance) + { + var rightVector = Vector3.Transform(Vector3.UnitX, _orientation); + var translation = rightVector * distance; + _position += translation; + } - public void Rotate(float yaw, float pitch, float roll) - { - _viewMatrix *= Matrix4x4.CreateFromYawPitchRoll(yaw, pitch, roll); - } + public void MoveRight(float distance) + { + var rightVector = Vector3.Transform(Vector3.UnitX, _orientation); + var translation = rightVector * -distance; + _position += translation; + } - public void Shoot(World world, PackedMemoryImage image) - { - if (world is null) - { - throw new ArgumentNullException(nameof(world)); - } + public void MoveUp(float distance) + { + var upVector = Vector3.Transform(Vector3.UnitY, _orientation); + var translation = upVector * distance; + _position += translation; + } - for (var imageY = 0; imageY < image.Height; ++imageY) - { - for (var imageX = 0; imageX < image.Width; ++imageX) - { - var rayDirection = Vector3.Normalize( - new Vector3( - Frustum.Left + imageX * Frustum.Width / image.Width, - Frustum.Bottom + imageY * Frustum.Height / image.Height, - -FocalLength - ) - ); - - var ray = new Ray(Vector3.Zero, Vector3.Normalize(rayDirection)); - var rayWorld = Ray.Transform(ray, _viewMatrix); - var color = Trace(world, rayWorld, 0, 1f); - image[imageY, imageX] = color.ToArgb8888(); - } - } - } + public void MoveDown(float distance) + { + var upVector = Vector3.Transform(Vector3.UnitY, _orientation); + var translation = upVector * -distance; + _position += translation; + } - private static Rgb32f Trace(World world, Ray ray, int level, float weight) - { - var intersection = ray.Intersect(world.Objects).MinBy(e => e.Distance); - if (intersection != null) - { - return Shade(world, intersection, level, weight); - } - return Rgb32f.Black; - } + public void Yaw(float radians) + { + var upVector = Vector3.Transform(Vector3.UnitY, _orientation); + var rotation = Quaternion.CreateFromAxisAngle(upVector, radians); + _orientation *= rotation; + } - private static Rgb32f Shade(World world, Intersection intersection, int level, float weight) - { - var shade = Rgb32f.Black; - var n = intersection.Normal; - var p = intersection.Point; + public void Pitch(float radians) + { + var rightVector = Vector3.Transform(Vector3.UnitX, _orientation); + var rotation = Quaternion.CreateFromAxisAngle(rightVector, radians); + _orientation *= rotation; + } - foreach (var light in world.Lights) - { - var l = Vector3.Normalize(light.Position - p); - //var illumination = Vector3.Dot(n, l); - //if (illumination > 0f) - //{ - // var shadowRay = new Ray(p, -l); - // if (Shadow(world, shadowRay, Vector3.Distance(p, light.Position)) > 0f) - // { - // shade += illumination * light.Color; - // } - //} - var i = intersection.Object.Surface.Shade(world.Ambient, n, l, light.Color); - shade += i; - } - return shade; - } + public void Roll(float radians) + { + var forwardVector = Vector3.Transform(Vector3.UnitZ, _orientation); + var rotation = Quaternion.CreateFromAxisAngle(forwardVector, radians); + _orientation *= rotation; + } - private const float RoundOffErrorTolerance = 1e-7f; + public PackedMemoryImage TakeSnapshot(World world) + { + ArgumentNullException.ThrowIfNull(world); - private static float Shadow(World world, Ray ray, float tmax) + var rotationMatrix = Matrix4x4.CreateFromQuaternion(Quaternion.Inverse(_orientation)); + var translationMatrix = Matrix4x4.CreateTranslation(-_position); + var viewMatrix = rotationMatrix * translationMatrix; + Parallel.For(0, Snapshot.Height, y => { - var intersection = ray.Intersect(world.Objects).MinBy(e => e.Distance); - if (intersection == null || intersection.Distance > tmax - RoundOffErrorTolerance) + for (var x = 0; x < Snapshot.Width; ++x) { - return 1f; + var rayDirection = Vector3.Normalize( + new Vector3( + Frustum.Left + x * Frustum.Width / Snapshot.Width, + Frustum.Bottom + y * Frustum.Height / Snapshot.Height, + -FocalLength + ) + ); + + var ray = new Ray(Vector3.Zero, Vector3.Normalize(rayDirection)); + var rayWorld = Ray.Transform(ray, viewMatrix); + var color = world.Trace(rayWorld, 0, 1f); + Snapshot[x, y] = color.ToArgb8888(); } - return 0f; - } + }); + + return Snapshot; } } diff --git a/samples/RayTracer/Frustum.cs b/samples/RayTracer/Frustum.cs index b8870df5..2ff599e8 100644 --- a/samples/RayTracer/Frustum.cs +++ b/samples/RayTracer/Frustum.cs @@ -18,34 +18,31 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -namespace RayTracer +internal sealed class Frustum { - internal sealed class Frustum + public Frustum(float left, float right, float bottom, float top, float near, float far) { - public Frustum(float left, float right, float bottom, float top, float near, float far) - { - Left = left; - Right = right; - Bottom = bottom; - Top = top; - Near = near; - Far = far; - } + Left = left; + Right = right; + Bottom = bottom; + Top = top; + Near = near; + Far = far; + } - public float Left { get; } + public float Left { get; } - public float Right { get; } + public float Right { get; } - public float Bottom { get; } + public float Bottom { get; } - public float Top { get; } + public float Top { get; } - public float Near { get; } + public float Near { get; } - public float Far { get; } + public float Far { get; } - public float Width => Right - Left; + public float Width => Right - Left; - public float Height => Top - Bottom; - } + public float Height => Top - Bottom; } diff --git a/samples/RayTracer/IObject.cs b/samples/RayTracer/IObject.cs index 020536a1..6087a6be 100644 --- a/samples/RayTracer/IObject.cs +++ b/samples/RayTracer/IObject.cs @@ -19,15 +19,17 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Numerics; +using SDL2Sharp; -namespace RayTracer +internal interface IObject { - internal interface IObject - { - ISurface Surface { get; } + float AmbientCoefficient { get; set; } - Intersection? Intersect(Ray ray); + float DiffuseCoefficient { get; set; } - Vector3 NormalAt(Vector3 surfacePoint); - } + RGB96f DiffuseColor { get; set; } + + Intersection? Intersect(Ray ray); + + Vector3 NormalAt(Vector3 surfacePoint); } diff --git a/samples/RayTracer/Intersection.cs b/samples/RayTracer/Intersection.cs index 7d459029..17c6e14c 100644 --- a/samples/RayTracer/Intersection.cs +++ b/samples/RayTracer/Intersection.cs @@ -20,38 +20,35 @@ using System.Numerics; -namespace RayTracer +internal sealed class Intersection { - internal sealed class Intersection + public Intersection(IObject @object, Ray ray, float distance) { - public Intersection(IObject @object, Ray ray, float distance) - { - Object = @object; - Ray = ray; - Distance = distance; - } + Object = @object; + Ray = ray; + Distance = distance; + } - public IObject Object { get; } + public IObject Object { get; } - public Ray Ray { get; } + public Ray Ray { get; } - public float Distance { get; } + public float Distance { get; } - public Vector3 Point => Ray.Origin + Ray.Direction * Distance; + public Vector3 Point => Ray.Origin + Ray.Direction * Distance; - public Vector3 Normal + public Vector3 Normal + { + get { - get - { - var normal = Object.NormalAt(Point); - - if (Vector3.Dot(Ray.Direction, normal) > 0f) - { - normal = Vector3.Negate(normal); - } + var normal = Object.NormalAt(Point); - return normal; + if (Vector3.Dot(Ray.Direction, normal) > 0f) + { + normal = Vector3.Negate(normal); } + + return normal; } } } diff --git a/samples/RayTracer/MatteSurface.cs b/samples/RayTracer/MatteSurface.cs deleted file mode 100644 index 37c544e7..00000000 --- a/samples/RayTracer/MatteSurface.cs +++ /dev/null @@ -1,39 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Numerics; -using SDL2Sharp.Extensions; - -namespace RayTracer -{ - internal sealed class MatteSurface : ISurface - { - public float AmbientCoefficient { get; set; } = 1f; - - public float DiffuseCoefficient { get; set; } = 1f; - - public Rgb32f DiffuseColor { get; set; } - - public Rgb32f Shade(Rgb32f ambient, Vector3 surfaceNormal, Vector3 lightVector, Rgb32f lightColor) - { - return ambient * AmbientCoefficient + lightColor * DiffuseCoefficient * DiffuseColor * Vector3.Dot(surfaceNormal, lightVector); - } - } -} diff --git a/samples/RayTracer/Plane.cs b/samples/RayTracer/Plane.cs index 77d39936..d63d36bc 100644 --- a/samples/RayTracer/Plane.cs +++ b/samples/RayTracer/Plane.cs @@ -19,38 +19,40 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Numerics; +using SDL2Sharp; -namespace RayTracer +internal sealed class Plane : IObject { - internal sealed class Plane : IObject - { - public Vector3 Position { get; set; } = new Vector3(0f, 0f, 0f); + public float AmbientCoefficient { get; set; } = 1f; + + public float DiffuseCoefficient { get; set; } = 1f; + + public RGB96f DiffuseColor { get; set; } = RGB96f.Black; + + public Vector3 Position { get; set; } = new Vector3(0f, 0f, 0f); - public Vector3 Normal { get; set; } = new Vector3(0f, 1f, 0f); + public Vector3 Normal { get; set; } = new Vector3(0f, 1f, 0f); - public ISurface Surface { get; set; } = new MatteSurface(); + public Vector3 NormalAt(Vector3 point) + { + return Normal; + } - public Vector3 NormalAt(Vector3 point) + public Intersection? Intersect(Ray ray) + { + var denominator = Vector3.Dot(Normal, ray.Direction); + if (denominator == 0f) { - return Normal; + return null; } - public Intersection? Intersect(Ray ray) + var numerator = -Vector3.Dot(Normal, ray.Origin + Position); + var t = numerator / denominator; + if (t <= Ray.Epsilon) { - var denominator = Vector3.Dot(Normal, ray.Direction); - if (denominator == 0f) - { - return null; - } - - var numerator = -Vector3.Dot(Normal, ray.Origin + Position); - var t = numerator / denominator; - if (t < 0) - { - return null; - } - - return new Intersection(this, ray, t); + return null; } + + return new Intersection(this, ray, t); } } diff --git a/samples/RayTracer/PointLight.cs b/samples/RayTracer/PointLight.cs index beebae59..c4e594b5 100644 --- a/samples/RayTracer/PointLight.cs +++ b/samples/RayTracer/PointLight.cs @@ -19,14 +19,11 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Numerics; -using SDL2Sharp.Extensions; +using SDL2Sharp; -namespace RayTracer +internal sealed class PointLight { - internal sealed class PointLight - { - public Vector3 Position { get; set; } + public Vector3 Position { get; set; } - public Rgb32f Color { get; set; } - } + public RGB96f Color { get; set; } } diff --git a/samples/RayTracer/Program.cs b/samples/RayTracer/Program.cs new file mode 100644 index 00000000..ebd7c428 --- /dev/null +++ b/samples/RayTracer/Program.cs @@ -0,0 +1,253 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Diagnostics; +using System.Numerics; +using SDL2Sharp; + +internal static class Program +{ + public static void Main() + { +#pragma warning disable IDE1006 // Naming Styles + using var SDL = new SDL(); +#pragma warning restore IDE1006 // Naming Styles + + using var window = SDL.Video.CreateWindow("Ray Tracer", 640, 480, WindowFlags.Shown | WindowFlags.Resizable); + using var renderer = window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); + using var screenTexture = renderer.CreatePackedTexture(TextureAccess.Streaming, renderer.OutputSize); + using var lazyFont = SDL.Fonts.OpenFont("lazy.ttf", 28); + + var world = new World + { + Ambient = new RGB96f(0.55f, 0.44f, 0.47f), + Objects = + { + // Backdrop Plane + new Plane + { + Position = new Vector3(0f, 0f, 0f), + Normal = new Vector3(0f, 1f, 0f), + DiffuseColor = new RGB96f(.5f, .5f, .5f) + }, + // Large center orange Sphere + new Sphere + { + Position = new Vector3(0f, 5.25f, 0f), + Radius = 10.5f / 2f, + DiffuseColor = new RGB96f(0.89f, 0.48f, 0.42f) + }, + // Small center yellow Sphere + new Sphere + { + Position = new Vector3(-3.5f, 1.6f, -6.7f), + Radius = 3.2f / 2f, + DiffuseColor = new RGB96f(0.95f, 0.93f, 0.31f) + }, + // Large back right pink Sphere + new Sphere + { + Position = new Vector3(14f, 7f, 6.5f), + Radius = 14f / 2f, + DiffuseColor = new RGB96f(1f, 0.44f, 0.64f) + }, + // Small front right orange Sphere + new Sphere + { + Position = new Vector3(8.2f, 3.5f, -6.5f), + Radius = 7f / 2f, + DiffuseColor = new RGB96f(0.89f, 0.48f, 0.42f) + }, + // Large back left pink Sphere + new Sphere + { + Position = new Vector3(-16.6f, 6.5f, 0f), + Radius = 13f / 2f, + DiffuseColor = new RGB96f(1f, 0.44f, 0.64f) + }, + // Medium front back left pink Sphere + new Sphere + { + Position = new Vector3(-9.5f, 3f, -6f), + Radius = 6f / 2f, + DiffuseColor = new RGB96f(1f, 0.44f, 0.64f) + }, + // Back left yellow Sphere + new Sphere + { + Position = new Vector3(-15f, 3f, 12f), + Radius = 6f / 2f, + DiffuseColor = new RGB96f(0.95f, 0.93f, 0.31f) + }, + // Far Back right blue Sphere + new Sphere + { + Position = new Vector3(40f, 10f, 175f), + Radius = 20f / 2f, + DiffuseColor = new RGB96f(0.18f, 0.31f, 0.68f) + }, + }, + Lights = + { + new PointLight + { + Position = new Vector3(-300f, 350f, 10f), + Color = new RGB96f(0.70f, 0.689f, 0.6885f) + }, + }, + }; + + var camera = new Camera(); + camera.Roll(180f * MathF.PI / 180f); + camera.Pitch(6f * MathF.PI / 180f); + camera.MoveUp(8.5f); + camera.MoveBackward(32f); + + var lastFrameTime = TimeSpan.Zero; + var accumulatedFrameTime = TimeSpan.Zero; + var frameCounter = 0; + var frameRate = 0d; + + var programClock = Stopwatch.StartNew(); + + while (true) + { + var @event = SDL.Events.PollEvent(); + if (@event is not null) + { + switch (@event) + { + case QuitEvent: + return; + + case KeyUpEvent keyEvent: + switch (keyEvent.KeyCode) + { + case KeyCode.Return when keyEvent.Modifiers.HasFlag(KeyModifiers.Alt): + case KeyCode.F11: + window.IsFullScreenDesktop = !window.IsFullScreenDesktop; + break; + } + break; + } + } + else + { + var currentFrameTime = programClock.Elapsed; + var elapsedFrameTime = currentFrameTime - lastFrameTime; + accumulatedFrameTime += elapsedFrameTime; + + var keyboardState = SDL.KeyboardState; + if (keyboardState.IsPressed(Scancode.Up) || keyboardState.IsPressed(Scancode.Keypad8)) + { + camera.Pitch(1f * MathF.PI / 180f); + } + + if (keyboardState.IsPressed(Scancode.Down) || keyboardState.IsPressed(Scancode.Keypad2)) + { + camera.Pitch(-1f * MathF.PI / 180f); + } + + if (keyboardState.IsPressed(Scancode.Left) || keyboardState.IsPressed(Scancode.Keypad4)) + { + camera.Yaw(1f * MathF.PI / 180f); + } + + if (keyboardState.IsPressed(Scancode.Right) || keyboardState.IsPressed(Scancode.Keypad6)) + { + camera.Yaw(-1f * MathF.PI / 180f); + } + + if (keyboardState.IsPressed(Scancode.Keypad7)) + { + camera.Roll(1f * MathF.PI / 180f); + } + + if (keyboardState.IsPressed(Scancode.Keypad9)) + { + camera.Roll(-1f * MathF.PI / 180f); + } + + if (keyboardState.IsPressed(Scancode.W)) + { + if (keyboardState.IsPressed(Scancode.LeftShift)) + { + camera.MoveUp(1); + } + else + { + camera.MoveForward(1); + } + } + + if (keyboardState.IsPressed(Scancode.S)) + { + if (keyboardState.IsPressed(Scancode.LeftShift)) + { + camera.MoveDown(1); + } + else + { + camera.MoveBackward(1); + } + } + + if (keyboardState.IsPressed(Scancode.A)) + { + camera.MoveLeft(1); + } + + if (keyboardState.IsPressed(Scancode.D)) + { + camera.MoveRight(1); + } + + if (keyboardState.IsPressed(Scancode.Q)) + { + camera.MoveUp(1); + } + + screenTexture.Update(camera.TakeSnapshot(world)); + + renderer.BlendMode = BlendMode.None; + renderer.DrawColor = Color.Black; + renderer.Clear(); + renderer.Copy(screenTexture); + renderer.DrawColor = Color.White; + renderer.DrawTextBlended(8, 8, lazyFont, $"FPS: {frameRate:0.0}"); + renderer.Present(); + + if (accumulatedFrameTime >= TimeSpan.FromSeconds(1)) + { + frameRate = frameCounter / accumulatedFrameTime.TotalSeconds; + accumulatedFrameTime = TimeSpan.Zero; + frameCounter = 0; + } + else + { + ++frameCounter; + } + + lastFrameTime = currentFrameTime; + } + } + } +} diff --git a/samples/RayTracer/Ray.cs b/samples/RayTracer/Ray.cs index 86038627..6329960f 100644 --- a/samples/RayTracer/Ray.cs +++ b/samples/RayTracer/Ray.cs @@ -20,27 +20,26 @@ using System.Numerics; -namespace RayTracer +internal readonly struct Ray { - internal readonly struct Ray - { - public Vector3 Origin { get; } + public const float Epsilon = 1e-2f; - public Vector3 Direction { get; } + public Vector3 Origin { get; } - public Ray(Vector3 origin, Vector3 direction) - { - Origin = origin; - Direction = direction; - } + public Vector3 Direction { get; } - public static Ray Transform(Ray ray, Matrix4x4 matrix) - { - var origin = Vector3.Transform(ray.Origin, matrix); - var direction = Vector3.Normalize( - Vector3.TransformNormal(ray.Direction, matrix) - ); - return new Ray(origin, direction); - } + public Ray(Vector3 origin, Vector3 direction) + { + Origin = origin; + Direction = direction; + } + + public static Ray Transform(Ray ray, Matrix4x4 matrix) + { + var origin = Vector3.Transform(ray.Origin, matrix); + var direction = Vector3.Normalize( + Vector3.TransformNormal(ray.Direction, matrix) + ); + return new Ray(origin, direction); } } diff --git a/samples/RayTracer/RayExtensions.cs b/samples/RayTracer/RayExtensions.cs index 80b75325..c4024dc8 100644 --- a/samples/RayTracer/RayExtensions.cs +++ b/samples/RayTracer/RayExtensions.cs @@ -19,21 +19,15 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Collections.Generic; +using System.Linq; -namespace RayTracer +internal static class RayExtensions { - internal static class RayExtensions + public static Intersection? Intersect(this Ray ray, IEnumerable objects) { - public static IEnumerable Intersect(this Ray ray, IEnumerable objects) - { - foreach (var @object in objects) - { - var intersection = @object.Intersect(ray); - if (intersection != null) - { - yield return intersection; - } - } - } + return objects + .Select(@object => @object.Intersect(ray)) + .Where(@intersection => @intersection is not null) + .MinBy(@intersection => @intersection!.Distance); } } diff --git a/samples/RayTracer/RayTracer.csproj b/samples/RayTracer/RayTracer.csproj index 30820e0c..2a8fa539 100644 --- a/samples/RayTracer/RayTracer.csproj +++ b/samples/RayTracer/RayTracer.csproj @@ -2,7 +2,7 @@ WinExe - net6.0 + net8.0 AnyCPU false @@ -21,7 +21,6 @@ - diff --git a/samples/RayTracer/Resolution.cs b/samples/RayTracer/Resolution.cs index 2887862f..719ab5c5 100644 --- a/samples/RayTracer/Resolution.cs +++ b/samples/RayTracer/Resolution.cs @@ -20,56 +20,53 @@ using System; -namespace RayTracer +internal struct Resolution { - internal struct Resolution + private int _width; + + private int _height; + + public Resolution(int width, int height) { - private int _width; + if (width <= 0) + throw new ArgumentOutOfRangeException( + nameof(width), "Width must be greater than zero"); - private int _height; + if (height <= 0) + throw new ArgumentOutOfRangeException( + nameof(height), "Height must be greater than zero"); - public Resolution(int width, int height) - { - if (width <= 0) - throw new ArgumentOutOfRangeException( - nameof(width), "Width must be greater than zero"); + _width = width; + _height = height; + } - if (height <= 0) + public int Width + { + get + { + return _width; + } + set + { + if (_width <= 0) throw new ArgumentOutOfRangeException( - nameof(height), "Height must be greater than zero"); - - _width = width; - _height = height; + nameof(value), "Width must be greater than zero"); + _width = value; } + } - public int Width + public int Height + { + get { - get - { - return _width; - } - set - { - if (_width <= 0) - throw new ArgumentOutOfRangeException( - nameof(value), "Width must be greater than zero"); - _width = value; - } + return _height; } - - public int Height + set { - get - { - return _height; - } - set - { - if (_height <= 0) - throw new ArgumentOutOfRangeException( - nameof(value), "Height must be greater than zero"); - _height = value; - } + if (_height <= 0) + throw new ArgumentOutOfRangeException( + nameof(value), "Height must be greater than zero"); + _height = value; } } } diff --git a/samples/RayTracer/Sphere.cs b/samples/RayTracer/Sphere.cs index 5c35ab27..b7d3961c 100644 --- a/samples/RayTracer/Sphere.cs +++ b/samples/RayTracer/Sphere.cs @@ -20,45 +20,49 @@ using System; using System.Numerics; +using SDL2Sharp; -namespace RayTracer +internal sealed class Sphere : IObject { - internal sealed class Sphere : IObject - { - public Vector3 Position { get; set; } = new Vector3(0f, 0f, 0f); + public Vector3 Position { get; set; } = new Vector3(0f, 0f, 0f); - public float Radius { get; set; } = 1f; + public float Radius { get; set; } - public ISurface Surface { get; set; } = new MatteSurface(); + public float AmbientCoefficient { get; set; } = 1f; - public Vector3 NormalAt(Vector3 point) - { - return Vector3.Normalize((point - Position) / Radius); - } + public float DiffuseCoefficient { get; set; } = 1f; + + public RGB96f DiffuseColor { get; set; } = RGB96f.Black; + + public Vector3 NormalAt(Vector3 point) + { + return Vector3.Normalize((point - Position) / Radius); + } - public Intersection? Intersect(Ray ray) + public Intersection? Intersect(Ray ray) + { + var v = Position - ray.Origin; + var b = Vector3.Dot(v, ray.Direction); + var discriminant = b * b - Vector3.Dot(v, v) + Radius * Radius; + if (discriminant <= 0f) { - var v = ray.Origin - Position; - var b = Vector3.Dot(v, ray.Direction); - var c = Vector3.Dot(v, v) - Radius * Radius; - if (c > 0f && b > 0f) - { - return null; - } + return null; + } - var discriminant = b * b - c; - if (discriminant < 0f) - { - return null; - } + discriminant = MathF.Sqrt(discriminant); - var t = -b - MathF.Sqrt(discriminant); - if (t < 0f) - { - t = 0f; - } + var t2 = b + discriminant; + if (t2 <= Ray.Epsilon) + { + return null; + } - return new Intersection(this, ray, t); + var t1 = b - discriminant; + if (t1 > Ray.Epsilon) + { + return new Intersection(this, ray, t1); } + + return new Intersection(this, ray, t2); } } diff --git a/samples/RayTracer/VectorExtensions.cs b/samples/RayTracer/VectorExtensions.cs index e1e87554..c5de8855 100644 --- a/samples/RayTracer/VectorExtensions.cs +++ b/samples/RayTracer/VectorExtensions.cs @@ -21,17 +21,14 @@ using System; using System.Numerics; -namespace RayTracer +internal static class VectorExtensions { - internal static class VectorExtensions + public static Vector3 RotateX(this Vector3 vector, float radians) { - public static Vector3 RotateX(this Vector3 vector, float radians) - { - return new Vector3( - vector.X, - vector.Y * MathF.Cos(radians) - vector.Z * MathF.Sin(radians), - vector.Y * MathF.Sin(radians) + vector.Z * MathF.Cos(radians) - ); - } + return new Vector3( + vector.X, + vector.Y * MathF.Cos(radians) - vector.Z * MathF.Sin(radians), + vector.Y * MathF.Sin(radians) + vector.Z * MathF.Cos(radians) + ); } } diff --git a/samples/RayTracer/World.cs b/samples/RayTracer/World.cs index 1be43b53..d4090819 100644 --- a/samples/RayTracer/World.cs +++ b/samples/RayTracer/World.cs @@ -18,17 +18,59 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +using System; using System.Collections.Generic; -using SDL2Sharp.Extensions; +using System.Numerics; +using SDL2Sharp; -namespace RayTracer +internal sealed class World { - internal sealed class World + public RGB96f Ambient { get; set; } + + public ICollection Objects { get; } = []; + + public ICollection Lights { get; } = []; + + public RGB96f Trace(Ray ray, int level, float weight) + { + var nearestIntersection = ray.Intersect(Objects); + if (nearestIntersection is not null) + { + return Shade(nearestIntersection, level, weight); + } + return RGB96f.Black; + } + + private RGB96f Shade(Intersection intersection, int level, float weight) { - public Rgb32f Ambient { get; set; } + var color = RGB96f.Black; + var @object = intersection.Object; + var surfaceNormal = intersection.Normal; + var surfacePoint = intersection.Point; - public ICollection Objects { get; } = new List(); + foreach (var light in Lights) + { + var lightVector = Vector3.Normalize(light.Position - surfacePoint); + var illumination = Vector3.Dot(surfaceNormal, lightVector); + var shadowRay = new Ray(surfacePoint, lightVector); + var visibility = Shadow(shadowRay, MathF.Abs(Vector3.Distance(surfacePoint, light.Position))); + if (illumination > 0f && visibility > 0f) + { + var ambientCoefficient = intersection.Object.AmbientCoefficient; + var diffuseCoefficient = intersection.Object.DiffuseCoefficient; + color += Ambient * ambientCoefficient + light.Color * diffuseCoefficient * @object.DiffuseColor * illumination; + } + } + return color; + } - public ICollection Lights { get; } = new List(); + private float Shadow(Ray ray, float maxDistance) + { + var nearestIntersection = ray.Intersect(Objects); + if (nearestIntersection is null || nearestIntersection.Distance > (maxDistance - Ray.Epsilon)) + { + return 1f; + } + return 0f; } } diff --git a/samples/SwirlStars/App.cs b/samples/SwirlStars/App.cs deleted file mode 100644 index c144dbf0..00000000 --- a/samples/SwirlStars/App.cs +++ /dev/null @@ -1,209 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Diagnostics; -using System.Numerics; -using System.Collections.Generic; -using SDL2Sharp; -using SDL2Sharp.Extensions; - -namespace SwirlStars -{ - internal sealed class App : Application - { - private static readonly TimeSpan HideCursorDelay = TimeSpan.FromSeconds(1); - - private static readonly Font _frameRateFont = new("lazy.ttf", 28); - - private static readonly Color _frameRateColor = new(255, 255, 255, 255); - - private static readonly Color _backgroundColor = new(0, 0, 0, 255); - - private static readonly Random _randomizer = new(); - - private Window _window = null!; - - private Renderer _renderer = null!; - - private Stopwatch _realTime = null!; - - private Stopwatch _frameTime = null!; - - private int _frameCount; - - private double _frameRate; - - private DateTime _cursorLastActive = DateTime.UtcNow; - - private List _stars = null!; - - protected override void OnInitializing() - { - Subsystems = Subsystems.Video; - } - - protected override void OnInitialized() - { - _window = new Window("Swirl Stars", 640, 480, WindowFlags.Shown | WindowFlags.Resizable); - _window.KeyDown += OnWindowKeyDown; - _window.SizeChanged += OnWindowSizeChanged; - _window.MouseMotion += OnWindowMouseMotion; - _renderer = _window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); - _realTime = new Stopwatch(); - _frameTime = new Stopwatch(); - _frameCount = 0; - _frameRate = double.NaN; - _realTime.Start(); - _stars = new List(GenerateStars(256)); - } - - private static IEnumerable GenerateStars(int count) - { - for (var i = 0; i < count; ++i) - { - var star = new Star(); - ResetStar(star); - yield return star; - } - } - - private static void ResetStar(Star star) - { - star.Position = new Vector3( - x: -500f + 1000f * _randomizer.NextSingle(), - y: -500f + 1000f * _randomizer.NextSingle(), - z: 100f + 900f * _randomizer.NextSingle()); - star.Velocity = new Vector3( - x: 0f, - y: 0f, - z: -(.5f + 4.5f * _randomizer.NextSingle())); - star.Color = new Rgb32f( - r: _randomizer.NextSingle(), - g: _randomizer.NextSingle(), - b: _randomizer.NextSingle() - ); - } - - protected override void OnQuiting() - { - _realTime.Stop(); - _renderer?.Dispose(); - _window?.Dispose(); - } - - protected override void OnIdle() - { - if (Cursor.Shown) - { - var cursorInactivity = DateTime.UtcNow - _cursorLastActive; - if (cursorInactivity >= HideCursorDelay) - { - Cursor.Hide(); - } - } - - _frameTime.Start(); - Render(_realTime.Elapsed); - _frameTime.Stop(); - _frameCount++; - - if (_frameTime.ElapsedMilliseconds >= 1000d) - { - _frameRate = _frameCount * 1000d / _frameTime.ElapsedMilliseconds; - _frameCount = 0; - _frameTime.Reset(); - } - } - - private void Render(TimeSpan realTime) - { - _renderer.BlendMode = BlendMode.None; - _renderer.DrawColor = _backgroundColor; - _renderer.Clear(); - - var screenSize = _renderer.OutputSize; - var screenCenterX = screenSize.Width / 2f; - var screenCenterY = screenSize.Height / 2f; - const int maxSubFrameCount = 20; - for (var subFrame = 0; subFrame < maxSubFrameCount; subFrame++) - { - foreach (var star in _stars) - { - star.Position += star.Velocity / maxSubFrameCount; - - var screenX = star.Position.X / star.Position.Z * 100f + screenCenterX; - var screenY = star.Position.Y / star.Position.Z * 100f + screenCenterY; - if (screenX < 0f || screenX >= screenSize.Width || - screenY < 0f || screenY >= screenSize.Height || - star.Position.Z < 0f || star.Position.Z > 1000f) - { - ResetStar(star); - } - - var starBrightness = 1f - Vector3.Distance(Vector3.Zero, star.Position) / 1000f; - var starDimmedColor = star.Color * starBrightness; - var starDrawColor = starDimmedColor.ToColor(); - _renderer.DrawColor = starDrawColor; - _renderer.DrawPoint(screenX, screenY); - } - } - - _renderer.DrawColor = _frameRateColor; - _renderer.DrawTextBlended(8, 8, _frameRateFont, $"FPS: {_frameRate:0.0}"); - _renderer.Present(); - } - - private void OnWindowKeyDown(object? sender, KeyEventArgs e) - { - if (sender is Window window) - { - if (e.KeyCode == KeyCode.F11 || (e.KeyCode == KeyCode.Return && e.Alt)) - { - window.IsFullScreenDesktop = !window.IsFullScreenDesktop; - } - } - } - - private void OnWindowSizeChanged(object? sender, WindowSizeChangedEventArgs e) - { - _renderer?.Dispose(); - - _renderer = _window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); - } - - private void OnWindowMouseMotion(object? sender, MouseMotionEventArgs e) - { - if (Cursor.Hidden) - { - Cursor.Show(); - } - - _cursorLastActive = DateTime.UtcNow; - } - - private static int Main(string[] args) - { - var app = new App(); - var exitCode = app.Run(args); - return exitCode; - } - } -} diff --git a/samples/SwirlStars/Program.cs b/samples/SwirlStars/Program.cs new file mode 100644 index 00000000..97c053bc --- /dev/null +++ b/samples/SwirlStars/Program.cs @@ -0,0 +1,154 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Diagnostics; +using System.Numerics; +using System.Collections.Generic; +using SDL2Sharp; + +internal static class Program +{ + public static void Main() + { +#pragma warning disable IDE1006 // Naming Styles + using var SDL = new SDL(); +#pragma warning restore IDE1006 // Naming Styles + + using var window = SDL.Video.CreateWindow("Swirl Stars", 640, 480, WindowFlags.Shown | WindowFlags.Resizable); + using var renderer = window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); + using var lazyFont = SDL.Fonts.OpenFont("lazy.ttf", 28); + + var stars = new List(GenerateStars(256)); + + var lastFrameTime = TimeSpan.Zero; + var accumulatedFrameTime = TimeSpan.Zero; + var frameCounter = 0; + var frameRate = 0d; + + var programClock = Stopwatch.StartNew(); + + while (true) + { + var @event = SDL.Events.PollEvent(); + if (@event is not null) + { + switch (@event) + { + case QuitEvent: + return; + + case KeyUpEvent keyEvent when !keyEvent.Repeat: + switch (keyEvent.KeyCode) + { + case KeyCode.Return when keyEvent.Modifiers.HasFlag(KeyModifiers.Alt): + case KeyCode.F11: + window.IsFullScreenDesktop = !window.IsFullScreenDesktop; + break; + } + break; + } + } + else + { + var currentFrameTime = programClock.Elapsed; + var elapsedFrameTime = currentFrameTime - lastFrameTime; + accumulatedFrameTime += elapsedFrameTime; + + renderer.DrawColor = Color.Black; + renderer.BlendMode = BlendMode.None; + renderer.Clear(); + + var screenSize = renderer.OutputSize; + var screenCenterX = screenSize.Width / 2f; + var screenCenterY = screenSize.Height / 2f; + const int maxSubFrameCount = 20; + for (var subFrame = 0; subFrame < maxSubFrameCount; subFrame++) + { + foreach (var star in stars) + { + star.Position += star.Velocity / maxSubFrameCount; + + var screenX = star.Position.X / star.Position.Z * 100f + screenCenterX; + var screenY = star.Position.Y / star.Position.Z * 100f + screenCenterY; + if (screenX < 0f || screenX >= screenSize.Width || + screenY < 0f || screenY >= screenSize.Height || + star.Position.Z < 0f || star.Position.Z > 1000f) + { + ResetStar(star); + } + + var starBrightness = 1f - Vector3.Distance(Vector3.Zero, star.Position) / 1000f; + var starDimmedColor = star.Color * starBrightness; + var starDrawColor = starDimmedColor.ToColor(); + renderer.DrawColor = starDrawColor; + renderer.DrawPoint(screenX, screenY); + } + } + + renderer.DrawColor = Color.White; + renderer.DrawTextBlended(8, 8, lazyFont, $"FPS: {frameRate:0.0}"); + renderer.Present(); + + if (accumulatedFrameTime >= TimeSpan.FromSeconds(1)) + { + frameRate = frameCounter / accumulatedFrameTime.TotalSeconds; + accumulatedFrameTime = TimeSpan.Zero; + frameCounter = 0; + } + else + { + ++frameCounter; + } + + lastFrameTime = currentFrameTime; + } + } + } + + private static readonly Random _randomizer = new(); + + private static IEnumerable GenerateStars(int count) + { + for (var i = 0; i < count; ++i) + { + var star = new Star(); + ResetStar(star); + yield return star; + } + } + + private static void ResetStar(Star star) + { + star.Position = new Vector3( + x: -500f + 1000f * _randomizer.NextSingle(), + y: -500f + 1000f * _randomizer.NextSingle(), + z: 100f + 900f * _randomizer.NextSingle()); + star.Velocity = new Vector3( + x: 0f, + y: 0f, + z: -(.5f + 4.5f * _randomizer.NextSingle())); + star.Color = new RGB96f( + r: _randomizer.NextSingle(), + g: _randomizer.NextSingle(), + b: _randomizer.NextSingle() + ); + } +} diff --git a/samples/SwirlStars/Star.cs b/samples/SwirlStars/Star.cs index cdc31674..fa725f90 100644 --- a/samples/SwirlStars/Star.cs +++ b/samples/SwirlStars/Star.cs @@ -19,16 +19,13 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Numerics; -using SDL2Sharp.Extensions; +using SDL2Sharp; -namespace SwirlStars +internal sealed class Star { - internal sealed class Star - { - public Vector3 Position { get; set; } = Vector3.Zero; + public Vector3 Position { get; set; } = Vector3.Zero; - public Vector3 Velocity { get; set; } = Vector3.Zero; + public Vector3 Velocity { get; set; } = Vector3.Zero; - public Rgb32f Color { get; set; } = Rgb32f.Black; - } + public RGB96f Color { get; set; } = RGB96f.Black; } diff --git a/samples/SwirlStars/SwirlStars.csproj b/samples/SwirlStars/SwirlStars.csproj index 30820e0c..2a8fa539 100644 --- a/samples/SwirlStars/SwirlStars.csproj +++ b/samples/SwirlStars/SwirlStars.csproj @@ -2,7 +2,7 @@ WinExe - net6.0 + net8.0 AnyCPU false @@ -21,7 +21,6 @@ - diff --git a/samples/TunnelEffect/App.cs b/samples/TunnelEffect/App.cs deleted file mode 100644 index f8f3ae4f..00000000 --- a/samples/TunnelEffect/App.cs +++ /dev/null @@ -1,239 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Diagnostics; -using Microsoft.Toolkit.HighPerformance; -using SDL2Sharp; -using SDL2Sharp.Colors; -using SDL2Sharp.Extensions; -using static System.Math; -using static SDL2Sharp.Extensions.MathExtensions; - -namespace TunnelEffect -{ - internal sealed class App : Application - { - private readonly struct Transform - { - public Transform(int angle, int distance) - { - Angle = angle; - Distance = distance; - } - - public int Angle { get; } - - public int Distance { get; } - } - - private static readonly Font _frameRateFont = new("lazy.ttf", 28); - - private static readonly Color _frameRateColor = new(255, 255, 255, 255); - - private static readonly Color _backgroundColor = new(0, 0, 0, 255); - - private Window _window = null!; - - private Renderer _renderer = null!; - - private PackedTexture _screenTexture = null!; - - private Memory2D _sourceImage = null!; - - private Memory2D _transformTable = null!; - - private Stopwatch _realTime = null!; - - private Stopwatch _frameTime = null!; - - private int _frameCount; - - private double _frameRate; - - protected override void OnInitializing() - { - Subsystems = Subsystems.Video; - } - - protected override void OnInitialized() - { - _window = new Window("Tunnel Effect", 640, 480, WindowFlags.Resizable); - _window.KeyDown += OnWindowKeyDown; - _window.SizeChanged += OnWindowSizeChanged; - _realTime = new Stopwatch(); - _frameTime = new Stopwatch(); - _frameCount = 0; - _frameRate = double.NaN; - - OnWindowSizeChanged(null, new WindowSizeChangedEventArgs(_window.Width, _window.Height)); - - _realTime.Start(); - } - - protected override void OnQuiting() - { - _realTime.Stop(); - _renderer?.Dispose(); - _window?.Dispose(); - } - - protected override void OnIdle() - { - _frameTime.Start(); - Render(_realTime.Elapsed); - _frameTime.Stop(); - _frameCount++; - - if (_frameTime.ElapsedMilliseconds >= 1000d) - { - _frameRate = _frameCount * 1000d / _frameTime.ElapsedMilliseconds; - _frameCount = 0; - _frameTime.Reset(); - } - } - - private void Render(TimeSpan realTime) - { - _screenTexture.WithLock(screenImage => - { - var screenWidth = screenImage.Width; - var screenHeight = screenImage.Height; - - var sourceImage = _sourceImage.Span; - var sourceWidth = _sourceImage.Width; - var sourceHeight = _sourceImage.Height; - var sourceWidthMask = sourceWidth - 1; - var sourceHeightMask = sourceHeight - 1; - - var transformTable = _transformTable.Span; - - var shiftX = (int)(screenWidth * 1.0 * realTime.TotalSeconds); - var shiftY = (int)(screenHeight * 0.25 * realTime.TotalSeconds); - var lookX = (sourceWidth - screenWidth) / 2; - var lookY = (sourceHeight - screenHeight) / 2; - var shiftLookX = shiftX + lookX; - var shiftLookY = shiftY + lookY; - - for (var screenY = 0; screenY < screenHeight; ++screenY) - { - var transformY = screenY + lookY; - for (var screenX = 0; screenX < screenWidth; ++screenX) - { - var transformX = screenX + lookX; - var transform = transformTable[transformY, transformX]; - var sourceX = (transform.Distance + shiftLookX) & sourceWidthMask; - var sourceY = (transform.Angle + shiftLookY) & sourceHeightMask; - screenImage[screenY, screenX] = sourceImage[sourceY, sourceX]; - } - } - }); - - _renderer.BlendMode = BlendMode.None; - _renderer.DrawColor = _backgroundColor; - _renderer.Clear(); - _renderer.Copy(_screenTexture); - _renderer.DrawColor = _frameRateColor; - _renderer.DrawTextBlended(8, 8, _frameRateFont, $"FPS: {_frameRate:0.0}"); - _renderer.Present(); - } - - private static Memory2D GenerateXorImage(int size) - { - return GenerateXorImage(size, size); - } - - private static Memory2D GenerateXorImage(int width, int height) - { - var image = new Argb8888[height, width]; - for (var y = 0; y < height; y++) - { - for (var x = 0; x < width; x++) - { - image[y, x] = new Argb8888( - a: 0xFF, - r: 0x00, - g: 0x00, - b: (byte)((x * 256 / width) ^ (y * 256 / height)) - ); - } - } - return new Memory2D(image); - } - - private static Memory2D GenerateTransformTable(int size) - { - return GenerateTransformTable(size, size); - } - - private static Memory2D GenerateTransformTable(int width, int height) - { - const double ratio = 32d; - var transformTable = new Transform[height, width]; - for (var y = 0; y < height; y++) - { - for (var x = 0; x < width; x++) - { - unchecked - { - var angle = (int)(0.5 * width * Atan2(y - height / 2.0, x - width / 2.0) / PI); - var distance = (int)(ratio * height / Sqrt((x - width / 2d) * (x - width / 2d) + (y - height / 2d) * (y - height / 2d))) % height; - transformTable[y, x] = new Transform(angle, distance); - } - } - } - return new Memory2D(transformTable); - } - - private void OnWindowKeyDown(object? sender, KeyEventArgs e) - { - if (sender is Window window) - { - if (e.KeyCode == KeyCode.F11 || (e.KeyCode == KeyCode.Return && e.Alt)) - { - window.IsFullScreenDesktop = !window.IsFullScreenDesktop; - } - } - } - - private void OnWindowSizeChanged(object? sender, WindowSizeChangedEventArgs e) - { - _screenTexture?.Dispose(); - - _renderer?.Dispose(); - - _renderer = _window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); - var screenSize = _renderer.OutputSize; - _screenTexture = _renderer.CreateTexture(TextureAccess.Streaming, screenSize); - var sourceImageSize = NextPowerOfTwo(Max(screenSize.Width, screenSize.Height)); - _sourceImage = GenerateXorImage(sourceImageSize); - _transformTable = GenerateTransformTable(sourceImageSize); - - _renderer.Present(); - } - - private static int Main(string[] args) - { - var app = new App(); - var exitCode = app.Run(args); - return exitCode; - } - } -} diff --git a/samples/TunnelEffect/Program.cs b/samples/TunnelEffect/Program.cs new file mode 100644 index 00000000..5a0f9bd1 --- /dev/null +++ b/samples/TunnelEffect/Program.cs @@ -0,0 +1,189 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Diagnostics; +using SDL2Sharp; +using static System.Math; + +internal static class Program +{ + public static void Main() + { +#pragma warning disable IDE1006 // Naming Styles + using var SDL = new SDL(); +#pragma warning restore IDE1006 // Naming Styles + + using var window = SDL.Video.CreateWindow("Tunnel Effect", 640, 480, WindowFlags.Shown | WindowFlags.Resizable); + using var renderer = window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); + using var screenTexture = renderer.CreatePackedTexture(TextureAccess.Streaming, renderer.OutputSize); + using var lazyFont = SDL.Fonts.OpenFont("lazy.ttf", 28); + + var screenImage = new PackedMemoryImage(renderer.OutputSize); + var sourceImageSize = NextPowerOfTwo(Max(renderer.OutputWidth, renderer.OutputHeight)); + var sourceImage = GenerateXorImage(sourceImageSize); + var transformTable = GenerateTransformTable(sourceImageSize); + + var lastFrameTime = TimeSpan.Zero; + var accumulatedFrameTime = TimeSpan.Zero; + var frameCounter = 0; + var frameRate = 0d; + + var programClock = Stopwatch.StartNew(); + + while (true) + { + var @event = SDL.Events.PollEvent(); + if (@event is not null) + { + switch (@event) + { + case QuitEvent: + return; + + case KeyUpEvent keyEvent when !keyEvent.Repeat: + switch (keyEvent.KeyCode) + { + case KeyCode.Return when keyEvent.Modifiers.HasFlag(KeyModifiers.Alt): + case KeyCode.F11: + window.IsFullScreenDesktop = !window.IsFullScreenDesktop; + break; + } + break; + } + } + else + { + var currentFrameTime = programClock.Elapsed; + var elapsedFrameTime = currentFrameTime - lastFrameTime; + accumulatedFrameTime += elapsedFrameTime; + + var screenWidth = screenImage.Width; + var screenHeight = screenImage.Height; + var sourceWidth = sourceImage.Width; + var sourceHeight = sourceImage.Height; + var sourceWidthMask = sourceWidth - 1; + var sourceHeightMask = sourceHeight - 1; + + var shiftX = (int)(screenWidth * 1.0 * currentFrameTime.TotalSeconds); + var shiftY = (int)(screenHeight * 0.25 * currentFrameTime.TotalSeconds); + var lookX = (sourceWidth - screenWidth) / 2; + var lookY = (sourceHeight - screenHeight) / 2; + var shiftLookX = shiftX + lookX; + var shiftLookY = shiftY + lookY; + + for (var screenY = 0; screenY < screenHeight; ++screenY) + { + var transformY = screenY + lookY; + for (var screenX = 0; screenX < screenWidth; ++screenX) + { + var transformX = screenX + lookX; + var transform = transformTable[transformX, transformY]; + var sourceX = (transform.Distance + shiftLookX) & sourceWidthMask; + var sourceY = (transform.Angle + shiftLookY) & sourceHeightMask; + screenImage[screenX, screenY] = sourceImage[sourceX, sourceY]; + } + } + + screenTexture.Update(screenImage); + + renderer.BlendMode = BlendMode.None; + renderer.DrawColor = Color.Black; + renderer.Clear(); + renderer.Copy(screenTexture); + renderer.DrawColor = Color.White; + renderer.DrawTextBlended(8, 8, lazyFont, $"FPS: {frameRate:0.0}"); + renderer.Present(); + + if (accumulatedFrameTime >= TimeSpan.FromSeconds(1)) + { + frameRate = frameCounter / accumulatedFrameTime.TotalSeconds; + accumulatedFrameTime = TimeSpan.Zero; + frameCounter = 0; + } + else + { + ++frameCounter; + } + + lastFrameTime = currentFrameTime; + } + } + } + + private static PackedMemoryImage GenerateXorImage(int size) + { + return GenerateXorImage(size, size); + } + + private static PackedMemoryImage GenerateXorImage(int width, int height) + { + var image = new PackedMemoryImage(width, height); + for (var y = 0; y < height; y++) + { + for (var x = 0; x < width; x++) + { + image[x, y] = new ARGB8888( + a: 0xFF, + r: 0x00, + g: 0x00, + b: (byte)((x * 256 / width) ^ (y * 256 / height)) + ); + } + } + return image; + } + + private static PackedMemoryImage GenerateTransformTable(int size) + { + return GenerateTransformTable(size, size); + } + + private static PackedMemoryImage GenerateTransformTable(int width, int height) + { + const double ratio = 32d; + var transformTable = new PackedMemoryImage(width, height); + for (var y = 0; y < height; y++) + { + for (var x = 0; x < width; x++) + { + unchecked + { + var angle = (int)(0.5 * width * Atan2(y - height / 2.0, x - width / 2.0) / PI); + var distance = (int)(ratio * height / Sqrt((x - width / 2d) * (x - width / 2d) + (y - height / 2d) * (y - height / 2d))) % height; + transformTable[x, y] = new Transform(angle, distance); + } + } + } + return transformTable; + } + + private static int NextPowerOfTwo(int value) + { + --value; + value |= value >> 1; + value |= value >> 2; + value |= value >> 4; + value |= value >> 8; + value |= value >> 16; + ++value; + return value; + } +} diff --git a/samples/TunnelEffect/Transform.cs b/samples/TunnelEffect/Transform.cs new file mode 100644 index 00000000..e5879fe1 --- /dev/null +++ b/samples/TunnelEffect/Transform.cs @@ -0,0 +1,32 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +internal readonly struct Transform +{ + public Transform(int angle, int distance) + { + Angle = angle; + Distance = distance; + } + + public int Angle { get; } + + public int Distance { get; } +} diff --git a/samples/TunnelEffect/TunnelEffect.csproj b/samples/TunnelEffect/TunnelEffect.csproj index 48babeb3..7934b626 100644 --- a/samples/TunnelEffect/TunnelEffect.csproj +++ b/samples/TunnelEffect/TunnelEffect.csproj @@ -2,7 +2,7 @@ WinExe - net6.0 + net8.0 AnyCPU false @@ -21,11 +21,10 @@ - + - diff --git a/samples/WavePlayer/App.cs b/samples/WavePlayer/App.cs deleted file mode 100644 index c9afc3f7..00000000 --- a/samples/WavePlayer/App.cs +++ /dev/null @@ -1,210 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Threading; -using SDL2Sharp; -using SDL2Sharp.Extensions; -using SDL2Sharp.Interop; - -namespace WavePlayer -{ - internal sealed class App : Application - { - private static readonly Font _frameRateFont = new("lazy.ttf", 28); - - private static readonly Color _frameRateColor = new(255, 255, 255, 255); - - private static readonly Color _backgroundColor = new(0, 0, 0, 255); - - private static readonly Color _waveColor = new(255, 255, 0, 255); - - private static readonly Color _channelSeparatorColor = new(0, 0, 255, 255); - - private Window _window = null!; - - private Thread _renderingThread = null!; - - private volatile bool _rendererInvalidated = false; - - private volatile bool _rendering = false; - - private WaveFile _waveFile = null!; - - private AudioDevice _audioDevice = null!; - - private int _wavePosition = 0; - - protected override void OnInitializing() - { - Subsystems = Subsystems.Audio | Subsystems.Video; - } - - protected override void OnInitialized() - { - Environment.SetEnvironmentVariable("SDL_AUDIODRIVER", "directsound"); - - try - { - _window = new Window("Wave Player", 640, 480, WindowFlags.Shown | WindowFlags.Resizable); - _window.SizeChanged += OnWindowSizeChanged; - _renderingThread = new Thread(Render); - _rendererInvalidated = true; - _rendering = true; - _waveFile = new WaveFile(CommandLineArgs[0]); - _audioDevice = new AudioDevice(_waveFile.Spec, OnAudioDeviceCallback, null!, AudioDeviceAllowedChanges.None); - _renderingThread.Start(); - _audioDevice.Unpause(); - } - catch (Exception e) - { - Console.Error.WriteLine($"Could not run sample: {e.Message}"); - Quit(1); - } - } - - protected override void OnQuiting() - { - _audioDevice?.Pause(); - _rendererInvalidated = false; - _rendering = false; - _renderingThread?.SafeJoin(); - _audioDevice?.Dispose(); - _waveFile?.Dispose(); - _window?.Dispose(); - } - - private void OnAudioDeviceCallback(object userdata, Span stream) - { - stream.Fill(_waveFile.Spec.Silence); - var sliceLength = (int)Math.Min(_waveFile.Length - _wavePosition, stream.Length); - if (sliceLength <= 0) - { - return; - } - var slice = _waveFile.Buffer.Slice(_wavePosition, sliceLength); - stream.MixAudioFormat(slice, _waveFile.Spec.Format, SDL.SDL_MIX_MAXVOLUME); - _wavePosition += sliceLength; - } - - private void OnWindowSizeChanged(object? sender, WindowSizeChangedEventArgs e) - { - _rendererInvalidated = true; - } - - private void Render() - { - Renderer renderer = null!; - var frameRateUpdatedTime = DateTime.Now; - var frameRateUpdateInterval = TimeSpan.FromMilliseconds(500d); - var frameRate = 0d; - var frameRateText = $"FPS: {frameRate:0.00}"; - var frameCounter = 0; - var channelCount = (int)_waveFile.Spec.Channels; - var waves = new Point[channelCount][]; - var sampleFormat = _waveFile.Spec.Format; - var sampleSize = sampleFormat.BitSize() / 8; - - try - { - while (_rendering) - { - if (_rendererInvalidated) - { - renderer?.Dispose(); - renderer = _window.CreateRenderer(RendererFlags.Accelerated/* | RendererFlags.PresentVSync*/); - for (var channel = 0; channel < channelCount; ++channel) - { - waves[channel] = new Point[renderer.OutputSize.Width]; - }; - _rendererInvalidated = false; - } - - renderer.DrawColor = _backgroundColor; - - renderer.Clear(); - - var currentTime = DateTime.Now; - var elapsedTime = currentTime - frameRateUpdatedTime; - if (elapsedTime > frameRateUpdateInterval) - { - frameRate = frameCounter / elapsedTime.TotalSeconds; - frameRateText = $"FPS: {frameRate:0.00}"; - frameRateUpdatedTime = currentTime; - frameCounter = 0; - } - - renderer.DrawColor = _frameRateColor; - - renderer.DrawTextBlended(8, 8, _frameRateFont, frameRateText); - - renderer.DrawColor = _waveColor; - - var channelHeight = renderer.OutputSize.Height / channelCount; - var halfGraphHeight = channelHeight * 9 / 20; - for (var channel = 0; channel < channelCount; ++channel) - { - var centerLine = channel * channelHeight + channelHeight / 2; - var sampleOffset = _wavePosition + sampleSize * channel; - for (var x = 0; x < renderer.OutputSize.Width; ++x) - { - var y = centerLine; - - if (sampleOffset < _waveFile.Buffer.Length) - { - var normalizedSample = _waveFile.Buffer.ToNormalizedSingle(sampleOffset, sampleFormat); - y = (int)(centerLine + normalizedSample * halfGraphHeight); - } - - waves[channel][x] = new Point(x, y); - - sampleOffset += sampleSize * channelCount; - } - - renderer.DrawLines(waves[channel]); - } - - renderer.DrawColor = _channelSeparatorColor; - - for (var channel = 0; channel <= channelCount; ++channel) - { - var y = channel * channelHeight; - renderer.DrawLine(0, y, renderer.OutputSize.Width, y); - } - - renderer.Present(); - - frameCounter++; - } - } - finally - { - renderer?.Dispose(); - } - } - - private static int Main(string[] args) - { - var app = new App(); - var exitCode = app.Run(args); - return exitCode; - } - } -} diff --git a/samples/WavePlayer/Program.cs b/samples/WavePlayer/Program.cs new file mode 100644 index 00000000..f46ba56a --- /dev/null +++ b/samples/WavePlayer/Program.cs @@ -0,0 +1,168 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Diagnostics; +using SDL2Sharp; +using static System.Math; +using static SDL2Sharp.StaticMethods; + +internal static class Program +{ + public static void Main() + { +#pragma warning disable IDE1006 // Naming Styles + using var SDL = new SDL(); +#pragma warning restore IDE1006 // Naming Styles + + using var window = SDL.Video.CreateWindow("Wave Player", 640, 480, WindowFlags.Shown | WindowFlags.Resizable); + using var renderer = window.CreateRenderer(RendererFlags.Accelerated | RendererFlags.PresentVSync); + using var lazyFont = SDL.Fonts.OpenFont("lazy.ttf", 28); + using var waveFile = SDL.Audio.OpenWaveFile(Environment.GetCommandLineArgs()[1]); + + var audioPlaybackPosition = 0; + var audioChannelCount = (int)waveFile.Channels; + var audioSampleSize = waveFile.Format.BitSize() / 8; + + using var audioDevice = SDL.Audio.OpenDevice( + waveFile.Frequency, + waveFile.Format, + waveFile.Channels, + waveFile.Samples, + OnAudioDeviceCallback, + AudioDeviceAllowedChanges.None); + + var lastFrameTime = TimeSpan.Zero; + var accumulatedFrameTime = TimeSpan.Zero; + var frameCounter = 0; + var frameRate = 0d; + + var programClock = Stopwatch.StartNew(); + + audioDevice.Unpause(); + + while (true) + { + var @event = SDL.Events.PollEvent(); + if (@event is not null) + { + switch (@event) + { + case QuitEvent: + return; + + case KeyUpEvent keyEvent when !keyEvent.Repeat: + switch (keyEvent.KeyCode) + { + case KeyCode.Return when keyEvent.Modifiers.HasFlag(KeyModifiers.Alt): + case KeyCode.F11: + window.IsFullScreenDesktop = !window.IsFullScreenDesktop; + break; + + case KeyCode.Space: + if (audioDevice.Status == AudioStatus.Paused) + { + audioDevice.Unpause(); + } + else + { + audioDevice.Pause(); + } + break; + } + break; + } + } + else + { + var currentFrameTime = programClock.Elapsed; + var elapsedFrameTime = currentFrameTime - lastFrameTime; + accumulatedFrameTime += elapsedFrameTime; + + renderer.DrawColor = Color.Black; + renderer.Clear(); + renderer.DrawColor = Color.Yellow; + + var audioWavePoints = new Point[renderer.OutputSize.Width]; + var renderChannelHeight = renderer.OutputSize.Height / audioChannelCount; + var renderHalfGraphHeight = renderChannelHeight * 9 / 20; + for (var channel = 0; channel < audioChannelCount; ++channel) + { + var renderCenterLine = channel * renderChannelHeight + renderChannelHeight / 2; + var audioSampleOffset = audioPlaybackPosition + audioSampleSize * channel; + for (var x = 0; x < audioWavePoints.Length; ++x) + { + var y = renderCenterLine; + + if (audioSampleOffset < waveFile.Buffer.Length) + { + var normalizedSample = waveFile.Buffer.ToNormalizedSingle(audioSampleOffset, waveFile.Format); + y = (int)(renderCenterLine + normalizedSample * renderHalfGraphHeight); + } + + audioWavePoints[x] = new Point(x, y); + + audioSampleOffset += audioSampleSize * audioChannelCount; + } + + renderer.DrawLines(audioWavePoints); + } + + renderer.DrawColor = Color.Blue; + + for (var channel = 0; channel <= audioChannelCount; ++channel) + { + var y = channel * renderChannelHeight; + renderer.DrawLine(0, y, renderer.OutputSize.Width - 1, y); + } + + renderer.DrawColor = Color.Black; + renderer.DrawTextBlendedCentered(lazyFont, $"Average Frames Per Second: {frameRate:0.0}"); + renderer.Present(); + + if (accumulatedFrameTime >= TimeSpan.FromSeconds(1)) + { + frameRate = frameCounter / accumulatedFrameTime.TotalSeconds; + accumulatedFrameTime = TimeSpan.Zero; + frameCounter = 0; + } + else + { + ++frameCounter; + } + + lastFrameTime = currentFrameTime; + } + } + + void OnAudioDeviceCallback(Span stream) + { + stream.Fill(waveFile.Silence); + var sliceLength = (int)Min(waveFile.Length - audioPlaybackPosition, stream.Length); + if (sliceLength <= 0) + { + return; + } + var slice = waveFile.Buffer.Slice(audioPlaybackPosition, sliceLength); + MixAudioFormat(stream, slice, waveFile.Format, AudioConstants.MixMaxVolume); + audioPlaybackPosition += sliceLength; + } + } +} diff --git a/samples/WavePlayer/WavePlayer.csproj b/samples/WavePlayer/WavePlayer.csproj index 27abf425..4748c446 100644 --- a/samples/WavePlayer/WavePlayer.csproj +++ b/samples/WavePlayer/WavePlayer.csproj @@ -2,7 +2,7 @@ WinExe - net8.0;net7.0;net6.0;net462;net47;net471;net472;net48;net481 + net8.0 AnyCPU false @@ -24,7 +24,6 @@ - diff --git a/sources/Directory.Build.props b/sources/Directory.Build.props index 1019778a..8454ffd6 100644 --- a/sources/Directory.Build.props +++ b/sources/Directory.Build.props @@ -22,7 +22,7 @@ - + \ No newline at end of file diff --git a/sources/SDL2Sharp.Extensions/SDL2Sharp.Extensions.csproj b/sources/SDL2Sharp.Extensions/SDL2Sharp.Extensions.csproj deleted file mode 100644 index 5c82e799..00000000 --- a/sources/SDL2Sharp.Extensions/SDL2Sharp.Extensions.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - netstandard2.0;net461 - AnyCPU - Provides extensions for type safe wrappers for SDL2 bindings written in C#. - SDL2 - - - - - - - - - - - diff --git a/sources/SDL2Sharp.Interop/.editorconfig b/sources/SDL2Sharp.Interop/.editorconfig new file mode 100644 index 00000000..e1713a8e --- /dev/null +++ b/sources/SDL2Sharp.Interop/.editorconfig @@ -0,0 +1,8 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = false + +# Treat code files as generated code +[*.cs] +generated_code = true \ No newline at end of file diff --git a/sources/SDL2Sharp.Interop/SDL2Sharp.Interop.csproj b/sources/SDL2Sharp.Interop/SDL2Sharp.Interop.csproj index 6038f918..da532c65 100644 --- a/sources/SDL2Sharp.Interop/SDL2Sharp.Interop.csproj +++ b/sources/SDL2Sharp.Interop/SDL2Sharp.Interop.csproj @@ -1,17 +1,21 @@  - netstandard2.0;net461 + net8.0 AnyCPU Provides SDL2 bindings written in C#. SDL2 - - - - + + + + + + + + diff --git a/sources/SDL2Sharp.Interop/SDL_AudioFilter.cs b/sources/SDL2Sharp.Interop/SDL_AudioFilter.cs deleted file mode 100644 index 6d696655..00000000 --- a/sources/SDL2Sharp.Interop/SDL_AudioFilter.cs +++ /dev/null @@ -1,27 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; - -namespace SDL2Sharp.Interop -{ - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public unsafe delegate void SDL_AudioFilter([NativeTypeName("struct SDL_AudioCVT *")] SDL_AudioCVT* cvt, [NativeTypeName("SDL_AudioFormat")] ushort format); -} diff --git a/sources/SDL2Sharp.Interop/SDL_HintCallback.cs b/sources/SDL2Sharp.Interop/SDL_HintCallback.cs deleted file mode 100644 index 799a0d49..00000000 --- a/sources/SDL2Sharp.Interop/SDL_HintCallback.cs +++ /dev/null @@ -1,27 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; - -namespace SDL2Sharp.Interop -{ - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public unsafe delegate void SDL_HintCallback(void* userdata, [NativeTypeName("const char *")] sbyte* name, [NativeTypeName("const char *")] sbyte* oldValue, [NativeTypeName("const char *")] sbyte* newValue); -} diff --git a/sources/SDL2Sharp.Interop/SDL_HitTest.cs b/sources/SDL2Sharp.Interop/SDL_HitTest.cs deleted file mode 100644 index fd412ad2..00000000 --- a/sources/SDL2Sharp.Interop/SDL_HitTest.cs +++ /dev/null @@ -1,27 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; - -namespace SDL2Sharp.Interop -{ - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public unsafe delegate SDL_HitTestResult SDL_HitTest(SDL_Window* win, [NativeTypeName("const SDL_Point *")] SDL_Point* area, void* data); -} diff --git a/sources/SDL2Sharp.Interop/SDL_LogOutputFunction.cs b/sources/SDL2Sharp.Interop/SDL_LogOutputFunction.cs deleted file mode 100644 index 08b8f567..00000000 --- a/sources/SDL2Sharp.Interop/SDL_LogOutputFunction.cs +++ /dev/null @@ -1,27 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; - -namespace SDL2Sharp.Interop -{ - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public unsafe delegate void SDL_LogOutputFunction(void* userdata, int category, SDL_LogPriority priority, [NativeTypeName("const char *")] sbyte* message); -} diff --git a/sources/SDL2Sharp.Interop/SDL_WindowsMessageHook.cs b/sources/SDL2Sharp.Interop/SDL_WindowsMessageHook.cs deleted file mode 100644 index fda93f33..00000000 --- a/sources/SDL2Sharp.Interop/SDL_WindowsMessageHook.cs +++ /dev/null @@ -1,27 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; - -namespace SDL2Sharp.Interop -{ - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public unsafe delegate void SDL_WindowsMessageHook(void* userdata, void* hWnd, [NativeTypeName("unsigned int")] uint message, [NativeTypeName("Uint64")] ulong wParam, [NativeTypeName("Sint64")] long lParam); -} diff --git a/sources/SDL2Sharp.Interop/SDL_blit.cs b/sources/SDL2Sharp.Interop/SDL_blit.cs deleted file mode 100644 index 35ece88a..00000000 --- a/sources/SDL2Sharp.Interop/SDL_blit.cs +++ /dev/null @@ -1,27 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; - -namespace SDL2Sharp.Interop -{ - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public unsafe delegate int SDL_blit([NativeTypeName("struct SDL_Surface *")] SDL_Surface* src, SDL_Rect* srcrect, [NativeTypeName("struct SDL_Surface *")] SDL_Surface* dst, SDL_Rect* dstrect); -} diff --git a/sources/SDL2Sharp.Interop/SDL_calloc_func.cs b/sources/SDL2Sharp.Interop/SDL_calloc_func.cs deleted file mode 100644 index 968f9973..00000000 --- a/sources/SDL2Sharp.Interop/SDL_calloc_func.cs +++ /dev/null @@ -1,28 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Runtime.InteropServices; - -namespace SDL2Sharp.Interop -{ - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public unsafe delegate void* SDL_calloc_func([NativeTypeName("size_t")] UIntPtr nmemb, [NativeTypeName("size_t")] UIntPtr size); -} diff --git a/sources/SDL2Sharp.Interop/SDL_malloc_func.cs b/sources/SDL2Sharp.Interop/SDL_malloc_func.cs deleted file mode 100644 index 8bbd3a31..00000000 --- a/sources/SDL2Sharp.Interop/SDL_malloc_func.cs +++ /dev/null @@ -1,28 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Runtime.InteropServices; - -namespace SDL2Sharp.Interop -{ - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public unsafe delegate void* SDL_malloc_func([NativeTypeName("size_t")] UIntPtr size); -} diff --git a/sources/SDL2Sharp.Interop/SDL_realloc_func.cs b/sources/SDL2Sharp.Interop/SDL_realloc_func.cs deleted file mode 100644 index 322a5eb0..00000000 --- a/sources/SDL2Sharp.Interop/SDL_realloc_func.cs +++ /dev/null @@ -1,28 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Runtime.InteropServices; - -namespace SDL2Sharp.Interop -{ - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public unsafe delegate void* SDL_realloc_func(void* mem, [NativeTypeName("size_t")] UIntPtr size); -} diff --git a/sources/SDL2Sharp.Interop/ID3D11Device.cs b/sources/SDL2Sharp.Interop/codegen/ID3D11Device.cs similarity index 100% rename from sources/SDL2Sharp.Interop/ID3D11Device.cs rename to sources/SDL2Sharp.Interop/codegen/ID3D11Device.cs diff --git a/sources/SDL2Sharp.Interop/ID3D12Device.cs b/sources/SDL2Sharp.Interop/codegen/ID3D12Device.cs similarity index 100% rename from sources/SDL2Sharp.Interop/ID3D12Device.cs rename to sources/SDL2Sharp.Interop/codegen/ID3D12Device.cs diff --git a/sources/SDL2Sharp.Interop/IDirect3DDevice9.cs b/sources/SDL2Sharp.Interop/codegen/IDirect3DDevice9.cs similarity index 100% rename from sources/SDL2Sharp.Interop/IDirect3DDevice9.cs rename to sources/SDL2Sharp.Interop/codegen/IDirect3DDevice9.cs diff --git a/sources/SDL2Sharp.Interop/IMG.cs b/sources/SDL2Sharp.Interop/codegen/IMG.cs similarity index 100% rename from sources/SDL2Sharp.Interop/IMG.cs rename to sources/SDL2Sharp.Interop/codegen/IMG.cs diff --git a/sources/SDL2Sharp.Interop/IMG_Animation.cs b/sources/SDL2Sharp.Interop/codegen/IMG_Animation.cs similarity index 100% rename from sources/SDL2Sharp.Interop/IMG_Animation.cs rename to sources/SDL2Sharp.Interop/codegen/IMG_Animation.cs diff --git a/sources/SDL2Sharp.Interop/IMG_InitFlags.cs b/sources/SDL2Sharp.Interop/codegen/IMG_InitFlags.cs similarity index 100% rename from sources/SDL2Sharp.Interop/IMG_InitFlags.cs rename to sources/SDL2Sharp.Interop/codegen/IMG_InitFlags.cs diff --git a/sources/SDL2Sharp.Interop/SDL.cs b/sources/SDL2Sharp.Interop/codegen/SDL.cs similarity index 80% rename from sources/SDL2Sharp.Interop/SDL.cs rename to sources/SDL2Sharp.Interop/codegen/SDL.cs index ffe9f358..3812e4cc 100644 --- a/sources/SDL2Sharp.Interop/SDL.cs +++ b/sources/SDL2Sharp.Interop/codegen/SDL.cs @@ -330,19 +330,19 @@ public static unsafe partial class SDL public static extern int PushEvent(SDL_Event* @event); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_SetEventFilter", ExactSpelling = true)] - public static extern void SetEventFilter([NativeTypeName("SDL_EventFilter")] IntPtr filter, void* userdata); + public static extern void SetEventFilter([NativeTypeName("SDL_EventFilter")] delegate* unmanaged[Cdecl] filter, void* userdata); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetEventFilter", ExactSpelling = true)] - public static extern SDL_bool GetEventFilter([NativeTypeName("SDL_EventFilter *")] IntPtr* filter, void** userdata); + public static extern SDL_bool GetEventFilter([NativeTypeName("SDL_EventFilter *")] delegate* unmanaged[Cdecl]* filter, void** userdata); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_AddEventWatch", ExactSpelling = true)] - public static extern void AddEventWatch([NativeTypeName("SDL_EventFilter")] IntPtr filter, void* userdata); + public static extern void AddEventWatch([NativeTypeName("SDL_EventFilter")] delegate* unmanaged[Cdecl] filter, void* userdata); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_DelEventWatch", ExactSpelling = true)] - public static extern void DelEventWatch([NativeTypeName("SDL_EventFilter")] IntPtr filter, void* userdata); + public static extern void DelEventWatch([NativeTypeName("SDL_EventFilter")] delegate* unmanaged[Cdecl] filter, void* userdata); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_FilterEvents", ExactSpelling = true)] - public static extern void FilterEvents([NativeTypeName("SDL_EventFilter")] IntPtr filter, void* userdata); + public static extern void FilterEvents([NativeTypeName("SDL_EventFilter")] delegate* unmanaged[Cdecl] filter, void* userdata); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_EventState", ExactSpelling = true)] [return: NativeTypeName("Uint8")] @@ -402,535 +402,535 @@ public static unsafe partial class SDL public static extern SDL_bool GetHintBoolean([NativeTypeName("const char *")] sbyte* name, SDL_bool default_value); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_AddHintCallback", ExactSpelling = true)] - public static extern void AddHintCallback([NativeTypeName("const char *")] sbyte* name, [NativeTypeName("SDL_HintCallback")] IntPtr callback, void* userdata); + public static extern void AddHintCallback([NativeTypeName("const char *")] sbyte* name, [NativeTypeName("SDL_HintCallback")] delegate* unmanaged[Cdecl] callback, void* userdata); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_DelHintCallback", ExactSpelling = true)] - public static extern void DelHintCallback([NativeTypeName("const char *")] sbyte* name, [NativeTypeName("SDL_HintCallback")] IntPtr callback, void* userdata); + public static extern void DelHintCallback([NativeTypeName("const char *")] sbyte* name, [NativeTypeName("SDL_HintCallback")] delegate* unmanaged[Cdecl] callback, void* userdata); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_ClearHints", ExactSpelling = true)] public static extern void ClearHints(); [NativeTypeName("#define SDL_HINT_ACCELEROMETER_AS_JOYSTICK \"SDL_ACCELEROMETER_AS_JOYSTICK\"")] - public static ReadOnlySpan SDL_HINT_ACCELEROMETER_AS_JOYSTICK => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x43, 0x43, 0x45, 0x4C, 0x45, 0x52, 0x4F, 0x4D, 0x45, 0x54, 0x45, 0x52, 0x5F, 0x41, 0x53, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x00 }; + public static ReadOnlySpan SDL_HINT_ACCELEROMETER_AS_JOYSTICK => "SDL_ACCELEROMETER_AS_JOYSTICK"u8; [NativeTypeName("#define SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED \"SDL_ALLOW_ALT_TAB_WHILE_GRABBED\"")] - public static ReadOnlySpan SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x4C, 0x4C, 0x4F, 0x57, 0x5F, 0x41, 0x4C, 0x54, 0x5F, 0x54, 0x41, 0x42, 0x5F, 0x57, 0x48, 0x49, 0x4C, 0x45, 0x5F, 0x47, 0x52, 0x41, 0x42, 0x42, 0x45, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED => "SDL_ALLOW_ALT_TAB_WHILE_GRABBED"u8; [NativeTypeName("#define SDL_HINT_ALLOW_TOPMOST \"SDL_ALLOW_TOPMOST\"")] - public static ReadOnlySpan SDL_HINT_ALLOW_TOPMOST => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x4C, 0x4C, 0x4F, 0x57, 0x5F, 0x54, 0x4F, 0x50, 0x4D, 0x4F, 0x53, 0x54, 0x00 }; + public static ReadOnlySpan SDL_HINT_ALLOW_TOPMOST => "SDL_ALLOW_TOPMOST"u8; [NativeTypeName("#define SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION \"SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION\"")] - public static ReadOnlySpan SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x4E, 0x44, 0x52, 0x4F, 0x49, 0x44, 0x5F, 0x41, 0x50, 0x4B, 0x5F, 0x45, 0x58, 0x50, 0x41, 0x4E, 0x53, 0x49, 0x4F, 0x4E, 0x5F, 0x4D, 0x41, 0x49, 0x4E, 0x5F, 0x46, 0x49, 0x4C, 0x45, 0x5F, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4F, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION => "SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"u8; [NativeTypeName("#define SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION \"SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION\"")] - public static ReadOnlySpan SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x4E, 0x44, 0x52, 0x4F, 0x49, 0x44, 0x5F, 0x41, 0x50, 0x4B, 0x5F, 0x45, 0x58, 0x50, 0x41, 0x4E, 0x53, 0x49, 0x4F, 0x4E, 0x5F, 0x50, 0x41, 0x54, 0x43, 0x48, 0x5F, 0x46, 0x49, 0x4C, 0x45, 0x5F, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4F, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION => "SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION"u8; [NativeTypeName("#define SDL_HINT_ANDROID_BLOCK_ON_PAUSE \"SDL_ANDROID_BLOCK_ON_PAUSE\"")] - public static ReadOnlySpan SDL_HINT_ANDROID_BLOCK_ON_PAUSE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x4E, 0x44, 0x52, 0x4F, 0x49, 0x44, 0x5F, 0x42, 0x4C, 0x4F, 0x43, 0x4B, 0x5F, 0x4F, 0x4E, 0x5F, 0x50, 0x41, 0x55, 0x53, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_ANDROID_BLOCK_ON_PAUSE => "SDL_ANDROID_BLOCK_ON_PAUSE"u8; [NativeTypeName("#define SDL_HINT_ANDROID_BLOCK_ON_PAUSE_PAUSEAUDIO \"SDL_ANDROID_BLOCK_ON_PAUSE_PAUSEAUDIO\"")] - public static ReadOnlySpan SDL_HINT_ANDROID_BLOCK_ON_PAUSE_PAUSEAUDIO => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x4E, 0x44, 0x52, 0x4F, 0x49, 0x44, 0x5F, 0x42, 0x4C, 0x4F, 0x43, 0x4B, 0x5F, 0x4F, 0x4E, 0x5F, 0x50, 0x41, 0x55, 0x53, 0x45, 0x5F, 0x50, 0x41, 0x55, 0x53, 0x45, 0x41, 0x55, 0x44, 0x49, 0x4F, 0x00 }; + public static ReadOnlySpan SDL_HINT_ANDROID_BLOCK_ON_PAUSE_PAUSEAUDIO => "SDL_ANDROID_BLOCK_ON_PAUSE_PAUSEAUDIO"u8; [NativeTypeName("#define SDL_HINT_ANDROID_TRAP_BACK_BUTTON \"SDL_ANDROID_TRAP_BACK_BUTTON\"")] - public static ReadOnlySpan SDL_HINT_ANDROID_TRAP_BACK_BUTTON => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x4E, 0x44, 0x52, 0x4F, 0x49, 0x44, 0x5F, 0x54, 0x52, 0x41, 0x50, 0x5F, 0x42, 0x41, 0x43, 0x4B, 0x5F, 0x42, 0x55, 0x54, 0x54, 0x4F, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_ANDROID_TRAP_BACK_BUTTON => "SDL_ANDROID_TRAP_BACK_BUTTON"u8; [NativeTypeName("#define SDL_HINT_APP_NAME \"SDL_APP_NAME\"")] - public static ReadOnlySpan SDL_HINT_APP_NAME => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x50, 0x50, 0x5F, 0x4E, 0x41, 0x4D, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_APP_NAME => "SDL_APP_NAME"u8; [NativeTypeName("#define SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS \"SDL_APPLE_TV_CONTROLLER_UI_EVENTS\"")] - public static ReadOnlySpan SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x50, 0x50, 0x4C, 0x45, 0x5F, 0x54, 0x56, 0x5F, 0x43, 0x4F, 0x4E, 0x54, 0x52, 0x4F, 0x4C, 0x4C, 0x45, 0x52, 0x5F, 0x55, 0x49, 0x5F, 0x45, 0x56, 0x45, 0x4E, 0x54, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS => "SDL_APPLE_TV_CONTROLLER_UI_EVENTS"u8; [NativeTypeName("#define SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION \"SDL_APPLE_TV_REMOTE_ALLOW_ROTATION\"")] - public static ReadOnlySpan SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x50, 0x50, 0x4C, 0x45, 0x5F, 0x54, 0x56, 0x5F, 0x52, 0x45, 0x4D, 0x4F, 0x54, 0x45, 0x5F, 0x41, 0x4C, 0x4C, 0x4F, 0x57, 0x5F, 0x52, 0x4F, 0x54, 0x41, 0x54, 0x49, 0x4F, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION => "SDL_APPLE_TV_REMOTE_ALLOW_ROTATION"u8; [NativeTypeName("#define SDL_HINT_AUDIO_CATEGORY \"SDL_AUDIO_CATEGORY\"")] - public static ReadOnlySpan SDL_HINT_AUDIO_CATEGORY => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x55, 0x44, 0x49, 0x4F, 0x5F, 0x43, 0x41, 0x54, 0x45, 0x47, 0x4F, 0x52, 0x59, 0x00 }; + public static ReadOnlySpan SDL_HINT_AUDIO_CATEGORY => "SDL_AUDIO_CATEGORY"u8; [NativeTypeName("#define SDL_HINT_AUDIO_DEVICE_APP_NAME \"SDL_AUDIO_DEVICE_APP_NAME\"")] - public static ReadOnlySpan SDL_HINT_AUDIO_DEVICE_APP_NAME => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x55, 0x44, 0x49, 0x4F, 0x5F, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x5F, 0x41, 0x50, 0x50, 0x5F, 0x4E, 0x41, 0x4D, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_AUDIO_DEVICE_APP_NAME => "SDL_AUDIO_DEVICE_APP_NAME"u8; [NativeTypeName("#define SDL_HINT_AUDIO_DEVICE_STREAM_NAME \"SDL_AUDIO_DEVICE_STREAM_NAME\"")] - public static ReadOnlySpan SDL_HINT_AUDIO_DEVICE_STREAM_NAME => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x55, 0x44, 0x49, 0x4F, 0x5F, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x5F, 0x53, 0x54, 0x52, 0x45, 0x41, 0x4D, 0x5F, 0x4E, 0x41, 0x4D, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_AUDIO_DEVICE_STREAM_NAME => "SDL_AUDIO_DEVICE_STREAM_NAME"u8; [NativeTypeName("#define SDL_HINT_AUDIO_DEVICE_STREAM_ROLE \"SDL_AUDIO_DEVICE_STREAM_ROLE\"")] - public static ReadOnlySpan SDL_HINT_AUDIO_DEVICE_STREAM_ROLE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x55, 0x44, 0x49, 0x4F, 0x5F, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x5F, 0x53, 0x54, 0x52, 0x45, 0x41, 0x4D, 0x5F, 0x52, 0x4F, 0x4C, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_AUDIO_DEVICE_STREAM_ROLE => "SDL_AUDIO_DEVICE_STREAM_ROLE"u8; [NativeTypeName("#define SDL_HINT_AUDIO_RESAMPLING_MODE \"SDL_AUDIO_RESAMPLING_MODE\"")] - public static ReadOnlySpan SDL_HINT_AUDIO_RESAMPLING_MODE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x55, 0x44, 0x49, 0x4F, 0x5F, 0x52, 0x45, 0x53, 0x41, 0x4D, 0x50, 0x4C, 0x49, 0x4E, 0x47, 0x5F, 0x4D, 0x4F, 0x44, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_AUDIO_RESAMPLING_MODE => "SDL_AUDIO_RESAMPLING_MODE"u8; [NativeTypeName("#define SDL_HINT_AUTO_UPDATE_JOYSTICKS \"SDL_AUTO_UPDATE_JOYSTICKS\"")] - public static ReadOnlySpan SDL_HINT_AUTO_UPDATE_JOYSTICKS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x55, 0x54, 0x4F, 0x5F, 0x55, 0x50, 0x44, 0x41, 0x54, 0x45, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_AUTO_UPDATE_JOYSTICKS => "SDL_AUTO_UPDATE_JOYSTICKS"u8; [NativeTypeName("#define SDL_HINT_AUTO_UPDATE_SENSORS \"SDL_AUTO_UPDATE_SENSORS\"")] - public static ReadOnlySpan SDL_HINT_AUTO_UPDATE_SENSORS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x55, 0x54, 0x4F, 0x5F, 0x55, 0x50, 0x44, 0x41, 0x54, 0x45, 0x5F, 0x53, 0x45, 0x4E, 0x53, 0x4F, 0x52, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_AUTO_UPDATE_SENSORS => "SDL_AUTO_UPDATE_SENSORS"u8; [NativeTypeName("#define SDL_HINT_BMP_SAVE_LEGACY_FORMAT \"SDL_BMP_SAVE_LEGACY_FORMAT\"")] - public static ReadOnlySpan SDL_HINT_BMP_SAVE_LEGACY_FORMAT => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x42, 0x4D, 0x50, 0x5F, 0x53, 0x41, 0x56, 0x45, 0x5F, 0x4C, 0x45, 0x47, 0x41, 0x43, 0x59, 0x5F, 0x46, 0x4F, 0x52, 0x4D, 0x41, 0x54, 0x00 }; + public static ReadOnlySpan SDL_HINT_BMP_SAVE_LEGACY_FORMAT => "SDL_BMP_SAVE_LEGACY_FORMAT"u8; [NativeTypeName("#define SDL_HINT_DISPLAY_USABLE_BOUNDS \"SDL_DISPLAY_USABLE_BOUNDS\"")] - public static ReadOnlySpan SDL_HINT_DISPLAY_USABLE_BOUNDS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x44, 0x49, 0x53, 0x50, 0x4C, 0x41, 0x59, 0x5F, 0x55, 0x53, 0x41, 0x42, 0x4C, 0x45, 0x5F, 0x42, 0x4F, 0x55, 0x4E, 0x44, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_DISPLAY_USABLE_BOUNDS => "SDL_DISPLAY_USABLE_BOUNDS"u8; [NativeTypeName("#define SDL_HINT_EMSCRIPTEN_ASYNCIFY \"SDL_EMSCRIPTEN_ASYNCIFY\"")] - public static ReadOnlySpan SDL_HINT_EMSCRIPTEN_ASYNCIFY => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x45, 0x4D, 0x53, 0x43, 0x52, 0x49, 0x50, 0x54, 0x45, 0x4E, 0x5F, 0x41, 0x53, 0x59, 0x4E, 0x43, 0x49, 0x46, 0x59, 0x00 }; + public static ReadOnlySpan SDL_HINT_EMSCRIPTEN_ASYNCIFY => "SDL_EMSCRIPTEN_ASYNCIFY"u8; [NativeTypeName("#define SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT \"SDL_EMSCRIPTEN_KEYBOARD_ELEMENT\"")] - public static ReadOnlySpan SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x45, 0x4D, 0x53, 0x43, 0x52, 0x49, 0x50, 0x54, 0x45, 0x4E, 0x5F, 0x4B, 0x45, 0x59, 0x42, 0x4F, 0x41, 0x52, 0x44, 0x5F, 0x45, 0x4C, 0x45, 0x4D, 0x45, 0x4E, 0x54, 0x00 }; + public static ReadOnlySpan SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT => "SDL_EMSCRIPTEN_KEYBOARD_ELEMENT"u8; [NativeTypeName("#define SDL_HINT_ENABLE_SCREEN_KEYBOARD \"SDL_ENABLE_SCREEN_KEYBOARD\"")] - public static ReadOnlySpan SDL_HINT_ENABLE_SCREEN_KEYBOARD => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x45, 0x4E, 0x41, 0x42, 0x4C, 0x45, 0x5F, 0x53, 0x43, 0x52, 0x45, 0x45, 0x4E, 0x5F, 0x4B, 0x45, 0x59, 0x42, 0x4F, 0x41, 0x52, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_ENABLE_SCREEN_KEYBOARD => "SDL_ENABLE_SCREEN_KEYBOARD"u8; [NativeTypeName("#define SDL_HINT_ENABLE_STEAM_CONTROLLERS \"SDL_ENABLE_STEAM_CONTROLLERS\"")] - public static ReadOnlySpan SDL_HINT_ENABLE_STEAM_CONTROLLERS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x45, 0x4E, 0x41, 0x42, 0x4C, 0x45, 0x5F, 0x53, 0x54, 0x45, 0x41, 0x4D, 0x5F, 0x43, 0x4F, 0x4E, 0x54, 0x52, 0x4F, 0x4C, 0x4C, 0x45, 0x52, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_ENABLE_STEAM_CONTROLLERS => "SDL_ENABLE_STEAM_CONTROLLERS"u8; [NativeTypeName("#define SDL_HINT_EVENT_LOGGING \"SDL_EVENT_LOGGING\"")] - public static ReadOnlySpan SDL_HINT_EVENT_LOGGING => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x45, 0x56, 0x45, 0x4E, 0x54, 0x5F, 0x4C, 0x4F, 0x47, 0x47, 0x49, 0x4E, 0x47, 0x00 }; + public static ReadOnlySpan SDL_HINT_EVENT_LOGGING => "SDL_EVENT_LOGGING"u8; [NativeTypeName("#define SDL_HINT_FORCE_RAISEWINDOW \"SDL_HINT_FORCE_RAISEWINDOW\"")] - public static ReadOnlySpan SDL_HINT_FORCE_RAISEWINDOW => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x48, 0x49, 0x4E, 0x54, 0x5F, 0x46, 0x4F, 0x52, 0x43, 0x45, 0x5F, 0x52, 0x41, 0x49, 0x53, 0x45, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x00 }; + public static ReadOnlySpan SDL_HINT_FORCE_RAISEWINDOW => "SDL_HINT_FORCE_RAISEWINDOW"u8; [NativeTypeName("#define SDL_HINT_FRAMEBUFFER_ACCELERATION \"SDL_FRAMEBUFFER_ACCELERATION\"")] - public static ReadOnlySpan SDL_HINT_FRAMEBUFFER_ACCELERATION => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x46, 0x52, 0x41, 0x4D, 0x45, 0x42, 0x55, 0x46, 0x46, 0x45, 0x52, 0x5F, 0x41, 0x43, 0x43, 0x45, 0x4C, 0x45, 0x52, 0x41, 0x54, 0x49, 0x4F, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_FRAMEBUFFER_ACCELERATION => "SDL_FRAMEBUFFER_ACCELERATION"u8; [NativeTypeName("#define SDL_HINT_GAMECONTROLLERCONFIG \"SDL_GAMECONTROLLERCONFIG\"")] - public static ReadOnlySpan SDL_HINT_GAMECONTROLLERCONFIG => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x47, 0x41, 0x4D, 0x45, 0x43, 0x4F, 0x4E, 0x54, 0x52, 0x4F, 0x4C, 0x4C, 0x45, 0x52, 0x43, 0x4F, 0x4E, 0x46, 0x49, 0x47, 0x00 }; + public static ReadOnlySpan SDL_HINT_GAMECONTROLLERCONFIG => "SDL_GAMECONTROLLERCONFIG"u8; [NativeTypeName("#define SDL_HINT_GAMECONTROLLERCONFIG_FILE \"SDL_GAMECONTROLLERCONFIG_FILE\"")] - public static ReadOnlySpan SDL_HINT_GAMECONTROLLERCONFIG_FILE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x47, 0x41, 0x4D, 0x45, 0x43, 0x4F, 0x4E, 0x54, 0x52, 0x4F, 0x4C, 0x4C, 0x45, 0x52, 0x43, 0x4F, 0x4E, 0x46, 0x49, 0x47, 0x5F, 0x46, 0x49, 0x4C, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_GAMECONTROLLERCONFIG_FILE => "SDL_GAMECONTROLLERCONFIG_FILE"u8; [NativeTypeName("#define SDL_HINT_GAMECONTROLLERTYPE \"SDL_GAMECONTROLLERTYPE\"")] - public static ReadOnlySpan SDL_HINT_GAMECONTROLLERTYPE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x47, 0x41, 0x4D, 0x45, 0x43, 0x4F, 0x4E, 0x54, 0x52, 0x4F, 0x4C, 0x4C, 0x45, 0x52, 0x54, 0x59, 0x50, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_GAMECONTROLLERTYPE => "SDL_GAMECONTROLLERTYPE"u8; [NativeTypeName("#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES \"SDL_GAMECONTROLLER_IGNORE_DEVICES\"")] - public static ReadOnlySpan SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x47, 0x41, 0x4D, 0x45, 0x43, 0x4F, 0x4E, 0x54, 0x52, 0x4F, 0x4C, 0x4C, 0x45, 0x52, 0x5F, 0x49, 0x47, 0x4E, 0x4F, 0x52, 0x45, 0x5F, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES => "SDL_GAMECONTROLLER_IGNORE_DEVICES"u8; [NativeTypeName("#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT \"SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT\"")] - public static ReadOnlySpan SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x47, 0x41, 0x4D, 0x45, 0x43, 0x4F, 0x4E, 0x54, 0x52, 0x4F, 0x4C, 0x4C, 0x45, 0x52, 0x5F, 0x49, 0x47, 0x4E, 0x4F, 0x52, 0x45, 0x5F, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x53, 0x5F, 0x45, 0x58, 0x43, 0x45, 0x50, 0x54, 0x00 }; + public static ReadOnlySpan SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT => "SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT"u8; [NativeTypeName("#define SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS \"SDL_GAMECONTROLLER_USE_BUTTON_LABELS\"")] - public static ReadOnlySpan SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x47, 0x41, 0x4D, 0x45, 0x43, 0x4F, 0x4E, 0x54, 0x52, 0x4F, 0x4C, 0x4C, 0x45, 0x52, 0x5F, 0x55, 0x53, 0x45, 0x5F, 0x42, 0x55, 0x54, 0x54, 0x4F, 0x4E, 0x5F, 0x4C, 0x41, 0x42, 0x45, 0x4C, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS => "SDL_GAMECONTROLLER_USE_BUTTON_LABELS"u8; [NativeTypeName("#define SDL_HINT_GRAB_KEYBOARD \"SDL_GRAB_KEYBOARD\"")] - public static ReadOnlySpan SDL_HINT_GRAB_KEYBOARD => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x47, 0x52, 0x41, 0x42, 0x5F, 0x4B, 0x45, 0x59, 0x42, 0x4F, 0x41, 0x52, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_GRAB_KEYBOARD => "SDL_GRAB_KEYBOARD"u8; [NativeTypeName("#define SDL_HINT_HIDAPI_IGNORE_DEVICES \"SDL_HIDAPI_IGNORE_DEVICES\"")] - public static ReadOnlySpan SDL_HINT_HIDAPI_IGNORE_DEVICES => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x49, 0x47, 0x4E, 0x4F, 0x52, 0x45, 0x5F, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_HIDAPI_IGNORE_DEVICES => "SDL_HIDAPI_IGNORE_DEVICES"u8; [NativeTypeName("#define SDL_HINT_IDLE_TIMER_DISABLED \"SDL_IOS_IDLE_TIMER_DISABLED\"")] - public static ReadOnlySpan SDL_HINT_IDLE_TIMER_DISABLED => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x49, 0x4F, 0x53, 0x5F, 0x49, 0x44, 0x4C, 0x45, 0x5F, 0x54, 0x49, 0x4D, 0x45, 0x52, 0x5F, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4C, 0x45, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_IDLE_TIMER_DISABLED => "SDL_IOS_IDLE_TIMER_DISABLED"u8; [NativeTypeName("#define SDL_HINT_IME_INTERNAL_EDITING \"SDL_IME_INTERNAL_EDITING\"")] - public static ReadOnlySpan SDL_HINT_IME_INTERNAL_EDITING => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x49, 0x4D, 0x45, 0x5F, 0x49, 0x4E, 0x54, 0x45, 0x52, 0x4E, 0x41, 0x4C, 0x5F, 0x45, 0x44, 0x49, 0x54, 0x49, 0x4E, 0x47, 0x00 }; + public static ReadOnlySpan SDL_HINT_IME_INTERNAL_EDITING => "SDL_IME_INTERNAL_EDITING"u8; [NativeTypeName("#define SDL_HINT_IME_SHOW_UI \"SDL_IME_SHOW_UI\"")] - public static ReadOnlySpan SDL_HINT_IME_SHOW_UI => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x49, 0x4D, 0x45, 0x5F, 0x53, 0x48, 0x4F, 0x57, 0x5F, 0x55, 0x49, 0x00 }; + public static ReadOnlySpan SDL_HINT_IME_SHOW_UI => "SDL_IME_SHOW_UI"u8; [NativeTypeName("#define SDL_HINT_IME_SUPPORT_EXTENDED_TEXT \"SDL_IME_SUPPORT_EXTENDED_TEXT\"")] - public static ReadOnlySpan SDL_HINT_IME_SUPPORT_EXTENDED_TEXT => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x49, 0x4D, 0x45, 0x5F, 0x53, 0x55, 0x50, 0x50, 0x4F, 0x52, 0x54, 0x5F, 0x45, 0x58, 0x54, 0x45, 0x4E, 0x44, 0x45, 0x44, 0x5F, 0x54, 0x45, 0x58, 0x54, 0x00 }; + public static ReadOnlySpan SDL_HINT_IME_SUPPORT_EXTENDED_TEXT => "SDL_IME_SUPPORT_EXTENDED_TEXT"u8; [NativeTypeName("#define SDL_HINT_IOS_HIDE_HOME_INDICATOR \"SDL_IOS_HIDE_HOME_INDICATOR\"")] - public static ReadOnlySpan SDL_HINT_IOS_HIDE_HOME_INDICATOR => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x49, 0x4F, 0x53, 0x5F, 0x48, 0x49, 0x44, 0x45, 0x5F, 0x48, 0x4F, 0x4D, 0x45, 0x5F, 0x49, 0x4E, 0x44, 0x49, 0x43, 0x41, 0x54, 0x4F, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_IOS_HIDE_HOME_INDICATOR => "SDL_IOS_HIDE_HOME_INDICATOR"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS \"SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x41, 0x4C, 0x4C, 0x4F, 0x57, 0x5F, 0x42, 0x41, 0x43, 0x4B, 0x47, 0x52, 0x4F, 0x55, 0x4E, 0x44, 0x5F, 0x45, 0x56, 0x45, 0x4E, 0x54, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS => "SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI \"SDL_JOYSTICK_HIDAPI\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI => "SDL_JOYSTICK_HIDAPI"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE \"SDL_JOYSTICK_HIDAPI_GAMECUBE\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x47, 0x41, 0x4D, 0x45, 0x43, 0x55, 0x42, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE => "SDL_JOYSTICK_HIDAPI_GAMECUBE"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_GAMECUBE_RUMBLE_BRAKE \"SDL_JOYSTICK_GAMECUBE_RUMBLE_BRAKE\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_GAMECUBE_RUMBLE_BRAKE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x47, 0x41, 0x4D, 0x45, 0x43, 0x55, 0x42, 0x45, 0x5F, 0x52, 0x55, 0x4D, 0x42, 0x4C, 0x45, 0x5F, 0x42, 0x52, 0x41, 0x4B, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_GAMECUBE_RUMBLE_BRAKE => "SDL_JOYSTICK_GAMECUBE_RUMBLE_BRAKE"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS \"SDL_JOYSTICK_HIDAPI_JOY_CONS\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x4A, 0x4F, 0x59, 0x5F, 0x43, 0x4F, 0x4E, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS => "SDL_JOYSTICK_HIDAPI_JOY_CONS"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_COMBINE_JOY_CONS \"SDL_JOYSTICK_HIDAPI_COMBINE_JOY_CONS\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_COMBINE_JOY_CONS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x43, 0x4F, 0x4D, 0x42, 0x49, 0x4E, 0x45, 0x5F, 0x4A, 0x4F, 0x59, 0x5F, 0x43, 0x4F, 0x4E, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_COMBINE_JOY_CONS => "SDL_JOYSTICK_HIDAPI_COMBINE_JOY_CONS"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS \"SDL_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x56, 0x45, 0x52, 0x54, 0x49, 0x43, 0x41, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x5F, 0x43, 0x4F, 0x4E, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS => "SDL_JOYSTICK_HIDAPI_VERTICAL_JOY_CONS"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_LUNA \"SDL_JOYSTICK_HIDAPI_LUNA\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_LUNA => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x4C, 0x55, 0x4E, 0x41, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_LUNA => "SDL_JOYSTICK_HIDAPI_LUNA"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC \"SDL_JOYSTICK_HIDAPI_NINTENDO_CLASSIC\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x4E, 0x49, 0x4E, 0x54, 0x45, 0x4E, 0x44, 0x4F, 0x5F, 0x43, 0x4C, 0x41, 0x53, 0x53, 0x49, 0x43, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC => "SDL_JOYSTICK_HIDAPI_NINTENDO_CLASSIC"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_SHIELD \"SDL_JOYSTICK_HIDAPI_SHIELD\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_SHIELD => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x53, 0x48, 0x49, 0x45, 0x4C, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_SHIELD => "SDL_JOYSTICK_HIDAPI_SHIELD"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_PS3 \"SDL_JOYSTICK_HIDAPI_PS3\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_PS3 => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x50, 0x53, 0x33, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_PS3 => "SDL_JOYSTICK_HIDAPI_PS3"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_PS4 \"SDL_JOYSTICK_HIDAPI_PS4\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_PS4 => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x50, 0x53, 0x34, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_PS4 => "SDL_JOYSTICK_HIDAPI_PS4"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE \"SDL_JOYSTICK_HIDAPI_PS4_RUMBLE\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x50, 0x53, 0x34, 0x5F, 0x52, 0x55, 0x4D, 0x42, 0x4C, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE => "SDL_JOYSTICK_HIDAPI_PS4_RUMBLE"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_PS5 \"SDL_JOYSTICK_HIDAPI_PS5\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_PS5 => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x50, 0x53, 0x35, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_PS5 => "SDL_JOYSTICK_HIDAPI_PS5"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED \"SDL_JOYSTICK_HIDAPI_PS5_PLAYER_LED\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x50, 0x53, 0x35, 0x5F, 0x50, 0x4C, 0x41, 0x59, 0x45, 0x52, 0x5F, 0x4C, 0x45, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED => "SDL_JOYSTICK_HIDAPI_PS5_PLAYER_LED"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE \"SDL_JOYSTICK_HIDAPI_PS5_RUMBLE\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x50, 0x53, 0x35, 0x5F, 0x52, 0x55, 0x4D, 0x42, 0x4C, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE => "SDL_JOYSTICK_HIDAPI_PS5_RUMBLE"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_STADIA \"SDL_JOYSTICK_HIDAPI_STADIA\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_STADIA => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x53, 0x54, 0x41, 0x44, 0x49, 0x41, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_STADIA => "SDL_JOYSTICK_HIDAPI_STADIA"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_STEAM \"SDL_JOYSTICK_HIDAPI_STEAM\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_STEAM => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x53, 0x54, 0x45, 0x41, 0x4D, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_STEAM => "SDL_JOYSTICK_HIDAPI_STEAM"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_SWITCH \"SDL_JOYSTICK_HIDAPI_SWITCH\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_SWITCH => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x53, 0x57, 0x49, 0x54, 0x43, 0x48, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_SWITCH => "SDL_JOYSTICK_HIDAPI_SWITCH"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED \"SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x53, 0x57, 0x49, 0x54, 0x43, 0x48, 0x5F, 0x48, 0x4F, 0x4D, 0x45, 0x5F, 0x4C, 0x45, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED => "SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED \"SDL_JOYSTICK_HIDAPI_JOYCON_HOME_LED\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x4A, 0x4F, 0x59, 0x43, 0x4F, 0x4E, 0x5F, 0x48, 0x4F, 0x4D, 0x45, 0x5F, 0x4C, 0x45, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED => "SDL_JOYSTICK_HIDAPI_JOYCON_HOME_LED"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED \"SDL_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x53, 0x57, 0x49, 0x54, 0x43, 0x48, 0x5F, 0x50, 0x4C, 0x41, 0x59, 0x45, 0x52, 0x5F, 0x4C, 0x45, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED => "SDL_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_WII \"SDL_JOYSTICK_HIDAPI_WII\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_WII => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x57, 0x49, 0x49, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_WII => "SDL_JOYSTICK_HIDAPI_WII"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_WII_PLAYER_LED \"SDL_JOYSTICK_HIDAPI_WII_PLAYER_LED\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_WII_PLAYER_LED => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x57, 0x49, 0x49, 0x5F, 0x50, 0x4C, 0x41, 0x59, 0x45, 0x52, 0x5F, 0x4C, 0x45, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_WII_PLAYER_LED => "SDL_JOYSTICK_HIDAPI_WII_PLAYER_LED"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_XBOX \"SDL_JOYSTICK_HIDAPI_XBOX\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_XBOX => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x58, 0x42, 0x4F, 0x58, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_XBOX => "SDL_JOYSTICK_HIDAPI_XBOX"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_XBOX_360 \"SDL_JOYSTICK_HIDAPI_XBOX_360\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_XBOX_360 => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x58, 0x42, 0x4F, 0x58, 0x5F, 0x33, 0x36, 0x30, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_XBOX_360 => "SDL_JOYSTICK_HIDAPI_XBOX_360"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_XBOX_360_PLAYER_LED \"SDL_JOYSTICK_HIDAPI_XBOX_360_PLAYER_LED\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_XBOX_360_PLAYER_LED => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x58, 0x42, 0x4F, 0x58, 0x5F, 0x33, 0x36, 0x30, 0x5F, 0x50, 0x4C, 0x41, 0x59, 0x45, 0x52, 0x5F, 0x4C, 0x45, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_XBOX_360_PLAYER_LED => "SDL_JOYSTICK_HIDAPI_XBOX_360_PLAYER_LED"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_XBOX_360_WIRELESS \"SDL_JOYSTICK_HIDAPI_XBOX_360_WIRELESS\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_XBOX_360_WIRELESS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x58, 0x42, 0x4F, 0x58, 0x5F, 0x33, 0x36, 0x30, 0x5F, 0x57, 0x49, 0x52, 0x45, 0x4C, 0x45, 0x53, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_XBOX_360_WIRELESS => "SDL_JOYSTICK_HIDAPI_XBOX_360_WIRELESS"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE \"SDL_JOYSTICK_HIDAPI_XBOX_ONE\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x58, 0x42, 0x4F, 0x58, 0x5F, 0x4F, 0x4E, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE => "SDL_JOYSTICK_HIDAPI_XBOX_ONE"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED \"SDL_JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x48, 0x49, 0x44, 0x41, 0x50, 0x49, 0x5F, 0x58, 0x42, 0x4F, 0x58, 0x5F, 0x4F, 0x4E, 0x45, 0x5F, 0x48, 0x4F, 0x4D, 0x45, 0x5F, 0x4C, 0x45, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED => "SDL_JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_RAWINPUT \"SDL_JOYSTICK_RAWINPUT\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_RAWINPUT => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x52, 0x41, 0x57, 0x49, 0x4E, 0x50, 0x55, 0x54, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_RAWINPUT => "SDL_JOYSTICK_RAWINPUT"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_RAWINPUT_CORRELATE_XINPUT \"SDL_JOYSTICK_RAWINPUT_CORRELATE_XINPUT\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_RAWINPUT_CORRELATE_XINPUT => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x52, 0x41, 0x57, 0x49, 0x4E, 0x50, 0x55, 0x54, 0x5F, 0x43, 0x4F, 0x52, 0x52, 0x45, 0x4C, 0x41, 0x54, 0x45, 0x5F, 0x58, 0x49, 0x4E, 0x50, 0x55, 0x54, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_RAWINPUT_CORRELATE_XINPUT => "SDL_JOYSTICK_RAWINPUT_CORRELATE_XINPUT"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_ROG_CHAKRAM \"SDL_JOYSTICK_ROG_CHAKRAM\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_ROG_CHAKRAM => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x52, 0x4F, 0x47, 0x5F, 0x43, 0x48, 0x41, 0x4B, 0x52, 0x41, 0x4D, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_ROG_CHAKRAM => "SDL_JOYSTICK_ROG_CHAKRAM"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_THREAD \"SDL_JOYSTICK_THREAD\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_THREAD => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x54, 0x48, 0x52, 0x45, 0x41, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_THREAD => "SDL_JOYSTICK_THREAD"u8; [NativeTypeName("#define SDL_HINT_KMSDRM_REQUIRE_DRM_MASTER \"SDL_KMSDRM_REQUIRE_DRM_MASTER\"")] - public static ReadOnlySpan SDL_HINT_KMSDRM_REQUIRE_DRM_MASTER => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4B, 0x4D, 0x53, 0x44, 0x52, 0x4D, 0x5F, 0x52, 0x45, 0x51, 0x55, 0x49, 0x52, 0x45, 0x5F, 0x44, 0x52, 0x4D, 0x5F, 0x4D, 0x41, 0x53, 0x54, 0x45, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_KMSDRM_REQUIRE_DRM_MASTER => "SDL_KMSDRM_REQUIRE_DRM_MASTER"u8; [NativeTypeName("#define SDL_HINT_JOYSTICK_DEVICE \"SDL_JOYSTICK_DEVICE\"")] - public static ReadOnlySpan SDL_HINT_JOYSTICK_DEVICE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_JOYSTICK_DEVICE => "SDL_JOYSTICK_DEVICE"u8; [NativeTypeName("#define SDL_HINT_LINUX_DIGITAL_HATS \"SDL_LINUX_DIGITAL_HATS\"")] - public static ReadOnlySpan SDL_HINT_LINUX_DIGITAL_HATS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4C, 0x49, 0x4E, 0x55, 0x58, 0x5F, 0x44, 0x49, 0x47, 0x49, 0x54, 0x41, 0x4C, 0x5F, 0x48, 0x41, 0x54, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_LINUX_DIGITAL_HATS => "SDL_LINUX_DIGITAL_HATS"u8; [NativeTypeName("#define SDL_HINT_LINUX_HAT_DEADZONES \"SDL_LINUX_HAT_DEADZONES\"")] - public static ReadOnlySpan SDL_HINT_LINUX_HAT_DEADZONES => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4C, 0x49, 0x4E, 0x55, 0x58, 0x5F, 0x48, 0x41, 0x54, 0x5F, 0x44, 0x45, 0x41, 0x44, 0x5A, 0x4F, 0x4E, 0x45, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_LINUX_HAT_DEADZONES => "SDL_LINUX_HAT_DEADZONES"u8; [NativeTypeName("#define SDL_HINT_LINUX_JOYSTICK_CLASSIC \"SDL_LINUX_JOYSTICK_CLASSIC\"")] - public static ReadOnlySpan SDL_HINT_LINUX_JOYSTICK_CLASSIC => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4C, 0x49, 0x4E, 0x55, 0x58, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x43, 0x4C, 0x41, 0x53, 0x53, 0x49, 0x43, 0x00 }; + public static ReadOnlySpan SDL_HINT_LINUX_JOYSTICK_CLASSIC => "SDL_LINUX_JOYSTICK_CLASSIC"u8; [NativeTypeName("#define SDL_HINT_LINUX_JOYSTICK_DEADZONES \"SDL_LINUX_JOYSTICK_DEADZONES\"")] - public static ReadOnlySpan SDL_HINT_LINUX_JOYSTICK_DEADZONES => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4C, 0x49, 0x4E, 0x55, 0x58, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x44, 0x45, 0x41, 0x44, 0x5A, 0x4F, 0x4E, 0x45, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_LINUX_JOYSTICK_DEADZONES => "SDL_LINUX_JOYSTICK_DEADZONES"u8; [NativeTypeName("#define SDL_HINT_MAC_BACKGROUND_APP \"SDL_MAC_BACKGROUND_APP\"")] - public static ReadOnlySpan SDL_HINT_MAC_BACKGROUND_APP => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x41, 0x43, 0x5F, 0x42, 0x41, 0x43, 0x4B, 0x47, 0x52, 0x4F, 0x55, 0x4E, 0x44, 0x5F, 0x41, 0x50, 0x50, 0x00 }; + public static ReadOnlySpan SDL_HINT_MAC_BACKGROUND_APP => "SDL_MAC_BACKGROUND_APP"u8; [NativeTypeName("#define SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK \"SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK\"")] - public static ReadOnlySpan SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x41, 0x43, 0x5F, 0x43, 0x54, 0x52, 0x4C, 0x5F, 0x43, 0x4C, 0x49, 0x43, 0x4B, 0x5F, 0x45, 0x4D, 0x55, 0x4C, 0x41, 0x54, 0x45, 0x5F, 0x52, 0x49, 0x47, 0x48, 0x54, 0x5F, 0x43, 0x4C, 0x49, 0x43, 0x4B, 0x00 }; + public static ReadOnlySpan SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK => "SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK"u8; [NativeTypeName("#define SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH \"SDL_MAC_OPENGL_ASYNC_DISPATCH\"")] - public static ReadOnlySpan SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x41, 0x43, 0x5F, 0x4F, 0x50, 0x45, 0x4E, 0x47, 0x4C, 0x5F, 0x41, 0x53, 0x59, 0x4E, 0x43, 0x5F, 0x44, 0x49, 0x53, 0x50, 0x41, 0x54, 0x43, 0x48, 0x00 }; + public static ReadOnlySpan SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH => "SDL_MAC_OPENGL_ASYNC_DISPATCH"u8; [NativeTypeName("#define SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS \"SDL_MOUSE_DOUBLE_CLICK_RADIUS\"")] - public static ReadOnlySpan SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x44, 0x4F, 0x55, 0x42, 0x4C, 0x45, 0x5F, 0x43, 0x4C, 0x49, 0x43, 0x4B, 0x5F, 0x52, 0x41, 0x44, 0x49, 0x55, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS => "SDL_MOUSE_DOUBLE_CLICK_RADIUS"u8; [NativeTypeName("#define SDL_HINT_MOUSE_DOUBLE_CLICK_TIME \"SDL_MOUSE_DOUBLE_CLICK_TIME\"")] - public static ReadOnlySpan SDL_HINT_MOUSE_DOUBLE_CLICK_TIME => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x44, 0x4F, 0x55, 0x42, 0x4C, 0x45, 0x5F, 0x43, 0x4C, 0x49, 0x43, 0x4B, 0x5F, 0x54, 0x49, 0x4D, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_MOUSE_DOUBLE_CLICK_TIME => "SDL_MOUSE_DOUBLE_CLICK_TIME"u8; [NativeTypeName("#define SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH \"SDL_MOUSE_FOCUS_CLICKTHROUGH\"")] - public static ReadOnlySpan SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x46, 0x4F, 0x43, 0x55, 0x53, 0x5F, 0x43, 0x4C, 0x49, 0x43, 0x4B, 0x54, 0x48, 0x52, 0x4F, 0x55, 0x47, 0x48, 0x00 }; + public static ReadOnlySpan SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH => "SDL_MOUSE_FOCUS_CLICKTHROUGH"u8; [NativeTypeName("#define SDL_HINT_MOUSE_NORMAL_SPEED_SCALE \"SDL_MOUSE_NORMAL_SPEED_SCALE\"")] - public static ReadOnlySpan SDL_HINT_MOUSE_NORMAL_SPEED_SCALE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x4E, 0x4F, 0x52, 0x4D, 0x41, 0x4C, 0x5F, 0x53, 0x50, 0x45, 0x45, 0x44, 0x5F, 0x53, 0x43, 0x41, 0x4C, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_MOUSE_NORMAL_SPEED_SCALE => "SDL_MOUSE_NORMAL_SPEED_SCALE"u8; [NativeTypeName("#define SDL_HINT_MOUSE_RELATIVE_MODE_CENTER \"SDL_MOUSE_RELATIVE_MODE_CENTER\"")] - public static ReadOnlySpan SDL_HINT_MOUSE_RELATIVE_MODE_CENTER => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x52, 0x45, 0x4C, 0x41, 0x54, 0x49, 0x56, 0x45, 0x5F, 0x4D, 0x4F, 0x44, 0x45, 0x5F, 0x43, 0x45, 0x4E, 0x54, 0x45, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_MOUSE_RELATIVE_MODE_CENTER => "SDL_MOUSE_RELATIVE_MODE_CENTER"u8; [NativeTypeName("#define SDL_HINT_MOUSE_RELATIVE_MODE_WARP \"SDL_MOUSE_RELATIVE_MODE_WARP\"")] - public static ReadOnlySpan SDL_HINT_MOUSE_RELATIVE_MODE_WARP => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x52, 0x45, 0x4C, 0x41, 0x54, 0x49, 0x56, 0x45, 0x5F, 0x4D, 0x4F, 0x44, 0x45, 0x5F, 0x57, 0x41, 0x52, 0x50, 0x00 }; + public static ReadOnlySpan SDL_HINT_MOUSE_RELATIVE_MODE_WARP => "SDL_MOUSE_RELATIVE_MODE_WARP"u8; [NativeTypeName("#define SDL_HINT_MOUSE_RELATIVE_SCALING \"SDL_MOUSE_RELATIVE_SCALING\"")] - public static ReadOnlySpan SDL_HINT_MOUSE_RELATIVE_SCALING => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x52, 0x45, 0x4C, 0x41, 0x54, 0x49, 0x56, 0x45, 0x5F, 0x53, 0x43, 0x41, 0x4C, 0x49, 0x4E, 0x47, 0x00 }; + public static ReadOnlySpan SDL_HINT_MOUSE_RELATIVE_SCALING => "SDL_MOUSE_RELATIVE_SCALING"u8; [NativeTypeName("#define SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE \"SDL_MOUSE_RELATIVE_SPEED_SCALE\"")] - public static ReadOnlySpan SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x52, 0x45, 0x4C, 0x41, 0x54, 0x49, 0x56, 0x45, 0x5F, 0x53, 0x50, 0x45, 0x45, 0x44, 0x5F, 0x53, 0x43, 0x41, 0x4C, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE => "SDL_MOUSE_RELATIVE_SPEED_SCALE"u8; [NativeTypeName("#define SDL_HINT_MOUSE_RELATIVE_SYSTEM_SCALE \"SDL_MOUSE_RELATIVE_SYSTEM_SCALE\"")] - public static ReadOnlySpan SDL_HINT_MOUSE_RELATIVE_SYSTEM_SCALE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x52, 0x45, 0x4C, 0x41, 0x54, 0x49, 0x56, 0x45, 0x5F, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4D, 0x5F, 0x53, 0x43, 0x41, 0x4C, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_MOUSE_RELATIVE_SYSTEM_SCALE => "SDL_MOUSE_RELATIVE_SYSTEM_SCALE"u8; [NativeTypeName("#define SDL_HINT_MOUSE_RELATIVE_WARP_MOTION \"SDL_MOUSE_RELATIVE_WARP_MOTION\"")] - public static ReadOnlySpan SDL_HINT_MOUSE_RELATIVE_WARP_MOTION => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x52, 0x45, 0x4C, 0x41, 0x54, 0x49, 0x56, 0x45, 0x5F, 0x57, 0x41, 0x52, 0x50, 0x5F, 0x4D, 0x4F, 0x54, 0x49, 0x4F, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_MOUSE_RELATIVE_WARP_MOTION => "SDL_MOUSE_RELATIVE_WARP_MOTION"u8; [NativeTypeName("#define SDL_HINT_MOUSE_TOUCH_EVENTS \"SDL_MOUSE_TOUCH_EVENTS\"")] - public static ReadOnlySpan SDL_HINT_MOUSE_TOUCH_EVENTS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x54, 0x4F, 0x55, 0x43, 0x48, 0x5F, 0x45, 0x56, 0x45, 0x4E, 0x54, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_MOUSE_TOUCH_EVENTS => "SDL_MOUSE_TOUCH_EVENTS"u8; [NativeTypeName("#define SDL_HINT_MOUSE_AUTO_CAPTURE \"SDL_MOUSE_AUTO_CAPTURE\"")] - public static ReadOnlySpan SDL_HINT_MOUSE_AUTO_CAPTURE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x41, 0x55, 0x54, 0x4F, 0x5F, 0x43, 0x41, 0x50, 0x54, 0x55, 0x52, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_MOUSE_AUTO_CAPTURE => "SDL_MOUSE_AUTO_CAPTURE"u8; [NativeTypeName("#define SDL_HINT_NO_SIGNAL_HANDLERS \"SDL_NO_SIGNAL_HANDLERS\"")] - public static ReadOnlySpan SDL_HINT_NO_SIGNAL_HANDLERS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4E, 0x4F, 0x5F, 0x53, 0x49, 0x47, 0x4E, 0x41, 0x4C, 0x5F, 0x48, 0x41, 0x4E, 0x44, 0x4C, 0x45, 0x52, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_NO_SIGNAL_HANDLERS => "SDL_NO_SIGNAL_HANDLERS"u8; [NativeTypeName("#define SDL_HINT_OPENGL_ES_DRIVER \"SDL_OPENGL_ES_DRIVER\"")] - public static ReadOnlySpan SDL_HINT_OPENGL_ES_DRIVER => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4F, 0x50, 0x45, 0x4E, 0x47, 0x4C, 0x5F, 0x45, 0x53, 0x5F, 0x44, 0x52, 0x49, 0x56, 0x45, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_OPENGL_ES_DRIVER => "SDL_OPENGL_ES_DRIVER"u8; [NativeTypeName("#define SDL_HINT_ORIENTATIONS \"SDL_IOS_ORIENTATIONS\"")] - public static ReadOnlySpan SDL_HINT_ORIENTATIONS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x49, 0x4F, 0x53, 0x5F, 0x4F, 0x52, 0x49, 0x45, 0x4E, 0x54, 0x41, 0x54, 0x49, 0x4F, 0x4E, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_ORIENTATIONS => "SDL_IOS_ORIENTATIONS"u8; [NativeTypeName("#define SDL_HINT_POLL_SENTINEL \"SDL_POLL_SENTINEL\"")] - public static ReadOnlySpan SDL_HINT_POLL_SENTINEL => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x50, 0x4F, 0x4C, 0x4C, 0x5F, 0x53, 0x45, 0x4E, 0x54, 0x49, 0x4E, 0x45, 0x4C, 0x00 }; + public static ReadOnlySpan SDL_HINT_POLL_SENTINEL => "SDL_POLL_SENTINEL"u8; [NativeTypeName("#define SDL_HINT_PREFERRED_LOCALES \"SDL_PREFERRED_LOCALES\"")] - public static ReadOnlySpan SDL_HINT_PREFERRED_LOCALES => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x50, 0x52, 0x45, 0x46, 0x45, 0x52, 0x52, 0x45, 0x44, 0x5F, 0x4C, 0x4F, 0x43, 0x41, 0x4C, 0x45, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_PREFERRED_LOCALES => "SDL_PREFERRED_LOCALES"u8; [NativeTypeName("#define SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION \"SDL_QTWAYLAND_CONTENT_ORIENTATION\"")] - public static ReadOnlySpan SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x51, 0x54, 0x57, 0x41, 0x59, 0x4C, 0x41, 0x4E, 0x44, 0x5F, 0x43, 0x4F, 0x4E, 0x54, 0x45, 0x4E, 0x54, 0x5F, 0x4F, 0x52, 0x49, 0x45, 0x4E, 0x54, 0x41, 0x54, 0x49, 0x4F, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION => "SDL_QTWAYLAND_CONTENT_ORIENTATION"u8; [NativeTypeName("#define SDL_HINT_QTWAYLAND_WINDOW_FLAGS \"SDL_QTWAYLAND_WINDOW_FLAGS\"")] - public static ReadOnlySpan SDL_HINT_QTWAYLAND_WINDOW_FLAGS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x51, 0x54, 0x57, 0x41, 0x59, 0x4C, 0x41, 0x4E, 0x44, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x5F, 0x46, 0x4C, 0x41, 0x47, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_QTWAYLAND_WINDOW_FLAGS => "SDL_QTWAYLAND_WINDOW_FLAGS"u8; [NativeTypeName("#define SDL_HINT_RENDER_BATCHING \"SDL_RENDER_BATCHING\"")] - public static ReadOnlySpan SDL_HINT_RENDER_BATCHING => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x52, 0x45, 0x4E, 0x44, 0x45, 0x52, 0x5F, 0x42, 0x41, 0x54, 0x43, 0x48, 0x49, 0x4E, 0x47, 0x00 }; + public static ReadOnlySpan SDL_HINT_RENDER_BATCHING => "SDL_RENDER_BATCHING"u8; [NativeTypeName("#define SDL_HINT_RENDER_LINE_METHOD \"SDL_RENDER_LINE_METHOD\"")] - public static ReadOnlySpan SDL_HINT_RENDER_LINE_METHOD => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x52, 0x45, 0x4E, 0x44, 0x45, 0x52, 0x5F, 0x4C, 0x49, 0x4E, 0x45, 0x5F, 0x4D, 0x45, 0x54, 0x48, 0x4F, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_RENDER_LINE_METHOD => "SDL_RENDER_LINE_METHOD"u8; [NativeTypeName("#define SDL_HINT_RENDER_DIRECT3D11_DEBUG \"SDL_RENDER_DIRECT3D11_DEBUG\"")] - public static ReadOnlySpan SDL_HINT_RENDER_DIRECT3D11_DEBUG => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x52, 0x45, 0x4E, 0x44, 0x45, 0x52, 0x5F, 0x44, 0x49, 0x52, 0x45, 0x43, 0x54, 0x33, 0x44, 0x31, 0x31, 0x5F, 0x44, 0x45, 0x42, 0x55, 0x47, 0x00 }; + public static ReadOnlySpan SDL_HINT_RENDER_DIRECT3D11_DEBUG => "SDL_RENDER_DIRECT3D11_DEBUG"u8; [NativeTypeName("#define SDL_HINT_RENDER_DIRECT3D_THREADSAFE \"SDL_RENDER_DIRECT3D_THREADSAFE\"")] - public static ReadOnlySpan SDL_HINT_RENDER_DIRECT3D_THREADSAFE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x52, 0x45, 0x4E, 0x44, 0x45, 0x52, 0x5F, 0x44, 0x49, 0x52, 0x45, 0x43, 0x54, 0x33, 0x44, 0x5F, 0x54, 0x48, 0x52, 0x45, 0x41, 0x44, 0x53, 0x41, 0x46, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_RENDER_DIRECT3D_THREADSAFE => "SDL_RENDER_DIRECT3D_THREADSAFE"u8; [NativeTypeName("#define SDL_HINT_RENDER_DRIVER \"SDL_RENDER_DRIVER\"")] - public static ReadOnlySpan SDL_HINT_RENDER_DRIVER => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x52, 0x45, 0x4E, 0x44, 0x45, 0x52, 0x5F, 0x44, 0x52, 0x49, 0x56, 0x45, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_RENDER_DRIVER => "SDL_RENDER_DRIVER"u8; [NativeTypeName("#define SDL_HINT_RENDER_LOGICAL_SIZE_MODE \"SDL_RENDER_LOGICAL_SIZE_MODE\"")] - public static ReadOnlySpan SDL_HINT_RENDER_LOGICAL_SIZE_MODE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x52, 0x45, 0x4E, 0x44, 0x45, 0x52, 0x5F, 0x4C, 0x4F, 0x47, 0x49, 0x43, 0x41, 0x4C, 0x5F, 0x53, 0x49, 0x5A, 0x45, 0x5F, 0x4D, 0x4F, 0x44, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_RENDER_LOGICAL_SIZE_MODE => "SDL_RENDER_LOGICAL_SIZE_MODE"u8; [NativeTypeName("#define SDL_HINT_RENDER_OPENGL_SHADERS \"SDL_RENDER_OPENGL_SHADERS\"")] - public static ReadOnlySpan SDL_HINT_RENDER_OPENGL_SHADERS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x52, 0x45, 0x4E, 0x44, 0x45, 0x52, 0x5F, 0x4F, 0x50, 0x45, 0x4E, 0x47, 0x4C, 0x5F, 0x53, 0x48, 0x41, 0x44, 0x45, 0x52, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_RENDER_OPENGL_SHADERS => "SDL_RENDER_OPENGL_SHADERS"u8; [NativeTypeName("#define SDL_HINT_RENDER_SCALE_QUALITY \"SDL_RENDER_SCALE_QUALITY\"")] - public static ReadOnlySpan SDL_HINT_RENDER_SCALE_QUALITY => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x52, 0x45, 0x4E, 0x44, 0x45, 0x52, 0x5F, 0x53, 0x43, 0x41, 0x4C, 0x45, 0x5F, 0x51, 0x55, 0x41, 0x4C, 0x49, 0x54, 0x59, 0x00 }; + public static ReadOnlySpan SDL_HINT_RENDER_SCALE_QUALITY => "SDL_RENDER_SCALE_QUALITY"u8; [NativeTypeName("#define SDL_HINT_RENDER_VSYNC \"SDL_RENDER_VSYNC\"")] - public static ReadOnlySpan SDL_HINT_RENDER_VSYNC => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x52, 0x45, 0x4E, 0x44, 0x45, 0x52, 0x5F, 0x56, 0x53, 0x59, 0x4E, 0x43, 0x00 }; + public static ReadOnlySpan SDL_HINT_RENDER_VSYNC => "SDL_RENDER_VSYNC"u8; [NativeTypeName("#define SDL_HINT_PS2_DYNAMIC_VSYNC \"SDL_PS2_DYNAMIC_VSYNC\"")] - public static ReadOnlySpan SDL_HINT_PS2_DYNAMIC_VSYNC => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x50, 0x53, 0x32, 0x5F, 0x44, 0x59, 0x4E, 0x41, 0x4D, 0x49, 0x43, 0x5F, 0x56, 0x53, 0x59, 0x4E, 0x43, 0x00 }; + public static ReadOnlySpan SDL_HINT_PS2_DYNAMIC_VSYNC => "SDL_PS2_DYNAMIC_VSYNC"u8; [NativeTypeName("#define SDL_HINT_RETURN_KEY_HIDES_IME \"SDL_RETURN_KEY_HIDES_IME\"")] - public static ReadOnlySpan SDL_HINT_RETURN_KEY_HIDES_IME => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x52, 0x45, 0x54, 0x55, 0x52, 0x4E, 0x5F, 0x4B, 0x45, 0x59, 0x5F, 0x48, 0x49, 0x44, 0x45, 0x53, 0x5F, 0x49, 0x4D, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_RETURN_KEY_HIDES_IME => "SDL_RETURN_KEY_HIDES_IME"u8; [NativeTypeName("#define SDL_HINT_RPI_VIDEO_LAYER \"SDL_RPI_VIDEO_LAYER\"")] - public static ReadOnlySpan SDL_HINT_RPI_VIDEO_LAYER => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x52, 0x50, 0x49, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x4C, 0x41, 0x59, 0x45, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_RPI_VIDEO_LAYER => "SDL_RPI_VIDEO_LAYER"u8; [NativeTypeName("#define SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME \"SDL_SCREENSAVER_INHIBIT_ACTIVITY_NAME\"")] - public static ReadOnlySpan SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x53, 0x43, 0x52, 0x45, 0x45, 0x4E, 0x53, 0x41, 0x56, 0x45, 0x52, 0x5F, 0x49, 0x4E, 0x48, 0x49, 0x42, 0x49, 0x54, 0x5F, 0x41, 0x43, 0x54, 0x49, 0x56, 0x49, 0x54, 0x59, 0x5F, 0x4E, 0x41, 0x4D, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME => "SDL_SCREENSAVER_INHIBIT_ACTIVITY_NAME"u8; [NativeTypeName("#define SDL_HINT_THREAD_FORCE_REALTIME_TIME_CRITICAL \"SDL_THREAD_FORCE_REALTIME_TIME_CRITICAL\"")] - public static ReadOnlySpan SDL_HINT_THREAD_FORCE_REALTIME_TIME_CRITICAL => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x54, 0x48, 0x52, 0x45, 0x41, 0x44, 0x5F, 0x46, 0x4F, 0x52, 0x43, 0x45, 0x5F, 0x52, 0x45, 0x41, 0x4C, 0x54, 0x49, 0x4D, 0x45, 0x5F, 0x54, 0x49, 0x4D, 0x45, 0x5F, 0x43, 0x52, 0x49, 0x54, 0x49, 0x43, 0x41, 0x4C, 0x00 }; + public static ReadOnlySpan SDL_HINT_THREAD_FORCE_REALTIME_TIME_CRITICAL => "SDL_THREAD_FORCE_REALTIME_TIME_CRITICAL"u8; [NativeTypeName("#define SDL_HINT_THREAD_PRIORITY_POLICY \"SDL_THREAD_PRIORITY_POLICY\"")] - public static ReadOnlySpan SDL_HINT_THREAD_PRIORITY_POLICY => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x54, 0x48, 0x52, 0x45, 0x41, 0x44, 0x5F, 0x50, 0x52, 0x49, 0x4F, 0x52, 0x49, 0x54, 0x59, 0x5F, 0x50, 0x4F, 0x4C, 0x49, 0x43, 0x59, 0x00 }; + public static ReadOnlySpan SDL_HINT_THREAD_PRIORITY_POLICY => "SDL_THREAD_PRIORITY_POLICY"u8; [NativeTypeName("#define SDL_HINT_THREAD_STACK_SIZE \"SDL_THREAD_STACK_SIZE\"")] - public static ReadOnlySpan SDL_HINT_THREAD_STACK_SIZE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x54, 0x48, 0x52, 0x45, 0x41, 0x44, 0x5F, 0x53, 0x54, 0x41, 0x43, 0x4B, 0x5F, 0x53, 0x49, 0x5A, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_THREAD_STACK_SIZE => "SDL_THREAD_STACK_SIZE"u8; [NativeTypeName("#define SDL_HINT_TIMER_RESOLUTION \"SDL_TIMER_RESOLUTION\"")] - public static ReadOnlySpan SDL_HINT_TIMER_RESOLUTION => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x54, 0x49, 0x4D, 0x45, 0x52, 0x5F, 0x52, 0x45, 0x53, 0x4F, 0x4C, 0x55, 0x54, 0x49, 0x4F, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_TIMER_RESOLUTION => "SDL_TIMER_RESOLUTION"u8; [NativeTypeName("#define SDL_HINT_TOUCH_MOUSE_EVENTS \"SDL_TOUCH_MOUSE_EVENTS\"")] - public static ReadOnlySpan SDL_HINT_TOUCH_MOUSE_EVENTS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x54, 0x4F, 0x55, 0x43, 0x48, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x45, 0x56, 0x45, 0x4E, 0x54, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_TOUCH_MOUSE_EVENTS => "SDL_TOUCH_MOUSE_EVENTS"u8; [NativeTypeName("#define SDL_HINT_VITA_TOUCH_MOUSE_DEVICE \"SDL_HINT_VITA_TOUCH_MOUSE_DEVICE\"")] - public static ReadOnlySpan SDL_HINT_VITA_TOUCH_MOUSE_DEVICE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x48, 0x49, 0x4E, 0x54, 0x5F, 0x56, 0x49, 0x54, 0x41, 0x5F, 0x54, 0x4F, 0x55, 0x43, 0x48, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_VITA_TOUCH_MOUSE_DEVICE => "SDL_HINT_VITA_TOUCH_MOUSE_DEVICE"u8; [NativeTypeName("#define SDL_HINT_TV_REMOTE_AS_JOYSTICK \"SDL_TV_REMOTE_AS_JOYSTICK\"")] - public static ReadOnlySpan SDL_HINT_TV_REMOTE_AS_JOYSTICK => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x54, 0x56, 0x5F, 0x52, 0x45, 0x4D, 0x4F, 0x54, 0x45, 0x5F, 0x41, 0x53, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x00 }; + public static ReadOnlySpan SDL_HINT_TV_REMOTE_AS_JOYSTICK => "SDL_TV_REMOTE_AS_JOYSTICK"u8; [NativeTypeName("#define SDL_HINT_VIDEO_ALLOW_SCREENSAVER \"SDL_VIDEO_ALLOW_SCREENSAVER\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_ALLOW_SCREENSAVER => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x41, 0x4C, 0x4C, 0x4F, 0x57, 0x5F, 0x53, 0x43, 0x52, 0x45, 0x45, 0x4E, 0x53, 0x41, 0x56, 0x45, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_ALLOW_SCREENSAVER => "SDL_VIDEO_ALLOW_SCREENSAVER"u8; [NativeTypeName("#define SDL_HINT_VIDEO_DOUBLE_BUFFER \"SDL_VIDEO_DOUBLE_BUFFER\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_DOUBLE_BUFFER => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x44, 0x4F, 0x55, 0x42, 0x4C, 0x45, 0x5F, 0x42, 0x55, 0x46, 0x46, 0x45, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_DOUBLE_BUFFER => "SDL_VIDEO_DOUBLE_BUFFER"u8; [NativeTypeName("#define SDL_HINT_VIDEO_EGL_ALLOW_TRANSPARENCY \"SDL_VIDEO_EGL_ALLOW_TRANSPARENCY\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_EGL_ALLOW_TRANSPARENCY => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x45, 0x47, 0x4C, 0x5F, 0x41, 0x4C, 0x4C, 0x4F, 0x57, 0x5F, 0x54, 0x52, 0x41, 0x4E, 0x53, 0x50, 0x41, 0x52, 0x45, 0x4E, 0x43, 0x59, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_EGL_ALLOW_TRANSPARENCY => "SDL_VIDEO_EGL_ALLOW_TRANSPARENCY"u8; [NativeTypeName("#define SDL_HINT_VIDEO_EXTERNAL_CONTEXT \"SDL_VIDEO_EXTERNAL_CONTEXT\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_EXTERNAL_CONTEXT => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x45, 0x58, 0x54, 0x45, 0x52, 0x4E, 0x41, 0x4C, 0x5F, 0x43, 0x4F, 0x4E, 0x54, 0x45, 0x58, 0x54, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_EXTERNAL_CONTEXT => "SDL_VIDEO_EXTERNAL_CONTEXT"u8; [NativeTypeName("#define SDL_HINT_VIDEO_HIGHDPI_DISABLED \"SDL_VIDEO_HIGHDPI_DISABLED\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_HIGHDPI_DISABLED => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x48, 0x49, 0x47, 0x48, 0x44, 0x50, 0x49, 0x5F, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4C, 0x45, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_HIGHDPI_DISABLED => "SDL_VIDEO_HIGHDPI_DISABLED"u8; [NativeTypeName("#define SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES \"SDL_VIDEO_MAC_FULLSCREEN_SPACES\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x4D, 0x41, 0x43, 0x5F, 0x46, 0x55, 0x4C, 0x4C, 0x53, 0x43, 0x52, 0x45, 0x45, 0x4E, 0x5F, 0x53, 0x50, 0x41, 0x43, 0x45, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES => "SDL_VIDEO_MAC_FULLSCREEN_SPACES"u8; [NativeTypeName("#define SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS \"SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x4D, 0x49, 0x4E, 0x49, 0x4D, 0x49, 0x5A, 0x45, 0x5F, 0x4F, 0x4E, 0x5F, 0x46, 0x4F, 0x43, 0x55, 0x53, 0x5F, 0x4C, 0x4F, 0x53, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS => "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS"u8; [NativeTypeName("#define SDL_HINT_VIDEO_WAYLAND_ALLOW_LIBDECOR \"SDL_VIDEO_WAYLAND_ALLOW_LIBDECOR\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_WAYLAND_ALLOW_LIBDECOR => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x57, 0x41, 0x59, 0x4C, 0x41, 0x4E, 0x44, 0x5F, 0x41, 0x4C, 0x4C, 0x4F, 0x57, 0x5F, 0x4C, 0x49, 0x42, 0x44, 0x45, 0x43, 0x4F, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_WAYLAND_ALLOW_LIBDECOR => "SDL_VIDEO_WAYLAND_ALLOW_LIBDECOR"u8; [NativeTypeName("#define SDL_HINT_VIDEO_WAYLAND_PREFER_LIBDECOR \"SDL_VIDEO_WAYLAND_PREFER_LIBDECOR\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_WAYLAND_PREFER_LIBDECOR => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x57, 0x41, 0x59, 0x4C, 0x41, 0x4E, 0x44, 0x5F, 0x50, 0x52, 0x45, 0x46, 0x45, 0x52, 0x5F, 0x4C, 0x49, 0x42, 0x44, 0x45, 0x43, 0x4F, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_WAYLAND_PREFER_LIBDECOR => "SDL_VIDEO_WAYLAND_PREFER_LIBDECOR"u8; [NativeTypeName("#define SDL_HINT_VIDEO_WAYLAND_MODE_EMULATION \"SDL_VIDEO_WAYLAND_MODE_EMULATION\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_WAYLAND_MODE_EMULATION => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x57, 0x41, 0x59, 0x4C, 0x41, 0x4E, 0x44, 0x5F, 0x4D, 0x4F, 0x44, 0x45, 0x5F, 0x45, 0x4D, 0x55, 0x4C, 0x41, 0x54, 0x49, 0x4F, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_WAYLAND_MODE_EMULATION => "SDL_VIDEO_WAYLAND_MODE_EMULATION"u8; [NativeTypeName("#define SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP \"SDL_VIDEO_WAYLAND_EMULATE_MOUSE_WARP\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x57, 0x41, 0x59, 0x4C, 0x41, 0x4E, 0x44, 0x5F, 0x45, 0x4D, 0x55, 0x4C, 0x41, 0x54, 0x45, 0x5F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x5F, 0x57, 0x41, 0x52, 0x50, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP => "SDL_VIDEO_WAYLAND_EMULATE_MOUSE_WARP"u8; [NativeTypeName("#define SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT \"SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x5F, 0x53, 0x48, 0x41, 0x52, 0x45, 0x5F, 0x50, 0x49, 0x58, 0x45, 0x4C, 0x5F, 0x46, 0x4F, 0x52, 0x4D, 0x41, 0x54, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT => "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT"u8; [NativeTypeName("#define SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL \"SDL_VIDEO_FOREIGN_WINDOW_OPENGL\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x46, 0x4F, 0x52, 0x45, 0x49, 0x47, 0x4E, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x5F, 0x4F, 0x50, 0x45, 0x4E, 0x47, 0x4C, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL => "SDL_VIDEO_FOREIGN_WINDOW_OPENGL"u8; [NativeTypeName("#define SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN \"SDL_VIDEO_FOREIGN_WINDOW_VULKAN\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x46, 0x4F, 0x52, 0x45, 0x49, 0x47, 0x4E, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x5F, 0x56, 0x55, 0x4C, 0x4B, 0x41, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN => "SDL_VIDEO_FOREIGN_WINDOW_VULKAN"u8; [NativeTypeName("#define SDL_HINT_VIDEO_WIN_D3DCOMPILER \"SDL_VIDEO_WIN_D3DCOMPILER\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_WIN_D3DCOMPILER => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x57, 0x49, 0x4E, 0x5F, 0x44, 0x33, 0x44, 0x43, 0x4F, 0x4D, 0x50, 0x49, 0x4C, 0x45, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_WIN_D3DCOMPILER => "SDL_VIDEO_WIN_D3DCOMPILER"u8; [NativeTypeName("#define SDL_HINT_VIDEO_X11_FORCE_EGL \"SDL_VIDEO_X11_FORCE_EGL\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_X11_FORCE_EGL => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x58, 0x31, 0x31, 0x5F, 0x46, 0x4F, 0x52, 0x43, 0x45, 0x5F, 0x45, 0x47, 0x4C, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_X11_FORCE_EGL => "SDL_VIDEO_X11_FORCE_EGL"u8; [NativeTypeName("#define SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR \"SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x58, 0x31, 0x31, 0x5F, 0x4E, 0x45, 0x54, 0x5F, 0x57, 0x4D, 0x5F, 0x42, 0x59, 0x50, 0x41, 0x53, 0x53, 0x5F, 0x43, 0x4F, 0x4D, 0x50, 0x4F, 0x53, 0x49, 0x54, 0x4F, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR => "SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR"u8; [NativeTypeName("#define SDL_HINT_VIDEO_X11_NET_WM_PING \"SDL_VIDEO_X11_NET_WM_PING\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_X11_NET_WM_PING => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x58, 0x31, 0x31, 0x5F, 0x4E, 0x45, 0x54, 0x5F, 0x57, 0x4D, 0x5F, 0x50, 0x49, 0x4E, 0x47, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_X11_NET_WM_PING => "SDL_VIDEO_X11_NET_WM_PING"u8; [NativeTypeName("#define SDL_HINT_VIDEO_X11_WINDOW_VISUALID \"SDL_VIDEO_X11_WINDOW_VISUALID\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_X11_WINDOW_VISUALID => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x58, 0x31, 0x31, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x5F, 0x56, 0x49, 0x53, 0x55, 0x41, 0x4C, 0x49, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_X11_WINDOW_VISUALID => "SDL_VIDEO_X11_WINDOW_VISUALID"u8; [NativeTypeName("#define SDL_HINT_VIDEO_X11_XINERAMA \"SDL_VIDEO_X11_XINERAMA\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_X11_XINERAMA => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x58, 0x31, 0x31, 0x5F, 0x58, 0x49, 0x4E, 0x45, 0x52, 0x41, 0x4D, 0x41, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_X11_XINERAMA => "SDL_VIDEO_X11_XINERAMA"u8; [NativeTypeName("#define SDL_HINT_VIDEO_X11_XRANDR \"SDL_VIDEO_X11_XRANDR\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_X11_XRANDR => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x58, 0x31, 0x31, 0x5F, 0x58, 0x52, 0x41, 0x4E, 0x44, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_X11_XRANDR => "SDL_VIDEO_X11_XRANDR"u8; [NativeTypeName("#define SDL_HINT_VIDEO_X11_XVIDMODE \"SDL_VIDEO_X11_XVIDMODE\"")] - public static ReadOnlySpan SDL_HINT_VIDEO_X11_XVIDMODE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x5F, 0x58, 0x31, 0x31, 0x5F, 0x58, 0x56, 0x49, 0x44, 0x4D, 0x4F, 0x44, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEO_X11_XVIDMODE => "SDL_VIDEO_X11_XVIDMODE"u8; [NativeTypeName("#define SDL_HINT_WAVE_FACT_CHUNK \"SDL_WAVE_FACT_CHUNK\"")] - public static ReadOnlySpan SDL_HINT_WAVE_FACT_CHUNK => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x41, 0x56, 0x45, 0x5F, 0x46, 0x41, 0x43, 0x54, 0x5F, 0x43, 0x48, 0x55, 0x4E, 0x4B, 0x00 }; + public static ReadOnlySpan SDL_HINT_WAVE_FACT_CHUNK => "SDL_WAVE_FACT_CHUNK"u8; [NativeTypeName("#define SDL_HINT_WAVE_RIFF_CHUNK_SIZE \"SDL_WAVE_RIFF_CHUNK_SIZE\"")] - public static ReadOnlySpan SDL_HINT_WAVE_RIFF_CHUNK_SIZE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x41, 0x56, 0x45, 0x5F, 0x52, 0x49, 0x46, 0x46, 0x5F, 0x43, 0x48, 0x55, 0x4E, 0x4B, 0x5F, 0x53, 0x49, 0x5A, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_WAVE_RIFF_CHUNK_SIZE => "SDL_WAVE_RIFF_CHUNK_SIZE"u8; [NativeTypeName("#define SDL_HINT_WAVE_TRUNCATION \"SDL_WAVE_TRUNCATION\"")] - public static ReadOnlySpan SDL_HINT_WAVE_TRUNCATION => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x41, 0x56, 0x45, 0x5F, 0x54, 0x52, 0x55, 0x4E, 0x43, 0x41, 0x54, 0x49, 0x4F, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_WAVE_TRUNCATION => "SDL_WAVE_TRUNCATION"u8; [NativeTypeName("#define SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING \"SDL_WINDOWS_DISABLE_THREAD_NAMING\"")] - public static ReadOnlySpan SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x53, 0x5F, 0x44, 0x49, 0x53, 0x41, 0x42, 0x4C, 0x45, 0x5F, 0x54, 0x48, 0x52, 0x45, 0x41, 0x44, 0x5F, 0x4E, 0x41, 0x4D, 0x49, 0x4E, 0x47, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING => "SDL_WINDOWS_DISABLE_THREAD_NAMING"u8; [NativeTypeName("#define SDL_HINT_WINDOWS_ENABLE_MENU_MNEMONICS \"SDL_WINDOWS_ENABLE_MENU_MNEMONICS\"")] - public static ReadOnlySpan SDL_HINT_WINDOWS_ENABLE_MENU_MNEMONICS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x53, 0x5F, 0x45, 0x4E, 0x41, 0x42, 0x4C, 0x45, 0x5F, 0x4D, 0x45, 0x4E, 0x55, 0x5F, 0x4D, 0x4E, 0x45, 0x4D, 0x4F, 0x4E, 0x49, 0x43, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINDOWS_ENABLE_MENU_MNEMONICS => "SDL_WINDOWS_ENABLE_MENU_MNEMONICS"u8; [NativeTypeName("#define SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP \"SDL_WINDOWS_ENABLE_MESSAGELOOP\"")] - public static ReadOnlySpan SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x53, 0x5F, 0x45, 0x4E, 0x41, 0x42, 0x4C, 0x45, 0x5F, 0x4D, 0x45, 0x53, 0x53, 0x41, 0x47, 0x45, 0x4C, 0x4F, 0x4F, 0x50, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP => "SDL_WINDOWS_ENABLE_MESSAGELOOP"u8; [NativeTypeName("#define SDL_HINT_WINDOWS_FORCE_MUTEX_CRITICAL_SECTIONS \"SDL_WINDOWS_FORCE_MUTEX_CRITICAL_SECTIONS\"")] - public static ReadOnlySpan SDL_HINT_WINDOWS_FORCE_MUTEX_CRITICAL_SECTIONS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x53, 0x5F, 0x46, 0x4F, 0x52, 0x43, 0x45, 0x5F, 0x4D, 0x55, 0x54, 0x45, 0x58, 0x5F, 0x43, 0x52, 0x49, 0x54, 0x49, 0x43, 0x41, 0x4C, 0x5F, 0x53, 0x45, 0x43, 0x54, 0x49, 0x4F, 0x4E, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINDOWS_FORCE_MUTEX_CRITICAL_SECTIONS => "SDL_WINDOWS_FORCE_MUTEX_CRITICAL_SECTIONS"u8; [NativeTypeName("#define SDL_HINT_WINDOWS_FORCE_SEMAPHORE_KERNEL \"SDL_WINDOWS_FORCE_SEMAPHORE_KERNEL\"")] - public static ReadOnlySpan SDL_HINT_WINDOWS_FORCE_SEMAPHORE_KERNEL => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x53, 0x5F, 0x46, 0x4F, 0x52, 0x43, 0x45, 0x5F, 0x53, 0x45, 0x4D, 0x41, 0x50, 0x48, 0x4F, 0x52, 0x45, 0x5F, 0x4B, 0x45, 0x52, 0x4E, 0x45, 0x4C, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINDOWS_FORCE_SEMAPHORE_KERNEL => "SDL_WINDOWS_FORCE_SEMAPHORE_KERNEL"u8; [NativeTypeName("#define SDL_HINT_WINDOWS_INTRESOURCE_ICON \"SDL_WINDOWS_INTRESOURCE_ICON\"")] - public static ReadOnlySpan SDL_HINT_WINDOWS_INTRESOURCE_ICON => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x53, 0x5F, 0x49, 0x4E, 0x54, 0x52, 0x45, 0x53, 0x4F, 0x55, 0x52, 0x43, 0x45, 0x5F, 0x49, 0x43, 0x4F, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINDOWS_INTRESOURCE_ICON => "SDL_WINDOWS_INTRESOURCE_ICON"u8; [NativeTypeName("#define SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL \"SDL_WINDOWS_INTRESOURCE_ICON_SMALL\"")] - public static ReadOnlySpan SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x53, 0x5F, 0x49, 0x4E, 0x54, 0x52, 0x45, 0x53, 0x4F, 0x55, 0x52, 0x43, 0x45, 0x5F, 0x49, 0x43, 0x4F, 0x4E, 0x5F, 0x53, 0x4D, 0x41, 0x4C, 0x4C, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL => "SDL_WINDOWS_INTRESOURCE_ICON_SMALL"u8; [NativeTypeName("#define SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 \"SDL_WINDOWS_NO_CLOSE_ON_ALT_F4\"")] - public static ReadOnlySpan SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x53, 0x5F, 0x4E, 0x4F, 0x5F, 0x43, 0x4C, 0x4F, 0x53, 0x45, 0x5F, 0x4F, 0x4E, 0x5F, 0x41, 0x4C, 0x54, 0x5F, 0x46, 0x34, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 => "SDL_WINDOWS_NO_CLOSE_ON_ALT_F4"u8; [NativeTypeName("#define SDL_HINT_WINDOWS_USE_D3D9EX \"SDL_WINDOWS_USE_D3D9EX\"")] - public static ReadOnlySpan SDL_HINT_WINDOWS_USE_D3D9EX => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x53, 0x5F, 0x55, 0x53, 0x45, 0x5F, 0x44, 0x33, 0x44, 0x39, 0x45, 0x58, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINDOWS_USE_D3D9EX => "SDL_WINDOWS_USE_D3D9EX"u8; [NativeTypeName("#define SDL_HINT_WINDOWS_DPI_AWARENESS \"SDL_WINDOWS_DPI_AWARENESS\"")] - public static ReadOnlySpan SDL_HINT_WINDOWS_DPI_AWARENESS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x53, 0x5F, 0x44, 0x50, 0x49, 0x5F, 0x41, 0x57, 0x41, 0x52, 0x45, 0x4E, 0x45, 0x53, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINDOWS_DPI_AWARENESS => "SDL_WINDOWS_DPI_AWARENESS"u8; [NativeTypeName("#define SDL_HINT_WINDOWS_DPI_SCALING \"SDL_WINDOWS_DPI_SCALING\"")] - public static ReadOnlySpan SDL_HINT_WINDOWS_DPI_SCALING => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x53, 0x5F, 0x44, 0x50, 0x49, 0x5F, 0x53, 0x43, 0x41, 0x4C, 0x49, 0x4E, 0x47, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINDOWS_DPI_SCALING => "SDL_WINDOWS_DPI_SCALING"u8; [NativeTypeName("#define SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN \"SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN\"")] - public static ReadOnlySpan SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x5F, 0x46, 0x52, 0x41, 0x4D, 0x45, 0x5F, 0x55, 0x53, 0x41, 0x42, 0x4C, 0x45, 0x5F, 0x57, 0x48, 0x49, 0x4C, 0x45, 0x5F, 0x43, 0x55, 0x52, 0x53, 0x4F, 0x52, 0x5F, 0x48, 0x49, 0x44, 0x44, 0x45, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN => "SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN"u8; [NativeTypeName("#define SDL_HINT_WINDOW_NO_ACTIVATION_WHEN_SHOWN \"SDL_WINDOW_NO_ACTIVATION_WHEN_SHOWN\"")] - public static ReadOnlySpan SDL_HINT_WINDOW_NO_ACTIVATION_WHEN_SHOWN => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x5F, 0x4E, 0x4F, 0x5F, 0x41, 0x43, 0x54, 0x49, 0x56, 0x41, 0x54, 0x49, 0x4F, 0x4E, 0x5F, 0x57, 0x48, 0x45, 0x4E, 0x5F, 0x53, 0x48, 0x4F, 0x57, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINDOW_NO_ACTIVATION_WHEN_SHOWN => "SDL_WINDOW_NO_ACTIVATION_WHEN_SHOWN"u8; [NativeTypeName("#define SDL_HINT_WINRT_HANDLE_BACK_BUTTON \"SDL_WINRT_HANDLE_BACK_BUTTON\"")] - public static ReadOnlySpan SDL_HINT_WINRT_HANDLE_BACK_BUTTON => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x52, 0x54, 0x5F, 0x48, 0x41, 0x4E, 0x44, 0x4C, 0x45, 0x5F, 0x42, 0x41, 0x43, 0x4B, 0x5F, 0x42, 0x55, 0x54, 0x54, 0x4F, 0x4E, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINRT_HANDLE_BACK_BUTTON => "SDL_WINRT_HANDLE_BACK_BUTTON"u8; [NativeTypeName("#define SDL_HINT_WINRT_PRIVACY_POLICY_LABEL \"SDL_WINRT_PRIVACY_POLICY_LABEL\"")] - public static ReadOnlySpan SDL_HINT_WINRT_PRIVACY_POLICY_LABEL => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x52, 0x54, 0x5F, 0x50, 0x52, 0x49, 0x56, 0x41, 0x43, 0x59, 0x5F, 0x50, 0x4F, 0x4C, 0x49, 0x43, 0x59, 0x5F, 0x4C, 0x41, 0x42, 0x45, 0x4C, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINRT_PRIVACY_POLICY_LABEL => "SDL_WINRT_PRIVACY_POLICY_LABEL"u8; [NativeTypeName("#define SDL_HINT_WINRT_PRIVACY_POLICY_URL \"SDL_WINRT_PRIVACY_POLICY_URL\"")] - public static ReadOnlySpan SDL_HINT_WINRT_PRIVACY_POLICY_URL => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x57, 0x49, 0x4E, 0x52, 0x54, 0x5F, 0x50, 0x52, 0x49, 0x56, 0x41, 0x43, 0x59, 0x5F, 0x50, 0x4F, 0x4C, 0x49, 0x43, 0x59, 0x5F, 0x55, 0x52, 0x4C, 0x00 }; + public static ReadOnlySpan SDL_HINT_WINRT_PRIVACY_POLICY_URL => "SDL_WINRT_PRIVACY_POLICY_URL"u8; [NativeTypeName("#define SDL_HINT_X11_FORCE_OVERRIDE_REDIRECT \"SDL_X11_FORCE_OVERRIDE_REDIRECT\"")] - public static ReadOnlySpan SDL_HINT_X11_FORCE_OVERRIDE_REDIRECT => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x58, 0x31, 0x31, 0x5F, 0x46, 0x4F, 0x52, 0x43, 0x45, 0x5F, 0x4F, 0x56, 0x45, 0x52, 0x52, 0x49, 0x44, 0x45, 0x5F, 0x52, 0x45, 0x44, 0x49, 0x52, 0x45, 0x43, 0x54, 0x00 }; + public static ReadOnlySpan SDL_HINT_X11_FORCE_OVERRIDE_REDIRECT => "SDL_X11_FORCE_OVERRIDE_REDIRECT"u8; [NativeTypeName("#define SDL_HINT_XINPUT_ENABLED \"SDL_XINPUT_ENABLED\"")] - public static ReadOnlySpan SDL_HINT_XINPUT_ENABLED => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x58, 0x49, 0x4E, 0x50, 0x55, 0x54, 0x5F, 0x45, 0x4E, 0x41, 0x42, 0x4C, 0x45, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_XINPUT_ENABLED => "SDL_XINPUT_ENABLED"u8; [NativeTypeName("#define SDL_HINT_DIRECTINPUT_ENABLED \"SDL_DIRECTINPUT_ENABLED\"")] - public static ReadOnlySpan SDL_HINT_DIRECTINPUT_ENABLED => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x44, 0x49, 0x52, 0x45, 0x43, 0x54, 0x49, 0x4E, 0x50, 0x55, 0x54, 0x5F, 0x45, 0x4E, 0x41, 0x42, 0x4C, 0x45, 0x44, 0x00 }; + public static ReadOnlySpan SDL_HINT_DIRECTINPUT_ENABLED => "SDL_DIRECTINPUT_ENABLED"u8; [NativeTypeName("#define SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING \"SDL_XINPUT_USE_OLD_JOYSTICK_MAPPING\"")] - public static ReadOnlySpan SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x58, 0x49, 0x4E, 0x50, 0x55, 0x54, 0x5F, 0x55, 0x53, 0x45, 0x5F, 0x4F, 0x4C, 0x44, 0x5F, 0x4A, 0x4F, 0x59, 0x53, 0x54, 0x49, 0x43, 0x4B, 0x5F, 0x4D, 0x41, 0x50, 0x50, 0x49, 0x4E, 0x47, 0x00 }; + public static ReadOnlySpan SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING => "SDL_XINPUT_USE_OLD_JOYSTICK_MAPPING"u8; [NativeTypeName("#define SDL_HINT_AUDIO_INCLUDE_MONITORS \"SDL_AUDIO_INCLUDE_MONITORS\"")] - public static ReadOnlySpan SDL_HINT_AUDIO_INCLUDE_MONITORS => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x55, 0x44, 0x49, 0x4F, 0x5F, 0x49, 0x4E, 0x43, 0x4C, 0x55, 0x44, 0x45, 0x5F, 0x4D, 0x4F, 0x4E, 0x49, 0x54, 0x4F, 0x52, 0x53, 0x00 }; + public static ReadOnlySpan SDL_HINT_AUDIO_INCLUDE_MONITORS => "SDL_AUDIO_INCLUDE_MONITORS"u8; [NativeTypeName("#define SDL_HINT_X11_WINDOW_TYPE \"SDL_X11_WINDOW_TYPE\"")] - public static ReadOnlySpan SDL_HINT_X11_WINDOW_TYPE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x58, 0x31, 0x31, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x5F, 0x54, 0x59, 0x50, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_X11_WINDOW_TYPE => "SDL_X11_WINDOW_TYPE"u8; [NativeTypeName("#define SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE \"SDL_QUIT_ON_LAST_WINDOW_CLOSE\"")] - public static ReadOnlySpan SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x51, 0x55, 0x49, 0x54, 0x5F, 0x4F, 0x4E, 0x5F, 0x4C, 0x41, 0x53, 0x54, 0x5F, 0x57, 0x49, 0x4E, 0x44, 0x4F, 0x57, 0x5F, 0x43, 0x4C, 0x4F, 0x53, 0x45, 0x00 }; + public static ReadOnlySpan SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE => "SDL_QUIT_ON_LAST_WINDOW_CLOSE"u8; [NativeTypeName("#define SDL_HINT_VIDEODRIVER \"SDL_VIDEODRIVER\"")] - public static ReadOnlySpan SDL_HINT_VIDEODRIVER => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x56, 0x49, 0x44, 0x45, 0x4F, 0x44, 0x52, 0x49, 0x56, 0x45, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_VIDEODRIVER => "SDL_VIDEODRIVER"u8; [NativeTypeName("#define SDL_HINT_AUDIODRIVER \"SDL_AUDIODRIVER\"")] - public static ReadOnlySpan SDL_HINT_AUDIODRIVER => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x41, 0x55, 0x44, 0x49, 0x4F, 0x44, 0x52, 0x49, 0x56, 0x45, 0x52, 0x00 }; + public static ReadOnlySpan SDL_HINT_AUDIODRIVER => "SDL_AUDIODRIVER"u8; [NativeTypeName("#define SDL_HINT_KMSDRM_DEVICE_INDEX \"SDL_KMSDRM_DEVICE_INDEX\"")] - public static ReadOnlySpan SDL_HINT_KMSDRM_DEVICE_INDEX => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x4B, 0x4D, 0x53, 0x44, 0x52, 0x4D, 0x5F, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x5F, 0x49, 0x4E, 0x44, 0x45, 0x58, 0x00 }; + public static ReadOnlySpan SDL_HINT_KMSDRM_DEVICE_INDEX => "SDL_KMSDRM_DEVICE_INDEX"u8; [NativeTypeName("#define SDL_HINT_TRACKPAD_IS_TOUCH_ONLY \"SDL_TRACKPAD_IS_TOUCH_ONLY\"")] - public static ReadOnlySpan SDL_HINT_TRACKPAD_IS_TOUCH_ONLY => new byte[] { 0x53, 0x44, 0x4C, 0x5F, 0x54, 0x52, 0x41, 0x43, 0x4B, 0x50, 0x41, 0x44, 0x5F, 0x49, 0x53, 0x5F, 0x54, 0x4F, 0x55, 0x43, 0x48, 0x5F, 0x4F, 0x4E, 0x4C, 0x59, 0x00 }; + public static ReadOnlySpan SDL_HINT_TRACKPAD_IS_TOUCH_ONLY => "SDL_TRACKPAD_IS_TOUCH_ONLY"u8; [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_LockJoysticks", ExactSpelling = true)] public static extern void LockJoysticks(); @@ -1644,20 +1644,20 @@ public static unsafe partial class SDL [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_RWread", ExactSpelling = true)] [return: NativeTypeName("size_t")] - public static extern UIntPtr RWread(SDL_RWops* context, void* ptr, [NativeTypeName("size_t")] UIntPtr size, [NativeTypeName("size_t")] UIntPtr maxnum); + public static extern nuint RWread(SDL_RWops* context, void* ptr, [NativeTypeName("size_t")] nuint size, [NativeTypeName("size_t")] nuint maxnum); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_RWwrite", ExactSpelling = true)] [return: NativeTypeName("size_t")] - public static extern UIntPtr RWwrite(SDL_RWops* context, [NativeTypeName("const void *")] void* ptr, [NativeTypeName("size_t")] UIntPtr size, [NativeTypeName("size_t")] UIntPtr num); + public static extern nuint RWwrite(SDL_RWops* context, [NativeTypeName("const void *")] void* ptr, [NativeTypeName("size_t")] nuint size, [NativeTypeName("size_t")] nuint num); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_RWclose", ExactSpelling = true)] public static extern int RWclose(SDL_RWops* context); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_LoadFile_RW", ExactSpelling = true)] - public static extern void* LoadFile_RW(SDL_RWops* src, [NativeTypeName("size_t *")] UIntPtr* datasize, int freesrc); + public static extern void* LoadFile_RW(SDL_RWops* src, [NativeTypeName("size_t *")] nuint* datasize, int freesrc); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_LoadFile", ExactSpelling = true)] - public static extern void* LoadFile([NativeTypeName("const char *")] sbyte* file, [NativeTypeName("size_t *")] UIntPtr* datasize); + public static extern void* LoadFile([NativeTypeName("const char *")] sbyte* file, [NativeTypeName("size_t *")] nuint* datasize); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_ReadU8", ExactSpelling = true)] [return: NativeTypeName("Uint8")] @@ -1689,31 +1689,31 @@ public static unsafe partial class SDL [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_WriteU8", ExactSpelling = true)] [return: NativeTypeName("size_t")] - public static extern UIntPtr WriteU8(SDL_RWops* dst, [NativeTypeName("Uint8")] byte value); + public static extern nuint WriteU8(SDL_RWops* dst, [NativeTypeName("Uint8")] byte value); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_WriteLE16", ExactSpelling = true)] [return: NativeTypeName("size_t")] - public static extern UIntPtr WriteLE16(SDL_RWops* dst, [NativeTypeName("Uint16")] ushort value); + public static extern nuint WriteLE16(SDL_RWops* dst, [NativeTypeName("Uint16")] ushort value); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_WriteBE16", ExactSpelling = true)] [return: NativeTypeName("size_t")] - public static extern UIntPtr WriteBE16(SDL_RWops* dst, [NativeTypeName("Uint16")] ushort value); + public static extern nuint WriteBE16(SDL_RWops* dst, [NativeTypeName("Uint16")] ushort value); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_WriteLE32", ExactSpelling = true)] [return: NativeTypeName("size_t")] - public static extern UIntPtr WriteLE32(SDL_RWops* dst, [NativeTypeName("Uint32")] uint value); + public static extern nuint WriteLE32(SDL_RWops* dst, [NativeTypeName("Uint32")] uint value); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_WriteBE32", ExactSpelling = true)] [return: NativeTypeName("size_t")] - public static extern UIntPtr WriteBE32(SDL_RWops* dst, [NativeTypeName("Uint32")] uint value); + public static extern nuint WriteBE32(SDL_RWops* dst, [NativeTypeName("Uint32")] uint value); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_WriteLE64", ExactSpelling = true)] [return: NativeTypeName("size_t")] - public static extern UIntPtr WriteLE64(SDL_RWops* dst, [NativeTypeName("Uint64")] ulong value); + public static extern nuint WriteLE64(SDL_RWops* dst, [NativeTypeName("Uint64")] ulong value); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_WriteBE64", ExactSpelling = true)] [return: NativeTypeName("size_t")] - public static extern UIntPtr WriteBE64(SDL_RWops* dst, [NativeTypeName("Uint64")] ulong value); + public static extern nuint WriteBE64(SDL_RWops* dst, [NativeTypeName("Uint64")] ulong value); [NativeTypeName("#define SDL_RWOPS_UNKNOWN 0U")] public const uint SDL_RWOPS_UNKNOWN = 0U; @@ -1743,25 +1743,25 @@ public static unsafe partial class SDL public const int RW_SEEK_END = 2; [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_malloc", ExactSpelling = true)] - public static extern void* malloc([NativeTypeName("size_t")] UIntPtr size); + public static extern void* malloc([NativeTypeName("size_t")] nuint size); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_calloc", ExactSpelling = true)] - public static extern void* calloc([NativeTypeName("size_t")] UIntPtr nmemb, [NativeTypeName("size_t")] UIntPtr size); + public static extern void* calloc([NativeTypeName("size_t")] nuint nmemb, [NativeTypeName("size_t")] nuint size); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_realloc", ExactSpelling = true)] - public static extern void* realloc(void* mem, [NativeTypeName("size_t")] UIntPtr size); + public static extern void* realloc(void* mem, [NativeTypeName("size_t")] nuint size); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_free", ExactSpelling = true)] public static extern void free(void* mem); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetOriginalMemoryFunctions", ExactSpelling = true)] - public static extern void GetOriginalMemoryFunctions([NativeTypeName("SDL_malloc_func *")] IntPtr* malloc_func, [NativeTypeName("SDL_calloc_func *")] IntPtr* calloc_func, [NativeTypeName("SDL_realloc_func *")] IntPtr* realloc_func, [NativeTypeName("SDL_free_func *")] IntPtr* free_func); + public static extern void GetOriginalMemoryFunctions([NativeTypeName("SDL_malloc_func *")] delegate* unmanaged[Cdecl]* malloc_func, [NativeTypeName("SDL_calloc_func *")] delegate* unmanaged[Cdecl]* calloc_func, [NativeTypeName("SDL_realloc_func *")] delegate* unmanaged[Cdecl]* realloc_func, [NativeTypeName("SDL_free_func *")] delegate* unmanaged[Cdecl]* free_func); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetMemoryFunctions", ExactSpelling = true)] - public static extern void GetMemoryFunctions([NativeTypeName("SDL_malloc_func *")] IntPtr* malloc_func, [NativeTypeName("SDL_calloc_func *")] IntPtr* calloc_func, [NativeTypeName("SDL_realloc_func *")] IntPtr* realloc_func, [NativeTypeName("SDL_free_func *")] IntPtr* free_func); + public static extern void GetMemoryFunctions([NativeTypeName("SDL_malloc_func *")] delegate* unmanaged[Cdecl]* malloc_func, [NativeTypeName("SDL_calloc_func *")] delegate* unmanaged[Cdecl]* calloc_func, [NativeTypeName("SDL_realloc_func *")] delegate* unmanaged[Cdecl]* realloc_func, [NativeTypeName("SDL_free_func *")] delegate* unmanaged[Cdecl]* free_func); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_SetMemoryFunctions", ExactSpelling = true)] - public static extern int SetMemoryFunctions([NativeTypeName("SDL_malloc_func")] IntPtr malloc_func, [NativeTypeName("SDL_calloc_func")] IntPtr calloc_func, [NativeTypeName("SDL_realloc_func")] IntPtr realloc_func, [NativeTypeName("SDL_free_func")] IntPtr free_func); + public static extern int SetMemoryFunctions([NativeTypeName("SDL_malloc_func")] delegate* unmanaged[Cdecl] malloc_func, [NativeTypeName("SDL_calloc_func")] delegate* unmanaged[Cdecl] calloc_func, [NativeTypeName("SDL_realloc_func")] delegate* unmanaged[Cdecl] realloc_func, [NativeTypeName("SDL_free_func")] delegate* unmanaged[Cdecl] free_func); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetNumAllocations", ExactSpelling = true)] public static extern int GetNumAllocations(); @@ -1779,11 +1779,11 @@ public static unsafe partial class SDL [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_iconv", ExactSpelling = true)] [return: NativeTypeName("size_t")] - public static extern UIntPtr iconv([NativeTypeName("SDL_iconv_t")] _SDL_iconv_t* cd, [NativeTypeName("const char **")] sbyte** inbuf, [NativeTypeName("size_t *")] UIntPtr* inbytesleft, [NativeTypeName("char **")] sbyte** outbuf, [NativeTypeName("size_t *")] UIntPtr* outbytesleft); + public static extern nuint iconv([NativeTypeName("SDL_iconv_t")] _SDL_iconv_t* cd, [NativeTypeName("const char **")] sbyte** inbuf, [NativeTypeName("size_t *")] nuint* inbytesleft, [NativeTypeName("char **")] sbyte** outbuf, [NativeTypeName("size_t *")] nuint* outbytesleft); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_iconv_string", ExactSpelling = true)] [return: NativeTypeName("char *")] - public static extern sbyte* iconv_string([NativeTypeName("const char *")] sbyte* tocode, [NativeTypeName("const char *")] sbyte* fromcode, [NativeTypeName("const char *")] sbyte* inbuf, [NativeTypeName("size_t")] UIntPtr inbytesleft); + public static extern sbyte* iconv_string([NativeTypeName("const char *")] sbyte* tocode, [NativeTypeName("const char *")] sbyte* fromcode, [NativeTypeName("const char *")] sbyte* inbuf, [NativeTypeName("size_t")] nuint inbytesleft); [NativeTypeName("#define SDL_SIZE_MAX SIZE_MAX")] public const ulong SDL_SIZE_MAX = 0xffffffffffffffffUL; @@ -1840,43 +1840,43 @@ public static unsafe partial class SDL public const float SDL_FLT_EPSILON = 1.1920928955078125e-07F; [NativeTypeName("#define SDL_PRIs64 \"I64d\"")] - public static ReadOnlySpan SDL_PRIs64 => new byte[] { 0x49, 0x36, 0x34, 0x64, 0x00 }; + public static ReadOnlySpan SDL_PRIs64 => "I64d"u8; [NativeTypeName("#define SDL_PRIu64 \"I64u\"")] - public static ReadOnlySpan SDL_PRIu64 => new byte[] { 0x49, 0x36, 0x34, 0x75, 0x00 }; + public static ReadOnlySpan SDL_PRIu64 => "I64u"u8; [NativeTypeName("#define SDL_PRIx64 \"I64x\"")] - public static ReadOnlySpan SDL_PRIx64 => new byte[] { 0x49, 0x36, 0x34, 0x78, 0x00 }; + public static ReadOnlySpan SDL_PRIx64 => "I64x"u8; [NativeTypeName("#define SDL_PRIX64 \"I64X\"")] - public static ReadOnlySpan SDL_PRIX64 => new byte[] { 0x49, 0x36, 0x34, 0x58, 0x00 }; + public static ReadOnlySpan SDL_PRIX64 => "I64X"u8; [NativeTypeName("#define SDL_PRIs32 \"d\"")] - public static ReadOnlySpan SDL_PRIs32 => new byte[] { 0x64, 0x00 }; + public static ReadOnlySpan SDL_PRIs32 => "d"u8; [NativeTypeName("#define SDL_PRIu32 \"u\"")] - public static ReadOnlySpan SDL_PRIu32 => new byte[] { 0x75, 0x00 }; + public static ReadOnlySpan SDL_PRIu32 => "u"u8; [NativeTypeName("#define SDL_PRIx32 \"x\"")] - public static ReadOnlySpan SDL_PRIx32 => new byte[] { 0x78, 0x00 }; + public static ReadOnlySpan SDL_PRIx32 => "x"u8; [NativeTypeName("#define SDL_PRIX32 \"X\"")] - public static ReadOnlySpan SDL_PRIX32 => new byte[] { 0x58, 0x00 }; + public static ReadOnlySpan SDL_PRIX32 => "X"u8; [NativeTypeName("#define M_PI 3.14159265358979323846264338327950288")] public const double M_PI = 3.14159265358979323846264338327950288; [NativeTypeName("#define SDL_ICONV_ERROR (size_t)-1")] - public static readonly UIntPtr SDL_ICONV_ERROR = unchecked((nuint)(-1)); + public static readonly nuint SDL_ICONV_ERROR = unchecked((nuint)(-1)); [NativeTypeName("#define SDL_ICONV_E2BIG (size_t)-2")] - public static readonly UIntPtr SDL_ICONV_E2BIG = unchecked((nuint)(-2)); + public static readonly nuint SDL_ICONV_E2BIG = unchecked((nuint)(-2)); [NativeTypeName("#define SDL_ICONV_EILSEQ (size_t)-3")] - public static readonly UIntPtr SDL_ICONV_EILSEQ = unchecked((nuint)(-3)); + public static readonly nuint SDL_ICONV_EILSEQ = unchecked((nuint)(-3)); [NativeTypeName("#define SDL_ICONV_EINVAL (size_t)-4")] - public static readonly UIntPtr SDL_ICONV_EINVAL = unchecked((nuint)(-4)); + public static readonly nuint SDL_ICONV_EINVAL = unchecked((nuint)(-4)); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_CreateRGBSurface", ExactSpelling = true)] public static extern SDL_Surface* CreateRGBSurface([NativeTypeName("Uint32")] uint flags, int width, int height, int depth, [NativeTypeName("Uint32")] uint Rmask, [NativeTypeName("Uint32")] uint Gmask, [NativeTypeName("Uint32")] uint Bmask, [NativeTypeName("Uint32")] uint Amask); @@ -2011,7 +2011,7 @@ public static unsafe partial class SDL public const int SDL_SIMD_ALIGNED = 0x00000008; [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_SetWindowsMessageHook", ExactSpelling = true)] - public static extern void SetWindowsMessageHook([NativeTypeName("SDL_WindowsMessageHook")] IntPtr callback, void* userdata); + public static extern void SetWindowsMessageHook([NativeTypeName("SDL_WindowsMessageHook")] delegate* unmanaged[Cdecl] callback, void* userdata); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_Direct3D9GetAdapterIndex", ExactSpelling = true)] public static extern int Direct3D9GetAdapterIndex(int displayIndex); @@ -2138,7 +2138,7 @@ public static unsafe partial class SDL public static extern int GetWindowDisplayMode(SDL_Window* window, SDL_DisplayMode* mode); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetWindowICCProfile", ExactSpelling = true)] - public static extern void* GetWindowICCProfile(SDL_Window* window, [NativeTypeName("size_t *")] UIntPtr* size); + public static extern void* GetWindowICCProfile(SDL_Window* window, [NativeTypeName("size_t *")] nuint* size); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetWindowPixelFormat", ExactSpelling = true)] [return: NativeTypeName("Uint32")] @@ -2305,7 +2305,7 @@ public static unsafe partial class SDL public static extern int GetWindowGammaRamp(SDL_Window* window, [NativeTypeName("Uint16 *")] ushort* red, [NativeTypeName("Uint16 *")] ushort* green, [NativeTypeName("Uint16 *")] ushort* blue); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_SetWindowHitTest", ExactSpelling = true)] - public static extern int SetWindowHitTest(SDL_Window* window, [NativeTypeName("SDL_HitTest")] IntPtr callback, void* callback_data); + public static extern int SetWindowHitTest(SDL_Window* window, [NativeTypeName("SDL_HitTest")] delegate* unmanaged[Cdecl] callback, void* callback_data); [DllImport("SDL2", CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_FlashWindow", ExactSpelling = true)] public static extern int FlashWindow(SDL_Window* window, SDL_FlashOperation operation); diff --git a/sources/SDL2Sharp.Interop/SDL_ArrayOrder.cs b/sources/SDL2Sharp.Interop/codegen/SDL_ArrayOrder.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_ArrayOrder.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_ArrayOrder.cs diff --git a/sources/SDL2Sharp.Interop/SDL_AudioCVT.cs b/sources/SDL2Sharp.Interop/codegen/SDL_AudioCVT.cs similarity index 64% rename from sources/SDL2Sharp.Interop/SDL_AudioCVT.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_AudioCVT.cs index 027f7f78..541c3ca4 100644 --- a/sources/SDL2Sharp.Interop/SDL_AudioCVT.cs +++ b/sources/SDL2Sharp.Interop/codegen/SDL_AudioCVT.cs @@ -18,7 +18,6 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using System; using System.Runtime.CompilerServices; namespace SDL2Sharp.Interop @@ -51,25 +50,25 @@ public unsafe partial struct SDL_AudioCVT public int filter_index; - public partial struct _filters_e__FixedBuffer + public unsafe partial struct _filters_e__FixedBuffer { - public IntPtr e0; - public IntPtr e1; - public IntPtr e2; - public IntPtr e3; - public IntPtr e4; - public IntPtr e5; - public IntPtr e6; - public IntPtr e7; - public IntPtr e8; - public IntPtr e9; + public delegate* unmanaged[Cdecl] e0; + public delegate* unmanaged[Cdecl] e1; + public delegate* unmanaged[Cdecl] e2; + public delegate* unmanaged[Cdecl] e3; + public delegate* unmanaged[Cdecl] e4; + public delegate* unmanaged[Cdecl] e5; + public delegate* unmanaged[Cdecl] e6; + public delegate* unmanaged[Cdecl] e7; + public delegate* unmanaged[Cdecl] e8; + public delegate* unmanaged[Cdecl] e9; - public unsafe ref IntPtr this[int index] + public ref delegate* unmanaged[Cdecl] this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - fixed (IntPtr* pThis = &e0) + fixed (delegate* unmanaged[Cdecl]* pThis = &e0) { return ref pThis[index]; } diff --git a/sources/SDL2Sharp.Interop/SDL_AudioDeviceEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_AudioDeviceEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_AudioDeviceEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_AudioDeviceEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_AudioSpec.cs b/sources/SDL2Sharp.Interop/codegen/SDL_AudioSpec.cs similarity index 95% rename from sources/SDL2Sharp.Interop/SDL_AudioSpec.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_AudioSpec.cs index fe0e438e..17080911 100644 --- a/sources/SDL2Sharp.Interop/SDL_AudioSpec.cs +++ b/sources/SDL2Sharp.Interop/codegen/SDL_AudioSpec.cs @@ -18,8 +18,6 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using System; - namespace SDL2Sharp.Interop { public unsafe partial struct SDL_AudioSpec @@ -45,7 +43,7 @@ public unsafe partial struct SDL_AudioSpec public uint size; [NativeTypeName("SDL_AudioCallback")] - public IntPtr callback; + public delegate* unmanaged[Cdecl] callback; public void* userdata; } diff --git a/sources/SDL2Sharp.Interop/SDL_AudioStatus.cs b/sources/SDL2Sharp.Interop/codegen/SDL_AudioStatus.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_AudioStatus.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_AudioStatus.cs diff --git a/sources/SDL2Sharp.Interop/SDL_BitmapOrder.cs b/sources/SDL2Sharp.Interop/codegen/SDL_BitmapOrder.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_BitmapOrder.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_BitmapOrder.cs diff --git a/sources/SDL2Sharp.Interop/SDL_BlendFactor.cs b/sources/SDL2Sharp.Interop/codegen/SDL_BlendFactor.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_BlendFactor.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_BlendFactor.cs diff --git a/sources/SDL2Sharp.Interop/SDL_BlendMode.cs b/sources/SDL2Sharp.Interop/codegen/SDL_BlendMode.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_BlendMode.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_BlendMode.cs diff --git a/sources/SDL2Sharp.Interop/SDL_BlendOperation.cs b/sources/SDL2Sharp.Interop/codegen/SDL_BlendOperation.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_BlendOperation.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_BlendOperation.cs diff --git a/sources/SDL2Sharp.Interop/SDL_BlitMap.cs b/sources/SDL2Sharp.Interop/codegen/SDL_BlitMap.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_BlitMap.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_BlitMap.cs diff --git a/sources/SDL2Sharp.Interop/SDL_Color.cs b/sources/SDL2Sharp.Interop/codegen/SDL_Color.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_Color.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_Color.cs diff --git a/sources/SDL2Sharp.Interop/SDL_CommonEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_CommonEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_CommonEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_CommonEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_ControllerAxisEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_ControllerAxisEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_ControllerAxisEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_ControllerAxisEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_ControllerButtonEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_ControllerButtonEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_ControllerButtonEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_ControllerButtonEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_ControllerDeviceEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_ControllerDeviceEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_ControllerDeviceEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_ControllerDeviceEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_ControllerSensorEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_ControllerSensorEvent.cs similarity index 83% rename from sources/SDL2Sharp.Interop/SDL_ControllerSensorEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_ControllerSensorEvent.cs index 2dfb1b42..56df83fc 100644 --- a/sources/SDL2Sharp.Interop/SDL_ControllerSensorEvent.cs +++ b/sources/SDL2Sharp.Interop/codegen/SDL_ControllerSensorEvent.cs @@ -18,9 +18,11 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +using System.Runtime.CompilerServices; + namespace SDL2Sharp.Interop { - public unsafe partial struct SDL_ControllerSensorEvent + public partial struct SDL_ControllerSensorEvent { [NativeTypeName("Uint32")] public uint type; @@ -35,9 +37,15 @@ public unsafe partial struct SDL_ControllerSensorEvent public int sensor; [NativeTypeName("float[3]")] - public fixed float data[3]; + public _data_e__FixedBuffer data; [NativeTypeName("Uint64")] public ulong timestamp_us; + + [InlineArray(3)] + public partial struct _data_e__FixedBuffer + { + public float e0; + } } } diff --git a/sources/SDL2Sharp.Interop/SDL_ControllerTouchpadEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_ControllerTouchpadEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_ControllerTouchpadEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_ControllerTouchpadEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_Cursor.cs b/sources/SDL2Sharp.Interop/codegen/SDL_Cursor.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_Cursor.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_Cursor.cs diff --git a/sources/SDL2Sharp.Interop/SDL_DUMMY_ENUM.cs b/sources/SDL2Sharp.Interop/codegen/SDL_DUMMY_ENUM.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_DUMMY_ENUM.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_DUMMY_ENUM.cs diff --git a/sources/SDL2Sharp.Interop/SDL_DisplayEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_DisplayEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_DisplayEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_DisplayEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_DisplayEventID.cs b/sources/SDL2Sharp.Interop/codegen/SDL_DisplayEventID.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_DisplayEventID.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_DisplayEventID.cs diff --git a/sources/SDL2Sharp.Interop/SDL_DisplayMode.cs b/sources/SDL2Sharp.Interop/codegen/SDL_DisplayMode.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_DisplayMode.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_DisplayMode.cs diff --git a/sources/SDL2Sharp.Interop/SDL_DisplayOrientation.cs b/sources/SDL2Sharp.Interop/codegen/SDL_DisplayOrientation.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_DisplayOrientation.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_DisplayOrientation.cs diff --git a/sources/SDL2Sharp.Interop/SDL_DollarGestureEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_DollarGestureEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_DollarGestureEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_DollarGestureEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_DropEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_DropEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_DropEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_DropEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_Event.cs b/sources/SDL2Sharp.Interop/codegen/SDL_Event.cs similarity index 92% rename from sources/SDL2Sharp.Interop/SDL_Event.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_Event.cs index 7db609df..31467af9 100644 --- a/sources/SDL2Sharp.Interop/SDL_Event.cs +++ b/sources/SDL2Sharp.Interop/codegen/SDL_Event.cs @@ -18,12 +18,13 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace SDL2Sharp.Interop { [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct SDL_Event + public partial struct SDL_Event { [FieldOffset(0)] [NativeTypeName("Uint32")] @@ -121,6 +122,12 @@ public unsafe partial struct SDL_Event [FieldOffset(0)] [NativeTypeName("Uint8[56]")] - public fixed byte padding[56]; + public _padding_e__FixedBuffer padding; + + [InlineArray(56)] + public partial struct _padding_e__FixedBuffer + { + public byte e0; + } } } diff --git a/sources/SDL2Sharp.Interop/SDL_EventType.cs b/sources/SDL2Sharp.Interop/codegen/SDL_EventType.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_EventType.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_EventType.cs diff --git a/sources/SDL2Sharp.Interop/SDL_FPoint.cs b/sources/SDL2Sharp.Interop/codegen/SDL_FPoint.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_FPoint.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_FPoint.cs diff --git a/sources/SDL2Sharp.Interop/SDL_FRect.cs b/sources/SDL2Sharp.Interop/codegen/SDL_FRect.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_FRect.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_FRect.cs diff --git a/sources/SDL2Sharp.Interop/SDL_FlashOperation.cs b/sources/SDL2Sharp.Interop/codegen/SDL_FlashOperation.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_FlashOperation.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_FlashOperation.cs diff --git a/sources/SDL2Sharp.Interop/SDL_GLContextResetNotification.cs b/sources/SDL2Sharp.Interop/codegen/SDL_GLContextResetNotification.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_GLContextResetNotification.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_GLContextResetNotification.cs diff --git a/sources/SDL2Sharp.Interop/SDL_GLattr.cs b/sources/SDL2Sharp.Interop/codegen/SDL_GLattr.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_GLattr.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_GLattr.cs diff --git a/sources/SDL2Sharp.Interop/SDL_GLcontextFlag.cs b/sources/SDL2Sharp.Interop/codegen/SDL_GLcontextFlag.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_GLcontextFlag.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_GLcontextFlag.cs diff --git a/sources/SDL2Sharp.Interop/SDL_GLcontextReleaseFlag.cs b/sources/SDL2Sharp.Interop/codegen/SDL_GLcontextReleaseFlag.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_GLcontextReleaseFlag.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_GLcontextReleaseFlag.cs diff --git a/sources/SDL2Sharp.Interop/SDL_GLprofile.cs b/sources/SDL2Sharp.Interop/codegen/SDL_GLprofile.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_GLprofile.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_GLprofile.cs diff --git a/sources/SDL2Sharp.Interop/SDL_GUID.cs b/sources/SDL2Sharp.Interop/codegen/SDL_GUID.cs similarity index 80% rename from sources/SDL2Sharp.Interop/SDL_GUID.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_GUID.cs index fb41ca1e..58ccdfac 100644 --- a/sources/SDL2Sharp.Interop/SDL_GUID.cs +++ b/sources/SDL2Sharp.Interop/codegen/SDL_GUID.cs @@ -18,11 +18,19 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +using System.Runtime.CompilerServices; + namespace SDL2Sharp.Interop { - public unsafe partial struct SDL_GUID + public partial struct SDL_GUID { [NativeTypeName("Uint8[16]")] - public fixed byte data[16]; + public _data_e__FixedBuffer data; + + [InlineArray(16)] + public partial struct _data_e__FixedBuffer + { + public byte e0; + } } } diff --git a/sources/SDL2Sharp.Interop/SDL_HintPriority.cs b/sources/SDL2Sharp.Interop/codegen/SDL_HintPriority.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_HintPriority.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_HintPriority.cs diff --git a/sources/SDL2Sharp.Interop/SDL_HitTestResult.cs b/sources/SDL2Sharp.Interop/codegen/SDL_HitTestResult.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_HitTestResult.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_HitTestResult.cs diff --git a/sources/SDL2Sharp.Interop/SDL_JoyAxisEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_JoyAxisEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_JoyAxisEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_JoyAxisEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_JoyBallEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_JoyBallEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_JoyBallEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_JoyBallEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_JoyBatteryEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_JoyBatteryEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_JoyBatteryEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_JoyBatteryEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_JoyButtonEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_JoyButtonEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_JoyButtonEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_JoyButtonEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_JoyDeviceEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_JoyDeviceEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_JoyDeviceEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_JoyDeviceEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_JoyHatEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_JoyHatEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_JoyHatEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_JoyHatEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_JoystickPowerLevel.cs b/sources/SDL2Sharp.Interop/codegen/SDL_JoystickPowerLevel.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_JoystickPowerLevel.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_JoystickPowerLevel.cs diff --git a/sources/SDL2Sharp.Interop/SDL_JoystickType.cs b/sources/SDL2Sharp.Interop/codegen/SDL_JoystickType.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_JoystickType.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_JoystickType.cs diff --git a/sources/SDL2Sharp.Interop/SDL_KeyCode.cs b/sources/SDL2Sharp.Interop/codegen/SDL_KeyCode.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_KeyCode.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_KeyCode.cs diff --git a/sources/SDL2Sharp.Interop/SDL_KeyboardEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_KeyboardEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_KeyboardEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_KeyboardEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_Keymod.cs b/sources/SDL2Sharp.Interop/codegen/SDL_Keymod.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_Keymod.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_Keymod.cs diff --git a/sources/SDL2Sharp.Interop/SDL_Keysym.cs b/sources/SDL2Sharp.Interop/codegen/SDL_Keysym.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_Keysym.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_Keysym.cs diff --git a/sources/SDL2Sharp.Interop/SDL_LogCategory.cs b/sources/SDL2Sharp.Interop/codegen/SDL_LogCategory.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_LogCategory.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_LogCategory.cs diff --git a/sources/SDL2Sharp.Interop/SDL_LogPriority.cs b/sources/SDL2Sharp.Interop/codegen/SDL_LogPriority.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_LogPriority.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_LogPriority.cs diff --git a/sources/SDL2Sharp.Interop/SDL_MouseButtonEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_MouseButtonEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_MouseButtonEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_MouseButtonEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_MouseMotionEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_MouseMotionEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_MouseMotionEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_MouseMotionEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_MouseWheelDirection.cs b/sources/SDL2Sharp.Interop/codegen/SDL_MouseWheelDirection.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_MouseWheelDirection.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_MouseWheelDirection.cs diff --git a/sources/SDL2Sharp.Interop/SDL_MouseWheelEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_MouseWheelEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_MouseWheelEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_MouseWheelEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_MultiGestureEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_MultiGestureEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_MultiGestureEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_MultiGestureEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_OSEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_OSEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_OSEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_OSEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_PackedLayout.cs b/sources/SDL2Sharp.Interop/codegen/SDL_PackedLayout.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_PackedLayout.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_PackedLayout.cs diff --git a/sources/SDL2Sharp.Interop/SDL_PackedOrder.cs b/sources/SDL2Sharp.Interop/codegen/SDL_PackedOrder.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_PackedOrder.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_PackedOrder.cs diff --git a/sources/SDL2Sharp.Interop/SDL_Palette.cs b/sources/SDL2Sharp.Interop/codegen/SDL_Palette.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_Palette.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_Palette.cs diff --git a/sources/SDL2Sharp.Interop/SDL_PixelFormat.cs b/sources/SDL2Sharp.Interop/codegen/SDL_PixelFormat.cs similarity index 91% rename from sources/SDL2Sharp.Interop/SDL_PixelFormat.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_PixelFormat.cs index fa3c1100..00c49e68 100644 --- a/sources/SDL2Sharp.Interop/SDL_PixelFormat.cs +++ b/sources/SDL2Sharp.Interop/codegen/SDL_PixelFormat.cs @@ -18,6 +18,8 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +using System.Runtime.CompilerServices; + namespace SDL2Sharp.Interop { public unsafe partial struct SDL_PixelFormat @@ -34,7 +36,7 @@ public unsafe partial struct SDL_PixelFormat public byte BytesPerPixel; [NativeTypeName("Uint8[2]")] - public fixed byte padding[2]; + public _padding_e__FixedBuffer padding; [NativeTypeName("Uint32")] public uint Rmask; @@ -76,5 +78,11 @@ public unsafe partial struct SDL_PixelFormat [NativeTypeName("struct SDL_PixelFormat *")] public SDL_PixelFormat* next; + + [InlineArray(2)] + public partial struct _padding_e__FixedBuffer + { + public byte e0; + } } } diff --git a/sources/SDL2Sharp.Interop/SDL_PixelFormatEnum.cs b/sources/SDL2Sharp.Interop/codegen/SDL_PixelFormatEnum.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_PixelFormatEnum.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_PixelFormatEnum.cs diff --git a/sources/SDL2Sharp.Interop/SDL_PixelType.cs b/sources/SDL2Sharp.Interop/codegen/SDL_PixelType.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_PixelType.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_PixelType.cs diff --git a/sources/SDL2Sharp.Interop/SDL_Point.cs b/sources/SDL2Sharp.Interop/codegen/SDL_Point.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_Point.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_Point.cs diff --git a/sources/SDL2Sharp.Interop/SDL_QuitEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_QuitEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_QuitEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_QuitEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_RWops.cs b/sources/SDL2Sharp.Interop/codegen/SDL_RWops.cs similarity index 86% rename from sources/SDL2Sharp.Interop/SDL_RWops.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_RWops.cs index 54b9583d..945a6527 100644 --- a/sources/SDL2Sharp.Interop/SDL_RWops.cs +++ b/sources/SDL2Sharp.Interop/codegen/SDL_RWops.cs @@ -18,27 +18,26 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using System; using System.Runtime.InteropServices; namespace SDL2Sharp.Interop { - public partial struct SDL_RWops + public unsafe partial struct SDL_RWops { [NativeTypeName("Sint64 (*)(struct SDL_RWops *) __attribute__((cdecl))")] - public IntPtr size; + public delegate* unmanaged[Cdecl] size; [NativeTypeName("Sint64 (*)(struct SDL_RWops *, Sint64, int) __attribute__((cdecl))")] - public IntPtr seek; + public delegate* unmanaged[Cdecl] seek; [NativeTypeName("size_t (*)(struct SDL_RWops *, void *, size_t, size_t) __attribute__((cdecl))")] - public IntPtr read; + public delegate* unmanaged[Cdecl] read; [NativeTypeName("size_t (*)(struct SDL_RWops *, const void *, size_t, size_t) __attribute__((cdecl))")] - public IntPtr write; + public delegate* unmanaged[Cdecl] write; [NativeTypeName("int (*)(struct SDL_RWops *) __attribute__((cdecl))")] - public IntPtr close; + public delegate* unmanaged[Cdecl] close; [NativeTypeName("Uint32")] public uint type; @@ -75,10 +74,10 @@ public unsafe partial struct _buffer_e__Struct public void* data; [NativeTypeName("size_t")] - public UIntPtr size; + public nuint size; [NativeTypeName("size_t")] - public UIntPtr left; + public nuint left; } } diff --git a/sources/SDL2Sharp.Interop/SDL_Rect.cs b/sources/SDL2Sharp.Interop/codegen/SDL_Rect.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_Rect.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_Rect.cs diff --git a/sources/SDL2Sharp.Interop/SDL_Renderer.cs b/sources/SDL2Sharp.Interop/codegen/SDL_Renderer.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_Renderer.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_Renderer.cs diff --git a/sources/SDL2Sharp.Interop/SDL_RendererFlags.cs b/sources/SDL2Sharp.Interop/codegen/SDL_RendererFlags.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_RendererFlags.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_RendererFlags.cs diff --git a/sources/SDL2Sharp.Interop/SDL_RendererFlip.cs b/sources/SDL2Sharp.Interop/codegen/SDL_RendererFlip.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_RendererFlip.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_RendererFlip.cs diff --git a/sources/SDL2Sharp.Interop/SDL_RendererInfo.cs b/sources/SDL2Sharp.Interop/codegen/SDL_RendererInfo.cs similarity index 85% rename from sources/SDL2Sharp.Interop/SDL_RendererInfo.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_RendererInfo.cs index c21a4ba1..0bd45762 100644 --- a/sources/SDL2Sharp.Interop/SDL_RendererInfo.cs +++ b/sources/SDL2Sharp.Interop/codegen/SDL_RendererInfo.cs @@ -18,6 +18,8 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +using System.Runtime.CompilerServices; + namespace SDL2Sharp.Interop { public unsafe partial struct SDL_RendererInfo @@ -32,10 +34,16 @@ public unsafe partial struct SDL_RendererInfo public uint num_texture_formats; [NativeTypeName("Uint32[16]")] - public fixed uint texture_formats[16]; + public _texture_formats_e__FixedBuffer texture_formats; public int max_texture_width; public int max_texture_height; + + [InlineArray(16)] + public partial struct _texture_formats_e__FixedBuffer + { + public uint e0; + } } } diff --git a/sources/SDL2Sharp.Interop/SDL_ScaleMode.cs b/sources/SDL2Sharp.Interop/codegen/SDL_ScaleMode.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_ScaleMode.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_ScaleMode.cs diff --git a/sources/SDL2Sharp.Interop/SDL_Scancode.cs b/sources/SDL2Sharp.Interop/codegen/SDL_Scancode.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_Scancode.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_Scancode.cs diff --git a/sources/SDL2Sharp.Interop/SDL_SensorEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_SensorEvent.cs similarity index 83% rename from sources/SDL2Sharp.Interop/SDL_SensorEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_SensorEvent.cs index ce329d9f..62e50ba4 100644 --- a/sources/SDL2Sharp.Interop/SDL_SensorEvent.cs +++ b/sources/SDL2Sharp.Interop/codegen/SDL_SensorEvent.cs @@ -18,9 +18,11 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +using System.Runtime.CompilerServices; + namespace SDL2Sharp.Interop { - public unsafe partial struct SDL_SensorEvent + public partial struct SDL_SensorEvent { [NativeTypeName("Uint32")] public uint type; @@ -32,9 +34,15 @@ public unsafe partial struct SDL_SensorEvent public int which; [NativeTypeName("float[6]")] - public fixed float data[6]; + public _data_e__FixedBuffer data; [NativeTypeName("Uint64")] public ulong timestamp_us; + + [InlineArray(6)] + public partial struct _data_e__FixedBuffer + { + public float e0; + } } } diff --git a/sources/SDL2Sharp.Interop/SDL_Surface.cs b/sources/SDL2Sharp.Interop/codegen/SDL_Surface.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_Surface.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_Surface.cs diff --git a/sources/SDL2Sharp.Interop/SDL_SysWMEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_SysWMEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_SysWMEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_SysWMEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_SysWMmsg.cs b/sources/SDL2Sharp.Interop/codegen/SDL_SysWMmsg.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_SysWMmsg.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_SysWMmsg.cs diff --git a/sources/SDL2Sharp.Interop/SDL_SystemCursor.cs b/sources/SDL2Sharp.Interop/codegen/SDL_SystemCursor.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_SystemCursor.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_SystemCursor.cs diff --git a/sources/SDL2Sharp.Interop/SDL_TextEditingEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_TextEditingEvent.cs similarity index 84% rename from sources/SDL2Sharp.Interop/SDL_TextEditingEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_TextEditingEvent.cs index 40f05865..2265bade 100644 --- a/sources/SDL2Sharp.Interop/SDL_TextEditingEvent.cs +++ b/sources/SDL2Sharp.Interop/codegen/SDL_TextEditingEvent.cs @@ -18,9 +18,11 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +using System.Runtime.CompilerServices; + namespace SDL2Sharp.Interop { - public unsafe partial struct SDL_TextEditingEvent + public partial struct SDL_TextEditingEvent { [NativeTypeName("Uint32")] public uint type; @@ -32,12 +34,18 @@ public unsafe partial struct SDL_TextEditingEvent public uint windowID; [NativeTypeName("char[32]")] - public fixed sbyte text[32]; + public _text_e__FixedBuffer text; [NativeTypeName("Sint32")] public int start; [NativeTypeName("Sint32")] public int length; + + [InlineArray(32)] + public partial struct _text_e__FixedBuffer + { + public sbyte e0; + } } } diff --git a/sources/SDL2Sharp.Interop/SDL_TextEditingExtEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_TextEditingExtEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_TextEditingExtEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_TextEditingExtEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_TextInputEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_TextInputEvent.cs similarity index 82% rename from sources/SDL2Sharp.Interop/SDL_TextInputEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_TextInputEvent.cs index 285e9416..f5f9bb1f 100644 --- a/sources/SDL2Sharp.Interop/SDL_TextInputEvent.cs +++ b/sources/SDL2Sharp.Interop/codegen/SDL_TextInputEvent.cs @@ -18,9 +18,11 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +using System.Runtime.CompilerServices; + namespace SDL2Sharp.Interop { - public unsafe partial struct SDL_TextInputEvent + public partial struct SDL_TextInputEvent { [NativeTypeName("Uint32")] public uint type; @@ -32,6 +34,12 @@ public unsafe partial struct SDL_TextInputEvent public uint windowID; [NativeTypeName("char[32]")] - public fixed sbyte text[32]; + public _text_e__FixedBuffer text; + + [InlineArray(32)] + public partial struct _text_e__FixedBuffer + { + public sbyte e0; + } } } diff --git a/sources/SDL2Sharp.Interop/SDL_Texture.cs b/sources/SDL2Sharp.Interop/codegen/SDL_Texture.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_Texture.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_Texture.cs diff --git a/sources/SDL2Sharp.Interop/SDL_TextureAccess.cs b/sources/SDL2Sharp.Interop/codegen/SDL_TextureAccess.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_TextureAccess.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_TextureAccess.cs diff --git a/sources/SDL2Sharp.Interop/SDL_TextureModulate.cs b/sources/SDL2Sharp.Interop/codegen/SDL_TextureModulate.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_TextureModulate.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_TextureModulate.cs diff --git a/sources/SDL2Sharp.Interop/SDL_TouchFingerEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_TouchFingerEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_TouchFingerEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_TouchFingerEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_UserEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_UserEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_UserEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_UserEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_Vertex.cs b/sources/SDL2Sharp.Interop/codegen/SDL_Vertex.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_Vertex.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_Vertex.cs diff --git a/sources/SDL2Sharp.Interop/SDL_VirtualJoystickDesc.cs b/sources/SDL2Sharp.Interop/codegen/SDL_VirtualJoystickDesc.cs similarity index 83% rename from sources/SDL2Sharp.Interop/SDL_VirtualJoystickDesc.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_VirtualJoystickDesc.cs index 34a9ad27..4a75f501 100644 --- a/sources/SDL2Sharp.Interop/SDL_VirtualJoystickDesc.cs +++ b/sources/SDL2Sharp.Interop/codegen/SDL_VirtualJoystickDesc.cs @@ -18,8 +18,6 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using System; - namespace SDL2Sharp.Interop { public unsafe partial struct SDL_VirtualJoystickDesc @@ -60,21 +58,21 @@ public unsafe partial struct SDL_VirtualJoystickDesc public void* userdata; [NativeTypeName("void (*)(void *) __attribute__((cdecl))")] - public IntPtr Update; + public delegate* unmanaged[Cdecl] Update; [NativeTypeName("void (*)(void *, int) __attribute__((cdecl))")] - public IntPtr SetPlayerIndex; + public delegate* unmanaged[Cdecl] SetPlayerIndex; [NativeTypeName("int (*)(void *, Uint16, Uint16) __attribute__((cdecl))")] - public IntPtr Rumble; + public delegate* unmanaged[Cdecl] Rumble; [NativeTypeName("int (*)(void *, Uint16, Uint16) __attribute__((cdecl))")] - public IntPtr RumbleTriggers; + public delegate* unmanaged[Cdecl] RumbleTriggers; [NativeTypeName("int (*)(void *, Uint8, Uint8, Uint8) __attribute__((cdecl))")] - public IntPtr SetLED; + public delegate* unmanaged[Cdecl] SetLED; [NativeTypeName("int (*)(void *, const void *, int) __attribute__((cdecl))")] - public IntPtr SendEffect; + public delegate* unmanaged[Cdecl] SendEffect; } } diff --git a/sources/SDL2Sharp.Interop/SDL_Window.cs b/sources/SDL2Sharp.Interop/codegen/SDL_Window.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_Window.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_Window.cs diff --git a/sources/SDL2Sharp.Interop/SDL_WindowEvent.cs b/sources/SDL2Sharp.Interop/codegen/SDL_WindowEvent.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_WindowEvent.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_WindowEvent.cs diff --git a/sources/SDL2Sharp.Interop/SDL_WindowEventID.cs b/sources/SDL2Sharp.Interop/codegen/SDL_WindowEventID.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_WindowEventID.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_WindowEventID.cs diff --git a/sources/SDL2Sharp.Interop/SDL_WindowFlags.cs b/sources/SDL2Sharp.Interop/codegen/SDL_WindowFlags.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_WindowFlags.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_WindowFlags.cs diff --git a/sources/SDL2Sharp.Interop/SDL_YUV_CONVERSION_MODE.cs b/sources/SDL2Sharp.Interop/codegen/SDL_YUV_CONVERSION_MODE.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_YUV_CONVERSION_MODE.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_YUV_CONVERSION_MODE.cs diff --git a/sources/SDL2Sharp.Interop/SDL_bool.cs b/sources/SDL2Sharp.Interop/codegen/SDL_bool.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_bool.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_bool.cs diff --git a/sources/SDL2Sharp.Interop/SDL_errorcode.cs b/sources/SDL2Sharp.Interop/codegen/SDL_errorcode.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_errorcode.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_errorcode.cs diff --git a/sources/SDL2Sharp.Interop/SDL_eventaction.cs b/sources/SDL2Sharp.Interop/codegen/SDL_eventaction.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_eventaction.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_eventaction.cs diff --git a/sources/SDL2Sharp.Interop/SDL_version.cs b/sources/SDL2Sharp.Interop/codegen/SDL_version.cs similarity index 100% rename from sources/SDL2Sharp.Interop/SDL_version.cs rename to sources/SDL2Sharp.Interop/codegen/SDL_version.cs diff --git a/sources/SDL2Sharp.Interop/TTF.cs b/sources/SDL2Sharp.Interop/codegen/TTF.cs similarity index 100% rename from sources/SDL2Sharp.Interop/TTF.cs rename to sources/SDL2Sharp.Interop/codegen/TTF.cs diff --git a/sources/SDL2Sharp.Interop/TTF_Direction.cs b/sources/SDL2Sharp.Interop/codegen/TTF_Direction.cs similarity index 100% rename from sources/SDL2Sharp.Interop/TTF_Direction.cs rename to sources/SDL2Sharp.Interop/codegen/TTF_Direction.cs diff --git a/sources/SDL2Sharp.Interop/_SDL_AudioStream.cs b/sources/SDL2Sharp.Interop/codegen/_SDL_AudioStream.cs similarity index 100% rename from sources/SDL2Sharp.Interop/_SDL_AudioStream.cs rename to sources/SDL2Sharp.Interop/codegen/_SDL_AudioStream.cs diff --git a/sources/SDL2Sharp.Interop/_SDL_Joystick.cs b/sources/SDL2Sharp.Interop/codegen/_SDL_Joystick.cs similarity index 100% rename from sources/SDL2Sharp.Interop/_SDL_Joystick.cs rename to sources/SDL2Sharp.Interop/codegen/_SDL_Joystick.cs diff --git a/sources/SDL2Sharp.Interop/_SDL_iconv_t.cs b/sources/SDL2Sharp.Interop/codegen/_SDL_iconv_t.cs similarity index 100% rename from sources/SDL2Sharp.Interop/_SDL_iconv_t.cs rename to sources/SDL2Sharp.Interop/codegen/_SDL_iconv_t.cs diff --git a/sources/SDL2Sharp.Interop/_TTF_Font.cs b/sources/SDL2Sharp.Interop/codegen/_TTF_Font.cs similarity index 100% rename from sources/SDL2Sharp.Interop/_TTF_Font.cs rename to sources/SDL2Sharp.Interop/codegen/_TTF_Font.cs diff --git a/sources/SDL2Sharp.Interop/Extensions/IMG.Error.cs b/sources/SDL2Sharp.Interop/extensions/IMG.Error.cs similarity index 96% rename from sources/SDL2Sharp.Interop/Extensions/IMG.Error.cs rename to sources/SDL2Sharp.Interop/extensions/IMG.Error.cs index 5130ec35..54f08b5b 100644 --- a/sources/SDL2Sharp.Interop/Extensions/IMG.Error.cs +++ b/sources/SDL2Sharp.Interop/extensions/IMG.Error.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // @@ -22,10 +22,12 @@ namespace SDL2Sharp.Interop { public static unsafe partial class IMG { +#if NET8_0_OR_GREATER [NativeTypeName("#define IMG_SetError SDL_SetError")] public static int SetError(sbyte* fmt) => SDL.SetError(fmt, __arglist()); [NativeTypeName("#define IMG_GetError SDL_GetError")] public static sbyte* GetError() => SDL.GetError(); +#endif } } diff --git a/sources/SDL2Sharp.Interop/Extensions/SDL.Blit.cs b/sources/SDL2Sharp.Interop/extensions/SDL.Blit.cs similarity index 97% rename from sources/SDL2Sharp.Interop/Extensions/SDL.Blit.cs rename to sources/SDL2Sharp.Interop/extensions/SDL.Blit.cs index db157c13..3b922079 100644 --- a/sources/SDL2Sharp.Interop/Extensions/SDL.Blit.cs +++ b/sources/SDL2Sharp.Interop/extensions/SDL.Blit.cs @@ -22,6 +22,8 @@ namespace SDL2Sharp.Interop { public static unsafe partial class SDL { +#if NET8_0_OR_GREATER public static readonly delegate* Blit = &UpperBlit; +#endif } } diff --git a/sources/SDL2Sharp.Interop/Extensions/SDL.BlitScaled.cs b/sources/SDL2Sharp.Interop/extensions/SDL.BlitScaled.cs similarity index 97% rename from sources/SDL2Sharp.Interop/Extensions/SDL.BlitScaled.cs rename to sources/SDL2Sharp.Interop/extensions/SDL.BlitScaled.cs index 10cd4062..5410632b 100644 --- a/sources/SDL2Sharp.Interop/Extensions/SDL.BlitScaled.cs +++ b/sources/SDL2Sharp.Interop/extensions/SDL.BlitScaled.cs @@ -22,7 +22,9 @@ namespace SDL2Sharp.Interop { public static unsafe partial class SDL { +#if NET8_0_OR_GREATER [NativeTypeName("#define SDL_BlitScaled SDL_UpperBlitScaled")] public static readonly delegate* BlitScaled = &UpperBlitScaled; +#endif } } diff --git a/sources/SDL2Sharp.Interop/Extensions/SDL.BlitSurface.cs b/sources/SDL2Sharp.Interop/extensions/SDL.BlitSurface.cs similarity index 97% rename from sources/SDL2Sharp.Interop/Extensions/SDL.BlitSurface.cs rename to sources/SDL2Sharp.Interop/extensions/SDL.BlitSurface.cs index 60767285..673e5c70 100644 --- a/sources/SDL2Sharp.Interop/Extensions/SDL.BlitSurface.cs +++ b/sources/SDL2Sharp.Interop/extensions/SDL.BlitSurface.cs @@ -22,7 +22,9 @@ namespace SDL2Sharp.Interop { public static unsafe partial class SDL { +#if NET8_0_OR_GREATER [NativeTypeName("#define SDL_BlitSurface SDL_UpperBlit")] public static readonly delegate* BlitSurface = &UpperBlit; +#endif } } diff --git a/sources/SDL2Sharp.Interop/Extensions/TTF.Error.cs b/sources/SDL2Sharp.Interop/extensions/TTF.Error.cs similarity index 96% rename from sources/SDL2Sharp.Interop/Extensions/TTF.Error.cs rename to sources/SDL2Sharp.Interop/extensions/TTF.Error.cs index 6bc77fc3..eac64778 100644 --- a/sources/SDL2Sharp.Interop/Extensions/TTF.Error.cs +++ b/sources/SDL2Sharp.Interop/extensions/TTF.Error.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // @@ -22,10 +22,12 @@ namespace SDL2Sharp.Interop { public static unsafe partial class TTF { +#if NET8_0_OR_GREATER [NativeTypeName("#define IMG_SetError SDL_SetError")] public static int SetError(sbyte* fmt) => SDL.SetError(fmt, __arglist()); [NativeTypeName("#define IMG_GetError SDL_GetError")] public static sbyte* GetError() => SDL.GetError(); +#endif } } diff --git a/sources/SDL2Sharp.Interop/Internals/NativeTypeNameAttribute.cs b/sources/SDL2Sharp.Interop/internals/NativeTypeNameAttribute.cs similarity index 100% rename from sources/SDL2Sharp.Interop/Internals/NativeTypeNameAttribute.cs rename to sources/SDL2Sharp.Interop/internals/NativeTypeNameAttribute.cs diff --git a/sources/SDL2Sharp/Application.cs b/sources/SDL2Sharp/Application.cs deleted file mode 100644 index b09bbbb6..00000000 --- a/sources/SDL2Sharp/Application.cs +++ /dev/null @@ -1,213 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Linq; -using System.Runtime.InteropServices; -using SDL2Sharp.Interop; - -namespace SDL2Sharp -{ - public abstract unsafe class Application - { - private static Application s_instance = null!; - - public static Application Instance - { - get - { - return s_instance; - } - private set - { - if (s_instance != null) - { - throw new InvalidOperationException(); - } - - s_instance = value; - } - } - - protected string[] CommandLineArgs { get; private set; } - - protected Subsystems Subsystems { get; set; } - - protected int ExitCode { get; set; } - - protected Application() - { - Instance = this; - CommandLineArgs = Array.Empty(); - Subsystems = Subsystems.All; - ExitCode = 0; - } - - public int Run() - { - return Run(Environment.GetCommandLineArgs()); - } - - public int Run(string[] commandLineArgs) - { - CommandLineArgs = commandLineArgs; - var @event = new SDL_Event(); - var eventFilterCallback = new EventFilterCallbackDelegate(OnEventFilterCallback); - - try - { - OnInitializing(); - Error.ThrowOnFailure(SDL.Init((uint)Subsystems)); - Error.ThrowOnFailure(TTF.Init()); - var eventFilterCallbackPointer = Marshal.GetFunctionPointerForDelegate(eventFilterCallback); - SDL.SetEventFilter(eventFilterCallbackPointer, null); - OnInitialized(); - - while (true) - { - while (0 != SDL.PollEvent(&@event)) - { - var eventType = (SDL_EventType)@event.type; - switch (eventType) - { - case SDL_EventType.SDL_QUIT: - return ExitCode; - - case SDL_EventType.SDL_KEYUP: - DispatchKeyUpEvent(@event.key); - break; - - case SDL_EventType.SDL_KEYDOWN: - DispatchKeyDownEvent(@event.key); - break; - - case SDL_EventType.SDL_MOUSEMOTION: - DispatchMouseMotionEvent(@event.motion); - break; - - case SDL_EventType.SDL_MOUSEWHEEL: - DispatchMouseWheelEvent(@event.wheel); - break; - - case SDL_EventType.SDL_WINDOWEVENT: - DispatchWindowEvent(@event.window); - break; - } - } - - OnIdle(); - } - } - finally - { - SDL.SetEventFilter(IntPtr.Zero, null); - GC.KeepAlive(eventFilterCallback); - GC.KeepAlive(@event); - - OnQuiting(); - TTF.Quit(); - SDL.Quit(); - OnQuited(); - } - } - - public void Quit() - { - Quit(0); - } - - public void Quit(int exitCode) - { - ExitCode = exitCode; - var @event = new SDL_Event { type = (uint)SDL_EventType.SDL_QUIT }; - Error.ThrowOnFailure(SDL.PushEvent(&@event)); - } - - protected virtual void OnInitializing() { } - - protected virtual void OnInitialized() { } - - protected virtual void OnQuiting() { } - - protected virtual void OnQuited() { } - - protected virtual void OnIdle() { } - - private static void DispatchKeyDownEvent(SDL_KeyboardEvent @event) - { - var window = Window.All.FirstOrDefault(w => w.Id == @event.windowID); - if (window is not null) - { - window.HandleKeyDownEvent(@event); - } - } - - private static void DispatchKeyUpEvent(SDL_KeyboardEvent @event) - { - var window = Window.All.FirstOrDefault(w => w.Id == @event.windowID); - if (window is not null) - { - window.HandleKeyUpEvent(@event); - } - } - - private static void DispatchMouseMotionEvent(SDL_MouseMotionEvent @event) - { - var window = Window.All.FirstOrDefault(w => w.Id == @event.windowID); - if (window is not null) - { - window.HandleMouseMotionEvent(@event); - } - } - - private static void DispatchMouseWheelEvent(SDL_MouseWheelEvent @event) - { - var window = Window.All.FirstOrDefault(w => w.Id == @event.windowID); - if (window is not null) - { - window.HandleMouseWheelEvent(@event); - } - } - - private static void DispatchWindowEvent(SDL_WindowEvent @event) - { - var window = Window.All.FirstOrDefault(w => w.Id == @event.windowID); - if (window is not null) - { - window.HandleWindowEvent(@event); - } - } - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int EventFilterCallbackDelegate(void* userdata, SDL_Event* @event); - - private static int OnEventFilterCallback(void* userdata, SDL_Event* @event) - { - var eventType = (SDL_EventType)@event->type; - switch (eventType) - { - case SDL_EventType.SDL_WINDOWEVENT: - DispatchWindowEvent(@event->window); - return 0; - } - return 1; - } - } -} diff --git a/sources/SDL2Sharp/AudioDevice.cs b/sources/SDL2Sharp/AudioDevice.cs deleted file mode 100644 index cd4b13f9..00000000 --- a/sources/SDL2Sharp/AudioDevice.cs +++ /dev/null @@ -1,292 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Runtime.InteropServices; -using SDL2Sharp.Interop; - -namespace SDL2Sharp -{ - public sealed unsafe class AudioDevice : IDisposable - { - private uint _deviceID = 0; - - private AudioDeviceCallback _callback = null!; - - private AudioDeviceCallbackDelegate _unmanagedCallback = null!; - - private SDL_AudioSpec _obtainedSpec; - - private object _userdata = null!; - - private GCHandle _unmanagedUserdata = default; - - private bool _disposed = false; - - public bool IsDisposed => _disposed; - - public bool IsOpen => _deviceID != 0; - - public AudioDeviceSpec ObtainedSpec - { - get - { - ThrowIfDisposed(); - ThrowIfClosed(); - return new AudioDeviceSpec(_obtainedSpec); - } - } - - public AudioDevice() - : this(null!) - { } - - public AudioDevice(AudioDeviceSpec spec) - : this(spec, null!) - { } - - public AudioDevice(AudioDeviceSpec spec, AudioDeviceCallback callback) - : this(spec, callback, null!) - { } - - public AudioDevice(AudioDeviceSpec spec, AudioDeviceCallback callback, object userdata) - { - Open(spec, callback, userdata); - } - - public AudioDevice(AudioDeviceSpec spec, AudioDeviceCallback callback, object userdata, AudioDeviceAllowedChanges allowedChanges) - { - Open(spec, callback, userdata, allowedChanges); - } - - ~AudioDevice() - { - Dispose(false); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool _) - { - if (!_disposed) - { - try - { - Close(); - } - finally - { - _disposed = true; - } - } - } - - public void Open(AudioDeviceSpec spec) - { - if (!TryOpen(spec, null!, null!, out var error)) - { - throw error; - } - } - - public void Open(AudioDeviceSpec spec, AudioDeviceCallback callback) - { - if (!TryOpen(spec, callback, null!, out var error)) - { - throw error; - } - } - - public void Open(AudioDeviceSpec spec, AudioDeviceCallback callback, object userdata) - { - if (!TryOpen(spec, callback, userdata, out var error)) - { - throw error; - } - } - - public void Open(AudioDeviceSpec spec, AudioDeviceCallback callback, object userdata, AudioDeviceAllowedChanges allowedChanges) - { - if (!TryOpen(spec, callback, userdata, allowedChanges, out var error)) - { - throw error; - } - } - - public bool TryOpen(AudioDeviceSpec spec, out Error error) - { - return TryOpen(spec, null!, null!, out error); - } - - public bool TryOpen(AudioDeviceSpec spec, AudioDeviceCallback callback, out Error error) - { - return TryOpen(spec, callback, null!, out error); - } - - public bool TryOpen(AudioDeviceSpec spec, AudioDeviceCallback callback, object userdata, out Error error) - { - return TryOpen(spec, callback, userdata, AudioDeviceAllowedChanges.None, out error); - } - - public bool TryOpen(AudioDeviceSpec spec, AudioDeviceCallback callback, object userdata, AudioDeviceAllowedChanges allowedChanges, out Error error) - { - ThrowIfDisposed(); - ThrowIfOpen(); - - var desiredSpec = new SDL_AudioSpec - { - freq = spec.Frequency, - format = (ushort)spec.Format, - channels = (byte)spec.Channels, - silence = 0, - samples = 0, - padding = 0, - size = spec.Size - }; - - if (callback != null) - { - _callback = callback; - _userdata = userdata; - _unmanagedUserdata = GCHandle.Alloc(this, GCHandleType.Normal); - _unmanagedCallback = new AudioDeviceCallbackDelegate(OnAudioDeviceCallback); - - desiredSpec.callback = Marshal.GetFunctionPointerForDelegate(_unmanagedCallback); - desiredSpec.userdata = (void*)(IntPtr)_unmanagedUserdata; - } - - fixed (SDL_AudioSpec* obtainedSpec = &_obtainedSpec) - { - _deviceID = SDL.OpenAudioDevice(null, 0, &desiredSpec, obtainedSpec, (int)allowedChanges); - - if (_deviceID == 0) - { - error = new Error(new string(SDL.GetError())); - return false; - } - else - { - error = null!; - return true; - } - } - } - - public void Close() - { - ThrowIfDisposed(); - - if (_deviceID != 0) - { - SDL.CloseAudioDevice(_deviceID); - - _deviceID = 0; - _callback = null!; - _userdata = null!; - _unmanagedCallback = null!; - - if (_unmanagedUserdata.IsAllocated) - { - _unmanagedUserdata.Free(); - } - } - } - - public void Pause() - { - ThrowIfDisposed(); - ThrowIfClosed(); - SDL.PauseAudioDevice(_deviceID, 1); - } - - public void Unpause() - { - ThrowIfDisposed(); - ThrowIfClosed(); - SDL.PauseAudioDevice(_deviceID, 0); - } - - public void Lock() - { - ThrowIfDisposed(); - ThrowIfClosed(); - SDL.LockAudioDevice(_deviceID); - } - - public void Unlock() - { - ThrowIfDisposed(); - ThrowIfClosed(); - SDL.UnlockAudioDevice(_deviceID); - } - - public void Queue(Span buffer) - { - ThrowIfDisposed(); - ThrowIfClosed(); - fixed (void* data = &buffer[0]) - { - Error.ThrowOnFailure( - SDL.QueueAudio(_deviceID, data, (uint)buffer.Length) - ); - } - } - - private void ThrowIfOpen() - { - if (IsOpen) - { - throw new InvalidOperationException("The Audio Device is open"); - } - } - - private void ThrowIfClosed() - { - if (!IsOpen) - { - throw new InvalidOperationException("The Audio Device is closed"); - } - } - - private void ThrowIfDisposed() - { - if (IsDisposed) - { - throw new ObjectDisposedException(GetType().FullName); - } - } - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void AudioDeviceCallbackDelegate(void* userdata, byte* stream, int len); - - private static void OnAudioDeviceCallback(void* userdata, byte* stream, int len) - { - var audioDeviceHandle = GCHandle.FromIntPtr((IntPtr)userdata); - if (audioDeviceHandle.Target is AudioDevice audioDevice) - { - audioDevice._callback(audioDevice._userdata, new Span(stream, len)); - } - } - } -} diff --git a/sources/SDL2Sharp/Colors/Bgr565.cs b/sources/SDL2Sharp/Colors/Bgr565.cs deleted file mode 100644 index 34094998..00000000 --- a/sources/SDL2Sharp/Colors/Bgr565.cs +++ /dev/null @@ -1,43 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; -using SDL2Sharp.Internals; - -namespace SDL2Sharp.Colors -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 1)] - [PackedColor(PixelFormatEnum.BGR565)] - public readonly record struct Bgr565 - { - private readonly ushort _value; - - public byte B => (byte)(_value >> 11 & 0x1F); - - public byte G => (byte)(_value >> 5 & 0x3F); - - public byte R => (byte)(_value & 0x1F); - - public Bgr565(byte b, byte g, byte r) - { - _value = (ushort)((b & 0x1F) << 11 | (g & 0x3F) << 5 | r & 0x1F); - } - } -} diff --git a/sources/SDL2Sharp/Colors/Bgra4444.cs b/sources/SDL2Sharp/Colors/Bgra4444.cs deleted file mode 100644 index 376827b5..00000000 --- a/sources/SDL2Sharp/Colors/Bgra4444.cs +++ /dev/null @@ -1,45 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; -using SDL2Sharp.Internals; - -namespace SDL2Sharp.Colors -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 2)] - [PackedColor(PixelFormatEnum.BGRA4444)] - public readonly record struct Bgra4444 - { - private readonly ushort _value; - - public byte B => (byte)(_value >> 12 & 0xF); - - public byte G => (byte)(_value >> 8 & 0xF); - - public byte R => (byte)(_value >> 4 & 0xF); - - public byte A => (byte)(_value & 0xFF); - - public Bgra4444(byte b, byte g, byte r, byte a) - { - _value = (ushort)((b & 0xF) << 12 | (g & 0xF) << 8 | (r & 0xF) << 4 | a & 0xF); - } - } -} diff --git a/sources/SDL2Sharp/Colors/Bgra5551.cs b/sources/SDL2Sharp/Colors/Bgra5551.cs deleted file mode 100644 index c178277d..00000000 --- a/sources/SDL2Sharp/Colors/Bgra5551.cs +++ /dev/null @@ -1,45 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; -using SDL2Sharp.Internals; - -namespace SDL2Sharp.Colors -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 1)] - [PackedColor(PixelFormatEnum.BGRA5551)] - public readonly record struct Bgra5551 - { - private readonly ushort _value; - - public byte B => (byte)(_value >> 10 & 0x1F); - - public byte G => (byte)(_value >> 5 & 0x1F); - - public byte R => (byte)(_value >> 1 & 0x1F); - - public byte A => (byte)(_value & 0x1); - - public Bgra5551(byte b, byte g, byte r, byte a) - { - _value = (ushort)((b & 0x1F) << 11 | (g & 0x1F) << 6 | (r & 0x1F) << 1 | a & 0x1); - } - } -} diff --git a/sources/SDL2Sharp/Colors/Rgb565.cs b/sources/SDL2Sharp/Colors/Rgb565.cs deleted file mode 100644 index fd9869f0..00000000 --- a/sources/SDL2Sharp/Colors/Rgb565.cs +++ /dev/null @@ -1,43 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; -using SDL2Sharp.Internals; - -namespace SDL2Sharp.Colors -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 1)] - [PackedColor(PixelFormatEnum.RGB565)] - public readonly record struct Rgb565 - { - private readonly ushort _value; - - public byte R => (byte)(_value >> 11 & 0x1F); - - public byte G => (byte)(_value >> 5 & 0x3F); - - public byte B => (byte)(_value & 0x1F); - - public Rgb565(byte r, byte g, byte b) - { - _value = (ushort)((r & 0x1F) << 11 | (g & 0x3F) << 5 | b & 0x1F); - } - } -} diff --git a/sources/SDL2Sharp/Colors/Rgba4444.cs b/sources/SDL2Sharp/Colors/Rgba4444.cs deleted file mode 100644 index a8871981..00000000 --- a/sources/SDL2Sharp/Colors/Rgba4444.cs +++ /dev/null @@ -1,45 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; -using SDL2Sharp.Internals; - -namespace SDL2Sharp.Colors -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 2)] - [PackedColor(PixelFormatEnum.RGBA4444)] - public readonly record struct Rgba4444 - { - private readonly ushort _value; - - public byte R => (byte)(_value >> 12 & 0xF); - - public byte G => (byte)(_value >> 8 & 0xF); - - public byte B => (byte)(_value >> 4 & 0xF); - - public byte A => (byte)(_value & 0xFF); - - public Rgba4444(byte r, byte g, byte b, byte a) - { - _value = (ushort)((r & 0xF) << 12 | (g & 0xF) << 8 | (b & 0xF) << 4 | a & 0xF); - } - } -} diff --git a/sources/SDL2Sharp/Colors/Rgba5551.cs b/sources/SDL2Sharp/Colors/Rgba5551.cs deleted file mode 100644 index 42c2bdb7..00000000 --- a/sources/SDL2Sharp/Colors/Rgba5551.cs +++ /dev/null @@ -1,45 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; -using SDL2Sharp.Internals; - -namespace SDL2Sharp.Colors -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 1)] - [PackedColor(PixelFormatEnum.RGBA5551)] - public readonly record struct Rgba5551 - { - private readonly ushort _value; - - public byte R => (byte)(_value >> 10 & 0x1F); - - public byte G => (byte)(_value >> 5 & 0x1F); - - public byte B => (byte)(_value >> 1 & 0x1F); - - public byte A => (byte)(_value & 0x1); - - public Rgba5551(byte r, byte g, byte b, byte a) - { - _value = (ushort)((r & 0x1F) << 11 | (g & 0x1F) << 6 | (b & 0x1F) << 1 | a & 0x1); - } - } -} diff --git a/sources/SDL2Sharp/Colors/Rgba8888.cs b/sources/SDL2Sharp/Colors/Rgba8888.cs deleted file mode 100644 index 2cd96553..00000000 --- a/sources/SDL2Sharp/Colors/Rgba8888.cs +++ /dev/null @@ -1,48 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; -using SDL2Sharp.Internals; - -namespace SDL2Sharp.Colors -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 4)] - [PackedColor(PixelFormatEnum.RGBA8888)] - public readonly record struct Rgba8888 - { - private readonly uint _value; - - public byte R => (byte)(_value >> 24 & 0xFF); - - public byte G => (byte)(_value >> 16 & 0xFF); - - public byte B => (byte)(_value >> 8 & 0xFF); - - public byte A => (byte)(_value & 0xFF); - - public Rgba8888(byte r, byte g, byte b, byte a) - { - unchecked - { - _value = (uint)(r << 24 | g << 16 | b << 8 | a); - } - } - } -} diff --git a/sources/SDL2Sharp/Colors/Xbgr1555.cs b/sources/SDL2Sharp/Colors/Xbgr1555.cs deleted file mode 100644 index 14e98890..00000000 --- a/sources/SDL2Sharp/Colors/Xbgr1555.cs +++ /dev/null @@ -1,43 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; -using SDL2Sharp.Internals; - -namespace SDL2Sharp.Colors -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 1)] - [PackedColor(PixelFormatEnum.XBGR1555)] - public readonly record struct Xbgr1555 - { - private readonly ushort _value; - - public byte B => (byte)(_value >> 10 & 0x1F); - - public byte G => (byte)(_value >> 5 & 0x1F); - - public byte R => (byte)(_value & 0x1F); - - public Xbgr1555(byte b, byte g, byte r) - { - _value = (ushort)((b & 0x1F) << 10 | (g & 0x1F) << 5 | r & 0x1F); - } - } -} diff --git a/sources/SDL2Sharp/Colors/Xbgr4444.cs b/sources/SDL2Sharp/Colors/Xbgr4444.cs deleted file mode 100644 index f71a5bd6..00000000 --- a/sources/SDL2Sharp/Colors/Xbgr4444.cs +++ /dev/null @@ -1,43 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; -using SDL2Sharp.Internals; - -namespace SDL2Sharp.Colors -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 2)] - [PackedColor(PixelFormatEnum.XBGR4444)] - public readonly record struct Xbgr4444 - { - private readonly ushort _value; - - public byte B => (byte)(_value >> 8 & 0xF); - - public byte G => (byte)(_value >> 4 & 0xF); - - public byte R => (byte)(_value & 0xFF); - - public Xbgr4444(byte b, byte g, byte r) - { - _value = (ushort)((b & 0xF) << 8 | (g & 0xF) << 4 | r & 0xF); - } - } -} diff --git a/sources/SDL2Sharp/Colors/Xbgr8888.cs b/sources/SDL2Sharp/Colors/Xbgr8888.cs deleted file mode 100644 index 49e09f32..00000000 --- a/sources/SDL2Sharp/Colors/Xbgr8888.cs +++ /dev/null @@ -1,43 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; -using SDL2Sharp.Internals; - -namespace SDL2Sharp.Colors -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 4)] - [PackedColor(PixelFormatEnum.XBGR8888)] - public readonly record struct Xbgr8888 - { - private readonly uint _value; - - public byte B => (byte)(_value >> 16 & 0xFF); - - public byte G => (byte)(_value >> 8 & 0xFF); - - public byte R => (byte)(_value & 0xFF); - - public Xbgr8888(byte b, byte g, byte r) - { - _value = (uint)(b << 16 | g << 8 | r); - } - } -} diff --git a/sources/SDL2Sharp/Colors/Xrgb1555.cs b/sources/SDL2Sharp/Colors/Xrgb1555.cs deleted file mode 100644 index 6012c6f8..00000000 --- a/sources/SDL2Sharp/Colors/Xrgb1555.cs +++ /dev/null @@ -1,43 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; -using SDL2Sharp.Internals; - -namespace SDL2Sharp.Colors -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 1)] - [PackedColor(PixelFormatEnum.XRGB1555)] - public readonly record struct Xrgb1555 - { - private readonly ushort _value; - - public byte R => (byte)(_value >> 10 & 0x1F); - - public byte G => (byte)(_value >> 5 & 0x1F); - - public byte B => (byte)(_value & 0x1F); - - public Xrgb1555(byte r, byte g, byte b) - { - _value = (ushort)((r & 0x1F) << 10 | (g & 0x1F) << 5 | b & 0x1F); - } - } -} diff --git a/sources/SDL2Sharp/Colors/Xrgb4444.cs b/sources/SDL2Sharp/Colors/Xrgb4444.cs deleted file mode 100644 index 43bdafbb..00000000 --- a/sources/SDL2Sharp/Colors/Xrgb4444.cs +++ /dev/null @@ -1,43 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; -using SDL2Sharp.Internals; - -namespace SDL2Sharp.Colors -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 2)] - [PackedColor(PixelFormatEnum.XRGB4444)] - public readonly record struct Xrgb4444 - { - private readonly ushort _value; - - public byte R => (byte)(_value >> 8 & 0xF); - - public byte G => (byte)(_value >> 4 & 0xF); - - public byte B => (byte)(_value & 0xFF); - - public Xrgb4444(byte r, byte g, byte b) - { - _value = (ushort)((r & 0xF) << 8 | (g & 0xF) << 4 | b & 0xF); - } - } -} diff --git a/sources/SDL2Sharp/Colors/Xrgb8888.cs b/sources/SDL2Sharp/Colors/Xrgb8888.cs deleted file mode 100644 index ed6a9b7a..00000000 --- a/sources/SDL2Sharp/Colors/Xrgb8888.cs +++ /dev/null @@ -1,43 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.InteropServices; -using SDL2Sharp.Internals; - -namespace SDL2Sharp.Colors -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 4)] - [PackedColor(PixelFormatEnum.XRGB8888)] - public readonly record struct Xrgb8888 - { - private readonly uint _value; - - public byte R => (byte)(_value >> 16 & 0xFF); - - public byte G => (byte)(_value >> 8 & 0xFF); - - public byte B => (byte)(_value & 0xFF); - - public Xrgb8888(byte r, byte g, byte b) - { - _value = (uint)(r << 16 | g << 8 | b); - } - } -} diff --git a/sources/SDL2Sharp/Extensions/PixelFormatEnumExtensions.cs b/sources/SDL2Sharp/Extensions/PixelFormatEnumExtensions.cs deleted file mode 100644 index d116477b..00000000 --- a/sources/SDL2Sharp/Extensions/PixelFormatEnumExtensions.cs +++ /dev/null @@ -1,66 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -namespace SDL2Sharp.Extensions -{ - public static class PixelFormatEnumExtensions - { - public static bool IsFourCC(this PixelFormatEnum format) - { - return (format != PixelFormatEnum.Unknown) && (GetPixelFlag(format) != 1); - } - - public static uint GetPixelFlag(this PixelFormatEnum format) - { - return (((uint)format) >> 28) & 0x0FU; - } - - public static PixelType GetPixelType(this PixelFormatEnum format) - { - return (PixelType)((((uint)format) >> 24) & 0x0F); - } - - public static uint GetBitsPerPixel(this PixelFormatEnum format) - { - return (((uint)format) >> 8) & 0xFFU; - } - - public static uint GetBytesPerPixel(this PixelFormatEnum pixelFormat) - { - return IsFourCC(pixelFormat) ? - (((pixelFormat == PixelFormatEnum.YUY2) || - (pixelFormat == PixelFormatEnum.UYVY) || - (pixelFormat == PixelFormatEnum.YVYU)) ? 2u : 1u) : ((uint)pixelFormat) & 0xFF; - } - - public static bool IsPacked(this PixelFormatEnum pixelFormat) - { - if (IsFourCC(pixelFormat)) - { - return false; - } - - var pixelType = GetPixelType(pixelFormat); - return (pixelType == PixelType.Packed8) - || (pixelType == PixelType.Packed16) - || (pixelType == PixelType.Packet32); - } - } -} diff --git a/sources/SDL2Sharp/Font.cs b/sources/SDL2Sharp/Font.cs deleted file mode 100644 index 8539f8e1..00000000 --- a/sources/SDL2Sharp/Font.cs +++ /dev/null @@ -1,98 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using SDL2Sharp.Colors; -using SDL2Sharp.Internals; -using SDL2Sharp.Interop; - -namespace SDL2Sharp -{ - public sealed unsafe class Font : IDisposable - { - private _TTF_Font* _handle; - - public Font(string path, int pointSize) - { - using (var marshaledPath = new MarshaledString(path)) - { - var handle = TTF.OpenFont(marshaledPath, pointSize); - FontError.ThrowOnFailure(handle); - _handle = handle; - } - } - - ~Font() - { - Dispose(true); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool _) - { - if (_handle is null) return; - TTF.CloseFont(_handle); - _handle = null; - } - - public Surface RenderSolid(string text, Color color) - { - ThrowWhenDisposed(); - - using (var marshaledText = new MarshaledString(text)) - { - return new Surface(TTF.RenderText_Solid(_handle, marshaledText, color)); - } - } - - public Surface RenderBlended(string text, Color color) - { - ThrowWhenDisposed(); - - using (var marshaledText = new MarshaledString(text)) - { - return new Surface(TTF.RenderText_Blended(_handle, marshaledText, color)); - } - } - - public static implicit operator _TTF_Font*(Font font) - { - if (font is null) - { - throw new ArgumentNullException(nameof(font)); - } - - return font._handle; - } - - private void ThrowWhenDisposed() - { - if (_handle is null) - { - throw new ObjectDisposedException(GetType().FullName); - } - } - } -} diff --git a/sources/SDL2Sharp/Hints.cs b/sources/SDL2Sharp/Hints.cs deleted file mode 100644 index 1d3de5c2..00000000 --- a/sources/SDL2Sharp/Hints.cs +++ /dev/null @@ -1,275 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using SDL2Sharp.Internals; -using SDL2Sharp.Interop; - -namespace SDL2Sharp -{ - public static class Hints - { - public static readonly string FramebufferAcceleration = SDL.SDL_HINT_FRAMEBUFFER_ACCELERATION.AsString(); - - public static readonly string RenderDriver = SDL.SDL_HINT_RENDER_DRIVER.AsString(); - - public static readonly string OpenGlShaders = SDL.SDL_HINT_RENDER_OPENGL_SHADERS.AsString(); - - public static readonly string Direct3DThreadSafe = SDL.SDL_HINT_RENDER_DIRECT3D_THREADSAFE.AsString(); - - public static readonly string Direct3D11Debug = SDL.SDL_HINT_RENDER_DIRECT3D11_DEBUG.AsString(); - - public static readonly string LogicalSizeMode = SDL.SDL_HINT_RENDER_LOGICAL_SIZE_MODE.AsString(); - - public static readonly string RenderScaleQuality = SDL.SDL_HINT_RENDER_SCALE_QUALITY.AsString(); - - public static readonly string RenderVSync = SDL.SDL_HINT_RENDER_VSYNC.AsString(); - - public static readonly string VideoAllowScreensaver = SDL.SDL_HINT_VIDEO_ALLOW_SCREENSAVER.AsString(); - - public static readonly string VideoExternalContext = SDL.SDL_HINT_VIDEO_EXTERNAL_CONTEXT.AsString(); - - public static readonly string VideoX11XVidMode = SDL.SDL_HINT_VIDEO_X11_XVIDMODE.AsString(); - - public static readonly string VideoX11Xinerama = SDL.SDL_HINT_VIDEO_X11_XINERAMA.AsString(); - - public static readonly string VideoX11XRandr = SDL.SDL_HINT_VIDEO_X11_XRANDR.AsString(); - - public static readonly string VideoX11WindowVisualId = SDL.SDL_HINT_VIDEO_X11_WINDOW_VISUALID.AsString(); - - public static readonly string VideoX11NetWmPing = SDL.SDL_HINT_VIDEO_X11_NET_WM_PING.AsString(); - - public static readonly string VideoX11NetWmBypassCompositor = SDL.SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR.AsString(); - - public static readonly string VideoX11ForceEgl = SDL.SDL_HINT_VIDEO_X11_FORCE_EGL.AsString(); - - public static readonly string WindowFrameUsableWhileCursorHidden = SDL.SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN.AsString(); - - public static readonly string WindowsIntResourceIcon = SDL.SDL_HINT_WINDOWS_INTRESOURCE_ICON.AsString(); - - public static readonly string WindowsIntResourceIconSmall = SDL.SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL.AsString(); - - public static readonly string WindowsEnableMessageLoop = SDL.SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP.AsString(); - - public static readonly string GrabKeyboard = SDL.SDL_HINT_GRAB_KEYBOARD.AsString(); - - public static readonly string MouseDoubleClickTime = SDL.SDL_HINT_MOUSE_DOUBLE_CLICK_TIME.AsString(); - - public static readonly string MouseDoubleClickRadius = SDL.SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS.AsString(); - - public static readonly string MouseNormalSpeedScale = SDL.SDL_HINT_MOUSE_NORMAL_SPEED_SCALE.AsString(); - - public static readonly string MouseRelativeSpeedScale = SDL.SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE.AsString(); - - public static readonly string MouseRelativeScaling = SDL.SDL_HINT_MOUSE_RELATIVE_SCALING.AsString(); - - public static readonly string MouseRelativeModeWarp = SDL.SDL_HINT_MOUSE_RELATIVE_MODE_WARP.AsString(); - - public static readonly string MouseFocusClickThrough = SDL.SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH.AsString(); - - public static readonly string TouchMouseEvents = SDL.SDL_HINT_TOUCH_MOUSE_EVENTS.AsString(); - - public static readonly string MouseTouchEvents = SDL.SDL_HINT_MOUSE_TOUCH_EVENTS.AsString(); - - public static readonly string VideoMinimizeOnFocusLoss = SDL.SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS.AsString(); - - public static readonly string IdleTimerDisabled = SDL.SDL_HINT_IDLE_TIMER_DISABLED.AsString(); - - public static readonly string Orientations = SDL.SDL_HINT_ORIENTATIONS.AsString(); - - public static readonly string AppleTvControllerUiEvents = SDL.SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS.AsString(); - - public static readonly string AppleTvRemoteAllowRotation = SDL.SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION.AsString(); - - public static readonly string IosHideHomeIndicator = SDL.SDL_HINT_IOS_HIDE_HOME_INDICATOR.AsString(); - - public static readonly string AccelerometerAsJoystick = SDL.SDL_HINT_ACCELEROMETER_AS_JOYSTICK.AsString(); - - public static readonly string TvRemoveAsJoystick = SDL.SDL_HINT_TV_REMOTE_AS_JOYSTICK.AsString(); - - public static readonly string XInputEnabled = SDL.SDL_HINT_XINPUT_ENABLED.AsString(); - - public static readonly string XInputUseOldJoystickMapping = SDL.SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING.AsString(); - - public static readonly string GameControllerType = SDL.SDL_HINT_GAMECONTROLLERTYPE.AsString(); - - public static readonly string GameControllerConfig = SDL.SDL_HINT_GAMECONTROLLERCONFIG.AsString(); - - public static readonly string GameControllerConfigFile = SDL.SDL_HINT_GAMECONTROLLERCONFIG_FILE.AsString(); - - public static readonly string GameControllerIgnoreDevices = SDL.SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES.AsString(); - - public static readonly string GameControllerIgnoreDevicesExcept = SDL.SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT.AsString(); - - public static readonly string GameControllerUseButtonLabels = SDL.SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS.AsString(); - - public static readonly string JOYSTICK_ALLOW_BACKGROUND_EVENTS = SDL.SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS.AsString(); - - public static readonly string JoystickHidApi = SDL.SDL_HINT_JOYSTICK_HIDAPI.AsString(); - - public static readonly string JoystickHidApiGameCube = SDL.SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE.AsString(); - - public static readonly string JoystickHidApiJoyCons = SDL.SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS.AsString(); - - public static readonly string JoystickHidApiLuna = SDL.SDL_HINT_JOYSTICK_HIDAPI_LUNA.AsString(); - - public static readonly string JoystickHidApiPS4 = SDL.SDL_HINT_JOYSTICK_HIDAPI_PS4.AsString(); - - public static readonly string JoystickHidApiPS4Rumble = SDL.SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE.AsString(); - - public static readonly string JoystickHidApiPS5 = SDL.SDL_HINT_JOYSTICK_HIDAPI_PS5.AsString(); - - public static readonly string JoystickHidApiPS5PlayerLed = SDL.SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED.AsString(); - - public static readonly string JoystickHidApiPS5Rumble = SDL.SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE.AsString(); - - public static readonly string JoystickHidApiStadia = SDL.SDL_HINT_JOYSTICK_HIDAPI_STADIA.AsString(); - - public static readonly string JoystickHidApiSteam = SDL.SDL_HINT_JOYSTICK_HIDAPI_STEAM.AsString(); - - public static readonly string JoystickHidApiSwitch = SDL.SDL_HINT_JOYSTICK_HIDAPI_SWITCH.AsString(); - - public static readonly string JoystickHidApiSwitchHomeLed = SDL.SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED.AsString(); - - public static readonly string JoystickHidApiXbox = SDL.SDL_HINT_JOYSTICK_HIDAPI_XBOX.AsString(); - - public static readonly string EnableSteamControllers = SDL.SDL_HINT_ENABLE_STEAM_CONTROLLERS.AsString(); - - public static readonly string JoystickRawInput = SDL.SDL_HINT_JOYSTICK_RAWINPUT.AsString(); - - public static readonly string JoystickThread = SDL.SDL_HINT_JOYSTICK_THREAD.AsString(); - - public static readonly string LinuxJoystickDeadzones = SDL.SDL_HINT_LINUX_JOYSTICK_DEADZONES.AsString(); - - public static readonly string AllowTopMost = SDL.SDL_HINT_ALLOW_TOPMOST.AsString(); - - public static readonly string TimerResolution = SDL.SDL_HINT_TIMER_RESOLUTION.AsString(); - - public static readonly string QtWaylandContentOrientation = SDL.SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION.AsString(); - - public static readonly string QtWaylandWindowFlags = SDL.SDL_HINT_QTWAYLAND_WINDOW_FLAGS.AsString(); - - public static readonly string ThreadStackSize = SDL.SDL_HINT_THREAD_STACK_SIZE.AsString(); - - public static readonly string ThreadPriorityPolicy = SDL.SDL_HINT_THREAD_PRIORITY_POLICY.AsString(); - - public static readonly string ThreadForceRealtimeTimeCritical = SDL.SDL_HINT_THREAD_FORCE_REALTIME_TIME_CRITICAL.AsString(); - - public static readonly string VideoHighDpiDisabled = SDL.SDL_HINT_VIDEO_HIGHDPI_DISABLED.AsString(); - - public static readonly string MacCtrlClickEmulateRightClick = SDL.SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK.AsString(); - - public static readonly string VideoWinD3DCompiler = SDL.SDL_HINT_VIDEO_WIN_D3DCOMPILER.AsString(); - - public static readonly string VideoWindowSharePixelFormat = SDL.SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT.AsString(); - - public static readonly string WinrtPrivacyPolicyUrl = SDL.SDL_HINT_WINRT_PRIVACY_POLICY_URL.AsString(); - - public static readonly string WinrtPrivacyPolicyLabel = SDL.SDL_HINT_WINRT_PRIVACY_POLICY_LABEL.AsString(); - - public static readonly string WinrtHandleBackButton = SDL.SDL_HINT_WINRT_HANDLE_BACK_BUTTON.AsString(); - - public static readonly string VideoMacFullScreenSpaces = SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES.AsString(); - - public static readonly string MacBackgroundApp = SDL.SDL_HINT_MAC_BACKGROUND_APP.AsString(); - - public static readonly string AndroidApkExpansionMainFileVersion = SDL.SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION.AsString(); - - public static readonly string AndroidApkExpansionPatchFileVersion = SDL.SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION.AsString(); - - public static readonly string ImeInternalEditing = SDL.SDL_HINT_IME_INTERNAL_EDITING.AsString(); - - public static readonly string AndroidTrapBackButton = SDL.SDL_HINT_ANDROID_TRAP_BACK_BUTTON.AsString(); - - public static readonly string AndroidBlockOnPause = SDL.SDL_HINT_ANDROID_BLOCK_ON_PAUSE.AsString(); - - public static readonly string AndroidBlockOnPausePauseAudio = SDL.SDL_HINT_ANDROID_BLOCK_ON_PAUSE_PAUSEAUDIO.AsString(); - - public static readonly string ReturnKeyHidesIme = SDL.SDL_HINT_RETURN_KEY_HIDES_IME.AsString(); - - public static readonly string EmscriptenKeyboardElement = SDL.SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT.AsString(); - - public static readonly string EmscriptenAsyncify = SDL.SDL_HINT_EMSCRIPTEN_ASYNCIFY.AsString(); - - public static readonly string NoSignalHandlers = SDL.SDL_HINT_NO_SIGNAL_HANDLERS.AsString(); - - public static readonly string WindowsNoCloseOnAltF4 = SDL.SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4.AsString(); - - public static readonly string BmpSaveLegacyFormat = SDL.SDL_HINT_BMP_SAVE_LEGACY_FORMAT.AsString(); - - public static readonly string WindowsDisableThreadNaming = SDL.SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING.AsString(); - - public static readonly string RpiVideoLayer = SDL.SDL_HINT_RPI_VIDEO_LAYER.AsString(); - - public static readonly string VideoDoubleBuffer = SDL.SDL_HINT_VIDEO_DOUBLE_BUFFER.AsString(); - - public static readonly string OpenGlEsDriver = SDL.SDL_HINT_OPENGL_ES_DRIVER.AsString(); - - public static readonly string AudioResamplingMode = SDL.SDL_HINT_AUDIO_RESAMPLING_MODE.AsString(); - - public static readonly string AudioCategory = SDL.SDL_HINT_AUDIO_CATEGORY.AsString(); - - public static readonly string RenderBatching = SDL.SDL_HINT_RENDER_BATCHING.AsString(); - - public static readonly string AutoUpdateJoysticks = SDL.SDL_HINT_AUTO_UPDATE_JOYSTICKS.AsString(); - - public static readonly string AutoUpdateSensors = SDL.SDL_HINT_AUTO_UPDATE_SENSORS.AsString(); - - public static readonly string EventLogging = SDL.SDL_HINT_EVENT_LOGGING.AsString(); - - public static readonly string WaveRiffChunkSize = SDL.SDL_HINT_WAVE_RIFF_CHUNK_SIZE.AsString(); - - public static readonly string WaveTruncation = SDL.SDL_HINT_WAVE_TRUNCATION.AsString(); - - public static readonly string WaveFactChunk = SDL.SDL_HINT_WAVE_FACT_CHUNK.AsString(); - - public static readonly string DisplayUsableBounds = SDL.SDL_HINT_DISPLAY_USABLE_BOUNDS.AsString(); - - public static readonly string AudioDeviceAppName = SDL.SDL_HINT_AUDIO_DEVICE_APP_NAME.AsString(); - - public static readonly string AudioDeviceStreamName = SDL.SDL_HINT_AUDIO_DEVICE_STREAM_NAME.AsString(); - - public static readonly string PreferredLocales = SDL.SDL_HINT_PREFERRED_LOCALES.AsString(); - - public static unsafe bool SetValue(string name, string value) - { - using var marshaledName = new MarshaledString(name); - using var marshaledValue = new MarshaledString(value); - return 0 != SDL.SetHint(marshaledName, marshaledValue); - } - - public static unsafe bool SetValue(string name, string value, HintPriority priority) - { - using var marshaledName = new MarshaledString(name); - using var marshaledValue = new MarshaledString(value); - return 0 != SDL.SetHintWithPriority(marshaledName, marshaledValue, (SDL_HintPriority)priority); - } - - public static unsafe string GetValue(string name) - { - using var marshaledName = new MarshaledString(name); - var value = SDL.GetHint(marshaledName); - if (value is null) - { - return null!; - } - return new string(value); - } - } -} diff --git a/sources/SDL2Sharp/Internals/PackedColorAttribute.cs b/sources/SDL2Sharp/Internals/PackedColorAttribute.cs deleted file mode 100644 index ebb6de6d..00000000 --- a/sources/SDL2Sharp/Internals/PackedColorAttribute.cs +++ /dev/null @@ -1,47 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Reflection; - -namespace SDL2Sharp.Internals -{ - [AttributeUsage(AttributeTargets.Struct)] - internal sealed class PackedColorAttribute : Attribute - { - public PixelFormatEnum PixelFormat { get; } - - public PackedColorAttribute(PixelFormatEnum pixelFormat) - { - PixelFormat = pixelFormat; - } - - public static PixelFormatEnum GetPixelFormatOf() - { - var pixelFormatType = typeof(TPackedColor); - var pixelFormatAttribute = pixelFormatType.GetCustomAttribute(); - if (pixelFormatAttribute == null) - { - return PixelFormatEnum.Unknown; - } - return pixelFormatAttribute.PixelFormat; - } - } -} diff --git a/sources/SDL2Sharp/Internals/PlanarColorAttribute.cs b/sources/SDL2Sharp/Internals/PlanarColorAttribute.cs deleted file mode 100644 index e5f4b2bd..00000000 --- a/sources/SDL2Sharp/Internals/PlanarColorAttribute.cs +++ /dev/null @@ -1,47 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Reflection; - -namespace SDL2Sharp.Internals -{ - [AttributeUsage(AttributeTargets.Struct)] - internal sealed class PlanarColorAttribute : Attribute - { - public PixelFormatEnum PixelFormat { get; } - - public PlanarColorAttribute(PixelFormatEnum pixelFormat) - { - PixelFormat = pixelFormat; - } - - public static PixelFormatEnum GetPixelFormatOf() - { - var pixelFormatType = typeof(TPlanarColor); - var pixelFormatAttribute = pixelFormatType.GetCustomAttribute(); - if (pixelFormatAttribute == null) - { - return PixelFormatEnum.Unknown; - } - return pixelFormatAttribute.PixelFormat; - } - } -} diff --git a/sources/SDL2Sharp/KeyEventArgs.cs b/sources/SDL2Sharp/KeyEventArgs.cs deleted file mode 100644 index 53732856..00000000 --- a/sources/SDL2Sharp/KeyEventArgs.cs +++ /dev/null @@ -1,49 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; - -namespace SDL2Sharp -{ - public sealed class KeyEventArgs : EventArgs - { - public KeyEventArgs(Scancode scanCode, KeyCode keyCode, KeyModifiers modifiers, int repeat) - { - ScanCode = scanCode; - KeyCode = keyCode; - Modifiers = modifiers; - Repeat = repeat; - } - - public Scancode ScanCode { get; } - - public KeyCode KeyCode { get; } - - public KeyModifiers Modifiers { get; } - - public bool Alt => Modifiers.HasFlag(KeyModifiers.LeftAlt) || Modifiers.HasFlag(KeyModifiers.RightAlt); - - public bool Ctrl => Modifiers.HasFlag(KeyModifiers.LeftCtrl) || Modifiers.HasFlag(KeyModifiers.RightCtrl); - - public bool Shift => Modifiers.HasFlag(KeyModifiers.LeftShift) || Modifiers.HasFlag(KeyModifiers.RightShift); - - public int Repeat { get; } - } -} diff --git a/sources/SDL2Sharp/PackedTexture.cs b/sources/SDL2Sharp/PackedTexture.cs deleted file mode 100644 index 5f197231..00000000 --- a/sources/SDL2Sharp/PackedTexture.cs +++ /dev/null @@ -1,130 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using Microsoft.Toolkit.HighPerformance; -using SDL2Sharp.Interop; - -namespace SDL2Sharp -{ - public sealed unsafe class PackedTexture : Texture where TPackedColor : struct - { - internal PackedTexture(SDL_Texture* texture) - : base(texture) - { } - - public void WithLock(WithLockPackedImageCallback callback) - { - WithLock(0, 0, Width, Height, callback); - } - - public void WithLock(Rectangle rectangle, WithLockPackedImageCallback callback) - { - WithLock(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, callback); - } - - public void WithLock(int x, int y, int width, int height, WithLockPackedImageCallback callback) - { - ThrowWhenDisposed(); - - var rect = new SDL_Rect { x = x, y = y, w = width, h = height }; - void* pixels; - int pitchInBytes; - Error.ThrowOnFailure( - SDL.LockTexture(this, &rect, &pixels, &pitchInBytes) - ); - - var bytesPerPixel = Marshal.SizeOf(); - var pitch = pitchInBytes / bytesPerPixel; - var image = new PackedImage(pixels, height, width, pitch); - callback(image); - SDL.UnlockTexture(this); - } - - public void WithLock(WithLockSurfaceCallback callback) - { - WithLock(0, 0, Width, Height, callback); - } - - public void WithLock(Rectangle rectangle, WithLockSurfaceCallback callback) - { - WithLock(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, callback); - } - - public void WithLock(int x, int y, int width, int height, WithLockSurfaceCallback callback) - { - ThrowWhenDisposed(); - - var rect = new SDL_Rect { x = x, y = y, w = width, h = height }; - SDL_Surface* surfaceHandle; - Error.ThrowOnFailure( - SDL.LockTextureToSurface(this, &rect, &surfaceHandle) - ); - var surface = new Surface(surfaceHandle, false); - callback.Invoke(surface); - SDL.UnlockTexture(this); - } - - public void Update(PackedMemoryImage image) - { - ThrowWhenDisposed(); - - var pointer = Unsafe.AsPointer(ref image.DangerousGetReference()); - var pitch = image.Width * Marshal.SizeOf(); - Update(null, pointer, pitch); - } - - public void Update(PackedImage pixels) - { - ThrowWhenDisposed(); - - var pointer = Unsafe.AsPointer(ref pixels.DangerousGetReference()); - var pitch = pixels.Width * Marshal.SizeOf(); - Update(null, pointer, pitch); - } - - public void Update(Span2D pixels) - { - ThrowWhenDisposed(); - - var pointer = Unsafe.AsPointer(ref pixels.DangerousGetReference()); - var pitch = pixels.Width * Marshal.SizeOf(); - Update(null, pointer, pitch); - } - - public void Update(TPackedColor[,] pixels) - { - ThrowWhenDisposed(); - - var pointer = Unsafe.AsPointer(ref pixels.DangerousGetReference()); - var width = pixels.GetLength(1); - var pitch = width * Marshal.SizeOf(); - Update(null, pointer, pitch); - } - - private void Update(SDL_Rect* rect, void* pixels, int pitch) - { - Error.ThrowOnFailure( - SDL.UpdateTexture(this, rect, pixels, pitch) - ); - } - } -} diff --git a/sources/SDL2Sharp/Palette.cs b/sources/SDL2Sharp/Palette.cs deleted file mode 100644 index 62cfd357..00000000 --- a/sources/SDL2Sharp/Palette.cs +++ /dev/null @@ -1,108 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; - -namespace SDL2Sharp -{ - public sealed class Palette where TColor : struct - { - private readonly TColor[] _colors; - - private int _offset; - - public int Count => _colors.Length; - - public TColor this[int index] - { - get - { - if (index < 0) - { - throw new ArgumentOutOfRangeException(nameof(index), index, "The specified index cannot be less than zero."); - } - - if (index >= _colors.Length) - { - throw new ArgumentOutOfRangeException(nameof(index), index, "The specified index cannot be greater than or equal to the number of colors in the palette."); - } - - var shiftedIndex = _offset + index; - if (shiftedIndex >= _colors.Length) - { - shiftedIndex -= _colors.Length; - } - - return _colors[shiftedIndex]; - } - set - { - if (index < 0) - { - throw new ArgumentOutOfRangeException(nameof(index), index, "The specified index cannot be less than zero."); - } - - if (index >= _colors.Length) - { - throw new ArgumentOutOfRangeException(nameof(index), index, "The specified index cannot be greater than or equal to the number of colors in the palette."); - } - - var shiftedIndex = _offset + index; - if (shiftedIndex >= _colors.Length) - { - shiftedIndex -= _colors.Length; - } - - _colors[shiftedIndex] = value; - } - } - - public Palette(int size) - { - if (size < 0) - { - throw new ArgumentOutOfRangeException(nameof(size), size, "The size of a palette cannot be less than zero"); - } - - _colors = new TColor[size]; - _offset = 0; - } - - public void RotateLeft() - { - --_offset; - - if (_offset < 0) - { - _offset += _colors.Length; - } - } - - public void RotateRight() - { - ++_offset; - - if (_offset >= _colors.Length) - { - _offset -= _colors.Length; - } - } - } -} diff --git a/sources/SDL2Sharp/PixelFormatEnum.cs b/sources/SDL2Sharp/PixelFormatEnum.cs deleted file mode 100644 index f62029f1..00000000 --- a/sources/SDL2Sharp/PixelFormatEnum.cs +++ /dev/null @@ -1,78 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using SDL2Sharp.Interop; - -namespace SDL2Sharp -{ - public enum PixelFormatEnum : uint - { - Unknown = SDL_PixelFormatEnum.SDL_PIXELFORMAT_UNKNOWN, - Index1LSB = SDL_PixelFormatEnum.SDL_PIXELFORMAT_INDEX1LSB, - Index1MSB = SDL_PixelFormatEnum.SDL_PIXELFORMAT_INDEX1MSB, - Index4LSB = SDL_PixelFormatEnum.SDL_PIXELFORMAT_INDEX4LSB, - Index4MSB = SDL_PixelFormatEnum.SDL_PIXELFORMAT_INDEX4MSB, - Index8 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_INDEX8, - RGB332 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_RGB332, - XRGB4444 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_XRGB4444, - RGB444 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_RGB444, - XBGR4444 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_XBGR4444, - BGR444 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_BGR444, - XRGB1555 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_XRGB1555, - RGB555 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_RGB555, - XBGR1555 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_XBGR1555, - BGR555 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_BGR555, - ARGB4444 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_ARGB4444, - RGBA4444 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_RGBA4444, - ABGR4444 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_ABGR4444, - BGRA4444 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_BGRA4444, - ARGB1555 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_ARGB1555, - RGBA5551 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_RGBA5551, - ABGR1555 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_ABGR1555, - BGRA5551 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_BGRA5551, - RGB565 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_RGB565, - BGR565 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_BGR565, - RGB24 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_RGB24, - BGR24 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_BGR24, - XRGB8888 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_XRGB8888, - RGB888 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_RGB888, - RGBX8888 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_RGBX8888, - XBGR8888 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_XBGR8888, - BGR888 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_BGR888, - BGRX8888 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_BGRX8888, - ARGB8888 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_ARGB8888, - RGBA8888 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_RGBA8888, - ABGR8888 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_ABGR8888, - BGRA8888 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_BGRA8888, - ARGB2101010 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_ARGB2101010, - RGBA32 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_RGBA32, - ARGB32 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_ARGB32, - BGRA32 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_BGRA32, - ABGR32 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_ABGR32, - YV12 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_YV12, - IYUV = SDL_PixelFormatEnum.SDL_PIXELFORMAT_IYUV, - YUY2 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_YUY2, - UYVY = SDL_PixelFormatEnum.SDL_PIXELFORMAT_UYVY, - YVYU = SDL_PixelFormatEnum.SDL_PIXELFORMAT_YVYU, - NV12 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_NV12, - NV21 = SDL_PixelFormatEnum.SDL_PIXELFORMAT_NV21, - ExternalOES = SDL_PixelFormatEnum.SDL_PIXELFORMAT_EXTERNAL_OES, - } -} diff --git a/sources/SDL2Sharp/Renderer.cs b/sources/SDL2Sharp/Renderer.cs deleted file mode 100644 index 065c12a5..00000000 --- a/sources/SDL2Sharp/Renderer.cs +++ /dev/null @@ -1,423 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using SDL2Sharp.Internals; -using SDL2Sharp.Interop; - -namespace SDL2Sharp -{ - public sealed unsafe class Renderer : IDisposable - { - private SDL_Renderer* _handle; - - private Texture? _renderTarget; - - public RendererInfo Info - { - get - { - ThrowWhenDisposed(); - - var rendererInfo = new SDL_RendererInfo(); - Error.ThrowOnFailure( - SDL.GetRendererInfo(_handle, &rendererInfo) - ); - return new RendererInfo(rendererInfo); - } - } - - public Size OutputSize - { - get - { - ThrowWhenDisposed(); - - int width, height; - Error.ThrowOnFailure( - SDL.GetRendererOutputSize(_handle, &width, &height) - ); - return new Size(width, height); - } - } - - public Color DrawColor - { - get - { - ThrowWhenDisposed(); - - byte r, g, b, a; - Error.ThrowOnFailure( - SDL.GetRenderDrawColor(_handle, &r, &g, &b, &a) - ); - return new Color(r, g, b, a); - } - set - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.SetRenderDrawColor(_handle, value.R, value.G, value.B, value.A) - ); - } - } - - public BlendMode BlendMode - { - get - { - ThrowWhenDisposed(); - - SDL_BlendMode blendMode; - Error.ThrowOnFailure( - SDL.GetRenderDrawBlendMode(_handle, &blendMode) - ); - return (BlendMode)blendMode; - } - set - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.SetRenderDrawBlendMode(_handle, (SDL_BlendMode)value) - ); - } - } - - public Size LogicalViewSize - { - get - { - ThrowWhenDisposed(); - - int width, height; - SDL.RenderGetLogicalSize(_handle, &width, &height); - return new Size(width, height); - } - set - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.RenderSetLogicalSize(_handle, value.Width, value.Height) - ); - } - } - - public Scale Scale - { - get - { - - ThrowWhenDisposed(); - - float scaleX, scaleY; - SDL.RenderGetScale(_handle, &scaleX, &scaleY); - return new Scale(scaleX, scaleY); - } - set - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.RenderSetScale(_handle, value.X, value.Y) - ); - } - } - - public Rectangle ViewPort - { - get - { - ThrowWhenDisposed(); - - var rect = new SDL_Rect(); - SDL.RenderGetViewport(_handle, &rect); - return new Rectangle(rect.x, rect.y, rect.w, rect.h); - } - set - { - ThrowWhenDisposed(); - - var rect = new SDL_Rect { x = value.X, y = value.Y, w = value.Width, h = value.Height }; - Error.ThrowOnFailure( - SDL.RenderSetViewport(_handle, &rect) - ); - } - } - - public Texture? Target - { - get - { - ThrowWhenDisposed(); - - return _renderTarget; - } - set - { - ThrowWhenDisposed(); - - if (value is null) - { - Error.ThrowOnFailure( - SDL.SetRenderTarget(_handle, null) - ); - } - else - { - Error.ThrowOnFailure( - SDL.SetRenderTarget(_handle, value) - ); - } - - _renderTarget = value; - } - } - - internal Renderer(SDL_Renderer* renderer) - { - if (renderer is null) - { - throw new ArgumentNullException(nameof(renderer)); - } - - _handle = renderer; - } - - ~Renderer() - { - Dispose(false); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool _) - { - if (_handle is null) return; - SDL.DestroyRenderer(_handle); - _handle = null; - } - - public Texture CreateTexture(PixelFormatEnum pixelFormat, TextureAccess access, Size size) - { - return CreateTexture(pixelFormat, access, size.Width, size.Height); - } - - public Texture CreateTexture(PixelFormatEnum pixelFormat, TextureAccess access, int width, int height) - { - ThrowWhenDisposed(); - - var texture = SDL.CreateTexture(_handle, (uint)pixelFormat, (int)access, width, height); - Error.ThrowOnFailure(texture); - return new Texture(texture); - } - - - public PackedTexture CreateTexture(TextureAccess access, Size size) where TPackedColor : struct - { - return CreateTexture(access, size.Width, size.Height); - } - - public PackedTexture CreateTexture(TextureAccess access, int width, int height) where TPackedColor : struct - { - ThrowWhenDisposed(); - - var pixelFormat = PackedColorAttribute.GetPixelFormatOf(); - var texture = SDL.CreateTexture(_handle, (uint)pixelFormat, (int)access, width, height); - Error.ThrowOnFailure(texture); - return new PackedTexture(texture); - } - - public Texture CreateTextureFromSurface(Surface surface) - { - ThrowWhenDisposed(); - - var texture = SDL.CreateTextureFromSurface(_handle, surface); - Error.ThrowOnFailure(texture); - return new Texture(texture); - } - - - public PackedTexture CreateTextureFromSurface(Surface surface) where TPackedColor : struct - { - ThrowWhenDisposed(); - - var texture = SDL.CreateTextureFromSurface(_handle, surface); - Error.ThrowOnFailure(texture); - return new PackedTexture(texture); - } - - public void Clear() - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.RenderClear(_handle) - ); - } - - public void Copy(Texture texture) - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.RenderCopy(_handle, texture, null, null) - ); - } - - public void Copy(Texture texture, Rectangle destination) - { - ThrowWhenDisposed(); - - var dest = new SDL_Rect - { - x = destination.X, - y = destination.Y, - w = destination.Width, - h = destination.Height - }; - - Error.ThrowOnFailure( - SDL.RenderCopy(_handle, texture, null, &dest) - ); - } - - public void Copy(Texture texture, Rectangle source, Rectangle destination) - { - ThrowWhenDisposed(); - - var src = new SDL_Rect - { - x = source.X, - y = source.Y, - w = source.Width, - h = source.Height - }; - - var dest = new SDL_Rect - { - x = destination.X, - y = destination.Y, - w = destination.Width, - h = destination.Height - }; - - Error.ThrowOnFailure( - SDL.RenderCopy(_handle, texture, &src, &dest) - ); - } - - public void DrawLine(int x1, int y1, int x2, int y2) - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.RenderDrawLine(_handle, x1, y1, x2, y2) - ); - } - - public void DrawLines(Point[] points) - { - ThrowWhenDisposed(); - - fixed (Point* point = &points[0]) - { - Error.ThrowOnFailure( - SDL.RenderDrawLines(_handle, (SDL_Point*)point, points.Length) - ); - } - } - - public void DrawLine(float x1, float y1, float x2, float y2) - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.RenderDrawLineF(_handle, x1, y1, x2, y2) - ); - } - - public void DrawPoint(int x, int y) - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.RenderDrawPoint(_handle, x, y) - ); - } - - public void DrawPoint(float x, float y) - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.RenderDrawPointF(_handle, x, y) - ); - } - - public void DrawPoints(Point[] points) - { - ThrowWhenDisposed(); - - fixed (Point* point = &points[0]) - { - Error.ThrowOnFailure( - SDL.RenderDrawPoints(_handle, (SDL_Point*)point, points.Length) - ); - } - } - - public void FillRect(int x, int y, int width, int height) - { - ThrowWhenDisposed(); - - var rect = new SDL_Rect { x = x, y = y, w = width, h = height }; - Error.ThrowOnFailure( - SDL.RenderFillRect(_handle, &rect) - ); - } - - public void FillRect(Rectangle rectangle) - { - FillRect(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); - } - - public void Present() - { - ThrowWhenDisposed(); - - SDL.RenderPresent(_handle); - } - - private void ThrowWhenDisposed() - { - if (_handle is null) - { - throw new ObjectDisposedException(GetType().FullName); - } - } - } -} diff --git a/sources/SDL2Sharp/SDL2Sharp.csproj b/sources/SDL2Sharp/SDL2Sharp.csproj index 6ac1254f..6d9d1c93 100644 --- a/sources/SDL2Sharp/SDL2Sharp.csproj +++ b/sources/SDL2Sharp/SDL2Sharp.csproj @@ -1,18 +1,19 @@  - - - - - - - - - netstandard2.0;net461 + net8.0 AnyCPU Provides type safe wrappers for SDL2 bindings written in C#. SDL2 + + + + + + + + + diff --git a/sources/SDL2Sharp/Surface.cs b/sources/SDL2Sharp/Surface.cs deleted file mode 100644 index edb33446..00000000 --- a/sources/SDL2Sharp/Surface.cs +++ /dev/null @@ -1,184 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using SDL2Sharp.Internals; -using SDL2Sharp.Interop; - -namespace SDL2Sharp -{ - public sealed unsafe class Surface : IDisposable - { - private SDL_Surface* _handle; - - private readonly bool _freeHandle; - - public PixelFormat Format => new(_handle->format, false); - - public int Width => _handle->w; - - public int Height => _handle->h; - - public int Pitch => _handle->pitch; - - public PackedImage Pixels() - { - return new PackedImage( - _handle->pixels, - _handle->h, - _handle->w, - _handle->pitch); - } - - public bool MustLock => ((_handle->flags & SDL.SDL_RLEACCEL) != 0); - - public static Surface LoadBitmap(string filename) - { - using var file = new MarshaledString(filename); - using var mode = new MarshaledString("rb"); - var source = SDL.RWFromFile(file, mode); - Error.ThrowOnFailure(source); - var bitmap = SDL.LoadBMP_RW(source, 1); - Error.ThrowOnFailure(bitmap); - return new Surface(bitmap); - } - - public Surface(SDL_Surface* handle) - : this(handle, true) - { } - - public Surface(SDL_Surface* handle, bool freeHandle) - { - if (handle is null) - { - throw new ArgumentNullException(nameof(handle)); - } - - _handle = handle; - _freeHandle = freeHandle; - } - - public Surface(int width, int height, int depth, PixelFormatEnum format) - : this(Error.ReturnOrThrowOnFailure(SDL.CreateRGBSurfaceWithFormat(0, width, height, depth, (uint)format))) - { } - - public Surface(int width, int height, int depth, uint redMask, uint greenMask, uint blueMask, uint alphaMask) - : this(Error.ReturnOrThrowOnFailure(SDL.CreateRGBSurface(0, width, height, depth, redMask, greenMask, blueMask, alphaMask))) - { } - - public Surface(void* pixels, int width, int height, int depth, int pitch, PixelFormatEnum format) - : this(Error.ReturnOrThrowOnFailure(SDL.CreateRGBSurfaceWithFormatFrom(pixels, width, height, depth, pitch, (uint)format))) - { } - - public Surface(void* pixels, int width, int height, int depth, int pitch, uint redMask, uint greenMask, uint blueMask, uint alphaMask) - : this(Error.ReturnOrThrowOnFailure(SDL.CreateRGBSurfaceFrom(pixels, width, height, depth, pitch, redMask, greenMask, blueMask, alphaMask))) - { } - - ~Surface() - { - Dispose(false); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool _) - { - if (_handle is null) - { - return; - } - - if (_freeHandle) - { - SDL.FreeSurface(_handle); - } - - _handle = null; - } - - public void Blit(Surface surface) - { - ThrowWhenDisposed(); - - if (surface is null) - { - throw new ArgumentNullException(nameof(surface)); - } - - Error.ThrowOnFailure( - SDL.Blit(_handle, null, surface._handle, null) - ); - } - - public Surface Convert(PixelFormatEnum format) - { - ThrowWhenDisposed(); - - return new Surface(SDL.ConvertSurfaceFormat(_handle, (uint)format, 0)); - } - - public void FillRect(uint color) - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.FillRect(_handle, null, color) - ); - } - - public void Lock() - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.LockSurface(_handle) - ); - } - - public void Unlock() - { - ThrowWhenDisposed(); - - SDL.UnlockSurface(_handle); - } - - private void ThrowWhenDisposed() - { - if (_handle is null) - { - throw new ObjectDisposedException(GetType().FullName); - } - } - - public static implicit operator SDL_Surface*(Surface surface) - { - if (surface is null) - { - throw new ArgumentNullException(nameof(surface)); - } - - return surface._handle; - } - } -} diff --git a/sources/SDL2Sharp/Surface{T}.cs b/sources/SDL2Sharp/Surface{T}.cs deleted file mode 100644 index ad4e6d02..00000000 --- a/sources/SDL2Sharp/Surface{T}.cs +++ /dev/null @@ -1,176 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using Microsoft.Toolkit.HighPerformance; -using SDL2Sharp.Interop; - -namespace SDL2Sharp -{ - public sealed unsafe class Surface : IDisposable where TPackedColor : struct - { - private SDL_Surface* _handle; - - private readonly bool _freeHandle; - - public PixelFormat Format => new(_handle->format, false); - - public int Width => _handle->w; - - public int Height => _handle->h; - - public int Pitch => _handle->pitch; - - public Span2D Pixels - { - get - { - // In SDL pitch is synonymous to stride, and is defined as the - // length of a row of pixels in bytes. Span2D, however, defines - // pitch as the difference between stride and width in pixels. - return new Span2D(_handle->pixels, _handle->h, _handle->w, - _handle->pitch - _handle->w * _handle->format->BytesPerPixel); - } - } - - public bool MustLock => ((_handle->flags & SDL.SDL_RLEACCEL) != 0); - - internal Surface(SDL_Surface* handle) - : this(handle, true) - { } - - internal Surface(SDL_Surface* handle, bool freeHandle) - { - if (handle is null) - { - throw new ArgumentNullException(nameof(handle)); - } - - _handle = handle; - _freeHandle = freeHandle; - } - - internal Surface(int width, int height, int depth, PixelFormatEnum format) - : this(SDL.CreateRGBSurfaceWithFormat(0, width, height, depth, (uint)format)) - { } - - internal Surface(int width, int height, int depth, uint redMask, uint greenMask, uint blueMask, uint alphaMask) - : this(SDL.CreateRGBSurface(0, width, height, depth, redMask, greenMask, blueMask, alphaMask)) - { } - - internal Surface(void* pixels, int width, int height, int depth, int pitch, PixelFormatEnum format) - : this(SDL.CreateRGBSurfaceWithFormatFrom(pixels, width, height, depth, pitch, (uint)format)) - { } - - internal Surface(void* pixels, int width, int height, int depth, int pitch, uint redMask, uint greenMask, uint blueMask, uint alphaMask) - : this(SDL.CreateRGBSurfaceFrom(pixels, width, height, depth, pitch, redMask, greenMask, blueMask, alphaMask)) - { } - - ~Surface() - { - Dispose(false); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool _) - { - if (_handle is null) - { - return; - } - - if (_freeHandle) - { - SDL.FreeSurface(_handle); - } - - _handle = null; - } - - public void Blit(Surface surface) - { - ThrowWhenDisposed(); - - if (surface is null) - { - throw new ArgumentNullException(nameof(surface)); - } - - Error.ThrowOnFailure( - SDL.Blit(_handle, null, surface._handle, null) - ); - } - - public Surface Convert(PixelFormatEnum format) - { - ThrowWhenDisposed(); - - return new Surface(SDL.ConvertSurfaceFormat(_handle, (uint)format, 0)); - } - - public void FillRect(uint color) - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.FillRect(_handle, null, color) - ); - } - - public void Lock() - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.LockSurface(_handle) - ); - } - - public void Unlock() - { - ThrowWhenDisposed(); - - SDL.UnlockSurface(_handle); - } - - private void ThrowWhenDisposed() - { - if (_handle is null) - { - throw new ObjectDisposedException(GetType().FullName); - } - } - - public static implicit operator SDL_Surface*(Surface surface) - { - if (surface is null) - { - throw new ArgumentNullException(nameof(surface)); - } - - return surface._handle; - } - } -} diff --git a/sources/SDL2Sharp/Texture.cs b/sources/SDL2Sharp/Texture.cs deleted file mode 100644 index 69d1293b..00000000 --- a/sources/SDL2Sharp/Texture.cs +++ /dev/null @@ -1,195 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using System.Runtime.InteropServices; -using SDL2Sharp.Interop; - -namespace SDL2Sharp -{ - public unsafe class Texture : IDisposable - { - private SDL_Texture* _handle; - - public PixelFormatEnum Format - { - get - { - uint format; - Error.ThrowOnFailure(SDL.QueryTexture(_handle, &format, null, null, null)); - return (PixelFormatEnum)format; - } - } - - public TextureAccess Access - { - get - { - int access; - Error.ThrowOnFailure(SDL.QueryTexture(_handle, null, &access, null, null)); - return (TextureAccess)access; - } - } - - public int Width - { - get - { - int width; - Error.ThrowOnFailure(SDL.QueryTexture(_handle, null, null, &width, null)); - return width; - } - } - - public int Height - { - get - { - int height; - Error.ThrowOnFailure(SDL.QueryTexture(_handle, null, null, null, &height)); - return height; - } - } - - public BlendMode BlendMode - { - get - { - SDL_BlendMode blendMode; - Error.ThrowOnFailure( - SDL.GetTextureBlendMode(_handle, &blendMode) - ); - return (BlendMode)blendMode; - } - set - { - Error.ThrowOnFailure( - SDL.SetTextureBlendMode(_handle, (SDL_BlendMode)value) - ); - } - } - - public bool IsValid => 0 == SDL.QueryTexture(_handle, null, null, null, null); - - internal Texture(SDL_Texture* texture) - { - if (texture is null) - { - throw new ArgumentNullException(nameof(texture)); - } - - _handle = texture; - } - - ~Texture() - { - Dispose(false); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool _) - { - if (_handle is null) return; - SDL.DestroyTexture(_handle); - _handle = null; - } - - public void WithLock(WithLockPackedImageCallback callback) - where TPackedColor : struct - { - WithLock(0, 0, Width, Height, callback); - } - - public void WithLock(Rectangle rectangle, WithLockPackedImageCallback callback) - where TPackedColor : struct - { - WithLock(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, callback); - } - - public void WithLock(int x, int y, int width, int height, WithLockPackedImageCallback callback) - where TPackedColor : struct - { - ThrowWhenDisposed(); - - var rect = new SDL_Rect { x = x, y = y, w = width, h = height }; - void* pixels; - int pitchInBytes; - Error.ThrowOnFailure( - SDL.LockTexture(_handle, &rect, &pixels, &pitchInBytes) - ); - - var bytesPerPixel = Marshal.SizeOf(); - var pitch = pitchInBytes / bytesPerPixel; - var image = new PackedImage(pixels, height, width, pitch); - callback.Invoke(image); - SDL.UnlockTexture(this); - } - - public void WithLock(WithLockSurfaceCallback callback) - where TPackedColor : struct - { - WithLock(0, 0, Width, Height, callback); - } - - public void WithLock(Rectangle rectangle, WithLockSurfaceCallback callback) - where TPackedColor : struct - { - WithLock(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, callback); - } - - public void WithLock(int x, int y, int width, int height, WithLockSurfaceCallback callback) - where TPackedColor : struct - { - ThrowWhenDisposed(); - - var rect = new SDL_Rect { x = x, y = y, w = width, h = height }; - SDL_Surface* surfaceHandle; - Error.ThrowOnFailure( - SDL.LockTextureToSurface(_handle, &rect, &surfaceHandle) - ); - var surface = new Surface(surfaceHandle, false); - callback.Invoke(surface); - SDL.UnlockTexture(this); - } - - protected void ThrowWhenDisposed() - { - if (_handle is null) - { - throw new ObjectDisposedException(GetType().FullName); - } - } - - public static implicit operator SDL_Texture*(Texture texture) - { - if (texture is null) - { - throw new ArgumentNullException(nameof(texture)); - } - - return texture._handle; - } - } -} diff --git a/sources/SDL2Sharp/Window.cs b/sources/SDL2Sharp/Window.cs deleted file mode 100644 index a19d3204..00000000 --- a/sources/SDL2Sharp/Window.cs +++ /dev/null @@ -1,779 +0,0 @@ -// SDL2Sharp -// -// Copyright (C) 2021-2024 Ronald van Manen -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source distribution. - -using System; -using SDL2Sharp.Internals; -using SDL2Sharp.Interop; -using System.Runtime.InteropServices; -using System.Collections.Generic; - -namespace SDL2Sharp -{ - public sealed unsafe class Window : IDisposable - { - public event EventHandler? Shown; - - public event EventHandler? Hidden; - - public event EventHandler? Exposed; - - public event EventHandler? Moved; - - public event EventHandler? Resized; - - public event EventHandler? SizeChanged; - - public event EventHandler? Minimized; - - public event EventHandler? Maximized; - - public event EventHandler? Restored; - - public event EventHandler? Enter; - - public event EventHandler? Leave; - - public event EventHandler? FocusGained; - - public event EventHandler? FocusLost; - - public event EventHandler? Close; - - public event EventHandler? TakeFocus; - - public event EventHandler? HitTest; - - public event EventHandler? KeyDown; - - public event EventHandler? KeyUp; - - public event EventHandler? MouseMotion; - - public event EventHandler? MouseWheel; - - private static readonly List _all = new(); - - private SDL_Window* _handle; - - private readonly HitTestCallbackDelegate _hitTestCallback; - - public static IReadOnlyList All => _all; - - public uint Id - { - get - { - ThrowWhenDisposed(); - - return SDL.GetWindowID(_handle); - } - } - - public string Title - { - get - { - ThrowWhenDisposed(); - - return new string(SDL.GetWindowTitle(_handle)); - } - set - { - ThrowWhenDisposed(); - - using (var marshaledValue = new MarshaledString(value)) - { - SDL.SetWindowTitle(_handle, marshaledValue); - } - } - } - - public Point Position - { - get - { - ThrowWhenDisposed(); - - int x, y; - SDL.GetWindowPosition(_handle, &x, &y); - return new Point(x, y); - } - set - { - ThrowWhenDisposed(); - - SDL.SetWindowPosition(_handle, value.X, value.Y); - } - } - - public int Width - { - get - { - ThrowWhenDisposed(); - - int width; - SDL.GetWindowSize(_handle, &width, null); - return width; - } - } - - public int Height - { - get - { - ThrowWhenDisposed(); - - int height; - SDL.GetWindowSize(_handle, null, &height); - return height; - } - } - - public Size Size - { - get - { - ThrowWhenDisposed(); - - int width, height; - SDL.GetWindowSize(_handle, &width, &height); - return new Size(width, height); - } - set - { - ThrowWhenDisposed(); - - SDL.SetWindowSize(_handle, value.Width, value.Height); - } - } - - public Size MinimumSize - { - get - { - ThrowWhenDisposed(); - - int width, height; - SDL.GetWindowMinimumSize(_handle, &width, &height); - return new Size(width, height); - } - set - { - ThrowWhenDisposed(); - - SDL.SetWindowMinimumSize(_handle, value.Width, value.Height); - } - } - - public Size MaximumSize - { - get - { - ThrowWhenDisposed(); - - int width, height; - SDL.GetWindowMaximumSize(_handle, &width, &height); - return new Size(width, height); - } - set - { - ThrowWhenDisposed(); - - SDL.SetWindowMaximumSize(_handle, value.Width, value.Height); - } - } - - public Size ClientSize - { - get - { - ThrowWhenDisposed(); - - int borderTop, borderLeft, borderBottom, borderRight; - Error.ThrowOnFailure( - SDL.GetWindowBordersSize(_handle, &borderTop, &borderLeft, &borderBottom, &borderRight) - ); - int windowWidth, windowHeight; - SDL.GetWindowSize(_handle, &windowWidth, &windowHeight); - var clientWidth = windowWidth - borderRight - borderLeft; - var clientHeight = windowHeight - borderBottom - borderTop; - return new Size(clientWidth, clientHeight); - } - } - - public PixelFormatEnum PixelFormat - { - get - { - ThrowWhenDisposed(); - - var pixelFormat = SDL.GetWindowPixelFormat(_handle); - Error.ThrowOnFailure(pixelFormat); - return (PixelFormatEnum)pixelFormat; - } - } - - public Surface Surface - { - get - { - ThrowWhenDisposed(); - - var surfaceHandle = SDL.GetWindowSurface(_handle); - Error.ThrowOnFailure(surfaceHandle); - return new Surface(surfaceHandle, false); - } - } - - public bool IsBordered - { - get - { - const uint flag = (uint)SDL_WindowFlags.SDL_WINDOW_BORDERLESS; - var flags = SDL.GetWindowFlags(_handle); - return (flags & flag) == 0; - } - set - { - ThrowWhenDisposed(); - - SDL.SetWindowBordered(_handle, value ? SDL_bool.SDL_TRUE : SDL_bool.SDL_FALSE); - } - } - - - public bool IsResizable - { - get - { - ThrowWhenDisposed(); - - const uint flag = (uint)SDL_WindowFlags.SDL_WINDOW_RESIZABLE; - var flags = SDL.GetWindowFlags(_handle); - return (flags & flag) != 0; - } - set - { - ThrowWhenDisposed(); - - SDL.SetWindowResizable(_handle, value ? SDL_bool.SDL_TRUE : SDL_bool.SDL_FALSE); - } - } - - public bool IsFullScreen - { - get - { - ThrowWhenDisposed(); - - const uint flag = (uint)SDL_WindowFlags.SDL_WINDOW_FULLSCREEN; - var flags = SDL.GetWindowFlags(_handle); - return (flags & flag) != 0; - } - set - { - ThrowWhenDisposed(); - - const uint flag = (uint)SDL_WindowFlags.SDL_WINDOW_FULLSCREEN; - Error.ThrowOnFailure( - SDL.SetWindowFullscreen(_handle, value ? flag : 0u) - ); - } - } - - public bool IsFullScreenDesktop - { - get - { - ThrowWhenDisposed(); - - const uint flag = (uint)SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP; - var flags = SDL.GetWindowFlags(_handle); - return (flags & flag) != 0; - } - set - { - ThrowWhenDisposed(); - - const uint flag = (uint)SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP; - Error.ThrowOnFailure( - SDL.SetWindowFullscreen(_handle, value ? flag : 0u) - ); - } - } - - public bool IsVisible - { - get - { - ThrowWhenDisposed(); - - const uint flag = (uint)SDL_WindowFlags.SDL_WINDOW_SHOWN; - var flags = SDL.GetWindowFlags(_handle); - return (flags & flag) != 0; - } - } - - public Window(string title, int width, int height) - : this(title, (int)SDL.SDL_WINDOWPOS_UNDEFINED, (int)SDL.SDL_WINDOWPOS_UNDEFINED, width, height, (uint)0) - { } - - public Window(string title, int width, int height, WindowFlags flags) - : this(title, (int)SDL.SDL_WINDOWPOS_UNDEFINED, (int)SDL.SDL_WINDOWPOS_UNDEFINED, width, height, (uint)flags) - { } - - public Window(string title, int x, int y, int width, int height) - : this(title, x, y, width, height, (uint)0) - { } - - public Window(string title, int x, int y, int width, int height, WindowFlags flags) - : this(title, x, y, width, height, (uint)flags) - { } - - private Window(string title, int x, int y, int width, int height, uint flags) - { - using (var marshaledTitle = new MarshaledString(title)) - { - _handle = Error.ReturnOrThrowOnFailure( - SDL.CreateWindow(marshaledTitle, x, y, width, height, flags) - ); - - if (!IsBordered) - { - _hitTestCallback = new HitTestCallbackDelegate(HitTestCallback); - var hitTestCallback = Marshal.GetFunctionPointerForDelegate(_hitTestCallback); - Error.ThrowOnFailure( - SDL.SetWindowHitTest(_handle, hitTestCallback, null) - ); - } - else - { - _hitTestCallback = null!; - } - } - - _all.Add(this); - } - - ~Window() - { - Dispose(false); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool _) - { - if (_handle is null) - { - return; - } - - SDL.DestroyWindow(_handle); - _all.Remove(this); - _handle = null; - } - - public void Show() - { - ThrowWhenDisposed(); - - SDL.ShowWindow(_handle); - } - - public void Hide() - { - ThrowWhenDisposed(); - - SDL.HideWindow(_handle); - } - - public void Raise() - { - ThrowWhenDisposed(); - - SDL.RaiseWindow(_handle); - } - - public void Maximize() - { - ThrowWhenDisposed(); - - SDL.MaximizeWindow(_handle); - } - - public void Minimize() - { - ThrowWhenDisposed(); - - SDL.MinimizeWindow(_handle); - } - - public void Restore() - { - ThrowWhenDisposed(); - - SDL.RestoreWindow(_handle); - } - - public Renderer CreateRenderer() - { - return CreateRenderer(RendererFlags.None); - } - - public Renderer CreateRenderer(RendererFlags flags) - { - if (!TryCreateRenderer(flags, out var renderer, out var error)) - { - throw error; - } - - return renderer; - } - - public bool TryCreateRenderer(out Renderer renderer) - { - return TryCreateRenderer(RendererFlags.None, out renderer); - } - - public bool TryCreateRenderer(RendererFlags flags, out Renderer renderer) - { - return TryCreateRenderer(flags, out renderer, out _); - } - - public bool TryCreateRenderer(RendererFlags flags, out Renderer renderer, out Error error) - { - ThrowWhenDisposed(); - - var handle = SDL.CreateRenderer(_handle, -1, (uint)flags); - if (handle is null) - { - error = new Error(new string(SDL.GetError())); - renderer = null!; - return false; - } - else - { - error = null!; - renderer = new Renderer(handle); - return true; - } - } - - public void Update() - { - ThrowWhenDisposed(); - - Error.ThrowOnFailure( - SDL.UpdateWindowSurface(_handle) - ); - } - - private void ThrowWhenDisposed() - { - if (_handle is null) - { - throw new ObjectDisposedException(GetType().FullName); - } - } - - internal void HandleKeyDownEvent(SDL_KeyboardEvent @event) - { - OnKeyDown( - new KeyEventArgs( - (Scancode)@event.keysym.scancode, - (KeyCode)@event.keysym.sym, - (KeyModifiers)@event.keysym.mod, - @event.repeat - ) - ); - } - - internal void HandleKeyUpEvent(SDL_KeyboardEvent @event) - { - OnKeyUp( - new KeyEventArgs( - (Scancode)@event.keysym.scancode, - (KeyCode)@event.keysym.sym, - (KeyModifiers)@event.keysym.mod, - @event.repeat - ) - ); - } - - internal void HandleMouseMotionEvent(SDL_MouseMotionEvent @event) - { - OnMouseMotion( - new MouseMotionEventArgs( - @event.x, - @event.y, - @event.xrel, - @event.yrel - ) - ); - } - - internal void HandleMouseWheelEvent(SDL_MouseWheelEvent @event) - { - OnMouseWheelEvent( - new MouseWheelEventArgs( - @event.which, - (MouseWheelDirection)@event.direction, - @event.x, - @event.y, - @event.preciseX, - @event.preciseY - ) - ); - } - - internal void HandleWindowEvent(SDL_WindowEvent windowEvent) - { - switch ((SDL_WindowEventID)windowEvent.@event) - { - case SDL_WindowEventID.SDL_WINDOWEVENT_SHOWN: - OnShown(); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_HIDDEN: - OnHidden(); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_EXPOSED: - OnExposed(); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_MOVED: - OnMoved(windowEvent.data1, windowEvent.data2); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED: - OnResized(windowEvent.data1, windowEvent.data2); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED: - OnSizeChanged(windowEvent.data1, windowEvent.data2); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED: - OnMinimized(); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_MAXIMIZED: - OnMaximized(); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_RESTORED: - OnRestored(); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_ENTER: - OnEnter(); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE: - OnLeave(); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: - OnFocusGained(); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: - OnFocusLost(); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE: - OnClose(); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_TAKE_FOCUS: - OnTakeFocus(); - break; - case SDL_WindowEventID.SDL_WINDOWEVENT_HIT_TEST: - OnHitTest(); - break; - } - } - - private void OnShown() - { - Shown?.Invoke(this, EventArgs.Empty); - } - - private void OnHidden() - { - Hidden?.Invoke(this, EventArgs.Empty); - } - - private void OnExposed() - { - Exposed?.Invoke(this, EventArgs.Empty); - } - - private void OnMoved(int x, int y) - { - Moved?.Invoke(this, new WindowMovedEventArgs(x, y)); - } - - private void OnResized(int width, int height) - { - Resized?.Invoke(this, new WindowResizedEventArgs(width, height)); - } - - private void OnSizeChanged(int width, int height) - { - SizeChanged?.Invoke(this, new WindowSizeChangedEventArgs(width, height)); - } - - private void OnMinimized() - { - Minimized?.Invoke(this, EventArgs.Empty); - } - - private void OnMaximized() - { - Maximized?.Invoke(this, EventArgs.Empty); - } - - private void OnRestored() - { - Restored?.Invoke(this, EventArgs.Empty); - } - - private void OnEnter() - { - Enter?.Invoke(this, EventArgs.Empty); - } - - private void OnLeave() - { - Leave?.Invoke(this, EventArgs.Empty); - } - - private void OnFocusGained() - { - FocusGained?.Invoke(this, EventArgs.Empty); - } - - private void OnFocusLost() - { - FocusLost?.Invoke(this, EventArgs.Empty); - } - - private void OnClose() - { - Close?.Invoke(this, EventArgs.Empty); - } - - private void OnTakeFocus() - { - TakeFocus?.Invoke(this, EventArgs.Empty); - } - - private void OnHitTest() - { - HitTest?.Invoke(this, EventArgs.Empty); - } - - private void OnKeyDown(KeyEventArgs eventArgs) - { - KeyDown?.Invoke(this, eventArgs); - } - - private void OnKeyUp(KeyEventArgs eventArgs) - { - KeyUp?.Invoke(this, eventArgs); - } - - private void OnMouseMotion(MouseMotionEventArgs eventArgs) - { - MouseMotion?.Invoke(this, eventArgs); - } - - private void OnMouseWheelEvent(MouseWheelEventArgs eventArgs) - { - MouseWheel?.Invoke(this, eventArgs); - } - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate SDL_HitTestResult HitTestCallbackDelegate(SDL_Window* win, SDL_Point* area, void* data); - - private static unsafe SDL_HitTestResult HitTestCallback(SDL_Window* win, SDL_Point* area, void* data) - { - int x = area->x; - int y = area->y; - - int windowWidth = 0, windowHeight = 0; - SDL.GetWindowSize(win, &windowWidth, &windowHeight); - - int windowTop = 0; - int windowLeft = 0; - int windowBottom = windowTop + windowHeight; - int windowRight = windowLeft + windowWidth; - - int borderTop = 0, borderLeft = 0, borderBottom = 0, borderRight = 0; - SDL.GetWindowBordersSize(win, &borderTop, &borderLeft, &borderBottom, &borderRight); - - int clientAreaTop = windowTop + borderTop; - int clientAreaLeft = windowLeft + borderLeft; - int clientAreaBottom = windowBottom - borderBottom; - int clientAreaRight = windowRight - borderRight; - - if (y > windowTop && y < clientAreaTop) - { - return SDL_HitTestResult.SDL_HITTEST_DRAGGABLE; - } - - if (y >= windowTop && y <= clientAreaTop) - { - if (x >= windowLeft && x <= clientAreaLeft) - { - return SDL_HitTestResult.SDL_HITTEST_RESIZE_TOPLEFT; - } - - if (x >= clientAreaRight && x <= windowRight) - { - return SDL_HitTestResult.SDL_HITTEST_RESIZE_TOPRIGHT; - } - - return SDL_HitTestResult.SDL_HITTEST_RESIZE_TOP; - } - - if (y >= clientAreaBottom && y <= windowBottom) - { - if (x >= windowLeft && x <= clientAreaLeft) - { - return SDL_HitTestResult.SDL_HITTEST_RESIZE_BOTTOMLEFT; - } - - if (x >= clientAreaRight && x <= windowRight) - { - return SDL_HitTestResult.SDL_HITTEST_RESIZE_BOTTOMRIGHT; - } - - return SDL_HitTestResult.SDL_HITTEST_RESIZE_BOTTOM; - } - - if (x >= windowLeft && x <= clientAreaLeft) - { - return SDL_HitTestResult.SDL_HITTEST_RESIZE_LEFT; - } - - if (x >= clientAreaRight && x <= windowRight) - { - return SDL_HitTestResult.SDL_HITTEST_RESIZE_RIGHT; - } - - return SDL_HitTestResult.SDL_HITTEST_NORMAL; - } - } -} diff --git a/sources/SDL2Sharp/AudioChannelLayout.cs b/sources/SDL2Sharp/audio/AudioChannelLayout.cs similarity index 98% rename from sources/SDL2Sharp/AudioChannelLayout.cs rename to sources/SDL2Sharp/audio/AudioChannelLayout.cs index dde80dc6..5165d7fd 100644 --- a/sources/SDL2Sharp/AudioChannelLayout.cs +++ b/sources/SDL2Sharp/audio/AudioChannelLayout.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // diff --git a/sources/SDL2Sharp/audio/AudioConstants.cs b/sources/SDL2Sharp/audio/AudioConstants.cs new file mode 100644 index 00000000..be2e731d --- /dev/null +++ b/sources/SDL2Sharp/audio/AudioConstants.cs @@ -0,0 +1,27 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +namespace SDL2Sharp +{ + public static class AudioConstants + { + public const int MixMaxVolume = Interop.SDL.SDL_MIX_MAXVOLUME; + } +} diff --git a/sources/SDL2Sharp/audio/AudioDevice.cs b/sources/SDL2Sharp/audio/AudioDevice.cs new file mode 100644 index 00000000..fe803064 --- /dev/null +++ b/sources/SDL2Sharp/audio/AudioDevice.cs @@ -0,0 +1,257 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed unsafe class AudioDevice : IDisposable + { + private uint _deviceID = 0; + + private AudioDeviceCallback _callback = null!; + + private GCHandle _callbackUserData = default; + + private bool _disposed = false; + + public bool IsDisposed => _disposed; + + public bool IsOpen => _deviceID != 0; + + public int Frequency { get; private set; } + + public AudioFormat Format { get; private set; } + + public AudioChannelLayout Channels { get; private set; } + + public byte Silence { get; private set; } + + public ushort Samples { get; private set; } + + public uint Size { get; private set; } + + public AudioStatus Status => (AudioStatus)Interop.SDL.GetAudioDeviceStatus(_deviceID); + + internal AudioDevice() + { } + + internal AudioDevice(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples) + : this(frequency, format, channels, samples, null!) + { } + + internal AudioDevice(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples, AudioDeviceCallback callback) + : this(frequency, format, channels, samples, callback, AudioDeviceAllowedChanges.None) + { } + + internal AudioDevice(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples, AudioDeviceCallback callback, AudioDeviceAllowedChanges allowedChanges) + { + Open(frequency, format, channels, samples, callback, allowedChanges); + } + + ~AudioDevice() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool _) + { + if (!_disposed) + { + try + { + Close(); + } + finally + { + _disposed = true; + } + } + } + + public void Open(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples) + { + Open(frequency, format, channels, samples, null!); + } + + public void Open(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples, AudioDeviceCallback callback) + { + Open(frequency, format, channels, samples, callback, AudioDeviceAllowedChanges.None); + } + + public void Open(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples, AudioDeviceCallback callback, AudioDeviceAllowedChanges allowedChanges) + { + if (!TryOpen(frequency, format, channels, samples, callback, allowedChanges, out var error)) + { + throw error; + } + } + + public bool TryOpen(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples, out Error error) + { + return TryOpen(frequency, format, channels, samples, null!, out error); + } + + public bool TryOpen(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples, AudioDeviceCallback callback, out Error error) + { + return TryOpen(frequency, format, channels, samples, callback, AudioDeviceAllowedChanges.None, out error); + } + + public bool TryOpen(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples, AudioDeviceCallback callback, AudioDeviceAllowedChanges allowedChanges, out Error error) + { + ThrowIfDisposed(); + ThrowIfOpen(); + + var desiredSpec = new SDL_AudioSpec + { + freq = frequency, + format = (ushort)format, + channels = (byte)channels, + silence = 0, + samples = samples, + padding = 0, + size = 0 + }; + + if (callback != null) + { + _callback = callback; + _callbackUserData = GCHandle.Alloc(this, GCHandleType.Normal); + desiredSpec.callback = &OnAudioDeviceCallback; + desiredSpec.userdata = (void*)(IntPtr)_callbackUserData; + } + + var obtainedSpec = new SDL_AudioSpec(); + _deviceID = Interop.SDL.OpenAudioDevice(null, 0, &desiredSpec, &obtainedSpec, (int)allowedChanges); + if (_deviceID == 0) + { + error = Error.GetLastError(); + return false; + } + else + { + Frequency = obtainedSpec.freq; + Format = (AudioFormat)obtainedSpec.format; + Channels = (AudioChannelLayout)obtainedSpec.channels; + Silence = obtainedSpec.silence; + Samples = obtainedSpec.samples; + Size = obtainedSpec.size; + error = null!; + return true; + } + } + + public void Close() + { + ThrowIfDisposed(); + + if (_deviceID != 0) + { + Interop.SDL.CloseAudioDevice(_deviceID); + _deviceID = 0; + _callback = null!; + if (_callbackUserData.IsAllocated) + { + _callbackUserData.Free(); + } + } + } + + public void Pause() + { + ThrowIfDisposed(); + ThrowIfClosed(); + Interop.SDL.PauseAudioDevice(_deviceID, 1); + } + + public void Unpause() + { + ThrowIfDisposed(); + ThrowIfClosed(); + Interop.SDL.PauseAudioDevice(_deviceID, 0); + } + + public void Lock() + { + ThrowIfDisposed(); + ThrowIfClosed(); + Interop.SDL.LockAudioDevice(_deviceID); + } + + public void Unlock() + { + ThrowIfDisposed(); + ThrowIfClosed(); + Interop.SDL.UnlockAudioDevice(_deviceID); + } + + public void Queue(Span buffer) + { + ThrowIfDisposed(); + ThrowIfClosed(); + fixed (void* data = &buffer[0]) + { + Error.ThrowLastErrorIfNegative( + Interop.SDL.QueueAudio(_deviceID, data, (uint)buffer.Length) + ); + } + } + + private void ThrowIfOpen() + { + if (IsOpen) + { + throw new InvalidOperationException("The Audio Device is open"); + } + } + + private void ThrowIfClosed() + { + if (!IsOpen) + { + throw new InvalidOperationException("The Audio Device is closed"); + } + } + + private void ThrowIfDisposed() + { + ObjectDisposedException.ThrowIf(IsDisposed, this); + } + + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])] + private static void OnAudioDeviceCallback(void* userdata, byte* stream, int len) + { + var audioDeviceHandle = GCHandle.FromIntPtr((IntPtr)userdata); + if (audioDeviceHandle.Target is AudioDevice audioDevice) + { + audioDevice._callback(new Span(stream, len)); + } + } + } +} diff --git a/sources/SDL2Sharp/AudioDeviceAllowedChanges.cs b/sources/SDL2Sharp/audio/AudioDeviceAllowedChanges.cs similarity index 76% rename from sources/SDL2Sharp/AudioDeviceAllowedChanges.cs rename to sources/SDL2Sharp/audio/AudioDeviceAllowedChanges.cs index 989d3eef..51236744 100644 --- a/sources/SDL2Sharp/AudioDeviceAllowedChanges.cs +++ b/sources/SDL2Sharp/audio/AudioDeviceAllowedChanges.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // @@ -18,7 +18,6 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using SDL2Sharp.Interop; using System; namespace SDL2Sharp @@ -27,10 +26,10 @@ namespace SDL2Sharp public enum AudioDeviceAllowedChanges { None = 0, - Frequency = SDL.SDL_AUDIO_ALLOW_FREQUENCY_CHANGE, - Format = SDL.SDL_AUDIO_ALLOW_FORMAT_CHANGE, - Channels = SDL.SDL_AUDIO_ALLOW_CHANNELS_CHANGE, - Samples = SDL.SDL_AUDIO_ALLOW_SAMPLES_CHANGE, - Any = SDL.SDL_AUDIO_ALLOW_ANY_CHANGE, + Frequency = Interop.SDL.SDL_AUDIO_ALLOW_FREQUENCY_CHANGE, + Format = Interop.SDL.SDL_AUDIO_ALLOW_FORMAT_CHANGE, + Channels = Interop.SDL.SDL_AUDIO_ALLOW_CHANNELS_CHANGE, + Samples = Interop.SDL.SDL_AUDIO_ALLOW_SAMPLES_CHANGE, + Any = Interop.SDL.SDL_AUDIO_ALLOW_ANY_CHANGE, } } diff --git a/sources/SDL2Sharp/AudioDeviceCallback.cs b/sources/SDL2Sharp/audio/AudioDeviceCallback.cs similarity index 90% rename from sources/SDL2Sharp/AudioDeviceCallback.cs rename to sources/SDL2Sharp/audio/AudioDeviceCallback.cs index bf84a694..0846902e 100644 --- a/sources/SDL2Sharp/AudioDeviceCallback.cs +++ b/sources/SDL2Sharp/audio/AudioDeviceCallback.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // @@ -22,5 +22,5 @@ namespace SDL2Sharp { - public delegate void AudioDeviceCallback(object userdata, Span stream); + public delegate void AudioDeviceCallback(Span stream); } diff --git a/sources/SDL2Sharp/AudioFormat.cs b/sources/SDL2Sharp/audio/AudioFormat.cs similarity index 53% rename from sources/SDL2Sharp/AudioFormat.cs rename to sources/SDL2Sharp/audio/AudioFormat.cs index 11cf9780..ec9e9c3a 100644 --- a/sources/SDL2Sharp/AudioFormat.cs +++ b/sources/SDL2Sharp/audio/AudioFormat.cs @@ -18,29 +18,29 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using SDL2Sharp.Interop; - namespace SDL2Sharp { public enum AudioFormat : ushort { - U8 = SDL.AUDIO_U8, - S8 = SDL.AUDIO_S8, - U16LSB = SDL.AUDIO_U16LSB, - S16LSB = SDL.AUDIO_S16LSB, - U16MSB = SDL.AUDIO_U16MSB, - S16MSB = SDL.AUDIO_S16MSB, - U16 = SDL.AUDIO_U16, - S16 = SDL.AUDIO_S16, - S32LSB = SDL.AUDIO_S32LSB, - S32MSB = SDL.AUDIO_S32MSB, - S32 = SDL.AUDIO_S32, - F32LSB = SDL.AUDIO_F32LSB, - F32MSB = SDL.AUDIO_F32MSB, - F32 = SDL.AUDIO_F32, - U16SYS = SDL.AUDIO_U16SYS, - S16SYS = SDL.AUDIO_S16SYS, - S32SYS = SDL.AUDIO_S32SYS, - F32SYS = SDL.AUDIO_F32SYS +#pragma warning disable CA1069 // Enums values should not be duplicated + U8 = Interop.SDL.AUDIO_U8, + S8 = Interop.SDL.AUDIO_S8, + U16LSB = Interop.SDL.AUDIO_U16LSB, + S16LSB = Interop.SDL.AUDIO_S16LSB, + U16MSB = Interop.SDL.AUDIO_U16MSB, + S16MSB = Interop.SDL.AUDIO_S16MSB, + U16 = Interop.SDL.AUDIO_U16, + S16 = Interop.SDL.AUDIO_S16, + S32LSB = Interop.SDL.AUDIO_S32LSB, + S32MSB = Interop.SDL.AUDIO_S32MSB, + S32 = Interop.SDL.AUDIO_S32, + F32LSB = Interop.SDL.AUDIO_F32LSB, + F32MSB = Interop.SDL.AUDIO_F32MSB, + F32 = Interop.SDL.AUDIO_F32, + U16SYS = Interop.SDL.AUDIO_U16SYS, + S16SYS = Interop.SDL.AUDIO_S16SYS, + S32SYS = Interop.SDL.AUDIO_S32SYS, + F32SYS = Interop.SDL.AUDIO_F32SYS +#pragma warning restore CA1069 // Enums values should not be duplicated } } diff --git a/sources/SDL2Sharp/Extensions/AudioFormatExtensions.cs b/sources/SDL2Sharp/audio/AudioFormatExtensions.cs similarity index 82% rename from sources/SDL2Sharp/Extensions/AudioFormatExtensions.cs rename to sources/SDL2Sharp/audio/AudioFormatExtensions.cs index 7c1b10a0..7181ca5a 100644 --- a/sources/SDL2Sharp/Extensions/AudioFormatExtensions.cs +++ b/sources/SDL2Sharp/audio/AudioFormatExtensions.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // @@ -18,30 +18,28 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using SDL2Sharp.Interop; - -namespace SDL2Sharp.Extensions +namespace SDL2Sharp { public static class AudioFormatExtensions { public static int BitSize(this AudioFormat format) { - return (ushort)format & SDL.SDL_AUDIO_MASK_BITSIZE; + return (ushort)format & Interop.SDL.SDL_AUDIO_MASK_BITSIZE; } public static bool IsFloat(this AudioFormat format) { - return ((ushort)format & SDL.SDL_AUDIO_MASK_DATATYPE) != 0; + return ((ushort)format & Interop.SDL.SDL_AUDIO_MASK_DATATYPE) != 0; } public static bool IsBigEndian(this AudioFormat format) { - return ((ushort)format & SDL.SDL_AUDIO_MASK_ENDIAN) != 0; + return ((ushort)format & Interop.SDL.SDL_AUDIO_MASK_ENDIAN) != 0; } public static bool IsSigned(this AudioFormat format) { - return ((ushort)format & SDL.SDL_AUDIO_MASK_SIGNED) != 0; + return ((ushort)format & Interop.SDL.SDL_AUDIO_MASK_SIGNED) != 0; } public static bool IsInt(this AudioFormat format) diff --git a/sources/SDL2Sharp/audio/AudioStatus.cs b/sources/SDL2Sharp/audio/AudioStatus.cs new file mode 100644 index 00000000..695d33ae --- /dev/null +++ b/sources/SDL2Sharp/audio/AudioStatus.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using static SDL2Sharp.Interop.SDL_AudioStatus; + +namespace SDL2Sharp +{ + public enum AudioStatus : ushort + { + Stopped = SDL_AUDIO_STOPPED, + Playing = SDL_AUDIO_PLAYING, + Paused = SDL_AUDIO_PAUSED + } +} diff --git a/sources/SDL2Sharp/audio/AudioSubsystem.cs b/sources/SDL2Sharp/audio/AudioSubsystem.cs new file mode 100644 index 00000000..b52a9c7b --- /dev/null +++ b/sources/SDL2Sharp/audio/AudioSubsystem.cs @@ -0,0 +1,80 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +namespace SDL2Sharp +{ + internal sealed class AudioSubsystem : FinalizableObject, IAudioSubsystem + { + private const uint InitSubsystemFlags = Interop.SDL.SDL_INIT_AUDIO; + + private bool _fullyInitialized; + + public AudioSubsystem() + { + Error.ThrowLastErrorIfNegative( + Interop.SDL.InitSubSystem(InitSubsystemFlags) + ); + + _fullyInitialized = true; + } + + protected override void Dispose(bool disposing) + { + if (!_fullyInitialized) return; + Interop.SDL.QuitSubSystem(InitSubsystemFlags); + _fullyInitialized = false; + } + + public AudioDevice CreateDevice() + { + ThrowIfDisposed(); + + return new AudioDevice(); + } + + public AudioDevice OpenDevice(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples) + { + ThrowIfDisposed(); + + return new AudioDevice(frequency, format, channels, samples); + } + + public AudioDevice OpenDevice(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples, AudioDeviceCallback callback) + { + ThrowIfDisposed(); + + return new AudioDevice(frequency, format, channels, samples, callback); + } + + public AudioDevice OpenDevice(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples, AudioDeviceCallback callback, AudioDeviceAllowedChanges allowedChanges) + { + ThrowIfDisposed(); + + return new AudioDevice(frequency, format, channels, samples, callback, allowedChanges); + } + + public WaveFile OpenWaveFile(string filename) + { + ThrowIfDisposed(); + + return new WaveFile(filename); + } + } +} diff --git a/sources/SDL2Sharp/audio/IAudioSubsystem.cs b/sources/SDL2Sharp/audio/IAudioSubsystem.cs new file mode 100644 index 00000000..52ffec67 --- /dev/null +++ b/sources/SDL2Sharp/audio/IAudioSubsystem.cs @@ -0,0 +1,35 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +namespace SDL2Sharp +{ + public interface IAudioSubsystem + { + AudioDevice CreateDevice(); + + AudioDevice OpenDevice(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples); + + AudioDevice OpenDevice(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples, AudioDeviceCallback callback); + + AudioDevice OpenDevice(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples, AudioDeviceCallback callback, AudioDeviceAllowedChanges allowedChanges); + + WaveFile OpenWaveFile(string filename); + } +} diff --git a/sources/SDL2Sharp.Extensions/ReadOnlySpanExtensions.cs b/sources/SDL2Sharp/audio/ReadOnlySpanExtensions.cs similarity index 96% rename from sources/SDL2Sharp.Extensions/ReadOnlySpanExtensions.cs rename to sources/SDL2Sharp/audio/ReadOnlySpanExtensions.cs index f46a20f0..e81de883 100644 --- a/sources/SDL2Sharp.Extensions/ReadOnlySpanExtensions.cs +++ b/sources/SDL2Sharp/audio/ReadOnlySpanExtensions.cs @@ -20,17 +20,12 @@ using System; -namespace SDL2Sharp.Extensions +namespace SDL2Sharp { public static class ReadOnlySpanExtensions { public static unsafe short ToInt16(this ReadOnlySpan bytes, int sampleOffset, bool isLittleEndian) { - if (bytes == null) - { - throw new ArgumentNullException(nameof(bytes)); - } - if (sampleOffset < 0) { throw new ArgumentOutOfRangeException(nameof(sampleOffset), sampleOffset, "startIndex cannot be less than zero"); @@ -65,11 +60,6 @@ public static unsafe ushort ToUInt16(this ReadOnlySpan bytes, int sampleOf public static unsafe int ToInt32(this ReadOnlySpan bytes, int sampleOffset, bool isLittleEndian) { - if (bytes == null) - { - throw new ArgumentNullException(nameof(bytes)); - } - if (sampleOffset < 0) { throw new ArgumentOutOfRangeException(nameof(sampleOffset), sampleOffset, "startIndex cannot be less than zero"); diff --git a/sources/SDL2Sharp.Extensions/SpanExtensions.cs b/sources/SDL2Sharp/audio/StaticMethods.cs similarity index 69% rename from sources/SDL2Sharp.Extensions/SpanExtensions.cs rename to sources/SDL2Sharp/audio/StaticMethods.cs index 8437b3f3..72f2e116 100644 --- a/sources/SDL2Sharp.Extensions/SpanExtensions.cs +++ b/sources/SDL2Sharp/audio/StaticMethods.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // @@ -19,30 +19,29 @@ // 3. This notice may not be removed or altered from any source distribution. using System; -using SDL2Sharp.Interop; -namespace SDL2Sharp.Extensions +namespace SDL2Sharp { - public static class SpanExtensions + public static partial class StaticMethods { - public static unsafe void MixAudioFormat(this Span destination, Span source, AudioFormat format, int volume) + public static unsafe void MixAudioFormat(Span destination, Span source, AudioFormat format, int volume) { fixed (byte* dst = destination) { fixed (byte* src = source) { - SDL.MixAudioFormat(dst, src, (ushort)format, (uint)source.Length, volume); + Interop.SDL.MixAudioFormat(dst, src, (ushort)format, (uint)source.Length, volume); } } } - public static unsafe void MixAudioFormat(this Span destination, ReadOnlySpan source, AudioFormat format, int volume) + public static unsafe void MixAudioFormat(Span destination, ReadOnlySpan source, AudioFormat format, int volume) { fixed (byte* dst = destination) { fixed (byte* src = source) { - SDL.MixAudioFormat(dst, src, (ushort)format, (uint)source.Length, volume); + Interop.SDL.MixAudioFormat(dst, src, (ushort)format, (uint)source.Length, volume); } } } diff --git a/sources/SDL2Sharp/WaveFile.cs b/sources/SDL2Sharp/audio/WaveFile.cs similarity index 56% rename from sources/SDL2Sharp/WaveFile.cs rename to sources/SDL2Sharp/audio/WaveFile.cs index 2cd11420..9b7e8b5a 100644 --- a/sources/SDL2Sharp/WaveFile.cs +++ b/sources/SDL2Sharp/audio/WaveFile.cs @@ -19,12 +19,11 @@ // 3. This notice may not be removed or altered from any source distribution. using System; -using SDL2Sharp.Internals; using SDL2Sharp.Interop; namespace SDL2Sharp { - public sealed unsafe class WaveFile : IDisposable + public sealed unsafe class WaveFile : FinalizableObject { private SDL_AudioSpec _waveSpec; @@ -32,48 +31,47 @@ public sealed unsafe class WaveFile : IDisposable private uint _waveLength; - public AudioDeviceSpec Spec => new(_waveSpec); + public int Frequency => _waveSpec.freq; + + public AudioFormat Format => (AudioFormat)_waveSpec.format; + + public AudioChannelLayout Channels => (AudioChannelLayout)_waveSpec.channels; + + public byte Silence => _waveSpec.silence; + + public ushort Samples => _waveSpec.samples; + + public uint Size => _waveSpec.size; public ReadOnlySpan Buffer => new(_waveBuffer, (int)_waveLength); public uint Length => _waveLength; - public WaveFile(string filename) + internal WaveFile(string filename) { - using (var unmanagedFilename = new MarshaledString(filename)) - using (var unmanagedMode = new MarshaledString("rb")) + using var unmanagedFilename = new MarshaledString(filename); + using var unmanagedMode = new MarshaledString("rb"); + var fileStream = Error.ThrowLastErrorIfNull( + Interop.SDL.RWFromFile(unmanagedFilename, unmanagedMode) + ); + + fixed (SDL_AudioSpec* waveSpec = &_waveSpec) + fixed (byte** waveBuffer = &_waveBuffer) + fixed (uint* waveLength = &_waveLength) { - var fileStream = Error.ReturnOrThrowOnFailure( - SDL.RWFromFile(unmanagedFilename, unmanagedMode) + Error.ThrowLastErrorIfNull( + Interop.SDL.LoadWAV_RW(fileStream, 1, waveSpec, waveBuffer, waveLength) ); - - fixed (SDL_AudioSpec* waveSpec = &_waveSpec) - fixed (byte** waveBuffer = &_waveBuffer) - fixed (uint* waveLength = &_waveLength) - { - Error.ThrowOnFailure( - SDL.LoadWAV_RW(fileStream, 1, waveSpec, waveBuffer, waveLength) - ); - } } } - ~WaveFile() - { - Dispose(false); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } + ~WaveFile() => Dispose(false); - private void Dispose(bool _) + protected override void Dispose(bool _) { if (_waveBuffer != null) { - SDL.FreeWAV(_waveBuffer); + Interop.SDL.FreeWAV(_waveBuffer); _waveSpec = default; _waveBuffer = null; _waveLength = 0; diff --git a/sources/SDL2Sharp/basics/DisposableObject.cs b/sources/SDL2Sharp/basics/DisposableObject.cs new file mode 100644 index 00000000..c12c2664 --- /dev/null +++ b/sources/SDL2Sharp/basics/DisposableObject.cs @@ -0,0 +1,51 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Threading; + +namespace SDL2Sharp +{ + public abstract class DisposableObject : IDisposable + { + private volatile uint _disposed = 0; + + public bool IsDisposed => _disposed != 0; + + ~DisposableObject() + { + Dispose(false); + } + + public void Dispose() + { + if (Interlocked.Exchange(ref _disposed, 1) == 0) return; + Dispose(true); + GC.SuppressFinalize(this); + } + + protected abstract void Dispose(bool disposing); + + protected void ThrowIfDisposed() + { + ObjectDisposedException.ThrowIf(_disposed != 0, this); + } + } +} \ No newline at end of file diff --git a/sources/SDL2Sharp/Error.cs b/sources/SDL2Sharp/basics/Error.cs similarity index 55% rename from sources/SDL2Sharp/Error.cs rename to sources/SDL2Sharp/basics/Error.cs index 00b1e83d..16b852c8 100644 --- a/sources/SDL2Sharp/Error.cs +++ b/sources/SDL2Sharp/basics/Error.cs @@ -19,8 +19,6 @@ // 3. This notice may not be removed or altered from any source distribution. using System; -using System.Runtime.Serialization; -using SDL2Sharp.Interop; namespace SDL2Sharp { @@ -32,54 +30,50 @@ public Error(string message) : base(message) { } - public Error(SerializationInfo info, StreamingContext context) - : base(info, context) - { } - public Error(string message, Exception innerException) : base(message, innerException) { } - internal static unsafe void ThrowOnFailure(void* pointer) + public static unsafe Error GetLastError() { - if (pointer is null) - { - throw new Error(new string(SDL.GetError())); - } + return new Error(new string(Interop.SDL.GetError())); } - internal static unsafe void ThrowOnFailure(int returnCode) + public static void ThrowLastError() { - if (returnCode < 0) - { - throw new Error(new string(SDL.GetError())); - } + throw GetLastError(); } - internal static unsafe void ThrowOnFailure(uint returnCode) + public static void ThrowLastErrorIf(bool condition) { - if (returnCode == 0) + if (condition) { - throw new Error(new string(SDL.GetError())); + ThrowLastError(); } } - internal static unsafe uint ReturnOrThrowOnFailure(uint returnCode) + public static unsafe void* ThrowLastErrorIfNull(void* pointer) { - if (returnCode == 0) - { - throw new Error(new string(SDL.GetError())); - } - return returnCode; + ThrowLastErrorIf(pointer is null); + + return pointer; } - internal static unsafe T* ReturnOrThrowOnFailure(T* pointer) where T : unmanaged + public static unsafe T* ThrowLastErrorIfNull(T* pointer) where T : unmanaged { - if (pointer is null) - { - throw new Error(new string(SDL.GetError())); - } + ThrowLastErrorIf(pointer is null); + return pointer; } + + public static void ThrowLastErrorIfNegative(int returnCode) + { + ThrowLastErrorIf(returnCode < 0); + } + + public static void ThrowLastErrorIfZero(uint returnCode) + { + ThrowLastErrorIf(returnCode == 0); + } } } diff --git a/sources/SDL2Sharp/basics/FinalizableObject.cs b/sources/SDL2Sharp/basics/FinalizableObject.cs new file mode 100644 index 00000000..dcaa6bf2 --- /dev/null +++ b/sources/SDL2Sharp/basics/FinalizableObject.cs @@ -0,0 +1,27 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +namespace SDL2Sharp +{ + public abstract class FinalizableObject : DisposableObject + { + ~FinalizableObject() => Dispose(false); + } +} diff --git a/sources/SDL2Sharp/AudioDeviceSpec.cs b/sources/SDL2Sharp/basics/Hint.cs similarity index 50% rename from sources/SDL2Sharp/AudioDeviceSpec.cs rename to sources/SDL2Sharp/basics/Hint.cs index 6221f1e2..f764604d 100644 --- a/sources/SDL2Sharp/AudioDeviceSpec.cs +++ b/sources/SDL2Sharp/basics/Hint.cs @@ -22,38 +22,38 @@ namespace SDL2Sharp { - public sealed unsafe class AudioDeviceSpec + public sealed unsafe class Hint { - public AudioDeviceSpec(int frequency, AudioFormat format, AudioChannelLayout channels, ushort samples) + private readonly string _name; + + public Hint(string name) { - Frequency = frequency; - Format = format; - Channels = channels; - Silence = 0; - Samples = samples; - Size = 0; + _name = name; } - public AudioDeviceSpec(SDL_AudioSpec audioSpec) + public bool SetValue(string value) { - Frequency = audioSpec.freq; - Format = (AudioFormat)audioSpec.format; - Channels = (AudioChannelLayout)audioSpec.channels; - Silence = audioSpec.silence; - Samples = audioSpec.samples; - Size = audioSpec.size; + using var marshaledName = new MarshaledString(_name); + using var marshaledValue = new MarshaledString(value); + return 0 != Interop.SDL.SetHint(marshaledName, marshaledValue); } - public int Frequency { get; set; } - - public AudioFormat Format { get; set; } - - public AudioChannelLayout Channels { get; set; } - - public byte Silence { get; private set; } - - public ushort Samples { get; set; } + public bool SetValue(string value, HintPriority priority) + { + using var marshaledName = new MarshaledString(_name); + using var marshaledValue = new MarshaledString(value); + return 0 != Interop.SDL.SetHintWithPriority(marshaledName, marshaledValue, (SDL_HintPriority)priority); + } - public uint Size { get; private set; } + public string GetValue() + { + using var marshaledName = new MarshaledString(_name); + var value = Interop.SDL.GetHint(marshaledName); + if (value is null) + { + return null!; + } + return new string(value); + } } } diff --git a/sources/SDL2Sharp/HintPriority.cs b/sources/SDL2Sharp/basics/HintPriority.cs similarity index 100% rename from sources/SDL2Sharp/HintPriority.cs rename to sources/SDL2Sharp/basics/HintPriority.cs diff --git a/sources/SDL2Sharp/basics/Hints.cs b/sources/SDL2Sharp/basics/Hints.cs new file mode 100644 index 00000000..578df610 --- /dev/null +++ b/sources/SDL2Sharp/basics/Hints.cs @@ -0,0 +1,274 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public static class Hints + { + public static readonly Hint FramebufferAcceleration = new(Interop.SDL.SDL_HINT_FRAMEBUFFER_ACCELERATION.AsString()); + + public static readonly string RenderDriver = Interop.SDL.SDL_HINT_RENDER_DRIVER.AsString(); + + public static readonly string OpenGlShaders = Interop.SDL.SDL_HINT_RENDER_OPENGL_SHADERS.AsString(); + + public static readonly string Direct3DThreadSafe = Interop.SDL.SDL_HINT_RENDER_DIRECT3D_THREADSAFE.AsString(); + + public static readonly string Direct3D11Debug = Interop.SDL.SDL_HINT_RENDER_DIRECT3D11_DEBUG.AsString(); + + public static readonly string LogicalSizeMode = Interop.SDL.SDL_HINT_RENDER_LOGICAL_SIZE_MODE.AsString(); + + public static readonly string RenderScaleQuality = Interop.SDL.SDL_HINT_RENDER_SCALE_QUALITY.AsString(); + + public static readonly string RenderVSync = Interop.SDL.SDL_HINT_RENDER_VSYNC.AsString(); + + public static readonly string VideoAllowScreensaver = Interop.SDL.SDL_HINT_VIDEO_ALLOW_SCREENSAVER.AsString(); + + public static readonly string VideoExternalContext = Interop.SDL.SDL_HINT_VIDEO_EXTERNAL_CONTEXT.AsString(); + + public static readonly string VideoX11XVidMode = Interop.SDL.SDL_HINT_VIDEO_X11_XVIDMODE.AsString(); + + public static readonly string VideoX11Xinerama = Interop.SDL.SDL_HINT_VIDEO_X11_XINERAMA.AsString(); + + public static readonly string VideoX11XRandr = Interop.SDL.SDL_HINT_VIDEO_X11_XRANDR.AsString(); + + public static readonly string VideoX11WindowVisualId = Interop.SDL.SDL_HINT_VIDEO_X11_WINDOW_VISUALID.AsString(); + + public static readonly string VideoX11NetWmPing = Interop.SDL.SDL_HINT_VIDEO_X11_NET_WM_PING.AsString(); + + public static readonly string VideoX11NetWmBypassCompositor = Interop.SDL.SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR.AsString(); + + public static readonly string VideoX11ForceEgl = Interop.SDL.SDL_HINT_VIDEO_X11_FORCE_EGL.AsString(); + + public static readonly string WindowFrameUsableWhileCursorHidden = Interop.SDL.SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN.AsString(); + + public static readonly string WindowsIntResourceIcon = Interop.SDL.SDL_HINT_WINDOWS_INTRESOURCE_ICON.AsString(); + + public static readonly string WindowsIntResourceIconSmall = Interop.SDL.SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL.AsString(); + + public static readonly string WindowsEnableMessageLoop = Interop.SDL.SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP.AsString(); + + public static readonly string GrabKeyboard = Interop.SDL.SDL_HINT_GRAB_KEYBOARD.AsString(); + + public static readonly string MouseDoubleClickTime = Interop.SDL.SDL_HINT_MOUSE_DOUBLE_CLICK_TIME.AsString(); + + public static readonly string MouseDoubleClickRadius = Interop.SDL.SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS.AsString(); + + public static readonly string MouseNormalSpeedScale = Interop.SDL.SDL_HINT_MOUSE_NORMAL_SPEED_SCALE.AsString(); + + public static readonly string MouseRelativeSpeedScale = Interop.SDL.SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE.AsString(); + + public static readonly string MouseRelativeScaling = Interop.SDL.SDL_HINT_MOUSE_RELATIVE_SCALING.AsString(); + + public static readonly string MouseRelativeModeWarp = Interop.SDL.SDL_HINT_MOUSE_RELATIVE_MODE_WARP.AsString(); + + public static readonly string MouseFocusClickThrough = Interop.SDL.SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH.AsString(); + + public static readonly string TouchMouseEvents = Interop.SDL.SDL_HINT_TOUCH_MOUSE_EVENTS.AsString(); + + public static readonly string MouseTouchEvents = Interop.SDL.SDL_HINT_MOUSE_TOUCH_EVENTS.AsString(); + + public static readonly string VideoMinimizeOnFocusLoss = Interop.SDL.SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS.AsString(); + + public static readonly string IdleTimerDisabled = Interop.SDL.SDL_HINT_IDLE_TIMER_DISABLED.AsString(); + + public static readonly string Orientations = Interop.SDL.SDL_HINT_ORIENTATIONS.AsString(); + + public static readonly string AppleTvControllerUiEvents = Interop.SDL.SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS.AsString(); + + public static readonly string AppleTvRemoteAllowRotation = Interop.SDL.SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION.AsString(); + + public static readonly string IosHideHomeIndicator = Interop.SDL.SDL_HINT_IOS_HIDE_HOME_INDICATOR.AsString(); + + public static readonly string AccelerometerAsJoystick = Interop.SDL.SDL_HINT_ACCELEROMETER_AS_JOYSTICK.AsString(); + + public static readonly string TvRemoveAsJoystick = Interop.SDL.SDL_HINT_TV_REMOTE_AS_JOYSTICK.AsString(); + + public static readonly string XInputEnabled = Interop.SDL.SDL_HINT_XINPUT_ENABLED.AsString(); + + public static readonly string XInputUseOldJoystickMapping = Interop.SDL.SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING.AsString(); + + public static readonly string GameControllerType = Interop.SDL.SDL_HINT_GAMECONTROLLERTYPE.AsString(); + + public static readonly string GameControllerConfig = Interop.SDL.SDL_HINT_GAMECONTROLLERCONFIG.AsString(); + + public static readonly string GameControllerConfigFile = Interop.SDL.SDL_HINT_GAMECONTROLLERCONFIG_FILE.AsString(); + + public static readonly string GameControllerIgnoreDevices = Interop.SDL.SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES.AsString(); + + public static readonly string GameControllerIgnoreDevicesExcept = Interop.SDL.SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT.AsString(); + + public static readonly string GameControllerUseButtonLabels = Interop.SDL.SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS.AsString(); + + public static readonly string JoystickAllowBackgroundEvents = Interop.SDL.SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS.AsString(); + + public static readonly string JoystickHidApi = Interop.SDL.SDL_HINT_JOYSTICK_HIDAPI.AsString(); + + public static readonly string JoystickHidApiGameCube = Interop.SDL.SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE.AsString(); + + public static readonly string JoystickHidApiJoyCons = Interop.SDL.SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS.AsString(); + + public static readonly string JoystickHidApiLuna = Interop.SDL.SDL_HINT_JOYSTICK_HIDAPI_LUNA.AsString(); + + public static readonly string JoystickHidApiPS4 = Interop.SDL.SDL_HINT_JOYSTICK_HIDAPI_PS4.AsString(); + + public static readonly string JoystickHidApiPS4Rumble = Interop.SDL.SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE.AsString(); + + public static readonly string JoystickHidApiPS5 = Interop.SDL.SDL_HINT_JOYSTICK_HIDAPI_PS5.AsString(); + + public static readonly string JoystickHidApiPS5PlayerLed = Interop.SDL.SDL_HINT_JOYSTICK_HIDAPI_PS5_PLAYER_LED.AsString(); + + public static readonly string JoystickHidApiPS5Rumble = Interop.SDL.SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE.AsString(); + + public static readonly string JoystickHidApiStadia = Interop.SDL.SDL_HINT_JOYSTICK_HIDAPI_STADIA.AsString(); + + public static readonly string JoystickHidApiSteam = Interop.SDL.SDL_HINT_JOYSTICK_HIDAPI_STEAM.AsString(); + + public static readonly string JoystickHidApiSwitch = Interop.SDL.SDL_HINT_JOYSTICK_HIDAPI_SWITCH.AsString(); + + public static readonly string JoystickHidApiSwitchHomeLed = Interop.SDL.SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED.AsString(); + + public static readonly string JoystickHidApiXbox = Interop.SDL.SDL_HINT_JOYSTICK_HIDAPI_XBOX.AsString(); + + public static readonly string EnableSteamControllers = Interop.SDL.SDL_HINT_ENABLE_STEAM_CONTROLLERS.AsString(); + + public static readonly string JoystickRawInput = Interop.SDL.SDL_HINT_JOYSTICK_RAWINPUT.AsString(); + + public static readonly string JoystickThread = Interop.SDL.SDL_HINT_JOYSTICK_THREAD.AsString(); + + public static readonly string LinuxJoystickDeadzones = Interop.SDL.SDL_HINT_LINUX_JOYSTICK_DEADZONES.AsString(); + + public static readonly string AllowTopMost = Interop.SDL.SDL_HINT_ALLOW_TOPMOST.AsString(); + + public static readonly string TimerResolution = Interop.SDL.SDL_HINT_TIMER_RESOLUTION.AsString(); + + public static readonly string QtWaylandContentOrientation = Interop.SDL.SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION.AsString(); + + public static readonly string QtWaylandWindowFlags = Interop.SDL.SDL_HINT_QTWAYLAND_WINDOW_FLAGS.AsString(); + + public static readonly string ThreadStackSize = Interop.SDL.SDL_HINT_THREAD_STACK_SIZE.AsString(); + + public static readonly string ThreadPriorityPolicy = Interop.SDL.SDL_HINT_THREAD_PRIORITY_POLICY.AsString(); + + public static readonly string ThreadForceRealtimeTimeCritical = Interop.SDL.SDL_HINT_THREAD_FORCE_REALTIME_TIME_CRITICAL.AsString(); + + public static readonly string VideoHighDpiDisabled = Interop.SDL.SDL_HINT_VIDEO_HIGHDPI_DISABLED.AsString(); + + public static readonly string MacCtrlClickEmulateRightClick = Interop.SDL.SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK.AsString(); + + public static readonly string VideoWinD3DCompiler = Interop.SDL.SDL_HINT_VIDEO_WIN_D3DCOMPILER.AsString(); + + public static readonly string VideoWindowSharePixelFormat = Interop.SDL.SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT.AsString(); + + public static readonly string WinrtPrivacyPolicyUrl = Interop.SDL.SDL_HINT_WINRT_PRIVACY_POLICY_URL.AsString(); + + public static readonly string WinrtPrivacyPolicyLabel = Interop.SDL.SDL_HINT_WINRT_PRIVACY_POLICY_LABEL.AsString(); + + public static readonly string WinrtHandleBackButton = Interop.SDL.SDL_HINT_WINRT_HANDLE_BACK_BUTTON.AsString(); + + public static readonly string VideoMacFullScreenSpaces = Interop.SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES.AsString(); + + public static readonly string MacBackgroundApp = Interop.SDL.SDL_HINT_MAC_BACKGROUND_APP.AsString(); + + public static readonly string AndroidApkExpansionMainFileVersion = Interop.SDL.SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION.AsString(); + + public static readonly string AndroidApkExpansionPatchFileVersion = Interop.SDL.SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION.AsString(); + + public static readonly string ImeInternalEditing = Interop.SDL.SDL_HINT_IME_INTERNAL_EDITING.AsString(); + + public static readonly string AndroidTrapBackButton = Interop.SDL.SDL_HINT_ANDROID_TRAP_BACK_BUTTON.AsString(); + + public static readonly string AndroidBlockOnPause = Interop.SDL.SDL_HINT_ANDROID_BLOCK_ON_PAUSE.AsString(); + + public static readonly string AndroidBlockOnPausePauseAudio = Interop.SDL.SDL_HINT_ANDROID_BLOCK_ON_PAUSE_PAUSEAUDIO.AsString(); + + public static readonly string ReturnKeyHidesIme = Interop.SDL.SDL_HINT_RETURN_KEY_HIDES_IME.AsString(); + + public static readonly string EmscriptenKeyboardElement = Interop.SDL.SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT.AsString(); + + public static readonly string EmscriptenAsyncify = Interop.SDL.SDL_HINT_EMSCRIPTEN_ASYNCIFY.AsString(); + + public static readonly string NoSignalHandlers = Interop.SDL.SDL_HINT_NO_SIGNAL_HANDLERS.AsString(); + + public static readonly string WindowsNoCloseOnAltF4 = Interop.SDL.SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4.AsString(); + + public static readonly string BmpSaveLegacyFormat = Interop.SDL.SDL_HINT_BMP_SAVE_LEGACY_FORMAT.AsString(); + + public static readonly string WindowsDisableThreadNaming = Interop.SDL.SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING.AsString(); + + public static readonly string RpiVideoLayer = Interop.SDL.SDL_HINT_RPI_VIDEO_LAYER.AsString(); + + public static readonly string VideoDoubleBuffer = Interop.SDL.SDL_HINT_VIDEO_DOUBLE_BUFFER.AsString(); + + public static readonly string OpenGlEsDriver = Interop.SDL.SDL_HINT_OPENGL_ES_DRIVER.AsString(); + + public static readonly string AudioResamplingMode = Interop.SDL.SDL_HINT_AUDIO_RESAMPLING_MODE.AsString(); + + public static readonly string AudioCategory = Interop.SDL.SDL_HINT_AUDIO_CATEGORY.AsString(); + + public static readonly string RenderBatching = Interop.SDL.SDL_HINT_RENDER_BATCHING.AsString(); + + public static readonly string AutoUpdateJoysticks = Interop.SDL.SDL_HINT_AUTO_UPDATE_JOYSTICKS.AsString(); + + public static readonly string AutoUpdateSensors = Interop.SDL.SDL_HINT_AUTO_UPDATE_SENSORS.AsString(); + + public static readonly string EventLogging = Interop.SDL.SDL_HINT_EVENT_LOGGING.AsString(); + + public static readonly string WaveRiffChunkSize = Interop.SDL.SDL_HINT_WAVE_RIFF_CHUNK_SIZE.AsString(); + + public static readonly string WaveTruncation = Interop.SDL.SDL_HINT_WAVE_TRUNCATION.AsString(); + + public static readonly string WaveFactChunk = Interop.SDL.SDL_HINT_WAVE_FACT_CHUNK.AsString(); + + public static readonly string DisplayUsableBounds = Interop.SDL.SDL_HINT_DISPLAY_USABLE_BOUNDS.AsString(); + + public static readonly string AudioDeviceAppName = Interop.SDL.SDL_HINT_AUDIO_DEVICE_APP_NAME.AsString(); + + public static readonly string AudioDeviceStreamName = Interop.SDL.SDL_HINT_AUDIO_DEVICE_STREAM_NAME.AsString(); + + public static readonly string PreferredLocales = Interop.SDL.SDL_HINT_PREFERRED_LOCALES.AsString(); + + public static unsafe bool SetValue(string name, string value) + { + using var marshaledName = new MarshaledString(name); + using var marshaledValue = new MarshaledString(value); + return 0 != Interop.SDL.SetHint(marshaledName, marshaledValue); + } + + public static unsafe bool SetValue(string name, string value, HintPriority priority) + { + using var marshaledName = new MarshaledString(name); + using var marshaledValue = new MarshaledString(value); + return 0 != Interop.SDL.SetHintWithPriority(marshaledName, marshaledValue, (SDL_HintPriority)priority); + } + + public static unsafe string GetValue(string name) + { + using var marshaledName = new MarshaledString(name); + var value = Interop.SDL.GetHint(marshaledName); + if (value is null) + { + return null!; + } + return new string(value); + } + } +} diff --git a/sources/SDL2Sharp/basics/SDL.cs b/sources/SDL2Sharp/basics/SDL.cs new file mode 100644 index 00000000..512ade00 --- /dev/null +++ b/sources/SDL2Sharp/basics/SDL.cs @@ -0,0 +1,95 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using static SDL2Sharp.Utilities; + +namespace SDL2Sharp +{ + public sealed partial class SDL : FinalizableObject + { + private VideoSubsystem? _videoSubsystem; + + private AudioSubsystem? _audioSubsystem; + + private EventsSubsystem? _eventsSubsystem; + + private FontSubsystem? _fontSubsystem; + + public IVideoSubsystem Video + { + get + { + ThrowIfDisposed(); + + return _videoSubsystem ??= new VideoSubsystem(); + } + } + + public IAudioSubsystem Audio + { + get + { + ThrowIfDisposed(); + + return _audioSubsystem ??= new AudioSubsystem(); + } + } + + public IEventsSubsystem Events + { + get + { + ThrowIfDisposed(); + + return _eventsSubsystem ??= new EventsSubsystem(); + } + } + + public IFontSubsystem Fonts + { + get + { + ThrowIfDisposed(); + + return _fontSubsystem ??= new FontSubsystem(); + } + } + + public SDL() + { + Error.ThrowLastErrorIfNegative( + Interop.SDL.Init(0) + ); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + SafeDispose(ref _videoSubsystem); + SafeDispose(ref _audioSubsystem); + SafeDispose(ref _eventsSubsystem); + SafeDispose(ref _fontSubsystem); + } + + Interop.SDL.Quit(); + } + } +} diff --git a/samples/RayTracer/ISurface.cs b/sources/SDL2Sharp/events/AppDidEnterBackgroundEvent.cs similarity index 82% rename from samples/RayTracer/ISurface.cs rename to sources/SDL2Sharp/events/AppDidEnterBackgroundEvent.cs index 2edfe9c1..d2eda2da 100644 --- a/samples/RayTracer/ISurface.cs +++ b/sources/SDL2Sharp/events/AppDidEnterBackgroundEvent.cs @@ -18,13 +18,14 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using System.Numerics; -using SDL2Sharp.Extensions; +using SDL2Sharp.Interop; -namespace RayTracer +namespace SDL2Sharp { - internal interface ISurface + public sealed class AppDidEnterBackgroundEvent : Event { - Rgb32f Shade(Rgb32f ambient, Vector3 surfaceNormal, Vector3 lightVector, Rgb32f lightColor); + internal AppDidEnterBackgroundEvent(SDL_Event handle) + : base(handle) + { } } } diff --git a/sources/SDL2Sharp/events/AppDidEnterForegroundEvent.cs b/sources/SDL2Sharp/events/AppDidEnterForegroundEvent.cs new file mode 100644 index 00000000..20a0102e --- /dev/null +++ b/sources/SDL2Sharp/events/AppDidEnterForegroundEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class AppDidEnterForegroundEvent : Event + { + internal AppDidEnterForegroundEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp.Interop/SDL_EventFilter.cs b/sources/SDL2Sharp/events/AppLowMemoryEvent.cs similarity index 82% rename from sources/SDL2Sharp.Interop/SDL_EventFilter.cs rename to sources/SDL2Sharp/events/AppLowMemoryEvent.cs index 21f529a8..abbc07fe 100644 --- a/sources/SDL2Sharp.Interop/SDL_EventFilter.cs +++ b/sources/SDL2Sharp/events/AppLowMemoryEvent.cs @@ -18,10 +18,14 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using System.Runtime.InteropServices; +using SDL2Sharp.Interop; -namespace SDL2Sharp.Interop +namespace SDL2Sharp { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public unsafe delegate int SDL_EventFilter(void* userdata, SDL_Event* @event); + public sealed class AppLowMemoryEvent : Event + { + internal AppLowMemoryEvent(SDL_Event handle) + : base(handle) + { } + } } diff --git a/sources/SDL2Sharp/events/AppTerminatingEvent.cs b/sources/SDL2Sharp/events/AppTerminatingEvent.cs new file mode 100644 index 00000000..db939c74 --- /dev/null +++ b/sources/SDL2Sharp/events/AppTerminatingEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class AppTerminatingEvent : Event + { + internal AppTerminatingEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/AppWillEnterBackgroundEvent.cs b/sources/SDL2Sharp/events/AppWillEnterBackgroundEvent.cs new file mode 100644 index 00000000..e86ab8c2 --- /dev/null +++ b/sources/SDL2Sharp/events/AppWillEnterBackgroundEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class AppWillEnterBackgroundEvent : Event + { + internal AppWillEnterBackgroundEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/AppWillEnterForegroundEvent.cs b/sources/SDL2Sharp/events/AppWillEnterForegroundEvent.cs new file mode 100644 index 00000000..77ea0e2b --- /dev/null +++ b/sources/SDL2Sharp/events/AppWillEnterForegroundEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class AppWillEnterForegroundEvent : Event + { + internal AppWillEnterForegroundEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/AudioDeviceAddedEvent.cs b/sources/SDL2Sharp/events/AudioDeviceAddedEvent.cs new file mode 100644 index 00000000..88b1ecb7 --- /dev/null +++ b/sources/SDL2Sharp/events/AudioDeviceAddedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class AudioDeviceAddedEvent : Event + { + internal AudioDeviceAddedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/AudioDeviceRemovedEvent.cs b/sources/SDL2Sharp/events/AudioDeviceRemovedEvent.cs new file mode 100644 index 00000000..c46876bf --- /dev/null +++ b/sources/SDL2Sharp/events/AudioDeviceRemovedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class AudioDeviceRemovedEvent : Event + { + internal AudioDeviceRemovedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/ClipboardUpdateEvent.cs b/sources/SDL2Sharp/events/ClipboardUpdateEvent.cs new file mode 100644 index 00000000..61f2b39c --- /dev/null +++ b/sources/SDL2Sharp/events/ClipboardUpdateEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class ClipboardUpdateEvent : Event + { + internal ClipboardUpdateEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/ControllerAxisMotionEvent.cs b/sources/SDL2Sharp/events/ControllerAxisMotionEvent.cs new file mode 100644 index 00000000..0f830035 --- /dev/null +++ b/sources/SDL2Sharp/events/ControllerAxisMotionEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class ControllerAxisMotionEvent : Event + { + internal ControllerAxisMotionEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/ControllerButtonDownEvent.cs b/sources/SDL2Sharp/events/ControllerButtonDownEvent.cs new file mode 100644 index 00000000..40b717bb --- /dev/null +++ b/sources/SDL2Sharp/events/ControllerButtonDownEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class ControllerButtonDownEvent : Event + { + internal ControllerButtonDownEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/ControllerButtonUpEvent.cs b/sources/SDL2Sharp/events/ControllerButtonUpEvent.cs new file mode 100644 index 00000000..ef5a389a --- /dev/null +++ b/sources/SDL2Sharp/events/ControllerButtonUpEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class ControllerButtonUpEvent : Event + { + internal ControllerButtonUpEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/ControllerDeviceAddedEvent.cs b/sources/SDL2Sharp/events/ControllerDeviceAddedEvent.cs new file mode 100644 index 00000000..4043ded7 --- /dev/null +++ b/sources/SDL2Sharp/events/ControllerDeviceAddedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class ControllerDeviceAddedEvent : Event + { + internal ControllerDeviceAddedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/ControllerDeviceRemappedEvent.cs b/sources/SDL2Sharp/events/ControllerDeviceRemappedEvent.cs new file mode 100644 index 00000000..9222af99 --- /dev/null +++ b/sources/SDL2Sharp/events/ControllerDeviceRemappedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class ControllerDeviceRemappedEvent : Event + { + internal ControllerDeviceRemappedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/ControllerDeviceRemovedEvent.cs b/sources/SDL2Sharp/events/ControllerDeviceRemovedEvent.cs new file mode 100644 index 00000000..e69dd5fd --- /dev/null +++ b/sources/SDL2Sharp/events/ControllerDeviceRemovedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class ControllerDeviceRemovedEvent : Event + { + internal ControllerDeviceRemovedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/ControllerSensorUpdateEvent.cs b/sources/SDL2Sharp/events/ControllerSensorUpdateEvent.cs new file mode 100644 index 00000000..ec763f42 --- /dev/null +++ b/sources/SDL2Sharp/events/ControllerSensorUpdateEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class ControllerSensorUpdateEvent : Event + { + internal ControllerSensorUpdateEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/ControllerTouchpadDownEvent.cs b/sources/SDL2Sharp/events/ControllerTouchpadDownEvent.cs new file mode 100644 index 00000000..cdcc65ed --- /dev/null +++ b/sources/SDL2Sharp/events/ControllerTouchpadDownEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class ControllerTouchpadDownEvent : Event + { + internal ControllerTouchpadDownEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/ControllerTouchpadMotionEvent.cs b/sources/SDL2Sharp/events/ControllerTouchpadMotionEvent.cs new file mode 100644 index 00000000..3e1470cb --- /dev/null +++ b/sources/SDL2Sharp/events/ControllerTouchpadMotionEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class ControllerTouchpadMotionEvent : Event + { + internal ControllerTouchpadMotionEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/ControllerTouchpadUpEvent.cs b/sources/SDL2Sharp/events/ControllerTouchpadUpEvent.cs new file mode 100644 index 00000000..a8eb4f24 --- /dev/null +++ b/sources/SDL2Sharp/events/ControllerTouchpadUpEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class ControllerTouchpadUpEvent : Event + { + internal ControllerTouchpadUpEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/DisplayEvent.cs b/sources/SDL2Sharp/events/DisplayEvent.cs new file mode 100644 index 00000000..f88d7af4 --- /dev/null +++ b/sources/SDL2Sharp/events/DisplayEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class DisplayEvent : Event + { + internal DisplayEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/DollarGestureEvent.cs b/sources/SDL2Sharp/events/DollarGestureEvent.cs new file mode 100644 index 00000000..1697f05e --- /dev/null +++ b/sources/SDL2Sharp/events/DollarGestureEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class DollarGestureEvent : Event + { + internal DollarGestureEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/DollarRecordEvent.cs b/sources/SDL2Sharp/events/DollarRecordEvent.cs new file mode 100644 index 00000000..afba41c3 --- /dev/null +++ b/sources/SDL2Sharp/events/DollarRecordEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class DollarRecordEvent : Event + { + internal DollarRecordEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/DropBeginEvent.cs b/sources/SDL2Sharp/events/DropBeginEvent.cs new file mode 100644 index 00000000..7da34d55 --- /dev/null +++ b/sources/SDL2Sharp/events/DropBeginEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class DropBeginEvent : Event + { + internal DropBeginEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/DropCompleteEvent.cs b/sources/SDL2Sharp/events/DropCompleteEvent.cs new file mode 100644 index 00000000..5e7ff6fd --- /dev/null +++ b/sources/SDL2Sharp/events/DropCompleteEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class DropCompleteEvent : Event + { + internal DropCompleteEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/DropFileEvent.cs b/sources/SDL2Sharp/events/DropFileEvent.cs new file mode 100644 index 00000000..136cf628 --- /dev/null +++ b/sources/SDL2Sharp/events/DropFileEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class DropFileEvent : Event + { + internal DropFileEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/DropTextEvent.cs b/sources/SDL2Sharp/events/DropTextEvent.cs new file mode 100644 index 00000000..aab2e4cc --- /dev/null +++ b/sources/SDL2Sharp/events/DropTextEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class DropTextEvent : Event + { + internal DropTextEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/Event.cs b/sources/SDL2Sharp/events/Event.cs new file mode 100644 index 00000000..47195c02 --- /dev/null +++ b/sources/SDL2Sharp/events/Event.cs @@ -0,0 +1,40 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public abstract class Event + { + protected SDL_Event _handle; + + internal SDL_Event Handle => _handle; + + protected Event() + : this(new SDL_Event()) + { } + + protected Event(SDL_Event handle) + { + _handle = handle; + } + } +} \ No newline at end of file diff --git a/sources/SDL2Sharp/events/EventsSubsystem.cs b/sources/SDL2Sharp/events/EventsSubsystem.cs new file mode 100644 index 00000000..d484cb87 --- /dev/null +++ b/sources/SDL2Sharp/events/EventsSubsystem.cs @@ -0,0 +1,268 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + internal sealed unsafe class EventsSubsystem : FinalizableObject, IEventsSubsystem + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int EventWatchCallbackDelegate(void* userdata, SDL_Event* @event); + + private const uint InitSubsystemFlags = Interop.SDL.SDL_INIT_EVENTS; + + private GCHandle _watchCallbackUserData = default; + + private readonly HashSet> _watchCallbacks = []; + + public EventsSubsystem() + { + Error.ThrowLastErrorIfNegative( + Interop.SDL.InitSubSystem(InitSubsystemFlags) + ); + + _watchCallbackUserData = GCHandle.Alloc(this, GCHandleType.Normal); + var watchUserDataPointer = (void*)(IntPtr)_watchCallbackUserData; + Interop.SDL.AddEventWatch(&OnEventWatchCallback, watchUserDataPointer); + } + + protected override void Dispose(bool disposing) + { + var watchUserDataPointer = (void*)(IntPtr)_watchCallbackUserData; + Interop.SDL.DelEventWatch(&OnEventWatchCallback, watchUserDataPointer); + _watchCallbackUserData.Free(); + + Interop.SDL.QuitSubSystem(InitSubsystemFlags); + } + + public Event? PollEvent() + { + var @event = new SDL_Event(); + if (Interop.SDL.PollEvent(&@event) == 0) + { + return null; + } + return WrapEvent(@event); + } + + public void PushEvent(Event @event) + { + var eventHandle = @event.Handle; + var result = Interop.SDL.PushEvent(&eventHandle); + Error.ThrowLastErrorIfNegative(result); + } + + public void AddWatch(Action callback) + { + _watchCallbacks.Add(callback); + } + + public void DeleteWatch(Action callback) + { + _watchCallbacks.Remove(callback); + } + + private static Event WrapEvent(SDL_Event @event) + { + var eventType = (SDL_EventType)@event.type; + switch (eventType) + { + case SDL_EventType.SDL_QUIT: + return new QuitEvent(@event); + case SDL_EventType.SDL_APP_TERMINATING: + return new AppTerminatingEvent(@event); + case SDL_EventType.SDL_APP_LOWMEMORY: + return new AppLowMemoryEvent(@event); + case SDL_EventType.SDL_APP_WILLENTERBACKGROUND: + return new AppWillEnterBackgroundEvent(@event); + case SDL_EventType.SDL_APP_DIDENTERBACKGROUND: + return new AppDidEnterBackgroundEvent(@event); + case SDL_EventType.SDL_APP_WILLENTERFOREGROUND: + return new AppWillEnterForegroundEvent(@event); + case SDL_EventType.SDL_APP_DIDENTERFOREGROUND: + return new AppDidEnterForegroundEvent(@event); + case SDL_EventType.SDL_LOCALECHANGED: + return new LocaleChangedEvent(@event); + case SDL_EventType.SDL_DISPLAYEVENT: + return new DisplayEvent(@event); + case SDL_EventType.SDL_WINDOWEVENT: + switch ((SDL_WindowEventID)@event.window.@event) + { + case SDL_WindowEventID.SDL_WINDOWEVENT_SHOWN: + return new WindowShownEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_HIDDEN: + return new WindowHiddenEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_EXPOSED: + return new WindowExposedEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_MOVED: + return new WindowMovedEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED: + return new WindowResizedEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED: + return new WindowSizeChangedEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED: + return new WindowMinimizedEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_MAXIMIZED: + return new WindowMaximizedEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_RESTORED: + return new WindowRestoredEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_ENTER: + return new WindowEnterEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE: + return new WindowLeaveEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: + return new WindowFocusGainedEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: + return new WindowFocusLostEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE: + return new WindowCloseEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_TAKE_FOCUS: + return new WindowTakeFocusEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_HIT_TEST: + return new WindowHitTestEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_ICCPROF_CHANGED: + return new WindowIccProfileChangedEvent(@event); + case SDL_WindowEventID.SDL_WINDOWEVENT_DISPLAY_CHANGED: + return new WindowDisplayChangedEvent(@event); + } + break; + case SDL_EventType.SDL_SYSWMEVENT: + return new SystemWindowManagerEvent(@event); + case SDL_EventType.SDL_KEYDOWN: + return new KeyDownEvent(@event); + case SDL_EventType.SDL_KEYUP: + return new KeyUpEvent(@event); + case SDL_EventType.SDL_TEXTEDITING: + return new TextEditingEvent(@event); + case SDL_EventType.SDL_TEXTINPUT: + return new TextInputEvent(@event); + case SDL_EventType.SDL_KEYMAPCHANGED: + return new KeyMapChangedEvent(@event); + case SDL_EventType.SDL_TEXTEDITING_EXT: + return new TextEditingExtEvent(@event); + case SDL_EventType.SDL_MOUSEMOTION: + return new MouseMotionEvent(@event); + case SDL_EventType.SDL_MOUSEBUTTONDOWN: + return new MouseButtonDownEvent(@event); + case SDL_EventType.SDL_MOUSEBUTTONUP: + return new MouseButtonUpEvent(@event); + case SDL_EventType.SDL_MOUSEWHEEL: + return new MouseWheelEvent(@event); + case SDL_EventType.SDL_JOYAXISMOTION: + return new JoystickAxisMotionEvent(@event); + case SDL_EventType.SDL_JOYBALLMOTION: + return new JoystickBallMotionEvent(@event); + case SDL_EventType.SDL_JOYHATMOTION: + return new JoystickHatMotionEvent(@event); + case SDL_EventType.SDL_JOYBUTTONDOWN: + return new JoystickButtonDownEvent(@event); + case SDL_EventType.SDL_JOYBUTTONUP: + return new JoystickButtonUpEvent(@event); + case SDL_EventType.SDL_JOYDEVICEADDED: + return new JoystickDeviceAddedEvent(@event); + case SDL_EventType.SDL_JOYDEVICEREMOVED: + return new JoystickDeviceRemovedEvent(@event); + case SDL_EventType.SDL_JOYBATTERYUPDATED: + return new JoystickBatteryUpdatedEvent(@event); + case SDL_EventType.SDL_CONTROLLERAXISMOTION: + return new ControllerAxisMotionEvent(@event); + case SDL_EventType.SDL_CONTROLLERBUTTONDOWN: + return new ControllerButtonDownEvent(@event); + case SDL_EventType.SDL_CONTROLLERBUTTONUP: + return new ControllerButtonUpEvent(@event); + case SDL_EventType.SDL_CONTROLLERDEVICEADDED: + return new ControllerDeviceAddedEvent(@event); + case SDL_EventType.SDL_CONTROLLERDEVICEREMOVED: + return new ControllerDeviceRemovedEvent(@event); + case SDL_EventType.SDL_CONTROLLERDEVICEREMAPPED: + return new ControllerDeviceRemappedEvent(@event); + case SDL_EventType.SDL_CONTROLLERTOUCHPADDOWN: + return new ControllerTouchpadDownEvent(@event); + case SDL_EventType.SDL_CONTROLLERTOUCHPADMOTION: + return new ControllerTouchpadMotionEvent(@event); + case SDL_EventType.SDL_CONTROLLERTOUCHPADUP: + return new ControllerTouchpadUpEvent(@event); + case SDL_EventType.SDL_CONTROLLERSENSORUPDATE: + return new ControllerSensorUpdateEvent(@event); + case SDL_EventType.SDL_FINGERDOWN: + return new FingerDownEvent(@event); + case SDL_EventType.SDL_FINGERUP: + return new FingerUpEvent(@event); + case SDL_EventType.SDL_FINGERMOTION: + return new FingerMotionEvent(@event); + case SDL_EventType.SDL_DOLLARGESTURE: + return new DollarGestureEvent(@event); + case SDL_EventType.SDL_DOLLARRECORD: + return new DollarRecordEvent(@event); + case SDL_EventType.SDL_MULTIGESTURE: + return new MultiGestureEvent(@event); + case SDL_EventType.SDL_CLIPBOARDUPDATE: + return new ClipboardUpdateEvent(@event); + case SDL_EventType.SDL_DROPFILE: + return new DropFileEvent(@event); + case SDL_EventType.SDL_DROPTEXT: + return new DropTextEvent(@event); + case SDL_EventType.SDL_DROPBEGIN: + return new DropBeginEvent(@event); + case SDL_EventType.SDL_DROPCOMPLETE: + return new DropCompleteEvent(@event); + case SDL_EventType.SDL_AUDIODEVICEADDED: + return new AudioDeviceAddedEvent(@event); + case SDL_EventType.SDL_AUDIODEVICEREMOVED: + return new AudioDeviceRemovedEvent(@event); + case SDL_EventType.SDL_SENSORUPDATE: + return new SensorUpdateEvent(@event); + case SDL_EventType.SDL_RENDER_TARGETS_RESET: + return new RenderTargetsResetEvent(@event); + case SDL_EventType.SDL_RENDER_DEVICE_RESET: + return new RenderDeviceResetEvent(@event); + case SDL_EventType.SDL_POLLSENTINEL: + return new PollSentinelEvent(@event); + case SDL_EventType.SDL_USEREVENT: + return new UserEvent(@event); + } + throw new NotImplementedException("Event type not implemented"); + } + + private void OnEventWatchCallback(Event @event) + { + foreach (var callback in _watchCallbacks) + { + callback(@event); + } + } + + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])] + private static int OnEventWatchCallback(void* userdata, SDL_Event* @event) + { + var eventSubsystemHandle = GCHandle.FromIntPtr((IntPtr)userdata); + if (eventSubsystemHandle.Target is EventsSubsystem eventSubsystem) + { + eventSubsystem.OnEventWatchCallback(WrapEvent(*@event)); + } + return 0; + } + } +} diff --git a/sources/SDL2Sharp/events/FingerDownEvent.cs b/sources/SDL2Sharp/events/FingerDownEvent.cs new file mode 100644 index 00000000..3d928441 --- /dev/null +++ b/sources/SDL2Sharp/events/FingerDownEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class FingerDownEvent : Event + { + internal FingerDownEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/FingerMotionEvent.cs b/sources/SDL2Sharp/events/FingerMotionEvent.cs new file mode 100644 index 00000000..8580e75f --- /dev/null +++ b/sources/SDL2Sharp/events/FingerMotionEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class FingerMotionEvent : Event + { + internal FingerMotionEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/FingerUpEvent.cs b/sources/SDL2Sharp/events/FingerUpEvent.cs new file mode 100644 index 00000000..5295359c --- /dev/null +++ b/sources/SDL2Sharp/events/FingerUpEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class FingerUpEvent : Event + { + internal FingerUpEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/WindowMovedEventArgs.cs b/sources/SDL2Sharp/events/IEventsSubsystem.cs similarity index 81% rename from sources/SDL2Sharp/WindowMovedEventArgs.cs rename to sources/SDL2Sharp/events/IEventsSubsystem.cs index f533e1ad..e6084ae1 100644 --- a/sources/SDL2Sharp/WindowMovedEventArgs.cs +++ b/sources/SDL2Sharp/events/IEventsSubsystem.cs @@ -22,16 +22,14 @@ namespace SDL2Sharp { - public sealed class WindowMovedEventArgs : EventArgs + public interface IEventsSubsystem { - public int X { get; } + void AddWatch(Action callback); - public int Y { get; } + void DeleteWatch(Action callback); - public WindowMovedEventArgs(int x, int y) - { - X = x; - Y = y; - } + Event? PollEvent(); + + void PushEvent(Event @event); } } diff --git a/sources/SDL2Sharp/events/JoystickAxisMotionEvent.cs b/sources/SDL2Sharp/events/JoystickAxisMotionEvent.cs new file mode 100644 index 00000000..24aa3e73 --- /dev/null +++ b/sources/SDL2Sharp/events/JoystickAxisMotionEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class JoystickAxisMotionEvent : Event + { + internal JoystickAxisMotionEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/JoystickBallMotionEvent.cs b/sources/SDL2Sharp/events/JoystickBallMotionEvent.cs new file mode 100644 index 00000000..6b400a47 --- /dev/null +++ b/sources/SDL2Sharp/events/JoystickBallMotionEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class JoystickBallMotionEvent : Event + { + internal JoystickBallMotionEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/JoystickBatteryUpdatedEvent.cs b/sources/SDL2Sharp/events/JoystickBatteryUpdatedEvent.cs new file mode 100644 index 00000000..dbeb09cb --- /dev/null +++ b/sources/SDL2Sharp/events/JoystickBatteryUpdatedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class JoystickBatteryUpdatedEvent : Event + { + internal JoystickBatteryUpdatedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/JoystickButtonDownEvent.cs b/sources/SDL2Sharp/events/JoystickButtonDownEvent.cs new file mode 100644 index 00000000..5ee0d482 --- /dev/null +++ b/sources/SDL2Sharp/events/JoystickButtonDownEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class JoystickButtonDownEvent : Event + { + internal JoystickButtonDownEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/JoystickButtonUpEvent.cs b/sources/SDL2Sharp/events/JoystickButtonUpEvent.cs new file mode 100644 index 00000000..955bc480 --- /dev/null +++ b/sources/SDL2Sharp/events/JoystickButtonUpEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class JoystickButtonUpEvent : Event + { + internal JoystickButtonUpEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/JoystickDeviceAddedEvent.cs b/sources/SDL2Sharp/events/JoystickDeviceAddedEvent.cs new file mode 100644 index 00000000..ce3c06c1 --- /dev/null +++ b/sources/SDL2Sharp/events/JoystickDeviceAddedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class JoystickDeviceAddedEvent : Event + { + internal JoystickDeviceAddedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/JoystickDeviceRemovedEvent.cs b/sources/SDL2Sharp/events/JoystickDeviceRemovedEvent.cs new file mode 100644 index 00000000..5b715a30 --- /dev/null +++ b/sources/SDL2Sharp/events/JoystickDeviceRemovedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class JoystickDeviceRemovedEvent : Event + { + internal JoystickDeviceRemovedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/JoystickHatMotionEvent.cs b/sources/SDL2Sharp/events/JoystickHatMotionEvent.cs new file mode 100644 index 00000000..2143eb00 --- /dev/null +++ b/sources/SDL2Sharp/events/JoystickHatMotionEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class JoystickHatMotionEvent : Event + { + internal JoystickHatMotionEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/KeyDownEvent.cs b/sources/SDL2Sharp/events/KeyDownEvent.cs new file mode 100644 index 00000000..7ab167cc --- /dev/null +++ b/sources/SDL2Sharp/events/KeyDownEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class KeyDownEvent : KeyboardEvent + { + internal KeyDownEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/KeyMapChangedEvent.cs b/sources/SDL2Sharp/events/KeyMapChangedEvent.cs new file mode 100644 index 00000000..844f2019 --- /dev/null +++ b/sources/SDL2Sharp/events/KeyMapChangedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class KeyMapChangedEvent : Event + { + internal KeyMapChangedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/KeyModifiers.cs b/sources/SDL2Sharp/events/KeyModifiers.cs similarity index 99% rename from sources/SDL2Sharp/KeyModifiers.cs rename to sources/SDL2Sharp/events/KeyModifiers.cs index ce6c5969..394d9e00 100644 --- a/sources/SDL2Sharp/KeyModifiers.cs +++ b/sources/SDL2Sharp/events/KeyModifiers.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // diff --git a/sources/SDL2Sharp/events/KeyUpEvent.cs b/sources/SDL2Sharp/events/KeyUpEvent.cs new file mode 100644 index 00000000..2adb2dcb --- /dev/null +++ b/sources/SDL2Sharp/events/KeyUpEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class KeyUpEvent : KeyboardEvent + { + internal KeyUpEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/Subsystems.cs b/sources/SDL2Sharp/events/KeyboardEvent.cs similarity index 66% rename from sources/SDL2Sharp/Subsystems.cs rename to sources/SDL2Sharp/events/KeyboardEvent.cs index 95fedba8..dcc63d2d 100644 --- a/sources/SDL2Sharp/Subsystems.cs +++ b/sources/SDL2Sharp/events/KeyboardEvent.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // @@ -18,24 +18,24 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using System; using SDL2Sharp.Interop; namespace SDL2Sharp { - [Flags] - public enum Subsystems : uint + public abstract class KeyboardEvent : Event { - None = 0, - Timer = SDL.SDL_INIT_TIMER, - Audio = SDL.SDL_INIT_AUDIO, - Video = SDL.SDL_INIT_VIDEO, - Joystick = SDL.SDL_INIT_JOYSTICK, - Haptic = SDL.SDL_INIT_HAPTIC, - GameController = SDL.SDL_INIT_GAMECONTROLLER, - Events = SDL.SDL_INIT_EVENTS, - Sensor = SDL.SDL_INIT_SENSOR, - NoParachute = SDL.SDL_INIT_NOPARACHUTE, - All = SDL.SDL_INIT_EVERYTHING, + public uint WindowID => _handle.key.windowID; + + public Scancode Scancode => (Scancode)_handle.key.keysym.scancode; + + public KeyCode KeyCode => (KeyCode)_handle.key.keysym.sym; + + public KeyModifiers Modifiers => (KeyModifiers)_handle.key.keysym.mod; + + public bool Repeat => _handle.key.repeat != 0; + + protected KeyboardEvent(SDL_Event handle) + : base(handle) + { } } } diff --git a/sources/SDL2Sharp/events/LocaleChangedEvent.cs b/sources/SDL2Sharp/events/LocaleChangedEvent.cs new file mode 100644 index 00000000..69104792 --- /dev/null +++ b/sources/SDL2Sharp/events/LocaleChangedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class LocaleChangedEvent : Event + { + internal LocaleChangedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/MouseButtonDownEvent.cs b/sources/SDL2Sharp/events/MouseButtonDownEvent.cs new file mode 100644 index 00000000..ede9745a --- /dev/null +++ b/sources/SDL2Sharp/events/MouseButtonDownEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class MouseButtonDownEvent : Event + { + internal MouseButtonDownEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/MouseButtonUpEvent.cs b/sources/SDL2Sharp/events/MouseButtonUpEvent.cs new file mode 100644 index 00000000..18f22368 --- /dev/null +++ b/sources/SDL2Sharp/events/MouseButtonUpEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class MouseButtonUpEvent : Event + { + internal MouseButtonUpEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/MouseMotionEvent.cs b/sources/SDL2Sharp/events/MouseMotionEvent.cs new file mode 100644 index 00000000..26743356 --- /dev/null +++ b/sources/SDL2Sharp/events/MouseMotionEvent.cs @@ -0,0 +1,41 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class MouseMotionEvent : Event + { + public uint WindowID => _handle.motion.windowID; + + public int X => _handle.motion.x; + + public int Y => _handle.motion.y; + + public int RelativeX => _handle.motion.xrel; + + public int RelativeY => _handle.motion.yrel; + + internal MouseMotionEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/MouseWheelDirection.cs b/sources/SDL2Sharp/events/MouseWheelDirection.cs similarity index 98% rename from sources/SDL2Sharp/MouseWheelDirection.cs rename to sources/SDL2Sharp/events/MouseWheelDirection.cs index 24007bfa..dbec458e 100644 --- a/sources/SDL2Sharp/MouseWheelDirection.cs +++ b/sources/SDL2Sharp/events/MouseWheelDirection.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // diff --git a/sources/SDL2Sharp/events/MouseWheelEvent.cs b/sources/SDL2Sharp/events/MouseWheelEvent.cs new file mode 100644 index 00000000..a2d6cff4 --- /dev/null +++ b/sources/SDL2Sharp/events/MouseWheelEvent.cs @@ -0,0 +1,45 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class MouseWheelEvent : Event + { + public uint WindowID => _handle.wheel.windowID; + + public uint Which => _handle.wheel.which; + + public MouseWheelDirection Direction => (MouseWheelDirection)_handle.wheel.direction; + + public int X => _handle.wheel.x; + + public int Y => _handle.wheel.y; + + public float PreciseX => _handle.wheel.preciseX; + + public float PreciseY => _handle.wheel.preciseY; + + internal MouseWheelEvent(SDL_Event @event) + : base(@event) + { } + } +} diff --git a/sources/SDL2Sharp/events/MultiGestureEvent.cs b/sources/SDL2Sharp/events/MultiGestureEvent.cs new file mode 100644 index 00000000..99f6dc2a --- /dev/null +++ b/sources/SDL2Sharp/events/MultiGestureEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class MultiGestureEvent : Event + { + internal MultiGestureEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/PollSentinelEvent.cs b/sources/SDL2Sharp/events/PollSentinelEvent.cs new file mode 100644 index 00000000..129e1491 --- /dev/null +++ b/sources/SDL2Sharp/events/PollSentinelEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class PollSentinelEvent : Event + { + internal PollSentinelEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/QuitEvent.cs b/sources/SDL2Sharp/events/QuitEvent.cs new file mode 100644 index 00000000..f6c62013 --- /dev/null +++ b/sources/SDL2Sharp/events/QuitEvent.cs @@ -0,0 +1,35 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class QuitEvent : Event + { + public QuitEvent() + : base(new SDL_Event { type = (uint)SDL_EventType.SDL_QUIT }) + { } + + internal QuitEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/RenderDeviceResetEvent.cs b/sources/SDL2Sharp/events/RenderDeviceResetEvent.cs new file mode 100644 index 00000000..930028f5 --- /dev/null +++ b/sources/SDL2Sharp/events/RenderDeviceResetEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class RenderDeviceResetEvent : Event + { + internal RenderDeviceResetEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/RenderTargetsResetEvent.cs b/sources/SDL2Sharp/events/RenderTargetsResetEvent.cs new file mode 100644 index 00000000..ba47a551 --- /dev/null +++ b/sources/SDL2Sharp/events/RenderTargetsResetEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class RenderTargetsResetEvent : Event + { + internal RenderTargetsResetEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/SensorUpdateEvent.cs b/sources/SDL2Sharp/events/SensorUpdateEvent.cs new file mode 100644 index 00000000..e2034dec --- /dev/null +++ b/sources/SDL2Sharp/events/SensorUpdateEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class SensorUpdateEvent : Event + { + internal SensorUpdateEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/SystemWindowManagerEvent.cs b/sources/SDL2Sharp/events/SystemWindowManagerEvent.cs new file mode 100644 index 00000000..957af9f7 --- /dev/null +++ b/sources/SDL2Sharp/events/SystemWindowManagerEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class SystemWindowManagerEvent : Event + { + internal SystemWindowManagerEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/TextEditingEvent.cs b/sources/SDL2Sharp/events/TextEditingEvent.cs new file mode 100644 index 00000000..0f75d1fa --- /dev/null +++ b/sources/SDL2Sharp/events/TextEditingEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class TextEditingEvent : Event + { + internal TextEditingEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/TextEditingExtEvent.cs b/sources/SDL2Sharp/events/TextEditingExtEvent.cs new file mode 100644 index 00000000..05b7f311 --- /dev/null +++ b/sources/SDL2Sharp/events/TextEditingExtEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class TextEditingExtEvent : Event + { + internal TextEditingExtEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/TextInputEvent.cs b/sources/SDL2Sharp/events/TextInputEvent.cs new file mode 100644 index 00000000..4b3db588 --- /dev/null +++ b/sources/SDL2Sharp/events/TextInputEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class TextInputEvent : Event + { + internal TextInputEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp.Interop/SDL_free_func.cs b/sources/SDL2Sharp/events/UserEvent.cs similarity index 84% rename from sources/SDL2Sharp.Interop/SDL_free_func.cs rename to sources/SDL2Sharp/events/UserEvent.cs index e4cc9387..59f89691 100644 --- a/sources/SDL2Sharp.Interop/SDL_free_func.cs +++ b/sources/SDL2Sharp/events/UserEvent.cs @@ -18,10 +18,14 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using System.Runtime.InteropServices; +using SDL2Sharp.Interop; -namespace SDL2Sharp.Interop +namespace SDL2Sharp { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public unsafe delegate void SDL_free_func(void* mem); + public sealed class UserEvent : Event + { + internal UserEvent(SDL_Event handle) + : base(handle) + { } + } } diff --git a/sources/SDL2Sharp/events/WindowCloseEvent.cs b/sources/SDL2Sharp/events/WindowCloseEvent.cs new file mode 100644 index 00000000..657d9c7d --- /dev/null +++ b/sources/SDL2Sharp/events/WindowCloseEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowCloseEvent : WindowEvent + { + internal WindowCloseEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowDisplayChangedEvent.cs b/sources/SDL2Sharp/events/WindowDisplayChangedEvent.cs new file mode 100644 index 00000000..3b39d1f9 --- /dev/null +++ b/sources/SDL2Sharp/events/WindowDisplayChangedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowDisplayChangedEvent : Event + { + internal WindowDisplayChangedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowEnterEvent.cs b/sources/SDL2Sharp/events/WindowEnterEvent.cs new file mode 100644 index 00000000..e8aafe4c --- /dev/null +++ b/sources/SDL2Sharp/events/WindowEnterEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowEnterEvent : WindowEvent + { + internal WindowEnterEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp.Interop/SDL_AudioCallback.cs b/sources/SDL2Sharp/events/WindowEvent.cs similarity index 79% rename from sources/SDL2Sharp.Interop/SDL_AudioCallback.cs rename to sources/SDL2Sharp/events/WindowEvent.cs index 19851f45..380e4e56 100644 --- a/sources/SDL2Sharp.Interop/SDL_AudioCallback.cs +++ b/sources/SDL2Sharp/events/WindowEvent.cs @@ -18,10 +18,16 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using System.Runtime.InteropServices; +using SDL2Sharp.Interop; -namespace SDL2Sharp.Interop +namespace SDL2Sharp { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public unsafe delegate void SDL_AudioCallback(void* userdata, [NativeTypeName("Uint8 *")] byte* stream, int len); + public abstract class WindowEvent : Event + { + public uint WindowID => _handle.window.windowID; + + protected WindowEvent(SDL_Event handle) + : base(handle) + { } + } } diff --git a/sources/SDL2Sharp/events/WindowExposedEvent.cs b/sources/SDL2Sharp/events/WindowExposedEvent.cs new file mode 100644 index 00000000..9d954f84 --- /dev/null +++ b/sources/SDL2Sharp/events/WindowExposedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowExposedEvent : WindowEvent + { + internal WindowExposedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowFocusGainedEvent.cs b/sources/SDL2Sharp/events/WindowFocusGainedEvent.cs new file mode 100644 index 00000000..f027f55f --- /dev/null +++ b/sources/SDL2Sharp/events/WindowFocusGainedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowFocusGainedEvent : WindowEvent + { + internal WindowFocusGainedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowFocusLostEvent.cs b/sources/SDL2Sharp/events/WindowFocusLostEvent.cs new file mode 100644 index 00000000..be32ebc7 --- /dev/null +++ b/sources/SDL2Sharp/events/WindowFocusLostEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowFocusLostEvent : WindowEvent + { + internal WindowFocusLostEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowHiddenEvent.cs b/sources/SDL2Sharp/events/WindowHiddenEvent.cs new file mode 100644 index 00000000..c7a1b098 --- /dev/null +++ b/sources/SDL2Sharp/events/WindowHiddenEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowHiddenEvent : WindowEvent + { + internal WindowHiddenEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowHitTestEvent.cs b/sources/SDL2Sharp/events/WindowHitTestEvent.cs new file mode 100644 index 00000000..ac618a50 --- /dev/null +++ b/sources/SDL2Sharp/events/WindowHitTestEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowHitTestEvent : WindowEvent + { + internal WindowHitTestEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowIccProfileChangedEvent.cs b/sources/SDL2Sharp/events/WindowIccProfileChangedEvent.cs new file mode 100644 index 00000000..c5389cc0 --- /dev/null +++ b/sources/SDL2Sharp/events/WindowIccProfileChangedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowIccProfileChangedEvent : Event + { + internal WindowIccProfileChangedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowLeaveEvent.cs b/sources/SDL2Sharp/events/WindowLeaveEvent.cs new file mode 100644 index 00000000..f738df67 --- /dev/null +++ b/sources/SDL2Sharp/events/WindowLeaveEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowLeaveEvent : WindowEvent + { + internal WindowLeaveEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowMaximizedEvent.cs b/sources/SDL2Sharp/events/WindowMaximizedEvent.cs new file mode 100644 index 00000000..e83ca405 --- /dev/null +++ b/sources/SDL2Sharp/events/WindowMaximizedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowMaximizedEvent : WindowEvent + { + internal WindowMaximizedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowMinimizedEvent.cs b/sources/SDL2Sharp/events/WindowMinimizedEvent.cs new file mode 100644 index 00000000..ca879e91 --- /dev/null +++ b/sources/SDL2Sharp/events/WindowMinimizedEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowMinimizedEvent : WindowEvent + { + internal WindowMinimizedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowMovedEvent.cs b/sources/SDL2Sharp/events/WindowMovedEvent.cs new file mode 100644 index 00000000..6a286b6a --- /dev/null +++ b/sources/SDL2Sharp/events/WindowMovedEvent.cs @@ -0,0 +1,35 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowMovedEvent : WindowEvent + { + public int X => _handle.window.data1; + + public int Y => _handle.window.data2; + + internal WindowMovedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowResizedEvent.cs b/sources/SDL2Sharp/events/WindowResizedEvent.cs new file mode 100644 index 00000000..d73425ea --- /dev/null +++ b/sources/SDL2Sharp/events/WindowResizedEvent.cs @@ -0,0 +1,35 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowResizedEvent : WindowEvent + { + public int Width => _handle.window.data1; + + public int Height => _handle.window.data2; + + internal WindowResizedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowRestoredEvent.cs b/sources/SDL2Sharp/events/WindowRestoredEvent.cs new file mode 100644 index 00000000..7f6f4031 --- /dev/null +++ b/sources/SDL2Sharp/events/WindowRestoredEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowRestoredEvent : WindowEvent + { + internal WindowRestoredEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowShownEvent.cs b/sources/SDL2Sharp/events/WindowShownEvent.cs new file mode 100644 index 00000000..87ac4920 --- /dev/null +++ b/sources/SDL2Sharp/events/WindowShownEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowShownEvent : WindowEvent + { + internal WindowShownEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowSizeChangedEvent.cs b/sources/SDL2Sharp/events/WindowSizeChangedEvent.cs new file mode 100644 index 00000000..91caaa79 --- /dev/null +++ b/sources/SDL2Sharp/events/WindowSizeChangedEvent.cs @@ -0,0 +1,35 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowSizeChangedEvent : WindowEvent + { + public int Width => _handle.window.data1; + + public int Height => _handle.window.data2; + + internal WindowSizeChangedEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/events/WindowTakeFocusEvent.cs b/sources/SDL2Sharp/events/WindowTakeFocusEvent.cs new file mode 100644 index 00000000..2ac1928c --- /dev/null +++ b/sources/SDL2Sharp/events/WindowTakeFocusEvent.cs @@ -0,0 +1,31 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class WindowTakeFocusEvent : WindowEvent + { + internal WindowTakeFocusEvent(SDL_Event handle) + : base(handle) + { } + } +} diff --git a/sources/SDL2Sharp/fonts/Font.cs b/sources/SDL2Sharp/fonts/Font.cs new file mode 100644 index 00000000..a1d3daab --- /dev/null +++ b/sources/SDL2Sharp/fonts/Font.cs @@ -0,0 +1,64 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed unsafe class Font : FinalizableObject + { + private _TTF_Font* _handle; + + internal _TTF_Font* Handle => _handle; + + internal Font(string path, int pointSize) + { + using var marshaledPath = new MarshaledString(path); + var handle = TTF.OpenFont(marshaledPath, pointSize); + FontError.ThrowLastErrorIfNull(handle); + _handle = handle; + } + + protected override void Dispose(bool disposing) + { + if (_handle is null) return; + TTF.CloseFont(_handle); + _handle = null; + } + + public Surface RenderSolid(string text, Color color) + { + ThrowIfDisposed(); + + using var marshaledText = new MarshaledString(text); + var surfaceHandle = TTF.RenderText_Solid(_handle, marshaledText, color); + return new Surface(surfaceHandle); + } + + public Surface RenderBlended(string text, Color color) + { + ThrowIfDisposed(); + + using var marshaledText = new MarshaledString(text); + var surfaceHandle = TTF.RenderText_Blended(_handle, marshaledText, color); + return new Surface(surfaceHandle); + } + } +} diff --git a/sources/SDL2Sharp/FontError.cs b/sources/SDL2Sharp/fonts/FontError.cs similarity index 60% rename from sources/SDL2Sharp/FontError.cs rename to sources/SDL2Sharp/fonts/FontError.cs index 82e557a9..520842f7 100644 --- a/sources/SDL2Sharp/FontError.cs +++ b/sources/SDL2Sharp/fonts/FontError.cs @@ -19,7 +19,6 @@ // 3. This notice may not be removed or altered from any source distribution. using System; -using System.Runtime.Serialization; using SDL2Sharp.Interop; namespace SDL2Sharp @@ -32,54 +31,52 @@ public FontError(string message) : base(message) { } - public FontError(SerializationInfo info, StreamingContext context) - : base(info, context) - { } - public FontError(string message, Exception innerException) : base(message, innerException) { } - internal static unsafe void ThrowOnFailure(void* pointer) + public static unsafe FontError GetLastError() { - if (pointer is null) - { - throw new FontError(new string(TTF.GetError())); - } + return new FontError(new string(TTF.GetError())); } - internal static unsafe void ThrowOnFailure(int returnCode) + public static void ThrowLastError() { - if (returnCode < 0) - { - throw new Error(new string(TTF.GetError())); - } + throw GetLastError(); } - internal static unsafe void ThrowOnFailure(uint returnCode) + public static void ThrowLastErrorIf(bool condition) { - if (returnCode == 0) + if (condition) { - throw new Error(new string(TTF.GetError())); + ThrowLastError(); } } - internal static unsafe uint ReturnOrThrowOnFailure(uint returnCode) + public static unsafe void* ThrowLastErrorIfNull(void* pointer) { - if (returnCode == 0) - { - throw new Error(new string(TTF.GetError())); - } - return returnCode; + ThrowLastErrorIf(pointer is null); + + return pointer; + } + + public static void ThrowLastErrorIfNegative(int returnCode) + { + ThrowLastErrorIf(returnCode < 0); } - internal static unsafe T* ReturnOrThrowOnFailure(T* pointer) where T : unmanaged + public static void ThrowLastErrorIfZero(uint returnCode) { - if (pointer is null) + ThrowLastErrorIf(returnCode == 0); + } + + internal static uint ReturnOrThrowOnFailure(uint returnCode) + { + if (returnCode == 0) { - throw new Error(new string(TTF.GetError())); + ThrowLastError(); } - return pointer; + return returnCode; } } } diff --git a/sources/SDL2Sharp/Cursor.cs b/sources/SDL2Sharp/fonts/FontSubsystem.cs similarity index 64% rename from sources/SDL2Sharp/Cursor.cs rename to sources/SDL2Sharp/fonts/FontSubsystem.cs index ae5ac6ca..ac1749ac 100644 --- a/sources/SDL2Sharp/Cursor.cs +++ b/sources/SDL2Sharp/fonts/FontSubsystem.cs @@ -22,24 +22,30 @@ namespace SDL2Sharp { - public static class Cursor + internal sealed class FontSubsystem : FinalizableObject, IFontSubsystem { - public static bool Shown => SDL.SDL_ENABLE == SDL.ShowCursor(SDL.SDL_QUERY); + private bool _fullyInitialized; - public static bool Hidden => SDL.SDL_DISABLE == SDL.ShowCursor(SDL.SDL_QUERY); + public FontSubsystem() + { + Error.ThrowLastErrorIfNegative( + TTF.Init() + ); + _fullyInitialized = true; + } - public static bool Show() + protected override void Dispose(bool disposing) { - var result = SDL.ShowCursor(SDL.SDL_ENABLE); - Error.ThrowOnFailure(result); - return result == SDL.SDL_ENABLE; + if (!_fullyInitialized) return; + TTF.Quit(); + _fullyInitialized = false; } - public static bool Hide() + public Font OpenFont(string path, int pointSize) { - var result = SDL.ShowCursor(SDL.SDL_DISABLE); - Error.ThrowOnFailure(result); - return result == SDL.SDL_DISABLE; + ThrowIfDisposed(); + + return new Font(path, pointSize); } } } diff --git a/sources/SDL2Sharp/WithLockSurfaceCallback.cs b/sources/SDL2Sharp/fonts/IFontSubsystem.cs similarity index 88% rename from sources/SDL2Sharp/WithLockSurfaceCallback.cs rename to sources/SDL2Sharp/fonts/IFontSubsystem.cs index 9a5a0fab..27848688 100644 --- a/sources/SDL2Sharp/WithLockSurfaceCallback.cs +++ b/sources/SDL2Sharp/fonts/IFontSubsystem.cs @@ -20,6 +20,8 @@ namespace SDL2Sharp { - public delegate void WithLockSurfaceCallback(Surface image) - where TPackedColor : struct; + public interface IFontSubsystem + { + Font OpenFont(string path, int pointSize); + } } diff --git a/sources/SDL2Sharp/Internals/MarshaledString.cs b/sources/SDL2Sharp/internals/MarshaledString.cs similarity index 92% rename from sources/SDL2Sharp/Internals/MarshaledString.cs rename to sources/SDL2Sharp/internals/MarshaledString.cs index a4287d3a..5cadda62 100644 --- a/sources/SDL2Sharp/Internals/MarshaledString.cs +++ b/sources/SDL2Sharp/internals/MarshaledString.cs @@ -22,7 +22,7 @@ using System.Runtime.InteropServices; using System.Text; -namespace SDL2Sharp.Internals +namespace SDL2Sharp { internal unsafe struct MarshaledString : IDisposable { @@ -38,7 +38,7 @@ public MarshaledString(string input) } else { - var valueBytes = (input.Length != 0) ? Encoding.UTF8.GetBytes(input) : Array.Empty(); + var valueBytes = (input.Length != 0) ? Encoding.UTF8.GetBytes(input) : []; length = valueBytes.Length; value = Marshal.AllocHGlobal(length + 1); Marshal.Copy(valueBytes, 0, value, length); @@ -49,7 +49,7 @@ public MarshaledString(string input) Value = (sbyte*)value; } - public ReadOnlySpan AsSpan() => new(Value, Length); + public readonly ReadOnlySpan AsSpan() => new(Value, Length); public int Length { get; private set; } @@ -67,7 +67,7 @@ public void Dispose() public static implicit operator sbyte*(in MarshaledString value) => value.Value; - public override string ToString() + public override readonly string ToString() { var span = new ReadOnlySpan(Value, Length); return span.AsString(); diff --git a/sources/SDL2Sharp/Internals/SpanExtensions.cs b/sources/SDL2Sharp/internals/SpanExtensions.cs similarity index 98% rename from sources/SDL2Sharp/Internals/SpanExtensions.cs rename to sources/SDL2Sharp/internals/SpanExtensions.cs index 452e3abb..0f9f5f11 100644 --- a/sources/SDL2Sharp/Internals/SpanExtensions.cs +++ b/sources/SDL2Sharp/internals/SpanExtensions.cs @@ -21,7 +21,7 @@ using System; using System.Text; -namespace SDL2Sharp.Internals +namespace SDL2Sharp { internal static unsafe class SpanExtensions { diff --git a/sources/SDL2Sharp/internals/Utilities.cs b/sources/SDL2Sharp/internals/Utilities.cs new file mode 100644 index 00000000..2eca7948 --- /dev/null +++ b/sources/SDL2Sharp/internals/Utilities.cs @@ -0,0 +1,34 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; + +namespace SDL2Sharp +{ + internal static class Utilities + { + public static void SafeDispose(ref TDisposable? disposable) where TDisposable : IDisposable + { + var temp = disposable; + disposable = default; + temp?.Dispose(); + } + } +} \ No newline at end of file diff --git a/sources/SDL2Sharp/KeyCode.cs b/sources/SDL2Sharp/keyboard/KeyCode.cs similarity index 99% rename from sources/SDL2Sharp/KeyCode.cs rename to sources/SDL2Sharp/keyboard/KeyCode.cs index 6205803f..9a24b338 100644 --- a/sources/SDL2Sharp/KeyCode.cs +++ b/sources/SDL2Sharp/keyboard/KeyCode.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // diff --git a/sources/SDL2Sharp/keyboard/KeyboardState.cs b/sources/SDL2Sharp/keyboard/KeyboardState.cs new file mode 100644 index 00000000..3f6e4827 --- /dev/null +++ b/sources/SDL2Sharp/keyboard/KeyboardState.cs @@ -0,0 +1,44 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; + +namespace SDL2Sharp +{ + public readonly ref struct KeyboardState + { + private readonly ReadOnlySpan _keyStates; + + internal KeyboardState(Span keyStates) + { + _keyStates = keyStates; + } + + public bool IsPressed(Scancode scanCode) + { + return _keyStates[(int)scanCode] == 1; + } + + public bool IsReleased(Scancode scanCode) + { + return _keyStates[(int)scanCode] == 0; + } + } +} diff --git a/sources/SDL2Sharp/MouseMotionEventArgs.cs b/sources/SDL2Sharp/keyboard/SDL.cs similarity index 74% rename from sources/SDL2Sharp/MouseMotionEventArgs.cs rename to sources/SDL2Sharp/keyboard/SDL.cs index 2063e6fe..afd35a01 100644 --- a/sources/SDL2Sharp/MouseMotionEventArgs.cs +++ b/sources/SDL2Sharp/keyboard/SDL.cs @@ -22,22 +22,18 @@ namespace SDL2Sharp { - public sealed class MouseMotionEventArgs : EventArgs + public sealed partial class SDL { - public int X { get; } - - public int Y { get; } - - public int RelativeX { get; } - - public int RelativeY { get; } - - public MouseMotionEventArgs(int x, int y, int relativeX, int relativeY) + public unsafe KeyboardState KeyboardState { - X = x; - Y = y; - RelativeX = relativeX; - RelativeY = relativeY; + get + { + ThrowIfDisposed(); + + int keyCount; + byte* keyStates = Interop.SDL.GetKeyboardState(&keyCount); + return new KeyboardState(new Span(keyStates, keyCount)); + } } } } diff --git a/sources/SDL2Sharp/Scancode.cs b/sources/SDL2Sharp/keyboard/Scancode.cs similarity index 99% rename from sources/SDL2Sharp/Scancode.cs rename to sources/SDL2Sharp/keyboard/Scancode.cs index 452c6794..e5f4de47 100644 --- a/sources/SDL2Sharp/Scancode.cs +++ b/sources/SDL2Sharp/keyboard/Scancode.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // diff --git a/sources/SDL2Sharp/mouse/SDL.cs b/sources/SDL2Sharp/mouse/SDL.cs new file mode 100644 index 00000000..5dfd8073 --- /dev/null +++ b/sources/SDL2Sharp/mouse/SDL.cs @@ -0,0 +1,43 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +namespace SDL2Sharp +{ + public sealed partial class SDL + { + public bool ShowCursor + { + get + { + ThrowIfDisposed(); + + return Interop.SDL.SDL_ENABLE == Interop.SDL.ShowCursor(Interop.SDL.SDL_QUERY); + } + set + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.ShowCursor(Interop.SDL.SDL_ENABLE) + ); + } + } + } +} diff --git a/sources/SDL2Sharp/PixelArrayOrder.cs b/sources/SDL2Sharp/video/ArrayOrder.cs similarity index 98% rename from sources/SDL2Sharp/PixelArrayOrder.cs rename to sources/SDL2Sharp/video/ArrayOrder.cs index 2b857077..26143b45 100644 --- a/sources/SDL2Sharp/PixelArrayOrder.cs +++ b/sources/SDL2Sharp/video/ArrayOrder.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // diff --git a/sources/SDL2Sharp/BitmapOrder.cs b/sources/SDL2Sharp/video/BitmapOrder.cs similarity index 98% rename from sources/SDL2Sharp/BitmapOrder.cs rename to sources/SDL2Sharp/video/BitmapOrder.cs index 7a170424..4ceeeb8a 100644 --- a/sources/SDL2Sharp/BitmapOrder.cs +++ b/sources/SDL2Sharp/video/BitmapOrder.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // diff --git a/sources/SDL2Sharp/BlendMode.cs b/sources/SDL2Sharp/video/BlendMode.cs similarity index 75% rename from sources/SDL2Sharp/BlendMode.cs rename to sources/SDL2Sharp/video/BlendMode.cs index d4f945a1..ff92cb29 100644 --- a/sources/SDL2Sharp/BlendMode.cs +++ b/sources/SDL2Sharp/video/BlendMode.cs @@ -18,17 +18,17 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using SDL2Sharp.Interop; +using static SDL2Sharp.Interop.SDL_BlendMode; namespace SDL2Sharp { public enum BlendMode { - None = SDL_BlendMode.SDL_BLENDMODE_NONE, - Blend = SDL_BlendMode.SDL_BLENDMODE_BLEND, - Add = SDL_BlendMode.SDL_BLENDMODE_ADD, - Mod = SDL_BlendMode.SDL_BLENDMODE_MOD, - Mul = SDL_BlendMode.SDL_BLENDMODE_MUL, - Invalid = SDL_BlendMode.SDL_BLENDMODE_INVALID, + None = SDL_BLENDMODE_NONE, + Blend = SDL_BLENDMODE_BLEND, + Add = SDL_BLENDMODE_ADD, + Mod = SDL_BLENDMODE_MOD, + Mul = SDL_BLENDMODE_MUL, + Invalid = SDL_BLENDMODE_INVALID, } } diff --git a/sources/SDL2Sharp/Color.cs b/sources/SDL2Sharp/video/Color.cs similarity index 79% rename from sources/SDL2Sharp/Color.cs rename to sources/SDL2Sharp/video/Color.cs index f1091dc2..7f41f0ec 100644 --- a/sources/SDL2Sharp/Color.cs +++ b/sources/SDL2Sharp/video/Color.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // @@ -24,6 +24,18 @@ namespace SDL2Sharp { public readonly struct Color { + public static readonly Color Black = new(0, 0, 0, 255); + + public static readonly Color White = new(255, 255, 255, 255); + + public static readonly Color Red = new(255, 0, 0, 255); + + public static readonly Color Green = new(0, 255, 0, 255); + + public static readonly Color Blue = new(0, 0, 255, 255); + + public static readonly Color Yellow = new(255, 255, 0, 255); + private readonly SDL_Color _handle; public Color(byte r, byte g, byte b, byte a) diff --git a/sources/SDL2Sharp/video/Display.cs b/sources/SDL2Sharp/video/Display.cs new file mode 100644 index 00000000..df905b37 --- /dev/null +++ b/sources/SDL2Sharp/video/Display.cs @@ -0,0 +1,121 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Collections.Generic; +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed unsafe class Display + { + private readonly int _displayIndex; + + public string Name + { + get + { + return new string( + Error.ThrowLastErrorIfNull( + Interop.SDL.GetDisplayName(_displayIndex) + ) + ); + } + } + + public Rectangle Bounds + { + get + { + var rect = new SDL_Rect(); + Error.ThrowLastErrorIfNegative( + Interop.SDL.GetDisplayBounds(_displayIndex, &rect) + ); + return new Rectangle(rect.x, rect.y, rect.w, rect.h); + } + } + + public DisplayMode CurrentMode + { + get + { + var displayMode = new SDL_DisplayMode(); + Error.ThrowLastErrorIfNegative( + Interop.SDL.GetCurrentDisplayMode(_displayIndex, &displayMode) + ); + return new DisplayMode( + (PixelFormat)displayMode.format, + displayMode.w, + displayMode.h, + displayMode.refresh_rate); + } + } + + public DisplayMode DesktopMode + { + get + { + var displayMode = new SDL_DisplayMode(); + Error.ThrowLastErrorIfNegative( + Interop.SDL.GetDesktopDisplayMode(_displayIndex, &displayMode) + ); + return new DisplayMode( + (PixelFormat)displayMode.format, + displayMode.w, + displayMode.h, + displayMode.refresh_rate); + } + } + + public IReadOnlyList Modes + { + get + { + var modeCount = Interop.SDL.GetNumDisplayModes(_displayIndex); + var modes = new List(modeCount); + for (var modeIndex = 0; modeIndex < modeCount; modeIndex++) + { + var displayMode = new SDL_DisplayMode(); + Error.ThrowLastErrorIfNegative( + Interop.SDL.GetDisplayMode(_displayIndex, modeIndex, &displayMode) + ); + modes.Add(new DisplayMode( + (PixelFormat)displayMode.format, + displayMode.w, + displayMode.h, + displayMode.refresh_rate)); + } + return modes.AsReadOnly(); + } + } + + public DisplayOrientation Orientation + { + get + { + return (DisplayOrientation)Interop.SDL.GetDisplayOrientation(_displayIndex); + } + } + + internal Display(int displayIndex) + { + _displayIndex = displayIndex; + } + } +} diff --git a/sources/SDL2Sharp/WindowSizeChangedEventArgs.cs b/sources/SDL2Sharp/video/DisplayMode.cs similarity index 80% rename from sources/SDL2Sharp/WindowSizeChangedEventArgs.cs rename to sources/SDL2Sharp/video/DisplayMode.cs index b5f63ca1..cb4d6167 100644 --- a/sources/SDL2Sharp/WindowSizeChangedEventArgs.cs +++ b/sources/SDL2Sharp/video/DisplayMode.cs @@ -18,20 +18,24 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using System; - namespace SDL2Sharp { - public sealed class WindowSizeChangedEventArgs : EventArgs + public sealed class DisplayMode { + public PixelFormat Format { get; } + public int Width { get; } public int Height { get; } - public WindowSizeChangedEventArgs(int width, int height) + public int RefreshRate { get; } + + internal DisplayMode(PixelFormat format, int width, int height, int refreshRate) { + Format = format; Width = width; Height = height; + RefreshRate = refreshRate; } } } diff --git a/sources/SDL2Sharp/video/DisplayOrientation.cs b/sources/SDL2Sharp/video/DisplayOrientation.cs new file mode 100644 index 00000000..d1b1c69a --- /dev/null +++ b/sources/SDL2Sharp/video/DisplayOrientation.cs @@ -0,0 +1,33 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using static SDL2Sharp.Interop.SDL_DisplayOrientation; + +namespace SDL2Sharp +{ + public enum DisplayOrientation + { + Unknown = SDL_ORIENTATION_UNKNOWN, + Landscape = SDL_ORIENTATION_LANDSCAPE, + LandscapeFlipped = SDL_ORIENTATION_LANDSCAPE_FLIPPED, + Portrait = SDL_ORIENTATION_PORTRAIT, + PortraitFlipped = SDL_ORIENTATION_PORTRAIT_FLIPPED + } +} diff --git a/sources/SDL2Sharp/video/IVideoSubsystem.cs b/sources/SDL2Sharp/video/IVideoSubsystem.cs new file mode 100644 index 00000000..c594bdad --- /dev/null +++ b/sources/SDL2Sharp/video/IVideoSubsystem.cs @@ -0,0 +1,37 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Collections.Generic; + +namespace SDL2Sharp +{ + public interface IVideoSubsystem + { + IReadOnlyList Displays { get; } + + Window CreateWindow(string title, int width, int height); + + Window CreateWindow(string title, int x, int y, int width, int height); + + Window CreateWindow(string title, int x, int y, int width, int height, WindowFlags flags); + + Window CreateWindow(string title, int width, int height, WindowFlags flags); + } +} diff --git a/sources/SDL2Sharp/PackedMemoryImage.cs b/sources/SDL2Sharp/video/ImageMemoryPlane.cs similarity index 76% rename from sources/SDL2Sharp/PackedMemoryImage.cs rename to sources/SDL2Sharp/video/ImageMemoryPlane.cs index 1916de5f..6c6d5a7b 100644 --- a/sources/SDL2Sharp/PackedMemoryImage.cs +++ b/sources/SDL2Sharp/video/ImageMemoryPlane.cs @@ -19,23 +19,28 @@ // 3. This notice may not be removed or altered from any source distribution. using System; -using Microsoft.Toolkit.HighPerformance; +using System.Runtime.InteropServices; +using CommunityToolkit.HighPerformance; namespace SDL2Sharp { - public sealed class PackedMemoryImage where TPackedColor : struct + public sealed class ImageMemoryPlane where TPackedPixel : struct { + private readonly int _width; + private readonly int _height; - private readonly int _width; + private readonly TPackedPixel[] _pixels; - private readonly TPackedColor[] _pixels; + public int Width => _width; public int Height => _height; - public int Width => _width; + public Size Size => new(_width, _height); - public TPackedColor this[int y, int x] + public int Pitch => _width * Marshal.SizeOf(); + + public TPackedPixel this[int x, int y] { get { @@ -47,14 +52,14 @@ public sealed class PackedMemoryImage where TPackedColor : struct } } - public PackedMemoryImage(int width, int height) + public ImageMemoryPlane(int width, int height) { if (width <= 0) { throw new ArgumentOutOfRangeException( nameof(width), width, - "The width of the image must be a positive integer."); + "The width of the image plane must be a positive integer."); } if (height <= 0) @@ -62,19 +67,19 @@ public PackedMemoryImage(int width, int height) throw new ArgumentOutOfRangeException( nameof(height), height, - "The height of the image must be a positive integer."); + "The height of the image plane must be a positive integer."); } _width = width; _height = height; - _pixels = new TPackedColor[_height * _width]; + _pixels = new TPackedPixel[_height * _width]; } - public PackedMemoryImage(Size size) + public ImageMemoryPlane(Size size) : this(size.Width, size.Height) { } - public PackedMemoryImage Crop(int top, int left, int bottom, int right) + public ImageMemoryPlane Crop(int top, int left, int bottom, int right) { if (top < 0) { @@ -124,20 +129,25 @@ public PackedMemoryImage Crop(int top, int left, int bottom, int r "The right of the crop rectangle cannot be less than or equal to the left of the crop rectangle."); } - var croppedImage = new PackedMemoryImage(right - left, bottom - top); + var croppedImage = new ImageMemoryPlane(right - left, bottom - top); for (var y = 0; y < croppedImage.Height; ++y) { for (var x = 0; x < croppedImage.Width; ++x) { - croppedImage[y, x] = this[y + top, x + left]; + croppedImage[x, y] = this[x + left, y + top]; } } return croppedImage; } - public ref TPackedColor DangerousGetReference() + public ref TPackedPixel DangerousGetReference() { return ref _pixels.DangerousGetReference(); } + + public static unsafe explicit operator void*(ImageMemoryPlane imagePlane) + { + return (void*)imagePlane; + } } } diff --git a/sources/SDL2Sharp/PackedImage.cs b/sources/SDL2Sharp/video/ImagePlane.cs similarity index 56% rename from sources/SDL2Sharp/PackedImage.cs rename to sources/SDL2Sharp/video/ImagePlane.cs index bdd925c1..93f45382 100644 --- a/sources/SDL2Sharp/PackedImage.cs +++ b/sources/SDL2Sharp/video/ImagePlane.cs @@ -25,76 +25,82 @@ namespace SDL2Sharp { - public ref struct PackedImage + public readonly unsafe ref struct ImagePlane where TPackedPixel : struct { - private readonly Span _pixels; - - private readonly int _height; + private readonly void* _pixels; private readonly int _width; + private readonly int _height; + private readonly int _pitch; - public int Width + public readonly int Width { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return _width; - } + get => _width; } - public int Height + public readonly int Height { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return _height; - } + get => _height; + } + + public Size Size + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => new(_width, _height); } - public ref TPackedColor this[int row, int column] + public readonly int Pitch + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _pitch; + } + + public ref TPackedPixel this[int x, int y] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if (row < 0) + if (x < 0) { throw new ArgumentOutOfRangeException( - nameof(row), - row, - "row cannot be less than zero"); + nameof(x), + x, + "x cannot be less than zero"); } - if (row >= _height) + if (x >= _width) { throw new ArgumentOutOfRangeException( - nameof(column), - column, - "row cannot be greater than or equal to the height of the image"); + nameof(x), + x, + "x cannot be greater than or equal to the width of the image"); } - if (column < 0) + if (y < 0) { throw new ArgumentOutOfRangeException( - nameof(column), - column, - "column cannot be less than zero"); + nameof(y), + y, + "y cannot be less than zero"); } - if (column >= _width) + if (y >= _height) { throw new ArgumentOutOfRangeException( - nameof(column), - column, - "column cannot be greater than or equal to the width of the image"); + nameof(x), + x, + "y cannot be greater than or equal to the height of the image"); } - return ref DangerousGetReferenceAt(row, column); + return ref DangerousGetReferenceAt(x, y); } } - public unsafe PackedImage(void* pixels, int height, int width, int pitch) + public ImagePlane(void* pixels, int width, int height, int pitch) { if (height < 0) { @@ -117,10 +123,10 @@ public unsafe PackedImage(void* pixels, int height, int width, int pitch) throw new ArgumentOutOfRangeException( nameof(pitch), pitch, - "height cannot be less than zero"); + "pitch cannot be less than zero"); } - _pixels = new Span(pixels, height * pitch); + _pixels = pixels; _height = height; _width = width; _pitch = pitch; @@ -128,24 +134,35 @@ public unsafe PackedImage(void* pixels, int height, int width, int pitch) [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref TPackedColor DangerousGetReference() + public readonly ref TPackedPixel DangerousGetReference() { - return ref MemoryMarshal.GetReference(_pixels); + return ref Unsafe.AsRef(_pixels); } [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ref TPackedColor DangerousGetReferenceAt(int row, int column) + public readonly ref TPackedPixel DangerousGetReferenceAt(int x, int y) { - ref var r0 = ref MemoryMarshal.GetReference(_pixels); - var index = row * _pitch + column; - return ref Unsafe.Add(ref r0, index); + ref var r0 = ref Unsafe.AsRef(_pixels); + var index = y * _pitch + x * Marshal.SizeOf(); + return ref Unsafe.AddByteOffset(ref r0, index); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Fill(TPackedColor value) + public readonly void Fill(TPackedPixel value) + { + for (var y = 0; y < _height; y++) + { + for (var x = 0; x < _width; x++) + { + this[x, y] = value; + } + } + } + + public static explicit operator void*(ImagePlane imagePlane) { - _pixels.Fill(value); + return imagePlane._pixels; } } } diff --git a/sources/SDL2Sharp/video/NV12Image.cs b/sources/SDL2Sharp/video/NV12Image.cs new file mode 100644 index 00000000..25697ae7 --- /dev/null +++ b/sources/SDL2Sharp/video/NV12Image.cs @@ -0,0 +1,79 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Runtime.CompilerServices; + +namespace SDL2Sharp +{ + public readonly ref struct NV12Image + { + private readonly ImagePlane _yPlane; + + private readonly ImagePlane _uvPlane; + + public ImagePlane Y => _yPlane; + + public ImagePlane UV => _uvPlane; + + public readonly int Width + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _yPlane.Width; + } + + public readonly int Height + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _yPlane.Height; + } + + public unsafe NV12Image(void* pixels, int width, int height, int pitch) + { + if (height < 0) + { + throw new ArgumentOutOfRangeException( + nameof(height), + height, + "height cannot be less than zero"); + } + + if (width < 0) + { + throw new ArgumentOutOfRangeException( + nameof(width), + width, + "height cannot be less than zero"); + } + + if (pitch < 0) + { + throw new ArgumentOutOfRangeException( + nameof(pitch), + pitch, + "pitch cannot be less than zero"); + } + + _yPlane = new ImagePlane(pixels, width, height, pitch); + var uvPlanePixels = Unsafe.Add(pixels, height * pitch); + _uvPlane = new ImagePlane(uvPlanePixels, width / 2, height / 2, pitch / 2); + } + } +} diff --git a/sources/SDL2Sharp/video/NV12MemoryImage.cs b/sources/SDL2Sharp/video/NV12MemoryImage.cs new file mode 100644 index 00000000..b445ce93 --- /dev/null +++ b/sources/SDL2Sharp/video/NV12MemoryImage.cs @@ -0,0 +1,70 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Runtime.CompilerServices; + +namespace SDL2Sharp +{ + public sealed class NV12MemoryImage + { + private readonly ImageMemoryPlane _yPlane; + + private readonly ImageMemoryPlane _uvPlane; + + public ImageMemoryPlane Y => _yPlane; + + public ImageMemoryPlane UV => _uvPlane; + + public int Width + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _yPlane.Width; + } + + public int Height + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _yPlane.Height; + } + + public NV12MemoryImage(int width, int height) + { + if (width < 0) + { + throw new ArgumentOutOfRangeException( + nameof(width), + width, + "height cannot be less than zero"); + } + + if (height < 0) + { + throw new ArgumentOutOfRangeException( + nameof(height), + height, + "height cannot be less than zero"); + } + + _yPlane = new ImageMemoryPlane(width, height); + _uvPlane = new ImageMemoryPlane(width / 2, height / 2); + } + } +} diff --git a/sources/SDL2Sharp/video/NV12Texture.cs b/sources/SDL2Sharp/video/NV12Texture.cs new file mode 100644 index 00000000..3f995266 --- /dev/null +++ b/sources/SDL2Sharp/video/NV12Texture.cs @@ -0,0 +1,188 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed unsafe class NV12Texture : DisposableObject + { + public delegate void LockCallback(NV12Image pixels); + + private readonly Texture _texture; + + public PixelFormat Format + { + get + { + ThrowIfDisposed(); + + return _texture.Format; + } + } + + public TextureAccess Access + { + get + { + ThrowIfDisposed(); + + return _texture.Access; + } + } + + public int Width + { + get + { + ThrowIfDisposed(); + + return _texture.Width; + } + } + + public int Height + { + get + { + ThrowIfDisposed(); + + return _texture.Height; + } + } + + public Size Size + { + get + { + ThrowIfDisposed(); + + return _texture.Size; + } + } + + public BlendMode BlendMode + { + get + { + ThrowIfDisposed(); + + return _texture.BlendMode; + } + set + { + ThrowIfDisposed(); + + _texture.BlendMode = value; + } + } + + public bool IsValid + { + get + { + ThrowIfDisposed(); + + return _texture.IsValid; + } + } + + internal NV12Texture(Texture texture) + { + ArgumentNullException.ThrowIfNull(texture); + + if (texture.Format != PixelFormat.NV12) + { + throw new ArgumentException("Texture is not in a NV12 format", nameof(texture)); + } + + _texture = texture; + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + _texture?.Dispose(); + } + } + + public void WithLock(LockCallback callback) + { + WithLock(0, 0, Width, Height, callback); + } + + public void WithLock(Rectangle rectangle, LockCallback callback) + { + WithLock(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, callback); + } + + public void WithLock(int x, int y, int width, int height, LockCallback callback) + { + ArgumentNullException.ThrowIfNull(callback); + + ThrowIfDisposed(); + + var rect = new SDL_Rect { x = x, y = y, w = width, h = height }; + void* pixels; + int pitch; + Error.ThrowLastErrorIfNegative( + Interop.SDL.LockTexture(_texture.Handle, &rect, &pixels, &pitch) + ); + + var image = new NV12Image(pixels, width, height, pitch); + callback.Invoke(image); + Interop.SDL.UnlockTexture(_texture.Handle); + } + + public void Update(NV12Image image) + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.UpdateNVTexture(_texture.Handle, null, + (byte*)image.Y, image.Y.Pitch, + (byte*)image.UV, image.UV.Pitch) + ); + } + + public void Update(NV12MemoryImage image) + { + ArgumentNullException.ThrowIfNull(image); + + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.UpdateNVTexture(_texture.Handle, null, + (byte*)image.Y, image.Y.Pitch, + (byte*)image.UV, image.UV.Pitch + ) + ); + } + + public static implicit operator Texture(NV12Texture texture) + { + ArgumentNullException.ThrowIfNull(texture); + + return texture._texture; + } + } +} diff --git a/sources/SDL2Sharp/video/NV21Image.cs b/sources/SDL2Sharp/video/NV21Image.cs new file mode 100644 index 00000000..e05c7098 --- /dev/null +++ b/sources/SDL2Sharp/video/NV21Image.cs @@ -0,0 +1,79 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Runtime.CompilerServices; + +namespace SDL2Sharp +{ + public readonly ref struct NV21Image + { + private readonly ImagePlane _yPlane; + + private readonly ImagePlane _uvPlane; + + public ImagePlane Y => _yPlane; + + public ImagePlane UV => _uvPlane; + + public readonly int Width + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _yPlane.Width; + } + + public readonly int Height + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _yPlane.Height; + } + + public unsafe NV21Image(void* pixels, int width, int height, int pitch) + { + if (height < 0) + { + throw new ArgumentOutOfRangeException( + nameof(height), + height, + "height cannot be less than zero"); + } + + if (width < 0) + { + throw new ArgumentOutOfRangeException( + nameof(width), + width, + "height cannot be less than zero"); + } + + if (pitch < 0) + { + throw new ArgumentOutOfRangeException( + nameof(pitch), + pitch, + "pitch cannot be less than zero"); + } + + _yPlane = new ImagePlane(pixels, width, height, pitch); + var uvPlanePixels = Unsafe.Add(pixels, height * pitch); + _uvPlane = new ImagePlane(uvPlanePixels, width / 2, height / 2, pitch / 2); + } + } +} diff --git a/sources/SDL2Sharp/video/NV21MemoryImage.cs b/sources/SDL2Sharp/video/NV21MemoryImage.cs new file mode 100644 index 00000000..40725b25 --- /dev/null +++ b/sources/SDL2Sharp/video/NV21MemoryImage.cs @@ -0,0 +1,70 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Runtime.CompilerServices; + +namespace SDL2Sharp +{ + public sealed class NV21MemoryImage + { + private readonly ImageMemoryPlane _yPlane; + + private readonly ImageMemoryPlane _uvPlane; + + public ImageMemoryPlane Y => _yPlane; + + public ImageMemoryPlane UV => _uvPlane; + + public int Width + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _yPlane.Width; + } + + public int Height + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _yPlane.Height; + } + + public NV21MemoryImage(int width, int height) + { + if (width < 0) + { + throw new ArgumentOutOfRangeException( + nameof(width), + width, + "height cannot be less than zero"); + } + + if (height < 0) + { + throw new ArgumentOutOfRangeException( + nameof(height), + height, + "height cannot be less than zero"); + } + + _yPlane = new ImageMemoryPlane(width, height); + _uvPlane = new ImageMemoryPlane(width / 2, height / 2); + } + } +} diff --git a/sources/SDL2Sharp/video/NV21Texture.cs b/sources/SDL2Sharp/video/NV21Texture.cs new file mode 100644 index 00000000..3aecc047 --- /dev/null +++ b/sources/SDL2Sharp/video/NV21Texture.cs @@ -0,0 +1,188 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed unsafe class NV21Texture : DisposableObject + { + public delegate void LockCallback(NV21Image pixels); + + private readonly Texture _texture; + + public PixelFormat Format + { + get + { + ThrowIfDisposed(); + + return _texture.Format; + } + } + + public TextureAccess Access + { + get + { + ThrowIfDisposed(); + + return _texture.Access; + } + } + + public int Width + { + get + { + ThrowIfDisposed(); + + return _texture.Width; + } + } + + public int Height + { + get + { + ThrowIfDisposed(); + + return _texture.Height; + } + } + + public Size Size + { + get + { + ThrowIfDisposed(); + + return _texture.Size; + } + } + + public BlendMode BlendMode + { + get + { + ThrowIfDisposed(); + + return _texture.BlendMode; + } + set + { + ThrowIfDisposed(); + + _texture.BlendMode = value; + } + } + + public bool IsValid + { + get + { + ThrowIfDisposed(); + + return _texture.IsValid; + } + } + + internal NV21Texture(Texture texture) + { + ArgumentNullException.ThrowIfNull(texture); + + if (texture.Format != PixelFormat.NV21) + { + throw new ArgumentException("Texture is not in a NV21 format", nameof(texture)); + } + + _texture = texture; + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + _texture?.Dispose(); + } + } + + public void WithLock(LockCallback callback) + { + WithLock(0, 0, Width, Height, callback); + } + + public void WithLock(Rectangle rectangle, LockCallback callback) + { + WithLock(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, callback); + } + + public void WithLock(int x, int y, int width, int height, LockCallback callback) + { + ArgumentNullException.ThrowIfNull(callback); + + ThrowIfDisposed(); + + var rect = new SDL_Rect { x = x, y = y, w = width, h = height }; + void* pixels; + int pitch; + Error.ThrowLastErrorIfNegative( + Interop.SDL.LockTexture(_texture.Handle, &rect, &pixels, &pitch) + ); + + var image = new NV21Image(pixels, width, height, pitch); + callback.Invoke(image); + Interop.SDL.UnlockTexture(_texture.Handle); + } + + public void Update(NV21Image image) + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.UpdateNVTexture(_texture.Handle, null, + (byte*)image.Y, image.Y.Pitch, + (byte*)image.UV, image.UV.Pitch) + ); + } + + public void Update(NV21MemoryImage image) + { + ArgumentNullException.ThrowIfNull(image); + + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.UpdateNVTexture(_texture.Handle, null, + (byte*)image.Y, image.Y.Pitch, + (byte*)image.UV, image.UV.Pitch + ) + ); + } + + public static implicit operator Texture(NV21Texture texture) + { + ArgumentNullException.ThrowIfNull(texture); + + return texture._texture; + } + } +} diff --git a/sources/SDL2Sharp/video/PackedImage.cs b/sources/SDL2Sharp/video/PackedImage.cs new file mode 100644 index 00000000..4a20f05a --- /dev/null +++ b/sources/SDL2Sharp/video/PackedImage.cs @@ -0,0 +1,90 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Diagnostics.Contracts; +using System.Runtime.CompilerServices; + +namespace SDL2Sharp +{ + public readonly ref struct PackedImage where TPackedPixel : struct + { + private readonly ImagePlane _plane; + + public int Width + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _plane.Width; + } + + public int Height + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _plane.Height; + } + + public Size Size + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _plane.Size; + } + + public int Pitch + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _plane.Pitch; + } + + public ref TPackedPixel this[int x, int y] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => ref _plane[x, y]; + } + + public unsafe PackedImage(void* pixels, int width, int height, int pitch) + { + _plane = new ImagePlane(pixels, width, height, pitch); + } + + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ref TPackedPixel DangerousGetReference() + { + return ref _plane.DangerousGetReference(); + } + + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ref TPackedPixel DangerousGetReferenceAt(int x, int y) + { + return ref _plane.DangerousGetReferenceAt(x, y); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Fill(TPackedPixel value) + { + _plane.Fill(value); + } + + public static unsafe explicit operator void*(PackedImage image) + { + return (void*)image; + } + } +} diff --git a/sources/SDL2Sharp/video/PackedLayout.cs b/sources/SDL2Sharp/video/PackedLayout.cs new file mode 100644 index 00000000..f19c85f3 --- /dev/null +++ b/sources/SDL2Sharp/video/PackedLayout.cs @@ -0,0 +1,37 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using static SDL2Sharp.Interop.SDL_PackedLayout; + +namespace SDL2Sharp +{ + public enum PackedLayout + { + None = SDL_PACKEDLAYOUT_NONE, + _332 = SDL_PACKEDLAYOUT_332, + _4444 = SDL_PACKEDLAYOUT_4444, + _1555 = SDL_PACKEDLAYOUT_1555, + _5551 = SDL_PACKEDLAYOUT_5551, + _565 = SDL_PACKEDLAYOUT_565, + _8888 = SDL_PACKEDLAYOUT_8888, + _2101010 = SDL_PACKEDLAYOUT_2101010, + _1010102 = SDL_PACKEDLAYOUT_1010102, + } +} diff --git a/sources/SDL2Sharp/video/PackedMemoryImage.cs b/sources/SDL2Sharp/video/PackedMemoryImage.cs new file mode 100644 index 00000000..7ba71ee7 --- /dev/null +++ b/sources/SDL2Sharp/video/PackedMemoryImage.cs @@ -0,0 +1,80 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Runtime.CompilerServices; + +namespace SDL2Sharp +{ + public sealed class PackedMemoryImage where TPackedPixel : struct + { + private readonly ImageMemoryPlane _plane; + + public int Width => _plane.Width; + + public int Height => _plane.Height; + + public Size Size => _plane.Size; + + public int Pitch => _plane.Pitch; + + public TPackedPixel this[int x, int y] + { + get + { + return _plane[x, y]; + } + set + { + _plane[x, y] = value; + } + } + + public PackedMemoryImage(Size size) + : this(size.Width, size.Height) + { } + + public PackedMemoryImage(int width, int height) + : this(new ImageMemoryPlane(width, height)) + { } + + private PackedMemoryImage(ImageMemoryPlane plane) + { + _plane = plane ?? throw new ArgumentNullException(nameof(plane)); + } + + public PackedMemoryImage Crop(int top, int left, int bottom, int right) + { + var croppedPlane = _plane.Crop(top, left, bottom, right); + var croppedImage = new PackedMemoryImage(croppedPlane); + return croppedImage; + } + + public ref TPackedPixel DangerousGetReference() + { + return ref _plane.DangerousGetReference(); + } + + public static unsafe explicit operator void*(PackedMemoryImage image) + { + return Unsafe.AsPointer(ref image.DangerousGetReference()); + } + } +} diff --git a/sources/SDL2Sharp/video/PackedOrder.cs b/sources/SDL2Sharp/video/PackedOrder.cs new file mode 100644 index 00000000..833a0123 --- /dev/null +++ b/sources/SDL2Sharp/video/PackedOrder.cs @@ -0,0 +1,37 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using static SDL2Sharp.Interop.SDL_PackedOrder; + +namespace SDL2Sharp +{ + public enum PackedOrder + { + None = SDL_PACKEDORDER_NONE, + Xrgb = SDL_PACKEDORDER_XRGB, + Rgbx = SDL_PACKEDORDER_RGBX, + Argb = SDL_PACKEDORDER_ARGB, + Rgba = SDL_PACKEDORDER_RGBA, + Xbgr = SDL_PACKEDORDER_XBGR, + Bgrx = SDL_PACKEDORDER_BGRX, + Abgr = SDL_PACKEDORDER_ABGR, + Bgra = SDL_PACKEDORDER_BGRA, + } +} diff --git a/sources/SDL2Sharp/video/PackedTexture.cs b/sources/SDL2Sharp/video/PackedTexture.cs new file mode 100644 index 00000000..8d12227a --- /dev/null +++ b/sources/SDL2Sharp/video/PackedTexture.cs @@ -0,0 +1,222 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using CommunityToolkit.HighPerformance; +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed unsafe class PackedTexture : DisposableObject + where TPackedPixel : struct, IPackedPixel + { + public delegate void LockCallback(PackedImage pixels); + + public delegate void LockToSurfaceCallback(Surface surface); + + private readonly Texture _texture; + + public PixelFormat Format + { + get + { + ThrowIfDisposed(); + + return _texture.Format; + } + } + + public TextureAccess Access + { + get + { + ThrowIfDisposed(); + + return _texture.Access; + } + } + + public int Width + { + get + { + ThrowIfDisposed(); + + return _texture.Width; + } + } + + public int Height + { + get + { + ThrowIfDisposed(); + + return _texture.Height; + } + } + + public Size Size + { + get + { + ThrowIfDisposed(); + + return _texture.Size; + } + } + + public BlendMode BlendMode + { + get + { + ThrowIfDisposed(); + + return _texture.BlendMode; + } + set + { + ThrowIfDisposed(); + + _texture.BlendMode = value; + } + } + + public bool IsValid + { + get + { + ThrowIfDisposed(); + + return _texture.IsValid; + } + } + + internal PackedTexture(Texture texture) + { + ArgumentNullException.ThrowIfNull(texture); + + if (!texture.Format.IsPacked()) + { + throw new ArgumentException("Texture is not in a packed color format.", nameof(texture)); + } + + _texture = texture; + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + _texture?.Dispose(); + } + } + + public void WithLock(LockCallback callback) + { + WithLock(0, 0, Width, Height, callback); + } + + public void WithLock(Rectangle rectangle, LockCallback callback) + { + WithLock(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, callback); + } + + public void WithLock(int x, int y, int width, int height, LockCallback callback) + { + ThrowIfDisposed(); + + var rect = new SDL_Rect { x = x, y = y, w = width, h = height }; + void* pixels; + int pitch; + Error.ThrowLastErrorIfNegative( + Interop.SDL.LockTexture(_texture.Handle, &rect, &pixels, &pitch) + ); + + var image = new PackedImage(pixels, width, height, pitch); + callback.Invoke(image); + Interop.SDL.UnlockTexture(_texture.Handle); + } + + public void WithLock(LockToSurfaceCallback callback) + { + WithLock(0, 0, Width, Height, callback); + } + + public void WithLock(Rectangle rectangle, LockToSurfaceCallback callback) + { + WithLock(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, callback); + } + + public void WithLock(int x, int y, int width, int height, LockToSurfaceCallback callback) + { + ThrowIfDisposed(); + + var rect = new SDL_Rect { x = x, y = y, w = width, h = height }; + SDL_Surface* surfaceHandle; + Error.ThrowLastErrorIfNegative( + Interop.SDL.LockTextureToSurface(_texture.Handle, &rect, &surfaceHandle) + ); + var surface = new Surface(surfaceHandle, false); + callback.Invoke(surface); + Interop.SDL.UnlockTexture(_texture.Handle); + } + + public void Update(PackedImage pixels) + { + ThrowIfDisposed(); + + Update(null, (void*)pixels, pixels.Pitch); + } + + public void Update(PackedMemoryImage image) + { + ThrowIfDisposed(); + + Update(null, (void*)image, image.Pitch); + } + + public void Update(TPackedPixel[,] pixels) + { + ThrowIfDisposed(); + + var pointer = Unsafe.AsPointer(ref pixels.DangerousGetReference()); + var width = pixels.GetLength(1); + var pitch = width * Marshal.SizeOf(); + Update(null, pointer, pitch); + } + + private void Update(SDL_Rect* rect, void* pixels, int pitch) + { + Error.ThrowLastErrorIfNegative( + Interop.SDL.UpdateTexture(_texture.Handle, rect, pixels, pitch) + ); + } + + public static implicit operator Texture(PackedTexture texture) + { + ArgumentNullException.ThrowIfNull(texture); + + return texture._texture; + } + } +} diff --git a/sources/SDL2Sharp/video/PixelFormat.cs b/sources/SDL2Sharp/video/PixelFormat.cs new file mode 100644 index 00000000..c4f6d926 --- /dev/null +++ b/sources/SDL2Sharp/video/PixelFormat.cs @@ -0,0 +1,80 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using static SDL2Sharp.Interop.SDL_PixelFormatEnum; + +namespace SDL2Sharp +{ + public enum PixelFormat : uint + { +#pragma warning disable CA1069 // Enums values should not be duplicated + Unknown = SDL_PIXELFORMAT_UNKNOWN, + Index1LSB = SDL_PIXELFORMAT_INDEX1LSB, + Index1MSB = SDL_PIXELFORMAT_INDEX1MSB, + Index4LSB = SDL_PIXELFORMAT_INDEX4LSB, + Index4MSB = SDL_PIXELFORMAT_INDEX4MSB, + Index8 = SDL_PIXELFORMAT_INDEX8, + RGB332 = SDL_PIXELFORMAT_RGB332, + XRGB4444 = SDL_PIXELFORMAT_XRGB4444, + RGB444 = SDL_PIXELFORMAT_RGB444, + XBGR4444 = SDL_PIXELFORMAT_XBGR4444, + BGR444 = SDL_PIXELFORMAT_BGR444, + XRGB1555 = SDL_PIXELFORMAT_XRGB1555, + RGB555 = SDL_PIXELFORMAT_RGB555, + XBGR1555 = SDL_PIXELFORMAT_XBGR1555, + BGR555 = SDL_PIXELFORMAT_BGR555, + ARGB4444 = SDL_PIXELFORMAT_ARGB4444, + RGBA4444 = SDL_PIXELFORMAT_RGBA4444, + ABGR4444 = SDL_PIXELFORMAT_ABGR4444, + BGRA4444 = SDL_PIXELFORMAT_BGRA4444, + ARGB1555 = SDL_PIXELFORMAT_ARGB1555, + RGBA5551 = SDL_PIXELFORMAT_RGBA5551, + ABGR1555 = SDL_PIXELFORMAT_ABGR1555, + BGRA5551 = SDL_PIXELFORMAT_BGRA5551, + RGB565 = SDL_PIXELFORMAT_RGB565, + BGR565 = SDL_PIXELFORMAT_BGR565, + RGB24 = SDL_PIXELFORMAT_RGB24, + BGR24 = SDL_PIXELFORMAT_BGR24, + XRGB8888 = SDL_PIXELFORMAT_XRGB8888, + RGB888 = SDL_PIXELFORMAT_RGB888, + RGBX8888 = SDL_PIXELFORMAT_RGBX8888, + XBGR8888 = SDL_PIXELFORMAT_XBGR8888, + BGR888 = SDL_PIXELFORMAT_BGR888, + BGRX8888 = SDL_PIXELFORMAT_BGRX8888, + ARGB8888 = SDL_PIXELFORMAT_ARGB8888, + RGBA8888 = SDL_PIXELFORMAT_RGBA8888, + ABGR8888 = SDL_PIXELFORMAT_ABGR8888, + BGRA8888 = SDL_PIXELFORMAT_BGRA8888, + ARGB2101010 = SDL_PIXELFORMAT_ARGB2101010, + RGBA32 = SDL_PIXELFORMAT_RGBA32, + ARGB32 = SDL_PIXELFORMAT_ARGB32, + BGRA32 = SDL_PIXELFORMAT_BGRA32, + ABGR32 = SDL_PIXELFORMAT_ABGR32, + YV12 = SDL_PIXELFORMAT_YV12, + IYUV = SDL_PIXELFORMAT_IYUV, + YUY2 = SDL_PIXELFORMAT_YUY2, + UYVY = SDL_PIXELFORMAT_UYVY, + YVYU = SDL_PIXELFORMAT_YVYU, + NV12 = SDL_PIXELFORMAT_NV12, + NV21 = SDL_PIXELFORMAT_NV21, + ExternalOES = SDL_PIXELFORMAT_EXTERNAL_OES, +#pragma warning restore CA1069 // Enums values should not be duplicated + } +} diff --git a/sources/SDL2Sharp/PixelFormat.cs b/sources/SDL2Sharp/video/PixelFormatDescriptor.cs similarity index 62% rename from sources/SDL2Sharp/PixelFormat.cs rename to sources/SDL2Sharp/video/PixelFormatDescriptor.cs index 523577a0..0d4a42d6 100644 --- a/sources/SDL2Sharp/PixelFormat.cs +++ b/sources/SDL2Sharp/video/PixelFormatDescriptor.cs @@ -23,13 +23,15 @@ namespace SDL2Sharp { - public sealed unsafe class PixelFormat : IDisposable + public sealed unsafe class PixelFormatDescriptor : FinalizableObject { private SDL_PixelFormat* _handle; private readonly bool _ownsHandle; - public PixelFormatEnum Format => (PixelFormatEnum)_handle->format; + internal SDL_PixelFormat* Handle => _handle; + + public PixelFormat Format => (PixelFormat)_handle->format; public byte BitsPerPixel => _handle->BitsPerPixel; @@ -59,36 +61,46 @@ public sealed unsafe class PixelFormat : IDisposable public byte AlphaShift => _handle->Ashift; - internal PixelFormat(SDL_PixelFormat* handle, bool ownsHandle) + internal PixelFormatDescriptor(SDL_PixelFormat* handle, bool ownsHandle) { - if (handle == null) - { - throw new ArgumentNullException(nameof(handle)); - } - + ArgumentNullException.ThrowIfNull(handle); _handle = handle; _ownsHandle = ownsHandle; } - public PixelFormat(PixelFormatEnum pixelFormat) - : this(Error.ReturnOrThrowOnFailure(SDL.AllocFormat((uint)pixelFormat)), true) + public PixelFormatDescriptor(PixelFormat pixelFormat) + : this(Error.ThrowLastErrorIfNull(Interop.SDL.AllocFormat((uint)pixelFormat)), true) { } - ~PixelFormat() + protected override void Dispose(bool disposing) { - Dispose(false); + if (!_ownsHandle || _handle == null) return; + Interop.SDL.FreeFormat(_handle); + _handle = null; } - public void Dispose() + internal uint MapRGB(byte r, byte g, byte b) { - Dispose(true); + return Interop.SDL.MapRGB(_handle, r, g, b); } - private void Dispose(bool _) + public uint MapRGBA(byte r, byte g, byte b, byte a) { - if (!_ownsHandle || _handle == null) return; - SDL.FreeFormat(_handle); - _handle = null; + return Interop.SDL.MapRGBA(_handle, r, g, b, a); + } + + public (byte r, byte g, byte b) GetRGB(uint value) + { + byte r, g, b; + Interop.SDL.GetRGB(value, _handle, &r, &g, &b); + return (r, g, b); + } + + public (byte r, byte g, byte b, byte a) GetRGBA(uint value) + { + byte r, g, b, a; + Interop.SDL.GetRGBA(value, _handle, &r, &g, &b, &a); + return (r, g, b, a); } } } diff --git a/sources/SDL2Sharp/video/PixelFormatExtensions.cs b/sources/SDL2Sharp/video/PixelFormatExtensions.cs new file mode 100644 index 00000000..39578e01 --- /dev/null +++ b/sources/SDL2Sharp/video/PixelFormatExtensions.cs @@ -0,0 +1,133 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +namespace SDL2Sharp +{ + public static class PixelFormatExtensions + { + public static bool IsFourCC(this PixelFormat format) + { + return (format != PixelFormat.Unknown) && (GetPixelFlag(format) != 1); + } + + public static uint GetPixelFlag(this PixelFormat format) + { + return (((uint)format) >> 28) & 0x0FU; + } + + public static PixelType GetPixelType(this PixelFormat format) + { + return (PixelType)((((uint)format) >> 24) & 0x0F); + } + + public static uint GetBitsPerPixel(this PixelFormat format) + { + return (((uint)format) >> 8) & 0xFFU; + } + + public static uint GetBytesPerPixel(this PixelFormat pixelFormat) + { + return IsFourCC(pixelFormat) ? + (((pixelFormat == PixelFormat.YUY2) || + (pixelFormat == PixelFormat.UYVY) || + (pixelFormat == PixelFormat.YVYU)) ? 2u : 1u) : ((uint)pixelFormat) & 0xFF; + } + + public static PixelOrder GetPixelOrder(this PixelFormat format) + { + return (PixelOrder)((((uint)format) >> 20) & 0x0F); + } + + public static PackedLayout GetPixelLayout(this PixelFormat format) + { + return (PackedLayout)((((uint)format) >> 16) & 0x0F); + } + + public static bool IsIndexed(this PixelFormat pixelFormat) + { + if (IsFourCC(pixelFormat)) + { + return false; + } + + var pixelType = GetPixelType(pixelFormat); + return (pixelType == PixelType.Index1) + || (pixelType == PixelType.Index4) + || (pixelType == PixelType.Index8); + } + + public static bool IsPacked(this PixelFormat pixelFormat) + { + if (IsFourCC(pixelFormat)) + { + return false; + } + + var pixelType = GetPixelType(pixelFormat); + return (pixelType == PixelType.Packed8) + || (pixelType == PixelType.Packed16) + || (pixelType == PixelType.Packet32); + } + + public static bool IsArray(this PixelFormat pixelFormat) + { + if (IsFourCC(pixelFormat)) + { + return false; + } + + var pixelType = GetPixelType(pixelFormat); + return (pixelType == PixelType.ArrayU8) + || (pixelType == PixelType.ArrayU16) + || (pixelType == PixelType.ArrayU32) + || (pixelType == PixelType.ArrayF16) + || (pixelType == PixelType.ArrayF32); + } + + public static bool IsAlpha(this PixelFormat pixelFormat) + { + if (IsFourCC(pixelFormat)) + { + return false; + } + + var pixelOrder = GetPixelOrder(pixelFormat); + if (IsPacked(pixelFormat)) + { + var packedOrder = (PackedOrder)pixelOrder; + return (packedOrder == PackedOrder.Argb) + || (packedOrder == PackedOrder.Rgba) + || (packedOrder == PackedOrder.Abgr) + || (packedOrder == PackedOrder.Bgra); + } + + if (IsArray(pixelFormat)) + { + var arrayOrder = (ArrayOrder)pixelOrder; + return (arrayOrder == ArrayOrder.Argb) + || (arrayOrder == ArrayOrder.Rgba) + || (arrayOrder == ArrayOrder.Abgr) + || (arrayOrder == ArrayOrder.Bgra); + } + + return false; + } + } +} diff --git a/sources/SDL2Sharp/WithLockPackedImageCallback.cs b/sources/SDL2Sharp/video/PixelOrder.cs similarity index 87% rename from sources/SDL2Sharp/WithLockPackedImageCallback.cs rename to sources/SDL2Sharp/video/PixelOrder.cs index b011369a..38e12711 100644 --- a/sources/SDL2Sharp/WithLockPackedImageCallback.cs +++ b/sources/SDL2Sharp/video/PixelOrder.cs @@ -20,6 +20,7 @@ namespace SDL2Sharp { - public delegate void WithLockPackedImageCallback(PackedImage image) - where TPackedColor : struct; + public enum PixelOrder : uint + { + } } diff --git a/sources/SDL2Sharp/PixelType.cs b/sources/SDL2Sharp/video/PixelType.cs similarity index 100% rename from sources/SDL2Sharp/PixelType.cs rename to sources/SDL2Sharp/video/PixelType.cs diff --git a/sources/SDL2Sharp/Point.cs b/sources/SDL2Sharp/video/Point.cs similarity index 100% rename from sources/SDL2Sharp/Point.cs rename to sources/SDL2Sharp/video/Point.cs diff --git a/sources/SDL2Sharp/Rectangle.cs b/sources/SDL2Sharp/video/Rectangle.cs similarity index 98% rename from sources/SDL2Sharp/Rectangle.cs rename to sources/SDL2Sharp/video/Rectangle.cs index 2cf0c414..239c9db3 100644 --- a/sources/SDL2Sharp/Rectangle.cs +++ b/sources/SDL2Sharp/video/Rectangle.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // diff --git a/sources/SDL2Sharp/video/Renderer.cs b/sources/SDL2Sharp/video/Renderer.cs new file mode 100644 index 00000000..bd285aec --- /dev/null +++ b/sources/SDL2Sharp/video/Renderer.cs @@ -0,0 +1,434 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed unsafe class Renderer : FinalizableObject + { + private SDL_Renderer* _handle; + + private Texture? _renderTarget; + + public RendererInfo Info + { + get + { + ThrowIfDisposed(); + + var rendererInfo = new SDL_RendererInfo(); + Error.ThrowLastErrorIfNegative( + Interop.SDL.GetRendererInfo(_handle, &rendererInfo) + ); + return new RendererInfo(rendererInfo); + } + } + + public Size OutputSize + { + get + { + ThrowIfDisposed(); + + int width, height; + Error.ThrowLastErrorIfNegative( + Interop.SDL.GetRendererOutputSize(_handle, &width, &height) + ); + return new Size(width, height); + } + } + + public int OutputWidth + { + get + { + ThrowIfDisposed(); + + int width; + Error.ThrowLastErrorIfNegative( + Interop.SDL.GetRendererOutputSize(_handle, &width, null) + ); + return width; + } + } + + public int OutputHeight + { + get + { + ThrowIfDisposed(); + + int height; + Error.ThrowLastErrorIfNegative( + Interop.SDL.GetRendererOutputSize(_handle, null, &height) + ); + return height; + } + } + + public Color DrawColor + { + get + { + ThrowIfDisposed(); + + byte r, g, b, a; + Error.ThrowLastErrorIfNegative( + Interop.SDL.GetRenderDrawColor(_handle, &r, &g, &b, &a) + ); + return new Color(r, g, b, a); + } + set + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.SetRenderDrawColor(_handle, value.R, value.G, value.B, value.A) + ); + } + } + + public BlendMode BlendMode + { + get + { + ThrowIfDisposed(); + + SDL_BlendMode blendMode; + Error.ThrowLastErrorIfNegative( + Interop.SDL.GetRenderDrawBlendMode(_handle, &blendMode) + ); + return (BlendMode)blendMode; + } + set + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.SetRenderDrawBlendMode(_handle, (SDL_BlendMode)value) + ); + } + } + + public Size LogicalViewSize + { + get + { + ThrowIfDisposed(); + + int width, height; + Interop.SDL.RenderGetLogicalSize(_handle, &width, &height); + return new Size(width, height); + } + set + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderSetLogicalSize(_handle, value.Width, value.Height) + ); + } + } + + public Scale Scale + { + get + { + + ThrowIfDisposed(); + + float scaleX, scaleY; + Interop.SDL.RenderGetScale(_handle, &scaleX, &scaleY); + return new Scale(scaleX, scaleY); + } + set + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderSetScale(_handle, value.X, value.Y) + ); + } + } + + public Rectangle ViewPort + { + get + { + ThrowIfDisposed(); + + var rect = new SDL_Rect(); + Interop.SDL.RenderGetViewport(_handle, &rect); + return new Rectangle(rect.x, rect.y, rect.w, rect.h); + } + set + { + ThrowIfDisposed(); + + var rect = new SDL_Rect { x = value.X, y = value.Y, w = value.Width, h = value.Height }; + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderSetViewport(_handle, &rect) + ); + } + } + + public Texture? Target + { + get + { + ThrowIfDisposed(); + + return _renderTarget; + } + set + { + ThrowIfDisposed(); + + if (value is null) + { + Error.ThrowLastErrorIfNegative( + Interop.SDL.SetRenderTarget(_handle, null) + ); + } + else + { + Error.ThrowLastErrorIfNegative( + Interop.SDL.SetRenderTarget(_handle, value.Handle) + ); + } + + _renderTarget = value; + } + } + + internal Renderer(SDL_Renderer* renderer) + { + ArgumentNullException.ThrowIfNull(renderer); + + _handle = renderer; + } + + protected override void Dispose(bool disposing) + { + if (_handle is null) return; + Interop.SDL.DestroyRenderer(_handle); + _handle = null; + } + + public Texture CreateTexture(PixelFormat pixelFormat, TextureAccess access, Size size) + { + return CreateTexture(pixelFormat, access, size.Width, size.Height); + } + + public Texture CreateTexture(PixelFormat pixelFormat, TextureAccess access, int width, int height) + { + ThrowIfDisposed(); + + var texture = Interop.SDL.CreateTexture(_handle, (uint)pixelFormat, (int)access, width, height); + Error.ThrowLastErrorIfNull(texture); + return new Texture(texture); + } + + public Texture CreateTextureFromSurface(Surface surface) + { + ThrowIfDisposed(); + + var texture = Interop.SDL.CreateTextureFromSurface(_handle, surface.Handle); + Error.ThrowLastErrorIfNull(texture); + return new Texture(texture); + } + + public void Clear() + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderClear(_handle) + ); + } + + public void Copy(Texture texture) + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderCopy(_handle, texture.Handle, null, null) + ); + } + + public void Copy(Texture texture, Rectangle destination) + { + ThrowIfDisposed(); + + var dest = new SDL_Rect + { + x = destination.X, + y = destination.Y, + w = destination.Width, + h = destination.Height + }; + + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderCopy(_handle, texture.Handle, null, &dest) + ); + } + + public void Copy(Texture texture, Rectangle source, Rectangle destination) + { + ThrowIfDisposed(); + + var src = new SDL_Rect + { + x = source.X, + y = source.Y, + w = source.Width, + h = source.Height + }; + + var dest = new SDL_Rect + { + x = destination.X, + y = destination.Y, + w = destination.Width, + h = destination.Height + }; + + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderCopy(_handle, texture.Handle, &src, &dest) + ); + } + + public void DrawLine(int x1, int y1, int x2, int y2) + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderDrawLine(_handle, x1, y1, x2, y2) + ); + } + + public void DrawLines(Point[] points) + { + ThrowIfDisposed(); + + fixed (Point* point = &points[0]) + { + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderDrawLines(_handle, (SDL_Point*)point, points.Length) + ); + } + } + + public void DrawLine(float x1, float y1, float x2, float y2) + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderDrawLineF(_handle, x1, y1, x2, y2) + ); + } + + public void DrawPoint(int x, int y) + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderDrawPoint(_handle, x, y) + ); + } + + public void DrawPoint(float x, float y) + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderDrawPointF(_handle, x, y) + ); + } + + public void DrawPoints(Point[] points) + { + ThrowIfDisposed(); + + fixed (Point* point = &points[0]) + { + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderDrawPoints(_handle, (SDL_Point*)point, points.Length) + ); + } + } + + public void FillRect(int x, int y, int width, int height) + { + ThrowIfDisposed(); + + var rect = new SDL_Rect { x = x, y = y, w = width, h = height }; + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderFillRect(_handle, &rect) + ); + } + + public void FillRect(Rectangle rectangle) + { + FillRect(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); + } + + public void Present() + { + ThrowIfDisposed(); + + Interop.SDL.RenderPresent(_handle); + } + + public PackedMemoryImage ReadPixels() + where TPackedPixel : struct, IPackedPixel + { + ThrowIfDisposed(); + + return ReadPixels( + new Rectangle(0, 0, OutputWidth, OutputHeight) + ); + } + + public PackedMemoryImage ReadPixels(Rectangle rectangle) + where TPackedPixel : struct, IPackedPixel + { + ThrowIfDisposed(); + + var rect = new SDL_Rect { x = rectangle.X, y = rectangle.Y, w = rectangle.Width, h = rectangle.Height }; + var format = (uint)TPackedPixel.Format; + var image = new PackedMemoryImage(rectangle.Width, rectangle.Height); + var pixels = Unsafe.AsPointer(ref image.DangerousGetReference()); + var pitch = rectangle.Width * Marshal.SizeOf(); + Error.ThrowLastErrorIfNegative( + Interop.SDL.RenderReadPixels(_handle, + &rect, + format, + pixels, + pitch) + ); + return image; + } + } +} diff --git a/sources/SDL2Sharp.Extensions/RendererExtensions.cs b/sources/SDL2Sharp/video/RendererExtensions.cs similarity index 65% rename from sources/SDL2Sharp.Extensions/RendererExtensions.cs rename to sources/SDL2Sharp/video/RendererExtensions.cs index badadc5a..af0baf39 100644 --- a/sources/SDL2Sharp.Extensions/RendererExtensions.cs +++ b/sources/SDL2Sharp/video/RendererExtensions.cs @@ -19,22 +19,94 @@ // 3. This notice may not be removed or altered from any source distribution. using System; +using static System.Math; -namespace SDL2Sharp.Extensions +namespace SDL2Sharp { public static class RendererExtensions { - public static Texture CreateTextureFromBitmap(this Renderer renderer, string filename) + public static PackedTexture CreatePackedTexture(this Renderer renderer, TextureAccess access, Size size) + where TPackedPixel : struct, IPackedPixel { - if (renderer is null) - { - throw new ArgumentNullException(nameof(renderer)); - } + ArgumentNullException.ThrowIfNull(renderer); - if (string.IsNullOrWhiteSpace(filename)) - { - throw new ArgumentException($"'{nameof(filename)}' cannot be null or whitespace.", nameof(filename)); - } + return renderer.CreatePackedTexture(access, size.Width, size.Height); + } + + public static PackedTexture CreatePackedTexture(this Renderer renderer, TextureAccess access, int width, int height) + where TPackedPixel : struct, IPackedPixel + { + ArgumentNullException.ThrowIfNull(renderer); + + var pixelFormat = TPackedPixel.Format; + var texture = renderer.CreateTexture(pixelFormat, access, width, height); + return new PackedTexture(texture); + } + + public static YUVTexture CreateYUVTexture(this Renderer renderer, TextureAccess access, Size size) + where TYUVFormat : IYUVFormat, new() + { + ArgumentNullException.ThrowIfNull(renderer); + + return renderer.CreateYUVTexture(access, size.Width, size.Height); + } + + public static YUVTexture CreateYUVTexture(this Renderer renderer, TextureAccess access, int width, int height) + where TYUVFormat : IYUVFormat + { + ArgumentNullException.ThrowIfNull(renderer); + + var pixelFormat = TYUVFormat.PixelFormat; + var texture = renderer.CreateTexture(pixelFormat, access, width, height); + return new YUVTexture(texture); + } + + public static NV12Texture CreateNV12Texture(this Renderer renderer, TextureAccess access, Size size) + { + ArgumentNullException.ThrowIfNull(renderer); + + return renderer.CreateNV12Texture(access, size.Width, size.Height); + } + + public static NV12Texture CreateNV12Texture(this Renderer renderer, TextureAccess access, int width, int height) + { + ArgumentNullException.ThrowIfNull(renderer); + + var pixelFormat = PixelFormat.NV12; + var texture = renderer.CreateTexture(pixelFormat, access, width, height); + return new NV12Texture(texture); + } + + public static NV21Texture CreateNV21Texture(this Renderer renderer, TextureAccess access, Size size) + { + ArgumentNullException.ThrowIfNull(renderer); + + return renderer.CreateNV21Texture(access, size.Width, size.Height); + } + + public static NV21Texture CreateNV21Texture(this Renderer renderer, TextureAccess access, int width, int height) + { + ArgumentNullException.ThrowIfNull(renderer); + + var pixelFormat = PixelFormat.NV21; + var texture = renderer.CreateTexture(pixelFormat, access, width, height); + return new NV21Texture(texture); + } + + public static PackedTexture CreateTextureFromSurface(this Renderer renderer, Surface surface) + where TPackedPixel : struct, IPackedPixel + { + ArgumentNullException.ThrowIfNull(renderer); + + var texture = renderer.CreateTextureFromSurface(surface); + var packedTexture = new PackedTexture(texture); + return packedTexture; + } + + public static Texture CreateTextureFromBitmap(this Renderer renderer, string filename) + { + ArgumentNullException.ThrowIfNull(renderer); + ArgumentException.ThrowIfNullOrWhiteSpace(filename, nameof(filename)); using var surface = Surface.LoadBitmap(filename); var texture = renderer.CreateTextureFromSurface(surface); @@ -43,10 +115,7 @@ public static Texture CreateTextureFromBitmap(this Renderer renderer, string fil public static void DrawCircle(this Renderer renderer, int centerX, int centerY, int radius) { - if (renderer is null) - { - throw new ArgumentNullException(nameof(renderer)); - } + ArgumentNullException.ThrowIfNull(renderer); if (radius < 0) { @@ -94,10 +163,7 @@ public static void DrawEllipse(this Renderer renderer, int centerX, int centerY, // // See: http://enchantia.com/software/graphapp/doc/tech/ellipses.html - if (renderer is null) - { - throw new ArgumentNullException(nameof(renderer)); - } + ArgumentNullException.ThrowIfNull(renderer); if (radiusX < 0) { @@ -179,10 +245,7 @@ public static void FillEllipse(this Renderer renderer, int centerX, int centerY, // // See: http://enchantia.com/software/graphapp/doc/tech/ellipses.html - if (renderer is null) - { - throw new ArgumentNullException(nameof(renderer)); - } + ArgumentNullException.ThrowIfNull(renderer); if (radiusX < 0) { @@ -295,24 +358,31 @@ void IncrementY() public static void DrawTextBlended(this Renderer renderer, int x, int y, Font font, string text) { - if (renderer is null) - { - throw new ArgumentNullException(nameof(renderer)); - } + ArgumentNullException.ThrowIfNull(renderer); + ArgumentNullException.ThrowIfNull(font); + ArgumentNullException.ThrowIfNull(text); - if (font is null) - { - throw new ArgumentNullException(nameof(font)); - } + using var surface = font.RenderBlended(text, renderer.DrawColor); + using var texture = renderer.CreateTextureFromSurface(surface); + var destination = new Rectangle(x, y, texture.Width, texture.Height); - if (text is null) - { - throw new ArgumentNullException(nameof(text)); - } - - using var textSurface = font.RenderBlended(text, renderer.DrawColor); - using var textTexture = renderer.CreateTextureFromSurface(textSurface); - renderer.Copy(textTexture, new Rectangle(x, y, textTexture.Width, textTexture.Height)); + renderer.Copy(texture, destination); + } + public static void DrawTextBlendedCentered(this Renderer renderer, Font font, string text) + { + ArgumentNullException.ThrowIfNull(renderer); + ArgumentNullException.ThrowIfNull(font); + ArgumentNullException.ThrowIfNull(text); + + using var surface = font.RenderBlended(text, renderer.DrawColor); + using var texture = renderer.CreateTextureFromSurface(surface); + var textureSize = texture.Size; + var outputSize = renderer.OutputSize; + var x = Abs(outputSize.Width - texture.Width) / 2; + var y = Abs(outputSize.Height - texture.Height) / 2; + var destination = new Rectangle(x, y, texture.Width, texture.Height); + + renderer.Copy(texture, destination); } } } diff --git a/sources/SDL2Sharp/RendererFlags.cs b/sources/SDL2Sharp/video/RendererFlags.cs similarity index 98% rename from sources/SDL2Sharp/RendererFlags.cs rename to sources/SDL2Sharp/video/RendererFlags.cs index 6ca63459..7031ae32 100644 --- a/sources/SDL2Sharp/RendererFlags.cs +++ b/sources/SDL2Sharp/video/RendererFlags.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // diff --git a/sources/SDL2Sharp/RendererInfo.cs b/sources/SDL2Sharp/video/RendererInfo.cs similarity index 83% rename from sources/SDL2Sharp/RendererInfo.cs rename to sources/SDL2Sharp/video/RendererInfo.cs index d518a765..e8e321cf 100644 --- a/sources/SDL2Sharp/RendererInfo.cs +++ b/sources/SDL2Sharp/video/RendererInfo.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // @@ -28,18 +28,18 @@ public sealed unsafe class RendererInfo { private readonly SDL_RendererInfo _handle; - private readonly Lazy> _textureFormats; + private readonly Lazy> _textureFormats; public RendererInfo(SDL_RendererInfo handle) { _handle = handle; - _textureFormats = new Lazy>(() => + _textureFormats = new Lazy>(() => { var numTextureFormats = (int)_handle.num_texture_formats; - var textureFormats = new List(numTextureFormats); + var textureFormats = new List(numTextureFormats); for (var index = 0; index < numTextureFormats; ++index) { - textureFormats.Add((PixelFormatEnum)_handle.texture_formats[index]); + textureFormats.Add((PixelFormat)_handle.texture_formats[index]); } return textureFormats.AsReadOnly(); }); @@ -49,7 +49,7 @@ public RendererInfo(SDL_RendererInfo handle) public RendererFlags Flags => (RendererFlags)_handle.flags; - public IReadOnlyList TextureFormats => _textureFormats.Value; + public IReadOnlyList TextureFormats => _textureFormats.Value; public int MaxTextureWidth => _handle.max_texture_width; diff --git a/sources/SDL2Sharp/Scale.cs b/sources/SDL2Sharp/video/Scale.cs similarity index 98% rename from sources/SDL2Sharp/Scale.cs rename to sources/SDL2Sharp/video/Scale.cs index 2719c6ae..6d4f7102 100644 --- a/sources/SDL2Sharp/Scale.cs +++ b/sources/SDL2Sharp/video/Scale.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // diff --git a/sources/SDL2Sharp/Size.cs b/sources/SDL2Sharp/video/Size.cs similarity index 98% rename from sources/SDL2Sharp/Size.cs rename to sources/SDL2Sharp/video/Size.cs index 5c119444..a1f6ba5c 100644 --- a/sources/SDL2Sharp/Size.cs +++ b/sources/SDL2Sharp/video/Size.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // diff --git a/sources/SDL2Sharp/video/Surface.cs b/sources/SDL2Sharp/video/Surface.cs new file mode 100644 index 00000000..5dcada17 --- /dev/null +++ b/sources/SDL2Sharp/video/Surface.cs @@ -0,0 +1,158 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed unsafe class Surface : FinalizableObject + { + private SDL_Surface* _handle; + + private readonly bool _freeHandle; + + internal SDL_Surface* Handle => _handle; + + public PixelFormatDescriptor Format => new(_handle->format, false); + + public int Width => _handle->w; + + public int Height => _handle->h; + + public Size Size => new(Width, Height); + + public int Pitch => _handle->pitch; + + private bool MustLock => (_handle->flags & Interop.SDL.SDL_RLEACCEL) != 0; + + public static Surface LoadBitmap(string filename) + { + using var file = new MarshaledString(filename); + using var mode = new MarshaledString("rb"); + var source = Interop.SDL.RWFromFile(file, mode); + Error.ThrowLastErrorIfNull(source); + var bitmap = Interop.SDL.LoadBMP_RW(source, 1); + Error.ThrowLastErrorIfNull(bitmap); + return new Surface(bitmap); + } + + internal Surface(SDL_Surface* handle) + : this(handle, true) + { } + + internal Surface(SDL_Surface* handle, bool freeHandle) + { + if (handle is null) + { + throw new ArgumentNullException(nameof(handle)); + } + + _handle = handle; + _freeHandle = freeHandle; + } + + public Surface(int width, int height, PixelFormat format) + : this(Error.ThrowLastErrorIfNull(Interop.SDL.CreateRGBSurfaceWithFormat(0, width, height, 0, (uint)format))) + { } + + public Surface(int width, int height, uint redMask, uint greenMask, uint blueMask, uint alphaMask) + : this(Error.ThrowLastErrorIfNull(Interop.SDL.CreateRGBSurface(0, width, height, 0, redMask, greenMask, blueMask, alphaMask))) + { } + + public Surface(void* pixels, int width, int height, int pitch, PixelFormat format) + : this(Error.ThrowLastErrorIfNull(Interop.SDL.CreateRGBSurfaceWithFormatFrom(pixels, width, height, 0, pitch, (uint)format))) + { } + + public Surface(void* pixels, int width, int height, int pitch, uint redMask, uint greenMask, uint blueMask, uint alphaMask) + : this(Error.ThrowLastErrorIfNull(Interop.SDL.CreateRGBSurfaceFrom(pixels, width, height, 0, pitch, redMask, greenMask, blueMask, alphaMask))) + { } + + protected override void Dispose(bool disposing) + { + if (!_freeHandle || _handle is null) + { + return; + } + + Interop.SDL.FreeSurface(_handle); + + _handle = null; + } + + public void Blit(Surface surface) + { + ThrowWhenDisposed(); + + ArgumentNullException.ThrowIfNull(surface); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.Blit(_handle, null, surface._handle, null) + ); + } + + public Surface ConvertTo(PixelFormat format) + { + ThrowWhenDisposed(); + + return new Surface(Interop.SDL.ConvertSurfaceFormat(_handle, (uint)format, 0)); + } + + public void FillRect(uint color) + { + ThrowWhenDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.FillRect(_handle, null, color) + ); + } + + public void WithLock(SurfaceLockCallback callback) + where TPackedPixel : struct + { + ThrowWhenDisposed(); + + var mustLock = MustLock; + if (mustLock) + { + Error.ThrowLastErrorIfNegative( + Interop.SDL.LockSurface(_handle) + ); + } + + callback.Invoke( + new PackedImage( + _handle->pixels, + _handle->w, + _handle->h, + _handle->pitch)); + + if (mustLock) + { + Interop.SDL.UnlockSurface(_handle); + } + } + + private void ThrowWhenDisposed() + { + ObjectDisposedException.ThrowIf(_handle is null, this); + } + } +} diff --git a/sources/SDL2Sharp/video/SurfaceLockCallback.cs b/sources/SDL2Sharp/video/SurfaceLockCallback.cs new file mode 100644 index 00000000..5601a6dd --- /dev/null +++ b/sources/SDL2Sharp/video/SurfaceLockCallback.cs @@ -0,0 +1,25 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +namespace SDL2Sharp +{ + public delegate void SurfaceLockCallback(PackedImage pixels) + where TPacketColor : struct; +} diff --git a/sources/SDL2Sharp/video/Surface{T}.cs b/sources/SDL2Sharp/video/Surface{T}.cs new file mode 100644 index 00000000..57fc4623 --- /dev/null +++ b/sources/SDL2Sharp/video/Surface{T}.cs @@ -0,0 +1,106 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed class Surface : DisposableObject + where TPackedPixel : struct, IPackedPixel + { + private readonly Surface _surface; + + public PixelFormatDescriptor Format => _surface.Format; + + public int Width => _surface.Width; + + public int Height => _surface.Height; + + public int Pitch => _surface.Pitch; + + public Size Size => new(Width, Height); + + public Surface(int width, int height) + : this(new Surface(width, height, TPackedPixel.Format)) + { } + + internal unsafe Surface(SDL_Surface* surface) + : this(new Surface(surface)) + { } + + internal unsafe Surface(SDL_Surface* surface, bool freeHandle) + : this(new Surface(surface, freeHandle)) + { } + + internal Surface(Surface surface) + { + _surface = surface ?? throw new ArgumentNullException(nameof(surface)); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + _surface?.Dispose(); + } + } + + public void Blit(Surface surface) + { + ThrowIfDisposed(); + + ArgumentNullException.ThrowIfNull(surface); + + _surface.Blit(surface._surface); + } + + public Surface Convert() + where TTargetPackedPixel : struct, IPackedPixel + { + ThrowIfDisposed(); + + var targetPixelFormat = TTargetPackedPixel.Format; + var targetSurface = _surface.ConvertTo(targetPixelFormat); + return new Surface(targetSurface); + } + + public void FillRect(uint color) + { + ThrowIfDisposed(); + + _surface.FillRect(color); + } + + public void WithLock(SurfaceLockCallback callback) + { + ThrowIfDisposed(); + + _surface.WithLock(callback); + } + + public static implicit operator Surface(Surface surface) + { + ArgumentNullException.ThrowIfNull(surface); + + return surface._surface; + } + } +} diff --git a/sources/SDL2Sharp/video/Texture.cs b/sources/SDL2Sharp/video/Texture.cs new file mode 100644 index 00000000..7bf04161 --- /dev/null +++ b/sources/SDL2Sharp/video/Texture.cs @@ -0,0 +1,164 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed unsafe class Texture : FinalizableObject + { + public delegate void LockToSurfaceCallback(Surface pixels); + + private SDL_Texture* _handle; + + internal SDL_Texture* Handle => _handle; + + public PixelFormat Format + { + get + { + ThrowIfDisposed(); + + uint format; + Error.ThrowLastErrorIfNegative(Interop.SDL.QueryTexture(_handle, &format, null, null, null)); + return (PixelFormat)format; + } + } + + public TextureAccess Access + { + get + { + ThrowIfDisposed(); + + int access; + Error.ThrowLastErrorIfNegative(Interop.SDL.QueryTexture(_handle, null, &access, null, null)); + return (TextureAccess)access; + } + } + + public int Width + { + get + { + ThrowIfDisposed(); + + int width; + Error.ThrowLastErrorIfNegative(Interop.SDL.QueryTexture(_handle, null, null, &width, null)); + return width; + } + } + + public int Height + { + get + { + ThrowIfDisposed(); + + int height; + Error.ThrowLastErrorIfNegative(Interop.SDL.QueryTexture(_handle, null, null, null, &height)); + return height; + } + } + + public Size Size + { + get + { + ThrowIfDisposed(); + + int width, height; + Error.ThrowLastErrorIfNegative(Interop.SDL.QueryTexture(_handle, null, null, &width, &height)); + return new Size(width, height); + } + } + + public BlendMode BlendMode + { + get + { + ThrowIfDisposed(); + + SDL_BlendMode blendMode; + Error.ThrowLastErrorIfNegative( + Interop.SDL.GetTextureBlendMode(_handle, &blendMode) + ); + return (BlendMode)blendMode; + } + set + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.SetTextureBlendMode(_handle, (SDL_BlendMode)value) + ); + } + } + + public bool IsValid + { + get + { + ThrowIfDisposed(); + + return 0 == Interop.SDL.QueryTexture(_handle, null, null, null, null); + } + } + + internal Texture(SDL_Texture* handle) + { + ArgumentNullException.ThrowIfNull(handle); + + _handle = handle; + } + + protected override void Dispose(bool disposing) + { + if (_handle is null) return; + Interop.SDL.DestroyTexture(_handle); + _handle = null; + } + + public void WithLock(LockToSurfaceCallback callback) + { + WithLock(0, 0, Width, Height, callback); + } + + public void WithLock(Rectangle rectangle, LockToSurfaceCallback callback) + { + WithLock(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, callback); + } + + public void WithLock(int x, int y, int width, int height, LockToSurfaceCallback callback) + { + ThrowIfDisposed(); + + var rect = new SDL_Rect { x = x, y = y, w = width, h = height }; + SDL_Surface* surfaceHandle; + Error.ThrowLastErrorIfNegative( + Interop.SDL.LockTextureToSurface(_handle, &rect, &surfaceHandle) + ); + var surface = new Surface(surfaceHandle, false); + callback.Invoke(surface); + Interop.SDL.UnlockTexture(_handle); + } + } +} diff --git a/sources/SDL2Sharp/TextureAccess.cs b/sources/SDL2Sharp/video/TextureAccess.cs similarity index 100% rename from sources/SDL2Sharp/TextureAccess.cs rename to sources/SDL2Sharp/video/TextureAccess.cs diff --git a/sources/SDL2Sharp/MouseWheelEventArgs.cs b/sources/SDL2Sharp/video/TextureExtensions.cs similarity index 58% rename from sources/SDL2Sharp/MouseWheelEventArgs.cs rename to sources/SDL2Sharp/video/TextureExtensions.cs index 873f0141..6b44a571 100644 --- a/sources/SDL2Sharp/MouseWheelEventArgs.cs +++ b/sources/SDL2Sharp/video/TextureExtensions.cs @@ -20,28 +20,28 @@ namespace SDL2Sharp { - public sealed class MouseWheelEventArgs + public static class TextureExtensions { - public uint Which { get; } - - public MouseWheelDirection Direction { get; } - - public int X { get; } - - public int Y { get; } + public static PackedTexture AsPacked(this Texture texture) + where TPackedPixel : struct, IPackedPixel + { + return new PackedTexture(texture); + } - public float PreciseX { get; } + public static YUVTexture AsYUV(this Texture texture) + where TYUVFormat : IYUVFormat + { + return new YUVTexture(texture); + } - public float PreciseY { get; } + public static NV12Texture AsNV12(this Texture texture) + { + return new NV12Texture(texture); + } - public MouseWheelEventArgs(uint which, MouseWheelDirection direction, int x, int y, float preciseX, float preciseY) + public static NV21Texture AsNV21(this Texture texture) { - Which = which; - Direction = direction; - X = x; - Y = y; - PreciseX = preciseX; - PreciseY = preciseY; + return new NV21Texture(texture); } } } diff --git a/sources/SDL2Sharp/video/VideoSubsystem.cs b/sources/SDL2Sharp/video/VideoSubsystem.cs new file mode 100644 index 00000000..b9e1a4b8 --- /dev/null +++ b/sources/SDL2Sharp/video/VideoSubsystem.cs @@ -0,0 +1,90 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Collections.Generic; + +namespace SDL2Sharp +{ + internal sealed class VideoSubsystem : FinalizableObject, IVideoSubsystem + { + private const uint InitSubsystemFlags = Interop.SDL.SDL_INIT_VIDEO; + + private bool _fullyInitialized; + + public IReadOnlyList Displays + { + get + { + ThrowIfDisposed(); + + var displayCount = Interop.SDL.GetNumVideoDisplays(); + var displays = new List(displayCount); + for (var displayIndex = 0; displayIndex < displayCount; displayIndex++) + { + displays.Add(new Display(displayIndex)); + } + return displays.AsReadOnly(); + } + } + + public VideoSubsystem() + { + Error.ThrowLastErrorIfNegative( + Interop.SDL.InitSubSystem(InitSubsystemFlags) + ); + _fullyInitialized = true; + } + + protected override void Dispose(bool disposing) + { + if (!_fullyInitialized) return; + Interop.SDL.QuitSubSystem(InitSubsystemFlags); + _fullyInitialized = false; + } + + public Window CreateWindow(string title, int width, int height) + { + ThrowIfDisposed(); + + return new Window(title, width, height); + } + + public Window CreateWindow(string title, int width, int height, WindowFlags flags) + { + ThrowIfDisposed(); + + return new Window(title, width, height, flags); + } + + public Window CreateWindow(string title, int x, int y, int width, int height) + { + ThrowIfDisposed(); + + return new Window(title, x, y, width, height); + } + + public Window CreateWindow(string title, int x, int y, int width, int height, WindowFlags flags) + { + ThrowIfDisposed(); + + return new Window(title, x, y, width, height, flags); + } + } +} diff --git a/sources/SDL2Sharp/video/Window.cs b/sources/SDL2Sharp/video/Window.cs new file mode 100644 index 00000000..416eca0d --- /dev/null +++ b/sources/SDL2Sharp/video/Window.cs @@ -0,0 +1,493 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using SDL2Sharp.Interop; +using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; + +namespace SDL2Sharp +{ + + public sealed unsafe class Window : FinalizableObject + { + private SDL_Window* _handle; + + public uint Id + { + get + { + ThrowIfDisposed(); + + return Interop.SDL.GetWindowID(_handle); + } + } + + public string Title + { + get + { + ThrowIfDisposed(); + + return new string(Interop.SDL.GetWindowTitle(_handle)); + } + set + { + ThrowIfDisposed(); + + using var marshaledValue = new MarshaledString(value); + Interop.SDL.SetWindowTitle(_handle, marshaledValue); + } + } + + public Point Position + { + get + { + ThrowIfDisposed(); + + int x, y; + Interop.SDL.GetWindowPosition(_handle, &x, &y); + return new Point(x, y); + } + set + { + ThrowIfDisposed(); + + Interop.SDL.SetWindowPosition(_handle, value.X, value.Y); + } + } + + public int Width + { + get + { + ThrowIfDisposed(); + + int width; + Interop.SDL.GetWindowSize(_handle, &width, null); + return width; + } + } + + public int Height + { + get + { + ThrowIfDisposed(); + + int height; + Interop.SDL.GetWindowSize(_handle, null, &height); + return height; + } + } + + public Size Size + { + get + { + ThrowIfDisposed(); + + int width, height; + Interop.SDL.GetWindowSize(_handle, &width, &height); + return new Size(width, height); + } + set + { + ThrowIfDisposed(); + + Interop.SDL.SetWindowSize(_handle, value.Width, value.Height); + } + } + + public Size MinimumSize + { + get + { + ThrowIfDisposed(); + + int width, height; + Interop.SDL.GetWindowMinimumSize(_handle, &width, &height); + return new Size(width, height); + } + set + { + ThrowIfDisposed(); + + Interop.SDL.SetWindowMinimumSize(_handle, value.Width, value.Height); + } + } + + public Size MaximumSize + { + get + { + ThrowIfDisposed(); + + int width, height; + Interop.SDL.GetWindowMaximumSize(_handle, &width, &height); + return new Size(width, height); + } + set + { + ThrowIfDisposed(); + + Interop.SDL.SetWindowMaximumSize(_handle, value.Width, value.Height); + } + } + + public Size ClientSize + { + get + { + ThrowIfDisposed(); + + int borderTop, borderLeft, borderBottom, borderRight; + Error.ThrowLastErrorIfNegative( + Interop.SDL.GetWindowBordersSize(_handle, &borderTop, &borderLeft, &borderBottom, &borderRight) + ); + int windowWidth, windowHeight; + Interop.SDL.GetWindowSize(_handle, &windowWidth, &windowHeight); + var clientWidth = windowWidth - borderRight - borderLeft; + var clientHeight = windowHeight - borderBottom - borderTop; + return new Size(clientWidth, clientHeight); + } + } + + public PixelFormat PixelFormat + { + get + { + ThrowIfDisposed(); + + var pixelFormat = Interop.SDL.GetWindowPixelFormat(_handle); + Error.ThrowLastErrorIfZero(pixelFormat); + return (PixelFormat)pixelFormat; + } + } + + public Surface Surface + { + get + { + ThrowIfDisposed(); + + var surfaceHandle = Interop.SDL.GetWindowSurface(_handle); + Error.ThrowLastErrorIfNull(surfaceHandle); + return new Surface(surfaceHandle, false); + } + } + + public bool IsBordered + { + get + { + ThrowIfDisposed(); + + return HasWindowFlag(SDL_WindowFlags.SDL_WINDOW_BORDERLESS); + } + set + { + ThrowIfDisposed(); + + Interop.SDL.SetWindowBordered(_handle, value ? SDL_bool.SDL_TRUE : SDL_bool.SDL_FALSE); + } + } + + public bool IsResizable + { + get + { + ThrowIfDisposed(); + + return HasWindowFlag(SDL_WindowFlags.SDL_WINDOW_RESIZABLE); + } + set + { + ThrowIfDisposed(); + + Interop.SDL.SetWindowResizable(_handle, value ? SDL_bool.SDL_TRUE : SDL_bool.SDL_FALSE); + } + } + + public bool IsFullScreen + { + get + { + ThrowIfDisposed(); + + return HasWindowFlag(SDL_WindowFlags.SDL_WINDOW_FULLSCREEN); + } + set + { + ThrowIfDisposed(); + + var flags = value ? SDL_WindowFlags.SDL_WINDOW_FULLSCREEN : 0; + Error.ThrowLastErrorIfNegative( + Interop.SDL.SetWindowFullscreen(_handle, (uint)flags) + ); + } + } + + public bool IsFullScreenDesktop + { + get + { + ThrowIfDisposed(); + + return HasWindowFlag(SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP); + } + set + { + ThrowIfDisposed(); + + var flags = value ? SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP : 0; + Error.ThrowLastErrorIfNegative( + Interop.SDL.SetWindowFullscreen(_handle, (uint)flags) + ); + } + } + + public bool IsVisible + { + get + { + ThrowIfDisposed(); + + return HasWindowFlag(SDL_WindowFlags.SDL_WINDOW_SHOWN); + } + } + + internal Window(string title, int width, int height) + : this(title, (int)Interop.SDL.SDL_WINDOWPOS_UNDEFINED, (int)Interop.SDL.SDL_WINDOWPOS_UNDEFINED, width, height, (uint)0) + { } + + internal Window(string title, int width, int height, WindowFlags flags) + : this(title, (int)Interop.SDL.SDL_WINDOWPOS_UNDEFINED, (int)Interop.SDL.SDL_WINDOWPOS_UNDEFINED, width, height, (uint)flags) + { } + + internal Window(string title, int x, int y, int width, int height) + : this(title, x, y, width, height, (uint)0) + { } + + internal Window(string title, int x, int y, int width, int height, WindowFlags flags) + : this(title, x, y, width, height, (uint)flags) + { } + + private Window(string title, int x, int y, int width, int height, uint flags) + { + using var marshaledTitle = new MarshaledString(title); + + _handle = Error.ThrowLastErrorIfNull( + Interop.SDL.CreateWindow(marshaledTitle, x, y, width, height, flags) + ); + + if (!IsBordered) + { + Error.ThrowLastErrorIfNegative( + Interop.SDL.SetWindowHitTest(_handle, &HitTestCallback, null) + ); + } + } + + protected override void Dispose(bool _) + { + if (_handle is null) return; + Interop.SDL.DestroyWindow(_handle); + _handle = null; + } + + public void Show() + { + ThrowIfDisposed(); + + Interop.SDL.ShowWindow(_handle); + } + + public void Hide() + { + ThrowIfDisposed(); + + Interop.SDL.HideWindow(_handle); + } + + public void Raise() + { + ThrowIfDisposed(); + + Interop.SDL.RaiseWindow(_handle); + } + + public void Maximize() + { + ThrowIfDisposed(); + + Interop.SDL.MaximizeWindow(_handle); + } + + public void Minimize() + { + ThrowIfDisposed(); + + Interop.SDL.MinimizeWindow(_handle); + } + + public void Restore() + { + ThrowIfDisposed(); + + Interop.SDL.RestoreWindow(_handle); + } + + public Renderer CreateRenderer() + { + return CreateRenderer(RendererFlags.None); + } + + public Renderer CreateRenderer(RendererFlags flags) + { + if (!TryCreateRenderer(flags, out var renderer, out var error)) + { + throw error; + } + + return renderer; + } + + public bool TryCreateRenderer(out Renderer renderer) + { + return TryCreateRenderer(RendererFlags.None, out renderer); + } + + public bool TryCreateRenderer(RendererFlags flags, out Renderer renderer) + { + return TryCreateRenderer(flags, out renderer, out _); + } + + public bool TryCreateRenderer(RendererFlags flags, out Renderer renderer, out Error error) + { + ThrowIfDisposed(); + + var handle = Interop.SDL.CreateRenderer(_handle, -1, (uint)flags); + if (handle is null) + { + error = new Error(new string(Interop.SDL.GetError())); + renderer = null!; + return false; + } + else + { + error = null!; + renderer = new Renderer(handle); + return true; + } + } + + public void UpdateSurface() + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.UpdateWindowSurface(_handle) + ); + } + + private bool HasWindowFlag(SDL_WindowFlags flag) + { + var flags = (SDL_WindowFlags)Interop.SDL.GetWindowFlags(_handle); + var hasFlag = flags.HasFlag(flag); + return hasFlag; + } + + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])] + private static unsafe SDL_HitTestResult HitTestCallback(SDL_Window* win, SDL_Point* area, void* data) + { + var x = area->x; + var y = area->y; + + int windowWidth = 0, windowHeight = 0; + Interop.SDL.GetWindowSize(win, &windowWidth, &windowHeight); + + var windowTop = 0; + var windowLeft = 0; + var windowBottom = windowTop + windowHeight; + var windowRight = windowLeft + windowWidth; + + var borderTop = 0; + var borderLeft = 0; + var borderBottom = 0; + var borderRight = 0; +#pragma warning disable CA1806 // Do not ignore method results + Interop.SDL.GetWindowBordersSize(win, &borderTop, &borderLeft, &borderBottom, &borderRight); +#pragma warning restore CA1806 // Do not ignore method results + + var clientAreaTop = windowTop + borderTop; + var clientAreaLeft = windowLeft + borderLeft; + var clientAreaBottom = windowBottom - borderBottom; + var clientAreaRight = windowRight - borderRight; + + if (y > windowTop && y < clientAreaTop) + { + return SDL_HitTestResult.SDL_HITTEST_DRAGGABLE; + } + + if (y >= windowTop && y <= clientAreaTop) + { + if (x >= windowLeft && x <= clientAreaLeft) + { + return SDL_HitTestResult.SDL_HITTEST_RESIZE_TOPLEFT; + } + + if (x >= clientAreaRight && x <= windowRight) + { + return SDL_HitTestResult.SDL_HITTEST_RESIZE_TOPRIGHT; + } + + return SDL_HitTestResult.SDL_HITTEST_RESIZE_TOP; + } + + if (y >= clientAreaBottom && y <= windowBottom) + { + if (x >= windowLeft && x <= clientAreaLeft) + { + return SDL_HitTestResult.SDL_HITTEST_RESIZE_BOTTOMLEFT; + } + + if (x >= clientAreaRight && x <= windowRight) + { + return SDL_HitTestResult.SDL_HITTEST_RESIZE_BOTTOMRIGHT; + } + + return SDL_HitTestResult.SDL_HITTEST_RESIZE_BOTTOM; + } + + if (x >= windowLeft && x <= clientAreaLeft) + { + return SDL_HitTestResult.SDL_HITTEST_RESIZE_LEFT; + } + + if (x >= clientAreaRight && x <= windowRight) + { + return SDL_HitTestResult.SDL_HITTEST_RESIZE_RIGHT; + } + + return SDL_HitTestResult.SDL_HITTEST_NORMAL; + } + } +} diff --git a/sources/SDL2Sharp/WindowFlags.cs b/sources/SDL2Sharp/video/WindowFlags.cs similarity index 99% rename from sources/SDL2Sharp/WindowFlags.cs rename to sources/SDL2Sharp/video/WindowFlags.cs index 83e28208..04ecdce9 100644 --- a/sources/SDL2Sharp/WindowFlags.cs +++ b/sources/SDL2Sharp/video/WindowFlags.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // diff --git a/sources/SDL2Sharp/YuvConversionMode.cs b/sources/SDL2Sharp/video/YUVConversionMode.cs similarity index 96% rename from sources/SDL2Sharp/YuvConversionMode.cs rename to sources/SDL2Sharp/video/YUVConversionMode.cs index d314b828..3a2341be 100644 --- a/sources/SDL2Sharp/YuvConversionMode.cs +++ b/sources/SDL2Sharp/video/YUVConversionMode.cs @@ -1,4 +1,4 @@ -// SDL2Sharp +// SDL2Sharp // // Copyright (C) 2021-2024 Ronald van Manen // @@ -20,7 +20,7 @@ namespace SDL2Sharp { - public enum YuvConversionMode + public enum YUVConversionMode { Jpeg = Interop.SDL_YUV_CONVERSION_MODE.SDL_YUV_CONVERSION_JPEG, Bt601 = Interop.SDL_YUV_CONVERSION_MODE.SDL_YUV_CONVERSION_BT601, diff --git a/sources/SDL2Sharp/video/YUVImage.cs b/sources/SDL2Sharp/video/YUVImage.cs new file mode 100644 index 00000000..892da554 --- /dev/null +++ b/sources/SDL2Sharp/video/YUVImage.cs @@ -0,0 +1,83 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Runtime.CompilerServices; + +namespace SDL2Sharp +{ + public readonly ref struct YUVImage where TYUVFormat : IYUVFormat + { + private readonly ImagePlane _yPlane; + + private readonly ImagePlane _uPlane; + + private readonly ImagePlane _vPlane; + + public ImagePlane Y => _yPlane; + + public ImagePlane U => _uPlane; + + public ImagePlane V => _vPlane; + + public readonly int Width + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _yPlane.Width; + } + + public readonly int Height + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _yPlane.Height; + } + + public unsafe YUVImage(void* pixels, int width, int height, int pitch) + { + if (height < 0) + { + throw new ArgumentOutOfRangeException( + nameof(height), + height, + "height cannot be less than zero"); + } + + if (width < 0) + { + throw new ArgumentOutOfRangeException( + nameof(width), + width, + "height cannot be less than zero"); + } + + if (pitch < 0) + { + throw new ArgumentOutOfRangeException( + nameof(pitch), + pitch, + "pitch cannot be less than zero"); + } + + _yPlane = TYUVFormat.CreateYPlane(pixels, width, height, pitch); + _uPlane = TYUVFormat.CreateUPlane(pixels, width, height, pitch); + _vPlane = TYUVFormat.CreateVPlane(pixels, width, height, pitch); + } + } +} diff --git a/sources/SDL2Sharp/video/YUVMemoryImage.cs b/sources/SDL2Sharp/video/YUVMemoryImage.cs new file mode 100644 index 00000000..898d3393 --- /dev/null +++ b/sources/SDL2Sharp/video/YUVMemoryImage.cs @@ -0,0 +1,75 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Runtime.CompilerServices; + +namespace SDL2Sharp +{ + public sealed class YUVMemoryImage + { + private readonly ImageMemoryPlane _yPlane; + + private readonly ImageMemoryPlane _uPlane; + + private readonly ImageMemoryPlane _vPlane; + + public ImageMemoryPlane Y => _yPlane; + + public ImageMemoryPlane U => _uPlane; + + public ImageMemoryPlane V => _vPlane; + + public int Width + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _yPlane.Width; + } + + public int Height + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _yPlane.Height; + } + + public YUVMemoryImage(int width, int height) + { + if (width < 0) + { + throw new ArgumentOutOfRangeException( + nameof(width), + width, + "height cannot be less than zero"); + } + + if (height < 0) + { + throw new ArgumentOutOfRangeException( + nameof(height), + height, + "height cannot be less than zero"); + } + + _yPlane = new ImageMemoryPlane(width, height); + _uPlane = new ImageMemoryPlane(width / 2, height / 2); + _vPlane = new ImageMemoryPlane(width / 2, height / 2); + } + } +} diff --git a/sources/SDL2Sharp/video/YUVTexture.cs b/sources/SDL2Sharp/video/YUVTexture.cs new file mode 100644 index 00000000..055a75ec --- /dev/null +++ b/sources/SDL2Sharp/video/YUVTexture.cs @@ -0,0 +1,187 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using SDL2Sharp.Interop; + +namespace SDL2Sharp +{ + public sealed unsafe partial class YUVTexture : DisposableObject where TYUVFormat : IYUVFormat + { + public delegate void LockCallback(YUVImage pixels); + + private readonly Texture _texture; + + public PixelFormat Format + { + get + { + ThrowIfDisposed(); + + return _texture.Format; + } + } + + public TextureAccess Access + { + get + { + ThrowIfDisposed(); + + return _texture.Access; + } + } + + public int Width + { + get + { + ThrowIfDisposed(); + + return _texture.Width; + } + } + + public int Height + { + get + { + ThrowIfDisposed(); + + return _texture.Height; + } + } + + public Size Size + { + get + { + ThrowIfDisposed(); + + return _texture.Size; + } + } + + public BlendMode BlendMode + { + get + { + ThrowIfDisposed(); + + return _texture.BlendMode; + } + set + { + ThrowIfDisposed(); + + _texture.BlendMode = value; + } + } + + public bool IsValid + { + get + { + ThrowIfDisposed(); + + return _texture.IsValid; + } + } + + internal YUVTexture(Texture texture) + { + ArgumentNullException.ThrowIfNull(texture); + + if (texture.Format != TYUVFormat.PixelFormat) + { + throw new ArgumentException($"Texture is not in a {TYUVFormat.PixelFormat} format", nameof(texture)); + } + + _texture = texture; + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + _texture?.Dispose(); + } + } + + public void WithLock(LockCallback callback) + { + WithLock(0, 0, Width, Height, callback); + } + + public void WithLock(Rectangle rectangle, LockCallback callback) + { + WithLock(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, callback); + } + + public void WithLock(int x, int y, int width, int height, LockCallback callback) + { + ThrowIfDisposed(); + + var rect = new SDL_Rect { x = x, y = y, w = width, h = height }; + void* pixels; + int pitch; + Error.ThrowLastErrorIfNegative( + Interop.SDL.LockTexture(_texture.Handle, &rect, &pixels, &pitch) + ); + + var image = new YUVImage(pixels, width, height, pitch); + callback.Invoke(image); + Interop.SDL.UnlockTexture(_texture.Handle); + } + + public void Update(YUVImage image) + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.UpdateYUVTexture(_texture.Handle, null, + (byte*)image.Y, image.Y.Pitch, + (byte*)image.U, image.U.Pitch, + (byte*)image.V, image.V.Pitch + ) + ); + } + + public void Update(YUVMemoryImage image) + { + ThrowIfDisposed(); + + Error.ThrowLastErrorIfNegative( + Interop.SDL.UpdateYUVTexture(_texture.Handle, null, + (byte*)image.Y, image.Y.Pitch, + (byte*)image.U, image.U.Pitch, + (byte*)image.V, image.V.Pitch + ) + ); + } + + public static implicit operator Texture(YUVTexture texture) + { + ArgumentNullException.ThrowIfNull(texture); + + return texture._texture; + } + } +} diff --git a/sources/SDL2Sharp/Colors/Argb4444.cs b/sources/SDL2Sharp/video/pixels/ABGR1555.cs similarity index 52% rename from sources/SDL2Sharp/Colors/Argb4444.cs rename to sources/SDL2Sharp/video/pixels/ABGR1555.cs index 27d412a5..b86496c4 100644 --- a/sources/SDL2Sharp/Colors/Argb4444.cs +++ b/sources/SDL2Sharp/video/pixels/ABGR1555.cs @@ -19,27 +19,41 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Runtime.InteropServices; -using SDL2Sharp.Internals; -namespace SDL2Sharp.Colors +namespace SDL2Sharp { - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 2)] - [PackedColor(PixelFormatEnum.ARGB4444)] - public readonly record struct Argb4444 + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct ABGR1555 : IPackedPixel { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.ABGR1555); + private readonly ushort _value; - public byte A => (byte)(_value >> 12 & 0xF); + public static PixelFormat Format => _formatDescriptor.Format; - public byte R => (byte)(_value >> 8 & 0xF); + public static ABGR1555 FromRGB(byte r, byte g, byte b) + { + return new ABGR1555((ushort)_formatDescriptor.MapRGB(r, g, b)); + } + + public static ABGR1555 FromRGBA(byte r, byte g, byte b, byte a) + { + return new ABGR1555((ushort)_formatDescriptor.MapRGBA(r, g, b, a)); + } - public byte G => (byte)(_value >> 4 & 0xF); + private ABGR1555(ushort value) + { + _value = value; + } - public byte B => (byte)(_value & 0xFF); + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } - public Argb4444(byte a, byte r, byte g, byte b) + public (byte r, byte g, byte b, byte a) ToRGBA() { - _value = (ushort)((a & 0xF) << 12 | (r & 0xF) << 8 | (g & 0xF) << 4 | b & 0xF); + return _formatDescriptor.GetRGBA(_value); } } } diff --git a/sources/SDL2Sharp/Colors/Abgr4444.cs b/sources/SDL2Sharp/video/pixels/ABGR4444.cs similarity index 52% rename from sources/SDL2Sharp/Colors/Abgr4444.cs rename to sources/SDL2Sharp/video/pixels/ABGR4444.cs index abcdb75c..0185e66d 100644 --- a/sources/SDL2Sharp/Colors/Abgr4444.cs +++ b/sources/SDL2Sharp/video/pixels/ABGR4444.cs @@ -19,27 +19,41 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Runtime.InteropServices; -using SDL2Sharp.Internals; -namespace SDL2Sharp.Colors +namespace SDL2Sharp { - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 2)] - [PackedColor(PixelFormatEnum.ABGR4444)] - public readonly record struct Abgr4444 + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct ABGR4444 : IPackedPixel { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.ABGR4444); + private readonly ushort _value; - public byte A => (byte)(_value >> 12 & 0xF); + public static PixelFormat Format => _formatDescriptor.Format; - public byte B => (byte)(_value >> 8 & 0xF); + public static ABGR4444 FromRGB(byte r, byte g, byte b) + { + return new ABGR4444((ushort)_formatDescriptor.MapRGB(r, g, b)); + } + + public static ABGR4444 FromRGBA(byte r, byte g, byte b, byte a) + { + return new ABGR4444((ushort)_formatDescriptor.MapRGBA(r, g, b, a)); + } - public byte G => (byte)(_value >> 4 & 0xF); + private ABGR4444(ushort value) + { + _value = value; + } - public byte R => (byte)(_value & 0xFF); + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } - public Abgr4444(byte a, byte b, byte g, byte r) + public (byte r, byte g, byte b, byte a) ToRGBA() { - _value = (ushort)((a & 0xF) << 12 | (b & 0xF) << 8 | (g & 0xF) << 4 | r & 0xF); + return _formatDescriptor.GetRGBA(_value); } } } diff --git a/sources/SDL2Sharp/video/pixels/ABGR8888.cs b/sources/SDL2Sharp/video/pixels/ABGR8888.cs new file mode 100644 index 00000000..33babdd1 --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/ABGR8888.cs @@ -0,0 +1,63 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)] + public readonly record struct ABGR8888 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.ABGR8888); + + private readonly uint _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static ABGR8888 FromRGB(byte r, byte g, byte b) + { + return new ABGR8888(_formatDescriptor.MapRGB(r, g, b)); + } + + public static ABGR8888 FromRGBA(byte r, byte g, byte b, byte a) + { + return new ABGR8888(_formatDescriptor.MapRGBA(r, g, b, a)); + } + + public ABGR8888(byte a, byte b, byte g, byte r) + : this(_formatDescriptor.MapRGBA(r, g, b, a)) + { } + + private ABGR8888(uint value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/video/pixels/ARGB1555.cs b/sources/SDL2Sharp/video/pixels/ARGB1555.cs new file mode 100644 index 00000000..d6989eae --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/ARGB1555.cs @@ -0,0 +1,59 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct ARGB1555 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.ARGB1555); + + private readonly ushort _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static ARGB1555 FromRGB(byte r, byte g, byte b) + { + return new ARGB1555((ushort)_formatDescriptor.MapRGB(r, g, b)); + } + + public static ARGB1555 FromRGBA(byte r, byte g, byte b, byte a) + { + return new ARGB1555((ushort)_formatDescriptor.MapRGBA(r, g, b, a)); + } + + private ARGB1555(ushort value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/Colors/Abgr8888.cs b/sources/SDL2Sharp/video/pixels/ARGB2101010.cs similarity index 52% rename from sources/SDL2Sharp/Colors/Abgr8888.cs rename to sources/SDL2Sharp/video/pixels/ARGB2101010.cs index fc97dd49..98893e34 100644 --- a/sources/SDL2Sharp/Colors/Abgr8888.cs +++ b/sources/SDL2Sharp/video/pixels/ARGB2101010.cs @@ -19,30 +19,41 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Runtime.InteropServices; -using SDL2Sharp.Internals; -namespace SDL2Sharp.Colors +namespace SDL2Sharp { - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 4)] - [PackedColor(PixelFormatEnum.ABGR8888)] - public readonly record struct Abgr8888 + [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)] + public readonly record struct ARGB2101010 : IPackedPixel { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.ARGB2101010); + private readonly uint _value; - public byte A => (byte)(_value >> 24 & 0xFF); + public static PixelFormat Format => _formatDescriptor.Format; - public byte B => (byte)(_value >> 16 & 0xFF); + public static ARGB2101010 FromRGB(byte r, byte g, byte b) + { + return new ARGB2101010(_formatDescriptor.MapRGB(r, g, b)); + } + + public static ARGB2101010 FromRGBA(byte r, byte g, byte b, byte a) + { + return new ARGB2101010(_formatDescriptor.MapRGBA(r, g, b, a)); + } - public byte G => (byte)(_value >> 8 & 0xFF); + private ARGB2101010(uint value) + { + _value = value; + } - public byte R => (byte)(_value & 0xFF); + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } - public Abgr8888(byte a, byte b, byte g, byte r) + public (byte r, byte g, byte b, byte a) ToRGBA() { - unchecked - { - _value = (uint)(a << 24 | b << 16 | g << 8 | r); - } + return _formatDescriptor.GetRGBA(_value); } } } diff --git a/sources/SDL2Sharp/video/pixels/ARGB4444.cs b/sources/SDL2Sharp/video/pixels/ARGB4444.cs new file mode 100644 index 00000000..fcb7c452 --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/ARGB4444.cs @@ -0,0 +1,59 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct ARGB4444 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.ARGB4444); + + private readonly ushort _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static ARGB4444 FromRGB(byte r, byte g, byte b) + { + return new ARGB4444((ushort)_formatDescriptor.MapRGB(r, g, b)); + } + + public static ARGB4444 FromRGBA(byte r, byte g, byte b, byte a) + { + return new ARGB4444((ushort)_formatDescriptor.MapRGBA(r, g, b, a)); + } + + private ARGB4444(ushort value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/video/pixels/ARGB8888.cs b/sources/SDL2Sharp/video/pixels/ARGB8888.cs new file mode 100644 index 00000000..e0fb91db --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/ARGB8888.cs @@ -0,0 +1,63 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)] + public readonly record struct ARGB8888 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.ARGB8888); + + private readonly uint _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static ARGB8888 FromRGB(byte r, byte g, byte b) + { + return new ARGB8888(_formatDescriptor.MapRGB(r, g, b)); + } + + public static ARGB8888 FromRGBA(byte r, byte g, byte b, byte a) + { + return new ARGB8888(_formatDescriptor.MapRGBA(r, g, b, a)); + } + + public ARGB8888(byte a, byte r, byte g, byte b) + : this(_formatDescriptor.MapRGBA(r, g, b, a)) + { } + + private ARGB8888(uint value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/Colors/Bgr24.cs b/sources/SDL2Sharp/video/pixels/BGR24.cs similarity index 87% rename from sources/SDL2Sharp/Colors/Bgr24.cs rename to sources/SDL2Sharp/video/pixels/BGR24.cs index a8513168..b1c1192b 100644 --- a/sources/SDL2Sharp/Colors/Bgr24.cs +++ b/sources/SDL2Sharp/video/pixels/BGR24.cs @@ -19,13 +19,11 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Runtime.InteropServices; -using SDL2Sharp.Internals; -namespace SDL2Sharp.Colors +namespace SDL2Sharp { [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 3)] - [PackedColor(PixelFormatEnum.BGR24)] - public readonly record struct Bgr24 + public readonly record struct BGR24 { private readonly byte _r, _g, _b; @@ -35,7 +33,7 @@ public readonly record struct Bgr24 public byte R => _r; - public Bgr24(byte b, byte g, byte r) + public BGR24(byte b, byte g, byte r) { _b = b; _g = g; diff --git a/sources/SDL2Sharp/Colors/Argb1555.cs b/sources/SDL2Sharp/video/pixels/BGR565.cs similarity index 52% rename from sources/SDL2Sharp/Colors/Argb1555.cs rename to sources/SDL2Sharp/video/pixels/BGR565.cs index ced06a17..a7a5e769 100644 --- a/sources/SDL2Sharp/Colors/Argb1555.cs +++ b/sources/SDL2Sharp/video/pixels/BGR565.cs @@ -19,27 +19,41 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Runtime.InteropServices; -using SDL2Sharp.Internals; -namespace SDL2Sharp.Colors +namespace SDL2Sharp { - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 1)] - [PackedColor(PixelFormatEnum.ARGB1555)] - public readonly record struct Argb1555 + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct BGR565 : IPackedPixel { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.BGR565); + private readonly ushort _value; - public byte A => (byte)(_value >> 15 & 0x1); + public static PixelFormat Format => _formatDescriptor.Format; - public byte R => (byte)(_value >> 10 & 0x1F); + public static BGR565 FromRGB(byte r, byte g, byte b) + { + return new BGR565((ushort)_formatDescriptor.MapRGB(r, g, b)); + } + + public static BGR565 FromRGBA(byte r, byte g, byte b, byte a) + { + return new BGR565((ushort)_formatDescriptor.MapRGBA(r, g, b, a)); + } - public byte G => (byte)(_value >> 5 & 0x1F); + private BGR565(ushort value) + { + _value = value; + } - public byte B => (byte)(_value & 0x1F); + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } - public Argb1555(byte a, byte r, byte g, byte b) + public (byte r, byte g, byte b, byte a) ToRGBA() { - _value = (ushort)((a & 0x1) << 15 | (r & 0x1F) << 10 | (g & 0x1F) << 5 | b & 0x1F); + return _formatDescriptor.GetRGBA(_value); } } } diff --git a/sources/SDL2Sharp/video/pixels/BGRA4444.cs b/sources/SDL2Sharp/video/pixels/BGRA4444.cs new file mode 100644 index 00000000..aba91336 --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/BGRA4444.cs @@ -0,0 +1,59 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct BGRA4444 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.BGRA4444); + + private readonly ushort _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static BGRA4444 FromRGB(byte r, byte g, byte b) + { + return new BGRA4444((ushort)_formatDescriptor.MapRGB(r, g, b)); + } + + public static BGRA4444 FromRGBA(byte r, byte g, byte b, byte a) + { + return new BGRA4444((ushort)_formatDescriptor.MapRGBA(r, g, b, a)); + } + + private BGRA4444(ushort value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/video/pixels/BGRA5551.cs b/sources/SDL2Sharp/video/pixels/BGRA5551.cs new file mode 100644 index 00000000..5786b28f --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/BGRA5551.cs @@ -0,0 +1,59 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct BGRA5551 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.BGRA5551); + + private readonly ushort _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static BGRA5551 FromRGB(byte r, byte g, byte b) + { + return new BGRA5551((ushort)_formatDescriptor.MapRGB(r, g, b)); + } + + public static BGRA5551 FromRGBA(byte r, byte g, byte b, byte a) + { + return new BGRA5551((ushort)_formatDescriptor.MapRGBA(r, g, b, a)); + } + + private BGRA5551(ushort value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/video/pixels/BGRA8888.cs b/sources/SDL2Sharp/video/pixels/BGRA8888.cs new file mode 100644 index 00000000..4c64c0f6 --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/BGRA8888.cs @@ -0,0 +1,69 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)] + public readonly record struct BGRA8888 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.BGRA8888); + + private readonly uint _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static BGRA8888 FromRGBA(byte r, byte g, byte b) + { + return new BGRA8888(_formatDescriptor.MapRGB(r, g, b)); + } + + public static BGRA8888 FromRGBA(byte r, byte g, byte b, byte a) + { + return new BGRA8888(_formatDescriptor.MapRGBA(r, g, b, a)); + } + + public BGRA8888(byte b, byte g, byte r, byte a) + : this(_formatDescriptor.MapRGBA(r, g, b, a)) + { } + + private BGRA8888(uint value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + + public static BGRA8888 FromRGB(byte r, byte g, byte b) + { + throw new NotImplementedException(); + } + } +} diff --git a/sources/SDL2Sharp/Colors/Argb2101010.cs b/sources/SDL2Sharp/video/pixels/BGRX8888.cs similarity index 50% rename from sources/SDL2Sharp/Colors/Argb2101010.cs rename to sources/SDL2Sharp/video/pixels/BGRX8888.cs index 148c9dc4..0626b0d4 100644 --- a/sources/SDL2Sharp/Colors/Argb2101010.cs +++ b/sources/SDL2Sharp/video/pixels/BGRX8888.cs @@ -19,30 +19,45 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Runtime.InteropServices; -using SDL2Sharp.Internals; -namespace SDL2Sharp.Colors +namespace SDL2Sharp { - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 4)] - [PackedColor(PixelFormatEnum.ARGB2101010)] - public readonly record struct Argb2101010 + [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)] + public readonly record struct BGRX8888 : IPackedPixel { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.BGRX8888); + private readonly uint _value; - public ushort A => (ushort)(_value >> 30 & 0x3); + public static PixelFormat Format => _formatDescriptor.Format; + + public static BGRX8888 FromRGB(byte r, byte g, byte b) + { + return new BGRX8888(_formatDescriptor.MapRGB(r, g, b)); + } - public ushort R => (ushort)(_value >> 20 & 0x3FF); + public static BGRX8888 FromRGBA(byte r, byte g, byte b, byte a) + { + return new BGRX8888(_formatDescriptor.MapRGBA(r, g, b, a)); + } - public ushort G => (ushort)(_value >> 10 & 0x3FF); + public BGRX8888(byte b, byte g, byte r) + : this(_formatDescriptor.MapRGB(r, g, b)) + { } - public ushort B => (ushort)(_value & 0x3FF); + private BGRX8888(uint value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } - public Argb2101010(byte a, ushort r, ushort g, ushort b) + public (byte r, byte g, byte b, byte a) ToRGBA() { - unchecked - { - _value = (uint)(a << 30 & 0x3 | r << 20 & 0x3FF | g << 10 & 0x3FF | b & 0x3FF); - } + return _formatDescriptor.GetRGBA(_value); } } } diff --git a/sources/SDL2Sharp/video/pixels/IPackedPixel.cs b/sources/SDL2Sharp/video/pixels/IPackedPixel.cs new file mode 100644 index 00000000..fb171006 --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/IPackedPixel.cs @@ -0,0 +1,35 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +namespace SDL2Sharp +{ + public interface IPackedPixel where TPackedPixel : struct + { + public static abstract PixelFormat Format { get; } + + public static abstract TPackedPixel FromRGB(byte r, byte g, byte b); + + public static abstract TPackedPixel FromRGBA(byte r, byte g, byte b, byte a); + + public abstract (byte r, byte g, byte b) ToRGB(); + + public abstract (byte r, byte g, byte b, byte a) ToRGBA(); + } +} diff --git a/sources/SDL2Sharp/video/pixels/IYUV.cs b/sources/SDL2Sharp/video/pixels/IYUV.cs new file mode 100644 index 00000000..40b308d1 --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/IYUV.cs @@ -0,0 +1,54 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.CompilerServices; + +namespace SDL2Sharp +{ + public readonly struct IYUV : IYUVFormat + { + public static PixelFormat PixelFormat => PixelFormat.IYUV; + + public static unsafe ImagePlane CreateYPlane(void* pixels, int imageWidth, int imageHeight, int imagePitch) + { + return new ImagePlane(pixels, imageWidth, imageHeight, imagePitch); + } + + public static unsafe ImagePlane CreateUPlane(void* pixels, int imageWidth, int imageHeight, int imagePitch) + { + var uPlaneWidth = imageWidth / 2; + var uPlaneHeight = imageHeight / 2; + var uPlanePitch = imagePitch / 2; + var uPlaneOffset = imageHeight * imagePitch; + var uPlanePixels = Unsafe.Add(pixels, uPlaneOffset); + return new ImagePlane(uPlanePixels, uPlaneWidth, uPlaneHeight, uPlanePitch); + } + + public static unsafe ImagePlane CreateVPlane(void* pixels, int imageWidth, int imageHeight, int imagePitch) + { + var vPlaneWidth = imageWidth / 2; + var vPlaneHeight = imageHeight / 2; + var vPlanePitch = imagePitch / 2; + var vPlaneOffset = imageHeight * imagePitch + imageHeight * imagePitch / 4; + var vPlanePixels = Unsafe.Add(pixels, vPlaneOffset); + return new ImagePlane(vPlanePixels, vPlaneWidth, vPlaneHeight, vPlanePitch); + } + } +} diff --git a/sources/SDL2Sharp/video/pixels/IYUVFormat.cs b/sources/SDL2Sharp/video/pixels/IYUVFormat.cs new file mode 100644 index 00000000..b55962d7 --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/IYUVFormat.cs @@ -0,0 +1,33 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +namespace SDL2Sharp +{ + public interface IYUVFormat + { + static abstract PixelFormat PixelFormat { get; } + + static abstract unsafe ImagePlane CreateYPlane(void* pixels, int imageWidth, int imageHeight, int imagePitch); + + static abstract unsafe ImagePlane CreateUPlane(void* pixels, int imageWidth, int imageHeight, int imagePitch); + + static abstract unsafe ImagePlane CreateVPlane(void* pixels, int imageWidth, int imageHeight, int imagePitch); + } +} diff --git a/sources/SDL2Sharp/Colors/Rgb24.cs b/sources/SDL2Sharp/video/pixels/RGB24.cs similarity index 87% rename from sources/SDL2Sharp/Colors/Rgb24.cs rename to sources/SDL2Sharp/video/pixels/RGB24.cs index 2d7b12ba..985015c5 100644 --- a/sources/SDL2Sharp/Colors/Rgb24.cs +++ b/sources/SDL2Sharp/video/pixels/RGB24.cs @@ -19,13 +19,11 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Runtime.InteropServices; -using SDL2Sharp.Internals; -namespace SDL2Sharp.Colors +namespace SDL2Sharp { [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 3)] - [PackedColor(PixelFormatEnum.RGB24)] - public readonly record struct Rgb24 + public readonly record struct RGB24 { private readonly byte _b, _g, _r; @@ -35,7 +33,7 @@ public readonly record struct Rgb24 public byte B => _b; - public Rgb24(byte r, byte g, byte b) + public RGB24(byte r, byte g, byte b) { _r = r; _g = g; diff --git a/sources/SDL2Sharp/Colors/Rgb332.cs b/sources/SDL2Sharp/video/pixels/RGB332.cs similarity index 55% rename from sources/SDL2Sharp/Colors/Rgb332.cs rename to sources/SDL2Sharp/video/pixels/RGB332.cs index c8b3f8fb..c7674226 100644 --- a/sources/SDL2Sharp/Colors/Rgb332.cs +++ b/sources/SDL2Sharp/video/pixels/RGB332.cs @@ -19,25 +19,41 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Runtime.InteropServices; -using SDL2Sharp.Internals; -namespace SDL2Sharp.Colors +namespace SDL2Sharp { [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 1)] - [PackedColor(PixelFormatEnum.RGB332)] - public readonly record struct Rgb332 + public readonly record struct RGB332 : IPackedPixel { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.RGB332); + private readonly byte _value; - public byte R => (byte)(_value >> 5 & 0x7); + public static PixelFormat Format => _formatDescriptor.Format; + + public static RGB332 FromRGB(byte r, byte g, byte b) + { + return new RGB332((byte)_formatDescriptor.MapRGB(r, g, b)); + } - public byte G => (byte)(_value >> 2 & 0x7); + public static RGB332 FromRGBA(byte r, byte g, byte b, byte a) + { + return new RGB332((byte)_formatDescriptor.MapRGBA(r, g, b, a)); + } - public byte B => (byte)(_value & 0x3); + private RGB332(byte value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } - public Rgb332(byte r, byte g, byte b) + public (byte r, byte g, byte b, byte a) ToRGBA() { - _value = (byte)((r & 0x7) << 5 | (g & 0x7) << 2 | b & 0x3); + return _formatDescriptor.GetRGBA(_value); } } } diff --git a/sources/SDL2Sharp/Colors/Abgr1555.cs b/sources/SDL2Sharp/video/pixels/RGB565.cs similarity index 52% rename from sources/SDL2Sharp/Colors/Abgr1555.cs rename to sources/SDL2Sharp/video/pixels/RGB565.cs index f310b555..d8536c49 100644 --- a/sources/SDL2Sharp/Colors/Abgr1555.cs +++ b/sources/SDL2Sharp/video/pixels/RGB565.cs @@ -19,27 +19,41 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Runtime.InteropServices; -using SDL2Sharp.Internals; -namespace SDL2Sharp.Colors +namespace SDL2Sharp { - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 1)] - [PackedColor(PixelFormatEnum.ABGR1555)] - public readonly record struct Abgr1555 + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct RGB565 : IPackedPixel { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.RGB565); + private readonly ushort _value; - public byte A => (byte)(_value >> 15 & 0x1); + public static PixelFormat Format => _formatDescriptor.Format; - public byte B => (byte)(_value >> 10 & 0x1F); + public static RGB565 FromRGB(byte r, byte g, byte b) + { + return new RGB565((ushort)_formatDescriptor.MapRGB(r, g, b)); + } + + public static RGB565 FromRGBA(byte r, byte g, byte b, byte a) + { + return new RGB565((ushort)_formatDescriptor.MapRGBA(r, g, b, a)); + } - public byte G => (byte)(_value >> 5 & 0x1F); + private RGB565(ushort value) + { + _value = value; + } - public byte R => (byte)(_value & 0x1F); + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } - public Abgr1555(byte a, byte b, byte g, byte r) + public (byte r, byte g, byte b, byte a) ToRGBA() { - _value = (ushort)((a & 0x1) << 15 | (b & 0x1F) << 10 | (g & 0x1F) << 5 | r & 0x1F); + return _formatDescriptor.GetRGBA(_value); } } } diff --git a/sources/SDL2Sharp.Extensions/Rgb32f.cs b/sources/SDL2Sharp/video/pixels/RGB96f.cs similarity index 68% rename from sources/SDL2Sharp.Extensions/Rgb32f.cs rename to sources/SDL2Sharp/video/pixels/RGB96f.cs index 715d95fe..5306f406 100644 --- a/sources/SDL2Sharp.Extensions/Rgb32f.cs +++ b/sources/SDL2Sharp/video/pixels/RGB96f.cs @@ -23,14 +23,14 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace SDL2Sharp.Extensions +namespace SDL2Sharp { [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 12)] - public readonly struct Rgb32f : IEquatable + public readonly struct RGB96f : IEquatable { - public static Rgb32f Black { get; } = new Rgb32f(0f, 0f, 0f); + public static RGB96f Black { get; } = new RGB96f(0f, 0f, 0f); - public static Rgb32f White { get; } = new Rgb32f(1f, 1f, 1f); + public static RGB96f White { get; } = new RGB96f(1f, 1f, 1f); private readonly Vector3 _components; @@ -62,23 +62,23 @@ public float B } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Rgb32f(float r, float g, float b) + public RGB96f(float r, float g, float b) : this(new Vector3(r, g, b)) { } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Rgb32f(Rgb32f other) + public RGB96f(RGB96f other) : this(other._components) { } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private Rgb32f(Vector3 components) + private RGB96f(Vector3 components) { _components = components; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly bool Equals(Rgb32f other) + public readonly bool Equals(RGB96f other) { return _components.Equals(other._components); } @@ -86,7 +86,7 @@ public readonly bool Equals(Rgb32f other) [MethodImpl(MethodImplOptions.AggressiveInlining)] public override readonly bool Equals(object? obj) { - if (obj is Rgb32f other) + if (obj is RGB96f other) { return Equals(other); } @@ -99,127 +99,127 @@ public override readonly int GetHashCode() } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f Negate(Rgb32f value) + public static RGB96f Negate(RGB96f value) { - return new Rgb32f(-value._components); + return new RGB96f(-value._components); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f Add(Rgb32f left, Rgb32f right) + public static RGB96f Add(RGB96f left, RGB96f right) { - return new Rgb32f(left._components + right._components); + return new RGB96f(left._components + right._components); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f Subtract(Rgb32f left, Rgb32f right) + public static RGB96f Subtract(RGB96f left, RGB96f right) { - return new Rgb32f(left._components - right._components); + return new RGB96f(left._components - right._components); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f Multiply(float left, Rgb32f right) + public static RGB96f Multiply(float left, RGB96f right) { - return new Rgb32f(left * right._components); + return new RGB96f(left * right._components); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f Multiply(Rgb32f left, float right) + public static RGB96f Multiply(RGB96f left, float right) { - return new Rgb32f(left._components * right); + return new RGB96f(left._components * right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f Multiply(Rgb32f left, Rgb32f right) + public static RGB96f Multiply(RGB96f left, RGB96f right) { - return new Rgb32f(left._components * right._components); + return new RGB96f(left._components * right._components); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f Divide(Rgb32f left, Rgb32f right) + public static RGB96f Divide(RGB96f left, RGB96f right) { - return new Rgb32f(left._components / right._components); + return new RGB96f(left._components / right._components); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f Divide(Rgb32f left, float right) + public static RGB96f Divide(RGB96f left, float right) { - return new Rgb32f(left._components / right); + return new RGB96f(left._components / right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f Clamp(Rgb32f value, Rgb32f min, Rgb32f max) + public static RGB96f Clamp(RGB96f value, RGB96f min, RGB96f max) { - return new Rgb32f(Vector3.Clamp(value._components, min._components, max._components)); + return new RGB96f(Vector3.Clamp(value._components, min._components, max._components)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f Clamp(Rgb32f value) + public static RGB96f Clamp(RGB96f value) { return Clamp(value, Black, White); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f operator +(Rgb32f value) + public static RGB96f operator +(RGB96f value) { return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f operator -(Rgb32f value) + public static RGB96f operator -(RGB96f value) { return Negate(value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f operator +(Rgb32f left, Rgb32f right) + public static RGB96f operator +(RGB96f left, RGB96f right) { return Add(left, right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f operator -(Rgb32f left, Rgb32f right) + public static RGB96f operator -(RGB96f left, RGB96f right) { return Subtract(left, right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f operator *(float left, Rgb32f right) + public static RGB96f operator *(float left, RGB96f right) { return Multiply(left, right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f operator *(Rgb32f left, float right) + public static RGB96f operator *(RGB96f left, float right) { return Multiply(left, right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f operator *(Rgb32f left, Rgb32f right) + public static RGB96f operator *(RGB96f left, RGB96f right) { return Multiply(left, right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f operator /(Rgb32f left, Rgb32f right) + public static RGB96f operator /(RGB96f left, RGB96f right) { return Divide(left, right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb32f operator /(Rgb32f left, float right) + public static RGB96f operator /(RGB96f left, float right) { return Divide(left, right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator ==(Rgb32f left, Rgb32f right) + public static bool operator ==(RGB96f left, RGB96f right) { return left.Equals(right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator !=(Rgb32f left, Rgb32f right) + public static bool operator !=(RGB96f left, RGB96f right) { return !left.Equals(right); } diff --git a/sources/SDL2Sharp.Extensions/Rgb32fExtensions.cs b/sources/SDL2Sharp/video/pixels/RGB96fExtensions.cs similarity index 56% rename from sources/SDL2Sharp.Extensions/Rgb32fExtensions.cs rename to sources/SDL2Sharp/video/pixels/RGB96fExtensions.cs index bf7cd829..fd420c93 100644 --- a/sources/SDL2Sharp.Extensions/Rgb32fExtensions.cs +++ b/sources/SDL2Sharp/video/pixels/RGB96fExtensions.cs @@ -18,40 +18,40 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using SDL2Sharp.Colors; +using static System.Math; -namespace SDL2Sharp.Extensions +namespace SDL2Sharp { - public static class Rgb32fExtensions + public static class RGB96fExtensions { - public static Color ToColor(this Rgb32f color) + public static Color ToColor(this RGB96f color) { - var clampedColor = Rgb32f.Clamp(color); + var clampedColor = RGB96f.Clamp(color); var scaledColor = clampedColor * 255f; - var r = (byte)scaledColor.R; - var g = (byte)scaledColor.G; - var b = (byte)scaledColor.B; + var r = (byte)Round(scaledColor.R); + var g = (byte)Round(scaledColor.G); + var b = (byte)Round(scaledColor.B); return new Color(r, g, b, 255); } - public static Rgba8888 ToRgba8888(this Rgb32f color) + public static RGBA8888 ToRgba8888(this RGB96f color) { - var clampedColor = Rgb32f.Clamp(color); + var clampedColor = RGB96f.Clamp(color); var scaledColor = clampedColor * 255f; - var r = (byte)scaledColor.R; - var g = (byte)scaledColor.G; - var b = (byte)scaledColor.B; - return new Rgba8888(r, g, b, 255); + var r = (byte)Round(scaledColor.R); + var g = (byte)Round(scaledColor.G); + var b = (byte)Round(scaledColor.B); + return new RGBA8888(r, g, b, 255); } - public static Argb8888 ToArgb8888(this Rgb32f color) + public static ARGB8888 ToArgb8888(this RGB96f color) { - var clampedColor = Rgb32f.Clamp(color); + var clampedColor = RGB96f.Clamp(color); var scaledColor = clampedColor * 255f; - var r = (byte)scaledColor.R; - var g = (byte)scaledColor.G; - var b = (byte)scaledColor.B; - return new Argb8888(255, r, g, b); + var r = (byte)Round(scaledColor.R); + var g = (byte)Round(scaledColor.G); + var b = (byte)Round(scaledColor.B); + return new ARGB8888(255, r, g, b); } } } diff --git a/sources/SDL2Sharp/video/pixels/RGBA4444.cs b/sources/SDL2Sharp/video/pixels/RGBA4444.cs new file mode 100644 index 00000000..38887247 --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/RGBA4444.cs @@ -0,0 +1,59 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct RGBA4444 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.RGBA4444); + + public static PixelFormat Format => _formatDescriptor.Format; + + public static RGBA4444 FromRGB(byte r, byte g, byte b) + { + return new RGBA4444((ushort)_formatDescriptor.MapRGB(r, g, b)); + } + + public static RGBA4444 FromRGBA(byte r, byte g, byte b, byte a) + { + return new RGBA4444((ushort)_formatDescriptor.MapRGBA(r, g, b, a)); + } + + private readonly ushort _value; + + private RGBA4444(ushort value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/video/pixels/RGBA5551.cs b/sources/SDL2Sharp/video/pixels/RGBA5551.cs new file mode 100644 index 00000000..232308da --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/RGBA5551.cs @@ -0,0 +1,59 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct RGBA5551 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.RGBA5551); + + private readonly ushort _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static RGBA5551 FromRGB(byte r, byte g, byte b) + { + return new RGBA5551((ushort)_formatDescriptor.MapRGB(r, g, b)); + } + + public static RGBA5551 FromRGBA(byte r, byte g, byte b, byte a) + { + return new RGBA5551((ushort)_formatDescriptor.MapRGBA(r, g, b, a)); + } + + private RGBA5551(ushort value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/video/pixels/RGBA8888.cs b/sources/SDL2Sharp/video/pixels/RGBA8888.cs new file mode 100644 index 00000000..e4d18298 --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/RGBA8888.cs @@ -0,0 +1,63 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)] + public readonly record struct RGBA8888 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.RGBA8888); + + private readonly uint _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static RGBA8888 FromRGB(byte r, byte g, byte b) + { + return new RGBA8888(_formatDescriptor.MapRGB(r, g, b)); + } + + public static RGBA8888 FromRGBA(byte r, byte g, byte b, byte a) + { + return new RGBA8888(_formatDescriptor.MapRGBA(r, g, b, a)); + } + + public RGBA8888(byte r, byte g, byte b, byte a) + : this(_formatDescriptor.MapRGBA(r, g, b, a)) + { } + + private RGBA8888(uint value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/Colors/Argb8888.cs b/sources/SDL2Sharp/video/pixels/RGBX8888.cs similarity index 50% rename from sources/SDL2Sharp/Colors/Argb8888.cs rename to sources/SDL2Sharp/video/pixels/RGBX8888.cs index b2848e89..853bd7a8 100644 --- a/sources/SDL2Sharp/Colors/Argb8888.cs +++ b/sources/SDL2Sharp/video/pixels/RGBX8888.cs @@ -19,30 +19,45 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Runtime.InteropServices; -using SDL2Sharp.Internals; -namespace SDL2Sharp.Colors +namespace SDL2Sharp { - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 4)] - [PackedColor(PixelFormatEnum.ARGB8888)] - public readonly record struct Argb8888 + [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)] + public readonly record struct RGBX8888 : IPackedPixel { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.RGBX8888); + private readonly uint _value; - public byte A => (byte)(_value >> 24 & 0xFF); + public static PixelFormat Format => _formatDescriptor.Format; + + public static RGBX8888 FromRGB(byte r, byte g, byte b) + { + return new RGBX8888(_formatDescriptor.MapRGB(r, g, b)); + } - public byte R => (byte)(_value >> 16 & 0xFF); + public static RGBX8888 FromRGBA(byte r, byte g, byte b, byte a) + { + return new RGBX8888(_formatDescriptor.MapRGBA(r, g, b, a)); + } - public byte G => (byte)(_value >> 8 & 0xFF); + public RGBX8888(byte r, byte g, byte b) + : this(_formatDescriptor.MapRGB(r, g, b)) + { } - public byte B => (byte)(_value & 0xFF); + private RGBX8888(uint value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } - public Argb8888(byte a, byte r, byte g, byte b) + public (byte r, byte g, byte b, byte a) ToRGBA() { - unchecked - { - _value = (uint)(a << 24 | r << 16 | g << 8 | b); - } + return _formatDescriptor.GetRGBA(_value); } } } diff --git a/tests/SDL2Sharp.UnitTests/ApplicationTests.cs b/sources/SDL2Sharp/video/pixels/U8.cs similarity index 79% rename from tests/SDL2Sharp.UnitTests/ApplicationTests.cs rename to sources/SDL2Sharp/video/pixels/U8.cs index 27ac47de..db6cc563 100644 --- a/tests/SDL2Sharp.UnitTests/ApplicationTests.cs +++ b/sources/SDL2Sharp/video/pixels/U8.cs @@ -18,18 +18,18 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using Xunit; +using System.Runtime.InteropServices; -namespace SDL2Sharp.UnitTests +namespace SDL2Sharp { - public static class ApplicationTests + [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 1)] + public readonly record struct U8 { - private sealed class App : Application { } + private readonly byte _value; - [Fact] - public static void TestConstructor() + public U8(byte value) { - Assert.NotNull(new App()); + _value = value; } } } diff --git a/sources/SDL2Sharp.Extensions/ThreadExtensions.cs b/sources/SDL2Sharp/video/pixels/UV88.cs similarity index 71% rename from sources/SDL2Sharp.Extensions/ThreadExtensions.cs rename to sources/SDL2Sharp/video/pixels/UV88.cs index 6f1fb128..3e7f435b 100644 --- a/sources/SDL2Sharp.Extensions/ThreadExtensions.cs +++ b/sources/SDL2Sharp/video/pixels/UV88.cs @@ -18,23 +18,24 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using System; -using System.Threading; +using System.Runtime.InteropServices; -namespace SDL2Sharp.Extensions +namespace SDL2Sharp { - public static class ThreadExtensions + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct UV88 { - public static void SafeJoin(this Thread thread) - { - if (thread is null) - { - throw new ArgumentNullException(nameof(thread)); - } + private readonly ushort _value; - if (thread.ThreadState != ThreadState.Unstarted) + public byte U => (byte)(_value >> 8 & 0xFF); + + public byte V => (byte)(_value & 0xFF); + + public UV88(byte u, byte v) + { + unchecked { - thread.Join(); + _value = (ushort)(u << 8 | v); } } } diff --git a/sources/SDL2Sharp/Colors/Rgbx8888.cs b/sources/SDL2Sharp/video/pixels/UYVY.cs similarity index 70% rename from sources/SDL2Sharp/Colors/Rgbx8888.cs rename to sources/SDL2Sharp/video/pixels/UYVY.cs index b5e935a4..1f14d2ce 100644 --- a/sources/SDL2Sharp/Colors/Rgbx8888.cs +++ b/sources/SDL2Sharp/video/pixels/UYVY.cs @@ -19,27 +19,27 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Runtime.InteropServices; -using SDL2Sharp.Internals; -namespace SDL2Sharp.Colors +namespace SDL2Sharp { - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 4)] - [PackedColor(PixelFormatEnum.RGBX8888)] - public readonly record struct Rgbx8888 + [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)] + public readonly record struct UYVY { private readonly uint _value; - public byte R => (byte)(_value >> 24 & 0xFF); + public byte U0 => (byte)(_value & 0xFF); - public byte G => (byte)(_value >> 16 & 0xFF); + public byte Y0 => (byte)(_value >> 8 & 0xFF); - public byte B => (byte)(_value >> 8 & 0xFF); + public byte V0 => (byte)(_value >> 16 & 0xFF); - public Rgbx8888(byte r, byte g, byte b) + public byte Y1 => (byte)(_value >> 24 & 0xFF); + + public UYVY(byte u0, byte y0, byte v0, byte y1) { unchecked { - _value = (uint)(r << 24 | g << 16 | b << 8); + _value = (uint)(u0 | y0 << 8 | v0 << 16 | y1 << 24); } } } diff --git a/sources/SDL2Sharp/WindowResizedEventArgs.cs b/sources/SDL2Sharp/video/pixels/V8.cs similarity index 79% rename from sources/SDL2Sharp/WindowResizedEventArgs.cs rename to sources/SDL2Sharp/video/pixels/V8.cs index 5eeed938..83285a49 100644 --- a/sources/SDL2Sharp/WindowResizedEventArgs.cs +++ b/sources/SDL2Sharp/video/pixels/V8.cs @@ -18,20 +18,18 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using System; +using System.Runtime.InteropServices; namespace SDL2Sharp { - public sealed class WindowResizedEventArgs : EventArgs + [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 1)] + public readonly record struct V8 { - public int Width { get; } + private readonly byte _value; - public int Height { get; } - - public WindowResizedEventArgs(int width, int height) + public V8(byte value) { - Width = width; - Height = height; + _value = value; } } } diff --git a/sources/SDL2Sharp/video/pixels/VU88.cs b/sources/SDL2Sharp/video/pixels/VU88.cs new file mode 100644 index 00000000..59eb9e2e --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/VU88.cs @@ -0,0 +1,42 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct VU88 + { + private readonly ushort _value; + + public byte V => (byte)(_value >> 8 & 0xFF); + + public byte U => (byte)(_value & 0xFF); + + public VU88(byte v, byte u) + { + unchecked + { + _value = (ushort)(v << 8 | u); + } + } + } +} diff --git a/sources/SDL2Sharp/video/pixels/XBGR1555.cs b/sources/SDL2Sharp/video/pixels/XBGR1555.cs new file mode 100644 index 00000000..56fdc6d8 --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/XBGR1555.cs @@ -0,0 +1,59 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct XBGR1555 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.XBGR1555); + + private readonly ushort _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static XBGR1555 FromRGB(byte r, byte g, byte b) + { + return new XBGR1555((ushort)_formatDescriptor.MapRGB(r, g, b)); + } + + public static XBGR1555 FromRGBA(byte r, byte g, byte b, byte a) + { + return new XBGR1555((ushort)_formatDescriptor.MapRGBA(r, g, b, a)); + } + + private XBGR1555(ushort value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/video/pixels/XBGR4444.cs b/sources/SDL2Sharp/video/pixels/XBGR4444.cs new file mode 100644 index 00000000..338d7809 --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/XBGR4444.cs @@ -0,0 +1,59 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct XBGR4444 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.XBGR4444); + + private readonly ushort _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static XBGR4444 FromRGB(byte r, byte g, byte b) + { + return new XBGR4444((ushort)_formatDescriptor.MapRGB(r, g, b)); + } + + public static XBGR4444 FromRGBA(byte r, byte g, byte b, byte a) + { + return new XBGR4444((ushort)_formatDescriptor.MapRGBA(r, g, b, a)); + } + + private XBGR4444(ushort value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/video/pixels/XBGR8888.cs b/sources/SDL2Sharp/video/pixels/XBGR8888.cs new file mode 100644 index 00000000..11ff6f85 --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/XBGR8888.cs @@ -0,0 +1,63 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)] + public readonly record struct XBGR8888 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.XBGR8888); + + private readonly uint _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static XBGR8888 FromRGB(byte r, byte g, byte b) + { + return new XBGR8888(_formatDescriptor.MapRGB(r, g, b)); + } + + public static XBGR8888 FromRGBA(byte r, byte g, byte b, byte a) + { + return new XBGR8888(_formatDescriptor.MapRGBA(r, g, b, a)); + } + + public XBGR8888(byte b, byte g, byte r) + : this(_formatDescriptor.MapRGB(r, g, b)) + { } + + private XBGR8888(uint value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/video/pixels/XRGB1555.cs b/sources/SDL2Sharp/video/pixels/XRGB1555.cs new file mode 100644 index 00000000..9e65a844 --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/XRGB1555.cs @@ -0,0 +1,59 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct XRGB1555 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.XRGB1555); + + private readonly ushort _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static XRGB1555 FromRGB(byte r, byte g, byte b) + { + return new XRGB1555((ushort)_formatDescriptor.MapRGB(r, g, b)); + } + + public static XRGB1555 FromRGBA(byte r, byte g, byte b, byte a) + { + return new XRGB1555((ushort)_formatDescriptor.MapRGBA(r, g, b, a)); + } + + private XRGB1555(ushort value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/video/pixels/XRGB4444.cs b/sources/SDL2Sharp/video/pixels/XRGB4444.cs new file mode 100644 index 00000000..1c01e24d --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/XRGB4444.cs @@ -0,0 +1,59 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 2, Size = 2)] + public readonly record struct XRGB4444 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.XRGB4444); + + private readonly ushort _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static XRGB4444 FromRGB(byte r, byte g, byte b) + { + return new XRGB4444((ushort)_formatDescriptor.MapRGB(r, g, b)); + } + + public static XRGB4444 FromRGBA(byte r, byte g, byte b, byte a) + { + return new XRGB4444((ushort)_formatDescriptor.MapRGBA(r, g, b, a)); + } + + private XRGB4444(ushort value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/video/pixels/XRGB8888.cs b/sources/SDL2Sharp/video/pixels/XRGB8888.cs new file mode 100644 index 00000000..b4829368 --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/XRGB8888.cs @@ -0,0 +1,63 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)] + public readonly record struct XRGB8888 : IPackedPixel + { + private static readonly PixelFormatDescriptor _formatDescriptor = new(PixelFormat.XRGB8888); + + private readonly uint _value; + + public static PixelFormat Format => _formatDescriptor.Format; + + public static XRGB8888 FromRGB(byte r, byte g, byte b) + { + return new XRGB8888(_formatDescriptor.MapRGB(r, g, b)); + } + + public static XRGB8888 FromRGBA(byte r, byte g, byte b, byte a) + { + return new XRGB8888(_formatDescriptor.MapRGBA(r, g, b, a)); + } + + public XRGB8888(byte r, byte g, byte b) + : this(_formatDescriptor.MapRGB(r, g, b)) + { } + + private XRGB8888(uint value) + { + _value = value; + } + + public (byte r, byte g, byte b) ToRGB() + { + return _formatDescriptor.GetRGB(_value); + } + + public (byte r, byte g, byte b, byte a) ToRGBA() + { + return _formatDescriptor.GetRGBA(_value); + } + } +} diff --git a/sources/SDL2Sharp/video/pixels/Y8.cs b/sources/SDL2Sharp/video/pixels/Y8.cs new file mode 100644 index 00000000..089cc3cf --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/Y8.cs @@ -0,0 +1,35 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.InteropServices; + +namespace SDL2Sharp +{ + [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 1)] + public readonly record struct Y8 + { + private readonly byte _value; + + public Y8(byte value) + { + _value = value; + } + } +} diff --git a/sources/SDL2Sharp/Colors/Bgrx8888.cs b/sources/SDL2Sharp/video/pixels/YUY2.cs similarity index 70% rename from sources/SDL2Sharp/Colors/Bgrx8888.cs rename to sources/SDL2Sharp/video/pixels/YUY2.cs index 3f186e04..562f6e38 100644 --- a/sources/SDL2Sharp/Colors/Bgrx8888.cs +++ b/sources/SDL2Sharp/video/pixels/YUY2.cs @@ -19,27 +19,27 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Runtime.InteropServices; -using SDL2Sharp.Internals; -namespace SDL2Sharp.Colors +namespace SDL2Sharp { - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 4)] - [PackedColor(PixelFormatEnum.BGRX8888)] - public readonly record struct Bgrx8888 + [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)] + public readonly record struct YUY2 { private readonly uint _value; - public byte B => (byte)(_value >> 24 & 0xFF); + public byte Y0 => (byte)(_value & 0xFF); - public byte G => (byte)(_value >> 16 & 0xFF); + public byte U0 => (byte)(_value >> 8 & 0xFF); - public byte R => (byte)(_value >> 8 & 0xFF); + public byte Y1 => (byte)(_value >> 16 & 0xFF); - public Bgrx8888(byte b, byte g, byte r) + public byte V0 => (byte)(_value >> 24 & 0xFF); + + public YUY2(byte y0, byte u0, byte y1, byte v0) { unchecked { - _value = (uint)(b << 24 | g << 16 | r << 8); + _value = (uint)(y0 | u0 << 8 | y1 << 16 | v0 << 24); } } } diff --git a/sources/SDL2Sharp/video/pixels/YV12.cs b/sources/SDL2Sharp/video/pixels/YV12.cs new file mode 100644 index 00000000..8e62dc8a --- /dev/null +++ b/sources/SDL2Sharp/video/pixels/YV12.cs @@ -0,0 +1,54 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System.Runtime.CompilerServices; + +namespace SDL2Sharp +{ + public readonly struct YV12 : IYUVFormat + { + public static PixelFormat PixelFormat => PixelFormat.YV12; + + public static unsafe ImagePlane CreateYPlane(void* pixels, int imageWidth, int imageHeight, int imagePitch) + { + return new ImagePlane(pixels, imageWidth, imageHeight, imagePitch); + } + + public static unsafe ImagePlane CreateUPlane(void* pixels, int imageWidth, int imageHeight, int imagePitch) + { + var uPlaneWidth = imageWidth / 2; + var uPlaneHeight = imageHeight / 2; + var uPlanePitch = imagePitch / 2; + var uPlaneOffset = imageHeight * imagePitch + imageHeight * imagePitch / 4; + var uPlanePixels = Unsafe.Add(pixels, uPlaneOffset); + return new ImagePlane(uPlanePixels, uPlaneWidth, uPlaneHeight, uPlanePitch); + } + + public static unsafe ImagePlane CreateVPlane(void* pixels, int imageWidth, int imageHeight, int imagePitch) + { + var vPlaneWidth = imageWidth / 2; + var vPlaneHeight = imageHeight / 2; + var vPlanePitch = imagePitch / 2; + var vPlaneOffset = imageHeight * imagePitch; + var vPlanePixels = Unsafe.Add(pixels, vPlaneOffset); + return new ImagePlane(vPlanePixels, vPlaneWidth, vPlaneHeight, vPlanePitch); + } + } +} diff --git a/sources/SDL2Sharp/Colors/Bgra8888.cs b/sources/SDL2Sharp/video/pixels/YVYU.cs similarity index 67% rename from sources/SDL2Sharp/Colors/Bgra8888.cs rename to sources/SDL2Sharp/video/pixels/YVYU.cs index 0b412200..3324a228 100644 --- a/sources/SDL2Sharp/Colors/Bgra8888.cs +++ b/sources/SDL2Sharp/video/pixels/YVYU.cs @@ -19,29 +19,27 @@ // 3. This notice may not be removed or altered from any source distribution. using System.Runtime.InteropServices; -using SDL2Sharp.Internals; -namespace SDL2Sharp.Colors +namespace SDL2Sharp { - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 4)] - [PackedColor(PixelFormatEnum.BGRA8888)] - public readonly record struct Bgra8888 + [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)] + public readonly record struct YVYU { private readonly uint _value; - public byte B => (byte)(_value >> 24 & 0xFF); + public byte Y0 => (byte)(_value & 0xFF); - public byte G => (byte)(_value >> 16 & 0xFF); + public byte V0 => (byte)(_value >> 8 & 0xFF); - public byte R => (byte)(_value >> 8 & 0xFF); + public byte Y1 => (byte)(_value >> 16 & 0xFF); - public byte A => (byte)(_value & 0xFF); + public byte U0 => (byte)(_value >> 24 & 0xFF); - public Bgra8888(byte b, byte g, byte r, byte a) + public YVYU(byte y0, byte v0, byte y1, byte u0) { unchecked { - _value = (uint)(b << 24 | g << 16 | r << 8 | a); + _value = (uint)(y0 | v0 << 8 | y1 << 16 | u0 << 24); } } } diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index a5a00a99..8ef07da0 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -24,13 +24,14 @@ - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/SDL2Sharp.Interop.Tests/.editorconfig b/tests/SDL2Sharp.Interop.Tests/.editorconfig new file mode 100644 index 00000000..e1713a8e --- /dev/null +++ b/tests/SDL2Sharp.Interop.Tests/.editorconfig @@ -0,0 +1,8 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = false + +# Treat code files as generated code +[*.cs] +generated_code = true \ No newline at end of file diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL2Sharp.Interop.UnitTests.csproj b/tests/SDL2Sharp.Interop.Tests/SDL2Sharp.Interop.Tests.csproj similarity index 64% rename from tests/SDL2Sharp.Interop.UnitTests/SDL2Sharp.Interop.UnitTests.csproj rename to tests/SDL2Sharp.Interop.Tests/SDL2Sharp.Interop.Tests.csproj index 4648d9fc..b5d00b6d 100644 --- a/tests/SDL2Sharp.Interop.UnitTests/SDL2Sharp.Interop.UnitTests.csproj +++ b/tests/SDL2Sharp.Interop.Tests/SDL2Sharp.Interop.Tests.csproj @@ -1,14 +1,18 @@  - net8.0;net7.0;net6.0;net462;net47;net471;net472;net48;net481 + net8.0 false AnyCPU false - + + + + + diff --git a/tests/SDL2Sharp.Interop.UnitTests/ID3D11DeviceTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/ID3D11DeviceTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/ID3D11DeviceTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/ID3D11DeviceTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/ID3D12DeviceTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/ID3D12DeviceTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/ID3D12DeviceTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/ID3D12DeviceTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/IDirect3DDevice9Tests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/IDirect3DDevice9Tests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/IDirect3DDevice9Tests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/IDirect3DDevice9Tests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/IMG_AnimationTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/IMG_AnimationTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/IMG_AnimationTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/IMG_AnimationTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_AudioCVTTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_AudioCVTTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_AudioCVTTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_AudioCVTTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_AudioDeviceEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_AudioDeviceEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_AudioDeviceEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_AudioDeviceEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_AudioSpecTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_AudioSpecTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_AudioSpecTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_AudioSpecTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_BlitMapTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_BlitMapTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_BlitMapTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_BlitMapTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_ColorTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_ColorTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_ColorTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_ColorTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_CommonEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_CommonEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_CommonEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_CommonEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_ControllerAxisEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_ControllerAxisEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_ControllerAxisEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_ControllerAxisEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_ControllerButtonEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_ControllerButtonEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_ControllerButtonEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_ControllerButtonEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_ControllerDeviceEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_ControllerDeviceEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_ControllerDeviceEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_ControllerDeviceEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_ControllerSensorEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_ControllerSensorEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_ControllerSensorEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_ControllerSensorEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_ControllerTouchpadEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_ControllerTouchpadEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_ControllerTouchpadEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_ControllerTouchpadEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_CursorTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_CursorTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_CursorTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_CursorTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_DisplayEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_DisplayEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_DisplayEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_DisplayEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_DisplayModeTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_DisplayModeTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_DisplayModeTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_DisplayModeTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_DollarGestureEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_DollarGestureEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_DollarGestureEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_DollarGestureEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_DropEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_DropEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_DropEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_DropEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_EventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_EventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_EventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_EventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_FPointTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_FPointTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_FPointTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_FPointTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_FRectTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_FRectTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_FRectTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_FRectTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_GUIDTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_GUIDTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_GUIDTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_GUIDTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_JoyAxisEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_JoyAxisEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_JoyAxisEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_JoyAxisEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_JoyBallEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_JoyBallEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_JoyBallEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_JoyBallEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_JoyBatteryEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_JoyBatteryEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_JoyBatteryEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_JoyBatteryEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_JoyButtonEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_JoyButtonEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_JoyButtonEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_JoyButtonEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_JoyDeviceEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_JoyDeviceEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_JoyDeviceEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_JoyDeviceEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_JoyHatEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_JoyHatEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_JoyHatEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_JoyHatEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_KeyboardEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_KeyboardEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_KeyboardEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_KeyboardEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_KeysymTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_KeysymTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_KeysymTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_KeysymTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_MouseButtonEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_MouseButtonEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_MouseButtonEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_MouseButtonEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_MouseMotionEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_MouseMotionEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_MouseMotionEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_MouseMotionEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_MouseWheelEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_MouseWheelEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_MouseWheelEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_MouseWheelEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_MultiGestureEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_MultiGestureEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_MultiGestureEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_MultiGestureEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_OSEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_OSEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_OSEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_OSEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_PaletteTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_PaletteTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_PaletteTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_PaletteTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_PixelFormatTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_PixelFormatTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_PixelFormatTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_PixelFormatTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_PointTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_PointTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_PointTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_PointTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_QuitEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_QuitEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_QuitEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_QuitEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_RWopsTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_RWopsTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_RWopsTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_RWopsTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_RectTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_RectTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_RectTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_RectTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_RendererInfoTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_RendererInfoTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_RendererInfoTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_RendererInfoTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_RendererTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_RendererTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_RendererTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_RendererTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_SensorEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_SensorEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_SensorEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_SensorEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_SurfaceTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_SurfaceTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_SurfaceTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_SurfaceTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_SysWMEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_SysWMEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_SysWMEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_SysWMEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_SysWMmsgTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_SysWMmsgTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_SysWMmsgTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_SysWMmsgTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_TextEditingEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_TextEditingEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_TextEditingEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_TextEditingEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_TextEditingExtEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_TextEditingExtEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_TextEditingExtEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_TextEditingExtEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_TextInputEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_TextInputEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_TextInputEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_TextInputEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_TextureTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_TextureTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_TextureTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_TextureTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_TouchFingerEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_TouchFingerEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_TouchFingerEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_TouchFingerEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_UserEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_UserEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_UserEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_UserEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_VertexTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_VertexTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_VertexTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_VertexTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_VirtualJoystickDescTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_VirtualJoystickDescTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_VirtualJoystickDescTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_VirtualJoystickDescTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_WindowEventTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_WindowEventTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_WindowEventTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_WindowEventTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_WindowTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_WindowTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_WindowTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_WindowTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/SDL_versionTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/SDL_versionTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/SDL_versionTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/SDL_versionTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/_SDL_AudioStreamTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/_SDL_AudioStreamTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/_SDL_AudioStreamTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/_SDL_AudioStreamTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/_SDL_JoystickTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/_SDL_JoystickTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/_SDL_JoystickTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/_SDL_JoystickTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/_SDL_iconv_tTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/_SDL_iconv_tTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/_SDL_iconv_tTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/_SDL_iconv_tTests.cs diff --git a/tests/SDL2Sharp.Interop.UnitTests/_TTF_FontTests.cs b/tests/SDL2Sharp.Interop.Tests/codegen/_TTF_FontTests.cs similarity index 100% rename from tests/SDL2Sharp.Interop.UnitTests/_TTF_FontTests.cs rename to tests/SDL2Sharp.Interop.Tests/codegen/_TTF_FontTests.cs diff --git a/tests/SDL2Sharp.Interop.Tests/xunit.runner.json b/tests/SDL2Sharp.Interop.Tests/xunit.runner.json new file mode 100644 index 00000000..be78ad92 --- /dev/null +++ b/tests/SDL2Sharp.Interop.Tests/xunit.runner.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "shadowCopy": false, + "parallelizeAssembly": false, + "parallelizeTestCollections": false +} diff --git a/tests/SDL2Sharp.Interop.UnitTests/App.config b/tests/SDL2Sharp.Interop.UnitTests/App.config deleted file mode 100644 index 7c16b080..00000000 --- a/tests/SDL2Sharp.Interop.UnitTests/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/tests/SDL2Sharp.UnitTests/SDL2Sharp.UnitTests.csproj b/tests/SDL2Sharp.Tests/SDL2Sharp.Tests.csproj similarity index 71% rename from tests/SDL2Sharp.UnitTests/SDL2Sharp.UnitTests.csproj rename to tests/SDL2Sharp.Tests/SDL2Sharp.Tests.csproj index cb6ae263..7378daf7 100644 --- a/tests/SDL2Sharp.UnitTests/SDL2Sharp.UnitTests.csproj +++ b/tests/SDL2Sharp.Tests/SDL2Sharp.Tests.csproj @@ -1,14 +1,14 @@  - net8.0;net7.0;net6.0;net462;net47;net471;net472;net48;net481 + net8.0 false AnyCPU false - + diff --git a/tests/SDL2Sharp.Tests/audio/AudioCollectionDefinition.cs b/tests/SDL2Sharp.Tests/audio/AudioCollectionDefinition.cs new file mode 100644 index 00000000..ae65f3b7 --- /dev/null +++ b/tests/SDL2Sharp.Tests/audio/AudioCollectionDefinition.cs @@ -0,0 +1,27 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using Xunit; + +namespace SDL2Sharp.Tests +{ + [CollectionDefinition("Audio", DisableParallelization = true)] + public sealed class AudioCollectionDefinition { } +} diff --git a/tests/SDL2Sharp.UnitTests/AudioFormatExtensionTests.cs b/tests/SDL2Sharp.Tests/audio/AudioFormatExtensionTests.cs similarity index 97% rename from tests/SDL2Sharp.UnitTests/AudioFormatExtensionTests.cs rename to tests/SDL2Sharp.Tests/audio/AudioFormatExtensionTests.cs index 33e9b558..b8f7fcf5 100644 --- a/tests/SDL2Sharp.UnitTests/AudioFormatExtensionTests.cs +++ b/tests/SDL2Sharp.Tests/audio/AudioFormatExtensionTests.cs @@ -18,11 +18,11 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using SDL2Sharp.Extensions; using Xunit; -namespace SDL2Sharp.UnitTests +namespace SDL2Sharp.Tests { + [Collection("Audio")] public static class AudioFormatExtensionTests { [Fact] diff --git a/tests/SDL2Sharp.Tests/video/PackedTextureTests.cs b/tests/SDL2Sharp.Tests/video/PackedTextureTests.cs new file mode 100644 index 00000000..81b3b9c6 --- /dev/null +++ b/tests/SDL2Sharp.Tests/video/PackedTextureTests.cs @@ -0,0 +1,254 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using Xunit; + +namespace SDL2Sharp.Tests +{ + [Collection("Video")] + public sealed class PackedTextureTests(SDL sdl) : IAssemblyFixture + { + private readonly SDL _sdl = sdl ?? throw new ArgumentNullException(nameof(sdl)); + + private readonly Random _random = new(); + + private SDL SDL => _sdl; + + [Fact] + public void WriteAndReadAbgr1555() => WriteAndRead + ( + () => ABGR1555.FromRGBA( + r: (byte)_random.Next(0, 256), + g: (byte)_random.Next(0, 256), + b: (byte)_random.Next(0, 256), + a: (byte)_random.Next(0, 256) + ) + ); + + [Fact] + public void WriteAndReadAbgr4444() => WriteAndRead + ( + () => ABGR4444.FromRGBA( + r: (byte)_random.Next(0, 256), + g: (byte)_random.Next(0, 256), + b: (byte)_random.Next(0, 256), + a: (byte)_random.Next(0, 256) + ) + ); + + [Fact] + public void WriteAndReadAbgr8888() => WriteAndRead + ( + () => ABGR8888.FromRGBA( + r: (byte)_random.Next(0, 256), + g: (byte)_random.Next(0, 256), + b: (byte)_random.Next(0, 256), + a: (byte)_random.Next(0, 256) + ) + ); + + [Fact] + public void WriteAndReadArgb1555() => WriteAndRead + ( + () => ARGB1555.FromRGBA( + r: (byte)_random.Next(0, 256), + g: (byte)_random.Next(0, 256), + b: (byte)_random.Next(0, 256), + a: (byte)_random.Next(0, 256) + ) + ); + + [Fact] + public void WriteAndReadArgb2101010() => WriteAndRead + ( + () => ARGB2101010.FromRGBA( + r: (byte)_random.Next(0, 256), + g: (byte)_random.Next(0, 256), + b: (byte)_random.Next(0, 256), + a: (byte)_random.Next(0, 256) + ) + ); + + [Fact] + public void WriteAndReadArgb4444() => WriteAndRead + ( + () => ARGB4444.FromRGBA( + r: (byte)_random.Next(0, 256), + g: (byte)_random.Next(0, 256), + b: (byte)_random.Next(0, 256), + a: (byte)_random.Next(0, 256) + ) + ); + + [Fact] + public void WriteAndReadArgb8888() => WriteAndRead( + () => ARGB8888.FromRGBA( + r: (byte)_random.Next(0, 256), + g: (byte)_random.Next(0, 256), + b: (byte)_random.Next(0, 256), + a: (byte)_random.Next(0, 256) + ) + ); + + [Fact] + public void WriteAndReadRgba8888() => WriteAndRead( + () => new RGBA8888( + a: (byte)_random.Next(0, 256), + r: (byte)_random.Next(0, 256), + g: (byte)_random.Next(0, 256), + b: (byte)_random.Next(0, 256) + ) + ); + + [Fact] + public void WriteAndReadBgr565() => WriteAndRead( + () => BGR565.FromRGB( + r: (byte)_random.Next(0, 256), + g: (byte)_random.Next(0, 256), + b: (byte)_random.Next(0, 256) + ) + ); + + [Fact] + public void WriteAndReadBgra4444() => WriteAndRead( + () => BGRA4444.FromRGBA( + r: (byte)_random.Next(0, 256), + g: (byte)_random.Next(0, 256), + b: (byte)_random.Next(0, 256), + a: (byte)_random.Next(0, 256) + ) + ); + + [Fact] + public void WriteAndReadBgra5551() => WriteAndRead( + () => BGRA4444.FromRGBA( + r: (byte)_random.Next(0, 256), + g: (byte)_random.Next(0, 256), + b: (byte)_random.Next(0, 256), + a: (byte)_random.Next(0, 256) + ) + ); + + [Fact] + public void WriteAndReadBgra8888() => WriteAndRead( + () => new BGRA8888( + b: (byte)_random.Next(0, 256), + g: (byte)_random.Next(0, 256), + r: (byte)_random.Next(0, 256), + a: (byte)_random.Next(0, 256) + ) + ); + + //[Fact] + //public void WriteAndReadRgb332() => WriteAndRead( + // () => Rgb332.FromRGB( + // r: (byte)_random.Next(0, 256), + // g: (byte)_random.Next(0, 256), + // b: (byte)_random.Next(0, 256) + // ) + //); + + [Fact] + public void WriteAndReadRgb565() => WriteAndRead( + () => RGB565.FromRGB( + r: (byte)_random.Next(0, 256), + g: (byte)_random.Next(0, 256), + b: (byte)_random.Next(0, 256) + ) + ); + + private void WriteAndRead(Func colorGenerator) + where TPackedPixelFormat : struct, IPackedPixel + { + using var window = SDL.Video.CreateWindow("PackedTextureTests", 640, 480, WindowFlags.Hidden); + using var renderer = window.CreateRenderer(RendererFlags.Software | RendererFlags.TargetTexture); + using var sourceTexture = renderer.CreatePackedTexture(TextureAccess.Streaming, renderer.OutputSize); + using var targetTexture = renderer.CreatePackedTexture(TextureAccess.Target, renderer.OutputSize); + var sourceImage = GenerateImage(renderer.OutputSize, colorGenerator); + + sourceTexture.Update(sourceImage); + + //sourceTexture.WithLock(pixels => + //{ + // for (var y = 0; y < pixels.Height; y++) + // { + // for (var x = 0; x < pixels.Width; x++) + // { + // pixels[x, y] = sourceImage[x, y]; + // } + // } + //}); + + renderer.Target = targetTexture; + renderer.Copy(sourceTexture); + renderer.Present(); + + var targetImage = renderer.ReadPixels(); + + Assert.Equal(sourceImage.Size, targetImage.Size); + Assert.Equal(sourceImage.Height, targetImage.Height); + Assert.Equal(sourceImage.Width, targetImage.Width); + Assert.Equal(sourceImage, targetImage, (expectedImage, actualImage) => + { + if (expectedImage is null && actualImage is null) + { + return true; + } + + if (expectedImage is null || actualImage is null) + { + return false; + } + + if (expectedImage.Size != actualImage.Size) + { + return false; + } + + for (var y = 0; y < expectedImage.Height; y++) + { + for (var x = 0; x < expectedImage.Width; x++) + { + if (!expectedImage[x, y].Equals(actualImage[x, y])) + { + return false; + } + } + } + + return true; + }); + } + + private static PackedMemoryImage GenerateImage(Size size, Func createRandomColor) where TColor : struct + { + var image = new PackedMemoryImage(size.Width, size.Height); + for (var y = 0; y < image.Height; y++) + { + for (var x = 0; x < image.Width; x++) + { + image[x, y] = createRandomColor(); + } + } + return image; + } + } +} diff --git a/tests/SDL2Sharp.UnitTests/PackedTextureTests.cs b/tests/SDL2Sharp.Tests/video/PlanarTextureTests.cs similarity index 54% rename from tests/SDL2Sharp.UnitTests/PackedTextureTests.cs rename to tests/SDL2Sharp.Tests/video/PlanarTextureTests.cs index e2878fab..52fea55f 100644 --- a/tests/SDL2Sharp.UnitTests/PackedTextureTests.cs +++ b/tests/SDL2Sharp.Tests/video/PlanarTextureTests.cs @@ -18,29 +18,39 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -using SDL2Sharp.Colors; +using System; using Xunit; -namespace SDL2Sharp.UnitTests +namespace SDL2Sharp.Tests { - public static class PackedTextureTests + [Collection("Video")] + public sealed class PlanarTextureTests(SDL sdl) : IAssemblyFixture { + private readonly SDL _sdl = sdl ?? throw new ArgumentNullException(nameof(sdl)); + + private SDL SDL => _sdl; + + [Fact] + public void WriteAndReadYV12() => WriteAndRead(); + [Fact] - public static void CreatePackedTextureOfArgb8888() + public void WriteAndReadIYUV() => WriteAndRead(); + + private void WriteAndRead() + where TYUVFormat : struct, IYUVFormat { - using var window = new Window("TextureTests", 640, 480, WindowFlags.Hidden); + using var window = SDL.Video.CreateWindow("PlanarTextureTests", 640, 480, WindowFlags.Hidden); using var renderer = window.CreateRenderer(); - using var texture = renderer.CreateTexture(TextureAccess.Streaming, renderer.OutputSize); - var white = new Argb8888(255, 255, 255, 255); - texture.WithLock(image => + using var texture = renderer.CreateYUVTexture(TextureAccess.Streaming, renderer.OutputSize); + + var y = new Y8(255); + var u = new U8(128); + var v = new V8(128); + texture.WithLock(pixels => { - for (var y = 0; y < image.Height; ++y) - { - for (var x = 0; x < image.Width; ++x) - { - image[y, x] = white; - } - } + pixels.Y.Fill(y); + pixels.U.Fill(u); + pixels.V.Fill(v); }); renderer.Copy(texture); renderer.Present(); diff --git a/sources/SDL2Sharp.Extensions/MathExtensions.cs b/tests/SDL2Sharp.Tests/video/SurfaceTests.cs similarity index 62% rename from sources/SDL2Sharp.Extensions/MathExtensions.cs rename to tests/SDL2Sharp.Tests/video/SurfaceTests.cs index 26738af1..d208cdef 100644 --- a/sources/SDL2Sharp.Extensions/MathExtensions.cs +++ b/tests/SDL2Sharp.Tests/video/SurfaceTests.cs @@ -18,30 +18,27 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. -namespace SDL2Sharp.Extensions +using Xunit; + +namespace SDL2Sharp.Tests { - public static class MathExtensions + [Collection("Video")] + public sealed class SurfaceTests { - public static int Mod(int a, int b) + [Fact] + public void CreateSurface() { - var result = a % b; - if (result < 0) - { - result += b; - } - return result; + var color = new ARGB8888(255, 255, 255, 255); + using var surface = new Surface(512, 512, PixelFormat.ARGB8888); + surface.WithLock(pixels => pixels.Fill(color)); } - public static int NextPowerOfTwo(int value) + [Fact] + public void CreateSurfaceOfArgb8888() { - --value; - value |= value >> 1; - value |= value >> 2; - value |= value >> 4; - value |= value >> 8; - value |= value >> 16; - ++value; - return value; + var color = new ARGB8888(255, 255, 255, 255); + using var surface = new Surface(512, 512); + surface.WithLock(pixels => pixels.Fill(color)); } } } diff --git a/tests/SDL2Sharp.Tests/video/TextureTests.cs b/tests/SDL2Sharp.Tests/video/TextureTests.cs new file mode 100644 index 00000000..e8d0882e --- /dev/null +++ b/tests/SDL2Sharp.Tests/video/TextureTests.cs @@ -0,0 +1,134 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using System; +using Xunit; + +namespace SDL2Sharp.Tests +{ + [Collection("Video")] + public sealed class TextureTests(SDL sdl) : IAssemblyFixture + { + private readonly SDL _sdl = sdl ?? throw new ArgumentNullException(nameof(sdl)); + + private SDL SDL => _sdl; + + [Fact] + public void CreateTextureOfArgb8888() + { + WithRenderer(renderer => + { + using var texture = renderer.CreateTexture(PixelFormat.ARGB8888, TextureAccess.Streaming, renderer.OutputSize); + using var packedTexture = texture.AsPacked(); + var color = new ARGB8888(255, 255, 255, 255); + packedTexture.WithLock(pixels => pixels.Fill(color)); + renderer.Copy(texture); + renderer.Present(); + }); + } + + [Fact] + public void CreateTextureOfIYUV() + { + WithRenderer(renderer => + { + using var texture = renderer.CreateTexture(PixelFormat.IYUV, TextureAccess.Streaming, renderer.OutputSize); + using var planarTexture = texture.AsYUV(); + var y = new Y8(255); + var u = new U8(128); + var v = new V8(128); + planarTexture.WithLock(pixels => + { + pixels.Y.Fill(y); + pixels.U.Fill(u); + pixels.V.Fill(v); + }); + renderer.Copy(texture); + renderer.Present(); + }); + } + + [Fact] + public void CreateTextureOfNV12() + { + WithRenderer(renderer => + { + using var texture = renderer.CreateTexture(PixelFormat.NV12, TextureAccess.Streaming, renderer.OutputSize); + using var planarTexture = texture.AsNV12(); + var y = new Y8(255); + var uv = new UV88(128, 128); + planarTexture.WithLock(pixels => + { + pixels.Y.Fill(y); + pixels.UV.Fill(uv); + }); + renderer.Copy(texture); + renderer.Present(); + }); + } + + [Fact] + public void CreateTextureOfNV21() + { + WithRenderer(renderer => + { + using var texture = renderer.CreateTexture(PixelFormat.NV21, TextureAccess.Streaming, renderer.OutputSize); + using var planarTexture = texture.AsNV21(); + var y = new Y8(255); + var vu = new VU88(128, 128); + planarTexture.WithLock(pixels => + { + pixels.Y.Fill(y); + pixels.UV.Fill(vu); + }); + renderer.Copy(texture); + renderer.Present(); + }); + } + + [Fact] + public void CreateTextureOfYV12() + { + WithRenderer(renderer => + { + using var texture = renderer.CreateTexture(PixelFormat.YV12, TextureAccess.Streaming, renderer.OutputSize); + using var planarTexture = texture.AsYUV(); + var y = new Y8(255); + var u = new U8(128); + var v = new V8(128); + planarTexture.WithLock(pixels => + { + pixels.Y.Fill(y); + pixels.V.Fill(v); + pixels.U.Fill(u); + }); + renderer.Copy(texture); + renderer.Present(); + }); + } + + private void WithRenderer(Action test) + { + using var window = SDL.Video.CreateWindow("TextureTests", 640, 480, WindowFlags.Hidden); + using var renderer = window.CreateRenderer(); + test(renderer); + } + } +} diff --git a/tests/SDL2Sharp.Tests/video/VideoCollectionDefinition.cs b/tests/SDL2Sharp.Tests/video/VideoCollectionDefinition.cs new file mode 100644 index 00000000..1f9cdb62 --- /dev/null +++ b/tests/SDL2Sharp.Tests/video/VideoCollectionDefinition.cs @@ -0,0 +1,27 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using Xunit; + +namespace SDL2Sharp.Tests +{ + [CollectionDefinition("Video", DisableParallelization = true)] + public sealed class VideoCollectionDefinition { } +} diff --git a/tests/SDL2Sharp.Tests/video/pixels/Argb2101010Tests.cs b/tests/SDL2Sharp.Tests/video/pixels/Argb2101010Tests.cs new file mode 100644 index 00000000..246bb154 --- /dev/null +++ b/tests/SDL2Sharp.Tests/video/pixels/Argb2101010Tests.cs @@ -0,0 +1,46 @@ +// SDL2Sharp +// +// Copyright (C) 2021-2024 Ronald van Manen +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source distribution. + +using Xunit; + +namespace SDL2Sharp.Tests +{ + public static class Argb2101010Tests + { + [Fact] + public static void SelfEquality() + { +#pragma warning disable CS1718 // Comparison made to same variable + var color = ARGB2101010.FromRGBA(r: 63, g: 127, b: 191, a: 255); + Assert.True(color == color); + Assert.False(color != color); +#pragma warning restore CS1718 // Comparison made to same variable + } + + [Fact] + public static void Equality() + { + var a = ARGB2101010.FromRGBA(r: 63, g: 127, b: 191, a: 255); + var b = ARGB2101010.FromRGBA(r: 63, g: 127, b: 191, a: 255); + Assert.True(a == b); + Assert.False(a != b); + } + } +} diff --git a/tests/SDL2Sharp.Tests/xunit.runner.json b/tests/SDL2Sharp.Tests/xunit.runner.json new file mode 100644 index 00000000..be78ad92 --- /dev/null +++ b/tests/SDL2Sharp.Tests/xunit.runner.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "shadowCopy": false, + "parallelizeAssembly": false, + "parallelizeTestCollections": false +} diff --git a/tests/SDL2Sharp.UnitTests/App.config b/tests/SDL2Sharp.UnitTests/App.config deleted file mode 100644 index 7c16b080..00000000 --- a/tests/SDL2Sharp.UnitTests/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file