hedgewars/SDLh.pas
changeset 2663 d53918cd22bb
parent 2633 9eb131794a6e
child 2664 949c189ba568
equal deleted inserted replaced
2662:12dc696f1c81 2663:d53918cd22bb
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 unit SDLh;
    21 unit SDLh;
    22 interface
    22 interface
    23 
    23 
    24 
       
    25 {$IFDEF LINUX}
    24 {$IFDEF LINUX}
    26   {$DEFINE UNIX}
    25   {$DEFINE UNIX}
    27 {$ENDIF}
    26 {$ENDIF}
    28 {$IFDEF FREEBSD}
    27 {$IFDEF FREEBSD}
    29   {$DEFINE UNIX}
    28   {$DEFINE UNIX}
    50     {$linkframework SDL_net}
    49     {$linkframework SDL_net}
    51     {$linkframework SDL_image}
    50     {$linkframework SDL_image}
    52     {$linkframework SDL_ttf}
    51     {$linkframework SDL_ttf}
    53     {$linkframework SDL_mixer}
    52     {$linkframework SDL_mixer}
    54     {$linklib SDLmain}
    53     {$linklib SDLmain}
    55     {$linklib gcc}
       
    56   {$ENDIF}
    54   {$ENDIF}
    57 {$ENDIF}
    55 {$ENDIF}
    58 
    56 
    59 
    57 
    60 (*  SDL  *)
    58 (*  SDL  *)
    64 	SDL_TTFLibName = 'SDL_ttf.dll';
    62 	SDL_TTFLibName = 'SDL_ttf.dll';
    65 	SDL_MixerLibName = 'SDL_mixer.dll';
    63 	SDL_MixerLibName = 'SDL_mixer.dll';
    66 	SDL_ImageLibName = 'SDL_image.dll';
    64 	SDL_ImageLibName = 'SDL_image.dll';
    67 	SDL_NetLibName = 'SDL_net.dll';
    65 	SDL_NetLibName = 'SDL_net.dll';
    68 {$ELSE}
    66 {$ELSE}
    69 	{$IFDEF DARWIN}
    67   {$IFDEF DARWIN}
    70 		SDLLibName = 'SDL';
    68 	SDLLibName = 'SDL';
    71 		SDL_TTFLibName = 'SDL_ttf';
    69 	SDL_TTFLibName = 'SDL_ttf';
    72 		SDL_MixerLibName = 'SDL_mixer';
    70 	SDL_MixerLibName = 'SDL_mixer';
    73 		SDL_ImageLibName = 'SDL_image';
    71 	SDL_ImageLibName = 'SDL_image';
    74 		SDL_NetLibName = 'SDL_net';
    72 	SDL_NetLibName = 'SDL_net';
    75         {$ELSE}
    73   {$ELSE}
    76 		SDLLibName = 'libSDL.so';
    74 	SDLLibName = 'libSDL.so';
    77 		SDL_TTFLibName = 'libSDL_ttf.so';
    75 	SDL_TTFLibName = 'libSDL_ttf.so';
    78 		SDL_MixerLibName = 'libSDL_mixer.so';
    76 	SDL_MixerLibName = 'libSDL_mixer.so';
    79 		SDL_ImageLibName = 'libSDL_image.so';
    77 	SDL_ImageLibName = 'libSDL_image.so';
    80 		SDL_NetLibName = 'libSDL_net.so';
    78 	SDL_NetLibName = 'libSDL_net.so';
    81         {$ENDIF}
    79   {$ENDIF}
    82 {$ENDIF}
    80 {$ENDIF}
    83 
    81 
    84 /////////////////////////////////////////////////////////////////
    82 /////////////////////////////////////////////////////////////////
    85 /////////////////////  CONSTANT DEFINITIONS /////////////////////
    83 /////////////////////  CONSTANT DEFINITIONS /////////////////////
    86 /////////////////////////////////////////////////////////////////
    84 /////////////////////////////////////////////////////////////////
   104 
   102 
   105 	SDL_APPINPUTFOCUS    = 2;
   103 	SDL_APPINPUTFOCUS    = 2;
   106 	SDL_BUTTON_WHEELDUP  = 4;
   104 	SDL_BUTTON_WHEELDUP  = 4;
   107 	SDL_BUTTON_WHEELDOWN = 5;
   105 	SDL_BUTTON_WHEELDOWN = 5;
   108 		
   106 		
   109 {*begin sdl_event binding*}
   107 {*begin SDL_Event binding*}
   110 	SDL_NOEVENT = 0;
   108 	SDL_NOEVENT = 0;
   111 	SDL_KEYDOWN = 2;
   109 	SDL_KEYDOWN = 2;
   112 	SDL_KEYUP = 3;
   110 	SDL_KEYUP = 3;
   113 {$IFDEF SDL13}
   111 {$IFDEF SDL13}
   114         SDL_WINDOWEVENT = 1;
   112         SDL_WINDOWEVENT = 1;
   135 	SDL_JOYBUTTONDOWN = 10;
   133 	SDL_JOYBUTTONDOWN = 10;
   136 	SDL_JOYBUTTONUP = 11;
   134 	SDL_JOYBUTTONUP = 11;
   137 	SDL_QUITEV = 12;
   135 	SDL_QUITEV = 12;
   138 	SDL_VIDEORESIZE = 16; // TODO: outdated? no longer in SDL 1.3?
   136 	SDL_VIDEORESIZE = 16; // TODO: outdated? no longer in SDL 1.3?
   139 {$ENDIF}
   137 {$ENDIF}
   140 {*end sdl_event binding*}
   138 {*end SDL_Event binding*}
   141 		
   139 		
   142 {$IFDEF SDL13}
   140 {$IFDEF SDL13}
   143 	SDL_ASYNCBLIT   = $08000000;
   141 	SDL_ASYNCBLIT   = $08000000;
   144 	SDL_ANYFORMAT   = $10000000;
   142 	SDL_ANYFORMAT   = $10000000;
   145 	SDL_HWPALETTE   = $00200000;
   143 	SDL_HWPALETTE   = $00200000;
   311 		modifier: Longword;
   309 		modifier: Longword;
   312 		unicode: Word;
   310 		unicode: Word;
   313 		end;
   311 		end;
   314 
   312 
   315 
   313 
   316 {* SDL_event type definition *}
   314 {* SDL_Event type definition *}
   317 
   315 
   318 {$IFDEF SDL13}
   316 {$IFDEF SDL13}
   319 	TSDL_WindowID = LongInt;
   317 	TSDL_WindowID = LongInt;
   320 
   318 
   321 	TSDL_WindowEvent = record
   319 	TSDL_WindowEvent = record
   322 {$ELSE}
       
   323 	TSDL_ActiveEvent = record
       
   324 {$ENDIF}
       
   325 		type_: byte;
   320 		type_: byte;
   326 		gain: byte;
   321 		gain: byte;
   327 		state: byte;
   322 		state: byte;
   328 {$IFDEF SDL13}
       
   329 		windowID: TSDL_WindowID;
   323 		windowID: TSDL_WindowID;
   330 		data1, data2: LongInt;
   324 		data1, data2: LongInt;
   331 {$ENDIF}
   325 		end;
   332 		end;
   326 
   333 
   327 // implement SDL_TextEditingEvent + SDL_TextInputEvent for sdl13
   334 //SDL_TextEditingEvent + SDL_TextInputEvent for sdl13
   328 {$ELSE}
       
   329 	TSDL_ActiveEvent = record
       
   330 		type_: byte;
       
   331 		gain: byte;
       
   332 		state: byte;
       
   333 		end;
       
   334 {$ENDIF}
   335 
   335 
   336 	TSDL_MouseMotionEvent = record
   336 	TSDL_MouseMotionEvent = record
   337                              type_: byte;
   337 		type_: byte;
   338                              which: byte;
   338 		which: byte;
   339                              state: byte;
   339 		state: byte;
   340 {$IFDEF SDL13}
   340 {$IFDEF SDL13}
   341                              x, y, xrel, yrel : LongInt;
   341 		x, y, xrel, yrel : LongInt;
   342 			     pressure, pressure_max, pressure_min,
   342 		pressure, pressure_max, pressure_min,
   343 			     rotation, tilt, cursor: LongInt; 
   343 		rotation, tilt, cursor: LongInt; 
   344 {$ELSE}
   344 {$ELSE}
   345                              x, y, xrel, yrel : word;
   345 		x, y, xrel, yrel : word;
   346 {$ENDIF}
   346 {$ENDIF}
   347                              end;
   347 		end;
   348 
   348 
   349 	TSDL_KeyboardEvent = record
   349 	TSDL_KeyboardEvent = record
   350 		type_: Byte;
   350 		type_: Byte;
   351 {$IFDEF SDL13}
   351 {$IFDEF SDL13}
   352 		windowID: TSDL_WindowID;
   352 		windowID: TSDL_WindowID;
   568 
   568 
   569 /////////////////////////////////////////////////////////////////
   569 /////////////////////////////////////////////////////////////////
   570 /////////////////////  FUNCTION DEFINITIONS /////////////////////
   570 /////////////////////  FUNCTION DEFINITIONS /////////////////////
   571 /////////////////////////////////////////////////////////////////
   571 /////////////////////////////////////////////////////////////////
   572 
   572 
   573 {$IFDEF FPC}
       
   574 
   573 
   575 {* SDL *}
   574 {* SDL *}
   576 function  SDL_Init(flags: Longword): LongInt; cdecl; external SDLLibName;
   575 function  SDL_Init(flags: Longword): LongInt; cdecl; external SDLLibName;
   577 procedure SDL_Quit; cdecl; external SDLLibName;
   576 procedure SDL_Quit; cdecl; external SDLLibName;
   578 function  SDL_VideoDriverName(var namebuf; maxlen: LongInt): PChar; cdecl; external SDLLibName;
   577 function  SDL_VideoDriverName(var namebuf; maxlen: LongInt): PChar; cdecl; external SDLLibName;
   638 function  SDL_UnlockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName name 'SDL_mutexV';
   637 function  SDL_UnlockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName name 'SDL_mutexV';
   639 
   638 
   640 function  SDL_GL_SetAttribute(attr: TSDL_GLattr; value: LongInt): LongInt; cdecl; external SDLLibName;
   639 function  SDL_GL_SetAttribute(attr: TSDL_GLattr; value: LongInt): LongInt; cdecl; external SDLLibName;
   641 procedure SDL_GL_SwapBuffers(); cdecl; external SDLLibName;
   640 procedure SDL_GL_SwapBuffers(); cdecl; external SDLLibName;
   642 
   641 
   643 {$IFDEF SDL13}
       
   644 {$IFDEF IPHONEOS}
   642 {$IFDEF IPHONEOS}
   645 function  SDL_iPhoneKeyboardShow(windowID: LongInt): LongInt; cdecl; external SDLLibName;
   643 function  SDL_iPhoneKeyboardShow(windowID: LongInt): LongInt; cdecl; external SDLLibName;
   646 function  SDL_iPhoneKeyboardHide(windowID: LongInt): LongInt; cdecl; external SDLLibName;
   644 function  SDL_iPhoneKeyboardHide(windowID: LongInt): LongInt; cdecl; external SDLLibName;
   647 function  SDL_iPhoneKeyboardIsShown(windowID: LongInt): boolean; cdecl; external SDLLibName;
   645 function  SDL_iPhoneKeyboardIsShown(windowID: LongInt): boolean; cdecl; external SDLLibName;
   648 function  SDL_iPhoneKeyboardToggle(windowID: LongInt): LongInt; cdecl; external SDLLibName;
   646 function  SDL_iPhoneKeyboardToggle(windowID: LongInt): LongInt; cdecl; external SDLLibName;
   649 {$ENDIF}
       
   650 {$ENDIF}
   647 {$ENDIF}
   651 
   648 
   652 function  SDL_NumJoysticks: LongInt; cdecl; external SDLLibName;
   649 function  SDL_NumJoysticks: LongInt; cdecl; external SDLLibName;
   653 function  SDL_JoystickName(idx: LongInt): PChar; cdecl; external SDLLibName;
   650 function  SDL_JoystickName(idx: LongInt): PChar; cdecl; external SDLLibName;
   654 function  SDL_JoystickOpen(idx: LongInt): PSDL_Joystick; cdecl; external SDLLibName;
   651 function  SDL_JoystickOpen(idx: LongInt): PSDL_Joystick; cdecl; external SDLLibName;
   722 procedure SDLNet_TCP_Close(sock: PTCPsocket); cdecl; external SDL_NetLibName;
   719 procedure SDLNet_TCP_Close(sock: PTCPsocket); cdecl; external SDL_NetLibName;
   723 procedure SDLNet_FreeSocketSet(_set: PSDLNet_SocketSet); cdecl; external SDL_NetLibName;
   720 procedure SDLNet_FreeSocketSet(_set: PSDLNet_SocketSet); cdecl; external SDL_NetLibName;
   724 function  SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): LongInt; cdecl; external SDL_NetLibName;
   721 function  SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): LongInt; cdecl; external SDL_NetLibName;
   725 function  SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: LongInt): LongInt; cdecl; external SDL_NetLibName;
   722 function  SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: LongInt): LongInt; cdecl; external SDL_NetLibName;
   726 
   723 
   727 {$IFDEF IPHONEOS}
       
   728 function  get_documents_path: PChar; cdecl; external 'hwutils';
       
   729 {$ENDIF}
       
   730 
       
   731 {$ELSE}{$ENDIF}
       
   732 
   724 
   733 procedure SDLNet_Write16(value: Word; buf: pointer);
   725 procedure SDLNet_Write16(value: Word; buf: pointer);
   734 procedure SDLNet_Write32(value: LongWord; buf: pointer);
   726 procedure SDLNet_Write32(value: LongWord; buf: pointer);
   735 function  SDLNet_Read16(buf: pointer): Word;
   727 function  SDLNet_Read16(buf: pointer): Word;
   736 function  SDLNet_Read32(buf: pointer): LongWord;
   728 function  SDLNet_Read32(buf: pointer): LongWord;
   737 
   729 
   738 implementation
   730 implementation
   739 
   731 
   740 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
   732 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
   741 begin
   733 begin
   742   SDL_MustLock:= ( surface^.offset <> 0 ) or (( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0)
   734 	SDL_MustLock:= ( surface^.offset <> 0 ) or (( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0)
   743 end;
   735 end;
   744 
   736 
   745 procedure SDLNet_Write16(value: Word; buf: pointer);
   737 procedure SDLNet_Write16(value: Word; buf: pointer);
   746 begin
   738 begin
   747   PByteArray(buf)^[1]:= value;
   739 	PByteArray(buf)^[1]:= value;
   748   PByteArray(buf)^[0]:= value shr 8
   740 	PByteArray(buf)^[0]:= value shr 8
   749 end;
   741 end;
   750 
   742 
   751 procedure SDLNet_Write32(value: LongWord; buf: pointer);
   743 procedure SDLNet_Write32(value: LongWord; buf: pointer);
   752 begin
   744 begin
   753   PByteArray(buf)^[3]:= value;
   745 	PByteArray(buf)^[3]:= value;
   754   PByteArray(buf)^[2]:= value shr  8;
   746 	PByteArray(buf)^[2]:= value shr  8;
   755   PByteArray(buf)^[1]:= value shr 16;
   747 	PByteArray(buf)^[1]:= value shr 16;
   756   PByteArray(buf)^[0]:= value shr 24
   748 	PByteArray(buf)^[0]:= value shr 24
   757 end;
   749 end;
   758 
   750 
   759 function SDLNet_Read16(buf: pointer): Word;
   751 function SDLNet_Read16(buf: pointer): Word;
   760 begin
   752 begin
   761   SDLNet_Read16:= PByteArray(buf)^[1] or
   753 	SDLNet_Read16:= PByteArray(buf)^[1] or
   762                  (PByteArray(buf)^[0] shl 8)
   754                  (PByteArray(buf)^[0] shl 8)
   763 end;
   755 end;
   764 
   756 
   765 function SDLNet_Read32(buf: pointer): LongWord;
   757 function SDLNet_Read32(buf: pointer): LongWord;
   766 begin
   758 begin
   767   SDLNet_Read32:=  PByteArray(buf)^[3] or
   759 	SDLNet_Read32:=  PByteArray(buf)^[3] or
   768                   (PByteArray(buf)^[2] shl  8) or
   760                   (PByteArray(buf)^[2] shl  8) or
   769                   (PByteArray(buf)^[1] shl 16) or
   761                   (PByteArray(buf)^[1] shl 16) or
   770                   (PByteArray(buf)^[0] shl 24)
   762                   (PByteArray(buf)^[0] shl 24)
   771 end;
   763 end;
   772 
   764