hedgewars/uMisc.pas
branchqmlfrontend
changeset 11403 b894922d58cc
parent 11071 3851ce4f2061
parent 11367 a91c4c4fd85c
child 11828 a69124eb7ce7
equal deleted inserted replaced
11076:fcbdee9cdd74 11403:b894922d58cc
    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; dump: LongWord): boolean;
    31 function MakeScreenshot(filename: shortstring; k: LongInt; dump: LongWord): 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 
   302     image^.height:= cScreenHeight div k
   298     image^.height:= cScreenHeight div k
   303     end;
   299     end;
   304 image^.size:= size;
   300 image^.size:= size;
   305 image^.buffer:= p;
   301 image^.buffer:= p;
   306 
   302 
   307 SDL_CreateThread(@SaveScreenshot{$IFDEF SDL2}, 'snapshot'{$ENDIF}, image);
   303 SDL_CreateThread(@SaveScreenshot, PChar('snapshot'), image);
   308 MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate
   304 MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate
   309 end;
   305 end;
   310 
   306 
   311 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   307 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   312 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   308 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   320         SDL_FreeSurface(tmpsurf);
   316         SDL_FreeSurface(tmpsurf);
   321         doSurfaceConversion:= convertedSurf;
   317         doSurfaceConversion:= convertedSurf;
   322     end;
   318     end;
   323 end;
   319 end;
   324 
   320 
   325 {$IFDEF SDL2}
       
   326 function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline;
   321 function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline;
   327 {$ELSE}
       
   328 function SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect; inline;
       
   329 {$ENDIF}
       
   330 begin
   322 begin
   331     SDL_RectMake.x:= x;
   323     SDL_RectMake.x:= x;
   332     SDL_RectMake.y:= y;
   324     SDL_RectMake.y:= y;
   333     SDL_RectMake.w:= width;
   325     SDL_RectMake.w:= width;
   334     SDL_RectMake.h:= height;
   326     SDL_RectMake.h:= height;
   339 begin
   331 begin
   340     s:= p^.TeamName + ':' + IntToStr(p^.TeamHealth) + ':';
   332     s:= p^.TeamName + ':' + IntToStr(p^.TeamHealth) + ':';
   341     GetTeamStatString:= s;
   333     GetTeamStatString:= s;
   342 end;
   334 end;
   343 
   335 
   344 {$IFDEF SDL2}
   336 procedure initModule;
   345 // FIXME - pretty sure this is not handling endianness correctly like the SDL1 is
       
   346 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;
   337 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;
   347 {$ELSE}
   338 begin
   348 const format: TSDL_PixelFormat = (
       
   349         palette: nil; BitsPerPixel: 32; BytesPerPixel: 4;
       
   350         Rloss: 0; Gloss: 0; Bloss: 0; Aloss: 0;
       
   351         Rshift: RShift; Gshift: GShift; Bshift: BShift; Ashift: AShift;
       
   352         RMask: RMask; GMask: GMask; BMask: BMask; AMask: AMask;
       
   353         colorkey: 0; alpha: 255);
       
   354 {$ENDIF}
       
   355 
       
   356 procedure initModule;
       
   357 begin
       
   358 {$IFDEF SDL2}
       
   359     conversionFormat:= SDL_AllocFormat(SDL_PIXELFORMAT_ABGR8888);
   339     conversionFormat:= SDL_AllocFormat(SDL_PIXELFORMAT_ABGR8888);
   360 {$ELSE}
       
   361     conversionFormat:= @format;
       
   362 {$ENDIF}
       
   363 end;
   340 end;
   364 
   341 
   365 procedure freeModule;
   342 procedure freeModule;
   366 begin
   343 begin
   367 {$IFDEF SDL2}
       
   368     SDL_FreeFormat(conversionFormat);
   344     SDL_FreeFormat(conversionFormat);
   369 {$ENDIF}
       
   370 end;
   345 end;
   371 
   346 
   372 end.
   347 end.