OpenTTD Source: src/screenshot.cpp Source File

OpenTTD Source 1.11.0-RC1

screenshot.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "fileio_func.h"
12 #include "viewport_func.h"
13 #include "gfx_func.h"
14 #include "screenshot.h"
15 #include "blitter/factory.hpp"
16 #include "zoom_func.h"
17 #include "core/endian_func.hpp"
18 #include "saveload/saveload.h"
19 #include "company_base.h"
20 #include "company_func.h"
21 #include "strings_func.h"
22 #include "error.h"
23 #include "textbuf_gui.h"
24 #include "window_gui.h"
25 #include "window_func.h"
26 #include "tile_map.h"
27 #include "landscape.h"
28 #include "video/video_driver.hpp"
29
30 #include "table/strings.h"
31
32 #include "safeguards.h"
33
34 static const char * const SCREENSHOT_NAME = "screenshot";
35 static const char * const HEIGHTMAP_NAME = "heightmap";
36
37 char _screenshot_format_name[8];
38 uint _num_screenshot_formats;
39 uint _cur_screenshot_format;
40 static char _screenshot_name[128];
41 char _full_screenshot_name[MAX_PATH];
42
51 typedef void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n);
52
64 typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette);
65
67 struct ScreenshotFormat {
68 const char *extension;
69 ScreenshotHandlerProc *proc;
70 };
71
72 #define MKCOLOUR(x) TO_LE32X(x)
73
74 /*************************************************
75 **** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP)
76 *************************************************/
77
79 PACK(struct BitmapFileHeader {
80 uint16 type;
81 uint32 size;
82 uint32 reserved;
83 uint32 off_bits;
84 });
85 static_assert(sizeof(BitmapFileHeader) == 14);
86
88 struct BitmapInfoHeader {
89 uint32 size;
90 int32 width, height;
91 uint16 planes, bitcount;
92 uint32 compression, sizeimage, xpels, ypels, clrused, clrimp;
93 };
94 static_assert(sizeof(BitmapInfoHeader) == 40);
95
97 struct RgbQuad {
98 byte blue, green, red, reserved;
99 };
100 static_assert(sizeof(RgbQuad) == 4);
101
114 static bool MakeBMPImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
115 {
116 uint bpp; // bytes per pixel
117 switch (pixelformat) {
118 case 8: bpp = 1; break;
119 /* 32bpp mode is saved as 24bpp BMP */
120 case 32: bpp = 3; break;
121 /* Only implemented for 8bit and 32bit images so far */
122 default: return false;
123 }
124
125 FILE *f = fopen(name, "wb");
126 if (f == nullptr) return false;
127
128 /* Each scanline must be aligned on a 32bit boundary */
129 uint bytewidth = Align(w * bpp, 4); // bytes per line in file
130
131 /* Size of palette. Only present for 8bpp mode */
132 uint pal_size = pixelformat == 8 ? sizeof(RgbQuad) * 256 : 0;
133
134 /* Setup the file header */
135 BitmapFileHeader bfh;
136 bfh.type = TO_LE16('MB');
137 bfh.size = TO_LE32(sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + pal_size + bytewidth * h);
138 bfh.reserved = 0;
139 bfh.off_bits = TO_LE32(sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + pal_size);
140
141 /* Setup the info header */
142 BitmapInfoHeader bih;
143 bih.size = TO_LE32(sizeof(BitmapInfoHeader));
144 bih.width = TO_LE32(w);
145 bih.height = TO_LE32(h);
146 bih.planes = TO_LE16(1);
147 bih.bitcount = TO_LE16(bpp * 8);
148 bih.compression = 0;
149 bih.sizeimage = 0;
150 bih.xpels = 0;
151 bih.ypels = 0;
152 bih.clrused = 0;
153 bih.clrimp = 0;
154
155 /* Write file header and info header */
156 if (fwrite(&bfh, sizeof(bfh), 1, f) != 1 || fwrite(&bih, sizeof(bih), 1, f) != 1) {
157 fclose(f);
158 return false;
159 }
160
161 if (pixelformat == 8) {
162 /* Convert the palette to the windows format */
163 RgbQuad rq[256];
164 for (uint i = 0; i < 256; i++) {
165 rq[i].red = palette[i].r;
166 rq[i].green = palette[i].g;
167 rq[i].blue = palette[i].b;
168 rq[i].reserved = 0;
169 }
170 /* Write the palette */
171 if (fwrite(rq, sizeof(rq), 1, f) != 1) {
172 fclose(f);
173 return false;
174 }
175 }
176
177 /* Try to use 64k of memory, store between 16 and 128 lines */
178 uint maxlines = Clamp(65536 / (w * pixelformat / 8), 16, 128); // number of lines per iteration
179
180 uint8 *buff = MallocT<uint8>(maxlines * w * pixelformat / 8); // buffer which is rendered to
181 uint8 *line = AllocaM(uint8, bytewidth); // one line, stored to file
182 memset(line, 0, bytewidth);
183
184 /* Start at the bottom, since bitmaps are stored bottom up */
185 do {
186 uint n = std::min(h, maxlines);
187 h -= n;
188
189 /* Render the pixels */
190 callb(userdata, buff, h, w, n);
191
192 /* Write each line */
193 while (n-- != 0) {
194 if (pixelformat == 8) {
195 /* Move to 'line', leave last few pixels in line zeroed */
196 memcpy(line, buff + n * w, w);
197 } else {
198 /* Convert from 'native' 32bpp to BMP-like 24bpp.
199 * Works for both big and little endian machines */
200 Colour *src = ((Colour *)buff) + n * w;
201 byte *dst = line;
202 for (uint i = 0; i < w; i++) {
203 dst[i * 3 ] = src[i].b;
204 dst[i * 3 + 1] = src[i].g;
205 dst[i * 3 + 2] = src[i].r;
206 }
207 }
208 /* Write to file */
209 if (fwrite(line, bytewidth, 1, f) != 1) {
210 free(buff);
211 fclose(f);
212 return false;
213 }
214 }
215 } while (h != 0);
216
217 free(buff);
218 fclose(f);
219
220 return true;
221 }
222
223 /*********************************************************
224 **** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG)
225 *********************************************************/
226 #if defined(WITH_PNG)
227 #include <png.h>
228
229 #ifdef PNG_TEXT_SUPPORTED
230 #include "rev.h"
231 #include "newgrf_config.h"
232 #include "ai/ai_info.hpp"
233 #include "company_base.h"
234 #include "base_media_base.h"
235 #endif /* PNG_TEXT_SUPPORTED */
236
237 static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message)
238 {
239 DEBUG(misc, 0, "[libpng] error: %s - %s", message, (const char *)png_get_error_ptr(png_ptr));
240 longjmp(png_jmpbuf(png_ptr), 1);
241 }
242
243 static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message)
244 {
245 DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (const char *)png_get_error_ptr(png_ptr));
246 }
247
260 static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
261 {
262 png_color rq[256];
263 FILE *f;
264 uint i, y, n;
265 uint maxlines;
266 uint bpp = pixelformat / 8;
267 png_structp png_ptr;
268 png_infop info_ptr;
269
270 /* only implemented for 8bit and 32bit images so far. */
271 if (pixelformat != 8 && pixelformat != 32) return false;
272
273 f = fopen(name, "wb");
274 if (f == nullptr) return false;
275
276 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, const_cast<char *>(name), png_my_error, png_my_warning);
277
278 if (png_ptr == nullptr) {
279 fclose(f);
280 return false;
281 }
282
283 info_ptr = png_create_info_struct(png_ptr);
284 if (info_ptr == nullptr) {
285 png_destroy_write_struct(&png_ptr, (png_infopp)nullptr);
286 fclose(f);
287 return false;
288 }
289
290 if (setjmp(png_jmpbuf(png_ptr))) {
291 png_destroy_write_struct(&png_ptr, &info_ptr);
292 fclose(f);
293 return false;
294 }
295
296 png_init_io(png_ptr, f);
297
298 png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
299
300 png_set_IHDR(png_ptr, info_ptr, w, h, 8, pixelformat == 8 ? PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_RGB,
301 PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
302
303 #ifdef PNG_TEXT_SUPPORTED
304 /* Try to add some game metadata to the PNG screenshot so
305 * it's more useful for debugging and archival purposes. */
306 png_text_struct text[2];
307 memset(text, 0, sizeof(text));
308 text[0].key = const_cast<char *>("Software");
309 text[0].text = const_cast<char *>(_openttd_revision);
310 text[0].text_length = strlen(_openttd_revision);
311 text[0].compression = PNG_TEXT_COMPRESSION_NONE;
312
313 char buf[8192];
314 char *p = buf;
315 p += seprintf(p, lastof(buf), "Graphics set: %s (%u)\n", BaseGraphics::GetUsedSet()->name.c_str(), BaseGraphics::GetUsedSet()->version);
316 p = strecpy(p, "NewGRFs:\n", lastof(buf));
317 for (const GRFConfig *c = _game_mode == GM_MENU ? nullptr : _grfconfig; c != nullptr; c = c->next) {
318 p += seprintf(p, lastof(buf), "%08X ", BSWAP32(c->ident.grfid));
319 p = md5sumToString(p, lastof(buf), c->ident.md5sum);
320 p += seprintf(p, lastof(buf), " %s\n", c->filename);
321 }
322 p = strecpy(p, "\nCompanies:\n", lastof(buf));
323 for (const Company *c : Company::Iterate()) {
324 if (c->ai_info == nullptr) {
325 p += seprintf(p, lastof(buf), "%2i: Human\n", (int)c->index);
326 } else {
327 p += seprintf(p, lastof(buf), "%2i: %s (v%d)\n", (int)c->index, c->ai_info->GetName(), c->ai_info->GetVersion());
328 }
329 }
330 text[1].key = const_cast<char *>("Description");
331 text[1].text = buf;
332 text[1].text_length = p - buf;
333 text[1].compression = PNG_TEXT_COMPRESSION_zTXt;
334 png_set_text(png_ptr, info_ptr, text, 2);
335 #endif /* PNG_TEXT_SUPPORTED */
336
337 if (pixelformat == 8) {
338 /* convert the palette to the .PNG format. */
339 for (i = 0; i != 256; i++) {
340 rq[i].red = palette[i].r;
341 rq[i].green = palette[i].g;
342 rq[i].blue = palette[i].b;
343 }
344
345 png_set_PLTE(png_ptr, info_ptr, rq, 256);
346 }
347
348 png_write_info(png_ptr, info_ptr);
349 png_set_flush(png_ptr, 512);
350
351 if (pixelformat == 32) {
352 png_color_8 sig_bit;
353
354 /* Save exact colour/alpha resolution */
355 sig_bit.alpha = 0;
356 sig_bit.blue = 8;
357 sig_bit.green = 8;
358 sig_bit.red = 8;
359 sig_bit.gray = 8;
360 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
361
362 #if TTD_ENDIAN == TTD_LITTLE_ENDIAN
363 png_set_bgr(png_ptr);
364 png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
365 #else
366 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
367 #endif /* TTD_ENDIAN == TTD_LITTLE_ENDIAN */
368 }
369
370 /* use by default 64k temp memory */
371 maxlines = Clamp(65536 / w, 16, 128);
372
373 /* now generate the bitmap bits */
374 void *buff = CallocT<uint8>(w * maxlines * bpp); // by default generate 128 lines at a time.
375
376 y = 0;
377 do {
378 /* determine # lines to write */
379 n = std::min(h - y, maxlines);
380
381 /* render the pixels into the buffer */
382 callb(userdata, buff, y, w, n);
383 y += n;
384
385 /* write them to png */
386 for (i = 0; i != n; i++) {
387 png_write_row(png_ptr, (png_bytep)buff + i * w * bpp);
388 }
389 } while (y != h);
390
391 png_write_end(png_ptr, info_ptr);
392 png_destroy_write_struct(&png_ptr, &info_ptr);
393
394 free(buff);
395 fclose(f);
396 return true;
397 }
398 #endif /* WITH_PNG */
399
400
401 /*************************************************
402 **** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX)
403 *************************************************/
404
406 struct PcxHeader {
407 byte manufacturer;
408 byte version;
409 byte rle;
410 byte bpp;
411 uint32 unused;
412 uint16 xmax, ymax;
413 uint16 hdpi, vdpi;
414 byte pal_small[16 * 3];
415 byte reserved;
416 byte planes;
417 uint16 pitch;
418 uint16 cpal;
419 uint16 width;
420 uint16 height;
421 byte filler[54];
422 };
423 static_assert(sizeof(PcxHeader) == 128);
424
437 static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
438 {
439 FILE *f;
440 uint maxlines;
441 uint y;
442 PcxHeader pcx;
443 bool success;
444
445 if (pixelformat == 32) {
446 DEBUG(misc, 0, "Can't convert a 32bpp screenshot to PCX format. Please pick another format.");
447 return false;
448 }
449 if (pixelformat != 8 || w == 0) return false;
450
451 f = fopen(name, "wb");
452 if (f == nullptr) return false;
453
454 memset(&pcx, 0, sizeof(pcx));
455
456 /* setup pcx header */
457 pcx.manufacturer = 10;
458 pcx.version = 5;
459 pcx.rle = 1;
460 pcx.bpp = 8;
461 pcx.xmax = TO_LE16(w - 1);
462 pcx.ymax = TO_LE16(h - 1);
463 pcx.hdpi = TO_LE16(320);
464 pcx.vdpi = TO_LE16(320);
465
466 pcx.planes = 1;
467 pcx.cpal = TO_LE16(1);
468 pcx.width = pcx.pitch = TO_LE16(w);
469 pcx.height = TO_LE16(h);
470
471 /* write pcx header */
472 if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) {
473 fclose(f);
474 return false;
475 }
476
477 /* use by default 64k temp memory */
478 maxlines = Clamp(65536 / w, 16, 128);
479
480 /* now generate the bitmap bits */
481 uint8 *buff = CallocT<uint8>(w * maxlines); // by default generate 128 lines at a time.
482
483 y = 0;
484 do {
485 /* determine # lines to write */
486 uint n = std::min(h - y, maxlines);
487 uint i;
488
489 /* render the pixels into the buffer */
490 callb(userdata, buff, y, w, n);
491 y += n;
492
493 /* write them to pcx */
494 for (i = 0; i != n; i++) {
495 const uint8 *bufp = buff + i * w;
496 byte runchar = bufp[0];
497 uint runcount = 1;
498 uint j;
499
500 /* for each pixel... */
501 for (j = 1; j < w; j++) {
502 uint8 ch = bufp[j];
503
504 if (ch != runchar || runcount >= 0x3f) {
505 if (runcount > 1 || (runchar & 0xC0) == 0xC0) {
506 if (fputc(0xC0 | runcount, f) == EOF) {
507 free(buff);
508 fclose(f);
509 return false;
510 }
511 }
512 if (fputc(runchar, f) == EOF) {
513 free(buff);
514 fclose(f);
515 return false;
516 }
517 runcount = 0;
518 runchar = ch;
519 }
520 runcount++;
521 }
522
523 /* write remaining bytes.. */
524 if (runcount > 1 || (runchar & 0xC0) == 0xC0) {
525 if (fputc(0xC0 | runcount, f) == EOF) {
526 free(buff);
527 fclose(f);
528 return false;
529 }
530 }
531 if (fputc(runchar, f) == EOF) {
532 free(buff);
533 fclose(f);
534 return false;
535 }
536 }
537 } while (y != h);
538
539 free(buff);
540
541 /* write 8-bit colour palette */
542 if (fputc(12, f) == EOF) {
543 fclose(f);
544 return false;
545 }
546
547 /* Palette is word-aligned, copy it to a temporary byte array */
548 byte tmp[256 * 3];
549
550 for (uint i = 0; i < 256; i++) {
551 tmp[i * 3 + 0] = palette[i].r;
552 tmp[i * 3 + 1] = palette[i].g;
553 tmp[i * 3 + 2] = palette[i].b;
554 }
555 success = fwrite(tmp, sizeof(tmp), 1, f) == 1;
556
557 fclose(f);
558
559 return success;
560 }
561
562 /*************************************************
563 **** GENERIC SCREENSHOT CODE
564 *************************************************/
565
567 static const ScreenshotFormat _screenshot_formats[] = {
568 #if defined(WITH_PNG)
569 {"png", &MakePNGImage},
570 #endif
571 {"bmp", &MakeBMPImage},
572 {"pcx", &MakePCXImage},
573 };
574
576 const char *GetCurrentScreenshotExtension()
577 {
578 return _screenshot_formats[_cur_screenshot_format].extension;
579 }
580
582 void InitializeScreenshotFormats()
583 {
584 uint j = 0;
585 for (uint i = 0; i < lengthof(_screenshot_formats); i++) {
586 if (!strcmp(_screenshot_format_name, _screenshot_formats[i].extension)) {
587 j = i;
588 break;
589 }
590 }
591 _cur_screenshot_format = j;
592 _num_screenshot_formats = lengthof(_screenshot_formats);
593 }
594
599 static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
600 {
601 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
602 void *src = blitter->MoveTo(_screen.dst_ptr, 0, y);
603 blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch);
604 }
605
614 static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
615 {
616 Viewport *vp = (Viewport *)userdata;
617 DrawPixelInfo dpi, *old_dpi;
618 int wx, left;
619
620 /* We are no longer rendering to the screen */
621 DrawPixelInfo old_screen = _screen;
622 bool old_disable_anim = _screen_disable_anim;
623
624 _screen.dst_ptr = buf;
625 _screen.width = pitch;
626 _screen.height = n;
627 _screen.pitch = pitch;
628 _screen_disable_anim = true;
629
630 old_dpi = _cur_dpi;
631 _cur_dpi = &dpi;
632
633 dpi.dst_ptr = buf;
634 dpi.height = n;
635 dpi.width = vp->width;
636 dpi.pitch = pitch;
637 dpi.zoom = ZOOM_LVL_WORLD_SCREENSHOT;
638 dpi.left = 0;
639 dpi.top = y;
640
641 /* Render viewport in blocks of 1600 pixels width */
642 left = 0;
643 while (vp->width - left != 0) {
644 wx = std::min(vp->width - left, 1600);
645 left += wx;
646
647 ViewportDoDraw(vp,
648 ScaleByZoom(left - wx - vp->left, vp->zoom) + vp->virtual_left,
649 ScaleByZoom(y - vp->top, vp->zoom) + vp->virtual_top,
650 ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left,
651 ScaleByZoom((y + n) - vp->top, vp->zoom) + vp->virtual_top
652 );
653 }
654
655 _cur_dpi = old_dpi;
656
657 /* Switch back to rendering to the screen */
658 _screen = old_screen;
659 _screen_disable_anim = old_disable_anim;
660 }
661
669 static const char *MakeScreenshotName(const char *default_fn, const char *ext, bool crashlog = false)
670 {
671 bool generate = StrEmpty(_screenshot_name);
672
673 if (generate) {
674 if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
675 strecpy(_screenshot_name, default_fn, lastof(_screenshot_name));
676 } else {
677 GenerateDefaultSaveName(_screenshot_name, lastof(_screenshot_name));
678 }
679 }
680
681 /* Add extension to screenshot file */
682 size_t len = strlen(_screenshot_name);
683 seprintf(&_screenshot_name[len], lastof(_screenshot_name), ".%s", ext);
684
685 const char *screenshot_dir = crashlog ? _personal_dir.c_str() : FiosGetScreenshotDir();
686
687 for (uint serial = 1;; serial++) {
688 if (seprintf(_full_screenshot_name, lastof(_full_screenshot_name), "%s%s", screenshot_dir, _screenshot_name) >= (int)lengthof(_full_screenshot_name)) {
689 /* We need more characters than MAX_PATH -> end with error */
690 _full_screenshot_name[0] = '\0';
691 break;
692 }
693 if (!generate) break; // allow overwriting of non-automatic filenames
694 if (!FileExists(_full_screenshot_name)) break;
695 /* If file exists try another one with same name, but just with a higher index */
696 seprintf(&_screenshot_name[len], lastof(_screenshot_name) - len, "#%u.%s", serial, ext);
697 }
698
699 return _full_screenshot_name;
700 }
701
703 static bool MakeSmallScreenshot(bool crashlog)
704 {
705 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
706 return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension, crashlog), CurrentScreenCallback, nullptr, _screen.width, _screen.height,
707 BlitterFactory::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette);
708 }
709
717 void SetupScreenshotViewport(ScreenshotType t, Viewport *vp, uint32 width, uint32 height)
718 {
719 switch(t) {
720 case SC_VIEWPORT:
721 case SC_CRASHLOG: {
722 assert(width == 0 && height == 0);
723
724 Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
725 vp->virtual_left = w->viewport->virtual_left;
726 vp->virtual_top = w->viewport->virtual_top;
727 vp->virtual_width = w->viewport->virtual_width;
728 vp->virtual_height = w->viewport->virtual_height;
729
730 /* Compute pixel coordinates */
731 vp->left = 0;
732 vp->top = 0;
733 vp->width = _screen.width;
734 vp->height = _screen.height;
735 vp->overlay = w->viewport->overlay;
736 break;
737 }
738 case SC_WORLD: {
739 assert(width == 0 && height == 0);
740
741 /* Determine world coordinates of screenshot */
742 vp->zoom = ZOOM_LVL_WORLD_SCREENSHOT;
743
744 TileIndex north_tile = _settings_game.construction.freeform_edges ? TileXY(1, 1) : TileXY(0, 0);
745 TileIndex south_tile = MapSize() - 1;
746
747 /* We need to account for a hill or high building at tile 0,0. */
748 int extra_height_top = TilePixelHeight(north_tile) + 150;
749 /* If there is a hill at the bottom don't create a large black area. */
750 int reclaim_height_bottom = TilePixelHeight(south_tile);
751
752 vp->virtual_left = RemapCoords(TileX(south_tile) * TILE_SIZE, TileY(north_tile) * TILE_SIZE, 0).x;
753 vp->virtual_top = RemapCoords(TileX(north_tile) * TILE_SIZE, TileY(north_tile) * TILE_SIZE, extra_height_top).y;
754 vp->virtual_width = RemapCoords(TileX(north_tile) * TILE_SIZE, TileY(south_tile) * TILE_SIZE, 0).x - vp->virtual_left + 1;
755 vp->virtual_height = RemapCoords(TileX(south_tile) * TILE_SIZE, TileY(south_tile) * TILE_SIZE, reclaim_height_bottom).y - vp->virtual_top + 1;
756
757 /* Compute pixel coordinates */
758 vp->left = 0;
759 vp->top = 0;
760 vp->width = UnScaleByZoom(vp->virtual_width, vp->zoom);
761 vp->height = UnScaleByZoom(vp->virtual_height, vp->zoom);
762 vp->overlay = nullptr;
763 break;
764 }
765 default: {
766 vp->zoom = (t == SC_ZOOMEDIN) ? _settings_client.gui.zoom_min : ZOOM_LVL_VIEWPORT;
767
768 Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
769 vp->virtual_left = w->viewport->virtual_left;
770 vp->virtual_top = w->viewport->virtual_top;
771
772 if (width == 0 || height == 0) {
773 vp->virtual_width = w->viewport->virtual_width;
774 vp->virtual_height = w->viewport->virtual_height;
775 } else {
776 vp->virtual_width = width << vp->zoom;
777 vp->virtual_height = height << vp->zoom;
778 }
779
780 /* Compute pixel coordinates */
781 vp->left = 0;
782 vp->top = 0;
783 vp->width = UnScaleByZoom(vp->virtual_width, vp->zoom);
784 vp->height = UnScaleByZoom(vp->virtual_height, vp->zoom);
785 vp->overlay = nullptr;
786 break;
787 }
788 }
789 }
790
798 static bool MakeLargeWorldScreenshot(ScreenshotType t, uint32 width = 0, uint32 height = 0)
799 {
800 Viewport vp;
801 SetupScreenshotViewport(t, &vp, width, height);
802
803 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
804 return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), LargeWorldCallback, &vp, vp.width, vp.height,
805 BlitterFactory::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette);
806 }
807
817 static void HeightmapCallback(void *userdata, void *buffer, uint y, uint pitch, uint n)
818 {
819 byte *buf = (byte *)buffer;
820 while (n > 0) {
821 TileIndex ti = TileXY(MapMaxX(), y);
822 for (uint x = MapMaxX(); true; x--) {
823 *buf = 256 * TileHeight(ti) / (1 + _settings_game.construction.max_heightlevel);
824 buf++;
825 if (x == 0) break;
826 ti = TILE_ADDXY(ti, -1, 0);
827 }
828 y++;
829 n--;
830 }
831 }
832
837 bool MakeHeightmapScreenshot(const char *filename)
838 {
839 Colour palette[256];
840 for (uint i = 0; i < lengthof(palette); i++) {
841 palette[i].a = 0xff;
842 palette[i].r = i;
843 palette[i].g = i;
844 palette[i].b = i;
845 }
846 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
847 return sf->proc(filename, HeightmapCallback, nullptr, MapSizeX(), MapSizeY(), 8, palette);
848 }
849
850 static ScreenshotType _confirmed_screenshot_type;
851
857 static void ScreenshotConfirmationCallback(Window *w, bool confirmed)
858 {
859 if (confirmed) MakeScreenshot(_confirmed_screenshot_type, nullptr);
860 }
861
868 void MakeScreenshotWithConfirm(ScreenshotType t)
869 {
870 Viewport vp;
871 SetupScreenshotViewport(t, &vp);
872
873 bool heightmap_or_minimap = t == SC_HEIGHTMAP || t == SC_MINIMAP;
874 uint64_t width = (heightmap_or_minimap ? MapSizeX() : vp.width);
875 uint64_t height = (heightmap_or_minimap ? MapSizeY() : vp.height);
876
877 if (width * height > 8192 * 8192) {
878 /* Ask for confirmation */
879 _confirmed_screenshot_type = t;
880 SetDParam(0, width);
881 SetDParam(1, height);
882 ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmationCallback);
883 } else {
884 /* Less than 64M pixels, just do it */
885 MakeScreenshot(t, nullptr);
886 }
887 }
888
899 bool MakeScreenshot(ScreenshotType t, const char *name, uint32 width, uint32 height)
900 {
901 VideoDriver::VideoBufferLocker lock;
902
903 if (t == SC_VIEWPORT) {
904 /* First draw the dirty parts of the screen and only then change the name
905 * of the screenshot. This way the screenshot will always show the name
906 * of the previous screenshot in the 'successful' message instead of the
907 * name of the new screenshot (or an empty name). */
908 UndrawMouseCursor();
909 DrawDirtyBlocks();
910 }
911
912 _screenshot_name[0] = '\0';
913 if (name != nullptr) strecpy(_screenshot_name, name, lastof(_screenshot_name));
914
915 bool ret;
916 switch (t) {
917 case SC_VIEWPORT:
918 ret = MakeSmallScreenshot(false);
919 break;
920
921 case SC_CRASHLOG:
922 ret = MakeSmallScreenshot(true);
923 break;
924
925 case SC_ZOOMEDIN:
926 case SC_DEFAULTZOOM:
927 ret = MakeLargeWorldScreenshot(t, width, height);
928 break;
929
930 case SC_WORLD:
931 ret = MakeLargeWorldScreenshot(t);
932 break;
933
934 case SC_HEIGHTMAP: {
935 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
936 ret = MakeHeightmapScreenshot(MakeScreenshotName(HEIGHTMAP_NAME, sf->extension));
937 break;
938 }
939
940 case SC_MINIMAP:
941 ret = MakeMinimapWorldScreenshot();
942 break;
943
944 default:
945 NOT_REACHED();
946 }
947
948 if (ret) {
949 SetDParamStr(0, _screenshot_name);
950 ShowErrorMessage(STR_MESSAGE_SCREENSHOT_SUCCESSFULLY, INVALID_STRING_ID, WL_WARNING);
951 } else {
952 ShowErrorMessage(STR_ERROR_SCREENSHOT_FAILED, INVALID_STRING_ID, WL_ERROR);
953 }
954
955 return ret;
956 }
957
958
965 static Owner GetMinimapOwner(TileIndex tile)
966 {
967 Owner o;
968
969 if (IsTileType(tile, MP_VOID)) {
970 return OWNER_END;
971 } else {
972 switch (GetTileType(tile)) {
973 case MP_INDUSTRY: o = OWNER_DEITY; break;
974 case MP_HOUSE: o = OWNER_TOWN; break;
975 default: o = GetTileOwner(tile); break;
976 /* FIXME: For MP_ROAD there are multiple owners.
977 * GetTileOwner returns the rail owner (level crossing) resp. the owner of ROADTYPE_ROAD (normal road),
978 * even if there are no ROADTYPE_ROAD bits on the tile.
979 */
980 }
981
982 return o;
983 }
984 }
985
986 static void MinimapScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
987 {
988 /* Fill with the company colours */
989 byte owner_colours[OWNER_END + 1];
990 for (const Company *c : Company::Iterate()) {
991 owner_colours[c->index] = MKCOLOUR(_colour_gradient[c->colour][5]);
992 }
993
994 /* Fill with some special colours */
995 owner_colours[OWNER_TOWN] = PC_DARK_RED;
996 owner_colours[OWNER_NONE] = PC_GRASS_LAND;
997 owner_colours[OWNER_WATER] = PC_WATER;
998 owner_colours[OWNER_DEITY] = PC_DARK_GREY; // industry
999 owner_colours[OWNER_END] = PC_BLACK;
1000
1001 uint32 *ubuf = (uint32 *)buf;
1002 uint num = (pitch * n);
1003 for (uint i = 0; i < num; i++) {
1004 uint row = y + (int)(i / pitch);
1005 uint col = (MapSizeX() - 1) - (i % pitch);
1006
1007 TileIndex tile = TileXY(col, row);
1008 Owner o = GetMinimapOwner(tile);
1009 byte val = owner_colours[o];
1010
1011 uint32 colour_buf = 0;
1012 colour_buf = (_cur_palette.palette[val].b << 0);
1013 colour_buf |= (_cur_palette.palette[val].g << 8);
1014 colour_buf |= (_cur_palette.palette[val].r << 16);
1015
1016 *ubuf = colour_buf;
1017 ubuf++; // Skip alpha
1018 }
1019 }
1020
1024 bool MakeMinimapWorldScreenshot()
1025 {
1026 const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
1027 return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), MinimapScreenCallback, nullptr, MapSizeX(), MapSizeY(), 32, _cur_palette.palette);
1028 }
MP_HOUSE
@ MP_HOUSE
A house by a town.
Definition: tile_type.h:44
RgbQuad
Format of palette data in BMP header.
Definition: screenshot.cpp:97
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
factory.hpp
SetupScreenshotViewport
void SetupScreenshotViewport(ScreenshotType t, Viewport *vp, uint32 width, uint32 height)
Configure a Viewport for rendering (a part of) the map into a screenshot.
Definition: screenshot.cpp:717
GetMinimapOwner
static Owner GetMinimapOwner(TileIndex tile)
Return the owner of a tile to display it with in the small map in mode "Owner".
Definition: screenshot.cpp:965
ScreenshotType
ScreenshotType
Type of requested screenshot.
Definition: screenshot.h:18
_personal_dir
std::string _personal_dir
custom directory for personal settings, saves, newgrf, etc.
Definition: fileio.cpp:1119
endian_func.hpp
ConstructionSettings::max_heightlevel
uint8 max_heightlevel
maximum allowed heightlevel
Definition: settings_type.h:317
PcxHeader
Definition of a PCX file header.
Definition: screenshot.cpp:406
WL_WARNING
@ WL_WARNING
Other information.
Definition: error.h:23
PC_DARK_RED
static const uint8 PC_DARK_RED
Dark red palette colour.
Definition: gfx_func.h:212
HeightmapCallback
static void HeightmapCallback(void *userdata, void *buffer, uint y, uint pitch, uint n)
Callback for generating a heightmap.
Definition: screenshot.cpp:817
company_base.h
lock
std::mutex lock
synchronization for playback status fields
Definition: win32_m.cpp:34
Blitter
How all blitters should look like.
Definition: base.hpp:28
TilePixelHeight
static uint TilePixelHeight(TileIndex tile)
Returns the height of a tile in pixels.
Definition: tile_map.h:72
Viewport::width
int width
Screen width of the viewport.
Definition: viewport_type.h:25
SC_HEIGHTMAP
@ SC_HEIGHTMAP
Heightmap of the world.
Definition: screenshot.h:24
RemapCoords
static Point RemapCoords(int x, int y, int z)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
Definition: landscape.h:82
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:326
Blitter::GetScreenDepth
virtual uint8 GetScreenDepth()=0
Get the screen depth this blitter works for.
Viewport::height
int height
Screen height of the viewport.
Definition: viewport_type.h:26
Viewport::top
int top
Screen coordinate top edge of the viewport.
Definition: viewport_type.h:24
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1133
BitmapInfoHeader
BMP Info Header (stored in little endian)
Definition: screenshot.cpp:88
saveload.h
zoom_func.h
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:13
fileio_func.h
base_media_base.h
BaseSet::version
uint32 version
The version of this base set.
Definition: base_media_base.h:64
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
SC_ZOOMEDIN
@ SC_ZOOMEDIN
Fully zoomed in screenshot of the visible area.
Definition: screenshot.h:21
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:49
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
PC_GRASS_LAND
static const uint8 PC_GRASS_LAND
Dark green palette colour for grass land.
Definition: gfx_func.h:230
newgrf_config.h
ScreenshotFormat::extension
const char * extension
File extension.
Definition: screenshot.cpp:68
Viewport::virtual_top
int virtual_top
Virtual top coordinate.
Definition: viewport_type.h:29
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:52
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
MakeHeightmapScreenshot
bool MakeHeightmapScreenshot(const char *filename)
Make a heightmap of the current map.
Definition: screenshot.cpp:837
InitializeScreenshotFormats
void InitializeScreenshotFormats()
Initialize screenshot format information on startup, with _screenshot_format_name filled from the loa...
Definition: screenshot.cpp:582
textbuf_gui.h
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:372
ai_info.hpp
screenshot.h
gfx_func.h
MapSizeX
static uint MapSizeX()
Get the size of the map along the X.
Definition: map_func.h:72
_confirmed_screenshot_type
static ScreenshotType _confirmed_screenshot_type
Screenshot type the current query is about to confirm.
Definition: screenshot.cpp:850
window_gui.h
Viewport
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
tile_map.h
_screenshot_name
static char _screenshot_name[128]
Filename of the screenshot file.
Definition: screenshot.cpp:40
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
Align
static T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
Definition: math_func.hpp:35
TileHeight
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:29
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:152
Viewport::virtual_left
int virtual_left
Virtual left coordinate.
Definition: viewport_type.h:28
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
_screen_disable_anim
bool _screen_disable_anim
Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
Definition: gfx.cpp:43
Viewport::left
int left
Screen coordinate left edge of the viewport.
Definition: viewport_type.h:23
Palette::palette
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Definition: gfx_type.h:314
FileExists
bool FileExists(const std::string &filename)
Test whether the given filename exists.
Definition: fileio.cpp:280
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:80
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:140
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
safeguards.h
ScreenshotHandlerProc
bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
Function signature for a screenshot generation routine for one of the available formats.
Definition: screenshot.cpp:64
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition: settings_type.h:329
ScreenshotFormat
Screenshot format information.
Definition: screenshot.cpp:67
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:60
DrawDirtyBlocks
void DrawDirtyBlocks()
Repaints the rectangle blocks which are marked as 'dirty'.
Definition: gfx.cpp:1465
ScreenshotCallback
void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
Callback function signature for generating lines of pixel data to be written to the screenshot file.
Definition: screenshot.cpp:51
_num_screenshot_formats
uint _num_screenshot_formats
Number of available screenshot formats.
Definition: screenshot.cpp:38
CurrentScreenCallback
static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
Callback of the screenshot generator that dumps the current video buffer.
Definition: screenshot.cpp:599
MakeScreenshotName
static const char * MakeScreenshotName(const char *default_fn, const char *ext, bool crashlog=false)
Construct a pathname for a screenshot file.
Definition: screenshot.cpp:669
Viewport::virtual_width
int virtual_width
width << zoom
Definition: viewport_type.h:30
ZOOM_LVL_WORLD_SCREENSHOT
@ ZOOM_LVL_WORLD_SCREENSHOT
Default zoom level for the world screen shot.
Definition: zoom_type.h:43
error.h
MapSizeY
static uint MapSizeY()
Get the size of the map along the Y.
Definition: map_func.h:82
UnScaleByZoom
static int UnScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift right (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Definition: zoom_func.h:34
stdafx.h
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:206
ZOOM_LVL_VIEWPORT
@ ZOOM_LVL_VIEWPORT
Default zoom level for viewports.
Definition: zoom_type.h:35
landscape.h
BSWAP32
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
Definition: bitmath_func.hpp:380
ScreenshotFormat::proc
ScreenshotHandlerProc * proc
Function for writing the screenshot.
Definition: screenshot.cpp:69
viewport_func.h
Blitter::CopyImageToBuffer
virtual void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)=0
Copy from the screen to a buffer in a palette format for 8bpp and RGBA format for 32bpp.
PACK
PACK(struct BitmapFileHeader { uint16 type;uint32 size;uint32 reserved;uint32 off_bits;})
BMP File Header (stored in little endian)
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
GenerateDefaultSaveName
void GenerateDefaultSaveName(char *buf, const char *last)
Fill the buffer with the default name for a savegame or screenshot.
Definition: saveload.cpp:2861
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
Colour
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Definition: gfx_type.h:163
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition: settings_type.h:118
LargeWorldCallback
static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
generate a large piece of the world
Definition: screenshot.cpp:614
_screenshot_formats
static const ScreenshotFormat _screenshot_formats[]
Available screenshot formats.
Definition: screenshot.cpp:567
ShowQuery
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard 'yes' and 'no' buttons The window is aligned to the ce...
Definition: misc_gui.cpp:1274
MakeLargeWorldScreenshot
static bool MakeLargeWorldScreenshot(ScreenshotType t, uint32 width=0, uint32 height=0)
Make a screenshot of the map.
Definition: screenshot.cpp:798
rev.h
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
MakeBMPImage
static bool MakeBMPImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
Generic .BMP writer.
Definition: screenshot.cpp:114
strings_func.h
MakeScreenshot
bool MakeScreenshot(ScreenshotType t, const char *name, uint32 width, uint32 height)
Make a screenshot.
Definition: screenshot.cpp:899
ScaleByZoom
static int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Definition: zoom_func.h:22
SC_WORLD
@ SC_WORLD
World screenshot.
Definition: screenshot.h:23
MakePCXImage
static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
Generic .PCX file image writer.
Definition: screenshot.cpp:437
HEIGHTMAP_NAME
static const char *const HEIGHTMAP_NAME
Default filename of a saved heightmap.
Definition: screenshot.cpp:35
Colour::a
uint8 a
colour channels in LE order
Definition: gfx_type.h:171
MP_VOID
@ MP_VOID
Invisible tiles at the SW and SE border.
Definition: tile_type.h:48
Blitter::MoveTo
virtual void * MoveTo(void *video, int x, int y)=0
Move the destination pointer the requested amount x and y, keeping in mind any pitch and bpp of the r...
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
video_driver.hpp
COMPANY_SPECTATOR
@ COMPANY_SPECTATOR
The client is spectating.
Definition: company_type.h:35
GRFConfig::next
struct GRFConfig * next
NOSAVE: Next item in the linked list.
Definition: newgrf_config.h:177
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
MakePNGImage
static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
Generic .PNG file image writer.
Definition: screenshot.cpp:260
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:442
SC_DEFAULTZOOM
@ SC_DEFAULTZOOM
Zoomed to default zoom level screenshot of the visible area.
Definition: screenshot.h:22
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:27
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:44
_screenshot_format_name
char _screenshot_format_name[8]
Extension of the current screenshot format (corresponds with _cur_screenshot_format).
Definition: screenshot.cpp:37
MakeSmallScreenshot
static bool MakeSmallScreenshot(bool crashlog)
Make a screenshot of the current screen.
Definition: screenshot.cpp:703
company_func.h
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:24
_full_screenshot_name
char _full_screenshot_name[MAX_PATH]
Pathname of the screenshot file.
Definition: screenshot.cpp:41
MapMaxX
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
PC_WATER
static const uint8 PC_WATER
Dark blue palette colour for water.
Definition: gfx_func.h:235
MakeMinimapWorldScreenshot
bool MakeMinimapWorldScreenshot()
Make a minimap screenshot.
Definition: screenshot.cpp:1024
TILE_ADDXY
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:258
_cur_palette
Palette _cur_palette
Current palette.
Definition: gfx.cpp:48
_grfconfig
GRFConfig * _grfconfig
First item in list of current GRF set up.
Definition: newgrf_config.cpp:170
_cur_screenshot_format
uint _cur_screenshot_format
Index of the currently selected screenshot format in _screenshot_formats.
Definition: screenshot.cpp:39
window_func.h
GetCurrentScreenshotExtension
const char * GetCurrentScreenshotExtension()
Get filename extension of current screenshot file format.
Definition: screenshot.cpp:576
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
Viewport::zoom
ZoomLevel zoom
The zoom level of the viewport.
Definition: viewport_type.h:33
SC_VIEWPORT
@ SC_VIEWPORT
Screenshot of viewport.
Definition: screenshot.h:19
MakeScreenshotWithConfirm
void MakeScreenshotWithConfirm(ScreenshotType t)
Make a screenshot.
Definition: screenshot.cpp:868
OWNER_END
@ OWNER_END
Last + 1 owner.
Definition: company_type.h:28
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:561
Window
Data structure for an opened window.
Definition: window_gui.h:276
md5sumToString
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
Definition: string.cpp:460
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
SC_CRASHLOG
@ SC_CRASHLOG
Raw screenshot from blitter buffer.
Definition: screenshot.h:20
BaseMedia< GraphicsSet >::GetUsedSet
static const GraphicsSet * GetUsedSet()
Return the used set.
Definition: base_media_func.h:357
PC_DARK_GREY
static const uint8 PC_DARK_GREY
Dark grey palette colour.
Definition: gfx_func.h:207
Viewport::virtual_height
int virtual_height
height << zoom
Definition: viewport_type.h:31
SC_MINIMAP
@ SC_MINIMAP
Minimap screenshot.
Definition: screenshot.h:25
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:112
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:454
SCREENSHOT_NAME
static const char *const SCREENSHOT_NAME
Default filename of a saved screenshot.
Definition: screenshot.cpp:34
Company
Definition: company_base.h:110
OWNER_WATER
@ OWNER_WATER
The tile/execution is done by "water".
Definition: company_type.h:26
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:383
VideoDriver::VideoBufferLocker
Helper struct to ensure the video buffer is locked and ready for drawing.
Definition: video_driver.hpp:195
OWNER_TOWN
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:286
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:577
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:155
FiosGetScreenshotDir
const char * FiosGetScreenshotDir()
Get the directory for screenshots.
Definition: fios.cpp:628
ScreenshotConfirmationCallback
static void ScreenshotConfirmationCallback(Window *w, bool confirmed)
Callback on the confirmation window for huge screenshots.
Definition: screenshot.cpp:857
AllocaM
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro
Definition: alloc_func.hpp:132