OpenTTD Source 20250428-master-ga5578166bb
screenshot.cpp File Reference

The creation of screenshots! More...

#include "stdafx.h"
#include "core/backup_type.hpp"
#include "fileio_func.h"
#include "viewport_func.h"
#include "gfx_func.h"
#include "screenshot.h"
#include "screenshot_gui.h"
#include "blitter/factory.hpp"
#include "zoom_func.h"
#include "saveload/saveload.h"
#include "company_func.h"
#include "strings_func.h"
#include "error.h"
#include "textbuf_gui.h"
#include "window_gui.h"
#include "window_func.h"
#include "tile_map.h"
#include "landscape.h"
#include "video/video_driver.hpp"
#include "smallmap_gui.h"
#include "screenshot_type.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Functions

static ScreenshotProviderGetScreenshotProvider ()
 Get the screenshot provider for the selected format.
 
std::string_view GetCurrentScreenshotExtension ()
 Get filename extension of current screenshot file format.
 
static void CurrentScreenCallback (void *buf, uint y, uint pitch, uint n)
 Callback of the screenshot generator that dumps the current video buffer.
 
static void LargeWorldCallback (Viewport &vp, void *buf, uint y, uint pitch, uint n)
 generate a large piece of the world
 
static std::string_view MakeScreenshotName (std::string_view default_fn, std::string_view ext, bool crashlog=false)
 Construct a pathname for a screenshot file.
 
static bool MakeSmallScreenshot (bool crashlog)
 Make a screenshot of the current screen.
 
static Viewport SetupScreenshotViewport (ScreenshotType t, uint32_t width=0, uint32_t height=0)
 Configure a Viewport for rendering (a part of) the map into a screenshot.
 
static bool MakeLargeWorldScreenshot (ScreenshotType t, uint32_t width=0, uint32_t height=0)
 Make a screenshot of the map.
 
static void HeightmapCallback (void *buffer, uint y, uint, uint n)
 Callback for generating a heightmap.
 
bool MakeHeightmapScreenshot (std::string_view filename)
 Make a heightmap of the current map.
 
static void ScreenshotConfirmationCallback (Window *, bool confirmed)
 Callback on the confirmation window for huge screenshots.
 
void MakeScreenshotWithConfirm (ScreenshotType t)
 Make a screenshot.
 
static bool RealMakeScreenshot (ScreenshotType t, const std::string &name, uint32_t width, uint32_t height)
 Make a screenshot.
 
bool MakeScreenshot (ScreenshotType t, const std::string &name, uint32_t width, uint32_t height)
 Schedule making a screenshot.
 
static void MinimapScreenCallback (void *buf, uint y, uint pitch, uint n)
 
bool MakeMinimapWorldScreenshot ()
 Make a minimap screenshot.
 

Variables

static const char *const SCREENSHOT_NAME = "screenshot"
 Default filename of a saved screenshot.
 
static const char *const HEIGHTMAP_NAME = "heightmap"
 Default filename of a saved heightmap.
 
std::string _screenshot_format_name
 Extension of the current screenshot format.
 
static std::string _screenshot_name
 Filename of the screenshot file.
 
std::string _full_screenshot_path
 Pathname of the screenshot file.
 
uint _heightmap_highest_peak
 When saving a heightmap, this contains the highest peak on the map.
 
static ScreenshotType _confirmed_screenshot_type
 Screenshot type the current query is about to confirm.
 

Detailed Description

The creation of screenshots!

Definition in file screenshot.cpp.

Function Documentation

◆ CurrentScreenCallback()

static void CurrentScreenCallback ( void *  buf,
uint  y,
uint  pitch,
uint  n 
)
static

Callback of the screenshot generator that dumps the current video buffer.

See also
ScreenshotCallback

Definition at line 73 of file screenshot.cpp.

References Blitter::CopyImageToBuffer(), BlitterFactory::GetCurrentBlitter(), and Blitter::MoveTo().

