summaryrefslogtreecommitdiff
path: root/src/screenshot.cpp
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-11-01 18:15:35 +0000
committersmatz <smatz@openttd.org>2009-11-01 18:15:35 +0000
commit090c762921d7452b7f7730016d6a1d385fcfc953 (patch)
tree2c52bd64ede330c0b5b308dfd79d7b0f9606e5a5 /src/screenshot.cpp
parentbe446d6f542fccf1e5cc2ed50225c4a8289aa7dc (diff)
downloadopenttd-090c762921d7452b7f7730016d6a1d385fcfc953.tar.xz
(svn r17938) -Feature: non-automatic screenshot name can be entered in console
Diffstat (limited to 'src/screenshot.cpp')
-rw-r--r--src/screenshot.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/screenshot.cpp b/src/screenshot.cpp
index a9142715c..77d5f4e03 100644
--- a/src/screenshot.cpp
+++ b/src/screenshot.cpp
@@ -539,21 +539,20 @@ static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, ui
static char *MakeScreenshotName(const char *ext)
{
- static char filename[MAX_PATH];
- int serial;
- size_t len;
-
- if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
- strecpy(_screenshot_name, "screenshot", lastof(_screenshot_name));
- } else {
- GenerateDefaultSaveName(_screenshot_name, lastof(_screenshot_name));
+ if (_screenshot_name[0] == '\0') {
+ if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
+ strecpy(_screenshot_name, "screenshot", lastof(_screenshot_name));
+ } else {
+ GenerateDefaultSaveName(_screenshot_name, lastof(_screenshot_name));
+ }
}
/* Add extension to screenshot file */
- len = strlen(_screenshot_name);
+ size_t len = strlen(_screenshot_name);
snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext);
- for (serial = 1;; serial++) {
+ static char filename[20 + 1]; // 1 character more to detect overflow
+ for (uint serial = 1;; serial++) {
if (snprintf(filename, lengthof(filename), "%s%s", _personal_dir, _screenshot_name) >= (int)lengthof(filename)) {
/* We need more characters than MAX_PATH -> end with error */
filename[0] = '\0';
@@ -561,15 +560,17 @@ static char *MakeScreenshotName(const char *ext)
}
if (!FileExists(filename)) break;
/* If file exists try another one with same name, but just with a higher index */
- snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, "#%d.%s", serial, ext);
+ snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, "#%u.%s", serial, ext);
}
return filename;
}
-void SetScreenshotType(ScreenshotType t)
+void RequestScreenshot(ScreenshotType t, const char *name)
{
_screenshot_type = t;
+ _screenshot_name[0] = '\0';
+ if (name != NULL) strecpy(_screenshot_name, name, lastof(_screenshot_name));
}
bool IsScreenshotRequested()