hedgewars/SDLh.pas
branchui-scaling
changeset 15288 c4fd2813b127
parent 14836 64f88108926b
child 15319 fe705efbfc52
equal deleted inserted replaced
13395:0135e64c6c66 15288:c4fd2813b127
    57 {$ENDIF}
    57 {$ENDIF}
    58 
    58 
    59 
    59 
    60 (*  SDL  *)
    60 (*  SDL  *)
    61 const
    61 const
    62 {$IFDEF WIN32}
    62 {$IFDEF WINDOWS}
    63     SDLLibName = 'SDL2.dll';
    63     SDLLibName = 'SDL2.dll';
    64     SDL_TTFLibName = 'SDL2_ttf.dll';
    64     SDL_TTFLibName = 'SDL2_ttf.dll';
    65     SDL_MixerLibName = 'SDL2_mixer.dll';
    65     SDL_MixerLibName = 'SDL2_mixer.dll';
    66     SDL_ImageLibName = 'SDL2_image.dll';
    66     SDL_ImageLibName = 'SDL2_image.dll';
    67     SDL_NetLibName = 'SDL2_net.dll';
    67     SDL_NetLibName = 'SDL2_net.dll';
   107     SDL_BUTTON_MIDDLE    = 2;
   107     SDL_BUTTON_MIDDLE    = 2;
   108     SDL_BUTTON_RIGHT     = 3;
   108     SDL_BUTTON_RIGHT     = 3;
   109     SDL_BUTTON_X1        = 4;
   109     SDL_BUTTON_X1        = 4;
   110     SDL_BUTTON_X2        = 5;
   110     SDL_BUTTON_X2        = 5;
   111 
   111 
       
   112     // SDL_ShowCursor consts
       
   113     SDL_QUERY = -1;
       
   114     SDL_DISABLE = 0;
       
   115     SDL_ENABLE = 1;
   112 
   116 
   113     SDL_TEXTEDITINGEVENT_TEXT_SIZE = 32;
   117     SDL_TEXTEDITINGEVENT_TEXT_SIZE = 32;
   114     SDL_TEXTINPUTEVENT_TEXT_SIZE   = 32;
   118     SDL_TEXTINPUTEVENT_TEXT_SIZE   = 32;
   115 
   119 
   116     // SDL_Event types
   120     // SDL_Event types
   245     MIX_INIT_MOD        = $00000002;
   249     MIX_INIT_MOD        = $00000002;
   246     MIX_INIT_MODPLUG    = $00000004;
   250     MIX_INIT_MODPLUG    = $00000004;
   247     MIX_INIT_MP3        = $00000008;
   251     MIX_INIT_MP3        = $00000008;
   248     MIX_INIT_OGG        = $00000010;
   252     MIX_INIT_OGG        = $00000010;
   249     MIX_INIT_FLUIDSYNTH = $00000020;
   253     MIX_INIT_FLUIDSYNTH = $00000020;
       
   254     MIX_INIT_OPUS       = $00000040;
   250 
   255 
   251     {* SDL_TTF *}
   256     {* SDL_TTF *}
   252     TTF_STYLE_NORMAL = 0;
   257     TTF_STYLE_NORMAL = 0;
   253     TTF_STYLE_BOLD   = 1;
   258     TTF_STYLE_BOLD   = 1;
   254     TTF_STYLE_ITALIC = 2;
   259     TTF_STYLE_ITALIC = 2;
   539 /////////////////////////////////////////////////////////////////
   544 /////////////////////////////////////////////////////////////////
   540 ///////////////////////  TYPE DEFINITIONS ///////////////////////
   545 ///////////////////////  TYPE DEFINITIONS ///////////////////////
   541 /////////////////////////////////////////////////////////////////
   546 /////////////////////////////////////////////////////////////////
   542 
   547 
   543 // two important reference points for the wanderers of this area
   548 // two important reference points for the wanderers of this area
   544 // http://www.freepascal.org/docs-html/ref/refsu5.html
   549 // https://www.freepascal.org/docs-html/ref/refsu5.html
   545 // http://www.freepascal.org/docs-html/prog/progsu144.html
   550 // https://www.freepascal.org/docs-html/prog/progsu144.html
   546 
   551 
   547 type
   552 type
   548     PSDL_Window   = Pointer;
   553     PSDL_Window   = Pointer;
   549     PSDL_Renderer = Pointer;
   554     PSDL_Renderer = Pointer;
   550     PSDL_Texture  = Pointer;
   555     PSDL_Texture  = Pointer;
   551     PSDL_GLContext= Pointer;
   556     PSDL_GLContext= Pointer;
   552     TSDL_TouchId  = Int64;
   557     TSDL_TouchId  = Int64;
   553     TSDL_FingerId = Int64;
   558     TSDL_FingerId = Int64;
   554     TSDL_Keycode = LongInt;
   559     TSDL_Keycode = LongInt;
   555     TSDL_Scancode = LongInt;
   560     TSDL_Scancode = LongInt;
       
   561     TSDL_JoystickID = LongInt;
       
   562     TSDL_bool = LongInt;
   556 
   563 
   557     TSDL_eventaction = (SDL_ADDEVENT, SDL_PEEPEVENT, SDL_GETEVENT);
   564     TSDL_eventaction = (SDL_ADDEVENT, SDL_PEEPEVENT, SDL_GETEVENT);
   558 
   565 
   559     PSDL_Rect = ^TSDL_Rect;
   566     PSDL_Rect = ^TSDL_Rect;
   560     TSDL_Rect = record
   567     TSDL_Rect = record
   654         readMethod, assetFileDescriptor: Pointer;
   661         readMethod, assetFileDescriptor: Pointer;
   655         position, size, offset: Int64;
   662         position, size, offset: Int64;
   656         fd: LongInt;
   663         fd: LongInt;
   657         end;
   664         end;
   658 {$ELSE}
   665 {$ELSE}
   659 {$IFDEF WIN32}
   666 {$IFDEF WINDOWS}
   660     TWinbuffer = record
   667     TWinbuffer = record
   661         data: Pointer;
   668         data: Pointer;
   662         size, left: LongInt;
   669         size, left: LongInt;
   663         end;
   670         end;
   664     TWindowsio = record
   671     TWindowsio = record
   678         type_: LongWord;
   685         type_: LongWord;
   679         case Byte of
   686         case Byte of
   680 {$IFDEF ANDROID}
   687 {$IFDEF ANDROID}
   681             0: (androidio: TAndroidio);
   688             0: (androidio: TAndroidio);
   682 {$ELSE}
   689 {$ELSE}
   683 {$IFDEF WIN32}
   690 {$IFDEF WINDOWS}
   684             0: (windowsio: TWindowsio);
   691             0: (windowsio: TWindowsio);
   685 {$ENDIF}
   692 {$ENDIF}
   686 {$ENDIF}
   693 {$ENDIF}
   687             1: (stdio: TStdio);     // assumes HAVE_STDIO_H
   694             1: (stdio: TStdio);     // assumes HAVE_STDIO_H
   688             2: (mem: TMem);
   695             2: (mem: TMem);
   763         end;
   770         end;
   764 
   771 
   765     TSDL_ControllerAxisEvent = record
   772     TSDL_ControllerAxisEvent = record
   766         type_: LongWord;
   773         type_: LongWord;
   767         timestamp: LongWord;
   774         timestamp: LongWord;
   768         which: LongInt;
   775         which: TSDL_JoystickID;
   769         axis, padding1, padding2, padding3: Byte;
   776         axis, padding1, padding2, padding3: Byte;
   770         value: SmallInt;
   777         value: SmallInt;
   771         padding4: Word;
   778         padding4: Word;
   772         end;
   779         end;
   773 
   780 
   774     TSDL_ControllerButtonEvent = record
   781     TSDL_ControllerButtonEvent = record
   775         type_: LongWord;
   782         type_: LongWord;
   776         timestamp: LongWord;
   783         timestamp: LongWord;
       
   784         which: TSDL_JoystickID;
       
   785         button, states, padding1, padding2: Byte;
       
   786         end;
       
   787 
       
   788     TSDL_ControllerDeviceEvent = record
       
   789         type_: LongWord;
       
   790         timestamp: LongWord;
   777         which: LongInt;
   791         which: LongInt;
   778         button, states, padding1, padding2: Byte;
       
   779         end;
       
   780 
       
   781     TSDL_ControllerDeviceEvent = record
       
   782         type_: LongWord;
       
   783         timestamp: LongWord;
       
   784         which: SmallInt;
       
   785         end;
   792         end;
   786 
   793 
   787     TSDL_JoyDeviceEvent = TSDL_ControllerDeviceEvent;
   794     TSDL_JoyDeviceEvent = TSDL_ControllerDeviceEvent;
   788 
   795 
   789     TSDL_CommonEvent = record
   796     TSDL_CommonEvent = record
   827         end;
   834         end;
   828 
   835 
   829     TSDL_JoyAxisEvent = record
   836     TSDL_JoyAxisEvent = record
   830         type_: LongWord;
   837         type_: LongWord;
   831         timestamp: LongWord;
   838         timestamp: LongWord;
   832         which: LongWord;
   839         which: TSDL_JoystickID;
   833         axis: Byte;
   840         axis: Byte;
   834         padding1, padding2, padding3: Byte;
   841         padding1, padding2, padding3: Byte;
   835         value: LongInt;
   842         value: SmallInt;
   836         padding4: Word;
   843         padding4: Word;
   837         end;
   844         end;
   838 
   845 
   839     TSDL_JoyBallEvent = record
   846     TSDL_JoyBallEvent = record
   840         type_: LongWord;
   847         type_: LongWord;
   841         timestamp: LongWord;
   848         timestamp: LongWord;
   842         which: LongWord;
   849         which: TSDL_JoystickID;
   843         ball: Byte;
   850         ball: Byte;
   844         padding1, padding2, padding3: Byte;
   851         padding1, padding2, padding3: Byte;
   845         xrel, yrel: SmallInt;
   852         xrel, yrel: SmallInt;
   846         end;
   853         end;
   847 
   854 
   848     TSDL_JoyHatEvent = record
   855     TSDL_JoyHatEvent = record
   849         type_: LongWord;
   856         type_: LongWord;
   850         timestamp: LongWord;
   857         timestamp: LongWord;
   851         which: LongWord;
   858         which: TSDL_JoystickID;
   852         hat: Byte;
   859         hat: Byte;
   853         value: Byte;
   860         value: Byte;
   854         padding1, padding2: Byte;
   861         padding1, padding2: Byte;
   855         end;
   862         end;
   856 
   863 
   857     TSDL_JoyButtonEvent = record
   864     TSDL_JoyButtonEvent = record
   858         type_: LongWord;
   865         type_: LongWord;
   859         timestamp: LongWord;
   866         timestamp: LongWord;
   860         which: Byte;
   867         which: TSDL_JoystickID;
   861         button: Byte;
   868         button: Byte;
   862         state: Byte;
   869         state: Byte;
   863         padding1: Byte;
   870         padding1: Byte;
       
   871         padding2: Byte;
   864         end;
   872         end;
   865 
   873 
   866     TSDL_QuitEvent = record
   874     TSDL_QuitEvent = record
   867         type_: LongWord;
   875         type_: LongWord;
   868         timestamp: LongWord;
   876         timestamp: LongWord;
  1019                         numsockets,
  1027                         numsockets,
  1020                         maxsockets: LongInt;
  1028                         maxsockets: LongInt;
  1021                         sockets: PTCPSocket;
  1029                         sockets: PTCPSocket;
  1022                         end;
  1030                         end;
  1023 
  1031 
  1024 {$IFDEF WIN32}
  1032 {$IFDEF WINDOWS}
  1025      TThreadFunction = function (p: pointer): Longword; stdcall;
  1033      TThreadFunction = function (p: pointer): Longword; stdcall;
  1026      pfnSDL_CurrentBeginThread = function (
  1034      pfnSDL_CurrentBeginThread = function (
  1027         _Security: pointer; 
  1035         _Security: pointer; 
  1028         _StackSize: LongWord;
  1036         _StackSize: LongWord;
  1029         _StartAddress: TThreadFunction;
  1037         _StartAddress: TThreadFunction;
  1103 function  SDL_RenderClear(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName;
  1111 function  SDL_RenderClear(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName;
  1104 procedure SDL_RenderPresent(renderer: PSDL_Renderer); cdecl; external SDLLibName;
  1112 procedure SDL_RenderPresent(renderer: PSDL_Renderer); cdecl; external SDLLibName;
  1105 function  SDL_RenderReadPixels(renderer: PSDL_Renderer; rect: PSDL_Rect; format: LongInt; pixels: Pointer; pitch: LongInt): LongInt; cdecl; external SDLLibName;
  1113 function  SDL_RenderReadPixels(renderer: PSDL_Renderer; rect: PSDL_Rect; format: LongInt; pixels: Pointer; pitch: LongInt): LongInt; cdecl; external SDLLibName;
  1106 function  SDL_RenderSetViewport(window: PSDL_Window; rect: PSDL_Rect): LongInt; cdecl; external SDLLibName;
  1114 function  SDL_RenderSetViewport(window: PSDL_Window; rect: PSDL_Rect): LongInt; cdecl; external SDLLibName;
  1107 
  1115 
       
  1116 function  SDL_SetRelativeMouseMode(enabled: TSDL_bool): LongInt; cdecl; external SDLLibName;
  1108 function  SDL_GetRelativeMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
  1117 function  SDL_GetRelativeMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
  1109 function  SDL_PixelFormatEnumToMasks(format: TSDL_ArrayByteOrder; bpp: PLongInt; Rmask, Gmask, Bmask, Amask: PLongInt): Boolean; cdecl; external SDLLibName;
  1118 function  SDL_PixelFormatEnumToMasks(format: TSDL_ArrayByteOrder; bpp: PLongInt; Rmask, Gmask, Bmask, Amask: PLongInt): Boolean; cdecl; external SDLLibName;
  1110 
  1119 
  1111 procedure SDL_WarpMouseInWindow(window: PSDL_Window; x, y: LongInt); cdecl; external SDLLibName;
  1120 procedure SDL_WarpMouseInWindow(window: PSDL_Window; x, y: LongInt); cdecl; external SDLLibName;
  1112 function  SDL_SetHint(name, value: PChar): Boolean; cdecl; external SDLLibName;
  1121 function  SDL_SetHint(name, value: PChar): Boolean; cdecl; external SDLLibName;
  1141 function  SDL_WM_ToggleFullScreen(surface: PSDL_Surface): LongInt; cdecl; external SDLLibName;
  1150 function  SDL_WM_ToggleFullScreen(surface: PSDL_Surface): LongInt; cdecl; external SDLLibName;
  1142 
  1151 
  1143 
  1152 
  1144 (* remember to mark the threaded functions as 'cdecl; export;'
  1153 (* remember to mark the threaded functions as 'cdecl; export;'
  1145    (or have fun debugging nil arguments) *)
  1154    (or have fun debugging nil arguments) *)
  1146 {$IFDEF WIN32}
  1155 {$IFDEF WINDOWS}
  1147 // SDL uses wrapper in windows
  1156 // SDL uses wrapper in windows
  1148 function  SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer; bt: pfnSDL_CurrentBeginThread; et: pfnSDL_CurrentEndThread): PSDL_Thread; cdecl; external SDLLibName;
  1157 function  SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer; bt: pfnSDL_CurrentBeginThread; et: pfnSDL_CurrentEndThread): PSDL_Thread; cdecl; external SDLLibName;
  1149 function  SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer): PSDL_Thread; cdecl; overload;
  1158 function  SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer): PSDL_Thread; cdecl; overload;
  1150 {$ELSE}
  1159 {$ELSE}
  1151 function  SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer): PSDL_Thread; cdecl; external SDLLibName;
  1160 function  SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer): PSDL_Thread; cdecl; external SDLLibName;
  1163 
  1172 
  1164 procedure SDL_LockAudio; cdecl; external SDLLibName;
  1173 procedure SDL_LockAudio; cdecl; external SDLLibName;
  1165 procedure SDL_UnlockAudio; cdecl; external SDLLibName;
  1174 procedure SDL_UnlockAudio; cdecl; external SDLLibName;
  1166 
  1175 
  1167 function  SDL_NumJoysticks: LongInt; cdecl; external SDLLibName;
  1176 function  SDL_NumJoysticks: LongInt; cdecl; external SDLLibName;
  1168 function  SDL_JoystickName(idx: LongInt): PChar; cdecl; external SDLLibName;
  1177 function  SDL_JoystickNameForIndex(idx: LongInt): PChar; cdecl; external SDLLibName;
  1169 function  SDL_JoystickOpen(idx: LongInt): PSDL_Joystick; cdecl; external SDLLibName;
  1178 function  SDL_JoystickOpen(idx: LongInt): PSDL_Joystick; cdecl; external SDLLibName;
  1170 function  SDL_JoystickOpened(idx: LongInt): LongInt; cdecl; external SDLLibName;
  1179 function  SDL_JoystickOpened(idx: LongInt): LongInt; cdecl; external SDLLibName;
  1171 function  SDL_JoystickIndex(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName;
  1180 function  SDL_JoystickIndex(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName;
  1172 function  SDL_JoystickNumAxes(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName;
  1181 function  SDL_JoystickNumAxes(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName;
  1173 function  SDL_JoystickNumBalls(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName;
  1182 function  SDL_JoystickNumBalls(joy: PSDL_Joystick): LongInt; cdecl; external SDLLibName;
  1179 function  SDL_JoystickGetBall(joy: PSDL_Joystick; ball: LongInt; dx: PInteger; dy: PInteger): Word; cdecl; external SDLLibName;
  1188 function  SDL_JoystickGetBall(joy: PSDL_Joystick; ball: LongInt; dx: PInteger; dy: PInteger): Word; cdecl; external SDLLibName;
  1180 function  SDL_JoystickGetHat(joy: PSDL_Joystick; hat: LongInt): Byte; cdecl; external SDLLibName;
  1189 function  SDL_JoystickGetHat(joy: PSDL_Joystick; hat: LongInt): Byte; cdecl; external SDLLibName;
  1181 function  SDL_JoystickGetButton(joy: PSDL_Joystick; button: LongInt): Byte; cdecl; external SDLLibName;
  1190 function  SDL_JoystickGetButton(joy: PSDL_Joystick; button: LongInt): Byte; cdecl; external SDLLibName;
  1182 procedure SDL_JoystickClose(joy: PSDL_Joystick); cdecl; external SDLLibName;
  1191 procedure SDL_JoystickClose(joy: PSDL_Joystick); cdecl; external SDLLibName;
  1183 
  1192 
  1184 {$IFDEF WIN32}
  1193 {$IFDEF WINDOWS}
  1185 function SDL_putenv(const text: PChar): LongInt; cdecl; external SDLLibName;
  1194 function SDL_putenv(const text: PChar): LongInt; cdecl; external SDLLibName;
  1186 function SDL_getenv(const text: PChar): PChar; cdecl; external SDLLibName;
  1195 function SDL_getenv(const text: PChar): PChar; cdecl; external SDLLibName;
  1187 {$ENDIF}
  1196 {$ENDIF}
  1188 
  1197 
  1189 
  1198 
  1317                   (PByteArray(buf)^[2] shl  8) or
  1326                   (PByteArray(buf)^[2] shl  8) or
  1318                   (PByteArray(buf)^[1] shl 16) or
  1327                   (PByteArray(buf)^[1] shl 16) or
  1319                   (PByteArray(buf)^[0] shl 24)
  1328                   (PByteArray(buf)^[0] shl 24)
  1320 end;
  1329 end;
  1321 
  1330 
  1322 {$IFDEF WIN32}
  1331 {$IFDEF WINDOWS}
  1323 function  SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer): PSDL_Thread; cdecl;
  1332 function  SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer): PSDL_Thread; cdecl;
  1324 begin
  1333 begin
  1325     SDL_CreateThread:= SDL_CreateThread(fn, name, data, nil, nil)
  1334     SDL_CreateThread:= SDL_CreateThread(fn, name, data, nil, nil)
  1326 end;  
  1335 end;  
  1327 {$ENDIF}
  1336 {$ENDIF}