-
Notifications
You must be signed in to change notification settings - Fork 33
/
SDL2.cs
5642 lines (4992 loc) · 232 KB
/
SDL2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#region License
/* SDL2# - C# Wrapper for SDL2
*
* Copyright (c) 2013-2014 Ethan Lee.
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from
* the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software in a
* product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
* Ethan "flibitijibibo" Lee <[email protected]>
*
*/
#endregion
#region Using Statements
using System;
using System.Runtime.InteropServices;
#endregion
namespace SDL2
{
/// <summary>
/// Entry point for all SDL-related (non-extension) types and methods
/// </summary>
public static class SDL
{
#region SDL2# Variables
/// <summary>
/// Used by DllImport to load the native library.
/// </summary>
///
#if LINUX
private const string nativeLibName = "libSDL2-2.0.so.0";
#else
private const string nativeLibName = "SDL2.dll";
#endif
#endregion
#region SDL_stdinc.h
public static uint SDL_FOURCC(byte A, byte B, byte C, byte D)
{
return (uint)(A | (B << 8) | (C << 16) | (D << 24));
}
public enum SDL_bool
{
SDL_FALSE = 0,
SDL_TRUE = 1
}
#endregion
#region SDL_rwops.h
/* Note about SDL2# and Internal RWops:
* These functions are currently not supported for public use.
* They are only meant to be used internally in functions marked with
* the phrase "THIS IS AN RWops FUNCTION!"
*/
/// <summary>
/// Use this function to create a new SDL_RWops structure for reading from and/or writing to a named file.
/// </summary>
/// <param name="file">a UTF-8 string representing the filename to open</param>
/// <param name="mode">an ASCII string representing the mode to be used for opening the file; see Remarks for details</param>
/// <returns>Returns a pointer to the SDL_RWops structure that is created, or NULL on failure; call SDL_GetError() for more information.</returns>
[DllImport(nativeLibName, EntryPoint = "SDL_RWFromFile", CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr INTERNAL_SDL_RWFromFile(
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string file,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string mode
);
/* These are the public RWops functions. They should be used by
* functions marked with the phrase "THIS IS A PUBLIC RWops FUNCTION!"
*/
/* IntPtr refers to an SDL_RWops */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr SDL_RWFromMem(byte[] mem, int size);
#endregion
#region SDL_main.h
/// <summary>
/// Use this function to circumvent failure of SDL_Init() when not using SDL_main() as an entry point.
/// </summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_SetMainReady();
#endregion
#region SDL.h
public const uint SDL_INIT_TIMER = 0x00000001;
public const uint SDL_INIT_AUDIO = 0x00000010;
public const uint SDL_INIT_VIDEO = 0x00000020;
public const uint SDL_INIT_JOYSTICK = 0x00000200;
public const uint SDL_INIT_HAPTIC = 0x00001000;
public const uint SDL_INIT_GAMECONTROLLER = 0x00002000;
public const uint SDL_INIT_NOPARACHUTE = 0x00100000;
public const uint SDL_INIT_EVERYTHING = (
SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO |
SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC |
SDL_INIT_GAMECONTROLLER
);
/// <summary>
/// Use this function to initialize the SDL library.
/// This must be called before using any other SDL function.
/// </summary>
/// <param name="flags">subsystem initialization flags; see Remarks for details</param>
/// <returns>Returns 0 on success or a negative error code on failure.
/// Call <see cref="SDL_GetError()"/> for more information.</returns>
/// <remarks>The Event Handling, File I/O, and Threading subsystems are initialized by default.
/// You must specifically initialize other subsystems if you use them in your application.</remarks>
/// <remarks>Unless the SDL_INIT_NOPARACHUTE flag is set, it will install cleanup signal handlers
/// for some commonly ignored fatal signals (like SIGSEGV). </remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_Init(uint flags);
/// <summary>
/// Use this function to initialize specific SDL subsystems.
/// </summary>
/// <param name="flags">any of the flags used by SDL_Init(); see Remarks for details</param>
/// <returns>Returns 0 on success or a negative error code on failure.
/// Call <see cref="SDL_GetError()"/> for more information.</returns>
/// <remarks>After SDL has been initialized with <see cref="SDL_Init()"/> you may initialize
/// uninitialized subsystems with <see cref="SDL_InitSubSystem()"/>.</remarks>
/// <remarks>If you want to initialize subsystems separately you would call <see cref="SDL_Init(0)"/>
/// followed by <see cref="SDL_InitSubSystem()"/> with the desired subsystem flag. </remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_InitSubSystem(uint flags);
/// <summary>
/// Use this function to clean up all initialized subsystems.
/// You should call it upon all exit conditions.
/// </summary>
/// <remarks>You should call this function even if you have already shutdown each initialized
/// subsystem with <see cref="SDL_QuitSubSystem()"/>.</remarks>
/// <remarks>If you start a subsystem using a call to that subsystem's init function (for example
/// <see cref="SDL_VideoInit()"/>) instead of <see cref="SDL_Init()"/> or <see cref="SDL_InitSubSystem()"/>,
/// then you must use that subsystem's quit function (<see cref="SDL_VideoQuit()"/>) to shut it down
/// before calling <see cref="SDL_Quit()"/>.</remarks>
/// <remarks>You can use this function with atexit() to ensure that it is run when your application is
/// shutdown, but it is not wise to do this from a library or other dynamically loaded code. </remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_Quit();
/// <summary>
/// Use this function to shut down specific SDL subsystems.
/// </summary>
/// <param name="flags">any of the flags used by <see cref="SDL_Init()"/>; see Remarks for details</param>
/// <remarks>If you start a subsystem using a call to that subsystem's init function (for example
/// <see cref="SDL_VideoInit()"/>) instead of <see cref="SDL_Init()"/> or <see cref="SDL_InitSubSystem()"/>,
/// then you must use that subsystem's quit function (<see cref="SDL_VideoQuit()"/>) to shut it down
/// before calling <see cref="SDL_Quit()"/>.</remarks>
/// <remarks>You can use this function with atexit() to en
/// <remarks>You still need to call <see cref="SDL_Quit()"/> even if you close all open subsystems with SDL_QuitSubSystem(). </remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_QuitSubSystem(uint flags);
/// <summary>
/// Use this function to return a mask of the specified subsystems which have previously been initialized.
/// </summary>
/// <param name="flags">any of the flags used by <see cref="SDL_Init()"/>; see Remarks for details</param>
/// <returns>If flags is 0 it returns a mask of all initialized subsystems, otherwise it returns the
/// initialization status of the specified subsystems. The return value does not include SDL_INIT_NOPARACHUTE.</returns>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint SDL_WasInit(uint flags);
#endregion
#region SDL_platform.h
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler), MarshalCookie = LPUtf8StrMarshaler.LeaveAllocated)]
public static extern string SDL_GetPlatform();
#endregion
#region SDL_hints.h
public const string SDL_HINT_FRAMEBUFFER_ACCELERATION =
"SDL_FRAMEBUFFER_ACCELERATION";
public const string SDL_HINT_RENDER_DRIVER =
"SDL_RENDER_DRIVER";
public const string SDL_HINT_RENDER_OPENGL_SHADERS =
"SDL_RENDER_OPENGL_SHADERS";
public const string SDL_HINT_RENDER_DIRECT3D_THREADSAFE =
"SDL_RENDER_DIRECT3D_THREADSAFE";
public const string SDL_HINT_RENDER_VSYNC =
"SDL_RENDER_VSYNC";
public const string SDL_HINT_VIDEO_X11_XVIDMODE =
"SDL_VIDEO_X11_XVIDMODE";
public const string SDL_HINT_VIDEO_X11_XINERAMA =
"SDL_VIDEO_X11_XINERAMA";
public const string SDL_HINT_VIDEO_X11_XRANDR =
"SDL_VIDEO_X11_XRANDR";
public const string SDL_HINT_GRAB_KEYBOARD =
"SDL_GRAB_KEYBOARD";
public const string SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS =
"SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS";
public const string SDL_HINT_IDLE_TIMER_DISABLED =
"SDL_IOS_IDLE_TIMER_DISABLED";
public const string SDL_HINT_ORIENTATIONS =
"SDL_IOS_ORIENTATIONS";
public const string SDL_HINT_XINPUT_ENABLED =
"SDL_XINPUT_ENABLED";
public const string SDL_HINT_GAMECONTROLLERCONFIG =
"SDL_GAMECONTROLLERCONFIG";
public const string SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS =
"SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS";
public const string SDL_HINT_ALLOW_TOPMOST =
"SDL_ALLOW_TOPMOST";
public const string SDL_HINT_TIMER_RESOLUTION =
"SDL_TIMER_RESOLUTION";
public const string SDL_HINT_RENDER_SCALE_QUALITY =
"SDL_RENDER_SCALE_QUALITY";
/* Only available in SDL 2.0.1 or higher */
public const string SDL_HINT_VIDEO_HIGHDPI_DISABLED =
"SDL_VIDEO_HIGHDPI_DISABLED";
/* Only available in SDL 2.0.2 or higher */
public const string SDL_HINT_CTRL_CLICK_EMULATE_RIGHT_CLICK =
"SDL_CTRL_CLICK_EMULATE_RIGHT_CLICK";
public const string SDL_HINT_VIDEO_WIN_D3DCOMPILER =
"SDL_VIDEO_WIN_D3DCOMPILER";
public const string SDL_HINT_MOUSE_RELATIVE_MODE_WARP =
"SDL_MOUSE_RELATIVE_MODE_WARP";
public const string SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT =
"SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT";
public const string SDL_HINT_VIDEO_ALLOW_SCREENSAVER =
"SDL_VIDEO_ALLOW_SCREENSAVER";
public const string SDL_HINT_ACCELEROMETER_AS_JOYSTICK =
"SDL_ACCELEROMETER_AS_JOYSTICK";
public const string SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES =
"SDL_VIDEO_MAC_FULLSCREEN_SPACES";
public enum SDL_HintPriority
{
SDL_HINT_DEFAULT,
SDL_HINT_NORMAL,
SDL_HINT_OVERRIDE
}
/// <summary>
/// Use this function to clear all hints.
/// </summary>
/// <remarks>This function is automatically called during <see cref="SDL_Quit()"/>. </remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_ClearHints();
/// <summary>
/// Use this function to get the value of a hint.
/// </summary>
/// <param name="name">the hint to query; see the list of hints on
/// <a href="http://wiki.libsdl.org/moin.cgi/CategoryHints#Hints">CategoryHints</a> for details</param>
/// <returns>Returns the string value of a hint or NULL if the hint isn't set.</returns>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler), MarshalCookie = LPUtf8StrMarshaler.LeaveAllocated)]
public static extern string SDL_GetHint(
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string name
);
/// <summary>
/// Use this function to set a hint with normal priority.
/// </summary>
/// <param name="name">the hint to query; see the list of hints on
/// <a href="http://wiki.libsdl.org/moin.cgi/CategoryHints#Hints">CategoryHints</a> for details</param>
/// <param name="value">the value of the hint variable</param>
/// <returns>Returns SDL_TRUE if the hint was set, SDL_FALSE otherwise.</returns>
/// <remarks>Hints will not be set if there is an existing override hint or environment
/// variable that takes precedence. You can use <see cref="SDL_SetHintWithPriority()"/> to set the hint with
/// override priority instead.</remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern SDL_bool SDL_SetHint(
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string name,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string value
);
/// <summary>
/// Use this function to set a hint with a specific priority.
/// </summary>
/// <param name="name">the hint to query; see the list of hints on
/// <a href="http://wiki.libsdl.org/moin.cgi/CategoryHints#Hints">CategoryHints</a> for details</param>
/// <param name="value">the value of the hint variable</param>
/// <param name="priority">the <see cref="SDL_HintPriority"/> level for the hint</param>
/// <returns>Returns SDL_TRUE if the hint was set, SDL_FALSE otherwise.</returns>
/// <remarks>The priority controls the behavior when setting a hint that already has a value.
/// Hints will replace existing hints of their priority and lower. Environment variables are
/// considered to have override priority. </remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern SDL_bool SDL_SetHintWithPriority(
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string name,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string value,
SDL_HintPriority priority
);
#endregion
#region SDL_error.h
/// <summary>
/// Use this function to clear any previous error message.
/// </summary>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_ClearError();
/// <summary>
/// Use this function to retrieve a message about the last error that occurred.
/// </summary>
/// <returns>Returns a message with information about the specific error that occurred,
/// or an empty string if there hasn't been an error since the last call to <see cref="SDL_ClearError()"/>.
/// Without calling <see cref="SDL_ClearError()"/>, the message is only applicable when an SDL function
/// has signaled an error. You must check the return values of SDL function calls to determine
/// when to appropriately call <see cref="SDL_GetError()"/>.
/// This string is statically allocated and must not be freed by the application.</returns>
/// <remarks>It is possible for multiple errors to occur before calling SDL_GetError(). Only the last error is returned. </remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler), MarshalCookie = LPUtf8StrMarshaler.LeaveAllocated)]
public static extern string SDL_GetError();
/// <summary>
/// Use this function to set the SDL error string.
/// </summary>
/// <param name="fmt">a printf() style message format string </param>
/// <param name="...">additional parameters matching % tokens in the fmt string, if any</param>
/// <remarks>Calling this function will replace any previous error message that was set.</remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_SetError(
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string fmt,
__arglist
);
#endregion
#region SDL_log.h
/* Begin nameless enum SDL_LOG_CATEGORY */
public const int SDL_LOG_CATEGORY_APPLICATION = 0;
public const int SDL_LOG_CATEGORY_ERROR = 1;
public const int SDL_LOG_CATEGORY_ASSERT = 2;
public const int SDL_LOG_CATEGORY_SYSTEM = 3;
public const int SDL_LOG_CATEGORY_AUDIO = 4;
public const int SDL_LOG_CATEGORY_VIDEO = 5;
public const int SDL_LOG_CATEGORY_RENDER = 6;
public const int SDL_LOG_CATEGORY_INPUT = 7;
public const int SDL_LOG_CATEGORY_TEST = 8;
/* Reserved for future SDL library use */
public const int SDL_LOG_CATEGORY_RESERVED1 = 9;
public const int SDL_LOG_CATEGORY_RESERVED2 = 10;
public const int SDL_LOG_CATEGORY_RESERVED3 = 11;
public const int SDL_LOG_CATEGORY_RESERVED4 = 12;
public const int SDL_LOG_CATEGORY_RESERVED5 = 13;
public const int SDL_LOG_CATEGORY_RESERVED6 = 14;
public const int SDL_LOG_CATEGORY_RESERVED7 = 15;
public const int SDL_LOG_CATEGORY_RESERVED8 = 16;
public const int SDL_LOG_CATEGORY_RESERVED9 = 17;
public const int SDL_LOG_CATEGORY_RESERVED10 = 18;
/* Beyond this point is reserved for application use, e.g.
enum {
LOG_CATEGORY_AWESOME1 = SDL_LOG_CATEGORY_CUSTOM,
LOG_CATEGORY_AWESOME2,
LOG_CATEGORY_AWESOME3,
...
};
*/
public const int SDL_LOG_CATEGORY_CUSTOM = 19;
/* End nameless enum SDL_LOG_CATEGORY */
/// <summary>
/// An enumeration of the predefined log priorities.
/// </summary>
public enum SDL_LogPriority
{
SDL_LOG_PRIORITY_VERBOSE = 1,
SDL_LOG_PRIORITY_DEBUG,
SDL_LOG_PRIORITY_INFO,
SDL_LOG_PRIORITY_WARN,
SDL_LOG_PRIORITY_ERROR,
SDL_LOG_PRIORITY_CRITICAL,
SDL_NUM_LOG_PRIORITIES
}
/// <summary>
/// Used as a callback for <see cref="SDL_LogGetOutputFunction()"/> and <see cref="SDL_LogSetOutputFunction()"/>
/// </summary>
/// <param name="userdata">what was passed as userdata to <see cref="SDL_LogSetOutputFunction()"/></param>
/// <param name="category">the category of the message; see Remarks for details</param>
/// <param name="priority">the priority of the message; see Remarks for details</param>
/// <param name="message">the message being output</param>
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
/// <remarks>The priority can be one of SDL_LOG_PRIORITY*</remarks>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void SDL_LogOutputFunction(
IntPtr userdata, // void*
int category,
SDL_LogPriority priority,
IntPtr message // const char*
);
/// <summary>
/// Use this function to log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO.
/// </summary>
/// <param name="fmt">a printf() style message format string</param>
/// <param name="...">additional parameters matching % tokens in the fmt string, if any</param>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_Log(
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string fmt,
__arglist
);
/// <summary>
/// Use this function to log a message with SDL_LOG_PRIORITY_VERBOSE.
/// </summary>
/// <param name="category">the category of the message; see Remarks for details</param>
/// <param name="fmt">a printf() style message format string</param>
/// <param name="...">additional parameters matching % tokens in the fmt string, if any</param>
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_LogVerbose(
int category,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string fmt,
__arglist
);
/// <summary>
/// Use this function to log a message with SDL_LOG_PRIORITY_DEBUG.
/// </summary>
/// <param name="category">the category of the message; see Remarks for details</param>
/// <param name="fmt">a printf() style message format string</param>
/// <param name="...">additional parameters matching % tokens in the fmt string, if any</param>
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_LogDebug(
int category,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string fmt,
__arglist
);
/// <summary>
/// Use this function to log a message with SDL_LOG_PRIORITY_INFO.
/// </summary>
/// <param name="category">the category of the message; see Remarks for details</param>
/// <param name="fmt">a printf() style message format string</param>
/// <param name="...">additional parameters matching % tokens in the fmt string, if any</param>
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_LogInfo(
int category,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string fmt,
__arglist
);
/// <summary>
/// Use this function to log a message with SDL_LOG_PRIORITY_WARN.
/// </summary>
/// <param name="category">the category of the message; see Remarks for details</param>
/// <param name="fmt">a printf() style message format string</param>
/// <param name="...">additional parameters matching % tokens in the fmt string, if any</param>
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_LogWarn(
int category,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string fmt,
__arglist
);
/// <summary>
/// Use this function to log a message with SDL_LOG_PRIORITY_ERROR.
/// </summary>
/// <param name="category">the category of the message; see Remarks for details</param>
/// <param name="fmt">a printf() style message format string</param>
/// <param name="...">additional parameters matching % tokens in the fmt string, if any</param>
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_LogError(
int category,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string fmt,
__arglist
);
/// <summary>
/// Use this function to log a message with SDL_LOG_PRIORITY_CRITICAL.
/// </summary>
/// <param name="category">the category of the message; see Remarks for details</param>
/// <param name="fmt">a printf() style message format string</param>
/// <param name="...">additional parameters matching % tokens in the fmt string, if any</param>
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_LogCritical(
int category,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string fmt,
__arglist
);
/// <summary>
/// Use this function to log a message with the specified category and priority.
/// </summary>
/// <param name="category">the category of the message; see Remarks for details</param>
/// <param name="priority">the priority of the message; see Remarks for details</param>
/// <param name="fmt">a printf() style message format string</param>
/// <param name="...">additional parameters matching % tokens in the fmt string, if any</param>
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
/// <remarks>The priority can be one of SDL_LOG_PRIORITY*</remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_LogMessage(
int category,
SDL_LogPriority priority,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string fmt,
__arglist
);
/// <summary>
/// Use this function to log a message with the specified category and priority.
/// This version of <see cref="SDL_LogMessage"/> uses a stdarg variadic argument list.
/// </summary>
/// <param name="category">the category of the message; see Remarks for details</param>
/// <param name="priority">the priority of the message; see Remarks for details</param>
/// <param name="fmt">a printf() style message format string</param>
/// <param name="...">additional parameters matching % tokens in the fmt string, if any</param>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_LogMessageV(
int category,
SDL_LogPriority priority,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string fmt,
__arglist
);
/// <summary>
/// Use this function to get the priority of a particular log category.
/// </summary>
/// <param name="category">the category to query; see Remarks for details</param>
/// <returns>Returns the <see cref="SDL_LogPriority"/> for the requested category; see Remarks for details. </returns>
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
/// <remarks>The returned priority will be one of SDL_LOG_PRIORITY*</remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern SDL_LogPriority SDL_LogGetPriority(
int category
);
/// <summary>
/// Use this function to set the priority of a particular log category.
/// </summary>
/// <param name="category">the category to query; see Remarks for details</param>
/// <param name="priority">the <see cref="SDL_LogPriority"/> of the message; see Remarks for details</param>
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
/// <remarks>The priority can be one of SDL_LOG_PRIORITY*</remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_LogSetPriority(
int category,
SDL_LogPriority priority
);
/// <summary>
/// Use this function to set the priority of all log categories.
/// </summary>
/// <param name="priority">the <see cref="SDL_LogPriority"/> of the message; see Remarks for details</param>
/// <remarks>The priority can be one of SDL_LOG_PRIORITY*</remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_LogSetAllPriority(
SDL_LogPriority priority
);
/// <summary>
/// Use this function to reset all priorities to default.
/// </summary>
/// <remarks>This is called in <see cref="SDL_Quit()"/>. </remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_LogResetPriorities();
/// <summary>
/// Use this function to get the current log output function.
/// </summary>
/// <param name="callback">a pointer filled in with the current log callback; see Remarks for details</param>
/// <param name="userdata">a pointer filled in with the pointer that is passed to callback (refers to void*)</param>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_LogGetOutputFunction(
out SDL_LogOutputFunction callback,
out IntPtr userdata
);
/* userdata refers to a void* */
/// <summary>
/// Use this function to replace the default log output function with one of your own.
/// </summary>
/// <param name="callback">the function to call instead of the default; see Remarks for details</param>
/// <param name="userdata">a pointer that is passed to callback (refers to void*)</param>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_LogSetOutputFunction(
SDL_LogOutputFunction callback,
IntPtr userdata
);
#endregion
#region SDL_messagebox.h
[Flags]
public enum SDL_MessageBoxFlags : uint
{
SDL_MESSAGEBOX_ERROR = 0x00000010,
SDL_MESSAGEBOX_WARNING = 0x00000020,
SDL_MESSAGEBOX_INFORMATION = 0x00000040
}
[Flags]
public enum SDL_MessageBoxButtonFlags : uint
{
SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001,
SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002
}
[StructLayout(LayoutKind.Sequential)]
private struct INTERNAL_SDL_MessageBoxButtonData
{
public SDL_MessageBoxButtonFlags flags;
public int buttonid;
public IntPtr text; /* The UTF-8 button text */
}
[StructLayout(LayoutKind.Sequential)]
public struct SDL_MessageBoxButtonData
{
public SDL_MessageBoxButtonFlags flags;
public int buttonid;
public string text; /* The UTF-8 button text */
}
[StructLayout(LayoutKind.Sequential)]
public struct SDL_MessageBoxColor
{
public byte r, g, b;
}
public enum SDL_MessageBoxColorType
{
SDL_MESSAGEBOX_COLOR_BACKGROUND,
SDL_MESSAGEBOX_COLOR_TEXT,
SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,
SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND,
SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED,
SDL_MESSAGEBOX_COLOR_MAX
}
[StructLayout(LayoutKind.Sequential)]
public struct SDL_MessageBoxColorScheme
{
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = (int)SDL_MessageBoxColorType.SDL_MESSAGEBOX_COLOR_MAX)]
public SDL_MessageBoxColor[] colors;
}
[StructLayout(LayoutKind.Sequential)]
private struct INTERNAL_SDL_MessageBoxData
{
public SDL_MessageBoxFlags flags;
public IntPtr window; /* Parent window, can be NULL */
public IntPtr title; /* UTF-8 title */
public IntPtr message; /* UTF-8 message text */
public int numbuttons;
public IntPtr buttons;
public IntPtr colorScheme; /* Can be NULL to use system settings */
}
[StructLayout(LayoutKind.Sequential)]
public struct SDL_MessageBoxData
{
public SDL_MessageBoxFlags flags;
public IntPtr window; /* Parent window, can be NULL */
public string title; /* UTF-8 title */
public string message; /* UTF-8 message text */
public int numbuttons;
public SDL_MessageBoxButtonData[] buttons;
public SDL_MessageBoxColorScheme? colorScheme; /* Can be NULL to use system settings */
}
/// <summary>
///
/// </summary>
/// <param name="messageboxdata"></param>
/// <param name="buttonid"></param>
/// <returns></returns>
[DllImport(nativeLibName, EntryPoint = "SDL_ShowMessageBox", CallingConvention = CallingConvention.Cdecl)]
private static extern int INTERNAL_SDL_ShowMessageBox([In()] ref INTERNAL_SDL_MessageBoxData messageboxdata, out int buttonid);
/// <summary>
///
/// </summary>
/// <param name="messageboxdata"></param>
/// <param name="buttonid"></param>
/// <returns></returns>
public static unsafe int SDL_ShowMessageBox([In()] ref SDL_MessageBoxData messageboxdata, out int buttonid)
{
var utf8 = LPUtf8StrMarshaler.GetInstance(null);
var data = new INTERNAL_SDL_MessageBoxData()
{
flags = messageboxdata.flags,
window = messageboxdata.window,
title = utf8.MarshalManagedToNative(messageboxdata.title),
message = utf8.MarshalManagedToNative(messageboxdata.message),
numbuttons = messageboxdata.numbuttons,
};
var buttons = new INTERNAL_SDL_MessageBoxButtonData[messageboxdata.numbuttons];
for (int i = 0; i < messageboxdata.numbuttons; i++)
{
buttons[i] = new INTERNAL_SDL_MessageBoxButtonData()
{
flags = messageboxdata.buttons[i].flags,
buttonid = messageboxdata.buttons[i].buttonid,
text = utf8.MarshalManagedToNative(messageboxdata.buttons[i].text),
};
}
if (messageboxdata.colorScheme != null)
{
data.colorScheme = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SDL_MessageBoxColorScheme)));
Marshal.StructureToPtr(messageboxdata.colorScheme.Value, data.colorScheme, false);
}
int result;
fixed (INTERNAL_SDL_MessageBoxButtonData* buttonsPtr = &buttons[0])
{
data.buttons = (IntPtr)buttonsPtr;
result = INTERNAL_SDL_ShowMessageBox(ref data, out buttonid);
}
Marshal.FreeHGlobal(data.colorScheme);
for (int i = 0; i < messageboxdata.numbuttons; i++)
{
utf8.CleanUpNativeData(buttons[i].text);
}
utf8.CleanUpNativeData(data.message);
utf8.CleanUpNativeData(data.title);
return result;
}
/// <summary>
/// Use this function to display a simple message box.
/// </summary>
/// <param name="flags">An <see cref="SDL_MessageBoxFlag"/>; see Remarks for details;</param>
/// <param name="title">UTF-8 title text</param>
/// <param name="message">UTF-8 message text</param>
/// <param name="window">the parent window, or NULL for no parent (refers to a <see cref="SDL_Window"/></param>
/// <returns>0 on success or a negative error code on failure; call SDL_GetError() for more information. </returns>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_ShowSimpleMessageBox(
SDL_MessageBoxFlags flags,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string title,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string message,
IntPtr window
);
#endregion
#region SDL_version.h, SDL_revision.h
/* Similar to the headers, this is the version we're expecting to be
* running with. You will likely want to check this somewhere in your
* program!
*/
public const int SDL_MAJOR_VERSION = 2;
public const int SDL_MINOR_VERSION = 0;
public const int SDL_PATCHLEVEL = 3;
public static readonly int SDL_COMPILEDVERSION = SDL_VERSIONNUM(
SDL_MAJOR_VERSION,
SDL_MINOR_VERSION,
SDL_PATCHLEVEL
);
/// <summary>
/// A structure that contains information about the version of SDL in use.
/// </summary>
/// <remarks>Represents the library's version as three levels: </remarks>
/// <remarks>major revision (increments with massive changes, additions, and enhancements) </remarks>
/// <remarks>minor revision (increments with backwards-compatible changes to the major revision), and </remarks>
/// <remarks>patchlevel (increments with fixes to the minor revision)</remarks>
/// <remarks><see cref="SDL_VERSION"/> can be used to populate this structure with information</remarks>
[StructLayout(LayoutKind.Sequential)]
public struct SDL_version
{
public byte major;
public byte minor;
public byte patch;
}
/// <summary>
/// Use this macro to determine the SDL version your program was compiled against.
/// </summary>
/// <param name="x">an <see cref="SDL_version"/> structure to initialize</param>
public static void SDL_VERSION(out SDL_version x)
{
x.major = SDL_MAJOR_VERSION;
x.minor = SDL_MINOR_VERSION;
x.patch = SDL_PATCHLEVEL;
}
/// <summary>
/// Use this macro to convert separate version components into a single numeric value.
/// </summary>
/// <param name="X">major version; reported in thousands place</param>
/// <param name="Y">minor version; reported in hundreds place</param>
/// <param name="Z">update version (patchlevel); reported in tens and ones places</param>
/// <returns></returns>
/// <remarks>This assumes that there will never be more than 100 patchlevels.</remarks>
/// <remarks>Example: SDL_VERSIONNUM(1,2,3) -> (1203)</remarks>
public static int SDL_VERSIONNUM(int X, int Y, int Z)
{
return (X * 1000) + (Y * 100) + Z;
}
/// <summary>
/// Use this macro to determine whether the SDL version compiled against is at least as new as the specified version.
/// </summary>
/// <param name="X">major version</param>
/// <param name="Y">minor version</param>
/// <param name="Z">update version (patchlevel)</param>
/// <returns>This macro will evaluate to true if compiled with SDL version at least X.Y.Z. </returns>
public static bool SDL_VERSION_ATLEAST(int X, int Y, int Z)
{
return (SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z));
}
/// <summary>
/// Use this function to get the version of SDL that is linked against your program.
/// </summary>
/// <param name="ver">the <see cref="SDL_version"/> structure that contains the version information</param>
/// <remarks>This function may be called safely at any time, even before SDL_Init(). </remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_GetVersion(out SDL_version ver);
/// <summary>
/// Use this function to get the code revision of SDL that is linked against your program.
/// </summary>
/// <returns>Returns an arbitrary string, uniquely identifying the exact revision
/// of the SDL library in use. </returns>
/// <remarks>The revision is a string including sequential revision number that is
/// incremented with each commit, and a hash of the last code change.</remarks>
/// <remarks>Example: hg-5344:94189aa89b54</remarks>
/// <remarks>This value is the revision of the code you are linked with and may be
/// different from the code you are compiling with, which is found in the constant SDL_REVISION.</remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler), MarshalCookie = LPUtf8StrMarshaler.LeaveAllocated)]
public static extern string SDL_GetRevision();
/// <summary>
/// Use this function to get the revision number of SDL that is linked against your program.
/// </summary>
/// <returns>Returns a number uniquely identifying the exact revision of the SDL library in use.</returns>
/// <remarks>This is an incrementing number based on commits to hg.libsdl.org.</remarks>
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_GetRevisionNumber();
#endregion
#region SDL_video.h
/* Actually, this is from SDL_blendmode.h */
/// <summary>
/// An enumeration of blend modes used in SDL_RenderCopy() and drawing operations.
/// </summary>
[Flags]
public enum SDL_BlendMode
{
SDL_BLENDMODE_NONE = 0x00000000,
SDL_BLENDMODE_BLEND = 0x00000001,
SDL_BLENDMODE_ADD = 0x00000002,
SDL_BLENDMODE_MOD = 0x00000004
}
/// <summary>
/// An enumeration of OpenGL configuration attributes.
/// </summary>
public enum SDL_GLattr
{
SDL_GL_RED_SIZE,
SDL_GL_GREEN_SIZE,
SDL_GL_BLUE_SIZE,
SDL_GL_ALPHA_SIZE,
SDL_GL_BUFFER_SIZE,
SDL_GL_DOUBLEBUFFER,
SDL_GL_DEPTH_SIZE,
SDL_GL_STENCIL_SIZE,
SDL_GL_ACCUM_RED_SIZE,
SDL_GL_ACCUM_GREEN_SIZE,
SDL_GL_ACCUM_BLUE_SIZE,
SDL_GL_ACCUM_ALPHA_SIZE,
SDL_GL_STEREO,
SDL_GL_MULTISAMPLEBUFFERS,
SDL_GL_MULTISAMPLESAMPLES,
SDL_GL_ACCELERATED_VISUAL,
SDL_GL_RETAINED_BACKING,
SDL_GL_CONTEXT_MAJOR_VERSION,
SDL_GL_CONTEXT_MINOR_VERSION,
SDL_GL_CONTEXT_EGL,
SDL_GL_CONTEXT_FLAGS,
SDL_GL_CONTEXT_PROFILE_MASK,
SDL_GL_SHARE_WITH_CURRENT_CONTEXT,
SDL_GL_FRAMEBUFFER_SRGB_CAPABLE
}
/// <summary>
/// An enumeration of OpenGL profiles.
/// </summary>
[Flags]
public enum SDL_GLprofile
{
SDL_GL_CONTEXT_PROFILE_CORE = 0x0001,
SDL_GL_CONTEXT_PROFILE_COMPATIBILITY = 0x0002,
SDL_GL_CONTEXT_PROFILE_ES = 0x0004
}
/// <summary>
/// This enumeration is used in conjunction with SDL_GL_SetAttribute
/// and SDL_GL_CONTEXT_FLAGS. Multiple flags can be OR'd together.
/// </summary>
[Flags]
public enum SDL_GLcontext
{
SDL_GL_CONTEXT_DEBUG_FLAG = 0x0001,
SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG = 0x0002,
SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG = 0x0004,
SDL_GL_CONTEXT_RESET_ISOLATION_FLAG = 0x0008
}
/// <summary>
/// An enumeration of window events.
/// </summary>
public enum SDL_WindowEventID : byte
{
SDL_WINDOWEVENT_NONE,
SDL_WINDOWEVENT_SHOWN,
SDL_WINDOWEVENT_HIDDEN,
SDL_WINDOWEVENT_EXPOSED,
SDL_WINDOWEVENT_MOVED,
SDL_WINDOWEVENT_RESIZED,
SDL_WINDOWEVENT_SIZE_CHANGED,
SDL_WINDOWEVENT_MINIMIZED,
SDL_WINDOWEVENT_MAXIMIZED,
SDL_WINDOWEVENT_RESTORED,
SDL_WINDOWEVENT_ENTER,
SDL_WINDOWEVENT_LEAVE,
SDL_WINDOWEVENT_FOCUS_GAINED,
SDL_WINDOWEVENT_FOCUS_LOST,
SDL_WINDOWEVENT_CLOSE,
}
/// <summary>
/// An enumeration of window states.
/// </summary>
[Flags]
public enum SDL_WindowFlags
{
SDL_WINDOW_FULLSCREEN = 0x00000001,
SDL_WINDOW_OPENGL = 0x00000002,
SDL_WINDOW_SHOWN = 0x00000004,