hedgewars/uMisc.pas
branchsdl2transition
changeset 11338 7a7611adf715
parent 9317 a04c30940d2d
child 11342 ed5a6478e710
equal deleted inserted replaced
9798:f2b18754742f 11338:7a7611adf715
    28 
    28 
    29 procedure movecursor(dx, dy: LongInt);
    29 procedure movecursor(dx, dy: LongInt);
    30 function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
    30 function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
    31 function  MakeScreenshot(filename: shortstring; k: LongInt): boolean;
    31 function  MakeScreenshot(filename: shortstring; k: LongInt): boolean;
    32 function  GetTeamStatString(p: PTeam): shortstring;
    32 function  GetTeamStatString(p: PTeam): shortstring;
    33 {$IFDEF SDL2}
       
    34 function  SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline;
    33 function  SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline;
    35 {$ELSE}
       
    36 function  SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect; inline;
       
    37 {$ENDIF}
       
    38 
    34 
    39 implementation
    35 implementation
    40 uses SysUtils, uVariables, uUtils
    36 uses SysUtils, uVariables, uUtils
    41      {$IFDEF PNG_SCREENSHOTS}, PNGh, png {$ENDIF};
    37      {$IFDEF PNG_SCREENSHOTS}, PNGh, png {$ENDIF};
    42 
    38 
   259 image^.width:= cScreenWidth div k;
   255 image^.width:= cScreenWidth div k;
   260 image^.height:= cScreenHeight div k;
   256 image^.height:= cScreenHeight div k;
   261 image^.size:= size;
   257 image^.size:= size;
   262 image^.buffer:= p;
   258 image^.buffer:= p;
   263 
   259 
   264 SDL_CreateThread(@SaveScreenshot{$IFDEF SDL2}, 'snapshot'{$ENDIF}, image);
   260 SDL_CreateThread(@SaveScreenshot, 'snapshot', image);
   265 MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate
   261 MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate
   266 end;
   262 end;
   267 
   263 
   268 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   264 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   269 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   265 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   277         SDL_FreeSurface(tmpsurf);
   273         SDL_FreeSurface(tmpsurf);
   278         doSurfaceConversion:= convertedSurf;
   274         doSurfaceConversion:= convertedSurf;
   279     end;
   275     end;
   280 end;
   276 end;
   281 
   277 
   282 {$IFDEF SDL2}
       
   283 function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline;
   278 function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline;
   284 {$ELSE}
       
   285 function SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect; inline;
       
   286 {$ENDIF}
       
   287 begin
   279 begin
   288     SDL_RectMake.x:= x;
   280     SDL_RectMake.x:= x;
   289     SDL_RectMake.y:= y;
   281     SDL_RectMake.y:= y;
   290     SDL_RectMake.w:= width;
   282     SDL_RectMake.w:= width;
   291     SDL_RectMake.h:= height;
   283     SDL_RectMake.h:= height;
   297     s:= p^.TeamName + ':' + IntToStr(p^.TeamHealth) + ':';
   289     s:= p^.TeamName + ':' + IntToStr(p^.TeamHealth) + ':';
   298     GetTeamStatString:= s;
   290     GetTeamStatString:= s;
   299 end;
   291 end;
   300 
   292 
   301 procedure initModule;
   293 procedure initModule;
   302 {$IFDEF SDL2}
       
   303 const SDL_PIXELFORMAT_ABGR8888 = (1 shl 28) or (6 shl 24) or (7 shl 20) or (6 shl 16) or (32 shl 8) or 4;
   294 const SDL_PIXELFORMAT_ABGR8888 = (1 shl 28) or (6 shl 24) or (7 shl 20) or (6 shl 16) or (32 shl 8) or 4;
   304 {$ELSE}
   295 begin
   305 const format: TSDL_PixelFormat = (
       
   306         palette: nil; BitsPerPixel: 32; BytesPerPixel: 4;
       
   307         Rloss: 0; Gloss: 0; Bloss: 0; Aloss: 0;
       
   308         Rshift: RShift; Gshift: GShift; Bshift: BShift; Ashift: AShift;
       
   309         RMask: RMask; GMask: GMask; BMask: BMask; AMask: AMask;
       
   310         colorkey: 0; alpha: 255);
       
   311 {$ENDIF}
       
   312 begin
       
   313 {$IFDEF SDL2}
       
   314     conversionFormat:= SDL_AllocFormat(SDL_PIXELFORMAT_ABGR8888);
   296     conversionFormat:= SDL_AllocFormat(SDL_PIXELFORMAT_ABGR8888);
   315 {$ELSE}
       
   316     conversionFormat:= @format;
       
   317 {$ENDIF}
       
   318 end;
   297 end;
   319 
   298 
   320 procedure freeModule;
   299 procedure freeModule;
   321 begin
   300 begin
   322 {$IFDEF SDL2}
       
   323     SDL_FreeFormat(conversionFormat);
   301     SDL_FreeFormat(conversionFormat);
   324 {$ENDIF}
       
   325 end;
   302 end;
   326 
   303 
   327 end.
   304 end.