├── .github └── FUNDING.yml ├── .gitignore ├── .gitlab-ci.yml ├── LICENSE ├── Makefile ├── README ├── SDL2-CS.Core.csproj ├── SDL2-CS.csproj ├── SDL2-CS.sln ├── app.config ├── gitlab-ci ├── SDL2-CS.nuspec ├── build-net461.sh ├── build-netcore.sh ├── deploy.sh └── package.sh └── src ├── SDL2.cs ├── SDL2_gfx.cs ├── SDL2_image.cs ├── SDL2_mixer.cs └── SDL2_ttf.cs /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [flibitijibibo] 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | obj/ 3 | *.pidb 4 | *.userprefs 5 | *.suo 6 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | stages: 2 | - build 3 | - package 4 | - deploy 5 | 6 | build_net461: 7 | image: mono 8 | stage: build 9 | only: 10 | - schedules 11 | script: 12 | - ./gitlab-ci/build-net461.sh 13 | artifacts: 14 | paths: 15 | - bin/ 16 | tags: 17 | - docker 18 | 19 | build_netcore: 20 | image: microsoft/dotnet:2.1-sdk 21 | stage: build 22 | only: 23 | - schedules 24 | script: 25 | - ./gitlab-ci/build-netcore.sh 26 | artifacts: 27 | paths: 28 | - bin/ 29 | tags: 30 | - docker 31 | 32 | package_nuget: 33 | image: mono 34 | stage: package 35 | only: 36 | - schedules 37 | script: 38 | - ./gitlab-ci/package.sh 39 | dependencies: 40 | - build_net461 41 | - build_netcore 42 | artifacts: 43 | paths: 44 | - '*.nupkg' 45 | 46 | deploy_nuget: 47 | image: mono 48 | stage: deploy 49 | only: 50 | - schedules 51 | script: 52 | - ./gitlab-ci/deploy.sh 53 | dependencies: 54 | - package_nuget 55 | environment: 56 | name: nuget 57 | url: http://nuget.org/ 58 | 59 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | /* SDL2# - C# Wrapper for SDL2 2 | * 3 | * Copyright (c) 2013-2024 Ethan Lee. 4 | * 5 | * This software is provided 'as-is', without any express or implied warranty. 6 | * In no event will the authors be held liable for any damages arising from 7 | * the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any purpose, 10 | * including commercial applications, and to alter it and redistribute it 11 | * freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software in a 15 | * product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and must not be 19 | * misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source distribution. 22 | * 23 | * Ethan "flibitijibibo" Lee 24 | * 25 | */ 26 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for SDL2# 2 | # Written by Ethan "flibitijibibo" Lee 3 | 4 | # Source Lists 5 | SRC = \ 6 | src/SDL2.cs \ 7 | src/SDL2_gfx.cs \ 8 | src/SDL2_image.cs \ 9 | src/SDL2_mixer.cs \ 10 | src/SDL2_ttf.cs 11 | 12 | # Targets 13 | 14 | debug: clean-debug 15 | mkdir -p bin/Debug 16 | cp app.config bin/Debug/SDL2-CS.dll.config 17 | mcs /unsafe -debug -out:bin/Debug/SDL2-CS.dll -target:library $(SRC) 18 | 19 | clean-debug: 20 | rm -rf bin/Debug 21 | 22 | release: clean-release 23 | mkdir -p bin/Release 24 | cp app.config bin/Release/SDL2-CS.dll.config 25 | mcs /unsafe -optimize -out:bin/Release/SDL2-CS.dll -target:library $(SRC) 26 | 27 | clean-release: 28 | rm -rf bin/Release 29 | 30 | clean: clean-debug clean-release 31 | rm -rf bin 32 | 33 | all: debug release 34 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This is SDL2#, a C# wrapper for SDL2. 2 | 3 | Project Website: https://github.com/flibitijibibo/SDL2-CS 4 | 5 | License 6 | ------- 7 | SDL2 and SDL2# are released under the zlib license. See LICENSE for details. 8 | 9 | About SDL2 10 | ---------- 11 | For more information about SDL2, visit the SDL wiki: 12 | 13 | http://wiki.libsdl.org/moin.fcg/FrontPage 14 | 15 | About the C# Wrapper 16 | -------------------- 17 | The C# wrapper was written to be used for FNA's platform support. However, this 18 | is written in a way that can be used for any general C# application. 19 | 20 | The wrapper provides bindings for the following libraries: 21 | - SDL2 22 | - SDL2_gfx 23 | - SDL2_image 24 | - SDL2_mixer 25 | - SDL2_ttf 26 | 27 | Note that SDL2# will not provide every single SDL2 function. This is due to 28 | limitations in the C# language that would cause major conflicts with the native 29 | SDL2 library and its extensions. 30 | 31 | SDL2# is a pure port of the C headers. The naming schemes for this library will 32 | be exactly as they are done in the C library, with little-to-no concern for 33 | "appropriate" C# style. The namespace indicates that this is SDL2, the class 34 | names will indicate which library file the function/type/value exists in, and 35 | everything else will be as close to the C version as technically possible. 36 | 37 | About the Visual Studio Debugger 38 | -------------------------------- 39 | When running C# applications under the Visual Studio debugger, native code that 40 | names threads with the 0x406D1388 exception will silently exit. To prevent this 41 | exception from being thrown by SDL, add this line before your SDL_Init call: 42 | 43 | SDL.SDL_SetHint(SDL.SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1"); 44 | -------------------------------------------------------------------------------- /SDL2-CS.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net40;netstandard2.0;net8.0 4 | x64 5 | 6 | 7 | false 8 | SDL2-CS 9 | SDL2 10 | true 11 | false 12 | 13 | 14 | true 15 | true 16 | 17 | 18 | $(SolutionDir)SDL2-CS.Settings.props 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /SDL2-CS.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | 9.0.21022 7 | 2.0 8 | {85480198-8711-4355-830E-72FD794AD3F6} 9 | Library 10 | SDL2 11 | SDL2-CS 12 | 13 | 14 | true 15 | full 16 | false 17 | bin\Debug 18 | DEBUG; 19 | prompt 20 | 4 21 | x86 22 | false 23 | true 24 | 25 | 26 | none 27 | true 28 | bin\Release 29 | prompt 30 | 4 31 | x86 32 | false 33 | true 34 | 35 | 36 | true 37 | full 38 | false 39 | bin\Debug 40 | DEBUG; 41 | prompt 42 | 4 43 | false 44 | true 45 | 46 | 47 | none 48 | true 49 | bin\Release 50 | prompt 51 | 4 52 | true 53 | false 54 | 55 | 56 | true 57 | full 58 | false 59 | bin\Debug 60 | DEBUG; 61 | prompt 62 | 4 63 | x64 64 | true 65 | false 66 | 67 | 68 | none 69 | true 70 | bin\Release 71 | prompt 72 | 4 73 | x64 74 | false 75 | true 76 | 77 | 78 | 79 | $(SolutionDir)SDL2-CS.Settings.props 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | $(TargetFileName).config 96 | PreserveNewest 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /SDL2-CS.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDL2-CS", "SDL2-CS.csproj", "{85480198-8711-4355-830E-72FD794AD3F6}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|x86 = Debug|x86 9 | Release|x86 = Release|x86 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | Debug|x64 = Debug|x64 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {85480198-8711-4355-830E-72FD794AD3F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {85480198-8711-4355-830E-72FD794AD3F6}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {85480198-8711-4355-830E-72FD794AD3F6}.Debug|x64.ActiveCfg = Debug|x64 19 | {85480198-8711-4355-830E-72FD794AD3F6}.Debug|x64.Build.0 = Debug|x64 20 | {85480198-8711-4355-830E-72FD794AD3F6}.Debug|x86.ActiveCfg = Debug|x86 21 | {85480198-8711-4355-830E-72FD794AD3F6}.Debug|x86.Build.0 = Debug|x86 22 | {85480198-8711-4355-830E-72FD794AD3F6}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {85480198-8711-4355-830E-72FD794AD3F6}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {85480198-8711-4355-830E-72FD794AD3F6}.Release|x64.ActiveCfg = Release|x64 25 | {85480198-8711-4355-830E-72FD794AD3F6}.Release|x64.Build.0 = Release|x64 26 | {85480198-8711-4355-830E-72FD794AD3F6}.Release|x86.ActiveCfg = Release|x86 27 | {85480198-8711-4355-830E-72FD794AD3F6}.Release|x86.Build.0 = Release|x86 28 | EndGlobalSection 29 | GlobalSection(MonoDevelopProperties) = preSolution 30 | StartupItem = SDL2-CS.csproj 31 | EndGlobalSection 32 | EndGlobal 33 | -------------------------------------------------------------------------------- /app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /gitlab-ci/SDL2-CS.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SDL2-CS-Rolling 5 | 2000.1.1 6 | flibitijibibo 7 | beannaich 8 | https://github.com/flibitijibibo/SDL2-CS/blob/master/LICENSE 9 | https://github.com/flibitijibibo/SDL2-CS 10 | false 11 | SDL2# - C# Wrapper for SDL2 12 | Copyright 2013-2024 13 | SDL2# SDL2 SDL 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /gitlab-ci/build-net461.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | msbuild /p:Configuration=Release SDL2-CS.csproj 4 | -------------------------------------------------------------------------------- /gitlab-ci/build-netcore.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | dotnet build -c Release SDL2-CS.Core.csproj 4 | -------------------------------------------------------------------------------- /gitlab-ci/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | nuget setApiKey $NUGET_API_KEY -verbosity quiet 6 | 7 | for package in `find *.nupkg`; do 8 | nuget push $package -source https://nuget.org/ 9 | done 10 | -------------------------------------------------------------------------------- /gitlab-ci/package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | version=`date +"%Y.%m.%d"` 6 | 7 | nuspec="gitlab-ci/SDL2-CS.nuspec" 8 | 9 | nuget pack $nuspec -Version $version 10 | -------------------------------------------------------------------------------- /src/SDL2_gfx.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* SDL2# - C# Wrapper for SDL2 3 | * 4 | * Copyright (c) 2013-2024 Ethan Lee. 5 | * 6 | * This software is provided 'as-is', without any express or implied warranty. 7 | * In no event will the authors be held liable for any damages arising from 8 | * the use of this software. 9 | * 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 14 | * 1. The origin of this software must not be misrepresented; you must not 15 | * claim that you wrote the original software. If you use this software in a 16 | * product, an acknowledgment in the product documentation would be 17 | * appreciated but is not required. 18 | * 19 | * 2. Altered source versions must be plainly marked as such, and must not be 20 | * misrepresented as being the original software. 21 | * 22 | * 3. This notice may not be removed or altered from any source distribution. 23 | * 24 | * Ethan "flibitijibibo" Lee 25 | * 26 | */ 27 | #endregion 28 | 29 | #region Using Statements 30 | using System; 31 | using System.Runtime.InteropServices; 32 | #endregion 33 | 34 | namespace SDL2 35 | { 36 | public static class SDL_gfx 37 | { 38 | #region SDL2# Variables 39 | 40 | /* Used by DllImport to load the native library. */ 41 | private const string nativeLibName = "SDL2_gfx"; 42 | 43 | #endregion 44 | 45 | public const double M_PI = 3.1415926535897932384626433832795; 46 | 47 | #region SDL2_gfxPrimitives.h 48 | 49 | public const uint SDL2_GFXPRIMITIVES_MAJOR = 1; 50 | public const uint SDL2_GFXPRIMITIVES_MINOR = 0; 51 | public const uint SDL2_GFXPRIMITIVES_MICRO = 1; 52 | 53 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 54 | public static extern int pixelColor(IntPtr renderer, short x, short y, uint color); 55 | 56 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 57 | public static extern int pixelRGBA(IntPtr renderer, short x, short y, byte r, byte g, byte b, byte a); 58 | 59 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 60 | public static extern int hlineColor(IntPtr renderer, short x1, short x2, short y, uint color); 61 | 62 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 63 | public static extern int hlineRGBA(IntPtr renderer, short x1, short x2, short y, byte r, byte g, byte b, byte a); 64 | 65 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 66 | public static extern int vlineColor(IntPtr renderer, short x, short y1, short y2, uint color); 67 | 68 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 69 | public static extern int vlineRGBA(IntPtr renderer, short x, short y1, short y2, byte r, byte g, byte b, byte a); 70 | 71 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 72 | public static extern int rectangleColor(IntPtr renderer, short x1, short y1, short x2, short y2, uint color); 73 | 74 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 75 | public static extern int rectangleRGBA(IntPtr renderer, short x1, short y1, short x2, short y2, byte r, byte g, byte b, byte a); 76 | 77 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 78 | public static extern int roundedRectangleColor(IntPtr renderer, short x1, short y1, short x2, short y2, short rad, uint color); 79 | 80 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 81 | public static extern int roundedRectangleRGBA(IntPtr renderer, short x1, short y1, short x2, short y2, short rad, byte r, byte g, byte b, byte a); 82 | 83 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 84 | public static extern int boxColor(IntPtr renderer, short x1, short y1, short x2, short y2, uint color); 85 | 86 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 87 | public static extern int boxRGBA(IntPtr renderer, short x1, short y1, short x2, short y2, byte r, byte g, byte b, byte a); 88 | 89 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 90 | public static extern int roundedBoxColor(IntPtr renderer, short x1, short y1, short x2, short y2, short rad, uint color); 91 | 92 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 93 | public static extern int roundedBoxRGBA(IntPtr renderer, short x1, short y1, short x2, short y2, short rad, byte r, byte g, byte b, byte a); 94 | 95 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 96 | public static extern int lineColor(IntPtr renderer, short x1, short y1, short x2, short y2, uint color); 97 | 98 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 99 | public static extern int lineRGBA(IntPtr renderer, short x1, short y1, short x2, short y2, byte r, byte g, byte b, byte a); 100 | 101 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 102 | public static extern int aalineColor(IntPtr renderer, short x1, short y1, short x2, short y2, uint color); 103 | 104 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 105 | public static extern int aalineRGBA(IntPtr renderer, short x1, short y1, short x2, short y2, byte r, byte g, byte b, byte a); 106 | 107 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 108 | public static extern int thickLineColor(IntPtr renderer, short x1, short y1, short x2, short y2, byte width, uint color); 109 | 110 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 111 | public static extern int thickLineRGBA(IntPtr renderer, short x1, short y1, short x2, short y2, byte width, byte r, byte g, byte b, byte a); 112 | 113 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 114 | public static extern int circleColor(IntPtr renderer, short x, short y, short rad, uint color); 115 | 116 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 117 | public static extern int circleRGBA(IntPtr renderer, short x, short y, short rad, byte r, byte g, byte b, byte a); 118 | 119 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 120 | public static extern int arcColor(IntPtr renderer, short x, short y, short rad, short start, short end, uint color); 121 | 122 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 123 | public static extern int arcRGBA(IntPtr renderer, short x, short y, short rad, short start, short end, byte r, byte g, byte b, byte a); 124 | 125 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 126 | public static extern int aacircleColor(IntPtr renderer, short x, short y, short rad, uint color); 127 | 128 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 129 | public static extern int aacircleRGBA(IntPtr renderer, short x, short y, short rad, byte r, byte g, byte b, byte a); 130 | 131 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 132 | public static extern int filledCircleColor(IntPtr renderer, short x, short y, short rad, uint color); 133 | 134 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 135 | public static extern int filledCircleRGBA(IntPtr renderer, short x, short y, short rad, byte r, byte g, byte b, byte a); 136 | 137 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 138 | public static extern int ellipseColor(IntPtr renderer, short x, short y, short rx, short ry, uint color); 139 | 140 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 141 | public static extern int ellipseRGBA(IntPtr renderer, short x, short y, short rx, short ry, byte r, byte g, byte b, byte a); 142 | 143 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 144 | public static extern int aaellipseColor(IntPtr renderer, short x, short y, short rx, short ry, uint color); 145 | 146 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 147 | public static extern int aaellipseRGBA(IntPtr renderer, short x, short y, short rx, short ry, byte r, byte g, byte b, byte a); 148 | 149 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 150 | public static extern int filledEllipseColor(IntPtr renderer, short x, short y, short rx, short ry, uint color); 151 | 152 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 153 | public static extern int filledEllipseRGBA(IntPtr renderer, short x, short y, short rx, short ry, byte r, byte g, byte b, byte a); 154 | 155 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 156 | public static extern int pieColor(IntPtr renderer, short x, short y, short rad, short start, short end, uint color); 157 | 158 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 159 | public static extern int pieRGBA(IntPtr renderer, short x, short y, short rad, short start, short end, byte r, byte g, byte b, byte a); 160 | 161 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 162 | public static extern int filledPieColor(IntPtr renderer, short x, short y, short rad, short start, short end, uint color); 163 | 164 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 165 | public static extern int filledPieRGBA(IntPtr renderer, short x, short y, short rad, short start, short end, byte r, byte g, byte b, byte a); 166 | 167 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 168 | public static extern int trigonColor(IntPtr renderer, short x1, short y1, short x2, short y2, short x3, short y3, uint color); 169 | 170 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 171 | public static extern int trigonRGBA(IntPtr renderer, short x1, short y1, short x2, short y2, short x3, short y3, byte r, byte g, byte b, byte a); 172 | 173 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 174 | public static extern int aatrigonColor(IntPtr renderer, short x1, short y1, short x2, short y2, short x3, short y3, uint color); 175 | 176 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 177 | public static extern int aatrigonRGBA(IntPtr renderer, short x1, short y1, short x2, short y2, short x3, short y3, byte r, byte g, byte b, byte a); 178 | 179 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 180 | public static extern int filledTrigonColor(IntPtr renderer, short x1, short y1, short x2, short y2, short x3, short y3, uint color); 181 | 182 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 183 | public static extern int filledTrigonRGBA(IntPtr renderer, short x1, short y1, short x2, short y2, short x3, short y3, byte r, byte g, byte b, byte a); 184 | 185 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 186 | public static extern int polygonColor(IntPtr renderer, [In] short[] vx, [In] short[] vy, int n, uint color); 187 | 188 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 189 | public static extern int polygonRGBA(IntPtr renderer, [In] short[] vx, [In] short[] vy, int n, byte r, byte g, byte b, byte a); 190 | 191 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 192 | public static extern int aapolygonColor(IntPtr renderer, [In] short[] vx, [In] short[] vy, int n, uint color); 193 | 194 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 195 | public static extern int aapolygonRGBA(IntPtr renderer, [In] short[] vx, [In] short[] vy, int n, byte r, byte g, byte b, byte a); 196 | 197 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 198 | public static extern int filledPolygonColor(IntPtr renderer, [In] short[] vx, [In] short[] vy, int n, uint color); 199 | 200 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 201 | public static extern int filledPolygonRGBA(IntPtr renderer, [In] short[] vx, [In] short[] vy, int n, byte r, byte g, byte b, byte a); 202 | 203 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 204 | public static extern int texturedPolygon(IntPtr renderer, [In] short[] vx, [In] short[] vy, int n, IntPtr texture, int texture_dx, int texture_dy); 205 | 206 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 207 | public static extern int bezierColor(IntPtr renderer, [In] short[] vx, [In] short[] vy, int n, int s, uint color); 208 | 209 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 210 | public static extern int bezierRGBA(IntPtr renderer, [In] short[] vx, [In] short[] vy, int n, int s, byte r, byte g, byte b, byte a); 211 | 212 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 213 | public static extern void gfxPrimitivesSetFont([In] byte[] fontdata, uint cw, uint ch); 214 | 215 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 216 | public static extern void gfxPrimitivesSetFontRotation(uint rotation); 217 | 218 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 219 | public static extern int characterColor(IntPtr renderer, short x, short y, char c, uint color); 220 | 221 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 222 | public static extern int characterRGBA(IntPtr renderer, short x, short y, char c, byte r, byte g, byte b, byte a); 223 | 224 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 225 | public static extern int stringColor(IntPtr renderer, short x, short y, string s, uint color); 226 | 227 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 228 | public static extern int stringRGBA(IntPtr renderer, short x, short y, string s, byte r, byte g, byte b, byte a); 229 | 230 | #endregion 231 | 232 | #region SDL2_rotozoom.h 233 | 234 | public const int SMOOTHING_OFF = 0; 235 | public const int SMOOTHING_ON = 1; 236 | 237 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 238 | public static extern IntPtr rotozoomSurface(IntPtr src, double angle, double zoom, int smooth); 239 | 240 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 241 | public static extern IntPtr rotozoomSurfaceXY(IntPtr src, double angle, double zoomx, double zoomy, int smooth); 242 | 243 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 244 | public static extern void rotozoomSurfaceSize(int width, int height, double angle, double zoom, out int dstwidth, out int dstheight); 245 | 246 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 247 | public static extern void rotozoomSurfaceSizeXY(int width, int height, double angle, double zoomx, double zoomy, out int dstwidth, out int dstheight); 248 | 249 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 250 | public static extern IntPtr zoomSurface(IntPtr src, double zoomx, double zoomy, int smooth); 251 | 252 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 253 | public static extern void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, out int dstwidth, out int dstheight); 254 | 255 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 256 | public static extern IntPtr shrinkSurface(IntPtr src, int factorx, int factory); 257 | 258 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 259 | public static extern IntPtr rotateSurface90Degrees(IntPtr src, int numClockwiseTurns); 260 | 261 | #endregion 262 | 263 | #region SDL2_framerate.h 264 | 265 | public const int FPS_UPPER_LIMIT = 200; 266 | public const int FPS_LOWER_LIMIT = 1; 267 | public const int FPS_DEFAULT = 30; 268 | 269 | [StructLayout(LayoutKind.Sequential)] 270 | public struct FPSmanager 271 | { 272 | public uint framecount; 273 | public float rateticks; 274 | public uint baseticks; 275 | public uint lastticks; 276 | public uint rate; 277 | } 278 | 279 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 280 | public static extern void SDL_initFramerate(ref FPSmanager manager); 281 | 282 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 283 | public static extern int SDL_setFramerate(ref FPSmanager manager, uint rate); 284 | 285 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 286 | public static extern int SDL_getFramerate(ref FPSmanager manager); 287 | 288 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 289 | public static extern int SDL_getFramecount(ref FPSmanager manager); 290 | 291 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 292 | public static extern uint SDL_framerateDelay(ref FPSmanager manager); 293 | 294 | #endregion 295 | 296 | #region SDL2_imageFilter.h 297 | 298 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 299 | public static extern int SDL_imageFilterMMXdetect(); 300 | 301 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 302 | public static extern void SDL_imageFilterMMXoff(); 303 | 304 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 305 | public static extern void SDL_imageFilterMMXon(); 306 | 307 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 308 | public static extern int SDL_imageFilterAdd([In] byte[] src1, [In] byte[] src2, [Out] byte[] dest, uint length); 309 | 310 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 311 | public static extern int SDL_imageFilterMean([In] byte[] src1, [In] byte[] src2, [Out] byte[] dest, uint length); 312 | 313 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 314 | public static extern int SDL_imageFilterSub([In] byte[] src1, [In] byte[] src2, [Out] byte[] dest, uint length); 315 | 316 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 317 | public static extern int SDL_imageFilterAbsDiff([In] byte[] src1, [In] byte[] src2, [Out] byte[] dest, uint length); 318 | 319 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 320 | public static extern int SDL_imageFilterMult([In] byte[] src1, [In] byte[] src2, [Out] byte[] dest, uint length); 321 | 322 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 323 | public static extern int SDL_imageFilterMultNor([In] byte[] src1, [In] byte[] src2, [Out] byte[] dest, uint length); 324 | 325 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 326 | public static extern int SDL_imageFilterMultDivby2([In] byte[] src1, [In] byte[] src2, [Out] byte[] dest, uint length); 327 | 328 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 329 | public static extern int SDL_imageFilterMultDivby4([In] byte[] src1, [In] byte[] src2, [Out] byte[] dest, uint length); 330 | 331 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 332 | public static extern int SDL_imageFilterBitAnd([In] byte[] src1, [In] byte[] src2, [Out] byte[] dest, uint length); 333 | 334 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 335 | public static extern int SDL_imageFilterBitOr([In] byte[] src1, [In] byte[] src2, [Out] byte[] dest, uint length); 336 | 337 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 338 | public static extern int SDL_imageFilterDiv([In] byte[] src1, [In] byte[] src2, [Out] byte[] dest, uint length); 339 | 340 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 341 | public static extern int SDL_imageFilterBitNegation([In] byte[] src1, [Out] byte[] dest, uint length); 342 | 343 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 344 | public static extern int SDL_imageFilterAddByte([In] byte[] src1, [Out] byte[] dest, uint length, byte c); 345 | 346 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 347 | public static extern int SDL_imageFilterAddUint([In] byte[] src1, [Out] byte[] dest, uint length, uint c); 348 | 349 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 350 | public static extern int SDL_imageFilterAddByteToHalf([In] byte[] src1, [Out] byte[] dest, uint length, byte c); 351 | 352 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 353 | public static extern int SDL_imageFilterSubByte([In] byte[] src1, [Out] byte[] dest, uint length, byte c); 354 | 355 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 356 | public static extern int SDL_imageFilterSubUint([In] byte[] src1, [Out] byte[] dest, uint length, uint c); 357 | 358 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 359 | public static extern int SDL_imageFilterShiftRight([In] byte[] src1, [Out] byte[] dest, uint length, byte n); 360 | 361 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 362 | public static extern int SDL_imageFilterShiftRightUint([In] byte[] src1, [Out] byte[] dest, uint length, byte n); 363 | 364 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 365 | public static extern int SDL_imageFilterMultByByte([In] byte[] src1, [Out] byte[] dest, uint length, byte c); 366 | 367 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 368 | public static extern int SDL_imageFilterShiftRightAndMultByByte([In] byte[] src1, [Out] byte[] dest, uint length, byte n, byte c); 369 | 370 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 371 | public static extern int SDL_imageFilterShiftLeftByte([In] byte[] src1, [Out] byte[] dest, uint length, byte n); 372 | 373 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 374 | public static extern int SDL_imageFilterShiftLeftUint([In] byte[] src1, [Out] byte[] dest, uint length, byte n); 375 | 376 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 377 | public static extern int SDL_imageFilterShiftLeft([In] byte[] src1, [Out] byte[] dest, uint length, byte n); 378 | 379 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 380 | public static extern int SDL_imageFilterBinarizeUsingThreshold([In] byte[] src1, [Out] byte[] dest, uint length, byte t); 381 | 382 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 383 | public static extern int SDL_imageFilterClipToRange([In] byte[] src1, [Out] byte[] dest, uint length, byte tmin, byte tmax); 384 | 385 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 386 | public static extern int SDL_imageFilterNormalizeLinear([In] byte[] src1, [Out] byte[] dest, uint length, int cmin, int cmax, int nmin, int nmax); 387 | 388 | #endregion 389 | } 390 | } 391 | -------------------------------------------------------------------------------- /src/SDL2_image.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* SDL2# - C# Wrapper for SDL2 3 | * 4 | * Copyright (c) 2013-2024 Ethan Lee. 5 | * 6 | * This software is provided 'as-is', without any express or implied warranty. 7 | * In no event will the authors be held liable for any damages arising from 8 | * the use of this software. 9 | * 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 14 | * 1. The origin of this software must not be misrepresented; you must not 15 | * claim that you wrote the original software. If you use this software in a 16 | * product, an acknowledgment in the product documentation would be 17 | * appreciated but is not required. 18 | * 19 | * 2. Altered source versions must be plainly marked as such, and must not be 20 | * misrepresented as being the original software. 21 | * 22 | * 3. This notice may not be removed or altered from any source distribution. 23 | * 24 | * Ethan "flibitijibibo" Lee 25 | * 26 | */ 27 | #endregion 28 | 29 | #region Using Statements 30 | using System; 31 | using System.Runtime.InteropServices; 32 | #endregion 33 | 34 | namespace SDL2 35 | { 36 | public static class SDL_image 37 | { 38 | #region SDL2# Variables 39 | 40 | /* Used by DllImport to load the native library. */ 41 | private const string nativeLibName = "SDL2_image"; 42 | 43 | #endregion 44 | 45 | #region SDL_image.h 46 | 47 | /* Similar to the headers, this is the version we're expecting to be 48 | * running with. You will likely want to check this somewhere in your 49 | * program! 50 | */ 51 | public const int SDL_IMAGE_MAJOR_VERSION = 2; 52 | public const int SDL_IMAGE_MINOR_VERSION = 0; 53 | public const int SDL_IMAGE_PATCHLEVEL = 6; 54 | 55 | [Flags] 56 | public enum IMG_InitFlags 57 | { 58 | IMG_INIT_JPG = 0x00000001, 59 | IMG_INIT_PNG = 0x00000002, 60 | IMG_INIT_TIF = 0x00000004, 61 | IMG_INIT_WEBP = 0x00000008 62 | } 63 | 64 | public static void SDL_IMAGE_VERSION(out SDL.SDL_version X) 65 | { 66 | X.major = SDL_IMAGE_MAJOR_VERSION; 67 | X.minor = SDL_IMAGE_MINOR_VERSION; 68 | X.patch = SDL_IMAGE_PATCHLEVEL; 69 | } 70 | 71 | [DllImport(nativeLibName, EntryPoint = "IMG_Linked_Version", CallingConvention = CallingConvention.Cdecl)] 72 | private static extern IntPtr INTERNAL_IMG_Linked_Version(); 73 | public static SDL.SDL_version IMG_Linked_Version() 74 | { 75 | SDL.SDL_version result; 76 | IntPtr result_ptr = INTERNAL_IMG_Linked_Version(); 77 | result = SDL.PtrToStructure( 78 | result_ptr 79 | ); 80 | return result; 81 | } 82 | 83 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 84 | public static extern int IMG_Init(IMG_InitFlags flags); 85 | 86 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 87 | public static extern void IMG_Quit(); 88 | 89 | /* IntPtr refers to an SDL_Surface* */ 90 | [DllImport(nativeLibName, EntryPoint = "IMG_Load", CallingConvention = CallingConvention.Cdecl)] 91 | private static extern unsafe IntPtr INTERNAL_IMG_Load( 92 | byte* file 93 | ); 94 | public static unsafe IntPtr IMG_Load(string file) 95 | { 96 | byte* utf8File = SDL.Utf8EncodeHeap(file); 97 | IntPtr handle = INTERNAL_IMG_Load( 98 | utf8File 99 | ); 100 | Marshal.FreeHGlobal((IntPtr) utf8File); 101 | return handle; 102 | } 103 | 104 | /* src refers to an SDL_RWops*, IntPtr to an SDL_Surface* */ 105 | /* THIS IS A PUBLIC RWops FUNCTION! */ 106 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 107 | public static extern IntPtr IMG_Load_RW( 108 | IntPtr src, 109 | int freesrc 110 | ); 111 | 112 | /* src refers to an SDL_RWops*, IntPtr to an SDL_Surface* */ 113 | /* THIS IS A PUBLIC RWops FUNCTION! */ 114 | [DllImport(nativeLibName, EntryPoint = "IMG_LoadTyped_RW", CallingConvention = CallingConvention.Cdecl)] 115 | private static extern unsafe IntPtr INTERNAL_IMG_LoadTyped_RW( 116 | IntPtr src, 117 | int freesrc, 118 | byte* type 119 | ); 120 | public static unsafe IntPtr IMG_LoadTyped_RW( 121 | IntPtr src, 122 | int freesrc, 123 | string type 124 | ) { 125 | int utf8TypeBufSize = SDL.Utf8Size(type); 126 | byte* utf8Type = stackalloc byte[utf8TypeBufSize]; 127 | return INTERNAL_IMG_LoadTyped_RW( 128 | src, 129 | freesrc, 130 | SDL.Utf8Encode(type, utf8Type, utf8TypeBufSize) 131 | ); 132 | } 133 | 134 | /* IntPtr refers to an SDL_Texture*, renderer to an SDL_Renderer* */ 135 | [DllImport(nativeLibName, EntryPoint = "IMG_LoadTexture", CallingConvention = CallingConvention.Cdecl)] 136 | private static extern unsafe IntPtr INTERNAL_IMG_LoadTexture( 137 | IntPtr renderer, 138 | byte* file 139 | ); 140 | public static unsafe IntPtr IMG_LoadTexture( 141 | IntPtr renderer, 142 | string file 143 | ) { 144 | byte* utf8File = SDL.Utf8EncodeHeap(file); 145 | IntPtr handle = INTERNAL_IMG_LoadTexture( 146 | renderer, 147 | utf8File 148 | ); 149 | Marshal.FreeHGlobal((IntPtr) utf8File); 150 | return handle; 151 | } 152 | 153 | /* renderer refers to an SDL_Renderer*. 154 | * src refers to an SDL_RWops*. 155 | * IntPtr to an SDL_Texture*. 156 | */ 157 | /* THIS IS A PUBLIC RWops FUNCTION! */ 158 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 159 | public static extern IntPtr IMG_LoadTexture_RW( 160 | IntPtr renderer, 161 | IntPtr src, 162 | int freesrc 163 | ); 164 | 165 | /* renderer refers to an SDL_Renderer*. 166 | * src refers to an SDL_RWops*. 167 | * IntPtr to an SDL_Texture*. 168 | */ 169 | /* THIS IS A PUBLIC RWops FUNCTION! */ 170 | [DllImport(nativeLibName, EntryPoint = "IMG_LoadTextureTyped_RW", CallingConvention = CallingConvention.Cdecl)] 171 | private static extern unsafe IntPtr INTERNAL_IMG_LoadTextureTyped_RW( 172 | IntPtr renderer, 173 | IntPtr src, 174 | int freesrc, 175 | byte* type 176 | ); 177 | public static unsafe IntPtr IMG_LoadTextureTyped_RW( 178 | IntPtr renderer, 179 | IntPtr src, 180 | int freesrc, 181 | string type 182 | ) { 183 | byte* utf8Type = SDL.Utf8EncodeHeap(type); 184 | IntPtr handle = INTERNAL_IMG_LoadTextureTyped_RW( 185 | renderer, 186 | src, 187 | freesrc, 188 | utf8Type 189 | ); 190 | Marshal.FreeHGlobal((IntPtr) utf8Type); 191 | return handle; 192 | } 193 | 194 | /* IntPtr refers to an SDL_Surface* */ 195 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 196 | public static extern IntPtr IMG_ReadXPMFromArray( 197 | [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] 198 | string[] xpm 199 | ); 200 | 201 | /* surface refers to an SDL_Surface* */ 202 | [DllImport(nativeLibName, EntryPoint = "IMG_SavePNG", CallingConvention = CallingConvention.Cdecl)] 203 | private static extern unsafe int INTERNAL_IMG_SavePNG( 204 | IntPtr surface, 205 | byte* file 206 | ); 207 | public static unsafe int IMG_SavePNG(IntPtr surface, string file) 208 | { 209 | byte* utf8File = SDL.Utf8EncodeHeap(file); 210 | int result = INTERNAL_IMG_SavePNG( 211 | surface, 212 | utf8File 213 | ); 214 | Marshal.FreeHGlobal((IntPtr) utf8File); 215 | return result; 216 | } 217 | 218 | /* surface refers to an SDL_Surface*, dst to an SDL_RWops* */ 219 | /* THIS IS A PUBLIC RWops FUNCTION! */ 220 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 221 | public static extern int IMG_SavePNG_RW( 222 | IntPtr surface, 223 | IntPtr dst, 224 | int freedst 225 | ); 226 | 227 | /* surface refers to an SDL_Surface* */ 228 | [DllImport(nativeLibName, EntryPoint = "IMG_SaveJPG", CallingConvention = CallingConvention.Cdecl)] 229 | private static extern unsafe int INTERNAL_IMG_SaveJPG( 230 | IntPtr surface, 231 | byte* file, 232 | int quality 233 | ); 234 | public static unsafe int IMG_SaveJPG(IntPtr surface, string file, int quality) 235 | { 236 | byte* utf8File = SDL.Utf8EncodeHeap(file); 237 | int result = INTERNAL_IMG_SaveJPG( 238 | surface, 239 | utf8File, 240 | quality 241 | ); 242 | Marshal.FreeHGlobal((IntPtr) utf8File); 243 | return result; 244 | } 245 | 246 | /* surface refers to an SDL_Surface*, dst to an SDL_RWops* */ 247 | /* THIS IS A PUBLIC RWops FUNCTION! */ 248 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 249 | public static extern int IMG_SaveJPG_RW( 250 | IntPtr surface, 251 | IntPtr dst, 252 | int freedst, 253 | int quality 254 | ); 255 | 256 | public static string IMG_GetError() 257 | { 258 | return SDL.SDL_GetError(); 259 | } 260 | 261 | public static void IMG_SetError(string fmtAndArglist) 262 | { 263 | SDL.SDL_SetError(fmtAndArglist); 264 | } 265 | 266 | #region Animated Image Support 267 | 268 | /* This region is only available in 2.0.6 or higher. */ 269 | 270 | public struct IMG_Animation 271 | { 272 | public int w; 273 | public int h; 274 | public IntPtr frames; /* SDL_Surface** */ 275 | public IntPtr delays; /* int* */ 276 | } 277 | 278 | /* IntPtr refers to an IMG_Animation* */ 279 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 280 | public static extern IntPtr IMG_LoadAnimation( 281 | [In()] [MarshalAs(UnmanagedType.LPStr)] 282 | string file 283 | ); 284 | 285 | /* IntPtr refers to an IMG_Animation*, src to an SDL_RWops* */ 286 | /* THIS IS A PUBLIC RWops FUNCTION! */ 287 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 288 | public static extern IntPtr IMG_LoadAnimation_RW( 289 | IntPtr src, 290 | int freesrc 291 | ); 292 | 293 | /* IntPtr refers to an IMG_Animation*, src to an SDL_RWops* */ 294 | /* THIS IS A PUBLIC RWops FUNCTION! */ 295 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 296 | public static extern IntPtr IMG_LoadAnimationTyped_RW( 297 | IntPtr src, 298 | int freesrc, 299 | [In()] [MarshalAs(UnmanagedType.LPStr)] 300 | string type 301 | ); 302 | 303 | /* anim refers to an IMG_Animation* */ 304 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 305 | public static extern void IMG_FreeAnimation(IntPtr anim); 306 | 307 | /* IntPtr refers to an IMG_Animation*, src to an SDL_RWops* */ 308 | /* THIS IS A PUBLIC RWops FUNCTION! */ 309 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 310 | public static extern IntPtr IMG_LoadGIFAnimation_RW(IntPtr src); 311 | 312 | #endregion 313 | 314 | #endregion 315 | } 316 | } 317 | -------------------------------------------------------------------------------- /src/SDL2_mixer.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* SDL2# - C# Wrapper for SDL2 3 | * 4 | * Copyright (c) 2013-2024 Ethan Lee. 5 | * 6 | * This software is provided 'as-is', without any express or implied warranty. 7 | * In no event will the authors be held liable for any damages arising from 8 | * the use of this software. 9 | * 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 14 | * 1. The origin of this software must not be misrepresented; you must not 15 | * claim that you wrote the original software. If you use this software in a 16 | * product, an acknowledgment in the product documentation would be 17 | * appreciated but is not required. 18 | * 19 | * 2. Altered source versions must be plainly marked as such, and must not be 20 | * misrepresented as being the original software. 21 | * 22 | * 3. This notice may not be removed or altered from any source distribution. 23 | * 24 | * Ethan "flibitijibibo" Lee 25 | * 26 | */ 27 | #endregion 28 | 29 | #region Using Statements 30 | using System; 31 | using System.Runtime.InteropServices; 32 | #endregion 33 | 34 | namespace SDL2 35 | { 36 | public static class SDL_mixer 37 | { 38 | #region SDL2# Variables 39 | 40 | /* Used by DllImport to load the native library. */ 41 | private const string nativeLibName = "SDL2_mixer"; 42 | 43 | #endregion 44 | 45 | #region SDL_mixer.h 46 | 47 | /* Similar to the headers, this is the version we're expecting to be 48 | * running with. You will likely want to check this somewhere in your 49 | * program! 50 | */ 51 | public const int SDL_MIXER_MAJOR_VERSION = 2; 52 | public const int SDL_MIXER_MINOR_VERSION = 0; 53 | public const int SDL_MIXER_PATCHLEVEL = 5; 54 | 55 | /* In C, you can redefine this value before including SDL_mixer.h. 56 | * We're not going to allow this in SDL2#, since the value of this 57 | * variable is persistent and not dependent on preprocessor ordering. 58 | */ 59 | public const int MIX_CHANNELS = 8; 60 | 61 | public static readonly int MIX_DEFAULT_FREQUENCY = 44100; 62 | public static readonly ushort MIX_DEFAULT_FORMAT = 63 | BitConverter.IsLittleEndian ? SDL.AUDIO_S16LSB : SDL.AUDIO_S16MSB; 64 | public static readonly int MIX_DEFAULT_CHANNELS = 2; 65 | public static readonly byte MIX_MAX_VOLUME = 128; 66 | 67 | [Flags] 68 | public enum MIX_InitFlags 69 | { 70 | MIX_INIT_FLAC = 0x00000001, 71 | MIX_INIT_MOD = 0x00000002, 72 | MIX_INIT_MP3 = 0x00000008, 73 | MIX_INIT_OGG = 0x00000010, 74 | MIX_INIT_MID = 0x00000020, 75 | MIX_INIT_OPUS = 0x00000040 76 | } 77 | 78 | public struct MIX_Chunk 79 | { 80 | public int allocated; 81 | public IntPtr abuf; /* Uint8* */ 82 | public uint alen; 83 | public byte volume; 84 | } 85 | 86 | public enum Mix_Fading 87 | { 88 | MIX_NO_FADING, 89 | MIX_FADING_OUT, 90 | MIX_FADING_IN 91 | } 92 | 93 | public enum Mix_MusicType 94 | { 95 | MUS_NONE, 96 | MUS_CMD, 97 | MUS_WAV, 98 | MUS_MOD, 99 | MUS_MID, 100 | MUS_OGG, 101 | MUS_MP3, 102 | MUS_MP3_MAD_UNUSED, 103 | MUS_FLAC, 104 | MUS_MODPLUG_UNUSED, 105 | MUS_OPUS 106 | } 107 | 108 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 109 | public delegate void MixFuncDelegate( 110 | IntPtr udata, // void* 111 | IntPtr stream, // Uint8* 112 | int len 113 | ); 114 | 115 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 116 | public delegate void Mix_EffectFunc_t( 117 | int chan, 118 | IntPtr stream, // void* 119 | int len, 120 | IntPtr udata // void* 121 | ); 122 | 123 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 124 | public delegate void Mix_EffectDone_t( 125 | int chan, 126 | IntPtr udata // void* 127 | ); 128 | 129 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 130 | public delegate void MusicFinishedDelegate(); 131 | 132 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 133 | public delegate void ChannelFinishedDelegate(int channel); 134 | 135 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 136 | public delegate int SoundFontDelegate( 137 | IntPtr a, // const char* 138 | IntPtr b // void* 139 | ); 140 | 141 | public static void SDL_MIXER_VERSION(out SDL.SDL_version X) 142 | { 143 | X.major = SDL_MIXER_MAJOR_VERSION; 144 | X.minor = SDL_MIXER_MINOR_VERSION; 145 | X.patch = SDL_MIXER_PATCHLEVEL; 146 | } 147 | 148 | [DllImport(nativeLibName, EntryPoint = "MIX_Linked_Version", CallingConvention = CallingConvention.Cdecl)] 149 | private static extern IntPtr INTERNAL_MIX_Linked_Version(); 150 | public static SDL.SDL_version MIX_Linked_Version() 151 | { 152 | SDL.SDL_version result; 153 | IntPtr result_ptr = INTERNAL_MIX_Linked_Version(); 154 | result = SDL.PtrToStructure( 155 | result_ptr 156 | ); 157 | return result; 158 | } 159 | 160 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 161 | public static extern int Mix_Init(MIX_InitFlags flags); 162 | 163 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 164 | public static extern void Mix_Quit(); 165 | 166 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 167 | public static extern int Mix_OpenAudio( 168 | int frequency, 169 | ushort format, 170 | int channels, 171 | int chunksize 172 | ); 173 | 174 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 175 | public static extern int Mix_AllocateChannels(int numchans); 176 | 177 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 178 | public static extern int Mix_QuerySpec( 179 | out int frequency, 180 | out ushort format, 181 | out int channels 182 | ); 183 | 184 | /* src refers to an SDL_RWops*, IntPtr to a Mix_Chunk* */ 185 | /* THIS IS A PUBLIC RWops FUNCTION! */ 186 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 187 | public static extern IntPtr Mix_LoadWAV_RW( 188 | IntPtr src, 189 | int freesrc 190 | ); 191 | 192 | /* IntPtr refers to a Mix_Chunk* */ 193 | /* This is an RWops macro in the C header. */ 194 | public static IntPtr Mix_LoadWAV(string file) 195 | { 196 | IntPtr rwops = SDL.SDL_RWFromFile(file, "rb"); 197 | return Mix_LoadWAV_RW(rwops, 1); 198 | } 199 | 200 | /* IntPtr refers to a Mix_Music* */ 201 | [DllImport(nativeLibName, EntryPoint = "Mix_LoadMUS", CallingConvention = CallingConvention.Cdecl)] 202 | private static extern unsafe IntPtr INTERNAL_Mix_LoadMUS( 203 | byte* file 204 | ); 205 | public static unsafe IntPtr Mix_LoadMUS(string file) 206 | { 207 | byte* utf8File = SDL.Utf8EncodeHeap(file); 208 | IntPtr handle = INTERNAL_Mix_LoadMUS( 209 | utf8File 210 | ); 211 | Marshal.FreeHGlobal((IntPtr) utf8File); 212 | return handle; 213 | } 214 | 215 | /* IntPtr refers to a Mix_Chunk* */ 216 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 217 | public static extern IntPtr Mix_QuickLoad_WAV( 218 | [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1)] 219 | byte[] mem 220 | ); 221 | 222 | /* IntPtr refers to a Mix_Chunk* */ 223 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 224 | public static extern IntPtr Mix_QuickLoad_RAW( 225 | [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 1)] 226 | byte[] mem, 227 | uint len 228 | ); 229 | 230 | /* chunk refers to a Mix_Chunk* */ 231 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 232 | public static extern void Mix_FreeChunk(IntPtr chunk); 233 | 234 | /* music refers to a Mix_Music* */ 235 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 236 | public static extern void Mix_FreeMusic(IntPtr music); 237 | 238 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 239 | public static extern int Mix_GetNumChunkDecoders(); 240 | 241 | [DllImport(nativeLibName, EntryPoint = "Mix_GetChunkDecoder", CallingConvention = CallingConvention.Cdecl)] 242 | private static extern IntPtr INTERNAL_Mix_GetChunkDecoder(int index); 243 | public static string Mix_GetChunkDecoder(int index) 244 | { 245 | return SDL.UTF8_ToManaged( 246 | INTERNAL_Mix_GetChunkDecoder(index) 247 | ); 248 | } 249 | 250 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 251 | public static extern int Mix_GetNumMusicDecoders(); 252 | 253 | [DllImport(nativeLibName, EntryPoint = "Mix_GetMusicDecoder", CallingConvention = CallingConvention.Cdecl)] 254 | private static extern IntPtr INTERNAL_Mix_GetMusicDecoder(int index); 255 | public static string Mix_GetMusicDecoder(int index) 256 | { 257 | return SDL.UTF8_ToManaged( 258 | INTERNAL_Mix_GetMusicDecoder(index) 259 | ); 260 | } 261 | 262 | /* music refers to a Mix_Music* */ 263 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 264 | public static extern Mix_MusicType Mix_GetMusicType(IntPtr music); 265 | 266 | /* music refers to a Mix_Music* 267 | * Only available in 2.0.5 or higher. 268 | */ 269 | [DllImport(nativeLibName, EntryPoint = "Mix_GetMusicTitle", CallingConvention = CallingConvention.Cdecl)] 270 | public static extern IntPtr INTERNAL_Mix_GetMusicTitle(IntPtr music); 271 | public static string Mix_GetMusicTitle(IntPtr music) 272 | { 273 | return SDL.UTF8_ToManaged( 274 | INTERNAL_Mix_GetMusicTitle(music) 275 | ); 276 | } 277 | 278 | /* music refers to a Mix_Music* 279 | * Only available in 2.0.5 or higher. 280 | */ 281 | [DllImport(nativeLibName, EntryPoint = "Mix_GetMusicTitleTag", CallingConvention = CallingConvention.Cdecl)] 282 | public static extern IntPtr INTERNAL_Mix_GetMusicTitleTag(IntPtr music); 283 | public static string Mix_GetMusicTitleTag(IntPtr music) 284 | { 285 | return SDL.UTF8_ToManaged( 286 | INTERNAL_Mix_GetMusicTitleTag(music) 287 | ); 288 | } 289 | 290 | /* music refers to a Mix_Music* 291 | * Only available in 2.0.5 or higher. 292 | */ 293 | [DllImport(nativeLibName, EntryPoint = "Mix_GetMusicArtistTag", CallingConvention = CallingConvention.Cdecl)] 294 | public static extern IntPtr INTERNAL_Mix_GetMusicArtistTag(IntPtr music); 295 | public static string Mix_GetMusicArtistTag(IntPtr music) 296 | { 297 | return SDL.UTF8_ToManaged( 298 | INTERNAL_Mix_GetMusicArtistTag(music) 299 | ); 300 | } 301 | 302 | /* music refers to a Mix_Music* 303 | * Only available in 2.0.5 or higher. 304 | */ 305 | [DllImport(nativeLibName, EntryPoint = "Mix_GetMusicAlbumTag", CallingConvention = CallingConvention.Cdecl)] 306 | public static extern IntPtr INTERNAL_Mix_GetMusicAlbumTag(IntPtr music); 307 | public static string Mix_GetMusicAlbumTag(IntPtr music) 308 | { 309 | return SDL.UTF8_ToManaged( 310 | INTERNAL_Mix_GetMusicAlbumTag(music) 311 | ); 312 | } 313 | 314 | /* music refers to a Mix_Music* 315 | * Only available in 2.0.5 or higher. 316 | */ 317 | [DllImport(nativeLibName, EntryPoint = "Mix_GetMusicCopyrightTag", CallingConvention = CallingConvention.Cdecl)] 318 | public static extern IntPtr INTERNAL_Mix_GetMusicCopyrightTag(IntPtr music); 319 | public static string Mix_GetMusicCopyrightTag(IntPtr music) 320 | { 321 | return SDL.UTF8_ToManaged( 322 | INTERNAL_Mix_GetMusicCopyrightTag(music) 323 | ); 324 | } 325 | 326 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 327 | public static extern void Mix_SetPostMix( 328 | MixFuncDelegate mix_func, 329 | IntPtr arg // void* 330 | ); 331 | 332 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 333 | public static extern void Mix_HookMusic( 334 | MixFuncDelegate mix_func, 335 | IntPtr arg // void* 336 | ); 337 | 338 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 339 | public static extern void Mix_HookMusicFinished( 340 | MusicFinishedDelegate music_finished 341 | ); 342 | 343 | /* IntPtr refers to a void* */ 344 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 345 | public static extern IntPtr Mix_GetMusicHookData(); 346 | 347 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 348 | public static extern void Mix_ChannelFinished( 349 | ChannelFinishedDelegate channel_finished 350 | ); 351 | 352 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 353 | public static extern int Mix_RegisterEffect( 354 | int chan, 355 | Mix_EffectFunc_t f, 356 | Mix_EffectDone_t d, 357 | IntPtr arg // void* 358 | ); 359 | 360 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 361 | public static extern int Mix_UnregisterEffect( 362 | int channel, 363 | Mix_EffectFunc_t f 364 | ); 365 | 366 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 367 | public static extern int Mix_UnregisterAllEffects(int channel); 368 | 369 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 370 | public static extern int Mix_SetPanning( 371 | int channel, 372 | byte left, 373 | byte right 374 | ); 375 | 376 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 377 | public static extern int Mix_SetPosition( 378 | int channel, 379 | short angle, 380 | byte distance 381 | ); 382 | 383 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 384 | public static extern int Mix_SetDistance(int channel, byte distance); 385 | 386 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 387 | public static extern int Mix_SetReverseStereo(int channel, int flip); 388 | 389 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 390 | public static extern int Mix_ReserveChannels(int num); 391 | 392 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 393 | public static extern int Mix_GroupChannel(int which, int tag); 394 | 395 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 396 | public static extern int Mix_GroupChannels(int from, int to, int tag); 397 | 398 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 399 | public static extern int Mix_GroupAvailable(int tag); 400 | 401 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 402 | public static extern int Mix_GroupCount(int tag); 403 | 404 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 405 | public static extern int Mix_GroupOldest(int tag); 406 | 407 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 408 | public static extern int Mix_GroupNewer(int tag); 409 | 410 | /* chunk refers to a Mix_Chunk* */ 411 | public static int Mix_PlayChannel( 412 | int channel, 413 | IntPtr chunk, 414 | int loops 415 | ) { 416 | return Mix_PlayChannelTimed(channel, chunk, loops, -1); 417 | } 418 | 419 | /* chunk refers to a Mix_Chunk* */ 420 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 421 | public static extern int Mix_PlayChannelTimed( 422 | int channel, 423 | IntPtr chunk, 424 | int loops, 425 | int ticks 426 | ); 427 | 428 | /* music refers to a Mix_Music* */ 429 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 430 | public static extern int Mix_PlayMusic(IntPtr music, int loops); 431 | 432 | /* music refers to a Mix_Music* */ 433 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 434 | public static extern int Mix_FadeInMusic( 435 | IntPtr music, 436 | int loops, 437 | int ms 438 | ); 439 | 440 | /* music refers to a Mix_Music* */ 441 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 442 | public static extern int Mix_FadeInMusicPos( 443 | IntPtr music, 444 | int loops, 445 | int ms, 446 | double position 447 | ); 448 | 449 | /* chunk refers to a Mix_Chunk* */ 450 | public static int Mix_FadeInChannel( 451 | int channel, 452 | IntPtr chunk, 453 | int loops, 454 | int ms 455 | ) { 456 | return Mix_FadeInChannelTimed(channel, chunk, loops, ms, -1); 457 | } 458 | 459 | /* chunk refers to a Mix_Chunk* */ 460 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 461 | public static extern int Mix_FadeInChannelTimed( 462 | int channel, 463 | IntPtr chunk, 464 | int loops, 465 | int ms, 466 | int ticks 467 | ); 468 | 469 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 470 | public static extern int Mix_Volume(int channel, int volume); 471 | 472 | /* chunk refers to a Mix_Chunk* */ 473 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 474 | public static extern int Mix_VolumeChunk( 475 | IntPtr chunk, 476 | int volume 477 | ); 478 | 479 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 480 | public static extern int Mix_VolumeMusic(int volume); 481 | 482 | /* music refers to a Mix_Music* 483 | * Only available in 2.0.5 or higher. 484 | */ 485 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 486 | public static extern int Mix_GetVolumeMusicStream(IntPtr music); 487 | 488 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 489 | public static extern int Mix_HaltChannel(int channel); 490 | 491 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 492 | public static extern int Mix_HaltGroup(int tag); 493 | 494 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 495 | public static extern int Mix_HaltMusic(); 496 | 497 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 498 | public static extern int Mix_ExpireChannel(int channel, int ticks); 499 | 500 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 501 | public static extern int Mix_FadeOutChannel(int which, int ms); 502 | 503 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 504 | public static extern int Mix_FadeOutGroup(int tag, int ms); 505 | 506 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 507 | public static extern int Mix_FadeOutMusic(int ms); 508 | 509 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 510 | public static extern Mix_Fading Mix_FadingMusic(); 511 | 512 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 513 | public static extern Mix_Fading Mix_FadingChannel(int which); 514 | 515 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 516 | public static extern void Mix_Pause(int channel); 517 | 518 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 519 | public static extern void Mix_Resume(int channel); 520 | 521 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 522 | public static extern int Mix_Paused(int channel); 523 | 524 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 525 | public static extern void Mix_PauseMusic(); 526 | 527 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 528 | public static extern void Mix_ResumeMusic(); 529 | 530 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 531 | public static extern void Mix_RewindMusic(); 532 | 533 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 534 | public static extern int Mix_PausedMusic(); 535 | 536 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 537 | public static extern int Mix_SetMusicPosition(double position); 538 | 539 | /* music refers to a Mix_Music* 540 | * Only available in 2.0.5 or higher. 541 | */ 542 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 543 | public static extern double Mix_GetMusicPosition(IntPtr music); 544 | 545 | /* music refers to a Mix_Music* 546 | * Only available in 2.0.5 or higher. 547 | */ 548 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 549 | public static extern double Mix_MusicDuration(IntPtr music); 550 | 551 | /* music refers to a Mix_Music* 552 | * Only available in 2.0.5 or higher. 553 | */ 554 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 555 | public static extern double Mix_GetMusicLoopStartTime(IntPtr music); 556 | 557 | /* music refers to a Mix_Music* 558 | * Only available in 2.0.5 or higher. 559 | */ 560 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 561 | public static extern double Mix_GetMusicLoopEndTime(IntPtr music); 562 | 563 | /* music refers to a Mix_Music* 564 | * Only available in 2.0.5 or higher. 565 | */ 566 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 567 | public static extern double Mix_GetMusicLoopLengthTime(IntPtr music); 568 | 569 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 570 | public static extern int Mix_Playing(int channel); 571 | 572 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 573 | public static extern int Mix_PlayingMusic(); 574 | 575 | [DllImport(nativeLibName, EntryPoint = "Mix_SetMusicCMD", CallingConvention = CallingConvention.Cdecl)] 576 | private static extern unsafe int INTERNAL_Mix_SetMusicCMD( 577 | byte* command 578 | ); 579 | public static unsafe int Mix_SetMusicCMD(string command) 580 | { 581 | byte* utf8Cmd = SDL.Utf8EncodeHeap(command); 582 | int result = INTERNAL_Mix_SetMusicCMD( 583 | utf8Cmd 584 | ); 585 | Marshal.FreeHGlobal((IntPtr) utf8Cmd); 586 | return result; 587 | } 588 | 589 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 590 | public static extern int Mix_SetSynchroValue(int value); 591 | 592 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 593 | public static extern int Mix_GetSynchroValue(); 594 | 595 | [DllImport(nativeLibName, EntryPoint = "Mix_SetSoundFonts", CallingConvention = CallingConvention.Cdecl)] 596 | private static extern unsafe int INTERNAL_Mix_SetSoundFonts( 597 | byte* paths 598 | ); 599 | public static unsafe int Mix_SetSoundFonts(string paths) 600 | { 601 | byte* utf8Paths = SDL.Utf8EncodeHeap(paths); 602 | int result = INTERNAL_Mix_SetSoundFonts( 603 | utf8Paths 604 | ); 605 | Marshal.FreeHGlobal((IntPtr) utf8Paths); 606 | return result; 607 | } 608 | 609 | [DllImport(nativeLibName, EntryPoint = "Mix_GetSoundFonts", CallingConvention = CallingConvention.Cdecl)] 610 | private static extern IntPtr INTERNAL_Mix_GetSoundFonts(); 611 | public static string Mix_GetSoundFonts() 612 | { 613 | return SDL.UTF8_ToManaged( 614 | INTERNAL_Mix_GetSoundFonts() 615 | ); 616 | } 617 | 618 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 619 | public static extern int Mix_EachSoundFont( 620 | SoundFontDelegate function, 621 | IntPtr data // void* 622 | ); 623 | 624 | /* Only available in 2.0.5 or later. */ 625 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 626 | public static extern int Mix_SetTimidityCfg( 627 | [In()] [MarshalAs(UnmanagedType.LPStr)] 628 | string path 629 | ); 630 | 631 | /* Only available in 2.0.5 or later. */ 632 | [DllImport(nativeLibName, EntryPoint = "Mix_GetTimidityCfg", CallingConvention = CallingConvention.Cdecl)] 633 | public static extern IntPtr INTERNAL_Mix_GetTimidityCfg(); 634 | public static string Mix_GetTimidityCfg() 635 | { 636 | return SDL.UTF8_ToManaged( 637 | INTERNAL_Mix_GetTimidityCfg() 638 | ); 639 | } 640 | 641 | /* IntPtr refers to a Mix_Chunk* */ 642 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 643 | public static extern IntPtr Mix_GetChunk(int channel); 644 | 645 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 646 | public static extern void Mix_CloseAudio(); 647 | 648 | public static string Mix_GetError() 649 | { 650 | return SDL.SDL_GetError(); 651 | } 652 | 653 | public static void Mix_SetError(string fmtAndArglist) 654 | { 655 | SDL.SDL_SetError(fmtAndArglist); 656 | } 657 | 658 | public static void Mix_ClearError() 659 | { 660 | SDL.SDL_ClearError(); 661 | } 662 | 663 | #endregion 664 | } 665 | } 666 | -------------------------------------------------------------------------------- /src/SDL2_ttf.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* SDL2# - C# Wrapper for SDL2 3 | * 4 | * Copyright (c) 2013-2024 Ethan Lee. 5 | * 6 | * This software is provided 'as-is', without any express or implied warranty. 7 | * In no event will the authors be held liable for any damages arising from 8 | * the use of this software. 9 | * 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 14 | * 1. The origin of this software must not be misrepresented; you must not 15 | * claim that you wrote the original software. If you use this software in a 16 | * product, an acknowledgment in the product documentation would be 17 | * appreciated but is not required. 18 | * 19 | * 2. Altered source versions must be plainly marked as such, and must not be 20 | * misrepresented as being the original software. 21 | * 22 | * 3. This notice may not be removed or altered from any source distribution. 23 | * 24 | * Ethan "flibitijibibo" Lee 25 | * 26 | */ 27 | #endregion 28 | 29 | #region Using Statements 30 | using System; 31 | using System.Runtime.InteropServices; 32 | #endregion 33 | 34 | namespace SDL2 35 | { 36 | public static class SDL_ttf 37 | { 38 | #region SDL2# Variables 39 | 40 | /* Used by DllImport to load the native library. */ 41 | private const string nativeLibName = "SDL2_ttf"; 42 | 43 | #endregion 44 | 45 | #region SDL_ttf.h 46 | 47 | /* Similar to the headers, this is the version we're expecting to be 48 | * running with. You will likely want to check this somewhere in your 49 | * program! 50 | */ 51 | public const int SDL_TTF_MAJOR_VERSION = 2; 52 | public const int SDL_TTF_MINOR_VERSION = 0; 53 | public const int SDL_TTF_PATCHLEVEL = 16; 54 | 55 | public const int UNICODE_BOM_NATIVE = 0xFEFF; 56 | public const int UNICODE_BOM_SWAPPED = 0xFFFE; 57 | 58 | public const int TTF_STYLE_NORMAL = 0x00; 59 | public const int TTF_STYLE_BOLD = 0x01; 60 | public const int TTF_STYLE_ITALIC = 0x02; 61 | public const int TTF_STYLE_UNDERLINE = 0x04; 62 | public const int TTF_STYLE_STRIKETHROUGH = 0x08; 63 | 64 | public const int TTF_HINTING_NORMAL = 0; 65 | public const int TTF_HINTING_LIGHT = 1; 66 | public const int TTF_HINTING_MONO = 2; 67 | public const int TTF_HINTING_NONE = 3; 68 | public const int TTF_HINTING_LIGHT_SUBPIXEL = 4; /* >= 2.0.16 */ 69 | 70 | public static void SDL_TTF_VERSION(out SDL.SDL_version X) 71 | { 72 | X.major = SDL_TTF_MAJOR_VERSION; 73 | X.minor = SDL_TTF_MINOR_VERSION; 74 | X.patch = SDL_TTF_PATCHLEVEL; 75 | } 76 | 77 | [DllImport(nativeLibName, EntryPoint = "TTF_LinkedVersion", CallingConvention = CallingConvention.Cdecl)] 78 | private static extern IntPtr INTERNAL_TTF_LinkedVersion(); 79 | public static SDL.SDL_version TTF_LinkedVersion() 80 | { 81 | SDL.SDL_version result; 82 | IntPtr result_ptr = INTERNAL_TTF_LinkedVersion(); 83 | result = SDL.PtrToStructure( 84 | result_ptr 85 | ); 86 | return result; 87 | } 88 | 89 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 90 | public static extern void TTF_ByteSwappedUNICODE(int swapped); 91 | 92 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 93 | public static extern int TTF_Init(); 94 | 95 | /* IntPtr refers to a TTF_Font* */ 96 | [DllImport(nativeLibName, EntryPoint = "TTF_OpenFont", CallingConvention = CallingConvention.Cdecl)] 97 | private static extern unsafe IntPtr INTERNAL_TTF_OpenFont( 98 | byte* file, 99 | int ptsize 100 | ); 101 | public static unsafe IntPtr TTF_OpenFont(string file, int ptsize) 102 | { 103 | byte* utf8File = SDL.Utf8EncodeHeap(file); 104 | IntPtr handle = INTERNAL_TTF_OpenFont( 105 | utf8File, 106 | ptsize 107 | ); 108 | Marshal.FreeHGlobal((IntPtr) utf8File); 109 | return handle; 110 | } 111 | 112 | /* src refers to an SDL_RWops*, IntPtr to a TTF_Font* */ 113 | /* THIS IS A PUBLIC RWops FUNCTION! */ 114 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 115 | public static extern IntPtr TTF_OpenFontRW( 116 | IntPtr src, 117 | int freesrc, 118 | int ptsize 119 | ); 120 | 121 | /* IntPtr refers to a TTF_Font* */ 122 | [DllImport(nativeLibName, EntryPoint = "TTF_OpenFontIndex", CallingConvention = CallingConvention.Cdecl)] 123 | private static extern unsafe IntPtr INTERNAL_TTF_OpenFontIndex( 124 | byte* file, 125 | int ptsize, 126 | long index 127 | ); 128 | public static unsafe IntPtr TTF_OpenFontIndex( 129 | string file, 130 | int ptsize, 131 | long index 132 | ) { 133 | byte* utf8File = SDL.Utf8EncodeHeap(file); 134 | IntPtr handle = INTERNAL_TTF_OpenFontIndex( 135 | utf8File, 136 | ptsize, 137 | index 138 | ); 139 | Marshal.FreeHGlobal((IntPtr) utf8File); 140 | return handle; 141 | } 142 | 143 | /* src refers to an SDL_RWops*, IntPtr to a TTF_Font* */ 144 | /* THIS IS A PUBLIC RWops FUNCTION! */ 145 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 146 | public static extern IntPtr TTF_OpenFontIndexRW( 147 | IntPtr src, 148 | int freesrc, 149 | int ptsize, 150 | long index 151 | ); 152 | 153 | /* font refers to a TTF_Font* 154 | * Only available in 2.0.16 or higher. 155 | */ 156 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 157 | public static extern int TTF_SetFontSize( 158 | IntPtr font, 159 | int ptsize 160 | ); 161 | 162 | /* font refers to a TTF_Font* */ 163 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 164 | public static extern int TTF_GetFontStyle(IntPtr font); 165 | 166 | /* font refers to a TTF_Font* */ 167 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 168 | public static extern void TTF_SetFontStyle(IntPtr font, int style); 169 | 170 | /* font refers to a TTF_Font* */ 171 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 172 | public static extern int TTF_GetFontOutline(IntPtr font); 173 | 174 | /* font refers to a TTF_Font* */ 175 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 176 | public static extern void TTF_SetFontOutline(IntPtr font, int outline); 177 | 178 | /* font refers to a TTF_Font* */ 179 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 180 | public static extern int TTF_GetFontHinting(IntPtr font); 181 | 182 | /* font refers to a TTF_Font* */ 183 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 184 | public static extern void TTF_SetFontHinting(IntPtr font, int hinting); 185 | 186 | /* font refers to a TTF_Font* */ 187 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 188 | public static extern int TTF_FontHeight(IntPtr font); 189 | 190 | /* font refers to a TTF_Font* */ 191 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 192 | public static extern int TTF_FontAscent(IntPtr font); 193 | 194 | /* font refers to a TTF_Font* */ 195 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 196 | public static extern int TTF_FontDescent(IntPtr font); 197 | 198 | /* font refers to a TTF_Font* */ 199 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 200 | public static extern int TTF_FontLineSkip(IntPtr font); 201 | 202 | /* font refers to a TTF_Font* */ 203 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 204 | public static extern int TTF_GetFontKerning(IntPtr font); 205 | 206 | /* font refers to a TTF_Font* */ 207 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 208 | public static extern void TTF_SetFontKerning(IntPtr font, int allowed); 209 | 210 | /* font refers to a TTF_Font*. 211 | * IntPtr is actually a C long! This ignores Win64! 212 | */ 213 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 214 | public static extern IntPtr TTF_FontFaces(IntPtr font); 215 | 216 | /* font refers to a TTF_Font* */ 217 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 218 | public static extern int TTF_FontFaceIsFixedWidth(IntPtr font); 219 | 220 | /* font refers to a TTF_Font* */ 221 | [DllImport(nativeLibName, EntryPoint = "TTF_FontFaceFamilyName", CallingConvention = CallingConvention.Cdecl)] 222 | private static extern IntPtr INTERNAL_TTF_FontFaceFamilyName( 223 | IntPtr font 224 | ); 225 | public static string TTF_FontFaceFamilyName(IntPtr font) 226 | { 227 | return SDL.UTF8_ToManaged( 228 | INTERNAL_TTF_FontFaceFamilyName(font) 229 | ); 230 | } 231 | 232 | /* font refers to a TTF_Font* */ 233 | [DllImport(nativeLibName, EntryPoint = "TTF_FontFaceStyleName", CallingConvention = CallingConvention.Cdecl)] 234 | private static extern IntPtr INTERNAL_TTF_FontFaceStyleName( 235 | IntPtr font 236 | ); 237 | public static string TTF_FontFaceStyleName(IntPtr font) 238 | { 239 | return SDL.UTF8_ToManaged( 240 | INTERNAL_TTF_FontFaceStyleName(font) 241 | ); 242 | } 243 | 244 | /* font refers to a TTF_Font* */ 245 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 246 | public static extern int TTF_GlyphIsProvided(IntPtr font, ushort ch); 247 | 248 | /* font refers to a TTF_Font* 249 | * Only available in 2.0.16 or higher. 250 | */ 251 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 252 | public static extern int TTF_GlyphIsProvided32(IntPtr font, uint ch); 253 | 254 | /* font refers to a TTF_Font* */ 255 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 256 | public static extern int TTF_GlyphMetrics( 257 | IntPtr font, 258 | ushort ch, 259 | out int minx, 260 | out int maxx, 261 | out int miny, 262 | out int maxy, 263 | out int advance 264 | ); 265 | 266 | /* font refers to a TTF_Font* 267 | * Only available in 2.0.16 or higher. 268 | */ 269 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 270 | public static extern int TTF_GlyphMetrics32( 271 | IntPtr font, 272 | uint ch, 273 | out int minx, 274 | out int maxx, 275 | out int miny, 276 | out int maxy, 277 | out int advance 278 | ); 279 | 280 | /* font refers to a TTF_Font* */ 281 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 282 | public static extern int TTF_SizeText( 283 | IntPtr font, 284 | [In()] [MarshalAs(UnmanagedType.LPStr)] 285 | string text, 286 | out int w, 287 | out int h 288 | ); 289 | 290 | /* font refers to a TTF_Font* */ 291 | [DllImport(nativeLibName, EntryPoint = "TTF_SizeUTF8", CallingConvention = CallingConvention.Cdecl)] 292 | public static extern unsafe int INTERNAL_TTF_SizeUTF8( 293 | IntPtr font, 294 | byte* text, 295 | out int w, 296 | out int h 297 | ); 298 | public static unsafe int TTF_SizeUTF8( 299 | IntPtr font, 300 | string text, 301 | out int w, 302 | out int h 303 | ) { 304 | byte* utf8Text = SDL.Utf8EncodeHeap(text); 305 | int result = INTERNAL_TTF_SizeUTF8( 306 | font, 307 | utf8Text, 308 | out w, 309 | out h 310 | ); 311 | Marshal.FreeHGlobal((IntPtr) utf8Text); 312 | return result; 313 | } 314 | 315 | /* font refers to a TTF_Font* */ 316 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 317 | public static extern int TTF_SizeUNICODE( 318 | IntPtr font, 319 | [In()] [MarshalAs(UnmanagedType.LPWStr)] 320 | string text, 321 | out int w, 322 | out int h 323 | ); 324 | 325 | /* font refers to a TTF_Font* 326 | * Only available in 2.0.16 or higher. 327 | */ 328 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 329 | public static extern int TTF_MeasureText( 330 | IntPtr font, 331 | [In()] [MarshalAs(UnmanagedType.LPStr)] 332 | string text, 333 | int measure_width, 334 | out int extent, 335 | out int count 336 | ); 337 | 338 | /* font refers to a TTF_Font* 339 | * Only available in 2.0.16 or higher. 340 | */ 341 | [DllImport(nativeLibName, EntryPoint = "TTF_MeasureUTF8", CallingConvention = CallingConvention.Cdecl)] 342 | public static extern unsafe int INTERNAL_TTF_MeasureUTF8( 343 | IntPtr font, 344 | byte* text, 345 | int measure_width, 346 | out int extent, 347 | out int count 348 | ); 349 | public static unsafe int TTF_MeasureUTF8( 350 | IntPtr font, 351 | string text, 352 | int measure_width, 353 | out int extent, 354 | out int count 355 | ) { 356 | byte* utf8Text = SDL.Utf8EncodeHeap(text); 357 | int result = INTERNAL_TTF_MeasureUTF8( 358 | font, 359 | utf8Text, 360 | measure_width, 361 | out extent, 362 | out count 363 | ); 364 | Marshal.FreeHGlobal((IntPtr) utf8Text); 365 | return result; 366 | } 367 | 368 | /* font refers to a TTF_Font* 369 | * Only available in 2.0.16 or higher. 370 | */ 371 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 372 | public static extern int TTF_MeasureUNICODE( 373 | IntPtr font, 374 | [In()] [MarshalAs(UnmanagedType.LPWStr)] 375 | string text, 376 | int measure_width, 377 | out int extent, 378 | out int count 379 | ); 380 | 381 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 382 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 383 | public static extern IntPtr TTF_RenderText_Solid( 384 | IntPtr font, 385 | [In()] [MarshalAs(UnmanagedType.LPStr)] 386 | string text, 387 | SDL.SDL_Color fg 388 | ); 389 | 390 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 391 | [DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Solid", CallingConvention = CallingConvention.Cdecl)] 392 | private static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Solid( 393 | IntPtr font, 394 | byte* text, 395 | SDL.SDL_Color fg 396 | ); 397 | public static unsafe IntPtr TTF_RenderUTF8_Solid( 398 | IntPtr font, 399 | string text, 400 | SDL.SDL_Color fg 401 | ) { 402 | byte* utf8Text = SDL.Utf8EncodeHeap(text); 403 | IntPtr result = INTERNAL_TTF_RenderUTF8_Solid( 404 | font, 405 | utf8Text, 406 | fg 407 | ); 408 | Marshal.FreeHGlobal((IntPtr) utf8Text); 409 | return result; 410 | } 411 | 412 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 413 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 414 | public static extern IntPtr TTF_RenderUNICODE_Solid( 415 | IntPtr font, 416 | [In()] [MarshalAs(UnmanagedType.LPWStr)] 417 | string text, 418 | SDL.SDL_Color fg 419 | ); 420 | 421 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* 422 | * Only available in 2.0.16 or higher. 423 | */ 424 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 425 | public static extern IntPtr TTF_RenderText_Solid_Wrapped( 426 | IntPtr font, 427 | [In()] [MarshalAs(UnmanagedType.LPStr)] 428 | string text, 429 | SDL.SDL_Color fg, 430 | uint wrapLength 431 | ); 432 | 433 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* 434 | * Only available in 2.0.16 or higher. 435 | */ 436 | [DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Solid_Wrapped", CallingConvention = CallingConvention.Cdecl)] 437 | public static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Solid_Wrapped( 438 | IntPtr font, 439 | byte* text, 440 | SDL.SDL_Color fg, 441 | uint wrapLength 442 | ); 443 | public static unsafe IntPtr TTF_RenderUTF8_Solid_Wrapped( 444 | IntPtr font, 445 | string text, 446 | SDL.SDL_Color fg, 447 | uint wrapLength 448 | ) { 449 | byte* utf8Text = SDL.Utf8EncodeHeap(text); 450 | IntPtr result = INTERNAL_TTF_RenderUTF8_Solid_Wrapped( 451 | font, 452 | utf8Text, 453 | fg, 454 | wrapLength 455 | ); 456 | Marshal.FreeHGlobal((IntPtr) utf8Text); 457 | return result; 458 | } 459 | 460 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* 461 | * Only available in 2.0.16 or higher. 462 | */ 463 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 464 | public static extern IntPtr TTF_RenderUNICODE_Solid_Wrapped( 465 | IntPtr font, 466 | [In()] [MarshalAs(UnmanagedType.LPWStr)] 467 | string text, 468 | SDL.SDL_Color fg, 469 | uint wrapLength 470 | ); 471 | 472 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 473 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 474 | public static extern IntPtr TTF_RenderGlyph_Solid( 475 | IntPtr font, 476 | ushort ch, 477 | SDL.SDL_Color fg 478 | ); 479 | 480 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* 481 | * Only available in 2.0.16 or higher. 482 | */ 483 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 484 | public static extern IntPtr TTF_RenderGlyph32_Solid( 485 | IntPtr font, 486 | uint ch, 487 | SDL.SDL_Color fg 488 | ); 489 | 490 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 491 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 492 | public static extern IntPtr TTF_RenderText_Shaded( 493 | IntPtr font, 494 | [In()] [MarshalAs(UnmanagedType.LPStr)] 495 | string text, 496 | SDL.SDL_Color fg, 497 | SDL.SDL_Color bg 498 | ); 499 | 500 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 501 | [DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Shaded", CallingConvention = CallingConvention.Cdecl)] 502 | private static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Shaded( 503 | IntPtr font, 504 | byte* text, 505 | SDL.SDL_Color fg, 506 | SDL.SDL_Color bg 507 | ); 508 | public static unsafe IntPtr TTF_RenderUTF8_Shaded( 509 | IntPtr font, 510 | string text, 511 | SDL.SDL_Color fg, 512 | SDL.SDL_Color bg 513 | ) { 514 | byte* utf8Text = SDL.Utf8EncodeHeap(text); 515 | IntPtr result = INTERNAL_TTF_RenderUTF8_Shaded( 516 | font, 517 | utf8Text, 518 | fg, 519 | bg 520 | ); 521 | Marshal.FreeHGlobal((IntPtr) utf8Text); 522 | return result; 523 | } 524 | 525 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 526 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 527 | public static extern IntPtr TTF_RenderUNICODE_Shaded( 528 | IntPtr font, 529 | [In()] [MarshalAs(UnmanagedType.LPWStr)] 530 | string text, 531 | SDL.SDL_Color fg, 532 | SDL.SDL_Color bg 533 | ); 534 | 535 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 536 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 537 | public static extern IntPtr TTF_RenderText_Shaded_Wrapped( 538 | IntPtr font, 539 | [In()] [MarshalAs(UnmanagedType.LPStr)] 540 | string text, 541 | SDL.SDL_Color fg, 542 | SDL.SDL_Color bg, 543 | uint wrapLength 544 | ); 545 | 546 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* 547 | * Only available in 2.0.16 or higher. 548 | */ 549 | [DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Shaded_Wrapped", CallingConvention = CallingConvention.Cdecl)] 550 | public static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Shaded_Wrapped( 551 | IntPtr font, 552 | byte* text, 553 | SDL.SDL_Color fg, 554 | SDL.SDL_Color bg, 555 | uint wrapLength 556 | ); 557 | public static unsafe IntPtr TTF_RenderUTF8_Shaded_Wrapped( 558 | IntPtr font, 559 | string text, 560 | SDL.SDL_Color fg, 561 | SDL.SDL_Color bg, 562 | uint wrapLength 563 | ) { 564 | byte* utf8Text = SDL.Utf8EncodeHeap(text); 565 | IntPtr result = INTERNAL_TTF_RenderUTF8_Shaded_Wrapped( 566 | font, 567 | utf8Text, 568 | fg, 569 | bg, 570 | wrapLength 571 | ); 572 | Marshal.FreeHGlobal((IntPtr) utf8Text); 573 | return result; 574 | } 575 | 576 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 577 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 578 | public static extern IntPtr TTF_RenderUNICODE_Shaded_Wrapped( 579 | IntPtr font, 580 | [In()] [MarshalAs(UnmanagedType.LPWStr)] 581 | string text, 582 | SDL.SDL_Color fg, 583 | SDL.SDL_Color bg, 584 | uint wrapLength 585 | ); 586 | 587 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 588 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 589 | public static extern IntPtr TTF_RenderGlyph_Shaded( 590 | IntPtr font, 591 | ushort ch, 592 | SDL.SDL_Color fg, 593 | SDL.SDL_Color bg 594 | ); 595 | 596 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* 597 | * Only available in 2.0.16 or higher. 598 | */ 599 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 600 | public static extern IntPtr TTF_RenderGlyph32_Shaded( 601 | IntPtr font, 602 | uint ch, 603 | SDL.SDL_Color fg, 604 | SDL.SDL_Color bg 605 | ); 606 | 607 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 608 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 609 | public static extern IntPtr TTF_RenderText_Blended( 610 | IntPtr font, 611 | [In()] [MarshalAs(UnmanagedType.LPStr)] 612 | string text, 613 | SDL.SDL_Color fg 614 | ); 615 | 616 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 617 | [DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Blended", CallingConvention = CallingConvention.Cdecl)] 618 | private static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Blended( 619 | IntPtr font, 620 | byte* text, 621 | SDL.SDL_Color fg 622 | ); 623 | public static unsafe IntPtr TTF_RenderUTF8_Blended( 624 | IntPtr font, 625 | string text, 626 | SDL.SDL_Color fg 627 | ) { 628 | byte* utf8Text = SDL.Utf8EncodeHeap(text); 629 | IntPtr result = INTERNAL_TTF_RenderUTF8_Blended( 630 | font, 631 | utf8Text, 632 | fg 633 | ); 634 | Marshal.FreeHGlobal((IntPtr) utf8Text); 635 | return result; 636 | } 637 | 638 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 639 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 640 | public static extern IntPtr TTF_RenderUNICODE_Blended( 641 | IntPtr font, 642 | [In()] [MarshalAs(UnmanagedType.LPWStr)] 643 | string text, 644 | SDL.SDL_Color fg 645 | ); 646 | 647 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 648 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 649 | public static extern IntPtr TTF_RenderText_Blended_Wrapped( 650 | IntPtr font, 651 | [In()] [MarshalAs(UnmanagedType.LPStr)] 652 | string text, 653 | SDL.SDL_Color fg, 654 | uint wrapped 655 | ); 656 | 657 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 658 | [DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Blended_Wrapped", CallingConvention = CallingConvention.Cdecl)] 659 | private static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Blended_Wrapped( 660 | IntPtr font, 661 | byte* text, 662 | SDL.SDL_Color fg, 663 | uint wrapped 664 | ); 665 | public static unsafe IntPtr TTF_RenderUTF8_Blended_Wrapped( 666 | IntPtr font, 667 | string text, 668 | SDL.SDL_Color fg, 669 | uint wrapped 670 | ) { 671 | byte* utf8Text = SDL.Utf8EncodeHeap(text); 672 | IntPtr result = INTERNAL_TTF_RenderUTF8_Blended_Wrapped( 673 | font, 674 | utf8Text, 675 | fg, 676 | wrapped 677 | ); 678 | Marshal.FreeHGlobal((IntPtr) utf8Text); 679 | return result; 680 | } 681 | 682 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 683 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 684 | public static extern IntPtr TTF_RenderUNICODE_Blended_Wrapped( 685 | IntPtr font, 686 | [In()] [MarshalAs(UnmanagedType.LPWStr)] 687 | string text, 688 | SDL.SDL_Color fg, 689 | uint wrapped 690 | ); 691 | 692 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ 693 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 694 | public static extern IntPtr TTF_RenderGlyph_Blended( 695 | IntPtr font, 696 | ushort ch, 697 | SDL.SDL_Color fg 698 | ); 699 | 700 | /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* 701 | * Only available in 2.0.16 or higher. 702 | */ 703 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 704 | public static extern IntPtr TTF_RenderGlyph32_Blended( 705 | IntPtr font, 706 | uint ch, 707 | SDL.SDL_Color fg 708 | ); 709 | 710 | /* Only available in 2.0.16 or higher. */ 711 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 712 | public static extern int TTF_SetDirection(int direction); 713 | 714 | /* Only available in 2.0.16 or higher. */ 715 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 716 | public static extern int TTF_SetScript(int script); 717 | 718 | /* font refers to a TTF_Font* */ 719 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 720 | public static extern void TTF_CloseFont(IntPtr font); 721 | 722 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 723 | public static extern void TTF_Quit(); 724 | 725 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 726 | public static extern int TTF_WasInit(); 727 | 728 | /* font refers to a TTF_Font* */ 729 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 730 | public static extern int SDL_GetFontKerningSize( 731 | IntPtr font, 732 | int prev_index, 733 | int index 734 | ); 735 | 736 | /* font refers to a TTF_Font* 737 | * Only available in 2.0.15 or higher. 738 | */ 739 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 740 | public static extern int TTF_GetFontKerningSizeGlyphs( 741 | IntPtr font, 742 | ushort previous_ch, 743 | ushort ch 744 | ); 745 | 746 | /* font refers to a TTF_Font* 747 | * Only available in 2.0.16 or higher. 748 | */ 749 | [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] 750 | public static extern int TTF_GetFontKerningSizeGlyphs32( 751 | IntPtr font, 752 | ushort previous_ch, 753 | ushort ch 754 | ); 755 | 756 | public static string TTF_GetError() 757 | { 758 | return SDL.SDL_GetError(); 759 | } 760 | 761 | public static void TTF_SetError(string fmtAndArglist) 762 | { 763 | SDL.SDL_SetError(fmtAndArglist); 764 | } 765 | 766 | #endregion 767 | } 768 | } 769 | --------------------------------------------------------------------------------