diff options
author | rubidium <rubidium@openttd.org> | 2009-12-19 19:21:37 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-12-19 19:21:37 +0000 |
commit | a6146f5f516ce08dfb9c5ad62b260ba2e3ae8010 (patch) | |
tree | c9d60cba50de218e9bc3a85a2e140cbb6eb4aa82 | |
parent | 29d6491605bb13e7a751b2a1a8b8728f17bbc54b (diff) | |
download | openttd-a6146f5f516ce08dfb9c5ad62b260ba2e3ae8010.tar.xz |
(svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested.
-rw-r--r-- | src/console_cmds.cpp | 3 | ||||
-rw-r--r-- | src/crashlog.cpp | 3 | ||||
-rw-r--r-- | src/openttd.cpp | 14 | ||||
-rw-r--r-- | src/screenshot.cpp | 54 | ||||
-rw-r--r-- | src/screenshot.h | 5 | ||||
-rw-r--r-- | src/toolbar_gui.cpp | 4 |
6 files changed, 38 insertions, 45 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index bb0ae0310..70b251ac6 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -1236,8 +1236,7 @@ DEF_CONSOLE_CMD(ConScreenShot) } } - RequestScreenshot(type, name); - + MakeScreenshot(type, name); return true; } diff --git a/src/crashlog.cpp b/src/crashlog.cpp index 7b0ced062..2dec5ab38 100644 --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -262,8 +262,7 @@ bool CrashLog::WriteScreenshot(char *filename, const char *filename_last) const /* Don't draw when we have invalid screen size */ if (_screen.width < 1 || _screen.height < 1 || _screen.dst_ptr == NULL) return false; - RequestScreenshot(SC_RAW, "crash"); - bool res = MakeScreenshot(); + bool res = MakeScreenshot(SC_RAW, "crash"); if (res) strecpy(filename, _full_screenshot_name, filename_last); return res; } diff --git a/src/openttd.cpp b/src/openttd.cpp index 2f632b4be..46999783c 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -768,17 +768,6 @@ void HandleExitGameRequest() } } -static void ShowScreenshotResult(bool b) -{ - if (b) { - SetDParamStr(0, _screenshot_name); - ShowErrorMessage(STR_MESSAGE_SCREENSHOT_SUCCESSFULLY, INVALID_STRING_ID, 0, 0); - } else { - ShowErrorMessage(STR_ERROR_SCREENSHOT_FAILED, INVALID_STRING_ID, 0, 0); - } - -} - static void MakeNewGameDone() { SettingsDisableElrail(_settings_game.vehicle.disable_elrails); @@ -1239,9 +1228,6 @@ void GameLoop() RedrawAutosave(); } - /* make a screenshot? */ - if (IsScreenshotRequested()) ShowScreenshotResult(MakeScreenshot()); - /* switch game mode? */ if (_switch_mode != SM_NONE) { SwitchToMode(_switch_mode); diff --git a/src/screenshot.cpp b/src/screenshot.cpp index 05f2881a5..329ed0160 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -21,6 +21,10 @@ #include "map_func.h" #include "saveload/saveload.h" #include "company_func.h" +#include "strings_func.h" +#include "gui.h" + +#include "table/strings.h" char _screenshot_format_name[8]; @@ -28,7 +32,6 @@ uint _num_screenshot_formats; uint _cur_screenshot_format; char _screenshot_name[128]; char _full_screenshot_name[MAX_PATH]; -static ScreenshotType _screenshot_type; /* called by the ScreenShot proc to generate screenshot lines. */ typedef void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n); @@ -493,7 +496,6 @@ void InitializeScreenshotFormats() } _cur_screenshot_format = j; _num_screenshot_formats = lengthof(_screenshot_formats); - _screenshot_type = SC_NONE; } const char *GetScreenshotFormatDesc(int i) @@ -601,18 +603,6 @@ static const char *MakeScreenshotName(const char *ext) return _full_screenshot_name; } -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() -{ - return (_screenshot_type != SC_NONE); -} - static bool MakeSmallScreenshot() { const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; @@ -638,19 +628,41 @@ static bool MakeWorldScreenshot() return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); } -bool MakeScreenshot() +/** + * Make an actual screenshot. + * @param t the type of screenshot to make. + * @param name the name to give to the screenshot. + * @return true iff the screenshow was made succesfully + */ +bool MakeScreenshot(ScreenshotType t, const char *name) { - switch (_screenshot_type) { + _screenshot_name[0] = '\0'; + if (name != NULL) strecpy(_screenshot_name, name, lastof(_screenshot_name)); + + bool ret; + switch (t) { case SC_VIEWPORT: UndrawMouseCursor(); DrawDirtyBlocks(); /* FALL THROUGH */ case SC_RAW: - _screenshot_type = SC_NONE; - return MakeSmallScreenshot(); + ret = MakeSmallScreenshot(); + break; + case SC_WORLD: - _screenshot_type = SC_NONE; - return MakeWorldScreenshot(); - default: return false; + ret = MakeWorldScreenshot(); + break; + + default: + NOT_REACHED(); } + + if (ret) { + SetDParamStr(0, _screenshot_name); + ShowErrorMessage(STR_MESSAGE_SCREENSHOT_SUCCESSFULLY, INVALID_STRING_ID, 0, 0); + } else { + ShowErrorMessage(STR_ERROR_SCREENSHOT_FAILED, INVALID_STRING_ID, 0, 0); + } + + return ret; } diff --git a/src/screenshot.h b/src/screenshot.h index 81b97f9ad..2ceac4486 100644 --- a/src/screenshot.h +++ b/src/screenshot.h @@ -19,15 +19,12 @@ void SetScreenshotFormat(int i); /** Type of requested screenshot */ enum ScreenshotType { - SC_NONE, ///< No screenshot requested SC_VIEWPORT, ///< Screenshot of viewport SC_RAW, ///< Raw screenshot from blitter buffer SC_WORLD, ///< World screenshot }; -bool MakeScreenshot(); -void RequestScreenshot(ScreenshotType t, const char *name); -bool IsScreenshotRequested(); +bool MakeScreenshot(ScreenshotType t, const char *name); extern char _screenshot_format_name[8]; extern uint _num_screenshot_formats; diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 0190e9ec6..3f4d8e1b0 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -756,12 +756,12 @@ static void ToolbarHelpClick(Window *w) static void MenuClickSmallScreenshot() { - RequestScreenshot(SC_VIEWPORT, NULL); + MakeScreenshot(SC_VIEWPORT, NULL); } static void MenuClickWorldScreenshot() { - RequestScreenshot(SC_WORLD, NULL); + MakeScreenshot(SC_WORLD, NULL); } static void MenuClickHelp(int index) |