hedgewars/uMisc.pas
changeset 8865 dd4035ee0f12
parent 7848 775a72905708
child 9080 9b42757d7e71
equal deleted inserted replaced
8862:85eb1f4b4a5f 8865:dd4035ee0f12
    36 function  SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect; inline;
    36 function  SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect; inline;
    37 {$ENDIF}
    37 {$ENDIF}
    38 
    38 
    39 implementation
    39 implementation
    40 uses SysUtils, uVariables, uUtils
    40 uses SysUtils, uVariables, uUtils
    41      {$IFDEF PNG_SCREENSHOTS}, PNGh, png {$ENDIF}
    41      {$IFDEF PNG_SCREENSHOTS}, PNGh, png {$ENDIF};
    42      {$IFNDEF USE_SDLTHREADS} {$IFDEF UNIX}, cthreads{$ENDIF} {$ENDIF};
       
    43 
    42 
    44 type PScreenshot = ^TScreenshot;
    43 type PScreenshot = ^TScreenshot;
    45      TScreenshot = record
    44      TScreenshot = record
    46          buffer: PByte;
    45          buffer: PByte;
    47          filename: shortstring;
    46          filename: shortstring;
    62 SDL_WarpMouse(x, y);
    61 SDL_WarpMouse(x, y);
    63 end;
    62 end;
    64 
    63 
    65 {$IFDEF PNG_SCREENSHOTS}
    64 {$IFDEF PNG_SCREENSHOTS}
    66 // this funtion will be executed in separate thread
    65 // this funtion will be executed in separate thread
    67 function SaveScreenshot(screenshot: pointer): PtrInt;
    66 function SaveScreenshot(screenshot: pointer): LongInt; cdecl; export;
    68 var i: LongInt;
    67 var i: LongInt;
    69     png_ptr: ^png_struct;
    68     png_ptr: ^png_struct;
    70     info_ptr: ^png_info;
    69     info_ptr: ^png_info;
    71     f: file;
    70     f: file;
    72     image: PScreenshot;
    71     image: PScreenshot;
   117 end;
   116 end;
   118 
   117 
   119 {$ELSE} // no PNG_SCREENSHOTS
   118 {$ELSE} // no PNG_SCREENSHOTS
   120 
   119 
   121 // this funtion will be executed in separate thread
   120 // this funtion will be executed in separate thread
   122 function SaveScreenshot(screenshot: pointer): PtrInt;
   121 function SaveScreenshot(screenshot: pointer): LongInt; cdecl; export;
   123 var f: file;
   122 var f: file;
   124     // Windows Bitmap Header
   123     // Windows Bitmap Header
   125     head: array[0..53] of Byte = (
   124     head: array[0..53] of Byte = (
   126     $42, $4D,       // identifier ("BM")
   125     $42, $4D,       // identifier ("BM")
   127     0, 0, 0, 0,     // file size
   126     0, 0, 0, 0,     // file size
   260 image^.width:= cScreenWidth div k;
   259 image^.width:= cScreenWidth div k;
   261 image^.height:= cScreenHeight div k;
   260 image^.height:= cScreenHeight div k;
   262 image^.size:= size;
   261 image^.size:= size;
   263 image^.buffer:= p;
   262 image^.buffer:= p;
   264 
   263 
   265 {$IFDEF USE_SDLTHREADS}
   264 SDL_CreateThread(@SaveScreenshot{$IFDEF SDL13}, 'snapshot'{$ENDIF}, image);
   266 SDL_CreateThread(@SaveScreenshot{$IFDEF SDL13}, nil{$ENDIF}, image);
       
   267 {$ELSE}
       
   268 BeginThread(@SaveScreenshot, image);
       
   269 {$ENDIF}
       
   270 MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate
   265 MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate
   271 end;
   266 end;
   272 
   267 
   273 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   268 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   274 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   269 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;