File diff r19848:28461ca62457 → r19849:42900960d059
src/screenshot.cpp
Show inline comments
 
@@ -695,15 +695,16 @@ static void LargeWorldCallback(void *use
 
}
 

	
 
/**
 
 * Construct a pathname for a screenshot file.
 
 * @param default_fn Default filename.
 
 * @param ext        Extension to use.
 
 * @param crashlog   Create path for crash.png
 
 * @return Pathname for a screenshot file.
 
 */
 
static const char *MakeScreenshotName(const char *default_fn, const char *ext)
 
static const char *MakeScreenshotName(const char *default_fn, const char *ext, bool crashlog = false)
 
{
 
	bool generate = StrEmpty(_screenshot_name);
 

	
 
	if (generate) {
 
		if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
 
			strecpy(_screenshot_name, default_fn, lastof(_screenshot_name));
 
@@ -713,14 +714,16 @@ static const char *MakeScreenshotName(co
 
	}
 

	
 
	/* Add extension to screenshot file */
 
	size_t len = strlen(_screenshot_name);
 
	snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext);
 

	
 
	const char *screenshot_dir = crashlog ? _personal_dir : FiosGetScreenshotDir();
 

	
 
	for (uint serial = 1;; serial++) {
 
		if (snprintf(_full_screenshot_name, lengthof(_full_screenshot_name), "%s%s", _personal_dir, _screenshot_name) >= (int)lengthof(_full_screenshot_name)) {
 
		if (snprintf(_full_screenshot_name, lengthof(_full_screenshot_name), "%s%s", screenshot_dir, _screenshot_name) >= (int)lengthof(_full_screenshot_name)) {
 
			/* We need more characters than MAX_PATH -> end with error */
 
			_full_screenshot_name[0] = '\0';
 
			break;
 
		}
 
		if (!generate) break; // allow overwriting of non-automatic filenames
 
		if (!FileExists(_full_screenshot_name)) break;
 
@@ -729,16 +732,16 @@ static const char *MakeScreenshotName(co
 
	}
 

	
 
	return _full_screenshot_name;
 
}
 

	
 
/** Make a screenshot of the current screen. */
 
static bool MakeSmallScreenshot()
 
static bool MakeSmallScreenshot(bool crashlog)
 
{
 
	const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
 
	return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height,
 
	return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension, crashlog), CurrentScreenCallback, NULL, _screen.width, _screen.height,
 
			BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette);
 
}
 

	
 
/** Make a zoomed-in screenshot of the currently visible area. */
 
static bool MakeZoomedInScreenshot(ZoomLevel zl)
 
{
 
@@ -848,14 +851,17 @@ bool MakeScreenshot(ScreenshotType t, co
 
	_screenshot_name[0] = '\0';
 
	if (name != NULL) strecpy(_screenshot_name, name, lastof(_screenshot_name));
 

	
 
	bool ret;
 
	switch (t) {
 
		case SC_VIEWPORT:
 
		case SC_RAW:
 
			ret = MakeSmallScreenshot();
 
			ret = MakeSmallScreenshot(false);
 
			break;
 

	
 
		case SC_CRASHLOG:
 
			ret = MakeSmallScreenshot(true);
 
			break;
 

	
 
		case SC_ZOOMEDIN:
 
			ret = MakeZoomedInScreenshot(_settings_client.gui.zoom_min);
 
			break;