hedgewars/SDLh.pas
changeset 9317 a04c30940d2d
parent 9311 5baf10a52f43
child 9319 492a0ad67e33
equal deleted inserted replaced
9315:15487f7fed42 9317:a04c30940d2d
    91     // SDL_Init() flags
    91     // SDL_Init() flags
    92     SDL_INIT_TIMER          = $00000001;
    92     SDL_INIT_TIMER          = $00000001;
    93     SDL_INIT_AUDIO          = $00000010;
    93     SDL_INIT_AUDIO          = $00000010;
    94     SDL_INIT_VIDEO          = $00000020;
    94     SDL_INIT_VIDEO          = $00000020;
    95     SDL_INIT_JOYSTICK       = $00000200;
    95     SDL_INIT_JOYSTICK       = $00000200;
    96 {$IFDEF SDL13}
    96 {$IFDEF SDL2}
    97     SDL_INIT_HAPTIC         = $00001000;
    97     SDL_INIT_HAPTIC         = $00001000;
    98     SDL_INIT_GAMECONTROLLER = $00002000; // implicitly activates JOYSTICK */
    98     SDL_INIT_GAMECONTROLLER = $00002000; // implicitly activates JOYSTICK */
    99 {$ELSE}
    99 {$ELSE}
   100     SDL_INIT_CDROM          = $00000100;
   100     SDL_INIT_CDROM          = $00000100;
   101     SDL_INIT_EVENTTHREAD    = $01000000;
   101     SDL_INIT_EVENTTHREAD    = $01000000;
   111     SDL_BUTTON_RIGHT     = 3;
   111     SDL_BUTTON_RIGHT     = 3;
   112     SDL_BUTTON_WHEELUP   = 4;
   112     SDL_BUTTON_WHEELUP   = 4;
   113     SDL_BUTTON_WHEELDOWN = 5;
   113     SDL_BUTTON_WHEELDOWN = 5;
   114 
   114 
   115 
   115 
   116 {$IFDEF SDL13}
   116 {$IFDEF SDL2}
   117     // SDL_Event types
   117     // SDL_Event types
   118     // pascal does not support unions as is, so we list here every possible event
   118     // pascal does not support unions as is, so we list here every possible event
   119     // and later associate a struct type each
   119     // and later associate a struct type each
   120     SDL_FIRSTEVENT        = 0;              // type
   120     SDL_FIRSTEVENT        = 0;              // type
   121     SDL_COMMONDEVENT      = 1;              // type and timestamp
   121     SDL_COMMONDEVENT      = 1;              // type and timestamp
   325 // two important reference points for the wanderers of this area
   325 // two important reference points for the wanderers of this area
   326 // http://www.freepascal.org/docs-html/ref/refsu5.html
   326 // http://www.freepascal.org/docs-html/ref/refsu5.html
   327 // http://www.freepascal.org/docs-html/prog/progsu144.html
   327 // http://www.freepascal.org/docs-html/prog/progsu144.html
   328 
   328 
   329 type
   329 type
   330 {$IFDEF SDL13}
   330 {$IFDEF SDL2}
   331     PSDL_Window   = Pointer;
   331     PSDL_Window   = Pointer;
   332     PSDL_Renderer = Pointer;
   332     PSDL_Renderer = Pointer;
   333     PSDL_Texture  = Pointer;
   333     PSDL_Texture  = Pointer;
   334     PSDL_GLContext= Pointer;
   334     PSDL_GLContext= Pointer;
       
   335     TSDL_TouchId  = Int64;
       
   336 {$ENDIF}
   335     TSDL_FingerId = Int64;
   337     TSDL_FingerId = Int64;
   336     TSDL_TouchId  = Int64;
       
   337 {$ENDIF}
       
   338 
   338 
   339     TSDL_eventaction = (SDL_ADDEVENT, SDL_PEEPEVENT, SDL_GETEVENT);
   339     TSDL_eventaction = (SDL_ADDEVENT, SDL_PEEPEVENT, SDL_GETEVENT);
   340 
   340 
   341     PSDL_Rect = ^TSDL_Rect;
   341     PSDL_Rect = ^TSDL_Rect;
   342     TSDL_Rect = record
   342     TSDL_Rect = record
   343 {$IFDEF SDL13}
   343 {$IFDEF SDL2}
   344         x, y, w, h: LongInt;
   344         x, y, w, h: LongInt;
   345 {$ELSE}
   345 {$ELSE}
   346         x, y: SmallInt;
   346         x, y: SmallInt;
   347         w, h: Word;
   347         w, h: Word;
   348 {$ENDIF}
   348 {$ENDIF}
   352         x, y: LongInt;
   352         x, y: LongInt;
   353         end;
   353         end;
   354 
   354 
   355     PSDL_PixelFormat = ^TSDL_PixelFormat;
   355     PSDL_PixelFormat = ^TSDL_PixelFormat;
   356     TSDL_PixelFormat = record
   356     TSDL_PixelFormat = record
   357 {$IFDEF SDL13}
   357 {$IFDEF SDL2}
   358         format: LongWord;
   358         format: LongWord;
   359         palette: Pointer;
   359         palette: Pointer;
   360         BitsPerPixel : Byte;
   360         BitsPerPixel : Byte;
   361         BytesPerPixel: Byte;
   361         BytesPerPixel: Byte;
   362         padding: array[0..1] of Byte;
   362         padding: array[0..1] of Byte;
   398     PSDL_Surface = ^TSDL_Surface;
   398     PSDL_Surface = ^TSDL_Surface;
   399     TSDL_Surface = record
   399     TSDL_Surface = record
   400         flags : LongWord;
   400         flags : LongWord;
   401         format: PSDL_PixelFormat;
   401         format: PSDL_PixelFormat;
   402         w, h  : LongInt;
   402         w, h  : LongInt;
   403         pitch : {$IFDEF SDL13}LongInt{$ELSE}Word{$ENDIF};
   403         pitch : {$IFDEF SDL2}LongInt{$ELSE}Word{$ENDIF};
   404         pixels: Pointer;
   404         pixels: Pointer;
   405 {$IFDEF SDL13}
   405 {$IFDEF SDL2}
   406         userdata: Pointer;
   406         userdata: Pointer;
   407         locked: LongInt;
   407         locked: LongInt;
   408         lock_data: Pointer;
   408         lock_data: Pointer;
   409         clip_rect: TSDL_Rect;
   409         clip_rect: TSDL_Rect;
   410         map: Pointer;
   410         map: Pointer;
   430     TRead  = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; maxnum : LongInt ): LongInt;  cdecl;
   430     TRead  = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; maxnum : LongInt ): LongInt;  cdecl;
   431     TWrite = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; num: LongInt ): LongInt; cdecl;
   431     TWrite = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; num: LongInt ): LongInt; cdecl;
   432     TClose = function( context: PSDL_RWops ): LongInt; cdecl;
   432     TClose = function( context: PSDL_RWops ): LongInt; cdecl;
   433 
   433 
   434     TStdio = record
   434     TStdio = record
   435         autoclose: {$IFDEF SDL13}Boolean{$ELSE}LongInt{$ENDIF};
   435         autoclose: {$IFDEF SDL2}Boolean{$ELSE}LongInt{$ENDIF};
   436         fp: Pointer;
   436         fp: Pointer;
   437         end;
   437         end;
   438 
   438 
   439     TMem = record
   439     TMem = record
   440         base: PByte;
   440         base: PByte;
   442         stop: PByte;
   442         stop: PByte;
   443         end;
   443         end;
   444 
   444 
   445     TUnknown = record
   445     TUnknown = record
   446         data1: Pointer;
   446         data1: Pointer;
   447 {$IFDEF SDL13}
   447 {$IFDEF SDL2}
   448         data2: Pointer;
   448         data2: Pointer;
   449 {$ENDIF}
   449 {$ENDIF}
   450         end;
   450         end;
   451 
   451 
   452 {$IFDEF ANDROID}
   452 {$IFDEF ANDROID}
   460     TWinbuffer = record
   460     TWinbuffer = record
   461         data = pointer;
   461         data = pointer;
   462         size, left : LongInt;
   462         size, left : LongInt;
   463         end;
   463         end;
   464     TWindowsio = record
   464     TWindowsio = record
   465         append = {$IFDEF SDL13}Boolean{$ELSE}LongInt{$ENDIF};
   465         append = {$IFDEF SDL2}Boolean{$ELSE}LongInt{$ENDIF};
   466         h = pointer;
   466         h = pointer;
   467         buffer = TWinbuffer;
   467         buffer = TWinbuffer;
   468         end;
   468         end;
   469 {$ENDIF}
   469 {$ENDIF}
   470 {$ENDIF}
   470 {$ENDIF}
   489             end;
   489             end;
   490 
   490 
   491 
   491 
   492 {* SDL_Event type definition *}
   492 {* SDL_Event type definition *}
   493 
   493 
   494 {$IFDEF SDL13}
   494 {$IFDEF SDL2}
   495     TSDL_Keysym = record
   495     TSDL_Keysym = record
   496         scancode: LongInt;
   496         scancode: LongInt;
   497         sym: LongInt;
   497         sym: LongInt;
   498         modifier: Word;
   498         modifier: Word;
   499         unused: LongWord;
   499         unused: LongWord;
   612         w, h: LongInt;
   612         w, h: LongInt;
   613         end;
   613         end;
   614 {$ENDIF}
   614 {$ENDIF}
   615 
   615 
   616     TSDL_KeyboardEvent = record
   616     TSDL_KeyboardEvent = record
   617 {$IFDEF SDL13}
   617 {$IFDEF SDL2}
   618         type_: LongWord;
   618         type_: LongWord;
   619         timestamp: LongWord;
   619         timestamp: LongWord;
   620         windowID: LongWord;
   620         windowID: LongWord;
   621         state, repeat_, padding2, padding3: Byte;
   621         state, repeat_, padding2, padding3: Byte;
   622 {$ELSE}
   622 {$ELSE}
   624 {$ENDIF}
   624 {$ENDIF}
   625         keysym: TSDL_Keysym;
   625         keysym: TSDL_Keysym;
   626         end;
   626         end;
   627 
   627 
   628     TSDL_MouseMotionEvent = record
   628     TSDL_MouseMotionEvent = record
   629 {$IFDEF SDL13}
   629 {$IFDEF SDL2}
   630         type_: LongWord;
   630         type_: LongWord;
   631         timestamp: LongWord;
   631         timestamp: LongWord;
   632         windowID: LongWord;
   632         windowID: LongWord;
   633         which, state: LongWord;
   633         which, state: LongWord;
   634         x, y, xrel, yrel: LongInt;
   634         x, y, xrel, yrel: LongInt;
   637         x, y, xrel, yrel: Word;
   637         x, y, xrel, yrel: Word;
   638 {$ENDIF}
   638 {$ENDIF}
   639         end;
   639         end;
   640 
   640 
   641     TSDL_MouseButtonEvent = record
   641     TSDL_MouseButtonEvent = record
   642 {$IFDEF SDL13}
   642 {$IFDEF SDL2}
   643         type_: LongWord;
   643         type_: LongWord;
   644         timestamp: LongWord;
   644         timestamp: LongWord;
   645         windowID: LongWord;
   645         windowID: LongWord;
   646         which: LongWord;
   646         which: LongWord;
   647         button, state, padding1, padding2: Byte;
   647         button, state, padding1, padding2: Byte;
   652 {$ENDIF}
   652 {$ENDIF}
   653         end;
   653         end;
   654 
   654 
   655     TSDL_MouseWheelEvent = record
   655     TSDL_MouseWheelEvent = record
   656         type_: LongWord;
   656         type_: LongWord;
   657 {$IFDEF SDL13}
   657 {$IFDEF SDL2}
   658         timestamp: LongWord;
   658         timestamp: LongWord;
   659         windowID: LongWord;
   659         windowID: LongWord;
   660         which: LongWord;
   660         which: LongWord;
   661 {$ELSE}
   661 {$ELSE}
   662         which: Byte;
   662         which: Byte;
   663 {$ENDIF}
   663 {$ENDIF}
   664         x, y: LongInt;
   664         x, y: LongInt;
   665         end;
   665         end;
   666 
   666 
   667     TSDL_JoyAxisEvent = record
   667     TSDL_JoyAxisEvent = record
   668 {$IFDEF SDL13}
   668 {$IFDEF SDL2}
   669         type_: LongWord;
   669         type_: LongWord;
   670         timestamp: LongWord;
   670         timestamp: LongWord;
   671         which: LongWord;
   671         which: LongWord;
   672 {$ELSE}
   672 {$ELSE}
   673         type_: Byte;
   673         type_: Byte;
   674         which: Byte;
   674         which: Byte;
   675 {$ENDIF}
   675 {$ENDIF}
   676         axis: Byte;
   676         axis: Byte;
   677 {$IFDEF SDL13}
   677 {$IFDEF SDL2}
   678         padding1, padding2, padding3: Byte;
   678         padding1, padding2, padding3: Byte;
   679         value: LongInt;
   679         value: LongInt;
   680         padding4: Word;
   680         padding4: Word;
   681 {$ELSE}
   681 {$ELSE}
   682         value: SmallInt;
   682         value: SmallInt;
   683 {$ENDIF}
   683 {$ENDIF}
   684         end;
   684         end;
   685 
   685 
   686     TSDL_JoyBallEvent = record
   686     TSDL_JoyBallEvent = record
   687 {$IFDEF SDL13}
   687 {$IFDEF SDL2}
   688         type_: LongWord;
   688         type_: LongWord;
   689         timestamp: LongWord;
   689         timestamp: LongWord;
   690         which: LongWord;
   690         which: LongWord;
   691 {$ELSE}
   691 {$ELSE}
   692         type_: Byte;
   692         type_: Byte;
   693         which: Byte;
   693         which: Byte;
   694 {$ENDIF}
   694 {$ENDIF}
   695         ball: Byte;
   695         ball: Byte;
   696 {$IFDEF SDL13}
   696 {$IFDEF SDL2}
   697         padding1, padding2, padding3: Byte;
   697         padding1, padding2, padding3: Byte;
   698 {$ENDIF}
   698 {$ENDIF}
   699         xrel, yrel: SmallInt;
   699         xrel, yrel: SmallInt;
   700         end;
   700         end;
   701 
   701 
   702     TSDL_JoyHatEvent = record
   702     TSDL_JoyHatEvent = record
   703 {$IFDEF SDL13}
   703 {$IFDEF SDL2}
   704         type_: LongWord;
   704         type_: LongWord;
   705         timestamp: LongWord;
   705         timestamp: LongWord;
   706         which: LongWord;
   706         which: LongWord;
   707 {$ELSE}
   707 {$ELSE}
   708         type_: Byte;
   708         type_: Byte;
   709         which: Byte;
   709         which: Byte;
   710 {$ENDIF}
   710 {$ENDIF}
   711         hat: Byte;
   711         hat: Byte;
   712         value: Byte;
   712         value: Byte;
   713 {$IFDEF SDL13}
   713 {$IFDEF SDL2}
   714         padding1, padding2: Byte;
   714         padding1, padding2: Byte;
   715 {$ENDIF}
   715 {$ENDIF}
   716         end;
   716         end;
   717 
   717 
   718     TSDL_JoyButtonEvent = record
   718     TSDL_JoyButtonEvent = record
   719 {$IFDEF SDL13}
   719 {$IFDEF SDL2}
   720         type_: LongWord;
   720         type_: LongWord;
   721         timestamp: LongWord;
   721         timestamp: LongWord;
   722 {$ELSE}
   722 {$ELSE}
   723         type_: Byte;
   723         type_: Byte;
   724 {$ENDIF}
   724 {$ENDIF}
   725         which: Byte;
   725         which: Byte;
   726         button: Byte;
   726         button: Byte;
   727         state: Byte;
   727         state: Byte;
   728 {$IFDEF SDL13}
   728 {$IFDEF SDL2}
   729         padding1: Byte;
   729         padding1: Byte;
   730 {$ENDIF}
   730 {$ENDIF}
   731         end;
   731         end;
   732 
   732 
   733     TSDL_QuitEvent = record
   733     TSDL_QuitEvent = record
   734 {$IFDEF SDL13}
   734 {$IFDEF SDL2}
   735         type_: LongWord;
   735         type_: LongWord;
   736         timestamp: LongWord;
   736         timestamp: LongWord;
   737 {$ELSE}
   737 {$ELSE}
   738         type_: Byte;
   738         type_: Byte;
   739 {$ENDIF}
   739 {$ENDIF}
   740         end;
   740         end;
   741 
   741 
   742     TSDL_UserEvent = record
   742     TSDL_UserEvent = record
   743 {$IFDEF SDL13}
   743 {$IFDEF SDL2}
   744         type_: LongWord;
   744         type_: LongWord;
   745         timestamp: LongWord;
   745         timestamp: LongWord;
   746         windowID: LongWord;
   746         windowID: LongWord;
   747 {$ELSE}
   747 {$ELSE}
   748         type_: Byte;
   748         type_: Byte;
   751         data1, data2: Pointer;
   751         data1, data2: Pointer;
   752         end;
   752         end;
   753 
   753 
   754     PSDL_Event = ^TSDL_Event;
   754     PSDL_Event = ^TSDL_Event;
   755     TSDL_Event = record
   755     TSDL_Event = record
   756 {$IFDEF SDL13}
   756 {$IFDEF SDL2}
   757         case LongInt of
   757         case LongInt of
   758             SDL_FIRSTEVENT: (type_: LongWord);
   758             SDL_FIRSTEVENT: (type_: LongWord);
   759             SDL_COMMONDEVENT: (common: TSDL_CommonEvent);
   759             SDL_COMMONDEVENT: (common: TSDL_CommonEvent);
   760             SDL_WINDOWEVENT: (window: TSDL_WindowEvent);
   760             SDL_WINDOWEVENT: (window: TSDL_WindowEvent);
   761             SDL_KEYDOWN,
   761             SDL_KEYDOWN,
   835         SDL_GL_ACCUM_ALPHA_SIZE,
   835         SDL_GL_ACCUM_ALPHA_SIZE,
   836         SDL_GL_STEREO,
   836         SDL_GL_STEREO,
   837         SDL_GL_MULTISAMPLEBUFFERS,
   837         SDL_GL_MULTISAMPLEBUFFERS,
   838         SDL_GL_MULTISAMPLESAMPLES,
   838         SDL_GL_MULTISAMPLESAMPLES,
   839         SDL_GL_ACCELERATED_VISUAL,
   839         SDL_GL_ACCELERATED_VISUAL,
   840 {$IFDEF SDL13}
   840 {$IFDEF SDL2}
   841         SDL_GL_RETAINED_BACKING,
   841         SDL_GL_RETAINED_BACKING,
   842         SDL_GL_CONTEXT_MAJOR_VERSION,
   842         SDL_GL_CONTEXT_MAJOR_VERSION,
   843         SDL_GL_CONTEXT_MINOR_VERSION,
   843         SDL_GL_CONTEXT_MINOR_VERSION,
   844         SDL_GL_CONTEXT_EGL,
   844         SDL_GL_CONTEXT_EGL,
   845         SDL_GL_CONTEXT_FLAGS,
   845         SDL_GL_CONTEXT_FLAGS,
   848 {$ELSE}
   848 {$ELSE}
   849         SDL_GL_SWAP_CONTROL
   849         SDL_GL_SWAP_CONTROL
   850 {$ENDIF}
   850 {$ENDIF}
   851         );
   851         );
   852 
   852 
   853 {$IFDEF SDL13}
   853 {$IFDEF SDL2}
   854     TSDL_ArrayByteOrder = (  // array component order, low Byte -> high Byte
   854     TSDL_ArrayByteOrder = (  // array component order, low Byte -> high Byte
   855         SDL_ARRAYORDER_NONE,
   855         SDL_ARRAYORDER_NONE,
   856         SDL_ARRAYORDER_RGB,
   856         SDL_ARRAYORDER_RGB,
   857         SDL_ARRAYORDER_RGBA,
   857         SDL_ARRAYORDER_RGBA,
   858         SDL_ARRAYORDER_ARGB,
   858         SDL_ARRAYORDER_ARGB,
   963 function  SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName;
   963 function  SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName;
   964 
   964 
   965 function  SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName;
   965 function  SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName;
   966 function  SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: LongInt): LongInt; cdecl; external SDLLibName;
   966 function  SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: LongInt): LongInt; cdecl; external SDLLibName;
   967 
   967 
   968 {$IFDEF SDL13}
   968 {$IFDEF SDL2}
   969 function  SDL_CreateWindow(title: PChar; x,y,w,h: LongInt; flags: LongWord): PSDL_Window; cdecl; external SDLLibName;
   969 function  SDL_CreateWindow(title: PChar; x,y,w,h: LongInt; flags: LongWord): PSDL_Window; cdecl; external SDLLibName;
   970 function  SDL_CreateRenderer(window: PSDL_Window; index: LongInt; flags: LongWord): PSDL_Renderer; cdecl; external SDLLibName;
   970 function  SDL_CreateRenderer(window: PSDL_Window; index: LongInt; flags: LongWord): PSDL_Renderer; cdecl; external SDLLibName;
   971 function  SDL_DestroyWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName;
   971 function  SDL_DestroyWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName;
   972 function  SDL_DestroyRenderer(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName;
   972 function  SDL_DestroyRenderer(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName;
   973 procedure SDL_SetWindowSize(window: PSDL_Window; w, h: LongInt); cdecl; external SDLLibName;
   973 procedure SDL_SetWindowSize(window: PSDL_Window; w, h: LongInt); cdecl; external SDLLibName;
   996 procedure SDL_WarpMouseInWindow(window: PSDL_Window; x, y: LongInt); cdecl; external SDLLibName;
   996 procedure SDL_WarpMouseInWindow(window: PSDL_Window; x, y: LongInt); cdecl; external SDLLibName;
   997 function  SDL_SetHint(name, value: PChar): Boolean; cdecl; external SDLLibName;
   997 function  SDL_SetHint(name, value: PChar): Boolean; cdecl; external SDLLibName;
   998 procedure SDL_StartTextInput; cdecl; external SDLLibName;
   998 procedure SDL_StartTextInput; cdecl; external SDLLibName;
   999 
   999 
  1000 function  SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: TSDL_eventaction; minType, maxType: LongWord): LongInt; cdecl; external SDLLibName;
  1000 function  SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: TSDL_eventaction; minType, maxType: LongWord): LongInt; cdecl; external SDLLibName;
       
  1001 
       
  1002 function  SDL_AllocFormat(format: LongWord): PSDL_PixelFormat; cdecl; external SDLLibName;
       
  1003 procedure SDL_FreeFormat(pixelformat: PSDL_PixelFormat); cdecl; external SDLLibName;
  1001 {$ELSE}
  1004 {$ELSE}
  1002 function  SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: TSDL_eventaction; mask: LongWord): LongInt; cdecl; external SDLLibName;
  1005 function  SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: TSDL_eventaction; mask: LongWord): LongInt; cdecl; external SDLLibName;
       
  1006 
       
  1007 function  SDL_EnableUNICODE(enable: LongInt): LongInt; cdecl; external SDLLibName;
       
  1008 function  SDL_EnableKeyRepeat(timedelay, interval: LongInt): LongInt; cdecl; external SDLLibName;
       
  1009 function  SDL_VideoDriverName(namebuf: PChar; maxlen: LongInt): PChar; cdecl; external SDLLibName;
  1003 {$ENDIF}
  1010 {$ENDIF}
  1004 
  1011 
  1005 
  1012 
  1006 function  SDL_GetMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
  1013 function  SDL_GetMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
  1007 function  SDL_GetKeyName(key: LongWord): PChar; cdecl; external SDLLibName;
  1014 function  SDL_GetKeyName(key: LongWord): PChar; cdecl; external SDLLibName;
  1013 function  SDL_PollEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
  1020 function  SDL_PollEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
  1014 function  SDL_WaitEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
  1021 function  SDL_WaitEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
  1015 procedure SDL_SetEventFilter(filter: TSDL_EventFilter); cdecl; external SDLLibName;
  1022 procedure SDL_SetEventFilter(filter: TSDL_EventFilter); cdecl; external SDLLibName;
  1016 
  1023 
  1017 function  SDL_ShowCursor(toggle: LongInt): LongInt; cdecl; external SDLLibName;
  1024 function  SDL_ShowCursor(toggle: LongInt): LongInt; cdecl; external SDLLibName;
       
  1025 procedure SDL_WarpMouse(x, y: Word); {$IFDEF SDL2}inline{$ELSE}cdecl; external SDLLibName{$ENDIF};
       
  1026 function  SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName {$IFDEF SDL2} name 'SDL_GetKeyboardState'{$ENDIF};
  1018 
  1027 
  1019 procedure SDL_WM_SetIcon(icon: PSDL_Surface; mask : Byte); cdecl; external SDLLibName;
  1028 procedure SDL_WM_SetIcon(icon: PSDL_Surface; mask : Byte); cdecl; external SDLLibName;
  1020 procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName;
  1029 procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName;
  1021 function  SDL_WM_ToggleFullScreen(surface: PSDL_Surface): LongInt; cdecl; external SDLLibName;
  1030 function  SDL_WM_ToggleFullScreen(surface: PSDL_Surface): LongInt; cdecl; external SDLLibName;
  1022 
  1031 
  1023 
  1032 
  1024 // remember to mark the threaded functions as 'cdecl; export;'
  1033 (* remember to mark the threaded functions as 'cdecl; export;'
  1025 // (or have fun debugging nil arguments)
  1034    (or have fun debugging nil arguments) *)
  1026 function  SDL_CreateThread(fn: Pointer; {$IFDEF SDL13}name: PChar;{$ENDIF} data: Pointer): PSDL_Thread; cdecl; external SDLLibName;
  1035 function  SDL_CreateThread(fn: Pointer; {$IFDEF SDL2}name: PChar;{$ENDIF} data: Pointer): PSDL_Thread; cdecl; external SDLLibName;
  1027 procedure SDL_WaitThread(thread: PSDL_Thread; status: PLongInt); cdecl; external SDLLibName;
  1036 procedure SDL_WaitThread(thread: PSDL_Thread; status: PLongInt); cdecl; external SDLLibName;
  1028 procedure SDL_KillThread(thread: PSDL_Thread); cdecl; external SDLLibName;
  1037 procedure SDL_KillThread(thread: PSDL_Thread); cdecl; external SDLLibName;
  1029 
  1038 
  1030 function  SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName;
  1039 function  SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName;
  1031 procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName;
  1040 procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName;
  1032 function  SDL_LockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName {$IFNDEF SDL13}name 'SDL_mutexP'{$ENDIF};
  1041 function  SDL_LockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName {$IFNDEF SDL2}name 'SDL_mutexP'{$ENDIF};
  1033 function  SDL_UnlockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName {$IFNDEF SDL13}name 'SDL_mutexV'{$ENDIF};
  1042 function  SDL_UnlockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName {$IFNDEF SDL2}name 'SDL_mutexV'{$ENDIF};
  1034 
  1043 
  1035 function  SDL_GL_SetAttribute(attr: TSDL_GLattr; value: LongInt): LongInt; cdecl; external SDLLibName;
  1044 function  SDL_GL_SetAttribute(attr: TSDL_GLattr; value: LongInt): LongInt; cdecl; external SDLLibName;
  1036 procedure SDL_GL_SwapBuffers; cdecl; external SDLLibName;
  1045 procedure SDL_GL_SwapBuffers; cdecl; external SDLLibName;
  1037 
  1046 
  1038 procedure SDL_LockAudio; cdecl; external SDLLibName;
  1047 procedure SDL_LockAudio; cdecl; external SDLLibName;
  1059 function SDL_putenv(const text: PChar): LongInt; cdecl; external SDLLibName;
  1068 function SDL_putenv(const text: PChar): LongInt; cdecl; external SDLLibName;
  1060 function SDL_getenv(const text: PChar): PChar; cdecl; external SDLLibName;
  1069 function SDL_getenv(const text: PChar): PChar; cdecl; external SDLLibName;
  1061 {$ENDIF}
  1070 {$ENDIF}
  1062 
  1071 
  1063 
  1072 
  1064 {* Compatibility between SDL-1.2 and SDL-1.3 *}
       
  1065 procedure SDL_WarpMouse(x, y: Word); {$IFDEF SDL13}inline{$ELSE}cdecl; external SDLLibName{$ENDIF};
       
  1066 function  SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName {$IFDEF SDL13} name 'SDL_GetKeyboardState'{$ENDIF};
       
  1067 function  SDL_AllocFormat(format: LongWord): PSDL_PixelFormat; {$IFDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
       
  1068 procedure SDL_FreeFormat(pixelformat: PSDL_PixelFormat); {$IFDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
       
  1069 function  SDL_VideoDriverName(namebuf: PChar; maxlen: LongInt): PChar; {$IFNDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
       
  1070 function  SDL_EnableUNICODE(enable: LongInt): LongInt; {$IFNDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
       
  1071 function  SDL_EnableKeyRepeat(timedelay, interval: LongInt): LongInt; {$IFNDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
       
  1072 
       
  1073 (*  SDL_ttf  *)
  1073 (*  SDL_ttf  *)
  1074 function  TTF_Init: LongInt; cdecl; external SDL_TTFLibName;
  1074 function  TTF_Init: LongInt; cdecl; external SDL_TTFLibName;
  1075 procedure TTF_Quit; cdecl; external SDL_TTFLibName;
  1075 procedure TTF_Quit; cdecl; external SDL_TTFLibName;
  1076 
  1076 
  1077 function  TTF_SizeUTF8(font: PTTF_Font; const text: PChar; w, h: PLongInt): LongInt; cdecl; external SDL_TTFLibName;
  1077 function  TTF_SizeUTF8(font: PTTF_Font; const text: PChar; w, h: PLongInt): LongInt; cdecl; external SDL_TTFLibName;
  1082 
  1082 
  1083 function  TTF_OpenFontRW(src: PSDL_RWops; freesrc: LongBool; size: LongInt): PTTF_Font; cdecl; external SDL_TTFLibName;
  1083 function  TTF_OpenFontRW(src: PSDL_RWops; freesrc: LongBool; size: LongInt): PTTF_Font; cdecl; external SDL_TTFLibName;
  1084 procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName;
  1084 procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName;
  1085 
  1085 
  1086 (*  SDL_mixer  *)
  1086 (*  SDL_mixer  *)
  1087 function  Mix_Init(flags: LongInt): LongInt; {$IFDEF SDL_MIXER_NEWER}cdecl; external SDL_MixerLibName;{$ENDIF}
  1087 function  Mix_Init(flags: LongInt): LongInt; {$IFDEF SDL_MIXER_NEWER}cdecl; external SDL_MixerLibName{$ELSE}inline{$ENDIF};
  1088 procedure Mix_Quit; {$IFDEF SDL_MIXER_NEWER}cdecl; external SDL_MixerLibName;{$ENDIF}
  1088 procedure Mix_Quit; {$IFDEF SDL_MIXER_NEWER}cdecl; external SDL_MixerLibName{$ELSE}inline{$ENDIF};
  1089 
  1089 
  1090 function  Mix_OpenAudio(frequency: LongInt; format: Word; channels: LongInt; chunksize: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1090 function  Mix_OpenAudio(frequency: LongInt; format: Word; channels: LongInt; chunksize: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1091 procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName;
  1091 procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName;
  1092 function  Mix_QuerySpec(frequency: PLongInt; format: PWord; channels: PLongInt): LongInt; cdecl; external SDL_MixerLibName;
  1092 function  Mix_QuerySpec(frequency: PLongInt; format: PWord; channels: PLongInt): LongInt; cdecl; external SDL_MixerLibName;
  1093 
  1093 
  1118 function  Mix_FadeOutChannel(channel: LongInt; fadems: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1118 function  Mix_FadeOutChannel(channel: LongInt; fadems: LongInt): LongInt; cdecl; external SDL_MixerLibName;
  1119 
  1119 
  1120 procedure Mix_SetPostMix( mix_func: TPostMix; arg: pointer); cdecl; external SDL_MixerLibName;
  1120 procedure Mix_SetPostMix( mix_func: TPostMix; arg: pointer); cdecl; external SDL_MixerLibName;
  1121 
  1121 
  1122 (*  SDL_image  *)
  1122 (*  SDL_image  *)
  1123 function  IMG_Init(flags: LongInt): LongInt; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName;{$ENDIF}
  1123 function  IMG_Init(flags: LongInt): LongInt; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName{$ELSE}inline{$ENDIF};
  1124 procedure IMG_Quit; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName;{$ENDIF}
  1124 procedure IMG_Quit; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName{$ELSE}inline{$ENDIF};
  1125 
  1125 
  1126 function  IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1126 function  IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1127 function  IMG_Load_RW(rwop: PSDL_RWops; freesrc: LongBool): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1127 function  IMG_Load_RW(rwop: PSDL_RWops; freesrc: LongBool): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1128 function  IMG_LoadPNG_RW(rwop: PSDL_RWops): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1128 function  IMG_LoadPNG_RW(rwop: PSDL_RWops): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1129 function  IMG_LoadTyped_RW(rwop: PSDL_RWops; freesrc: LongBool; type_: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1129 function  IMG_LoadTyped_RW(rwop: PSDL_RWops; freesrc: LongBool; type_: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
  1148 procedure SDLNet_Write32(value: LongWord; buf: Pointer);
  1148 procedure SDLNet_Write32(value: LongWord; buf: Pointer);
  1149 function  SDLNet_Read16(buf: Pointer): Word;
  1149 function  SDLNet_Read16(buf: Pointer): Word;
  1150 function  SDLNet_Read32(buf: Pointer): LongWord;
  1150 function  SDLNet_Read32(buf: Pointer): LongWord;
  1151 
  1151 
  1152 implementation
  1152 implementation
  1153 {$IFDEF SDL13}
  1153 {$IFDEF SDL2}
  1154 uses strings, uVariables, uStore;
  1154 uses uStore;
  1155 
  1155 
  1156 // compatible functions
  1156 // for sdl1.2 we directly call SDL_WarpMouse()
       
  1157 // for sdl2 we provide a SDL_WarpMouse() which calls the right SDL_WarpMouseInWindow() function
       
  1158 // this has the advantage of reducing 'uses' and 'ifdef' statements
       
  1159 // (SDLwindow is a private member of uStore module)
  1157 procedure SDL_WarpMouse(x, y: Word); inline;
  1160 procedure SDL_WarpMouse(x, y: Word); inline;
  1158 begin
  1161 begin
  1159     WarpMouse(x, y);
  1162     WarpMouse(x, y);
  1160 end;
  1163 end;
  1161 
       
  1162 function SDL_VideoDriverName(namebuf: PChar; maxlen: LongInt): PChar;
       
  1163 var name : PChar = nil;
       
  1164 begin
       
  1165     name:= SDL_GetCurrentVideoDriver();
       
  1166     if (name <> nil) and (namebuf <> nil) then
       
  1167         begin
       
  1168         strlcopy(namebuf, name, maxlen);
       
  1169         SDL_VideoDriverName:= namebuf
       
  1170         end;
       
  1171     SDL_VideoDriverName:= name;
       
  1172 end;
       
  1173 
       
  1174 function SDL_EnableUNICODE(enable: LongInt): LongInt;
       
  1175 begin
       
  1176     enable:= enable; // avoid hint
       
  1177     SDL_StartTextInput();
       
  1178     SDL_EnableUNICODE:= 0;
       
  1179 end;
       
  1180 
       
  1181 function SDL_EnableKeyRepeat(timedelay, interval: LongInt): LongInt;
       
  1182 begin
       
  1183     timedelay:= timedelay;  // avoid hint
       
  1184     interval:= interval;    // avoid hint
       
  1185     SDL_EnableKeyRepeat:= 0;
       
  1186 end;
       
  1187 {$ELSE}
       
  1188 const conversionFormat: TSDL_PixelFormat = (
       
  1189         palette: nil; BitsPerPixel: 32; BytesPerPixel: 4;
       
  1190         Rloss: 0; Gloss: 0; Bloss: 0; Aloss: 0;
       
  1191         Rshift: RShift; Gshift: GShift; Bshift: BShift; Ashift: AShift;
       
  1192         RMask: RMask; GMask: GMask; BMask: BMask; AMask: AMask;
       
  1193         colorkey: 0; alpha: 255);
       
  1194 
       
  1195 function SDL_AllocFormat(format: LongWord): PSDL_PixelFormat;
       
  1196 begin
       
  1197     format:= format;
       
  1198     SDL_AllocFormat:= @conversionFormat;
       
  1199 end;
       
  1200 
       
  1201 procedure SDL_FreeFormat(pixelformat: PSDL_PixelFormat);
       
  1202 begin
       
  1203     pixelformat:= pixelformat;  // avoid hint
       
  1204 end;
       
  1205 {$ENDIF}
  1164 {$ENDIF}
  1206 
  1165 
  1207 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
  1166 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
  1208 begin
  1167 begin
  1209     SDL_MustLock:=
  1168     SDL_MustLock:=
  1210 {$IFDEF SDL13}
  1169 {$IFDEF SDL2}
  1211         ((surface^.flags and SDL_RLEACCEL) <> 0)
  1170         ((surface^.flags and SDL_RLEACCEL) <> 0)
  1212 {$ELSE}
  1171 {$ELSE}
  1213         ( surface^.offset <> 0 ) or (( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0)
  1172         ( surface^.offset <> 0 ) or (( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0)
  1214 {$ENDIF}
  1173 {$ENDIF}
  1215 end;
  1174 end;
  1216 
  1175 
  1217 {$IFNDEF SDL_MIXER_NEWER}
  1176 {$IFNDEF SDL_MIXER_NEWER}
  1218 function  Mix_Init(flags: LongInt): LongInt;
  1177 function  Mix_Init(flags: LongInt): LongInt; inline;
  1219 begin
  1178 begin
  1220     Mix_Init:= flags;
  1179     Mix_Init:= flags;
  1221 end;
  1180 end;
  1222 
  1181 
  1223 procedure Mix_Quit;
  1182 procedure Mix_Quit; inline;
  1224 begin
  1183 begin
  1225 end;
  1184 end;
  1226 {$ENDIF}
  1185 {$ENDIF}
  1227 
  1186 
  1228 {$IFNDEF SDL_IMAGE_NEWER}
  1187 {$IFNDEF SDL_IMAGE_NEWER}
  1229 function  IMG_Init(flags: LongInt): LongInt;
  1188 function  IMG_Init(flags: LongInt): LongInt; inline;
  1230 begin
  1189 begin
  1231     IMG_Init:= flags;
  1190     IMG_Init:= flags;
  1232 end;
  1191 end;
  1233 
  1192 
  1234 procedure IMG_Quit;
  1193 procedure IMG_Quit; inline;
  1235 begin
  1194 begin
  1236 end;
  1195 end;
  1237 {$ENDIF}
  1196 {$ENDIF}
  1238 
  1197 
  1239 procedure SDLNet_Write16(value: Word; buf: Pointer);
  1198 procedure SDLNet_Write16(value: Word; buf: Pointer);