126 lines
3.9 KiB
C#
126 lines
3.9 KiB
C#
#region License
|
|
/* SDL2# - C# Wrapper for SDL2
|
|
*
|
|
* Copyright (c) 2013-2014 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.dll";
|
|
|
|
#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 = 0;
|
|
|
|
[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_LinkedVersion", CallingConvention = CallingConvention.Cdecl)]
|
|
private static extern IntPtr INTERNAL_IMG_LinkedVersion();
|
|
public static SDL.SDL_version IMG_LinkedVersion()
|
|
{
|
|
SDL.SDL_version result;
|
|
IntPtr result_ptr = INTERNAL_IMG_LinkedVersion();
|
|
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, CallingConvention = CallingConvention.Cdecl)]
|
|
public static extern IntPtr IMG_Load(
|
|
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
|
|
string file
|
|
);
|
|
|
|
/* IntPtr refers to an SDL_Texture*, renderer to an SDL_Renderer* */
|
|
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
|
public static extern IntPtr IMG_LoadTexture(
|
|
IntPtr renderer,
|
|
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
|
|
string file
|
|
);
|
|
|
|
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
|
public static extern int IMG_InvertAlpha(int on);
|
|
|
|
/* 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, CallingConvention = CallingConvention.Cdecl)]
|
|
public static extern int IMG_SavePNG(
|
|
IntPtr surface,
|
|
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
|
|
string file
|
|
);
|
|
|
|
#endregion
|
|
}
|
|
}
|