Referenced by MakeSmallScreenshot().

◆ GetCurrentScreenshotExtension()

std::string_view GetCurrentScreenshotExtension ( )

Get filename extension of current screenshot file format.

Definition at line 61 of file screenshot.cpp.

References GetScreenshotProvider().

Referenced by FiosMakeHeightmapName().

◆ GetScreenshotProvider()

static ScreenshotProvider * GetScreenshotProvider ( )
static

Get the screenshot provider for the selected format.

If the selected provider is not found, then the first provider will be used instead.

Returns
ScreenshotProvider, or null if none exist.

Definition at line 49 of file screenshot.cpp.

References _screenshot_format_name, and ProviderManager< TProviderType >::GetProviders().

Referenced by GetCurrentScreenshotExtension(), MakeHeightmapScreenshot(), MakeLargeWorldScreenshot(), MakeMinimapWorldScreenshot(), MakeSmallScreenshot(), and RealMakeScreenshot().

◆ HeightmapCallback()

static void HeightmapCallback ( void *  buffer,
uint  y,
uint  ,
uint  n 
)
static

Callback for generating a heightmap.

Supports 8bpp grayscale only.

Parameters
bufferDestination buffer.
yLine number of the first line to write.
nNumber of lines to write.
See also
ScreenshotCallback

Definition at line 294 of file screenshot.cpp.

References _heightmap_highest_peak, Map::MaxX(), TileAddXY(), TileHeight(), and TileXY().

Referenced by MakeHeightmapScreenshot().

◆ LargeWorldCallback()

static void LargeWorldCallback ( Viewport vp,
void *  buf,
uint  y,
uint  pitch,
uint  n 
)
static

generate a large piece of the world

Parameters
vpViewport area to draw
bufVideobuffer with same bitdepth as current blitter
yFirst line to render
pitchPitch of the videobuffer
nNumber of lines to render

Definition at line 88 of file screenshot.cpp.

References _screen_disable_anim, Viewport::left, ScaleByZoom(), Viewport::top, Viewport::virtual_left, Viewport::virtual_top, Viewport::width, Viewport::zoom, ZOOM_LVL_MIN, and ZOOM_LVL_WORLD_SCREENSHOT.

◆ MakeHeightmapScreenshot()

bool MakeHeightmapScreenshot ( std::string_view  filename)

Make a heightmap of the current map.

Parameters
filenameFilename to use for saving.

Definition at line 314 of file screenshot.cpp.

References _heightmap_highest_peak, GetScreenshotProvider(), HeightmapCallback(), Map::Iterate(), lengthof, Map::SizeX(), Map::SizeY(), and TileHeight().

Referenced by RealMakeScreenshot().

◆ MakeLargeWorldScreenshot()

static bool MakeLargeWorldScreenshot ( ScreenshotType  t,
uint32_t  width = 0,
uint32_t  height = 0 
)
static

Make a screenshot of the map.

Parameters
tScreenshot type: World or viewport screenshot
widththe width of the screenshot of, or 0 for current viewport width.
heightthe height of the screenshot of, or 0 for current viewport height.
Returns
true on success

Definition at line 274 of file screenshot.cpp.

References _cur_palette, BlitterFactory::GetCurrentBlitter(), Blitter::GetScreenDepth(), GetScreenshotProvider(), Viewport::height, MakeScreenshotName(), Palette::palette, SCREENSHOT_NAME, SetupScreenshotViewport(), and Viewport::width.

Referenced by RealMakeScreenshot().

◆ MakeMinimapWorldScreenshot()

bool MakeMinimapWorldScreenshot ( )

Make a minimap screenshot.

Definition at line 497 of file screenshot.cpp.

References _cur_palette, GetScreenshotProvider(), MakeScreenshotName(), Palette::palette, SCREENSHOT_NAME, Map::SizeX(), and Map::SizeY().

Referenced by RealMakeScreenshot().

