# HG changeset patch # User rubidium # Date 1261250497 0 # Node ID 96fa151f99f9dc4c717058e304c05b0253363d6c # Parent 56eed0602d08ec3521980eafe54d94d44f99bb78 (svn r18546) -Codechange: make making the screenshot not asynchronious; just do it at the moment it's requested. diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -1236,8 +1236,7 @@ } } - RequestScreenshot(type, name); - + MakeScreenshot(type, name); return true; } diff --git a/src/crashlog.cpp b/src/crashlog.cpp --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -262,8 +262,7 @@ /* 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 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -768,17 +768,6 @@ } } -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 @@ 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 --- 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 _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 @@ } _cur_screenshot_format = j; _num_screenshot_formats = lengthof(_screenshot_formats); - _screenshot_type = SC_NONE; } const char *GetScreenshotFormatDesc(int i) @@ -601,18 +603,6 @@ 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 @@ 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 --- a/src/screenshot.h +++ b/src/screenshot.h @@ -19,15 +19,12 @@ /** 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 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -756,12 +756,12 @@ 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)