Began implementing windows handle, game state manager, and game loop.
This commit is contained in:
parent
8ee18b1fcf
commit
bd6b085687
27
.vscode/launch.json
vendored
Normal file
27
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||
// Use hover for the description of the existing attributes
|
||||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
// If you have changed target frameworks, make sure to update the program path.
|
||||
"program": "${workspaceFolder}/src/SlatedGameToolkit.Tools/bin/Debug/netcoreapp3.1/SlatedGameToolkit.Tools.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/src/SlatedGameToolkit.Tools",
|
||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||
"console": "internalConsole",
|
||||
"stopAtEntry": false
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command:pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
42
.vscode/tasks.json
vendored
Normal file
42
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/src/SlatedGameToolkit.Tools/SlatedGameToolkit.Tools.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "publish",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/src/SlatedGameToolkit.Tools/SlatedGameToolkit.Tools.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "watch",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"${workspaceFolder}/src/SlatedGameToolkit.Tools/SlatedGameToolkit.Tools.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace SlatedGameToolkit.Framework
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
}
|
||||
}
|
67
src/SlatedGameToolkit.Framework/DataTypes/FloatRectangle.cs
Normal file
67
src/SlatedGameToolkit.Framework/DataTypes/FloatRectangle.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
|
||||
namespace SlatedGameToolkit.Framework.DataTypes
|
||||
{
|
||||
public struct FloatRectangle {
|
||||
public FloatVector2 BottomLeft, TopRight;
|
||||
|
||||
public float Width {
|
||||
get {
|
||||
return Math.Abs(BottomLeft.x - TopRight.x);
|
||||
}
|
||||
set {
|
||||
TopRight.x = BottomLeft.x + value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Height {
|
||||
get {
|
||||
return Math.Abs(BottomLeft.y - TopRight.y);
|
||||
}
|
||||
set {
|
||||
TopRight.y = BottomLeft.y + value;
|
||||
}
|
||||
}
|
||||
|
||||
public float X1 {
|
||||
get {
|
||||
return BottomLeft.x;
|
||||
}
|
||||
|
||||
set {
|
||||
BottomLeft.x = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float X2 {
|
||||
get {
|
||||
return TopRight.x;
|
||||
}
|
||||
|
||||
set {
|
||||
TopRight.x = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Y1 {
|
||||
get {
|
||||
return BottomLeft.y;
|
||||
}
|
||||
|
||||
set {
|
||||
BottomLeft.y = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Y2 {
|
||||
get {
|
||||
return TopRight.y;
|
||||
}
|
||||
|
||||
set {
|
||||
TopRight.y = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace SlatedGameToolkit.Framework.DataTypes
|
||||
{
|
||||
public struct FloatVector2 {
|
||||
public volatile float x, y;
|
||||
}
|
||||
}
|
35
src/SlatedGameToolkit.Framework/Exceptions/SDLException.cs
Normal file
35
src/SlatedGameToolkit.Framework/Exceptions/SDLException.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using SDL2;
|
||||
|
||||
namespace SlatedGameToolkit.Framework.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// An SDLException is defined as an exception that is thrown whenever an error occurrs in any SDL functions.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class SDLException : Exception {
|
||||
public string SDLMessage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates an SDL exception.
|
||||
/// </summary>
|
||||
/// <param name="Fetch">Whether or not to fetch the last error message that occurred in SDL.</param>
|
||||
public SDLException(bool autoFlush = true) : base() {
|
||||
if (autoFlush) {
|
||||
SDLMessage = SDL.SDL_GetError();
|
||||
SDL.SDL_ClearError();
|
||||
}
|
||||
}
|
||||
|
||||
public SDLException(string message, Exception inner) : base(message, inner) {
|
||||
|
||||
}
|
||||
|
||||
public SDLException(string message, bool autoFlush = true) : base(message) {
|
||||
if (autoFlush) {
|
||||
SDLMessage = SDL.SDL_GetError();
|
||||
SDL.SDL_ClearError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace SlatedGameToolkit.Framework.Exceptions
|
||||
{
|
||||
public class SlatedGameToolkitException : Exception {
|
||||
public SlatedGameToolkitException() {
|
||||
|
||||
}
|
||||
|
||||
public SlatedGameToolkitException(string message) : base(message) {
|
||||
|
||||
}
|
||||
|
||||
public SlatedGameToolkitException(string message, Exception inner) : base(message, inner) {
|
||||
}
|
||||
}
|
||||
}
|
130
src/SlatedGameToolkit.Framework/GameEngine.cs
Normal file
130
src/SlatedGameToolkit.Framework/GameEngine.cs
Normal file
@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using SDL2;
|
||||
using Serilog;
|
||||
using Serilog.Core;
|
||||
using SlatedGameToolkit.Framework.Exceptions;
|
||||
using SlatedGameToolkit.Framework.StateSystem;
|
||||
using SlatedGameToolkit.Framework.Window;
|
||||
|
||||
namespace SlatedGameToolkit.Framework {
|
||||
/// <summary>
|
||||
/// The main engine that will host the game loop.
|
||||
/// </summary>
|
||||
public static class GameEngine {
|
||||
public static readonly Logger logger = new LoggerConfiguration().
|
||||
WriteTo.Console().
|
||||
WriteTo.File("SlatedGameToolKit.Framework.Log").
|
||||
CreateLogger();
|
||||
private static readonly object ignitionLock = new object();
|
||||
private static Thread thread;
|
||||
private static volatile bool exit = false, loopCompleted = true;
|
||||
private static long updateDeltaTime = 50, frameDeltaTime = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of updates per second.
|
||||
/// Is floored to milleseconds.
|
||||
/// </summary>
|
||||
/// <value>The updates per second.</value>
|
||||
public static double UpdatesPerSecond {
|
||||
get {
|
||||
return TimeSpan.FromMilliseconds(1 / updateDeltaTime).TotalSeconds;
|
||||
}
|
||||
set {
|
||||
Interlocked.Exchange(ref updateDeltaTime, (long) TimeSpan.FromSeconds(1 / value).TotalMilliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The target frames per second. Will not go above this number, but may dip below this number.
|
||||
/// This value is floored to millesconds.
|
||||
/// </summary>
|
||||
/// <value>The target frames per second.</value>
|
||||
public static double targetFPS {
|
||||
get {
|
||||
return TimeSpan.FromMilliseconds(1 / frameDeltaTime).TotalSeconds;
|
||||
}
|
||||
set {
|
||||
Interlocked.Exchange(ref frameDeltaTime, (long) TimeSpan.FromSeconds(1 / value).TotalMilliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Loop(Object o) {
|
||||
if (!(o is Manager)) throw new ArgumentException("The passed object needs to be of type manager.");
|
||||
Manager manager = (Manager) o;
|
||||
long currentTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
long timePassedFromLastUpdate = 0;
|
||||
long timePassedFromLastRender = 0;
|
||||
loopCompleted = false;
|
||||
while (!exit) {
|
||||
long updateDeltaTime = Interlocked.Read(ref GameEngine.updateDeltaTime);
|
||||
long frameDeltaTime = Interlocked.Read(ref GameEngine.frameDeltaTime);
|
||||
long frameStart = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
long difference = frameStart - currentTime;
|
||||
currentTime = frameStart;
|
||||
|
||||
timePassedFromLastUpdate += difference;
|
||||
while (timePassedFromLastUpdate > updateDeltaTime) {
|
||||
manager.update(updateDeltaTime);
|
||||
timePassedFromLastUpdate -= updateDeltaTime;
|
||||
}
|
||||
|
||||
timePassedFromLastRender += difference;
|
||||
if (timePassedFromLastRender > frameDeltaTime) {
|
||||
manager.render(timePassedFromLastUpdate / updateDeltaTime);
|
||||
timePassedFromLastRender = 0;
|
||||
}
|
||||
}
|
||||
loopCompleted = true;
|
||||
SDL.SDL_Quit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requests to stop the game engine.
|
||||
/// Game engine will finish the frame its currently in.
|
||||
/// This needs to be called to perform proper clean up.
|
||||
/// </summary>
|
||||
/// <returns>False if the stop request has already been made.</returns>
|
||||
public static bool Stop() {
|
||||
lock (ignitionLock) {
|
||||
if (exit) return false;
|
||||
exit = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requests to start the game engine.
|
||||
/// </summary>
|
||||
/// <returns>True iff the engine is not already running.</returns>
|
||||
private static bool Ignite(Manager manager) {
|
||||
if (manager == null) throw new ArgumentNullException("manager");
|
||||
SDL.SDL_version SDLVersion;
|
||||
SDL.SDL_version SDLBuiltVersion;
|
||||
SDL.SDL_GetVersion(out SDLVersion);
|
||||
SDL.SDL_VERSION(out SDLBuiltVersion);
|
||||
logger.Information(String.Format("Attempting to initiate game engine with SDL version: {0}", SDLVersion.ToString()));
|
||||
if (SDL.SDL_VERSION_ATLEAST(SDLBuiltVersion.major, SDLBuiltVersion.minor, SDLBuiltVersion.patch)) {
|
||||
logger.Warning(String.Format("Engine was designed with SDL version {0}, currently running on {1}", SDLVersion.ToString(), SDLBuiltVersion.ToString()));
|
||||
if (SDLVersion.major < 2) {
|
||||
logger.Error("This engine was designed to work with SDL2. The version you're currently running is severely outdated.");
|
||||
throw new SlatedGameToolkitException("Outdated SDL binaries.");
|
||||
}
|
||||
}
|
||||
lock (ignitionLock) {
|
||||
if (!loopCompleted) return false;
|
||||
loopCompleted = false;
|
||||
exit = false;
|
||||
if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO) != 0) {
|
||||
throw new SDLException();
|
||||
}
|
||||
if (SDL.SDL_Init(SDL.SDL_INIT_AUDIO) != 0) {
|
||||
throw new SDLException();
|
||||
}
|
||||
thread = new Thread(Loop);
|
||||
thread.Start(manager);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
144
src/SlatedGameToolkit.Framework/Graphics/Window/WindowHandle.cs
Normal file
144
src/SlatedGameToolkit.Framework/Graphics/Window/WindowHandle.cs
Normal file
@ -0,0 +1,144 @@
|
||||
using System;
|
||||
using SDL2;
|
||||
using SlatedGameToolkit.Framework.DataTypes;
|
||||
using SlatedGameToolkit.Framework.Exceptions;
|
||||
|
||||
namespace SlatedGameToolkit.Framework.Graphics.Window
|
||||
{
|
||||
public sealed class WindowHandle : IDisposable
|
||||
{
|
||||
public readonly IntPtr window;
|
||||
IntPtr windowSurfaceHandle;
|
||||
|
||||
public bool Shown {
|
||||
set {
|
||||
if (value) {
|
||||
SDL.SDL_ShowWindow(window);
|
||||
} else {
|
||||
SDL.SDL_HideWindow(window);
|
||||
}
|
||||
}
|
||||
|
||||
get {
|
||||
return ((SDL.SDL_WindowFlags) Enum.Parse(typeof(SDL.SDL_WindowFlags), SDL.SDL_GetWindowFlags(window).ToString())).HasFlag(SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN);
|
||||
}
|
||||
}
|
||||
|
||||
public string WindowTitle {
|
||||
set {
|
||||
SDL.SDL_SetWindowTitle(window, value);
|
||||
}
|
||||
|
||||
get {
|
||||
return SDL.SDL_GetWindowTitle(window);
|
||||
}
|
||||
}
|
||||
|
||||
public bool WindowBordered {
|
||||
set {
|
||||
SDL.SDL_SetWindowBordered(window, value ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE);
|
||||
}
|
||||
|
||||
get {
|
||||
int top, bottom, left, right;
|
||||
int errorCode = SDL.SDL_GetWindowBordersSize(window, out top, out left, out bottom, out right);
|
||||
if (errorCode < 0) throw new SDLException();
|
||||
return top > 0 || bottom > 0 || left > 0 || right > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public bool WindowResizable {
|
||||
set {
|
||||
SDL.SDL_SetWindowResizable(window, value ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE);
|
||||
}
|
||||
get {
|
||||
return ((SDL.SDL_WindowFlags) Enum.Parse(typeof(SDL.SDL_WindowFlags), SDL.SDL_GetWindowFlags(window).ToString())).HasFlag(SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE);
|
||||
}
|
||||
}
|
||||
|
||||
public FloatRectangle WindowBoundaries {
|
||||
set {
|
||||
SDL.SDL_SetWindowPosition(window, (int)value.X1, (int)value.Y1);
|
||||
SDL.SDL_SetWindowSize(window, (int)value.Width, (int)value.Height);
|
||||
}
|
||||
get {
|
||||
int x, y, width, height;
|
||||
SDL.SDL_GetWindowSize(window, out x, out y);
|
||||
SDL.SDL_GetWindowPosition(window, out width, out height);
|
||||
FloatRectangle rectangle = new FloatRectangle();
|
||||
rectangle.X1 = x;
|
||||
rectangle.Y2 = y;
|
||||
rectangle.Width = width;
|
||||
rectangle.Height = height;
|
||||
|
||||
return rectangle;
|
||||
}
|
||||
}
|
||||
|
||||
public FloatVector2 MaximumSize {
|
||||
set {
|
||||
SDL.SDL_SetWindowMaximumSize(window, (int)value.x, (int)value.y);
|
||||
}
|
||||
get {
|
||||
int width, height;
|
||||
SDL.SDL_GetWindowMaximumSize(window, out width, out height);
|
||||
FloatVector2 maxSize = new FloatVector2();
|
||||
maxSize.x = width;
|
||||
maxSize.y = height;
|
||||
return maxSize;
|
||||
}
|
||||
}
|
||||
|
||||
public float Opacity {
|
||||
set {
|
||||
int errorCode = SDL.SDL_SetWindowOpacity(window, value);
|
||||
if (errorCode < 0) throw new SDLException();
|
||||
}
|
||||
get {
|
||||
float value;
|
||||
int errorCode = SDL.SDL_GetWindowOpacity(window, out value);
|
||||
if (errorCode < 0) throw new SDLException();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public FloatVector2 MinimumSize {
|
||||
set {
|
||||
SDL.SDL_SetWindowMinimumSize(window, (int)value.x, (int)value.y);
|
||||
}
|
||||
get {
|
||||
int width, height;
|
||||
SDL.SDL_GetWindowMinimumSize(window, out width, out height);
|
||||
FloatVector2 maxSize = new FloatVector2();
|
||||
maxSize.x = width;
|
||||
maxSize.y = height;
|
||||
return maxSize;
|
||||
}
|
||||
}
|
||||
|
||||
public WindowHandle(string title, int x, int y, int width, int height, WindowOptions options) {
|
||||
window = SDL.SDL_CreateWindow(title, x, y, width, height, SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL | options.ToSDLWindowFlag());
|
||||
windowSurfaceHandle = SDL.SDL_GetWindowSurface(window);
|
||||
}
|
||||
|
||||
public void RaiseToTop() {
|
||||
SDL.SDL_RaiseWindow(window);
|
||||
}
|
||||
|
||||
public int GetDisplayIndex() {
|
||||
int index = SDL.SDL_GetWindowDisplayIndex(window);
|
||||
if (index < 0) throw new SDLException();
|
||||
return index;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
SDL.SDL_FreeSurface(windowSurfaceHandle);
|
||||
SDL.SDL_DestroyWindow(window);
|
||||
}
|
||||
|
||||
~WindowHandle() {
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using SDL2;
|
||||
|
||||
namespace SlatedGameToolkit.Framework.Graphics.Window
|
||||
{
|
||||
public enum WindowOptions : uint
|
||||
{
|
||||
HIGH_DPI = SDL.SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI,
|
||||
HIDDEN = SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN,
|
||||
}
|
||||
internal static class WindowOptionsExtension {
|
||||
public static SDL.SDL_WindowFlags ToSDLWindowFlag(this WindowOptions options) {
|
||||
SDL.SDL_WindowFlags sdlFlag;
|
||||
Enum.TryParse(((uint) options).ToString(), out sdlFlag);
|
||||
return sdlFlag;
|
||||
}
|
||||
}
|
||||
}
|
13
src/SlatedGameToolkit.Framework/Input/InputMatrix.cs
Normal file
13
src/SlatedGameToolkit.Framework/Input/InputMatrix.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using SDL2;
|
||||
|
||||
namespace SlatedGameToolkit.Framework.Input
|
||||
{
|
||||
internal class InputMatrix {
|
||||
public void update() {
|
||||
SDL.SDL_Event inputEvent;
|
||||
while (SDL.SDL_PollEvent(out inputEvent) != 0) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
7833
src/SlatedGameToolkit.Framework/SDL2-bindings/SDL2.cs
Normal file
7833
src/SlatedGameToolkit.Framework/SDL2-bindings/SDL2.cs
Normal file
File diff suppressed because it is too large
Load Diff
307
src/SlatedGameToolkit.Framework/SDL2-bindings/SDL2_image.cs
Normal file
307
src/SlatedGameToolkit.Framework/SDL2-bindings/SDL2_image.cs
Normal file
@ -0,0 +1,307 @@
|
||||
#region License
|
||||
/* SDL2# - C# Wrapper for SDL2
|
||||
*
|
||||
* Copyright (c) 2013-2020 Ethan Lee.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from
|
||||
* the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in a
|
||||
* product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
* Ethan "flibitijibibo" Lee <flibitijibibo@flibitijibibo.com>
|
||||
*
|
||||
*/
|
||||
#endregion
|
||||
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
#endregion
|
||||
|
||||
namespace SDL2
|
||||
{
|
||||
public static class SDL_image
|
||||
{
|
||||
#region SDL2# Variables
|
||||
|
||||
/* Used by DllImport to load the native library. */
|
||||
private const string nativeLibName = "SDL2_image";
|
||||
|
||||
#endregion
|
||||
|
||||
#region SDL_image.h
|
||||
|
||||
/* Similar to the headers, this is the version we're expecting to be
|
||||
* running with. You will likely want to check this somewhere in your
|
||||
* program!
|
||||
*/
|
||||
public const int SDL_IMAGE_MAJOR_VERSION = 2;
|
||||
public const int SDL_IMAGE_MINOR_VERSION = 0;
|
||||
public const int SDL_IMAGE_PATCHLEVEL = 6;
|
||||
|
||||
[Flags]
|
||||
public enum IMG_InitFlags
|
||||
{
|
||||
IMG_INIT_JPG = 0x00000001,
|
||||
IMG_INIT_PNG = 0x00000002,
|
||||
IMG_INIT_TIF = 0x00000004,
|
||||
IMG_INIT_WEBP = 0x00000008
|
||||
}
|
||||
|
||||
public static void SDL_IMAGE_VERSION(out SDL.SDL_version X)
|
||||
{
|
||||
X.major = SDL_IMAGE_MAJOR_VERSION;
|
||||
X.minor = SDL_IMAGE_MINOR_VERSION;
|
||||
X.patch = SDL_IMAGE_PATCHLEVEL;
|
||||
}
|
||||
|
||||
[DllImport(nativeLibName, EntryPoint = "IMG_Linked_Version", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern IntPtr INTERNAL_IMG_Linked_Version();
|
||||
public static SDL.SDL_version IMG_Linked_Version()
|
||||
{
|
||||
SDL.SDL_version result;
|
||||
IntPtr result_ptr = INTERNAL_IMG_Linked_Version();
|
||||
result = (SDL.SDL_version) Marshal.PtrToStructure(
|
||||
result_ptr,
|
||||
typeof(SDL.SDL_version)
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int IMG_Init(IMG_InitFlags flags);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void IMG_Quit();
|
||||
|
||||
/* IntPtr refers to an SDL_Surface* */
|
||||
[DllImport(nativeLibName, EntryPoint = "IMG_Load", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe IntPtr INTERNAL_IMG_Load(
|
||||
byte* file
|
||||
);
|
||||
public static unsafe IntPtr IMG_Load(string file)
|
||||
{
|
||||
byte* utf8File = SDL.Utf8Encode(file);
|
||||
IntPtr handle = INTERNAL_IMG_Load(
|
||||
utf8File
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8File);
|
||||
return handle;
|
||||
}
|
||||
|
||||
/* src refers to an SDL_RWops*, IntPtr to an SDL_Surface* */
|
||||
/* THIS IS A PUBLIC RWops FUNCTION! */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr IMG_Load_RW(
|
||||
IntPtr src,
|
||||
int freesrc
|
||||
);
|
||||
|
||||
/* src refers to an SDL_RWops*, IntPtr to an SDL_Surface* */
|
||||
/* THIS IS A PUBLIC RWops FUNCTION! */
|
||||
[DllImport(nativeLibName, EntryPoint = "IMG_LoadTyped_RW", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe IntPtr INTERNAL_IMG_LoadTyped_RW(
|
||||
IntPtr src,
|
||||
int freesrc,
|
||||
byte* type
|
||||
);
|
||||
public static unsafe IntPtr IMG_LoadTyped_RW(
|
||||
IntPtr src,
|
||||
int freesrc,
|
||||
string type
|
||||
) {
|
||||
int utf8TypeBufSize = SDL.Utf8Size(type);
|
||||
byte* utf8Type = stackalloc byte[utf8TypeBufSize];
|
||||
return INTERNAL_IMG_LoadTyped_RW(
|
||||
src,
|
||||
freesrc,
|
||||
SDL.Utf8Encode(type, utf8Type, utf8TypeBufSize)
|
||||
);
|
||||
}
|
||||
|
||||
/* IntPtr refers to an SDL_Texture*, renderer to an SDL_Renderer* */
|
||||
[DllImport(nativeLibName, EntryPoint = "IMG_LoadTexture", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe IntPtr INTERNAL_IMG_LoadTexture(
|
||||
IntPtr renderer,
|
||||
byte* file
|
||||
);
|
||||
public static unsafe IntPtr IMG_LoadTexture(
|
||||
IntPtr renderer,
|
||||
string file
|
||||
) {
|
||||
byte* utf8File = SDL.Utf8Encode(file);
|
||||
IntPtr handle = INTERNAL_IMG_LoadTexture(
|
||||
renderer,
|
||||
utf8File
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8File);
|
||||
return handle;
|
||||
}
|
||||
|
||||
/* renderer refers to an SDL_Renderer*.
|
||||
* src refers to an SDL_RWops*.
|
||||
* IntPtr to an SDL_Texture*.
|
||||
*/
|
||||
/* THIS IS A PUBLIC RWops FUNCTION! */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr IMG_LoadTexture_RW(
|
||||
IntPtr renderer,
|
||||
IntPtr src,
|
||||
int freesrc
|
||||
);
|
||||
|
||||
/* renderer refers to an SDL_Renderer*.
|
||||
* src refers to an SDL_RWops*.
|
||||
* IntPtr to an SDL_Texture*.
|
||||
*/
|
||||
/* THIS IS A PUBLIC RWops FUNCTION! */
|
||||
[DllImport(nativeLibName, EntryPoint = "IMG_LoadTextureTyped_RW", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe IntPtr INTERNAL_IMG_LoadTextureTyped_RW(
|
||||
IntPtr renderer,
|
||||
IntPtr src,
|
||||
int freesrc,
|
||||
byte* type
|
||||
);
|
||||
public static unsafe IntPtr IMG_LoadTextureTyped_RW(
|
||||
IntPtr renderer,
|
||||
IntPtr src,
|
||||
int freesrc,
|
||||
string type
|
||||
) {
|
||||
byte* utf8Type = SDL.Utf8Encode(type);
|
||||
IntPtr handle = INTERNAL_IMG_LoadTextureTyped_RW(
|
||||
renderer,
|
||||
src,
|
||||
freesrc,
|
||||
utf8Type
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8Type);
|
||||
return handle;
|
||||
}
|
||||
|
||||
/* IntPtr refers to an SDL_Surface* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr IMG_ReadXPMFromArray(
|
||||
[In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)]
|
||||
string[] xpm
|
||||
);
|
||||
|
||||
/* surface refers to an SDL_Surface* */
|
||||
[DllImport(nativeLibName, EntryPoint = "IMG_SavePNG", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe int INTERNAL_IMG_SavePNG(
|
||||
IntPtr surface,
|
||||
byte* file
|
||||
);
|
||||
public static unsafe int IMG_SavePNG(IntPtr surface, string file)
|
||||
{
|
||||
byte* utf8File = SDL.Utf8Encode(file);
|
||||
int result = INTERNAL_IMG_SavePNG(
|
||||
surface,
|
||||
utf8File
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8File);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* surface refers to an SDL_Surface*, dst to an SDL_RWops* */
|
||||
/* THIS IS A PUBLIC RWops FUNCTION! */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int IMG_SavePNG_RW(
|
||||
IntPtr surface,
|
||||
IntPtr dst,
|
||||
int freedst
|
||||
);
|
||||
|
||||
/* surface refers to an SDL_Surface* */
|
||||
[DllImport(nativeLibName, EntryPoint = "IMG_SaveJPG", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe int INTERNAL_IMG_SaveJPG(
|
||||
IntPtr surface,
|
||||
byte* file,
|
||||
int quality
|
||||
);
|
||||
public static unsafe int IMG_SaveJPG(IntPtr surface, string file, int quality)
|
||||
{
|
||||
byte* utf8File = SDL.Utf8Encode(file);
|
||||
int result = INTERNAL_IMG_SaveJPG(
|
||||
surface,
|
||||
utf8File,
|
||||
quality
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8File);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* surface refers to an SDL_Surface*, dst to an SDL_RWops* */
|
||||
/* THIS IS A PUBLIC RWops FUNCTION! */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int IMG_SaveJPG_RW(
|
||||
IntPtr surface,
|
||||
IntPtr dst,
|
||||
int freedst,
|
||||
int quality
|
||||
);
|
||||
|
||||
#region Animated Image Support
|
||||
|
||||
/* This region is only available in 2.0.6 or higher. */
|
||||
|
||||
public struct IMG_Animation
|
||||
{
|
||||
public int w;
|
||||
public int h;
|
||||
public IntPtr frames; /* SDL_Surface** */
|
||||
public IntPtr delays; /* int* */
|
||||
}
|
||||
|
||||
/* IntPtr refers to an IMG_Animation* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr IMG_LoadAnimation(
|
||||
[In()] [MarshalAs(UnmanagedType.LPStr)]
|
||||
string file
|
||||
);
|
||||
|
||||
/* IntPtr refers to an IMG_Animation*, src to an SDL_RWops* */
|
||||
/* THIS IS A PUBLIC RWops FUNCTION! */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr IMG_LoadAnimation_RW(
|
||||
IntPtr src,
|
||||
int freesrc
|
||||
);
|
||||
|
||||
/* IntPtr refers to an IMG_Animation*, src to an SDL_RWops* */
|
||||
/* THIS IS A PUBLIC RWops FUNCTION! */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr IMG_LoadAnimationTyped_RW(
|
||||
IntPtr src,
|
||||
int freesrc,
|
||||
[In()] [MarshalAs(UnmanagedType.LPStr)]
|
||||
string type
|
||||
);
|
||||
|
||||
/* anim refers to an IMG_Animation* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void IMG_FreeAnimation(IntPtr anim);
|
||||
|
||||
/* IntPtr refers to an IMG_Animation*, src to an SDL_RWops* */
|
||||
/* THIS IS A PUBLIC RWops FUNCTION! */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr IMG_LoadGIFAnimation_RW(IntPtr src);
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
651
src/SlatedGameToolkit.Framework/SDL2-bindings/SDL2_mixer.cs
Normal file
651
src/SlatedGameToolkit.Framework/SDL2-bindings/SDL2_mixer.cs
Normal file
@ -0,0 +1,651 @@
|
||||
#region License
|
||||
/* SDL2# - C# Wrapper for SDL2
|
||||
*
|
||||
* Copyright (c) 2013-2020 Ethan Lee.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from
|
||||
* the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in a
|
||||
* product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
* Ethan "flibitijibibo" Lee <flibitijibibo@flibitijibibo.com>
|
||||
*
|
||||
*/
|
||||
#endregion
|
||||
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
#endregion
|
||||
|
||||
namespace SDL2
|
||||
{
|
||||
public static class SDL_mixer
|
||||
{
|
||||
#region SDL2# Variables
|
||||
|
||||
/* Used by DllImport to load the native library. */
|
||||
private const string nativeLibName = "SDL2_mixer";
|
||||
|
||||
#endregion
|
||||
|
||||
#region SDL_mixer.h
|
||||
|
||||
/* Similar to the headers, this is the version we're expecting to be
|
||||
* running with. You will likely want to check this somewhere in your
|
||||
* program!
|
||||
*/
|
||||
public const int SDL_MIXER_MAJOR_VERSION = 2;
|
||||
public const int SDL_MIXER_MINOR_VERSION = 0;
|
||||
public const int SDL_MIXER_PATCHLEVEL = 5;
|
||||
|
||||
/* In C, you can redefine this value before including SDL_mixer.h.
|
||||
* We're not going to allow this in SDL2#, since the value of this
|
||||
* variable is persistent and not dependent on preprocessor ordering.
|
||||
*/
|
||||
public const int MIX_CHANNELS = 8;
|
||||
|
||||
public static readonly int MIX_DEFAULT_FREQUENCY = 44100;
|
||||
public static readonly ushort MIX_DEFAULT_FORMAT =
|
||||
BitConverter.IsLittleEndian ? SDL.AUDIO_S16LSB : SDL.AUDIO_S16MSB;
|
||||
public static readonly int MIX_DEFAULT_CHANNELS = 2;
|
||||
public static readonly byte MIX_MAX_VOLUME = 128;
|
||||
|
||||
[Flags]
|
||||
public enum MIX_InitFlags
|
||||
{
|
||||
MIX_INIT_FLAC = 0x00000001,
|
||||
MIX_INIT_MOD = 0x00000002,
|
||||
MIX_INIT_MP3 = 0x00000008,
|
||||
MIX_INIT_OGG = 0x00000010,
|
||||
MIX_INIT_MID = 0x00000020,
|
||||
MIX_INIT_OPUS = 0x00000040
|
||||
}
|
||||
|
||||
public struct MIX_Chunk
|
||||
{
|
||||
public int allocated;
|
||||
public IntPtr abuf; /* Uint8* */
|
||||
public uint alen;
|
||||
public byte volume;
|
||||
}
|
||||
|
||||
public enum Mix_Fading
|
||||
{
|
||||
MIX_NO_FADING,
|
||||
MIX_FADING_OUT,
|
||||
MIX_FADING_IN
|
||||
}
|
||||
|
||||
public enum Mix_MusicType
|
||||
{
|
||||
MUS_NONE,
|
||||
MUS_CMD,
|
||||
MUS_WAV,
|
||||
MUS_MOD,
|
||||
MUS_MID,
|
||||
MUS_OGG,
|
||||
MUS_MP3,
|
||||
MUS_MP3_MAD_UNUSED,
|
||||
MUS_FLAC,
|
||||
MUS_MODPLUG_UNUSED,
|
||||
MUS_OPUS
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void MixFuncDelegate(
|
||||
IntPtr udata, // void*
|
||||
IntPtr stream, // Uint8*
|
||||
int len
|
||||
);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void Mix_EffectFunc_t(
|
||||
int chan,
|
||||
IntPtr stream, // void*
|
||||
int len,
|
||||
IntPtr udata // void*
|
||||
);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void Mix_EffectDone_t(
|
||||
int chan,
|
||||
IntPtr udata // void*
|
||||
);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void MusicFinishedDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void ChannelFinishedDelegate(int channel);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate int SoundFontDelegate(
|
||||
IntPtr a, // const char*
|
||||
IntPtr b // void*
|
||||
);
|
||||
|
||||
public static void SDL_MIXER_VERSION(out SDL.SDL_version X)
|
||||
{
|
||||
X.major = SDL_MIXER_MAJOR_VERSION;
|
||||
X.minor = SDL_MIXER_MINOR_VERSION;
|
||||
X.patch = SDL_MIXER_PATCHLEVEL;
|
||||
}
|
||||
|
||||
[DllImport(nativeLibName, EntryPoint = "MIX_Linked_Version", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern IntPtr INTERNAL_MIX_Linked_Version();
|
||||
public static SDL.SDL_version MIX_Linked_Version()
|
||||
{
|
||||
SDL.SDL_version result;
|
||||
IntPtr result_ptr = INTERNAL_MIX_Linked_Version();
|
||||
result = (SDL.SDL_version) Marshal.PtrToStructure(
|
||||
result_ptr,
|
||||
typeof(SDL.SDL_version)
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_Init(MIX_InitFlags flags);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Mix_Quit();
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_OpenAudio(
|
||||
int frequency,
|
||||
ushort format,
|
||||
int channels,
|
||||
int chunksize
|
||||
);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_AllocateChannels(int numchans);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_QuerySpec(
|
||||
out int frequency,
|
||||
out ushort format,
|
||||
out int channels
|
||||
);
|
||||
|
||||
/* src refers to an SDL_RWops*, IntPtr to a Mix_Chunk* */
|
||||
/* THIS IS A PUBLIC RWops FUNCTION! */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr Mix_LoadWAV_RW(
|
||||
IntPtr src,
|
||||
int freesrc
|
||||
);
|
||||
|
||||
/* IntPtr refers to a Mix_Chunk* */
|
||||
/* This is an RWops macro in the C header. */
|
||||
public static IntPtr Mix_LoadWAV(string file)
|
||||
{
|
||||
IntPtr rwops = SDL.SDL_RWFromFile(file, "rb");
|
||||
return Mix_LoadWAV_RW(rwops, 1);
|
||||
}
|
||||
|
||||
/* IntPtr refers to a Mix_Music* */
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_LoadMUS", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe IntPtr INTERNAL_Mix_LoadMUS(
|
||||
byte* file
|
||||
);
|
||||
public static unsafe IntPtr Mix_LoadMUS(string file)
|
||||
{
|
||||
byte* utf8File = SDL.Utf8Encode(file);
|
||||
IntPtr handle = INTERNAL_Mix_LoadMUS(
|
||||
utf8File
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8File);
|
||||
return handle;
|
||||
}
|
||||
|
||||
/* IntPtr refers to a Mix_Chunk* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr Mix_QuickLoad_WAV(
|
||||
[In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1)]
|
||||
byte[] mem
|
||||
);
|
||||
|
||||
/* IntPtr refers to a Mix_Chunk* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr Mix_QuickLoad_RAW(
|
||||
[In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 1)]
|
||||
byte[] mem,
|
||||
uint len
|
||||
);
|
||||
|
||||
/* chunk refers to a Mix_Chunk* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Mix_FreeChunk(IntPtr chunk);
|
||||
|
||||
/* music refers to a Mix_Music* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Mix_FreeMusic(IntPtr music);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_GetNumChunkDecoders();
|
||||
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_GetChunkDecoder", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern IntPtr INTERNAL_Mix_GetChunkDecoder(int index);
|
||||
public static string Mix_GetChunkDecoder(int index)
|
||||
{
|
||||
return SDL.UTF8_ToManaged(
|
||||
INTERNAL_Mix_GetChunkDecoder(index)
|
||||
);
|
||||
}
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_GetNumMusicDecoders();
|
||||
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_GetMusicDecoder", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern IntPtr INTERNAL_Mix_GetMusicDecoder(int index);
|
||||
public static string Mix_GetMusicDecoder(int index)
|
||||
{
|
||||
return SDL.UTF8_ToManaged(
|
||||
INTERNAL_Mix_GetMusicDecoder(index)
|
||||
);
|
||||
}
|
||||
|
||||
/* music refers to a Mix_Music* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Mix_MusicType Mix_GetMusicType(IntPtr music);
|
||||
|
||||
/* music refers to a Mix_Music*
|
||||
* Only available in 2.0.5 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_GetMusicTitle", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr INTERNAL_Mix_GetMusicTitle(IntPtr music);
|
||||
public static string Mix_GetMusicTitle(IntPtr music)
|
||||
{
|
||||
return SDL.UTF8_ToManaged(
|
||||
INTERNAL_Mix_GetMusicTitle(music)
|
||||
);
|
||||
}
|
||||
|
||||
/* music refers to a Mix_Music*
|
||||
* Only available in 2.0.5 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_GetMusicTitleTag", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr INTERNAL_Mix_GetMusicTitleTag(IntPtr music);
|
||||
public static string Mix_GetMusicTitleTag(IntPtr music)
|
||||
{
|
||||
return SDL.UTF8_ToManaged(
|
||||
INTERNAL_Mix_GetMusicTitleTag(music)
|
||||
);
|
||||
}
|
||||
|
||||
/* music refers to a Mix_Music*
|
||||
* Only available in 2.0.5 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_GetMusicArtistTag", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr INTERNAL_Mix_GetMusicArtistTag(IntPtr music);
|
||||
public static string Mix_GetMusicArtistTag(IntPtr music)
|
||||
{
|
||||
return SDL.UTF8_ToManaged(
|
||||
INTERNAL_Mix_GetMusicArtistTag(music)
|
||||
);
|
||||
}
|
||||
|
||||
/* music refers to a Mix_Music*
|
||||
* Only available in 2.0.5 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_GetMusicAlbumTag", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr INTERNAL_Mix_GetMusicAlbumTag(IntPtr music);
|
||||
public static string Mix_GetMusicAlbumTag(IntPtr music)
|
||||
{
|
||||
return SDL.UTF8_ToManaged(
|
||||
INTERNAL_Mix_GetMusicAlbumTag(music)
|
||||
);
|
||||
}
|
||||
|
||||
/* music refers to a Mix_Music*
|
||||
* Only available in 2.0.5 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_GetMusicCopyrightTag", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr INTERNAL_Mix_GetMusicCopyrightTag(IntPtr music);
|
||||
public static string Mix_GetMusicCopyrightTag(IntPtr music)
|
||||
{
|
||||
return SDL.UTF8_ToManaged(
|
||||
INTERNAL_Mix_GetMusicCopyrightTag(music)
|
||||
);
|
||||
}
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Mix_SetPostMix(
|
||||
MixFuncDelegate mix_func,
|
||||
IntPtr arg // void*
|
||||
);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Mix_HookMusic(
|
||||
MixFuncDelegate mix_func,
|
||||
IntPtr arg // void*
|
||||
);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Mix_HookMusicFinished(
|
||||
MusicFinishedDelegate music_finished
|
||||
);
|
||||
|
||||
/* IntPtr refers to a void* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr Mix_GetMusicHookData();
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Mix_ChannelFinished(
|
||||
ChannelFinishedDelegate channel_finished
|
||||
);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_RegisterEffect(
|
||||
int chan,
|
||||
Mix_EffectFunc_t f,
|
||||
Mix_EffectDone_t d,
|
||||
IntPtr arg // void*
|
||||
);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_UnregisterEffect(
|
||||
int channel,
|
||||
Mix_EffectFunc_t f
|
||||
);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_UnregisterAllEffects(int channel);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_SetPanning(
|
||||
int channel,
|
||||
byte left,
|
||||
byte right
|
||||
);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_SetPosition(
|
||||
int channel,
|
||||
short angle,
|
||||
byte distance
|
||||
);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_SetDistance(int channel, byte distance);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_SetReverseStereo(int channel, int flip);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_ReserveChannels(int num);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_GroupChannel(int which, int tag);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_GroupChannels(int from, int to, int tag);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_GroupAvailable(int tag);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_GroupCount(int tag);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_GroupOldest(int tag);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_GroupNewer(int tag);
|
||||
|
||||
/* chunk refers to a Mix_Chunk* */
|
||||
public static int Mix_PlayChannel(
|
||||
int channel,
|
||||
IntPtr chunk,
|
||||
int loops
|
||||
) {
|
||||
return Mix_PlayChannelTimed(channel, chunk, loops, -1);
|
||||
}
|
||||
|
||||
/* chunk refers to a Mix_Chunk* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_PlayChannelTimed(
|
||||
int channel,
|
||||
IntPtr chunk,
|
||||
int loops,
|
||||
int ticks
|
||||
);
|
||||
|
||||
/* music refers to a Mix_Music* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_PlayMusic(IntPtr music, int loops);
|
||||
|
||||
/* music refers to a Mix_Music* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_FadeInMusic(
|
||||
IntPtr music,
|
||||
int loops,
|
||||
int ms
|
||||
);
|
||||
|
||||
/* music refers to a Mix_Music* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_FadeInMusicPos(
|
||||
IntPtr music,
|
||||
int loops,
|
||||
int ms,
|
||||
double position
|
||||
);
|
||||
|
||||
/* chunk refers to a Mix_Chunk* */
|
||||
public static int Mix_FadeInChannel(
|
||||
int channel,
|
||||
IntPtr chunk,
|
||||
int loops,
|
||||
int ms
|
||||
) {
|
||||
return Mix_FadeInChannelTimed(channel, chunk, loops, ms, -1);
|
||||
}
|
||||
|
||||
/* chunk refers to a Mix_Chunk* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_FadeInChannelTimed(
|
||||
int channel,
|
||||
IntPtr chunk,
|
||||
int loops,
|
||||
int ms,
|
||||
int ticks
|
||||
);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_Volume(int channel, int volume);
|
||||
|
||||
/* chunk refers to a Mix_Chunk* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_VolumeChunk(
|
||||
IntPtr chunk,
|
||||
int volume
|
||||
);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_VolumeMusic(int volume);
|
||||
|
||||
/* music refers to a Mix_Music*
|
||||
* Only available in 2.0.5 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_GetVolumeMusicStream(IntPtr music);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_HaltChannel(int channel);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_HaltGroup(int tag);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_HaltMusic();
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_ExpireChannel(int channel, int ticks);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_FadeOutChannel(int which, int ms);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_FadeOutGroup(int tag, int ms);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_FadeOutMusic(int ms);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Mix_Fading Mix_FadingMusic();
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Mix_Fading Mix_FadingChannel(int which);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Mix_Pause(int channel);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Mix_Resume(int channel);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_Paused(int channel);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Mix_PauseMusic();
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Mix_ResumeMusic();
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Mix_RewindMusic();
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_PausedMusic();
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_SetMusicPosition(double position);
|
||||
|
||||
/* music refers to a Mix_Music*
|
||||
* Only available in 2.0.5 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern double Mix_GetMusicPosition(IntPtr music);
|
||||
|
||||
/* music refers to a Mix_Music*
|
||||
* Only available in 2.0.5 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern double Mix_MusicDuration(IntPtr music);
|
||||
|
||||
/* music refers to a Mix_Music*
|
||||
* Only available in 2.0.5 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern double Mix_GetMusicLoopStartTime(IntPtr music);
|
||||
|
||||
/* music refers to a Mix_Music*
|
||||
* Only available in 2.0.5 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern double Mix_GetMusicLoopEndTime(IntPtr music);
|
||||
|
||||
/* music refers to a Mix_Music*
|
||||
* Only available in 2.0.5 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern double Mix_GetMusicLoopLengthTime(IntPtr music);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_Playing(int channel);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_PlayingMusic();
|
||||
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_SetMusicCMD", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe int INTERNAL_Mix_SetMusicCMD(
|
||||
byte* command
|
||||
);
|
||||
public static unsafe int Mix_SetMusicCMD(string command)
|
||||
{
|
||||
byte* utf8Cmd = SDL.Utf8Encode(command);
|
||||
int result = INTERNAL_Mix_SetMusicCMD(
|
||||
utf8Cmd
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8Cmd);
|
||||
return result;
|
||||
}
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_SetSynchroValue(int value);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_GetSynchroValue();
|
||||
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_SetSoundFonts", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe int INTERNAL_Mix_SetSoundFonts(
|
||||
byte* paths
|
||||
);
|
||||
public static unsafe int Mix_SetSoundFonts(string paths)
|
||||
{
|
||||
byte* utf8Paths = SDL.Utf8Encode(paths);
|
||||
int result = INTERNAL_Mix_SetSoundFonts(
|
||||
utf8Paths
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8Paths);
|
||||
return result;
|
||||
}
|
||||
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_GetSoundFonts", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern IntPtr INTERNAL_Mix_GetSoundFonts();
|
||||
public static string Mix_GetSoundFonts()
|
||||
{
|
||||
return SDL.UTF8_ToManaged(
|
||||
INTERNAL_Mix_GetSoundFonts()
|
||||
);
|
||||
}
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_EachSoundFont(
|
||||
SoundFontDelegate function,
|
||||
IntPtr data // void*
|
||||
);
|
||||
|
||||
/* Only available in 2.0.5 or later. */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_SetTimidityCfg(
|
||||
[In()] [MarshalAs(UnmanagedType.LPStr)]
|
||||
string path
|
||||
);
|
||||
|
||||
/* Only available in 2.0.5 or later. */
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_GetTimidityCfg", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr INTERNAL_Mix_GetTimidityCfg();
|
||||
public static string Mix_GetTimidityCfg()
|
||||
{
|
||||
return SDL.UTF8_ToManaged(
|
||||
INTERNAL_Mix_GetTimidityCfg()
|
||||
);
|
||||
}
|
||||
|
||||
/* IntPtr refers to a Mix_Chunk* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr Mix_GetChunk(int channel);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void Mix_CloseAudio();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
757
src/SlatedGameToolkit.Framework/SDL2-bindings/SDL2_ttf.cs
Normal file
757
src/SlatedGameToolkit.Framework/SDL2-bindings/SDL2_ttf.cs
Normal file
@ -0,0 +1,757 @@
|
||||
#region License
|
||||
/* SDL2# - C# Wrapper for SDL2
|
||||
*
|
||||
* Copyright (c) 2013-2020 Ethan Lee.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from
|
||||
* the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in a
|
||||
* product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
* Ethan "flibitijibibo" Lee <flibitijibibo@flibitijibibo.com>
|
||||
*
|
||||
*/
|
||||
#endregion
|
||||
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
#endregion
|
||||
|
||||
namespace SDL2
|
||||
{
|
||||
public static class SDL_ttf
|
||||
{
|
||||
#region SDL2# Variables
|
||||
|
||||
/* Used by DllImport to load the native library. */
|
||||
private const string nativeLibName = "SDL2_ttf";
|
||||
|
||||
#endregion
|
||||
|
||||
#region SDL_ttf.h
|
||||
|
||||
/* Similar to the headers, this is the version we're expecting to be
|
||||
* running with. You will likely want to check this somewhere in your
|
||||
* program!
|
||||
*/
|
||||
public const int SDL_TTF_MAJOR_VERSION = 2;
|
||||
public const int SDL_TTF_MINOR_VERSION = 0;
|
||||
public const int SDL_TTF_PATCHLEVEL = 16;
|
||||
|
||||
public const int UNICODE_BOM_NATIVE = 0xFEFF;
|
||||
public const int UNICODE_BOM_SWAPPED = 0xFFFE;
|
||||
|
||||
public const int TTF_STYLE_NORMAL = 0x00;
|
||||
public const int TTF_STYLE_BOLD = 0x01;
|
||||
public const int TTF_STYLE_ITALIC = 0x02;
|
||||
public const int TTF_STYLE_UNDERLINE = 0x04;
|
||||
public const int TTF_STYLE_STRIKETHROUGH = 0x08;
|
||||
|
||||
public const int TTF_HINTING_NORMAL = 0;
|
||||
public const int TTF_HINTING_LIGHT = 1;
|
||||
public const int TTF_HINTING_MONO = 2;
|
||||
public const int TTF_HINTING_NONE = 3;
|
||||
public const int TTF_HINTING_LIGHT_SUBPIXEL = 4; /* >= 2.0.16 */
|
||||
|
||||
public static void SDL_TTF_VERSION(out SDL.SDL_version X)
|
||||
{
|
||||
X.major = SDL_TTF_MAJOR_VERSION;
|
||||
X.minor = SDL_TTF_MINOR_VERSION;
|
||||
X.patch = SDL_TTF_PATCHLEVEL;
|
||||
}
|
||||
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_LinkedVersion", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern IntPtr INTERNAL_TTF_LinkedVersion();
|
||||
public static SDL.SDL_version TTF_LinkedVersion()
|
||||
{
|
||||
SDL.SDL_version result;
|
||||
IntPtr result_ptr = INTERNAL_TTF_LinkedVersion();
|
||||
result = (SDL.SDL_version) Marshal.PtrToStructure(
|
||||
result_ptr,
|
||||
typeof(SDL.SDL_version)
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void TTF_ByteSwappedUNICODE(int swapped);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_Init();
|
||||
|
||||
/* IntPtr refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_OpenFont", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe IntPtr INTERNAL_TTF_OpenFont(
|
||||
byte* file,
|
||||
int ptsize
|
||||
);
|
||||
public static unsafe IntPtr TTF_OpenFont(string file, int ptsize)
|
||||
{
|
||||
byte* utf8File = SDL.Utf8Encode(file);
|
||||
IntPtr handle = INTERNAL_TTF_OpenFont(
|
||||
utf8File,
|
||||
ptsize
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8File);
|
||||
return handle;
|
||||
}
|
||||
|
||||
/* src refers to an SDL_RWops*, IntPtr to a TTF_Font* */
|
||||
/* THIS IS A PUBLIC RWops FUNCTION! */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_OpenFontRW(
|
||||
IntPtr src,
|
||||
int freesrc,
|
||||
int ptsize
|
||||
);
|
||||
|
||||
/* IntPtr refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_OpenFontIndex", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe IntPtr INTERNAL_TTF_OpenFontIndex(
|
||||
byte* file,
|
||||
int ptsize,
|
||||
long index
|
||||
);
|
||||
public static unsafe IntPtr TTF_OpenFontIndex(
|
||||
string file,
|
||||
int ptsize,
|
||||
long index
|
||||
) {
|
||||
byte* utf8File = SDL.Utf8Encode(file);
|
||||
IntPtr handle = INTERNAL_TTF_OpenFontIndex(
|
||||
utf8File,
|
||||
ptsize,
|
||||
index
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8File);
|
||||
return handle;
|
||||
}
|
||||
|
||||
/* src refers to an SDL_RWops*, IntPtr to a TTF_Font* */
|
||||
/* THIS IS A PUBLIC RWops FUNCTION! */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_OpenFontIndexRW(
|
||||
IntPtr src,
|
||||
int freesrc,
|
||||
int ptsize,
|
||||
long index
|
||||
);
|
||||
|
||||
/* font refers to a TTF_Font*
|
||||
* Only available in 2.0.16 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_SetFontSize(
|
||||
IntPtr font,
|
||||
int ptsize
|
||||
);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_GetFontStyle(IntPtr font);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void TTF_SetFontStyle(IntPtr font, int style);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_GetFontOutline(IntPtr font);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void TTF_SetFontOutline(IntPtr font, int outline);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_GetFontHinting(IntPtr font);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void TTF_SetFontHinting(IntPtr font, int hinting);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_FontHeight(IntPtr font);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_FontAscent(IntPtr font);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_FontDescent(IntPtr font);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_FontLineSkip(IntPtr font);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_GetFontKerning(IntPtr font);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void TTF_SetFontKerning(IntPtr font, int allowed);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern long TTF_FontFaces(IntPtr font);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_FontFaceIsFixedWidth(IntPtr font);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_FontFaceFamilyName", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern IntPtr INTERNAL_TTF_FontFaceFamilyName(
|
||||
IntPtr font
|
||||
);
|
||||
public static string TTF_FontFaceFamilyName(IntPtr font)
|
||||
{
|
||||
return SDL.UTF8_ToManaged(
|
||||
INTERNAL_TTF_FontFaceFamilyName(font)
|
||||
);
|
||||
}
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_FontFaceStyleName", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern IntPtr INTERNAL_TTF_FontFaceStyleName(
|
||||
IntPtr font
|
||||
);
|
||||
public static string TTF_FontFaceStyleName(IntPtr font)
|
||||
{
|
||||
return SDL.UTF8_ToManaged(
|
||||
INTERNAL_TTF_FontFaceStyleName(font)
|
||||
);
|
||||
}
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_GlyphIsProvided(IntPtr font, ushort ch);
|
||||
|
||||
/* font refers to a TTF_Font*
|
||||
* Only available in 2.0.16 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_GlyphIsProvided32(IntPtr font, uint ch);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_GlyphMetrics(
|
||||
IntPtr font,
|
||||
ushort ch,
|
||||
out int minx,
|
||||
out int maxx,
|
||||
out int miny,
|
||||
out int maxy,
|
||||
out int advance
|
||||
);
|
||||
|
||||
/* font refers to a TTF_Font*
|
||||
* Only available in 2.0.16 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_GlyphMetrics32(
|
||||
IntPtr font,
|
||||
uint ch,
|
||||
out int minx,
|
||||
out int maxx,
|
||||
out int miny,
|
||||
out int maxy,
|
||||
out int advance
|
||||
);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_SizeText(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPStr)]
|
||||
string text,
|
||||
out int w,
|
||||
out int h
|
||||
);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_SizeUTF8", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern unsafe int INTERNAL_TTF_SizeUTF8(
|
||||
IntPtr font,
|
||||
byte* text,
|
||||
out int w,
|
||||
out int h
|
||||
);
|
||||
public static unsafe int TTF_SizeUTF8(
|
||||
IntPtr font,
|
||||
string text,
|
||||
out int w,
|
||||
out int h
|
||||
) {
|
||||
byte* utf8Text = SDL.Utf8Encode(text);
|
||||
int result = INTERNAL_TTF_SizeUTF8(
|
||||
font,
|
||||
utf8Text,
|
||||
out w,
|
||||
out h
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8Text);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_SizeUNICODE(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPWStr)]
|
||||
string text,
|
||||
out int w,
|
||||
out int h
|
||||
);
|
||||
|
||||
/* font refers to a TTF_Font*
|
||||
* Only available in 2.0.16 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_MeasureText(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPStr)]
|
||||
string text,
|
||||
int measure_width,
|
||||
out int extent,
|
||||
out int count
|
||||
);
|
||||
|
||||
/* font refers to a TTF_Font*
|
||||
* Only available in 2.0.16 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_MeasureUTF8", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern unsafe int INTERNAL_TTF_MeasureUTF8(
|
||||
IntPtr font,
|
||||
byte* text,
|
||||
int measure_width,
|
||||
out int extent,
|
||||
out int count
|
||||
);
|
||||
public static unsafe int TTF_MeasureUTF8(
|
||||
IntPtr font,
|
||||
string text,
|
||||
int measure_width,
|
||||
out int extent,
|
||||
out int count
|
||||
) {
|
||||
byte* utf8Text = SDL.Utf8Encode(text);
|
||||
int result = INTERNAL_TTF_MeasureUTF8(
|
||||
font,
|
||||
utf8Text,
|
||||
measure_width,
|
||||
out extent,
|
||||
out count
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8Text);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* font refers to a TTF_Font*
|
||||
* Only available in 2.0.16 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_MeasureUNICODE(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPWStr)]
|
||||
string text,
|
||||
int measure_width,
|
||||
out int extent,
|
||||
out int count
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderText_Solid(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPStr)]
|
||||
string text,
|
||||
SDL.SDL_Color fg
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Solid", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Solid(
|
||||
IntPtr font,
|
||||
byte* text,
|
||||
SDL.SDL_Color fg
|
||||
);
|
||||
public static unsafe IntPtr TTF_RenderUTF8_Solid(
|
||||
IntPtr font,
|
||||
string text,
|
||||
SDL.SDL_Color fg
|
||||
) {
|
||||
byte* utf8Text = SDL.Utf8Encode(text);
|
||||
IntPtr result = INTERNAL_TTF_RenderUTF8_Solid(
|
||||
font,
|
||||
utf8Text,
|
||||
fg
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8Text);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderUNICODE_Solid(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPWStr)]
|
||||
string text,
|
||||
SDL.SDL_Color fg
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font*
|
||||
* Only available in 2.0.16 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderText_Solid_Wrapped(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPStr)]
|
||||
string text,
|
||||
SDL.SDL_Color fg,
|
||||
uint wrapLength
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font*
|
||||
* Only available in 2.0.16 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Solid_Wrapped", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Solid_Wrapped(
|
||||
IntPtr font,
|
||||
byte* text,
|
||||
SDL.SDL_Color fg,
|
||||
uint wrapLength
|
||||
);
|
||||
public static unsafe IntPtr TTF_RenderUTF8_Solid_Wrapped(
|
||||
IntPtr font,
|
||||
string text,
|
||||
SDL.SDL_Color fg,
|
||||
uint wrapLength
|
||||
) {
|
||||
byte* utf8Text = SDL.Utf8Encode(text);
|
||||
IntPtr result = INTERNAL_TTF_RenderUTF8_Solid_Wrapped(
|
||||
font,
|
||||
utf8Text,
|
||||
fg,
|
||||
wrapLength
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8Text);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font*
|
||||
* Only available in 2.0.16 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderUNICODE_Solid_Wrapped(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPWStr)]
|
||||
string text,
|
||||
SDL.SDL_Color fg,
|
||||
uint wrapLength
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderGlyph_Solid(
|
||||
IntPtr font,
|
||||
ushort ch,
|
||||
SDL.SDL_Color fg
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font*
|
||||
* Only available in 2.0.16 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderGlyph32_Solid(
|
||||
IntPtr font,
|
||||
uint ch,
|
||||
SDL.SDL_Color fg
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderText_Shaded(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPStr)]
|
||||
string text,
|
||||
SDL.SDL_Color fg,
|
||||
SDL.SDL_Color bg
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Shaded", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Shaded(
|
||||
IntPtr font,
|
||||
byte* text,
|
||||
SDL.SDL_Color fg,
|
||||
SDL.SDL_Color bg
|
||||
);
|
||||
public static unsafe IntPtr TTF_RenderUTF8_Shaded(
|
||||
IntPtr font,
|
||||
string text,
|
||||
SDL.SDL_Color fg,
|
||||
SDL.SDL_Color bg
|
||||
) {
|
||||
byte* utf8Text = SDL.Utf8Encode(text);
|
||||
IntPtr result = INTERNAL_TTF_RenderUTF8_Shaded(
|
||||
font,
|
||||
utf8Text,
|
||||
fg,
|
||||
bg
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8Text);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderUNICODE_Shaded(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPWStr)]
|
||||
string text,
|
||||
SDL.SDL_Color fg,
|
||||
SDL.SDL_Color bg
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderText_Shaded_Wrapped(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPStr)]
|
||||
string text,
|
||||
SDL.SDL_Color fg,
|
||||
SDL.SDL_Color bg,
|
||||
uint wrapLength
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font*
|
||||
* Only available in 2.0.16 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Shaded_Wrapped", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Shaded_Wrapped(
|
||||
IntPtr font,
|
||||
byte* text,
|
||||
SDL.SDL_Color fg,
|
||||
SDL.SDL_Color bg,
|
||||
uint wrapLength
|
||||
);
|
||||
public static unsafe IntPtr TTF_RenderUTF8_Shaded_Wrapped(
|
||||
IntPtr font,
|
||||
string text,
|
||||
SDL.SDL_Color fg,
|
||||
SDL.SDL_Color bg,
|
||||
uint wrapLength
|
||||
) {
|
||||
byte* utf8Text = SDL.Utf8Encode(text);
|
||||
IntPtr result = INTERNAL_TTF_RenderUTF8_Shaded_Wrapped(
|
||||
font,
|
||||
utf8Text,
|
||||
fg,
|
||||
bg,
|
||||
wrapLength
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8Text);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderUNICODE_Shaded_Wrapped(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPWStr)]
|
||||
string text,
|
||||
SDL.SDL_Color fg,
|
||||
SDL.SDL_Color bg,
|
||||
uint wrapLength
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderGlyph_Shaded(
|
||||
IntPtr font,
|
||||
ushort ch,
|
||||
SDL.SDL_Color fg,
|
||||
SDL.SDL_Color bg
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font*
|
||||
* Only available in 2.0.16 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderGlyph32_Shaded(
|
||||
IntPtr font,
|
||||
uint ch,
|
||||
SDL.SDL_Color fg,
|
||||
SDL.SDL_Color bg
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderText_Blended(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPStr)]
|
||||
string text,
|
||||
SDL.SDL_Color fg
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Blended", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Blended(
|
||||
IntPtr font,
|
||||
byte* text,
|
||||
SDL.SDL_Color fg
|
||||
);
|
||||
public static unsafe IntPtr TTF_RenderUTF8_Blended(
|
||||
IntPtr font,
|
||||
string text,
|
||||
SDL.SDL_Color fg
|
||||
) {
|
||||
byte* utf8Text = SDL.Utf8Encode(text);
|
||||
IntPtr result = INTERNAL_TTF_RenderUTF8_Blended(
|
||||
font,
|
||||
utf8Text,
|
||||
fg
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8Text);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderUNICODE_Blended(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPWStr)]
|
||||
string text,
|
||||
SDL.SDL_Color fg
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderText_Blended_Wrapped(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPStr)]
|
||||
string text,
|
||||
SDL.SDL_Color fg,
|
||||
uint wrapped
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Blended_Wrapped", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern unsafe IntPtr INTERNAL_TTF_RenderUTF8_Blended_Wrapped(
|
||||
IntPtr font,
|
||||
byte* text,
|
||||
SDL.SDL_Color fg,
|
||||
uint wrapped
|
||||
);
|
||||
public static unsafe IntPtr TTF_RenderUTF8_Blended_Wrapped(
|
||||
IntPtr font,
|
||||
string text,
|
||||
SDL.SDL_Color fg,
|
||||
uint wrapped
|
||||
) {
|
||||
byte* utf8Text = SDL.Utf8Encode(text);
|
||||
IntPtr result = INTERNAL_TTF_RenderUTF8_Blended_Wrapped(
|
||||
font,
|
||||
utf8Text,
|
||||
fg,
|
||||
wrapped
|
||||
);
|
||||
Marshal.FreeHGlobal((IntPtr) utf8Text);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderUNICODE_Blended_Wrapped(
|
||||
IntPtr font,
|
||||
[In()] [MarshalAs(UnmanagedType.LPWStr)]
|
||||
string text,
|
||||
SDL.SDL_Color fg,
|
||||
uint wrapped
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderGlyph_Blended(
|
||||
IntPtr font,
|
||||
ushort ch,
|
||||
SDL.SDL_Color fg
|
||||
);
|
||||
|
||||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font*
|
||||
* Only available in 2.0.16 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderGlyph32_Blended(
|
||||
IntPtr font,
|
||||
uint ch,
|
||||
SDL.SDL_Color fg
|
||||
);
|
||||
|
||||
/* Only available in 2.0.16 or higher. */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_SetDirection(int direction);
|
||||
|
||||
/* Only available in 2.0.16 or higher. */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_SetScript(int script);
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void TTF_CloseFont(IntPtr font);
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void TTF_Quit();
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_WasInit();
|
||||
|
||||
/* font refers to a TTF_Font* */
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int SDL_GetFontKerningSize(
|
||||
IntPtr font,
|
||||
int prev_index,
|
||||
int index
|
||||
);
|
||||
|
||||
/* font refers to a TTF_Font*
|
||||
* Only available in 2.0.15 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_GetFontKerningSizeGlyphs(
|
||||
IntPtr font,
|
||||
ushort previous_ch,
|
||||
ushort ch
|
||||
);
|
||||
|
||||
/* font refers to a TTF_Font*
|
||||
* Only available in 2.0.16 or higher.
|
||||
*/
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_GetFontKerningSizeGlyphs32(
|
||||
IntPtr font,
|
||||
ushort previous_ch,
|
||||
ushort ch
|
||||
);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -2,10 +2,13 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SFML.Net" Version="2.5.0" />
|
||||
<PackageReference Include="Serilog" Version="2.9.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
132
src/SlatedGameToolkit.Framework/StateSystem/Manager.cs
Normal file
132
src/SlatedGameToolkit.Framework/StateSystem/Manager.cs
Normal file
@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using SlatedGameToolkit.Framework.Graphics.Window;
|
||||
using SlatedGameToolkit.Framework.StateSystem.States;
|
||||
|
||||
namespace SlatedGameToolkit.Framework.StateSystem
|
||||
{
|
||||
public sealed class Manager : IDisposable {
|
||||
public Thread thread;
|
||||
public readonly WindowHandle window;
|
||||
private IState currentState;
|
||||
private IState nextState;
|
||||
private Dictionary<string, IState> states;
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a game state manager with an initial state, and a set of states to be added at the start.
|
||||
/// States can later be added or removed.
|
||||
/// None of the parameters can be null, and the initial state must exist in initial set of states.
|
||||
/// </summary>
|
||||
/// <param name="initialState">The name of the initial state.</param>
|
||||
/// <param name="window">The window handle being used for this set of states.</param>
|
||||
/// <param name="states">The initial set of game states to be added.</param>
|
||||
public Manager(string initialState, WindowHandle window, params IState[] states) {
|
||||
if (initialState == null) throw new ArgumentNullException("initialState");
|
||||
this.window = window ?? throw new ArgumentNullException("window");
|
||||
this.states = new Dictionary<string, IState>();
|
||||
thread = Thread.CurrentThread;
|
||||
addStates(states);
|
||||
if (!this.states.TryGetValue(initialState, out currentState)) throw new ArgumentException("The requested initial state name does not exist in the provided list of states.");
|
||||
}
|
||||
|
||||
internal void update(double delta) {
|
||||
if (nextState != null) {
|
||||
if (currentState.Deactivate() & nextState.Activate()) {
|
||||
currentState = nextState;
|
||||
nextState = null;
|
||||
}
|
||||
}
|
||||
currentState.Update(delta);
|
||||
}
|
||||
|
||||
internal void render(double delta) {
|
||||
currentState.Render(delta);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
public void changeState(string name) {
|
||||
if (thread != Thread.CurrentThread) throw new ThreadStateException("State cannot be changed from a different thread.");
|
||||
if (!states.TryGetValue(name, out nextState)) throw new ArgumentException("The requested state to change to does not exist in this manager.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given states to this manager under each of their own respective names.
|
||||
/// Initializes all the states.
|
||||
/// If there are two states of the same name, the first state in the array is added and the second is discarded.
|
||||
/// The discarded state will not be initialized and dispose will not be called on it.
|
||||
/// </summary>
|
||||
/// <param name="states">The states to add.</param>
|
||||
/// <returns>True if all the states were unique, and false if there were repetitions determined by name.</returns>
|
||||
public bool addStates(IState[] states) {
|
||||
if (states == null || states.Length == 0) throw new ArgumentException("The array of states cannot be null, and cannot be of size 0");
|
||||
bool unique = true;
|
||||
foreach (IState state in states)
|
||||
{
|
||||
unique = unique && addState(state) ? true : false;
|
||||
}
|
||||
return unique;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given state to this manager under it's own name.
|
||||
/// Initializes the state as well.
|
||||
/// Will not iniitialize the state if this method returns false.
|
||||
/// </summary>
|
||||
/// <param name="state">The state to be added to this manager.</param>
|
||||
/// <returns>False if a state of this name has already been registered.</returns>
|
||||
public bool addState(IState state) {
|
||||
if (thread != Thread.CurrentThread) throw new ThreadStateException("Cannot add a state from a different thread.");
|
||||
try {
|
||||
this.states.Add(state.getName(), state);
|
||||
} catch (ArgumentException) {
|
||||
return false;
|
||||
}
|
||||
state.Initialize(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the state given the name of the state.
|
||||
/// If the state doesn't exist, nothing happens.
|
||||
/// Will call dispose on the state.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the state.</param>
|
||||
/// <returns>False if the state is being used, or the state doesn't exist.</returns>
|
||||
public bool removeState(string name) {
|
||||
if (thread != Thread.CurrentThread) throw new ThreadStateException("Cannot remove a state from a different thread.");
|
||||
if (states[name] == currentState) return false;
|
||||
IState state = states[name];
|
||||
state.Dispose();
|
||||
return states.Remove(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all the states in this state manager except for the current one.
|
||||
/// Disposes of the removed states.
|
||||
/// </summary>
|
||||
public void removeAllStates() {
|
||||
foreach (String state in this.states.Keys)
|
||||
{
|
||||
removeState(state);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes of this manager.
|
||||
/// This also disposes the window and all the individual states.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
removeAllStates();
|
||||
window.Dispose();
|
||||
}
|
||||
|
||||
~Manager() {
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
56
src/SlatedGameToolkit.Framework/StateSystem/States/IState.cs
Normal file
56
src/SlatedGameToolkit.Framework/StateSystem/States/IState.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
|
||||
namespace SlatedGameToolkit.Framework.StateSystem.States
|
||||
{
|
||||
public interface IState : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when this state should be deactivated.
|
||||
/// Deactivate may be called multiple times:
|
||||
/// When this method returns false,
|
||||
/// and
|
||||
/// When the next state to be activated has not indicated it is ready.
|
||||
/// </summary>
|
||||
/// <returns>True if this state was successfully deactivated and false otherwise.</returns>
|
||||
bool Deactivate();
|
||||
|
||||
/// <summary>
|
||||
/// Called when this state is the active state.
|
||||
/// This method will be called until:
|
||||
/// This method returns true,
|
||||
/// and
|
||||
/// until the previous state indicates it is ready to be deactivated.
|
||||
/// </summary>
|
||||
/// <returns>True if this state was successfully activated and can be shown. False otherwise.</returns>
|
||||
bool Activate();
|
||||
|
||||
/// <summary>
|
||||
/// Called in intervals dependent on game loop chosen for every update cycle.
|
||||
/// Only called on if this state is the active state, indicated on the last status method called on this implementation (acitvate, and deactivate).
|
||||
/// </summary>
|
||||
/// <param name="delta">The time in seconds that has passed since the last update.</param>
|
||||
void Update(double delta);
|
||||
|
||||
/// <summary>
|
||||
/// Called in intervals dependent on game loop chose for every render cycle.
|
||||
/// Only called on if this state is the active state, indicated on the last status method called on this implementation (acitvate, and deactivate).
|
||||
/// </summary>
|
||||
/// <param name="delta">The time in seconds that has passed since the last render cycle.</param>
|
||||
void Render(double delta);
|
||||
|
||||
/// <summary>
|
||||
/// Called at the game managers convenience, but always before it it shown.
|
||||
/// Should be used to set up this state.
|
||||
/// </summary>
|
||||
/// <param name="manager">The manager that made this call.</param>
|
||||
void Initialize(Manager manager);
|
||||
|
||||
/// <summary>
|
||||
/// The name of this state.
|
||||
/// The name is used to refer to this state.
|
||||
/// The name needs to be unique in a manager.
|
||||
/// </summary>
|
||||
/// <return>A string representing the name of this state.</return>
|
||||
string getName();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user