MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / RealMakeScreenshot

Function RealMakeScreenshot

src/screenshot.cpp:381–444  ·  view source on GitHub ↗

* Make a screenshot. * @param t the type of screenshot to make. * @param name the name to give to the screenshot. * @param width the width of the screenshot of, or 0 for current viewport width (only works for SC_ZOOMEDIN and SC_DEFAULTZOOM). * @param height the height of the screenshot of, or 0 for current viewport height (only works for SC_ZOOMEDIN and SC_DEFAULTZOOM). * @return true iff

Source from the content-addressed store, hash-verified

379 * @return true iff the screenshot was made successfully
380 */
381static bool RealMakeScreenshot(ScreenshotType t, const std::string &name, uint32_t width, uint32_t height)
382{
383 if (t == SC_VIEWPORT) {
384 /* First draw the dirty parts of the screen and only then change the name
385 * of the screenshot. This way the screenshot will always show the name
386 * of the previous screenshot in the 'successful' message instead of the
387 * name of the new screenshot (or an empty name). */
388 SetScreenshotWindowVisibility(true);
389 UndrawMouseCursor();
390 DrawDirtyBlocks();
391 SetScreenshotWindowVisibility(false);
392 }
393
394 _screenshot_name = name;
395
396 bool ret;
397 switch (t) {
398 case SC_VIEWPORT:
399 ret = MakeSmallScreenshot(false);
400 break;
401
402 case SC_CRASHLOG:
403 ret = MakeSmallScreenshot(true);
404 break;
405
406 case SC_ZOOMEDIN:
407 case SC_DEFAULTZOOM:
408 ret = MakeLargeWorldScreenshot(t, width, height);
409 break;
410
411 case SC_WORLD:
412 ret = MakeLargeWorldScreenshot(t);
413 break;
414
415 case SC_HEIGHTMAP: {
416 auto provider = GetScreenshotProvider();
417 if (provider == nullptr) {
418 ret = false;
419 } else {
420 ret = MakeHeightmapScreenshot(MakeScreenshotName(HEIGHTMAP_NAME, provider->GetName()));
421 }
422 break;
423 }
424
425 case SC_MINIMAP:
426 ret = MakeMinimapWorldScreenshot();
427 break;
428
429 default:
430 NOT_REACHED();
431 }
432
433 if (ret) {
434 if (t == SC_HEIGHTMAP) {
435 ShowErrorMessage(GetEncodedString(STR_MESSAGE_HEIGHTMAP_SUCCESSFULLY, _screenshot_name, _heightmap_highest_peak), {}, WL_WARNING);
436 } else {
437 ShowErrorMessage(GetEncodedString(STR_MESSAGE_SCREENSHOT_SUCCESSFULLY, _screenshot_name), {}, WL_WARNING);
438 }

Callers 1

MakeScreenshotFunction · 0.85

Calls 13

UndrawMouseCursorFunction · 0.85
DrawDirtyBlocksFunction · 0.85
MakeSmallScreenshotFunction · 0.85
MakeLargeWorldScreenshotFunction · 0.85
GetScreenshotProviderFunction · 0.85
MakeHeightmapScreenshotFunction · 0.85
MakeScreenshotNameFunction · 0.85
NOT_REACHEDFunction · 0.85
ShowErrorMessageFunction · 0.85
GetEncodedStringFunction · 0.70

Tested by

no test coverage detected