◆ MakeScreenshot()

bool MakeScreenshot ( ScreenshotType  t,
const std::string &  name,
uint32_t  width,
uint32_t  height 
)

Schedule making a screenshot.

Unconditionally take a screenshot of the requested type.

Parameters
tthe type of screenshot to make.
namethe name to give to the screenshot.
widththe width of the screenshot of, or 0 for current viewport width (only works for SC_ZOOMEDIN and SC_DEFAULTZOOM).
heightthe height of the screenshot of, or 0 for current viewport height (only works for SC_ZOOMEDIN and SC_DEFAULTZOOM).
Returns
true iff the screenshot was successfully made.
See also
MakeScreenshotWithConfirm

Definition at line 456 of file screenshot.cpp.

References VideoDriver::GetInstance(), lock, VideoDriver::QueueOnMainThread(), RealMakeScreenshot(), and SC_CRASHLOG.

Referenced by MakeScreenshotWithConfirm(), ScreenshotConfirmationCallback(), and CrashLog::WriteScreenshot().

◆ MakeScreenshotName()

static std::string_view MakeScreenshotName ( std::string_view  default_fn,
std::string_view  ext,
bool  crashlog = false 
)
static

Construct a pathname for a screenshot file.

Parameters
default_fnDefault filename.
extExtension to use.
crashlogCreate path for crash.png
Returns
Pathname for a screenshot file.

Definition at line 135 of file screenshot.cpp.

References _full_screenshot_path, _local_company, _personal_dir, _screenshot_name, COMPANY_SPECTATOR, FileExists(), FiosGetScreenshotDir(), and GenerateDefaultSaveName().

Referenced by MakeLargeWorldScreenshot(), MakeMinimapWorldScreenshot(), MakeSmallScreenshot(), and RealMakeScreenshot().

◆ MakeScreenshotWithConfirm()

void MakeScreenshotWithConfirm ( ScreenshotType  t)

Make a screenshot.

Ask for confirmation first if the screenshot will be huge.

Parameters
tScreenshot type: World, defaultzoom, heightmap or viewport screenshot
See also
MakeScreenshot

Definition at line 353 of file screenshot.cpp.

References _confirmed_screenshot_type, GetEncodedString(), Viewport::height, MakeScreenshot(), SC_HEIGHTMAP, SC_MINIMAP, ScreenshotConfirmationCallback(), SetupScreenshotViewport(), ShowQuery(), Map::SizeX(), Map::SizeY(), and Viewport::width.

Referenced by ScreenshotWindow::OnClick(), MainToolbarWindow::OnHotkey(), and ScenarioEditorToolbarWindow::OnHotkey().

◆ MakeSmallScreenshot()

static bool MakeSmallScreenshot ( bool  crashlog)
static

◆ MinimapScreenCallback()

static void MinimapScreenCallback ( void *  buf,
uint  y,
uint  pitch,
uint  n 
)
static

Definition at line 473 of file screenshot.cpp.

◆ RealMakeScreenshot()

static bool RealMakeScreenshot ( ScreenshotType  t,
const std::string &  name,
uint32_t  width,
uint32_t  height 
)
static

Make a screenshot.

Parameters
tthe type of screenshot to make.
namethe name to give to the screenshot.
widththe width of the screenshot of, or 0 for current viewport width (only works for SC_ZOOMEDIN and SC_DEFAULTZOOM).
heightthe height of the screenshot of, or 0 for current viewport height (only works for SC_ZOOMEDIN and SC_DEFAULTZOOM).
Returns
true iff the screenshot was made successfully

Definition at line 381 of file screenshot.cpp.

