1 /*
2 
3 Boost Software License - Version 1.0 - August 17th, 2003
4 
5 Permission is hereby granted, free of charge, to any person or organization
6 obtaining a copy of the software and accompanying documentation covered by
7 this license (the "Software") to use, reproduce, display, distribute,
8 execute, and transmit the Software, and to prepare derivative works of the
9 Software, and to permit third-parties to whom the Software is furnished to
10 do so, all subject to the following:
11 
12 The copyright notices in the Software and this entire statement, including
13 the above license grant, this restriction and the following disclaimer,
14 must be included in all copies of the Software, in whole or in part, and
15 all derivative works of the Software, unless such copies or derivative
16 works are solely in the form of machine-executable object code generated by
17 a source language processor.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26 
27 */
28 module derelict.sdl.sdltypes;
29 
30 private
31 {
32     version(Tango)
33     {
34         import tango.stdc.stdio;
35     }
36     else
37     {
38         import core.stdc.stdio;
39     }
40 }
41 
42 // SDL.h
43 enum : Uint32
44 {
45     SDL_INIT_TIMER   = 0x00000001,
46     SDL_INIT_AUDIO   = 0x00000010,
47     SDL_INIT_VIDEO   = 0x00000020,
48     SDL_INIT_CDROM   = 0x00000100,
49     SDL_INIT_JOYSTICK  = 0x00000200,
50     SDL_INIT_NOPARACHUTE = 0x00100000,
51     SDL_INIT_EVENTTHREAD = 0x00200000,
52     SDL_INIT_EVERYTHING = 0x0000FFFF,
53 }
54 
55 // SDL_types.h
56 alias int SDL_bool;
57 enum
58 {
59     SDL_FALSE   = 0,
60     SDL_TRUE    = 1
61 }
62 alias ubyte Uint8;
63 alias byte Sint8;
64 alias ushort Uint16;
65 alias short Sint16;
66 alias uint Uint32;
67 alias int Sint32;
68 alias ulong Uint64;
69 alias long Sint64;
70 
71 enum
72 {
73     SDL_PRESSED     = 0x01,
74     SDL_RELEASED    = 0x00
75 }
76 
77 // SDL_active.h
78 enum : Uint8
79 {
80     SDL_APPMOUSEFOCUS   = 0x01,
81     SDL_APPINPUTFOCUS   = 0x02,
82     SDL_APPACTIVE       = 0x04,
83 }
84 
85 // SDL_audio.h
86 struct SDL_AudioSpec
87 {
88     int freq;
89     Uint16 format;
90     Uint8 channels;
91     Uint8 silence;
92     Uint16 samples;
93     Uint16 padding;
94     Uint32 size;
95     extern(C) void function(void *userdata, Uint8 *stream, int len) callback;
96     void *userdata;
97 }
98 
99 enum : Uint16
100 {
101     AUDIO_U8           = 0x0008,
102     AUDIO_S8           = 0x8008,
103     AUDIO_U16LSB       = 0x0010,
104     AUDIO_S16LSB       = 0x8010,
105     AUDIO_U16MSB       = 0x1010,
106     AUDIO_S16MSB       = 0x9010,
107     AUDIO_U16          = AUDIO_U16LSB,
108     AUDIO_S16          = AUDIO_S16LSB,
109 }
110 
111 version(LittleEndian)
112 {
113     enum : Uint16
114     {
115         AUDIO_U16SYS   = AUDIO_U16LSB,
116         AUDIO_S16SYS   = AUDIO_S16LSB,
117     }
118 }
119 else
120 {
121     enum : Uint16
122     {
123         AUDIO_U16SYS   = AUDIO_U16MSB,
124         AUDIO_S16SYS   = AUDIO_S16MSB,
125     }
126 }
127 
128 struct SDL_AudioCVT
129 {
130     int needed;
131     Uint16 src_format;
132     Uint16 dst_format;
133     double rate_incr;
134     Uint8 *buf;
135     int len;
136     int len_cvt;
137     int len_mult;
138     double len_ratio;
139     void function(SDL_AudioCVT *cvt, Uint16 format)[10] filters;
140     int filter_index;
141 }
142 
143 alias int SDL_audiostatus;
144 enum
145 {
146     SDL_AUDIO_STOPPED       = 0,
147     SDL_AUDIO_PLAYING,
148     SDL_AUDIO_PAUSED
149 }
150 
151 enum { SDL_MIX_MAXVOLUME = 128 }
152 
153 // SDL_byteorder.h
154 enum : uint
155 {
156     SDL_LIL_ENDIAN           = 1234,
157     SDL_BIG_ENDIAN           = 4321,
158 }
159 
160 version(LittleEndian)
161 {
162     enum : uint
163     {
164         SDL_BYTEORDER = SDL_LIL_ENDIAN,
165     }
166 }
167 else
168 {
169     enum : uint
170     {
171         SDL_BYTEORDER = SDL_BIG_ENDIAN,
172     }
173 }
174 
175 // SDL_cdrom.h
176 enum : Sint32 { SDL_MAX_TRACKS = 99 }
177 
178 enum : Uint8
179 {
180     SDL_AUDIO_TRACK     = 0x00,
181     SDL_DATA_TRACK      = 0x04,
182 }
183 
184 alias int CDstatus;
185 enum
186 {
187     CD_TRAYEMPTY,
188     CD_STOPPED,
189     CD_PLAYING,
190     CD_PAUSED,
191     CD_ERROR = -1
192 }
193 
194 struct SDL_CDtrack
195 {
196     Uint8 id;
197     Uint8 type;
198     Uint16 unused;
199     Uint32 length;
200     Uint32 offset;
201 }
202 
203 struct SDL_CD
204 {
205     int id;
206     CDstatus status;
207     int numtracks;
208     int cur_track;
209     int cur_frame;
210     SDL_CDtrack[SDL_MAX_TRACKS + 1] track;
211 }
212 
213 enum { CD_FPS = 75 }
214 
215 int CD_INDRIVE(int status)
216 {
217     return (cast(int)status > 0);
218 }
219 
220 void FRAMES_TO_MSF(int f, out int M, out int S, out int F)
221 {
222     int value = f;
223     F = value % CD_FPS;
224     value /= CD_FPS;
225     S = value % 60;
226     value /= 60;
227     M = value;
228 }
229 
230 int MSF_TO_FRAMES(int M, int S, int F)
231 {
232     return (M * 60 * CD_FPS + S * CD_FPS + F);
233 }
234 
235 // SDL_endian.h
236 Uint16 SDL_Swap16(Uint16 val)
237 {
238     return cast(Uint16)((val<<8)|(val>>8));
239 }
240 
241 Uint32 SDL_Swap32(Uint32 val)
242 {
243     return cast(Uint32)((val<<24)|((val<<8)&0x00FF0000)|((val>>8)&0x0000FF00)|(val>>24));
244 }
245 
246 Uint64 SDL_Swap64(Uint64 val)
247 {
248     Uint32 lo = cast(Uint32)(val & 0xFFFFFFFF);
249     val >>= 32;
250     Uint32 hi = cast(Uint32)(val & 0xFFFFFFFF);
251     val = SDL_Swap32(lo);
252     val <<= 32;
253     val |= SDL_Swap32(hi);
254     return val;
255 }
256 
257 version(LittleEndian)
258 {
259     Uint16 SDL_SwapLE16(Uint16 val)
260     {
261         return val;
262     }
263 
264     Uint32 SDL_SwapLE32(Uint32 val)
265     {
266         return val;
267     }
268 
269     Uint64 SDL_SwapLE64(Uint64 val)
270     {
271         return val;
272     }
273 
274     alias SDL_Swap16 SDL_SwapBE16;
275     alias SDL_Swap32 SDL_SwapBE32;
276     alias SDL_Swap64 SDL_SwapBE64;
277 }
278 else
279 {
280     alias SDL_Swap16 SDL_SwapLE16;
281     alias SDL_Swap32 SDL_SwapLE32;
282     alias SDL_Swap64 SDL_SwapLE64;
283 
284     Uint16 SDL_SwapBE16(Uint16 val)
285     {
286         return val;
287     }
288 
289     Uint32 SDL_SwapBE32(Uint32 val)
290     {
291         return val;
292     }
293 
294     Uint64 SDL_SwapBE64(Uint64 val)
295     {
296         return val;
297     }
298 }
299 
300 // SDL_events.h
301 enum
302 {
303     SDL_NOEVENT = 0,
304     SDL_ACTIVEEVENT,
305     SDL_KEYDOWN,
306     SDL_KEYUP,
307     SDL_MOUSEMOTION,
308     SDL_MOUSEBUTTONDOWN,
309     SDL_MOUSEBUTTONUP,
310     SDL_JOYAXISMOTION,
311     SDL_JOYBALLMOTION,
312     SDL_JOYHATMOTION,
313     SDL_JOYBUTTONDOWN,
314     SDL_JOYBUTTONUP,
315     SDL_QUIT,
316     SDL_SYSWMEVENT,
317     SDL_EVENT_RESERVEDA,
318     SDL_EVENT_RESERVEDB,
319     SDL_VIDEORESIZE,
320     SDL_VIDEOEXPOSE,
321     SDL_EVENT_RESERVED2,
322     SDL_EVENT_RESERVED3,
323     SDL_EVENT_RESERVED4,
324     SDL_EVENT_RESERVED5,
325     SDL_EVENT_RESERVED6,
326     SDL_EVENT_RESERVED7,
327     SDL_USEREVENT = 24,
328     SDL_NUMEVENTS = 32
329 }
330 
331 enum
332 {
333     SDL_ACTIVEEVENTMASK         = (1<<SDL_ACTIVEEVENT),
334     SDL_KEYDOWNMASK             = (1<<SDL_KEYDOWN),
335     SDL_KEYUPMASK               = (1<<SDL_KEYUP),
336     SDL_KEYEVENTMASK            = SDL_KEYDOWNMASK | SDL_KEYUPMASK,
337     SDL_MOUSEMOTIONMASK         = (1<<SDL_MOUSEMOTION),
338     SDL_MOUSEBUTTONDOWNMASK     = (1<<SDL_MOUSEBUTTONDOWN),
339     SDL_MOUSEBUTTONUPMASK       = (1<<SDL_MOUSEBUTTONUP),
340     SDL_MOUSEEVENTMADK          = (SDL_MOUSEMOTIONMASK |
341                                    SDL_MOUSEBUTTONDOWNMASK |
342                                    SDL_MOUSEBUTTONUPMASK),
343     SDL_JOYAXISMOTIONMASK       = (1<<SDL_JOYAXISMOTION),
344     SDL_JOYBALLMOTIONMASK       = (1<<SDL_JOYBALLMOTION),
345     SDL_JOYHATMOTIONMASK        = (1<<SDL_JOYHATMOTION),
346     SDL_JOYBUTTONDOWNMASK       = (1<<SDL_JOYBUTTONDOWN),
347     SDL_JOYBUTTONUPMASK         = (1<<SDL_JOYBUTTONUP),
348     SDL_JOYEVENTMASK            = (SDL_JOYAXISMOTIONMASK |
349                                    SDL_JOYBALLMOTIONMASK |
350                                    SDL_JOYHATMOTIONMASK |
351                                    SDL_JOYBUTTONDOWNMASK |
352                                    SDL_JOYBUTTONUPMASK),
353     SDL_VIDEORESIZEMASK         = (1<<SDL_VIDEORESIZE),
354     SDL_VIDEOEXPOSEMASK         = (1<<SDL_VIDEOEXPOSE),
355     SDL_QUITMASK                = (1<<SDL_QUIT),
356     SDL_SYSWMEVENTMASK          = (1<<SDL_SYSWMEVENT)
357 }
358 
359 enum : uint { SDL_ALLEVENTS = 0xFFFFFFFF }
360 
361 struct SDL_ActiveEvent
362 {
363     Uint8 type;
364     Uint8 gain;
365     Uint8 state;
366 }
367 
368 struct SDL_KeyboardEvent
369 {
370     Uint8 type;
371     Uint8 which;
372     Uint8 state;
373     SDL_keysym keysym;
374 }
375 
376 struct SDL_MouseMotionEvent
377 {
378     Uint8 type;
379     Uint8 which;
380     Uint8 state;
381     Uint16 x, y;
382     Sint16 xrel;
383     Sint16 yrel;
384 }
385 
386 struct SDL_MouseButtonEvent
387 {
388     Uint8 type;
389     Uint8 which;
390     Uint8 button;
391     Uint8 state;
392     Uint16 x, y;
393 }
394 
395 struct SDL_JoyAxisEvent
396 {
397     Uint8 type;
398     Uint8 which;
399     Uint8 axis;
400     Sint16 value;
401 }
402 
403 struct SDL_JoyBallEvent
404 {
405     Uint8 type;
406     Uint8 which;
407     Uint8 ball;
408     Sint16 xrel;
409     Sint16 yrel;
410 }
411 
412 struct SDL_JoyHatEvent
413 {
414     Uint8 type;
415     Uint8 which;
416     Uint8 hat;
417     Uint8 value;
418 }
419 
420 struct SDL_JoyButtonEvent
421 {
422     Uint8 type;
423     Uint8 which;
424     Uint8 button;
425     Uint8 state;
426 }
427 
428 struct SDL_ResizeEvent
429 {
430     Uint8 type;
431     int w;
432     int h;
433 }
434 
435 struct SDL_ExposeEvent
436 {
437     Uint8 type;
438 }
439 
440 struct SDL_QuitEvent
441 {
442     Uint8 type;
443 }
444 
445 struct SDL_UserEvent
446 {
447     Uint8 type;
448     int code;
449     void *data1;
450     void *data2;
451 }
452 
453 struct SDL_SysWMEvent
454 {
455     Uint8 type;
456     SDL_SysWMmsg *msg;
457 }
458 
459 union SDL_Event
460 {
461     Uint8 type;
462     SDL_ActiveEvent active;
463     SDL_KeyboardEvent key;
464     SDL_MouseMotionEvent motion;
465     SDL_MouseButtonEvent button;
466     SDL_JoyAxisEvent jaxis;
467     SDL_JoyBallEvent jball;
468     SDL_JoyHatEvent jhat;
469     SDL_JoyButtonEvent jbutton;
470     SDL_ResizeEvent resize;
471     SDL_ExposeEvent expose;
472     SDL_QuitEvent quit;
473     SDL_UserEvent user;
474     SDL_SysWMEvent syswm;
475 }
476 
477 alias int SDL_eventaction;
478 enum
479 {
480     SDL_ADDEVENT,
481     SDL_PEEKEVENT,
482     SDL_GETEVENT
483 }
484 
485 extern(C) alias int function(in SDL_Event *event) SDL_EventFilter;
486 
487 enum
488 {
489     SDL_QUERY           = -1,
490     SDL_IGNORE          = 0,
491     SDL_DISABLE         = 0,
492     SDL_ENABLE          = 1,
493 }
494 
495 // SDL_joystick.h
496 struct SDL_Joystick;
497 
498 enum : Uint8
499 {
500     SDL_HAT_CENTERED            = 0x00,
501     SDL_HAT_UP                  = 0x01,
502     SDL_HAT_RIGHT               = 0x02,
503     SDL_HAT_DOWN                = 0x04,
504     SDL_HAT_LEFT                = 0x08,
505     SDL_HAT_RIGHTUP             = SDL_HAT_RIGHT | SDL_HAT_UP,
506     SDL_HAT_RIGHTDOWN           = SDL_HAT_RIGHT | SDL_HAT_DOWN,
507     SDL_HAT_LEFTUP              = SDL_HAT_LEFT | SDL_HAT_UP,
508     SDL_HAT_LEFTDOWN            = SDL_HAT_LEFT | SDL_HAT_DOWN,
509 }
510 
511 // SDL_keyboard.h
512 struct SDL_keysym
513 {
514     Uint8 scancode;
515     SDLKey sym;
516     SDLMod mod;
517     Uint16 unicode;
518 }
519 
520 enum : uint { SDL_ALL_HOTKEYS = 0xFFFFFFFF }
521 
522 enum
523 {
524     SDL_DEFAULT_REPEAT_DELAY      = 500,
525     SDL_DEFAULT_REPEAT_INTERVAL   = 30,
526 }
527 
528 // SDL_keysym.h
529 alias int SDLKey;
530 enum
531 {
532     /* The keyboard syms have been cleverly chosen to map to ASCII */
533     SDLK_UNKNOWN        = 0,
534     SDLK_FIRST      = 0,
535     SDLK_BACKSPACE      = 8,
536     SDLK_TAB        = 9,
537     SDLK_CLEAR      = 12,
538     SDLK_RETURN     = 13,
539     SDLK_PAUSE      = 19,
540     SDLK_ESCAPE     = 27,
541     SDLK_SPACE      = 32,
542     SDLK_EXCLAIM        = 33,
543     SDLK_QUOTEDBL       = 34,
544     SDLK_HASH       = 35,
545     SDLK_DOLLAR     = 36,
546     SDLK_AMPERSAND      = 38,
547     SDLK_QUOTE      = 39,
548     SDLK_LEFTPAREN      = 40,
549     SDLK_RIGHTPAREN     = 41,
550     SDLK_ASTERISK       = 42,
551     SDLK_PLUS       = 43,
552     SDLK_COMMA      = 44,
553     SDLK_MINUS      = 45,
554     SDLK_PERIOD     = 46,
555     SDLK_SLASH      = 47,
556     SDLK_0          = 48,
557     SDLK_1          = 49,
558     SDLK_2          = 50,
559     SDLK_3          = 51,
560     SDLK_4          = 52,
561     SDLK_5          = 53,
562     SDLK_6          = 54,
563     SDLK_7          = 55,
564     SDLK_8          = 56,
565     SDLK_9          = 57,
566     SDLK_COLON      = 58,
567     SDLK_SEMICOLON      = 59,
568     SDLK_LESS       = 60,
569     SDLK_EQUALS     = 61,
570     SDLK_GREATER        = 62,
571     SDLK_QUESTION       = 63,
572     SDLK_AT         = 64,
573     /*
574        Skip uppercase letters
575      */
576     SDLK_LEFTBRACKET    = 91,
577     SDLK_BACKSLASH      = 92,
578     SDLK_RIGHTBRACKET   = 93,
579     SDLK_CARET      = 94,
580     SDLK_UNDERSCORE     = 95,
581     SDLK_BACKQUOTE      = 96,
582     SDLK_a          = 97,
583     SDLK_b          = 98,
584     SDLK_c          = 99,
585     SDLK_d          = 100,
586     SDLK_e          = 101,
587     SDLK_f          = 102,
588     SDLK_g          = 103,
589     SDLK_h          = 104,
590     SDLK_i          = 105,
591     SDLK_j          = 106,
592     SDLK_k          = 107,
593     SDLK_l          = 108,
594     SDLK_m          = 109,
595     SDLK_n          = 110,
596     SDLK_o          = 111,
597     SDLK_p          = 112,
598     SDLK_q          = 113,
599     SDLK_r          = 114,
600     SDLK_s          = 115,
601     SDLK_t          = 116,
602     SDLK_u          = 117,
603     SDLK_v          = 118,
604     SDLK_w          = 119,
605     SDLK_x          = 120,
606     SDLK_y          = 121,
607     SDLK_z          = 122,
608     SDLK_DELETE     = 127,
609     /* End of ASCII mapped keysyms */
610 
611     /* International keyboard syms */
612     SDLK_WORLD_0        = 160,      /* 0xA0 */
613     SDLK_WORLD_1        = 161,
614     SDLK_WORLD_2        = 162,
615     SDLK_WORLD_3        = 163,
616     SDLK_WORLD_4        = 164,
617     SDLK_WORLD_5        = 165,
618     SDLK_WORLD_6        = 166,
619     SDLK_WORLD_7        = 167,
620     SDLK_WORLD_8        = 168,
621     SDLK_WORLD_9        = 169,
622     SDLK_WORLD_10       = 170,
623     SDLK_WORLD_11       = 171,
624     SDLK_WORLD_12       = 172,
625     SDLK_WORLD_13       = 173,
626     SDLK_WORLD_14       = 174,
627     SDLK_WORLD_15       = 175,
628     SDLK_WORLD_16       = 176,
629     SDLK_WORLD_17       = 177,
630     SDLK_WORLD_18       = 178,
631     SDLK_WORLD_19       = 179,
632     SDLK_WORLD_20       = 180,
633     SDLK_WORLD_21       = 181,
634     SDLK_WORLD_22       = 182,
635     SDLK_WORLD_23       = 183,
636     SDLK_WORLD_24       = 184,
637     SDLK_WORLD_25       = 185,
638     SDLK_WORLD_26       = 186,
639     SDLK_WORLD_27       = 187,
640     SDLK_WORLD_28       = 188,
641     SDLK_WORLD_29       = 189,
642     SDLK_WORLD_30       = 190,
643     SDLK_WORLD_31       = 191,
644     SDLK_WORLD_32       = 192,
645     SDLK_WORLD_33       = 193,
646     SDLK_WORLD_34       = 194,
647     SDLK_WORLD_35       = 195,
648     SDLK_WORLD_36       = 196,
649     SDLK_WORLD_37       = 197,
650     SDLK_WORLD_38       = 198,
651     SDLK_WORLD_39       = 199,
652     SDLK_WORLD_40       = 200,
653     SDLK_WORLD_41       = 201,
654     SDLK_WORLD_42       = 202,
655     SDLK_WORLD_43       = 203,
656     SDLK_WORLD_44       = 204,
657     SDLK_WORLD_45       = 205,
658     SDLK_WORLD_46       = 206,
659     SDLK_WORLD_47       = 207,
660     SDLK_WORLD_48       = 208,
661     SDLK_WORLD_49       = 209,
662     SDLK_WORLD_50       = 210,
663     SDLK_WORLD_51       = 211,
664     SDLK_WORLD_52       = 212,
665     SDLK_WORLD_53       = 213,
666     SDLK_WORLD_54       = 214,
667     SDLK_WORLD_55       = 215,
668     SDLK_WORLD_56       = 216,
669     SDLK_WORLD_57       = 217,
670     SDLK_WORLD_58       = 218,
671     SDLK_WORLD_59       = 219,
672     SDLK_WORLD_60       = 220,
673     SDLK_WORLD_61       = 221,
674     SDLK_WORLD_62       = 222,
675     SDLK_WORLD_63       = 223,
676     SDLK_WORLD_64       = 224,
677     SDLK_WORLD_65       = 225,
678     SDLK_WORLD_66       = 226,
679     SDLK_WORLD_67       = 227,
680     SDLK_WORLD_68       = 228,
681     SDLK_WORLD_69       = 229,
682     SDLK_WORLD_70       = 230,
683     SDLK_WORLD_71       = 231,
684     SDLK_WORLD_72       = 232,
685     SDLK_WORLD_73       = 233,
686     SDLK_WORLD_74       = 234,
687     SDLK_WORLD_75       = 235,
688     SDLK_WORLD_76       = 236,
689     SDLK_WORLD_77       = 237,
690     SDLK_WORLD_78       = 238,
691     SDLK_WORLD_79       = 239,
692     SDLK_WORLD_80       = 240,
693     SDLK_WORLD_81       = 241,
694     SDLK_WORLD_82       = 242,
695     SDLK_WORLD_83       = 243,
696     SDLK_WORLD_84       = 244,
697     SDLK_WORLD_85       = 245,
698     SDLK_WORLD_86       = 246,
699     SDLK_WORLD_87       = 247,
700     SDLK_WORLD_88       = 248,
701     SDLK_WORLD_89       = 249,
702     SDLK_WORLD_90       = 250,
703     SDLK_WORLD_91       = 251,
704     SDLK_WORLD_92       = 252,
705     SDLK_WORLD_93       = 253,
706     SDLK_WORLD_94       = 254,
707     SDLK_WORLD_95       = 255,      /* 0xFF */
708 
709     /* Numeric keypad */
710     SDLK_KP0        = 256,
711     SDLK_KP1        = 257,
712     SDLK_KP2        = 258,
713     SDLK_KP3        = 259,
714     SDLK_KP4        = 260,
715     SDLK_KP5        = 261,
716     SDLK_KP6        = 262,
717     SDLK_KP7        = 263,
718     SDLK_KP8        = 264,
719     SDLK_KP9        = 265,
720     SDLK_KP_PERIOD      = 266,
721     SDLK_KP_DIVIDE      = 267,
722     SDLK_KP_MULTIPLY    = 268,
723     SDLK_KP_MINUS       = 269,
724     SDLK_KP_PLUS        = 270,
725     SDLK_KP_ENTER       = 271,
726     SDLK_KP_EQUALS      = 272,
727 
728     /* Arrows + Home/End pad */
729     SDLK_UP         = 273,
730     SDLK_DOWN       = 274,
731     SDLK_RIGHT      = 275,
732     SDLK_LEFT       = 276,
733     SDLK_INSERT     = 277,
734     SDLK_HOME       = 278,
735     SDLK_END        = 279,
736     SDLK_PAGEUP     = 280,
737     SDLK_PAGEDOWN       = 281,
738 
739     /* Function keys */
740     SDLK_F1         = 282,
741     SDLK_F2         = 283,
742     SDLK_F3         = 284,
743     SDLK_F4         = 285,
744     SDLK_F5         = 286,
745     SDLK_F6         = 287,
746     SDLK_F7         = 288,
747     SDLK_F8         = 289,
748     SDLK_F9         = 290,
749     SDLK_F10        = 291,
750     SDLK_F11        = 292,
751     SDLK_F12        = 293,
752     SDLK_F13        = 294,
753     SDLK_F14        = 295,
754     SDLK_F15        = 296,
755 
756     /* Key state modifier keys */
757     SDLK_NUMLOCK        = 300,
758     SDLK_CAPSLOCK       = 301,
759     SDLK_SCROLLOCK      = 302,
760     SDLK_RSHIFT     = 303,
761     SDLK_LSHIFT     = 304,
762     SDLK_RCTRL      = 305,
763     SDLK_LCTRL      = 306,
764     SDLK_RALT       = 307,
765     SDLK_LALT       = 308,
766     SDLK_RMETA      = 309,
767     SDLK_LMETA      = 310,
768     SDLK_LSUPER     = 311,      /* Left "Windows" key */
769     SDLK_RSUPER     = 312,      /* Right "Windows" key */
770     SDLK_MODE       = 313,      /* "Alt Gr" key */
771     SDLK_COMPOSE        = 314,      /* Multi-key compose key */
772 
773     /* Miscellaneous function keys */
774     SDLK_HELP       = 315,
775     SDLK_PRINT      = 316,
776     SDLK_SYSREQ     = 317,
777     SDLK_BREAK      = 318,
778     SDLK_MENU       = 319,
779     SDLK_POWER      = 320,      /* Power Macintosh power key */
780     SDLK_EURO       = 321,      /* Some european keyboards */
781     SDLK_UNDO       = 322,      /* Atari keyboard has Undo */
782 
783     /* Add any other keys here */
784 
785     SDLK_LAST
786 }
787 
788 alias int SDLMod;
789 enum
790 {
791     KMOD_NONE  = 0x0000,
792     KMOD_LSHIFT= 0x0001,
793     KMOD_RSHIFT= 0x0002,
794     KMOD_LCTRL = 0x0040,
795     KMOD_RCTRL = 0x0080,
796     KMOD_LALT  = 0x0100,
797     KMOD_RALT  = 0x0200,
798     KMOD_LMETA = 0x0400,
799     KMOD_RMETA = 0x0800,
800     KMOD_NUM   = 0x1000,
801     KMOD_CAPS  = 0x2000,
802     KMOD_MODE  = 0x4000,
803     KMOD_RESERVED = 0x8000,
804     KMOD_CTRL         = KMOD_LCTRL | KMOD_RCTRL,
805     KMOD_SHIFT        = KMOD_LSHIFT | KMOD_RSHIFT,
806     KMOD_ALT          = KMOD_LALT | KMOD_RALT,
807     KMOD_META         = KMOD_LMETA | KMOD_RMETA,
808 }
809 
810 // SDL_mouse.h
811 
812 struct WMcursor;
813 
814 struct SDL_Cursor
815 {
816     SDL_Rect area;
817     Sint16 hot_x, hot_y;
818     Uint8 *data;
819     Uint8 *mask;
820     Uint8[2] *save;
821     WMcursor *wm_cursor;
822 }
823 
824 enum : Uint8
825 {
826     SDL_BUTTON_LEFT         = 1,
827     SDL_BUTTON_MIDDLE       = 2,
828     SDL_BUTTON_RIGHT        = 3,
829     SDL_BUTTON_WHEELUP      = 4,
830     SDL_BUTTON_WHEELDOWN    = 5,
831     SDL_BUTTON_X1           = 6,
832     SDL_BUTTON_X2           = 7,
833     SDL_BUTTON_LMASK        = 1 << (SDL_BUTTON_LEFT-1),
834     SDL_BUTTON_MMASK        = 1 << (SDL_BUTTON_MIDDLE-1),
835     SDL_BUTTON_RMASK        = 1 << (SDL_BUTTON_RIGHT-1),
836     SDL_BUTTON_X1MASK       = 1 << (SDL_BUTTON_X1-1),
837     SDL_BUTTON_X2MASK       = 1 << (SDL_BUTTON_X2-1),
838 }
839 
840 Uint8 SDL_BUTTON(Uint8 x)
841 {
842     return cast(Uint8)(1 << (x - 1));
843 }
844 
845 // SDL_mutex.h
846 enum { SDL_MUTEX_TIMEOUT = 1 }
847 
848 enum : Uint32 { SDL_MUTEX_MAXWAIT = (~(cast(Uint32)0)) }
849 
850 struct SDL_mutex;
851 
852 struct SDL_sem;
853 
854 struct SDL_cond;
855 
856 // SDL_rwops.h
857 enum
858 {
859     RW_SEEK_SET       = 0,
860     RW_SEEK_CUR       = 1,
861     RW_SEEK_END       = 2,
862 }
863 
864 struct SDL_RWops
865 {
866     extern(C)
867     {
868         int function(SDL_RWops *context, int offset, int whence) seek;
869         int function(SDL_RWops *context, void *ptr, int size, int maxnum) read;
870         int function(SDL_RWops *context, in void *ptr, int size, int num) write;
871         int function(SDL_RWops *context) close;
872     }
873 
874     Uint32 type;
875     union Hidden
876     {
877         version(Windows)
878         {
879             struct Win32io
880             {
881                 int append;
882                 void *h;
883             }
884             Win32io win32io;
885         }
886 
887         struct Stdio
888         {
889             int autoclose;
890             FILE *fp;
891         }
892         Stdio stdio;
893 
894         struct Mem
895         {
896             Uint8 *base;
897             Uint8 *here;
898             Uint8 *stop;
899         }
900         Mem mem;
901 
902         struct Unknown
903         {
904             void *data1;
905         }
906         Unknown unknown;
907     }
908     Hidden hidden;
909 }
910 
911 int SDL_RWseek(SDL_RWops *context, int offset, int whence)
912 {
913     return context.seek(context, offset, whence);
914 }
915 
916 int SDL_RWtell(SDL_RWops *context)
917 {
918     return context.seek(context, 0, RW_SEEK_CUR);
919 }
920 
921 int SDL_RWread(SDL_RWops *context, void *ptr, int size, int maxnum)
922 {
923     return context.read(context, ptr, size, maxnum);
924 }
925 
926 int SDL_RWwrite(SDL_RWops *context, void *ptr, int size, int num)
927 {
928     return context.write(context, ptr, size, num);
929 }
930 
931 int SDL_RWclose(SDL_RWops *context)
932 {
933     return context.close(context);
934 }
935 
936 // SDL_version.h
937 enum : Uint8
938 {
939     SDL_MAJOR_VERSION   = 1,
940     SDL_MINOR_VERSION   = 2,
941     SDL_PATCHLEVEL      = 13,
942 }
943 
944 struct SDL_version
945 {
946     Uint8 major;
947     Uint8 minor;
948     Uint8 patch;
949 }
950 
951 version(D_Version2)
952 {
953     mixin("alias const(SDL_version*) CSDLVERPTR;" );
954 }
955 else
956 {
957     alias SDL_version* CSDLVERPTR;
958 }
959 
960 
961 void SDL_VERSION(SDL_version *X)
962 {
963     X.major = SDL_MAJOR_VERSION;
964     X.minor = SDL_MINOR_VERSION;
965     X.patch = SDL_PATCHLEVEL;
966 }
967 
968 uint SDL_VERSIONNUM(Uint8 major, Uint8 minor, Uint8 patch)
969 {
970     return (major * 1000 + minor * 100 + patch);
971 }
972 
973 enum : uint
974 {
975     SDL_COMPILEDVERSION =  SDL_MAJOR_VERSION * 1000 +
976                                   SDL_MINOR_VERSION * 100 + SDL_PATCHLEVEL,
977 }
978 
979 bool SDL_VERSION_ATLEAST(Uint8 major, Uint8 minor, Uint8 patch)
980 {
981     return cast(bool)(SDL_COMPILEDVERSION >= SDL_VERSIONNUM(major,minor,patch));
982 }
983 
984 // SDL_syswm.h
985 version(Windows)
986 {
987     import derelict.util.wintypes;
988 
989     struct SDL_SysWMmsg
990     {
991         // this is named 'version' in SDL_syswm.h, but since version is a keyword,
992         // 'ver' will have to do
993         SDL_version ver;
994         HWND hwnd;
995         UINT msg;
996         WPARAM wParam;
997         LPARAM lParam;
998     }
999 
1000     struct SDL_SysWMinfo
1001     {
1002         // this is named 'version' in SDL_syswm.h, but since version is a keyword,
1003         // 'ver' will have to do
1004         SDL_version ver;
1005         HWND window;
1006         HGLRC hglrc;
1007     }
1008 }
1009 else
1010 {
1011     struct SDL_SysWMmsg;
1012     struct SDL_SysWMinfo;
1013 }
1014 
1015 // SDL_thread.h
1016 struct SDL_Thread;
1017 
1018 // SDL_timer.h
1019 
1020 enum : Uint32
1021 {
1022     SDL_TIMESLICE          = 10,
1023     SDL_RESOLUTION         = 10,
1024 }
1025 
1026 extern(C)
1027 {
1028     alias Uint32 function(Uint32) SDL_TimerCallback;
1029     alias Uint32 function(Uint32,void*) SDL_NewTimerCallback;
1030 }
1031 
1032 alias void* SDL_TimerID;
1033 
1034 // SDL_video.h
1035 
1036 enum : Uint8
1037 {
1038     SDL_ALPHA_OPAQUE            = 255,
1039     SDL_ALPHA_TRANSPARENT       = 0,
1040 }
1041 
1042 struct SDL_Rect
1043 {
1044     Sint16 x, y;
1045     Uint16 w, h;
1046 }
1047 
1048 struct SDL_Color
1049 {
1050     Uint8 r;
1051     Uint8 g;
1052     Uint8 b;
1053     Uint8 unused;
1054 }
1055 alias SDL_Color SDL_Colour;
1056 
1057 struct SDL_Palette
1058 {
1059     int ncolors;
1060     SDL_Color *colors;
1061 }
1062 
1063 struct SDL_PixelFormat
1064 {
1065     SDL_Palette *palette;
1066     Uint8 BitsPerPixel;
1067     Uint8 BytesPerPixel;
1068     Uint8 Rloss;
1069     Uint8 Gloss;
1070     Uint8 Bloss;
1071     Uint8 Aloss;
1072     Uint8 Rshift;
1073     Uint8 Gshift;
1074     Uint8 Bshift;
1075     Uint8 Ashift;
1076     Uint32 Rmask;
1077     Uint32 Gmask;
1078     Uint32 Bmask;
1079     Uint32 Amask;
1080     Uint32 colorkey;
1081     Uint8 alpha;
1082 }
1083 
1084 struct SDL_Surface
1085 {
1086     Uint32 flags;
1087     SDL_PixelFormat *format;
1088     int w, h;
1089     Uint16 pitch;
1090     void *pixels;
1091     int offset;
1092     void *hwdata;
1093     SDL_Rect clip_rect;
1094     Uint32 unused1;
1095     Uint32 locked;
1096     void *map;
1097     uint format_version;
1098     int refcount;
1099 }
1100 
1101 enum : Uint32
1102 {
1103     SDL_SWSURFACE                  = 0x00000000,
1104     SDL_HWSURFACE                  = 0x00000001,
1105     SDL_ASYNCBLIT                  = 0x00000004,
1106     SDL_ANYFORMAT                  = 0x10000000,
1107     SDL_HWPALETTE                  = 0x20000000,
1108     SDL_DOUBLEBUF                  = 0x40000000,
1109     SDL_FULLSCREEN                 = 0x80000000,
1110     SDL_OPENGL                     = 0x00000002,
1111     SDL_OPENGLBLIT                 = 0x0000000A,
1112     SDL_RESIZABLE                  = 0x00000010,
1113     SDL_NOFRAME                    = 0x00000020,
1114     SDL_HWACCEL                    = 0x00000100,
1115     SDL_SRCCOLORKEY                = 0x00001000,
1116     SDL_RLEACCELOK                 = 0x00002000,
1117     SDL_RLEACCEL                   = 0x00004000,
1118     SDL_SRCALPHA                   = 0x00010000,
1119     SDL_PREALLOC                   = 0x01000000,
1120 }
1121 
1122 struct SDL_VideoInfo
1123 {
1124     Uint32 flags;
1125     Uint32 video_mem;
1126     SDL_PixelFormat *vfmt;
1127     int current_w;
1128     int current_h;
1129 }
1130 
1131 enum : Uint32
1132 {
1133     SDL_YV12_OVERLAY               = 0x32315659,
1134     SDL_IYUV_OVERLAY               = 0x56555949,
1135     SDL_YUY2_OVERLAY               = 0x32595559,
1136     SDL_UYVY_OVERLAY               = 0x59565955,
1137     SDL_YUYU_OVERLAY               = 0x55595659,
1138 }
1139 
1140 struct SDL_Overlay
1141 {
1142     Uint32 format;
1143     int w, h;
1144     int planes;
1145     Uint16 *pitches;
1146     Uint8 **pixels;
1147     void *hwfuncs;
1148     void *hwdata;
1149     Uint32 flags;
1150 }
1151 
1152 alias int SDL_GLattr;
1153 enum
1154 {
1155     SDL_GL_RED_SIZE,
1156     SDL_GL_GREEN_SIZE,
1157     SDL_GL_BLUE_SIZE,
1158     SDL_GL_ALPHA_SIZE,
1159     SDL_GL_BUFFER_SIZE,
1160     SDL_GL_DOUBLEBUFFER,
1161     SDL_GL_DEPTH_SIZE,
1162     SDL_GL_STENCIL_SIZE,
1163     SDL_GL_ACCUM_RED_SIZE,
1164     SDL_GL_ACCUM_GREEN_SIZE,
1165     SDL_GL_ACCUM_BLUE_SIZE,
1166     SDL_GL_ACCUM_ALPHA_SIZE,
1167     SDL_GL_STEREO,
1168     SDL_GL_MULTISAMPLEBUFFERS,
1169     SDL_GL_MULTISAMPLESAMPLES,
1170     SDL_GL_ACCELERATED_VISUAL,
1171     SDL_GL_SWAP_CONTROL
1172 }
1173 
1174 enum : Uint8
1175 {
1176     SDL_LOGPAL          = 0x01,
1177     SDL_PHYSPAL         = 0x02,
1178 }
1179 
1180 alias int SDL_GrabMode;
1181 enum
1182 {
1183     SDL_GRAB_QUERY = -1,
1184     SDL_GRAB_OFF = 0,
1185     SDL_GRAB_ON = 1,
1186     SDL_GRAB_FULLSCREEN
1187 }
1188 
1189 bool SDL_MUSTLOCK(SDL_Surface* surface)
1190 {
1191     return cast(bool)(surface.offset ||
1192         ((surface.flags & (SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_RLEACCEL)) != 0));
1193 }