ProjectArcade

Форк
0
8010 строк · 299.0 Кб
1

2
#region License
3
/* SDL2# - C# Wrapper for SDL2
4
 *
5
 * Copyright (c) 2013-2020 Ethan Lee.
6
 *
7
 * This software is provided 'as-is', without any express or implied warranty.
8
 * In no event will the authors be held liable for any damages arising from
9
 * the use of this software.
10
 *
11
 * Permission is granted to anyone to use this software for any purpose,
12
 * including commercial applications, and to alter it and redistribute it
13
 * freely, subject to the following restrictions:
14
 *
15
 * 1. The origin of this software must not be misrepresented; you must not
16
 * claim that you wrote the original software. If you use this software in a
17
 * product, an acknowledgment in the product documentation would be
18
 * appreciated but is not required.
19
 *
20
 * 2. Altered source versions must be plainly marked as such, and must not be
21
 * misrepresented as being the original software.
22
 *
23
 * 3. This notice may not be removed or altered from any source distribution.
24
 *
25
 * Ethan "flibitijibibo" Lee <flibitijibibo@flibitijibibo.com>
26
 *
27
 */
28
#endregion
29

30
#region Using Statements
31
using System;
32
using System.Runtime.InteropServices;
33
using System.Collections.Generic;
34
#endregion
35

36
namespace EmulatorLauncher.Common
37
{
38
    public static class SDL
39
    {
40
        #region SDL2# Variables
41

42
        private const string nativeLibName = "SDL2";
43

44
        #endregion
45

46
        #region UTF8 Marshaling
47

48
        internal static byte[] UTF8_ToNative(string s)
49
        {
50
            if (s == null)
51
            {
52
                return null;
53
            }
54

55
            // Add a null terminator. That's kind of it... :/
56
            return System.Text.Encoding.UTF8.GetBytes(s + '\0');
57
        }
58

59
        /* This is public because SDL_DropEvent needs it! */
60
        public static string UTF8_ToManaged(IntPtr s, bool freePtr = false)
61
        {
62
            string result = Marshal.PtrToStringAnsi(s);
63

64
            if (freePtr)
65
                SDL_free(s);
66

67
            return result;
68
        }
69

70
        #endregion
71

72
        #region SDL_stdinc.h
73

74
        public static uint SDL_FOURCC(byte A, byte B, byte C, byte D)
75
        {
76
            return (uint)(A | (B << 8) | (C << 16) | (D << 24));
77
        }
78

79
        public enum SDL_bool
80
        {
81
            SDL_FALSE = 0,
82
            SDL_TRUE = 1
83
        }
84

85
        /* malloc/free are used by the marshaler! -flibit */
86

87
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
88
        internal static extern IntPtr SDL_malloc(IntPtr size);
89

90
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
91
        internal static extern void SDL_free(IntPtr memblock);
92

93
        /* Buffer.BlockCopy is not available in every runtime yet. Also,
94
         * using memcpy directly can be a compatibility issue in other
95
         * strange ways. So, we expose this to get around all that.
96
         * -flibit
97
         */
98
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
99
        public static extern IntPtr SDL_memcpy(IntPtr dst, IntPtr src, IntPtr len);
100

101
        #endregion
102

103
        #region SDL_rwops.h
104

105
        public const int RW_SEEK_SET = 0;
106
        public const int RW_SEEK_CUR = 1;
107
        public const int RW_SEEK_END = 2;
108

109
        public const UInt32 SDL_RWOPS_UNKNOWN = 0; /* Unknown stream type */
110
        public const UInt32 SDL_RWOPS_WINFILE = 1; /* Win32 file */
111
        public const UInt32 SDL_RWOPS_STDFILE = 2; /* Stdio file */
112
        public const UInt32 SDL_RWOPS_JNIFILE = 3; /* Android asset */
113
        public const UInt32 SDL_RWOPS_MEMORY = 4; /* Memory stream */
114
        public const UInt32 SDL_RWOPS_MEMORY_RO = 5; /* Read-Only memory stream */
115

116
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
117
        public delegate long SDLRWopsSizeCallback(IntPtr context);
118

119
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
120
        public delegate long SDLRWopsSeekCallback(
121
            IntPtr context,
122
            long offset,
123
            int whence
124
        );
125

126
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
127
        public delegate IntPtr SDLRWopsReadCallback(
128
            IntPtr context,
129
            IntPtr ptr,
130
            IntPtr size,
131
            IntPtr maxnum
132
        );
133

134
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
135
        public delegate IntPtr SDLRWopsWriteCallback(
136
            IntPtr context,
137
            IntPtr ptr,
138
            IntPtr size,
139
            IntPtr num
140
        );
141

142
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
143
        public delegate int SDLRWopsCloseCallback(
144
            IntPtr context
145
        );
146

147
        [StructLayout(LayoutKind.Sequential)]
148
        public struct SDL_RWops
149
        {
150
            public IntPtr size;
151
            public IntPtr seek;
152
            public IntPtr read;
153
            public IntPtr write;
154
            public IntPtr close;
155

156
            public UInt32 type;
157

158
            /* NOTE: This isn't the full structure since
159
             * the native SDL_RWops contains a hidden union full of
160
             * internal information and platform-specific stuff depending
161
             * on what conditions the native library was built with
162
             */
163
        }
164

165
        /* IntPtr refers to an SDL_RWops* */
166
        [DllImport(nativeLibName, EntryPoint = "SDL_RWFromFile", CallingConvention = CallingConvention.Cdecl)]
167
        private static extern IntPtr INTERNAL_SDL_RWFromFile(
168
            byte[] file,
169
            byte[] mode
170
        );
171
        public static IntPtr SDL_RWFromFile(
172
            string file,
173
            string mode
174
        )
175
        {
176
            return INTERNAL_SDL_RWFromFile(
177
                UTF8_ToNative(file),
178
                UTF8_ToNative(mode)
179
            );
180
        }
181

182
        /* IntPtr refers to an SDL_RWops* */
183
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
184
        public static extern IntPtr SDL_AllocRW();
185

186
        /* area refers to an SDL_RWops* */
187
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
188
        public static extern void SDL_FreeRW(IntPtr area);
189

190
        /* fp refers to a void* */
191
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
192
        public static extern IntPtr SDL_RWFromFP(IntPtr fp, SDL_bool autoclose);
193

194
        /* mem refers to a void*, IntPtr to an SDL_RWops* */
195
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
196
        public static extern IntPtr SDL_RWFromMem(IntPtr mem, int size);
197

198
        /* mem refers to a const void*, IntPtr to an SDL_RWops* */
199
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
200
        public static extern IntPtr SDL_RWFromConstMem(IntPtr mem, int size);
201

202
        /* context refers to an SDL_RWops*.
203
         * Only available in SDL 2.0.10 or higher.
204
         */
205
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
206
        public static extern long SDL_RWsize(IntPtr context);
207

208
        /* context refers to an SDL_RWops*.
209
         * Only available in SDL 2.0.10 or higher.
210
         */
211
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
212
        public static extern long SDL_RWseek(
213
            IntPtr context,
214
            long offset,
215
            int whence
216
        );
217

218
        /* context refers to an SDL_RWops*.
219
         * Only available in SDL 2.0.10 or higher.
220
         */
221
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
222
        public static extern long SDL_RWtell(IntPtr context);
223

224
        /* context refers to an SDL_RWops*, ptr refers to a void*.
225
         * Only available in SDL 2.0.10 or higher.
226
         */
227
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
228
        public static extern long SDL_RWread(
229
            IntPtr context,
230
            IntPtr ptr,
231
            IntPtr size,
232
            IntPtr maxnum
233
        );
234

235
        /* context refers to an SDL_RWops*, ptr refers to a const void*.
236
         * Only available in SDL 2.0.10 or higher.
237
         */
238
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
239
        public static extern long SDL_RWwrite(
240
            IntPtr context,
241
            IntPtr ptr,
242
            IntPtr size,
243
            IntPtr maxnum
244
        );
245

246
        /* Read endian functions */
247

248
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
249
        public static extern byte SDL_ReadU8(IntPtr src);
250

251
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
252
        public static extern UInt16 SDL_ReadLE16(IntPtr src);
253

254
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
255
        public static extern UInt16 SDL_ReadBE16(IntPtr src);
256

257
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
258
        public static extern UInt32 SDL_ReadLE32(IntPtr src);
259

260
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
261
        public static extern UInt32 SDL_ReadBE32(IntPtr src);
262

263
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
264
        public static extern UInt64 SDL_ReadLE64(IntPtr src);
265

266
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
267
        public static extern UInt64 SDL_ReadBE64(IntPtr src);
268

269
        /* Write endian functions */
270

271
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
272
        public static extern uint SDL_WriteU8(IntPtr dst, byte value);
273

274
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
275
        public static extern uint SDL_WriteLE16(IntPtr dst, UInt16 value);
276

277
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
278
        public static extern uint SDL_WriteBE16(IntPtr dst, UInt16 value);
279

280
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
281
        public static extern uint SDL_WriteLE32(IntPtr dst, UInt32 value);
282

283
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
284
        public static extern uint SDL_WriteBE32(IntPtr dst, UInt32 value);
285

286
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
287
        public static extern uint SDL_WriteLE64(IntPtr dst, UInt64 value);
288

289
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
290
        public static extern uint SDL_WriteBE64(IntPtr dst, UInt64 value);
291

292
        /* context refers to an SDL_RWops*
293
         * Only available in SDL 2.0.10 or higher.
294
         */
295
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
296
        public static extern long SDL_RWclose(IntPtr context);
297

298
        /* file refers to a const char*, datasize to a size_t*
299
         * IntPtr refers to a void*
300
         * Only available in SDL 2.0.10 or higher.
301
         */
302
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
303
        public static extern IntPtr SDL_LoadFile(IntPtr file, IntPtr datasize);
304

305
        #endregion
306

307
        #region SDL_main.h
308

309
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
310
        public static extern void SDL_SetMainReady();
311

312
        /* This is used as a function pointer to a C main() function */
313
        public delegate int SDL_main_func(int argc, IntPtr argv);
314

315
        /* Use this function with UWP to call your C# Main() function! */
316
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
317
        public static extern int SDL_WinRTRunApp(
318
            SDL_main_func mainFunction,
319
            IntPtr reserved
320
        );
321

322
        /* Use this function with iOS to call your C# Main() function!
323
         * Only available in SDL 2.0.10 or higher.
324
         */
325
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
326
        public static extern int SDL_UIKitRunApp(
327
            int argc,
328
            IntPtr argv,
329
            SDL_main_func mainFunction
330
        );
331

332
        #endregion
333

334
        #region SDL.h
335

336
        public const uint SDL_INIT_TIMER = 0x00000001;
337
        public const uint SDL_INIT_AUDIO = 0x00000010;
338
        public const uint SDL_INIT_VIDEO = 0x00000020;
339
        public const uint SDL_INIT_JOYSTICK = 0x00000200;
340
        public const uint SDL_INIT_HAPTIC = 0x00001000;
341
        public const uint SDL_INIT_GAMECONTROLLER = 0x00002000;
342
        public const uint SDL_INIT_EVENTS = 0x00004000;
343
        public const uint SDL_INIT_SENSOR = 0x00008000;
344
        public const uint SDL_INIT_NOPARACHUTE = 0x00100000;
345
        public const uint SDL_INIT_EVERYTHING = (
346
            SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO |
347
            SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC |
348
            SDL_INIT_GAMECONTROLLER | SDL_INIT_SENSOR
349
        );
350

351
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
352
        public static extern int SDL_Init(uint flags);
353

354
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
355
        public static extern int SDL_InitSubSystem(uint flags);
356

357
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
358
        public static extern void SDL_Quit();
359

360
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
361
        public static extern void SDL_QuitSubSystem(uint flags);
362

363
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
364
        public static extern uint SDL_WasInit(uint flags);
365

366
        #endregion
367

368
        #region SDL_platform.h
369

370
        [DllImport(nativeLibName, EntryPoint = "SDL_GetPlatform", CallingConvention = CallingConvention.Cdecl)]
371
        private static extern IntPtr INTERNAL_SDL_GetPlatform();
372
        public static string SDL_GetPlatform()
373
        {
374
            return UTF8_ToManaged(INTERNAL_SDL_GetPlatform());
375
        }
376

377
        #endregion
378

379
        #region SDL_hints.h
380

381
        public const string SDL_HINT_FRAMEBUFFER_ACCELERATION =
382
            "SDL_FRAMEBUFFER_ACCELERATION";
383
        public const string SDL_HINT_RENDER_DRIVER =
384
            "SDL_RENDER_DRIVER";
385
        public const string SDL_HINT_RENDER_OPENGL_SHADERS =
386
            "SDL_RENDER_OPENGL_SHADERS";
387
        public const string SDL_HINT_RENDER_DIRECT3D_THREADSAFE =
388
            "SDL_RENDER_DIRECT3D_THREADSAFE";
389
        public const string SDL_HINT_RENDER_VSYNC =
390
            "SDL_RENDER_VSYNC";
391
        public const string SDL_HINT_VIDEO_X11_XVIDMODE =
392
            "SDL_VIDEO_X11_XVIDMODE";
393
        public const string SDL_HINT_VIDEO_X11_XINERAMA =
394
            "SDL_VIDEO_X11_XINERAMA";
395
        public const string SDL_HINT_VIDEO_X11_XRANDR =
396
            "SDL_VIDEO_X11_XRANDR";
397
        public const string SDL_HINT_GRAB_KEYBOARD =
398
            "SDL_GRAB_KEYBOARD";
399
        public const string SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS =
400
            "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS";
401
        public const string SDL_HINT_IDLE_TIMER_DISABLED =
402
            "SDL_IOS_IDLE_TIMER_DISABLED";
403
        public const string SDL_HINT_ORIENTATIONS =
404
            "SDL_IOS_ORIENTATIONS";
405
        public const string SDL_HINT_XINPUT_ENABLED =
406
            "SDL_XINPUT_ENABLED";
407
        public const string SDL_HINT_GAMECONTROLLERCONFIG =
408
            "SDL_GAMECONTROLLERCONFIG";
409
        public const string SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS =
410
            "SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS";
411
        public const string SDL_HINT_ALLOW_TOPMOST =
412
            "SDL_ALLOW_TOPMOST";
413
        public const string SDL_HINT_TIMER_RESOLUTION =
414
            "SDL_TIMER_RESOLUTION";
415
        public const string SDL_HINT_RENDER_SCALE_QUALITY =
416
            "SDL_RENDER_SCALE_QUALITY";
417
        public const string SDL_HINT_JOYSTICK_RAWINPUT =
418
            "SDL_HINT_JOYSTICK_RAWINPUT";
419
        
420
        /* Only available in SDL 2.0.1 or higher. */
421
        public const string SDL_HINT_VIDEO_HIGHDPI_DISABLED =
422
            "SDL_VIDEO_HIGHDPI_DISABLED";
423

424
        /* Only available in SDL 2.0.2 or higher. */
425
        public const string SDL_HINT_CTRL_CLICK_EMULATE_RIGHT_CLICK =
426
            "SDL_CTRL_CLICK_EMULATE_RIGHT_CLICK";
427
        public const string SDL_HINT_VIDEO_WIN_D3DCOMPILER =
428
            "SDL_VIDEO_WIN_D3DCOMPILER";
429
        public const string SDL_HINT_MOUSE_RELATIVE_MODE_WARP =
430
            "SDL_MOUSE_RELATIVE_MODE_WARP";
431
        public const string SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT =
432
            "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT";
433
        public const string SDL_HINT_VIDEO_ALLOW_SCREENSAVER =
434
            "SDL_VIDEO_ALLOW_SCREENSAVER";
435
        public const string SDL_HINT_ACCELEROMETER_AS_JOYSTICK =
436
            "SDL_ACCELEROMETER_AS_JOYSTICK";
437
        public const string SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES =
438
            "SDL_VIDEO_MAC_FULLSCREEN_SPACES";
439

440
        /* Only available in SDL 2.0.3 or higher. */
441
        public const string SDL_HINT_WINRT_PRIVACY_POLICY_URL =
442
            "SDL_WINRT_PRIVACY_POLICY_URL";
443
        public const string SDL_HINT_WINRT_PRIVACY_POLICY_LABEL =
444
            "SDL_WINRT_PRIVACY_POLICY_LABEL";
445
        public const string SDL_HINT_WINRT_HANDLE_BACK_BUTTON =
446
            "SDL_WINRT_HANDLE_BACK_BUTTON";
447

448
        /* Only available in SDL 2.0.4 or higher. */
449
        public const string SDL_HINT_NO_SIGNAL_HANDLERS =
450
            "SDL_NO_SIGNAL_HANDLERS";
451
        public const string SDL_HINT_IME_INTERNAL_EDITING =
452
            "SDL_IME_INTERNAL_EDITING";
453
        public const string SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH =
454
            "SDL_ANDROID_SEPARATE_MOUSE_AND_TOUCH";
455
        public const string SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT =
456
            "SDL_EMSCRIPTEN_KEYBOARD_ELEMENT";
457
        public const string SDL_HINT_THREAD_STACK_SIZE =
458
            "SDL_THREAD_STACK_SIZE";
459
        public const string SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN =
460
            "SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN";
461
        public const string SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP =
462
            "SDL_WINDOWS_ENABLE_MESSAGELOOP";
463
        public const string SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 =
464
            "SDL_WINDOWS_NO_CLOSE_ON_ALT_F4";
465
        public const string SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING =
466
            "SDL_XINPUT_USE_OLD_JOYSTICK_MAPPING";
467
        public const string SDL_HINT_MAC_BACKGROUND_APP =
468
            "SDL_MAC_BACKGROUND_APP";
469
        public const string SDL_HINT_VIDEO_X11_NET_WM_PING =
470
            "SDL_VIDEO_X11_NET_WM_PING";
471
        public const string SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION =
472
            "SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION";
473
        public const string SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION =
474
            "SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION";
475

476
        /* Only available in 2.0.5 or higher. */
477
        public const string SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH =
478
            "SDL_MOUSE_FOCUS_CLICKTHROUGH";
479
        public const string SDL_HINT_BMP_SAVE_LEGACY_FORMAT =
480
            "SDL_BMP_SAVE_LEGACY_FORMAT";
481
        public const string SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING =
482
            "SDL_WINDOWS_DISABLE_THREAD_NAMING";
483
        public const string SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION =
484
            "SDL_APPLE_TV_REMOTE_ALLOW_ROTATION";
485

486
        /* Only available in 2.0.6 or higher. */
487
        public const string SDL_HINT_AUDIO_RESAMPLING_MODE =
488
            "SDL_AUDIO_RESAMPLING_MODE";
489
        public const string SDL_HINT_RENDER_LOGICAL_SIZE_MODE =
490
            "SDL_RENDER_LOGICAL_SIZE_MODE";
491
        public const string SDL_HINT_MOUSE_NORMAL_SPEED_SCALE =
492
            "SDL_MOUSE_NORMAL_SPEED_SCALE";
493
        public const string SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE =
494
            "SDL_MOUSE_RELATIVE_SPEED_SCALE";
495
        public const string SDL_HINT_TOUCH_MOUSE_EVENTS =
496
            "SDL_TOUCH_MOUSE_EVENTS";
497
        public const string SDL_HINT_WINDOWS_INTRESOURCE_ICON =
498
            "SDL_WINDOWS_INTRESOURCE_ICON";
499
        public const string SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL =
500
            "SDL_WINDOWS_INTRESOURCE_ICON_SMALL";
501

502
        /* Only available in 2.0.8 or higher. */
503
        public const string SDL_HINT_IOS_HIDE_HOME_INDICATOR =
504
            "SDL_IOS_HIDE_HOME_INDICATOR";
505
        public const string SDL_HINT_TV_REMOTE_AS_JOYSTICK =
506
            "SDL_TV_REMOTE_AS_JOYSTICK";
507

508
        /* Only available in 2.0.9 or higher. */
509
        public const string SDL_HINT_MOUSE_DOUBLE_CLICK_TIME =
510
            "SDL_MOUSE_DOUBLE_CLICK_TIME";
511
        public const string SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS =
512
            "SDL_MOUSE_DOUBLE_CLICK_RADIUS";
513
        public const string SDL_HINT_JOYSTICK_HIDAPI =
514
            "SDL_JOYSTICK_HIDAPI";
515
        public const string SDL_HINT_JOYSTICK_HIDAPI_PS4 =
516
            "SDL_JOYSTICK_HIDAPI_PS4";
517
        public const string SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE =
518
            "SDL_JOYSTICK_HIDAPI_PS4_RUMBLE";
519
        public const string SDL_HINT_JOYSTICK_HIDAPI_STEAM =
520
            "SDL_JOYSTICK_HIDAPI_STEAM";
521
        public const string SDL_HINT_JOYSTICK_HIDAPI_SWITCH =
522
            "SDL_JOYSTICK_HIDAPI_SWITCH";
523
        public const string SDL_HINT_JOYSTICK_HIDAPI_XBOX =
524
            "SDL_JOYSTICK_HIDAPI_XBOX";
525
        public const string SDL_HINT_ENABLE_STEAM_CONTROLLERS =
526
            "SDL_ENABLE_STEAM_CONTROLLERS";
527
        public const string SDL_HINT_ANDROID_TRAP_BACK_BUTTON =
528
            "SDL_ANDROID_TRAP_BACK_BUTTON";
529
        public const string SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS =
530
           "SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS";
531

532
        /* Only available in 2.0.10 or higher. */
533
        public const string SDL_HINT_MOUSE_TOUCH_EVENTS =
534
            "SDL_MOUSE_TOUCH_EVENTS";
535
        public const string SDL_HINT_GAMECONTROLLERCONFIG_FILE =
536
            "SDL_GAMECONTROLLERCONFIG_FILE";
537
        public const string SDL_HINT_ANDROID_BLOCK_ON_PAUSE =
538
            "SDL_ANDROID_BLOCK_ON_PAUSE";
539
        public const string SDL_HINT_RENDER_BATCHING =
540
            "SDL_RENDER_BATCHING";
541
        public const string SDL_HINT_EVENT_LOGGING =
542
            "SDL_EVENT_LOGGING";
543
        public const string SDL_HINT_WAVE_RIFF_CHUNK_SIZE =
544
            "SDL_WAVE_RIFF_CHUNK_SIZE";
545
        public const string SDL_HINT_WAVE_TRUNCATION =
546
            "SDL_WAVE_TRUNCATION";
547
        public const string SDL_HINT_WAVE_FACT_CHUNK =
548
            "SDL_WAVE_FACT_CHUNK";
549

550
        /* Only available in 2.0.11 or higher. */
551
        public const string SDL_HINT_VIDO_X11_WINDOW_VISUALID =
552
            "SDL_VIDEO_X11_WINDOW_VISUALID";
553
        public const string SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS =
554
            "SDL_GAMECONTROLLER_USE_BUTTON_LABELS";
555
        public const string SDL_HINT_VIDEO_EXTERNAL_CONTEXT =
556
            "SDL_VIDEO_EXTERNAL_CONTEXT";
557
        public const string SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE =
558
            "SDL_JOYSTICK_HIDAPI_GAMECUBE";
559
        public const string SDL_HINT_DISPLAY_USABLE_BOUNDS =
560
            "SDL_DISPLAY_USABLE_BOUNDS";
561
        public const string SDL_HINT_VIDEO_X11_FORCE_EGL =
562
            "SDL_VIDEO_X11_FORCE_EGL";
563
        public const string SDL_HINT_GAMECONTROLLERTYPE =
564
            "SDL_GAMECONTROLLERTYPE";
565

566
        public enum SDL_HintPriority
567
        {
568
            SDL_HINT_DEFAULT,
569
            SDL_HINT_NORMAL,
570
            SDL_HINT_OVERRIDE
571
        }
572

573
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
574
        public static extern void SDL_ClearHints();
575

576
        [DllImport(nativeLibName, EntryPoint = "SDL_GetHint", CallingConvention = CallingConvention.Cdecl)]
577
        private static extern IntPtr INTERNAL_SDL_GetHint(byte[] name);
578
        public static string SDL_GetHint(string name)
579
        {
580
            return UTF8_ToManaged(
581
                INTERNAL_SDL_GetHint(
582
                    UTF8_ToNative(name)
583
                )
584
            );
585
        }
586

587
        [DllImport(nativeLibName, EntryPoint = "SDL_SetHint", CallingConvention = CallingConvention.Cdecl)]
588
        private static extern SDL_bool INTERNAL_SDL_SetHint(
589
            byte[] name,
590
            byte[] value
591
        );
592
        public static SDL_bool SDL_SetHint(string name, string value)
593
        {
594
            return INTERNAL_SDL_SetHint(
595
                UTF8_ToNative(name),
596
                UTF8_ToNative(value)
597
            );
598
        }
599

600
        [DllImport(nativeLibName, EntryPoint = "SDL_SetHintWithPriority", CallingConvention = CallingConvention.Cdecl)]
601
        private static extern SDL_bool INTERNAL_SDL_SetHintWithPriority(
602
            byte[] name,
603
            byte[] value,
604
            SDL_HintPriority priority
605
        );
606
        public static SDL_bool SDL_SetHintWithPriority(
607
            string name,
608
            string value,
609
            SDL_HintPriority priority
610
        )
611
        {
612
            return INTERNAL_SDL_SetHintWithPriority(
613
                UTF8_ToNative(name),
614
                UTF8_ToNative(value),
615
                priority
616
            );
617
        }
618

619
        /* Only available in 2.0.5 or higher. */
620
        [DllImport(nativeLibName, EntryPoint = "SDL_GetHintBoolean", CallingConvention = CallingConvention.Cdecl)]
621
        private static extern SDL_bool INTERNAL_SDL_GetHintBoolean(
622
            byte[] name,
623
            SDL_bool default_value
624
        );
625
        public static SDL_bool SDL_GetHintBoolean(
626
            string name,
627
            SDL_bool default_value
628
        )
629
        {
630
            return INTERNAL_SDL_GetHintBoolean(
631
                UTF8_ToNative(name),
632
                default_value
633
            );
634
        }
635

636
        #endregion
637

638
        #region SDL_error.h
639

640
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
641
        public static extern void SDL_ClearError();
642

643
        [DllImport(nativeLibName, EntryPoint = "SDL_GetError", CallingConvention = CallingConvention.Cdecl)]
644
        private static extern IntPtr INTERNAL_SDL_GetError();
645
        public static string SDL_GetError()
646
        {
647
            return UTF8_ToManaged(INTERNAL_SDL_GetError());
648
        }
649

650
        /* Use string.Format for arglists */
651
        [DllImport(nativeLibName, EntryPoint = "SDL_SetError", CallingConvention = CallingConvention.Cdecl)]
652
        private static extern void INTERNAL_SDL_SetError(byte[] fmtAndArglist);
653
        public static void SDL_SetError(string fmtAndArglist)
654
        {
655
            INTERNAL_SDL_SetError(
656
                UTF8_ToNative(fmtAndArglist)
657
            );
658
        }
659

660
        #endregion
661

662
        #region SDL_log.h
663

664
        public enum SDL_LogCategory
665
        {
666
            SDL_LOG_CATEGORY_APPLICATION,
667
            SDL_LOG_CATEGORY_ERROR,
668
            SDL_LOG_CATEGORY_ASSERT,
669
            SDL_LOG_CATEGORY_SYSTEM,
670
            SDL_LOG_CATEGORY_AUDIO,
671
            SDL_LOG_CATEGORY_VIDEO,
672
            SDL_LOG_CATEGORY_RENDER,
673
            SDL_LOG_CATEGORY_INPUT,
674
            SDL_LOG_CATEGORY_TEST,
675

676
            /* Reserved for future SDL library use */
677
            SDL_LOG_CATEGORY_RESERVED1,
678
            SDL_LOG_CATEGORY_RESERVED2,
679
            SDL_LOG_CATEGORY_RESERVED3,
680
            SDL_LOG_CATEGORY_RESERVED4,
681
            SDL_LOG_CATEGORY_RESERVED5,
682
            SDL_LOG_CATEGORY_RESERVED6,
683
            SDL_LOG_CATEGORY_RESERVED7,
684
            SDL_LOG_CATEGORY_RESERVED8,
685
            SDL_LOG_CATEGORY_RESERVED9,
686
            SDL_LOG_CATEGORY_RESERVED10,
687

688
            /* Beyond this point is reserved for application use, e.g.
689
            enum {
690
                MYAPP_CATEGORY_AWESOME1 = SDL_LOG_CATEGORY_CUSTOM,
691
                MYAPP_CATEGORY_AWESOME2,
692
                MYAPP_CATEGORY_AWESOME3,
693
                ...
694
            };
695
            */
696
            SDL_LOG_CATEGORY_CUSTOM
697
        }
698

699
        public enum SDL_LogPriority
700
        {
701
            SDL_LOG_PRIORITY_VERBOSE = 1,
702
            SDL_LOG_PRIORITY_DEBUG,
703
            SDL_LOG_PRIORITY_INFO,
704
            SDL_LOG_PRIORITY_WARN,
705
            SDL_LOG_PRIORITY_ERROR,
706
            SDL_LOG_PRIORITY_CRITICAL,
707
            SDL_NUM_LOG_PRIORITIES
708
        }
709

710
        /* userdata refers to a void*, message to a const char* */
711
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
712
        public delegate void SDL_LogOutputFunction(
713
            IntPtr userdata,
714
            int category,
715
            SDL_LogPriority priority,
716
            IntPtr message
717
        );
718

719
        /* Use string.Format for arglists */
720
        [DllImport(nativeLibName, EntryPoint = "SDL_Log", CallingConvention = CallingConvention.Cdecl)]
721
        private static extern void INTERNAL_SDL_Log(byte[] fmtAndArglist);
722
        public static void SDL_Log(string fmtAndArglist)
723
        {
724
            INTERNAL_SDL_Log(
725
                UTF8_ToNative(fmtAndArglist)
726
            );
727
        }
728

729
        /* Use string.Format for arglists */
730
        [DllImport(nativeLibName, EntryPoint = "SDL_LogVerbose", CallingConvention = CallingConvention.Cdecl)]
731
        private static extern void INTERNAL_SDL_LogVerbose(
732
            int category,
733
            byte[] fmtAndArglist
734
        );
735
        public static void SDL_LogVerbose(
736
            int category,
737
            string fmtAndArglist
738
        )
739
        {
740
            INTERNAL_SDL_LogVerbose(
741
                category,
742
                UTF8_ToNative(fmtAndArglist)
743
            );
744
        }
745

746
        /* Use string.Format for arglists */
747
        [DllImport(nativeLibName, EntryPoint = "SDL_LogDebug", CallingConvention = CallingConvention.Cdecl)]
748
        private static extern void INTERNAL_SDL_LogDebug(
749
            int category,
750
            byte[] fmtAndArglist
751
        );
752
        public static void SDL_LogDebug(
753
            int category,
754
            string fmtAndArglist
755
        )
756
        {
757
            INTERNAL_SDL_LogDebug(
758
                category,
759
                UTF8_ToNative(fmtAndArglist)
760
            );
761
        }
762

763
        /* Use string.Format for arglists */
764
        [DllImport(nativeLibName, EntryPoint = "SDL_LogInfo", CallingConvention = CallingConvention.Cdecl)]
765
        private static extern void INTERNAL_SDL_LogInfo(
766
            int category,
767
            byte[] fmtAndArglist
768
        );
769
        public static void SDL_LogInfo(
770
            int category,
771
            string fmtAndArglist
772
        )
773
        {
774
            INTERNAL_SDL_LogInfo(
775
                category,
776
                UTF8_ToNative(fmtAndArglist)
777
            );
778
        }
779

780
        /* Use string.Format for arglists */
781
        [DllImport(nativeLibName, EntryPoint = "SDL_LogWarn", CallingConvention = CallingConvention.Cdecl)]
782
        private static extern void INTERNAL_SDL_LogWarn(
783
            int category,
784
            byte[] fmtAndArglist
785
        );
786
        public static void SDL_LogWarn(
787
            int category,
788
            string fmtAndArglist
789
        )
790
        {
791
            INTERNAL_SDL_LogWarn(
792
                category,
793
                UTF8_ToNative(fmtAndArglist)
794
            );
795
        }
796

797
        /* Use string.Format for arglists */
798
        [DllImport(nativeLibName, EntryPoint = "SDL_LogError", CallingConvention = CallingConvention.Cdecl)]
799
        private static extern void INTERNAL_SDL_LogError(
800
            int category,
801
            byte[] fmtAndArglist
802
        );
803
        public static void SDL_LogError(
804
            int category,
805
            string fmtAndArglist
806
        )
807
        {
808
            INTERNAL_SDL_LogError(
809
                category,
810
                UTF8_ToNative(fmtAndArglist)
811
            );
812
        }
813

814
        /* Use string.Format for arglists */
815
        [DllImport(nativeLibName, EntryPoint = "SDL_LogCritical", CallingConvention = CallingConvention.Cdecl)]
816
        private static extern void INTERNAL_SDL_LogCritical(
817
            int category,
818
            byte[] fmtAndArglist
819
        );
820
        public static void SDL_LogCritical(
821
            int category,
822
            string fmtAndArglist
823
        )
824
        {
825
            INTERNAL_SDL_LogCritical(
826
                category,
827
                UTF8_ToNative(fmtAndArglist)
828
            );
829
        }
830

831
        /* Use string.Format for arglists */
832
        [DllImport(nativeLibName, EntryPoint = "SDL_LogMessage", CallingConvention = CallingConvention.Cdecl)]
833
        private static extern void INTERNAL_SDL_LogMessage(
834
            int category,
835
            SDL_LogPriority priority,
836
            byte[] fmtAndArglist
837
        );
838
        public static void SDL_LogMessage(
839
            int category,
840
            SDL_LogPriority priority,
841
            string fmtAndArglist
842
        )
843
        {
844
            INTERNAL_SDL_LogMessage(
845
                category,
846
                priority,
847
                UTF8_ToNative(fmtAndArglist)
848
            );
849
        }
850

851
        /* Use string.Format for arglists */
852
        [DllImport(nativeLibName, EntryPoint = "SDL_LogMessageV", CallingConvention = CallingConvention.Cdecl)]
853
        private static extern void INTERNAL_SDL_LogMessageV(
854
            int category,
855
            SDL_LogPriority priority,
856
            byte[] fmtAndArglist
857
        );
858
        public static void SDL_LogMessageV(
859
            int category,
860
            SDL_LogPriority priority,
861
            string fmtAndArglist
862
        )
863
        {
864
            INTERNAL_SDL_LogMessageV(
865
                category,
866
                priority,
867
                UTF8_ToNative(fmtAndArglist)
868
            );
869
        }
870

871
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
872
        public static extern SDL_LogPriority SDL_LogGetPriority(
873
            int category
874
        );
875

876
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
877
        public static extern void SDL_LogSetPriority(
878
            int category,
879
            SDL_LogPriority priority
880
        );
881

882
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
883
        public static extern void SDL_LogSetAllPriority(
884
            SDL_LogPriority priority
885
        );
886

887
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
888
        public static extern void SDL_LogResetPriorities();
889

890
        /* userdata refers to a void* */
891
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
892
        private static extern void SDL_LogGetOutputFunction(
893
            out IntPtr callback,
894
            out IntPtr userdata
895
        );
896
        public static void SDL_LogGetOutputFunction(
897
            out SDL_LogOutputFunction callback,
898
            out IntPtr userdata
899
        )
900
        {
901
            IntPtr result = IntPtr.Zero;
902
            SDL_LogGetOutputFunction(
903
                out result,
904
                out userdata
905
            );
906
            if (result != IntPtr.Zero)
907
            {
908
                callback = (SDL_LogOutputFunction)Marshal.GetDelegateForFunctionPointer(
909
                    result,
910
                    typeof(SDL_LogOutputFunction)
911
                );
912
            }
913
            else
914
            {
915
                callback = null;
916
            }
917
        }
918

919
        /* userdata refers to a void* */
920
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
921
        public static extern void SDL_LogSetOutputFunction(
922
            SDL_LogOutputFunction callback,
923
            IntPtr userdata
924
        );
925

926
        #endregion
927

928
        #region SDL_messagebox.h
929

930
        [Flags]
931
        public enum SDL_MessageBoxFlags : uint
932
        {
933
            SDL_MESSAGEBOX_ERROR = 0x00000010,
934
            SDL_MESSAGEBOX_WARNING = 0x00000020,
935
            SDL_MESSAGEBOX_INFORMATION = 0x00000040
936
        }
937

938
        [Flags]
939
        public enum SDL_MessageBoxButtonFlags : uint
940
        {
941
            SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001,
942
            SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002
943
        }
944

945
        [StructLayout(LayoutKind.Sequential)]
946
        private struct INTERNAL_SDL_MessageBoxButtonData
947
        {
948
            public SDL_MessageBoxButtonFlags flags;
949
            public int buttonid;
950
            public IntPtr text; /* The UTF-8 button text */
951
        }
952

953
        [StructLayout(LayoutKind.Sequential)]
954
        public struct SDL_MessageBoxButtonData
955
        {
956
            public SDL_MessageBoxButtonFlags flags;
957
            public int buttonid;
958
            public string text; /* The UTF-8 button text */
959
        }
960

961
        [StructLayout(LayoutKind.Sequential)]
962
        public struct SDL_MessageBoxColor
963
        {
964
            public byte r, g, b;
965
        }
966

967
        public enum SDL_MessageBoxColorType
968
        {
969
            SDL_MESSAGEBOX_COLOR_BACKGROUND,
970
            SDL_MESSAGEBOX_COLOR_TEXT,
971
            SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,
972
            SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND,
973
            SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED,
974
            SDL_MESSAGEBOX_COLOR_MAX
975
        }
976

977
        [StructLayout(LayoutKind.Sequential)]
978
        public struct SDL_MessageBoxColorScheme
979
        {
980
            [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = (int)SDL_MessageBoxColorType.SDL_MESSAGEBOX_COLOR_MAX)]
981
            public SDL_MessageBoxColor[] colors;
982
        }
983

984
        [StructLayout(LayoutKind.Sequential)]
985
        private struct INTERNAL_SDL_MessageBoxData
986
        {
987
            public SDL_MessageBoxFlags flags;
988
            public IntPtr window;				/* Parent window, can be NULL */
989
            public IntPtr title;				/* UTF-8 title */
990
            public IntPtr message;				/* UTF-8 message text */
991
            public int numbuttons;
992
            public IntPtr buttons;
993
            public IntPtr colorScheme;			/* Can be NULL to use system settings */
994
        }
995

996
        [StructLayout(LayoutKind.Sequential)]
997
        public struct SDL_MessageBoxData
998
        {
999
            public SDL_MessageBoxFlags flags;
1000
            public IntPtr window;				/* Parent window, can be NULL */
1001
            public string title;				/* UTF-8 title */
1002
            public string message;				/* UTF-8 message text */
1003
            public int numbuttons;
1004
            public SDL_MessageBoxButtonData[] buttons;
1005
            public SDL_MessageBoxColorScheme? colorScheme;	/* Can be NULL to use system settings */
1006
        }
1007

1008
        [DllImport(nativeLibName, EntryPoint = "SDL_ShowMessageBox", CallingConvention = CallingConvention.Cdecl)]
1009
        private static extern int INTERNAL_SDL_ShowMessageBox([In()] ref INTERNAL_SDL_MessageBoxData messageboxdata, out int buttonid);
1010

1011
        /* Ripped from Jameson's LpUtf8StrMarshaler */
1012
        private static IntPtr INTERNAL_AllocUTF8(string str)
1013
        {
1014
            if (string.IsNullOrEmpty(str))
1015
            {
1016
                return IntPtr.Zero;
1017
            }
1018
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str + '\0');
1019
            IntPtr mem = SDL.SDL_malloc((IntPtr)bytes.Length);
1020
            Marshal.Copy(bytes, 0, mem, bytes.Length);
1021
            return mem;
1022
        }
1023
        /*
1024
        public static unsafe int SDL_ShowMessageBox([In()] ref SDL_MessageBoxData messageboxdata, out int buttonid)
1025
        {
1026
            var data = new INTERNAL_SDL_MessageBoxData()
1027
            {
1028
                flags = messageboxdata.flags,
1029
                window = messageboxdata.window,
1030
                title = INTERNAL_AllocUTF8(messageboxdata.title),
1031
                message = INTERNAL_AllocUTF8(messageboxdata.message),
1032
                numbuttons = messageboxdata.numbuttons,
1033
            };
1034

1035
            var buttons = new INTERNAL_SDL_MessageBoxButtonData[messageboxdata.numbuttons];
1036
            for (int i = 0; i < messageboxdata.numbuttons; i++)
1037
            {
1038
                buttons[i] = new INTERNAL_SDL_MessageBoxButtonData()
1039
                {
1040
                    flags = messageboxdata.buttons[i].flags,
1041
                    buttonid = messageboxdata.buttons[i].buttonid,
1042
                    text = INTERNAL_AllocUTF8(messageboxdata.buttons[i].text),
1043
                };
1044
            }
1045

1046
            if (messageboxdata.colorScheme != null)
1047
            {
1048
                data.colorScheme = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SDL_MessageBoxColorScheme)));
1049
                Marshal.StructureToPtr(messageboxdata.colorScheme.Value, data.colorScheme, false);
1050
            }
1051

1052
            int result;
1053
            fixed (INTERNAL_SDL_MessageBoxButtonData* buttonsPtr = &buttons[0])
1054
            {
1055
                data.buttons = (IntPtr)buttonsPtr;
1056
                result = INTERNAL_SDL_ShowMessageBox(ref data, out buttonid);
1057
            }
1058

1059
            Marshal.FreeHGlobal(data.colorScheme);
1060
            for (int i = 0; i < messageboxdata.numbuttons; i++)
1061
            {
1062
                SDL_free(buttons[i].text);
1063
            }
1064
            SDL_free(data.message);
1065
            SDL_free(data.title);
1066

1067
            return result;
1068
        }
1069
        */
1070
        /* window refers to an SDL_Window* */
1071
        [DllImport(nativeLibName, EntryPoint = "SDL_ShowSimpleMessageBox", CallingConvention = CallingConvention.Cdecl)]
1072
        private static extern int INTERNAL_SDL_ShowSimpleMessageBox(
1073
            SDL_MessageBoxFlags flags,
1074
            byte[] title,
1075
            byte[] message,
1076
            IntPtr window
1077
        );
1078
        public static int SDL_ShowSimpleMessageBox(
1079
            SDL_MessageBoxFlags flags,
1080
            string title,
1081
            string message,
1082
            IntPtr window
1083
        )
1084
        {
1085
            return INTERNAL_SDL_ShowSimpleMessageBox(
1086
                flags,
1087
                UTF8_ToNative(title),
1088
                UTF8_ToNative(message),
1089
                window
1090
            );
1091
        }
1092

1093
        #endregion
1094

1095
        #region SDL_version.h, SDL_revision.h
1096

1097
        /* Similar to the headers, this is the version we're expecting to be
1098
		 * running with. You will likely want to check this somewhere in your
1099
		 * program!
1100
		 */
1101
        public const int SDL_MAJOR_VERSION = 2;
1102
        public const int SDL_MINOR_VERSION = 0;
1103
        public const int SDL_PATCHLEVEL = 12;
1104

1105
        public static readonly int SDL_COMPILEDVERSION = SDL_VERSIONNUM(
1106
            SDL_MAJOR_VERSION,
1107
            SDL_MINOR_VERSION,
1108
            SDL_PATCHLEVEL
1109
        );
1110

1111
        [StructLayout(LayoutKind.Sequential)]
1112
        public struct SDL_version
1113
        {
1114
            public byte major;
1115
            public byte minor;
1116
            public byte patch;
1117
        }
1118

1119
        public static void SDL_VERSION(out SDL_version x)
1120
        {
1121
            x.major = SDL_MAJOR_VERSION;
1122
            x.minor = SDL_MINOR_VERSION;
1123
            x.patch = SDL_PATCHLEVEL;
1124
        }
1125

1126
        public static int SDL_VERSIONNUM(int X, int Y, int Z)
1127
        {
1128
            return (X * 1000) + (Y * 100) + Z;
1129
        }
1130

1131
        public static bool SDL_VERSION_ATLEAST(int X, int Y, int Z)
1132
        {
1133
            return (SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z));
1134
        }
1135

1136
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1137
        public static extern void SDL_GetVersion(out SDL_version ver);
1138

1139
        static Version _version;
1140

1141
        public static Version Version
1142
        {
1143
            get
1144
            {
1145
                if (_version == null)
1146
                {
1147
                    SDL.SDL_version ver;
1148
                    SDL.SDL_GetVersion(out ver);
1149
                    _version = new Version(ver.major, ver.minor, ver.patch, 0);
1150
                }
1151

1152
                return _version;
1153
            }
1154
        }
1155

1156
        [DllImport(nativeLibName, EntryPoint = "SDL_GetRevision", CallingConvention = CallingConvention.Cdecl)]
1157
        private static extern IntPtr INTERNAL_SDL_GetRevision();
1158
        public static string SDL_GetRevision()
1159
        {
1160
            return UTF8_ToManaged(INTERNAL_SDL_GetRevision());
1161
        }
1162

1163
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1164
        public static extern int SDL_GetRevisionNumber();
1165

1166
        #endregion
1167

1168
        #region SDL_video.h
1169

1170
        public enum SDL_GLattr
1171
        {
1172
            SDL_GL_RED_SIZE,
1173
            SDL_GL_GREEN_SIZE,
1174
            SDL_GL_BLUE_SIZE,
1175
            SDL_GL_ALPHA_SIZE,
1176
            SDL_GL_BUFFER_SIZE,
1177
            SDL_GL_DOUBLEBUFFER,
1178
            SDL_GL_DEPTH_SIZE,
1179
            SDL_GL_STENCIL_SIZE,
1180
            SDL_GL_ACCUM_RED_SIZE,
1181
            SDL_GL_ACCUM_GREEN_SIZE,
1182
            SDL_GL_ACCUM_BLUE_SIZE,
1183
            SDL_GL_ACCUM_ALPHA_SIZE,
1184
            SDL_GL_STEREO,
1185
            SDL_GL_MULTISAMPLEBUFFERS,
1186
            SDL_GL_MULTISAMPLESAMPLES,
1187
            SDL_GL_ACCELERATED_VISUAL,
1188
            SDL_GL_RETAINED_BACKING,
1189
            SDL_GL_CONTEXT_MAJOR_VERSION,
1190
            SDL_GL_CONTEXT_MINOR_VERSION,
1191
            SDL_GL_CONTEXT_EGL,
1192
            SDL_GL_CONTEXT_FLAGS,
1193
            SDL_GL_CONTEXT_PROFILE_MASK,
1194
            SDL_GL_SHARE_WITH_CURRENT_CONTEXT,
1195
            SDL_GL_FRAMEBUFFER_SRGB_CAPABLE,
1196
            SDL_GL_CONTEXT_RELEASE_BEHAVIOR,
1197
            SDL_GL_CONTEXT_RESET_NOTIFICATION,	/* Requires >= 2.0.6 */
1198
            SDL_GL_CONTEXT_NO_ERROR,		/* Requires >= 2.0.6 */
1199
        }
1200

1201
        [Flags]
1202
        public enum SDL_GLprofile
1203
        {
1204
            SDL_GL_CONTEXT_PROFILE_CORE = 0x0001,
1205
            SDL_GL_CONTEXT_PROFILE_COMPATIBILITY = 0x0002,
1206
            SDL_GL_CONTEXT_PROFILE_ES = 0x0004
1207
        }
1208

1209
        [Flags]
1210
        public enum SDL_GLcontext
1211
        {
1212
            SDL_GL_CONTEXT_DEBUG_FLAG = 0x0001,
1213
            SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG = 0x0002,
1214
            SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG = 0x0004,
1215
            SDL_GL_CONTEXT_RESET_ISOLATION_FLAG = 0x0008
1216
        }
1217

1218
        public enum SDL_WindowEventID : byte
1219
        {
1220
            SDL_WINDOWEVENT_NONE,
1221
            SDL_WINDOWEVENT_SHOWN,
1222
            SDL_WINDOWEVENT_HIDDEN,
1223
            SDL_WINDOWEVENT_EXPOSED,
1224
            SDL_WINDOWEVENT_MOVED,
1225
            SDL_WINDOWEVENT_RESIZED,
1226
            SDL_WINDOWEVENT_SIZE_CHANGED,
1227
            SDL_WINDOWEVENT_MINIMIZED,
1228
            SDL_WINDOWEVENT_MAXIMIZED,
1229
            SDL_WINDOWEVENT_RESTORED,
1230
            SDL_WINDOWEVENT_ENTER,
1231
            SDL_WINDOWEVENT_LEAVE,
1232
            SDL_WINDOWEVENT_FOCUS_GAINED,
1233
            SDL_WINDOWEVENT_FOCUS_LOST,
1234
            SDL_WINDOWEVENT_CLOSE,
1235
            /* Only available in 2.0.5 or higher. */
1236
            SDL_WINDOWEVENT_TAKE_FOCUS,
1237
            SDL_WINDOWEVENT_HIT_TEST
1238
        }
1239

1240
        public enum SDL_DisplayEventID : byte
1241
        {
1242
            SDL_DISPLAYEVENT_NONE,
1243
            SDL_DISPLAYEVENT_ORIENTATION
1244
        }
1245

1246
        public enum SDL_DisplayOrientation
1247
        {
1248
            SDL_ORIENTATION_UNKNOWN,
1249
            SDL_ORIENTATION_LANDSCAPE,
1250
            SDL_ORIENTATION_LANDSCAPE_FLIPPED,
1251
            SDL_ORIENTATION_PORTRAIT,
1252
            SDL_ORIENTATION_PORTRAIT_FLIPPED
1253
        }
1254

1255
        [Flags]
1256
        public enum SDL_WindowFlags : uint
1257
        {
1258
            SDL_WINDOW_FULLSCREEN = 0x00000001,
1259
            SDL_WINDOW_OPENGL = 0x00000002,
1260
            SDL_WINDOW_SHOWN = 0x00000004,
1261
            SDL_WINDOW_HIDDEN = 0x00000008,
1262
            SDL_WINDOW_BORDERLESS = 0x00000010,
1263
            SDL_WINDOW_RESIZABLE = 0x00000020,
1264
            SDL_WINDOW_MINIMIZED = 0x00000040,
1265
            SDL_WINDOW_MAXIMIZED = 0x00000080,
1266
            SDL_WINDOW_INPUT_GRABBED = 0x00000100,
1267
            SDL_WINDOW_INPUT_FOCUS = 0x00000200,
1268
            SDL_WINDOW_MOUSE_FOCUS = 0x00000400,
1269
            SDL_WINDOW_FULLSCREEN_DESKTOP =
1270
                (SDL_WINDOW_FULLSCREEN | 0x00001000),
1271
            SDL_WINDOW_FOREIGN = 0x00000800,
1272
            SDL_WINDOW_ALLOW_HIGHDPI = 0x00002000,	/* Requires >= 2.0.1 */
1273
            SDL_WINDOW_MOUSE_CAPTURE = 0x00004000,	/* Requires >= 2.0.4 */
1274
            SDL_WINDOW_ALWAYS_ON_TOP = 0x00008000,	/* Requires >= 2.0.5 */
1275
            SDL_WINDOW_SKIP_TASKBAR = 0x00010000,	/* Requires >= 2.0.5 */
1276
            SDL_WINDOW_UTILITY = 0x00020000,	/* Requires >= 2.0.5 */
1277
            SDL_WINDOW_TOOLTIP = 0x00040000,	/* Requires >= 2.0.5 */
1278
            SDL_WINDOW_POPUP_MENU = 0x00080000,	/* Requires >= 2.0.5 */
1279
            SDL_WINDOW_VULKAN = 0x10000000,	/* Requires >= 2.0.6 */
1280
        }
1281

1282
        /* Only available in 2.0.4 or higher. */
1283
        public enum SDL_HitTestResult
1284
        {
1285
            SDL_HITTEST_NORMAL,		/* Region is normal. No special properties. */
1286
            SDL_HITTEST_DRAGGABLE,		/* Region can drag entire window. */
1287
            SDL_HITTEST_RESIZE_TOPLEFT,
1288
            SDL_HITTEST_RESIZE_TOP,
1289
            SDL_HITTEST_RESIZE_TOPRIGHT,
1290
            SDL_HITTEST_RESIZE_RIGHT,
1291
            SDL_HITTEST_RESIZE_BOTTOMRIGHT,
1292
            SDL_HITTEST_RESIZE_BOTTOM,
1293
            SDL_HITTEST_RESIZE_BOTTOMLEFT,
1294
            SDL_HITTEST_RESIZE_LEFT
1295
        }
1296

1297
        public const int SDL_WINDOWPOS_UNDEFINED_MASK = 0x1FFF0000;
1298
        public const int SDL_WINDOWPOS_CENTERED_MASK = 0x2FFF0000;
1299
        public const int SDL_WINDOWPOS_UNDEFINED = 0x1FFF0000;
1300
        public const int SDL_WINDOWPOS_CENTERED = 0x2FFF0000;
1301

1302
        public static int SDL_WINDOWPOS_UNDEFINED_DISPLAY(int X)
1303
        {
1304
            return (SDL_WINDOWPOS_UNDEFINED_MASK | X);
1305
        }
1306

1307
        public static bool SDL_WINDOWPOS_ISUNDEFINED(int X)
1308
        {
1309
            return (X & 0xFFFF0000) == SDL_WINDOWPOS_UNDEFINED_MASK;
1310
        }
1311

1312
        public static int SDL_WINDOWPOS_CENTERED_DISPLAY(int X)
1313
        {
1314
            return (SDL_WINDOWPOS_CENTERED_MASK | X);
1315
        }
1316

1317
        public static bool SDL_WINDOWPOS_ISCENTERED(int X)
1318
        {
1319
            return (X & 0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK;
1320
        }
1321

1322
        [StructLayout(LayoutKind.Sequential)]
1323
        public struct SDL_DisplayMode
1324
        {
1325
            public uint format;
1326
            public int w;
1327
            public int h;
1328
            public int refresh_rate;
1329
            public IntPtr driverdata; // void*
1330
        }
1331

1332
        /* win refers to an SDL_Window*, area to a const SDL_Point*, data to a void*.
1333
         * Only available in 2.0.4 or higher.
1334
         */
1335
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
1336
        public delegate SDL_HitTestResult SDL_HitTest(IntPtr win, IntPtr area, IntPtr data);
1337

1338
        /* IntPtr refers to an SDL_Window* */
1339
        [DllImport(nativeLibName, EntryPoint = "SDL_CreateWindow", CallingConvention = CallingConvention.Cdecl)]
1340
        private static extern IntPtr INTERNAL_SDL_CreateWindow(
1341
            byte[] title,
1342
            int x,
1343
            int y,
1344
            int w,
1345
            int h,
1346
            SDL_WindowFlags flags
1347
        );
1348
        public static IntPtr SDL_CreateWindow(
1349
            string title,
1350
            int x,
1351
            int y,
1352
            int w,
1353
            int h,
1354
            SDL_WindowFlags flags
1355
        )
1356
        {
1357
            return INTERNAL_SDL_CreateWindow(
1358
                UTF8_ToNative(title),
1359
                x, y, w, h,
1360
                flags
1361
            );
1362
        }
1363

1364
        /* window refers to an SDL_Window*, renderer to an SDL_Renderer* */
1365
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1366
        public static extern int SDL_CreateWindowAndRenderer(
1367
            int width,
1368
            int height,
1369
            SDL_WindowFlags window_flags,
1370
            out IntPtr window,
1371
            out IntPtr renderer
1372
        );
1373

1374
        /* data refers to some native window type, IntPtr to an SDL_Window* */
1375
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1376
        public static extern IntPtr SDL_CreateWindowFrom(IntPtr data);
1377

1378
        /* window refers to an SDL_Window* */
1379
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1380
        public static extern void SDL_DestroyWindow(IntPtr window);
1381

1382
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1383
        public static extern void SDL_DisableScreenSaver();
1384

1385
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1386
        public static extern void SDL_EnableScreenSaver();
1387

1388
        /* IntPtr refers to an SDL_DisplayMode. Just use closest. */
1389
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1390
        public static extern IntPtr SDL_GetClosestDisplayMode(
1391
            int displayIndex,
1392
            ref SDL_DisplayMode mode,
1393
            out SDL_DisplayMode closest
1394
        );
1395

1396
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1397
        public static extern int SDL_GetCurrentDisplayMode(
1398
            int displayIndex,
1399
            out SDL_DisplayMode mode
1400
        );
1401

1402
        [DllImport(nativeLibName, EntryPoint = "SDL_GetCurrentVideoDriver", CallingConvention = CallingConvention.Cdecl)]
1403
        private static extern IntPtr INTERNAL_SDL_GetCurrentVideoDriver();
1404
        public static string SDL_GetCurrentVideoDriver()
1405
        {
1406
            return UTF8_ToManaged(INTERNAL_SDL_GetCurrentVideoDriver());
1407
        }
1408

1409
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1410
        public static extern int SDL_GetDesktopDisplayMode(
1411
            int displayIndex,
1412
            out SDL_DisplayMode mode
1413
        );
1414

1415
        [DllImport(nativeLibName, EntryPoint = "SDL_GetDisplayName", CallingConvention = CallingConvention.Cdecl)]
1416
        private static extern IntPtr INTERNAL_SDL_GetDisplayName(int index);
1417
        public static string SDL_GetDisplayName(int index)
1418
        {
1419
            return UTF8_ToManaged(INTERNAL_SDL_GetDisplayName(index));
1420
        }
1421

1422
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1423
        public static extern int SDL_GetDisplayBounds(
1424
            int displayIndex,
1425
            out SDL_Rect rect
1426
        );
1427

1428
        /* Only available in 2.0.4 or higher. */
1429
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1430
        public static extern int SDL_GetDisplayDPI(
1431
            int displayIndex,
1432
            out float ddpi,
1433
            out float hdpi,
1434
            out float vdpi
1435
        );
1436

1437
        /* Only available in 2.0.9 or higher. */
1438
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1439
        public static extern SDL_DisplayOrientation SDL_GetDisplayOrientation(
1440
            int displayIndex
1441
        );
1442

1443
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1444
        public static extern int SDL_GetDisplayMode(
1445
            int displayIndex,
1446
            int modeIndex,
1447
            out SDL_DisplayMode mode
1448
        );
1449

1450
        /* Only available in 2.0.5 or higher. */
1451
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1452
        public static extern int SDL_GetDisplayUsableBounds(
1453
            int displayIndex,
1454
            out SDL_Rect rect
1455
        );
1456

1457
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1458
        public static extern int SDL_GetNumDisplayModes(
1459
            int displayIndex
1460
        );
1461

1462
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1463
        public static extern int SDL_GetNumVideoDisplays();
1464

1465
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1466
        public static extern int SDL_GetNumVideoDrivers();
1467

1468
        [DllImport(nativeLibName, EntryPoint = "SDL_GetVideoDriver", CallingConvention = CallingConvention.Cdecl)]
1469
        private static extern IntPtr INTERNAL_SDL_GetVideoDriver(
1470
            int index
1471
        );
1472
        public static string SDL_GetVideoDriver(int index)
1473
        {
1474
            return UTF8_ToManaged(INTERNAL_SDL_GetVideoDriver(index));
1475
        }
1476

1477
        /* window refers to an SDL_Window* */
1478
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1479
        public static extern float SDL_GetWindowBrightness(
1480
            IntPtr window
1481
        );
1482

1483
        /* window refers to an SDL_Window*
1484
         * Only available in 2.0.5 or higher.
1485
         */
1486
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1487
        public static extern int SDL_SetWindowOpacity(
1488
            IntPtr window,
1489
            float opacity
1490
        );
1491

1492
        /* window refers to an SDL_Window*
1493
         * Only available in 2.0.5 or higher.
1494
         */
1495
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1496
        public static extern int SDL_GetWindowOpacity(
1497
            IntPtr window,
1498
            out float out_opacity
1499
        );
1500

1501
        /* modal_window and parent_window refer to an SDL_Window*s
1502
         * Only available in 2.0.5 or higher.
1503
         */
1504
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1505
        public static extern int SDL_SetWindowModalFor(
1506
            IntPtr modal_window,
1507
            IntPtr parent_window
1508
        );
1509

1510
        /* window refers to an SDL_Window*
1511
         * Only available in 2.0.5 or higher.
1512
         */
1513
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1514
        public static extern int SDL_SetWindowInputFocus(IntPtr window);
1515

1516
        /* window refers to an SDL_Window*, IntPtr to a void* */
1517
        [DllImport(nativeLibName, EntryPoint = "SDL_GetWindowData", CallingConvention = CallingConvention.Cdecl)]
1518
        private static extern IntPtr INTERNAL_SDL_GetWindowData(
1519
            IntPtr window,
1520
            byte[] name
1521
        );
1522
        public static IntPtr SDL_GetWindowData(
1523
            IntPtr window,
1524
            string name
1525
        )
1526
        {
1527
            return INTERNAL_SDL_GetWindowData(
1528
                window,
1529
                UTF8_ToNative(name)
1530
            );
1531
        }
1532

1533
        /* window refers to an SDL_Window* */
1534
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1535
        public static extern int SDL_GetWindowDisplayIndex(
1536
            IntPtr window
1537
        );
1538

1539
        /* window refers to an SDL_Window* */
1540
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1541
        public static extern int SDL_GetWindowDisplayMode(
1542
            IntPtr window,
1543
            out SDL_DisplayMode mode
1544
        );
1545

1546
        /* window refers to an SDL_Window* */
1547
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1548
        public static extern uint SDL_GetWindowFlags(IntPtr window);
1549

1550
        /* IntPtr refers to an SDL_Window* */
1551
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1552
        public static extern IntPtr SDL_GetWindowFromID(uint id);
1553

1554
        /* window refers to an SDL_Window* */
1555
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1556
        public static extern int SDL_GetWindowGammaRamp(
1557
            IntPtr window,
1558
            [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)]
1559
				ushort[] red,
1560
            [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)]
1561
				ushort[] green,
1562
            [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)]
1563
				ushort[] blue
1564
        );
1565

1566
        /* window refers to an SDL_Window* */
1567
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1568
        public static extern SDL_bool SDL_GetWindowGrab(IntPtr window);
1569

1570
        /* window refers to an SDL_Window* */
1571
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1572
        public static extern uint SDL_GetWindowID(IntPtr window);
1573

1574
        /* window refers to an SDL_Window* */
1575
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1576
        public static extern uint SDL_GetWindowPixelFormat(
1577
            IntPtr window
1578
        );
1579

1580
        /* window refers to an SDL_Window* */
1581
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1582
        public static extern void SDL_GetWindowMaximumSize(
1583
            IntPtr window,
1584
            out int max_w,
1585
            out int max_h
1586
        );
1587

1588
        /* window refers to an SDL_Window* */
1589
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1590
        public static extern void SDL_GetWindowMinimumSize(
1591
            IntPtr window,
1592
            out int min_w,
1593
            out int min_h
1594
        );
1595

1596
        /* window refers to an SDL_Window* */
1597
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1598
        public static extern void SDL_GetWindowPosition(
1599
            IntPtr window,
1600
            out int x,
1601
            out int y
1602
        );
1603

1604
        /* window refers to an SDL_Window* */
1605
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1606
        public static extern void SDL_GetWindowSize(
1607
            IntPtr window,
1608
            out int w,
1609
            out int h
1610
        );
1611

1612
        /* IntPtr refers to an SDL_Surface*, window to an SDL_Window* */
1613
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1614
        public static extern IntPtr SDL_GetWindowSurface(IntPtr window);
1615

1616
        /* window refers to an SDL_Window* */
1617
        [DllImport(nativeLibName, EntryPoint = "SDL_GetWindowTitle", CallingConvention = CallingConvention.Cdecl)]
1618
        private static extern IntPtr INTERNAL_SDL_GetWindowTitle(
1619
            IntPtr window
1620
        );
1621
        public static string SDL_GetWindowTitle(IntPtr window)
1622
        {
1623
            return UTF8_ToManaged(
1624
                INTERNAL_SDL_GetWindowTitle(window)
1625
            );
1626
        }
1627

1628
        /* texture refers to an SDL_Texture* */
1629
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1630
        public static extern int SDL_GL_BindTexture(
1631
            IntPtr texture,
1632
            out float texw,
1633
            out float texh
1634
        );
1635

1636
        /* IntPtr and window refer to an SDL_GLContext and SDL_Window* */
1637
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1638
        public static extern IntPtr SDL_GL_CreateContext(IntPtr window);
1639

1640
        /* context refers to an SDL_GLContext */
1641
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1642
        public static extern void SDL_GL_DeleteContext(IntPtr context);
1643

1644
        /* IntPtr refers to a function pointer */
1645
        [DllImport(nativeLibName, EntryPoint = "SDL_GL_GetProcAddress", CallingConvention = CallingConvention.Cdecl)]
1646
        private static extern IntPtr INTERNAL_SDL_GL_GetProcAddress(
1647
            byte[] proc
1648
        );
1649
        public static IntPtr SDL_GL_GetProcAddress(string proc)
1650
        {
1651
            return INTERNAL_SDL_GL_GetProcAddress(
1652
                UTF8_ToNative(proc)
1653
            );
1654
        }
1655

1656
        [DllImport(nativeLibName, EntryPoint = "SDL_GL_LoadLibrary", CallingConvention = CallingConvention.Cdecl)]
1657
        private static extern int INTERNAL_SDL_GL_LoadLibrary(byte[] path);
1658
        public static int SDL_GL_LoadLibrary(string path)
1659
        {
1660
            return INTERNAL_SDL_GL_LoadLibrary(
1661
                UTF8_ToNative(path)
1662
            );
1663
        }
1664

1665
        /* IntPtr refers to a function pointer, proc to a const char* */
1666
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1667
        public static extern IntPtr SDL_GL_GetProcAddress(IntPtr proc);
1668

1669
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1670
        public static extern void SDL_GL_UnloadLibrary();
1671

1672
        [DllImport(nativeLibName, EntryPoint = "SDL_GL_ExtensionSupported", CallingConvention = CallingConvention.Cdecl)]
1673
        private static extern SDL_bool INTERNAL_SDL_GL_ExtensionSupported(
1674
            byte[] extension
1675
        );
1676
        public static SDL_bool SDL_GL_ExtensionSupported(string extension)
1677
        {
1678
            return INTERNAL_SDL_GL_ExtensionSupported(
1679
                UTF8_ToNative(extension)
1680
            );
1681
        }
1682

1683
        /* Only available in SDL 2.0.2 or higher. */
1684
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1685
        public static extern void SDL_GL_ResetAttributes();
1686

1687
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1688
        public static extern int SDL_GL_GetAttribute(
1689
            SDL_GLattr attr,
1690
            out int value
1691
        );
1692

1693
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1694
        public static extern int SDL_GL_GetSwapInterval();
1695

1696
        /* window and context refer to an SDL_Window* and SDL_GLContext */
1697
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1698
        public static extern int SDL_GL_MakeCurrent(
1699
            IntPtr window,
1700
            IntPtr context
1701
        );
1702

1703
        /* IntPtr refers to an SDL_Window* */
1704
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1705
        public static extern IntPtr SDL_GL_GetCurrentWindow();
1706

1707
        /* IntPtr refers to an SDL_Context */
1708
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1709
        public static extern IntPtr SDL_GL_GetCurrentContext();
1710

1711
        /* window refers to an SDL_Window*.
1712
         * Only available in SDL 2.0.1 or higher.
1713
         */
1714
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1715
        public static extern void SDL_GL_GetDrawableSize(
1716
            IntPtr window,
1717
            out int w,
1718
            out int h
1719
        );
1720

1721
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1722
        public static extern int SDL_GL_SetAttribute(
1723
            SDL_GLattr attr,
1724
            int value
1725
        );
1726

1727
        public static int SDL_GL_SetAttribute(
1728
            SDL_GLattr attr,
1729
            SDL_GLprofile profile
1730
        )
1731
        {
1732
            return SDL_GL_SetAttribute(attr, (int)profile);
1733
        }
1734

1735
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1736
        public static extern int SDL_GL_SetSwapInterval(int interval);
1737

1738
        /* window refers to an SDL_Window* */
1739
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1740
        public static extern void SDL_GL_SwapWindow(IntPtr window);
1741

1742
        /* texture refers to an SDL_Texture* */
1743
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1744
        public static extern int SDL_GL_UnbindTexture(IntPtr texture);
1745

1746
        /* window refers to an SDL_Window* */
1747
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1748
        public static extern void SDL_HideWindow(IntPtr window);
1749

1750
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1751
        public static extern SDL_bool SDL_IsScreenSaverEnabled();
1752

1753
        /* window refers to an SDL_Window* */
1754
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1755
        public static extern void SDL_MaximizeWindow(IntPtr window);
1756

1757
        /* window refers to an SDL_Window* */
1758
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1759
        public static extern void SDL_MinimizeWindow(IntPtr window);
1760

1761
        /* window refers to an SDL_Window* */
1762
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1763
        public static extern void SDL_RaiseWindow(IntPtr window);
1764

1765
        /* window refers to an SDL_Window* */
1766
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1767
        public static extern void SDL_RestoreWindow(IntPtr window);
1768

1769
        /* window refers to an SDL_Window* */
1770
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1771
        public static extern int SDL_SetWindowBrightness(
1772
            IntPtr window,
1773
            float brightness
1774
        );
1775

1776
        /* IntPtr and userdata are void*, window is an SDL_Window* */
1777
        [DllImport(nativeLibName, EntryPoint = "SDL_SetWindowData", CallingConvention = CallingConvention.Cdecl)]
1778
        private static extern IntPtr INTERNAL_SDL_SetWindowData(
1779
            IntPtr window,
1780
            byte[] name,
1781
            IntPtr userdata
1782
        );
1783
        public static IntPtr SDL_SetWindowData(
1784
            IntPtr window,
1785
            string name,
1786
            IntPtr userdata
1787
        )
1788
        {
1789
            return INTERNAL_SDL_SetWindowData(
1790
                window,
1791
                UTF8_ToNative(name),
1792
                userdata
1793
            );
1794
        }
1795

1796
        /* window refers to an SDL_Window* */
1797
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1798
        public static extern int SDL_SetWindowDisplayMode(
1799
            IntPtr window,
1800
            ref SDL_DisplayMode mode
1801
        );
1802

1803
        /* window refers to an SDL_Window* */
1804
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1805
        public static extern int SDL_SetWindowFullscreen(
1806
            IntPtr window,
1807
            uint flags
1808
        );
1809

1810
        /* window refers to an SDL_Window* */
1811
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1812
        public static extern int SDL_SetWindowGammaRamp(
1813
            IntPtr window,
1814
            [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)]
1815
				ushort[] red,
1816
            [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)]
1817
				ushort[] green,
1818
            [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)]
1819
				ushort[] blue
1820
        );
1821

1822
        /* window refers to an SDL_Window* */
1823
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1824
        public static extern void SDL_SetWindowGrab(
1825
            IntPtr window,
1826
            SDL_bool grabbed
1827
        );
1828

1829
        /* window refers to an SDL_Window*, icon to an SDL_Surface* */
1830
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1831
        public static extern void SDL_SetWindowIcon(
1832
            IntPtr window,
1833
            IntPtr icon
1834
        );
1835

1836
        /* window refers to an SDL_Window* */
1837
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1838
        public static extern void SDL_SetWindowMaximumSize(
1839
            IntPtr window,
1840
            int max_w,
1841
            int max_h
1842
        );
1843

1844
        /* window refers to an SDL_Window* */
1845
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1846
        public static extern void SDL_SetWindowMinimumSize(
1847
            IntPtr window,
1848
            int min_w,
1849
            int min_h
1850
        );
1851

1852
        /* window refers to an SDL_Window* */
1853
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1854
        public static extern void SDL_SetWindowPosition(
1855
            IntPtr window,
1856
            int x,
1857
            int y
1858
        );
1859

1860
        /* window refers to an SDL_Window* */
1861
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1862
        public static extern void SDL_SetWindowSize(
1863
            IntPtr window,
1864
            int w,
1865
            int h
1866
        );
1867

1868
        /* window refers to an SDL_Window* */
1869
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1870
        public static extern void SDL_SetWindowBordered(
1871
            IntPtr window,
1872
            SDL_bool bordered
1873
        );
1874

1875
        /* window refers to an SDL_Window* */
1876
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1877
        public static extern int SDL_GetWindowBordersSize(
1878
            IntPtr window,
1879
            out int top,
1880
            out int left,
1881
            out int bottom,
1882
            out int right
1883
        );
1884

1885
        /* window refers to an SDL_Window*
1886
         * Only available in 2.0.5 or higher.
1887
         */
1888
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1889
        public static extern void SDL_SetWindowResizable(
1890
            IntPtr window,
1891
            SDL_bool resizable
1892
        );
1893

1894
        /* window refers to an SDL_Window* */
1895
        [DllImport(nativeLibName, EntryPoint = "SDL_SetWindowTitle", CallingConvention = CallingConvention.Cdecl)]
1896
        private static extern void INTERNAL_SDL_SetWindowTitle(
1897
            IntPtr window,
1898
            byte[] title
1899
        );
1900
        public static void SDL_SetWindowTitle(
1901
            IntPtr window,
1902
            string title
1903
        )
1904
        {
1905
            INTERNAL_SDL_SetWindowTitle(
1906
                window,
1907
                UTF8_ToNative(title)
1908
            );
1909
        }
1910

1911
        /* window refers to an SDL_Window* */
1912
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1913
        public static extern void SDL_ShowWindow(IntPtr window);
1914

1915
        /* window refers to an SDL_Window* */
1916
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1917
        public static extern int SDL_UpdateWindowSurface(IntPtr window);
1918

1919
        /* window refers to an SDL_Window* */
1920
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1921
        public static extern int SDL_UpdateWindowSurfaceRects(
1922
            IntPtr window,
1923
            [In] SDL_Rect[] rects,
1924
            int numrects
1925
        );
1926

1927
        [DllImport(nativeLibName, EntryPoint = "SDL_VideoInit", CallingConvention = CallingConvention.Cdecl)]
1928
        private static extern int INTERNAL_SDL_VideoInit(
1929
            byte[] driver_name
1930
        );
1931
        public static int SDL_VideoInit(string driver_name)
1932
        {
1933
            return INTERNAL_SDL_VideoInit(
1934
                UTF8_ToNative(driver_name)
1935
            );
1936
        }
1937

1938
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1939
        public static extern void SDL_VideoQuit();
1940

1941
        /* window refers to an SDL_Window*, callback_data to a void*
1942
         * Only available in 2.0.4 or higher.
1943
         */
1944
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1945
        public static extern int SDL_SetWindowHitTest(
1946
            IntPtr window,
1947
            SDL_HitTest callback,
1948
            IntPtr callback_data
1949
        );
1950

1951
        /* IntPtr refers to an SDL_Window*
1952
         * Only available in 2.0.4 or higher.
1953
         */
1954
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1955
        public static extern IntPtr SDL_GetGrabbedWindow();
1956

1957
        #endregion
1958

1959
        #region SDL_blendmode.h
1960

1961
        [Flags]
1962
        public enum SDL_BlendMode
1963
        {
1964
            SDL_BLENDMODE_NONE = 0x00000000,
1965
            SDL_BLENDMODE_BLEND = 0x00000001,
1966
            SDL_BLENDMODE_ADD = 0x00000002,
1967
            SDL_BLENDMODE_MOD = 0x00000004,
1968
            SDL_BLENDMODE_MUL = 0x00000008,	/* >= 2.0.11 */
1969
            SDL_BLENDMODE_INVALID = 0x7FFFFFFF
1970
        }
1971

1972
        public enum SDL_BlendOperation
1973
        {
1974
            SDL_BLENDOPERATION_ADD = 0x1,
1975
            SDL_BLENDOPERATION_SUBTRACT = 0x2,
1976
            SDL_BLENDOPERATION_REV_SUBTRACT = 0x3,
1977
            SDL_BLENDOPERATION_MINIMUM = 0x4,
1978
            SDL_BLENDOPERATION_MAXIMUM = 0x5
1979
        }
1980

1981
        public enum SDL_BlendFactor
1982
        {
1983
            SDL_BLENDFACTOR_ZERO = 0x1,
1984
            SDL_BLENDFACTOR_ONE = 0x2,
1985
            SDL_BLENDFACTOR_SRC_COLOR = 0x3,
1986
            SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR = 0x4,
1987
            SDL_BLENDFACTOR_SRC_ALPHA = 0x5,
1988
            SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA = 0x6,
1989
            SDL_BLENDFACTOR_DST_COLOR = 0x7,
1990
            SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR = 0x8,
1991
            SDL_BLENDFACTOR_DST_ALPHA = 0x9,
1992
            SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA = 0xA
1993
        }
1994

1995
        /* Only available in 2.0.6 or higher. */
1996
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
1997
        public static extern SDL_BlendMode SDL_ComposeCustomBlendMode(
1998
            SDL_BlendFactor srcColorFactor,
1999
            SDL_BlendFactor dstColorFactor,
2000
            SDL_BlendOperation colorOperation,
2001
            SDL_BlendFactor srcAlphaFactor,
2002
            SDL_BlendFactor dstAlphaFactor,
2003
            SDL_BlendOperation alphaOperation
2004
        );
2005

2006
        #endregion
2007

2008
        #region SDL_vulkan.h
2009

2010
        /* Only available in 2.0.6 or higher. */
2011
        [DllImport(nativeLibName, EntryPoint = "SDL_Vulkan_LoadLibrary", CallingConvention = CallingConvention.Cdecl)]
2012
        private static extern int INTERNAL_SDL_Vulkan_LoadLibrary(
2013
            byte[] path
2014
        );
2015
        public static int SDL_Vulkan_LoadLibrary(string path)
2016
        {
2017
            return INTERNAL_SDL_Vulkan_LoadLibrary(
2018
                UTF8_ToNative(path)
2019
            );
2020
        }
2021

2022
        /* Only available in 2.0.6 or higher. */
2023
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2024
        public static extern IntPtr SDL_Vulkan_GetVkGetInstanceProcAddr();
2025

2026
        /* Only available in 2.0.6 or higher. */
2027
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2028
        public static extern void SDL_Vulkan_UnloadLibrary();
2029

2030
        /* window refers to an SDL_Window*, pNames to a const char**.
2031
         * Only available in 2.0.6 or higher.
2032
         */
2033
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2034
        public static extern SDL_bool SDL_Vulkan_GetInstanceExtensions(
2035
            IntPtr window,
2036
            out uint pCount,
2037
            IntPtr[] pNames
2038
        );
2039

2040
        /* window refers to an SDL_Window.
2041
         * instance refers to a VkInstance.
2042
         * surface refers to a VkSurfaceKHR.
2043
         * Only available in 2.0.6 or higher.
2044
         */
2045
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2046
        public static extern SDL_bool SDL_Vulkan_CreateSurface(
2047
            IntPtr window,
2048
            IntPtr instance,
2049
            out ulong surface
2050
        );
2051

2052
        /* window refers to an SDL_Window*.
2053
         * Only available in 2.0.6 or higher.
2054
         */
2055
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2056
        public static extern void SDL_Vulkan_GetDrawableSize(
2057
            IntPtr window,
2058
            out int w,
2059
            out int h
2060
        );
2061

2062
        #endregion
2063

2064
        #region SDL_metal.h
2065

2066
        /* Only available in 2.0.11 or higher. */
2067
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2068
        public static extern IntPtr SDL_Metal_CreateView(
2069
            IntPtr window
2070
        );
2071

2072
        /* Only available in 2.0.11 or higher. */
2073
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2074
        public static extern void SDL_Metal_DestroyView(
2075
            IntPtr view
2076
        );
2077

2078
        #endregion
2079

2080
        #region SDL_render.h
2081

2082
        [Flags]
2083
        public enum SDL_RendererFlags : uint
2084
        {
2085
            SDL_RENDERER_SOFTWARE = 0x00000001,
2086
            SDL_RENDERER_ACCELERATED = 0x00000002,
2087
            SDL_RENDERER_PRESENTVSYNC = 0x00000004,
2088
            SDL_RENDERER_TARGETTEXTURE = 0x00000008
2089
        }
2090

2091
        [Flags]
2092
        public enum SDL_RendererFlip
2093
        {
2094
            SDL_FLIP_NONE = 0x00000000,
2095
            SDL_FLIP_HORIZONTAL = 0x00000001,
2096
            SDL_FLIP_VERTICAL = 0x00000002
2097
        }
2098

2099
        public enum SDL_TextureAccess
2100
        {
2101
            SDL_TEXTUREACCESS_STATIC,
2102
            SDL_TEXTUREACCESS_STREAMING,
2103
            SDL_TEXTUREACCESS_TARGET
2104
        }
2105

2106
        [Flags]
2107
        public enum SDL_TextureModulate
2108
        {
2109
            SDL_TEXTUREMODULATE_NONE = 0x00000000,
2110
            SDL_TEXTUREMODULATE_HORIZONTAL = 0x00000001,
2111
            SDL_TEXTUREMODULATE_VERTICAL = 0x00000002
2112
        }
2113

2114
        [StructLayout(LayoutKind.Sequential)]
2115
        public struct SDL_RendererInfo
2116
        {
2117
            public IntPtr name; // const char*
2118
            public uint flags;
2119
            public uint num_texture_formats;
2120
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
2121
            public uint[] texture_formats;
2122
            public int max_texture_width;
2123
            public int max_texture_height;
2124
        }
2125

2126
        /* Only available in 2.0.11 or higher. */
2127
        public enum SDL_ScaleMode
2128
        {
2129
            SDL_ScaleModeNearest,
2130
            SDL_ScaleModeLinear,
2131
            SDL_ScaleModeBest
2132
        }
2133

2134
        /* IntPtr refers to an SDL_Renderer*, window to an SDL_Window* */
2135
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2136
        public static extern IntPtr SDL_CreateRenderer(
2137
            IntPtr window,
2138
            int index,
2139
            SDL_RendererFlags flags
2140
        );
2141

2142
        /* IntPtr refers to an SDL_Renderer*, surface to an SDL_Surface* */
2143
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2144
        public static extern IntPtr SDL_CreateSoftwareRenderer(IntPtr surface);
2145

2146
        /* IntPtr refers to an SDL_Texture*, renderer to an SDL_Renderer* */
2147
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2148
        public static extern IntPtr SDL_CreateTexture(
2149
            IntPtr renderer,
2150
            uint format,
2151
            int access,
2152
            int w,
2153
            int h
2154
        );
2155

2156
        /* IntPtr refers to an SDL_Texture*
2157
         * renderer refers to an SDL_Renderer*
2158
         * surface refers to an SDL_Surface*
2159
         */
2160
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2161
        public static extern IntPtr SDL_CreateTextureFromSurface(
2162
            IntPtr renderer,
2163
            IntPtr surface
2164
        );
2165

2166
        /* renderer refers to an SDL_Renderer* */
2167
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2168
        public static extern void SDL_DestroyRenderer(IntPtr renderer);
2169

2170
        /* texture refers to an SDL_Texture* */
2171
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2172
        public static extern void SDL_DestroyTexture(IntPtr texture);
2173

2174
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2175
        public static extern int SDL_GetNumRenderDrivers();
2176

2177
        /* renderer refers to an SDL_Renderer* */
2178
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2179
        public static extern int SDL_GetRenderDrawBlendMode(
2180
            IntPtr renderer,
2181
            out SDL_BlendMode blendMode
2182
        );
2183

2184
        /* texture refers to an SDL_Texture*
2185
         * Only available in 2.0.11 or higher.
2186
         */
2187
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2188
        public static extern int SDL_SetTextureScaleMode(
2189
            IntPtr texture,
2190
            SDL_ScaleMode scaleMode
2191
        );
2192

2193
        /* texture refers to an SDL_Texture*
2194
         * Only available in 2.0.11 or higher.
2195
         */
2196
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2197
        public static extern int SDL_GetTextureScaleMode(
2198
            IntPtr texture,
2199
            out SDL_ScaleMode scaleMode
2200
        );
2201

2202
        /* renderer refers to an SDL_Renderer* */
2203
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2204
        public static extern int SDL_GetRenderDrawColor(
2205
            IntPtr renderer,
2206
            out byte r,
2207
            out byte g,
2208
            out byte b,
2209
            out byte a
2210
        );
2211

2212
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2213
        public static extern int SDL_GetRenderDriverInfo(
2214
            int index,
2215
            out SDL_RendererInfo info
2216
        );
2217

2218
        /* IntPtr refers to an SDL_Renderer*, window to an SDL_Window* */
2219
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2220
        public static extern IntPtr SDL_GetRenderer(IntPtr window);
2221

2222
        /* renderer refers to an SDL_Renderer* */
2223
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2224
        public static extern int SDL_GetRendererInfo(
2225
            IntPtr renderer,
2226
            out SDL_RendererInfo info
2227
        );
2228

2229
        /* renderer refers to an SDL_Renderer* */
2230
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2231
        public static extern int SDL_GetRendererOutputSize(
2232
            IntPtr renderer,
2233
            out int w,
2234
            out int h
2235
        );
2236

2237
        /* texture refers to an SDL_Texture* */
2238
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2239
        public static extern int SDL_GetTextureAlphaMod(
2240
            IntPtr texture,
2241
            out byte alpha
2242
        );
2243

2244
        /* texture refers to an SDL_Texture* */
2245
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2246
        public static extern int SDL_GetTextureBlendMode(
2247
            IntPtr texture,
2248
            out SDL_BlendMode blendMode
2249
        );
2250

2251
        /* texture refers to an SDL_Texture* */
2252
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2253
        public static extern int SDL_GetTextureColorMod(
2254
            IntPtr texture,
2255
            out byte r,
2256
            out byte g,
2257
            out byte b
2258
        );
2259

2260
        /* texture refers to an SDL_Texture*, pixels to a void* */
2261
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2262
        public static extern int SDL_LockTexture(
2263
            IntPtr texture,
2264
            ref SDL_Rect rect,
2265
            out IntPtr pixels,
2266
            out int pitch
2267
        );
2268

2269
        /* texture refers to an SDL_Texture*, pixels to a void*.
2270
         * Internally, this function contains logic to use default values when
2271
         * the rectangle is passed as NULL.
2272
         * This overload allows for IntPtr.Zero to be passed for rect.
2273
         */
2274
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2275
        public static extern int SDL_LockTexture(
2276
            IntPtr texture,
2277
            IntPtr rect,
2278
            out IntPtr pixels,
2279
            out int pitch
2280
        );
2281

2282
        /* texture refers to an SDL_Texture*, surface to an SDL_Surface*
2283
         * Only available in 2.0.11 or higher.
2284
         */
2285
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2286
        public static extern int SDL_LockTextureToSurface(
2287
            IntPtr texture,
2288
            ref SDL_Rect rect,
2289
            out IntPtr surface
2290
        );
2291

2292
        /* texture refers to an SDL_Texture*, surface to an SDL_Surface*
2293
         * Internally, this function contains logic to use default values when
2294
         * the rectangle is passed as NULL.
2295
         * This overload allows for IntPtr.Zero to be passed for rect.
2296
         * Only available in 2.0.11 or higher.
2297
         */
2298
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2299
        public static extern int SDL_LockTextureToSurface(
2300
            IntPtr texture,
2301
            IntPtr rect,
2302
            out IntPtr surface
2303
        );
2304

2305
        /* texture refers to an SDL_Texture* */
2306
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2307
        public static extern int SDL_QueryTexture(
2308
            IntPtr texture,
2309
            out uint format,
2310
            out int access,
2311
            out int w,
2312
            out int h
2313
        );
2314

2315
        /* renderer refers to an SDL_Renderer* */
2316
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2317
        public static extern int SDL_RenderClear(IntPtr renderer);
2318

2319
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture* */
2320
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2321
        public static extern int SDL_RenderCopy(
2322
            IntPtr renderer,
2323
            IntPtr texture,
2324
            ref SDL_Rect srcrect,
2325
            ref SDL_Rect dstrect
2326
        );
2327

2328
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2329
         * Internally, this function contains logic to use default values when
2330
         * source and destination rectangles are passed as NULL.
2331
         * This overload allows for IntPtr.Zero (null) to be passed for srcrect.
2332
         */
2333
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2334
        public static extern int SDL_RenderCopy(
2335
            IntPtr renderer,
2336
            IntPtr texture,
2337
            IntPtr srcrect,
2338
            ref SDL_Rect dstrect
2339
        );
2340

2341
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2342
         * Internally, this function contains logic to use default values when
2343
         * source and destination rectangles are passed as NULL.
2344
         * This overload allows for IntPtr.Zero (null) to be passed for dstrect.
2345
         */
2346
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2347
        public static extern int SDL_RenderCopy(
2348
            IntPtr renderer,
2349
            IntPtr texture,
2350
            ref SDL_Rect srcrect,
2351
            IntPtr dstrect
2352
        );
2353

2354
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2355
         * Internally, this function contains logic to use default values when
2356
         * source and destination rectangles are passed as NULL.
2357
         * This overload allows for IntPtr.Zero (null) to be passed for both SDL_Rects.
2358
         */
2359
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2360
        public static extern int SDL_RenderCopy(
2361
            IntPtr renderer,
2362
            IntPtr texture,
2363
            IntPtr srcrect,
2364
            IntPtr dstrect
2365
        );
2366

2367
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture* */
2368
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2369
        public static extern int SDL_RenderCopyEx(
2370
            IntPtr renderer,
2371
            IntPtr texture,
2372
            ref SDL_Rect srcrect,
2373
            ref SDL_Rect dstrect,
2374
            double angle,
2375
            ref SDL_Point center,
2376
            SDL_RendererFlip flip
2377
        );
2378

2379
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2380
         * Internally, this function contains logic to use default values when
2381
         * source, destination, and/or center are passed as NULL.
2382
         * This overload allows for IntPtr.Zero (null) to be passed for srcrect.
2383
         */
2384
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2385
        public static extern int SDL_RenderCopyEx(
2386
            IntPtr renderer,
2387
            IntPtr texture,
2388
            IntPtr srcrect,
2389
            ref SDL_Rect dstrect,
2390
            double angle,
2391
            ref SDL_Point center,
2392
            SDL_RendererFlip flip
2393
        );
2394

2395
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2396
         * Internally, this function contains logic to use default values when
2397
         * source, destination, and/or center are passed as NULL.
2398
         * This overload allows for IntPtr.Zero (null) to be passed for dstrect.
2399
         */
2400
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2401
        public static extern int SDL_RenderCopyEx(
2402
            IntPtr renderer,
2403
            IntPtr texture,
2404
            ref SDL_Rect srcrect,
2405
            IntPtr dstrect,
2406
            double angle,
2407
            ref SDL_Point center,
2408
            SDL_RendererFlip flip
2409
        );
2410

2411
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2412
         * Internally, this function contains logic to use default values when
2413
         * source, destination, and/or center are passed as NULL.
2414
         * This overload allows for IntPtr.Zero (null) to be passed for center.
2415
         */
2416
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2417
        public static extern int SDL_RenderCopyEx(
2418
            IntPtr renderer,
2419
            IntPtr texture,
2420
            ref SDL_Rect srcrect,
2421
            ref SDL_Rect dstrect,
2422
            double angle,
2423
            IntPtr center,
2424
            SDL_RendererFlip flip
2425
        );
2426

2427
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2428
         * Internally, this function contains logic to use default values when
2429
         * source, destination, and/or center are passed as NULL.
2430
         * This overload allows for IntPtr.Zero (null) to be passed for both
2431
         * srcrect and dstrect.
2432
         */
2433
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2434
        public static extern int SDL_RenderCopyEx(
2435
            IntPtr renderer,
2436
            IntPtr texture,
2437
            IntPtr srcrect,
2438
            IntPtr dstrect,
2439
            double angle,
2440
            ref SDL_Point center,
2441
            SDL_RendererFlip flip
2442
        );
2443

2444
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2445
         * Internally, this function contains logic to use default values when
2446
         * source, destination, and/or center are passed as NULL.
2447
         * This overload allows for IntPtr.Zero (null) to be passed for both
2448
         * srcrect and center.
2449
         */
2450
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2451
        public static extern int SDL_RenderCopyEx(
2452
            IntPtr renderer,
2453
            IntPtr texture,
2454
            IntPtr srcrect,
2455
            ref SDL_Rect dstrect,
2456
            double angle,
2457
            IntPtr center,
2458
            SDL_RendererFlip flip
2459
        );
2460

2461
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2462
         * Internally, this function contains logic to use default values when
2463
         * source, destination, and/or center are passed as NULL.
2464
         * This overload allows for IntPtr.Zero (null) to be passed for both
2465
         * dstrect and center.
2466
         */
2467
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2468
        public static extern int SDL_RenderCopyEx(
2469
            IntPtr renderer,
2470
            IntPtr texture,
2471
            ref SDL_Rect srcrect,
2472
            IntPtr dstrect,
2473
            double angle,
2474
            IntPtr center,
2475
            SDL_RendererFlip flip
2476
        );
2477

2478
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2479
         * Internally, this function contains logic to use default values when
2480
         * source, destination, and/or center are passed as NULL.
2481
         * This overload allows for IntPtr.Zero (null) to be passed for all
2482
         * three parameters.
2483
         */
2484
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2485
        public static extern int SDL_RenderCopyEx(
2486
            IntPtr renderer,
2487
            IntPtr texture,
2488
            IntPtr srcrect,
2489
            IntPtr dstrect,
2490
            double angle,
2491
            IntPtr center,
2492
            SDL_RendererFlip flip
2493
        );
2494

2495
        /* renderer refers to an SDL_Renderer* */
2496
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2497
        public static extern int SDL_RenderDrawLine(
2498
            IntPtr renderer,
2499
            int x1,
2500
            int y1,
2501
            int x2,
2502
            int y2
2503
        );
2504

2505
        /* renderer refers to an SDL_Renderer* */
2506
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2507
        public static extern int SDL_RenderDrawLines(
2508
            IntPtr renderer,
2509
            [In] SDL_Point[] points,
2510
            int count
2511
        );
2512

2513
        /* renderer refers to an SDL_Renderer* */
2514
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2515
        public static extern int SDL_RenderDrawPoint(
2516
            IntPtr renderer,
2517
            int x,
2518
            int y
2519
        );
2520

2521
        /* renderer refers to an SDL_Renderer* */
2522
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2523
        public static extern int SDL_RenderDrawPoints(
2524
            IntPtr renderer,
2525
            [In] SDL_Point[] points,
2526
            int count
2527
        );
2528

2529
        /* renderer refers to an SDL_Renderer* */
2530
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2531
        public static extern int SDL_RenderDrawRect(
2532
            IntPtr renderer,
2533
            ref SDL_Rect rect
2534
        );
2535

2536
        /* renderer refers to an SDL_Renderer*, rect to an SDL_Rect*.
2537
         * This overload allows for IntPtr.Zero (null) to be passed for rect.
2538
         */
2539
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2540
        public static extern int SDL_RenderDrawRect(
2541
            IntPtr renderer,
2542
            IntPtr rect
2543
        );
2544

2545
        /* renderer refers to an SDL_Renderer* */
2546
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2547
        public static extern int SDL_RenderDrawRects(
2548
            IntPtr renderer,
2549
            [In] SDL_Rect[] rects,
2550
            int count
2551
        );
2552

2553
        /* renderer refers to an SDL_Renderer* */
2554
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2555
        public static extern int SDL_RenderFillRect(
2556
            IntPtr renderer,
2557
            ref SDL_Rect rect
2558
        );
2559

2560
        /* renderer refers to an SDL_Renderer*, rect to an SDL_Rect*.
2561
         * This overload allows for IntPtr.Zero (null) to be passed for rect.
2562
         */
2563
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2564
        public static extern int SDL_RenderFillRect(
2565
            IntPtr renderer,
2566
            IntPtr rect
2567
        );
2568

2569
        /* renderer refers to an SDL_Renderer* */
2570
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2571
        public static extern int SDL_RenderFillRects(
2572
            IntPtr renderer,
2573
            [In] SDL_Rect[] rects,
2574
            int count
2575
        );
2576

2577
        #region Floating Point Render Functions
2578

2579
        /* This region only available in SDL 2.0.10 or higher. */
2580

2581
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture* */
2582
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2583
        public static extern int SDL_RenderCopyF(
2584
            IntPtr renderer,
2585
            IntPtr texture,
2586
            ref SDL_Rect srcrect,
2587
            ref SDL_FRect dstrect
2588
        );
2589

2590
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2591
         * Internally, this function contains logic to use default values when
2592
         * source and destination rectangles are passed as NULL.
2593
         * This overload allows for IntPtr.Zero (null) to be passed for srcrect.
2594
         */
2595
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2596
        public static extern int SDL_RenderCopyF(
2597
            IntPtr renderer,
2598
            IntPtr texture,
2599
            IntPtr srcrect,
2600
            ref SDL_FRect dstrect
2601
        );
2602

2603
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2604
         * Internally, this function contains logic to use default values when
2605
         * source and destination rectangles are passed as NULL.
2606
         * This overload allows for IntPtr.Zero (null) to be passed for dstrect.
2607
         */
2608
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2609
        public static extern int SDL_RenderCopyF(
2610
            IntPtr renderer,
2611
            IntPtr texture,
2612
            ref SDL_Rect srcrect,
2613
            IntPtr dstrect
2614
        );
2615

2616
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2617
         * Internally, this function contains logic to use default values when
2618
         * source and destination rectangles are passed as NULL.
2619
         * This overload allows for IntPtr.Zero (null) to be passed for both SDL_Rects.
2620
         */
2621
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2622
        public static extern int SDL_RenderCopyF(
2623
            IntPtr renderer,
2624
            IntPtr texture,
2625
            IntPtr srcrect,
2626
            IntPtr dstrect
2627
        );
2628

2629
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture* */
2630
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2631
        public static extern int SDL_RenderCopyEx(
2632
            IntPtr renderer,
2633
            IntPtr texture,
2634
            ref SDL_Rect srcrect,
2635
            ref SDL_FRect dstrect,
2636
            double angle,
2637
            ref SDL_FPoint center,
2638
            SDL_RendererFlip flip
2639
        );
2640

2641
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2642
         * Internally, this function contains logic to use default values when
2643
         * source, destination, and/or center are passed as NULL.
2644
         * This overload allows for IntPtr.Zero (null) to be passed for srcrect.
2645
         */
2646
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2647
        public static extern int SDL_RenderCopyEx(
2648
            IntPtr renderer,
2649
            IntPtr texture,
2650
            IntPtr srcrect,
2651
            ref SDL_FRect dstrect,
2652
            double angle,
2653
            ref SDL_FPoint center,
2654
            SDL_RendererFlip flip
2655
        );
2656

2657
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2658
         * Internally, this function contains logic to use default values when
2659
         * source, destination, and/or center are passed as NULL.
2660
         * This overload allows for IntPtr.Zero (null) to be passed for dstrect.
2661
         */
2662
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2663
        public static extern int SDL_RenderCopyExF(
2664
            IntPtr renderer,
2665
            IntPtr texture,
2666
            ref SDL_Rect srcrect,
2667
            IntPtr dstrect,
2668
            double angle,
2669
            ref SDL_FPoint center,
2670
            SDL_RendererFlip flip
2671
        );
2672

2673
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2674
         * Internally, this function contains logic to use default values when
2675
         * source, destination, and/or center are passed as NULL.
2676
         * This overload allows for IntPtr.Zero (null) to be passed for center.
2677
         */
2678
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2679
        public static extern int SDL_RenderCopyExF(
2680
            IntPtr renderer,
2681
            IntPtr texture,
2682
            ref SDL_Rect srcrect,
2683
            ref SDL_FRect dstrect,
2684
            double angle,
2685
            IntPtr center,
2686
            SDL_RendererFlip flip
2687
        );
2688

2689
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2690
         * Internally, this function contains logic to use default values when
2691
         * source, destination, and/or center are passed as NULL.
2692
         * This overload allows for IntPtr.Zero (null) to be passed for both
2693
         * srcrect and dstrect.
2694
         */
2695
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2696
        public static extern int SDL_RenderCopyExF(
2697
            IntPtr renderer,
2698
            IntPtr texture,
2699
            IntPtr srcrect,
2700
            IntPtr dstrect,
2701
            double angle,
2702
            ref SDL_FPoint center,
2703
            SDL_RendererFlip flip
2704
        );
2705

2706
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2707
         * Internally, this function contains logic to use default values when
2708
         * source, destination, and/or center are passed as NULL.
2709
         * This overload allows for IntPtr.Zero (null) to be passed for both
2710
         * srcrect and center.
2711
         */
2712
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2713
        public static extern int SDL_RenderCopyExF(
2714
            IntPtr renderer,
2715
            IntPtr texture,
2716
            IntPtr srcrect,
2717
            ref SDL_FRect dstrect,
2718
            double angle,
2719
            IntPtr center,
2720
            SDL_RendererFlip flip
2721
        );
2722

2723
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2724
         * Internally, this function contains logic to use default values when
2725
         * source, destination, and/or center are passed as NULL.
2726
         * This overload allows for IntPtr.Zero (null) to be passed for both
2727
         * dstrect and center.
2728
         */
2729
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2730
        public static extern int SDL_RenderCopyExF(
2731
            IntPtr renderer,
2732
            IntPtr texture,
2733
            ref SDL_Rect srcrect,
2734
            IntPtr dstrect,
2735
            double angle,
2736
            IntPtr center,
2737
            SDL_RendererFlip flip
2738
        );
2739

2740
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture*.
2741
         * Internally, this function contains logic to use default values when
2742
         * source, destination, and/or center are passed as NULL.
2743
         * This overload allows for IntPtr.Zero (null) to be passed for all
2744
         * three parameters.
2745
         */
2746
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2747
        public static extern int SDL_RenderCopyExF(
2748
            IntPtr renderer,
2749
            IntPtr texture,
2750
            IntPtr srcrect,
2751
            IntPtr dstrect,
2752
            double angle,
2753
            IntPtr center,
2754
            SDL_RendererFlip flip
2755
        );
2756

2757
        /* renderer refers to an SDL_Renderer* */
2758
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2759
        public static extern int SDL_RenderDrawPointF(
2760
            IntPtr renderer,
2761
            float x,
2762
            float y
2763
        );
2764

2765
        /* renderer refers to an SDL_Renderer* */
2766
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2767
        public static extern int SDL_RenderDrawPointsF(
2768
            IntPtr renderer,
2769
            [In] SDL_FPoint[] points,
2770
            int count
2771
        );
2772

2773
        /* renderer refers to an SDL_Renderer* */
2774
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2775
        public static extern int SDL_RenderDrawLineF(
2776
            IntPtr renderer,
2777
            float x1,
2778
            float y1,
2779
            float x2,
2780
            float y2
2781
        );
2782

2783
        /* renderer refers to an SDL_Renderer* */
2784
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2785
        public static extern int SDL_RenderDrawLinesF(
2786
            IntPtr renderer,
2787
            [In] SDL_FPoint[] points,
2788
            int count
2789
        );
2790

2791
        /* renderer refers to an SDL_Renderer* */
2792
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2793
        public static extern int SDL_RenderDrawRectF(
2794
            IntPtr renderer,
2795
            ref SDL_FRect rect
2796
        );
2797

2798
        /* renderer refers to an SDL_Renderer*, rect to an SDL_Rect*.
2799
         * This overload allows for IntPtr.Zero (null) to be passed for rect.
2800
         */
2801
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2802
        public static extern int SDL_RenderDrawRectF(
2803
            IntPtr renderer,
2804
            IntPtr rect
2805
        );
2806

2807
        /* renderer refers to an SDL_Renderer* */
2808
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2809
        public static extern int SDL_RenderDrawRectsF(
2810
            IntPtr renderer,
2811
            [In] SDL_FRect[] rects,
2812
            int count
2813
        );
2814

2815
        /* renderer refers to an SDL_Renderer* */
2816
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2817
        public static extern int SDL_RenderFillRectF(
2818
            IntPtr renderer,
2819
            ref SDL_FRect rect
2820
        );
2821

2822
        /* renderer refers to an SDL_Renderer*, rect to an SDL_Rect*.
2823
         * This overload allows for IntPtr.Zero (null) to be passed for rect.
2824
         */
2825
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2826
        public static extern int SDL_RenderFillRectF(
2827
            IntPtr renderer,
2828
            IntPtr rect
2829
        );
2830

2831
        /* renderer refers to an SDL_Renderer* */
2832
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2833
        public static extern int SDL_RenderFillRectsF(
2834
            IntPtr renderer,
2835
            [In] SDL_FRect[] rects,
2836
            int count
2837
        );
2838

2839
        #endregion
2840

2841
        /* renderer refers to an SDL_Renderer* */
2842
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2843
        public static extern void SDL_RenderGetClipRect(
2844
            IntPtr renderer,
2845
            out SDL_Rect rect
2846
        );
2847

2848
        /* renderer refers to an SDL_Renderer* */
2849
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2850
        public static extern void SDL_RenderGetLogicalSize(
2851
            IntPtr renderer,
2852
            out int w,
2853
            out int h
2854
        );
2855

2856
        /* renderer refers to an SDL_Renderer* */
2857
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2858
        public static extern void SDL_RenderGetScale(
2859
            IntPtr renderer,
2860
            out float scaleX,
2861
            out float scaleY
2862
        );
2863

2864
        /* renderer refers to an SDL_Renderer* */
2865
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2866
        public static extern int SDL_RenderGetViewport(
2867
            IntPtr renderer,
2868
            out SDL_Rect rect
2869
        );
2870

2871
        /* renderer refers to an SDL_Renderer* */
2872
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2873
        public static extern void SDL_RenderPresent(IntPtr renderer);
2874

2875
        /* renderer refers to an SDL_Renderer* */
2876
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2877
        public static extern int SDL_RenderReadPixels(
2878
            IntPtr renderer,
2879
            ref SDL_Rect rect,
2880
            uint format,
2881
            IntPtr pixels,
2882
            int pitch
2883
        );
2884

2885
        /* renderer refers to an SDL_Renderer* */
2886
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2887
        public static extern int SDL_RenderSetClipRect(
2888
            IntPtr renderer,
2889
            ref SDL_Rect rect
2890
        );
2891

2892
        /* renderer refers to an SDL_Renderer*
2893
         * This overload allows for IntPtr.Zero (null) to be passed for rect.
2894
         */
2895
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2896
        public static extern int SDL_RenderSetClipRect(
2897
            IntPtr renderer,
2898
            IntPtr rect
2899
        );
2900

2901
        /* renderer refers to an SDL_Renderer* */
2902
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2903
        public static extern int SDL_RenderSetLogicalSize(
2904
            IntPtr renderer,
2905
            int w,
2906
            int h
2907
        );
2908

2909
        /* renderer refers to an SDL_Renderer* */
2910
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2911
        public static extern int SDL_RenderSetScale(
2912
            IntPtr renderer,
2913
            float scaleX,
2914
            float scaleY
2915
        );
2916

2917
        /* renderer refers to an SDL_Renderer*
2918
         * Only available in 2.0.5 or higher.
2919
         */
2920
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2921
        public static extern int SDL_RenderSetIntegerScale(
2922
            IntPtr renderer,
2923
            SDL_bool enable
2924
        );
2925

2926
        /* renderer refers to an SDL_Renderer* */
2927
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2928
        public static extern int SDL_RenderSetViewport(
2929
            IntPtr renderer,
2930
            ref SDL_Rect rect
2931
        );
2932

2933
        /* renderer refers to an SDL_Renderer* */
2934
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2935
        public static extern int SDL_SetRenderDrawBlendMode(
2936
            IntPtr renderer,
2937
            SDL_BlendMode blendMode
2938
        );
2939

2940
        /* renderer refers to an SDL_Renderer* */
2941
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2942
        public static extern int SDL_SetRenderDrawColor(
2943
            IntPtr renderer,
2944
            byte r,
2945
            byte g,
2946
            byte b,
2947
            byte a
2948
        );
2949

2950
        /* renderer refers to an SDL_Renderer*, texture to an SDL_Texture* */
2951
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2952
        public static extern int SDL_SetRenderTarget(
2953
            IntPtr renderer,
2954
            IntPtr texture
2955
        );
2956

2957
        /* texture refers to an SDL_Texture* */
2958
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2959
        public static extern int SDL_SetTextureAlphaMod(
2960
            IntPtr texture,
2961
            byte alpha
2962
        );
2963

2964
        /* texture refers to an SDL_Texture* */
2965
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2966
        public static extern int SDL_SetTextureBlendMode(
2967
            IntPtr texture,
2968
            SDL_BlendMode blendMode
2969
        );
2970

2971
        /* texture refers to an SDL_Texture* */
2972
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2973
        public static extern int SDL_SetTextureColorMod(
2974
            IntPtr texture,
2975
            byte r,
2976
            byte g,
2977
            byte b
2978
        );
2979

2980
        /* texture refers to an SDL_Texture* */
2981
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2982
        public static extern void SDL_UnlockTexture(IntPtr texture);
2983

2984
        /* texture refers to an SDL_Texture* */
2985
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2986
        public static extern int SDL_UpdateTexture(
2987
            IntPtr texture,
2988
            ref SDL_Rect rect,
2989
            IntPtr pixels,
2990
            int pitch
2991
        );
2992

2993
        /* texture refers to an SDL_Texture* */
2994
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
2995
        public static extern int SDL_UpdateTexture(
2996
            IntPtr texture,
2997
            IntPtr rect,
2998
            IntPtr pixels,
2999
            int pitch
3000
        );
3001

3002
        /* texture refers to an SDL_Texture*
3003
         * Only available in 2.0.1 or higher.
3004
         */
3005
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3006
        public static extern int SDL_UpdateYUVTexture(
3007
            IntPtr texture,
3008
            ref SDL_Rect rect,
3009
            IntPtr yPlane,
3010
            int yPitch,
3011
            IntPtr uPlane,
3012
            int uPitch,
3013
            IntPtr vPlane,
3014
            int vPitch
3015
        );
3016

3017
        /* renderer refers to an SDL_Renderer* */
3018
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3019
        public static extern SDL_bool SDL_RenderTargetSupported(
3020
            IntPtr renderer
3021
        );
3022

3023
        /* IntPtr refers to an SDL_Texture*, renderer to an SDL_Renderer* */
3024
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3025
        public static extern IntPtr SDL_GetRenderTarget(IntPtr renderer);
3026

3027
        /* renderer refers to an SDL_Renderer*
3028
         * Only available in 2.0.8 or higher.
3029
         */
3030
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3031
        public static extern IntPtr SDL_RenderGetMetalLayer(
3032
            IntPtr renderer
3033
        );
3034

3035
        /* renderer refers to an SDL_Renderer*
3036
         * Only available in 2.0.8 or higher.
3037
         */
3038
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3039
        public static extern IntPtr SDL_RenderGetMetalCommandEncoder(
3040
            IntPtr renderer
3041
        );
3042

3043
        /* renderer refers to an SDL_Renderer*
3044
         * Only available in 2.0.4 or higher.
3045
         */
3046
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3047
        public static extern SDL_bool SDL_RenderIsClipEnabled(IntPtr renderer);
3048

3049
        /* renderer refers to an SDL_Renderer*
3050
         * Only available in 2.0.10 or higher.
3051
         */
3052
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3053
        public static extern int SDL_RenderFlush(IntPtr renderer);
3054

3055
        #endregion
3056

3057
        #region SDL_pixels.h
3058

3059
        public static uint SDL_DEFINE_PIXELFOURCC(byte A, byte B, byte C, byte D)
3060
        {
3061
            return SDL_FOURCC(A, B, C, D);
3062
        }
3063

3064
        public static uint SDL_DEFINE_PIXELFORMAT(
3065
            SDL_PixelType type,
3066
            uint order,
3067
            SDL_PackedLayout layout,
3068
            byte bits,
3069
            byte bytes
3070
        )
3071
        {
3072
            return (uint)(
3073
                (1 << 28) |
3074
                (((byte)type) << 24) |
3075
                (((byte)order) << 20) |
3076
                (((byte)layout) << 16) |
3077
                (bits << 8) |
3078
                (bytes)
3079
            );
3080
        }
3081

3082
        public static byte SDL_PIXELFLAG(uint X)
3083
        {
3084
            return (byte)((X >> 28) & 0x0F);
3085
        }
3086

3087
        public static byte SDL_PIXELTYPE(uint X)
3088
        {
3089
            return (byte)((X >> 24) & 0x0F);
3090
        }
3091

3092
        public static byte SDL_PIXELORDER(uint X)
3093
        {
3094
            return (byte)((X >> 20) & 0x0F);
3095
        }
3096

3097
        public static byte SDL_PIXELLAYOUT(uint X)
3098
        {
3099
            return (byte)((X >> 16) & 0x0F);
3100
        }
3101

3102
        public static byte SDL_BITSPERPIXEL(uint X)
3103
        {
3104
            return (byte)((X >> 8) & 0xFF);
3105
        }
3106

3107
        public static byte SDL_BYTESPERPIXEL(uint X)
3108
        {
3109
            if (SDL_ISPIXELFORMAT_FOURCC(X))
3110
            {
3111
                if ((X == SDL_PIXELFORMAT_YUY2) ||
3112
                        (X == SDL_PIXELFORMAT_UYVY) ||
3113
                        (X == SDL_PIXELFORMAT_YVYU))
3114
                {
3115
                    return 2;
3116
                }
3117
                return 1;
3118
            }
3119
            return (byte)(X & 0xFF);
3120
        }
3121

3122
        public static bool SDL_ISPIXELFORMAT_INDEXED(uint format)
3123
        {
3124
            if (SDL_ISPIXELFORMAT_FOURCC(format))
3125
            {
3126
                return false;
3127
            }
3128
            SDL_PixelType pType =
3129
                (SDL_PixelType)SDL_PIXELTYPE(format);
3130
            return (
3131
                pType == SDL_PixelType.SDL_PIXELTYPE_INDEX1 ||
3132
                pType == SDL_PixelType.SDL_PIXELTYPE_INDEX4 ||
3133
                pType == SDL_PixelType.SDL_PIXELTYPE_INDEX8
3134
            );
3135
        }
3136

3137
        public static bool SDL_ISPIXELFORMAT_PACKED(uint format)
3138
        {
3139
            if (SDL_ISPIXELFORMAT_FOURCC(format))
3140
            {
3141
                return false;
3142
            }
3143
            SDL_PixelType pType =
3144
                (SDL_PixelType)SDL_PIXELTYPE(format);
3145
            return (
3146
                pType == SDL_PixelType.SDL_PIXELTYPE_PACKED8 ||
3147
                pType == SDL_PixelType.SDL_PIXELTYPE_PACKED16 ||
3148
                pType == SDL_PixelType.SDL_PIXELTYPE_PACKED32
3149
            );
3150
        }
3151

3152
        public static bool SDL_ISPIXELFORMAT_ARRAY(uint format)
3153
        {
3154
            if (SDL_ISPIXELFORMAT_FOURCC(format))
3155
            {
3156
                return false;
3157
            }
3158
            SDL_PixelType pType =
3159
                (SDL_PixelType)SDL_PIXELTYPE(format);
3160
            return (
3161
                pType == SDL_PixelType.SDL_PIXELTYPE_ARRAYU8 ||
3162
                pType == SDL_PixelType.SDL_PIXELTYPE_ARRAYU16 ||
3163
                pType == SDL_PixelType.SDL_PIXELTYPE_ARRAYU32 ||
3164
                pType == SDL_PixelType.SDL_PIXELTYPE_ARRAYF16 ||
3165
                pType == SDL_PixelType.SDL_PIXELTYPE_ARRAYF32
3166
            );
3167
        }
3168

3169
        public static bool SDL_ISPIXELFORMAT_ALPHA(uint format)
3170
        {
3171
            if (SDL_ISPIXELFORMAT_PACKED(format))
3172
            {
3173
                SDL_PackedOrder pOrder =
3174
                    (SDL_PackedOrder)SDL_PIXELORDER(format);
3175
                return (
3176
                    pOrder == SDL_PackedOrder.SDL_PACKEDORDER_ARGB ||
3177
                    pOrder == SDL_PackedOrder.SDL_PACKEDORDER_RGBA ||
3178
                    pOrder == SDL_PackedOrder.SDL_PACKEDORDER_ABGR ||
3179
                    pOrder == SDL_PackedOrder.SDL_PACKEDORDER_BGRA
3180
                );
3181
            }
3182
            else if (SDL_ISPIXELFORMAT_ARRAY(format))
3183
            {
3184
                SDL_ArrayOrder aOrder =
3185
                    (SDL_ArrayOrder)SDL_PIXELORDER(format);
3186
                return (
3187
                    aOrder == SDL_ArrayOrder.SDL_ARRAYORDER_ARGB ||
3188
                    aOrder == SDL_ArrayOrder.SDL_ARRAYORDER_RGBA ||
3189
                    aOrder == SDL_ArrayOrder.SDL_ARRAYORDER_ABGR ||
3190
                    aOrder == SDL_ArrayOrder.SDL_ARRAYORDER_BGRA
3191
                );
3192
            }
3193
            return false;
3194
        }
3195

3196
        public static bool SDL_ISPIXELFORMAT_FOURCC(uint format)
3197
        {
3198
            return (format == 0) && (SDL_PIXELFLAG(format) != 1);
3199
        }
3200

3201
        public enum SDL_PixelType
3202
        {
3203
            SDL_PIXELTYPE_UNKNOWN,
3204
            SDL_PIXELTYPE_INDEX1,
3205
            SDL_PIXELTYPE_INDEX4,
3206
            SDL_PIXELTYPE_INDEX8,
3207
            SDL_PIXELTYPE_PACKED8,
3208
            SDL_PIXELTYPE_PACKED16,
3209
            SDL_PIXELTYPE_PACKED32,
3210
            SDL_PIXELTYPE_ARRAYU8,
3211
            SDL_PIXELTYPE_ARRAYU16,
3212
            SDL_PIXELTYPE_ARRAYU32,
3213
            SDL_PIXELTYPE_ARRAYF16,
3214
            SDL_PIXELTYPE_ARRAYF32
3215
        }
3216

3217
        public enum SDL_BitmapOrder
3218
        {
3219
            SDL_BITMAPORDER_NONE,
3220
            SDL_BITMAPORDER_4321,
3221
            SDL_BITMAPORDER_1234
3222
        }
3223

3224
        public enum SDL_PackedOrder
3225
        {
3226
            SDL_PACKEDORDER_NONE,
3227
            SDL_PACKEDORDER_XRGB,
3228
            SDL_PACKEDORDER_RGBX,
3229
            SDL_PACKEDORDER_ARGB,
3230
            SDL_PACKEDORDER_RGBA,
3231
            SDL_PACKEDORDER_XBGR,
3232
            SDL_PACKEDORDER_BGRX,
3233
            SDL_PACKEDORDER_ABGR,
3234
            SDL_PACKEDORDER_BGRA
3235
        }
3236

3237
        public enum SDL_ArrayOrder
3238
        {
3239
            SDL_ARRAYORDER_NONE,
3240
            SDL_ARRAYORDER_RGB,
3241
            SDL_ARRAYORDER_RGBA,
3242
            SDL_ARRAYORDER_ARGB,
3243
            SDL_ARRAYORDER_BGR,
3244
            SDL_ARRAYORDER_BGRA,
3245
            SDL_ARRAYORDER_ABGR
3246
        }
3247

3248
        public enum SDL_PackedLayout
3249
        {
3250
            SDL_PACKEDLAYOUT_NONE,
3251
            SDL_PACKEDLAYOUT_332,
3252
            SDL_PACKEDLAYOUT_4444,
3253
            SDL_PACKEDLAYOUT_1555,
3254
            SDL_PACKEDLAYOUT_5551,
3255
            SDL_PACKEDLAYOUT_565,
3256
            SDL_PACKEDLAYOUT_8888,
3257
            SDL_PACKEDLAYOUT_2101010,
3258
            SDL_PACKEDLAYOUT_1010102
3259
        }
3260

3261
        public static readonly uint SDL_PIXELFORMAT_UNKNOWN = 0;
3262
        public static readonly uint SDL_PIXELFORMAT_INDEX1LSB =
3263
            SDL_DEFINE_PIXELFORMAT(
3264
                SDL_PixelType.SDL_PIXELTYPE_INDEX1,
3265
                (uint)SDL_BitmapOrder.SDL_BITMAPORDER_4321,
3266
                0,
3267
                1, 0
3268
            );
3269
        public static readonly uint SDL_PIXELFORMAT_INDEX1MSB =
3270
            SDL_DEFINE_PIXELFORMAT(
3271
                SDL_PixelType.SDL_PIXELTYPE_INDEX1,
3272
                (uint)SDL_BitmapOrder.SDL_BITMAPORDER_1234,
3273
                0,
3274
                1, 0
3275
            );
3276
        public static readonly uint SDL_PIXELFORMAT_INDEX4LSB =
3277
            SDL_DEFINE_PIXELFORMAT(
3278
                SDL_PixelType.SDL_PIXELTYPE_INDEX4,
3279
                (uint)SDL_BitmapOrder.SDL_BITMAPORDER_4321,
3280
                0,
3281
                4, 0
3282
            );
3283
        public static readonly uint SDL_PIXELFORMAT_INDEX4MSB =
3284
            SDL_DEFINE_PIXELFORMAT(
3285
                SDL_PixelType.SDL_PIXELTYPE_INDEX4,
3286
                (uint)SDL_BitmapOrder.SDL_BITMAPORDER_1234,
3287
                0,
3288
                4, 0
3289
            );
3290
        public static readonly uint SDL_PIXELFORMAT_INDEX8 =
3291
            SDL_DEFINE_PIXELFORMAT(
3292
                SDL_PixelType.SDL_PIXELTYPE_INDEX8,
3293
                0,
3294
                0,
3295
                8, 1
3296
            );
3297
        public static readonly uint SDL_PIXELFORMAT_RGB332 =
3298
            SDL_DEFINE_PIXELFORMAT(
3299
                SDL_PixelType.SDL_PIXELTYPE_PACKED8,
3300
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_XRGB,
3301
                SDL_PackedLayout.SDL_PACKEDLAYOUT_332,
3302
                8, 1
3303
            );
3304
        public static readonly uint SDL_PIXELFORMAT_RGB444 =
3305
            SDL_DEFINE_PIXELFORMAT(
3306
                SDL_PixelType.SDL_PIXELTYPE_PACKED16,
3307
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_XRGB,
3308
                SDL_PackedLayout.SDL_PACKEDLAYOUT_4444,
3309
                12, 2
3310
            );
3311
        public static readonly uint SDL_PIXELFORMAT_BGR444 =
3312
            SDL_DEFINE_PIXELFORMAT(
3313
                SDL_PixelType.SDL_PIXELTYPE_PACKED16,
3314
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_XBGR,
3315
                SDL_PackedLayout.SDL_PACKEDLAYOUT_4444,
3316
                12, 2
3317
            );
3318
        public static readonly uint SDL_PIXELFORMAT_RGB555 =
3319
            SDL_DEFINE_PIXELFORMAT(
3320
                SDL_PixelType.SDL_PIXELTYPE_PACKED16,
3321
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_XRGB,
3322
                SDL_PackedLayout.SDL_PACKEDLAYOUT_1555,
3323
                15, 2
3324
            );
3325
        public static readonly uint SDL_PIXELFORMAT_BGR555 =
3326
            SDL_DEFINE_PIXELFORMAT(
3327
                SDL_PixelType.SDL_PIXELTYPE_INDEX1,
3328
                (uint)SDL_BitmapOrder.SDL_BITMAPORDER_4321,
3329
                SDL_PackedLayout.SDL_PACKEDLAYOUT_1555,
3330
                15, 2
3331
            );
3332
        public static readonly uint SDL_PIXELFORMAT_ARGB4444 =
3333
            SDL_DEFINE_PIXELFORMAT(
3334
                SDL_PixelType.SDL_PIXELTYPE_PACKED16,
3335
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_ARGB,
3336
                SDL_PackedLayout.SDL_PACKEDLAYOUT_4444,
3337
                16, 2
3338
            );
3339
        public static readonly uint SDL_PIXELFORMAT_RGBA4444 =
3340
            SDL_DEFINE_PIXELFORMAT(
3341
                SDL_PixelType.SDL_PIXELTYPE_PACKED16,
3342
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_RGBA,
3343
                SDL_PackedLayout.SDL_PACKEDLAYOUT_4444,
3344
                16, 2
3345
            );
3346
        public static readonly uint SDL_PIXELFORMAT_ABGR4444 =
3347
            SDL_DEFINE_PIXELFORMAT(
3348
                SDL_PixelType.SDL_PIXELTYPE_PACKED16,
3349
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_ABGR,
3350
                SDL_PackedLayout.SDL_PACKEDLAYOUT_4444,
3351
                16, 2
3352
            );
3353
        public static readonly uint SDL_PIXELFORMAT_BGRA4444 =
3354
            SDL_DEFINE_PIXELFORMAT(
3355
                SDL_PixelType.SDL_PIXELTYPE_PACKED16,
3356
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_BGRA,
3357
                SDL_PackedLayout.SDL_PACKEDLAYOUT_4444,
3358
                16, 2
3359
            );
3360
        public static readonly uint SDL_PIXELFORMAT_ARGB1555 =
3361
            SDL_DEFINE_PIXELFORMAT(
3362
                SDL_PixelType.SDL_PIXELTYPE_PACKED16,
3363
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_ARGB,
3364
                SDL_PackedLayout.SDL_PACKEDLAYOUT_1555,
3365
                16, 2
3366
            );
3367
        public static readonly uint SDL_PIXELFORMAT_RGBA5551 =
3368
            SDL_DEFINE_PIXELFORMAT(
3369
                SDL_PixelType.SDL_PIXELTYPE_PACKED16,
3370
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_RGBA,
3371
                SDL_PackedLayout.SDL_PACKEDLAYOUT_5551,
3372
                16, 2
3373
            );
3374
        public static readonly uint SDL_PIXELFORMAT_ABGR1555 =
3375
            SDL_DEFINE_PIXELFORMAT(
3376
                SDL_PixelType.SDL_PIXELTYPE_PACKED16,
3377
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_ABGR,
3378
                SDL_PackedLayout.SDL_PACKEDLAYOUT_1555,
3379
                16, 2
3380
            );
3381
        public static readonly uint SDL_PIXELFORMAT_BGRA5551 =
3382
            SDL_DEFINE_PIXELFORMAT(
3383
                SDL_PixelType.SDL_PIXELTYPE_PACKED16,
3384
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_BGRA,
3385
                SDL_PackedLayout.SDL_PACKEDLAYOUT_5551,
3386
                16, 2
3387
            );
3388
        public static readonly uint SDL_PIXELFORMAT_RGB565 =
3389
            SDL_DEFINE_PIXELFORMAT(
3390
                SDL_PixelType.SDL_PIXELTYPE_PACKED16,
3391
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_XRGB,
3392
                SDL_PackedLayout.SDL_PACKEDLAYOUT_565,
3393
                16, 2
3394
            );
3395
        public static readonly uint SDL_PIXELFORMAT_BGR565 =
3396
            SDL_DEFINE_PIXELFORMAT(
3397
                SDL_PixelType.SDL_PIXELTYPE_PACKED16,
3398
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_XBGR,
3399
                SDL_PackedLayout.SDL_PACKEDLAYOUT_565,
3400
                16, 2
3401
            );
3402
        public static readonly uint SDL_PIXELFORMAT_RGB24 =
3403
            SDL_DEFINE_PIXELFORMAT(
3404
                SDL_PixelType.SDL_PIXELTYPE_ARRAYU8,
3405
                (uint)SDL_ArrayOrder.SDL_ARRAYORDER_RGB,
3406
                0,
3407
                24, 3
3408
            );
3409
        public static readonly uint SDL_PIXELFORMAT_BGR24 =
3410
            SDL_DEFINE_PIXELFORMAT(
3411
                SDL_PixelType.SDL_PIXELTYPE_ARRAYU8,
3412
                (uint)SDL_ArrayOrder.SDL_ARRAYORDER_BGR,
3413
                0,
3414
                24, 3
3415
            );
3416
        public static readonly uint SDL_PIXELFORMAT_RGB888 =
3417
            SDL_DEFINE_PIXELFORMAT(
3418
                SDL_PixelType.SDL_PIXELTYPE_PACKED32,
3419
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_XRGB,
3420
                SDL_PackedLayout.SDL_PACKEDLAYOUT_8888,
3421
                24, 4
3422
            );
3423
        public static readonly uint SDL_PIXELFORMAT_RGBX8888 =
3424
            SDL_DEFINE_PIXELFORMAT(
3425
                SDL_PixelType.SDL_PIXELTYPE_PACKED32,
3426
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_RGBX,
3427
                SDL_PackedLayout.SDL_PACKEDLAYOUT_8888,
3428
                24, 4
3429
            );
3430
        public static readonly uint SDL_PIXELFORMAT_BGR888 =
3431
            SDL_DEFINE_PIXELFORMAT(
3432
                SDL_PixelType.SDL_PIXELTYPE_PACKED32,
3433
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_XBGR,
3434
                SDL_PackedLayout.SDL_PACKEDLAYOUT_8888,
3435
                24, 4
3436
            );
3437
        public static readonly uint SDL_PIXELFORMAT_BGRX8888 =
3438
            SDL_DEFINE_PIXELFORMAT(
3439
                SDL_PixelType.SDL_PIXELTYPE_PACKED32,
3440
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_BGRX,
3441
                SDL_PackedLayout.SDL_PACKEDLAYOUT_8888,
3442
                24, 4
3443
            );
3444
        public static readonly uint SDL_PIXELFORMAT_ARGB8888 =
3445
            SDL_DEFINE_PIXELFORMAT(
3446
                SDL_PixelType.SDL_PIXELTYPE_PACKED32,
3447
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_ARGB,
3448
                SDL_PackedLayout.SDL_PACKEDLAYOUT_8888,
3449
                32, 4
3450
            );
3451
        public static readonly uint SDL_PIXELFORMAT_RGBA8888 =
3452
            SDL_DEFINE_PIXELFORMAT(
3453
                SDL_PixelType.SDL_PIXELTYPE_PACKED32,
3454
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_RGBA,
3455
                SDL_PackedLayout.SDL_PACKEDLAYOUT_8888,
3456
                32, 4
3457
            );
3458
        public static readonly uint SDL_PIXELFORMAT_ABGR8888 =
3459
            SDL_DEFINE_PIXELFORMAT(
3460
                SDL_PixelType.SDL_PIXELTYPE_PACKED32,
3461
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_ABGR,
3462
                SDL_PackedLayout.SDL_PACKEDLAYOUT_8888,
3463
                32, 4
3464
            );
3465
        public static readonly uint SDL_PIXELFORMAT_BGRA8888 =
3466
            SDL_DEFINE_PIXELFORMAT(
3467
                SDL_PixelType.SDL_PIXELTYPE_PACKED32,
3468
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_BGRA,
3469
                SDL_PackedLayout.SDL_PACKEDLAYOUT_8888,
3470
                32, 4
3471
            );
3472
        public static readonly uint SDL_PIXELFORMAT_ARGB2101010 =
3473
            SDL_DEFINE_PIXELFORMAT(
3474
                SDL_PixelType.SDL_PIXELTYPE_PACKED32,
3475
                (uint)SDL_PackedOrder.SDL_PACKEDORDER_ARGB,
3476
                SDL_PackedLayout.SDL_PACKEDLAYOUT_2101010,
3477
                32, 4
3478
            );
3479
        public static readonly uint SDL_PIXELFORMAT_YV12 =
3480
            SDL_DEFINE_PIXELFOURCC(
3481
                (byte)'Y', (byte)'V', (byte)'1', (byte)'2'
3482
            );
3483
        public static readonly uint SDL_PIXELFORMAT_IYUV =
3484
            SDL_DEFINE_PIXELFOURCC(
3485
                (byte)'I', (byte)'Y', (byte)'U', (byte)'V'
3486
            );
3487
        public static readonly uint SDL_PIXELFORMAT_YUY2 =
3488
            SDL_DEFINE_PIXELFOURCC(
3489
                (byte)'Y', (byte)'U', (byte)'Y', (byte)'2'
3490
            );
3491
        public static readonly uint SDL_PIXELFORMAT_UYVY =
3492
            SDL_DEFINE_PIXELFOURCC(
3493
                (byte)'U', (byte)'Y', (byte)'V', (byte)'Y'
3494
            );
3495
        public static readonly uint SDL_PIXELFORMAT_YVYU =
3496
            SDL_DEFINE_PIXELFOURCC(
3497
                (byte)'Y', (byte)'V', (byte)'Y', (byte)'U'
3498
            );
3499

3500
        [StructLayout(LayoutKind.Sequential)]
3501
        public struct SDL_Color
3502
        {
3503
            public byte r;
3504
            public byte g;
3505
            public byte b;
3506
            public byte a;
3507
        }
3508

3509
        [StructLayout(LayoutKind.Sequential)]
3510
        public struct SDL_Palette
3511
        {
3512
            public int ncolors;
3513
            public IntPtr colors;
3514
            public int version;
3515
            public int refcount;
3516
        }
3517

3518
        [StructLayout(LayoutKind.Sequential)]
3519
        public struct SDL_PixelFormat
3520
        {
3521
            public uint format;
3522
            public IntPtr palette; // SDL_Palette*
3523
            public byte BitsPerPixel;
3524
            public byte BytesPerPixel;
3525
            public uint Rmask;
3526
            public uint Gmask;
3527
            public uint Bmask;
3528
            public uint Amask;
3529
            public byte Rloss;
3530
            public byte Gloss;
3531
            public byte Bloss;
3532
            public byte Aloss;
3533
            public byte Rshift;
3534
            public byte Gshift;
3535
            public byte Bshift;
3536
            public byte Ashift;
3537
            public int refcount;
3538
            public IntPtr next; // SDL_PixelFormat*
3539
        }
3540

3541
        /* IntPtr refers to an SDL_PixelFormat* */
3542
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3543
        public static extern IntPtr SDL_AllocFormat(uint pixel_format);
3544

3545
        /* IntPtr refers to an SDL_Palette* */
3546
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3547
        public static extern IntPtr SDL_AllocPalette(int ncolors);
3548

3549
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3550
        public static extern void SDL_CalculateGammaRamp(
3551
            float gamma,
3552
            [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)]
3553
				ushort[] ramp
3554
        );
3555

3556
        /* format refers to an SDL_PixelFormat* */
3557
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3558
        public static extern void SDL_FreeFormat(IntPtr format);
3559

3560
        /* palette refers to an SDL_Palette* */
3561
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3562
        public static extern void SDL_FreePalette(IntPtr palette);
3563

3564
        [DllImport(nativeLibName, EntryPoint = "SDL_GetPixelFormatName", CallingConvention = CallingConvention.Cdecl)]
3565
        private static extern IntPtr INTERNAL_SDL_GetPixelFormatName(
3566
            uint format
3567
        );
3568
        public static string SDL_GetPixelFormatName(uint format)
3569
        {
3570
            return UTF8_ToManaged(
3571
                INTERNAL_SDL_GetPixelFormatName(format)
3572
            );
3573
        }
3574

3575
        /* format refers to an SDL_PixelFormat* */
3576
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3577
        public static extern void SDL_GetRGB(
3578
            uint pixel,
3579
            IntPtr format,
3580
            out byte r,
3581
            out byte g,
3582
            out byte b
3583
        );
3584

3585
        /* format refers to an SDL_PixelFormat* */
3586
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3587
        public static extern void SDL_GetRGBA(
3588
            uint pixel,
3589
            IntPtr format,
3590
            out byte r,
3591
            out byte g,
3592
            out byte b,
3593
            out byte a
3594
        );
3595

3596
        /* format refers to an SDL_PixelFormat* */
3597
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3598
        public static extern uint SDL_MapRGB(
3599
            IntPtr format,
3600
            byte r,
3601
            byte g,
3602
            byte b
3603
        );
3604

3605
        /* format refers to an SDL_PixelFormat* */
3606
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3607
        public static extern uint SDL_MapRGBA(
3608
            IntPtr format,
3609
            byte r,
3610
            byte g,
3611
            byte b,
3612
            byte a
3613
        );
3614

3615
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3616
        public static extern uint SDL_MasksToPixelFormatEnum(
3617
            int bpp,
3618
            uint Rmask,
3619
            uint Gmask,
3620
            uint Bmask,
3621
            uint Amask
3622
        );
3623

3624
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3625
        public static extern SDL_bool SDL_PixelFormatEnumToMasks(
3626
            uint format,
3627
            out int bpp,
3628
            out uint Rmask,
3629
            out uint Gmask,
3630
            out uint Bmask,
3631
            out uint Amask
3632
        );
3633

3634
        /* palette refers to an SDL_Palette* */
3635
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3636
        public static extern int SDL_SetPaletteColors(
3637
            IntPtr palette,
3638
            [In] SDL_Color[] colors,
3639
            int firstcolor,
3640
            int ncolors
3641
        );
3642

3643
        /* format and palette refer to an SDL_PixelFormat* and SDL_Palette* */
3644
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3645
        public static extern int SDL_SetPixelFormatPalette(
3646
            IntPtr format,
3647
            IntPtr palette
3648
        );
3649

3650
        #endregion
3651

3652
        #region SDL_rect.h
3653

3654
        [StructLayout(LayoutKind.Sequential)]
3655
        public struct SDL_Point
3656
        {
3657
            public int x;
3658
            public int y;
3659
        }
3660

3661
        [StructLayout(LayoutKind.Sequential)]
3662
        public struct SDL_Rect
3663
        {
3664
            public int x;
3665
            public int y;
3666
            public int w;
3667
            public int h;
3668
        }
3669

3670
        /* Only available in 2.0.10 or higher. */
3671
        [StructLayout(LayoutKind.Sequential)]
3672
        public struct SDL_FPoint
3673
        {
3674
            public float x;
3675
            public float y;
3676
        }
3677

3678
        /* Only available in 2.0.10 or higher. */
3679
        [StructLayout(LayoutKind.Sequential)]
3680
        public struct SDL_FRect
3681
        {
3682
            public float x;
3683
            public float y;
3684
            public float w;
3685
            public float h;
3686
        }
3687

3688
        /* Only available in 2.0.4 or higher. */
3689
        public static SDL_bool SDL_PointInRect(ref SDL_Point p, ref SDL_Rect r)
3690
        {
3691
            return ((p.x >= r.x) &&
3692
                    (p.x < (r.x + r.w)) &&
3693
                    (p.y >= r.y) &&
3694
                    (p.y < (r.y + r.h))) ?
3695
                SDL_bool.SDL_TRUE :
3696
                SDL_bool.SDL_FALSE;
3697
        }
3698

3699
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3700
        public static extern SDL_bool SDL_EnclosePoints(
3701
            [In] SDL_Point[] points,
3702
            int count,
3703
            ref SDL_Rect clip,
3704
            out SDL_Rect result
3705
        );
3706

3707
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3708
        public static extern SDL_bool SDL_HasIntersection(
3709
            ref SDL_Rect A,
3710
            ref SDL_Rect B
3711
        );
3712

3713
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3714
        public static extern SDL_bool SDL_IntersectRect(
3715
            ref SDL_Rect A,
3716
            ref SDL_Rect B,
3717
            out SDL_Rect result
3718
        );
3719

3720
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3721
        public static extern SDL_bool SDL_IntersectRectAndLine(
3722
            ref SDL_Rect rect,
3723
            ref int X1,
3724
            ref int Y1,
3725
            ref int X2,
3726
            ref int Y2
3727
        );
3728

3729
        public static SDL_bool SDL_RectEmpty(ref SDL_Rect r)
3730
        {
3731
            return ((r.w <= 0) || (r.h <= 0)) ?
3732
                SDL_bool.SDL_TRUE :
3733
                SDL_bool.SDL_FALSE;
3734
        }
3735

3736
        public static SDL_bool SDL_RectEquals(
3737
            ref SDL_Rect a,
3738
            ref SDL_Rect b
3739
        )
3740
        {
3741
            return ((a.x == b.x) &&
3742
                    (a.y == b.y) &&
3743
                    (a.w == b.w) &&
3744
                    (a.h == b.h)) ?
3745
                SDL_bool.SDL_TRUE :
3746
                SDL_bool.SDL_FALSE;
3747
        }
3748

3749
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3750
        public static extern void SDL_UnionRect(
3751
            ref SDL_Rect A,
3752
            ref SDL_Rect B,
3753
            out SDL_Rect result
3754
        );
3755

3756
        #endregion
3757

3758
        #region SDL_surface.h
3759

3760
        public const uint SDL_SWSURFACE = 0x00000000;
3761
        public const uint SDL_PREALLOC = 0x00000001;
3762
        public const uint SDL_RLEACCEL = 0x00000002;
3763
        public const uint SDL_DONTFREE = 0x00000004;
3764

3765
        [StructLayout(LayoutKind.Sequential)]
3766
        public struct SDL_Surface
3767
        {
3768
            public uint flags;
3769
            public IntPtr format; // SDL_PixelFormat*
3770
            public int w;
3771
            public int h;
3772
            public int pitch;
3773
            public IntPtr pixels; // void*
3774
            public IntPtr userdata; // void*
3775
            public int locked;
3776
            public IntPtr lock_data; // void*
3777
            public SDL_Rect clip_rect;
3778
            public IntPtr map; // SDL_BlitMap*
3779
            public int refcount;
3780
        }
3781

3782
        /* surface refers to an SDL_Surface* */
3783
        public static bool SDL_MUSTLOCK(IntPtr surface)
3784
        {
3785
            SDL_Surface sur;
3786
            sur = (SDL_Surface)Marshal.PtrToStructure(
3787
                surface,
3788
                typeof(SDL_Surface)
3789
            );
3790
            return (sur.flags & SDL_RLEACCEL) != 0;
3791
        }
3792

3793
        /* src and dst refer to an SDL_Surface* */
3794
        [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlit", CallingConvention = CallingConvention.Cdecl)]
3795
        public static extern int SDL_BlitSurface(
3796
            IntPtr src,
3797
            ref SDL_Rect srcrect,
3798
            IntPtr dst,
3799
            ref SDL_Rect dstrect
3800
        );
3801

3802
        /* src and dst refer to an SDL_Surface*
3803
         * Internally, this function contains logic to use default values when
3804
         * source and destination rectangles are passed as NULL.
3805
         * This overload allows for IntPtr.Zero (null) to be passed for srcrect.
3806
         */
3807
        [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlit", CallingConvention = CallingConvention.Cdecl)]
3808
        public static extern int SDL_BlitSurface(
3809
            IntPtr src,
3810
            IntPtr srcrect,
3811
            IntPtr dst,
3812
            ref SDL_Rect dstrect
3813
        );
3814

3815
        /* src and dst refer to an SDL_Surface*
3816
         * Internally, this function contains logic to use default values when
3817
         * source and destination rectangles are passed as NULL.
3818
         * This overload allows for IntPtr.Zero (null) to be passed for dstrect.
3819
         */
3820
        [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlit", CallingConvention = CallingConvention.Cdecl)]
3821
        public static extern int SDL_BlitSurface(
3822
            IntPtr src,
3823
            ref SDL_Rect srcrect,
3824
            IntPtr dst,
3825
            IntPtr dstrect
3826
        );
3827

3828
        /* src and dst refer to an SDL_Surface*
3829
         * Internally, this function contains logic to use default values when
3830
         * source and destination rectangles are passed as NULL.
3831
         * This overload allows for IntPtr.Zero (null) to be passed for both SDL_Rects.
3832
         */
3833
        [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlit", CallingConvention = CallingConvention.Cdecl)]
3834
        public static extern int SDL_BlitSurface(
3835
            IntPtr src,
3836
            IntPtr srcrect,
3837
            IntPtr dst,
3838
            IntPtr dstrect
3839
        );
3840

3841
        /* src and dst refer to an SDL_Surface* */
3842
        [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlitScaled", CallingConvention = CallingConvention.Cdecl)]
3843
        public static extern int SDL_BlitScaled(
3844
            IntPtr src,
3845
            ref SDL_Rect srcrect,
3846
            IntPtr dst,
3847
            ref SDL_Rect dstrect
3848
        );
3849

3850
        /* src and dst refer to an SDL_Surface*
3851
         * Internally, this function contains logic to use default values when
3852
         * source and destination rectangles are passed as NULL.
3853
         * This overload allows for IntPtr.Zero (null) to be passed for srcrect.
3854
         */
3855
        [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlitScaled", CallingConvention = CallingConvention.Cdecl)]
3856
        public static extern int SDL_BlitScaled(
3857
            IntPtr src,
3858
            IntPtr srcrect,
3859
            IntPtr dst,
3860
            ref SDL_Rect dstrect
3861
        );
3862

3863
        /* src and dst refer to an SDL_Surface*
3864
         * Internally, this function contains logic to use default values when
3865
         * source and destination rectangles are passed as NULL.
3866
         * This overload allows for IntPtr.Zero (null) to be passed for dstrect.
3867
         */
3868
        [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlitScaled", CallingConvention = CallingConvention.Cdecl)]
3869
        public static extern int SDL_BlitScaled(
3870
            IntPtr src,
3871
            ref SDL_Rect srcrect,
3872
            IntPtr dst,
3873
            IntPtr dstrect
3874
        );
3875

3876
        /* src and dst refer to an SDL_Surface*
3877
         * Internally, this function contains logic to use default values when
3878
         * source and destination rectangles are passed as NULL.
3879
         * This overload allows for IntPtr.Zero (null) to be passed for both SDL_Rects.
3880
         */
3881
        [DllImport(nativeLibName, EntryPoint = "SDL_UpperBlitScaled", CallingConvention = CallingConvention.Cdecl)]
3882
        public static extern int SDL_BlitScaled(
3883
            IntPtr src,
3884
            IntPtr srcrect,
3885
            IntPtr dst,
3886
            IntPtr dstrect
3887
        );
3888

3889
        /* src and dst are void* pointers */
3890
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3891
        public static extern int SDL_ConvertPixels(
3892
            int width,
3893
            int height,
3894
            uint src_format,
3895
            IntPtr src,
3896
            int src_pitch,
3897
            uint dst_format,
3898
            IntPtr dst,
3899
            int dst_pitch
3900
        );
3901

3902
        /* IntPtr refers to an SDL_Surface*
3903
         * src refers to an SDL_Surface*
3904
         * fmt refers to an SDL_PixelFormat*
3905
         */
3906
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3907
        public static extern IntPtr SDL_ConvertSurface(
3908
            IntPtr src,
3909
            IntPtr fmt,
3910
            uint flags
3911
        );
3912

3913
        /* IntPtr refers to an SDL_Surface*, src to an SDL_Surface* */
3914
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3915
        public static extern IntPtr SDL_ConvertSurfaceFormat(
3916
            IntPtr src,
3917
            uint pixel_format,
3918
            uint flags
3919
        );
3920

3921
        /* IntPtr refers to an SDL_Surface* */
3922
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3923
        public static extern IntPtr SDL_CreateRGBSurface(
3924
            uint flags,
3925
            int width,
3926
            int height,
3927
            int depth,
3928
            uint Rmask,
3929
            uint Gmask,
3930
            uint Bmask,
3931
            uint Amask
3932
        );
3933

3934
        /* IntPtr refers to an SDL_Surface*, pixels to a void* */
3935
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3936
        public static extern IntPtr SDL_CreateRGBSurfaceFrom(
3937
            IntPtr pixels,
3938
            int width,
3939
            int height,
3940
            int depth,
3941
            int pitch,
3942
            uint Rmask,
3943
            uint Gmask,
3944
            uint Bmask,
3945
            uint Amask
3946
        );
3947

3948
        /* IntPtr refers to an SDL_Surface*
3949
         * Only available in 2.0.5 or higher.
3950
         */
3951
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3952
        public static extern IntPtr SDL_CreateRGBSurfaceWithFormat(
3953
            uint flags,
3954
            int width,
3955
            int height,
3956
            int depth,
3957
            uint format
3958
        );
3959

3960
        /* IntPtr refers to an SDL_Surface*, pixels to a void*
3961
         * Only available in 2.0.5 or higher.
3962
         */
3963
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3964
        public static extern IntPtr SDL_CreateRGBSurfaceWithFormatFrom(
3965
            IntPtr pixels,
3966
            int width,
3967
            int height,
3968
            int depth,
3969
            int pitch,
3970
            uint format
3971
        );
3972

3973
        /* dst refers to an SDL_Surface* */
3974
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3975
        public static extern int SDL_FillRect(
3976
            IntPtr dst,
3977
            ref SDL_Rect rect,
3978
            uint color
3979
        );
3980

3981
        /* dst refers to an SDL_Surface*.
3982
         * This overload allows passing NULL to rect.
3983
         */
3984
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3985
        public static extern int SDL_FillRect(
3986
            IntPtr dst,
3987
            IntPtr rect,
3988
            uint color
3989
        );
3990

3991
        /* dst refers to an SDL_Surface* */
3992
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
3993
        public static extern int SDL_FillRects(
3994
            IntPtr dst,
3995
            [In] SDL_Rect[] rects,
3996
            int count,
3997
            uint color
3998
        );
3999

4000
        /* surface refers to an SDL_Surface* */
4001
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4002
        public static extern void SDL_FreeSurface(IntPtr surface);
4003

4004
        /* surface refers to an SDL_Surface* */
4005
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4006
        public static extern void SDL_GetClipRect(
4007
            IntPtr surface,
4008
            out SDL_Rect rect
4009
        );
4010

4011
        /* surface refers to an SDL_Surface*.
4012
         * Only available in 2.0.9 or higher.
4013
         */
4014
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4015
        public static extern SDL_bool SDL_HasColorKey(IntPtr surface);
4016

4017
        /* surface refers to an SDL_Surface* */
4018
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4019
        public static extern int SDL_GetColorKey(
4020
            IntPtr surface,
4021
            out uint key
4022
        );
4023

4024
        /* surface refers to an SDL_Surface* */
4025
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4026
        public static extern int SDL_GetSurfaceAlphaMod(
4027
            IntPtr surface,
4028
            out byte alpha
4029
        );
4030

4031
        /* surface refers to an SDL_Surface* */
4032
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4033
        public static extern int SDL_GetSurfaceBlendMode(
4034
            IntPtr surface,
4035
            out SDL_BlendMode blendMode
4036
        );
4037

4038
        /* surface refers to an SDL_Surface* */
4039
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4040
        public static extern int SDL_GetSurfaceColorMod(
4041
            IntPtr surface,
4042
            out byte r,
4043
            out byte g,
4044
            out byte b
4045
        );
4046

4047
        /* These are for SDL_LoadBMP, which is a macro in the SDL headers. */
4048
        /* IntPtr refers to an SDL_Surface* */
4049
        /* THIS IS AN RWops FUNCTION! */
4050
        [DllImport(nativeLibName, EntryPoint = "SDL_LoadBMP_RW", CallingConvention = CallingConvention.Cdecl)]
4051
        private static extern IntPtr INTERNAL_SDL_LoadBMP_RW(
4052
            IntPtr src,
4053
            int freesrc
4054
        );
4055
        public static IntPtr SDL_LoadBMP(string file)
4056
        {
4057
            IntPtr rwops = SDL_RWFromFile(file, "rb");
4058
            return INTERNAL_SDL_LoadBMP_RW(rwops, 1);
4059
        }
4060

4061
        /* surface refers to an SDL_Surface* */
4062
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4063
        public static extern int SDL_LockSurface(IntPtr surface);
4064

4065
        /* src and dst refer to an SDL_Surface* */
4066
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4067
        public static extern int SDL_LowerBlit(
4068
            IntPtr src,
4069
            ref SDL_Rect srcrect,
4070
            IntPtr dst,
4071
            ref SDL_Rect dstrect
4072
        );
4073

4074
        /* src and dst refer to an SDL_Surface* */
4075
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4076
        public static extern int SDL_LowerBlitScaled(
4077
            IntPtr src,
4078
            ref SDL_Rect srcrect,
4079
            IntPtr dst,
4080
            ref SDL_Rect dstrect
4081
        );
4082

4083
        /* These are for SDL_SaveBMP, which is a macro in the SDL headers. */
4084
        /* IntPtr refers to an SDL_Surface* */
4085
        /* THIS IS AN RWops FUNCTION! */
4086
        [DllImport(nativeLibName, EntryPoint = "SDL_SaveBMP_RW", CallingConvention = CallingConvention.Cdecl)]
4087
        private static extern int INTERNAL_SDL_SaveBMP_RW(
4088
            IntPtr surface,
4089
            IntPtr src,
4090
            int freesrc
4091
        );
4092
        public static int SDL_SaveBMP(IntPtr surface, string file)
4093
        {
4094
            IntPtr rwops = SDL_RWFromFile(file, "wb");
4095
            return INTERNAL_SDL_SaveBMP_RW(surface, rwops, 1);
4096
        }
4097

4098
        /* surface refers to an SDL_Surface* */
4099
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4100
        public static extern SDL_bool SDL_SetClipRect(
4101
            IntPtr surface,
4102
            ref SDL_Rect rect
4103
        );
4104

4105
        /* surface refers to an SDL_Surface* */
4106
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4107
        public static extern int SDL_SetColorKey(
4108
            IntPtr surface,
4109
            int flag,
4110
            uint key
4111
        );
4112

4113
        /* surface refers to an SDL_Surface* */
4114
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4115
        public static extern int SDL_SetSurfaceAlphaMod(
4116
            IntPtr surface,
4117
            byte alpha
4118
        );
4119

4120
        /* surface refers to an SDL_Surface* */
4121
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4122
        public static extern int SDL_SetSurfaceBlendMode(
4123
            IntPtr surface,
4124
            SDL_BlendMode blendMode
4125
        );
4126

4127
        /* surface refers to an SDL_Surface* */
4128
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4129
        public static extern int SDL_SetSurfaceColorMod(
4130
            IntPtr surface,
4131
            byte r,
4132
            byte g,
4133
            byte b
4134
        );
4135

4136
        /* surface refers to an SDL_Surface*, palette to an SDL_Palette* */
4137
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4138
        public static extern int SDL_SetSurfacePalette(
4139
            IntPtr surface,
4140
            IntPtr palette
4141
        );
4142

4143
        /* surface refers to an SDL_Surface* */
4144
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4145
        public static extern int SDL_SetSurfaceRLE(
4146
            IntPtr surface,
4147
            int flag
4148
        );
4149

4150
        /* src and dst refer to an SDL_Surface* */
4151
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4152
        public static extern int SDL_SoftStretch(
4153
            IntPtr src,
4154
            ref SDL_Rect srcrect,
4155
            IntPtr dst,
4156
            ref SDL_Rect dstrect
4157
        );
4158

4159
        /* surface refers to an SDL_Surface* */
4160
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4161
        public static extern void SDL_UnlockSurface(IntPtr surface);
4162

4163
        /* src and dst refer to an SDL_Surface* */
4164
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4165
        public static extern int SDL_UpperBlit(
4166
            IntPtr src,
4167
            ref SDL_Rect srcrect,
4168
            IntPtr dst,
4169
            ref SDL_Rect dstrect
4170
        );
4171

4172
        /* src and dst refer to an SDL_Surface* */
4173
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4174
        public static extern int SDL_UpperBlitScaled(
4175
            IntPtr src,
4176
            ref SDL_Rect srcrect,
4177
            IntPtr dst,
4178
            ref SDL_Rect dstrect
4179
        );
4180

4181
        /* surface and IntPtr refer to an SDL_Surface* */
4182
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4183
        public static extern IntPtr SDL_DuplicateSurface(IntPtr surface);
4184

4185
        #endregion
4186

4187
        #region SDL_clipboard.h
4188

4189
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4190
        public static extern SDL_bool SDL_HasClipboardText();
4191

4192
        [DllImport(nativeLibName, EntryPoint = "SDL_GetClipboardText", CallingConvention = CallingConvention.Cdecl)]
4193
        private static extern IntPtr INTERNAL_SDL_GetClipboardText();
4194
        public static string SDL_GetClipboardText()
4195
        {
4196
            return UTF8_ToManaged(INTERNAL_SDL_GetClipboardText(), true);
4197
        }
4198

4199
        [DllImport(nativeLibName, EntryPoint = "SDL_SetClipboardText", CallingConvention = CallingConvention.Cdecl)]
4200
        private static extern int INTERNAL_SDL_SetClipboardText(
4201
            byte[] text
4202
        );
4203
        public static int SDL_SetClipboardText(
4204
            string text
4205
        )
4206
        {
4207
            return INTERNAL_SDL_SetClipboardText(
4208
                UTF8_ToNative(text)
4209
            );
4210
        }
4211

4212
        #endregion
4213

4214
        #region SDL_events.h
4215

4216
        /* General keyboard/mouse state definitions. */
4217
        public const byte SDL_PRESSED = 1;
4218
        public const byte SDL_RELEASED = 0;
4219

4220
        /* Default size is according to SDL2 default. */
4221
        public const int SDL_TEXTEDITINGEVENT_TEXT_SIZE = 32;
4222
        public const int SDL_TEXTINPUTEVENT_TEXT_SIZE = 32;
4223

4224
        /* The types of events that can be delivered. */
4225
        public enum SDL_EventType : uint
4226
        {
4227
            SDL_FIRSTEVENT = 0,
4228

4229
            /* Application events */
4230
            SDL_QUIT = 0x100,
4231

4232
            /* iOS/Android/WinRT app events */
4233
            SDL_APP_TERMINATING,
4234
            SDL_APP_LOWMEMORY,
4235
            SDL_APP_WILLENTERBACKGROUND,
4236
            SDL_APP_DIDENTERBACKGROUND,
4237
            SDL_APP_WILLENTERFOREGROUND,
4238
            SDL_APP_DIDENTERFOREGROUND,
4239

4240
            /* Display events */
4241
            /* Only available in SDL 2.0.9 or higher. */
4242
            SDL_DISPLAYEVENT = 0x150,
4243

4244
            /* Window events */
4245
            SDL_WINDOWEVENT = 0x200,
4246
            SDL_SYSWMEVENT,
4247

4248
            /* Keyboard events */
4249
            SDL_KEYDOWN = 0x300,
4250
            SDL_KEYUP,
4251
            SDL_TEXTEDITING,
4252
            SDL_TEXTINPUT,
4253
            SDL_KEYMAPCHANGED,
4254

4255
            /* Mouse events */
4256
            SDL_MOUSEMOTION = 0x400,
4257
            SDL_MOUSEBUTTONDOWN,
4258
            SDL_MOUSEBUTTONUP,
4259
            SDL_MOUSEWHEEL,
4260

4261
            /* Joystick events */
4262
            SDL_JOYAXISMOTION = 0x600,
4263
            SDL_JOYBALLMOTION,
4264
            SDL_JOYHATMOTION,
4265
            SDL_JOYBUTTONDOWN,
4266
            SDL_JOYBUTTONUP,
4267
            SDL_JOYDEVICEADDED,
4268
            SDL_JOYDEVICEREMOVED,
4269
            SDL_JOYBATTERYUPDATED, // 1543
4270

4271
            /* Game controller events */
4272
            SDL_CONTROLLERAXISMOTION = 0x650,
4273
            SDL_CONTROLLERBUTTONDOWN,
4274
            SDL_CONTROLLERBUTTONUP,
4275
            SDL_CONTROLLERDEVICEADDED,
4276
            SDL_CONTROLLERDEVICEREMOVED,
4277
            SDL_CONTROLLERDEVICEREMAPPED,
4278

4279
            /* Touch events */
4280
            SDL_FINGERDOWN = 0x700,
4281
            SDL_FINGERUP,
4282
            SDL_FINGERMOTION,
4283

4284
            /* Gesture events */
4285
            SDL_DOLLARGESTURE = 0x800,
4286
            SDL_DOLLARRECORD,
4287
            SDL_MULTIGESTURE,
4288

4289
            /* Clipboard events */
4290
            SDL_CLIPBOARDUPDATE = 0x900,
4291

4292
            /* Drag and drop events */
4293
            SDL_DROPFILE = 0x1000,
4294
            /* Only available in 2.0.4 or higher. */
4295
            SDL_DROPTEXT,
4296
            SDL_DROPBEGIN,
4297
            SDL_DROPCOMPLETE,
4298

4299
            /* Audio hotplug events */
4300
            /* Only available in SDL 2.0.4 or higher. */
4301
            SDL_AUDIODEVICEADDED = 0x1100,
4302
            SDL_AUDIODEVICEREMOVED,
4303

4304
            /* Sensor events */
4305
            /* Only available in SDL 2.0.9 or higher. */
4306
            SDL_SENSORUPDATE = 0x1200,
4307

4308
            /* Render events */
4309
            /* Only available in SDL 2.0.2 or higher. */
4310
            SDL_RENDER_TARGETS_RESET = 0x2000,
4311
            /* Only available in SDL 2.0.4 or higher. */
4312
            SDL_RENDER_DEVICE_RESET,
4313

4314
            /* Events SDL_USEREVENT through SDL_LASTEVENT are for
4315
             * your use, and should be allocated with
4316
             * SDL_RegisterEvents()
4317
             */
4318
            SDL_USEREVENT = 0x8000,
4319

4320
            /* The last event, used for bouding arrays. */
4321
            SDL_LASTEVENT = 0xFFFF
4322
        }
4323

4324
        /* Only available in 2.0.4 or higher. */
4325
        public enum SDL_MouseWheelDirection : uint
4326
        {
4327
            SDL_MOUSEWHEEL_NORMAL,
4328
            SDL_MOUSEWHEEL_FLIPPED
4329
        }
4330

4331
        /* Fields shared by every event */
4332
        [StructLayout(LayoutKind.Sequential)]
4333
        public struct SDL_GenericEvent
4334
        {
4335
            public SDL_EventType type;
4336
            public UInt32 timestamp;
4337
        }
4338

4339
        // Ignore private members used for padding in this struct
4340
#pragma warning disable 0169
4341
        [StructLayout(LayoutKind.Sequential)]
4342
        public struct SDL_DisplayEvent
4343
        {
4344
            public SDL_EventType type;
4345
            public UInt32 timestamp;
4346
            public UInt32 display;
4347
            public SDL_DisplayEventID displayEvent; // event, lolC#
4348
            private byte padding1;
4349
            private byte padding2;
4350
            private byte padding3;
4351
            public Int32 data1;
4352
        }
4353
#pragma warning restore 0169
4354

4355
        // Ignore private members used for padding in this struct
4356
#pragma warning disable 0169
4357
        /* Window state change event data (event.window.*) */
4358
        [StructLayout(LayoutKind.Sequential)]
4359
        public struct SDL_WindowEvent
4360
        {
4361
            public SDL_EventType type;
4362
            public UInt32 timestamp;
4363
            public UInt32 windowID;
4364
            public SDL_WindowEventID windowEvent; // event, lolC#
4365
            private byte padding1;
4366
            private byte padding2;
4367
            private byte padding3;
4368
            public Int32 data1;
4369
            public Int32 data2;
4370
        }
4371
#pragma warning restore 0169
4372

4373
        // Ignore private members used for padding in this struct
4374
#pragma warning disable 0169
4375
        /* Keyboard button event structure (event.key.*) */
4376
        [StructLayout(LayoutKind.Sequential)]
4377
        public struct SDL_KeyboardEvent
4378
        {
4379
            public SDL_EventType type;
4380
            public UInt32 timestamp;
4381
            public UInt32 windowID;
4382
            public byte state;
4383
            public byte repeat; /* non-zero if this is a repeat */
4384
            private byte padding2;
4385
            private byte padding3;
4386
            public SDL_Keysym keysym;
4387
        }
4388
#pragma warning restore 0169
4389

4390
        [StructLayout(LayoutKind.Sequential)]
4391
        public struct SDL_TextEditingEvent
4392
        {
4393
            public SDL_EventType type;
4394
            public UInt32 timestamp;
4395
            public UInt32 windowID;
4396
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = SDL_TEXTEDITINGEVENT_TEXT_SIZE, ArraySubType = UnmanagedType.I1)]
4397
            public byte[] text;
4398
            public Int32 start;
4399
            public Int32 length;
4400
        }
4401

4402
        [StructLayout(LayoutKind.Sequential)]
4403
        public struct SDL_TextInputEvent
4404
        {
4405
            public SDL_EventType type;
4406
            public UInt32 timestamp;
4407
            public UInt32 windowID;
4408
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = SDL_TEXTINPUTEVENT_TEXT_SIZE, ArraySubType = UnmanagedType.I1)]
4409
            public byte[] text;
4410
        }
4411

4412
        // Ignore private members used for padding in this struct
4413
#pragma warning disable 0169
4414
        /* Mouse motion event structure (event.motion.*) */
4415
        [StructLayout(LayoutKind.Sequential)]
4416
        public struct SDL_MouseMotionEvent
4417
        {
4418
            public SDL_EventType type;
4419
            public UInt32 timestamp;
4420
            public UInt32 windowID;
4421
            public UInt32 which;
4422
            public byte state; /* bitmask of buttons */
4423
            private byte padding1;
4424
            private byte padding2;
4425
            private byte padding3;
4426
            public Int32 x;
4427
            public Int32 y;
4428
            public Int32 xrel;
4429
            public Int32 yrel;
4430
        }
4431
#pragma warning restore 0169
4432

4433
        // Ignore private members used for padding in this struct
4434
#pragma warning disable 0169
4435
        /* Mouse button event structure (event.button.*) */
4436
        [StructLayout(LayoutKind.Sequential)]
4437
        public struct SDL_MouseButtonEvent
4438
        {
4439
            public SDL_EventType type;
4440
            public UInt32 timestamp;
4441
            public UInt32 windowID;
4442
            public UInt32 which;
4443
            public byte button; /* button id */
4444
            public byte state; /* SDL_PRESSED or SDL_RELEASED */
4445
            public byte clicks; /* 1 for single-click, 2 for double-click, etc. */
4446
            private byte padding1;
4447
            public Int32 x;
4448
            public Int32 y;
4449
        }
4450
#pragma warning restore 0169
4451

4452
        /* Mouse wheel event structure (event.wheel.*) */
4453
        [StructLayout(LayoutKind.Sequential)]
4454
        public struct SDL_MouseWheelEvent
4455
        {
4456
            public SDL_EventType type;
4457
            public UInt32 timestamp;
4458
            public UInt32 windowID;
4459
            public UInt32 which;
4460
            public Int32 x; /* amount scrolled horizontally */
4461
            public Int32 y; /* amount scrolled vertically */
4462
            public UInt32 direction; /* Set to one of the SDL_MOUSEWHEEL_* defines */
4463
        }
4464

4465
        // Ignore private members used for padding in this struct
4466
#pragma warning disable 0169
4467
        /* Joystick axis motion event structure (event.jaxis.*) */
4468
        [StructLayout(LayoutKind.Sequential)]
4469
        public struct SDL_JoyAxisEvent
4470
        {
4471
            public SDL_EventType type;
4472
            public UInt32 timestamp;
4473
            public Int32 which; /* SDL_JoystickID */
4474
            public byte axis;
4475
            private byte padding1;
4476
            private byte padding2;
4477
            private byte padding3;
4478
            public Int16 axisValue; /* value, lolC# */
4479
            public UInt16 padding4;
4480
        }
4481
#pragma warning restore 0169
4482

4483
        // Ignore private members used for padding in this struct
4484
#pragma warning disable 0169
4485
        /* Joystick trackball motion event structure (event.jball.*) */
4486
        [StructLayout(LayoutKind.Sequential)]
4487
        public struct SDL_JoyBallEvent
4488
        {
4489
            public SDL_EventType type;
4490
            public UInt32 timestamp;
4491
            public Int32 which; /* SDL_JoystickID */
4492
            public byte ball;
4493
            private byte padding1;
4494
            private byte padding2;
4495
            private byte padding3;
4496
            public Int16 xrel;
4497
            public Int16 yrel;
4498
        }
4499
#pragma warning restore 0169
4500

4501
        // Ignore private members used for padding in this struct
4502
#pragma warning disable 0169
4503
        /* Joystick hat position change event struct (event.jhat.*) */
4504
        [StructLayout(LayoutKind.Sequential)]
4505
        public struct SDL_JoyHatEvent
4506
        {
4507
            public SDL_EventType type;
4508
            public UInt32 timestamp;
4509
            public Int32 which; /* SDL_JoystickID */
4510
            public byte hat; /* index of the hat */
4511
            public byte hatValue; /* value, lolC# */
4512
            private byte padding1;
4513
            private byte padding2;
4514
        }
4515
#pragma warning restore 0169
4516

4517
        // Ignore private members used for padding in this struct
4518
#pragma warning disable 0169
4519
        /* Joystick button event structure (event.jbutton.*) */
4520
        [StructLayout(LayoutKind.Sequential)]
4521
        public struct SDL_JoyButtonEvent
4522
        {
4523
            public SDL_EventType type;
4524
            public UInt32 timestamp;
4525
            public Int32 which; /* SDL_JoystickID */
4526
            public byte button;
4527
            public byte state; /* SDL_PRESSED or SDL_RELEASED */
4528
            private byte padding1;
4529
            private byte padding2;
4530
        }
4531
#pragma warning restore 0169
4532

4533
        /* Joystick device event structure (event.jdevice.*) */
4534
        [StructLayout(LayoutKind.Sequential)]
4535
        public struct SDL_JoyDeviceEvent
4536
        {
4537
            public SDL_EventType type;
4538
            public UInt32 timestamp;
4539
            public Int32 which; /* SDL_JoystickID */
4540
        }
4541

4542
        // Ignore private members used for padding in this struct
4543
#pragma warning disable 0169
4544
        /* Game controller axis motion event (event.caxis.*) */
4545
        [StructLayout(LayoutKind.Sequential)]
4546
        public struct SDL_ControllerAxisEvent
4547
        {
4548
            public SDL_EventType type;
4549
            public UInt32 timestamp;
4550
            public Int32 which; /* SDL_JoystickID */
4551
            public byte axis;
4552
            private byte padding1;
4553
            private byte padding2;
4554
            private byte padding3;
4555
            public Int16 axisValue; /* value, lolC# */
4556
            private UInt16 padding4;
4557
        }
4558
#pragma warning restore 0169
4559

4560
        // Ignore private members used for padding in this struct
4561
#pragma warning disable 0169
4562
        /* Game controller button event (event.cbutton.*) */
4563
        [StructLayout(LayoutKind.Sequential)]
4564
        public struct SDL_ControllerButtonEvent
4565
        {
4566
            public SDL_EventType type;
4567
            public UInt32 timestamp;
4568
            public Int32 which; /* SDL_JoystickID */
4569
            public byte button;
4570
            public byte state;
4571
            private byte padding1;
4572
            private byte padding2;
4573
        }
4574
#pragma warning restore 0169
4575

4576
        /* Game controller device event (event.cdevice.*) */
4577
        [StructLayout(LayoutKind.Sequential)]
4578
        public struct SDL_ControllerDeviceEvent
4579
        {
4580
            public SDL_EventType type;
4581
            public UInt32 timestamp;
4582
            public Int32 which;	/* joystick id for ADDED,
4583
						 * else instance id
4584
						 */
4585
        }
4586

4587
        // Ignore private members used for padding in this struct
4588
#pragma warning disable 0169
4589
        /* Audio device event (event.adevice.*) */
4590
        [StructLayout(LayoutKind.Sequential)]
4591
        public struct SDL_AudioDeviceEvent
4592
        {
4593
            public UInt32 type;
4594
            public UInt32 timestamp;
4595
            public UInt32 which;
4596
            public byte iscapture;
4597
            private byte padding1;
4598
            private byte padding2;
4599
            private byte padding3;
4600
        }
4601
#pragma warning restore 0169
4602

4603
        [StructLayout(LayoutKind.Sequential)]
4604
        public struct SDL_TouchFingerEvent
4605
        {
4606
            public UInt32 type;
4607
            public UInt32 timestamp;
4608
            public Int64 touchId; // SDL_TouchID
4609
            public Int64 fingerId; // SDL_GestureID
4610
            public float x;
4611
            public float y;
4612
            public float dx;
4613
            public float dy;
4614
            public float pressure;
4615
            public uint windowID;
4616
        }
4617

4618
        [StructLayout(LayoutKind.Sequential)]
4619
        public struct SDL_MultiGestureEvent
4620
        {
4621
            public UInt32 type;
4622
            public UInt32 timestamp;
4623
            public Int64 touchId; // SDL_TouchID
4624
            public float dTheta;
4625
            public float dDist;
4626
            public float x;
4627
            public float y;
4628
            public UInt16 numFingers;
4629
            public UInt16 padding;
4630
        }
4631

4632
        [StructLayout(LayoutKind.Sequential)]
4633
        public struct SDL_DollarGestureEvent
4634
        {
4635
            public UInt32 type;
4636
            public UInt32 timestamp;
4637
            public Int64 touchId; // SDL_TouchID
4638
            public Int64 gestureId; // SDL_GestureID
4639
            public UInt32 numFingers;
4640
            public float error;
4641
            public float x;
4642
            public float y;
4643
        }
4644

4645
        /* File open request by system (event.drop.*), enabled by
4646
         * default
4647
         */
4648
        [StructLayout(LayoutKind.Sequential)]
4649
        public struct SDL_DropEvent
4650
        {
4651
            public SDL_EventType type;
4652
            public UInt32 timestamp;
4653

4654
            /* char* filename, to be freed.
4655
             * Access the variable EXACTLY ONCE like this:
4656
             * string s = SDL.UTF8_ToManaged(evt.drop.file, true);
4657
             */
4658
            public IntPtr file;
4659
            public UInt32 windowID;
4660
        }
4661

4662
        [StructLayout(LayoutKind.Sequential)]
4663
        public struct SDL_SensorEvent
4664
        {
4665
            public SDL_EventType type;
4666
            public UInt32 timestamp;
4667
            public Int32 which;
4668
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
4669
            public float data;
4670
        }
4671

4672
        /* The "quit requested" event */
4673
        [StructLayout(LayoutKind.Sequential)]
4674
        public struct SDL_QuitEvent
4675
        {
4676
            public SDL_EventType type;
4677
            public UInt32 timestamp;
4678
        }
4679

4680
        /* A user defined event (event.user.*) */
4681
        [StructLayout(LayoutKind.Sequential)]
4682
        public struct SDL_UserEvent
4683
        {
4684
            public UInt32 type;
4685
            public UInt32 timestamp;
4686
            public UInt32 windowID;
4687
            public Int32 code;
4688
            public IntPtr data1; /* user-defined */
4689
            public IntPtr data2; /* user-defined */
4690
        }
4691

4692
        /* A video driver dependent event (event.syswm.*), disabled */
4693
        [StructLayout(LayoutKind.Sequential)]
4694
        public struct SDL_SysWMEvent
4695
        {
4696
            public SDL_EventType type;
4697
            public UInt32 timestamp;
4698
            public IntPtr msg; /* SDL_SysWMmsg*, system-dependent*/
4699
        }
4700

4701
        /* General event structure */
4702
        // C# doesn't do unions, so we do this ugly thing. */
4703
        [StructLayout(LayoutKind.Explicit, Size = 56)]
4704
        public struct SDL_Event
4705
        {
4706
            [FieldOffset(0)]
4707
            public SDL_EventType type;
4708
            [FieldOffset(0)]
4709
            public SDL_DisplayEvent display;
4710
            [FieldOffset(0)]
4711
            public SDL_WindowEvent window;
4712
            [FieldOffset(0)]
4713
            public SDL_KeyboardEvent key;
4714
            // [FieldOffset(0)]
4715
            // public SDL_TextEditingEvent edit;
4716
            // [FieldOffset(0)]
4717
            // public SDL_TextInputEvent text;
4718
            [FieldOffset(0)]
4719
            public SDL_MouseMotionEvent motion;
4720
            [FieldOffset(0)]
4721
            public SDL_MouseButtonEvent button;
4722
            [FieldOffset(0)]
4723
            public SDL_MouseWheelEvent wheel;
4724
            [FieldOffset(0)]
4725
            public SDL_JoyAxisEvent jaxis;
4726
            [FieldOffset(0)]
4727
            public SDL_JoyBallEvent jball;
4728
            [FieldOffset(0)]
4729
            public SDL_JoyHatEvent jhat;
4730
            [FieldOffset(0)]
4731
            public SDL_JoyButtonEvent jbutton;
4732
            [FieldOffset(0)]
4733
            public SDL_JoyDeviceEvent jdevice;
4734
            [FieldOffset(0)]
4735
            public SDL_ControllerAxisEvent caxis;
4736
            [FieldOffset(0)]
4737
            public SDL_ControllerButtonEvent cbutton;
4738
            [FieldOffset(0)]
4739
            public SDL_ControllerDeviceEvent cdevice;
4740
            [FieldOffset(0)]
4741
            public SDL_AudioDeviceEvent adevice;
4742
            // [FieldOffset(0)]
4743
            // public SDL_SensorEvent sensor;
4744
            [FieldOffset(0)]
4745
            public SDL_QuitEvent quit;
4746
            [FieldOffset(0)]
4747
            public SDL_UserEvent user;
4748
            [FieldOffset(0)]
4749
            public SDL_SysWMEvent syswm;
4750
            [FieldOffset(0)]
4751
            public SDL_TouchFingerEvent tfinger;
4752
            [FieldOffset(0)]
4753
            public SDL_MultiGestureEvent mgesture;
4754
            [FieldOffset(0)]
4755
            public SDL_DollarGestureEvent dgesture;
4756
            [FieldOffset(0)]
4757
            public SDL_DropEvent drop;
4758
        }
4759

4760
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
4761
        public delegate int SDL_EventFilter(
4762
            IntPtr userdata, // void*
4763
            IntPtr sdlevent // SDL_Event* event, lolC#
4764
        );
4765

4766
        /* Pump the event loop, getting events from the input devices*/
4767
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4768
        public static extern void SDL_PumpEvents();
4769

4770
        public enum SDL_eventaction
4771
        {
4772
            SDL_ADDEVENT,
4773
            SDL_PEEKEVENT,
4774
            SDL_GETEVENT
4775
        }
4776

4777
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4778
        public static extern int SDL_PeepEvents(
4779
            [Out] SDL_Event[] events,
4780
            int numevents,
4781
            SDL_eventaction action,
4782
            SDL_EventType minType,
4783
            SDL_EventType maxType
4784
        );
4785

4786
        /* Checks to see if certain events are in the event queue */
4787
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4788
        public static extern SDL_bool SDL_HasEvent(SDL_EventType type);
4789

4790
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4791
        public static extern SDL_bool SDL_HasEvents(
4792
            SDL_EventType minType,
4793
            SDL_EventType maxType
4794
        );
4795

4796
        /* Clears events from the event queue */
4797
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4798
        public static extern void SDL_FlushEvent(SDL_EventType type);
4799

4800
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4801
        public static extern void SDL_FlushEvents(
4802
            SDL_EventType min,
4803
            SDL_EventType max
4804
        );
4805

4806
        /* Polls for currently pending events */
4807
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4808
        public static extern int SDL_PollEvent(out SDL_Event _event);
4809

4810
        /* Waits indefinitely for the next event */
4811
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4812
        public static extern int SDL_WaitEvent(out SDL_Event _event);
4813

4814
        /* Waits until the specified timeout (in ms) for the next event
4815
         */
4816
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4817
        public static extern int SDL_WaitEventTimeout(out SDL_Event _event, int timeout);
4818

4819
        /* Add an event to the event queue */
4820
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4821
        public static extern int SDL_PushEvent(ref SDL_Event _event);
4822

4823
        /* userdata refers to a void* */
4824
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4825
        public static extern void SDL_SetEventFilter(
4826
            SDL_EventFilter filter,
4827
            IntPtr userdata
4828
        );
4829

4830
        /* userdata refers to a void* */
4831
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4832
        private static extern SDL_bool SDL_GetEventFilter(
4833
            out IntPtr filter,
4834
            out IntPtr userdata
4835
        );
4836
        public static SDL_bool SDL_GetEventFilter(
4837
            out SDL_EventFilter filter,
4838
            out IntPtr userdata
4839
        )
4840
        {
4841
            IntPtr result = IntPtr.Zero;
4842
            SDL_bool retval = SDL_GetEventFilter(out result, out userdata);
4843
            if (result != IntPtr.Zero)
4844
            {
4845
                filter = (SDL_EventFilter)Marshal.GetDelegateForFunctionPointer(
4846
                    result,
4847
                    typeof(SDL_EventFilter)
4848
                );
4849
            }
4850
            else
4851
            {
4852
                filter = null;
4853
            }
4854
            return retval;
4855
        }
4856

4857
        /* userdata refers to a void* */
4858
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4859
        public static extern void SDL_AddEventWatch(
4860
            SDL_EventFilter filter,
4861
            IntPtr userdata
4862
        );
4863

4864
        /* userdata refers to a void* */
4865
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4866
        public static extern void SDL_DelEventWatch(
4867
            SDL_EventFilter filter,
4868
            IntPtr userdata
4869
        );
4870

4871
        /* userdata refers to a void* */
4872
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4873
        public static extern void SDL_FilterEvents(
4874
            SDL_EventFilter filter,
4875
            IntPtr userdata
4876
        );
4877

4878
        /* These are for SDL_EventState() */
4879
        public const int SDL_QUERY = -1;
4880
        public const int SDL_IGNORE = 0;
4881
        public const int SDL_DISABLE = 0;
4882
        public const int SDL_ENABLE = 1;
4883

4884
        /* This function allows you to enable/disable certain events */
4885
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4886
        public static extern byte SDL_EventState(SDL_EventType type, int state);
4887

4888
        /* Get the state of an event */
4889
        public static byte SDL_GetEventState(SDL_EventType type)
4890
        {
4891
            return SDL_EventState(type, SDL_QUERY);
4892
        }
4893

4894
        /* Allocate a set of user-defined events */
4895
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
4896
        public static extern UInt32 SDL_RegisterEvents(int numevents);
4897
        #endregion
4898

4899
        #region SDL_scancode.h
4900

4901
        /* Scancodes based off USB keyboard page (0x07) */
4902
        public enum SDL_Scancode
4903
        {
4904
            SDL_SCANCODE_UNKNOWN = 0,
4905

4906
            SDL_SCANCODE_A = 4,
4907
            SDL_SCANCODE_B = 5,
4908
            SDL_SCANCODE_C = 6,
4909
            SDL_SCANCODE_D = 7,
4910
            SDL_SCANCODE_E = 8,
4911
            SDL_SCANCODE_F = 9,
4912
            SDL_SCANCODE_G = 10,
4913
            SDL_SCANCODE_H = 11,
4914
            SDL_SCANCODE_I = 12,
4915
            SDL_SCANCODE_J = 13,
4916
            SDL_SCANCODE_K = 14,
4917
            SDL_SCANCODE_L = 15,
4918
            SDL_SCANCODE_M = 16,
4919
            SDL_SCANCODE_N = 17,
4920
            SDL_SCANCODE_O = 18,
4921
            SDL_SCANCODE_P = 19,
4922
            SDL_SCANCODE_Q = 20,
4923
            SDL_SCANCODE_R = 21,
4924
            SDL_SCANCODE_S = 22,
4925
            SDL_SCANCODE_T = 23,
4926
            SDL_SCANCODE_U = 24,
4927
            SDL_SCANCODE_V = 25,
4928
            SDL_SCANCODE_W = 26,
4929
            SDL_SCANCODE_X = 27,
4930
            SDL_SCANCODE_Y = 28,
4931
            SDL_SCANCODE_Z = 29,
4932

4933
            SDL_SCANCODE_1 = 30,
4934
            SDL_SCANCODE_2 = 31,
4935
            SDL_SCANCODE_3 = 32,
4936
            SDL_SCANCODE_4 = 33,
4937
            SDL_SCANCODE_5 = 34,
4938
            SDL_SCANCODE_6 = 35,
4939
            SDL_SCANCODE_7 = 36,
4940
            SDL_SCANCODE_8 = 37,
4941
            SDL_SCANCODE_9 = 38,
4942
            SDL_SCANCODE_0 = 39,
4943

4944
            SDL_SCANCODE_RETURN = 40,
4945
            SDL_SCANCODE_ESCAPE = 41,
4946
            SDL_SCANCODE_BACKSPACE = 42,
4947
            SDL_SCANCODE_TAB = 43,
4948
            SDL_SCANCODE_SPACE = 44,
4949

4950
            SDL_SCANCODE_MINUS = 45,
4951
            SDL_SCANCODE_EQUALS = 46,
4952
            SDL_SCANCODE_LEFTBRACKET = 47,
4953
            SDL_SCANCODE_RIGHTBRACKET = 48,
4954
            SDL_SCANCODE_BACKSLASH = 49,
4955
            SDL_SCANCODE_NONUSHASH = 50,
4956
            SDL_SCANCODE_SEMICOLON = 51,
4957
            SDL_SCANCODE_APOSTROPHE = 52,
4958
            SDL_SCANCODE_GRAVE = 53,
4959
            SDL_SCANCODE_COMMA = 54,
4960
            SDL_SCANCODE_PERIOD = 55,
4961
            SDL_SCANCODE_SLASH = 56,
4962

4963
            SDL_SCANCODE_CAPSLOCK = 57,
4964

4965
            SDL_SCANCODE_F1 = 58,
4966
            SDL_SCANCODE_F2 = 59,
4967
            SDL_SCANCODE_F3 = 60,
4968
            SDL_SCANCODE_F4 = 61,
4969
            SDL_SCANCODE_F5 = 62,
4970
            SDL_SCANCODE_F6 = 63,
4971
            SDL_SCANCODE_F7 = 64,
4972
            SDL_SCANCODE_F8 = 65,
4973
            SDL_SCANCODE_F9 = 66,
4974
            SDL_SCANCODE_F10 = 67,
4975
            SDL_SCANCODE_F11 = 68,
4976
            SDL_SCANCODE_F12 = 69,
4977

4978
            SDL_SCANCODE_PRINTSCREEN = 70,
4979
            SDL_SCANCODE_SCROLLLOCK = 71,
4980
            SDL_SCANCODE_PAUSE = 72,
4981
            SDL_SCANCODE_INSERT = 73,
4982
            SDL_SCANCODE_HOME = 74,
4983
            SDL_SCANCODE_PAGEUP = 75,
4984
            SDL_SCANCODE_DELETE = 76,
4985
            SDL_SCANCODE_END = 77,
4986
            SDL_SCANCODE_PAGEDOWN = 78,
4987
            SDL_SCANCODE_RIGHT = 79,
4988
            SDL_SCANCODE_LEFT = 80,
4989
            SDL_SCANCODE_DOWN = 81,
4990
            SDL_SCANCODE_UP = 82,
4991

4992
            SDL_SCANCODE_NUMLOCKCLEAR = 83,
4993
            SDL_SCANCODE_KP_DIVIDE = 84,
4994
            SDL_SCANCODE_KP_MULTIPLY = 85,
4995
            SDL_SCANCODE_KP_MINUS = 86,
4996
            SDL_SCANCODE_KP_PLUS = 87,
4997
            SDL_SCANCODE_KP_ENTER = 88,
4998
            SDL_SCANCODE_KP_1 = 89,
4999
            SDL_SCANCODE_KP_2 = 90,
5000
            SDL_SCANCODE_KP_3 = 91,
5001
            SDL_SCANCODE_KP_4 = 92,
5002
            SDL_SCANCODE_KP_5 = 93,
5003
            SDL_SCANCODE_KP_6 = 94,
5004
            SDL_SCANCODE_KP_7 = 95,
5005
            SDL_SCANCODE_KP_8 = 96,
5006
            SDL_SCANCODE_KP_9 = 97,
5007
            SDL_SCANCODE_KP_0 = 98,
5008
            SDL_SCANCODE_KP_PERIOD = 99,
5009

5010
            SDL_SCANCODE_NONUSBACKSLASH = 100,
5011
            SDL_SCANCODE_APPLICATION = 101,
5012
            SDL_SCANCODE_POWER = 102,
5013
            SDL_SCANCODE_KP_EQUALS = 103,
5014
            SDL_SCANCODE_F13 = 104,
5015
            SDL_SCANCODE_F14 = 105,
5016
            SDL_SCANCODE_F15 = 106,
5017
            SDL_SCANCODE_F16 = 107,
5018
            SDL_SCANCODE_F17 = 108,
5019
            SDL_SCANCODE_F18 = 109,
5020
            SDL_SCANCODE_F19 = 110,
5021
            SDL_SCANCODE_F20 = 111,
5022
            SDL_SCANCODE_F21 = 112,
5023
            SDL_SCANCODE_F22 = 113,
5024
            SDL_SCANCODE_F23 = 114,
5025
            SDL_SCANCODE_F24 = 115,
5026
            SDL_SCANCODE_EXECUTE = 116,
5027
            SDL_SCANCODE_HELP = 117,
5028
            SDL_SCANCODE_MENU = 118,
5029
            SDL_SCANCODE_SELECT = 119,
5030
            SDL_SCANCODE_STOP = 120,
5031
            SDL_SCANCODE_AGAIN = 121,
5032
            SDL_SCANCODE_UNDO = 122,
5033
            SDL_SCANCODE_CUT = 123,
5034
            SDL_SCANCODE_COPY = 124,
5035
            SDL_SCANCODE_PASTE = 125,
5036
            SDL_SCANCODE_FIND = 126,
5037
            SDL_SCANCODE_MUTE = 127,
5038
            SDL_SCANCODE_VOLUMEUP = 128,
5039
            SDL_SCANCODE_VOLUMEDOWN = 129,
5040
            /* not sure whether there's a reason to enable these */
5041
            /*	SDL_SCANCODE_LOCKINGCAPSLOCK = 130, */
5042
            /*	SDL_SCANCODE_LOCKINGNUMLOCK = 131, */
5043
            /*	SDL_SCANCODE_LOCKINGSCROLLLOCK = 132, */
5044
            SDL_SCANCODE_KP_COMMA = 133,
5045
            SDL_SCANCODE_KP_EQUALSAS400 = 134,
5046

5047
            SDL_SCANCODE_INTERNATIONAL1 = 135,
5048
            SDL_SCANCODE_INTERNATIONAL2 = 136,
5049
            SDL_SCANCODE_INTERNATIONAL3 = 137,
5050
            SDL_SCANCODE_INTERNATIONAL4 = 138,
5051
            SDL_SCANCODE_INTERNATIONAL5 = 139,
5052
            SDL_SCANCODE_INTERNATIONAL6 = 140,
5053
            SDL_SCANCODE_INTERNATIONAL7 = 141,
5054
            SDL_SCANCODE_INTERNATIONAL8 = 142,
5055
            SDL_SCANCODE_INTERNATIONAL9 = 143,
5056
            SDL_SCANCODE_LANG1 = 144,
5057
            SDL_SCANCODE_LANG2 = 145,
5058
            SDL_SCANCODE_LANG3 = 146,
5059
            SDL_SCANCODE_LANG4 = 147,
5060
            SDL_SCANCODE_LANG5 = 148,
5061
            SDL_SCANCODE_LANG6 = 149,
5062
            SDL_SCANCODE_LANG7 = 150,
5063
            SDL_SCANCODE_LANG8 = 151,
5064
            SDL_SCANCODE_LANG9 = 152,
5065

5066
            SDL_SCANCODE_ALTERASE = 153,
5067
            SDL_SCANCODE_SYSREQ = 154,
5068
            SDL_SCANCODE_CANCEL = 155,
5069
            SDL_SCANCODE_CLEAR = 156,
5070
            SDL_SCANCODE_PRIOR = 157,
5071
            SDL_SCANCODE_RETURN2 = 158,
5072
            SDL_SCANCODE_SEPARATOR = 159,
5073
            SDL_SCANCODE_OUT = 160,
5074
            SDL_SCANCODE_OPER = 161,
5075
            SDL_SCANCODE_CLEARAGAIN = 162,
5076
            SDL_SCANCODE_CRSEL = 163,
5077
            SDL_SCANCODE_EXSEL = 164,
5078

5079
            SDL_SCANCODE_KP_00 = 176,
5080
            SDL_SCANCODE_KP_000 = 177,
5081
            SDL_SCANCODE_THOUSANDSSEPARATOR = 178,
5082
            SDL_SCANCODE_DECIMALSEPARATOR = 179,
5083
            SDL_SCANCODE_CURRENCYUNIT = 180,
5084
            SDL_SCANCODE_CURRENCYSUBUNIT = 181,
5085
            SDL_SCANCODE_KP_LEFTPAREN = 182,
5086
            SDL_SCANCODE_KP_RIGHTPAREN = 183,
5087
            SDL_SCANCODE_KP_LEFTBRACE = 184,
5088
            SDL_SCANCODE_KP_RIGHTBRACE = 185,
5089
            SDL_SCANCODE_KP_TAB = 186,
5090
            SDL_SCANCODE_KP_BACKSPACE = 187,
5091
            SDL_SCANCODE_KP_A = 188,
5092
            SDL_SCANCODE_KP_B = 189,
5093
            SDL_SCANCODE_KP_C = 190,
5094
            SDL_SCANCODE_KP_D = 191,
5095
            SDL_SCANCODE_KP_E = 192,
5096
            SDL_SCANCODE_KP_F = 193,
5097
            SDL_SCANCODE_KP_XOR = 194,
5098
            SDL_SCANCODE_KP_POWER = 195,
5099
            SDL_SCANCODE_KP_PERCENT = 196,
5100
            SDL_SCANCODE_KP_LESS = 197,
5101
            SDL_SCANCODE_KP_GREATER = 198,
5102
            SDL_SCANCODE_KP_AMPERSAND = 199,
5103
            SDL_SCANCODE_KP_DBLAMPERSAND = 200,
5104
            SDL_SCANCODE_KP_VERTICALBAR = 201,
5105
            SDL_SCANCODE_KP_DBLVERTICALBAR = 202,
5106
            SDL_SCANCODE_KP_COLON = 203,
5107
            SDL_SCANCODE_KP_HASH = 204,
5108
            SDL_SCANCODE_KP_SPACE = 205,
5109
            SDL_SCANCODE_KP_AT = 206,
5110
            SDL_SCANCODE_KP_EXCLAM = 207,
5111
            SDL_SCANCODE_KP_MEMSTORE = 208,
5112
            SDL_SCANCODE_KP_MEMRECALL = 209,
5113
            SDL_SCANCODE_KP_MEMCLEAR = 210,
5114
            SDL_SCANCODE_KP_MEMADD = 211,
5115
            SDL_SCANCODE_KP_MEMSUBTRACT = 212,
5116
            SDL_SCANCODE_KP_MEMMULTIPLY = 213,
5117
            SDL_SCANCODE_KP_MEMDIVIDE = 214,
5118
            SDL_SCANCODE_KP_PLUSMINUS = 215,
5119
            SDL_SCANCODE_KP_CLEAR = 216,
5120
            SDL_SCANCODE_KP_CLEARENTRY = 217,
5121
            SDL_SCANCODE_KP_BINARY = 218,
5122
            SDL_SCANCODE_KP_OCTAL = 219,
5123
            SDL_SCANCODE_KP_DECIMAL = 220,
5124
            SDL_SCANCODE_KP_HEXADECIMAL = 221,
5125

5126
            SDL_SCANCODE_LCTRL = 224,
5127
            SDL_SCANCODE_LSHIFT = 225,
5128
            SDL_SCANCODE_LALT = 226,
5129
            SDL_SCANCODE_LGUI = 227,
5130
            SDL_SCANCODE_RCTRL = 228,
5131
            SDL_SCANCODE_RSHIFT = 229,
5132
            SDL_SCANCODE_RALT = 230,
5133
            SDL_SCANCODE_RGUI = 231,
5134

5135
            SDL_SCANCODE_MODE = 257,
5136

5137
            /* These come from the USB consumer page (0x0C) */
5138
            SDL_SCANCODE_AUDIONEXT = 258,
5139
            SDL_SCANCODE_AUDIOPREV = 259,
5140
            SDL_SCANCODE_AUDIOSTOP = 260,
5141
            SDL_SCANCODE_AUDIOPLAY = 261,
5142
            SDL_SCANCODE_AUDIOMUTE = 262,
5143
            SDL_SCANCODE_MEDIASELECT = 263,
5144
            SDL_SCANCODE_WWW = 264,
5145
            SDL_SCANCODE_MAIL = 265,
5146
            SDL_SCANCODE_CALCULATOR = 266,
5147
            SDL_SCANCODE_COMPUTER = 267,
5148
            SDL_SCANCODE_AC_SEARCH = 268,
5149
            SDL_SCANCODE_AC_HOME = 269,
5150
            SDL_SCANCODE_AC_BACK = 270,
5151
            SDL_SCANCODE_AC_FORWARD = 271,
5152
            SDL_SCANCODE_AC_STOP = 272,
5153
            SDL_SCANCODE_AC_REFRESH = 273,
5154
            SDL_SCANCODE_AC_BOOKMARKS = 274,
5155

5156
            /* These come from other sources, and are mostly mac related */
5157
            SDL_SCANCODE_BRIGHTNESSDOWN = 275,
5158
            SDL_SCANCODE_BRIGHTNESSUP = 276,
5159
            SDL_SCANCODE_DISPLAYSWITCH = 277,
5160
            SDL_SCANCODE_KBDILLUMTOGGLE = 278,
5161
            SDL_SCANCODE_KBDILLUMDOWN = 279,
5162
            SDL_SCANCODE_KBDILLUMUP = 280,
5163
            SDL_SCANCODE_EJECT = 281,
5164
            SDL_SCANCODE_SLEEP = 282,
5165

5166
            SDL_SCANCODE_APP1 = 283,
5167
            SDL_SCANCODE_APP2 = 284,
5168

5169
            /* These come from the USB consumer page (0x0C) */
5170
            SDL_SCANCODE_AUDIOREWIND = 285,
5171
            SDL_SCANCODE_AUDIOFASTFORWARD = 286,
5172

5173
            /* This is not a key, simply marks the number of scancodes
5174
             * so that you know how big to make your arrays. */
5175
            SDL_NUM_SCANCODES = 512
5176
        }
5177

5178
        #endregion
5179

5180
        #region SDL_keycode.h
5181

5182
        public const int SDLK_SCANCODE_MASK = (1 << 30);
5183
        public static SDL_Keycode SDL_SCANCODE_TO_KEYCODE(SDL_Scancode X)
5184
        {
5185
            return (SDL_Keycode)((int)X | SDLK_SCANCODE_MASK);
5186
        }
5187

5188
        public enum SDL_Keycode
5189
        {
5190
            SDLK_UNKNOWN = 0,
5191

5192
            SDLK_RETURN = '\r',
5193
            SDLK_ESCAPE = 27, // '\033'
5194
            SDLK_BACKSPACE = '\b',
5195
            SDLK_TAB = '\t',
5196
            SDLK_SPACE = ' ',
5197
            SDLK_EXCLAIM = '!',
5198
            SDLK_QUOTEDBL = '"',
5199
            SDLK_HASH = '#',
5200
            SDLK_PERCENT = '%',
5201
            SDLK_DOLLAR = '$',
5202
            SDLK_AMPERSAND = '&',
5203
            SDLK_QUOTE = '\'',
5204
            SDLK_LEFTPAREN = '(',
5205
            SDLK_RIGHTPAREN = ')',
5206
            SDLK_ASTERISK = '*',
5207
            SDLK_PLUS = '+',
5208
            SDLK_COMMA = ',',
5209
            SDLK_MINUS = '-',
5210
            SDLK_PERIOD = '.',
5211
            SDLK_SLASH = '/',
5212
            SDLK_0 = '0',
5213
            SDLK_1 = '1',
5214
            SDLK_2 = '2',
5215
            SDLK_3 = '3',
5216
            SDLK_4 = '4',
5217
            SDLK_5 = '5',
5218
            SDLK_6 = '6',
5219
            SDLK_7 = '7',
5220
            SDLK_8 = '8',
5221
            SDLK_9 = '9',
5222
            SDLK_COLON = ':',
5223
            SDLK_SEMICOLON = ';',
5224
            SDLK_LESS = '<',
5225
            SDLK_EQUALS = '=',
5226
            SDLK_GREATER = '>',
5227
            SDLK_QUESTION = '?',
5228
            SDLK_AT = '@',
5229
            /*
5230
            Skip uppercase letters
5231
            */
5232
            SDLK_LEFTBRACKET = '[',
5233
            SDLK_BACKSLASH = '\\',
5234
            SDLK_RIGHTBRACKET = ']',
5235
            SDLK_CARET = '^',
5236
            SDLK_UNDERSCORE = '_',
5237
            SDLK_BACKQUOTE = '`',
5238
            SDLK_a = 'a',
5239
            SDLK_b = 'b',
5240
            SDLK_c = 'c',
5241
            SDLK_d = 'd',
5242
            SDLK_e = 'e',
5243
            SDLK_f = 'f',
5244
            SDLK_g = 'g',
5245
            SDLK_h = 'h',
5246
            SDLK_i = 'i',
5247
            SDLK_j = 'j',
5248
            SDLK_k = 'k',
5249
            SDLK_l = 'l',
5250
            SDLK_m = 'm',
5251
            SDLK_n = 'n',
5252
            SDLK_o = 'o',
5253
            SDLK_p = 'p',
5254
            SDLK_q = 'q',
5255
            SDLK_r = 'r',
5256
            SDLK_s = 's',
5257
            SDLK_t = 't',
5258
            SDLK_u = 'u',
5259
            SDLK_v = 'v',
5260
            SDLK_w = 'w',
5261
            SDLK_x = 'x',
5262
            SDLK_y = 'y',
5263
            SDLK_z = 'z',
5264

5265
            SDLK_CAPSLOCK = (int)SDL_Scancode.SDL_SCANCODE_CAPSLOCK | SDLK_SCANCODE_MASK,
5266

5267
            SDLK_F1 = (int)SDL_Scancode.SDL_SCANCODE_F1 | SDLK_SCANCODE_MASK,
5268
            SDLK_F2 = (int)SDL_Scancode.SDL_SCANCODE_F2 | SDLK_SCANCODE_MASK,
5269
            SDLK_F3 = (int)SDL_Scancode.SDL_SCANCODE_F3 | SDLK_SCANCODE_MASK,
5270
            SDLK_F4 = (int)SDL_Scancode.SDL_SCANCODE_F4 | SDLK_SCANCODE_MASK,
5271
            SDLK_F5 = (int)SDL_Scancode.SDL_SCANCODE_F5 | SDLK_SCANCODE_MASK,
5272
            SDLK_F6 = (int)SDL_Scancode.SDL_SCANCODE_F6 | SDLK_SCANCODE_MASK,
5273
            SDLK_F7 = (int)SDL_Scancode.SDL_SCANCODE_F7 | SDLK_SCANCODE_MASK,
5274
            SDLK_F8 = (int)SDL_Scancode.SDL_SCANCODE_F8 | SDLK_SCANCODE_MASK,
5275
            SDLK_F9 = (int)SDL_Scancode.SDL_SCANCODE_F9 | SDLK_SCANCODE_MASK,
5276
            SDLK_F10 = (int)SDL_Scancode.SDL_SCANCODE_F10 | SDLK_SCANCODE_MASK,
5277
            SDLK_F11 = (int)SDL_Scancode.SDL_SCANCODE_F11 | SDLK_SCANCODE_MASK,
5278
            SDLK_F12 = (int)SDL_Scancode.SDL_SCANCODE_F12 | SDLK_SCANCODE_MASK,
5279

5280
            SDLK_PRINTSCREEN = (int)SDL_Scancode.SDL_SCANCODE_PRINTSCREEN | SDLK_SCANCODE_MASK,
5281
            SDLK_SCROLLLOCK = (int)SDL_Scancode.SDL_SCANCODE_SCROLLLOCK | SDLK_SCANCODE_MASK,
5282
            SDLK_PAUSE = (int)SDL_Scancode.SDL_SCANCODE_PAUSE | SDLK_SCANCODE_MASK,
5283
            SDLK_INSERT = (int)SDL_Scancode.SDL_SCANCODE_INSERT | SDLK_SCANCODE_MASK,
5284
            SDLK_HOME = (int)SDL_Scancode.SDL_SCANCODE_HOME | SDLK_SCANCODE_MASK,
5285
            SDLK_PAGEUP = (int)SDL_Scancode.SDL_SCANCODE_PAGEUP | SDLK_SCANCODE_MASK,
5286
            SDLK_DELETE = 127,
5287
            SDLK_END = (int)SDL_Scancode.SDL_SCANCODE_END | SDLK_SCANCODE_MASK,
5288
            SDLK_PAGEDOWN = (int)SDL_Scancode.SDL_SCANCODE_PAGEDOWN | SDLK_SCANCODE_MASK,
5289
            SDLK_RIGHT = (int)SDL_Scancode.SDL_SCANCODE_RIGHT | SDLK_SCANCODE_MASK,
5290
            SDLK_LEFT = (int)SDL_Scancode.SDL_SCANCODE_LEFT | SDLK_SCANCODE_MASK,
5291
            SDLK_DOWN = (int)SDL_Scancode.SDL_SCANCODE_DOWN | SDLK_SCANCODE_MASK,
5292
            SDLK_UP = (int)SDL_Scancode.SDL_SCANCODE_UP | SDLK_SCANCODE_MASK,
5293

5294
            SDLK_NUMLOCKCLEAR = (int)SDL_Scancode.SDL_SCANCODE_NUMLOCKCLEAR | SDLK_SCANCODE_MASK,
5295
            SDLK_KP_DIVIDE = (int)SDL_Scancode.SDL_SCANCODE_KP_DIVIDE | SDLK_SCANCODE_MASK,
5296
            SDLK_KP_MULTIPLY = (int)SDL_Scancode.SDL_SCANCODE_KP_MULTIPLY | SDLK_SCANCODE_MASK,
5297
            SDLK_KP_MINUS = (int)SDL_Scancode.SDL_SCANCODE_KP_MINUS | SDLK_SCANCODE_MASK,
5298
            SDLK_KP_PLUS = (int)SDL_Scancode.SDL_SCANCODE_KP_PLUS | SDLK_SCANCODE_MASK,
5299
            SDLK_KP_ENTER = (int)SDL_Scancode.SDL_SCANCODE_KP_ENTER | SDLK_SCANCODE_MASK,
5300
            SDLK_KP_1 = (int)SDL_Scancode.SDL_SCANCODE_KP_1 | SDLK_SCANCODE_MASK,
5301
            SDLK_KP_2 = (int)SDL_Scancode.SDL_SCANCODE_KP_2 | SDLK_SCANCODE_MASK,
5302
            SDLK_KP_3 = (int)SDL_Scancode.SDL_SCANCODE_KP_3 | SDLK_SCANCODE_MASK,
5303
            SDLK_KP_4 = (int)SDL_Scancode.SDL_SCANCODE_KP_4 | SDLK_SCANCODE_MASK,
5304
            SDLK_KP_5 = (int)SDL_Scancode.SDL_SCANCODE_KP_5 | SDLK_SCANCODE_MASK,
5305
            SDLK_KP_6 = (int)SDL_Scancode.SDL_SCANCODE_KP_6 | SDLK_SCANCODE_MASK,
5306
            SDLK_KP_7 = (int)SDL_Scancode.SDL_SCANCODE_KP_7 | SDLK_SCANCODE_MASK,
5307
            SDLK_KP_8 = (int)SDL_Scancode.SDL_SCANCODE_KP_8 | SDLK_SCANCODE_MASK,
5308
            SDLK_KP_9 = (int)SDL_Scancode.SDL_SCANCODE_KP_9 | SDLK_SCANCODE_MASK,
5309
            SDLK_KP_0 = (int)SDL_Scancode.SDL_SCANCODE_KP_0 | SDLK_SCANCODE_MASK,
5310
            SDLK_KP_PERIOD = (int)SDL_Scancode.SDL_SCANCODE_KP_PERIOD | SDLK_SCANCODE_MASK,
5311

5312
            SDLK_APPLICATION = (int)SDL_Scancode.SDL_SCANCODE_APPLICATION | SDLK_SCANCODE_MASK,
5313
            SDLK_POWER = (int)SDL_Scancode.SDL_SCANCODE_POWER | SDLK_SCANCODE_MASK,
5314
            SDLK_KP_EQUALS = (int)SDL_Scancode.SDL_SCANCODE_KP_EQUALS | SDLK_SCANCODE_MASK,
5315
            SDLK_F13 = (int)SDL_Scancode.SDL_SCANCODE_F13 | SDLK_SCANCODE_MASK,
5316
            SDLK_F14 = (int)SDL_Scancode.SDL_SCANCODE_F14 | SDLK_SCANCODE_MASK,
5317
            SDLK_F15 = (int)SDL_Scancode.SDL_SCANCODE_F15 | SDLK_SCANCODE_MASK,
5318
            SDLK_F16 = (int)SDL_Scancode.SDL_SCANCODE_F16 | SDLK_SCANCODE_MASK,
5319
            SDLK_F17 = (int)SDL_Scancode.SDL_SCANCODE_F17 | SDLK_SCANCODE_MASK,
5320
            SDLK_F18 = (int)SDL_Scancode.SDL_SCANCODE_F18 | SDLK_SCANCODE_MASK,
5321
            SDLK_F19 = (int)SDL_Scancode.SDL_SCANCODE_F19 | SDLK_SCANCODE_MASK,
5322
            SDLK_F20 = (int)SDL_Scancode.SDL_SCANCODE_F20 | SDLK_SCANCODE_MASK,
5323
            SDLK_F21 = (int)SDL_Scancode.SDL_SCANCODE_F21 | SDLK_SCANCODE_MASK,
5324
            SDLK_F22 = (int)SDL_Scancode.SDL_SCANCODE_F22 | SDLK_SCANCODE_MASK,
5325
            SDLK_F23 = (int)SDL_Scancode.SDL_SCANCODE_F23 | SDLK_SCANCODE_MASK,
5326
            SDLK_F24 = (int)SDL_Scancode.SDL_SCANCODE_F24 | SDLK_SCANCODE_MASK,
5327
            SDLK_EXECUTE = (int)SDL_Scancode.SDL_SCANCODE_EXECUTE | SDLK_SCANCODE_MASK,
5328
            SDLK_HELP = (int)SDL_Scancode.SDL_SCANCODE_HELP | SDLK_SCANCODE_MASK,
5329
            SDLK_MENU = (int)SDL_Scancode.SDL_SCANCODE_MENU | SDLK_SCANCODE_MASK,
5330
            SDLK_SELECT = (int)SDL_Scancode.SDL_SCANCODE_SELECT | SDLK_SCANCODE_MASK,
5331
            SDLK_STOP = (int)SDL_Scancode.SDL_SCANCODE_STOP | SDLK_SCANCODE_MASK,
5332
            SDLK_AGAIN = (int)SDL_Scancode.SDL_SCANCODE_AGAIN | SDLK_SCANCODE_MASK,
5333
            SDLK_UNDO = (int)SDL_Scancode.SDL_SCANCODE_UNDO | SDLK_SCANCODE_MASK,
5334
            SDLK_CUT = (int)SDL_Scancode.SDL_SCANCODE_CUT | SDLK_SCANCODE_MASK,
5335
            SDLK_COPY = (int)SDL_Scancode.SDL_SCANCODE_COPY | SDLK_SCANCODE_MASK,
5336
            SDLK_PASTE = (int)SDL_Scancode.SDL_SCANCODE_PASTE | SDLK_SCANCODE_MASK,
5337
            SDLK_FIND = (int)SDL_Scancode.SDL_SCANCODE_FIND | SDLK_SCANCODE_MASK,
5338
            SDLK_MUTE = (int)SDL_Scancode.SDL_SCANCODE_MUTE | SDLK_SCANCODE_MASK,
5339
            SDLK_VOLUMEUP = (int)SDL_Scancode.SDL_SCANCODE_VOLUMEUP | SDLK_SCANCODE_MASK,
5340
            SDLK_VOLUMEDOWN = (int)SDL_Scancode.SDL_SCANCODE_VOLUMEDOWN | SDLK_SCANCODE_MASK,
5341
            SDLK_KP_COMMA = (int)SDL_Scancode.SDL_SCANCODE_KP_COMMA | SDLK_SCANCODE_MASK,
5342
            SDLK_KP_EQUALSAS400 =
5343
            (int)SDL_Scancode.SDL_SCANCODE_KP_EQUALSAS400 | SDLK_SCANCODE_MASK,
5344

5345
            SDLK_ALTERASE = (int)SDL_Scancode.SDL_SCANCODE_ALTERASE | SDLK_SCANCODE_MASK,
5346
            SDLK_SYSREQ = (int)SDL_Scancode.SDL_SCANCODE_SYSREQ | SDLK_SCANCODE_MASK,
5347
            SDLK_CANCEL = (int)SDL_Scancode.SDL_SCANCODE_CANCEL | SDLK_SCANCODE_MASK,
5348
            SDLK_CLEAR = (int)SDL_Scancode.SDL_SCANCODE_CLEAR | SDLK_SCANCODE_MASK,
5349
            SDLK_PRIOR = (int)SDL_Scancode.SDL_SCANCODE_PRIOR | SDLK_SCANCODE_MASK,
5350
            SDLK_RETURN2 = (int)SDL_Scancode.SDL_SCANCODE_RETURN2 | SDLK_SCANCODE_MASK,
5351
            SDLK_SEPARATOR = (int)SDL_Scancode.SDL_SCANCODE_SEPARATOR | SDLK_SCANCODE_MASK,
5352
            SDLK_OUT = (int)SDL_Scancode.SDL_SCANCODE_OUT | SDLK_SCANCODE_MASK,
5353
            SDLK_OPER = (int)SDL_Scancode.SDL_SCANCODE_OPER | SDLK_SCANCODE_MASK,
5354
            SDLK_CLEARAGAIN = (int)SDL_Scancode.SDL_SCANCODE_CLEARAGAIN | SDLK_SCANCODE_MASK,
5355
            SDLK_CRSEL = (int)SDL_Scancode.SDL_SCANCODE_CRSEL | SDLK_SCANCODE_MASK,
5356
            SDLK_EXSEL = (int)SDL_Scancode.SDL_SCANCODE_EXSEL | SDLK_SCANCODE_MASK,
5357

5358
            SDLK_KP_00 = (int)SDL_Scancode.SDL_SCANCODE_KP_00 | SDLK_SCANCODE_MASK,
5359
            SDLK_KP_000 = (int)SDL_Scancode.SDL_SCANCODE_KP_000 | SDLK_SCANCODE_MASK,
5360
            SDLK_THOUSANDSSEPARATOR =
5361
            (int)SDL_Scancode.SDL_SCANCODE_THOUSANDSSEPARATOR | SDLK_SCANCODE_MASK,
5362
            SDLK_DECIMALSEPARATOR =
5363
            (int)SDL_Scancode.SDL_SCANCODE_DECIMALSEPARATOR | SDLK_SCANCODE_MASK,
5364
            SDLK_CURRENCYUNIT = (int)SDL_Scancode.SDL_SCANCODE_CURRENCYUNIT | SDLK_SCANCODE_MASK,
5365
            SDLK_CURRENCYSUBUNIT =
5366
            (int)SDL_Scancode.SDL_SCANCODE_CURRENCYSUBUNIT | SDLK_SCANCODE_MASK,
5367
            SDLK_KP_LEFTPAREN = (int)SDL_Scancode.SDL_SCANCODE_KP_LEFTPAREN | SDLK_SCANCODE_MASK,
5368
            SDLK_KP_RIGHTPAREN = (int)SDL_Scancode.SDL_SCANCODE_KP_RIGHTPAREN | SDLK_SCANCODE_MASK,
5369
            SDLK_KP_LEFTBRACE = (int)SDL_Scancode.SDL_SCANCODE_KP_LEFTBRACE | SDLK_SCANCODE_MASK,
5370
            SDLK_KP_RIGHTBRACE = (int)SDL_Scancode.SDL_SCANCODE_KP_RIGHTBRACE | SDLK_SCANCODE_MASK,
5371
            SDLK_KP_TAB = (int)SDL_Scancode.SDL_SCANCODE_KP_TAB | SDLK_SCANCODE_MASK,
5372
            SDLK_KP_BACKSPACE = (int)SDL_Scancode.SDL_SCANCODE_KP_BACKSPACE | SDLK_SCANCODE_MASK,
5373
            SDLK_KP_A = (int)SDL_Scancode.SDL_SCANCODE_KP_A | SDLK_SCANCODE_MASK,
5374
            SDLK_KP_B = (int)SDL_Scancode.SDL_SCANCODE_KP_B | SDLK_SCANCODE_MASK,
5375
            SDLK_KP_C = (int)SDL_Scancode.SDL_SCANCODE_KP_C | SDLK_SCANCODE_MASK,
5376
            SDLK_KP_D = (int)SDL_Scancode.SDL_SCANCODE_KP_D | SDLK_SCANCODE_MASK,
5377
            SDLK_KP_E = (int)SDL_Scancode.SDL_SCANCODE_KP_E | SDLK_SCANCODE_MASK,
5378
            SDLK_KP_F = (int)SDL_Scancode.SDL_SCANCODE_KP_F | SDLK_SCANCODE_MASK,
5379
            SDLK_KP_XOR = (int)SDL_Scancode.SDL_SCANCODE_KP_XOR | SDLK_SCANCODE_MASK,
5380
            SDLK_KP_POWER = (int)SDL_Scancode.SDL_SCANCODE_KP_POWER | SDLK_SCANCODE_MASK,
5381
            SDLK_KP_PERCENT = (int)SDL_Scancode.SDL_SCANCODE_KP_PERCENT | SDLK_SCANCODE_MASK,
5382
            SDLK_KP_LESS = (int)SDL_Scancode.SDL_SCANCODE_KP_LESS | SDLK_SCANCODE_MASK,
5383
            SDLK_KP_GREATER = (int)SDL_Scancode.SDL_SCANCODE_KP_GREATER | SDLK_SCANCODE_MASK,
5384
            SDLK_KP_AMPERSAND = (int)SDL_Scancode.SDL_SCANCODE_KP_AMPERSAND | SDLK_SCANCODE_MASK,
5385
            SDLK_KP_DBLAMPERSAND =
5386
            (int)SDL_Scancode.SDL_SCANCODE_KP_DBLAMPERSAND | SDLK_SCANCODE_MASK,
5387
            SDLK_KP_VERTICALBAR =
5388
            (int)SDL_Scancode.SDL_SCANCODE_KP_VERTICALBAR | SDLK_SCANCODE_MASK,
5389
            SDLK_KP_DBLVERTICALBAR =
5390
            (int)SDL_Scancode.SDL_SCANCODE_KP_DBLVERTICALBAR | SDLK_SCANCODE_MASK,
5391
            SDLK_KP_COLON = (int)SDL_Scancode.SDL_SCANCODE_KP_COLON | SDLK_SCANCODE_MASK,
5392
            SDLK_KP_HASH = (int)SDL_Scancode.SDL_SCANCODE_KP_HASH | SDLK_SCANCODE_MASK,
5393
            SDLK_KP_SPACE = (int)SDL_Scancode.SDL_SCANCODE_KP_SPACE | SDLK_SCANCODE_MASK,
5394
            SDLK_KP_AT = (int)SDL_Scancode.SDL_SCANCODE_KP_AT | SDLK_SCANCODE_MASK,
5395
            SDLK_KP_EXCLAM = (int)SDL_Scancode.SDL_SCANCODE_KP_EXCLAM | SDLK_SCANCODE_MASK,
5396
            SDLK_KP_MEMSTORE = (int)SDL_Scancode.SDL_SCANCODE_KP_MEMSTORE | SDLK_SCANCODE_MASK,
5397
            SDLK_KP_MEMRECALL = (int)SDL_Scancode.SDL_SCANCODE_KP_MEMRECALL | SDLK_SCANCODE_MASK,
5398
            SDLK_KP_MEMCLEAR = (int)SDL_Scancode.SDL_SCANCODE_KP_MEMCLEAR | SDLK_SCANCODE_MASK,
5399
            SDLK_KP_MEMADD = (int)SDL_Scancode.SDL_SCANCODE_KP_MEMADD | SDLK_SCANCODE_MASK,
5400
            SDLK_KP_MEMSUBTRACT =
5401
            (int)SDL_Scancode.SDL_SCANCODE_KP_MEMSUBTRACT | SDLK_SCANCODE_MASK,
5402
            SDLK_KP_MEMMULTIPLY =
5403
            (int)SDL_Scancode.SDL_SCANCODE_KP_MEMMULTIPLY | SDLK_SCANCODE_MASK,
5404
            SDLK_KP_MEMDIVIDE = (int)SDL_Scancode.SDL_SCANCODE_KP_MEMDIVIDE | SDLK_SCANCODE_MASK,
5405
            SDLK_KP_PLUSMINUS = (int)SDL_Scancode.SDL_SCANCODE_KP_PLUSMINUS | SDLK_SCANCODE_MASK,
5406
            SDLK_KP_CLEAR = (int)SDL_Scancode.SDL_SCANCODE_KP_CLEAR | SDLK_SCANCODE_MASK,
5407
            SDLK_KP_CLEARENTRY = (int)SDL_Scancode.SDL_SCANCODE_KP_CLEARENTRY | SDLK_SCANCODE_MASK,
5408
            SDLK_KP_BINARY = (int)SDL_Scancode.SDL_SCANCODE_KP_BINARY | SDLK_SCANCODE_MASK,
5409
            SDLK_KP_OCTAL = (int)SDL_Scancode.SDL_SCANCODE_KP_OCTAL | SDLK_SCANCODE_MASK,
5410
            SDLK_KP_DECIMAL = (int)SDL_Scancode.SDL_SCANCODE_KP_DECIMAL | SDLK_SCANCODE_MASK,
5411
            SDLK_KP_HEXADECIMAL =
5412
            (int)SDL_Scancode.SDL_SCANCODE_KP_HEXADECIMAL | SDLK_SCANCODE_MASK,
5413

5414
            SDLK_LCTRL = (int)SDL_Scancode.SDL_SCANCODE_LCTRL | SDLK_SCANCODE_MASK,
5415
            SDLK_LSHIFT = (int)SDL_Scancode.SDL_SCANCODE_LSHIFT | SDLK_SCANCODE_MASK,
5416
            SDLK_LALT = (int)SDL_Scancode.SDL_SCANCODE_LALT | SDLK_SCANCODE_MASK,
5417
            SDLK_LGUI = (int)SDL_Scancode.SDL_SCANCODE_LGUI | SDLK_SCANCODE_MASK,
5418
            SDLK_RCTRL = (int)SDL_Scancode.SDL_SCANCODE_RCTRL | SDLK_SCANCODE_MASK,
5419
            SDLK_RSHIFT = (int)SDL_Scancode.SDL_SCANCODE_RSHIFT | SDLK_SCANCODE_MASK,
5420
            SDLK_RALT = (int)SDL_Scancode.SDL_SCANCODE_RALT | SDLK_SCANCODE_MASK,
5421
            SDLK_RGUI = (int)SDL_Scancode.SDL_SCANCODE_RGUI | SDLK_SCANCODE_MASK,
5422

5423
            SDLK_MODE = (int)SDL_Scancode.SDL_SCANCODE_MODE | SDLK_SCANCODE_MASK,
5424

5425
            SDLK_AUDIONEXT = (int)SDL_Scancode.SDL_SCANCODE_AUDIONEXT | SDLK_SCANCODE_MASK,
5426
            SDLK_AUDIOPREV = (int)SDL_Scancode.SDL_SCANCODE_AUDIOPREV | SDLK_SCANCODE_MASK,
5427
            SDLK_AUDIOSTOP = (int)SDL_Scancode.SDL_SCANCODE_AUDIOSTOP | SDLK_SCANCODE_MASK,
5428
            SDLK_AUDIOPLAY = (int)SDL_Scancode.SDL_SCANCODE_AUDIOPLAY | SDLK_SCANCODE_MASK,
5429
            SDLK_AUDIOMUTE = (int)SDL_Scancode.SDL_SCANCODE_AUDIOMUTE | SDLK_SCANCODE_MASK,
5430
            SDLK_MEDIASELECT = (int)SDL_Scancode.SDL_SCANCODE_MEDIASELECT | SDLK_SCANCODE_MASK,
5431
            SDLK_WWW = (int)SDL_Scancode.SDL_SCANCODE_WWW | SDLK_SCANCODE_MASK,
5432
            SDLK_MAIL = (int)SDL_Scancode.SDL_SCANCODE_MAIL | SDLK_SCANCODE_MASK,
5433
            SDLK_CALCULATOR = (int)SDL_Scancode.SDL_SCANCODE_CALCULATOR | SDLK_SCANCODE_MASK,
5434
            SDLK_COMPUTER = (int)SDL_Scancode.SDL_SCANCODE_COMPUTER | SDLK_SCANCODE_MASK,
5435
            SDLK_AC_SEARCH = (int)SDL_Scancode.SDL_SCANCODE_AC_SEARCH | SDLK_SCANCODE_MASK,
5436
            SDLK_AC_HOME = (int)SDL_Scancode.SDL_SCANCODE_AC_HOME | SDLK_SCANCODE_MASK,
5437
            SDLK_AC_BACK = (int)SDL_Scancode.SDL_SCANCODE_AC_BACK | SDLK_SCANCODE_MASK,
5438
            SDLK_AC_FORWARD = (int)SDL_Scancode.SDL_SCANCODE_AC_FORWARD | SDLK_SCANCODE_MASK,
5439
            SDLK_AC_STOP = (int)SDL_Scancode.SDL_SCANCODE_AC_STOP | SDLK_SCANCODE_MASK,
5440
            SDLK_AC_REFRESH = (int)SDL_Scancode.SDL_SCANCODE_AC_REFRESH | SDLK_SCANCODE_MASK,
5441
            SDLK_AC_BOOKMARKS = (int)SDL_Scancode.SDL_SCANCODE_AC_BOOKMARKS | SDLK_SCANCODE_MASK,
5442

5443
            SDLK_BRIGHTNESSDOWN =
5444
            (int)SDL_Scancode.SDL_SCANCODE_BRIGHTNESSDOWN | SDLK_SCANCODE_MASK,
5445
            SDLK_BRIGHTNESSUP = (int)SDL_Scancode.SDL_SCANCODE_BRIGHTNESSUP | SDLK_SCANCODE_MASK,
5446
            SDLK_DISPLAYSWITCH = (int)SDL_Scancode.SDL_SCANCODE_DISPLAYSWITCH | SDLK_SCANCODE_MASK,
5447
            SDLK_KBDILLUMTOGGLE =
5448
            (int)SDL_Scancode.SDL_SCANCODE_KBDILLUMTOGGLE | SDLK_SCANCODE_MASK,
5449
            SDLK_KBDILLUMDOWN = (int)SDL_Scancode.SDL_SCANCODE_KBDILLUMDOWN | SDLK_SCANCODE_MASK,
5450
            SDLK_KBDILLUMUP = (int)SDL_Scancode.SDL_SCANCODE_KBDILLUMUP | SDLK_SCANCODE_MASK,
5451
            SDLK_EJECT = (int)SDL_Scancode.SDL_SCANCODE_EJECT | SDLK_SCANCODE_MASK,
5452
            SDLK_SLEEP = (int)SDL_Scancode.SDL_SCANCODE_SLEEP | SDLK_SCANCODE_MASK,
5453
            SDLK_APP1 = (int)SDL_Scancode.SDL_SCANCODE_APP1 | SDLK_SCANCODE_MASK,
5454
            SDLK_APP2 = (int)SDL_Scancode.SDL_SCANCODE_APP2 | SDLK_SCANCODE_MASK,
5455

5456
            SDLK_AUDIOREWIND = (int)SDL_Scancode.SDL_SCANCODE_AUDIOREWIND | SDLK_SCANCODE_MASK,
5457
            SDLK_AUDIOFASTFORWARD = (int)SDL_Scancode.SDL_SCANCODE_AUDIOFASTFORWARD | SDLK_SCANCODE_MASK
5458
        }
5459

5460
        /* Key modifiers (bitfield) */
5461
        [Flags]
5462
        public enum SDL_Keymod : ushort
5463
        {
5464
            KMOD_NONE = 0x0000,
5465
            KMOD_LSHIFT = 0x0001,
5466
            KMOD_RSHIFT = 0x0002,
5467
            KMOD_LCTRL = 0x0040,
5468
            KMOD_RCTRL = 0x0080,
5469
            KMOD_LALT = 0x0100,
5470
            KMOD_RALT = 0x0200,
5471
            KMOD_LGUI = 0x0400,
5472
            KMOD_RGUI = 0x0800,
5473
            KMOD_NUM = 0x1000,
5474
            KMOD_CAPS = 0x2000,
5475
            KMOD_MODE = 0x4000,
5476
            KMOD_RESERVED = 0x8000,
5477

5478
            /* These are defines in the SDL headers */
5479
            KMOD_CTRL = (KMOD_LCTRL | KMOD_RCTRL),
5480
            KMOD_SHIFT = (KMOD_LSHIFT | KMOD_RSHIFT),
5481
            KMOD_ALT = (KMOD_LALT | KMOD_RALT),
5482
            KMOD_GUI = (KMOD_LGUI | KMOD_RGUI)
5483
        }
5484

5485
        #endregion
5486

5487
        #region SDL_keyboard.h
5488

5489
        [StructLayout(LayoutKind.Sequential)]
5490
        public struct SDL_Keysym
5491
        {
5492
            public SDL_Scancode scancode;
5493
            public SDL_Keycode sym;
5494
            public SDL_Keymod mod; /* UInt16 */
5495
            public UInt32 unicode; /* Deprecated */
5496
        }
5497

5498
        /* Get the window which has kbd focus */
5499
        /* Return type is an SDL_Window pointer */
5500
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5501
        public static extern IntPtr SDL_GetKeyboardFocus();
5502

5503
        /* Get a snapshot of the keyboard state. */
5504
        /* Return value is a pointer to a UInt8 array */
5505
        /* Numkeys returns the size of the array if non-null */
5506
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5507
        public static extern IntPtr SDL_GetKeyboardState(out int numkeys);
5508

5509
        /* Get the current key modifier state for the keyboard. */
5510
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5511
        public static extern SDL_Keymod SDL_GetModState();
5512

5513
        /* Set the current key modifier state */
5514
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5515
        public static extern void SDL_SetModState(SDL_Keymod modstate);
5516

5517
        /* Get the key code corresponding to the given scancode
5518
         * with the current keyboard layout.
5519
         */
5520
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5521
        public static extern SDL_Keycode SDL_GetKeyFromScancode(SDL_Scancode scancode);
5522

5523
        /* Get the scancode for the given keycode */
5524
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5525
        public static extern SDL_Scancode SDL_GetScancodeFromKey(SDL_Keycode key);
5526

5527
        /* Wrapper for SDL_GetScancodeName */
5528
        [DllImport(nativeLibName, EntryPoint = "SDL_GetScancodeName", CallingConvention = CallingConvention.Cdecl)]
5529
        private static extern IntPtr INTERNAL_SDL_GetScancodeName(SDL_Scancode scancode);
5530
        public static string SDL_GetScancodeName(SDL_Scancode scancode)
5531
        {
5532
            return UTF8_ToManaged(
5533
                INTERNAL_SDL_GetScancodeName(scancode)
5534
            );
5535
        }
5536

5537
        /* Get a scancode from a human-readable name */
5538
        [DllImport(nativeLibName, EntryPoint = "SDL_GetScancodeFromName", CallingConvention = CallingConvention.Cdecl)]
5539
        private static extern SDL_Scancode INTERNAL_SDL_GetScancodeFromName(
5540
            byte[] name
5541
        );
5542
        public static SDL_Scancode SDL_GetScancodeFromName(string name)
5543
        {
5544
            return INTERNAL_SDL_GetScancodeFromName(
5545
                UTF8_ToNative(name)
5546
            );
5547
        }
5548

5549
        /* Wrapper for SDL_GetKeyName */
5550
        [DllImport(nativeLibName, EntryPoint = "SDL_GetKeyName", CallingConvention = CallingConvention.Cdecl)]
5551
        private static extern IntPtr INTERNAL_SDL_GetKeyName(SDL_Keycode key);
5552
        public static string SDL_GetKeyName(SDL_Keycode key)
5553
        {
5554
            return UTF8_ToManaged(INTERNAL_SDL_GetKeyName(key));
5555
        }
5556

5557
        /* Get a key code from a human-readable name */
5558
        [DllImport(nativeLibName, EntryPoint = "SDL_GetKeyFromName", CallingConvention = CallingConvention.Cdecl)]
5559
        private static extern SDL_Keycode INTERNAL_SDL_GetKeyFromName(
5560
            byte[] name
5561
        );
5562
        public static SDL_Keycode SDL_GetKeyFromName(string name)
5563
        {
5564
            return INTERNAL_SDL_GetKeyFromName(UTF8_ToNative(name));
5565
        }
5566

5567
        /* Start accepting Unicode text input events, show keyboard */
5568
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5569
        public static extern void SDL_StartTextInput();
5570

5571
        /* Check if unicode input events are enabled */
5572
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5573
        public static extern SDL_bool SDL_IsTextInputActive();
5574

5575
        /* Stop receiving any text input events, hide onscreen kbd */
5576
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5577
        public static extern void SDL_StopTextInput();
5578

5579
        /* Set the rectangle used for text input, hint for IME */
5580
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5581
        public static extern void SDL_SetTextInputRect(ref SDL_Rect rect);
5582

5583
        /* Does the platform support an on-screen keyboard? */
5584
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5585
        public static extern SDL_bool SDL_HasScreenKeyboardSupport();
5586

5587
        /* Is the on-screen keyboard shown for a given window? */
5588
        /* window is an SDL_Window pointer */
5589
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5590
        public static extern SDL_bool SDL_IsScreenKeyboardShown(IntPtr window);
5591

5592
        #endregion
5593

5594
        #region SDL_mouse.c
5595

5596
        /* Note: SDL_Cursor is a typedef normally. We'll treat it as
5597
		 * an IntPtr, because C# doesn't do typedefs. Yay!
5598
		 */
5599

5600
        /* System cursor types */
5601
        public enum SDL_SystemCursor
5602
        {
5603
            SDL_SYSTEM_CURSOR_ARROW,	// Arrow
5604
            SDL_SYSTEM_CURSOR_IBEAM,	// I-beam
5605
            SDL_SYSTEM_CURSOR_WAIT,		// Wait
5606
            SDL_SYSTEM_CURSOR_CROSSHAIR,	// Crosshair
5607
            SDL_SYSTEM_CURSOR_WAITARROW,	// Small wait cursor (or Wait if not available)
5608
            SDL_SYSTEM_CURSOR_SIZENWSE,	// Double arrow pointing northwest and southeast
5609
            SDL_SYSTEM_CURSOR_SIZENESW,	// Double arrow pointing northeast and southwest
5610
            SDL_SYSTEM_CURSOR_SIZEWE,	// Double arrow pointing west and east
5611
            SDL_SYSTEM_CURSOR_SIZENS,	// Double arrow pointing north and south
5612
            SDL_SYSTEM_CURSOR_SIZEALL,	// Four pointed arrow pointing north, south, east, and west
5613
            SDL_SYSTEM_CURSOR_NO,		// Slashed circle or crossbones
5614
            SDL_SYSTEM_CURSOR_HAND,		// Hand
5615
            SDL_NUM_SYSTEM_CURSORS
5616
        }
5617

5618
        /* Get the window which currently has mouse focus */
5619
        /* Return value is an SDL_Window pointer */
5620
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5621
        public static extern IntPtr SDL_GetMouseFocus();
5622

5623
        /* Get the current state of the mouse */
5624
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5625
        public static extern UInt32 SDL_GetMouseState(out int x, out int y);
5626

5627
        /* Get the current state of the mouse */
5628
        /* This overload allows for passing NULL to x */
5629
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5630
        public static extern UInt32 SDL_GetMouseState(IntPtr x, out int y);
5631

5632
        /* Get the current state of the mouse */
5633
        /* This overload allows for passing NULL to y */
5634
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5635
        public static extern UInt32 SDL_GetMouseState(out int x, IntPtr y);
5636

5637
        /* Get the current state of the mouse */
5638
        /* This overload allows for passing NULL to both x and y */
5639
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5640
        public static extern UInt32 SDL_GetMouseState(IntPtr x, IntPtr y);
5641

5642
        /* Get the current state of the mouse, in relation to the desktop.
5643
         * Only available in 2.0.4 or higher.
5644
         */
5645
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5646
        public static extern UInt32 SDL_GetGlobalMouseState(out int x, out int y);
5647

5648
        /* Get the current state of the mouse, in relation to the desktop.
5649
         * Only available in 2.0.4 or higher.
5650
         * This overload allows for passing NULL to x.
5651
         */
5652
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5653
        public static extern UInt32 SDL_GetGlobalMouseState(IntPtr x, out int y);
5654

5655
        /* Get the current state of the mouse, in relation to the desktop.
5656
         * Only available in 2.0.4 or higher.
5657
         * This overload allows for passing NULL to y.
5658
         */
5659
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5660
        public static extern UInt32 SDL_GetGlobalMouseState(out int x, IntPtr y);
5661

5662
        /* Get the current state of the mouse, in relation to the desktop.
5663
         * Only available in 2.0.4 or higher.
5664
         * This overload allows for passing NULL to both x and y
5665
         */
5666
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5667
        public static extern UInt32 SDL_GetGlobalMouseState(IntPtr x, IntPtr y);
5668

5669
        /* Get the mouse state with relative coords*/
5670
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5671
        public static extern UInt32 SDL_GetRelativeMouseState(out int x, out int y);
5672

5673
        /* Set the mouse cursor's position (within a window) */
5674
        /* window is an SDL_Window pointer */
5675
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5676
        public static extern void SDL_WarpMouseInWindow(IntPtr window, int x, int y);
5677

5678
        /* Set the mouse cursor's position in global screen space.
5679
         * Only available in 2.0.4 or higher.
5680
         */
5681
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5682
        public static extern int SDL_WarpMouseGlobal(int x, int y);
5683

5684
        /* Enable/Disable relative mouse mode (grabs mouse, rel coords) */
5685
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5686
        public static extern int SDL_SetRelativeMouseMode(SDL_bool enabled);
5687

5688
        /* Capture the mouse, to track input outside an SDL window.
5689
         * Only available in 2.0.4 or higher.
5690
         */
5691
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5692
        public static extern int SDL_CaptureMouse(SDL_bool enabled);
5693

5694
        /* Query if the relative mouse mode is enabled */
5695
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5696
        public static extern SDL_bool SDL_GetRelativeMouseMode();
5697

5698
        /* Create a cursor from bitmap data (amd mask) in MSB format.
5699
         * data and mask are byte arrays, and w must be a multiple of 8.
5700
         * return value is an SDL_Cursor pointer.
5701
         */
5702
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5703
        public static extern IntPtr SDL_CreateCursor(
5704
            IntPtr data,
5705
            IntPtr mask,
5706
            int w,
5707
            int h,
5708
            int hot_x,
5709
            int hot_y
5710
        );
5711

5712
        /* Create a cursor from an SDL_Surface.
5713
         * IntPtr refers to an SDL_Cursor*, surface to an SDL_Surface*
5714
         */
5715
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5716
        public static extern IntPtr SDL_CreateColorCursor(
5717
            IntPtr surface,
5718
            int hot_x,
5719
            int hot_y
5720
        );
5721

5722
        /* Create a cursor from a system cursor id.
5723
         * return value is an SDL_Cursor pointer
5724
         */
5725
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5726
        public static extern IntPtr SDL_CreateSystemCursor(SDL_SystemCursor id);
5727

5728
        /* Set the active cursor.
5729
         * cursor is an SDL_Cursor pointer
5730
         */
5731
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5732
        public static extern void SDL_SetCursor(IntPtr cursor);
5733

5734
        /* Return the active cursor
5735
         * return value is an SDL_Cursor pointer
5736
         */
5737
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5738
        public static extern IntPtr SDL_GetCursor();
5739

5740
        /* Frees a cursor created with one of the CreateCursor functions.
5741
         * cursor in an SDL_Cursor pointer
5742
         */
5743
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5744
        public static extern void SDL_FreeCursor(IntPtr cursor);
5745

5746
        /* Toggle whether or not the cursor is shown */
5747
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5748
        public static extern int SDL_ShowCursor(int toggle);
5749

5750
        public static uint SDL_BUTTON(uint X)
5751
        {
5752
            // If only there were a better way of doing this in C#
5753
            return (uint)(1 << ((int)X - 1));
5754
        }
5755

5756
        public const uint SDL_BUTTON_LEFT = 1;
5757
        public const uint SDL_BUTTON_MIDDLE = 2;
5758
        public const uint SDL_BUTTON_RIGHT = 3;
5759
        public const uint SDL_BUTTON_X1 = 4;
5760
        public const uint SDL_BUTTON_X2 = 5;
5761
        public static readonly UInt32 SDL_BUTTON_LMASK = SDL_BUTTON(SDL_BUTTON_LEFT);
5762
        public static readonly UInt32 SDL_BUTTON_MMASK = SDL_BUTTON(SDL_BUTTON_MIDDLE);
5763
        public static readonly UInt32 SDL_BUTTON_RMASK = SDL_BUTTON(SDL_BUTTON_RIGHT);
5764
        public static readonly UInt32 SDL_BUTTON_X1MASK = SDL_BUTTON(SDL_BUTTON_X1);
5765
        public static readonly UInt32 SDL_BUTTON_X2MASK = SDL_BUTTON(SDL_BUTTON_X2);
5766

5767
        #endregion
5768

5769
        #region SDL_touch.h
5770

5771
        public const uint SDL_TOUCH_MOUSEID = uint.MaxValue;
5772

5773
        public struct SDL_Finger
5774
        {
5775
            public long id; // SDL_FingerID
5776
            public float x;
5777
            public float y;
5778
            public float pressure;
5779
        }
5780

5781
        /* Only available in 2.0.10 or higher. */
5782
        public enum SDL_TouchDeviceType
5783
        {
5784
            SDL_TOUCH_DEVICE_INVALID = -1,
5785
            SDL_TOUCH_DEVICE_DIRECT,            /* touch screen with window-relative coordinates */
5786
            SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE, /* trackpad with absolute device coordinates */
5787
            SDL_TOUCH_DEVICE_INDIRECT_RELATIVE  /* trackpad with screen cursor-relative coordinates */
5788
        }
5789

5790
        /**
5791
         *  \brief Get the number of registered touch devices.
5792
         */
5793
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5794
        public static extern int SDL_GetNumTouchDevices();
5795

5796
        /**
5797
         *  \brief Get the touch ID with the given index, or 0 if the index is invalid.
5798
         */
5799
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5800
        public static extern long SDL_GetTouchDevice(int index);
5801

5802
        /**
5803
         *  \brief Get the number of active fingers for a given touch device.
5804
         */
5805
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5806
        public static extern int SDL_GetNumTouchFingers(long touchID);
5807

5808
        /**
5809
         *  \brief Get the finger object of the given touch, with the given index.
5810
         *  Returns pointer to SDL_Finger.
5811
         */
5812
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5813
        public static extern IntPtr SDL_GetTouchFinger(long touchID, int index);
5814

5815
        /* Only available in 2.0.10 or higher. */
5816
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5817
        public static extern SDL_TouchDeviceType SDL_GetTouchDeviceType(Int64 touchID);
5818

5819
        #endregion
5820

5821
        #region SDL_joystick.h
5822

5823
        public const byte SDL_HAT_CENTERED = 0x00;
5824
        public const byte SDL_HAT_UP = 0x01;
5825
        public const byte SDL_HAT_RIGHT = 0x02;
5826
        public const byte SDL_HAT_DOWN = 0x04;
5827
        public const byte SDL_HAT_LEFT = 0x08;
5828
        public const byte SDL_HAT_RIGHTUP = SDL_HAT_RIGHT | SDL_HAT_UP;
5829
        public const byte SDL_HAT_RIGHTDOWN = SDL_HAT_RIGHT | SDL_HAT_DOWN;
5830
        public const byte SDL_HAT_LEFTUP = SDL_HAT_LEFT | SDL_HAT_UP;
5831
        public const byte SDL_HAT_LEFTDOWN = SDL_HAT_LEFT | SDL_HAT_DOWN;
5832

5833
        public enum SDL_JoystickPowerLevel
5834
        {
5835
            SDL_JOYSTICK_POWER_UNKNOWN = -1,
5836
            SDL_JOYSTICK_POWER_EMPTY,
5837
            SDL_JOYSTICK_POWER_LOW,
5838
            SDL_JOYSTICK_POWER_MEDIUM,
5839
            SDL_JOYSTICK_POWER_FULL,
5840
            SDL_JOYSTICK_POWER_WIRED,
5841
            SDL_JOYSTICK_POWER_MAX
5842
        }
5843

5844
        public enum SDL_JoystickType
5845
        {
5846
            SDL_JOYSTICK_TYPE_UNKNOWN,
5847
            SDL_JOYSTICK_TYPE_GAMECONTROLLER,
5848
            SDL_JOYSTICK_TYPE_WHEEL,
5849
            SDL_JOYSTICK_TYPE_ARCADE_STICK,
5850
            SDL_JOYSTICK_TYPE_FLIGHT_STICK,
5851
            SDL_JOYSTICK_TYPE_DANCE_PAD,
5852
            SDL_JOYSTICK_TYPE_GUITAR,
5853
            SDL_JOYSTICK_TYPE_DRUM_KIT,
5854
            SDL_JOYSTICK_TYPE_ARCADE_PAD
5855
        }
5856

5857
        /* joystick refers to an SDL_Joystick*.
5858
         * Only available in 2.0.9 or higher.
5859
         */
5860
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5861
        public static extern int SDL_JoystickRumble(
5862
            IntPtr joystick,
5863
            UInt16 low_frequency_rumble,
5864
            UInt16 high_frequency_rumble,
5865
            UInt32 duration_ms
5866
        );
5867

5868
        /* joystick refers to an SDL_Joystick* */
5869
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5870
        public static extern void SDL_JoystickClose(IntPtr joystick);
5871

5872
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5873
        public static extern int SDL_JoystickEventState(int state);
5874

5875
        /* joystick refers to an SDL_Joystick* */
5876
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5877
        public static extern short SDL_JoystickGetAxis(
5878
            IntPtr joystick,
5879
            int axis
5880
        );
5881

5882
        /* joystick refers to an SDL_Joystick*.
5883
         * Only available in 2.0.6 or higher.
5884
         */
5885
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5886
        public static extern SDL_bool SDL_JoystickGetAxisInitialState(
5887
            IntPtr joystick,
5888
            int axis,
5889
            out ushort state
5890
        );
5891

5892
        /* joystick refers to an SDL_Joystick* */
5893
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5894
        public static extern int SDL_JoystickGetBall(
5895
            IntPtr joystick,
5896
            int ball,
5897
            out int dx,
5898
            out int dy
5899
        );
5900

5901
        /* joystick refers to an SDL_Joystick* */
5902
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5903
        public static extern byte SDL_JoystickGetButton(
5904
            IntPtr joystick,
5905
            int button
5906
        );
5907

5908
        /* joystick refers to an SDL_Joystick* */
5909
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5910
        public static extern byte SDL_JoystickGetHat(
5911
            IntPtr joystick,
5912
            int hat
5913
        );
5914

5915
        /* joystick refers to an SDL_Joystick* */
5916
        [DllImport(nativeLibName, EntryPoint = "SDL_JoystickName", CallingConvention = CallingConvention.Cdecl)]
5917
        private static extern IntPtr INTERNAL_SDL_JoystickName(
5918
            IntPtr joystick
5919
        );
5920
        public static string SDL_JoystickName(IntPtr joystick)
5921
        {
5922
            return UTF8_ToManaged(
5923
                INTERNAL_SDL_JoystickName(joystick)
5924
            );
5925
        }
5926

5927
        [DllImport(nativeLibName, EntryPoint = "SDL_JoystickNameForIndex", CallingConvention = CallingConvention.Cdecl)]
5928
        private static extern IntPtr INTERNAL_SDL_JoystickNameForIndex(
5929
            int device_index
5930
        );
5931
        public static string SDL_JoystickNameForIndex(int device_index)
5932
        {
5933
            return UTF8_ToManaged(
5934
                INTERNAL_SDL_JoystickNameForIndex(device_index)
5935
            );
5936
        }
5937

5938
        /* joystick refers to an SDL_Joystick* */
5939
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5940
        public static extern int SDL_JoystickNumAxes(IntPtr joystick);
5941

5942
        /* joystick refers to an SDL_Joystick* */
5943
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5944
        public static extern int SDL_JoystickNumBalls(IntPtr joystick);
5945

5946
        /* joystick refers to an SDL_Joystick* */
5947
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5948
        public static extern int SDL_JoystickNumButtons(IntPtr joystick);
5949

5950
        /* joystick refers to an SDL_Joystick* */
5951
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5952
        public static extern int SDL_JoystickNumHats(IntPtr joystick);
5953

5954
        /* IntPtr refers to an SDL_Joystick* */
5955
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5956
        public static extern IntPtr SDL_JoystickOpen(int device_index);
5957

5958
        /* joystick refers to an SDL_Joystick* */
5959
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5960
        public static extern void SDL_JoystickUpdate();
5961

5962
        /* joystick refers to an SDL_Joystick* */
5963
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5964
        public static extern int SDL_NumJoysticks();
5965

5966
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5967
        public static extern Guid SDL_JoystickGetDeviceGUID(
5968
            int device_index
5969
        );
5970

5971
        /* joystick refers to an SDL_Joystick* */
5972
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5973
        public static extern Guid SDL_JoystickGetGUID(
5974
            IntPtr joystick
5975
        );
5976

5977
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5978
        public static extern void SDL_JoystickGetGUIDString(
5979
            Guid guid,
5980
            byte[] pszGUID,
5981
            int cbGUID
5982
        );
5983

5984
        [DllImport(nativeLibName, EntryPoint = "SDL_JoystickGetGUIDFromString", CallingConvention = CallingConvention.Cdecl)]
5985
        private static extern Guid INTERNAL_SDL_JoystickGetGUIDFromString(
5986
            byte[] pchGUID
5987
        );
5988
        public static Guid SDL_JoystickGetGUIDFromString(string pchGuid)
5989
        {
5990
            return INTERNAL_SDL_JoystickGetGUIDFromString(
5991
                UTF8_ToNative(pchGuid)
5992
            );
5993
        }
5994

5995
        /* Only available in 2.0.6 or higher. */
5996
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
5997
        public static extern ushort SDL_JoystickGetDeviceVendor(int device_index);
5998

5999
        /* Only available in 2.0.6 or higher. */
6000
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6001
        public static extern ushort SDL_JoystickGetDeviceProduct(int device_index);
6002

6003
        /* Only available in 2.0.6 or higher. */
6004
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6005
        public static extern ushort SDL_JoystickGetDeviceProductVersion(int device_index);
6006

6007
        /* Only available in 2.0.6 or higher. */
6008
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6009
        public static extern SDL_JoystickType SDL_JoystickGetDeviceType(int device_index);
6010

6011
        /* int refers to an SDL_JoystickID.
6012
         * Only available in 2.0.6 or higher.
6013
         */
6014
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6015
        public static extern int SDL_JoystickGetDeviceInstanceID(int device_index);
6016

6017
        /* joystick refers to an SDL_Joystick*.
6018
         * Only available in 2.0.6 or higher.
6019
         */
6020
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6021
        public static extern ushort SDL_JoystickGetVendor(IntPtr joystick);
6022

6023
        /* joystick refers to an SDL_Joystick*.
6024
         * Only available in 2.0.6 or higher.
6025
         */
6026
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6027
        public static extern ushort SDL_JoystickGetProduct(IntPtr joystick);
6028

6029
        /* joystick refers to an SDL_Joystick*.
6030
         * Only available in 2.0.6 or higher.
6031
         */
6032
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6033
        public static extern ushort SDL_JoystickGetProductVersion(IntPtr joystick);
6034

6035
        /* joystick refers to an SDL_Joystick*.
6036
         * Only available in 2.0.6 or higher.
6037
         */
6038
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6039
        public static extern SDL_JoystickType SDL_JoystickGetType(IntPtr joystick);
6040

6041
        /* joystick refers to an SDL_Joystick* */
6042
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6043
        public static extern SDL_bool SDL_JoystickGetAttached(IntPtr joystick);
6044

6045
        /* int refers to an SDL_JoystickID, joystick to an SDL_Joystick* */
6046
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6047
        public static extern int SDL_JoystickInstanceID(IntPtr joystick);
6048

6049
        /* joystick refers to an SDL_Joystick*.
6050
         * Only available in 2.0.4 or higher.
6051
         */
6052
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6053
        public static extern SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(
6054
            IntPtr joystick
6055
        );
6056

6057
        /* int refers to an SDL_JoystickID, IntPtr to an SDL_Joystick*.
6058
         * Only available in 2.0.4 or higher.
6059
         */
6060
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6061
        public static extern IntPtr SDL_JoystickFromInstanceID(int instance_id);
6062

6063
        /* Only available in 2.0.7 or higher. */
6064
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6065
        public static extern void SDL_LockJoysticks();
6066

6067
        /* Only available in 2.0.7 or higher. */
6068
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6069
        public static extern void SDL_UnlockJoysticks();
6070

6071
        /* IntPtr refers to an SDL_Joystick*.
6072
         * Only available in 2.0.11 or higher.
6073
         */
6074
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6075
        public static extern IntPtr SDL_JoystickFromPlayerIndex(int player_index);
6076

6077
        /* IntPtr refers to an SDL_Joystick*.
6078
         * Only available in 2.0.11 or higher.
6079
         */
6080
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6081
        public static extern void SDL_JoystickSetPlayerIndex(
6082
            IntPtr joystick,
6083
            int player_index
6084
        );
6085

6086
        [DllImport(nativeLibName, EntryPoint = "SDL_JoystickPathForIndex", CallingConvention = CallingConvention.Cdecl)]
6087
        private static extern IntPtr INTERNAL_SDL_JoystickPathForIndex(int device_index);
6088

6089
        public static string SDL_JoystickPathForIndex(int device_index)
6090
        {
6091
            if (Version >= new Version(2, 24, 0 , 0))
6092
                return UTF8_ToManaged(INTERNAL_SDL_JoystickPathForIndex(device_index));
6093

6094
            return null;
6095
        }
6096

6097
        [DllImport(nativeLibName, EntryPoint = "SDL_JoystickPath", CallingConvention = CallingConvention.Cdecl)]
6098
        private static extern IntPtr INTERNAL_SDL_JoystickPath(IntPtr joystick);
6099
      
6100
        public static string SDL_JoystickPath(IntPtr joystick)
6101
        {
6102
            if (Version >= new Version(2, 24, 0, 0))
6103
                return UTF8_ToManaged(INTERNAL_SDL_JoystickPath(joystick));
6104

6105
            return null;
6106
        }
6107
        
6108

6109
        #endregion
6110

6111
        #region SDL_gamecontroller.h
6112

6113
        public enum SDL_GameControllerBindType
6114
        {
6115
            SDL_CONTROLLER_BINDTYPE_NONE,
6116
            SDL_CONTROLLER_BINDTYPE_BUTTON,
6117
            SDL_CONTROLLER_BINDTYPE_AXIS,
6118
            SDL_CONTROLLER_BINDTYPE_HAT
6119
        }
6120

6121
        public enum SDL_GameControllerAxis
6122
        {
6123
            SDL_CONTROLLER_AXIS_INVALID = -1,
6124
            SDL_CONTROLLER_AXIS_LEFTX,
6125
            SDL_CONTROLLER_AXIS_LEFTY,
6126
            SDL_CONTROLLER_AXIS_RIGHTX,
6127
            SDL_CONTROLLER_AXIS_RIGHTY,
6128
            SDL_CONTROLLER_AXIS_TRIGGERLEFT,
6129
            SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
6130
            SDL_CONTROLLER_AXIS_MAX
6131
        }
6132

6133
        public enum SDL_GameControllerButton
6134
        {
6135
            SDL_CONTROLLER_BUTTON_INVALID = -1,
6136
            SDL_CONTROLLER_BUTTON_A,
6137
            SDL_CONTROLLER_BUTTON_B,
6138
            SDL_CONTROLLER_BUTTON_X,
6139
            SDL_CONTROLLER_BUTTON_Y,
6140
            SDL_CONTROLLER_BUTTON_BACK,
6141
            SDL_CONTROLLER_BUTTON_GUIDE,
6142
            SDL_CONTROLLER_BUTTON_START,
6143
            SDL_CONTROLLER_BUTTON_LEFTSTICK,
6144
            SDL_CONTROLLER_BUTTON_RIGHTSTICK,
6145
            SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
6146
            SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
6147
            SDL_CONTROLLER_BUTTON_DPAD_UP,
6148
            SDL_CONTROLLER_BUTTON_DPAD_DOWN,
6149
            SDL_CONTROLLER_BUTTON_DPAD_LEFT,
6150
            SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
6151
            SDL_CONTROLLER_BUTTON_MAX,
6152
        }
6153

6154
        public enum SDL_GameControllerType
6155
        {
6156
            SDL_CONTROLLER_TYPE_UNKNOWN = 0,
6157
            SDL_CONTROLLER_TYPE_XBOX360,
6158
            SDL_CONTROLLER_TYPE_XBOXONE,
6159
            SDL_CONTROLLER_TYPE_PS3,
6160
            SDL_CONTROLLER_TYPE_PS4,
6161
            SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO
6162
        }
6163

6164
        // FIXME: I'd rather this somehow be private...
6165
        [StructLayout(LayoutKind.Sequential)]
6166
        public struct INTERNAL_GameControllerButtonBind_hat
6167
        {
6168
            public int hat;
6169
            public int hat_mask;
6170
        }
6171

6172
        // FIXME: I'd rather this somehow be private...
6173
        [StructLayout(LayoutKind.Explicit)]
6174
        public struct INTERNAL_GameControllerButtonBind_union
6175
        {
6176
            [FieldOffset(0)]
6177
            public int button;
6178
            [FieldOffset(0)]
6179
            public int axis;
6180
            [FieldOffset(0)]
6181
            public INTERNAL_GameControllerButtonBind_hat hat;
6182
        }
6183

6184
        [StructLayout(LayoutKind.Sequential)]
6185
        public struct SDL_GameControllerButtonBind
6186
        {
6187
            public SDL_GameControllerBindType bindType;
6188
            public INTERNAL_GameControllerButtonBind_union value;
6189
        }
6190

6191
        /* This exists to deal with C# being stupid about blittable types. */
6192
        [StructLayout(LayoutKind.Sequential)]
6193
        private struct INTERNAL_SDL_GameControllerButtonBind
6194
        {
6195
            public int bindType;
6196
            /* Largest data type in the union is two ints in size */
6197
            public int unionVal0;
6198
            public int unionVal1;
6199
        }
6200

6201
        [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerAddMapping", CallingConvention = CallingConvention.Cdecl)]
6202
        private static extern int INTERNAL_SDL_GameControllerAddMapping(
6203
            byte[] mappingString
6204
        );
6205
        public static int SDL_GameControllerAddMapping(
6206
            string mappingString
6207
        )
6208
        {
6209
            return INTERNAL_SDL_GameControllerAddMapping(
6210
                UTF8_ToNative(mappingString)
6211
            );
6212
        }
6213

6214
        /* Only available in 2.0.6 or higher. */
6215
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6216
        public static extern int SDL_GameControllerNumMappings();
6217

6218
        /* Only available in 2.0.6 or higher. */
6219
        [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerMappingForIndex", CallingConvention = CallingConvention.Cdecl)]
6220
        private static extern IntPtr INTERNAL_SDL_GameControllerMappingForIndex(int mapping_index);
6221
        public static string SDL_GameControllerMappingForIndex(int mapping_index)
6222
        {
6223
            return UTF8_ToManaged(
6224
                INTERNAL_SDL_GameControllerMappingForIndex(
6225
                    mapping_index
6226
                )
6227
            );
6228
        }
6229

6230
        /* THIS IS AN RWops FUNCTION! */
6231
        [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerAddMappingsFromRW", CallingConvention = CallingConvention.Cdecl)]
6232
        private static extern int INTERNAL_SDL_GameControllerAddMappingsFromRW(
6233
            IntPtr rw,
6234
            int freerw
6235
        );
6236
        public static int SDL_GameControllerAddMappingsFromFile(string file)
6237
        {
6238
            IntPtr rwops = SDL_RWFromFile(file, "rb");
6239
            return INTERNAL_SDL_GameControllerAddMappingsFromRW(rwops, 1);
6240
        }
6241

6242
        [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerMappingForGUID", CallingConvention = CallingConvention.Cdecl)]
6243
        private static extern IntPtr INTERNAL_SDL_GameControllerMappingForGUID(
6244
            Guid guid
6245
        );
6246
        public static string SDL_GameControllerMappingForGUID(Guid guid)
6247
        {
6248
            return UTF8_ToManaged(
6249
                INTERNAL_SDL_GameControllerMappingForGUID(guid)
6250
            );
6251
        }
6252

6253
        /* gamecontroller refers to an SDL_GameController* */
6254
        [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerMapping", CallingConvention = CallingConvention.Cdecl)]
6255
        private static extern IntPtr INTERNAL_SDL_GameControllerMapping(
6256
            IntPtr gamecontroller
6257
        );
6258
        public static string SDL_GameControllerMapping(
6259
            IntPtr gamecontroller
6260
        )
6261
        {
6262
            return UTF8_ToManaged(
6263
                INTERNAL_SDL_GameControllerMapping(
6264
                    gamecontroller
6265
                )
6266
            );
6267
        }
6268

6269
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6270
        public static extern SDL_bool SDL_IsGameController(int joystick_index);
6271

6272
        [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerNameForIndex", CallingConvention = CallingConvention.Cdecl)]
6273
        private static extern IntPtr INTERNAL_SDL_GameControllerNameForIndex(
6274
            int joystick_index
6275
        );
6276
        public static string SDL_GameControllerNameForIndex(
6277
            int joystick_index
6278
        )
6279
        {
6280
            return UTF8_ToManaged(
6281
                INTERNAL_SDL_GameControllerNameForIndex(joystick_index)
6282
            );
6283
        }
6284

6285
        /* Only available in 2.0.9 or higher. */
6286
        [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerMappingForDeviceIndex", CallingConvention = CallingConvention.Cdecl)]
6287
        private static extern IntPtr INTERNAL_SDL_GameControllerMappingForDeviceIndex(
6288
            int joystick_index
6289
        );
6290
        public static string SDL_GameControllerMappingForDeviceIndex(
6291
            int joystick_index
6292
        )
6293
        {
6294
            return UTF8_ToManaged(
6295
                INTERNAL_SDL_GameControllerMappingForDeviceIndex(joystick_index)
6296
            );
6297
        }
6298

6299
        /* IntPtr refers to an SDL_GameController* */
6300
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6301
        public static extern IntPtr SDL_GameControllerOpen(int joystick_index);
6302

6303
        /* gamecontroller refers to an SDL_GameController* */
6304
        [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerName", CallingConvention = CallingConvention.Cdecl)]
6305
        private static extern IntPtr INTERNAL_SDL_GameControllerName(
6306
            IntPtr gamecontroller
6307
        );
6308
        public static string SDL_GameControllerName(
6309
            IntPtr gamecontroller
6310
        )
6311
        {
6312
            return UTF8_ToManaged(
6313
                INTERNAL_SDL_GameControllerName(gamecontroller)
6314
            );
6315
        }
6316

6317
        /* gamecontroller refers to an SDL_GameController*.
6318
         * Only available in 2.0.6 or higher.
6319
         */
6320
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6321
        public static extern ushort SDL_GameControllerGetVendor(
6322
            IntPtr gamecontroller
6323
        );
6324

6325
        /* gamecontroller refers to an SDL_GameController*.
6326
         * Only available in 2.0.6 or higher.
6327
         */
6328
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6329
        public static extern ushort SDL_GameControllerGetProduct(
6330
            IntPtr gamecontroller
6331
        );
6332

6333
        /* gamecontroller refers to an SDL_GameController*.
6334
         * Only available in 2.0.6 or higher.
6335
         */
6336
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6337
        public static extern ushort SDL_GameControllerGetProductVersion(
6338
            IntPtr gamecontroller
6339
        );
6340

6341
        /* gamecontroller refers to an SDL_GameController* */
6342
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6343
        public static extern SDL_bool SDL_GameControllerGetAttached(
6344
            IntPtr gamecontroller
6345
        );
6346

6347
        /* IntPtr refers to an SDL_Joystick*
6348
         * gamecontroller refers to an SDL_GameController*
6349
         */
6350
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6351
        public static extern IntPtr SDL_GameControllerGetJoystick(
6352
            IntPtr gamecontroller
6353
        );
6354

6355
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6356
        public static extern int SDL_GameControllerEventState(int state);
6357

6358
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6359
        public static extern void SDL_GameControllerUpdate();
6360

6361
        [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetAxisFromString", CallingConvention = CallingConvention.Cdecl)]
6362
        private static extern SDL_GameControllerAxis INTERNAL_SDL_GameControllerGetAxisFromString(
6363
            byte[] pchString
6364
        );
6365
        public static SDL_GameControllerAxis SDL_GameControllerGetAxisFromString(
6366
            string pchString
6367
        )
6368
        {
6369
            return INTERNAL_SDL_GameControllerGetAxisFromString(
6370
                UTF8_ToNative(pchString)
6371
            );
6372
        }
6373

6374
        [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetStringForAxis", CallingConvention = CallingConvention.Cdecl)]
6375
        private static extern IntPtr INTERNAL_SDL_GameControllerGetStringForAxis(
6376
            SDL_GameControllerAxis axis
6377
        );
6378
        public static string SDL_GameControllerGetStringForAxis(
6379
            SDL_GameControllerAxis axis
6380
        )
6381
        {
6382
            return UTF8_ToManaged(
6383
                INTERNAL_SDL_GameControllerGetStringForAxis(
6384
                    axis
6385
                )
6386
            );
6387
        }
6388

6389
        /* gamecontroller refers to an SDL_GameController* */
6390
        [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetBindForAxis", CallingConvention = CallingConvention.Cdecl)]
6391
        private static extern INTERNAL_SDL_GameControllerButtonBind INTERNAL_SDL_GameControllerGetBindForAxis(
6392
            IntPtr gamecontroller,
6393
            SDL_GameControllerAxis axis
6394
        );
6395
        public static SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(
6396
            IntPtr gamecontroller,
6397
            SDL_GameControllerAxis axis
6398
        )
6399
        {
6400
            // This is guaranteed to never be null
6401
            INTERNAL_SDL_GameControllerButtonBind dumb = INTERNAL_SDL_GameControllerGetBindForAxis(
6402
                gamecontroller,
6403
                axis
6404
            );
6405
            SDL_GameControllerButtonBind result = new SDL_GameControllerButtonBind();
6406
            result.bindType = (SDL_GameControllerBindType)dumb.bindType;
6407
            result.value.hat.hat = dumb.unionVal0;
6408
            result.value.hat.hat_mask = dumb.unionVal1;
6409
            return result;
6410
        }
6411

6412
        /* gamecontroller refers to an SDL_GameController* */
6413
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6414
        public static extern short SDL_GameControllerGetAxis(
6415
            IntPtr gamecontroller,
6416
            SDL_GameControllerAxis axis
6417
        );
6418

6419
        [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetButtonFromString", CallingConvention = CallingConvention.Cdecl)]
6420
        private static extern SDL_GameControllerButton INTERNAL_SDL_GameControllerGetButtonFromString(
6421
            byte[] pchString
6422
        );
6423
        public static SDL_GameControllerButton SDL_GameControllerGetButtonFromString(
6424
            string pchString
6425
        )
6426
        {
6427
            return INTERNAL_SDL_GameControllerGetButtonFromString(
6428
                UTF8_ToNative(pchString)
6429
            );
6430
        }
6431

6432
        [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetStringForButton", CallingConvention = CallingConvention.Cdecl)]
6433
        private static extern IntPtr INTERNAL_SDL_GameControllerGetStringForButton(
6434
            SDL_GameControllerButton button
6435
        );
6436
        public static string SDL_GameControllerGetStringForButton(
6437
            SDL_GameControllerButton button
6438
        )
6439
        {
6440
            return UTF8_ToManaged(
6441
                INTERNAL_SDL_GameControllerGetStringForButton(button)
6442
            );
6443
        }
6444

6445
        /* gamecontroller refers to an SDL_GameController* */
6446
        [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetBindForButton", CallingConvention = CallingConvention.Cdecl)]
6447
        private static extern INTERNAL_SDL_GameControllerButtonBind INTERNAL_SDL_GameControllerGetBindForButton(
6448
            IntPtr gamecontroller,
6449
            SDL_GameControllerButton button
6450
        );
6451
        public static SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(
6452
            IntPtr gamecontroller,
6453
            SDL_GameControllerButton button
6454
        )
6455
        {
6456
            // This is guaranteed to never be null
6457
            INTERNAL_SDL_GameControllerButtonBind dumb = INTERNAL_SDL_GameControllerGetBindForButton(
6458
                gamecontroller,
6459
                button
6460
            );
6461
            SDL_GameControllerButtonBind result = new SDL_GameControllerButtonBind();
6462
            result.bindType = (SDL_GameControllerBindType)dumb.bindType;
6463
            result.value.hat.hat = dumb.unionVal0;
6464
            result.value.hat.hat_mask = dumb.unionVal1;
6465
            return result;
6466
        }
6467

6468
        /* gamecontroller refers to an SDL_GameController* */
6469
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6470
        public static extern byte SDL_GameControllerGetButton(
6471
            IntPtr gamecontroller,
6472
            SDL_GameControllerButton button
6473
        );
6474

6475
        /* gamecontroller refers to an SDL_GameController*.
6476
         * Only available in 2.0.9 or higher.
6477
         */
6478
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6479
        public static extern int SDL_GameControllerRumble(
6480
            IntPtr gamecontroller,
6481
            UInt16 low_frequency_rumble,
6482
            UInt16 high_frequency_rumble,
6483
            UInt32 duration_ms
6484
        );
6485

6486
        /* gamecontroller refers to an SDL_GameController* */
6487
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6488
        public static extern void SDL_GameControllerClose(
6489
            IntPtr gamecontroller
6490
        );
6491

6492
        /* int refers to an SDL_JoystickID, IntPtr to an SDL_GameController*.
6493
         * Only available in 2.0.4 or higher.
6494
         */
6495
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6496
        public static extern IntPtr SDL_GameControllerFromInstanceID(int joyid);
6497

6498
        /* Only available in 2.0.11 or higher. */
6499
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6500
        public static extern SDL_GameControllerType SDL_GameControllerTypeForIndex(
6501
            int joystick_index
6502
        );
6503

6504
        /* IntPtr refers to an SDL_GameController*.
6505
         * Only available in 2.0.11 or higher.
6506
         */
6507
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6508
        public static extern SDL_GameControllerType SDL_GameControllerGetType(
6509
            IntPtr gamecontroller
6510
        );
6511

6512
        /* IntPtr refers to an SDL_GameController*.
6513
         * Only available in 2.0.11 or higher.
6514
         */
6515
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6516
        public static extern IntPtr SDL_GameControllerFromPlayerIndex(
6517
            int player_index
6518
        );
6519

6520
        /* IntPtr refers to an SDL_GameController*.
6521
         * Only available in 2.0.11 or higher.
6522
         */
6523
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6524
        public static extern void SDL_GameControllerSetPlayerIndex(
6525
            IntPtr gamecontroller,
6526
            int player_index
6527
        );
6528

6529
        #endregion
6530

6531
        #region SDL_haptic.h
6532

6533
        /* SDL_HapticEffect type */
6534
        public const ushort SDL_HAPTIC_CONSTANT = (1 << 0);
6535
        public const ushort SDL_HAPTIC_SINE = (1 << 1);
6536
        public const ushort SDL_HAPTIC_LEFTRIGHT = (1 << 2);
6537
        public const ushort SDL_HAPTIC_TRIANGLE = (1 << 3);
6538
        public const ushort SDL_HAPTIC_SAWTOOTHUP = (1 << 4);
6539
        public const ushort SDL_HAPTIC_SAWTOOTHDOWN = (1 << 5);
6540
        public const ushort SDL_HAPTIC_SPRING = (1 << 7);
6541
        public const ushort SDL_HAPTIC_DAMPER = (1 << 8);
6542
        public const ushort SDL_HAPTIC_INERTIA = (1 << 9);
6543
        public const ushort SDL_HAPTIC_FRICTION = (1 << 10);
6544
        public const ushort SDL_HAPTIC_CUSTOM = (1 << 11);
6545
        public const ushort SDL_HAPTIC_GAIN = (1 << 12);
6546
        public const ushort SDL_HAPTIC_AUTOCENTER = (1 << 13);
6547
        public const ushort SDL_HAPTIC_STATUS = (1 << 14);
6548
        public const ushort SDL_HAPTIC_PAUSE = (1 << 15);
6549

6550
        /* SDL_HapticDirection type */
6551
        public const byte SDL_HAPTIC_POLAR = 0;
6552
        public const byte SDL_HAPTIC_CARTESIAN = 1;
6553
        public const byte SDL_HAPTIC_SPHERICAL = 2;
6554

6555
        /* SDL_HapticRunEffect */
6556
        public const uint SDL_HAPTIC_INFINITY = 4294967295U;
6557

6558
        [StructLayout(LayoutKind.Sequential)]
6559
        public struct SDL_HapticDirection
6560
        {
6561
            public byte type;
6562
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
6563
            public int[] dir;
6564
        }
6565

6566
        [StructLayout(LayoutKind.Sequential)]
6567
        public struct SDL_HapticConstant
6568
        {
6569
            // Header
6570
            public ushort type;
6571
            public SDL_HapticDirection direction;
6572
            // Replay
6573
            public uint length;
6574
            public ushort delay;
6575
            // Trigger
6576
            public ushort button;
6577
            public ushort interval;
6578
            // Constant
6579
            public short level;
6580
            // Envelope
6581
            public ushort attack_length;
6582
            public ushort attack_level;
6583
            public ushort fade_length;
6584
            public ushort fade_level;
6585
        }
6586

6587
        [StructLayout(LayoutKind.Sequential)]
6588
        public struct SDL_HapticPeriodic
6589
        {
6590
            // Header
6591
            public ushort type;
6592
            public SDL_HapticDirection direction;
6593
            // Replay
6594
            public uint length;
6595
            public ushort delay;
6596
            // Trigger
6597
            public ushort button;
6598
            public ushort interval;
6599
            // Periodic
6600
            public ushort period;
6601
            public short magnitude;
6602
            public short offset;
6603
            public ushort phase;
6604
            // Envelope
6605
            public ushort attack_length;
6606
            public ushort attack_level;
6607
            public ushort fade_length;
6608
            public ushort fade_level;
6609
        }
6610

6611
        [StructLayout(LayoutKind.Sequential)]
6612
        public struct SDL_HapticCondition
6613
        {
6614
            // Header
6615
            public ushort type;
6616
            public SDL_HapticDirection direction;
6617
            // Replay
6618
            public uint length;
6619
            public ushort delay;
6620
            // Trigger
6621
            public ushort button;
6622
            public ushort interval;
6623
            // Condition
6624
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
6625
            public ushort[] right_sat;
6626
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
6627
            public ushort[] left_sat;
6628
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
6629
            public short[] right_coeff;
6630
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
6631
            public short[] left_coeff;
6632
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
6633
            public ushort[] deadband;
6634
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
6635
            public short[] center;
6636
        }
6637

6638
        [StructLayout(LayoutKind.Sequential)]
6639
        public struct SDL_HapticRamp
6640
        {
6641
            // Header
6642
            public ushort type;
6643
            public SDL_HapticDirection direction;
6644
            // Replay
6645
            public uint length;
6646
            public ushort delay;
6647
            // Trigger
6648
            public ushort button;
6649
            public ushort interval;
6650
            // Ramp
6651
            public short start;
6652
            public short end;
6653
            // Envelope
6654
            public ushort attack_length;
6655
            public ushort attack_level;
6656
            public ushort fade_length;
6657
            public ushort fade_level;
6658
        }
6659

6660
        [StructLayout(LayoutKind.Sequential)]
6661
        public struct SDL_HapticLeftRight
6662
        {
6663
            // Header
6664
            public ushort type;
6665
            // Replay
6666
            public uint length;
6667
            // Rumble
6668
            public ushort large_magnitude;
6669
            public ushort small_magnitude;
6670
        }
6671

6672
        [StructLayout(LayoutKind.Sequential)]
6673
        public struct SDL_HapticCustom
6674
        {
6675
            // Header
6676
            public ushort type;
6677
            public SDL_HapticDirection direction;
6678
            // Replay
6679
            public uint length;
6680
            public ushort delay;
6681
            // Trigger
6682
            public ushort button;
6683
            public ushort interval;
6684
            // Custom
6685
            public byte channels;
6686
            public ushort period;
6687
            public ushort samples;
6688
            public IntPtr data; // Uint16*
6689
            // Envelope
6690
            public ushort attack_length;
6691
            public ushort attack_level;
6692
            public ushort fade_length;
6693
            public ushort fade_level;
6694
        }
6695

6696
        [StructLayout(LayoutKind.Explicit)]
6697
        public struct SDL_HapticEffect
6698
        {
6699
            [FieldOffset(0)]
6700
            public ushort type;
6701
            [FieldOffset(0)]
6702
            public SDL_HapticConstant constant;
6703
            [FieldOffset(0)]
6704
            public SDL_HapticPeriodic periodic;
6705
            [FieldOffset(0)]
6706
            public SDL_HapticCondition condition;
6707
            [FieldOffset(0)]
6708
            public SDL_HapticRamp ramp;
6709
            [FieldOffset(0)]
6710
            public SDL_HapticLeftRight leftright;
6711
            [FieldOffset(0)]
6712
            public SDL_HapticCustom custom;
6713
        }
6714

6715
        /* haptic refers to an SDL_Haptic* */
6716
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6717
        public static extern void SDL_HapticClose(IntPtr haptic);
6718

6719
        /* haptic refers to an SDL_Haptic* */
6720
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6721
        public static extern void SDL_HapticDestroyEffect(
6722
            IntPtr haptic,
6723
            int effect
6724
        );
6725

6726
        /* haptic refers to an SDL_Haptic* */
6727
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6728
        public static extern int SDL_HapticEffectSupported(
6729
            IntPtr haptic,
6730
            ref SDL_HapticEffect effect
6731
        );
6732

6733
        /* haptic refers to an SDL_Haptic* */
6734
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6735
        public static extern int SDL_HapticGetEffectStatus(
6736
            IntPtr haptic,
6737
            int effect
6738
        );
6739

6740
        /* haptic refers to an SDL_Haptic* */
6741
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6742
        public static extern int SDL_HapticIndex(IntPtr haptic);
6743

6744
        /* haptic refers to an SDL_Haptic* */
6745
        [DllImport(nativeLibName, EntryPoint = "SDL_HapticName", CallingConvention = CallingConvention.Cdecl)]
6746
        private static extern IntPtr INTERNAL_SDL_HapticName(int device_index);
6747
        public static string SDL_HapticName(int device_index)
6748
        {
6749
            return UTF8_ToManaged(INTERNAL_SDL_HapticName(device_index));
6750
        }
6751

6752
        /* haptic refers to an SDL_Haptic* */
6753
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6754
        public static extern int SDL_HapticNewEffect(
6755
            IntPtr haptic,
6756
            ref SDL_HapticEffect effect
6757
        );
6758

6759
        /* haptic refers to an SDL_Haptic* */
6760
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6761
        public static extern int SDL_HapticNumAxes(IntPtr haptic);
6762

6763
        /* haptic refers to an SDL_Haptic* */
6764
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6765
        public static extern int SDL_HapticNumEffects(IntPtr haptic);
6766

6767
        /* haptic refers to an SDL_Haptic* */
6768
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6769
        public static extern int SDL_HapticNumEffectsPlaying(IntPtr haptic);
6770

6771
        /* IntPtr refers to an SDL_Haptic* */
6772
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6773
        public static extern IntPtr SDL_HapticOpen(int device_index);
6774

6775
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6776
        public static extern int SDL_HapticOpened(int device_index);
6777

6778
        /* IntPtr refers to an SDL_Haptic*, joystick to an SDL_Joystick* */
6779
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6780
        public static extern IntPtr SDL_HapticOpenFromJoystick(
6781
            IntPtr joystick
6782
        );
6783

6784
        /* IntPtr refers to an SDL_Haptic* */
6785
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6786
        public static extern IntPtr SDL_HapticOpenFromMouse();
6787

6788
        /* haptic refers to an SDL_Haptic* */
6789
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6790
        public static extern int SDL_HapticPause(IntPtr haptic);
6791

6792
        /* haptic refers to an SDL_Haptic* */
6793
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6794
        public static extern uint SDL_HapticQuery(IntPtr haptic);
6795

6796
        /* haptic refers to an SDL_Haptic* */
6797
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6798
        public static extern int SDL_HapticRumbleInit(IntPtr haptic);
6799

6800
        /* haptic refers to an SDL_Haptic* */
6801
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6802
        public static extern int SDL_HapticRumblePlay(
6803
            IntPtr haptic,
6804
            float strength,
6805
            uint length
6806
        );
6807

6808
        /* haptic refers to an SDL_Haptic* */
6809
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6810
        public static extern int SDL_HapticRumbleStop(IntPtr haptic);
6811

6812
        /* haptic refers to an SDL_Haptic* */
6813
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6814
        public static extern int SDL_HapticRumbleSupported(IntPtr haptic);
6815

6816
        /* haptic refers to an SDL_Haptic* */
6817
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6818
        public static extern int SDL_HapticRunEffect(
6819
            IntPtr haptic,
6820
            int effect,
6821
            uint iterations
6822
        );
6823

6824
        /* haptic refers to an SDL_Haptic* */
6825
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6826
        public static extern int SDL_HapticSetAutocenter(
6827
            IntPtr haptic,
6828
            int autocenter
6829
        );
6830

6831
        /* haptic refers to an SDL_Haptic* */
6832
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6833
        public static extern int SDL_HapticSetGain(
6834
            IntPtr haptic,
6835
            int gain
6836
        );
6837

6838
        /* haptic refers to an SDL_Haptic* */
6839
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6840
        public static extern int SDL_HapticStopAll(IntPtr haptic);
6841

6842
        /* haptic refers to an SDL_Haptic* */
6843
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6844
        public static extern int SDL_HapticStopEffect(
6845
            IntPtr haptic,
6846
            int effect
6847
        );
6848

6849
        /* haptic refers to an SDL_Haptic* */
6850
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6851
        public static extern int SDL_HapticUnpause(IntPtr haptic);
6852

6853
        /* haptic refers to an SDL_Haptic* */
6854
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6855
        public static extern int SDL_HapticUpdateEffect(
6856
            IntPtr haptic,
6857
            int effect,
6858
            ref SDL_HapticEffect data
6859
        );
6860

6861
        /* joystick refers to an SDL_Joystick* */
6862
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6863
        public static extern int SDL_JoystickIsHaptic(IntPtr joystick);
6864

6865
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6866
        public static extern int SDL_MouseIsHaptic();
6867

6868
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6869
        public static extern int SDL_NumHaptics();
6870

6871
        #endregion
6872

6873
        #region SDL_sensor.h
6874

6875
        /* This region is only available in 2.0.9 or higher. */
6876

6877
        public enum SDL_SensorType
6878
        {
6879
            SDL_SENSOR_INVALID = -1,
6880
            SDL_SENSOR_UNKNOWN,
6881
            SDL_SENSOR_ACCEL,
6882
            SDL_SENSOR_GYRO
6883
        }
6884

6885
        public const float SDL_STANDARD_GRAVITY = 9.80665f;
6886

6887
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6888
        public static extern int SDL_NumSensors();
6889

6890
        [DllImport(nativeLibName, EntryPoint = "SDL_SensorGetDeviceName", CallingConvention = CallingConvention.Cdecl)]
6891
        private static extern IntPtr INTERNAL_SDL_SensorGetDeviceName(int device_index);
6892
        public static string SDL_SensorGetDeviceName(int device_index)
6893
        {
6894
            return UTF8_ToManaged(INTERNAL_SDL_SensorGetDeviceName(device_index));
6895
        }
6896

6897
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6898
        public static extern SDL_SensorType SDL_SensorGetDeviceType(int device_index);
6899

6900
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6901
        public static extern int SDL_SensorGetDeviceNonPortableType(int device_index);
6902

6903
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6904
        public static extern Int32 SDL_SensorGetDeviceInstanceID(int device_index);
6905

6906
        /* IntPtr refers to an SDL_Sensor* */
6907
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6908
        public static extern IntPtr SDL_SensorOpen(int device_index);
6909

6910
        /* IntPtr refers to an SDL_Sensor* */
6911
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6912
        public static extern IntPtr SDL_SensorFromInstanceID(
6913
            Int32 instance_id
6914
        );
6915

6916
        /* sensor refers to an SDL_Sensor* */
6917
        [DllImport(nativeLibName, EntryPoint = "SDL_SensorGetName", CallingConvention = CallingConvention.Cdecl)]
6918
        private static extern IntPtr INTERNAL_SDL_SensorGetName(IntPtr sensor);
6919
        public static string SDL_SensorGetName(IntPtr sensor)
6920
        {
6921
            return UTF8_ToManaged(INTERNAL_SDL_SensorGetName(sensor));
6922
        }
6923

6924
        /* sensor refers to an SDL_Sensor* */
6925
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6926
        public static extern SDL_SensorType SDL_SensorGetType(IntPtr sensor);
6927

6928
        /* sensor refers to an SDL_Sensor* */
6929
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6930
        public static extern int SDL_SensorGetNonPortableType(IntPtr sensor);
6931

6932
        /* sensor refers to an SDL_Sensor* */
6933
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6934
        public static extern Int32 SDL_SensorGetInstanceID(IntPtr sensor);
6935

6936
        /* sensor refers to an SDL_Sensor* */
6937
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6938
        public static extern int SDL_SensorGetData(
6939
            IntPtr sensor,
6940
            float[] data,
6941
            int num_values
6942
        );
6943

6944
        /* sensor refers to an SDL_Sensor* */
6945
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6946
        public static extern void SDL_SensorClose(IntPtr sensor);
6947

6948
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
6949
        public static extern void SDL_SensorUpdate();
6950

6951
        #endregion
6952

6953
        #region SDL_audio.h
6954

6955
        public const ushort SDL_AUDIO_MASK_BITSIZE = 0xFF;
6956
        public const ushort SDL_AUDIO_MASK_DATATYPE = (1 << 8);
6957
        public const ushort SDL_AUDIO_MASK_ENDIAN = (1 << 12);
6958
        public const ushort SDL_AUDIO_MASK_SIGNED = (1 << 15);
6959

6960
        public static ushort SDL_AUDIO_BITSIZE(ushort x)
6961
        {
6962
            return (ushort)(x & SDL_AUDIO_MASK_BITSIZE);
6963
        }
6964

6965
        public static bool SDL_AUDIO_ISFLOAT(ushort x)
6966
        {
6967
            return (x & SDL_AUDIO_MASK_DATATYPE) != 0;
6968
        }
6969

6970
        public static bool SDL_AUDIO_ISBIGENDIAN(ushort x)
6971
        {
6972
            return (x & SDL_AUDIO_MASK_ENDIAN) != 0;
6973
        }
6974

6975
        public static bool SDL_AUDIO_ISSIGNED(ushort x)
6976
        {
6977
            return (x & SDL_AUDIO_MASK_SIGNED) != 0;
6978
        }
6979

6980
        public static bool SDL_AUDIO_ISINT(ushort x)
6981
        {
6982
            return (x & SDL_AUDIO_MASK_DATATYPE) == 0;
6983
        }
6984

6985
        public static bool SDL_AUDIO_ISLITTLEENDIAN(ushort x)
6986
        {
6987
            return (x & SDL_AUDIO_MASK_ENDIAN) == 0;
6988
        }
6989

6990
        public static bool SDL_AUDIO_ISUNSIGNED(ushort x)
6991
        {
6992
            return (x & SDL_AUDIO_MASK_SIGNED) == 0;
6993
        }
6994

6995
        public const ushort AUDIO_U8 = 0x0008;
6996
        public const ushort AUDIO_S8 = 0x8008;
6997
        public const ushort AUDIO_U16LSB = 0x0010;
6998
        public const ushort AUDIO_S16LSB = 0x8010;
6999
        public const ushort AUDIO_U16MSB = 0x1010;
7000
        public const ushort AUDIO_S16MSB = 0x9010;
7001
        public const ushort AUDIO_U16 = AUDIO_U16LSB;
7002
        public const ushort AUDIO_S16 = AUDIO_S16LSB;
7003
        public const ushort AUDIO_S32LSB = 0x8020;
7004
        public const ushort AUDIO_S32MSB = 0x9020;
7005
        public const ushort AUDIO_S32 = AUDIO_S32LSB;
7006
        public const ushort AUDIO_F32LSB = 0x8120;
7007
        public const ushort AUDIO_F32MSB = 0x9120;
7008
        public const ushort AUDIO_F32 = AUDIO_F32LSB;
7009

7010
        public static readonly ushort AUDIO_U16SYS =
7011
            BitConverter.IsLittleEndian ? AUDIO_U16LSB : AUDIO_U16MSB;
7012
        public static readonly ushort AUDIO_S16SYS =
7013
            BitConverter.IsLittleEndian ? AUDIO_S16LSB : AUDIO_S16MSB;
7014
        public static readonly ushort AUDIO_S32SYS =
7015
            BitConverter.IsLittleEndian ? AUDIO_S32LSB : AUDIO_S32MSB;
7016
        public static readonly ushort AUDIO_F32SYS =
7017
            BitConverter.IsLittleEndian ? AUDIO_F32LSB : AUDIO_F32MSB;
7018

7019
        public const uint SDL_AUDIO_ALLOW_FREQUENCY_CHANGE = 0x00000001;
7020
        public const uint SDL_AUDIO_ALLOW_FORMAT_CHANGE = 0x00000002;
7021
        public const uint SDL_AUDIO_ALLOW_CHANNELS_CHANGE = 0x00000004;
7022
        public const uint SDL_AUDIO_ALLOW_SAMPLES_CHANGE = 0x00000008;
7023
        public const uint SDL_AUDIO_ALLOW_ANY_CHANGE = (
7024
            SDL_AUDIO_ALLOW_FREQUENCY_CHANGE |
7025
            SDL_AUDIO_ALLOW_FORMAT_CHANGE |
7026
            SDL_AUDIO_ALLOW_CHANNELS_CHANGE |
7027
            SDL_AUDIO_ALLOW_SAMPLES_CHANGE
7028
        );
7029

7030
        public const int SDL_MIX_MAXVOLUME = 128;
7031

7032
        public enum SDL_AudioStatus
7033
        {
7034
            SDL_AUDIO_STOPPED,
7035
            SDL_AUDIO_PLAYING,
7036
            SDL_AUDIO_PAUSED
7037
        }
7038

7039
        [StructLayout(LayoutKind.Sequential)]
7040
        public struct SDL_AudioSpec
7041
        {
7042
            public int freq;
7043
            public ushort format; // SDL_AudioFormat
7044
            public byte channels;
7045
            public byte silence;
7046
            public ushort samples;
7047
            public uint size;
7048
            public SDL_AudioCallback callback;
7049
            public IntPtr userdata; // void*
7050
        }
7051

7052
        /* userdata refers to a void*, stream to a Uint8 */
7053
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
7054
        public delegate void SDL_AudioCallback(
7055
            IntPtr userdata,
7056
            IntPtr stream,
7057
            int len
7058
        );
7059

7060
        [DllImport(nativeLibName, EntryPoint = "SDL_AudioInit", CallingConvention = CallingConvention.Cdecl)]
7061
        private static extern int INTERNAL_SDL_AudioInit(
7062
            byte[] driver_name
7063
        );
7064
        public static int SDL_AudioInit(string driver_name)
7065
        {
7066
            return INTERNAL_SDL_AudioInit(
7067
                UTF8_ToNative(driver_name)
7068
            );
7069
        }
7070

7071
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7072
        public static extern void SDL_AudioQuit();
7073

7074
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7075
        public static extern void SDL_CloseAudio();
7076

7077
        /* dev refers to an SDL_AudioDeviceID */
7078
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7079
        public static extern void SDL_CloseAudioDevice(uint dev);
7080

7081
        /* audio_buf refers to a malloc()'d buffer from SDL_LoadWAV */
7082
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7083
        public static extern void SDL_FreeWAV(IntPtr audio_buf);
7084

7085
        [DllImport(nativeLibName, EntryPoint = "SDL_GetAudioDeviceName", CallingConvention = CallingConvention.Cdecl)]
7086
        private static extern IntPtr INTERNAL_SDL_GetAudioDeviceName(
7087
            int index,
7088
            int iscapture
7089
        );
7090
        public static string SDL_GetAudioDeviceName(
7091
            int index,
7092
            int iscapture
7093
        )
7094
        {
7095
            return UTF8_ToManaged(
7096
                INTERNAL_SDL_GetAudioDeviceName(index, iscapture)
7097
            );
7098
        }
7099

7100
        /* dev refers to an SDL_AudioDeviceID */
7101
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7102
        public static extern SDL_AudioStatus SDL_GetAudioDeviceStatus(
7103
            uint dev
7104
        );
7105

7106
        [DllImport(nativeLibName, EntryPoint = "SDL_GetAudioDriver", CallingConvention = CallingConvention.Cdecl)]
7107
        private static extern IntPtr INTERNAL_SDL_GetAudioDriver(int index);
7108
        public static string SDL_GetAudioDriver(int index)
7109
        {
7110
            return UTF8_ToManaged(
7111
                INTERNAL_SDL_GetAudioDriver(index)
7112
            );
7113
        }
7114

7115
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7116
        public static extern SDL_AudioStatus SDL_GetAudioStatus();
7117

7118
        [DllImport(nativeLibName, EntryPoint = "SDL_GetCurrentAudioDriver", CallingConvention = CallingConvention.Cdecl)]
7119
        private static extern IntPtr INTERNAL_SDL_GetCurrentAudioDriver();
7120
        public static string SDL_GetCurrentAudioDriver()
7121
        {
7122
            return UTF8_ToManaged(INTERNAL_SDL_GetCurrentAudioDriver());
7123
        }
7124

7125
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7126
        public static extern int SDL_GetNumAudioDevices(int iscapture);
7127

7128
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7129
        public static extern int SDL_GetNumAudioDrivers();
7130

7131
        /* audio_buf will refer to a malloc()'d byte buffer */
7132
        /* THIS IS AN RWops FUNCTION! */
7133
        [DllImport(nativeLibName, EntryPoint = "SDL_LoadWAV_RW", CallingConvention = CallingConvention.Cdecl)]
7134
        private static extern IntPtr INTERNAL_SDL_LoadWAV_RW(
7135
            IntPtr src,
7136
            int freesrc,
7137
            ref SDL_AudioSpec spec,
7138
            out IntPtr audio_buf,
7139
            out uint audio_len
7140
        );
7141
        public static SDL_AudioSpec SDL_LoadWAV(
7142
            string file,
7143
            ref SDL_AudioSpec spec,
7144
            out IntPtr audio_buf,
7145
            out uint audio_len
7146
        )
7147
        {
7148
            SDL_AudioSpec result;
7149
            IntPtr rwops = SDL_RWFromFile(file, "rb");
7150
            IntPtr result_ptr = INTERNAL_SDL_LoadWAV_RW(
7151
                rwops,
7152
                1,
7153
                ref spec,
7154
                out audio_buf,
7155
                out audio_len
7156
            );
7157
            result = (SDL_AudioSpec)Marshal.PtrToStructure(
7158
                result_ptr,
7159
                typeof(SDL_AudioSpec)
7160
            );
7161
            return result;
7162
        }
7163

7164
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7165
        public static extern void SDL_LockAudio();
7166

7167
        /* dev refers to an SDL_AudioDeviceID */
7168
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7169
        public static extern void SDL_LockAudioDevice(uint dev);
7170

7171
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7172
        public static extern void SDL_MixAudio(
7173
            [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 2)]
7174
				byte[] dst,
7175
            [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 2)]
7176
				byte[] src,
7177
            uint len,
7178
            int volume
7179
        );
7180

7181
        /* format refers to an SDL_AudioFormat */
7182
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7183
        public static extern void SDL_MixAudioFormat(
7184
            [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 3)]
7185
				byte[] dst,
7186
            [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 3)]
7187
				byte[] src,
7188
            ushort format,
7189
            uint len,
7190
            int volume
7191
        );
7192

7193
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7194
        public static extern int SDL_OpenAudio(
7195
            ref SDL_AudioSpec desired,
7196
            out SDL_AudioSpec obtained
7197
        );
7198

7199
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7200
        public static extern int SDL_OpenAudio(
7201
            ref SDL_AudioSpec desired,
7202
            IntPtr obtained
7203
        );
7204

7205
        /* uint refers to an SDL_AudioDeviceID */
7206
        [DllImport(nativeLibName, EntryPoint = "SDL_OpenAudioDevice", CallingConvention = CallingConvention.Cdecl)]
7207
        private static extern uint INTERNAL_SDL_OpenAudioDevice(
7208
            byte[] device,
7209
            int iscapture,
7210
            ref SDL_AudioSpec desired,
7211
            out SDL_AudioSpec obtained,
7212
            int allowed_changes
7213
        );
7214
        public static uint SDL_OpenAudioDevice(
7215
            string device,
7216
            int iscapture,
7217
            ref SDL_AudioSpec desired,
7218
            out SDL_AudioSpec obtained,
7219
            int allowed_changes
7220
        )
7221
        {
7222
            return INTERNAL_SDL_OpenAudioDevice(
7223
                UTF8_ToNative(device),
7224
                iscapture,
7225
                ref desired,
7226
                out obtained,
7227
                allowed_changes
7228
            );
7229
        }
7230

7231
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7232
        public static extern void SDL_PauseAudio(int pause_on);
7233

7234
        /* dev refers to an SDL_AudioDeviceID */
7235
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7236
        public static extern void SDL_PauseAudioDevice(
7237
            uint dev,
7238
            int pause_on
7239
        );
7240

7241
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7242
        public static extern void SDL_UnlockAudio();
7243

7244
        /* dev refers to an SDL_AudioDeviceID */
7245
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7246
        public static extern void SDL_UnlockAudioDevice(uint dev);
7247

7248
        /* dev refers to an SDL_AudioDeviceID, data to a void*
7249
         * Only available in 2.0.4 or higher.
7250
         */
7251
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7252
        public static extern int SDL_QueueAudio(
7253
            uint dev,
7254
            IntPtr data,
7255
            UInt32 len
7256
        );
7257

7258
        /* dev refers to an SDL_AudioDeviceID, data to a void*
7259
         * Only available in 2.0.5 or higher.
7260
         */
7261
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7262
        public static extern uint SDL_DequeueAudio(
7263
            uint dev,
7264
            IntPtr data,
7265
            uint len
7266
        );
7267

7268
        /* dev refers to an SDL_AudioDeviceID
7269
         * Only available in 2.0.4 or higher.
7270
         */
7271
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7272
        public static extern UInt32 SDL_GetQueuedAudioSize(uint dev);
7273

7274
        /* dev refers to an SDL_AudioDeviceID
7275
         * Only available in 2.0.4 or higher.
7276
         */
7277
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7278
        public static extern void SDL_ClearQueuedAudio(uint dev);
7279

7280
        /* src_format and dst_format refer to SDL_AudioFormats.
7281
         * IntPtr refers to an SDL_AudioStream*.
7282
         * Only available in 2.0.7 or higher.
7283
         */
7284
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7285
        public static extern IntPtr SDL_NewAudioStream(
7286
            ushort src_format,
7287
            byte src_channels,
7288
            int src_rate,
7289
            ushort dst_format,
7290
            byte dst_channels,
7291
            int dst_rate
7292
        );
7293

7294
        /* stream refers to an SDL_AudioStream*, buf to a void*.
7295
         * Only available in 2.0.7 or higher.
7296
         */
7297
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7298
        public static extern int SDL_AudioStreamPut(
7299
            IntPtr stream,
7300
            IntPtr buf,
7301
            int len
7302
        );
7303

7304
        /* stream refers to an SDL_AudioStream*, buf to a void*.
7305
         * Only available in 2.0.7 or higher.
7306
         */
7307
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7308
        public static extern int SDL_AudioStreamGet(
7309
            IntPtr stream,
7310
            IntPtr buf,
7311
            int len
7312
        );
7313

7314
        /* stream refers to an SDL_AudioStream*.
7315
         * Only available in 2.0.7 or higher.
7316
         */
7317
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7318
        public static extern int SDL_AudioStreamAvailable(IntPtr stream);
7319

7320
        /* stream refers to an SDL_AudioStream*.
7321
         * Only available in 2.0.7 or higher.
7322
         */
7323
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7324
        public static extern void SDL_AudioStreamClear(IntPtr stream);
7325

7326
        /* stream refers to an SDL_AudioStream*.
7327
         * Only available in 2.0.7 or higher.
7328
         */
7329
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7330
        public static extern void SDL_FreeAudioStream(IntPtr stream);
7331

7332
        #endregion
7333

7334
        #region SDL_timer.h
7335

7336
        /* System timers rely on different OS mechanisms depending on
7337
		 * which operating system SDL2 is compiled against.
7338
		 */
7339

7340
        /* Compare tick values, return true if A has passed B. Introduced in SDL 2.0.1,
7341
         * but does not require it (it was a macro).
7342
         */
7343
        public static bool SDL_TICKS_PASSED(UInt32 A, UInt32 B)
7344
        {
7345
            return ((Int32)(B - A) <= 0);
7346
        }
7347

7348
        /* Delays the thread's processing based on the milliseconds parameter */
7349
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7350
        public static extern void SDL_Delay(UInt32 ms);
7351

7352
        /* Returns the milliseconds that have passed since SDL was initialized */
7353
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7354
        public static extern UInt32 SDL_GetTicks();
7355

7356
        /* Get the current value of the high resolution counter */
7357
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7358
        public static extern UInt64 SDL_GetPerformanceCounter();
7359

7360
        /* Get the count per second of the high resolution counter */
7361
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7362
        public static extern UInt64 SDL_GetPerformanceFrequency();
7363

7364
        /* param refers to a void* */
7365
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
7366
        public delegate UInt32 SDL_TimerCallback(UInt32 interval, IntPtr param);
7367

7368
        /* int refers to an SDL_TimerID, param to a void* */
7369
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7370
        public static extern int SDL_AddTimer(
7371
            UInt32 interval,
7372
            SDL_TimerCallback callback,
7373
            IntPtr param
7374
        );
7375

7376
        /* id refers to an SDL_TimerID */
7377
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7378
        public static extern SDL_bool SDL_RemoveTimer(int id);
7379

7380
        #endregion
7381

7382
        #region SDL_system.h
7383

7384
        /* Windows */
7385

7386
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
7387
        public delegate IntPtr SDL_WindowsMessageHook(
7388
            IntPtr userdata,
7389
            IntPtr hWnd,
7390
            uint message,
7391
            ulong wParam,
7392
            long lParam
7393
        );
7394

7395
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7396
        public static extern void SDL_SetWindowsMessageHook(
7397
            SDL_WindowsMessageHook callback,
7398
            IntPtr userdata
7399
        );
7400

7401
        /* iOS */
7402

7403
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
7404
        public delegate void SDL_iPhoneAnimationCallback(IntPtr p);
7405

7406
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7407
        public static extern int SDL_iPhoneSetAnimationCallback(
7408
            IntPtr window, /* SDL_Window* */
7409
            int interval,
7410
            SDL_iPhoneAnimationCallback callback,
7411
            IntPtr callbackParam
7412
        );
7413

7414
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7415
        public static extern void SDL_iPhoneSetEventPump(SDL_bool enabled);
7416

7417
        /* Android */
7418

7419
        public const int SDL_ANDROID_EXTERNAL_STORAGE_READ = 0x01;
7420
        public const int SDL_ANDROID_EXTERNAL_STORAGE_WRITE = 0x02;
7421

7422
        /* IntPtr refers to a JNIEnv* */
7423
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7424
        public static extern IntPtr SDL_AndroidGetJNIEnv();
7425

7426
        /* IntPtr refers to a jobject */
7427
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7428
        public static extern IntPtr SDL_AndroidGetActivity();
7429

7430
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7431
        public static extern SDL_bool SDL_IsAndroidTV();
7432

7433
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7434
        public static extern SDL_bool SDL_IsChromebook();
7435

7436
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7437
        public static extern SDL_bool SDL_IsDeXMode();
7438

7439
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7440
        public static extern void SDL_AndroidBackButton();
7441

7442
        [DllImport(nativeLibName, EntryPoint = "SDL_AndroidGetInternalStoragePath", CallingConvention = CallingConvention.Cdecl)]
7443
        private static extern IntPtr INTERNAL_SDL_AndroidGetInternalStoragePath();
7444

7445
        public static string SDL_AndroidGetInternalStoragePath()
7446
        {
7447
            return UTF8_ToManaged(
7448
                INTERNAL_SDL_AndroidGetInternalStoragePath()
7449
            );
7450
        }
7451

7452
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7453
        public static extern int SDL_AndroidGetExternalStorageState();
7454

7455
        [DllImport(nativeLibName, EntryPoint = "SDL_AndroidGetExternalStorageState", CallingConvention = CallingConvention.Cdecl)]
7456
        private static extern IntPtr INTERNAL_SDL_AndroidGetExternalStoragePath();
7457

7458
        public static string SDL_AndroidGetExternalStoragePath()
7459
        {
7460
            return UTF8_ToManaged(
7461
                INTERNAL_SDL_AndroidGetExternalStoragePath()
7462
            );
7463
        }
7464

7465
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7466
        public static extern int SDL_GetAndroidSDKVersion();
7467

7468
        /* WinRT */
7469

7470
        public enum SDL_WinRT_DeviceFamily
7471
        {
7472
            SDL_WINRT_DEVICEFAMILY_UNKNOWN,
7473
            SDL_WINRT_DEVICEFAMILY_DESKTOP,
7474
            SDL_WINRT_DEVICEFAMILY_MOBILE,
7475
            SDL_WINRT_DEVICEFAMILY_XBOX
7476
        }
7477

7478
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7479
        public static extern SDL_WinRT_DeviceFamily SDL_WinRTGetDeviceFamily();
7480

7481
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7482
        public static extern SDL_bool SDL_IsTablet();
7483

7484
        #endregion
7485

7486
        #region SDL_syswm.h
7487

7488
        public enum SDL_SYSWM_TYPE
7489
        {
7490
            SDL_SYSWM_UNKNOWN,
7491
            SDL_SYSWM_WINDOWS,
7492
            SDL_SYSWM_X11,
7493
            SDL_SYSWM_DIRECTFB,
7494
            SDL_SYSWM_COCOA,
7495
            SDL_SYSWM_UIKIT,
7496
            SDL_SYSWM_WAYLAND,
7497
            SDL_SYSWM_MIR,
7498
            SDL_SYSWM_WINRT,
7499
            SDL_SYSWM_ANDROID,
7500
            SDL_SYSWM_VIVANTE,
7501
            SDL_SYSWM_OS2,
7502
            SDL_SYSWM_HAIKU
7503
        }
7504

7505
        // FIXME: I wish these weren't public...
7506
        [StructLayout(LayoutKind.Sequential)]
7507
        public struct INTERNAL_windows_wminfo
7508
        {
7509
            public IntPtr window; // Refers to an HWND
7510
            public IntPtr hdc; // Refers to an HDC
7511
            public IntPtr hinstance; // Refers to an HINSTANCE
7512
        }
7513

7514
        [StructLayout(LayoutKind.Sequential)]
7515
        public struct INTERNAL_winrt_wminfo
7516
        {
7517
            public IntPtr window; // Refers to an IInspectable*
7518
        }
7519

7520
        [StructLayout(LayoutKind.Sequential)]
7521
        public struct INTERNAL_x11_wminfo
7522
        {
7523
            public IntPtr display; // Refers to a Display*
7524
            public IntPtr window; // Refers to a Window (XID, use ToInt64!)
7525
        }
7526

7527
        [StructLayout(LayoutKind.Sequential)]
7528
        public struct INTERNAL_directfb_wminfo
7529
        {
7530
            public IntPtr dfb; // Refers to an IDirectFB*
7531
            public IntPtr window; // Refers to an IDirectFBWindow*
7532
            public IntPtr surface; // Refers to an IDirectFBSurface*
7533
        }
7534

7535
        [StructLayout(LayoutKind.Sequential)]
7536
        public struct INTERNAL_cocoa_wminfo
7537
        {
7538
            public IntPtr window; // Refers to an NSWindow*
7539
        }
7540

7541
        [StructLayout(LayoutKind.Sequential)]
7542
        public struct INTERNAL_uikit_wminfo
7543
        {
7544
            public IntPtr window; // Refers to a UIWindow*
7545
            public uint framebuffer;
7546
            public uint colorbuffer;
7547
            public uint resolveFramebuffer;
7548
        }
7549

7550
        [StructLayout(LayoutKind.Sequential)]
7551
        public struct INTERNAL_wayland_wminfo
7552
        {
7553
            public IntPtr display; // Refers to a wl_display*
7554
            public IntPtr surface; // Refers to a wl_surface*
7555
            public IntPtr shell_surface; // Refers to a wl_shell_surface*
7556
        }
7557

7558
        [StructLayout(LayoutKind.Sequential)]
7559
        public struct INTERNAL_mir_wminfo
7560
        {
7561
            public IntPtr connection; // Refers to a MirConnection*
7562
            public IntPtr surface; // Refers to a MirSurface*
7563
        }
7564

7565
        [StructLayout(LayoutKind.Sequential)]
7566
        public struct INTERNAL_android_wminfo
7567
        {
7568
            public IntPtr window; // Refers to an ANativeWindow
7569
            public IntPtr surface; // Refers to an EGLSurface
7570
        }
7571

7572
        [StructLayout(LayoutKind.Sequential)]
7573
        public struct INTERNAL_vivante_wminfo
7574
        {
7575
            public IntPtr display; // Refers to an EGLNativeDisplayType
7576
            public IntPtr window; // Refers to an EGLNativeWindowType
7577
        }
7578

7579
        [StructLayout(LayoutKind.Explicit)]
7580
        public struct INTERNAL_SysWMDriverUnion
7581
        {
7582
            [FieldOffset(0)]
7583
            public INTERNAL_windows_wminfo win;
7584
            [FieldOffset(0)]
7585
            public INTERNAL_winrt_wminfo winrt;
7586
            [FieldOffset(0)]
7587
            public INTERNAL_x11_wminfo x11;
7588
            [FieldOffset(0)]
7589
            public INTERNAL_directfb_wminfo dfb;
7590
            [FieldOffset(0)]
7591
            public INTERNAL_cocoa_wminfo cocoa;
7592
            [FieldOffset(0)]
7593
            public INTERNAL_uikit_wminfo uikit;
7594
            [FieldOffset(0)]
7595
            public INTERNAL_wayland_wminfo wl;
7596
            [FieldOffset(0)]
7597
            public INTERNAL_mir_wminfo mir;
7598
            [FieldOffset(0)]
7599
            public INTERNAL_android_wminfo android;
7600
            [FieldOffset(0)]
7601
            public INTERNAL_vivante_wminfo vivante;
7602
            // private int dummy;
7603
        }
7604

7605
        [StructLayout(LayoutKind.Sequential)]
7606
        public struct SDL_SysWMinfo
7607
        {
7608
            public SDL_version version;
7609
            public SDL_SYSWM_TYPE subsystem;
7610
            public INTERNAL_SysWMDriverUnion info;
7611
        }
7612

7613
        /* window refers to an SDL_Window* */
7614
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7615
        public static extern SDL_bool SDL_GetWindowWMInfo(
7616
            IntPtr window,
7617
            ref SDL_SysWMinfo info
7618
        );
7619

7620
        #endregion
7621

7622
        #region SDL_filesystem.h
7623

7624
        /* Only available in 2.0.1 or higher. */
7625
        [DllImport(nativeLibName, EntryPoint = "SDL_GetBasePath", CallingConvention = CallingConvention.Cdecl)]
7626
        private static extern IntPtr INTERNAL_SDL_GetBasePath();
7627
        public static string SDL_GetBasePath()
7628
        {
7629
            return UTF8_ToManaged(INTERNAL_SDL_GetBasePath(), true);
7630
        }
7631

7632
        /* Only available in 2.0.1 or higher. */
7633
        [DllImport(nativeLibName, EntryPoint = "SDL_GetPrefPath", CallingConvention = CallingConvention.Cdecl)]
7634
        private static extern IntPtr INTERNAL_SDL_GetPrefPath(
7635
            byte[] org,
7636
            byte[] app
7637
        );
7638
        public static string SDL_GetPrefPath(string org, string app)
7639
        {
7640
            return UTF8_ToManaged(
7641
                INTERNAL_SDL_GetPrefPath(
7642
                    UTF8_ToNative(org),
7643
                    UTF8_ToNative(app)
7644
                ),
7645
                true
7646
            );
7647
        }
7648

7649
        #endregion
7650

7651
        #region SDL_power.h
7652

7653
        public enum SDL_PowerState
7654
        {
7655
            SDL_POWERSTATE_UNKNOWN = 0,
7656
            SDL_POWERSTATE_ON_BATTERY,
7657
            SDL_POWERSTATE_NO_BATTERY,
7658
            SDL_POWERSTATE_CHARGING,
7659
            SDL_POWERSTATE_CHARGED
7660
        }
7661

7662
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7663
        public static extern SDL_PowerState SDL_GetPowerInfo(
7664
            out int secs,
7665
            out int pct
7666
        );
7667

7668
        #endregion
7669

7670
        #region SDL_cpuinfo.h
7671

7672
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7673
        public static extern int SDL_GetCPUCount();
7674

7675
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7676
        public static extern int SDL_GetCPUCacheLineSize();
7677

7678
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7679
        public static extern SDL_bool SDL_HasRDTSC();
7680

7681
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7682
        public static extern SDL_bool SDL_HasAltiVec();
7683

7684
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7685
        public static extern SDL_bool SDL_HasMMX();
7686

7687
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7688
        public static extern SDL_bool SDL_Has3DNow();
7689

7690
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7691
        public static extern SDL_bool SDL_HasSSE();
7692

7693
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7694
        public static extern SDL_bool SDL_HasSSE2();
7695

7696
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7697
        public static extern SDL_bool SDL_HasSSE3();
7698

7699
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7700
        public static extern SDL_bool SDL_HasSSE41();
7701

7702
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7703
        public static extern SDL_bool SDL_HasSSE42();
7704

7705
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7706
        public static extern SDL_bool SDL_HasAVX();
7707

7708
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7709
        public static extern SDL_bool SDL_HasAVX2();
7710

7711
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7712
        public static extern SDL_bool SDL_HasAVX512F();
7713

7714
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7715
        public static extern SDL_bool SDL_HasNEON();
7716

7717
        /* Only available in 2.0.1 or higher. */
7718
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7719
        public static extern int SDL_GetSystemRAM();
7720

7721
        /* Only available in SDL 2.0.10 or higher. */
7722
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7723
        public static extern uint SDL_SIMDGetAlignment();
7724

7725
        /* Only available in SDL 2.0.10 or higher. */
7726
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7727
        public static extern IntPtr SDL_SIMDAlloc(uint len);
7728

7729
        /* Only available in SDL 2.0.10 or higher. */
7730
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7731
        public static extern void SDL_SIMDFree(IntPtr ptr);
7732

7733
        /* Only available in SDL 2.0.11 or higher. */
7734
        [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
7735
        public static extern void SDL_HasARMSIMD();
7736

7737
        #endregion
7738

7739
        #region SDL_default_keymap
7740
        public static List<object> SDL_default_keymap = new List<object>() 
7741
        {
7742
            0, 0, 0, 0,
7743
            'a',
7744
            'b',
7745
            'c',
7746
            'd',
7747
            'e',
7748
            'f',
7749
            'g',
7750
            'h',
7751
            'i',
7752
            'j',
7753
            'k',
7754
            'l',
7755
            'm',
7756
            'n',
7757
            'o',
7758
            'p',
7759
            'q',
7760
            'r',
7761
            's',
7762
            't',
7763
            'u',
7764
            'v',
7765
            'w',
7766
            'x',
7767
            'y',
7768
            'z',
7769
            '1',
7770
            '2',
7771
            '3',
7772
            '4',
7773
            '5',
7774
            '6',
7775
            '7',
7776
            '8',
7777
            '9',
7778
            '0',
7779
            SDL_Keycode.SDLK_RETURN,
7780
            SDL_Keycode.SDLK_ESCAPE,
7781
            SDL_Keycode.SDLK_BACKSPACE,
7782
            SDL_Keycode.SDLK_TAB,
7783
            SDL_Keycode.SDLK_SPACE,
7784
            '-',
7785
            '=',
7786
            '[',
7787
            ']',
7788
            '\\',
7789
            '#',
7790
            ';',
7791
            '\'',
7792
            '`',
7793
            ',',
7794
            '.',
7795
            '/',
7796
            SDL_Keycode.SDLK_CAPSLOCK,
7797
            SDL_Keycode.SDLK_F1,
7798
            SDL_Keycode.SDLK_F2,
7799
            SDL_Keycode.SDLK_F3,
7800
            SDL_Keycode.SDLK_F4,
7801
            SDL_Keycode.SDLK_F5,
7802
            SDL_Keycode.SDLK_F6,
7803
            SDL_Keycode.SDLK_F7,
7804
            SDL_Keycode.SDLK_F8,
7805
            SDL_Keycode.SDLK_F9,
7806
            SDL_Keycode.SDLK_F10,
7807
            SDL_Keycode.SDLK_F11,
7808
            SDL_Keycode.SDLK_F12,
7809
            SDL_Keycode.SDLK_PRINTSCREEN,
7810
            SDL_Keycode.SDLK_SCROLLLOCK,
7811
            SDL_Keycode.SDLK_PAUSE,
7812
            SDL_Keycode.SDLK_INSERT,
7813
            SDL_Keycode.SDLK_HOME,
7814
            SDL_Keycode.SDLK_PAGEUP,
7815
            SDL_Keycode.SDLK_DELETE,
7816
            SDL_Keycode.SDLK_END,
7817
            SDL_Keycode.SDLK_PAGEDOWN,
7818
            SDL_Keycode.SDLK_RIGHT,
7819
            SDL_Keycode.SDLK_LEFT,
7820
            SDL_Keycode.SDLK_DOWN,
7821
            SDL_Keycode.SDLK_UP,
7822
            SDL_Keycode.SDLK_NUMLOCKCLEAR,
7823
            SDL_Keycode.SDLK_KP_DIVIDE,
7824
            SDL_Keycode.SDLK_KP_MULTIPLY,
7825
            SDL_Keycode.SDLK_KP_MINUS,
7826
            SDL_Keycode.SDLK_KP_PLUS,
7827
            SDL_Keycode.SDLK_KP_ENTER,
7828
            SDL_Keycode.SDLK_KP_1,
7829
            SDL_Keycode.SDLK_KP_2,
7830
            SDL_Keycode.SDLK_KP_3,
7831
            SDL_Keycode.SDLK_KP_4,
7832
            SDL_Keycode.SDLK_KP_5,
7833
            SDL_Keycode.SDLK_KP_6,
7834
            SDL_Keycode.SDLK_KP_7,
7835
            SDL_Keycode.SDLK_KP_8,
7836
            SDL_Keycode.SDLK_KP_9,
7837
            SDL_Keycode.SDLK_KP_0,
7838
            SDL_Keycode.SDLK_KP_PERIOD,
7839
            0,
7840
            SDL_Keycode.SDLK_APPLICATION,
7841
            SDL_Keycode.SDLK_POWER,
7842
            SDL_Keycode.SDLK_KP_EQUALS,
7843
            SDL_Keycode.SDLK_F13,
7844
            SDL_Keycode.SDLK_F14,
7845
            SDL_Keycode.SDLK_F15,
7846
            SDL_Keycode.SDLK_F16,
7847
            SDL_Keycode.SDLK_F17,
7848
            SDL_Keycode.SDLK_F18,
7849
            SDL_Keycode.SDLK_F19,
7850
            SDL_Keycode.SDLK_F20,
7851
            SDL_Keycode.SDLK_F21,
7852
            SDL_Keycode.SDLK_F22,
7853
            SDL_Keycode.SDLK_F23,
7854
            SDL_Keycode.SDLK_F24,
7855
            SDL_Keycode.SDLK_EXECUTE,
7856
            SDL_Keycode.SDLK_HELP,
7857
            SDL_Keycode.SDLK_MENU,
7858
            SDL_Keycode.SDLK_SELECT,
7859
            SDL_Keycode.SDLK_STOP,
7860
            SDL_Keycode.SDLK_AGAIN,
7861
            SDL_Keycode.SDLK_UNDO,
7862
            SDL_Keycode.SDLK_CUT,
7863
            SDL_Keycode.SDLK_COPY,
7864
            SDL_Keycode.SDLK_PASTE,
7865
            SDL_Keycode.SDLK_FIND,
7866
            SDL_Keycode.SDLK_MUTE,
7867
            SDL_Keycode.SDLK_VOLUMEUP,
7868
            SDL_Keycode.SDLK_VOLUMEDOWN,
7869
            0, 0, 0,
7870
            SDL_Keycode.SDLK_KP_COMMA,
7871
            SDL_Keycode.SDLK_KP_EQUALSAS400,
7872
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7873
            SDL_Keycode.SDLK_ALTERASE,
7874
            SDL_Keycode.SDLK_SYSREQ,
7875
            SDL_Keycode.SDLK_CANCEL,
7876
            SDL_Keycode.SDLK_CLEAR,
7877
            SDL_Keycode.SDLK_PRIOR,
7878
            SDL_Keycode.SDLK_RETURN2,
7879
            SDL_Keycode.SDLK_SEPARATOR,
7880
            SDL_Keycode.SDLK_OUT,
7881
            SDL_Keycode.SDLK_OPER,
7882
            SDL_Keycode.SDLK_CLEARAGAIN,
7883
            SDL_Keycode.SDLK_CRSEL,
7884
            SDL_Keycode.SDLK_EXSEL,
7885
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7886
            SDL_Keycode.SDLK_KP_00,
7887
            SDL_Keycode.SDLK_KP_000,
7888
            SDL_Keycode.SDLK_THOUSANDSSEPARATOR,
7889
            SDL_Keycode.SDLK_DECIMALSEPARATOR,
7890
            SDL_Keycode.SDLK_CURRENCYUNIT,
7891
            SDL_Keycode.SDLK_CURRENCYSUBUNIT,
7892
            SDL_Keycode.SDLK_KP_LEFTPAREN,
7893
            SDL_Keycode.SDLK_KP_RIGHTPAREN,
7894
            SDL_Keycode.SDLK_KP_LEFTBRACE,
7895
            SDL_Keycode.SDLK_KP_RIGHTBRACE,
7896
            SDL_Keycode.SDLK_KP_TAB,
7897
            SDL_Keycode.SDLK_KP_BACKSPACE,
7898
            SDL_Keycode.SDLK_KP_A,
7899
            SDL_Keycode.SDLK_KP_B,
7900
            SDL_Keycode.SDLK_KP_C,
7901
            SDL_Keycode.SDLK_KP_D,
7902
            SDL_Keycode.SDLK_KP_E,
7903
            SDL_Keycode.SDLK_KP_F,
7904
            SDL_Keycode.SDLK_KP_XOR,
7905
            SDL_Keycode.SDLK_KP_POWER,
7906
            SDL_Keycode.SDLK_KP_PERCENT,
7907
            SDL_Keycode.SDLK_KP_LESS,
7908
            SDL_Keycode.SDLK_KP_GREATER,
7909
            SDL_Keycode.SDLK_KP_AMPERSAND,
7910
            SDL_Keycode.SDLK_KP_DBLAMPERSAND,
7911
            SDL_Keycode.SDLK_KP_VERTICALBAR,
7912
            SDL_Keycode.SDLK_KP_DBLVERTICALBAR,
7913
            SDL_Keycode.SDLK_KP_COLON,
7914
            SDL_Keycode.SDLK_KP_HASH,
7915
            SDL_Keycode.SDLK_KP_SPACE,
7916
            SDL_Keycode.SDLK_KP_AT,
7917
            SDL_Keycode.SDLK_KP_EXCLAM,
7918
            SDL_Keycode.SDLK_KP_MEMSTORE,
7919
            SDL_Keycode.SDLK_KP_MEMRECALL,
7920
            SDL_Keycode.SDLK_KP_MEMCLEAR,
7921
            SDL_Keycode.SDLK_KP_MEMADD,
7922
            SDL_Keycode.SDLK_KP_MEMSUBTRACT,
7923
            SDL_Keycode.SDLK_KP_MEMMULTIPLY,
7924
            SDL_Keycode.SDLK_KP_MEMDIVIDE,
7925
            SDL_Keycode.SDLK_KP_PLUSMINUS,
7926
            SDL_Keycode.SDLK_KP_CLEAR,
7927
            SDL_Keycode.SDLK_KP_CLEARENTRY,
7928
            SDL_Keycode.SDLK_KP_BINARY,
7929
            SDL_Keycode.SDLK_KP_OCTAL,
7930
            SDL_Keycode.SDLK_KP_DECIMAL,
7931
            SDL_Keycode.SDLK_KP_HEXADECIMAL,
7932
            0, 0,
7933
            SDL_Keycode.SDLK_LCTRL,
7934
            SDL_Keycode.SDLK_LSHIFT,
7935
            SDL_Keycode.SDLK_LALT,
7936
            SDL_Keycode.SDLK_LGUI,
7937
            SDL_Keycode.SDLK_RCTRL,
7938
            SDL_Keycode.SDLK_RSHIFT,
7939
            SDL_Keycode.SDLK_RALT,
7940
            SDL_Keycode.SDLK_RGUI,
7941
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7942
            SDL_Keycode.SDLK_MODE,
7943
            SDL_Keycode.SDLK_AUDIONEXT,
7944
            SDL_Keycode.SDLK_AUDIOPREV,
7945
            SDL_Keycode.SDLK_AUDIOSTOP,
7946
            SDL_Keycode.SDLK_AUDIOPLAY,
7947
            SDL_Keycode.SDLK_AUDIOMUTE,
7948
            SDL_Keycode.SDLK_MEDIASELECT,
7949
            SDL_Keycode.SDLK_WWW,
7950
            SDL_Keycode.SDLK_MAIL,
7951
            SDL_Keycode.SDLK_CALCULATOR,
7952
            SDL_Keycode.SDLK_COMPUTER,
7953
            SDL_Keycode.SDLK_AC_SEARCH,
7954
            SDL_Keycode.SDLK_AC_HOME,
7955
            SDL_Keycode.SDLK_AC_BACK,
7956
            SDL_Keycode.SDLK_AC_FORWARD,
7957
            SDL_Keycode.SDLK_AC_STOP,
7958
            SDL_Keycode.SDLK_AC_REFRESH,
7959
            SDL_Keycode.SDLK_AC_BOOKMARKS,
7960
            SDL_Keycode.SDLK_BRIGHTNESSDOWN,
7961
            SDL_Keycode.SDLK_BRIGHTNESSUP,
7962
            SDL_Keycode.SDLK_DISPLAYSWITCH,
7963
            SDL_Keycode.SDLK_KBDILLUMTOGGLE,
7964
            SDL_Keycode.SDLK_KBDILLUMDOWN,
7965
            SDL_Keycode.SDLK_KBDILLUMUP,
7966
            SDL_Keycode.SDLK_EJECT,
7967
            SDL_Keycode.SDLK_SLEEP,
7968
            SDL_Keycode.SDLK_APP1,
7969
            SDL_Keycode.SDLK_APP2,
7970
            SDL_Keycode.SDLK_AUDIOREWIND,
7971
            SDL_Keycode.SDLK_AUDIOFASTFORWARD
7972
        };
7973
        #endregion
7974

7975
        #region SDL_crc16
7976
        static ushort crc16_for_byte(byte r)
7977
        {
7978
            ushort crc = 0;
7979

7980
            for (int i = 0; i < 8; ++i) 
7981
            {
7982
                if (((crc ^ r) & 1) != 0)
7983
                    crc = (ushort)(0xA001 ^ crc >> 1);
7984
                else
7985
                    crc = (ushort)(0 ^ crc >> 1);
7986

7987
                r >>= 1;
7988
            }
7989
            return crc;
7990
        }
7991

7992
        public static ushort SDL_crc16(byte[] data, ushort crc = 0)
7993
        {
7994
            // As an optimization we can precalculate a 256 entry table for each byte
7995
            for (int i = 0; i < data.Length; ++i) 
7996
            {
7997
                byte bt = (byte) (((byte)crc) ^ data[i]);
7998

7999
                ushort us = crc16_for_byte(bt);
8000
                crc = (ushort)(us ^ crc >> 8);
8001
            }
8002
            return crc;
8003
        }
8004

8005
        public static ushort SDL_Swap16(ushort x)
8006
        {
8007
            return (ushort)((ushort)((x & 0xff) << 8) | ((x >> 8) & 0xff));
8008
        }
8009
        #endregion
8010
    }
8011
}
8012

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.