1
0
Fork 0

Cleanup: Remove redundant implementation of TakeScreenshot

pull/8246/head
TechGeekNZ 2020-06-18 09:50:22 +12:00 committed by Charles Pigott
parent a2e1102b15
commit ed6f31f601
4 changed files with 55 additions and 84 deletions

View File

@ -20,6 +20,7 @@
#include "company_func.h" #include "company_func.h"
#include "strings_func.h" #include "strings_func.h"
#include "error.h" #include "error.h"
#include "textbuf_gui.h"
#include "window_gui.h" #include "window_gui.h"
#include "window_func.h" #include "window_func.h"
#include "tile_map.h" #include "tile_map.h"
@ -831,11 +832,47 @@ bool MakeHeightmapScreenshot(const char *filename)
return sf->proc(filename, HeightmapCallback, nullptr, MapSizeX(), MapSizeY(), 8, palette); return sf->proc(filename, HeightmapCallback, nullptr, MapSizeX(), MapSizeY(), 8, palette);
} }
static ScreenshotType _confirmed_screenshot_type; ///< Screenshot type the current query is about to confirm.
/** /**
* Make an actual screenshot. * 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 a screenshot.
* No questions asked, just do it.
* @param t the type of screenshot to make. * @param t the type of screenshot to make.
* @param name the name to give to the screenshot. * @param name the name to give to the screenshot.
* @return true iff the screenshot was made successfully * @return true iff the screenshot was made successfully
* @see TakeScreenshot
*/ */
bool MakeScreenshot(ScreenshotType t, const char *name) bool MakeScreenshot(ScreenshotType t, const char *name)
{ {

View File

@ -27,6 +27,7 @@ enum ScreenshotType {
void SetupScreenshotViewport(ScreenshotType t, struct ViewPort *vp); void SetupScreenshotViewport(ScreenshotType t, struct ViewPort *vp);
bool MakeHeightmapScreenshot(const char *filename); bool MakeHeightmapScreenshot(const char *filename);
void TakeScreenshot(ScreenshotType t);
bool MakeScreenshot(ScreenshotType t, const char *name); bool MakeScreenshot(ScreenshotType t, const char *name);
bool MakeMinimapWorldScreenshot(); bool MakeMinimapWorldScreenshot();

View File

@ -8,31 +8,26 @@
/** @file screenshot_gui.cpp GUI functions related to screenshots. */ /** @file screenshot_gui.cpp GUI functions related to screenshots. */
#include "stdafx.h" #include "stdafx.h"
#include "gui.h"
#include "viewport_func.h"
#include "window_func.h" #include "window_func.h"
#include "window_gui.h" #include "window_gui.h"
#include "screenshot.h" #include "screenshot.h"
#include "textbuf_gui.h"
#include "strings_func.h"
#include "widgets/screenshot_widget.h" #include "widgets/screenshot_widget.h"
#include "table/strings.h" #include "table/strings.h"
static ScreenshotType _screenshot_type;
struct ScreenshotWindow : Window { struct ScreenshotWindow : Window {
ScreenshotWindow(WindowDesc *desc) : Window(desc) { ScreenshotWindow(WindowDesc *desc) : Window(desc)
{
this->CreateNestedTree(); this->CreateNestedTree();
this->FinishInitNested(); this->FinishInitNested();
} }
void OnPaint() override { void OnPaint() override
{
this->DrawWidgets(); this->DrawWidgets();
} }
void OnClick(Point pt, int widget, int click_count) override { void OnClick(Point pt, int widget, int click_count) override
{
if (widget < 0) return; if (widget < 0) return;
ScreenshotType st; ScreenshotType st;
switch (widget) { switch (widget) {
@ -46,36 +41,6 @@ struct ScreenshotWindow : Window {
} }
TakeScreenshot(st); TakeScreenshot(st);
} }
/**
* Make a screenshot.
* Ask for confirmation if the screenshot will be huge.
* @param t Screenshot type: World, defaultzoom, heightmap or viewport screenshot
*/
static void TakeScreenshot(ScreenshotType st) {
ViewPort vp;
SetupScreenshotViewport(st, &vp);
if ((uint64)vp.width * (uint64)vp.height > 8192 * 8192) {
/* Ask for confirmation */
_screenshot_type = st;
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(st, nullptr);
}
}
/**
* 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(_screenshot_type, nullptr);
}
}; };
static const NWidgetPart _nested_screenshot[] = { static const NWidgetPart _nested_screenshot[] = {
@ -102,7 +67,8 @@ static WindowDesc _screenshot_window_desc(
_nested_screenshot, lengthof(_nested_screenshot) _nested_screenshot, lengthof(_nested_screenshot)
); );
void ShowScreenshotWindow() { void ShowScreenshotWindow()
{
DeleteWindowById(WC_SCREENSHOT, 0); DeleteWindowById(WC_SCREENSHOT, 0);
new ScreenshotWindow(&_screenshot_window_desc); new ScreenshotWindow(&_screenshot_window_desc);
} }

View File

@ -66,8 +66,6 @@ RailType _last_built_railtype;
RoadType _last_built_roadtype; RoadType _last_built_roadtype;
RoadType _last_built_tramtype; RoadType _last_built_tramtype;
static ScreenshotType _confirmed_screenshot_type; ///< Screenshot type the current query is about to confirm.
/** Toobar modes */ /** Toobar modes */
enum ToolbarMode { enum ToolbarMode {
TB_NORMAL, TB_NORMAL,
@ -1071,37 +1069,6 @@ static CallBackFunction ToolbarHelpClick(Window *w)
return CBF_NONE; return CBF_NONE;
} }
/**
* Callback on the confirmation window for huge screenshots.
* @param w Window with viewport
* @param confirmed true on confirmation
*/
static void ScreenshotConfirmCallback(Window *w, bool confirmed)
{
if (confirmed) MakeScreenshot(_confirmed_screenshot_type, nullptr);
}
/**
* Make a screenshot of the world.
* Ask for confirmation if the screenshot will be huge.
* @param t Screenshot type: World or viewport screenshot
*/
static void MenuClickScreenshot(ScreenshotType t)
{
ViewPort vp;
SetupScreenshotViewport(t, &vp);
if ((uint64)vp.width * (uint64)vp.height > 8192 * 8192) {
/* Ask for confirmation */
SetDParam(0, vp.width);
SetDParam(1, vp.height);
_confirmed_screenshot_type = t;
ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmCallback);
} else {
/* Less than 64M pixels, just do it */
MakeScreenshot(t, nullptr);
}
}
/** /**
* Toggle drawing of sprites' bounding boxes. * Toggle drawing of sprites' bounding boxes.
* @note has only an effect when newgrf_developer_tools are active. * @note has only an effect when newgrf_developer_tools are active.
@ -2119,10 +2086,10 @@ struct MainToolbarWindow : Window {
case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break; case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break;
case MTHK_MUSIC: ShowMusicWindow(); break; case MTHK_MUSIC: ShowMusicWindow(); break;
case MTHK_AI_DEBUG: ShowAIDebugWindow(); break; case MTHK_AI_DEBUG: ShowAIDebugWindow(); break;
case MTHK_SMALL_SCREENSHOT: MenuClickScreenshot(SC_VIEWPORT); break; case MTHK_SMALL_SCREENSHOT: TakeScreenshot(SC_VIEWPORT); break;
case MTHK_ZOOMEDIN_SCREENSHOT: MenuClickScreenshot(SC_ZOOMEDIN); break; case MTHK_ZOOMEDIN_SCREENSHOT: TakeScreenshot(SC_ZOOMEDIN); break;
case MTHK_DEFAULTZOOM_SCREENSHOT: MenuClickScreenshot(SC_DEFAULTZOOM); break; case MTHK_DEFAULTZOOM_SCREENSHOT: TakeScreenshot(SC_DEFAULTZOOM); break;
case MTHK_GIANT_SCREENSHOT: MenuClickScreenshot(SC_WORLD); break; case MTHK_GIANT_SCREENSHOT: TakeScreenshot(SC_WORLD); break;
case MTHK_CHEATS: if (!_networking) ShowCheatWindow(); break; case MTHK_CHEATS: if (!_networking) ShowCheatWindow(); break;
case MTHK_TERRAFORM: ShowTerraformToolbar(); break; case MTHK_TERRAFORM: ShowTerraformToolbar(); break;
case MTHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break; case MTHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
@ -2494,10 +2461,10 @@ struct ScenarioEditorToolbarWindow : Window {
case MTEHK_SIGN: cbf = ToolbarScenPlaceSign(this); break; case MTEHK_SIGN: cbf = ToolbarScenPlaceSign(this); break;
case MTEHK_MUSIC: ShowMusicWindow(); break; case MTEHK_MUSIC: ShowMusicWindow(); break;
case MTEHK_LANDINFO: cbf = PlaceLandBlockInfo(); break; case MTEHK_LANDINFO: cbf = PlaceLandBlockInfo(); break;
case MTEHK_SMALL_SCREENSHOT: MenuClickScreenshot(SC_VIEWPORT); break; case MTEHK_SMALL_SCREENSHOT: TakeScreenshot(SC_VIEWPORT); break;
case MTEHK_ZOOMEDIN_SCREENSHOT: MenuClickScreenshot(SC_ZOOMEDIN); break; case MTEHK_ZOOMEDIN_SCREENSHOT: TakeScreenshot(SC_ZOOMEDIN); break;
case MTEHK_DEFAULTZOOM_SCREENSHOT: MenuClickScreenshot(SC_DEFAULTZOOM); break; case MTEHK_DEFAULTZOOM_SCREENSHOT: TakeScreenshot(SC_DEFAULTZOOM); break;
case MTEHK_GIANT_SCREENSHOT: MenuClickScreenshot(SC_WORLD); break; case MTEHK_GIANT_SCREENSHOT: TakeScreenshot(SC_WORLD); break;
case MTEHK_ZOOM_IN: ToolbarZoomInClick(this); break; case MTEHK_ZOOM_IN: ToolbarZoomInClick(this); break;
case MTEHK_ZOOM_OUT: ToolbarZoomOutClick(this); break; case MTEHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
case MTEHK_TERRAFORM: ShowEditorTerraformToolbar(); break; case MTEHK_TERRAFORM: ShowEditorTerraformToolbar(); break;