hedgewars/SDLh.pas
branchsdl2transition
changeset 11360 7a7611adf715
parent 9697 198c3ed28fe8
child 11362 ed5a6478e710
equal deleted inserted replaced
9798:f2b18754742f 11360:7a7611adf715
    53     type PLongInt = ^LongInt;
    53     type PLongInt = ^LongInt;
    54 {$ENDIF}
    54 {$ENDIF}
    55 
    55 
    56 {$IFDEF DARWIN}
    56 {$IFDEF DARWIN}
    57     {$IFNDEF HWLIBRARY}
    57     {$IFNDEF HWLIBRARY}
    58         {$IFDEF SDL2}
    58         {$linkframework SDL2}
    59             {$linkframework SDL2}
    59         {$linkframework SDL2_net}
    60             {$linkframework SDL2_net}
    60         {$linkframework SDL2_image}
    61             {$linkframework SDL2_image}
    61         {$linkframework SDL2_ttf}
    62             {$linkframework SDL2_ttf}
    62         {$linkframework SDL2_mixer}
    63             {$linkframework SDL2_mixer}
       
    64         {$ELSE}
       
    65             {$linklib SDLmain}
       
    66             {$PASCALMAINNAME SDL_main}
       
    67             {$linkframework Cocoa}
       
    68             {$linkframework OpenGL}
       
    69             {$linkframework SDL}
       
    70             {$linkframework SDL_net}
       
    71             {$linkframework SDL_image}
       
    72             {$linkframework SDL_ttf}
       
    73             {$linkframework SDL_mixer}
       
    74         {$ENDIF}
       
    75     {$ENDIF}
    63     {$ENDIF}
    76 {$ENDIF}
    64 {$ENDIF}
    77 
    65 
    78 
    66 
    79 (*  SDL  *)
    67 (*  SDL  *)
    80 const
    68 const
    81 {$IFDEF SDL2}
    69 {$IFDEF WIN32}
    82     {$IFDEF WIN32}
    70     SDLLibName = 'SDL2.dll';
    83         SDLLibName = 'SDL2.dll';
    71     SDL_TTFLibName = 'SDL2_ttf.dll';
    84         SDL_TTFLibName = 'SDL2_ttf.dll';
    72     SDL_MixerLibName = 'SDL2_mixer.dll';
    85         SDL_MixerLibName = 'SDL2_mixer.dll';
    73     SDL_ImageLibName = 'SDL2_image.dll';
    86         SDL_ImageLibName = 'SDL2_image.dll';
    74     SDL_NetLibName = 'SDL2_net.dll';
    87         SDL_NetLibName = 'SDL2_net.dll';
       
    88     {$ELSE}
       
    89         SDLLibName = 'libSDL2';
       
    90         SDL_TTFLibName = 'libSDL2_ttf';
       
    91         SDL_MixerLibName = 'libSDL2_mixer';
       
    92         SDL_ImageLibName = 'libSDL2_image';
       
    93         SDL_NetLibName = 'libSDL2_net';
       
    94     {$ENDIF}
       
    95 {$ELSE}
    75 {$ELSE}
    96     {$IFDEF WIN32}
    76     SDLLibName = 'libSDL2';
    97         SDLLibName = 'SDL.dll';
    77     SDL_TTFLibName = 'libSDL2_ttf';
    98         SDL_TTFLibName = 'SDL_ttf.dll';
    78     SDL_MixerLibName = 'libSDL2_mixer';
    99         SDL_MixerLibName = 'SDL_mixer.dll';
    79     SDL_ImageLibName = 'libSDL2_image';
   100         SDL_ImageLibName = 'SDL_image.dll';
    80     SDL_NetLibName = 'libSDL2_net';
   101         SDL_NetLibName = 'SDL_net.dll';
       
   102     {$ELSE}
       
   103         SDLLibName = 'libSDL';
       
   104         SDL_TTFLibName = 'libSDL_ttf';
       
   105         SDL_MixerLibName = 'libSDL_mixer';
       
   106         SDL_ImageLibName = 'libSDL_image';
       
   107         SDL_NetLibName = 'libSDL_net';
       
   108     {$ENDIF}
       
   109 {$ENDIF}
    81 {$ENDIF}
   110 
    82 
   111 /////////////////////////////////////////////////////////////////
    83 /////////////////////////////////////////////////////////////////
   112 /////////////////////  CONSTANT DEFINITIONS /////////////////////
    84 /////////////////////  CONSTANT DEFINITIONS /////////////////////
   113 /////////////////////////////////////////////////////////////////
    85 /////////////////////////////////////////////////////////////////
   115     // SDL_Init() flags
    87     // SDL_Init() flags
   116     SDL_INIT_TIMER          = $00000001;
    88     SDL_INIT_TIMER          = $00000001;
   117     SDL_INIT_AUDIO          = $00000010;
    89     SDL_INIT_AUDIO          = $00000010;
   118     SDL_INIT_VIDEO          = $00000020; // implies SDL_INIT_EVENTS (sdl2)
    90     SDL_INIT_VIDEO          = $00000020; // implies SDL_INIT_EVENTS (sdl2)
   119     SDL_INIT_JOYSTICK       = $00000200; // implies SDL_INIT_EVENTS (sdl2)
    91     SDL_INIT_JOYSTICK       = $00000200; // implies SDL_INIT_EVENTS (sdl2)
   120 {$IFDEF SDL2}
       
   121     SDL_INIT_HAPTIC         = $00001000;
    92     SDL_INIT_HAPTIC         = $00001000;
   122     SDL_INIT_GAMECONTROLLER = $00002000; // implies SDL_INIT_JOYSTICK
    93     SDL_INIT_GAMECONTROLLER = $00002000; // implies SDL_INIT_JOYSTICK
   123     SDL_INIT_EVENTS         = $00004000;
    94     SDL_INIT_EVENTS         = $00004000;
   124 {$ELSE}
       
   125     SDL_INIT_CDROM          = $00000100;
       
   126     SDL_INIT_EVENTTHREAD    = $01000000;
       
   127 {$ENDIF}
       
   128     SDL_INIT_NOPARACHUTE    = $00100000;
    95     SDL_INIT_NOPARACHUTE    = $00100000;
   129     //SDL_INIT_EVERYTHING                // unsafe, init subsystems one at a time
    96     //SDL_INIT_EVERYTHING                // unsafe, init subsystems one at a time
   130 
    97 
   131     SDL_ALLEVENTS        = $FFFFFFFF;    // dummy event type to prevent stack corruption
    98     SDL_ALLEVENTS        = $FFFFFFFF;    // dummy event type to prevent stack corruption
   132     SDL_APPINPUTFOCUS    = $02;
    99     SDL_APPINPUTFOCUS    = $02;
   136     SDL_BUTTON_RIGHT     = 3;
   103     SDL_BUTTON_RIGHT     = 3;
   137     SDL_BUTTON_WHEELUP   = 4;
   104     SDL_BUTTON_WHEELUP   = 4;
   138     SDL_BUTTON_WHEELDOWN = 5;
   105     SDL_BUTTON_WHEELDOWN = 5;
   139 
   106 
   140 
   107 
   141 {$IFDEF SDL2}
       
   142     SDL_TEXTEDITINGEVENT_TEXT_SIZE = 32;
   108     SDL_TEXTEDITINGEVENT_TEXT_SIZE = 32;
   143     SDL_TEXTINPUTEVENT_TEXT_SIZE   = 32;
   109     SDL_TEXTINPUTEVENT_TEXT_SIZE   = 32;
   144 
   110 
   145     // SDL_Event types
   111     // SDL_Event types
   146     // pascal does not support unions as is, so we list here every possible event
   112     // pascal does not support unions as is, so we list here every possible event
   232     SDL_WINDOWEVENT_ENTER        = 10;   //*< Window has gained mouse focus
   198     SDL_WINDOWEVENT_ENTER        = 10;   //*< Window has gained mouse focus
   233     SDL_WINDOWEVENT_LEAVE        = 11;   //*< Window has lost mouse focus
   199     SDL_WINDOWEVENT_LEAVE        = 11;   //*< Window has lost mouse focus
   234     SDL_WINDOWEVENT_FOCUS_GAINED = 12;   //*< Window has gained keyboard focus
   200     SDL_WINDOWEVENT_FOCUS_GAINED = 12;   //*< Window has gained keyboard focus
   235     SDL_WINDOWEVENT_FOCUS_LOST   = 13;   //*< Window has lost keyboard focus
   201     SDL_WINDOWEVENT_FOCUS_LOST   = 13;   //*< Window has lost keyboard focus
   236     SDL_WINDOWEVENT_CLOSE        = 14;   //*< The window manager requests that the window be closed */
   202     SDL_WINDOWEVENT_CLOSE        = 14;   //*< The window manager requests that the window be closed */
   237 {$ELSE}
       
   238     // SDL_Event types
       
   239     SDL_NOEVENT         = 0;
       
   240     SDL_ACTIVEEVENT     = 1;
       
   241     SDL_KEYDOWN         = 2;
       
   242     SDL_KEYUP           = 3;
       
   243     SDL_MOUSEMOTION     = 4;
       
   244     SDL_MOUSEBUTTONDOWN = 5;
       
   245     SDL_MOUSEBUTTONUP   = 6;
       
   246     SDL_JOYAXISMOTION   = 7;
       
   247     SDL_JOYBALLMOTION   = 8;
       
   248     SDL_JOYHATMOTION    = 9;
       
   249     SDL_JOYBUTTONDOWN   = 10;
       
   250     SDL_JOYBUTTONUP     = 11;
       
   251     SDL_QUITEV          = 12;
       
   252     SDL_VIDEORESIZE     = 16;
       
   253 
       
   254     // SDL_Surface flags
       
   255     SDL_SWSURFACE   = $00000000;
       
   256     SDL_HWSURFACE   = $00000001;
       
   257     SDL_OPENGL      = $00000002;
       
   258     SDL_ASYNCBLIT   = $00000004;
       
   259     SDL_RESIZABLE   = $00000010;
       
   260     SDL_NOFRAME     = $00000020;
       
   261     SDL_HWACCEL     = $00000100;
       
   262     SDL_SRCCOLORKEY = $00001000;
       
   263     SDL_RLEACCEL    = $00004000;
       
   264     SDL_SRCALPHA    = $00010000;
       
   265     SDL_ANYFORMAT   = $00100000;
       
   266     SDL_HWPALETTE   = $20000000;
       
   267     SDL_DOUBLEBUF   = $40000000;
       
   268     SDL_FULLSCREEN  = $80000000;
       
   269 {$ENDIF}
       
   270 
   203 
   271 {$IFDEF ENDIAN_LITTLE}
   204 {$IFDEF ENDIAN_LITTLE}
   272     RMask = $000000FF;
   205     RMask = $000000FF;
   273     GMask = $0000FF00;
   206     GMask = $0000FF00;
   274     BMask = $00FF0000;
   207     BMask = $00FF0000;
   354 // two important reference points for the wanderers of this area
   287 // two important reference points for the wanderers of this area
   355 // http://www.freepascal.org/docs-html/ref/refsu5.html
   288 // http://www.freepascal.org/docs-html/ref/refsu5.html
   356 // http://www.freepascal.org/docs-html/prog/progsu144.html
   289 // http://www.freepascal.org/docs-html/prog/progsu144.html
   357 
   290 
   358 type
   291 type
   359 {$IFDEF SDL2}
       
   360     PSDL_Window   = Pointer;
   292     PSDL_Window   = Pointer;
   361     PSDL_Renderer = Pointer;
   293     PSDL_Renderer = Pointer;
   362     PSDL_Texture  = Pointer;
   294     PSDL_Texture  = Pointer;
   363     PSDL_GLContext= Pointer;
   295     PSDL_GLContext= Pointer;
   364     TSDL_TouchId  = Int64;
   296     TSDL_TouchId  = Int64;
   365 {$ENDIF}
       
   366     TSDL_FingerId = Int64;
   297     TSDL_FingerId = Int64;
   367 
   298 
   368     TSDL_eventaction = (SDL_ADDEVENT, SDL_PEEPEVENT, SDL_GETEVENT);
   299     TSDL_eventaction = (SDL_ADDEVENT, SDL_PEEPEVENT, SDL_GETEVENT);
   369 
   300 
   370     PSDL_Rect = ^TSDL_Rect;
   301     PSDL_Rect = ^TSDL_Rect;
   371     TSDL_Rect = record
   302     TSDL_Rect = record
   372 {$IFDEF SDL2}
       
   373         x, y, w, h: LongInt;
   303         x, y, w, h: LongInt;
   374 {$ELSE}
       
   375         x, y: SmallInt;
       
   376         w, h: Word;
       
   377 {$ENDIF}
       
   378         end;
   304         end;
   379 
   305 
   380     TPoint = record
   306     TPoint = record
   381         x, y: LongInt;
   307         x, y: LongInt;
   382         end;
   308         end;
   383 
   309 
   384     PSDL_PixelFormat = ^TSDL_PixelFormat;
   310     PSDL_PixelFormat = ^TSDL_PixelFormat;
   385     TSDL_PixelFormat = record
   311     TSDL_PixelFormat = record
   386 {$IFDEF SDL2}
       
   387         format: LongWord;
   312         format: LongWord;
   388         palette: Pointer;
   313         palette: Pointer;
   389         BitsPerPixel : Byte;
   314         BitsPerPixel : Byte;
   390         BytesPerPixel: Byte;
   315         BytesPerPixel: Byte;
   391         padding: array[0..1] of Byte;
   316         padding: array[0..1] of Byte;
   401         Gshift: Byte;
   326         Gshift: Byte;
   402         Bshift: Byte;
   327         Bshift: Byte;
   403         Ashift: Byte;
   328         Ashift: Byte;
   404         refcount: LongInt;
   329         refcount: LongInt;
   405         next: PSDL_PixelFormat;
   330         next: PSDL_PixelFormat;
   406 {$ELSE}
       
   407         palette: Pointer;
       
   408         BitsPerPixel : Byte;
       
   409         BytesPerPixel: Byte;
       
   410         Rloss : Byte;
       
   411         Gloss : Byte;
       
   412         Bloss : Byte;
       
   413         Aloss : Byte;
       
   414         Rshift: Byte;
       
   415         Gshift: Byte;
       
   416         Bshift: Byte;
       
   417         Ashift: Byte;
       
   418         RMask : LongWord;
       
   419         GMask : LongWord;
       
   420         BMask : LongWord;
       
   421         AMask : LongWord;
       
   422         colorkey: LongWord;
       
   423         alpha: Byte;
       
   424 {$ENDIF}
       
   425         end;
   331         end;
   426 
   332 
   427     PSDL_Surface = ^TSDL_Surface;
   333     PSDL_Surface = ^TSDL_Surface;
   428     TSDL_Surface = record
   334     TSDL_Surface = record
   429         flags : LongWord;
   335         flags : LongWord;
   430         format: PSDL_PixelFormat;
   336         format: PSDL_PixelFormat;
   431         w, h  : LongInt;
   337         w, h  : LongInt;
   432         pitch : {$IFDEF SDL2}LongInt{$ELSE}Word{$ENDIF};
   338         pitch : LongInt;
   433         pixels: Pointer;
   339         pixels: Pointer;
   434 {$IFDEF SDL2}
       
   435         userdata: Pointer;
   340         userdata: Pointer;
   436         locked: LongInt;
   341         locked: LongInt;
   437         lock_data: Pointer;
   342         lock_data: Pointer;
   438         clip_rect: TSDL_Rect;
   343         clip_rect: TSDL_Rect;
   439         map: Pointer;
   344         map: Pointer;
   440         refcount: LongInt;
   345         refcount: LongInt;
   441 {$ELSE}
       
   442         offset: LongInt;
       
   443 {$ENDIF}
       
   444         end;
   346         end;
   445 
   347 
   446 
   348 
   447     PSDL_Color = ^TSDL_Color;
   349     PSDL_Color = ^TSDL_Color;
   448     TSDL_Color = record
   350     TSDL_Color = record
   453         end;
   355         end;
   454 
   356 
   455 
   357 
   456     (* SDL_RWops and friends *)
   358     (* SDL_RWops and friends *)
   457     PSDL_RWops = ^TSDL_RWops;
   359     PSDL_RWops = ^TSDL_RWops;
   458 {$IFDEF SDL2}
       
   459     TSize  = function( context: PSDL_RWops): Int64; cdecl;
   360     TSize  = function( context: PSDL_RWops): Int64; cdecl;
   460     TSeek  = function( context: PSDL_RWops; offset: Int64; whence: LongInt ): Int64; cdecl;
   361     TSeek  = function( context: PSDL_RWops; offset: Int64; whence: LongInt ): Int64; cdecl;
   461 {$ELSE}
       
   462     TSeek  = function( context: PSDL_RWops; offset: LongInt; whence: LongInt ): LongInt; cdecl;
       
   463 {$ENDIF}
       
   464     TRead  = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; maxnum : LongInt ): LongInt;  cdecl;
   362     TRead  = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; maxnum : LongInt ): LongInt;  cdecl;
   465     TWrite = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; num: LongInt ): LongInt; cdecl;
   363     TWrite = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; num: LongInt ): LongInt; cdecl;
   466     TClose = function( context: PSDL_RWops ): LongInt; cdecl;
   364     TClose = function( context: PSDL_RWops ): LongInt; cdecl;
   467 
   365 
   468     TStdio = record
   366     TStdio = record
   469         autoclose: {$IFDEF SDL2}Boolean{$ELSE}LongInt{$ENDIF};
   367         autoclose: Boolean;
   470         fp: Pointer;
   368         fp: Pointer;
   471         end;
   369         end;
   472 
   370 
   473     TMem = record
   371     TMem = record
   474         base: PByte;
   372         base: PByte;
   476         stop: PByte;
   374         stop: PByte;
   477         end;
   375         end;
   478 
   376 
   479     TUnknown = record
   377     TUnknown = record
   480         data1: Pointer;
   378         data1: Pointer;
   481 {$IFDEF SDL2}
       
   482         data2: Pointer;
   379         data2: Pointer;
   483 {$ENDIF}
       
   484         end;
   380         end;
   485 
   381 
   486 {$IFDEF ANDROID}
   382 {$IFDEF ANDROID}
   487     TAndroidio = record
   383     TAndroidio = record
   488         fileName, inputStream, readableByteChannel: Pointer;
   384         fileName, inputStream, readableByteChannel: Pointer;
   495     TWinbuffer = record
   391     TWinbuffer = record
   496         data: Pointer;
   392         data: Pointer;
   497         size, left: LongInt;
   393         size, left: LongInt;
   498         end;
   394         end;
   499     TWindowsio = record
   395     TWindowsio = record
   500         append : {$IFDEF SDL2}Boolean{$ELSE}LongInt{$ENDIF};
   396         append : Boolean;
   501         h : Pointer;
   397         h : Pointer;
   502         buffer : TWinbuffer;
   398         buffer : TWinbuffer;
   503         end;
   399         end;
   504 {$ENDIF}
   400 {$ENDIF}
   505 {$ENDIF}
   401 {$ENDIF}
   506 
   402 
   507     TSDL_RWops = record
   403     TSDL_RWops = record
   508 {$IFDEF SDL2}
       
   509         size: TSize;
   404         size: TSize;
   510 {$ENDIF}
       
   511         seek: TSeek;
   405         seek: TSeek;
   512         read: TRead;
   406         read: TRead;
   513         write: TWrite;
   407         write: TWrite;
   514         close: TClose;
   408         close: TClose;
   515         type_: LongWord;
   409         type_: LongWord;
   527             end;
   421             end;
   528 
   422 
   529 
   423 
   530 {* SDL_Event type definition *}
   424 {* SDL_Event type definition *}
   531 
   425 
   532 {$IFDEF SDL2}
       
   533     TSDL_Keysym = record
   426     TSDL_Keysym = record
   534         scancode: LongInt;
   427         scancode: LongInt;
   535         sym: LongInt;
   428         sym: LongInt;
   536         modifier: Word;
   429         modifier: Word;
   537         unused: LongWord;
   430         unused: LongWord;
   628         type_: LongWord;
   521         type_: LongWord;
   629         timestamp: LongWord;
   522         timestamp: LongWord;
   630         end;
   523         end;
   631 
   524 
   632     TSDL_OSEvent = TSDL_CommonEvent;
   525     TSDL_OSEvent = TSDL_CommonEvent;
   633 {$ELSE}
       
   634     TSDL_KeySym = record
       
   635         scancode: Byte;
       
   636         sym: LongWord;
       
   637         modifier: LongWord;
       
   638         unicode: Word;
       
   639         end;
       
   640 
       
   641     TSDL_ActiveEvent = record
       
   642         type_: Byte;
       
   643         gain: Byte;
       
   644         state: Byte;
       
   645         end;
       
   646 
       
   647     TSDL_ResizeEvent = record
       
   648         type_: Byte;
       
   649         w, h: LongInt;
       
   650         end;
       
   651 {$ENDIF}
       
   652 
   526 
   653     TSDL_KeyboardEvent = record
   527     TSDL_KeyboardEvent = record
   654 {$IFDEF SDL2}
       
   655         type_: LongWord;
   528         type_: LongWord;
   656         timestamp: LongWord;
   529         timestamp: LongWord;
   657         windowID: LongWord;
   530         windowID: LongWord;
   658         state, repeat_, padding2, padding3: Byte;
   531         state, repeat_, padding2, padding3: Byte;
   659 {$ELSE}
       
   660         type_, which, state: Byte;
       
   661 {$ENDIF}
       
   662         keysym: TSDL_Keysym;
   532         keysym: TSDL_Keysym;
   663         end;
   533         end;
   664 
   534 
   665     TSDL_MouseMotionEvent = record
   535     TSDL_MouseMotionEvent = record
   666 {$IFDEF SDL2}
       
   667         type_: LongWord;
   536         type_: LongWord;
   668         timestamp: LongWord;
   537         timestamp: LongWord;
   669         windowID: LongWord;
   538         windowID: LongWord;
   670         which, state: LongWord;
   539         which, state: LongWord;
   671         x, y, xrel, yrel: LongInt;
   540         x, y, xrel, yrel: LongInt;
   672 {$ELSE}
       
   673         type_, which, state: Byte;
       
   674         x, y, xrel, yrel: Word;
       
   675 {$ENDIF}
       
   676         end;
   541         end;
   677 
   542 
   678     TSDL_MouseButtonEvent = record
   543     TSDL_MouseButtonEvent = record
   679 {$IFDEF SDL2}
       
   680         type_: LongWord;
   544         type_: LongWord;
   681         timestamp: LongWord;
   545         timestamp: LongWord;
   682         windowID: LongWord;
   546         windowID: LongWord;
   683         which: LongWord;
   547         which: LongWord;
   684         button, state, padding1, padding2: Byte;
   548         button, state, padding1, padding2: Byte;
   685         x, y: LongInt;
   549         x, y: LongInt;
   686 {$ELSE}
       
   687         type_, which, button, state: Byte;
       
   688         x, y: Word;
       
   689 {$ENDIF}
       
   690         end;
   550         end;
   691 
   551 
   692     TSDL_MouseWheelEvent = record
   552     TSDL_MouseWheelEvent = record
   693         type_: LongWord;
   553         type_: LongWord;
   694 {$IFDEF SDL2}
       
   695         timestamp: LongWord;
   554         timestamp: LongWord;
   696         windowID: LongWord;
   555         windowID: LongWord;
   697         which: LongWord;
   556         which: LongWord;
   698 {$ELSE}
       
   699         which: Byte;
       
   700 {$ENDIF}
       
   701         x, y: LongInt;
   557         x, y: LongInt;
   702         end;
   558         end;
   703 
   559 
   704     TSDL_JoyAxisEvent = record
   560     TSDL_JoyAxisEvent = record
   705 {$IFDEF SDL2}
       
   706         type_: LongWord;
   561         type_: LongWord;
   707         timestamp: LongWord;
   562         timestamp: LongWord;
   708         which: LongWord;
   563         which: LongWord;
   709 {$ELSE}
       
   710         type_: Byte;
       
   711         which: Byte;
       
   712 {$ENDIF}
       
   713         axis: Byte;
   564         axis: Byte;
   714 {$IFDEF SDL2}
       
   715         padding1, padding2, padding3: Byte;
   565         padding1, padding2, padding3: Byte;
   716         value: LongInt;
   566         value: LongInt;
   717         padding4: Word;
   567         padding4: Word;
   718 {$ELSE}
       
   719         value: SmallInt;
       
   720 {$ENDIF}
       
   721         end;
   568         end;
   722 
   569 
   723     TSDL_JoyBallEvent = record
   570     TSDL_JoyBallEvent = record
   724 {$IFDEF SDL2}
       
   725         type_: LongWord;
   571         type_: LongWord;
   726         timestamp: LongWord;
   572         timestamp: LongWord;
   727         which: LongWord;
   573         which: LongWord;
   728 {$ELSE}
       
   729         type_: Byte;
       
   730         which: Byte;
       
   731 {$ENDIF}
       
   732         ball: Byte;
   574         ball: Byte;
   733 {$IFDEF SDL2}
       
   734         padding1, padding2, padding3: Byte;
   575         padding1, padding2, padding3: Byte;
   735 {$ENDIF}
       
   736         xrel, yrel: SmallInt;
   576         xrel, yrel: SmallInt;
   737         end;
   577         end;
   738 
   578 
   739     TSDL_JoyHatEvent = record
   579     TSDL_JoyHatEvent = record
   740 {$IFDEF SDL2}
       
   741         type_: LongWord;
   580         type_: LongWord;
   742         timestamp: LongWord;
   581         timestamp: LongWord;
   743         which: LongWord;
   582         which: LongWord;
   744 {$ELSE}
       
   745         type_: Byte;
       
   746         which: Byte;
       
   747 {$ENDIF}
       
   748         hat: Byte;
   583         hat: Byte;
   749         value: Byte;
   584         value: Byte;
   750 {$IFDEF SDL2}
       
   751         padding1, padding2: Byte;
   585         padding1, padding2: Byte;
   752 {$ENDIF}
       
   753         end;
   586         end;
   754 
   587 
   755     TSDL_JoyButtonEvent = record
   588     TSDL_JoyButtonEvent = record
   756 {$IFDEF SDL2}
   589         type_: LongWord;
   757         type_: LongWord;
   590         timestamp: LongWord;
   758         timestamp: LongWord;
       
   759 {$ELSE}
       
   760         type_: Byte;
       
   761 {$ENDIF}
       
   762         which: Byte;
   591         which: Byte;
   763         button: Byte;
   592         button: Byte;
   764         state: Byte;
   593         state: Byte;
   765 {$IFDEF SDL2}
       
   766         padding1: Byte;
   594         padding1: Byte;
   767 {$ENDIF}
       
   768         end;
   595         end;
   769 
   596 
   770     TSDL_QuitEvent = record
   597     TSDL_QuitEvent = record
   771 {$IFDEF SDL2}
   598         type_: LongWord;
   772         type_: LongWord;
   599         timestamp: LongWord;
   773         timestamp: LongWord;
       
   774 {$ELSE}
       
   775         type_: Byte;
       
   776 {$ENDIF}
       
   777         end;
   600         end;
   778 
   601 
   779     TSDL_UserEvent = record
   602     TSDL_UserEvent = record
   780 {$IFDEF SDL2}
       
   781         type_: LongWord;
   603         type_: LongWord;
   782         timestamp: LongWord;
   604         timestamp: LongWord;
   783         windowID: LongWord;
   605         windowID: LongWord;
   784 {$ELSE}
       
   785         type_: Byte;
       
   786 {$ENDIF}
       
   787         code: LongInt;
   606         code: LongInt;
   788         data1, data2: Pointer;
   607         data1, data2: Pointer;
   789         end;
   608         end;
   790 
   609 
   791     PSDL_Event = ^TSDL_Event;
   610     PSDL_Event = ^TSDL_Event;
   792     TSDL_Event = record
   611     TSDL_Event = record
   793 {$IFDEF SDL2}
       
   794         case LongInt of
   612         case LongInt of
   795             SDL_FIRSTEVENT: (type_: LongWord);
   613             SDL_FIRSTEVENT: (type_: LongWord);
   796             SDL_COMMONDEVENT: (common: TSDL_CommonEvent);
   614             SDL_COMMONDEVENT: (common: TSDL_CommonEvent);
   797             SDL_WINDOWEVENT: (window: TSDL_WindowEvent);
   615             SDL_WINDOWEVENT: (window: TSDL_WindowEvent);
   798             SDL_KEYDOWN,
   616             SDL_KEYDOWN,
   824             SDL_FINGERMOTION: (tfinger: TSDL_TouchFingerEvent);
   642             SDL_FINGERMOTION: (tfinger: TSDL_TouchFingerEvent);
   825             SDL_MULTIGESTURE: (mgesture: TSDL_MultiGestureEvent);
   643             SDL_MULTIGESTURE: (mgesture: TSDL_MultiGestureEvent);
   826             SDL_DOLLARGESTURE: (dgesture: TSDL_DollarGestureEvent);
   644             SDL_DOLLARGESTURE: (dgesture: TSDL_DollarGestureEvent);
   827             SDL_DROPFILE: (drop: TSDL_DropEvent);
   645             SDL_DROPFILE: (drop: TSDL_DropEvent);
   828             SDL_ALLEVENTS: (foo: shortstring);
   646             SDL_ALLEVENTS: (foo: shortstring);
   829 {$ELSE}
       
   830         case Byte of
       
   831             SDL_NOEVENT: (type_: Byte);
       
   832             SDL_ACTIVEEVENT: (active: TSDL_ActiveEvent);
       
   833             SDL_KEYDOWN,
       
   834             SDL_KEYUP: (key: TSDL_KeyboardEvent);
       
   835             SDL_MOUSEMOTION: (motion: TSDL_MouseMotionEvent);
       
   836             SDL_MOUSEBUTTONDOWN,
       
   837             SDL_MOUSEBUTTONUP: (button: TSDL_MouseButtonEvent);
       
   838             SDL_JOYAXISMOTION: (jaxis: TSDL_JoyAxisEvent);
       
   839             SDL_JOYHATMOTION: (jhat: TSDL_JoyHatEvent);
       
   840             SDL_JOYBALLMOTION: (jball: TSDL_JoyBallEvent);
       
   841             SDL_JOYBUTTONDOWN,
       
   842             SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent);
       
   843             SDL_QUITEV: (quit: TSDL_QuitEvent);
       
   844             //SDL_SYSWMEVENT,SDL_EVENT_RESERVEDA,SDL_EVENT_RESERVEDB
       
   845             SDL_VIDEORESIZE: (resize: TSDL_ResizeEvent);
       
   846             SDL_ALLEVENTS: (foo: shortstring);
       
   847 {$ENDIF}
       
   848         end;
   647         end;
   849 
   648 
   850     TSDL_EventFilter = function( event : PSDL_Event ): Integer; cdecl;
   649     TSDL_EventFilter = function( event : PSDL_Event ): Integer; cdecl;
   851 
   650 
   852     TByteArray = array[0..65535] of Byte;
   651     TByteArray = array[0..65535] of Byte;
   872         SDL_GL_ACCUM_ALPHA_SIZE,
   671         SDL_GL_ACCUM_ALPHA_SIZE,
   873         SDL_GL_STEREO,
   672         SDL_GL_STEREO,
   874         SDL_GL_MULTISAMPLEBUFFERS,
   673         SDL_GL_MULTISAMPLEBUFFERS,
   875         SDL_GL_MULTISAMPLESAMPLES,
   674         SDL_GL_MULTISAMPLESAMPLES,
   876         SDL_GL_ACCELERATED_VISUAL,
   675         SDL_GL_ACCELERATED_VISUAL,
   877 {$IFDEF SDL2}
       
   878         SDL_GL_RETAINED_BACKING,
   676         SDL_GL_RETAINED_BACKING,
   879         SDL_GL_CONTEXT_MAJOR_VERSION,
   677         SDL_GL_CONTEXT_MAJOR_VERSION,
   880         SDL_GL_CONTEXT_MINOR_VERSION,
   678         SDL_GL_CONTEXT_MINOR_VERSION,
   881         SDL_GL_CONTEXT_EGL,
   679         SDL_GL_CONTEXT_EGL,
   882         SDL_GL_CONTEXT_FLAGS,
   680         SDL_GL_CONTEXT_FLAGS,
   883         SDL_GL_CONTEXT_PROFILE_MASK,
   681         SDL_GL_CONTEXT_PROFILE_MASK,
   884         SDL_GL_SHARE_WITH_CURRENT_CONTEXT
   682         SDL_GL_SHARE_WITH_CURRENT_CONTEXT
   885 {$ELSE}
       
   886         SDL_GL_SWAP_CONTROL
       
   887 {$ENDIF}
       
   888         );
   683         );
   889 
   684 
   890 {$IFDEF SDL2}
       
   891     TSDL_ArrayByteOrder = (  // array component order, low Byte -> high Byte
   685     TSDL_ArrayByteOrder = (  // array component order, low Byte -> high Byte
   892         SDL_ARRAYORDER_NONE,
   686         SDL_ARRAYORDER_NONE,
   893         SDL_ARRAYORDER_RGB,
   687         SDL_ARRAYORDER_RGB,
   894         SDL_ARRAYORDER_RGBA,
   688         SDL_ARRAYORDER_RGBA,
   895         SDL_ARRAYORDER_ARGB,
   689         SDL_ARRAYORDER_ARGB,
   896         SDL_ARRAYORDER_BGR,
   690         SDL_ARRAYORDER_BGR,
   897         SDL_ARRAYORDER_BGRA,
   691         SDL_ARRAYORDER_BGRA,
   898         SDL_ARRAYORDER_ABGR
   692         SDL_ARRAYORDER_ABGR
   899         );
   693         );
   900 {$ENDIF}
       
   901 
   694 
   902     // Joystick/Controller support
   695     // Joystick/Controller support
   903     PSDL_Joystick = ^TSDL_Joystick;
   696     PSDL_Joystick = ^TSDL_Joystick;
   904     TSDL_Joystick = record
   697     TSDL_Joystick = record
   905             end;
   698             end;
  1000 function  SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName;
   793 function  SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName;
  1001 
   794 
  1002 function  SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName;
   795 function  SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName;
  1003 function  SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: LongInt): LongInt; cdecl; external SDLLibName;
   796 function  SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: LongInt): LongInt; cdecl; external SDLLibName;
  1004 
   797 
  1005 {$IFDEF SDL2}
       
  1006 function  SDL_CreateWindow(title: PChar; x,y,w,h: LongInt; flags: LongWord): PSDL_Window; cdecl; external SDLLibName;
   798 function  SDL_CreateWindow(title: PChar; x,y,w,h: LongInt; flags: LongWord): PSDL_Window; cdecl; external SDLLibName;
  1007 function  SDL_CreateRenderer(window: PSDL_Window; index: LongInt; flags: LongWord): PSDL_Renderer; cdecl; external SDLLibName;
   799 function  SDL_CreateRenderer(window: PSDL_Window; index: LongInt; flags: LongWord): PSDL_Renderer; cdecl; external SDLLibName;
  1008 function  SDL_DestroyWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName;
   800 function  SDL_DestroyWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName;
  1009 function  SDL_DestroyRenderer(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName;
   801 function  SDL_DestroyRenderer(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName;
  1010 procedure SDL_SetWindowSize(window: PSDL_Window; w, h: LongInt); cdecl; external SDLLibName;
   802 procedure SDL_SetWindowSize(window: PSDL_Window; w, h: LongInt); cdecl; external SDLLibName;
  1037 
   829 
  1038 function  SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: TSDL_eventaction; minType, maxType: LongWord): LongInt; cdecl; external SDLLibName;
   830 function  SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: TSDL_eventaction; minType, maxType: LongWord): LongInt; cdecl; external SDLLibName;
  1039 
   831 
  1040 function  SDL_AllocFormat(format: LongWord): PSDL_PixelFormat; cdecl; external SDLLibName;
   832 function  SDL_AllocFormat(format: LongWord): PSDL_PixelFormat; cdecl; external SDLLibName;
  1041 procedure SDL_FreeFormat(pixelformat: PSDL_PixelFormat); cdecl; external SDLLibName;
   833 procedure SDL_FreeFormat(pixelformat: PSDL_PixelFormat); cdecl; external SDLLibName;
  1042 {$ELSE}
       
  1043 function  SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: TSDL_eventaction; mask: LongWord): LongInt; cdecl; external SDLLibName;
       
  1044 
       
  1045 function  SDL_EnableUNICODE(enable: LongInt): LongInt; cdecl; external SDLLibName;
       
  1046 function  SDL_EnableKeyRepeat(timedelay, interval: LongInt): LongInt; cdecl; external SDLLibName;
       
  1047 function  SDL_VideoDriverName(namebuf: PChar; maxlen: LongInt): PChar; cdecl; external SDLLibName;
       
  1048 {$ENDIF}
       
  1049 
   834 
  1050 
   835 
  1051 function  SDL_GetMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
   836 function  SDL_GetMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
  1052 function  SDL_GetKeyName(key: LongWord): PChar; cdecl; external SDLLibName;
   837 function  SDL_GetKeyName(key: LongWord): PChar; cdecl; external SDLLibName;
  1053 function  SDL_GetScancodeName(key: LongWord): PChar; cdecl; external SDLLibName;
   838 function  SDL_GetScancodeName(key: LongWord): PChar; cdecl; external SDLLibName;
  1058 function  SDL_PollEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
   843 function  SDL_PollEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
  1059 function  SDL_WaitEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
   844 function  SDL_WaitEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
  1060 procedure SDL_SetEventFilter(filter: TSDL_EventFilter); cdecl; external SDLLibName;
   845 procedure SDL_SetEventFilter(filter: TSDL_EventFilter); cdecl; external SDLLibName;
  1061 
   846 
  1062 function  SDL_ShowCursor(toggle: LongInt): LongInt; cdecl; external SDLLibName;
   847 function  SDL_ShowCursor(toggle: LongInt): LongInt; cdecl; external SDLLibName;
  1063 procedure SDL_WarpMouse(x, y: Word); {$IFDEF SDL2}inline{$ELSE}cdecl; external SDLLibName{$ENDIF};
   848 procedure SDL_WarpMouse(x, y: Word); inline;
  1064 function  SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName {$IFDEF SDL2} name 'SDL_GetKeyboardState'{$ENDIF};
   849 
       
   850 function  SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName  name 'SDL_GetKeyboardState';
  1065 
   851 
  1066 procedure SDL_WM_SetIcon(icon: PSDL_Surface; mask : Byte); cdecl; external SDLLibName;
   852 procedure SDL_WM_SetIcon(icon: PSDL_Surface; mask : Byte); cdecl; external SDLLibName;
  1067 procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName;
   853 procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName;
  1068 function  SDL_WM_ToggleFullScreen(surface: PSDL_Surface): LongInt; cdecl; external SDLLibName;
   854 function  SDL_WM_ToggleFullScreen(surface: PSDL_Surface): LongInt; cdecl; external SDLLibName;
  1069 
   855 
  1070 
   856 
  1071 (* remember to mark the threaded functions as 'cdecl; export;'
   857 (* remember to mark the threaded functions as 'cdecl; export;'
  1072    (or have fun debugging nil arguments) *)
   858    (or have fun debugging nil arguments) *)
  1073 function  SDL_CreateThread(fn: Pointer; {$IFDEF SDL2}name: PChar;{$ENDIF} data: Pointer): PSDL_Thread; cdecl; external SDLLibName;
   859 function  SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer): PSDL_Thread; cdecl; external SDLLibName;
  1074 procedure SDL_WaitThread(thread: PSDL_Thread; status: PLongInt); cdecl; external SDLLibName;
   860 procedure SDL_WaitThread(thread: PSDL_Thread; status: PLongInt); cdecl; external SDLLibName;
  1075 procedure SDL_KillThread(thread: PSDL_Thread); cdecl; external SDLLibName;
   861 procedure SDL_KillThread(thread: PSDL_Thread); cdecl; external SDLLibName;
  1076 
   862 
  1077 function  SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName;
   863 function  SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName;
  1078 procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName;
   864 procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName;
  1079 function  SDL_LockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName {$IFNDEF SDL2}name 'SDL_mutexP'{$ENDIF};
   865 function  SDL_LockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName;
  1080 function  SDL_UnlockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName {$IFNDEF SDL2}name 'SDL_mutexV'{$ENDIF};
   866 function  SDL_UnlockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName;
  1081 
   867 
  1082 function  SDL_GL_SetAttribute(attr: TSDL_GLattr; value: LongInt): LongInt; cdecl; external SDLLibName;
   868 function  SDL_GL_SetAttribute(attr: TSDL_GLattr; value: LongInt): LongInt; cdecl; external SDLLibName;
  1083 procedure SDL_GL_SwapBuffers; cdecl; external SDLLibName;
   869 procedure SDL_GL_SwapBuffers; cdecl; external SDLLibName;
  1084 
   870 
  1085 procedure SDL_LockAudio; cdecl; external SDLLibName;
   871 procedure SDL_LockAudio; cdecl; external SDLLibName;
  1186 procedure SDLNet_Write32(value: LongWord; buf: Pointer);
   972 procedure SDLNet_Write32(value: LongWord; buf: Pointer);
  1187 function  SDLNet_Read16(buf: Pointer): Word;
   973 function  SDLNet_Read16(buf: Pointer): Word;
  1188 function  SDLNet_Read32(buf: Pointer): LongWord;
   974 function  SDLNet_Read32(buf: Pointer): LongWord;
  1189 
   975 
  1190 implementation
   976 implementation
  1191 {$IFDEF SDL2}
       
  1192 uses uStore;
   977 uses uStore;
  1193 
   978 
  1194 // for sdl1.2 we directly call SDL_WarpMouse()
   979 // for sdl1.2 we directly call SDL_WarpMouse()
  1195 // for sdl2 we provide a SDL_WarpMouse() which calls the right SDL_WarpMouseInWindow() function
   980 // for sdl2 we provide a SDL_WarpMouse() which calls the right SDL_WarpMouseInWindow() function
  1196 // this has the advantage of reducing 'uses' and 'ifdef' statements
   981 // this has the advantage of reducing 'uses' and 'ifdef' statements
  1197 // (SDLwindow is a private member of uStore module)
   982 // (SDLwindow is a private member of uStore module)
  1198 procedure SDL_WarpMouse(x, y: Word); inline;
   983 procedure SDL_WarpMouse(x, y: Word); inline;
  1199 begin
   984 begin
  1200     WarpMouse(x, y);
   985     WarpMouse(x, y);
  1201 end;
   986 end;
  1202 {$ENDIF}
       
  1203 
   987 
  1204 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
   988 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
  1205 begin
   989 begin
  1206     SDL_MustLock:=
   990     SDL_MustLock:=
  1207 {$IFDEF SDL2}
       
  1208         ((surface^.flags and SDL_RLEACCEL) <> 0)
   991         ((surface^.flags and SDL_RLEACCEL) <> 0)
  1209 {$ELSE}
       
  1210         ( surface^.offset <> 0 ) or (( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0)
       
  1211 {$ENDIF}
       
  1212 end;
   992 end;
  1213 
   993 
  1214 {$IFNDEF SDL_MIXER_NEWER}
   994 {$IFNDEF SDL_MIXER_NEWER}
  1215 function  Mix_Init(flags: LongInt): LongInt; inline;
   995 function  Mix_Init(flags: LongInt): LongInt; inline;
  1216 begin
   996 begin