hedgewars/SDLh.pas
changeset 432 b0f693024b50
parent 377 d9b88dbdf5a9
child 433 9f8f22094c0e
equal deleted inserted replaced
431:79ac59673df3 432:b0f693024b50
    28 {$IFDEF UNIX}
    28 {$IFDEF UNIX}
    29 {$linklib c}
    29 {$linklib c}
    30 {$linklib pthread}
    30 {$linklib pthread}
    31 {$ENDIF}
    31 {$ENDIF}
    32 
    32 
    33 {$IFDEF FPC}
    33 {$PACKRECORDS C}
    34   {$MODE Delphi}
       
    35   { $PACKRECORDS 4}
       
    36 {$ENDIF}
       
    37 
    34 
    38 (*  SDL *)
    35 (*  SDL *)
    39 const {$IFDEF WIN32}
    36 const {$IFDEF WIN32}
    40       SDLLibName = 'SDL.dll';
    37       SDLLibName = 'SDL.dll';
    41       {$ENDIF}
    38       {$ENDIF}
   100 
    97 
   101      PSDL_Surface = ^TSDL_Surface;
    98      PSDL_Surface = ^TSDL_Surface;
   102      TSDL_Surface = record
    99      TSDL_Surface = record
   103                     flags : Longword;
   100                     flags : Longword;
   104                     format: PSDL_PixelFormat;
   101                     format: PSDL_PixelFormat;
   105                     w, h  : integer;
   102                     w, h  : LongInt;
   106                     pitch : Word;
   103                     pitch : Word;
   107                     pixels: Pointer;
   104                     pixels: Pointer;
   108                     offset: integer;
   105                     offset: LongInt;
   109                     end;
   106                     end;
   110 
   107 
   111      PSDL_Color = ^TSDL_Color;
   108      PSDL_Color = ^TSDL_Color;
   112      TSDL_Color = record
   109      TSDL_Color = record
   113                   case byte of
   110                   case byte of
   189      PByteArray = ^TByteArray;
   186      PByteArray = ^TByteArray;
   190      TByteArray = array[0..65535] of Byte;
   187      TByteArray = array[0..65535] of Byte;
   191      PLongWordArray = ^TLongWordArray;
   188      PLongWordArray = ^TLongWordArray;
   192      TLongWordArray = array[0..16383] of LongWord;
   189      TLongWordArray = array[0..16383] of LongWord;
   193 
   190 
   194 function  SDL_Init(flags: Longword): integer; cdecl; external SDLLibName;
   191 function  SDL_Init(flags: Longword): LongInt; cdecl; external SDLLibName;
   195 procedure SDL_Quit; cdecl; external SDLLibName;
   192 procedure SDL_Quit; cdecl; external SDLLibName;
   196 function  SDL_VideoDriverName(var namebuf; maxlen: integer): PChar; cdecl; external SDLLibName;
   193 function  SDL_VideoDriverName(var namebuf; maxlen: LongInt): PChar; cdecl; external SDLLibName;
   197 procedure SDL_EnableUNICODE(enable: integer); cdecl; external SDLLibName;
   194 procedure SDL_EnableUNICODE(enable: LongInt); cdecl; external SDLLibName;
   198 
   195 
   199 procedure SDL_Delay(msec: Longword); cdecl; external SDLLibName;
   196 procedure SDL_Delay(msec: Longword); cdecl; external SDLLibName;
   200 function  SDL_GetTicks: Longword; cdecl; external SDLLibName;
   197 function  SDL_GetTicks: Longword; cdecl; external SDLLibName;
   201 
   198 
   202 function  SDL_MustLock(Surface: PSDL_Surface): Boolean;
   199 function  SDL_MustLock(Surface: PSDL_Surface): Boolean;
   203 function  SDL_LockSurface(Surface: PSDL_Surface): integer; cdecl; external SDLLibName;
   200 function  SDL_LockSurface(Surface: PSDL_Surface): LongInt; cdecl; external SDLLibName;
   204 procedure SDL_UnlockSurface(Surface: PSDL_Surface); cdecl; external SDLLibName;
   201 procedure SDL_UnlockSurface(Surface: PSDL_Surface); cdecl; external SDLLibName;
   205 
   202 
   206 function  SDL_GetError: PChar; cdecl; external SDLLibName;
   203 function  SDL_GetError: PChar; cdecl; external SDLLibName;
   207 
   204 
   208 function  SDL_SetVideoMode(width, height, bpp: integer; flags: Longword): PSDL_Surface; cdecl; external SDLLibName;
   205 function  SDL_SetVideoMode(width, height, bpp: LongInt; flags: Longword): PSDL_Surface; cdecl; external SDLLibName;
   209 function  SDL_CreateRGBSurface(flags: Longword; Width, Height, Depth: integer; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName;
   206 function  SDL_CreateRGBSurface(flags: Longword; Width, Height, Depth: LongInt; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName;
   210 function  SDL_CreateRGBSurfaceFrom(pixels: Pointer; width, height, depth, pitch: integer; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName;
   207 function  SDL_CreateRGBSurfaceFrom(pixels: Pointer; width, height, depth, pitch: LongInt; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName;
   211 procedure SDL_FreeSurface(Surface: PSDL_Surface); cdecl; external SDLLibName;
   208 procedure SDL_FreeSurface(Surface: PSDL_Surface); cdecl; external SDLLibName;
   212 function  SDL_SetColorKey(surface: PSDL_Surface; flag, key: Longword): LongInt; cdecl; external SDLLibName;
   209 function  SDL_SetColorKey(surface: PSDL_Surface; flag, key: Longword): LongInt; cdecl; external SDLLibName;
   213 
   210 
   214 function  SDL_UpperBlit(src: PSDL_Surface; srcrect: PSDL_Rect; dst: PSDL_Surface; dstrect: PSDL_Rect): LongInt; cdecl; external SDLLibName;
   211 function  SDL_UpperBlit(src: PSDL_Surface; srcrect: PSDL_Rect; dst: PSDL_Surface; dstrect: PSDL_Rect): LongInt; cdecl; external SDLLibName;
   215 function  SDL_FillRect(dst: PSDL_Surface; dstrect: PSDL_Rect; color: Longword): LongInt; cdecl; external SDLLibName;
   212 function  SDL_FillRect(dst: PSDL_Surface; dstrect: PSDL_Rect; color: Longword): LongInt; cdecl; external SDLLibName;
   216 procedure SDL_UpdateRect(Screen: PSDL_Surface; x, y: LongInt; w, h: Longword); cdecl; external SDLLibName;
   213 procedure SDL_UpdateRect(Screen: PSDL_Surface; x, y: LongInt; w, h: Longword); cdecl; external SDLLibName;
   217 function  SDL_Flip(Screen: PSDL_Surface): integer; cdecl; external SDLLibName;
   214 function  SDL_Flip(Screen: PSDL_Surface): LongInt; cdecl; external SDLLibName;
   218 
   215 
   219 procedure SDL_GetRGB(pixel: Longword; fmt: PSDL_PixelFormat; r, g, b: PByte); cdecl; external SDLLibName;
   216 procedure SDL_GetRGB(pixel: Longword; fmt: PSDL_PixelFormat; r, g, b: PByte); cdecl; external SDLLibName;
   220 function  SDL_MapRGB(format: PSDL_PixelFormat; r, g, b: Byte): Longword; cdecl; external SDLLibName;
   217 function  SDL_MapRGB(format: PSDL_PixelFormat; r, g, b: Byte): Longword; cdecl; external SDLLibName;
   221 
   218 
   222 function  SDL_DisplayFormat(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName;
   219 function  SDL_DisplayFormat(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName;
   223 function  SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName;
   220 function  SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName;
   224 
   221 
   225 function  SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName;
   222 function  SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName;
   226 function  SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: integer): integer; cdecl; external SDLLibName;
   223 function  SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: LongInt): LongInt; cdecl; external SDLLibName;
   227 
   224 
   228 function  SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName;
   225 function  SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName;
   229 function  SDL_GetMouseState(x, y: PInteger): Byte; cdecl; external SDLLibName;
   226 function  SDL_GetMouseState(x, y: PInteger): Byte; cdecl; external SDLLibName;
   230 function  SDL_GetKeyName(key: Longword): PChar; cdecl; external SDLLibName;
   227 function  SDL_GetKeyName(key: Longword): PChar; cdecl; external SDLLibName;
   231 procedure SDL_WarpMouse(x, y: Word); cdecl; external SDLLibName;
   228 procedure SDL_WarpMouse(x, y: Word); cdecl; external SDLLibName;
   232 
   229 
   233 function  SDL_PollEvent(event: PSDL_Event): integer; cdecl; external SDLLibName;
   230 function  SDL_PollEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName;
   234 
   231 
   235 function  SDL_ShowCursor(toggle: integer): integer; cdecl; external SDLLibName;
   232 function  SDL_ShowCursor(toggle: LongInt): LongInt; cdecl; external SDLLibName;
   236 
   233 
   237 procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName;
   234 procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName;
   238 
   235 
   239 (*  TTF  *)
   236 (*  TTF  *)
   240 
   237 
   250 
   247 
   251 type PTTF_Font = ^TTTF_font;
   248 type PTTF_Font = ^TTTF_font;
   252      TTTF_Font = record
   249      TTTF_Font = record
   253                  end;
   250                  end;
   254 
   251 
   255 function TTF_Init: integer; cdecl; external SDL_TTFLibName;
   252 function TTF_Init: LongInt; cdecl; external SDL_TTFLibName;
   256 procedure TTF_Quit; cdecl; external SDL_TTFLibName;
   253 procedure TTF_Quit; cdecl; external SDL_TTFLibName;
   257 
   254 
   258 
   255 
   259 function TTF_SizeUTF8(font: PTTF_Font; const text: PChar; var w, h: integer): integer; cdecl; external SDL_TTFLibName;
   256 function TTF_SizeUTF8(font: PTTF_Font; const text: PChar; var w, h: LongInt): LongInt; cdecl; external SDL_TTFLibName;
   260 (* TSDL_Color -> Longword conversion is workaround over freepascal bug.
   257 (* TSDL_Color -> Longword conversion is workaround over freepascal bug.
   261    See http://www.freepascal.org/mantis/view.php?id=7613 for details *)
   258    See http://www.freepascal.org/mantis/view.php?id=7613 for details *)
   262 function TTF_RenderUTF8_Solid(font: PTTF_Font; const text: PChar; fg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName;
   259 function TTF_RenderUTF8_Solid(font: PTTF_Font; const text: PChar; fg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName;
   263 function TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName;
   260 function TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName;
   264 
   261 
   265 function TTF_OpenFont(const filename: PChar; size: integer): PTTF_Font; cdecl; external SDL_TTFLibName;
   262 function TTF_OpenFont(const filename: PChar; size: LongInt): PTTF_Font; cdecl; external SDL_TTFLibName;
   266 procedure TTF_SetFontStyle(font: PTTF_Font; style: integer); cdecl; external SDL_TTFLibName;
   263 procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName;
   267 
   264 
   268 (*  SDL_mixer *)
   265 (*  SDL_mixer *)
   269 
   266 
   270 const {$IFDEF WIN32}
   267 const {$IFDEF WIN32}
   271       SDL_MixerLibName = 'SDL_mixer.dll';
   268       SDL_MixerLibName = 'SDL_mixer.dll';
   383 
   380 
   384 implementation
   381 implementation
   385 
   382 
   386 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
   383 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
   387 begin
   384 begin
   388 Result:= ( surface^.offset <> 0 )
   385 SDL_MustLock:= ( surface^.offset <> 0 )
   389        or(( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0)
   386        or(( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0)
   390 end;
   387 end;
   391 
   388 
   392 end.
   389 end.