Skip to content

Commit

Permalink
Cleanup: Remove redundant implementation of TakeScreenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
techgeeknz committed Jun 17, 2020
1 parent 2086143 commit c775f4b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 48 deletions.
1 change: 1 addition & 0 deletions src/screenshot.h
Expand Up @@ -27,6 +27,7 @@ enum ScreenshotType {

void SetupScreenshotViewport(ScreenshotType t, struct ViewPort *vp);
bool MakeHeightmapScreenshot(const char *filename);
void TakeScreenshot(ScreenshotType t);
bool MakeScreenshot(ScreenshotType t, const char *name);
bool MakeMinimapWorldScreenshot();

Expand Down
57 changes: 33 additions & 24 deletions src/screenshot_gui.cpp
Expand Up @@ -20,8 +20,6 @@

#include "table/strings.h"

static ScreenshotType _screenshot_type;

struct ScreenshotWindow : Window {
ScreenshotWindow(WindowDesc *desc) : Window(desc) {
this->CreateNestedTree();
Expand Down Expand Up @@ -50,33 +48,44 @@ struct ScreenshotWindow : Window {
/**
* Make a screenshot.
* Ask for confirmation if the screenshot will be huge.
* @param t Screenshot type: World, defaultzoom, heightmap or viewport screenshot
* @param st 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);
}
::TakeScreenshot(st);
}
};

/**
* 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 ScreenshotType _screenshot_type;

/**
* 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);
}

/**
* Make a screenshot.
* Ask for confirmation if the screenshot will be huge.
* @param t Screenshot type: World, defaultzoom, heightmap or viewport screenshot
*/
void TakeScreenshot(ScreenshotType t) {
ViewPort vp;
SetupScreenshotViewport(t, &vp);
if ((uint64)vp.width * (uint64)vp.height > 8192 * 8192) {
/* Ask for confirmation */
_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);
}
}

static const NWidgetPart _nested_screenshot[] = {
NWidget(NWID_HORIZONTAL),
Expand Down
25 changes: 1 addition & 24 deletions src/toolbar_gui.cpp
Expand Up @@ -66,8 +66,6 @@ RailType _last_built_railtype;
RoadType _last_built_roadtype;
RoadType _last_built_tramtype;

static ScreenshotType _confirmed_screenshot_type; ///< Screenshot type the current query is about to confirm.

/** Toobar modes */
enum ToolbarMode {
TB_NORMAL,
Expand Down Expand Up @@ -1071,35 +1069,14 @@ static CallBackFunction ToolbarHelpClick(Window *w)
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);
}
TakeScreenshot(t);
}

/**
Expand Down

0 comments on commit c775f4b

Please sign in to comment.