References _heightmap_highest_peak, _screenshot_name, DrawDirtyBlocks(), GetEncodedString(), GetScreenshotProvider(), HEIGHTMAP_NAME, MakeHeightmapScreenshot(), MakeLargeWorldScreenshot(), MakeMinimapWorldScreenshot(), MakeScreenshotName(), MakeSmallScreenshot(), SC_CRASHLOG, SC_DEFAULTZOOM, SC_HEIGHTMAP, SC_MINIMAP, SC_VIEWPORT, SC_WORLD, SC_ZOOMEDIN, SetScreenshotWindowVisibility(), ShowErrorMessage(), WL_ERROR, and WL_WARNING.

Referenced by MakeScreenshot().

◆ ScreenshotConfirmationCallback()

static void ScreenshotConfirmationCallback ( Window ,
bool  confirmed 
)
static

Callback on the confirmation window for huge screenshots.

Parameters
confirmedtrue on confirmation

Definition at line 342 of file screenshot.cpp.

References _confirmed_screenshot_type, and MakeScreenshot().

Referenced by MakeScreenshotWithConfirm().

◆ SetupScreenshotViewport()

static Viewport SetupScreenshotViewport ( ScreenshotType  t,
uint32_t  width = 0,
uint32_t  height = 0 
)
static

Configure a Viewport for rendering (a part of) the map into a screenshot.

Parameters
tScreenshot type
widththe width of the screenshot, or 0 for current viewport width (needs to be 0 with SC_VIEWPORT, SC_CRASHLOG, and SC_WORLD).
heightthe height of the screenshot, or 0 for current viewport height (needs to be 0 with SC_VIEWPORT, SC_CRASHLOG, and SC_WORLD).
Returns
Viewport

Definition at line 189 of file screenshot.cpp.

References _settings_client, _settings_game, GameSettings::construction, ConstructionSettings::freeform_edges, GetMainWindow(), ClientSettings::gui, RemapCoords(), SC_CRASHLOG, SC_VIEWPORT, SC_WORLD, SC_ZOOMEDIN, Map::Size(), TILE_SIZE, TilePixelHeight(), TileX(), TileXY(), TileY(), UnScaleByZoom(), Window::viewport, ZOOM_LVL_VIEWPORT, ZOOM_LVL_WORLD_SCREENSHOT, and GUISettings::zoom_min.

Referenced by MakeLargeWorldScreenshot(), and MakeScreenshotWithConfirm().

Variable Documentation

◆ _confirmed_screenshot_type

ScreenshotType _confirmed_screenshot_type
static

Screenshot type the current query is about to confirm.

Definition at line 336 of file screenshot.cpp.

Referenced by MakeScreenshotWithConfirm(), and ScreenshotConfirmationCallback().

◆ _full_screenshot_path

std::string _full_screenshot_path

Pathname of the screenshot file.

Definition at line 41 of file screenshot.cpp.

Referenced by MakeScreenshotName(), and CrashLog::WriteScreenshot().

◆ _heightmap_highest_peak

uint _heightmap_highest_peak

When saving a heightmap, this contains the highest peak on the map.

Definition at line 42 of file screenshot.cpp.

Referenced by HeightmapCallback(), MakeHeightmapScreenshot(), and RealMakeScreenshot().

◆ _screenshot_format_name

std::string _screenshot_format_name

Extension of the current screenshot format.

Definition at line 39 of file screenshot.cpp.

Referenced by GetScreenshotProvider().

◆ _screenshot_name

std::string _screenshot_name
static

Filename of the screenshot file.

Definition at line 40 of file screenshot.cpp.

Referenced by MakeScreenshotName(), and RealMakeScreenshot().

◆ HEIGHTMAP_NAME

const char* const HEIGHTMAP_NAME = "heightmap"
static

Default filename of a saved heightmap.

Definition at line 37 of file screenshot.cpp.

Referenced by RealMakeScreenshot().

◆ SCREENSHOT_NAME

const char* const SCREENSHOT_NAME = "screenshot"
static

Default filename of a saved screenshot.

Definition at line 36 of file screenshot.cpp.

Referenced by MakeLargeWorldScreenshot(), MakeMinimapWorldScreenshot(), and MakeSmallScreenshot().