equal
deleted
inserted
replaced
1 (* |
1 (* |
2 * Hedgewars, a free turn based strategy game |
2 * Hedgewars, a free turn based strategy game |
3 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
3 * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com> |
4 * |
4 * |
5 * This program is free software; you can redistribute it and/or modify |
5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License as published by |
6 * it under the terms of the GNU General Public License as published by |
7 * the Free Software Foundation; version 2 of the License |
7 * the Free Software Foundation; version 2 of the License |
8 * |
8 * |
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 |
261 image^.width:= cScreenWidth div k; |
260 image^.width:= cScreenWidth div k; |
262 image^.height:= cScreenHeight div k; |
261 image^.height:= cScreenHeight div k; |
263 image^.size:= size; |
262 image^.size:= size; |
264 image^.buffer:= p; |
263 image^.buffer:= p; |
265 |
264 |
266 {$IFDEF USE_SDLTHREADS} |
265 SDL_CreateThread(@SaveScreenshot{$IFDEF SDL13}, 'snapshot'{$ENDIF}, image); |
267 SDL_CreateThread(@SaveScreenshot{$IFDEF SDL13}, nil{$ENDIF}, image); |
|
268 {$ELSE} |
|
269 BeginThread(@SaveScreenshot, image); |
|
270 {$ENDIF} |
|
271 MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate |
266 MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate |
272 end; |
267 end; |
273 |
268 |
274 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860 |
269 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860 |
275 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; |
270 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; |