diff options
author | TechGeekNZ <git@tech.geek.nz> | 2020-06-18 09:50:22 +1200 |
---|---|---|
committer | Charles Pigott <charlespigott@googlemail.com> | 2020-06-27 14:19:35 +0100 |
commit | ed6f31f601ef92e098f5555e9bb2b1492c5a7e79 (patch) | |
tree | 540359b092a9c4bed40f948037c3027262129e02 /src/screenshot.cpp | |
parent | a2e1102b15cd7f5ae86ab3ea5da4a534b6b58389 (diff) | |
download | openttd-ed6f31f601ef92e098f5555e9bb2b1492c5a7e79.tar.xz |
Cleanup: Remove redundant implementation of TakeScreenshot
Diffstat (limited to 'src/screenshot.cpp')
-rw-r--r-- | src/screenshot.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/screenshot.cpp b/src/screenshot.cpp index 1db7cceae..d2bb6a1f3 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -20,6 +20,7 @@ #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" @@ -831,11 +832,47 @@ bool MakeHeightmapScreenshot(const char *filename) return sf->proc(filename, HeightmapCallback, nullptr, MapSizeX(), MapSizeY(), 8, palette); } +static ScreenshotType _confirmed_screenshot_type; ///< Screenshot type the current query is about to confirm. + +/** + * Callback on the confirmation window for huge screenshots. + * @param w Window with viewport + * @param confirmed true on confirmation + */ +static void ScreenshotConfirmationCallback(Window *w, bool confirmed) +{ + if (confirmed) MakeScreenshot(_confirmed_screenshot_type, nullptr); +} + +/** + * Take a screenshot. + * Ask for confirmation if the screenshot will be huge. Delegates to \c MakeScreenshot to perform the action. + * @param t Screenshot type: World, defaultzoom, heightmap or viewport screenshot + * @see MakeScreenshot + */ +void TakeScreenshot(ScreenshotType t) +{ + ViewPort vp; + SetupScreenshotViewport(t, &vp); + if ((uint64)vp.width * (uint64)vp.height > 8192 * 8192) { + /* Ask for confirmation */ + _confirmed_screenshot_type = t; + SetDParam(0, vp.width); + SetDParam(1, vp.height); + ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmationCallback); + } else { + /* Less than 64M pixels, just do it */ + MakeScreenshot(t, nullptr); + } +} + /** - * Make an actual screenshot. + * Make a screenshot. + * No questions asked, just do it. * @param t the type of screenshot to make. * @param name the name to give to the screenshot. * @return true iff the screenshot was made successfully + * @see TakeScreenshot */ bool MakeScreenshot(ScreenshotType t, const char *name) { |