2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file screenshot_gui.cpp GUI functions related to screenshots. */
11 #include "window_func.h"
12 #include "window_gui.h"
13 #include "screenshot.h"
16 #include "widgets/screenshot_widget.h"
18 #include "table/strings.h"
20 #include "safeguards.h"
22 struct ScreenshotWindow
: Window
{
23 ScreenshotWindow(WindowDesc
&desc
) : Window(desc
)
25 this->CreateNestedTree();
26 this->FinishInitNested();
29 void OnPaint() override
34 void OnClick([[maybe_unused
]] Point pt
, WidgetID widget
, [[maybe_unused
]] int click_count
) override
39 case WID_SC_TAKE
: st
= SC_VIEWPORT
; break;
40 case WID_SC_TAKE_ZOOMIN
: st
= SC_ZOOMEDIN
; break;
41 case WID_SC_TAKE_DEFAULTZOOM
: st
= SC_DEFAULTZOOM
; break;
42 case WID_SC_TAKE_WORLD
: st
= SC_WORLD
; break;
43 case WID_SC_TAKE_HEIGHTMAP
: st
= SC_HEIGHTMAP
; break;
44 case WID_SC_TAKE_MINIMAP
: st
= SC_MINIMAP
; break;
46 MakeScreenshotWithConfirm(st
);
50 static constexpr NWidgetPart _nested_screenshot
[] = {
51 NWidget(NWID_HORIZONTAL
),
52 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
53 NWidget(WWT_CAPTION
, COLOUR_GREY
), SetDataTip(STR_SCREENSHOT_CAPTION
, 0),
54 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
55 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
57 NWidget(NWID_VERTICAL
, NC_EQUALSIZE
),
58 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SC_TAKE
), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_SCREENSHOT
, 0), SetMinimalTextLines(2, 0),
59 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SC_TAKE_ZOOMIN
), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_ZOOMIN_SCREENSHOT
, 0), SetMinimalTextLines(2, 0),
60 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SC_TAKE_DEFAULTZOOM
), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_DEFAULTZOOM_SCREENSHOT
, 0), SetMinimalTextLines(2, 0),
61 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SC_TAKE_WORLD
), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_WORLD_SCREENSHOT
, 0), SetMinimalTextLines(2, 0),
62 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SC_TAKE_HEIGHTMAP
), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_HEIGHTMAP_SCREENSHOT
, 0), SetMinimalTextLines(2, 0),
63 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SC_TAKE_MINIMAP
), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_MINIMAP_SCREENSHOT
, 0), SetMinimalTextLines(2, 0),
67 static WindowDesc
_screenshot_window_desc(
68 WDP_AUTO
, "take_a_screenshot", 200, 100,
69 WC_SCREENSHOT
, WC_NONE
,
74 void ShowScreenshotWindow()
76 CloseWindowById(WC_SCREENSHOT
, 0);
77 new ScreenshotWindow(_screenshot_window_desc
);
81 * Set the visibility of the screenshot window when taking a screenshot.
82 * @param hide Are we hiding the window or showing it again after the screenshot is taken?
84 void SetScreenshotWindowVisibility(bool hide
)
86 ScreenshotWindow
*scw
= dynamic_cast<ScreenshotWindow
*>(FindWindowById(WC_SCREENSHOT
, 0));
88 if (scw
== nullptr) return;
91 /* Set dirty the screen area where the window is covering (not the window itself), then move window off screen. */
93 scw
->left
+= 2 * _screen
.width
;
95 /* Return window to original position. */
96 scw
->left
-= 2 * _screen
.width
;