author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1309 | 4403a69da4f8 |
child 1891 | 862800791170 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
923
diff
changeset
|
3 |
#include "debug.h" |
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1299
diff
changeset
|
4 |
#include "strings.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
430
diff
changeset
|
5 |
#include "table/strings.h" |
0 | 6 |
#include "gfx.h" |
7 |
#include "viewport.h" |
|
8 |
#include "player.h" |
|
9 |
#include "gui.h" |
|
430 | 10 |
#include "screenshot.h" |
0 | 11 |
|
12 |
// called by the ScreenShot proc to generate screenshot lines. |
|
13 |
typedef void ScreenshotCallback(void *userdata, byte *buf, uint y, uint pitch, uint n); |
|
14 |
typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const byte *palette); |
|
15 |
||
16 |
typedef struct { |
|
17 |
const char *name; |
|
18 |
const char *extension; |
|
19 |
ScreenshotHandlerProc *proc; |
|
20 |
} ScreenshotFormat; |
|
21 |
||
22 |
//************************************************ |
|
23 |
//*** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP) |
|
24 |
//************************************************ |
|
923
fc5230f75a91
(svn r1411) -Fix: structure packing in the OS/2 version (eg, with the old loader).
truelight
parents:
534
diff
changeset
|
25 |
#if defined(_MSC_VER) || defined(__WATCOMC__) |
0 | 26 |
#pragma pack(push, 1) |
27 |
#endif |
|
28 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
29 |
typedef struct BitmapFileHeader { |
0 | 30 |
uint16 type; |
31 |
uint32 size; |
|
32 |
uint32 reserved; |
|
33 |
uint32 off_bits; |
|
34 |
} GCC_PACK BitmapFileHeader; |
|
35 |
assert_compile(sizeof(BitmapFileHeader) == 14); |
|
36 |
||
923
fc5230f75a91
(svn r1411) -Fix: structure packing in the OS/2 version (eg, with the old loader).
truelight
parents:
534
diff
changeset
|
37 |
#if defined(_MSC_VER) || defined(__WATCOMC__) |
0 | 38 |
#pragma pack(pop) |
39 |
#endif |
|
40 |
||
41 |
typedef struct BitmapInfoHeader { |
|
42 |
uint32 size; |
|
43 |
int32 width, height; |
|
44 |
uint16 planes, bitcount; |
|
45 |
uint32 compression, sizeimage, xpels, ypels, clrused, clrimp; |
|
46 |
} BitmapInfoHeader; |
|
47 |
assert_compile(sizeof(BitmapInfoHeader) == 40); |
|
48 |
||
49 |
typedef struct RgbQuad { |
|
50 |
byte blue, green, red, reserved; |
|
51 |
} RgbQuad; |
|
52 |
assert_compile(sizeof(RgbQuad) == 4); |
|
53 |
||
54 |
// generic .BMP writer |
|
55 |
static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const byte *palette) |
|
56 |
{ |
|
57 |
BitmapFileHeader bfh; |
|
58 |
BitmapInfoHeader bih; |
|
318
648afd1ab9a7
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
315
diff
changeset
|
59 |
RgbQuad rq[256]; |
0 | 60 |
byte *buff; |
61 |
FILE *f; |
|
62 |
uint i, padw; |
|
63 |
uint n, maxlines; |
|
64 |
||
65 |
// only implemented for 8bit images so far. |
|
66 |
if (pixelformat != 8) |
|
67 |
return false; |
|
68 |
||
69 |
f = fopen(name, "wb"); |
|
70 |
if (f == NULL) return false; |
|
71 |
||
72 |
// each scanline must be aligned on a 32bit boundary |
|
73 |
padw = (w + 3) & ~3; |
|
74 |
||
75 |
// setup the file header |
|
76 |
bfh.type = TO_LE16('MB'); |
|
77 |
bfh.size = TO_LE32(sizeof(bfh) + sizeof(bih) + sizeof(RgbQuad) * 256 + padw * h); |
|
78 |
bfh.reserved = 0; |
|
79 |
bfh.off_bits = TO_LE32(sizeof(bfh) + sizeof(bih) + sizeof(RgbQuad) * 256); |
|
80 |
||
81 |
// setup the info header |
|
82 |
bih.size = TO_LE32(sizeof(BitmapInfoHeader)); |
|
83 |
bih.width = TO_LE32(w); |
|
84 |
bih.height = TO_LE32(h); |
|
85 |
bih.planes = TO_LE16(1); |
|
86 |
bih.bitcount = TO_LE16(8); |
|
87 |
bih.compression = 0; |
|
88 |
bih.sizeimage = 0; |
|
89 |
bih.xpels = 0; |
|
90 |
bih.ypels = 0; |
|
91 |
bih.clrused = 0; |
|
92 |
bih.clrimp = 0; |
|
93 |
||
94 |
// convert the palette to the windows format |
|
430 | 95 |
for (i = 0; i != 256; i++) { |
0 | 96 |
rq[i].red = *palette++; |
97 |
rq[i].green = *palette++; |
|
98 |
rq[i].blue = *palette++; |
|
99 |
rq[i].reserved = 0; |
|
100 |
} |
|
101 |
||
102 |
// write file header and info header and palette |
|
430 | 103 |
if (fwrite(&bfh, sizeof(bfh), 1, f) != 1) return false; |
104 |
if (fwrite(&bih, sizeof(bih), 1, f) != 1) return false; |
|
105 |
if (fwrite(rq, sizeof(rq), 1, f) != 1) return false; |
|
0 | 106 |
|
107 |
// use by default 64k temp memory |
|
108 |
maxlines = clamp(65536 / padw, 16, 128); |
|
109 |
||
110 |
// now generate the bitmap bits |
|
430 | 111 |
buff = malloc(padw * maxlines); // by default generate 128 lines at a time. |
112 |
if (buff == NULL) { |
|
113 |
fclose(f); |
|
114 |
return false; |
|
115 |
} |
|
0 | 116 |
memset(buff, 0, padw * maxlines); // zero the buffer to have the padding bytes set to 0 |
117 |
||
118 |
// start at the bottom, since bitmaps are stored bottom up. |
|
119 |
do { |
|
120 |
// determine # lines |
|
121 |
n = min(h, maxlines); |
|
122 |
h -= n; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
123 |
|
0 | 124 |
// render the pixels |
125 |
callb(userdata, buff, h, padw, n); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
126 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
127 |
// write each line |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
128 |
while (n) |
430 | 129 |
if (fwrite(buff + (--n) * padw, padw, 1, f) != 1) { |
130 |
free(buff); |
|
131 |
fclose(f); |
|
132 |
return false; |
|
133 |
} |
|
134 |
} while (h != 0); |
|
0 | 135 |
|
430 | 136 |
free(buff); |
0 | 137 |
fclose(f); |
138 |
||
139 |
return true; |
|
140 |
} |
|
141 |
||
142 |
//******************************************************** |
|
143 |
//*** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG) |
|
144 |
//******************************************************** |
|
145 |
#if defined(WITH_PNG) |
|
146 |
#include <png.h> |
|
147 |
||
148 |
static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message) |
|
149 |
{ |
|
430 | 150 |
DEBUG(misc, 0) ("ERROR(libpng): %s - %s\n", message, (char *)png_get_error_ptr(png_ptr)); |
0 | 151 |
longjmp(png_ptr->jmpbuf, 1); |
152 |
} |
|
153 |
||
154 |
static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message) |
|
155 |
{ |
|
156 |
DEBUG(misc, 0) ("WARNING(libpng): %s - %s\n", message, (char *)png_get_error_ptr(png_ptr)); |
|
157 |
} |
|
158 |
||
159 |
static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const byte *palette) |
|
160 |
{ |
|
318
648afd1ab9a7
(svn r328) -Fix: remove some unlogical alloca()s (Tron)
darkvater
parents:
315
diff
changeset
|
161 |
png_color rq[256]; |
0 | 162 |
byte *buff; |
163 |
FILE *f; |
|
164 |
uint i, y, n; |
|
165 |
uint maxlines; |
|
166 |
png_structp png_ptr; |
|
167 |
png_infop info_ptr; |
|
168 |
||
169 |
// only implemented for 8bit images so far. |
|
170 |
if (pixelformat != 8) |
|
171 |
return false; |
|
172 |
||
173 |
f = fopen(name, "wb"); |
|
174 |
if (f == NULL) return false; |
|
175 |
||
430 | 176 |
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (char *)name, png_my_error, png_my_warning); |
0 | 177 |
|
430 | 178 |
if (png_ptr == NULL) { |
0 | 179 |
fclose(f); |
180 |
return false; |
|
181 |
} |
|
182 |
||
183 |
info_ptr = png_create_info_struct(png_ptr); |
|
430 | 184 |
if (info_ptr == NULL) { |
0 | 185 |
png_destroy_write_struct(&png_ptr, (png_infopp)NULL); |
186 |
fclose(f); |
|
187 |
return false; |
|
188 |
} |
|
189 |
||
190 |
if (setjmp(png_jmpbuf(png_ptr))) { |
|
191 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
192 |
fclose(f); |
|
193 |
return false; |
|
194 |
} |
|
195 |
||
196 |
png_init_io(png_ptr, f); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
197 |
|
0 | 198 |
png_set_filter(png_ptr, 0, PNG_FILTER_NONE); |
199 |
||
430 | 200 |
png_set_IHDR(png_ptr, info_ptr, w, h, pixelformat, PNG_COLOR_TYPE_PALETTE, |
201 |
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
|
0 | 202 |
|
203 |
// convert the palette to the .PNG format. |
|
204 |
{ |
|
205 |
// avoids "might be clobbered" warning of argument "palette" |
|
206 |
const byte *pal = palette; |
|
207 |
||
430 | 208 |
for (i = 0; i != 256; i++) { |
0 | 209 |
rq[i].red = *pal++; |
210 |
rq[i].green = *pal++; |
|
211 |
rq[i].blue = *pal++; |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
png_set_PLTE(png_ptr, info_ptr, rq, 256); |
|
216 |
png_write_info(png_ptr, info_ptr); |
|
217 |
png_set_flush(png_ptr, 512); |
|
218 |
||
219 |
// use by default 64k temp memory |
|
220 |
maxlines = clamp(65536 / w, 16, 128); |
|
221 |
||
222 |
// now generate the bitmap bits |
|
430 | 223 |
buff = malloc(w * maxlines); // by default generate 128 lines at a time. |
224 |
if (buff == NULL) { |
|
225 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
226 |
fclose(f); |
|
227 |
return false; |
|
228 |
} |
|
0 | 229 |
memset(buff, 0, w * maxlines); // zero the buffer to have the padding bytes set to 0 |
230 |
||
231 |
y = 0; |
|
232 |
do { |
|
233 |
// determine # lines to write |
|
234 |
n = min(h - y, maxlines); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
235 |
|
0 | 236 |
// render the pixels into the buffer |
237 |
callb(userdata, buff, y, w, n); |
|
238 |
y += n; |
|
239 |
||
240 |
// write them to png |
|
430 | 241 |
for (i = 0; i != n; i++) |
0 | 242 |
png_write_row(png_ptr, buff + i * w); |
243 |
} while (y != h); |
|
244 |
||
245 |
png_write_end(png_ptr, info_ptr); |
|
246 |
png_destroy_write_struct(&png_ptr, &info_ptr); |
|
247 |
||
430 | 248 |
free(buff); |
0 | 249 |
fclose(f); |
250 |
return true; |
|
251 |
} |
|
252 |
#endif // WITH_PNG |
|
253 |
||
254 |
||
255 |
//************************************************ |
|
256 |
//*** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX) |
|
257 |
//************************************************ |
|
258 |
||
259 |
typedef struct { |
|
260 |
byte manufacturer; |
|
261 |
byte version; |
|
262 |
byte rle; |
|
263 |
byte bpp; |
|
264 |
uint32 unused; |
|
265 |
uint16 xmax, ymax; |
|
266 |
uint16 hdpi, vdpi; |
|
267 |
byte pal_small[16*3]; |
|
268 |
byte reserved; |
|
269 |
byte planes; |
|
270 |
uint16 pitch; |
|
271 |
uint16 cpal; |
|
272 |
uint16 width; |
|
273 |
uint16 height; |
|
274 |
byte filler[54]; |
|
275 |
} PcxHeader; |
|
276 |
assert_compile(sizeof(PcxHeader) == 128); |
|
277 |
||
278 |
static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const byte *palette) |
|
279 |
{ |
|
280 |
byte *buff; |
|
281 |
FILE *f; |
|
282 |
uint maxlines; |
|
283 |
uint y; |
|
284 |
PcxHeader pcx; |
|
285 |
||
286 |
if (pixelformat != 8 || w == 0) |
|
287 |
return false; |
|
288 |
||
289 |
f = fopen(name, "wb"); |
|
290 |
if (f == NULL) return false; |
|
291 |
||
292 |
memset(&pcx, 0, sizeof(pcx)); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
293 |
|
0 | 294 |
// setup pcx header |
295 |
pcx.manufacturer = 10; |
|
296 |
pcx.version = 5; |
|
297 |
pcx.rle = 1; |
|
298 |
pcx.bpp = 8; |
|
430 | 299 |
pcx.xmax = TO_LE16(w - 1); |
300 |
pcx.ymax = TO_LE16(h - 1); |
|
0 | 301 |
pcx.hdpi = TO_LE16(320); |
302 |
pcx.vdpi = TO_LE16(320); |
|
303 |
||
304 |
pcx.planes = 1; |
|
305 |
pcx.cpal = TO_LE16(1); |
|
306 |
pcx.width = pcx.pitch = TO_LE16(w); |
|
307 |
pcx.height = TO_LE16(h); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
308 |
|
0 | 309 |
// write pcx header |
430 | 310 |
if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) { |
311 |
fclose(f); |
|
312 |
return false; |
|
313 |
} |
|
0 | 314 |
|
315 |
// use by default 64k temp memory |
|
316 |
maxlines = clamp(65536 / w, 16, 128); |
|
317 |
||
318 |
// now generate the bitmap bits |
|
430 | 319 |
buff = malloc(w * maxlines); // by default generate 128 lines at a time. |
320 |
if (buff == NULL) { |
|
321 |
fclose(f); |
|
322 |
return false; |
|
323 |
} |
|
324 |
memset(buff, 0, w * maxlines); // zero the buffer to have the padding bytes set to 0 |
|
0 | 325 |
|
326 |
y = 0; |
|
327 |
do { |
|
328 |
// determine # lines to write |
|
430 | 329 |
uint n = min(h - y, maxlines); |
330 |
uint i; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
331 |
|
0 | 332 |
// render the pixels into the buffer |
333 |
callb(userdata, buff, y, w, n); |
|
334 |
y += n; |
|
335 |
||
336 |
// write them to pcx |
|
430 | 337 |
for (i = 0; i != n; i++) { |
0 | 338 |
int runcount = 1; |
339 |
byte *bufp = buff + i * w; |
|
340 |
byte runchar = buff[0]; |
|
430 | 341 |
uint left; |
0 | 342 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
343 |
// for each pixel... |
430 | 344 |
for (left = w - 1; left > 0; --left) { |
0 | 345 |
byte ch = *bufp++; |
346 |
if (ch != runchar || runcount >= 0x3f) { |
|
430 | 347 |
if (runcount > 1 || (runchar & 0xC0) == 0xC0) |
348 |
if (fputc(0xC0 | runcount, f) == EOF) { |
|
349 |
free(buff); |
|
350 |
fclose(f); |
|
351 |
return false; |
|
352 |
} |
|
353 |
if (fputc(runchar, f) == EOF) { |
|
354 |
free(buff); |
|
355 |
fclose(f); |
|
356 |
return false; |
|
357 |
} |
|
0 | 358 |
runcount = 0; |
359 |
runchar = ch; |
|
360 |
} |
|
361 |
runcount++; |
|
362 |
} |
|
363 |
||
364 |
// write remaining bytes.. |
|
430 | 365 |
if (runcount > 1 || (runchar & 0xC0) == 0xC0) |
366 |
if (fputc(0xC0 | runcount, f) == EOF) { |
|
367 |
free(buff); |
|
368 |
fclose(f); |
|
369 |
return false; |
|
370 |
} |
|
371 |
if (fputc(runchar, f) == EOF) { |
|
372 |
free(buff); |
|
373 |
fclose(f); |
|
374 |
return false; |
|
375 |
} |
|
0 | 376 |
} |
377 |
} while (y != h); |
|
378 |
||
430 | 379 |
free(buff); |
380 |
||
0 | 381 |
// write 8-bit color palette |
430 | 382 |
if (fputc(12, f) == EOF) { |
383 |
fclose(f); |
|
384 |
return false; |
|
385 |
} |
|
386 |
if (fwrite(palette, 256 * 3, 1, f) != 1) { |
|
387 |
fclose(f); |
|
388 |
return false; |
|
389 |
} |
|
0 | 390 |
fclose(f); |
391 |
||
392 |
return true; |
|
393 |
} |
|
394 |
||
395 |
//************************************************ |
|
396 |
//*** GENERIC SCREENSHOT CODE |
|
397 |
//************************************************ |
|
398 |
||
399 |
static const ScreenshotFormat _screenshot_formats[] = { |
|
400 |
{"BMP", "bmp", &MakeBmpImage}, |
|
401 |
#if defined(WITH_PNG) |
|
402 |
{"PNG", "png", &MakePNGImage}, |
|
403 |
#endif |
|
404 |
{"PCX", "pcx", &MakePCXImage}, |
|
405 |
}; |
|
406 |
||
430 | 407 |
void InitializeScreenshotFormats(void) |
0 | 408 |
{ |
430 | 409 |
int i, j; |
410 |
for (i = 0, j = 0; i != lengthof(_screenshot_formats); i++) |
|
411 |
if (!strcmp(_screenshot_format_name, _screenshot_formats[i].extension)) { |
|
412 |
j = i; |
|
413 |
break; |
|
414 |
} |
|
0 | 415 |
_cur_screenshot_format = j; |
416 |
_num_screenshot_formats = lengthof(_screenshot_formats); |
|
417 |
} |
|
418 |
||
419 |
const char *GetScreenshotFormatDesc(int i) |
|
420 |
{ |
|
421 |
return _screenshot_formats[i].name; |
|
422 |
} |
|
423 |
||
424 |
void SetScreenshotFormat(int i) |
|
425 |
{ |
|
426 |
_cur_screenshot_format = i; |
|
427 |
strcpy(_screenshot_format_name, _screenshot_formats[i].extension); |
|
428 |
} |
|
429 |
||
430 |
// screenshot generator that dumps the current video buffer |
|
410 | 431 |
static void CurrentScreenCallback(void *userdata, byte *buf, uint y, uint pitch, uint n) |
0 | 432 |
{ |
430 | 433 |
for (; n > 0; --n) { |
315
6937bce0a9cb
(svn r321) -Fix: crash when making png screenshot with odd resolution (Tron)
truelight
parents:
193
diff
changeset
|
434 |
memcpy(buf, _screen.dst_ptr + y * _screen.pitch, _screen.width); |
6937bce0a9cb
(svn r321) -Fix: crash when making png screenshot with odd resolution (Tron)
truelight
parents:
193
diff
changeset
|
435 |
++y; |
6937bce0a9cb
(svn r321) -Fix: crash when making png screenshot with odd resolution (Tron)
truelight
parents:
193
diff
changeset
|
436 |
buf += pitch; |
6937bce0a9cb
(svn r321) -Fix: crash when making png screenshot with odd resolution (Tron)
truelight
parents:
193
diff
changeset
|
437 |
} |
0 | 438 |
} |
439 |
||
440 |
// generate a large piece of the world |
|
410 | 441 |
static void LargeWorldCallback(void *userdata, byte *buf, uint y, uint pitch, uint n) |
0 | 442 |
{ |
443 |
ViewPort *vp = (ViewPort *)userdata; |
|
444 |
DrawPixelInfo dpi, *old_dpi; |
|
445 |
int wx, left; |
|
446 |
||
447 |
old_dpi = _cur_dpi; |
|
448 |
_cur_dpi = &dpi; |
|
449 |
||
450 |
dpi.dst_ptr = buf; |
|
451 |
dpi.height = n; |
|
452 |
dpi.width = vp->width; |
|
453 |
dpi.pitch = pitch; |
|
454 |
dpi.zoom = 0; |
|
455 |
dpi.left = 0; |
|
456 |
dpi.top = y; |
|
457 |
||
458 |
left = 0; |
|
459 |
while (vp->width - left != 0) { |
|
460 |
wx = min(vp->width - left, 1600); |
|
461 |
left += wx; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
462 |
|
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
463 |
ViewportDoDraw(vp, |
0 | 464 |
((left - wx - vp->left) << vp->zoom) + vp->virtual_left, |
465 |
((y - vp->top) << vp->zoom) + vp->virtual_top, |
|
466 |
((left - vp->left) << vp->zoom) + vp->virtual_left, |
|
430 | 467 |
(((y + n) - vp->top) << vp->zoom) + vp->virtual_top |
0 | 468 |
); |
469 |
} |
|
470 |
||
471 |
_cur_dpi = old_dpi; |
|
472 |
} |
|
473 |
||
474 |
static char *MakeScreenshotName(const char *ext) |
|
475 |
{ |
|
476 |
static char filename[256]; |
|
477 |
char *base; |
|
478 |
int serial; |
|
479 |
||
1 | 480 |
if (_game_mode == GM_EDITOR || _local_player == OWNER_SPECTATOR) { |
0 | 481 |
sprintf(_screenshot_name, "screenshot"); |
482 |
} else { |
|
483 |
Player *p = &_players[_local_player]; |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
484 |
SetDParam(0, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
485 |
SetDParam(1, p->name_2); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
486 |
SetDParam(2, _date); |
0 | 487 |
GetString(_screenshot_name, STR_4004); |
488 |
} |
|
489 |
||
490 |
base = strchr(_screenshot_name, 0); |
|
491 |
base[0] = '.'; strcpy(base + 1, ext); |
|
492 |
||
493 |
serial = 0; |
|
430 | 494 |
for (;;) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
495 |
snprintf(filename, sizeof(filename), "%s%s", _path.personal_dir, _screenshot_name); |
0 | 496 |
if (!FileExists(filename)) |
497 |
break; |
|
498 |
sprintf(base, " #%d.%s", ++serial, ext); |
|
499 |
} |
|
500 |
||
501 |
return filename; |
|
502 |
} |
|
503 |
||
430 | 504 |
bool MakeScreenshot(void) |
0 | 505 |
{ |
506 |
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
1
diff
changeset
|
507 |
return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, 8, _cur_palette); |
0 | 508 |
} |
509 |
||
510 |
bool MakeWorldScreenshot(int left, int top, int width, int height, int zoom) |
|
511 |
{ |
|
512 |
ViewPort vp; |
|
513 |
const ScreenshotFormat *sf; |
|
514 |
||
515 |
vp.zoom = zoom; |
|
516 |
vp.left = 0; |
|
517 |
vp.top = 0; |
|
518 |
vp.virtual_width = width; |
|
519 |
vp.width = width >> zoom; |
|
520 |
vp.virtual_height = height; |
|
521 |
vp.height = height >> zoom; |
|
522 |
vp.virtual_left = left; |
|
523 |
vp.virtual_top = top; |
|
524 |
||
525 |
sf = _screenshot_formats + _cur_screenshot_format; |
|
526 |
return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, 8, _cur_palette); |
|
527 |
} |