Repository: zachbarth/minimalist-game-framework Branch: master Commit: c9a7c1ee2392 Files: 19 Total size: 382.6 KB Directory structure: gitextract__c256kt2/ ├── .gitignore ├── Assets/ │ └── INSTRUCTIONS.txt ├── Engine/ │ ├── Audio.cs │ ├── Content.cs │ ├── Engine.cs │ ├── Graphics.cs │ ├── Input.cs │ ├── SDL2/ │ │ ├── SDL2.cs │ │ ├── SDL2_image.cs │ │ ├── SDL2_mixer.cs │ │ └── SDL2_ttf.cs │ └── Utility/ │ ├── Bounds2.cs │ ├── Color.cs │ └── Vector2.cs ├── Game/ │ └── Game.cs ├── Game.csproj ├── Game.sln ├── LICENSE.md └── README.md ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ .vs/ Builds/ ================================================ FILE: Assets/INSTRUCTIONS.txt ================================================ Place your assets (textures, sounds, and fonts) in this directory and they will be automatically copied when making builds. ================================================ FILE: Engine/Audio.cs ================================================ using SDL2; using System; using System.Collections.Generic; static partial class Engine { private static readonly int AudioChannelCount = 64; private static Dictionary SoundInstances = new Dictionary(); private static int GetFadeTimeMs(float fadeTime) { return (int)(fadeTime * 1000); } /// /// Plays a sound. Returns an instance handle that can be passed to StopSound() to stop playback of the sound. /// /// The sound to play. /// Whether or not the sound should repeat until stopped. /// The amount of time (in seconds) to fade in the sound's volume. public static SoundInstance PlaySound(Sound sound, bool repeat = false, float fadeTime = 0) { // Start playing the new sound: int channel = SDL_mixer.Mix_FadeInChannel(-1, sound.Handle, repeat ? -1 : 0, GetFadeTimeMs(fadeTime)); // Silently fail when we run out of channels: if (channel == -1) { return new SoundInstance(); } // Invalidate old sound instances using this channel: foreach (var instanceAndChannel in SoundInstances) { if (instanceAndChannel.Value == channel) { SoundInstances.Remove(instanceAndChannel.Key); break; } } // Return a new sound instance for this channel: SoundInstance instance = new SoundInstance(); SoundInstances[instance] = channel; return instance; } /// /// Stops a playing sound. /// /// An instance handle from a prior call to PlaySound(). /// The amount of time (in seconds) to fade out the sound's volume. public static void StopSound(SoundInstance instance, float fadeTime = 0) { int channel; if (SoundInstances.TryGetValue(instance, out channel)) { SDL_mixer.Mix_FadeOutChannel(channel, GetFadeTimeMs(fadeTime)); } } /// /// Plays music, stopping any currently playing music first. /// /// The music to play. /// Whether or not the music should repeat until stopped. /// The amount of time (in seconds) to fade in the music's volume. public static void PlayMusic(Music music, bool looping = true, float fadeTime = 0) { SDL_mixer.Mix_FadeInMusic(music.Handle, looping ? -1 : 0, GetFadeTimeMs(fadeTime)); } /// /// Stops the current music. /// /// The amount of time (in seconds) to fade out the music's volume. public static void StopMusic(float fadeTime = 0) { SDL_mixer.Mix_FadeOutMusic(GetFadeTimeMs(fadeTime)); } } class SoundInstance { } ================================================ FILE: Engine/Content.cs ================================================ using SDL2; using System; using System.Collections.Generic; using System.IO; static partial class Engine { private static string GetAssetPath(string path) { return Path.Combine("Assets", path); } /// /// Loads a texture from the Assets directory. Supports the following formats: BMP, GIF, JPEG, PNG, SVG, TGA, TIFF, WEBP. /// /// The path to the texture file, relative to the Assets directory. public static Texture LoadTexture(string path) { IntPtr handle = SDL_image.IMG_LoadTexture(Renderer, GetAssetPath(path)); if (handle == IntPtr.Zero) { throw new Exception("Failed to load texture."); } uint format; int access, width, height; SDL.SDL_QueryTexture(handle, out format, out access, out width, out height); return new Texture(handle, width, height); } /// /// Loads a resizable texture from the Assets directory. Supports the following formats: BMP, GIF, JPEG, PNG, SVG, TGA, TIFF, WEBP. /// See the documentation for an explanation of what these parameters _actually_ mean. /// /// The path to the texture file, relative to the Assets directory. /// The resize offset from the left of the texture (in pixels). /// The resize offset from the right of the texture (in pixels). /// The resize offset from the top of the texture (in pixels). /// The resize offset from the bottom of the texture (in pixels). public static ResizableTexture LoadResizableTexture(string path, int leftOffset, int rightOffset, int topOffset, int bottomOffset) { IntPtr handle = SDL_image.IMG_LoadTexture(Renderer, GetAssetPath(path)); if (handle == IntPtr.Zero) { throw new Exception("Failed to load texture."); } uint format; int access, width, height; SDL.SDL_QueryTexture(handle, out format, out access, out width, out height); // Convert the relative offsets (from the edges) into absolute offsets (from the origin): rightOffset = width - rightOffset - 1; bottomOffset = height - bottomOffset - 1; if (leftOffset < 0 || rightOffset >= width || topOffset < 0 || bottomOffset >= height || leftOffset > rightOffset || topOffset > bottomOffset) { throw new Exception("Invalid offset parameter."); } return new ResizableTexture(handle, width, height, leftOffset, rightOffset, topOffset, bottomOffset); } /// /// Loads a font from the Assets directory for a single text size. Supports the following formats: TTF, FON. /// /// The path to the font file, relative to the Assets directory. /// The size of the text that will be rendered by this font (in points). public static Font LoadFont(string path, int pointSize) { IntPtr handle = SDL_ttf.TTF_OpenFont(GetAssetPath(path), pointSize); if (handle == IntPtr.Zero) { throw new Exception("Failed to load font."); } return new Font(handle); } /// /// Loads a sound file from the Assets directory. Supports the following formats: WAV, OGG. /// /// The path to the sound file, relative to the Assets directory. public static Sound LoadSound(string path) { IntPtr handle = SDL_mixer.Mix_LoadWAV(GetAssetPath(path)); if (handle == IntPtr.Zero) { throw new Exception("Failed to load sound."); } return new Sound(handle); } /// /// Loads a music file from the Assets directory. Supports the following formats: WAV, OGG, MP3, FLAC. /// /// The path to the music file, relative to the Assets directory. public static Music LoadMusic(string path) { IntPtr handle = SDL_mixer.Mix_LoadMUS(GetAssetPath(path)); if (handle == IntPtr.Zero) { throw new Exception("Failed to load music."); } return new Music(handle); } } /// /// A handle to a texture. These should only be created by calling LoadTexture(). /// class Texture { public readonly IntPtr Handle; public readonly int Width; public readonly int Height; public readonly Vector2 Size; public Texture(IntPtr handle, int width, int height) { Handle = handle; Width = width; Height = height; Size = new Vector2(width, height); } } /// /// A handle to a resizable texture. These should only be created by calling LoadResizableTexture(). /// class ResizableTexture { public readonly IntPtr Handle; public readonly int Width; public readonly int Height; public readonly int LeftOffset; public readonly int RightOffset; public readonly int TopOffset; public readonly int BottomOffset; public ResizableTexture(IntPtr handle, int width, int height, int leftOffset, int rightOffset, int topOffset, int bottomOffset) { Handle = handle; Width = width; Height = height; LeftOffset = leftOffset; RightOffset = rightOffset; TopOffset = topOffset; BottomOffset = bottomOffset; } } /// /// A handle to a font. These should only be created by calling LoadFont(). /// class Font { public readonly IntPtr Handle; public Font(IntPtr handle) { Handle = handle; } } /// /// A handle to a sound file. These should only be created by calling LoadSound(). /// class Sound { public readonly IntPtr Handle; public Sound(IntPtr handle) { Handle = handle; } } /// /// A handle to a music file. These should only be created by calling LoadMusic(). /// class Music { public readonly IntPtr Handle; public Music(IntPtr handle) { Handle = handle; } } ================================================ FILE: Engine/Engine.cs ================================================ using SDL2; using System; using System.Collections.Generic; static partial class Engine { private static IntPtr Window; private static bool Fullscreen; private static Texture RenderTarget; private static Game Game; /// /// The amount of time (in seconds) since the last frame. /// public static float TimeDelta { get; private set; } private static void Main(string[] args) { Start(); Run(); } private static void Start() { // ====================================================================================== // Initialize SDL // ====================================================================================== if (SDL.SDL_Init(SDL.SDL_INIT_EVERYTHING) != 0) { throw new Exception("Failed to initialize SDL."); } if (SDL_ttf.TTF_Init() != 0) { throw new Exception("Failed to initialize SDL_ttf."); } SDL_mixer.MIX_InitFlags mixInitFlags = SDL_mixer.MIX_InitFlags.MIX_INIT_MP3 | SDL_mixer.MIX_InitFlags.MIX_INIT_OGG | SDL_mixer.MIX_InitFlags.MIX_INIT_FLAC; if (((SDL_mixer.MIX_InitFlags)SDL_mixer.Mix_Init(mixInitFlags) & mixInitFlags) != mixInitFlags) { throw new Exception("Failed to initialize SDL_mixer."); } if (SDL_mixer.Mix_OpenAudio(44100, SDL_mixer.MIX_DEFAULT_FORMAT, 2, 1024) != 0) { throw new Exception("Failed to initialize SDL_mixer."); } SDL_mixer.Mix_AllocateChannels(AudioChannelCount); Window = SDL.SDL_CreateWindow( Game.Title, SDL.SDL_WINDOWPOS_CENTERED_DISPLAY(0), SDL.SDL_WINDOWPOS_CENTERED_DISPLAY(0), (int)Game.Resolution.X, (int)Game.Resolution.Y, 0); if (Window == IntPtr.Zero) { throw new Exception("Failed to create window."); } Renderer = SDL.SDL_CreateRenderer(Window, -1, SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED | SDL.SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC | SDL.SDL_RendererFlags.SDL_RENDERER_TARGETTEXTURE); if (Renderer == IntPtr.Zero) { throw new Exception("Failed to create renderer."); } IntPtr renderTargetHandle = SDL.SDL_CreateTexture(Renderer, SDL.SDL_PIXELFORMAT_RGBA8888, (int)SDL.SDL_TextureAccess.SDL_TEXTUREACCESS_TARGET, (int)Game.Resolution.X, (int)Game.Resolution.Y); RenderTarget = new Texture(renderTargetHandle, (int)Game.Resolution.X, (int)Game.Resolution.Y); // ====================================================================================== // Instantiate the game object // ====================================================================================== Game = new Game(); } private static void Run() { ulong lastFrameStartTime = SDL.SDL_GetPerformanceCounter(); while (true) { // Measure the time elapsed between one frame and the next: ulong now = SDL.SDL_GetPerformanceCounter(); TimeDelta = (now - lastFrameStartTime) / (float)SDL.SDL_GetPerformanceFrequency(); lastFrameStartTime = now; // Process pre-update engine logic: PollEvents(); // Toggle between windowed and fullscreen mode when Alt+Enter is pressed: if (GetKeyDown(Key.Return) && (GetKeyHeld(Key.LeftAlt) || GetKeyHeld(Key.RightAlt))) { Fullscreen = !Fullscreen; SDL.SDL_SetWindowFullscreen(Window, Fullscreen ? (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP : 0); } // Clear and start drawing into the render target: SDL.SDL_SetRenderTarget(Renderer, RenderTarget.Handle); SDL.SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); SDL.SDL_RenderClear(Renderer); // Update game logic: Game.Update(); // Figure out how to scale our render target to fill the window: int windowWidth, windowHeight; SDL.SDL_GetWindowSize(Window, out windowWidth, out windowHeight); float renderTargetScale = ((float)windowWidth / windowHeight > Game.Resolution.X / Game.Resolution.Y) ? windowHeight / Game.Resolution.Y : windowWidth / Game.Resolution.X; // Copy the render target to the screen: SDL.SDL_SetRenderTarget(Renderer, IntPtr.Zero); SDL.SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); SDL.SDL_RenderClear(Renderer); Vector2 renderTargetSize = Game.Resolution * renderTargetScale; Vector2 renderTargetPos = 0.5f * (new Vector2(windowWidth, windowHeight) - renderTargetSize); DrawTexture(RenderTarget, renderTargetPos, size: renderTargetSize, scaleMode: TextureScaleMode.Nearest); // Present the screen: SDL.SDL_RenderPresent(Renderer); // Process post-update engine logic: FreeUnusedTextCacheEntries(); } } } ================================================ FILE: Engine/Graphics.cs ================================================ using SDL2; using System; using System.Collections.Generic; static partial class Engine { private static IntPtr Renderer; private static Dictionary, TextCacheEntry> TextCache = new Dictionary, TextCacheEntry>(); // ====================================================================================== // Primitive drawing // ====================================================================================== private static void DrawPrimitiveSetup(Color color) { SDL.SDL_SetRenderDrawColor(Renderer, color.R, color.G, color.B, color.A); SDL.SDL_SetRenderDrawBlendMode(Renderer, SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND); } /// /// Draws a line. /// /// The start of the line. /// The end of the line. /// The color of the line. public static void DrawLine(Vector2 start, Vector2 end, Color color) { DrawPrimitiveSetup(color); SDL.SDL_RenderDrawLine(Renderer, (int)start.X, (int)start.Y, (int)end.X, (int)end.Y); } /// /// Draws an empty rectangle. /// /// The bounds of the rectangle. /// The color of the rectangle. public static void DrawRectEmpty(Bounds2 bounds, Color color) { DrawPrimitiveSetup(color); SDL.SDL_Rect rect = new SDL.SDL_Rect(); rect.x = (int)bounds.Position.X; rect.y = (int)bounds.Position.Y; rect.w = (int)bounds.Size.X; rect.h = (int)bounds.Size.Y; SDL.SDL_RenderDrawRect(Renderer, ref rect); } /// /// Draws a solid rectangle. /// /// The bounds of the rectangle. /// The color of the rectangle. public static void DrawRectSolid(Bounds2 bounds, Color color) { DrawPrimitiveSetup(color); SDL.SDL_Rect rect = new SDL.SDL_Rect(); rect.x = (int)bounds.Position.X; rect.y = (int)bounds.Position.Y; rect.w = (int)bounds.Size.X; rect.h = (int)bounds.Size.Y; SDL.SDL_RenderFillRect(Renderer, ref rect); } // ====================================================================================== // Texture drawing // ====================================================================================== private static void DrawTextureSetup(IntPtr textureHandle, Color? color, TextureBlendMode blendMode, TextureScaleMode scaleMode) { Color finalColor = color ?? Color.White; SDL.SDL_SetTextureColorMod(textureHandle, finalColor.R, finalColor.G, finalColor.B); SDL.SDL_SetTextureAlphaMod(textureHandle, finalColor.A); SDL.SDL_SetTextureBlendMode(textureHandle, (SDL.SDL_BlendMode)blendMode); SDL.SDL_SetTextureScaleMode(textureHandle, (SDL.SDL_ScaleMode)scaleMode); } /// /// Draws a texture. /// /// The texture to draw. /// The position where the texture will be drawn. /// The color to multiply with the colors of the texture. If unspecified the colors of the texture will be unchanged. /// The destination size of the texture. If unspecified the original texture size will be used. /// The amount the texture will be rotated clockwise (in degrees). If unspecified the texture will not be rotated. /// The offset from position to the pivot that the texture will be rotated about. If unspecified the center of the destination bounds will be used. /// The mirroring to apply to the texture. If unspecified the texture will not be mirrored. /// The source bounds of the texture to draw. If unspecified the entire texture will be drawn. /// The blend mode to use when drawing the texture. If unspecified the texture will be drawn using the standard alpha-based blend mode. /// The scale mode to use when drawing the texture. If unspecified the texture will be linearly interpolated. public static void DrawTexture(Texture texture, Vector2 position, Color? color = null, Vector2? size = null, float rotation = 0, Vector2? pivot = null, TextureMirror mirror = TextureMirror.None, Bounds2? source = null, TextureBlendMode blendMode = TextureBlendMode.Normal, TextureScaleMode scaleMode = TextureScaleMode.Linear) { DrawTextureSetup(texture.Handle, color, blendMode, scaleMode); SDL.SDL_Rect src; SDL.SDL_Rect dest; if (source.HasValue) { // Use the specified source coordinates: src.x = (int)source.Value.Position.X; src.y = (int)source.Value.Position.Y; src.w = (int)source.Value.Size.X; src.h = (int)source.Value.Size.Y; dest.x = (int)position.X; dest.y = (int)position.Y; dest.w = src.w; dest.h = src.h; } else { // Use the full texture as the source: src.x = 0; src.y = 0; src.w = texture.Width; src.h = texture.Height; dest.x = (int)position.X; dest.y = (int)position.Y; dest.w = texture.Width; dest.h = texture.Height; } // Apply the size override, if specified: if (size.HasValue) { dest.w = (int)size.Value.X; dest.h = (int)size.Value.Y; } // Apply the pivot override, if specified: SDL.SDL_Point center; if (pivot.HasValue) { center.x = (int)pivot.Value.X; center.y = (int)pivot.Value.Y; } else { center.x = dest.w / 2; center.y = dest.h / 2; } SDL.SDL_RenderCopyEx(Renderer, texture.Handle, ref src, ref dest, rotation, ref center, (SDL.SDL_RendererFlip)mirror); } /// /// Draws a resizable texture. /// See the documentation for an explanation of how resizable textures work. /// /// The resizable texture to draw. /// The bounds that the texture should be resized to. /// The color to multiply with the colors of the texture. If unspecified the colors of the texture will be unchanged. /// The blend mode to use when drawing the texture. If unspecified the texture will be drawn using the standard alpha-based blend mode. /// The scale mode to use when drawing the texture. If unspecified the texture will be linearly interpolated. public static void DrawResizableTexture(ResizableTexture texture, Bounds2 bounds, Color? color = null, TextureBlendMode blendMode = TextureBlendMode.Normal, TextureScaleMode scaleMode = TextureScaleMode.Linear) { DrawTextureSetup(texture.Handle, color, blendMode, scaleMode); /* * 0 bxmin bxmax txmax * v v v v * +----|-------------|----+ < tymax * | 1 | 5 | 2 | * -----+-------------+----- < bymax * | | | | * | | | | * | 6 | 9 | 7 | * | | | | * | | | | * -----+-------------+----- < bymin * | 3 | 8 | 4 | * +----|-------------|----+ < 0 */ int bxmin = texture.LeftOffset; int bxmax = texture.RightOffset; int bymin = texture.TopOffset; int bymax = texture.BottomOffset; int txmax = texture.Width; int tymax = texture.Height; int px = (int)bounds.Position.X; int py = (int)bounds.Position.Y; // Don't let the overall size be so small that segment 9 has a negative size in either dimension: int sx = Math.Max((int)bounds.Size.X, txmax - bxmax + bxmin); int sy = Math.Max((int)bounds.Size.Y, tymax - bymax + bymin); // Draw each of the nine segments: DrawResizableTextureSegment(texture, 0, 0, bxmin, bymin, px, py, bxmin, bymin); DrawResizableTextureSegment(texture, bxmax, 0, txmax - bxmax, bymin, px + sx - (txmax - bxmax), py, txmax - bxmax, bymin); DrawResizableTextureSegment(texture, 0, bymax, bxmin, tymax - bymax, px, py + sy - (tymax - bymax), bxmin, tymax - bymax); DrawResizableTextureSegment(texture, bxmax, bymax, txmax - bxmax, tymax - bymax, px + sx - (txmax - bxmax), py + sy - (tymax - bymax), txmax - bxmax, tymax - bymax); DrawResizableTextureSegment(texture, bxmin, 0, bxmax - bxmin, bymin, px + bxmin, py, sx - bxmin - (txmax - bxmax), bymin); DrawResizableTextureSegment(texture, 0, bymin, bxmin, bymax - bymin, px, py + bymin, bxmin, sy - bymin - (tymax - bymax)); DrawResizableTextureSegment(texture, bxmax, bymin, txmax - bxmax, bymax - bymin, px + sx - (txmax - bxmax), py + bymin, txmax - bxmax, sy - bymin - (tymax - bymax)); DrawResizableTextureSegment(texture, bxmin, bymax, bxmax - bxmin, tymax - bymax, px + bxmin, py + sy - (tymax - bymax), sx - bxmin - (txmax - bxmax), tymax - bymax); DrawResizableTextureSegment(texture, bxmin, bymin, bxmax - bxmin, bymax - bymin, px + bxmin, py + bymin, sx - bxmin - (txmax - bxmax), sy - bymin - (tymax - bymax)); } private static void DrawResizableTextureSegment(ResizableTexture texture, int subtextureX, int subtextureY, int subtextureW, int subtextureH, int destX, int destY, int destW, int destH) { // Don't draw invisible segments: if (subtextureW <= 0 || subtextureH <= 0) { return; } SDL.SDL_Rect src; src.x = subtextureX; src.y = subtextureY; src.w = subtextureW; src.h = subtextureH; SDL.SDL_Rect dest; dest.x = destX; dest.y = destY; dest.w = destW; dest.h = destH; SDL.SDL_RenderCopy(Renderer, texture.Handle, ref src, ref dest); } // ====================================================================================== // Text drawing // ====================================================================================== /// /// Draws a text string. Returns the bounds of the drawn text. /// /// The text to draw. /// The position where the text will be drawn. /// The color of the text. /// The font to use to draw the text. /// The alignment of the text relative to the position. If unspecified the text will be drawn left-aligned. /// If true the text will only be measured and not actually drawn to the screen. public static Bounds2 DrawString(string text, Vector2 position, Color color, Font font, TextAlignment alignment = TextAlignment.Left, bool measureOnly = false) { // Every time we draw a string we have to render it into a texture, which isn't the fastest thing in the world. // To make this faster we keep a cache of recently rendered strings and reuse them when possible. Tuple textCacheKey = Tuple.Create(font, text); TextCacheEntry entry; if (TextCache.TryGetValue(textCacheKey, out entry)) { // We found the text in the cache, so use it and reset its age so that it doesn't get freed this frame: entry.Age = 0; } else { // We were unable to find the text in the cache, so render it to a texture and cache it for later: SDL.SDL_Color white = new SDL.SDL_Color() { r = 255, g = 255, b = 255, a = 255 }; IntPtr surface = SDL_ttf.TTF_RenderText_Blended(font.Handle, text, white); IntPtr handle = SDL.SDL_CreateTextureFromSurface(Renderer, surface); SDL.SDL_FreeSurface(surface); entry = new TextCacheEntry(handle); TextCache[textCacheKey] = entry; } // Query the texture dimensions: uint format; int access, width, height; SDL.SDL_QueryTexture(entry.Handle, out format, out access, out width, out height); // Apply text alignment relative to the draw position: if (alignment == TextAlignment.Center) { position.X -= width / 2; } else if (alignment == TextAlignment.Right) { position.X -= width; } // If we're not only measuring the text, draw it: if (!measureOnly) { Texture texture = new Texture(entry.Handle, width, height); DrawTexture(texture, position, color); } // Return the bounds of the text: return new Bounds2(position, new Vector2(width, height)); } private static void FreeUnusedTextCacheEntries() { // Cache entries are aggressively purged, and will essentially only stick around when the same text is drawn every frame. List> expiredEntryKeys = new List>(); foreach (var keyAndEntry in TextCache) { keyAndEntry.Value.Age += 1; if (keyAndEntry.Value.Age > 2) { SDL.SDL_DestroyTexture(keyAndEntry.Value.Handle); expiredEntryKeys.Add(keyAndEntry.Key); } } foreach (Tuple key in expiredEntryKeys) { TextCache.Remove(key); } } private class TextCacheEntry { public readonly IntPtr Handle; public int Age; public TextCacheEntry(IntPtr handle) { Handle = handle; Age = 0; } } } enum TextAlignment { /// /// Left-align the text. /// Left, /// /// Center the text. /// Center, /// /// Right-align the text. /// Right, } [Flags] enum TextureMirror { /// /// Do not mirror the texture. /// None = SDL.SDL_RendererFlip.SDL_FLIP_NONE, /// /// Mirror the texture horizontally. /// Horizontal = SDL.SDL_RendererFlip.SDL_FLIP_HORIZONTAL, /// /// Mirror the texture vertically. /// Vertical = SDL.SDL_RendererFlip.SDL_FLIP_VERTICAL, /// /// Mirror the texture horizontally and vertically. Equivalent to rotating it 180 degrees. /// Both = Horizontal | Vertical, } enum TextureBlendMode { /// /// Use a normal blend mode where new colors replace old colors based on the alpha of the new color. /// Normal = SDL.SDL_BlendMode.SDL_BLENDMODE_BLEND, /// /// Use an additive blend mode where new colors are simply added to old colors and get brighter. /// Additive = SDL.SDL_BlendMode.SDL_BLENDMODE_ADD, } enum TextureScaleMode { /// /// Use a linear scale mode that interpolates between pixels for a smooth but blurry image. /// Nearest = SDL.SDL_ScaleMode.SDL_ScaleModeNearest, /// /// Use a nearest neighbor scale mode that interpolates between pixels for a sharp but pixelated image. /// Linear = SDL.SDL_ScaleMode.SDL_ScaleModeLinear, } ================================================ FILE: Engine/Input.cs ================================================ using SDL2; using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; static partial class Engine { private static HashSet MouseButtonsDown = new HashSet(); private static HashSet MouseButtonsHeld = new HashSet(); private static HashSet MouseButtonsUp = new HashSet(); private static HashSet KeysDown = new HashSet(); private static HashSet KeysDownAutorepeat = new HashSet(); private static HashSet KeysHeld = new HashSet(); private static HashSet KeysUp = new HashSet(); private static Dictionary GamepadsByID = new Dictionary(); private static Gamepad[] GamepadsByPlayer = new Gamepad[64]; /// /// The current position of the mouse cursor (in pixels). /// public static Vector2 MousePosition { get; private set; } /// /// The change in position of the mouse cursor this frame (in pixels). /// public static Vector2 MouseMotion { get; private set; } /// /// The amount the mouse wheel has been scrolled this frame (in scroll units). /// public static float MouseScroll { get; private set; } /// /// The textual representation of the keys that were pressed this frame. /// public static string TypedText { get; private set; } private static void PollEvents() { // ====================================================================================== // Reset per-frame input flags // ====================================================================================== MouseButtonsDown.Clear(); MouseButtonsUp.Clear(); MouseScroll = 0; KeysDown.Clear(); KeysDownAutorepeat.Clear(); KeysUp.Clear(); TypedText = ""; foreach (Gamepad gamepad in GamepadsByID.Values) { gamepad.ButtonsDown.Clear(); gamepad.ButtonsUp.Clear(); } // ====================================================================================== // Poll for new events from SDL // ====================================================================================== SDL.SDL_Event evt; while (SDL.SDL_PollEvent(out evt) != 0) { if (evt.type == SDL.SDL_EventType.SDL_MOUSEMOTION) { MousePosition = new Vector2(evt.motion.x, evt.motion.y); MouseMotion = new Vector2(evt.motion.xrel, evt.motion.yrel); } else if (evt.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN) { MouseButton button = (MouseButton)evt.button.button; MouseButtonsDown.Add(button); MouseButtonsHeld.Add(button); } else if (evt.type == SDL.SDL_EventType.SDL_MOUSEBUTTONUP) { MouseButton button = (MouseButton)evt.button.button; MouseButtonsUp.Add(button); MouseButtonsHeld.Remove(button); } else if (evt.type == SDL.SDL_EventType.SDL_MOUSEWHEEL) { MouseScroll = evt.wheel.y; } else if (evt.type == SDL.SDL_EventType.SDL_KEYDOWN) { if (evt.key.repeat == 0) { KeysDown.Add((Key)evt.key.keysym.sym); KeysHeld.Add((Key)evt.key.keysym.sym); } else { KeysDownAutorepeat.Add((Key)evt.key.keysym.sym); } } else if (evt.type == SDL.SDL_EventType.SDL_KEYUP) { KeysUp.Add((Key)evt.key.keysym.sym); KeysHeld.Remove((Key)evt.key.keysym.sym); } else if (evt.type == SDL.SDL_EventType.SDL_TEXTINPUT) { // Convert the byte array into a C# string: string text = null; unsafe { byte[] bufferCopy = new byte[SDL.SDL_TEXTINPUTEVENT_TEXT_SIZE]; Marshal.Copy((IntPtr)evt.text.text, bufferCopy, 0, bufferCopy.Length); text = Encoding.UTF8.GetString(bufferCopy); } TypedText += text[0]; } else if (evt.type == SDL.SDL_EventType.SDL_CONTROLLERDEVICEADDED) { // Create the gamepad object: IntPtr handle = SDL.SDL_GameControllerOpen(evt.cdevice.which); Gamepad gamepad = new Gamepad(handle); // All other gamepad events use the "joystick instance ID" to identify the gamepad: int id = SDL.SDL_JoystickInstanceID(SDL.SDL_GameControllerGetJoystick(handle)); GamepadsByID[id] = gamepad; // Use the lowest available player number for this gamepad: for (int i = 0; i < GamepadsByPlayer.Length; i++) { if (GamepadsByPlayer[i] == null) { GamepadsByPlayer[i] = gamepad; break; } } } else if (evt.type == SDL.SDL_EventType.SDL_CONTROLLERDEVICEREMOVED) { Gamepad gamepad; if (GamepadsByID.TryGetValue(evt.cdevice.which, out gamepad)) { // Destroy the gamepad: SDL.SDL_GameControllerClose(gamepad.Handle); GamepadsByID.Remove(evt.cdevice.which); // Free up this player number for use by the next gamepad attached: for (int i = 0; i < GamepadsByPlayer.Length; i++) { if (GamepadsByPlayer[i] == gamepad) { GamepadsByPlayer[i] = null; break; } } } } else if (evt.type == SDL.SDL_EventType.SDL_CONTROLLERAXISMOTION) { Gamepad gamepad; if (GamepadsByID.TryGetValue(evt.caxis.which, out gamepad)) { float value = ((float)evt.caxis.axisValue) / short.MaxValue; switch ((SDL.SDL_GameControllerAxis)evt.caxis.axis) { case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTX: gamepad.LeftStick.X = value; break; case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTY: gamepad.LeftStick.Y = value; break; case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTX: gamepad.RightStick.X = value; break; case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTY: gamepad.RightStick.Y = value; break; case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT: gamepad.Triggers.X = value; break; case SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT: gamepad.Triggers.Y = value; break; } } } else if (evt.type == SDL.SDL_EventType.SDL_CONTROLLERBUTTONDOWN) { Gamepad gamepad; if (GamepadsByID.TryGetValue(evt.cbutton.which, out gamepad)) { GamepadButton button = (GamepadButton)evt.cbutton.button; gamepad.ButtonsDown.Add(button); gamepad.ButtonsHeld.Add(button); } } else if (evt.type == SDL.SDL_EventType.SDL_CONTROLLERBUTTONUP) { Gamepad gamepad; if (GamepadsByID.TryGetValue(evt.cbutton.which, out gamepad)) { GamepadButton button = (GamepadButton)evt.cbutton.button; gamepad.ButtonsUp.Add(button); gamepad.ButtonsHeld.Remove(button); } } else if (evt.type == SDL.SDL_EventType.SDL_QUIT) { Environment.Exit(0); } } } // ====================================================================================== // Mouse input // ====================================================================================== /// /// Sets the mouse mode, which controls the visibility and lock state of the cursor. /// /// The mouse mode to set. public static void SetMouseMode(MouseMode mode) { switch (mode) { case MouseMode.Visible: SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_FALSE); SDL.SDL_ShowCursor(1); break; case MouseMode.Hidden: SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_FALSE); SDL.SDL_ShowCursor(0); break; case MouseMode.Locked: SDL.SDL_SetRelativeMouseMode(SDL.SDL_bool.SDL_TRUE); break; } } /// /// Returns true if a mouse button was pressed down this frame. /// /// The mouse button to query. public static bool GetMouseButtonDown(MouseButton button) { return MouseButtonsDown.Contains(button); } /// /// Returns true if a mouse button was held during this frame. /// /// The mouse button to query. public static bool GetMouseButtonHeld(MouseButton button) { return MouseButtonsHeld.Contains(button); } /// /// Returns true if a mouse button was released this frame. /// /// public static bool GetMouseButtonUp(MouseButton button) { return MouseButtonsUp.Contains(button); } // ====================================================================================== // Keyboard input // ====================================================================================== /// /// Returns true if a key was pressed down this frame. /// /// The key to query. /// Whether or not key-down events generated by autorepeat will be included. public static bool GetKeyDown(Key key, bool allowAutorepeat = false) { if (allowAutorepeat && KeysDownAutorepeat.Contains(key)) { return true; } return KeysDown.Contains(key); } /// /// Returns true if a key was held during this frame. /// /// The key to query. public static bool GetKeyHeld(Key key) { return KeysHeld.Contains(key); } /// /// Returns true if a key was released this frame. /// /// The key to query. public static bool GetKeyUp(Key key) { return KeysUp.Contains(key); } // ====================================================================================== // Gamepad input // ====================================================================================== /// /// Returns true if a player's gamepad is connected. /// /// The player to query, starting with 0. public static bool GetGamepadConnected(int player) { return player >= 0 && player < GamepadsByPlayer.Length && GamepadsByPlayer[player] != null; } /// /// Reads the analog values of the specified axis on a player's gamepad. /// /// The player to query, starting with 0. /// The gamepad axis to query. public static Vector2 GetGamepadAxis(int player, GamepadAxis axis) { if (GetGamepadConnected(player)) { switch (axis) { case GamepadAxis.LeftStick: return GamepadsByPlayer[player].LeftStick; case GamepadAxis.RightStick: return GamepadsByPlayer[player].RightStick; case GamepadAxis.Triggers: return GamepadsByPlayer[player].Triggers; default: throw new Exception("Unhandled case."); } } else { return Vector2.Zero; } } /// /// Returns true if a gamepad button was pressed down this frame. /// /// The player to query, starting with 0. /// The gamepad button to query. /// public static bool GetGamepadButtonDown(int player, GamepadButton button) { if (GetGamepadConnected(player)) { return GamepadsByPlayer[player].ButtonsDown.Contains(button); } else { return false; } } /// /// Returns true if a gamepad button was held during this frame. /// /// The player to query, starting with 0. /// The gamepad button to query. /// public static bool GetGamepadButtonHeld(int player, GamepadButton button) { if (GetGamepadConnected(player)) { return GamepadsByPlayer[player].ButtonsHeld.Contains(button); } else { return false; } } /// /// Returns true if a gamepad button was released this frame. /// /// The player to query, starting with 0. /// The gamepad button to query. /// public static bool GetGamepadButtonUp(int player, GamepadButton button) { if (GetGamepadConnected(player)) { return GamepadsByPlayer[player].ButtonsUp.Contains(button); } else { return false; } } private class Gamepad { public readonly IntPtr Handle; public readonly HashSet ButtonsDown = new HashSet(); public readonly HashSet ButtonsHeld = new HashSet(); public readonly HashSet ButtonsUp = new HashSet(); public Vector2 LeftStick = Vector2.Zero; public Vector2 RightStick = Vector2.Zero; public Vector2 Triggers = Vector2.Zero; public Gamepad(IntPtr handle) { Handle = handle; } } } public enum Key { Return = '\r', Escape = 27, Backspace = '\b', Tab = '\t', Space = ' ', Exclamation = '!', DoubleQuote = '"', Hash = '#', Percent = '%', Dollar = '$', Ampersand = '&', SingleQuote = '\'', LeftParen = '(', RightParen = ')', Asterisk = '*', Plus = '+', Comma = ',', Minus = '-', Period = '.', Slash = '/', NumRow0 = '0', NumRow1 = '1', NumRow2 = '2', NumRow3 = '3', NumRow4 = '4', NumRow5 = '5', NumRow6 = '6', NumRow7 = '7', NumRow8 = '8', NumRow9 = '9', Colon = ':', Semicolon = ';', Less = '<', Equals = '=', Greater = '>', Question = '?', At = '@', LeftBracket = '[', Backslash = '\\', RightBracket = ']', Caret = '^', Underscore = '_', Backquote = '`', A = 'a', B = 'b', C = 'c', D = 'd', E = 'e', F = 'f', G = 'g', H = 'h', I = 'i', J = 'j', K = 'k', L = 'l', M = 'm', N = 'n', O = 'o', P = 'p', Q = 'q', R = 'r', S = 's', T = 't', U = 'u', V = 'v', W = 'w', X = 'x', Y = 'y', Z = 'z', CapsLock = SDL.SDL_Scancode.SDL_SCANCODE_CAPSLOCK | SDL.SDLK_SCANCODE_MASK, F1 = SDL.SDL_Scancode.SDL_SCANCODE_F1 | SDL.SDLK_SCANCODE_MASK, F2 = SDL.SDL_Scancode.SDL_SCANCODE_F2 | SDL.SDLK_SCANCODE_MASK, F3 = SDL.SDL_Scancode.SDL_SCANCODE_F3 | SDL.SDLK_SCANCODE_MASK, F4 = SDL.SDL_Scancode.SDL_SCANCODE_F4 | SDL.SDLK_SCANCODE_MASK, F5 = SDL.SDL_Scancode.SDL_SCANCODE_F5 | SDL.SDLK_SCANCODE_MASK, F6 = SDL.SDL_Scancode.SDL_SCANCODE_F6 | SDL.SDLK_SCANCODE_MASK, F7 = SDL.SDL_Scancode.SDL_SCANCODE_F7 | SDL.SDLK_SCANCODE_MASK, F8 = SDL.SDL_Scancode.SDL_SCANCODE_F8 | SDL.SDLK_SCANCODE_MASK, F9 = SDL.SDL_Scancode.SDL_SCANCODE_F9 | SDL.SDLK_SCANCODE_MASK, F10 = SDL.SDL_Scancode.SDL_SCANCODE_F10 | SDL.SDLK_SCANCODE_MASK, F11 = SDL.SDL_Scancode.SDL_SCANCODE_F11 | SDL.SDLK_SCANCODE_MASK, F12 = SDL.SDL_Scancode.SDL_SCANCODE_F12 | SDL.SDLK_SCANCODE_MASK, PrintScreen = SDL.SDL_Scancode.SDL_SCANCODE_PRINTSCREEN | SDL.SDLK_SCANCODE_MASK, ScrollLock = SDL.SDL_Scancode.SDL_SCANCODE_SCROLLLOCK | SDL.SDLK_SCANCODE_MASK, Pause = SDL.SDL_Scancode.SDL_SCANCODE_PAUSE | SDL.SDLK_SCANCODE_MASK, Insert = SDL.SDL_Scancode.SDL_SCANCODE_INSERT | SDL.SDLK_SCANCODE_MASK, Home = SDL.SDL_Scancode.SDL_SCANCODE_HOME | SDL.SDLK_SCANCODE_MASK, PageUp = SDL.SDL_Scancode.SDL_SCANCODE_PAGEUP | SDL.SDLK_SCANCODE_MASK, Delete = 127, End = SDL.SDL_Scancode.SDL_SCANCODE_END | SDL.SDLK_SCANCODE_MASK, PageDown = SDL.SDL_Scancode.SDL_SCANCODE_PAGEDOWN | SDL.SDLK_SCANCODE_MASK, Right = SDL.SDL_Scancode.SDL_SCANCODE_RIGHT | SDL.SDLK_SCANCODE_MASK, Left = SDL.SDL_Scancode.SDL_SCANCODE_LEFT | SDL.SDLK_SCANCODE_MASK, Down = SDL.SDL_Scancode.SDL_SCANCODE_DOWN | SDL.SDLK_SCANCODE_MASK, Up = SDL.SDL_Scancode.SDL_SCANCODE_UP | SDL.SDLK_SCANCODE_MASK, NumpadDivide = SDL.SDL_Scancode.SDL_SCANCODE_KP_DIVIDE | SDL.SDLK_SCANCODE_MASK, NumpadMultiply = SDL.SDL_Scancode.SDL_SCANCODE_KP_MULTIPLY | SDL.SDLK_SCANCODE_MASK, NumpadMinus = SDL.SDL_Scancode.SDL_SCANCODE_KP_MINUS | SDL.SDLK_SCANCODE_MASK, NumpadPlus = SDL.SDL_Scancode.SDL_SCANCODE_KP_PLUS | SDL.SDLK_SCANCODE_MASK, NumpadEnter = SDL.SDL_Scancode.SDL_SCANCODE_KP_ENTER | SDL.SDLK_SCANCODE_MASK, Numpad1 = SDL.SDL_Scancode.SDL_SCANCODE_KP_1 | SDL.SDLK_SCANCODE_MASK, Numpad2 = SDL.SDL_Scancode.SDL_SCANCODE_KP_2 | SDL.SDLK_SCANCODE_MASK, Numpad3 = SDL.SDL_Scancode.SDL_SCANCODE_KP_3 | SDL.SDLK_SCANCODE_MASK, Numpad4 = SDL.SDL_Scancode.SDL_SCANCODE_KP_4 | SDL.SDLK_SCANCODE_MASK, Numpad5 = SDL.SDL_Scancode.SDL_SCANCODE_KP_5 | SDL.SDLK_SCANCODE_MASK, Numpad6 = SDL.SDL_Scancode.SDL_SCANCODE_KP_6 | SDL.SDLK_SCANCODE_MASK, Numpad7 = SDL.SDL_Scancode.SDL_SCANCODE_KP_7 | SDL.SDLK_SCANCODE_MASK, Numpad8 = SDL.SDL_Scancode.SDL_SCANCODE_KP_8 | SDL.SDLK_SCANCODE_MASK, Numpad9 = SDL.SDL_Scancode.SDL_SCANCODE_KP_9 | SDL.SDLK_SCANCODE_MASK, Numpad0 = SDL.SDL_Scancode.SDL_SCANCODE_KP_0 | SDL.SDLK_SCANCODE_MASK, NumpadPeriod = SDL.SDL_Scancode.SDL_SCANCODE_KP_PERIOD | SDL.SDLK_SCANCODE_MASK, LeftControl = SDL.SDL_Scancode.SDL_SCANCODE_LCTRL | SDL.SDLK_SCANCODE_MASK, LeftShift = SDL.SDL_Scancode.SDL_SCANCODE_LSHIFT | SDL.SDLK_SCANCODE_MASK, LeftAlt = SDL.SDL_Scancode.SDL_SCANCODE_LALT | SDL.SDLK_SCANCODE_MASK, RightControl = SDL.SDL_Scancode.SDL_SCANCODE_RCTRL | SDL.SDLK_SCANCODE_MASK, RightShift = SDL.SDL_Scancode.SDL_SCANCODE_RSHIFT | SDL.SDLK_SCANCODE_MASK, RightAlt = SDL.SDL_Scancode.SDL_SCANCODE_RALT | SDL.SDLK_SCANCODE_MASK, } public enum MouseMode { /// /// Show the cursor and allow it to move freely. The default mode. /// Visible, /// /// Hide the cursor and allow it to move freely. Useful for when you want to draw your own mouse cursor. /// Hidden, /// /// Hide the cursor and lock it to the center of the screen so that only MouseMotion is relevant. Useful for games like first-person shooters. /// Locked, } public enum MouseButton { Left = 1, Middle = 2, Right = 3, } public enum GamepadButton { A = 0, B, X, Y, Back, Guide, Start, LeftStick, RightStick, LeftShoulder, RightShoulder, Up, Down, Left, Right, } public enum GamepadAxis { /// /// The left analog stick, with values from -1 to 1. /// LeftStick, /// /// The right analog stick, with values from -1 to 1. /// RightStick, /// /// The analog triggers, with the left trigger in X, the right trigger in Y, and values from 0 to 1. /// Triggers, } ================================================ FILE: Engine/SDL2/SDL2.cs ================================================ #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 * */ #endregion #region Using Statements using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Text; #endregion namespace SDL2 { public static class SDL { #region SDL2# Variables private const string nativeLibName = "SDL2"; #endregion #region UTF8 Marshaling /* Used for stack allocated string marshaling. */ internal static int Utf8Size(string str) { Debug.Assert(str != null); return (str.Length * 4) + 1; } internal static int Utf8SizeNullable(string str) { return str != null ? (str.Length * 4) + 1 : 0; } internal static unsafe byte* Utf8Encode(string str, byte* buffer, int bufferSize) { Debug.Assert(str != null); fixed (char* strPtr = str) { Encoding.UTF8.GetBytes(strPtr, str.Length + 1, buffer, bufferSize); } return buffer; } internal static unsafe byte* Utf8EncodeNullable(string str, byte* buffer, int bufferSize) { if (str == null) { return (byte*) 0; } fixed (char* strPtr = str) { Encoding.UTF8.GetBytes(strPtr, str.Length + 1, buffer, bufferSize); } return buffer; } /* Used for heap allocated string marshaling. * Returned byte* must be free'd with FreeHGlobal. */ internal static unsafe byte* Utf8Encode(string str) { Debug.Assert(str != null); int bufferSize = Utf8Size(str); byte* buffer = (byte*) Marshal.AllocHGlobal(bufferSize); fixed (char* strPtr = str) { Encoding.UTF8.GetBytes(strPtr, str.Length + 1, buffer, bufferSize); } return buffer; } internal static unsafe byte* Utf8EncodeNullable(string str) { if (str == null) { return (byte*) 0; } int bufferSize = Utf8Size(str); byte* buffer = (byte*) Marshal.AllocHGlobal(bufferSize); fixed (char* strPtr = str) { Encoding.UTF8.GetBytes( strPtr, (str != null) ? (str.Length + 1) : 0, buffer, bufferSize ); } return buffer; } /* This is public because SDL_DropEvent needs it! */ public static unsafe string UTF8_ToManaged(IntPtr s, bool freePtr = false) { if (s == IntPtr.Zero) { return null; } /* We get to do strlen ourselves! */ byte* ptr = (byte*) s; while (*ptr != 0) { ptr++; } /* TODO: This #ifdef is only here because the equivalent * .NET 2.0 constructor appears to be less efficient? * Here's the pretty version, maybe steal this instead: * string result = new string( (sbyte*) s, // Also, why sbyte??? 0, (int) (ptr - (byte*) s), System.Text.Encoding.UTF8 ); * See the CoreCLR source for more info. * -flibit */ #if NETSTANDARD2_0 /* Modern C# lets you just send the byte*, nice! */ string result = System.Text.Encoding.UTF8.GetString( (byte*) s, (int) (ptr - (byte*) s) ); #else /* Old C# requires an extra memcpy, bleh! */ int len = (int) (ptr - (byte*) s); if (len == 0) { return string.Empty; } char* chars = stackalloc char[len]; int strLen = System.Text.Encoding.UTF8.GetChars((byte*) s, len, chars, len); string result = new string(chars, 0, strLen); #endif /* Some SDL functions will malloc, we have to free! */ if (freePtr) { SDL_free(s); } return result; } #endregion #region SDL_stdinc.h public static uint SDL_FOURCC(byte A, byte B, byte C, byte D) { return (uint) (A | (B << 8) | (C << 16) | (D << 24)); } public enum SDL_bool { SDL_FALSE = 0, SDL_TRUE = 1 } /* malloc/free are used by the marshaler! -flibit */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr SDL_malloc(IntPtr size); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] internal static extern void SDL_free(IntPtr memblock); /* Buffer.BlockCopy is not available in every runtime yet. Also, * using memcpy directly can be a compatibility issue in other * strange ways. So, we expose this to get around all that. * -flibit */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_memcpy(IntPtr dst, IntPtr src, IntPtr len); #endregion #region SDL_rwops.h public const int RW_SEEK_SET = 0; public const int RW_SEEK_CUR = 1; public const int RW_SEEK_END = 2; public const UInt32 SDL_RWOPS_UNKNOWN = 0; /* Unknown stream type */ public const UInt32 SDL_RWOPS_WINFILE = 1; /* Win32 file */ public const UInt32 SDL_RWOPS_STDFILE = 2; /* Stdio file */ public const UInt32 SDL_RWOPS_JNIFILE = 3; /* Android asset */ public const UInt32 SDL_RWOPS_MEMORY = 4; /* Memory stream */ public const UInt32 SDL_RWOPS_MEMORY_RO = 5; /* Read-Only memory stream */ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate long SDLRWopsSizeCallback(IntPtr context); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate long SDLRWopsSeekCallback( IntPtr context, long offset, int whence ); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate IntPtr SDLRWopsReadCallback( IntPtr context, IntPtr ptr, IntPtr size, IntPtr maxnum ); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate IntPtr SDLRWopsWriteCallback( IntPtr context, IntPtr ptr, IntPtr size, IntPtr num ); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate int SDLRWopsCloseCallback( IntPtr context ); [StructLayout(LayoutKind.Sequential)] public struct SDL_RWops { public IntPtr size; public IntPtr seek; public IntPtr read; public IntPtr write; public IntPtr close; public UInt32 type; /* NOTE: This isn't the full structure since * the native SDL_RWops contains a hidden union full of * internal information and platform-specific stuff depending * on what conditions the native library was built with */ } /* IntPtr refers to an SDL_RWops* */ [DllImport(nativeLibName, EntryPoint = "SDL_RWFromFile", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe IntPtr INTERNAL_SDL_RWFromFile( byte* file, byte* mode ); public static unsafe IntPtr SDL_RWFromFile( string file, string mode ) { byte* utf8File = Utf8Encode(file); byte* utf8Mode = Utf8Encode(mode); IntPtr rwOps = INTERNAL_SDL_RWFromFile( utf8File, utf8Mode ); Marshal.FreeHGlobal((IntPtr) utf8Mode); Marshal.FreeHGlobal((IntPtr) utf8File); return rwOps; } /* IntPtr refers to an SDL_RWops* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_AllocRW(); /* area refers to an SDL_RWops* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_FreeRW(IntPtr area); /* fp refers to a void* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_RWFromFP(IntPtr fp, SDL_bool autoclose); /* mem refers to a void*, IntPtr to an SDL_RWops* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_RWFromMem(IntPtr mem, int size); /* mem refers to a const void*, IntPtr to an SDL_RWops* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_RWFromConstMem(IntPtr mem, int size); /* context refers to an SDL_RWops*. * Only available in SDL 2.0.10 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern long SDL_RWsize(IntPtr context); /* context refers to an SDL_RWops*. * Only available in SDL 2.0.10 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern long SDL_RWseek( IntPtr context, long offset, int whence ); /* context refers to an SDL_RWops*. * Only available in SDL 2.0.10 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern long SDL_RWtell(IntPtr context); /* context refers to an SDL_RWops*, ptr refers to a void*. * Only available in SDL 2.0.10 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern long SDL_RWread( IntPtr context, IntPtr ptr, IntPtr size, IntPtr maxnum ); /* context refers to an SDL_RWops*, ptr refers to a const void*. * Only available in SDL 2.0.10 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern long SDL_RWwrite( IntPtr context, IntPtr ptr, IntPtr size, IntPtr maxnum ); /* Read endian functions */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern byte SDL_ReadU8(IntPtr src); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt16 SDL_ReadLE16(IntPtr src); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt16 SDL_ReadBE16(IntPtr src); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_ReadLE32(IntPtr src); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_ReadBE32(IntPtr src); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt64 SDL_ReadLE64(IntPtr src); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt64 SDL_ReadBE64(IntPtr src); /* Write endian functions */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_WriteU8(IntPtr dst, byte value); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_WriteLE16(IntPtr dst, UInt16 value); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_WriteBE16(IntPtr dst, UInt16 value); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_WriteLE32(IntPtr dst, UInt32 value); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_WriteBE32(IntPtr dst, UInt32 value); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_WriteLE64(IntPtr dst, UInt64 value); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_WriteBE64(IntPtr dst, UInt64 value); /* context refers to an SDL_RWops* * Only available in SDL 2.0.10 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern long SDL_RWclose(IntPtr context); /* file refers to a const char*, datasize to a size_t* * IntPtr refers to a void* * Only available in SDL 2.0.10 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_LoadFile(IntPtr file, IntPtr datasize); #endregion #region SDL_main.h [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SetMainReady(); /* This is used as a function pointer to a C main() function */ public delegate int SDL_main_func(int argc, IntPtr argv); /* Use this function with UWP to call your C# Main() function! */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_WinRTRunApp( SDL_main_func mainFunction, IntPtr reserved ); /* Use this function with iOS to call your C# Main() function! * Only available in SDL 2.0.10 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_UIKitRunApp( int argc, IntPtr argv, SDL_main_func mainFunction ); #endregion #region SDL.h public const uint SDL_INIT_TIMER = 0x00000001; public const uint SDL_INIT_AUDIO = 0x00000010; public const uint SDL_INIT_VIDEO = 0x00000020; public const uint SDL_INIT_JOYSTICK = 0x00000200; public const uint SDL_INIT_HAPTIC = 0x00001000; public const uint SDL_INIT_GAMECONTROLLER = 0x00002000; public const uint SDL_INIT_EVENTS = 0x00004000; public const uint SDL_INIT_SENSOR = 0x00008000; public const uint SDL_INIT_NOPARACHUTE = 0x00100000; public const uint SDL_INIT_EVERYTHING = ( SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_SENSOR ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_Init(uint flags); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_InitSubSystem(uint flags); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_Quit(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_QuitSubSystem(uint flags); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_WasInit(uint flags); #endregion #region SDL_platform.h [DllImport(nativeLibName, EntryPoint = "SDL_GetPlatform", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetPlatform(); public static string SDL_GetPlatform() { return UTF8_ToManaged(INTERNAL_SDL_GetPlatform()); } #endregion #region SDL_hints.h public const string SDL_HINT_FRAMEBUFFER_ACCELERATION = "SDL_FRAMEBUFFER_ACCELERATION"; public const string SDL_HINT_RENDER_DRIVER = "SDL_RENDER_DRIVER"; public const string SDL_HINT_RENDER_OPENGL_SHADERS = "SDL_RENDER_OPENGL_SHADERS"; public const string SDL_HINT_RENDER_DIRECT3D_THREADSAFE = "SDL_RENDER_DIRECT3D_THREADSAFE"; public const string SDL_HINT_RENDER_VSYNC = "SDL_RENDER_VSYNC"; public const string SDL_HINT_VIDEO_X11_XVIDMODE = "SDL_VIDEO_X11_XVIDMODE"; public const string SDL_HINT_VIDEO_X11_XINERAMA = "SDL_VIDEO_X11_XINERAMA"; public const string SDL_HINT_VIDEO_X11_XRANDR = "SDL_VIDEO_X11_XRANDR"; public const string SDL_HINT_GRAB_KEYBOARD = "SDL_GRAB_KEYBOARD"; public const string SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS = "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS"; public const string SDL_HINT_IDLE_TIMER_DISABLED = "SDL_IOS_IDLE_TIMER_DISABLED"; public const string SDL_HINT_ORIENTATIONS = "SDL_IOS_ORIENTATIONS"; public const string SDL_HINT_XINPUT_ENABLED = "SDL_XINPUT_ENABLED"; public const string SDL_HINT_GAMECONTROLLERCONFIG = "SDL_GAMECONTROLLERCONFIG"; public const string SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS = "SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS"; public const string SDL_HINT_ALLOW_TOPMOST = "SDL_ALLOW_TOPMOST"; public const string SDL_HINT_TIMER_RESOLUTION = "SDL_TIMER_RESOLUTION"; public const string SDL_HINT_RENDER_SCALE_QUALITY = "SDL_RENDER_SCALE_QUALITY"; /* Only available in SDL 2.0.1 or higher. */ public const string SDL_HINT_VIDEO_HIGHDPI_DISABLED = "SDL_VIDEO_HIGHDPI_DISABLED"; /* Only available in SDL 2.0.2 or higher. */ public const string SDL_HINT_CTRL_CLICK_EMULATE_RIGHT_CLICK = "SDL_CTRL_CLICK_EMULATE_RIGHT_CLICK"; public const string SDL_HINT_VIDEO_WIN_D3DCOMPILER = "SDL_VIDEO_WIN_D3DCOMPILER"; public const string SDL_HINT_MOUSE_RELATIVE_MODE_WARP = "SDL_MOUSE_RELATIVE_MODE_WARP"; public const string SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT = "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT"; public const string SDL_HINT_VIDEO_ALLOW_SCREENSAVER = "SDL_VIDEO_ALLOW_SCREENSAVER"; public const string SDL_HINT_ACCELEROMETER_AS_JOYSTICK = "SDL_ACCELEROMETER_AS_JOYSTICK"; public const string SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES = "SDL_VIDEO_MAC_FULLSCREEN_SPACES"; /* Only available in SDL 2.0.3 or higher. */ public const string SDL_HINT_WINRT_PRIVACY_POLICY_URL = "SDL_WINRT_PRIVACY_POLICY_URL"; public const string SDL_HINT_WINRT_PRIVACY_POLICY_LABEL = "SDL_WINRT_PRIVACY_POLICY_LABEL"; public const string SDL_HINT_WINRT_HANDLE_BACK_BUTTON = "SDL_WINRT_HANDLE_BACK_BUTTON"; /* Only available in SDL 2.0.4 or higher. */ public const string SDL_HINT_NO_SIGNAL_HANDLERS = "SDL_NO_SIGNAL_HANDLERS"; public const string SDL_HINT_IME_INTERNAL_EDITING = "SDL_IME_INTERNAL_EDITING"; public const string SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH = "SDL_ANDROID_SEPARATE_MOUSE_AND_TOUCH"; public const string SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT = "SDL_EMSCRIPTEN_KEYBOARD_ELEMENT"; public const string SDL_HINT_THREAD_STACK_SIZE = "SDL_THREAD_STACK_SIZE"; public const string SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN = "SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN"; public const string SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP = "SDL_WINDOWS_ENABLE_MESSAGELOOP"; public const string SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 = "SDL_WINDOWS_NO_CLOSE_ON_ALT_F4"; public const string SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING = "SDL_XINPUT_USE_OLD_JOYSTICK_MAPPING"; public const string SDL_HINT_MAC_BACKGROUND_APP = "SDL_MAC_BACKGROUND_APP"; public const string SDL_HINT_VIDEO_X11_NET_WM_PING = "SDL_VIDEO_X11_NET_WM_PING"; public const string SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION = "SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"; public const string SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION = "SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION"; /* Only available in 2.0.5 or higher. */ public const string SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH = "SDL_MOUSE_FOCUS_CLICKTHROUGH"; public const string SDL_HINT_BMP_SAVE_LEGACY_FORMAT = "SDL_BMP_SAVE_LEGACY_FORMAT"; public const string SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING = "SDL_WINDOWS_DISABLE_THREAD_NAMING"; public const string SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION = "SDL_APPLE_TV_REMOTE_ALLOW_ROTATION"; /* Only available in 2.0.6 or higher. */ public const string SDL_HINT_AUDIO_RESAMPLING_MODE = "SDL_AUDIO_RESAMPLING_MODE"; public const string SDL_HINT_RENDER_LOGICAL_SIZE_MODE = "SDL_RENDER_LOGICAL_SIZE_MODE"; public const string SDL_HINT_MOUSE_NORMAL_SPEED_SCALE = "SDL_MOUSE_NORMAL_SPEED_SCALE"; public const string SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE = "SDL_MOUSE_RELATIVE_SPEED_SCALE"; public const string SDL_HINT_TOUCH_MOUSE_EVENTS = "SDL_TOUCH_MOUSE_EVENTS"; public const string SDL_HINT_WINDOWS_INTRESOURCE_ICON = "SDL_WINDOWS_INTRESOURCE_ICON"; public const string SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL = "SDL_WINDOWS_INTRESOURCE_ICON_SMALL"; /* Only available in 2.0.8 or higher. */ public const string SDL_HINT_IOS_HIDE_HOME_INDICATOR = "SDL_IOS_HIDE_HOME_INDICATOR"; public const string SDL_HINT_TV_REMOTE_AS_JOYSTICK = "SDL_TV_REMOTE_AS_JOYSTICK"; /* Only available in 2.0.9 or higher. */ public const string SDL_HINT_MOUSE_DOUBLE_CLICK_TIME = "SDL_MOUSE_DOUBLE_CLICK_TIME"; public const string SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS = "SDL_MOUSE_DOUBLE_CLICK_RADIUS"; public const string SDL_HINT_JOYSTICK_HIDAPI = "SDL_JOYSTICK_HIDAPI"; public const string SDL_HINT_JOYSTICK_HIDAPI_PS4 = "SDL_JOYSTICK_HIDAPI_PS4"; public const string SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE = "SDL_JOYSTICK_HIDAPI_PS4_RUMBLE"; public const string SDL_HINT_JOYSTICK_HIDAPI_STEAM = "SDL_JOYSTICK_HIDAPI_STEAM"; public const string SDL_HINT_JOYSTICK_HIDAPI_SWITCH = "SDL_JOYSTICK_HIDAPI_SWITCH"; public const string SDL_HINT_JOYSTICK_HIDAPI_XBOX = "SDL_JOYSTICK_HIDAPI_XBOX"; public const string SDL_HINT_ENABLE_STEAM_CONTROLLERS = "SDL_ENABLE_STEAM_CONTROLLERS"; public const string SDL_HINT_ANDROID_TRAP_BACK_BUTTON = "SDL_ANDROID_TRAP_BACK_BUTTON"; /* Only available in 2.0.10 or higher. */ public const string SDL_HINT_MOUSE_TOUCH_EVENTS = "SDL_MOUSE_TOUCH_EVENTS"; public const string SDL_HINT_GAMECONTROLLERCONFIG_FILE = "SDL_GAMECONTROLLERCONFIG_FILE"; public const string SDL_HINT_ANDROID_BLOCK_ON_PAUSE = "SDL_ANDROID_BLOCK_ON_PAUSE"; public const string SDL_HINT_RENDER_BATCHING = "SDL_RENDER_BATCHING"; public const string SDL_HINT_EVENT_LOGGING = "SDL_EVENT_LOGGING"; public const string SDL_HINT_WAVE_RIFF_CHUNK_SIZE = "SDL_WAVE_RIFF_CHUNK_SIZE"; public const string SDL_HINT_WAVE_TRUNCATION = "SDL_WAVE_TRUNCATION"; public const string SDL_HINT_WAVE_FACT_CHUNK = "SDL_WAVE_FACT_CHUNK"; /* Only available in 2.0.11 or higher. */ public const string SDL_HINT_VIDO_X11_WINDOW_VISUALID = "SDL_VIDEO_X11_WINDOW_VISUALID"; public const string SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS = "SDL_GAMECONTROLLER_USE_BUTTON_LABELS"; public const string SDL_HINT_VIDEO_EXTERNAL_CONTEXT = "SDL_VIDEO_EXTERNAL_CONTEXT"; public const string SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE = "SDL_JOYSTICK_HIDAPI_GAMECUBE"; public const string SDL_HINT_DISPLAY_USABLE_BOUNDS = "SDL_DISPLAY_USABLE_BOUNDS"; public const string SDL_HINT_VIDEO_X11_FORCE_EGL = "SDL_VIDEO_X11_FORCE_EGL"; public const string SDL_HINT_GAMECONTROLLERTYPE = "SDL_GAMECONTROLLERTYPE"; public enum SDL_HintPriority { SDL_HINT_DEFAULT, SDL_HINT_NORMAL, SDL_HINT_OVERRIDE } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_ClearHints(); [DllImport(nativeLibName, EntryPoint = "SDL_GetHint", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe IntPtr INTERNAL_SDL_GetHint(byte* name); public static unsafe string SDL_GetHint(string name) { int utf8NameBufSize = Utf8Size(name); byte* utf8Name = stackalloc byte[utf8NameBufSize]; return UTF8_ToManaged( INTERNAL_SDL_GetHint( Utf8Encode(name, utf8Name, utf8NameBufSize) ) ); } [DllImport(nativeLibName, EntryPoint = "SDL_SetHint", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe SDL_bool INTERNAL_SDL_SetHint( byte* name, byte* value ); public static unsafe SDL_bool SDL_SetHint(string name, string value) { int utf8NameBufSize = Utf8Size(name); byte* utf8Name = stackalloc byte[utf8NameBufSize]; int utf8ValueBufSize = Utf8Size(value); byte* utf8Value = stackalloc byte[utf8ValueBufSize]; return INTERNAL_SDL_SetHint( Utf8Encode(name, utf8Name, utf8NameBufSize), Utf8Encode(value, utf8Value, utf8ValueBufSize) ); } [DllImport(nativeLibName, EntryPoint = "SDL_SetHintWithPriority", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe SDL_bool INTERNAL_SDL_SetHintWithPriority( byte* name, byte* value, SDL_HintPriority priority ); public static unsafe SDL_bool SDL_SetHintWithPriority( string name, string value, SDL_HintPriority priority ) { int utf8NameBufSize = Utf8Size(name); byte* utf8Name = stackalloc byte[utf8NameBufSize]; int utf8ValueBufSize = Utf8Size(value); byte* utf8Value = stackalloc byte[utf8ValueBufSize]; return INTERNAL_SDL_SetHintWithPriority( Utf8Encode(name, utf8Name, utf8NameBufSize), Utf8Encode(value, utf8Value, utf8ValueBufSize), priority ); } /* Only available in 2.0.5 or higher. */ [DllImport(nativeLibName, EntryPoint = "SDL_GetHintBoolean", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe SDL_bool INTERNAL_SDL_GetHintBoolean( byte* name, SDL_bool default_value ); public static unsafe SDL_bool SDL_GetHintBoolean( string name, SDL_bool default_value ) { int utf8NameBufSize = Utf8Size(name); byte* utf8Name = stackalloc byte[utf8NameBufSize]; return INTERNAL_SDL_GetHintBoolean( Utf8Encode(name, utf8Name, utf8NameBufSize), default_value ); } #endregion #region SDL_error.h [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_ClearError(); [DllImport(nativeLibName, EntryPoint = "SDL_GetError", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetError(); public static string SDL_GetError() { return UTF8_ToManaged(INTERNAL_SDL_GetError()); } /* Use string.Format for arglists */ [DllImport(nativeLibName, EntryPoint = "SDL_SetError", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe void INTERNAL_SDL_SetError(byte* fmtAndArglist); public static unsafe void SDL_SetError(string fmtAndArglist) { int utf8FmtAndArglistBufSize = Utf8Size(fmtAndArglist); byte* utf8FmtAndArglist = stackalloc byte[utf8FmtAndArglistBufSize]; INTERNAL_SDL_SetError( Utf8Encode(fmtAndArglist, utf8FmtAndArglist, utf8FmtAndArglistBufSize) ); } #endregion #region SDL_log.h public enum SDL_LogCategory { SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_CATEGORY_ERROR, SDL_LOG_CATEGORY_ASSERT, SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_CATEGORY_AUDIO, SDL_LOG_CATEGORY_VIDEO, SDL_LOG_CATEGORY_RENDER, SDL_LOG_CATEGORY_INPUT, SDL_LOG_CATEGORY_TEST, /* Reserved for future SDL library use */ SDL_LOG_CATEGORY_RESERVED1, SDL_LOG_CATEGORY_RESERVED2, SDL_LOG_CATEGORY_RESERVED3, SDL_LOG_CATEGORY_RESERVED4, SDL_LOG_CATEGORY_RESERVED5, SDL_LOG_CATEGORY_RESERVED6, SDL_LOG_CATEGORY_RESERVED7, SDL_LOG_CATEGORY_RESERVED8, SDL_LOG_CATEGORY_RESERVED9, SDL_LOG_CATEGORY_RESERVED10, /* Beyond this point is reserved for application use, e.g. enum { MYAPP_CATEGORY_AWESOME1 = SDL_LOG_CATEGORY_CUSTOM, MYAPP_CATEGORY_AWESOME2, MYAPP_CATEGORY_AWESOME3, ... }; */ SDL_LOG_CATEGORY_CUSTOM } public enum SDL_LogPriority { SDL_LOG_PRIORITY_VERBOSE = 1, SDL_LOG_PRIORITY_DEBUG, SDL_LOG_PRIORITY_INFO, SDL_LOG_PRIORITY_WARN, SDL_LOG_PRIORITY_ERROR, SDL_LOG_PRIORITY_CRITICAL, SDL_NUM_LOG_PRIORITIES } /* userdata refers to a void*, message to a const char* */ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void SDL_LogOutputFunction( IntPtr userdata, int category, SDL_LogPriority priority, IntPtr message ); /* Use string.Format for arglists */ [DllImport(nativeLibName, EntryPoint = "SDL_Log", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe void INTERNAL_SDL_Log(byte* fmtAndArglist); public static unsafe void SDL_Log(string fmtAndArglist) { int utf8FmtAndArglistBufSize = Utf8Size(fmtAndArglist); byte* utf8FmtAndArglist = stackalloc byte[utf8FmtAndArglistBufSize]; INTERNAL_SDL_Log( Utf8Encode(fmtAndArglist, utf8FmtAndArglist, utf8FmtAndArglistBufSize) ); } /* Use string.Format for arglists */ [DllImport(nativeLibName, EntryPoint = "SDL_LogVerbose", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe void INTERNAL_SDL_LogVerbose( int category, byte* fmtAndArglist ); public static unsafe void SDL_LogVerbose( int category, string fmtAndArglist ) { int utf8FmtAndArglistBufSize = Utf8Size(fmtAndArglist); byte* utf8FmtAndArglist = stackalloc byte[utf8FmtAndArglistBufSize]; INTERNAL_SDL_LogVerbose( category, Utf8Encode(fmtAndArglist, utf8FmtAndArglist, utf8FmtAndArglistBufSize) ); } /* Use string.Format for arglists */ [DllImport(nativeLibName, EntryPoint = "SDL_LogDebug", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe void INTERNAL_SDL_LogDebug( int category, byte* fmtAndArglist ); public static unsafe void SDL_LogDebug( int category, string fmtAndArglist ) { int utf8FmtAndArglistBufSize = Utf8Size(fmtAndArglist); byte* utf8FmtAndArglist = stackalloc byte[utf8FmtAndArglistBufSize]; INTERNAL_SDL_LogDebug( category, Utf8Encode(fmtAndArglist, utf8FmtAndArglist, utf8FmtAndArglistBufSize) ); } /* Use string.Format for arglists */ [DllImport(nativeLibName, EntryPoint = "SDL_LogInfo", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe void INTERNAL_SDL_LogInfo( int category, byte* fmtAndArglist ); public static unsafe void SDL_LogInfo( int category, string fmtAndArglist ) { int utf8FmtAndArglistBufSize = Utf8Size(fmtAndArglist); byte* utf8FmtAndArglist = stackalloc byte[utf8FmtAndArglistBufSize]; INTERNAL_SDL_LogInfo( category, Utf8Encode(fmtAndArglist, utf8FmtAndArglist, utf8FmtAndArglistBufSize) ); } /* Use string.Format for arglists */ [DllImport(nativeLibName, EntryPoint = "SDL_LogWarn", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe void INTERNAL_SDL_LogWarn( int category, byte* fmtAndArglist ); public static unsafe void SDL_LogWarn( int category, string fmtAndArglist ) { int utf8FmtAndArglistBufSize = Utf8Size(fmtAndArglist); byte* utf8FmtAndArglist = stackalloc byte[utf8FmtAndArglistBufSize]; INTERNAL_SDL_LogWarn( category, Utf8Encode(fmtAndArglist, utf8FmtAndArglist, utf8FmtAndArglistBufSize) ); } /* Use string.Format for arglists */ [DllImport(nativeLibName, EntryPoint = "SDL_LogError", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe void INTERNAL_SDL_LogError( int category, byte* fmtAndArglist ); public static unsafe void SDL_LogError( int category, string fmtAndArglist ) { int utf8FmtAndArglistBufSize = Utf8Size(fmtAndArglist); byte* utf8FmtAndArglist = stackalloc byte[utf8FmtAndArglistBufSize]; INTERNAL_SDL_LogError( category, Utf8Encode(fmtAndArglist, utf8FmtAndArglist, utf8FmtAndArglistBufSize) ); } /* Use string.Format for arglists */ [DllImport(nativeLibName, EntryPoint = "SDL_LogCritical", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe void INTERNAL_SDL_LogCritical( int category, byte* fmtAndArglist ); public static unsafe void SDL_LogCritical( int category, string fmtAndArglist ) { int utf8FmtAndArglistBufSize = Utf8Size(fmtAndArglist); byte* utf8FmtAndArglist = stackalloc byte[utf8FmtAndArglistBufSize]; INTERNAL_SDL_LogCritical( category, Utf8Encode(fmtAndArglist, utf8FmtAndArglist, utf8FmtAndArglistBufSize) ); } /* Use string.Format for arglists */ [DllImport(nativeLibName, EntryPoint = "SDL_LogMessage", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe void INTERNAL_SDL_LogMessage( int category, SDL_LogPriority priority, byte* fmtAndArglist ); public static unsafe void SDL_LogMessage( int category, SDL_LogPriority priority, string fmtAndArglist ) { int utf8FmtAndArglistBufSize = Utf8Size(fmtAndArglist); byte* utf8FmtAndArglist = stackalloc byte[utf8FmtAndArglistBufSize]; INTERNAL_SDL_LogMessage( category, priority, Utf8Encode(fmtAndArglist, utf8FmtAndArglist, utf8FmtAndArglistBufSize) ); } /* Use string.Format for arglists */ [DllImport(nativeLibName, EntryPoint = "SDL_LogMessageV", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe void INTERNAL_SDL_LogMessageV( int category, SDL_LogPriority priority, byte* fmtAndArglist ); public static unsafe void SDL_LogMessageV( int category, SDL_LogPriority priority, string fmtAndArglist ) { int utf8FmtAndArglistBufSize = Utf8Size(fmtAndArglist); byte* utf8FmtAndArglist = stackalloc byte[utf8FmtAndArglistBufSize]; INTERNAL_SDL_LogMessageV( category, priority, Utf8Encode(fmtAndArglist, utf8FmtAndArglist, utf8FmtAndArglistBufSize) ); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_LogPriority SDL_LogGetPriority( int category ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_LogSetPriority( int category, SDL_LogPriority priority ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_LogSetAllPriority( SDL_LogPriority priority ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_LogResetPriorities(); /* userdata refers to a void* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] private static extern void SDL_LogGetOutputFunction( out IntPtr callback, out IntPtr userdata ); public static void SDL_LogGetOutputFunction( out SDL_LogOutputFunction callback, out IntPtr userdata ) { IntPtr result = IntPtr.Zero; SDL_LogGetOutputFunction( out result, out userdata ); if (result != IntPtr.Zero) { callback = (SDL_LogOutputFunction) Marshal.GetDelegateForFunctionPointer( result, typeof(SDL_LogOutputFunction) ); } else { callback = null; } } /* userdata refers to a void* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_LogSetOutputFunction( SDL_LogOutputFunction callback, IntPtr userdata ); #endregion #region SDL_messagebox.h [Flags] public enum SDL_MessageBoxFlags : uint { SDL_MESSAGEBOX_ERROR = 0x00000010, SDL_MESSAGEBOX_WARNING = 0x00000020, SDL_MESSAGEBOX_INFORMATION = 0x00000040 } [Flags] public enum SDL_MessageBoxButtonFlags : uint { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001, SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002 } [StructLayout(LayoutKind.Sequential)] private struct INTERNAL_SDL_MessageBoxButtonData { public SDL_MessageBoxButtonFlags flags; public int buttonid; public IntPtr text; /* The UTF-8 button text */ } [StructLayout(LayoutKind.Sequential)] public struct SDL_MessageBoxButtonData { public SDL_MessageBoxButtonFlags flags; public int buttonid; public string text; /* The UTF-8 button text */ } [StructLayout(LayoutKind.Sequential)] public struct SDL_MessageBoxColor { public byte r, g, b; } public enum SDL_MessageBoxColorType { SDL_MESSAGEBOX_COLOR_BACKGROUND, SDL_MESSAGEBOX_COLOR_TEXT, SDL_MESSAGEBOX_COLOR_BUTTON_BORDER, SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND, SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED, SDL_MESSAGEBOX_COLOR_MAX } [StructLayout(LayoutKind.Sequential)] public struct SDL_MessageBoxColorScheme { [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = (int)SDL_MessageBoxColorType.SDL_MESSAGEBOX_COLOR_MAX)] public SDL_MessageBoxColor[] colors; } [StructLayout(LayoutKind.Sequential)] private struct INTERNAL_SDL_MessageBoxData { public SDL_MessageBoxFlags flags; public IntPtr window; /* Parent window, can be NULL */ public IntPtr title; /* UTF-8 title */ public IntPtr message; /* UTF-8 message text */ public int numbuttons; public IntPtr buttons; public IntPtr colorScheme; /* Can be NULL to use system settings */ } [StructLayout(LayoutKind.Sequential)] public struct SDL_MessageBoxData { public SDL_MessageBoxFlags flags; public IntPtr window; /* Parent window, can be NULL */ public string title; /* UTF-8 title */ public string message; /* UTF-8 message text */ public int numbuttons; public SDL_MessageBoxButtonData[] buttons; public SDL_MessageBoxColorScheme? colorScheme; /* Can be NULL to use system settings */ } [DllImport(nativeLibName, EntryPoint = "SDL_ShowMessageBox", CallingConvention = CallingConvention.Cdecl)] private static extern int INTERNAL_SDL_ShowMessageBox([In()] ref INTERNAL_SDL_MessageBoxData messageboxdata, out int buttonid); /* Ripped from Jameson's LpUtf8StrMarshaler */ private static IntPtr INTERNAL_AllocUTF8(string str) { if (string.IsNullOrEmpty(str)) { return IntPtr.Zero; } byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str + '\0'); IntPtr mem = SDL.SDL_malloc((IntPtr) bytes.Length); Marshal.Copy(bytes, 0, mem, bytes.Length); return mem; } public static unsafe int SDL_ShowMessageBox([In()] ref SDL_MessageBoxData messageboxdata, out int buttonid) { var data = new INTERNAL_SDL_MessageBoxData() { flags = messageboxdata.flags, window = messageboxdata.window, title = INTERNAL_AllocUTF8(messageboxdata.title), message = INTERNAL_AllocUTF8(messageboxdata.message), numbuttons = messageboxdata.numbuttons, }; var buttons = new INTERNAL_SDL_MessageBoxButtonData[messageboxdata.numbuttons]; for (int i = 0; i < messageboxdata.numbuttons; i++) { buttons[i] = new INTERNAL_SDL_MessageBoxButtonData() { flags = messageboxdata.buttons[i].flags, buttonid = messageboxdata.buttons[i].buttonid, text = INTERNAL_AllocUTF8(messageboxdata.buttons[i].text), }; } if (messageboxdata.colorScheme != null) { data.colorScheme = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SDL_MessageBoxColorScheme))); Marshal.StructureToPtr(messageboxdata.colorScheme.Value, data.colorScheme, false); } int result; fixed (INTERNAL_SDL_MessageBoxButtonData* buttonsPtr = &buttons[0]) { data.buttons = (IntPtr)buttonsPtr; result = INTERNAL_SDL_ShowMessageBox(ref data, out buttonid); } Marshal.FreeHGlobal(data.colorScheme); for (int i = 0; i < messageboxdata.numbuttons; i++) { SDL_free(buttons[i].text); } SDL_free(data.message); SDL_free(data.title); return result; } /* window refers to an SDL_Window* */ [DllImport(nativeLibName, EntryPoint = "SDL_ShowSimpleMessageBox", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe int INTERNAL_SDL_ShowSimpleMessageBox( SDL_MessageBoxFlags flags, byte* title, byte* message, IntPtr window ); public static unsafe int SDL_ShowSimpleMessageBox( SDL_MessageBoxFlags flags, string title, string message, IntPtr window ) { int utf8TitleBufSize = Utf8SizeNullable(title); byte* utf8Title = stackalloc byte[utf8TitleBufSize]; int utf8MessageBufSize = Utf8SizeNullable(message); byte* utf8Message = stackalloc byte[utf8MessageBufSize]; return INTERNAL_SDL_ShowSimpleMessageBox( flags, Utf8EncodeNullable(title, utf8Title, utf8TitleBufSize), Utf8EncodeNullable(message, utf8Message, utf8MessageBufSize), window ); } #endregion #region SDL_version.h, SDL_revision.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_MAJOR_VERSION = 2; public const int SDL_MINOR_VERSION = 0; public const int SDL_PATCHLEVEL = 12; public static readonly int SDL_COMPILEDVERSION = SDL_VERSIONNUM( SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL ); [StructLayout(LayoutKind.Sequential)] public struct SDL_version { public byte major; public byte minor; public byte patch; } public static void SDL_VERSION(out SDL_version x) { x.major = SDL_MAJOR_VERSION; x.minor = SDL_MINOR_VERSION; x.patch = SDL_PATCHLEVEL; } public static int SDL_VERSIONNUM(int X, int Y, int Z) { return (X * 1000) + (Y * 100) + Z; } public static bool SDL_VERSION_ATLEAST(int X, int Y, int Z) { return (SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z)); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GetVersion(out SDL_version ver); [DllImport(nativeLibName, EntryPoint = "SDL_GetRevision", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetRevision(); public static string SDL_GetRevision() { return UTF8_ToManaged(INTERNAL_SDL_GetRevision()); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetRevisionNumber(); #endregion #region SDL_video.h public enum SDL_GLattr { SDL_GL_RED_SIZE, SDL_GL_GREEN_SIZE, SDL_GL_BLUE_SIZE, SDL_GL_ALPHA_SIZE, SDL_GL_BUFFER_SIZE, SDL_GL_DOUBLEBUFFER, SDL_GL_DEPTH_SIZE, SDL_GL_STENCIL_SIZE, SDL_GL_ACCUM_RED_SIZE, SDL_GL_ACCUM_GREEN_SIZE, SDL_GL_ACCUM_BLUE_SIZE, SDL_GL_ACCUM_ALPHA_SIZE, SDL_GL_STEREO, SDL_GL_MULTISAMPLEBUFFERS, SDL_GL_MULTISAMPLESAMPLES, SDL_GL_ACCELERATED_VISUAL, SDL_GL_RETAINED_BACKING, SDL_GL_CONTEXT_MAJOR_VERSION, SDL_GL_CONTEXT_MINOR_VERSION, SDL_GL_CONTEXT_EGL, SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_SHARE_WITH_CURRENT_CONTEXT, SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, SDL_GL_CONTEXT_RELEASE_BEHAVIOR, SDL_GL_CONTEXT_RESET_NOTIFICATION, /* Requires >= 2.0.6 */ SDL_GL_CONTEXT_NO_ERROR, /* Requires >= 2.0.6 */ } [Flags] public enum SDL_GLprofile { SDL_GL_CONTEXT_PROFILE_CORE = 0x0001, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY = 0x0002, SDL_GL_CONTEXT_PROFILE_ES = 0x0004 } [Flags] public enum SDL_GLcontext { SDL_GL_CONTEXT_DEBUG_FLAG = 0x0001, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG = 0x0002, SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG = 0x0004, SDL_GL_CONTEXT_RESET_ISOLATION_FLAG = 0x0008 } public enum SDL_WindowEventID : byte { SDL_WINDOWEVENT_NONE, SDL_WINDOWEVENT_SHOWN, SDL_WINDOWEVENT_HIDDEN, SDL_WINDOWEVENT_EXPOSED, SDL_WINDOWEVENT_MOVED, SDL_WINDOWEVENT_RESIZED, SDL_WINDOWEVENT_SIZE_CHANGED, SDL_WINDOWEVENT_MINIMIZED, SDL_WINDOWEVENT_MAXIMIZED, SDL_WINDOWEVENT_RESTORED, SDL_WINDOWEVENT_ENTER, SDL_WINDOWEVENT_LEAVE, SDL_WINDOWEVENT_FOCUS_GAINED, SDL_WINDOWEVENT_FOCUS_LOST, SDL_WINDOWEVENT_CLOSE, /* Only available in 2.0.5 or higher. */ SDL_WINDOWEVENT_TAKE_FOCUS, SDL_WINDOWEVENT_HIT_TEST } public enum SDL_DisplayEventID : byte { SDL_DISPLAYEVENT_NONE, SDL_DISPLAYEVENT_ORIENTATION } public enum SDL_DisplayOrientation { SDL_ORIENTATION_UNKNOWN, SDL_ORIENTATION_LANDSCAPE, SDL_ORIENTATION_LANDSCAPE_FLIPPED, SDL_ORIENTATION_PORTRAIT, SDL_ORIENTATION_PORTRAIT_FLIPPED } [Flags] public enum SDL_WindowFlags : uint { SDL_WINDOW_FULLSCREEN = 0x00000001, SDL_WINDOW_OPENGL = 0x00000002, SDL_WINDOW_SHOWN = 0x00000004, SDL_WINDOW_HIDDEN = 0x00000008, SDL_WINDOW_BORDERLESS = 0x00000010, SDL_WINDOW_RESIZABLE = 0x00000020, SDL_WINDOW_MINIMIZED = 0x00000040, SDL_WINDOW_MAXIMIZED = 0x00000080, SDL_WINDOW_INPUT_GRABBED = 0x00000100, SDL_WINDOW_INPUT_FOCUS = 0x00000200, SDL_WINDOW_MOUSE_FOCUS = 0x00000400, SDL_WINDOW_FULLSCREEN_DESKTOP = (SDL_WINDOW_FULLSCREEN | 0x00001000), SDL_WINDOW_FOREIGN = 0x00000800, SDL_WINDOW_ALLOW_HIGHDPI = 0x00002000, /* Requires >= 2.0.1 */ SDL_WINDOW_MOUSE_CAPTURE = 0x00004000, /* Requires >= 2.0.4 */ SDL_WINDOW_ALWAYS_ON_TOP = 0x00008000, /* Requires >= 2.0.5 */ SDL_WINDOW_SKIP_TASKBAR = 0x00010000, /* Requires >= 2.0.5 */ SDL_WINDOW_UTILITY = 0x00020000, /* Requires >= 2.0.5 */ SDL_WINDOW_TOOLTIP = 0x00040000, /* Requires >= 2.0.5 */ SDL_WINDOW_POPUP_MENU = 0x00080000, /* Requires >= 2.0.5 */ SDL_WINDOW_VULKAN = 0x10000000, /* Requires >= 2.0.6 */ } /* Only available in 2.0.4 or higher. */ public enum SDL_HitTestResult { SDL_HITTEST_NORMAL, /* Region is normal. No special properties. */ SDL_HITTEST_DRAGGABLE, /* Region can drag entire window. */ SDL_HITTEST_RESIZE_TOPLEFT, SDL_HITTEST_RESIZE_TOP, SDL_HITTEST_RESIZE_TOPRIGHT, SDL_HITTEST_RESIZE_RIGHT, SDL_HITTEST_RESIZE_BOTTOMRIGHT, SDL_HITTEST_RESIZE_BOTTOM, SDL_HITTEST_RESIZE_BOTTOMLEFT, SDL_HITTEST_RESIZE_LEFT } public const int SDL_WINDOWPOS_UNDEFINED_MASK = 0x1FFF0000; public const int SDL_WINDOWPOS_CENTERED_MASK = 0x2FFF0000; public const int SDL_WINDOWPOS_UNDEFINED = 0x1FFF0000; public const int SDL_WINDOWPOS_CENTERED = 0x2FFF0000; public static int SDL_WINDOWPOS_UNDEFINED_DISPLAY(int X) { return (SDL_WINDOWPOS_UNDEFINED_MASK | X); } public static bool SDL_WINDOWPOS_ISUNDEFINED(int X) { return (X & 0xFFFF0000) == SDL_WINDOWPOS_UNDEFINED_MASK; } public static int SDL_WINDOWPOS_CENTERED_DISPLAY(int X) { return (SDL_WINDOWPOS_CENTERED_MASK | X); } public static bool SDL_WINDOWPOS_ISCENTERED(int X) { return (X & 0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK; } [StructLayout(LayoutKind.Sequential)] public struct SDL_DisplayMode { public uint format; public int w; public int h; public int refresh_rate; public IntPtr driverdata; // void* } /* win refers to an SDL_Window*, area to a const SDL_Point*, data to a void*. * Only available in 2.0.4 or higher. */ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate SDL_HitTestResult SDL_HitTest(IntPtr win, IntPtr area, IntPtr data); /* IntPtr refers to an SDL_Window* */ [DllImport(nativeLibName, EntryPoint = "SDL_CreateWindow", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe IntPtr INTERNAL_SDL_CreateWindow( byte* title, int x, int y, int w, int h, SDL_WindowFlags flags ); public static unsafe IntPtr SDL_CreateWindow( string title, int x, int y, int w, int h, SDL_WindowFlags flags ) { int utf8TitleBufSize = Utf8SizeNullable(title); byte* utf8Title = stackalloc byte[utf8TitleBufSize]; return INTERNAL_SDL_CreateWindow( Utf8EncodeNullable(title, utf8Title, utf8TitleBufSize), x, y, w, h, flags ); } /* window refers to an SDL_Window*, renderer to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_CreateWindowAndRenderer( int width, int height, SDL_WindowFlags window_flags, out IntPtr window, out IntPtr renderer ); /* data refers to some native window type, IntPtr to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_CreateWindowFrom(IntPtr data); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_DestroyWindow(IntPtr window); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_DisableScreenSaver(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_EnableScreenSaver(); /* IntPtr refers to an SDL_DisplayMode. Just use closest. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GetClosestDisplayMode( int displayIndex, ref SDL_DisplayMode mode, out SDL_DisplayMode closest ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetCurrentDisplayMode( int displayIndex, out SDL_DisplayMode mode ); [DllImport(nativeLibName, EntryPoint = "SDL_GetCurrentVideoDriver", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetCurrentVideoDriver(); public static string SDL_GetCurrentVideoDriver() { return UTF8_ToManaged(INTERNAL_SDL_GetCurrentVideoDriver()); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetDesktopDisplayMode( int displayIndex, out SDL_DisplayMode mode ); [DllImport(nativeLibName, EntryPoint = "SDL_GetDisplayName", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetDisplayName(int index); public static string SDL_GetDisplayName(int index) { return UTF8_ToManaged(INTERNAL_SDL_GetDisplayName(index)); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetDisplayBounds( int displayIndex, out SDL_Rect rect ); /* Only available in 2.0.4 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetDisplayDPI( int displayIndex, out float ddpi, out float hdpi, out float vdpi ); /* Only available in 2.0.9 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_DisplayOrientation SDL_GetDisplayOrientation( int displayIndex ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetDisplayMode( int displayIndex, int modeIndex, out SDL_DisplayMode mode ); /* Only available in 2.0.5 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetDisplayUsableBounds( int displayIndex, out SDL_Rect rect ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetNumDisplayModes( int displayIndex ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetNumVideoDisplays(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetNumVideoDrivers(); [DllImport(nativeLibName, EntryPoint = "SDL_GetVideoDriver", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetVideoDriver( int index ); public static string SDL_GetVideoDriver(int index) { return UTF8_ToManaged(INTERNAL_SDL_GetVideoDriver(index)); } /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern float SDL_GetWindowBrightness( IntPtr window ); /* window refers to an SDL_Window* * Only available in 2.0.5 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetWindowOpacity( IntPtr window, float opacity ); /* window refers to an SDL_Window* * Only available in 2.0.5 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetWindowOpacity( IntPtr window, out float out_opacity ); /* modal_window and parent_window refer to an SDL_Window*s * Only available in 2.0.5 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetWindowModalFor( IntPtr modal_window, IntPtr parent_window ); /* window refers to an SDL_Window* * Only available in 2.0.5 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetWindowInputFocus(IntPtr window); /* window refers to an SDL_Window*, IntPtr to a void* */ [DllImport(nativeLibName, EntryPoint = "SDL_GetWindowData", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe IntPtr INTERNAL_SDL_GetWindowData( IntPtr window, byte* name ); public static unsafe IntPtr SDL_GetWindowData( IntPtr window, string name ) { int utf8NameBufSize = Utf8Size(name); byte* utf8Name = stackalloc byte[utf8NameBufSize]; return INTERNAL_SDL_GetWindowData( window, Utf8Encode(name, utf8Name, utf8NameBufSize) ); } /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetWindowDisplayIndex( IntPtr window ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetWindowDisplayMode( IntPtr window, out SDL_DisplayMode mode ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_GetWindowFlags(IntPtr window); /* IntPtr refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GetWindowFromID(uint id); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetWindowGammaRamp( IntPtr window, [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)] ushort[] red, [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)] ushort[] green, [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)] ushort[] blue ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_GetWindowGrab(IntPtr window); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_GetWindowID(IntPtr window); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_GetWindowPixelFormat( IntPtr window ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GetWindowMaximumSize( IntPtr window, out int max_w, out int max_h ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GetWindowMinimumSize( IntPtr window, out int min_w, out int min_h ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GetWindowPosition( IntPtr window, out int x, out int y ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GetWindowSize( IntPtr window, out int w, out int h ); /* IntPtr refers to an SDL_Surface*, window to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GetWindowSurface(IntPtr window); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, EntryPoint = "SDL_GetWindowTitle", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetWindowTitle( IntPtr window ); public static string SDL_GetWindowTitle(IntPtr window) { return UTF8_ToManaged( INTERNAL_SDL_GetWindowTitle(window) ); } /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GL_BindTexture( IntPtr texture, out float texw, out float texh ); /* IntPtr and window refer to an SDL_GLContext and SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GL_CreateContext(IntPtr window); /* context refers to an SDL_GLContext */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GL_DeleteContext(IntPtr context); [DllImport(nativeLibName, EntryPoint = "SDL_GL_LoadLibrary", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe int INTERNAL_SDL_GL_LoadLibrary(byte* path); public static unsafe int SDL_GL_LoadLibrary(string path) { byte* utf8Path = Utf8Encode(path); int result = INTERNAL_SDL_GL_LoadLibrary( utf8Path ); Marshal.FreeHGlobal((IntPtr) utf8Path); return result; } /* IntPtr refers to a function pointer, proc to a const char* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GL_GetProcAddress(IntPtr proc); /* IntPtr refers to a function pointer */ public static unsafe IntPtr SDL_GL_GetProcAddress(string proc) { int utf8ProcBufSize = Utf8Size(proc); byte* utf8Proc = stackalloc byte[utf8ProcBufSize]; return SDL_GL_GetProcAddress( (IntPtr) Utf8Encode(proc, utf8Proc, utf8ProcBufSize) ); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GL_UnloadLibrary(); [DllImport(nativeLibName, EntryPoint = "SDL_GL_ExtensionSupported", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe SDL_bool INTERNAL_SDL_GL_ExtensionSupported( byte* extension ); public static unsafe SDL_bool SDL_GL_ExtensionSupported(string extension) { int utf8ExtensionBufSize = Utf8SizeNullable(extension); byte* utf8Extension = stackalloc byte[utf8ExtensionBufSize]; return INTERNAL_SDL_GL_ExtensionSupported( Utf8Encode(extension, utf8Extension, utf8ExtensionBufSize) ); } /* Only available in SDL 2.0.2 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GL_ResetAttributes(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GL_GetAttribute( SDL_GLattr attr, out int value ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GL_GetSwapInterval(); /* window and context refer to an SDL_Window* and SDL_GLContext */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GL_MakeCurrent( IntPtr window, IntPtr context ); /* IntPtr refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GL_GetCurrentWindow(); /* IntPtr refers to an SDL_Context */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GL_GetCurrentContext(); /* window refers to an SDL_Window*. * Only available in SDL 2.0.1 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GL_GetDrawableSize( IntPtr window, out int w, out int h ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GL_SetAttribute( SDL_GLattr attr, int value ); public static int SDL_GL_SetAttribute( SDL_GLattr attr, SDL_GLprofile profile ) { return SDL_GL_SetAttribute(attr, (int)profile); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GL_SetSwapInterval(int interval); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GL_SwapWindow(IntPtr window); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GL_UnbindTexture(IntPtr texture); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_HideWindow(IntPtr window); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_IsScreenSaverEnabled(); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_MaximizeWindow(IntPtr window); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_MinimizeWindow(IntPtr window); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_RaiseWindow(IntPtr window); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_RestoreWindow(IntPtr window); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetWindowBrightness( IntPtr window, float brightness ); /* IntPtr and userdata are void*, window is an SDL_Window* */ [DllImport(nativeLibName, EntryPoint = "SDL_SetWindowData", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe IntPtr INTERNAL_SDL_SetWindowData( IntPtr window, byte* name, IntPtr userdata ); public static unsafe IntPtr SDL_SetWindowData( IntPtr window, string name, IntPtr userdata ) { int utf8NameBufSize = Utf8Size(name); byte* utf8Name = stackalloc byte[utf8NameBufSize]; return INTERNAL_SDL_SetWindowData( window, Utf8Encode(name, utf8Name, utf8NameBufSize), userdata ); } /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetWindowDisplayMode( IntPtr window, ref SDL_DisplayMode mode ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetWindowFullscreen( IntPtr window, uint flags ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetWindowGammaRamp( IntPtr window, [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)] ushort[] red, [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)] ushort[] green, [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)] ushort[] blue ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SetWindowGrab( IntPtr window, SDL_bool grabbed ); /* window refers to an SDL_Window*, icon to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SetWindowIcon( IntPtr window, IntPtr icon ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SetWindowMaximumSize( IntPtr window, int max_w, int max_h ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SetWindowMinimumSize( IntPtr window, int min_w, int min_h ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SetWindowPosition( IntPtr window, int x, int y ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SetWindowSize( IntPtr window, int w, int h ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SetWindowBordered( IntPtr window, SDL_bool bordered ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetWindowBordersSize( IntPtr window, out int top, out int left, out int bottom, out int right ); /* window refers to an SDL_Window* * Only available in 2.0.5 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SetWindowResizable( IntPtr window, SDL_bool resizable ); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, EntryPoint = "SDL_SetWindowTitle", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe void INTERNAL_SDL_SetWindowTitle( IntPtr window, byte* title ); public static unsafe void SDL_SetWindowTitle( IntPtr window, string title ) { int utf8TitleBufSize = Utf8Size(title); byte* utf8Title = stackalloc byte[utf8TitleBufSize]; INTERNAL_SDL_SetWindowTitle( window, Utf8Encode(title, utf8Title, utf8TitleBufSize) ); } /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_ShowWindow(IntPtr window); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_UpdateWindowSurface(IntPtr window); /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_UpdateWindowSurfaceRects( IntPtr window, [In] SDL_Rect[] rects, int numrects ); [DllImport(nativeLibName, EntryPoint = "SDL_VideoInit", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe int INTERNAL_SDL_VideoInit( byte* driver_name ); public static unsafe int SDL_VideoInit(string driver_name) { int utf8DriverNameBufSize = Utf8Size(driver_name); byte* utf8DriverName = stackalloc byte[utf8DriverNameBufSize]; return INTERNAL_SDL_VideoInit( Utf8Encode(driver_name, utf8DriverName, utf8DriverNameBufSize) ); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_VideoQuit(); /* window refers to an SDL_Window*, callback_data to a void* * Only available in 2.0.4 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetWindowHitTest( IntPtr window, SDL_HitTest callback, IntPtr callback_data ); /* IntPtr refers to an SDL_Window* * Only available in 2.0.4 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GetGrabbedWindow(); #endregion #region SDL_blendmode.h [Flags] public enum SDL_BlendMode { SDL_BLENDMODE_NONE = 0x00000000, SDL_BLENDMODE_BLEND = 0x00000001, SDL_BLENDMODE_ADD = 0x00000002, SDL_BLENDMODE_MOD = 0x00000004, SDL_BLENDMODE_MUL = 0x00000008, /* >= 2.0.11 */ SDL_BLENDMODE_INVALID = 0x7FFFFFFF } public enum SDL_BlendOperation { SDL_BLENDOPERATION_ADD = 0x1, SDL_BLENDOPERATION_SUBTRACT = 0x2, SDL_BLENDOPERATION_REV_SUBTRACT = 0x3, SDL_BLENDOPERATION_MINIMUM = 0x4, SDL_BLENDOPERATION_MAXIMUM = 0x5 } public enum SDL_BlendFactor { SDL_BLENDFACTOR_ZERO = 0x1, SDL_BLENDFACTOR_ONE = 0x2, SDL_BLENDFACTOR_SRC_COLOR = 0x3, SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR = 0x4, SDL_BLENDFACTOR_SRC_ALPHA = 0x5, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA = 0x6, SDL_BLENDFACTOR_DST_COLOR = 0x7, SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR = 0x8, SDL_BLENDFACTOR_DST_ALPHA = 0x9, SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA = 0xA } /* Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_BlendMode SDL_ComposeCustomBlendMode( SDL_BlendFactor srcColorFactor, SDL_BlendFactor dstColorFactor, SDL_BlendOperation colorOperation, SDL_BlendFactor srcAlphaFactor, SDL_BlendFactor dstAlphaFactor, SDL_BlendOperation alphaOperation ); #endregion #region SDL_vulkan.h /* Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, EntryPoint = "SDL_Vulkan_LoadLibrary", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe int INTERNAL_SDL_Vulkan_LoadLibrary( byte* path ); public static unsafe int SDL_Vulkan_LoadLibrary(string path) { byte* utf8Path = Utf8Encode(path); int result = INTERNAL_SDL_Vulkan_LoadLibrary( utf8Path ); Marshal.FreeHGlobal((IntPtr) utf8Path); return result; } /* Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_Vulkan_GetVkGetInstanceProcAddr(); /* Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_Vulkan_UnloadLibrary(); /* window refers to an SDL_Window*, pNames to a const char**. * Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_Vulkan_GetInstanceExtensions( IntPtr window, out uint pCount, IntPtr[] pNames ); /* window refers to an SDL_Window. * instance refers to a VkInstance. * surface refers to a VkSurfaceKHR. * Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_Vulkan_CreateSurface( IntPtr window, IntPtr instance, out ulong surface ); /* window refers to an SDL_Window*. * Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_Vulkan_GetDrawableSize( IntPtr window, out int w, out int h ); #endregion #region SDL_metal.h /* Only available in 2.0.11 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_Metal_CreateView( IntPtr window ); /* Only available in 2.0.11 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_Metal_DestroyView( IntPtr view ); #endregion #region SDL_render.h [Flags] public enum SDL_RendererFlags : uint { SDL_RENDERER_SOFTWARE = 0x00000001, SDL_RENDERER_ACCELERATED = 0x00000002, SDL_RENDERER_PRESENTVSYNC = 0x00000004, SDL_RENDERER_TARGETTEXTURE = 0x00000008 } [Flags] public enum SDL_RendererFlip { SDL_FLIP_NONE = 0x00000000, SDL_FLIP_HORIZONTAL = 0x00000001, SDL_FLIP_VERTICAL = 0x00000002 } public enum SDL_TextureAccess { SDL_TEXTUREACCESS_STATIC, SDL_TEXTUREACCESS_STREAMING, SDL_TEXTUREACCESS_TARGET } [Flags] public enum SDL_TextureModulate { SDL_TEXTUREMODULATE_NONE = 0x00000000, SDL_TEXTUREMODULATE_HORIZONTAL = 0x00000001, SDL_TEXTUREMODULATE_VERTICAL = 0x00000002 } [StructLayout(LayoutKind.Sequential)] public unsafe struct SDL_RendererInfo { public IntPtr name; // const char* public uint flags; public uint num_texture_formats; public fixed uint texture_formats[16]; public int max_texture_width; public int max_texture_height; } /* Only available in 2.0.11 or higher. */ public enum SDL_ScaleMode { SDL_ScaleModeNearest, SDL_ScaleModeLinear, SDL_ScaleModeBest } /* IntPtr refers to an SDL_Renderer*, window to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_CreateRenderer( IntPtr window, int index, SDL_RendererFlags flags ); /* IntPtr refers to an SDL_Renderer*, surface to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_CreateSoftwareRenderer(IntPtr surface); /* IntPtr refers to an SDL_Texture*, renderer to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_CreateTexture( IntPtr renderer, uint format, int access, int w, int h ); /* IntPtr refers to an SDL_Texture* * renderer refers to an SDL_Renderer* * surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_CreateTextureFromSurface( IntPtr renderer, IntPtr surface ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_DestroyRenderer(IntPtr renderer); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_DestroyTexture(IntPtr texture); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetNumRenderDrivers(); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetRenderDrawBlendMode( IntPtr renderer, out SDL_BlendMode blendMode ); /* texture refers to an SDL_Texture* * Only available in 2.0.11 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetTextureScaleMode( IntPtr texture, SDL_ScaleMode scaleMode ); /* texture refers to an SDL_Texture* * Only available in 2.0.11 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetTextureScaleMode( IntPtr texture, out SDL_ScaleMode scaleMode ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetRenderDrawColor( IntPtr renderer, out byte r, out byte g, out byte b, out byte a ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetRenderDriverInfo( int index, out SDL_RendererInfo info ); /* IntPtr refers to an SDL_Renderer*, window to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GetRenderer(IntPtr window); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetRendererInfo( IntPtr renderer, out SDL_RendererInfo info ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetRendererOutputSize( IntPtr renderer, out int w, out int h ); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetTextureAlphaMod( IntPtr texture, out byte alpha ); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetTextureBlendMode( IntPtr texture, out SDL_BlendMode blendMode ); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetTextureColorMod( IntPtr texture, out byte r, out byte g, out byte b ); /* texture refers to an SDL_Texture*, pixels to a void* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_LockTexture( IntPtr texture, ref SDL_Rect rect, out IntPtr pixels, out int pitch ); /* texture refers to an SDL_Texture*, pixels to a void*. * Internally, this function contains logic to use default values when * the rectangle is passed as NULL. * This overload allows for IntPtr.Zero to be passed for rect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_LockTexture( IntPtr texture, IntPtr rect, out IntPtr pixels, out int pitch ); /* texture refers to an SDL_Texture*, surface to an SDL_Surface* * Only available in 2.0.11 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_LockTextureToSurface( IntPtr texture, ref SDL_Rect rect, out IntPtr surface ); /* texture refers to an SDL_Texture*, surface to an SDL_Surface* * Internally, this function contains logic to use default values when * the rectangle is passed as NULL. * This overload allows for IntPtr.Zero to be passed for rect. * Only available in 2.0.11 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_LockTextureToSurface( IntPtr texture, IntPtr rect, out IntPtr surface ); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_QueryTexture( IntPtr texture, out uint format, out int access, out int w, out int h ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderClear(IntPtr renderer); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopy( IntPtr renderer, IntPtr texture, ref SDL_Rect srcrect, ref SDL_Rect dstrect ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source and destination rectangles are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for srcrect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopy( IntPtr renderer, IntPtr texture, IntPtr srcrect, ref SDL_Rect dstrect ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source and destination rectangles are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for dstrect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopy( IntPtr renderer, IntPtr texture, ref SDL_Rect srcrect, IntPtr dstrect ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source and destination rectangles are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for both SDL_Rects. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopy( IntPtr renderer, IntPtr texture, IntPtr srcrect, IntPtr dstrect ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyEx( IntPtr renderer, IntPtr texture, ref SDL_Rect srcrect, ref SDL_Rect dstrect, double angle, ref SDL_Point center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source, destination, and/or center are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for srcrect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyEx( IntPtr renderer, IntPtr texture, IntPtr srcrect, ref SDL_Rect dstrect, double angle, ref SDL_Point center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source, destination, and/or center are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for dstrect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyEx( IntPtr renderer, IntPtr texture, ref SDL_Rect srcrect, IntPtr dstrect, double angle, ref SDL_Point center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source, destination, and/or center are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for center. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyEx( IntPtr renderer, IntPtr texture, ref SDL_Rect srcrect, ref SDL_Rect dstrect, double angle, IntPtr center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source, destination, and/or center are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for both * srcrect and dstrect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyEx( IntPtr renderer, IntPtr texture, IntPtr srcrect, IntPtr dstrect, double angle, ref SDL_Point center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source, destination, and/or center are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for both * srcrect and center. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyEx( IntPtr renderer, IntPtr texture, IntPtr srcrect, ref SDL_Rect dstrect, double angle, IntPtr center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source, destination, and/or center are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for both * dstrect and center. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyEx( IntPtr renderer, IntPtr texture, ref SDL_Rect srcrect, IntPtr dstrect, double angle, IntPtr center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source, destination, and/or center are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for all * three parameters. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyEx( IntPtr renderer, IntPtr texture, IntPtr srcrect, IntPtr dstrect, double angle, IntPtr center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawLine( IntPtr renderer, int x1, int y1, int x2, int y2 ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawLines( IntPtr renderer, [In] SDL_Point[] points, int count ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawPoint( IntPtr renderer, int x, int y ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawPoints( IntPtr renderer, [In] SDL_Point[] points, int count ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawRect( IntPtr renderer, ref SDL_Rect rect ); /* renderer refers to an SDL_Renderer*, rect to an SDL_Rect*. * This overload allows for IntPtr.Zero (null) to be passed for rect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawRect( IntPtr renderer, IntPtr rect ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawRects( IntPtr renderer, [In] SDL_Rect[] rects, int count ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderFillRect( IntPtr renderer, ref SDL_Rect rect ); /* renderer refers to an SDL_Renderer*, rect to an SDL_Rect*. * This overload allows for IntPtr.Zero (null) to be passed for rect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderFillRect( IntPtr renderer, IntPtr rect ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderFillRects( IntPtr renderer, [In] SDL_Rect[] rects, int count ); #region Floating Point Render Functions /* This region only available in SDL 2.0.10 or higher. */ /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyF( IntPtr renderer, IntPtr texture, ref SDL_Rect srcrect, ref SDL_FRect dstrect ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source and destination rectangles are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for srcrect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyF( IntPtr renderer, IntPtr texture, IntPtr srcrect, ref SDL_FRect dstrect ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source and destination rectangles are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for dstrect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyF( IntPtr renderer, IntPtr texture, ref SDL_Rect srcrect, IntPtr dstrect ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source and destination rectangles are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for both SDL_Rects. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyF( IntPtr renderer, IntPtr texture, IntPtr srcrect, IntPtr dstrect ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyEx( IntPtr renderer, IntPtr texture, ref SDL_Rect srcrect, ref SDL_FRect dstrect, double angle, ref SDL_FPoint center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source, destination, and/or center are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for srcrect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyEx( IntPtr renderer, IntPtr texture, IntPtr srcrect, ref SDL_FRect dstrect, double angle, ref SDL_FPoint center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source, destination, and/or center are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for dstrect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyExF( IntPtr renderer, IntPtr texture, ref SDL_Rect srcrect, IntPtr dstrect, double angle, ref SDL_FPoint center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source, destination, and/or center are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for center. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyExF( IntPtr renderer, IntPtr texture, ref SDL_Rect srcrect, ref SDL_FRect dstrect, double angle, IntPtr center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source, destination, and/or center are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for both * srcrect and dstrect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyExF( IntPtr renderer, IntPtr texture, IntPtr srcrect, IntPtr dstrect, double angle, ref SDL_FPoint center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source, destination, and/or center are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for both * srcrect and center. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyExF( IntPtr renderer, IntPtr texture, IntPtr srcrect, ref SDL_FRect dstrect, double angle, IntPtr center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source, destination, and/or center are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for both * dstrect and center. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyExF( IntPtr renderer, IntPtr texture, ref SDL_Rect srcrect, IntPtr dstrect, double angle, IntPtr center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*. * Internally, this function contains logic to use default values when * source, destination, and/or center are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for all * three parameters. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderCopyExF( IntPtr renderer, IntPtr texture, IntPtr srcrect, IntPtr dstrect, double angle, IntPtr center, SDL_RendererFlip flip ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawPointF( IntPtr renderer, float x, float y ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawPointsF( IntPtr renderer, [In] SDL_FPoint[] points, int count ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawLineF( IntPtr renderer, float x1, float y1, float x2, float y2 ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawLinesF( IntPtr renderer, [In] SDL_FPoint[] points, int count ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawRectF( IntPtr renderer, ref SDL_FRect rect ); /* renderer refers to an SDL_Renderer*, rect to an SDL_Rect*. * This overload allows for IntPtr.Zero (null) to be passed for rect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawRectF( IntPtr renderer, IntPtr rect ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawRectsF( IntPtr renderer, [In] SDL_FRect[] rects, int count ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderFillRectF( IntPtr renderer, ref SDL_FRect rect ); /* renderer refers to an SDL_Renderer*, rect to an SDL_Rect*. * This overload allows for IntPtr.Zero (null) to be passed for rect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderFillRectF( IntPtr renderer, IntPtr rect ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderFillRectsF( IntPtr renderer, [In] SDL_FRect[] rects, int count ); #endregion /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_RenderGetClipRect( IntPtr renderer, out SDL_Rect rect ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_RenderGetLogicalSize( IntPtr renderer, out int w, out int h ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_RenderGetScale( IntPtr renderer, out float scaleX, out float scaleY ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderGetViewport( IntPtr renderer, out SDL_Rect rect ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_RenderPresent(IntPtr renderer); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderReadPixels( IntPtr renderer, ref SDL_Rect rect, uint format, IntPtr pixels, int pitch ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderSetClipRect( IntPtr renderer, ref SDL_Rect rect ); /* renderer refers to an SDL_Renderer* * This overload allows for IntPtr.Zero (null) to be passed for rect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderSetClipRect( IntPtr renderer, IntPtr rect ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderSetLogicalSize( IntPtr renderer, int w, int h ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderSetScale( IntPtr renderer, float scaleX, float scaleY ); /* renderer refers to an SDL_Renderer* * Only available in 2.0.5 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderSetIntegerScale( IntPtr renderer, SDL_bool enable ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderSetViewport( IntPtr renderer, ref SDL_Rect rect ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetRenderDrawBlendMode( IntPtr renderer, SDL_BlendMode blendMode ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetRenderDrawColor( IntPtr renderer, byte r, byte g, byte b, byte a ); /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetRenderTarget( IntPtr renderer, IntPtr texture ); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetTextureAlphaMod( IntPtr texture, byte alpha ); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetTextureBlendMode( IntPtr texture, SDL_BlendMode blendMode ); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetTextureColorMod( IntPtr texture, byte r, byte g, byte b ); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_UnlockTexture(IntPtr texture); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_UpdateTexture( IntPtr texture, ref SDL_Rect rect, IntPtr pixels, int pitch ); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_UpdateTexture( IntPtr texture, IntPtr rect, IntPtr pixels, int pitch ); /* texture refers to an SDL_Texture* * Only available in 2.0.1 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_UpdateYUVTexture( IntPtr texture, ref SDL_Rect rect, IntPtr yPlane, int yPitch, IntPtr uPlane, int uPitch, IntPtr vPlane, int vPitch ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_RenderTargetSupported( IntPtr renderer ); /* IntPtr refers to an SDL_Texture*, renderer to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GetRenderTarget(IntPtr renderer); /* renderer refers to an SDL_Renderer* * Only available in 2.0.8 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_RenderGetMetalLayer( IntPtr renderer ); /* renderer refers to an SDL_Renderer* * Only available in 2.0.8 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_RenderGetMetalCommandEncoder( IntPtr renderer ); /* renderer refers to an SDL_Renderer* * Only available in 2.0.4 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_RenderIsClipEnabled(IntPtr renderer); /* renderer refers to an SDL_Renderer* * Only available in 2.0.10 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderFlush(IntPtr renderer); #endregion #region SDL_pixels.h public static uint SDL_DEFINE_PIXELFOURCC(byte A, byte B, byte C, byte D) { return SDL_FOURCC(A, B, C, D); } public static uint SDL_DEFINE_PIXELFORMAT( SDL_PixelType type, uint order, SDL_PackedLayout layout, byte bits, byte bytes ) { return (uint) ( (1 << 28) | (((byte) type) << 24) | (((byte) order) << 20) | (((byte) layout) << 16) | (bits << 8) | (bytes) ); } public static byte SDL_PIXELFLAG(uint X) { return (byte) ((X >> 28) & 0x0F); } public static byte SDL_PIXELTYPE(uint X) { return (byte) ((X >> 24) & 0x0F); } public static byte SDL_PIXELORDER(uint X) { return (byte) ((X >> 20) & 0x0F); } public static byte SDL_PIXELLAYOUT(uint X) { return (byte) ((X >> 16) & 0x0F); } public static byte SDL_BITSPERPIXEL(uint X) { return (byte) ((X >> 8) & 0xFF); } public static byte SDL_BYTESPERPIXEL(uint X) { if (SDL_ISPIXELFORMAT_FOURCC(X)) { if ( (X == SDL_PIXELFORMAT_YUY2) || (X == SDL_PIXELFORMAT_UYVY) || (X == SDL_PIXELFORMAT_YVYU) ) { return 2; } return 1; } return (byte) (X & 0xFF); } public static bool SDL_ISPIXELFORMAT_INDEXED(uint format) { if (SDL_ISPIXELFORMAT_FOURCC(format)) { return false; } SDL_PixelType pType = (SDL_PixelType) SDL_PIXELTYPE(format); return ( pType == SDL_PixelType.SDL_PIXELTYPE_INDEX1 || pType == SDL_PixelType.SDL_PIXELTYPE_INDEX4 || pType == SDL_PixelType.SDL_PIXELTYPE_INDEX8 ); } public static bool SDL_ISPIXELFORMAT_PACKED(uint format) { if (SDL_ISPIXELFORMAT_FOURCC(format)) { return false; } SDL_PixelType pType = (SDL_PixelType) SDL_PIXELTYPE(format); return ( pType == SDL_PixelType.SDL_PIXELTYPE_PACKED8 || pType == SDL_PixelType.SDL_PIXELTYPE_PACKED16 || pType == SDL_PixelType.SDL_PIXELTYPE_PACKED32 ); } public static bool SDL_ISPIXELFORMAT_ARRAY(uint format) { if (SDL_ISPIXELFORMAT_FOURCC(format)) { return false; } SDL_PixelType pType = (SDL_PixelType) SDL_PIXELTYPE(format); return ( pType == SDL_PixelType.SDL_PIXELTYPE_ARRAYU8 || pType == SDL_PixelType.SDL_PIXELTYPE_ARRAYU16 || pType == SDL_PixelType.SDL_PIXELTYPE_ARRAYU32 || pType == SDL_PixelType.SDL_PIXELTYPE_ARRAYF16 || pType == SDL_PixelType.SDL_PIXELTYPE_ARRAYF32 ); } public static bool SDL_ISPIXELFORMAT_ALPHA(uint format) { if (SDL_ISPIXELFORMAT_PACKED(format)) { SDL_PackedOrder pOrder = (SDL_PackedOrder) SDL_PIXELORDER(format); return ( pOrder == SDL_PackedOrder.SDL_PACKEDORDER_ARGB || pOrder == SDL_PackedOrder.SDL_PACKEDORDER_RGBA || pOrder == SDL_PackedOrder.SDL_PACKEDORDER_ABGR || pOrder == SDL_PackedOrder.SDL_PACKEDORDER_BGRA ); } else if (SDL_ISPIXELFORMAT_ARRAY(format)) { SDL_ArrayOrder aOrder = (SDL_ArrayOrder) SDL_PIXELORDER(format); return ( aOrder == SDL_ArrayOrder.SDL_ARRAYORDER_ARGB || aOrder == SDL_ArrayOrder.SDL_ARRAYORDER_RGBA || aOrder == SDL_ArrayOrder.SDL_ARRAYORDER_ABGR || aOrder == SDL_ArrayOrder.SDL_ARRAYORDER_BGRA ); } return false; } public static bool SDL_ISPIXELFORMAT_FOURCC(uint format) { return (format == 0) && (SDL_PIXELFLAG(format) != 1); } public enum SDL_PixelType { SDL_PIXELTYPE_UNKNOWN, SDL_PIXELTYPE_INDEX1, SDL_PIXELTYPE_INDEX4, SDL_PIXELTYPE_INDEX8, SDL_PIXELTYPE_PACKED8, SDL_PIXELTYPE_PACKED16, SDL_PIXELTYPE_PACKED32, SDL_PIXELTYPE_ARRAYU8, SDL_PIXELTYPE_ARRAYU16, SDL_PIXELTYPE_ARRAYU32, SDL_PIXELTYPE_ARRAYF16, SDL_PIXELTYPE_ARRAYF32 } public enum SDL_BitmapOrder { SDL_BITMAPORDER_NONE, SDL_BITMAPORDER_4321, SDL_BITMAPORDER_1234 } public enum SDL_PackedOrder { SDL_PACKEDORDER_NONE, SDL_PACKEDORDER_XRGB, SDL_PACKEDORDER_RGBX, SDL_PACKEDORDER_ARGB, SDL_PACKEDORDER_RGBA, SDL_PACKEDORDER_XBGR, SDL_PACKEDORDER_BGRX, SDL_PACKEDORDER_ABGR, SDL_PACKEDORDER_BGRA } public enum SDL_ArrayOrder { SDL_ARRAYORDER_NONE, SDL_ARRAYORDER_RGB, SDL_ARRAYORDER_RGBA, SDL_ARRAYORDER_ARGB, SDL_ARRAYORDER_BGR, SDL_ARRAYORDER_BGRA, SDL_ARRAYORDER_ABGR } public enum SDL_PackedLayout { SDL_PACKEDLAYOUT_NONE, SDL_PACKEDLAYOUT_332, SDL_PACKEDLAYOUT_4444, SDL_PACKEDLAYOUT_1555, SDL_PACKEDLAYOUT_5551, SDL_PACKEDLAYOUT_565, SDL_PACKEDLAYOUT_8888, SDL_PACKEDLAYOUT_2101010, SDL_PACKEDLAYOUT_1010102 } public static readonly uint SDL_PIXELFORMAT_UNKNOWN = 0; public static readonly uint SDL_PIXELFORMAT_INDEX1LSB = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_INDEX1, (uint) SDL_BitmapOrder.SDL_BITMAPORDER_4321, 0, 1, 0 ); public static readonly uint SDL_PIXELFORMAT_INDEX1MSB = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_INDEX1, (uint) SDL_BitmapOrder.SDL_BITMAPORDER_1234, 0, 1, 0 ); public static readonly uint SDL_PIXELFORMAT_INDEX4LSB = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_INDEX4, (uint) SDL_BitmapOrder.SDL_BITMAPORDER_4321, 0, 4, 0 ); public static readonly uint SDL_PIXELFORMAT_INDEX4MSB = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_INDEX4, (uint) SDL_BitmapOrder.SDL_BITMAPORDER_1234, 0, 4, 0 ); public static readonly uint SDL_PIXELFORMAT_INDEX8 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1 ); public static readonly uint SDL_PIXELFORMAT_RGB332 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED8, (uint) SDL_PackedOrder.SDL_PACKEDORDER_XRGB, SDL_PackedLayout.SDL_PACKEDLAYOUT_332, 8, 1 ); public static readonly uint SDL_PIXELFORMAT_RGB444 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED16, (uint) SDL_PackedOrder.SDL_PACKEDORDER_XRGB, SDL_PackedLayout.SDL_PACKEDLAYOUT_4444, 12, 2 ); public static readonly uint SDL_PIXELFORMAT_BGR444 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED16, (uint) SDL_PackedOrder.SDL_PACKEDORDER_XBGR, SDL_PackedLayout.SDL_PACKEDLAYOUT_4444, 12, 2 ); public static readonly uint SDL_PIXELFORMAT_RGB555 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED16, (uint) SDL_PackedOrder.SDL_PACKEDORDER_XRGB, SDL_PackedLayout.SDL_PACKEDLAYOUT_1555, 15, 2 ); public static readonly uint SDL_PIXELFORMAT_BGR555 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_INDEX1, (uint) SDL_BitmapOrder.SDL_BITMAPORDER_4321, SDL_PackedLayout.SDL_PACKEDLAYOUT_1555, 15, 2 ); public static readonly uint SDL_PIXELFORMAT_ARGB4444 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED16, (uint) SDL_PackedOrder.SDL_PACKEDORDER_ARGB, SDL_PackedLayout.SDL_PACKEDLAYOUT_4444, 16, 2 ); public static readonly uint SDL_PIXELFORMAT_RGBA4444 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED16, (uint) SDL_PackedOrder.SDL_PACKEDORDER_RGBA, SDL_PackedLayout.SDL_PACKEDLAYOUT_4444, 16, 2 ); public static readonly uint SDL_PIXELFORMAT_ABGR4444 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED16, (uint) SDL_PackedOrder.SDL_PACKEDORDER_ABGR, SDL_PackedLayout.SDL_PACKEDLAYOUT_4444, 16, 2 ); public static readonly uint SDL_PIXELFORMAT_BGRA4444 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED16, (uint) SDL_PackedOrder.SDL_PACKEDORDER_BGRA, SDL_PackedLayout.SDL_PACKEDLAYOUT_4444, 16, 2 ); public static readonly uint SDL_PIXELFORMAT_ARGB1555 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED16, (uint) SDL_PackedOrder.SDL_PACKEDORDER_ARGB, SDL_PackedLayout.SDL_PACKEDLAYOUT_1555, 16, 2 ); public static readonly uint SDL_PIXELFORMAT_RGBA5551 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED16, (uint) SDL_PackedOrder.SDL_PACKEDORDER_RGBA, SDL_PackedLayout.SDL_PACKEDLAYOUT_5551, 16, 2 ); public static readonly uint SDL_PIXELFORMAT_ABGR1555 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED16, (uint) SDL_PackedOrder.SDL_PACKEDORDER_ABGR, SDL_PackedLayout.SDL_PACKEDLAYOUT_1555, 16, 2 ); public static readonly uint SDL_PIXELFORMAT_BGRA5551 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED16, (uint) SDL_PackedOrder.SDL_PACKEDORDER_BGRA, SDL_PackedLayout.SDL_PACKEDLAYOUT_5551, 16, 2 ); public static readonly uint SDL_PIXELFORMAT_RGB565 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED16, (uint) SDL_PackedOrder.SDL_PACKEDORDER_XRGB, SDL_PackedLayout.SDL_PACKEDLAYOUT_565, 16, 2 ); public static readonly uint SDL_PIXELFORMAT_BGR565 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED16, (uint) SDL_PackedOrder.SDL_PACKEDORDER_XBGR, SDL_PackedLayout.SDL_PACKEDLAYOUT_565, 16, 2 ); public static readonly uint SDL_PIXELFORMAT_RGB24 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_ARRAYU8, (uint) SDL_ArrayOrder.SDL_ARRAYORDER_RGB, 0, 24, 3 ); public static readonly uint SDL_PIXELFORMAT_BGR24 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_ARRAYU8, (uint) SDL_ArrayOrder.SDL_ARRAYORDER_BGR, 0, 24, 3 ); public static readonly uint SDL_PIXELFORMAT_RGB888 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED32, (uint) SDL_PackedOrder.SDL_PACKEDORDER_XRGB, SDL_PackedLayout.SDL_PACKEDLAYOUT_8888, 24, 4 ); public static readonly uint SDL_PIXELFORMAT_RGBX8888 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED32, (uint) SDL_PackedOrder.SDL_PACKEDORDER_RGBX, SDL_PackedLayout.SDL_PACKEDLAYOUT_8888, 24, 4 ); public static readonly uint SDL_PIXELFORMAT_BGR888 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED32, (uint) SDL_PackedOrder.SDL_PACKEDORDER_XBGR, SDL_PackedLayout.SDL_PACKEDLAYOUT_8888, 24, 4 ); public static readonly uint SDL_PIXELFORMAT_BGRX8888 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED32, (uint) SDL_PackedOrder.SDL_PACKEDORDER_BGRX, SDL_PackedLayout.SDL_PACKEDLAYOUT_8888, 24, 4 ); public static readonly uint SDL_PIXELFORMAT_ARGB8888 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED32, (uint) SDL_PackedOrder.SDL_PACKEDORDER_ARGB, SDL_PackedLayout.SDL_PACKEDLAYOUT_8888, 32, 4 ); public static readonly uint SDL_PIXELFORMAT_RGBA8888 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED32, (uint) SDL_PackedOrder.SDL_PACKEDORDER_RGBA, SDL_PackedLayout.SDL_PACKEDLAYOUT_8888, 32, 4 ); public static readonly uint SDL_PIXELFORMAT_ABGR8888 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED32, (uint) SDL_PackedOrder.SDL_PACKEDORDER_ABGR, SDL_PackedLayout.SDL_PACKEDLAYOUT_8888, 32, 4 ); public static readonly uint SDL_PIXELFORMAT_BGRA8888 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED32, (uint) SDL_PackedOrder.SDL_PACKEDORDER_BGRA, SDL_PackedLayout.SDL_PACKEDLAYOUT_8888, 32, 4 ); public static readonly uint SDL_PIXELFORMAT_ARGB2101010 = SDL_DEFINE_PIXELFORMAT( SDL_PixelType.SDL_PIXELTYPE_PACKED32, (uint) SDL_PackedOrder.SDL_PACKEDORDER_ARGB, SDL_PackedLayout.SDL_PACKEDLAYOUT_2101010, 32, 4 ); public static readonly uint SDL_PIXELFORMAT_YV12 = SDL_DEFINE_PIXELFOURCC( (byte) 'Y', (byte) 'V', (byte) '1', (byte) '2' ); public static readonly uint SDL_PIXELFORMAT_IYUV = SDL_DEFINE_PIXELFOURCC( (byte) 'I', (byte) 'Y', (byte) 'U', (byte) 'V' ); public static readonly uint SDL_PIXELFORMAT_YUY2 = SDL_DEFINE_PIXELFOURCC( (byte) 'Y', (byte) 'U', (byte) 'Y', (byte) '2' ); public static readonly uint SDL_PIXELFORMAT_UYVY = SDL_DEFINE_PIXELFOURCC( (byte) 'U', (byte) 'Y', (byte) 'V', (byte) 'Y' ); public static readonly uint SDL_PIXELFORMAT_YVYU = SDL_DEFINE_PIXELFOURCC( (byte) 'Y', (byte) 'V', (byte) 'Y', (byte) 'U' ); [StructLayout(LayoutKind.Sequential)] public struct SDL_Color { public byte r; public byte g; public byte b; public byte a; } [StructLayout(LayoutKind.Sequential)] public struct SDL_Palette { public int ncolors; public IntPtr colors; public int version; public int refcount; } [StructLayout(LayoutKind.Sequential)] public struct SDL_PixelFormat { public uint format; public IntPtr palette; // SDL_Palette* public byte BitsPerPixel; public byte BytesPerPixel; public uint Rmask; public uint Gmask; public uint Bmask; public uint Amask; public byte Rloss; public byte Gloss; public byte Bloss; public byte Aloss; public byte Rshift; public byte Gshift; public byte Bshift; public byte Ashift; public int refcount; public IntPtr next; // SDL_PixelFormat* } /* IntPtr refers to an SDL_PixelFormat* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_AllocFormat(uint pixel_format); /* IntPtr refers to an SDL_Palette* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_AllocPalette(int ncolors); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_CalculateGammaRamp( float gamma, [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)] ushort[] ramp ); /* format refers to an SDL_PixelFormat* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_FreeFormat(IntPtr format); /* palette refers to an SDL_Palette* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_FreePalette(IntPtr palette); [DllImport(nativeLibName, EntryPoint = "SDL_GetPixelFormatName", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetPixelFormatName( uint format ); public static string SDL_GetPixelFormatName(uint format) { return UTF8_ToManaged( INTERNAL_SDL_GetPixelFormatName(format) ); } /* format refers to an SDL_PixelFormat* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GetRGB( uint pixel, IntPtr format, out byte r, out byte g, out byte b ); /* format refers to an SDL_PixelFormat* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GetRGBA( uint pixel, IntPtr format, out byte r, out byte g, out byte b, out byte a ); /* format refers to an SDL_PixelFormat* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_MapRGB( IntPtr format, byte r, byte g, byte b ); /* format refers to an SDL_PixelFormat* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_MapRGBA( IntPtr format, byte r, byte g, byte b, byte a ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_MasksToPixelFormatEnum( int bpp, uint Rmask, uint Gmask, uint Bmask, uint Amask ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_PixelFormatEnumToMasks( uint format, out int bpp, out uint Rmask, out uint Gmask, out uint Bmask, out uint Amask ); /* palette refers to an SDL_Palette* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetPaletteColors( IntPtr palette, [In] SDL_Color[] colors, int firstcolor, int ncolors ); /* format and palette refer to an SDL_PixelFormat* and SDL_Palette* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetPixelFormatPalette( IntPtr format, IntPtr palette ); #endregion #region SDL_rect.h [StructLayout(LayoutKind.Sequential)] public struct SDL_Point { public int x; public int y; } [StructLayout(LayoutKind.Sequential)] public struct SDL_Rect { public int x; public int y; public int w; public int h; } /* Only available in 2.0.10 or higher. */ [StructLayout(LayoutKind.Sequential)] public struct SDL_FPoint { public float x; public float y; } /* Only available in 2.0.10 or higher. */ [StructLayout(LayoutKind.Sequential)] public struct SDL_FRect { public float x; public float y; public float w; public float h; } /* Only available in 2.0.4 or higher. */ public static SDL_bool SDL_PointInRect(ref SDL_Point p, ref SDL_Rect r) { return ( (p.x >= r.x) && (p.x < (r.x + r.w)) && (p.y >= r.y) && (p.y < (r.y + r.h)) ) ? SDL_bool.SDL_TRUE : SDL_bool.SDL_FALSE; } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_EnclosePoints( [In] SDL_Point[] points, int count, ref SDL_Rect clip, out SDL_Rect result ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasIntersection( ref SDL_Rect A, ref SDL_Rect B ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_IntersectRect( ref SDL_Rect A, ref SDL_Rect B, out SDL_Rect result ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_IntersectRectAndLine( ref SDL_Rect rect, ref int X1, ref int Y1, ref int X2, ref int Y2 ); public static SDL_bool SDL_RectEmpty(ref SDL_Rect r) { return ((r.w <= 0) || (r.h <= 0)) ? SDL_bool.SDL_TRUE : SDL_bool.SDL_FALSE; } public static SDL_bool SDL_RectEquals( ref SDL_Rect a, ref SDL_Rect b ) { return ( (a.x == b.x) && (a.y == b.y) && (a.w == b.w) && (a.h == b.h) ) ? SDL_bool.SDL_TRUE : SDL_bool.SDL_FALSE; } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_UnionRect( ref SDL_Rect A, ref SDL_Rect B, out SDL_Rect result ); #endregion #region SDL_surface.h public const uint SDL_SWSURFACE = 0x00000000; public const uint SDL_PREALLOC = 0x00000001; public const uint SDL_RLEACCEL = 0x00000002; public const uint SDL_DONTFREE = 0x00000004; [StructLayout(LayoutKind.Sequential)] public struct SDL_Surface { public uint flags; public IntPtr format; // SDL_PixelFormat* public int w; public int h; public int pitch; public IntPtr pixels; // void* public IntPtr userdata; // void* public int locked; public IntPtr lock_data; // void* public SDL_Rect clip_rect; public IntPtr map; // SDL_BlitMap* public int refcount; } /* surface refers to an SDL_Surface* */ public static bool SDL_MUSTLOCK(IntPtr surface) { SDL_Surface sur; sur = (SDL_Surface) Marshal.PtrToStructure( surface, typeof(SDL_Surface) ); return (sur.flags & SDL_RLEACCEL) != 0; } /* src and dst refer to an SDL_Surface* */ [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlit", CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_BlitSurface( IntPtr src, ref SDL_Rect srcrect, IntPtr dst, ref SDL_Rect dstrect ); /* src and dst refer to an SDL_Surface* * Internally, this function contains logic to use default values when * source and destination rectangles are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for srcrect. */ [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlit", CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_BlitSurface( IntPtr src, IntPtr srcrect, IntPtr dst, ref SDL_Rect dstrect ); /* src and dst refer to an SDL_Surface* * Internally, this function contains logic to use default values when * source and destination rectangles are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for dstrect. */ [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlit", CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_BlitSurface( IntPtr src, ref SDL_Rect srcrect, IntPtr dst, IntPtr dstrect ); /* src and dst refer to an SDL_Surface* * Internally, this function contains logic to use default values when * source and destination rectangles are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for both SDL_Rects. */ [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlit", CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_BlitSurface( IntPtr src, IntPtr srcrect, IntPtr dst, IntPtr dstrect ); /* src and dst refer to an SDL_Surface* */ [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlitScaled", CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_BlitScaled( IntPtr src, ref SDL_Rect srcrect, IntPtr dst, ref SDL_Rect dstrect ); /* src and dst refer to an SDL_Surface* * Internally, this function contains logic to use default values when * source and destination rectangles are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for srcrect. */ [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlitScaled", CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_BlitScaled( IntPtr src, IntPtr srcrect, IntPtr dst, ref SDL_Rect dstrect ); /* src and dst refer to an SDL_Surface* * Internally, this function contains logic to use default values when * source and destination rectangles are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for dstrect. */ [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlitScaled", CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_BlitScaled( IntPtr src, ref SDL_Rect srcrect, IntPtr dst, IntPtr dstrect ); /* src and dst refer to an SDL_Surface* * Internally, this function contains logic to use default values when * source and destination rectangles are passed as NULL. * This overload allows for IntPtr.Zero (null) to be passed for both SDL_Rects. */ [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlitScaled", CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_BlitScaled( IntPtr src, IntPtr srcrect, IntPtr dst, IntPtr dstrect ); /* src and dst are void* pointers */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_ConvertPixels( int width, int height, uint src_format, IntPtr src, int src_pitch, uint dst_format, IntPtr dst, int dst_pitch ); /* IntPtr refers to an SDL_Surface* * src refers to an SDL_Surface* * fmt refers to an SDL_PixelFormat* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_ConvertSurface( IntPtr src, IntPtr fmt, uint flags ); /* IntPtr refers to an SDL_Surface*, src to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_ConvertSurfaceFormat( IntPtr src, uint pixel_format, uint flags ); /* IntPtr refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_CreateRGBSurface( uint flags, int width, int height, int depth, uint Rmask, uint Gmask, uint Bmask, uint Amask ); /* IntPtr refers to an SDL_Surface*, pixels to a void* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_CreateRGBSurfaceFrom( IntPtr pixels, int width, int height, int depth, int pitch, uint Rmask, uint Gmask, uint Bmask, uint Amask ); /* IntPtr refers to an SDL_Surface* * Only available in 2.0.5 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_CreateRGBSurfaceWithFormat( uint flags, int width, int height, int depth, uint format ); /* IntPtr refers to an SDL_Surface*, pixels to a void* * Only available in 2.0.5 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_CreateRGBSurfaceWithFormatFrom( IntPtr pixels, int width, int height, int depth, int pitch, uint format ); /* dst refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_FillRect( IntPtr dst, ref SDL_Rect rect, uint color ); /* dst refers to an SDL_Surface*. * This overload allows passing NULL to rect. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_FillRect( IntPtr dst, IntPtr rect, uint color ); /* dst refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_FillRects( IntPtr dst, [In] SDL_Rect[] rects, int count, uint color ); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_FreeSurface(IntPtr surface); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GetClipRect( IntPtr surface, out SDL_Rect rect ); /* surface refers to an SDL_Surface*. * Only available in 2.0.9 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasColorKey(IntPtr surface); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetColorKey( IntPtr surface, out uint key ); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetSurfaceAlphaMod( IntPtr surface, out byte alpha ); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetSurfaceBlendMode( IntPtr surface, out SDL_BlendMode blendMode ); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetSurfaceColorMod( IntPtr surface, out byte r, out byte g, out byte b ); /* These are for SDL_LoadBMP, which is a macro in the SDL headers. */ /* IntPtr refers to an SDL_Surface* */ /* THIS IS AN RWops FUNCTION! */ [DllImport(nativeLibName, EntryPoint = "SDL_LoadBMP_RW", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_LoadBMP_RW( IntPtr src, int freesrc ); public static IntPtr SDL_LoadBMP(string file) { IntPtr rwops = SDL_RWFromFile(file, "rb"); return INTERNAL_SDL_LoadBMP_RW(rwops, 1); } /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_LockSurface(IntPtr surface); /* src and dst refer to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_LowerBlit( IntPtr src, ref SDL_Rect srcrect, IntPtr dst, ref SDL_Rect dstrect ); /* src and dst refer to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_LowerBlitScaled( IntPtr src, ref SDL_Rect srcrect, IntPtr dst, ref SDL_Rect dstrect ); /* These are for SDL_SaveBMP, which is a macro in the SDL headers. */ /* IntPtr refers to an SDL_Surface* */ /* THIS IS AN RWops FUNCTION! */ [DllImport(nativeLibName, EntryPoint = "SDL_SaveBMP_RW", CallingConvention = CallingConvention.Cdecl)] private static extern int INTERNAL_SDL_SaveBMP_RW( IntPtr surface, IntPtr src, int freesrc ); public static int SDL_SaveBMP(IntPtr surface, string file) { IntPtr rwops = SDL_RWFromFile(file, "wb"); return INTERNAL_SDL_SaveBMP_RW(surface, rwops, 1); } /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_SetClipRect( IntPtr surface, ref SDL_Rect rect ); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetColorKey( IntPtr surface, int flag, uint key ); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetSurfaceAlphaMod( IntPtr surface, byte alpha ); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetSurfaceBlendMode( IntPtr surface, SDL_BlendMode blendMode ); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetSurfaceColorMod( IntPtr surface, byte r, byte g, byte b ); /* surface refers to an SDL_Surface*, palette to an SDL_Palette* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetSurfacePalette( IntPtr surface, IntPtr palette ); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetSurfaceRLE( IntPtr surface, int flag ); /* src and dst refer to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SoftStretch( IntPtr src, ref SDL_Rect srcrect, IntPtr dst, ref SDL_Rect dstrect ); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_UnlockSurface(IntPtr surface); /* src and dst refer to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_UpperBlit( IntPtr src, ref SDL_Rect srcrect, IntPtr dst, ref SDL_Rect dstrect ); /* src and dst refer to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_UpperBlitScaled( IntPtr src, ref SDL_Rect srcrect, IntPtr dst, ref SDL_Rect dstrect ); /* surface and IntPtr refer to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_DuplicateSurface(IntPtr surface); #endregion #region SDL_clipboard.h [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasClipboardText(); [DllImport(nativeLibName, EntryPoint = "SDL_GetClipboardText", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetClipboardText(); public static string SDL_GetClipboardText() { return UTF8_ToManaged(INTERNAL_SDL_GetClipboardText(), true); } [DllImport(nativeLibName, EntryPoint = "SDL_SetClipboardText", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe int INTERNAL_SDL_SetClipboardText( byte* text ); public static unsafe int SDL_SetClipboardText( string text ) { byte* utf8Text = Utf8Encode(text); int result = INTERNAL_SDL_SetClipboardText( utf8Text ); Marshal.FreeHGlobal((IntPtr) utf8Text); return result; } #endregion #region SDL_events.h /* General keyboard/mouse state definitions. */ public const byte SDL_PRESSED = 1; public const byte SDL_RELEASED = 0; /* Default size is according to SDL2 default. */ public const int SDL_TEXTEDITINGEVENT_TEXT_SIZE = 32; public const int SDL_TEXTINPUTEVENT_TEXT_SIZE = 32; /* The types of events that can be delivered. */ public enum SDL_EventType : uint { SDL_FIRSTEVENT = 0, /* Application events */ SDL_QUIT = 0x100, /* iOS/Android/WinRT app events */ SDL_APP_TERMINATING, SDL_APP_LOWMEMORY, SDL_APP_WILLENTERBACKGROUND, SDL_APP_DIDENTERBACKGROUND, SDL_APP_WILLENTERFOREGROUND, SDL_APP_DIDENTERFOREGROUND, /* Display events */ /* Only available in SDL 2.0.9 or higher. */ SDL_DISPLAYEVENT = 0x150, /* Window events */ SDL_WINDOWEVENT = 0x200, SDL_SYSWMEVENT, /* Keyboard events */ SDL_KEYDOWN = 0x300, SDL_KEYUP, SDL_TEXTEDITING, SDL_TEXTINPUT, SDL_KEYMAPCHANGED, /* Mouse events */ SDL_MOUSEMOTION = 0x400, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP, SDL_MOUSEWHEEL, /* Joystick events */ SDL_JOYAXISMOTION = 0x600, SDL_JOYBALLMOTION, SDL_JOYHATMOTION, SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED, /* Game controller events */ SDL_CONTROLLERAXISMOTION = 0x650, SDL_CONTROLLERBUTTONDOWN, SDL_CONTROLLERBUTTONUP, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEREMOVED, SDL_CONTROLLERDEVICEREMAPPED, /* Touch events */ SDL_FINGERDOWN = 0x700, SDL_FINGERUP, SDL_FINGERMOTION, /* Gesture events */ SDL_DOLLARGESTURE = 0x800, SDL_DOLLARRECORD, SDL_MULTIGESTURE, /* Clipboard events */ SDL_CLIPBOARDUPDATE = 0x900, /* Drag and drop events */ SDL_DROPFILE = 0x1000, /* Only available in 2.0.4 or higher. */ SDL_DROPTEXT, SDL_DROPBEGIN, SDL_DROPCOMPLETE, /* Audio hotplug events */ /* Only available in SDL 2.0.4 or higher. */ SDL_AUDIODEVICEADDED = 0x1100, SDL_AUDIODEVICEREMOVED, /* Sensor events */ /* Only available in SDL 2.0.9 or higher. */ SDL_SENSORUPDATE = 0x1200, /* Render events */ /* Only available in SDL 2.0.2 or higher. */ SDL_RENDER_TARGETS_RESET = 0x2000, /* Only available in SDL 2.0.4 or higher. */ SDL_RENDER_DEVICE_RESET, /* Events SDL_USEREVENT through SDL_LASTEVENT are for * your use, and should be allocated with * SDL_RegisterEvents() */ SDL_USEREVENT = 0x8000, /* The last event, used for bouding arrays. */ SDL_LASTEVENT = 0xFFFF } /* Only available in 2.0.4 or higher. */ public enum SDL_MouseWheelDirection : uint { SDL_MOUSEWHEEL_NORMAL, SDL_MOUSEWHEEL_FLIPPED } /* Fields shared by every event */ [StructLayout(LayoutKind.Sequential)] public struct SDL_GenericEvent { public SDL_EventType type; public UInt32 timestamp; } // Ignore private members used for padding in this struct #pragma warning disable 0169 [StructLayout(LayoutKind.Sequential)] public struct SDL_DisplayEvent { public SDL_EventType type; public UInt32 timestamp; public UInt32 display; public SDL_DisplayEventID displayEvent; // event, lolC# private byte padding1; private byte padding2; private byte padding3; public Int32 data1; } #pragma warning restore 0169 // Ignore private members used for padding in this struct #pragma warning disable 0169 /* Window state change event data (event.window.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_WindowEvent { public SDL_EventType type; public UInt32 timestamp; public UInt32 windowID; public SDL_WindowEventID windowEvent; // event, lolC# private byte padding1; private byte padding2; private byte padding3; public Int32 data1; public Int32 data2; } #pragma warning restore 0169 // Ignore private members used for padding in this struct #pragma warning disable 0169 /* Keyboard button event structure (event.key.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_KeyboardEvent { public SDL_EventType type; public UInt32 timestamp; public UInt32 windowID; public byte state; public byte repeat; /* non-zero if this is a repeat */ private byte padding2; private byte padding3; public SDL_Keysym keysym; } #pragma warning restore 0169 [StructLayout(LayoutKind.Sequential)] public unsafe struct SDL_TextEditingEvent { public SDL_EventType type; public UInt32 timestamp; public UInt32 windowID; public fixed byte text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; public Int32 start; public Int32 length; } [StructLayout(LayoutKind.Sequential)] public unsafe struct SDL_TextInputEvent { public SDL_EventType type; public UInt32 timestamp; public UInt32 windowID; public fixed byte text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; } // Ignore private members used for padding in this struct #pragma warning disable 0169 /* Mouse motion event structure (event.motion.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_MouseMotionEvent { public SDL_EventType type; public UInt32 timestamp; public UInt32 windowID; public UInt32 which; public byte state; /* bitmask of buttons */ private byte padding1; private byte padding2; private byte padding3; public Int32 x; public Int32 y; public Int32 xrel; public Int32 yrel; } #pragma warning restore 0169 // Ignore private members used for padding in this struct #pragma warning disable 0169 /* Mouse button event structure (event.button.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_MouseButtonEvent { public SDL_EventType type; public UInt32 timestamp; public UInt32 windowID; public UInt32 which; public byte button; /* button id */ public byte state; /* SDL_PRESSED or SDL_RELEASED */ public byte clicks; /* 1 for single-click, 2 for double-click, etc. */ private byte padding1; public Int32 x; public Int32 y; } #pragma warning restore 0169 /* Mouse wheel event structure (event.wheel.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_MouseWheelEvent { public SDL_EventType type; public UInt32 timestamp; public UInt32 windowID; public UInt32 which; public Int32 x; /* amount scrolled horizontally */ public Int32 y; /* amount scrolled vertically */ public UInt32 direction; /* Set to one of the SDL_MOUSEWHEEL_* defines */ } // Ignore private members used for padding in this struct #pragma warning disable 0169 /* Joystick axis motion event structure (event.jaxis.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_JoyAxisEvent { public SDL_EventType type; public UInt32 timestamp; public Int32 which; /* SDL_JoystickID */ public byte axis; private byte padding1; private byte padding2; private byte padding3; public Int16 axisValue; /* value, lolC# */ public UInt16 padding4; } #pragma warning restore 0169 // Ignore private members used for padding in this struct #pragma warning disable 0169 /* Joystick trackball motion event structure (event.jball.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_JoyBallEvent { public SDL_EventType type; public UInt32 timestamp; public Int32 which; /* SDL_JoystickID */ public byte ball; private byte padding1; private byte padding2; private byte padding3; public Int16 xrel; public Int16 yrel; } #pragma warning restore 0169 // Ignore private members used for padding in this struct #pragma warning disable 0169 /* Joystick hat position change event struct (event.jhat.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_JoyHatEvent { public SDL_EventType type; public UInt32 timestamp; public Int32 which; /* SDL_JoystickID */ public byte hat; /* index of the hat */ public byte hatValue; /* value, lolC# */ private byte padding1; private byte padding2; } #pragma warning restore 0169 // Ignore private members used for padding in this struct #pragma warning disable 0169 /* Joystick button event structure (event.jbutton.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_JoyButtonEvent { public SDL_EventType type; public UInt32 timestamp; public Int32 which; /* SDL_JoystickID */ public byte button; public byte state; /* SDL_PRESSED or SDL_RELEASED */ private byte padding1; private byte padding2; } #pragma warning restore 0169 /* Joystick device event structure (event.jdevice.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_JoyDeviceEvent { public SDL_EventType type; public UInt32 timestamp; public Int32 which; /* SDL_JoystickID */ } // Ignore private members used for padding in this struct #pragma warning disable 0169 /* Game controller axis motion event (event.caxis.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_ControllerAxisEvent { public SDL_EventType type; public UInt32 timestamp; public Int32 which; /* SDL_JoystickID */ public byte axis; private byte padding1; private byte padding2; private byte padding3; public Int16 axisValue; /* value, lolC# */ private UInt16 padding4; } #pragma warning restore 0169 // Ignore private members used for padding in this struct #pragma warning disable 0169 /* Game controller button event (event.cbutton.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_ControllerButtonEvent { public SDL_EventType type; public UInt32 timestamp; public Int32 which; /* SDL_JoystickID */ public byte button; public byte state; private byte padding1; private byte padding2; } #pragma warning restore 0169 /* Game controller device event (event.cdevice.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_ControllerDeviceEvent { public SDL_EventType type; public UInt32 timestamp; public Int32 which; /* joystick id for ADDED, * else instance id */ } // Ignore private members used for padding in this struct #pragma warning disable 0169 /* Audio device event (event.adevice.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_AudioDeviceEvent { public UInt32 type; public UInt32 timestamp; public UInt32 which; public byte iscapture; private byte padding1; private byte padding2; private byte padding3; } #pragma warning restore 0169 [StructLayout(LayoutKind.Sequential)] public struct SDL_TouchFingerEvent { public UInt32 type; public UInt32 timestamp; public Int64 touchId; // SDL_TouchID public Int64 fingerId; // SDL_GestureID public float x; public float y; public float dx; public float dy; public float pressure; public uint windowID; } [StructLayout(LayoutKind.Sequential)] public struct SDL_MultiGestureEvent { public UInt32 type; public UInt32 timestamp; public Int64 touchId; // SDL_TouchID public float dTheta; public float dDist; public float x; public float y; public UInt16 numFingers; public UInt16 padding; } [StructLayout(LayoutKind.Sequential)] public struct SDL_DollarGestureEvent { public UInt32 type; public UInt32 timestamp; public Int64 touchId; // SDL_TouchID public Int64 gestureId; // SDL_GestureID public UInt32 numFingers; public float error; public float x; public float y; } /* File open request by system (event.drop.*), enabled by * default */ [StructLayout(LayoutKind.Sequential)] public struct SDL_DropEvent { public SDL_EventType type; public UInt32 timestamp; /* char* filename, to be freed. * Access the variable EXACTLY ONCE like this: * string s = SDL.UTF8_ToManaged(evt.drop.file, true); */ public IntPtr file; public UInt32 windowID; } [StructLayout(LayoutKind.Sequential)] public unsafe struct SDL_SensorEvent { public SDL_EventType type; public UInt32 timestamp; public Int32 which; public fixed float data[6]; } /* The "quit requested" event */ [StructLayout(LayoutKind.Sequential)] public struct SDL_QuitEvent { public SDL_EventType type; public UInt32 timestamp; } /* A user defined event (event.user.*) */ [StructLayout(LayoutKind.Sequential)] public struct SDL_UserEvent { public UInt32 type; public UInt32 timestamp; public UInt32 windowID; public Int32 code; public IntPtr data1; /* user-defined */ public IntPtr data2; /* user-defined */ } /* A video driver dependent event (event.syswm.*), disabled */ [StructLayout(LayoutKind.Sequential)] public struct SDL_SysWMEvent { public SDL_EventType type; public UInt32 timestamp; public IntPtr msg; /* SDL_SysWMmsg*, system-dependent*/ } /* General event structure */ // C# doesn't do unions, so we do this ugly thing. */ [StructLayout(LayoutKind.Explicit)] public unsafe struct SDL_Event { [FieldOffset(0)] public SDL_EventType type; [FieldOffset(0)] public SDL_EventType typeFSharp; [FieldOffset(0)] public SDL_DisplayEvent display; [FieldOffset(0)] public SDL_WindowEvent window; [FieldOffset(0)] public SDL_KeyboardEvent key; [FieldOffset(0)] public SDL_TextEditingEvent edit; [FieldOffset(0)] public SDL_TextInputEvent text; [FieldOffset(0)] public SDL_MouseMotionEvent motion; [FieldOffset(0)] public SDL_MouseButtonEvent button; [FieldOffset(0)] public SDL_MouseWheelEvent wheel; [FieldOffset(0)] public SDL_JoyAxisEvent jaxis; [FieldOffset(0)] public SDL_JoyBallEvent jball; [FieldOffset(0)] public SDL_JoyHatEvent jhat; [FieldOffset(0)] public SDL_JoyButtonEvent jbutton; [FieldOffset(0)] public SDL_JoyDeviceEvent jdevice; [FieldOffset(0)] public SDL_ControllerAxisEvent caxis; [FieldOffset(0)] public SDL_ControllerButtonEvent cbutton; [FieldOffset(0)] public SDL_ControllerDeviceEvent cdevice; [FieldOffset(0)] public SDL_AudioDeviceEvent adevice; [FieldOffset(0)] public SDL_SensorEvent sensor; [FieldOffset(0)] public SDL_QuitEvent quit; [FieldOffset(0)] public SDL_UserEvent user; [FieldOffset(0)] public SDL_SysWMEvent syswm; [FieldOffset(0)] public SDL_TouchFingerEvent tfinger; [FieldOffset(0)] public SDL_MultiGestureEvent mgesture; [FieldOffset(0)] public SDL_DollarGestureEvent dgesture; [FieldOffset(0)] public SDL_DropEvent drop; [FieldOffset(0)] private fixed byte padding[56]; } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate int SDL_EventFilter( IntPtr userdata, // void* IntPtr sdlevent // SDL_Event* event, lolC# ); /* Pump the event loop, getting events from the input devices*/ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_PumpEvents(); public enum SDL_eventaction { SDL_ADDEVENT, SDL_PEEKEVENT, SDL_GETEVENT } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_PeepEvents( [Out] SDL_Event[] events, int numevents, SDL_eventaction action, SDL_EventType minType, SDL_EventType maxType ); /* Checks to see if certain events are in the event queue */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasEvent(SDL_EventType type); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasEvents( SDL_EventType minType, SDL_EventType maxType ); /* Clears events from the event queue */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_FlushEvent(SDL_EventType type); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_FlushEvents( SDL_EventType min, SDL_EventType max ); /* Polls for currently pending events */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_PollEvent(out SDL_Event _event); /* Waits indefinitely for the next event */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_WaitEvent(out SDL_Event _event); /* Waits until the specified timeout (in ms) for the next event */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_WaitEventTimeout(out SDL_Event _event, int timeout); /* Add an event to the event queue */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_PushEvent(ref SDL_Event _event); /* userdata refers to a void* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SetEventFilter( SDL_EventFilter filter, IntPtr userdata ); /* userdata refers to a void* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] private static extern SDL_bool SDL_GetEventFilter( out IntPtr filter, out IntPtr userdata ); public static SDL_bool SDL_GetEventFilter( out SDL_EventFilter filter, out IntPtr userdata ) { IntPtr result = IntPtr.Zero; SDL_bool retval = SDL_GetEventFilter(out result, out userdata); if (result != IntPtr.Zero) { filter = (SDL_EventFilter) Marshal.GetDelegateForFunctionPointer( result, typeof(SDL_EventFilter) ); } else { filter = null; } return retval; } /* userdata refers to a void* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_AddEventWatch( SDL_EventFilter filter, IntPtr userdata ); /* userdata refers to a void* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_DelEventWatch( SDL_EventFilter filter, IntPtr userdata ); /* userdata refers to a void* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_FilterEvents( SDL_EventFilter filter, IntPtr userdata ); /* These are for SDL_EventState() */ public const int SDL_QUERY = -1; public const int SDL_IGNORE = 0; public const int SDL_DISABLE = 0; public const int SDL_ENABLE = 1; /* This function allows you to enable/disable certain events */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern byte SDL_EventState(SDL_EventType type, int state); /* Get the state of an event */ public static byte SDL_GetEventState(SDL_EventType type) { return SDL_EventState(type, SDL_QUERY); } /* Allocate a set of user-defined events */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_RegisterEvents(int numevents); #endregion #region SDL_scancode.h /* Scancodes based off USB keyboard page (0x07) */ public enum SDL_Scancode { SDL_SCANCODE_UNKNOWN = 0, SDL_SCANCODE_A = 4, SDL_SCANCODE_B = 5, SDL_SCANCODE_C = 6, SDL_SCANCODE_D = 7, SDL_SCANCODE_E = 8, SDL_SCANCODE_F = 9, SDL_SCANCODE_G = 10, SDL_SCANCODE_H = 11, SDL_SCANCODE_I = 12, SDL_SCANCODE_J = 13, SDL_SCANCODE_K = 14, SDL_SCANCODE_L = 15, SDL_SCANCODE_M = 16, SDL_SCANCODE_N = 17, SDL_SCANCODE_O = 18, SDL_SCANCODE_P = 19, SDL_SCANCODE_Q = 20, SDL_SCANCODE_R = 21, SDL_SCANCODE_S = 22, SDL_SCANCODE_T = 23, SDL_SCANCODE_U = 24, SDL_SCANCODE_V = 25, SDL_SCANCODE_W = 26, SDL_SCANCODE_X = 27, SDL_SCANCODE_Y = 28, SDL_SCANCODE_Z = 29, SDL_SCANCODE_1 = 30, SDL_SCANCODE_2 = 31, SDL_SCANCODE_3 = 32, SDL_SCANCODE_4 = 33, SDL_SCANCODE_5 = 34, SDL_SCANCODE_6 = 35, SDL_SCANCODE_7 = 36, SDL_SCANCODE_8 = 37, SDL_SCANCODE_9 = 38, SDL_SCANCODE_0 = 39, SDL_SCANCODE_RETURN = 40, SDL_SCANCODE_ESCAPE = 41, SDL_SCANCODE_BACKSPACE = 42, SDL_SCANCODE_TAB = 43, SDL_SCANCODE_SPACE = 44, SDL_SCANCODE_MINUS = 45, SDL_SCANCODE_EQUALS = 46, SDL_SCANCODE_LEFTBRACKET = 47, SDL_SCANCODE_RIGHTBRACKET = 48, SDL_SCANCODE_BACKSLASH = 49, SDL_SCANCODE_NONUSHASH = 50, SDL_SCANCODE_SEMICOLON = 51, SDL_SCANCODE_APOSTROPHE = 52, SDL_SCANCODE_GRAVE = 53, SDL_SCANCODE_COMMA = 54, SDL_SCANCODE_PERIOD = 55, SDL_SCANCODE_SLASH = 56, SDL_SCANCODE_CAPSLOCK = 57, SDL_SCANCODE_F1 = 58, SDL_SCANCODE_F2 = 59, SDL_SCANCODE_F3 = 60, SDL_SCANCODE_F4 = 61, SDL_SCANCODE_F5 = 62, SDL_SCANCODE_F6 = 63, SDL_SCANCODE_F7 = 64, SDL_SCANCODE_F8 = 65, SDL_SCANCODE_F9 = 66, SDL_SCANCODE_F10 = 67, SDL_SCANCODE_F11 = 68, SDL_SCANCODE_F12 = 69, SDL_SCANCODE_PRINTSCREEN = 70, SDL_SCANCODE_SCROLLLOCK = 71, SDL_SCANCODE_PAUSE = 72, SDL_SCANCODE_INSERT = 73, SDL_SCANCODE_HOME = 74, SDL_SCANCODE_PAGEUP = 75, SDL_SCANCODE_DELETE = 76, SDL_SCANCODE_END = 77, SDL_SCANCODE_PAGEDOWN = 78, SDL_SCANCODE_RIGHT = 79, SDL_SCANCODE_LEFT = 80, SDL_SCANCODE_DOWN = 81, SDL_SCANCODE_UP = 82, SDL_SCANCODE_NUMLOCKCLEAR = 83, SDL_SCANCODE_KP_DIVIDE = 84, SDL_SCANCODE_KP_MULTIPLY = 85, SDL_SCANCODE_KP_MINUS = 86, SDL_SCANCODE_KP_PLUS = 87, SDL_SCANCODE_KP_ENTER = 88, SDL_SCANCODE_KP_1 = 89, SDL_SCANCODE_KP_2 = 90, SDL_SCANCODE_KP_3 = 91, SDL_SCANCODE_KP_4 = 92, SDL_SCANCODE_KP_5 = 93, SDL_SCANCODE_KP_6 = 94, SDL_SCANCODE_KP_7 = 95, SDL_SCANCODE_KP_8 = 96, SDL_SCANCODE_KP_9 = 97, SDL_SCANCODE_KP_0 = 98, SDL_SCANCODE_KP_PERIOD = 99, SDL_SCANCODE_NONUSBACKSLASH = 100, SDL_SCANCODE_APPLICATION = 101, SDL_SCANCODE_POWER = 102, SDL_SCANCODE_KP_EQUALS = 103, SDL_SCANCODE_F13 = 104, SDL_SCANCODE_F14 = 105, SDL_SCANCODE_F15 = 106, SDL_SCANCODE_F16 = 107, SDL_SCANCODE_F17 = 108, SDL_SCANCODE_F18 = 109, SDL_SCANCODE_F19 = 110, SDL_SCANCODE_F20 = 111, SDL_SCANCODE_F21 = 112, SDL_SCANCODE_F22 = 113, SDL_SCANCODE_F23 = 114, SDL_SCANCODE_F24 = 115, SDL_SCANCODE_EXECUTE = 116, SDL_SCANCODE_HELP = 117, SDL_SCANCODE_MENU = 118, SDL_SCANCODE_SELECT = 119, SDL_SCANCODE_STOP = 120, SDL_SCANCODE_AGAIN = 121, SDL_SCANCODE_UNDO = 122, SDL_SCANCODE_CUT = 123, SDL_SCANCODE_COPY = 124, SDL_SCANCODE_PASTE = 125, SDL_SCANCODE_FIND = 126, SDL_SCANCODE_MUTE = 127, SDL_SCANCODE_VOLUMEUP = 128, SDL_SCANCODE_VOLUMEDOWN = 129, /* not sure whether there's a reason to enable these */ /* SDL_SCANCODE_LOCKINGCAPSLOCK = 130, */ /* SDL_SCANCODE_LOCKINGNUMLOCK = 131, */ /* SDL_SCANCODE_LOCKINGSCROLLLOCK = 132, */ SDL_SCANCODE_KP_COMMA = 133, SDL_SCANCODE_KP_EQUALSAS400 = 134, SDL_SCANCODE_INTERNATIONAL1 = 135, SDL_SCANCODE_INTERNATIONAL2 = 136, SDL_SCANCODE_INTERNATIONAL3 = 137, SDL_SCANCODE_INTERNATIONAL4 = 138, SDL_SCANCODE_INTERNATIONAL5 = 139, SDL_SCANCODE_INTERNATIONAL6 = 140, SDL_SCANCODE_INTERNATIONAL7 = 141, SDL_SCANCODE_INTERNATIONAL8 = 142, SDL_SCANCODE_INTERNATIONAL9 = 143, SDL_SCANCODE_LANG1 = 144, SDL_SCANCODE_LANG2 = 145, SDL_SCANCODE_LANG3 = 146, SDL_SCANCODE_LANG4 = 147, SDL_SCANCODE_LANG5 = 148, SDL_SCANCODE_LANG6 = 149, SDL_SCANCODE_LANG7 = 150, SDL_SCANCODE_LANG8 = 151, SDL_SCANCODE_LANG9 = 152, SDL_SCANCODE_ALTERASE = 153, SDL_SCANCODE_SYSREQ = 154, SDL_SCANCODE_CANCEL = 155, SDL_SCANCODE_CLEAR = 156, SDL_SCANCODE_PRIOR = 157, SDL_SCANCODE_RETURN2 = 158, SDL_SCANCODE_SEPARATOR = 159, SDL_SCANCODE_OUT = 160, SDL_SCANCODE_OPER = 161, SDL_SCANCODE_CLEARAGAIN = 162, SDL_SCANCODE_CRSEL = 163, SDL_SCANCODE_EXSEL = 164, SDL_SCANCODE_KP_00 = 176, SDL_SCANCODE_KP_000 = 177, SDL_SCANCODE_THOUSANDSSEPARATOR = 178, SDL_SCANCODE_DECIMALSEPARATOR = 179, SDL_SCANCODE_CURRENCYUNIT = 180, SDL_SCANCODE_CURRENCYSUBUNIT = 181, SDL_SCANCODE_KP_LEFTPAREN = 182, SDL_SCANCODE_KP_RIGHTPAREN = 183, SDL_SCANCODE_KP_LEFTBRACE = 184, SDL_SCANCODE_KP_RIGHTBRACE = 185, SDL_SCANCODE_KP_TAB = 186, SDL_SCANCODE_KP_BACKSPACE = 187, SDL_SCANCODE_KP_A = 188, SDL_SCANCODE_KP_B = 189, SDL_SCANCODE_KP_C = 190, SDL_SCANCODE_KP_D = 191, SDL_SCANCODE_KP_E = 192, SDL_SCANCODE_KP_F = 193, SDL_SCANCODE_KP_XOR = 194, SDL_SCANCODE_KP_POWER = 195, SDL_SCANCODE_KP_PERCENT = 196, SDL_SCANCODE_KP_LESS = 197, SDL_SCANCODE_KP_GREATER = 198, SDL_SCANCODE_KP_AMPERSAND = 199, SDL_SCANCODE_KP_DBLAMPERSAND = 200, SDL_SCANCODE_KP_VERTICALBAR = 201, SDL_SCANCODE_KP_DBLVERTICALBAR = 202, SDL_SCANCODE_KP_COLON = 203, SDL_SCANCODE_KP_HASH = 204, SDL_SCANCODE_KP_SPACE = 205, SDL_SCANCODE_KP_AT = 206, SDL_SCANCODE_KP_EXCLAM = 207, SDL_SCANCODE_KP_MEMSTORE = 208, SDL_SCANCODE_KP_MEMRECALL = 209, SDL_SCANCODE_KP_MEMCLEAR = 210, SDL_SCANCODE_KP_MEMADD = 211, SDL_SCANCODE_KP_MEMSUBTRACT = 212, SDL_SCANCODE_KP_MEMMULTIPLY = 213, SDL_SCANCODE_KP_MEMDIVIDE = 214, SDL_SCANCODE_KP_PLUSMINUS = 215, SDL_SCANCODE_KP_CLEAR = 216, SDL_SCANCODE_KP_CLEARENTRY = 217, SDL_SCANCODE_KP_BINARY = 218, SDL_SCANCODE_KP_OCTAL = 219, SDL_SCANCODE_KP_DECIMAL = 220, SDL_SCANCODE_KP_HEXADECIMAL = 221, SDL_SCANCODE_LCTRL = 224, SDL_SCANCODE_LSHIFT = 225, SDL_SCANCODE_LALT = 226, SDL_SCANCODE_LGUI = 227, SDL_SCANCODE_RCTRL = 228, SDL_SCANCODE_RSHIFT = 229, SDL_SCANCODE_RALT = 230, SDL_SCANCODE_RGUI = 231, SDL_SCANCODE_MODE = 257, /* These come from the USB consumer page (0x0C) */ SDL_SCANCODE_AUDIONEXT = 258, SDL_SCANCODE_AUDIOPREV = 259, SDL_SCANCODE_AUDIOSTOP = 260, SDL_SCANCODE_AUDIOPLAY = 261, SDL_SCANCODE_AUDIOMUTE = 262, SDL_SCANCODE_MEDIASELECT = 263, SDL_SCANCODE_WWW = 264, SDL_SCANCODE_MAIL = 265, SDL_SCANCODE_CALCULATOR = 266, SDL_SCANCODE_COMPUTER = 267, SDL_SCANCODE_AC_SEARCH = 268, SDL_SCANCODE_AC_HOME = 269, SDL_SCANCODE_AC_BACK = 270, SDL_SCANCODE_AC_FORWARD = 271, SDL_SCANCODE_AC_STOP = 272, SDL_SCANCODE_AC_REFRESH = 273, SDL_SCANCODE_AC_BOOKMARKS = 274, /* These come from other sources, and are mostly mac related */ SDL_SCANCODE_BRIGHTNESSDOWN = 275, SDL_SCANCODE_BRIGHTNESSUP = 276, SDL_SCANCODE_DISPLAYSWITCH = 277, SDL_SCANCODE_KBDILLUMTOGGLE = 278, SDL_SCANCODE_KBDILLUMDOWN = 279, SDL_SCANCODE_KBDILLUMUP = 280, SDL_SCANCODE_EJECT = 281, SDL_SCANCODE_SLEEP = 282, SDL_SCANCODE_APP1 = 283, SDL_SCANCODE_APP2 = 284, /* These come from the USB consumer page (0x0C) */ SDL_SCANCODE_AUDIOREWIND = 285, SDL_SCANCODE_AUDIOFASTFORWARD = 286, /* This is not a key, simply marks the number of scancodes * so that you know how big to make your arrays. */ SDL_NUM_SCANCODES = 512 } #endregion #region SDL_keycode.h public const int SDLK_SCANCODE_MASK = (1 << 30); public static SDL_Keycode SDL_SCANCODE_TO_KEYCODE(SDL_Scancode X) { return (SDL_Keycode)((int)X | SDLK_SCANCODE_MASK); } public enum SDL_Keycode { SDLK_UNKNOWN = 0, SDLK_RETURN = '\r', SDLK_ESCAPE = 27, // '\033' SDLK_BACKSPACE = '\b', SDLK_TAB = '\t', SDLK_SPACE = ' ', SDLK_EXCLAIM = '!', SDLK_QUOTEDBL = '"', SDLK_HASH = '#', SDLK_PERCENT = '%', SDLK_DOLLAR = '$', SDLK_AMPERSAND = '&', SDLK_QUOTE = '\'', SDLK_LEFTPAREN = '(', SDLK_RIGHTPAREN = ')', SDLK_ASTERISK = '*', SDLK_PLUS = '+', SDLK_COMMA = ',', SDLK_MINUS = '-', SDLK_PERIOD = '.', SDLK_SLASH = '/', SDLK_0 = '0', SDLK_1 = '1', SDLK_2 = '2', SDLK_3 = '3', SDLK_4 = '4', SDLK_5 = '5', SDLK_6 = '6', SDLK_7 = '7', SDLK_8 = '8', SDLK_9 = '9', SDLK_COLON = ':', SDLK_SEMICOLON = ';', SDLK_LESS = '<', SDLK_EQUALS = '=', SDLK_GREATER = '>', SDLK_QUESTION = '?', SDLK_AT = '@', /* Skip uppercase letters */ SDLK_LEFTBRACKET = '[', SDLK_BACKSLASH = '\\', SDLK_RIGHTBRACKET = ']', SDLK_CARET = '^', SDLK_UNDERSCORE = '_', SDLK_BACKQUOTE = '`', SDLK_a = 'a', SDLK_b = 'b', SDLK_c = 'c', SDLK_d = 'd', SDLK_e = 'e', SDLK_f = 'f', SDLK_g = 'g', SDLK_h = 'h', SDLK_i = 'i', SDLK_j = 'j', SDLK_k = 'k', SDLK_l = 'l', SDLK_m = 'm', SDLK_n = 'n', SDLK_o = 'o', SDLK_p = 'p', SDLK_q = 'q', SDLK_r = 'r', SDLK_s = 's', SDLK_t = 't', SDLK_u = 'u', SDLK_v = 'v', SDLK_w = 'w', SDLK_x = 'x', SDLK_y = 'y', SDLK_z = 'z', SDLK_CAPSLOCK = (int)SDL_Scancode.SDL_SCANCODE_CAPSLOCK | SDLK_SCANCODE_MASK, SDLK_F1 = (int)SDL_Scancode.SDL_SCANCODE_F1 | SDLK_SCANCODE_MASK, SDLK_F2 = (int)SDL_Scancode.SDL_SCANCODE_F2 | SDLK_SCANCODE_MASK, SDLK_F3 = (int)SDL_Scancode.SDL_SCANCODE_F3 | SDLK_SCANCODE_MASK, SDLK_F4 = (int)SDL_Scancode.SDL_SCANCODE_F4 | SDLK_SCANCODE_MASK, SDLK_F5 = (int)SDL_Scancode.SDL_SCANCODE_F5 | SDLK_SCANCODE_MASK, SDLK_F6 = (int)SDL_Scancode.SDL_SCANCODE_F6 | SDLK_SCANCODE_MASK, SDLK_F7 = (int)SDL_Scancode.SDL_SCANCODE_F7 | SDLK_SCANCODE_MASK, SDLK_F8 = (int)SDL_Scancode.SDL_SCANCODE_F8 | SDLK_SCANCODE_MASK, SDLK_F9 = (int)SDL_Scancode.SDL_SCANCODE_F9 | SDLK_SCANCODE_MASK, SDLK_F10 = (int)SDL_Scancode.SDL_SCANCODE_F10 | SDLK_SCANCODE_MASK, SDLK_F11 = (int)SDL_Scancode.SDL_SCANCODE_F11 | SDLK_SCANCODE_MASK, SDLK_F12 = (int)SDL_Scancode.SDL_SCANCODE_F12 | SDLK_SCANCODE_MASK, SDLK_PRINTSCREEN = (int)SDL_Scancode.SDL_SCANCODE_PRINTSCREEN | SDLK_SCANCODE_MASK, SDLK_SCROLLLOCK = (int)SDL_Scancode.SDL_SCANCODE_SCROLLLOCK | SDLK_SCANCODE_MASK, SDLK_PAUSE = (int)SDL_Scancode.SDL_SCANCODE_PAUSE | SDLK_SCANCODE_MASK, SDLK_INSERT = (int)SDL_Scancode.SDL_SCANCODE_INSERT | SDLK_SCANCODE_MASK, SDLK_HOME = (int)SDL_Scancode.SDL_SCANCODE_HOME | SDLK_SCANCODE_MASK, SDLK_PAGEUP = (int)SDL_Scancode.SDL_SCANCODE_PAGEUP | SDLK_SCANCODE_MASK, SDLK_DELETE = 127, SDLK_END = (int)SDL_Scancode.SDL_SCANCODE_END | SDLK_SCANCODE_MASK, SDLK_PAGEDOWN = (int)SDL_Scancode.SDL_SCANCODE_PAGEDOWN | SDLK_SCANCODE_MASK, SDLK_RIGHT = (int)SDL_Scancode.SDL_SCANCODE_RIGHT | SDLK_SCANCODE_MASK, SDLK_LEFT = (int)SDL_Scancode.SDL_SCANCODE_LEFT | SDLK_SCANCODE_MASK, SDLK_DOWN = (int)SDL_Scancode.SDL_SCANCODE_DOWN | SDLK_SCANCODE_MASK, SDLK_UP = (int)SDL_Scancode.SDL_SCANCODE_UP | SDLK_SCANCODE_MASK, SDLK_NUMLOCKCLEAR = (int)SDL_Scancode.SDL_SCANCODE_NUMLOCKCLEAR | SDLK_SCANCODE_MASK, SDLK_KP_DIVIDE = (int)SDL_Scancode.SDL_SCANCODE_KP_DIVIDE | SDLK_SCANCODE_MASK, SDLK_KP_MULTIPLY = (int)SDL_Scancode.SDL_SCANCODE_KP_MULTIPLY | SDLK_SCANCODE_MASK, SDLK_KP_MINUS = (int)SDL_Scancode.SDL_SCANCODE_KP_MINUS | SDLK_SCANCODE_MASK, SDLK_KP_PLUS = (int)SDL_Scancode.SDL_SCANCODE_KP_PLUS | SDLK_SCANCODE_MASK, SDLK_KP_ENTER = (int)SDL_Scancode.SDL_SCANCODE_KP_ENTER | SDLK_SCANCODE_MASK, SDLK_KP_1 = (int)SDL_Scancode.SDL_SCANCODE_KP_1 | SDLK_SCANCODE_MASK, SDLK_KP_2 = (int)SDL_Scancode.SDL_SCANCODE_KP_2 | SDLK_SCANCODE_MASK, SDLK_KP_3 = (int)SDL_Scancode.SDL_SCANCODE_KP_3 | SDLK_SCANCODE_MASK, SDLK_KP_4 = (int)SDL_Scancode.SDL_SCANCODE_KP_4 | SDLK_SCANCODE_MASK, SDLK_KP_5 = (int)SDL_Scancode.SDL_SCANCODE_KP_5 | SDLK_SCANCODE_MASK, SDLK_KP_6 = (int)SDL_Scancode.SDL_SCANCODE_KP_6 | SDLK_SCANCODE_MASK, SDLK_KP_7 = (int)SDL_Scancode.SDL_SCANCODE_KP_7 | SDLK_SCANCODE_MASK, SDLK_KP_8 = (int)SDL_Scancode.SDL_SCANCODE_KP_8 | SDLK_SCANCODE_MASK, SDLK_KP_9 = (int)SDL_Scancode.SDL_SCANCODE_KP_9 | SDLK_SCANCODE_MASK, SDLK_KP_0 = (int)SDL_Scancode.SDL_SCANCODE_KP_0 | SDLK_SCANCODE_MASK, SDLK_KP_PERIOD = (int)SDL_Scancode.SDL_SCANCODE_KP_PERIOD | SDLK_SCANCODE_MASK, SDLK_APPLICATION = (int)SDL_Scancode.SDL_SCANCODE_APPLICATION | SDLK_SCANCODE_MASK, SDLK_POWER = (int)SDL_Scancode.SDL_SCANCODE_POWER | SDLK_SCANCODE_MASK, SDLK_KP_EQUALS = (int)SDL_Scancode.SDL_SCANCODE_KP_EQUALS | SDLK_SCANCODE_MASK, SDLK_F13 = (int)SDL_Scancode.SDL_SCANCODE_F13 | SDLK_SCANCODE_MASK, SDLK_F14 = (int)SDL_Scancode.SDL_SCANCODE_F14 | SDLK_SCANCODE_MASK, SDLK_F15 = (int)SDL_Scancode.SDL_SCANCODE_F15 | SDLK_SCANCODE_MASK, SDLK_F16 = (int)SDL_Scancode.SDL_SCANCODE_F16 | SDLK_SCANCODE_MASK, SDLK_F17 = (int)SDL_Scancode.SDL_SCANCODE_F17 | SDLK_SCANCODE_MASK, SDLK_F18 = (int)SDL_Scancode.SDL_SCANCODE_F18 | SDLK_SCANCODE_MASK, SDLK_F19 = (int)SDL_Scancode.SDL_SCANCODE_F19 | SDLK_SCANCODE_MASK, SDLK_F20 = (int)SDL_Scancode.SDL_SCANCODE_F20 | SDLK_SCANCODE_MASK, SDLK_F21 = (int)SDL_Scancode.SDL_SCANCODE_F21 | SDLK_SCANCODE_MASK, SDLK_F22 = (int)SDL_Scancode.SDL_SCANCODE_F22 | SDLK_SCANCODE_MASK, SDLK_F23 = (int)SDL_Scancode.SDL_SCANCODE_F23 | SDLK_SCANCODE_MASK, SDLK_F24 = (int)SDL_Scancode.SDL_SCANCODE_F24 | SDLK_SCANCODE_MASK, SDLK_EXECUTE = (int)SDL_Scancode.SDL_SCANCODE_EXECUTE | SDLK_SCANCODE_MASK, SDLK_HELP = (int)SDL_Scancode.SDL_SCANCODE_HELP | SDLK_SCANCODE_MASK, SDLK_MENU = (int)SDL_Scancode.SDL_SCANCODE_MENU | SDLK_SCANCODE_MASK, SDLK_SELECT = (int)SDL_Scancode.SDL_SCANCODE_SELECT | SDLK_SCANCODE_MASK, SDLK_STOP = (int)SDL_Scancode.SDL_SCANCODE_STOP | SDLK_SCANCODE_MASK, SDLK_AGAIN = (int)SDL_Scancode.SDL_SCANCODE_AGAIN | SDLK_SCANCODE_MASK, SDLK_UNDO = (int)SDL_Scancode.SDL_SCANCODE_UNDO | SDLK_SCANCODE_MASK, SDLK_CUT = (int)SDL_Scancode.SDL_SCANCODE_CUT | SDLK_SCANCODE_MASK, SDLK_COPY = (int)SDL_Scancode.SDL_SCANCODE_COPY | SDLK_SCANCODE_MASK, SDLK_PASTE = (int)SDL_Scancode.SDL_SCANCODE_PASTE | SDLK_SCANCODE_MASK, SDLK_FIND = (int)SDL_Scancode.SDL_SCANCODE_FIND | SDLK_SCANCODE_MASK, SDLK_MUTE = (int)SDL_Scancode.SDL_SCANCODE_MUTE | SDLK_SCANCODE_MASK, SDLK_VOLUMEUP = (int)SDL_Scancode.SDL_SCANCODE_VOLUMEUP | SDLK_SCANCODE_MASK, SDLK_VOLUMEDOWN = (int)SDL_Scancode.SDL_SCANCODE_VOLUMEDOWN | SDLK_SCANCODE_MASK, SDLK_KP_COMMA = (int)SDL_Scancode.SDL_SCANCODE_KP_COMMA | SDLK_SCANCODE_MASK, SDLK_KP_EQUALSAS400 = (int)SDL_Scancode.SDL_SCANCODE_KP_EQUALSAS400 | SDLK_SCANCODE_MASK, SDLK_ALTERASE = (int)SDL_Scancode.SDL_SCANCODE_ALTERASE | SDLK_SCANCODE_MASK, SDLK_SYSREQ = (int)SDL_Scancode.SDL_SCANCODE_SYSREQ | SDLK_SCANCODE_MASK, SDLK_CANCEL = (int)SDL_Scancode.SDL_SCANCODE_CANCEL | SDLK_SCANCODE_MASK, SDLK_CLEAR = (int)SDL_Scancode.SDL_SCANCODE_CLEAR | SDLK_SCANCODE_MASK, SDLK_PRIOR = (int)SDL_Scancode.SDL_SCANCODE_PRIOR | SDLK_SCANCODE_MASK, SDLK_RETURN2 = (int)SDL_Scancode.SDL_SCANCODE_RETURN2 | SDLK_SCANCODE_MASK, SDLK_SEPARATOR = (int)SDL_Scancode.SDL_SCANCODE_SEPARATOR | SDLK_SCANCODE_MASK, SDLK_OUT = (int)SDL_Scancode.SDL_SCANCODE_OUT | SDLK_SCANCODE_MASK, SDLK_OPER = (int)SDL_Scancode.SDL_SCANCODE_OPER | SDLK_SCANCODE_MASK, SDLK_CLEARAGAIN = (int)SDL_Scancode.SDL_SCANCODE_CLEARAGAIN | SDLK_SCANCODE_MASK, SDLK_CRSEL = (int)SDL_Scancode.SDL_SCANCODE_CRSEL | SDLK_SCANCODE_MASK, SDLK_EXSEL = (int)SDL_Scancode.SDL_SCANCODE_EXSEL | SDLK_SCANCODE_MASK, SDLK_KP_00 = (int)SDL_Scancode.SDL_SCANCODE_KP_00 | SDLK_SCANCODE_MASK, SDLK_KP_000 = (int)SDL_Scancode.SDL_SCANCODE_KP_000 | SDLK_SCANCODE_MASK, SDLK_THOUSANDSSEPARATOR = (int)SDL_Scancode.SDL_SCANCODE_THOUSANDSSEPARATOR | SDLK_SCANCODE_MASK, SDLK_DECIMALSEPARATOR = (int)SDL_Scancode.SDL_SCANCODE_DECIMALSEPARATOR | SDLK_SCANCODE_MASK, SDLK_CURRENCYUNIT = (int)SDL_Scancode.SDL_SCANCODE_CURRENCYUNIT | SDLK_SCANCODE_MASK, SDLK_CURRENCYSUBUNIT = (int)SDL_Scancode.SDL_SCANCODE_CURRENCYSUBUNIT | SDLK_SCANCODE_MASK, SDLK_KP_LEFTPAREN = (int)SDL_Scancode.SDL_SCANCODE_KP_LEFTPAREN | SDLK_SCANCODE_MASK, SDLK_KP_RIGHTPAREN = (int)SDL_Scancode.SDL_SCANCODE_KP_RIGHTPAREN | SDLK_SCANCODE_MASK, SDLK_KP_LEFTBRACE = (int)SDL_Scancode.SDL_SCANCODE_KP_LEFTBRACE | SDLK_SCANCODE_MASK, SDLK_KP_RIGHTBRACE = (int)SDL_Scancode.SDL_SCANCODE_KP_RIGHTBRACE | SDLK_SCANCODE_MASK, SDLK_KP_TAB = (int)SDL_Scancode.SDL_SCANCODE_KP_TAB | SDLK_SCANCODE_MASK, SDLK_KP_BACKSPACE = (int)SDL_Scancode.SDL_SCANCODE_KP_BACKSPACE | SDLK_SCANCODE_MASK, SDLK_KP_A = (int)SDL_Scancode.SDL_SCANCODE_KP_A | SDLK_SCANCODE_MASK, SDLK_KP_B = (int)SDL_Scancode.SDL_SCANCODE_KP_B | SDLK_SCANCODE_MASK, SDLK_KP_C = (int)SDL_Scancode.SDL_SCANCODE_KP_C | SDLK_SCANCODE_MASK, SDLK_KP_D = (int)SDL_Scancode.SDL_SCANCODE_KP_D | SDLK_SCANCODE_MASK, SDLK_KP_E = (int)SDL_Scancode.SDL_SCANCODE_KP_E | SDLK_SCANCODE_MASK, SDLK_KP_F = (int)SDL_Scancode.SDL_SCANCODE_KP_F | SDLK_SCANCODE_MASK, SDLK_KP_XOR = (int)SDL_Scancode.SDL_SCANCODE_KP_XOR | SDLK_SCANCODE_MASK, SDLK_KP_POWER = (int)SDL_Scancode.SDL_SCANCODE_KP_POWER | SDLK_SCANCODE_MASK, SDLK_KP_PERCENT = (int)SDL_Scancode.SDL_SCANCODE_KP_PERCENT | SDLK_SCANCODE_MASK, SDLK_KP_LESS = (int)SDL_Scancode.SDL_SCANCODE_KP_LESS | SDLK_SCANCODE_MASK, SDLK_KP_GREATER = (int)SDL_Scancode.SDL_SCANCODE_KP_GREATER | SDLK_SCANCODE_MASK, SDLK_KP_AMPERSAND = (int)SDL_Scancode.SDL_SCANCODE_KP_AMPERSAND | SDLK_SCANCODE_MASK, SDLK_KP_DBLAMPERSAND = (int)SDL_Scancode.SDL_SCANCODE_KP_DBLAMPERSAND | SDLK_SCANCODE_MASK, SDLK_KP_VERTICALBAR = (int)SDL_Scancode.SDL_SCANCODE_KP_VERTICALBAR | SDLK_SCANCODE_MASK, SDLK_KP_DBLVERTICALBAR = (int)SDL_Scancode.SDL_SCANCODE_KP_DBLVERTICALBAR | SDLK_SCANCODE_MASK, SDLK_KP_COLON = (int)SDL_Scancode.SDL_SCANCODE_KP_COLON | SDLK_SCANCODE_MASK, SDLK_KP_HASH = (int)SDL_Scancode.SDL_SCANCODE_KP_HASH | SDLK_SCANCODE_MASK, SDLK_KP_SPACE = (int)SDL_Scancode.SDL_SCANCODE_KP_SPACE | SDLK_SCANCODE_MASK, SDLK_KP_AT = (int)SDL_Scancode.SDL_SCANCODE_KP_AT | SDLK_SCANCODE_MASK, SDLK_KP_EXCLAM = (int)SDL_Scancode.SDL_SCANCODE_KP_EXCLAM | SDLK_SCANCODE_MASK, SDLK_KP_MEMSTORE = (int)SDL_Scancode.SDL_SCANCODE_KP_MEMSTORE | SDLK_SCANCODE_MASK, SDLK_KP_MEMRECALL = (int)SDL_Scancode.SDL_SCANCODE_KP_MEMRECALL | SDLK_SCANCODE_MASK, SDLK_KP_MEMCLEAR = (int)SDL_Scancode.SDL_SCANCODE_KP_MEMCLEAR | SDLK_SCANCODE_MASK, SDLK_KP_MEMADD = (int)SDL_Scancode.SDL_SCANCODE_KP_MEMADD | SDLK_SCANCODE_MASK, SDLK_KP_MEMSUBTRACT = (int)SDL_Scancode.SDL_SCANCODE_KP_MEMSUBTRACT | SDLK_SCANCODE_MASK, SDLK_KP_MEMMULTIPLY = (int)SDL_Scancode.SDL_SCANCODE_KP_MEMMULTIPLY | SDLK_SCANCODE_MASK, SDLK_KP_MEMDIVIDE = (int)SDL_Scancode.SDL_SCANCODE_KP_MEMDIVIDE | SDLK_SCANCODE_MASK, SDLK_KP_PLUSMINUS = (int)SDL_Scancode.SDL_SCANCODE_KP_PLUSMINUS | SDLK_SCANCODE_MASK, SDLK_KP_CLEAR = (int)SDL_Scancode.SDL_SCANCODE_KP_CLEAR | SDLK_SCANCODE_MASK, SDLK_KP_CLEARENTRY = (int)SDL_Scancode.SDL_SCANCODE_KP_CLEARENTRY | SDLK_SCANCODE_MASK, SDLK_KP_BINARY = (int)SDL_Scancode.SDL_SCANCODE_KP_BINARY | SDLK_SCANCODE_MASK, SDLK_KP_OCTAL = (int)SDL_Scancode.SDL_SCANCODE_KP_OCTAL | SDLK_SCANCODE_MASK, SDLK_KP_DECIMAL = (int)SDL_Scancode.SDL_SCANCODE_KP_DECIMAL | SDLK_SCANCODE_MASK, SDLK_KP_HEXADECIMAL = (int)SDL_Scancode.SDL_SCANCODE_KP_HEXADECIMAL | SDLK_SCANCODE_MASK, SDLK_LCTRL = (int)SDL_Scancode.SDL_SCANCODE_LCTRL | SDLK_SCANCODE_MASK, SDLK_LSHIFT = (int)SDL_Scancode.SDL_SCANCODE_LSHIFT | SDLK_SCANCODE_MASK, SDLK_LALT = (int)SDL_Scancode.SDL_SCANCODE_LALT | SDLK_SCANCODE_MASK, SDLK_LGUI = (int)SDL_Scancode.SDL_SCANCODE_LGUI | SDLK_SCANCODE_MASK, SDLK_RCTRL = (int)SDL_Scancode.SDL_SCANCODE_RCTRL | SDLK_SCANCODE_MASK, SDLK_RSHIFT = (int)SDL_Scancode.SDL_SCANCODE_RSHIFT | SDLK_SCANCODE_MASK, SDLK_RALT = (int)SDL_Scancode.SDL_SCANCODE_RALT | SDLK_SCANCODE_MASK, SDLK_RGUI = (int)SDL_Scancode.SDL_SCANCODE_RGUI | SDLK_SCANCODE_MASK, SDLK_MODE = (int)SDL_Scancode.SDL_SCANCODE_MODE | SDLK_SCANCODE_MASK, SDLK_AUDIONEXT = (int)SDL_Scancode.SDL_SCANCODE_AUDIONEXT | SDLK_SCANCODE_MASK, SDLK_AUDIOPREV = (int)SDL_Scancode.SDL_SCANCODE_AUDIOPREV | SDLK_SCANCODE_MASK, SDLK_AUDIOSTOP = (int)SDL_Scancode.SDL_SCANCODE_AUDIOSTOP | SDLK_SCANCODE_MASK, SDLK_AUDIOPLAY = (int)SDL_Scancode.SDL_SCANCODE_AUDIOPLAY | SDLK_SCANCODE_MASK, SDLK_AUDIOMUTE = (int)SDL_Scancode.SDL_SCANCODE_AUDIOMUTE | SDLK_SCANCODE_MASK, SDLK_MEDIASELECT = (int)SDL_Scancode.SDL_SCANCODE_MEDIASELECT | SDLK_SCANCODE_MASK, SDLK_WWW = (int)SDL_Scancode.SDL_SCANCODE_WWW | SDLK_SCANCODE_MASK, SDLK_MAIL = (int)SDL_Scancode.SDL_SCANCODE_MAIL | SDLK_SCANCODE_MASK, SDLK_CALCULATOR = (int)SDL_Scancode.SDL_SCANCODE_CALCULATOR | SDLK_SCANCODE_MASK, SDLK_COMPUTER = (int)SDL_Scancode.SDL_SCANCODE_COMPUTER | SDLK_SCANCODE_MASK, SDLK_AC_SEARCH = (int)SDL_Scancode.SDL_SCANCODE_AC_SEARCH | SDLK_SCANCODE_MASK, SDLK_AC_HOME = (int)SDL_Scancode.SDL_SCANCODE_AC_HOME | SDLK_SCANCODE_MASK, SDLK_AC_BACK = (int)SDL_Scancode.SDL_SCANCODE_AC_BACK | SDLK_SCANCODE_MASK, SDLK_AC_FORWARD = (int)SDL_Scancode.SDL_SCANCODE_AC_FORWARD | SDLK_SCANCODE_MASK, SDLK_AC_STOP = (int)SDL_Scancode.SDL_SCANCODE_AC_STOP | SDLK_SCANCODE_MASK, SDLK_AC_REFRESH = (int)SDL_Scancode.SDL_SCANCODE_AC_REFRESH | SDLK_SCANCODE_MASK, SDLK_AC_BOOKMARKS = (int)SDL_Scancode.SDL_SCANCODE_AC_BOOKMARKS | SDLK_SCANCODE_MASK, SDLK_BRIGHTNESSDOWN = (int)SDL_Scancode.SDL_SCANCODE_BRIGHTNESSDOWN | SDLK_SCANCODE_MASK, SDLK_BRIGHTNESSUP = (int)SDL_Scancode.SDL_SCANCODE_BRIGHTNESSUP | SDLK_SCANCODE_MASK, SDLK_DISPLAYSWITCH = (int)SDL_Scancode.SDL_SCANCODE_DISPLAYSWITCH | SDLK_SCANCODE_MASK, SDLK_KBDILLUMTOGGLE = (int)SDL_Scancode.SDL_SCANCODE_KBDILLUMTOGGLE | SDLK_SCANCODE_MASK, SDLK_KBDILLUMDOWN = (int)SDL_Scancode.SDL_SCANCODE_KBDILLUMDOWN | SDLK_SCANCODE_MASK, SDLK_KBDILLUMUP = (int)SDL_Scancode.SDL_SCANCODE_KBDILLUMUP | SDLK_SCANCODE_MASK, SDLK_EJECT = (int)SDL_Scancode.SDL_SCANCODE_EJECT | SDLK_SCANCODE_MASK, SDLK_SLEEP = (int)SDL_Scancode.SDL_SCANCODE_SLEEP | SDLK_SCANCODE_MASK, SDLK_APP1 = (int)SDL_Scancode.SDL_SCANCODE_APP1 | SDLK_SCANCODE_MASK, SDLK_APP2 = (int)SDL_Scancode.SDL_SCANCODE_APP2 | SDLK_SCANCODE_MASK, SDLK_AUDIOREWIND = (int)SDL_Scancode.SDL_SCANCODE_AUDIOREWIND | SDLK_SCANCODE_MASK, SDLK_AUDIOFASTFORWARD = (int)SDL_Scancode.SDL_SCANCODE_AUDIOFASTFORWARD | SDLK_SCANCODE_MASK } /* Key modifiers (bitfield) */ [Flags] public enum SDL_Keymod : ushort { KMOD_NONE = 0x0000, KMOD_LSHIFT = 0x0001, KMOD_RSHIFT = 0x0002, KMOD_LCTRL = 0x0040, KMOD_RCTRL = 0x0080, KMOD_LALT = 0x0100, KMOD_RALT = 0x0200, KMOD_LGUI = 0x0400, KMOD_RGUI = 0x0800, KMOD_NUM = 0x1000, KMOD_CAPS = 0x2000, KMOD_MODE = 0x4000, KMOD_RESERVED = 0x8000, /* These are defines in the SDL headers */ KMOD_CTRL = (KMOD_LCTRL | KMOD_RCTRL), KMOD_SHIFT = (KMOD_LSHIFT | KMOD_RSHIFT), KMOD_ALT = (KMOD_LALT | KMOD_RALT), KMOD_GUI = (KMOD_LGUI | KMOD_RGUI) } #endregion #region SDL_keyboard.h [StructLayout(LayoutKind.Sequential)] public struct SDL_Keysym { public SDL_Scancode scancode; public SDL_Keycode sym; public SDL_Keymod mod; /* UInt16 */ public UInt32 unicode; /* Deprecated */ } /* Get the window which has kbd focus */ /* Return type is an SDL_Window pointer */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GetKeyboardFocus(); /* Get a snapshot of the keyboard state. */ /* Return value is a pointer to a UInt8 array */ /* Numkeys returns the size of the array if non-null */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GetKeyboardState(out int numkeys); /* Get the current key modifier state for the keyboard. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_Keymod SDL_GetModState(); /* Set the current key modifier state */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SetModState(SDL_Keymod modstate); /* Get the key code corresponding to the given scancode * with the current keyboard layout. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_Keycode SDL_GetKeyFromScancode(SDL_Scancode scancode); /* Get the scancode for the given keycode */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_Scancode SDL_GetScancodeFromKey(SDL_Keycode key); /* Wrapper for SDL_GetScancodeName */ [DllImport(nativeLibName, EntryPoint = "SDL_GetScancodeName", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetScancodeName(SDL_Scancode scancode); public static string SDL_GetScancodeName(SDL_Scancode scancode) { return UTF8_ToManaged( INTERNAL_SDL_GetScancodeName(scancode) ); } /* Get a scancode from a human-readable name */ [DllImport(nativeLibName, EntryPoint = "SDL_GetScancodeFromName", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe SDL_Scancode INTERNAL_SDL_GetScancodeFromName( byte* name ); public static unsafe SDL_Scancode SDL_GetScancodeFromName(string name) { int utf8NameBufSize = Utf8Size(name); byte* utf8Name = stackalloc byte[utf8NameBufSize]; return INTERNAL_SDL_GetScancodeFromName( Utf8Encode(name, utf8Name, utf8NameBufSize) ); } /* Wrapper for SDL_GetKeyName */ [DllImport(nativeLibName, EntryPoint = "SDL_GetKeyName", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetKeyName(SDL_Keycode key); public static string SDL_GetKeyName(SDL_Keycode key) { return UTF8_ToManaged(INTERNAL_SDL_GetKeyName(key)); } /* Get a key code from a human-readable name */ [DllImport(nativeLibName, EntryPoint = "SDL_GetKeyFromName", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe SDL_Keycode INTERNAL_SDL_GetKeyFromName( byte* name ); public static unsafe SDL_Keycode SDL_GetKeyFromName(string name) { int utf8NameBufSize = Utf8Size(name); byte* utf8Name = stackalloc byte[utf8NameBufSize]; return INTERNAL_SDL_GetKeyFromName( Utf8Encode(name, utf8Name, utf8NameBufSize) ); } /* Start accepting Unicode text input events, show keyboard */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_StartTextInput(); /* Check if unicode input events are enabled */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_IsTextInputActive(); /* Stop receiving any text input events, hide onscreen kbd */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_StopTextInput(); /* Set the rectangle used for text input, hint for IME */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SetTextInputRect(ref SDL_Rect rect); /* Does the platform support an on-screen keyboard? */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasScreenKeyboardSupport(); /* Is the on-screen keyboard shown for a given window? */ /* window is an SDL_Window pointer */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_IsScreenKeyboardShown(IntPtr window); #endregion #region SDL_mouse.c /* Note: SDL_Cursor is a typedef normally. We'll treat it as * an IntPtr, because C# doesn't do typedefs. Yay! */ /* System cursor types */ public enum SDL_SystemCursor { SDL_SYSTEM_CURSOR_ARROW, // Arrow SDL_SYSTEM_CURSOR_IBEAM, // I-beam SDL_SYSTEM_CURSOR_WAIT, // Wait SDL_SYSTEM_CURSOR_CROSSHAIR, // Crosshair SDL_SYSTEM_CURSOR_WAITARROW, // Small wait cursor (or Wait if not available) SDL_SYSTEM_CURSOR_SIZENWSE, // Double arrow pointing northwest and southeast SDL_SYSTEM_CURSOR_SIZENESW, // Double arrow pointing northeast and southwest SDL_SYSTEM_CURSOR_SIZEWE, // Double arrow pointing west and east SDL_SYSTEM_CURSOR_SIZENS, // Double arrow pointing north and south SDL_SYSTEM_CURSOR_SIZEALL, // Four pointed arrow pointing north, south, east, and west SDL_SYSTEM_CURSOR_NO, // Slashed circle or crossbones SDL_SYSTEM_CURSOR_HAND, // Hand SDL_NUM_SYSTEM_CURSORS } /* Get the window which currently has mouse focus */ /* Return value is an SDL_Window pointer */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GetMouseFocus(); /* Get the current state of the mouse */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_GetMouseState(out int x, out int y); /* Get the current state of the mouse */ /* This overload allows for passing NULL to x */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_GetMouseState(IntPtr x, out int y); /* Get the current state of the mouse */ /* This overload allows for passing NULL to y */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_GetMouseState(out int x, IntPtr y); /* Get the current state of the mouse */ /* This overload allows for passing NULL to both x and y */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_GetMouseState(IntPtr x, IntPtr y); /* Get the current state of the mouse, in relation to the desktop. * Only available in 2.0.4 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_GetGlobalMouseState(out int x, out int y); /* Get the current state of the mouse, in relation to the desktop. * Only available in 2.0.4 or higher. * This overload allows for passing NULL to x. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_GetGlobalMouseState(IntPtr x, out int y); /* Get the current state of the mouse, in relation to the desktop. * Only available in 2.0.4 or higher. * This overload allows for passing NULL to y. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_GetGlobalMouseState(out int x, IntPtr y); /* Get the current state of the mouse, in relation to the desktop. * Only available in 2.0.4 or higher. * This overload allows for passing NULL to both x and y */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_GetGlobalMouseState(IntPtr x, IntPtr y); /* Get the mouse state with relative coords*/ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_GetRelativeMouseState(out int x, out int y); /* Set the mouse cursor's position (within a window) */ /* window is an SDL_Window pointer */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_WarpMouseInWindow(IntPtr window, int x, int y); /* Set the mouse cursor's position in global screen space. * Only available in 2.0.4 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_WarpMouseGlobal(int x, int y); /* Enable/Disable relative mouse mode (grabs mouse, rel coords) */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetRelativeMouseMode(SDL_bool enabled); /* Capture the mouse, to track input outside an SDL window. * Only available in 2.0.4 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_CaptureMouse(SDL_bool enabled); /* Query if the relative mouse mode is enabled */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_GetRelativeMouseMode(); /* Create a cursor from bitmap data (amd mask) in MSB format. * data and mask are byte arrays, and w must be a multiple of 8. * return value is an SDL_Cursor pointer. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_CreateCursor( IntPtr data, IntPtr mask, int w, int h, int hot_x, int hot_y ); /* Create a cursor from an SDL_Surface. * IntPtr refers to an SDL_Cursor*, surface to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_CreateColorCursor( IntPtr surface, int hot_x, int hot_y ); /* Create a cursor from a system cursor id. * return value is an SDL_Cursor pointer */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_CreateSystemCursor(SDL_SystemCursor id); /* Set the active cursor. * cursor is an SDL_Cursor pointer */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SetCursor(IntPtr cursor); /* Return the active cursor * return value is an SDL_Cursor pointer */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GetCursor(); /* Frees a cursor created with one of the CreateCursor functions. * cursor in an SDL_Cursor pointer */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_FreeCursor(IntPtr cursor); /* Toggle whether or not the cursor is shown */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_ShowCursor(int toggle); public static uint SDL_BUTTON(uint X) { // If only there were a better way of doing this in C# return (uint) (1 << ((int) X - 1)); } public const uint SDL_BUTTON_LEFT = 1; public const uint SDL_BUTTON_MIDDLE = 2; public const uint SDL_BUTTON_RIGHT = 3; public const uint SDL_BUTTON_X1 = 4; public const uint SDL_BUTTON_X2 = 5; public static readonly UInt32 SDL_BUTTON_LMASK = SDL_BUTTON(SDL_BUTTON_LEFT); public static readonly UInt32 SDL_BUTTON_MMASK = SDL_BUTTON(SDL_BUTTON_MIDDLE); public static readonly UInt32 SDL_BUTTON_RMASK = SDL_BUTTON(SDL_BUTTON_RIGHT); public static readonly UInt32 SDL_BUTTON_X1MASK = SDL_BUTTON(SDL_BUTTON_X1); public static readonly UInt32 SDL_BUTTON_X2MASK = SDL_BUTTON(SDL_BUTTON_X2); #endregion #region SDL_touch.h public const uint SDL_TOUCH_MOUSEID = uint.MaxValue; public struct SDL_Finger { public long id; // SDL_FingerID public float x; public float y; public float pressure; } /* Only available in 2.0.10 or higher. */ public enum SDL_TouchDeviceType { SDL_TOUCH_DEVICE_INVALID = -1, SDL_TOUCH_DEVICE_DIRECT, /* touch screen with window-relative coordinates */ SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE, /* trackpad with absolute device coordinates */ SDL_TOUCH_DEVICE_INDIRECT_RELATIVE /* trackpad with screen cursor-relative coordinates */ } /** * \brief Get the number of registered touch devices. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetNumTouchDevices(); /** * \brief Get the touch ID with the given index, or 0 if the index is invalid. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern long SDL_GetTouchDevice(int index); /** * \brief Get the number of active fingers for a given touch device. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetNumTouchFingers(long touchID); /** * \brief Get the finger object of the given touch, with the given index. * Returns pointer to SDL_Finger. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GetTouchFinger(long touchID, int index); /* Only available in 2.0.10 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_TouchDeviceType SDL_GetTouchDeviceType(Int64 touchID); #endregion #region SDL_joystick.h public const byte SDL_HAT_CENTERED = 0x00; public const byte SDL_HAT_UP = 0x01; public const byte SDL_HAT_RIGHT = 0x02; public const byte SDL_HAT_DOWN = 0x04; public const byte SDL_HAT_LEFT = 0x08; public const byte SDL_HAT_RIGHTUP = SDL_HAT_RIGHT | SDL_HAT_UP; public const byte SDL_HAT_RIGHTDOWN = SDL_HAT_RIGHT | SDL_HAT_DOWN; public const byte SDL_HAT_LEFTUP = SDL_HAT_LEFT | SDL_HAT_UP; public const byte SDL_HAT_LEFTDOWN = SDL_HAT_LEFT | SDL_HAT_DOWN; public enum SDL_JoystickPowerLevel { SDL_JOYSTICK_POWER_UNKNOWN = -1, SDL_JOYSTICK_POWER_EMPTY, SDL_JOYSTICK_POWER_LOW, SDL_JOYSTICK_POWER_MEDIUM, SDL_JOYSTICK_POWER_FULL, SDL_JOYSTICK_POWER_WIRED, SDL_JOYSTICK_POWER_MAX } public enum SDL_JoystickType { SDL_JOYSTICK_TYPE_UNKNOWN, SDL_JOYSTICK_TYPE_GAMECONTROLLER, SDL_JOYSTICK_TYPE_WHEEL, SDL_JOYSTICK_TYPE_ARCADE_STICK, SDL_JOYSTICK_TYPE_FLIGHT_STICK, SDL_JOYSTICK_TYPE_DANCE_PAD, SDL_JOYSTICK_TYPE_GUITAR, SDL_JOYSTICK_TYPE_DRUM_KIT, SDL_JOYSTICK_TYPE_ARCADE_PAD } /* joystick refers to an SDL_Joystick*. * Only available in 2.0.9 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_JoystickRumble( IntPtr joystick, UInt16 low_frequency_rumble, UInt16 high_frequency_rumble, UInt32 duration_ms ); /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_JoystickClose(IntPtr joystick); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_JoystickEventState(int state); /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern short SDL_JoystickGetAxis( IntPtr joystick, int axis ); /* joystick refers to an SDL_Joystick*. * Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_JoystickGetAxisInitialState( IntPtr joystick, int axis, out ushort state ); /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_JoystickGetBall( IntPtr joystick, int ball, out int dx, out int dy ); /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern byte SDL_JoystickGetButton( IntPtr joystick, int button ); /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern byte SDL_JoystickGetHat( IntPtr joystick, int hat ); /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, EntryPoint = "SDL_JoystickName", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_JoystickName( IntPtr joystick ); public static string SDL_JoystickName(IntPtr joystick) { return UTF8_ToManaged( INTERNAL_SDL_JoystickName(joystick) ); } [DllImport(nativeLibName, EntryPoint = "SDL_JoystickNameForIndex", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_JoystickNameForIndex( int device_index ); public static string SDL_JoystickNameForIndex(int device_index) { return UTF8_ToManaged( INTERNAL_SDL_JoystickNameForIndex(device_index) ); } /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_JoystickNumAxes(IntPtr joystick); /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_JoystickNumBalls(IntPtr joystick); /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_JoystickNumButtons(IntPtr joystick); /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_JoystickNumHats(IntPtr joystick); /* IntPtr refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_JoystickOpen(int device_index); /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_JoystickUpdate(); /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_NumJoysticks(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Guid SDL_JoystickGetDeviceGUID( int device_index ); /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Guid SDL_JoystickGetGUID( IntPtr joystick ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_JoystickGetGUIDString( Guid guid, byte[] pszGUID, int cbGUID ); [DllImport(nativeLibName, EntryPoint = "SDL_JoystickGetGUIDFromString", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe Guid INTERNAL_SDL_JoystickGetGUIDFromString( byte* pchGUID ); public static unsafe Guid SDL_JoystickGetGUIDFromString(string pchGuid) { int utf8PchGuidBufSize = Utf8Size(pchGuid); byte* utf8PchGuid = stackalloc byte[utf8PchGuidBufSize]; return INTERNAL_SDL_JoystickGetGUIDFromString( Utf8Encode(pchGuid, utf8PchGuid, utf8PchGuidBufSize) ); } /* Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern ushort SDL_JoystickGetDeviceVendor(int device_index); /* Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern ushort SDL_JoystickGetDeviceProduct(int device_index); /* Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern ushort SDL_JoystickGetDeviceProductVersion(int device_index); /* Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_JoystickType SDL_JoystickGetDeviceType(int device_index); /* int refers to an SDL_JoystickID. * Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_JoystickGetDeviceInstanceID(int device_index); /* joystick refers to an SDL_Joystick*. * Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern ushort SDL_JoystickGetVendor(IntPtr joystick); /* joystick refers to an SDL_Joystick*. * Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern ushort SDL_JoystickGetProduct(IntPtr joystick); /* joystick refers to an SDL_Joystick*. * Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern ushort SDL_JoystickGetProductVersion(IntPtr joystick); /* joystick refers to an SDL_Joystick*. * Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_JoystickType SDL_JoystickGetType(IntPtr joystick); /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_JoystickGetAttached(IntPtr joystick); /* int refers to an SDL_JoystickID, joystick to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_JoystickInstanceID(IntPtr joystick); /* joystick refers to an SDL_Joystick*. * Only available in 2.0.4 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel( IntPtr joystick ); /* int refers to an SDL_JoystickID, IntPtr to an SDL_Joystick*. * Only available in 2.0.4 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_JoystickFromInstanceID(int instance_id); /* Only available in 2.0.7 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_LockJoysticks(); /* Only available in 2.0.7 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_UnlockJoysticks(); /* IntPtr refers to an SDL_Joystick*. * Only available in 2.0.11 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_JoystickFromPlayerIndex(int player_index); /* IntPtr refers to an SDL_Joystick*. * Only available in 2.0.11 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_JoystickSetPlayerIndex( IntPtr joystick, int player_index ); #endregion #region SDL_gamecontroller.h public enum SDL_GameControllerBindType { SDL_CONTROLLER_BINDTYPE_NONE, SDL_CONTROLLER_BINDTYPE_BUTTON, SDL_CONTROLLER_BINDTYPE_AXIS, SDL_CONTROLLER_BINDTYPE_HAT } public enum SDL_GameControllerAxis { SDL_CONTROLLER_AXIS_INVALID = -1, SDL_CONTROLLER_AXIS_LEFTX, SDL_CONTROLLER_AXIS_LEFTY, SDL_CONTROLLER_AXIS_RIGHTX, SDL_CONTROLLER_AXIS_RIGHTY, SDL_CONTROLLER_AXIS_TRIGGERLEFT, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, SDL_CONTROLLER_AXIS_MAX } public enum SDL_GameControllerButton { SDL_CONTROLLER_BUTTON_INVALID = -1, SDL_CONTROLLER_BUTTON_A, SDL_CONTROLLER_BUTTON_B, SDL_CONTROLLER_BUTTON_X, SDL_CONTROLLER_BUTTON_Y, SDL_CONTROLLER_BUTTON_BACK, SDL_CONTROLLER_BUTTON_GUIDE, SDL_CONTROLLER_BUTTON_START, SDL_CONTROLLER_BUTTON_LEFTSTICK, SDL_CONTROLLER_BUTTON_RIGHTSTICK, SDL_CONTROLLER_BUTTON_LEFTSHOULDER, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, SDL_CONTROLLER_BUTTON_DPAD_UP, SDL_CONTROLLER_BUTTON_DPAD_DOWN, SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT, SDL_CONTROLLER_BUTTON_MAX, } public enum SDL_GameControllerType { SDL_CONTROLLER_TYPE_UNKNOWN = 0, SDL_CONTROLLER_TYPE_XBOX360, SDL_CONTROLLER_TYPE_XBOXONE, SDL_CONTROLLER_TYPE_PS3, SDL_CONTROLLER_TYPE_PS4, SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO } // FIXME: I'd rather this somehow be private... [StructLayout(LayoutKind.Sequential)] public struct INTERNAL_GameControllerButtonBind_hat { public int hat; public int hat_mask; } // FIXME: I'd rather this somehow be private... [StructLayout(LayoutKind.Explicit)] public struct INTERNAL_GameControllerButtonBind_union { [FieldOffset(0)] public int button; [FieldOffset(0)] public int axis; [FieldOffset(0)] public INTERNAL_GameControllerButtonBind_hat hat; } [StructLayout(LayoutKind.Sequential)] public struct SDL_GameControllerButtonBind { public SDL_GameControllerBindType bindType; public INTERNAL_GameControllerButtonBind_union value; } /* This exists to deal with C# being stupid about blittable types. */ [StructLayout(LayoutKind.Sequential)] private struct INTERNAL_SDL_GameControllerButtonBind { public int bindType; /* Largest data type in the union is two ints in size */ public int unionVal0; public int unionVal1; } [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerAddMapping", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe int INTERNAL_SDL_GameControllerAddMapping( byte* mappingString ); public static unsafe int SDL_GameControllerAddMapping( string mappingString ) { byte* utf8MappingString = Utf8Encode(mappingString); int result = INTERNAL_SDL_GameControllerAddMapping( utf8MappingString ); Marshal.FreeHGlobal((IntPtr) utf8MappingString); return result; } /* Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GameControllerNumMappings(); /* Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerMappingForIndex", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GameControllerMappingForIndex(int mapping_index); public static string SDL_GameControllerMappingForIndex(int mapping_index) { return UTF8_ToManaged( INTERNAL_SDL_GameControllerMappingForIndex( mapping_index ) ); } /* THIS IS AN RWops FUNCTION! */ [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerAddMappingsFromRW", CallingConvention = CallingConvention.Cdecl)] private static extern int INTERNAL_SDL_GameControllerAddMappingsFromRW( IntPtr rw, int freerw ); public static int SDL_GameControllerAddMappingsFromFile(string file) { IntPtr rwops = SDL_RWFromFile(file, "rb"); return INTERNAL_SDL_GameControllerAddMappingsFromRW(rwops, 1); } [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerMappingForGUID", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GameControllerMappingForGUID( Guid guid ); public static string SDL_GameControllerMappingForGUID(Guid guid) { return UTF8_ToManaged( INTERNAL_SDL_GameControllerMappingForGUID(guid) ); } /* gamecontroller refers to an SDL_GameController* */ [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerMapping", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GameControllerMapping( IntPtr gamecontroller ); public static string SDL_GameControllerMapping( IntPtr gamecontroller ) { return UTF8_ToManaged( INTERNAL_SDL_GameControllerMapping( gamecontroller ) ); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_IsGameController(int joystick_index); [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerNameForIndex", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GameControllerNameForIndex( int joystick_index ); public static string SDL_GameControllerNameForIndex( int joystick_index ) { return UTF8_ToManaged( INTERNAL_SDL_GameControllerNameForIndex(joystick_index) ); } /* Only available in 2.0.9 or higher. */ [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerMappingForDeviceIndex", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GameControllerMappingForDeviceIndex( int joystick_index ); public static string SDL_GameControllerMappingForDeviceIndex( int joystick_index ) { return UTF8_ToManaged( INTERNAL_SDL_GameControllerMappingForDeviceIndex(joystick_index) ); } /* IntPtr refers to an SDL_GameController* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GameControllerOpen(int joystick_index); /* gamecontroller refers to an SDL_GameController* */ [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerName", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GameControllerName( IntPtr gamecontroller ); public static string SDL_GameControllerName( IntPtr gamecontroller ) { return UTF8_ToManaged( INTERNAL_SDL_GameControllerName(gamecontroller) ); } /* gamecontroller refers to an SDL_GameController*. * Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern ushort SDL_GameControllerGetVendor( IntPtr gamecontroller ); /* gamecontroller refers to an SDL_GameController*. * Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern ushort SDL_GameControllerGetProduct( IntPtr gamecontroller ); /* gamecontroller refers to an SDL_GameController*. * Only available in 2.0.6 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern ushort SDL_GameControllerGetProductVersion( IntPtr gamecontroller ); /* gamecontroller refers to an SDL_GameController* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_GameControllerGetAttached( IntPtr gamecontroller ); /* IntPtr refers to an SDL_Joystick* * gamecontroller refers to an SDL_GameController* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GameControllerGetJoystick( IntPtr gamecontroller ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GameControllerEventState(int state); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GameControllerUpdate(); [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetAxisFromString", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe SDL_GameControllerAxis INTERNAL_SDL_GameControllerGetAxisFromString( byte* pchString ); public static unsafe SDL_GameControllerAxis SDL_GameControllerGetAxisFromString( string pchString ) { int utf8PchStringBufSize = Utf8Size(pchString); byte* utf8PchString = stackalloc byte[utf8PchStringBufSize]; return INTERNAL_SDL_GameControllerGetAxisFromString( Utf8Encode(pchString, utf8PchString, utf8PchStringBufSize) ); } [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetStringForAxis", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GameControllerGetStringForAxis( SDL_GameControllerAxis axis ); public static string SDL_GameControllerGetStringForAxis( SDL_GameControllerAxis axis ) { return UTF8_ToManaged( INTERNAL_SDL_GameControllerGetStringForAxis( axis ) ); } /* gamecontroller refers to an SDL_GameController* */ [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetBindForAxis", CallingConvention = CallingConvention.Cdecl)] private static extern INTERNAL_SDL_GameControllerButtonBind INTERNAL_SDL_GameControllerGetBindForAxis( IntPtr gamecontroller, SDL_GameControllerAxis axis ); public static SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis( IntPtr gamecontroller, SDL_GameControllerAxis axis ) { // This is guaranteed to never be null INTERNAL_SDL_GameControllerButtonBind dumb = INTERNAL_SDL_GameControllerGetBindForAxis( gamecontroller, axis ); SDL_GameControllerButtonBind result = new SDL_GameControllerButtonBind(); result.bindType = (SDL_GameControllerBindType) dumb.bindType; result.value.hat.hat = dumb.unionVal0; result.value.hat.hat_mask = dumb.unionVal1; return result; } /* gamecontroller refers to an SDL_GameController* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern short SDL_GameControllerGetAxis( IntPtr gamecontroller, SDL_GameControllerAxis axis ); [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetButtonFromString", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe SDL_GameControllerButton INTERNAL_SDL_GameControllerGetButtonFromString( byte* pchString ); public static unsafe SDL_GameControllerButton SDL_GameControllerGetButtonFromString( string pchString ) { int utf8PchStringBufSize = Utf8Size(pchString); byte* utf8PchString = stackalloc byte[utf8PchStringBufSize]; return INTERNAL_SDL_GameControllerGetButtonFromString( Utf8Encode(pchString, utf8PchString, utf8PchStringBufSize) ); } [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetStringForButton", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GameControllerGetStringForButton( SDL_GameControllerButton button ); public static string SDL_GameControllerGetStringForButton( SDL_GameControllerButton button ) { return UTF8_ToManaged( INTERNAL_SDL_GameControllerGetStringForButton(button) ); } /* gamecontroller refers to an SDL_GameController* */ [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetBindForButton", CallingConvention = CallingConvention.Cdecl)] private static extern INTERNAL_SDL_GameControllerButtonBind INTERNAL_SDL_GameControllerGetBindForButton( IntPtr gamecontroller, SDL_GameControllerButton button ); public static SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton( IntPtr gamecontroller, SDL_GameControllerButton button ) { // This is guaranteed to never be null INTERNAL_SDL_GameControllerButtonBind dumb = INTERNAL_SDL_GameControllerGetBindForButton( gamecontroller, button ); SDL_GameControllerButtonBind result = new SDL_GameControllerButtonBind(); result.bindType = (SDL_GameControllerBindType) dumb.bindType; result.value.hat.hat = dumb.unionVal0; result.value.hat.hat_mask = dumb.unionVal1; return result; } /* gamecontroller refers to an SDL_GameController* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern byte SDL_GameControllerGetButton( IntPtr gamecontroller, SDL_GameControllerButton button ); /* gamecontroller refers to an SDL_GameController*. * Only available in 2.0.9 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GameControllerRumble( IntPtr gamecontroller, UInt16 low_frequency_rumble, UInt16 high_frequency_rumble, UInt32 duration_ms ); /* gamecontroller refers to an SDL_GameController* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GameControllerClose( IntPtr gamecontroller ); /* int refers to an SDL_JoystickID, IntPtr to an SDL_GameController*. * Only available in 2.0.4 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GameControllerFromInstanceID(int joyid); /* Only available in 2.0.11 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_GameControllerType SDL_GameControllerTypeForIndex( int joystick_index ); /* IntPtr refers to an SDL_GameController*. * Only available in 2.0.11 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_GameControllerType SDL_GameControllerGetType( IntPtr gamecontroller ); /* IntPtr refers to an SDL_GameController*. * Only available in 2.0.11 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GameControllerFromPlayerIndex( int player_index ); /* IntPtr refers to an SDL_GameController*. * Only available in 2.0.11 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GameControllerSetPlayerIndex( IntPtr gamecontroller, int player_index ); #endregion #region SDL_haptic.h /* SDL_HapticEffect type */ public const ushort SDL_HAPTIC_CONSTANT = (1 << 0); public const ushort SDL_HAPTIC_SINE = (1 << 1); public const ushort SDL_HAPTIC_LEFTRIGHT = (1 << 2); public const ushort SDL_HAPTIC_TRIANGLE = (1 << 3); public const ushort SDL_HAPTIC_SAWTOOTHUP = (1 << 4); public const ushort SDL_HAPTIC_SAWTOOTHDOWN = (1 << 5); public const ushort SDL_HAPTIC_SPRING = (1 << 7); public const ushort SDL_HAPTIC_DAMPER = (1 << 8); public const ushort SDL_HAPTIC_INERTIA = (1 << 9); public const ushort SDL_HAPTIC_FRICTION = (1 << 10); public const ushort SDL_HAPTIC_CUSTOM = (1 << 11); public const ushort SDL_HAPTIC_GAIN = (1 << 12); public const ushort SDL_HAPTIC_AUTOCENTER = (1 << 13); public const ushort SDL_HAPTIC_STATUS = (1 << 14); public const ushort SDL_HAPTIC_PAUSE = (1 << 15); /* SDL_HapticDirection type */ public const byte SDL_HAPTIC_POLAR = 0; public const byte SDL_HAPTIC_CARTESIAN = 1; public const byte SDL_HAPTIC_SPHERICAL = 2; /* SDL_HapticRunEffect */ public const uint SDL_HAPTIC_INFINITY = 4294967295U; [StructLayout(LayoutKind.Sequential)] public unsafe struct SDL_HapticDirection { public byte type; public fixed int dir[3]; } [StructLayout(LayoutKind.Sequential)] public struct SDL_HapticConstant { // Header public ushort type; public SDL_HapticDirection direction; // Replay public uint length; public ushort delay; // Trigger public ushort button; public ushort interval; // Constant public short level; // Envelope public ushort attack_length; public ushort attack_level; public ushort fade_length; public ushort fade_level; } [StructLayout(LayoutKind.Sequential)] public struct SDL_HapticPeriodic { // Header public ushort type; public SDL_HapticDirection direction; // Replay public uint length; public ushort delay; // Trigger public ushort button; public ushort interval; // Periodic public ushort period; public short magnitude; public short offset; public ushort phase; // Envelope public ushort attack_length; public ushort attack_level; public ushort fade_length; public ushort fade_level; } [StructLayout(LayoutKind.Sequential)] public unsafe struct SDL_HapticCondition { // Header public ushort type; public SDL_HapticDirection direction; // Replay public uint length; public ushort delay; // Trigger public ushort button; public ushort interval; // Condition public fixed ushort right_sat[3]; public fixed ushort left_sat[3]; public fixed short right_coeff[3]; public fixed short left_coeff[3]; public fixed ushort deadband[3]; public fixed short center[3]; } [StructLayout(LayoutKind.Sequential)] public struct SDL_HapticRamp { // Header public ushort type; public SDL_HapticDirection direction; // Replay public uint length; public ushort delay; // Trigger public ushort button; public ushort interval; // Ramp public short start; public short end; // Envelope public ushort attack_length; public ushort attack_level; public ushort fade_length; public ushort fade_level; } [StructLayout(LayoutKind.Sequential)] public struct SDL_HapticLeftRight { // Header public ushort type; // Replay public uint length; // Rumble public ushort large_magnitude; public ushort small_magnitude; } [StructLayout(LayoutKind.Sequential)] public struct SDL_HapticCustom { // Header public ushort type; public SDL_HapticDirection direction; // Replay public uint length; public ushort delay; // Trigger public ushort button; public ushort interval; // Custom public byte channels; public ushort period; public ushort samples; public IntPtr data; // Uint16* // Envelope public ushort attack_length; public ushort attack_level; public ushort fade_length; public ushort fade_level; } [StructLayout(LayoutKind.Explicit)] public struct SDL_HapticEffect { [FieldOffset(0)] public ushort type; [FieldOffset(0)] public SDL_HapticConstant constant; [FieldOffset(0)] public SDL_HapticPeriodic periodic; [FieldOffset(0)] public SDL_HapticCondition condition; [FieldOffset(0)] public SDL_HapticRamp ramp; [FieldOffset(0)] public SDL_HapticLeftRight leftright; [FieldOffset(0)] public SDL_HapticCustom custom; } /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_HapticClose(IntPtr haptic); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_HapticDestroyEffect( IntPtr haptic, int effect ); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticEffectSupported( IntPtr haptic, ref SDL_HapticEffect effect ); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticGetEffectStatus( IntPtr haptic, int effect ); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticIndex(IntPtr haptic); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, EntryPoint = "SDL_HapticName", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_HapticName(int device_index); public static string SDL_HapticName(int device_index) { return UTF8_ToManaged(INTERNAL_SDL_HapticName(device_index)); } /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticNewEffect( IntPtr haptic, ref SDL_HapticEffect effect ); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticNumAxes(IntPtr haptic); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticNumEffects(IntPtr haptic); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticNumEffectsPlaying(IntPtr haptic); /* IntPtr refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_HapticOpen(int device_index); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticOpened(int device_index); /* IntPtr refers to an SDL_Haptic*, joystick to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_HapticOpenFromJoystick( IntPtr joystick ); /* IntPtr refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_HapticOpenFromMouse(); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticPause(IntPtr haptic); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_HapticQuery(IntPtr haptic); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticRumbleInit(IntPtr haptic); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticRumblePlay( IntPtr haptic, float strength, uint length ); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticRumbleStop(IntPtr haptic); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticRumbleSupported(IntPtr haptic); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticRunEffect( IntPtr haptic, int effect, uint iterations ); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticSetAutocenter( IntPtr haptic, int autocenter ); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticSetGain( IntPtr haptic, int gain ); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticStopAll(IntPtr haptic); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticStopEffect( IntPtr haptic, int effect ); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticUnpause(IntPtr haptic); /* haptic refers to an SDL_Haptic* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_HapticUpdateEffect( IntPtr haptic, int effect, ref SDL_HapticEffect data ); /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_JoystickIsHaptic(IntPtr joystick); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_MouseIsHaptic(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_NumHaptics(); #endregion #region SDL_sensor.h /* This region is only available in 2.0.9 or higher. */ public enum SDL_SensorType { SDL_SENSOR_INVALID = -1, SDL_SENSOR_UNKNOWN, SDL_SENSOR_ACCEL, SDL_SENSOR_GYRO } public const float SDL_STANDARD_GRAVITY = 9.80665f; [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_NumSensors(); [DllImport(nativeLibName, EntryPoint = "SDL_SensorGetDeviceName", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_SensorGetDeviceName(int device_index); public static string SDL_SensorGetDeviceName(int device_index) { return UTF8_ToManaged(INTERNAL_SDL_SensorGetDeviceName(device_index)); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_SensorType SDL_SensorGetDeviceType(int device_index); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SensorGetDeviceNonPortableType(int device_index); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Int32 SDL_SensorGetDeviceInstanceID(int device_index); /* IntPtr refers to an SDL_Sensor* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_SensorOpen(int device_index); /* IntPtr refers to an SDL_Sensor* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_SensorFromInstanceID( Int32 instance_id ); /* sensor refers to an SDL_Sensor* */ [DllImport(nativeLibName, EntryPoint = "SDL_SensorGetName", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_SensorGetName(IntPtr sensor); public static string SDL_SensorGetName(IntPtr sensor) { return UTF8_ToManaged(INTERNAL_SDL_SensorGetName(sensor)); } /* sensor refers to an SDL_Sensor* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_SensorType SDL_SensorGetType(IntPtr sensor); /* sensor refers to an SDL_Sensor* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SensorGetNonPortableType(IntPtr sensor); /* sensor refers to an SDL_Sensor* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern Int32 SDL_SensorGetInstanceID(IntPtr sensor); /* sensor refers to an SDL_Sensor* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SensorGetData( IntPtr sensor, float[] data, int num_values ); /* sensor refers to an SDL_Sensor* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SensorClose(IntPtr sensor); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SensorUpdate(); #endregion #region SDL_audio.h public const ushort SDL_AUDIO_MASK_BITSIZE = 0xFF; public const ushort SDL_AUDIO_MASK_DATATYPE = (1 << 8); public const ushort SDL_AUDIO_MASK_ENDIAN = (1 << 12); public const ushort SDL_AUDIO_MASK_SIGNED = (1 << 15); public static ushort SDL_AUDIO_BITSIZE(ushort x) { return (ushort) (x & SDL_AUDIO_MASK_BITSIZE); } public static bool SDL_AUDIO_ISFLOAT(ushort x) { return (x & SDL_AUDIO_MASK_DATATYPE) != 0; } public static bool SDL_AUDIO_ISBIGENDIAN(ushort x) { return (x & SDL_AUDIO_MASK_ENDIAN) != 0; } public static bool SDL_AUDIO_ISSIGNED(ushort x) { return (x & SDL_AUDIO_MASK_SIGNED) != 0; } public static bool SDL_AUDIO_ISINT(ushort x) { return (x & SDL_AUDIO_MASK_DATATYPE) == 0; } public static bool SDL_AUDIO_ISLITTLEENDIAN(ushort x) { return (x & SDL_AUDIO_MASK_ENDIAN) == 0; } public static bool SDL_AUDIO_ISUNSIGNED(ushort x) { return (x & SDL_AUDIO_MASK_SIGNED) == 0; } public const ushort AUDIO_U8 = 0x0008; public const ushort AUDIO_S8 = 0x8008; public const ushort AUDIO_U16LSB = 0x0010; public const ushort AUDIO_S16LSB = 0x8010; public const ushort AUDIO_U16MSB = 0x1010; public const ushort AUDIO_S16MSB = 0x9010; public const ushort AUDIO_U16 = AUDIO_U16LSB; public const ushort AUDIO_S16 = AUDIO_S16LSB; public const ushort AUDIO_S32LSB = 0x8020; public const ushort AUDIO_S32MSB = 0x9020; public const ushort AUDIO_S32 = AUDIO_S32LSB; public const ushort AUDIO_F32LSB = 0x8120; public const ushort AUDIO_F32MSB = 0x9120; public const ushort AUDIO_F32 = AUDIO_F32LSB; public static readonly ushort AUDIO_U16SYS = BitConverter.IsLittleEndian ? AUDIO_U16LSB : AUDIO_U16MSB; public static readonly ushort AUDIO_S16SYS = BitConverter.IsLittleEndian ? AUDIO_S16LSB : AUDIO_S16MSB; public static readonly ushort AUDIO_S32SYS = BitConverter.IsLittleEndian ? AUDIO_S32LSB : AUDIO_S32MSB; public static readonly ushort AUDIO_F32SYS = BitConverter.IsLittleEndian ? AUDIO_F32LSB : AUDIO_F32MSB; public const uint SDL_AUDIO_ALLOW_FREQUENCY_CHANGE = 0x00000001; public const uint SDL_AUDIO_ALLOW_FORMAT_CHANGE = 0x00000002; public const uint SDL_AUDIO_ALLOW_CHANNELS_CHANGE = 0x00000004; public const uint SDL_AUDIO_ALLOW_SAMPLES_CHANGE = 0x00000008; public const uint SDL_AUDIO_ALLOW_ANY_CHANGE = ( SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_FORMAT_CHANGE | SDL_AUDIO_ALLOW_CHANNELS_CHANGE | SDL_AUDIO_ALLOW_SAMPLES_CHANGE ); public const int SDL_MIX_MAXVOLUME = 128; public enum SDL_AudioStatus { SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED } [StructLayout(LayoutKind.Sequential)] public struct SDL_AudioSpec { public int freq; public ushort format; // SDL_AudioFormat public byte channels; public byte silence; public ushort samples; public uint size; public SDL_AudioCallback callback; public IntPtr userdata; // void* } /* userdata refers to a void*, stream to a Uint8 */ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void SDL_AudioCallback( IntPtr userdata, IntPtr stream, int len ); [DllImport(nativeLibName, EntryPoint = "SDL_AudioInit", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe int INTERNAL_SDL_AudioInit( byte* driver_name ); public static unsafe int SDL_AudioInit(string driver_name) { int utf8DriverNameBufSize = Utf8Size(driver_name); byte* utf8DriverName = stackalloc byte[utf8DriverNameBufSize]; return INTERNAL_SDL_AudioInit( Utf8Encode(driver_name, utf8DriverName, utf8DriverNameBufSize) ); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_AudioQuit(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_CloseAudio(); /* dev refers to an SDL_AudioDeviceID */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_CloseAudioDevice(uint dev); /* audio_buf refers to a malloc()'d buffer from SDL_LoadWAV */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_FreeWAV(IntPtr audio_buf); [DllImport(nativeLibName, EntryPoint = "SDL_GetAudioDeviceName", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetAudioDeviceName( int index, int iscapture ); public static string SDL_GetAudioDeviceName( int index, int iscapture ) { return UTF8_ToManaged( INTERNAL_SDL_GetAudioDeviceName(index, iscapture) ); } /* dev refers to an SDL_AudioDeviceID */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_AudioStatus SDL_GetAudioDeviceStatus( uint dev ); [DllImport(nativeLibName, EntryPoint = "SDL_GetAudioDriver", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetAudioDriver(int index); public static string SDL_GetAudioDriver(int index) { return UTF8_ToManaged( INTERNAL_SDL_GetAudioDriver(index) ); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_AudioStatus SDL_GetAudioStatus(); [DllImport(nativeLibName, EntryPoint = "SDL_GetCurrentAudioDriver", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetCurrentAudioDriver(); public static string SDL_GetCurrentAudioDriver() { return UTF8_ToManaged(INTERNAL_SDL_GetCurrentAudioDriver()); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetNumAudioDevices(int iscapture); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetNumAudioDrivers(); /* audio_buf will refer to a malloc()'d byte buffer */ /* THIS IS AN RWops FUNCTION! */ [DllImport(nativeLibName, EntryPoint = "SDL_LoadWAV_RW", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_LoadWAV_RW( IntPtr src, int freesrc, ref SDL_AudioSpec spec, out IntPtr audio_buf, out uint audio_len ); public static SDL_AudioSpec SDL_LoadWAV( string file, ref SDL_AudioSpec spec, out IntPtr audio_buf, out uint audio_len ) { SDL_AudioSpec result; IntPtr rwops = SDL_RWFromFile(file, "rb"); IntPtr result_ptr = INTERNAL_SDL_LoadWAV_RW( rwops, 1, ref spec, out audio_buf, out audio_len ); result = (SDL_AudioSpec) Marshal.PtrToStructure( result_ptr, typeof(SDL_AudioSpec) ); return result; } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_LockAudio(); /* dev refers to an SDL_AudioDeviceID */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_LockAudioDevice(uint dev); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_MixAudio( [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 2)] byte[] dst, [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 2)] byte[] src, uint len, int volume ); /* format refers to an SDL_AudioFormat */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_MixAudioFormat( [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 3)] byte[] dst, [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 3)] byte[] src, ushort format, uint len, int volume ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_OpenAudio( ref SDL_AudioSpec desired, out SDL_AudioSpec obtained ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_OpenAudio( ref SDL_AudioSpec desired, IntPtr obtained ); /* uint refers to an SDL_AudioDeviceID */ [DllImport(nativeLibName, EntryPoint = "SDL_OpenAudioDevice", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe uint INTERNAL_SDL_OpenAudioDevice( byte* device, int iscapture, ref SDL_AudioSpec desired, out SDL_AudioSpec obtained, int allowed_changes ); public static unsafe uint SDL_OpenAudioDevice( string device, int iscapture, ref SDL_AudioSpec desired, out SDL_AudioSpec obtained, int allowed_changes ) { int utf8DeviceBufSize = Utf8Size(device); byte* utf8Device = stackalloc byte[utf8DeviceBufSize]; return INTERNAL_SDL_OpenAudioDevice( Utf8Encode(device, utf8Device, utf8DeviceBufSize), iscapture, ref desired, out obtained, allowed_changes ); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_PauseAudio(int pause_on); /* dev refers to an SDL_AudioDeviceID */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_PauseAudioDevice( uint dev, int pause_on ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_UnlockAudio(); /* dev refers to an SDL_AudioDeviceID */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_UnlockAudioDevice(uint dev); /* dev refers to an SDL_AudioDeviceID, data to a void* * Only available in 2.0.4 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_QueueAudio( uint dev, IntPtr data, UInt32 len ); /* dev refers to an SDL_AudioDeviceID, data to a void* * Only available in 2.0.5 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_DequeueAudio( uint dev, IntPtr data, uint len ); /* dev refers to an SDL_AudioDeviceID * Only available in 2.0.4 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_GetQueuedAudioSize(uint dev); /* dev refers to an SDL_AudioDeviceID * Only available in 2.0.4 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_ClearQueuedAudio(uint dev); /* src_format and dst_format refer to SDL_AudioFormats. * IntPtr refers to an SDL_AudioStream*. * Only available in 2.0.7 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_NewAudioStream( ushort src_format, byte src_channels, int src_rate, ushort dst_format, byte dst_channels, int dst_rate ); /* stream refers to an SDL_AudioStream*, buf to a void*. * Only available in 2.0.7 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_AudioStreamPut( IntPtr stream, IntPtr buf, int len ); /* stream refers to an SDL_AudioStream*, buf to a void*. * Only available in 2.0.7 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_AudioStreamGet( IntPtr stream, IntPtr buf, int len ); /* stream refers to an SDL_AudioStream*. * Only available in 2.0.7 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_AudioStreamAvailable(IntPtr stream); /* stream refers to an SDL_AudioStream*. * Only available in 2.0.7 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_AudioStreamClear(IntPtr stream); /* stream refers to an SDL_AudioStream*. * Only available in 2.0.7 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_FreeAudioStream(IntPtr stream); #endregion #region SDL_timer.h /* System timers rely on different OS mechanisms depending on * which operating system SDL2 is compiled against. */ /* Compare tick values, return true if A has passed B. Introduced in SDL 2.0.1, * but does not require it (it was a macro). */ public static bool SDL_TICKS_PASSED(UInt32 A, UInt32 B) { return ((Int32)(B - A) <= 0); } /* Delays the thread's processing based on the milliseconds parameter */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_Delay(UInt32 ms); /* Returns the milliseconds that have passed since SDL was initialized */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_GetTicks(); /* Get the current value of the high resolution counter */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt64 SDL_GetPerformanceCounter(); /* Get the count per second of the high resolution counter */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt64 SDL_GetPerformanceFrequency(); /* param refers to a void* */ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate UInt32 SDL_TimerCallback(UInt32 interval, IntPtr param); /* int refers to an SDL_TimerID, param to a void* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_AddTimer( UInt32 interval, SDL_TimerCallback callback, IntPtr param ); /* id refers to an SDL_TimerID */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_RemoveTimer(int id); #endregion #region SDL_system.h /* Windows */ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate IntPtr SDL_WindowsMessageHook( IntPtr userdata, IntPtr hWnd, uint message, ulong wParam, long lParam ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SetWindowsMessageHook( SDL_WindowsMessageHook callback, IntPtr userdata ); /* iOS */ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void SDL_iPhoneAnimationCallback(IntPtr p); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_iPhoneSetAnimationCallback( IntPtr window, /* SDL_Window* */ int interval, SDL_iPhoneAnimationCallback callback, IntPtr callbackParam ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_iPhoneSetEventPump(SDL_bool enabled); /* Android */ public const int SDL_ANDROID_EXTERNAL_STORAGE_READ = 0x01; public const int SDL_ANDROID_EXTERNAL_STORAGE_WRITE = 0x02; /* IntPtr refers to a JNIEnv* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_AndroidGetJNIEnv(); /* IntPtr refers to a jobject */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_AndroidGetActivity(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_IsAndroidTV(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_IsChromebook(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_IsDeXMode(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_AndroidBackButton(); [DllImport(nativeLibName, EntryPoint = "SDL_AndroidGetInternalStoragePath", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_AndroidGetInternalStoragePath(); public static string SDL_AndroidGetInternalStoragePath() { return UTF8_ToManaged( INTERNAL_SDL_AndroidGetInternalStoragePath() ); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_AndroidGetExternalStorageState(); [DllImport(nativeLibName, EntryPoint = "SDL_AndroidGetExternalStoragePath", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_AndroidGetExternalStoragePath(); public static string SDL_AndroidGetExternalStoragePath() { return UTF8_ToManaged( INTERNAL_SDL_AndroidGetExternalStoragePath() ); } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetAndroidSDKVersion(); /* WinRT */ public enum SDL_WinRT_DeviceFamily { SDL_WINRT_DEVICEFAMILY_UNKNOWN, SDL_WINRT_DEVICEFAMILY_DESKTOP, SDL_WINRT_DEVICEFAMILY_MOBILE, SDL_WINRT_DEVICEFAMILY_XBOX } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_WinRT_DeviceFamily SDL_WinRTGetDeviceFamily(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_IsTablet(); #endregion #region SDL_syswm.h public enum SDL_SYSWM_TYPE { SDL_SYSWM_UNKNOWN, SDL_SYSWM_WINDOWS, SDL_SYSWM_X11, SDL_SYSWM_DIRECTFB, SDL_SYSWM_COCOA, SDL_SYSWM_UIKIT, SDL_SYSWM_WAYLAND, SDL_SYSWM_MIR, SDL_SYSWM_WINRT, SDL_SYSWM_ANDROID, SDL_SYSWM_VIVANTE, SDL_SYSWM_OS2, SDL_SYSWM_HAIKU } // FIXME: I wish these weren't public... [StructLayout(LayoutKind.Sequential)] public struct INTERNAL_windows_wminfo { public IntPtr window; // Refers to an HWND public IntPtr hdc; // Refers to an HDC public IntPtr hinstance; // Refers to an HINSTANCE } [StructLayout(LayoutKind.Sequential)] public struct INTERNAL_winrt_wminfo { public IntPtr window; // Refers to an IInspectable* } [StructLayout(LayoutKind.Sequential)] public struct INTERNAL_x11_wminfo { public IntPtr display; // Refers to a Display* public IntPtr window; // Refers to a Window (XID, use ToInt64!) } [StructLayout(LayoutKind.Sequential)] public struct INTERNAL_directfb_wminfo { public IntPtr dfb; // Refers to an IDirectFB* public IntPtr window; // Refers to an IDirectFBWindow* public IntPtr surface; // Refers to an IDirectFBSurface* } [StructLayout(LayoutKind.Sequential)] public struct INTERNAL_cocoa_wminfo { public IntPtr window; // Refers to an NSWindow* } [StructLayout(LayoutKind.Sequential)] public struct INTERNAL_uikit_wminfo { public IntPtr window; // Refers to a UIWindow* public uint framebuffer; public uint colorbuffer; public uint resolveFramebuffer; } [StructLayout(LayoutKind.Sequential)] public struct INTERNAL_wayland_wminfo { public IntPtr display; // Refers to a wl_display* public IntPtr surface; // Refers to a wl_surface* public IntPtr shell_surface; // Refers to a wl_shell_surface* } [StructLayout(LayoutKind.Sequential)] public struct INTERNAL_mir_wminfo { public IntPtr connection; // Refers to a MirConnection* public IntPtr surface; // Refers to a MirSurface* } [StructLayout(LayoutKind.Sequential)] public struct INTERNAL_android_wminfo { public IntPtr window; // Refers to an ANativeWindow public IntPtr surface; // Refers to an EGLSurface } [StructLayout(LayoutKind.Sequential)] public struct INTERNAL_vivante_wminfo { public IntPtr display; // Refers to an EGLNativeDisplayType public IntPtr window; // Refers to an EGLNativeWindowType } [StructLayout(LayoutKind.Explicit)] public struct INTERNAL_SysWMDriverUnion { [FieldOffset(0)] public INTERNAL_windows_wminfo win; [FieldOffset(0)] public INTERNAL_winrt_wminfo winrt; [FieldOffset(0)] public INTERNAL_x11_wminfo x11; [FieldOffset(0)] public INTERNAL_directfb_wminfo dfb; [FieldOffset(0)] public INTERNAL_cocoa_wminfo cocoa; [FieldOffset(0)] public INTERNAL_uikit_wminfo uikit; [FieldOffset(0)] public INTERNAL_wayland_wminfo wl; [FieldOffset(0)] public INTERNAL_mir_wminfo mir; [FieldOffset(0)] public INTERNAL_android_wminfo android; [FieldOffset(0)] public INTERNAL_vivante_wminfo vivante; // private int dummy; } [StructLayout(LayoutKind.Sequential)] public struct SDL_SysWMinfo { public SDL_version version; public SDL_SYSWM_TYPE subsystem; public INTERNAL_SysWMDriverUnion info; } /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_GetWindowWMInfo( IntPtr window, ref SDL_SysWMinfo info ); #endregion #region SDL_filesystem.h /* Only available in 2.0.1 or higher. */ [DllImport(nativeLibName, EntryPoint = "SDL_GetBasePath", CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr INTERNAL_SDL_GetBasePath(); public static string SDL_GetBasePath() { return UTF8_ToManaged(INTERNAL_SDL_GetBasePath(), true); } /* Only available in 2.0.1 or higher. */ [DllImport(nativeLibName, EntryPoint = "SDL_GetPrefPath", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe IntPtr INTERNAL_SDL_GetPrefPath( byte* org, byte* app ); public static unsafe string SDL_GetPrefPath(string org, string app) { int utf8OrgBufSize = Utf8SizeNullable(org); byte* utf8Org = stackalloc byte[utf8OrgBufSize]; int utf8AppBufSize = Utf8SizeNullable(app); byte* utf8App = stackalloc byte[utf8AppBufSize]; return UTF8_ToManaged( INTERNAL_SDL_GetPrefPath( Utf8EncodeNullable(org, utf8Org, utf8OrgBufSize), Utf8EncodeNullable(app, utf8App, utf8AppBufSize) ), true ); } #endregion #region SDL_power.h public enum SDL_PowerState { SDL_POWERSTATE_UNKNOWN = 0, SDL_POWERSTATE_ON_BATTERY, SDL_POWERSTATE_NO_BATTERY, SDL_POWERSTATE_CHARGING, SDL_POWERSTATE_CHARGED } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_PowerState SDL_GetPowerInfo( out int secs, out int pct ); #endregion #region SDL_cpuinfo.h [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetCPUCount(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetCPUCacheLineSize(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasRDTSC(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasAltiVec(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasMMX(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_Has3DNow(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasSSE(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasSSE2(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasSSE3(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasSSE41(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasSSE42(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasAVX(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasAVX2(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasAVX512F(); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_HasNEON(); /* Only available in 2.0.1 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetSystemRAM(); /* Only available in SDL 2.0.10 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_SIMDGetAlignment(); /* Only available in SDL 2.0.10 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_SIMDAlloc(uint len); /* Only available in SDL 2.0.10 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_SIMDFree(IntPtr ptr); /* Only available in SDL 2.0.11 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_HasARMSIMD(); #endregion } } ================================================ FILE: Engine/SDL2/SDL2_image.cs ================================================ #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 * */ #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 ); public static string IMG_GetError() { return SDL.SDL_GetError(); } public static void IMG_SetError(string fmtAndArglist) { SDL.SDL_SetError(fmtAndArglist); } #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 } } ================================================ FILE: Engine/SDL2/SDL2_mixer.cs ================================================ #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 * */ #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 } } ================================================ FILE: Engine/SDL2/SDL2_ttf.cs ================================================ #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 * */ #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 } } ================================================ FILE: Engine/Utility/Bounds2.cs ================================================ using System; using System.Collections.Generic; struct Bounds2 { public Vector2 Position; public Vector2 Size; private Vector2 Min => Position; private Vector2 Max => Position + Size; /// /// Creates a new 2D bounds rectangle. /// /// The origin of the bounds. /// The size of the bounds. public Bounds2(Vector2 position, Vector2 size) { Position = position; Size = size; } /// /// Creates a new 2D bounds rectangle. /// /// The X component of the origin of the bounds. /// The Y component of the origin of the bounds. /// The width of the bounds. /// The height of the bounds. public Bounds2(float x, float y, float width, float height) { Position = new Vector2(x, y); Size = new Vector2(width, height); } public override string ToString() { return string.Format("({0}, {1})", Position, Size); } /// /// Returns true if a point is within these bounds. /// /// The point to test. public bool Contains(Vector2 point) { return Min.X <= point.X && point.X <= Max.X && Min.Y <= point.Y && point.Y <= Max.Y; } /// /// Returns true if another bounds rectangle overlaps these bounds. /// /// The bounds to test. public bool Overlaps(Bounds2 bounds) { return !(bounds.Max.X < Min.X || bounds.Min.X > Max.X || bounds.Max.Y < Min.Y || bounds.Min.Y > Max.Y); } } ================================================ FILE: Engine/Utility/Color.cs ================================================ using System; using System.Collections.Generic; struct Color { public byte R; public byte G; public byte B; public byte A; /// /// Creates a new color with full opacity (alpha = 255). /// /// The red component, from 0 to 255. /// The green component, from 0 to 255. /// The blue component, from 0 to 255. public Color(byte r, byte g, byte b) { R = r; G = g; B = b; A = 0xFF; } /// /// Creates a new color. /// /// The red component, from 0 to 255. /// The green component, from 0 to 255. /// The blue component, from 0 to 255. /// The alpha component, from 0 to 255. public Color(byte r, byte g, byte b, byte a) { R = r; G = g; B = b; A = a; } public override string ToString() { return string.Format("({0}, {1}, {2}, {3})", R, G, B, A); } /// /// Returns a copy of this color with a modified alpha value. /// /// The scale factor to apply to the original alpha, between 0 and 1. public Color WithAlpha(float a) { byte alpha = (byte)Math.Max(Math.Min(A * a, 255), 0); return new Color(R, G, B, alpha); } public static readonly Color Transparent = new Color(0x00, 0x00, 0x00, 0x00); public static readonly Color AliceBlue = new Color(0xF0, 0xF8, 0xFF); public static readonly Color AntiqueWhite = new Color(0xFA, 0xEB, 0xD7); public static readonly Color Aqua = new Color(0x00, 0xFF, 0xFF); public static readonly Color Aquamarine = new Color(0x7F, 0xFF, 0xD4); public static readonly Color Azure = new Color(0xF0, 0xFF, 0xFF); public static readonly Color Beige = new Color(0xF5, 0xF5, 0xDC); public static readonly Color Bisque = new Color(0xFF, 0xE4, 0xC4); public static readonly Color Black = new Color(0x00, 0x00, 0x00); public static readonly Color BlanchedAlmond = new Color(0xFF, 0xEB, 0xCD); public static readonly Color Blue = new Color(0x00, 0x00, 0xFF); public static readonly Color BlueViolet = new Color(0x8A, 0x2B, 0xE2); public static readonly Color Brown = new Color(0xA5, 0x2A, 0x2A); public static readonly Color BurlyWood = new Color(0xDE, 0xB8, 0x87); public static readonly Color CadetBlue = new Color(0x5F, 0x9E, 0xA0); public static readonly Color Chartreuse = new Color(0x7F, 0xFF, 0x00); public static readonly Color Chocolate = new Color(0xD2, 0x69, 0x1E); public static readonly Color Coral = new Color(0xFF, 0x7F, 0x50); public static readonly Color CornflowerBlue = new Color(0x64, 0x95, 0xED); public static readonly Color Cornsilk = new Color(0xFF, 0xF8, 0xDC); public static readonly Color Crimson = new Color(0xDC, 0x14, 0x3C); public static readonly Color Cyan = new Color(0x00, 0xFF, 0xFF); public static readonly Color DarkBlue = new Color(0x00, 0x00, 0x8B); public static readonly Color DarkCyan = new Color(0x00, 0x8B, 0x8B); public static readonly Color DarkGoldenrod = new Color(0xB8, 0x86, 0x0B); public static readonly Color DarkGray = new Color(0xA9, 0xA9, 0xA9); public static readonly Color DarkGreen = new Color(0x00, 0x64, 0x00); public static readonly Color DarkKhaki = new Color(0xBD, 0xB7, 0x6B); public static readonly Color DarkMagenta = new Color(0x8B, 0x00, 0x8B); public static readonly Color DarkOliveGreen = new Color(0x55, 0x6B, 0x2F); public static readonly Color DarkOrange = new Color(0xFF, 0x8C, 0x00); public static readonly Color DarkOrchid = new Color(0x99, 0x32, 0xCC); public static readonly Color DarkRed = new Color(0x8B, 0x00, 0x00); public static readonly Color DarkSalmon = new Color(0xE9, 0x96, 0x7A); public static readonly Color DarkSeaGreen = new Color(0x8F, 0xBC, 0x8F); public static readonly Color DarkSlateBlue = new Color(0x48, 0x3D, 0x8B); public static readonly Color DarkSlateGray = new Color(0x2F, 0x4F, 0x4F); public static readonly Color DarkTurquoise = new Color(0x00, 0xCE, 0xD1); public static readonly Color DarkViolet = new Color(0x94, 0x00, 0xD3); public static readonly Color DeepPink = new Color(0xFF, 0x14, 0x93); public static readonly Color DeepSkyBlue = new Color(0x00, 0xBF, 0xFF); public static readonly Color DimGray = new Color(0x69, 0x69, 0x69); public static readonly Color DodgerBlue = new Color(0x1E, 0x90, 0xFF); public static readonly Color Firebrick = new Color(0xB2, 0x22, 0x22); public static readonly Color FloralWhite = new Color(0xFF, 0xFA, 0xF0); public static readonly Color ForestGreen = new Color(0x22, 0x8B, 0x22); public static readonly Color Fuchsia = new Color(0xFF, 0x00, 0xFF); public static readonly Color Gainsboro = new Color(0xDC, 0xDC, 0xDC); public static readonly Color GhostWhite = new Color(0xF8, 0xF8, 0xFF); public static readonly Color Gold = new Color(0xFF, 0xD7, 0x00); public static readonly Color Goldenrod = new Color(0xDA, 0xA5, 0x20); public static readonly Color Gray = new Color(0x80, 0x80, 0x80); public static readonly Color Green = new Color(0x00, 0x80, 0x00); public static readonly Color GreenYellow = new Color(0xAD, 0xFF, 0x2F); public static readonly Color Honeydew = new Color(0xF0, 0xFF, 0xF0); public static readonly Color HotPink = new Color(0xFF, 0x69, 0xB4); public static readonly Color IndianRed = new Color(0xCD, 0x5C, 0x5C); public static readonly Color Indigo = new Color(0x4B, 0x00, 0x82); public static readonly Color Ivory = new Color(0xFF, 0xFF, 0xF0); public static readonly Color Khaki = new Color(0xF0, 0xE6, 0x8C); public static readonly Color Lavender = new Color(0xE6, 0xE6, 0xFA); public static readonly Color LavenderBlush = new Color(0xFF, 0xF0, 0xF5); public static readonly Color LawnGreen = new Color(0x7C, 0xFC, 0x00); public static readonly Color LemonChiffon = new Color(0xFF, 0xFA, 0xCD); public static readonly Color LightBlue = new Color(0xAD, 0xD8, 0xE6); public static readonly Color LightCoral = new Color(0xF0, 0x80, 0x80); public static readonly Color LightCyan = new Color(0xE0, 0xFF, 0xFF); public static readonly Color LightGoldenrodYellow = new Color(0xFA, 0xFA, 0xD2); public static readonly Color LightGray = new Color(0xD3, 0xD3, 0xD3); public static readonly Color LightGreen = new Color(0x90, 0xEE, 0x90); public static readonly Color LightPink = new Color(0xFF, 0xB6, 0xC1); public static readonly Color LightSalmon = new Color(0xFF, 0xA0, 0x7A); public static readonly Color LightSeaGreen = new Color(0x20, 0xB2, 0xAA); public static readonly Color LightSkyBlue = new Color(0x87, 0xCE, 0xFA); public static readonly Color LightSlateGray = new Color(0x77, 0x88, 0x99); public static readonly Color LightSteelBlue = new Color(0xB0, 0xC4, 0xDE); public static readonly Color LightYellow = new Color(0xFF, 0xFF, 0xE0); public static readonly Color Lime = new Color(0x00, 0xFF, 0x00); public static readonly Color LimeGreen = new Color(0x32, 0xCD, 0x32); public static readonly Color Linen = new Color(0xFA, 0xF0, 0xE6); public static readonly Color Magenta = new Color(0xFF, 0x00, 0xFF); public static readonly Color Maroon = new Color(0x80, 0x00, 0x00); public static readonly Color MediumAquamarine = new Color(0x66, 0xCD, 0xAA); public static readonly Color MediumBlue = new Color(0x00, 0x00, 0xCD); public static readonly Color MediumOrchid = new Color(0xBA, 0x55, 0xD3); public static readonly Color MediumPurple = new Color(0x93, 0x70, 0xDB); public static readonly Color MediumSeaGreen = new Color(0x3C, 0xB3, 0x71); public static readonly Color MediumSlateBlue = new Color(0x7B, 0x68, 0xEE); public static readonly Color MediumSpringGreen = new Color(0x00, 0xFA, 0x9A); public static readonly Color MediumTurquoise = new Color(0x48, 0xD1, 0xCC); public static readonly Color MediumVioletRed = new Color(0xC7, 0x15, 0x85); public static readonly Color MidnightBlue = new Color(0x19, 0x19, 0x70); public static readonly Color MintCream = new Color(0xF5, 0xFF, 0xFA); public static readonly Color MistyRose = new Color(0xFF, 0xE4, 0xE1); public static readonly Color Moccasin = new Color(0xFF, 0xE4, 0xB5); public static readonly Color NavajoWhite = new Color(0xFF, 0xDE, 0xAD); public static readonly Color Navy = new Color(0x00, 0x00, 0x80); public static readonly Color OldLace = new Color(0xFD, 0xF5, 0xE6); public static readonly Color Olive = new Color(0x80, 0x80, 0x00); public static readonly Color OliveDrab = new Color(0x6B, 0x8E, 0x23); public static readonly Color Orange = new Color(0xFF, 0xA5, 0x00); public static readonly Color OrangeRed = new Color(0xFF, 0x45, 0x00); public static readonly Color Orchid = new Color(0xDA, 0x70, 0xD6); public static readonly Color PaleGoldenrod = new Color(0xEE, 0xE8, 0xAA); public static readonly Color PaleGreen = new Color(0x98, 0xFB, 0x98); public static readonly Color PaleTurquoise = new Color(0xAF, 0xEE, 0xEE); public static readonly Color PaleVioletRed = new Color(0xDB, 0x70, 0x93); public static readonly Color PapayaWhip = new Color(0xFF, 0xEF, 0xD5); public static readonly Color PeachPuff = new Color(0xFF, 0xDA, 0xB9); public static readonly Color Peru = new Color(0xCD, 0x85, 0x3F); public static readonly Color Pink = new Color(0xFF, 0xC0, 0xCB); public static readonly Color Plum = new Color(0xDD, 0xA0, 0xDD); public static readonly Color PowderBlue = new Color(0xB0, 0xE0, 0xE6); public static readonly Color Purple = new Color(0x80, 0x00, 0x80); public static readonly Color Red = new Color(0xFF, 0x00, 0x00); public static readonly Color RosyBrown = new Color(0xBC, 0x8F, 0x8F); public static readonly Color RoyalBlue = new Color(0x41, 0x69, 0xE1); public static readonly Color SaddleBrown = new Color(0x8B, 0x45, 0x13); public static readonly Color Salmon = new Color(0xFA, 0x80, 0x72); public static readonly Color SandyBrown = new Color(0xF4, 0xA4, 0x60); public static readonly Color SeaGreen = new Color(0x2E, 0x8B, 0x57); public static readonly Color SeaShell = new Color(0xFF, 0xF5, 0xEE); public static readonly Color Sienna = new Color(0xA0, 0x52, 0x2D); public static readonly Color Silver = new Color(0xC0, 0xC0, 0xC0); public static readonly Color SkyBlue = new Color(0x87, 0xCE, 0xEB); public static readonly Color SlateBlue = new Color(0x6A, 0x5A, 0xCD); public static readonly Color SlateGray = new Color(0x70, 0x80, 0x90); public static readonly Color Snow = new Color(0xFF, 0xFA, 0xFA); public static readonly Color SpringGreen = new Color(0x00, 0xFF, 0x7F); public static readonly Color SteelBlue = new Color(0x46, 0x82, 0xB4); public static readonly Color Tan = new Color(0xD2, 0xB4, 0x8C); public static readonly Color Teal = new Color(0x00, 0x80, 0x80); public static readonly Color Thistle = new Color(0xD8, 0xBF, 0xD8); public static readonly Color Tomato = new Color(0xFF, 0x63, 0x47); public static readonly Color Turquoise = new Color(0x40, 0xE0, 0xD0); public static readonly Color Violet = new Color(0xEE, 0x82, 0xEE); public static readonly Color Wheat = new Color(0xF5, 0xDE, 0xB3); public static readonly Color White = new Color(0xFF, 0xFF, 0xFF); public static readonly Color WhiteSmoke = new Color(0xF5, 0xF5, 0xF5); public static readonly Color Yellow = new Color(0xFF, 0xFF, 0x00); public static readonly Color YellowGreen = new Color(0x9A, 0xCD, 0x32); } ================================================ FILE: Engine/Utility/Vector2.cs ================================================ using System; using System.Collections.Generic; struct Vector2 { public float X, Y; public static readonly Vector2 Zero = new Vector2(0, 0); /// /// Creates a new 2D vector. /// /// The X component. /// The Y component. public Vector2(float x, float y) { X = x; Y = y; } public override string ToString() { return string.Format("({0}, {1})", X, Y); } /// /// Returns the length of this vector. /// public float Length() { return (float)Math.Sqrt(X * X + Y * Y); } /// /// Returns a copy of this vector rotated clockwise around the origin. /// /// The angle to rotate (in degrees). public Vector2 Rotated(float degrees) { float radians = (float)(degrees * Math.PI / 180); float sin = (float)Math.Sin(radians); float cos = (float)Math.Cos(radians); return new Vector2( X * cos - Y * sin, X * sin + Y * cos); } /// /// Returns a copy of this vector normalized so that its length is one. If the length is zero it will be unchanged. /// public Vector2 Normalized() { float length = Length(); if (length == 0) { return Vector2.Zero; } else { return this / length; } } /// /// Returns the dot product of two vectors. /// /// The first vector. /// The second vector. public static float Dot(Vector2 a, Vector2 b) { return a.X * b.X + a.Y * b.Y; } /// /// Returns the Z component of the cross product of two vectors. /// /// The first vector. /// The second vector. public static float Cross(Vector2 a, Vector2 b) { return a.X * b.Y - a.Y * b.X; } public static Vector2 operator -(Vector2 a) { return new Vector2(-a.X, -a.Y); } public static Vector2 operator +(Vector2 a, Vector2 b) { return new Vector2(a.X + b.X, a.Y + b.Y); } public static Vector2 operator -(Vector2 a, Vector2 b) { return new Vector2(a.X - b.X, a.Y - b.Y); } public static Vector2 operator *(float s, Vector2 v) { return new Vector2(s * v.X, s * v.Y); } public static Vector2 operator *(Vector2 v, float s) { return new Vector2(s * v.X, s * v.Y); } public static Vector2 operator *(int s, Vector2 v) { return new Vector2(s * v.X, s * v.Y); } public static Vector2 operator *(Vector2 v, int s) { return new Vector2(s * v.X, s * v.Y); } public static Vector2 operator /(Vector2 v, float s) { return new Vector2(v.X / s, v.Y / s); } public static Vector2 operator /(Vector2 v, int s) { return new Vector2(v.X / s, v.Y / s); } } ================================================ FILE: Game/Game.cs ================================================ using System; using System.Collections.Generic; class Game { public static readonly string Title = "Minimalist Game Framework"; public static readonly Vector2 Resolution = new Vector2(128, 128); // Define some constants controlling animation speed: static readonly float Framerate = 10; static readonly float WalkSpeed = 50; // Load some textures when the game starts: Texture texKnight = Engine.LoadTexture("knight.png"); Texture texBackground = Engine.LoadTexture("background.png"); // Keep track of the knight's state: Vector2 knightPosition = Resolution / 2; bool knightFaceLeft = false; float knightFrameIndex = 0; public Game() { } public void Update() { // Draw the background: Engine.DrawTexture(texBackground, Vector2.Zero); // Use the keyboard to control the knight: Vector2 moveOffset = Vector2.Zero; if (Engine.GetKeyHeld(Key.Left)) { moveOffset.X -= 1; knightFaceLeft = true; } if (Engine.GetKeyHeld(Key.Right)) { moveOffset.X += 1; knightFaceLeft = false; } if (Engine.GetKeyHeld(Key.Up)) { moveOffset.Y -= 1; } if (Engine.GetKeyHeld(Key.Down)) { moveOffset.Y += 1; } knightPosition += moveOffset * WalkSpeed * Engine.TimeDelta; // Advance through the knight's 6-frame animation and select the current frame: knightFrameIndex = (knightFrameIndex + Engine.TimeDelta * Framerate) % 6.0f; bool knightIdle = moveOffset.Length() == 0; Bounds2 knightFrameBounds = new Bounds2(((int)knightFrameIndex) * 16, knightIdle ? 0 : 16, 16, 16); // Draw the knight: Vector2 knightDrawPos = knightPosition + new Vector2(-8, -8); TextureMirror knightMirror = knightFaceLeft ? TextureMirror.Horizontal : TextureMirror.None; Engine.DrawTexture(texKnight, knightDrawPos, source: knightFrameBounds, mirror: knightMirror); } } ================================================ FILE: Game.csproj ================================================  Debug AnyCPU {6626172D-57E8-4E06-9449-65E8B8EFC912} WinExe Properties Game Game v4.5.2 512 true true Builds\Debug\ Builds\Temp\Debug DEBUG;TRACE full x64 prompt MinimumRecommendedRules.ruleset true true Builds\Release\ Builds\Temp\Release TRACE true pdbonly x64 prompt MinimumRecommendedRules.ruleset true true (robocopy "$(ProjectDir)Assets" "$(TargetDir)Assets" /MIR /W:1) ^& IF %25ERRORLEVEL%25 LSS 8 SET ERRORLEVEL = 0 (robocopy "$(ProjectDir)Libraries" "$(TargetDir)\" /W:1) ^& IF %25ERRORLEVEL%25 LSS 8 SET ERRORLEVEL = 0 ================================================ FILE: Game.sln ================================================  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29905.134 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Game", "Game.csproj", "{6626172D-57E8-4E06-9449-65E8B8EFC912}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {6626172D-57E8-4E06-9449-65E8B8EFC912}.Debug|x64.ActiveCfg = Debug|x64 {6626172D-57E8-4E06-9449-65E8B8EFC912}.Debug|x64.Build.0 = Debug|x64 {6626172D-57E8-4E06-9449-65E8B8EFC912}.Release|x64.ActiveCfg = Release|x64 {6626172D-57E8-4E06-9449-65E8B8EFC912}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D4DB74FD-4AB0-4BF4-B12B-D0DB1562152B} EndGlobalSection EndGlobal ================================================ FILE: LICENSE.md ================================================ Copyright (c) 2020 Zach Barth and Keith Holman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Minimalist Game Framework # This is a minimalist game framework in the style of the "game engine" we use at [Zachtronics](http://www.zachtronics.com). It is a thin layer over [SDL2](http://wiki.libsdl.org/FrontPage) that encourages you to modify and extend the framework to suit your needs and preferences. There is also a [Java version](https://github.com/zachbarth/minimalist-game-framework-java) of this framework. # Getting Started # 1. Clone the repo. 2. Add your assets (images, fonts, sounds, and music) to the Assets folder. These files will be automatically synchronized to your build directory by a post-build step in Visual Studio. 3. Start writing your game in the `Game` class. All functions and properties listed below are members of the static `Engine` class. For example, if you wanted to draw a line, you could call `Engine.DrawLine()` from anywhere in your code. Documentation for function arguments and enum values can be found in the code itself. # Example # ![Resizable Textures Example](Docs/example-game.gif) ```C# class Game { public static readonly string Title = "Minimalist Game Framework"; public static readonly Vector2 Resolution = new Vector2(128, 128); // Define some constants controlling animation speed: static readonly float Framerate = 10; static readonly float WalkSpeed = 50; // Load some textures when the game starts: Texture texKnight = Engine.LoadTexture("knight.png"); Texture texBackground = Engine.LoadTexture("background.png"); // Keep track of the knight's state: Vector2 knightPosition = Resolution / 2; bool knightFaceLeft = false; float knightFrameIndex = 0; public Game() { } public void Update() { // Draw the background: Engine.DrawTexture(texBackground, Vector2.Zero); // Use the keyboard to control the knight: Vector2 moveOffset = Vector2.Zero; if (Engine.GetKeyHeld(Key.Left)) { moveOffset.X -= 1; knightFaceLeft = true; } if (Engine.GetKeyHeld(Key.Right)) { moveOffset.X += 1; knightFaceLeft = false; } if (Engine.GetKeyHeld(Key.Up)) { moveOffset.Y -= 1; } if (Engine.GetKeyHeld(Key.Down)) { moveOffset.Y += 1; } knightPosition += moveOffset * WalkSpeed * Engine.TimeDelta; // Advance through the knight's 6-frame animation and select the current frame: knightFrameIndex = (knightFrameIndex + Engine.TimeDelta * Framerate) % 6.0f; bool knightIdle = moveOffset.Length() == 0; Bounds2 knightFrameBounds = new Bounds2(((int)knightFrameIndex) * 16, knightIdle ? 0 : 16, 16, 16); // Draw the knight: Vector2 knightDrawPos = knightPosition + new Vector2(-8, -8); TextureMirror knightMirror = knightFaceLeft ? TextureMirror.Horizontal : TextureMirror.None; Engine.DrawTexture(texKnight, knightDrawPos, source: knightFrameBounds, mirror: knightMirror); } } ``` Art Source: _[https://o-lobster.itch.io/simple-dungeon-crawler-16x16-pixel-pack](https://o-lobster.itch.io/simple-dungeon-crawler-16x16-pixel-pack)_ # Core # float **`TimeDelta`** * The amount of time (in seconds) since the last frame. # Content # Texture **`LoadTexture`**(string path) * Loads a texture from the Assets directory. * Supports the following formats: BMP, GIF, JPEG, PNG, SVG, TGA, TIFF, WEBP. ResizableTexture **`LoadResizableTexture`**(string path, int leftOffset, int rightOffset, int topOffset, int bottomOffset) * Loads a resizable texture from the Assets directory. * Supports the following formats: BMP, GIF, JPEG, PNG, SVG, TGA, TIFF, WEBP. * See below for an explanation of how resizable textures work. Font **`LoadFont`**(string path, int pointSize) * Loads a font from the Assets directory for a single text size. * Supports the following formats: TTF, FON. Sound **`LoadSound`**(string path) * Loads a sound file from the Assets directory. * Supports the following formats: WAV, OGG. Music **`LoadMusic`**(string path) * Loads a music file from the Assets directory. * Supports the following formats: WAV, OGG, MP3, FLAC. # Graphics # void **`DrawLine`**(Vector2 start, Vector2 end, Color color) * Draws a line. void **`DrawRectEmpty`**(Bounds2 bounds, Color color) * Draws an empty rectangle. void **`DrawRectSolid`**(Bounds2 bounds, Color color) * Draws a solid rectangle. void **`DrawTexture`**(Texture texture, Vector2 position, Color? color, Vector2? size, float rotation, Vector2? pivot, TextureMirror mirror, Bounds2? source, TextureBlendMode blendMode, TextureScaleMode scaleMode) * Draws a texture. * Look at the code for more information about the function arguments. Most of them are optional. void **`DrawResizableTexture`**(ResizableTexture texture, Bounds2 bounds, Color? color, TextureBlendMode blendMode, TextureScaleMode scaleMode) * Draws a resizable texture. * See below for an explanation of how resizable textures work. Bounds2 **`DrawString`**(string text, Vector2 position, Color color, Font font, TextAlignment alignment, bool measureOnly) * Draws a text string. * Returns the bounds of the drawn text. # Keyboard Input # bool **`GetKeyDown`**(Key key, bool allowAutorepeat) * Returns true if a key was pressed down this frame. bool **`GetKeyHeld`**(Key key) * Returns true if a key was held during this frame. bool **`GetKeyUp`**(Key key) * Returns true if a key was released this frame. string **`TypedText`** * The textual representation of the keys that were pressed this frame. # Mouse Input # Vector2 **`MousePosition`** * The current position of the mouse cursor (in pixels). Vector2 **`MouseMotion`** * The change in position of the mouse cursor this frame (in pixels). float **`MouseScroll`** * The amount the mouse wheel has been scrolled this frame (in scroll units). bool **`GetMouseButtonDown`**(MouseButton button) * Returns true if a mouse button was pressed down this frame. bool **`GetMouseButtonHeld`**(MouseButton button) * Returns true if a mouse button was held during this frame. bool **`GetMouseButtonUp`**(MouseButton button) * Returns true if a mouse button was released this frame. void **`SetMouseMode`**(MouseMode mode) * Sets the mouse mode, which controls the visibility and lock state of the cursor. # Gamepad Input # bool **`GetGamepadConnected`**(int player) * Returns true if a player's gamepad is connected. Vector2 **`GetGamepadAxis`**(int player, GamepadAxis axis) * Reads the analog values of the specified axis on a player's gamepad. bool **`GetGamepadButtonDown`**(int player, GamepadButton button) * Returns true if a gamepad button was pressed down this frame. bool **`GetGamepadButtonHeld`**(int player, GamepadButton button) * Returns true if a gamepad button was held during this frame. bool **`GetGamepadButtonUp`**(int player, GamepadButton button) * Returns true if a gamepad button was released this frame. # Audio # SoundInstance **`PlaySound`**(Sound sound, bool repeat, float fadeTime) * Plays a sound. * Returns an instance handle that can be passed to StopSound() to stop playback of the sound. void **`StopSound`**(SoundInstance instance, float fadeTime) * Stops a playing sound. void **`PlayMusic`**(Music music, bool looping, float fadeTime) * Plays music, stopping any currently playing music first. void **`StopMusic`**(float fadeTime) * Stops the current music. # Utility Classes # class **`Vector2`** * A simple 2D vector class that supports basic vector math operations that is used in many API functions. class **`Bounds2`** * A simple axis-aligned 2D bounding rectangle that is used in a few API functions. class **`Color`** * A data structure representing a 32-bit RGBA color that is used in many API functions. * The class also contains static members for all of the built-in .NET colors, e.g. `Color.CornflowerBlue` and others. # Appendix 1: Screen Resolution # To keep things simple, the resolution of the game is fixed and specified at the top of the `Game` class. If you hit Alt+Enter while the game is running it will toggle between windowed and fullscreen. * When running windowed the window will be the same size as the specified resolution. * When running fullscreen the game will scale up to fit your screen and automatically letterbox if the aspect ratios do not match (so that the contents are not distorted). # Appendix 2: Resizable Textures # Most of the asset types supported should be fairly obvious, but the framework also supports something ambiguously called a "resizable texture". Sometimes also called "nine-patches" or "border textures", these are textures that are divided into nine areas (specified at load time as numerical offsets from the edges) so that they can be drawn at different sizes without distorting the edges. The following example creates a resizable texture of a button and then draws it four times with different sizes: ```C# ResizableTexture button = Engine.LoadResizableTexture("button.png", 20, 20, 20, 40); Engine.DrawResizableTexture(button, new Bounds2(10, 40, 50, 80)); Engine.DrawResizableTexture(button, new Bounds2(70, 20, 100, 60)); Engine.DrawResizableTexture(button, new Bounds2(180, 10, 70, 100)); Engine.DrawResizableTexture(button, new Bounds2(260, 30, 120, 90)); ``` ![Resizable Textures Example](Docs/resizable-textures.png)