summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/screenshot.cpp39
-rw-r--r--src/screenshot.h1
-rw-r--r--src/screenshot_gui.cpp50
-rw-r--r--src/toolbar_gui.cpp49
4 files changed, 55 insertions, 84 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)
{
diff --git a/src/screenshot.h b/src/screenshot.h
index aea08a8d5..2f6324c22 100644
--- a/src/screenshot.h
+++ b/src/screenshot.h
@@ -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();
diff --git a/src/screenshot_gui.cpp b/src/screenshot_gui.cpp
index 323002024..ae5854fb7 100644
--- a/src/screenshot_gui.cpp
+++ b/src/screenshot_gui.cpp
@@ -8,31 +8,26 @@
/** @file screenshot_gui.cpp GUI functions related to screenshots. */
#include "stdafx.h"
-#include "gui.h"
-#include "viewport_func.h"
#include "window_func.h"
#include "window_gui.h"
#include "screenshot.h"
-#include "textbuf_gui.h"
-#include "strings_func.h"
-
#include "widgets/screenshot_widget.h"
-
#include "table/strings.h"
-static ScreenshotType _screenshot_type;
-
struct ScreenshotWindow : Window {
- ScreenshotWindow(WindowDesc *desc) : Window(desc) {
+ ScreenshotWindow(WindowDesc *desc) : Window(desc)
+ {
this->CreateNestedTree();
this->FinishInitNested();
}
- void OnPaint() override {
+ void OnPaint() override
+ {
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;
ScreenshotType st;
switch (widget) {
@@ -46,36 +41,6 @@ struct ScreenshotWindow : Window {
}
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[] = {
@@ -102,7 +67,8 @@ static WindowDesc _screenshot_window_desc(
_nested_screenshot, lengthof(_nested_screenshot)
);
-void ShowScreenshotWindow() {
+void ShowScreenshotWindow()
+{
DeleteWindowById(WC_SCREENSHOT, 0);
new ScreenshotWindow(&_screenshot_window_desc);
}
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index 303e4c729..4d97abb72 100644
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -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,
@@ -1072,37 +1070,6 @@ static CallBackFunction ToolbarHelpClick(Window *w)
}
/**
- * 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.
* @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_MUSIC: ShowMusicWindow(); break;
case MTHK_AI_DEBUG: ShowAIDebugWindow(); break;
- case MTHK_SMALL_SCREENSHOT: MenuClickScreenshot(SC_VIEWPORT); break;
- case MTHK_ZOOMEDIN_SCREENSHOT: MenuClickScreenshot(SC_ZOOMEDIN); break;
- case MTHK_DEFAULTZOOM_SCREENSHOT: MenuClickScreenshot(SC_DEFAULTZOOM); break;
- case MTHK_GIANT_SCREENSHOT: MenuClickScreenshot(SC_WORLD); break;
+ case MTHK_SMALL_SCREENSHOT: TakeScreenshot(SC_VIEWPORT); break;
+ case MTHK_ZOOMEDIN_SCREENSHOT: TakeScreenshot(SC_ZOOMEDIN); break;
+ case MTHK_DEFAULTZOOM_SCREENSHOT: TakeScreenshot(SC_DEFAULTZOOM); break;
+ case MTHK_GIANT_SCREENSHOT: TakeScreenshot(SC_WORLD); break;
case MTHK_CHEATS: if (!_networking) ShowCheatWindow(); break;
case MTHK_TERRAFORM: ShowTerraformToolbar(); break;
case MTHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
@@ -2494,10 +2461,10 @@ struct ScenarioEditorToolbarWindow : Window {
case MTEHK_SIGN: cbf = ToolbarScenPlaceSign(this); break;
case MTEHK_MUSIC: ShowMusicWindow(); break;
case MTEHK_LANDINFO: cbf = PlaceLandBlockInfo(); break;
- case MTEHK_SMALL_SCREENSHOT: MenuClickScreenshot(SC_VIEWPORT); break;
- case MTEHK_ZOOMEDIN_SCREENSHOT: MenuClickScreenshot(SC_ZOOMEDIN); break;
- case MTEHK_DEFAULTZOOM_SCREENSHOT: MenuClickScreenshot(SC_DEFAULTZOOM); break;
- case MTEHK_GIANT_SCREENSHOT: MenuClickScreenshot(SC_WORLD); break;
+ case MTEHK_SMALL_SCREENSHOT: TakeScreenshot(SC_VIEWPORT); break;
+ case MTEHK_ZOOMEDIN_SCREENSHOT: TakeScreenshot(SC_ZOOMEDIN); break;
+ case MTEHK_DEFAULTZOOM_SCREENSHOT: TakeScreenshot(SC_DEFAULTZOOM); break;
+ case MTEHK_GIANT_SCREENSHOT: TakeScreenshot(SC_WORLD); break;
case MTEHK_ZOOM_IN: ToolbarZoomInClick(this); break;
case MTEHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
case MTEHK_TERRAFORM: ShowEditorTerraformToolbar(); break;