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"
14 #include "widgets/screenshot_widget.h"
15 #include "table/strings.h"
18 struct ScreenshotWindow
: Window
{
19 ScreenshotWindow(WindowDesc
*desc
) : Window(desc
)
21 this->CreateNestedTree();
22 this->FinishInitNested();
25 void OnPaint() override
30 void OnClick([[maybe_unused
]] Point pt
, WidgetID widget
, [[maybe_unused
]] int click_count
) override
35 case WID_SC_TAKE
: st
= SC_VIEWPORT
; break;
36 case WID_SC_TAKE_ZOOMIN
: st
= SC_ZOOMEDIN
; break;
37 case WID_SC_TAKE_DEFAULTZOOM
: st
= SC_DEFAULTZOOM
; break;
38 case WID_SC_TAKE_WORLD
: st
= SC_WORLD
; break;
39 case WID_SC_TAKE_HEIGHTMAP
: st
= SC_HEIGHTMAP
; break;
40 case WID_SC_TAKE_MINIMAP
: st
= SC_MINIMAP
; break;
42 MakeScreenshotWithConfirm(st
);
46 static constexpr NWidgetPart _nested_screenshot
[] = {
47 NWidget(NWID_HORIZONTAL
),
48 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
49 NWidget(WWT_CAPTION
, COLOUR_GREY
), SetDataTip(STR_SCREENSHOT_CAPTION
, 0),
50 NWidget(WWT_SHADEBOX
, COLOUR_GREY
),
51 NWidget(WWT_STICKYBOX
, COLOUR_GREY
),
53 NWidget(NWID_VERTICAL
, NC_EQUALSIZE
),
54 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SC_TAKE
), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_SCREENSHOT
, 0), SetMinimalTextLines(2, 0),
55 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SC_TAKE_ZOOMIN
), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_ZOOMIN_SCREENSHOT
, 0), SetMinimalTextLines(2, 0),
56 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SC_TAKE_DEFAULTZOOM
), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_DEFAULTZOOM_SCREENSHOT
, 0), SetMinimalTextLines(2, 0),
57 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SC_TAKE_WORLD
), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_WORLD_SCREENSHOT
, 0), SetMinimalTextLines(2, 0),
58 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SC_TAKE_HEIGHTMAP
), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_HEIGHTMAP_SCREENSHOT
, 0), SetMinimalTextLines(2, 0),
59 NWidget(WWT_PUSHTXTBTN
, COLOUR_GREY
, WID_SC_TAKE_MINIMAP
), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_MINIMAP_SCREENSHOT
, 0), SetMinimalTextLines(2, 0),
63 static WindowDesc
_screenshot_window_desc(__FILE__
, __LINE__
,
64 WDP_AUTO
, "take_a_screenshot", 200, 100,
65 WC_SCREENSHOT
, WC_NONE
,
67 std::begin(_nested_screenshot
), std::end(_nested_screenshot
)
70 void ShowScreenshotWindow()
72 CloseWindowById(WC_SCREENSHOT
, 0);
73 new ScreenshotWindow(&_screenshot_window_desc
);
77 * Set the visibility of the screenshot window when taking a screenshot.
78 * @param hide Are we hiding the window or showing it again after the screenshot is taken?
80 void SetScreenshotWindowVisibility(bool hide
)
82 ScreenshotWindow
*scw
= (ScreenshotWindow
*)FindWindowById(WC_SCREENSHOT
, 0);
84 if (scw
== nullptr) return;
87 /* Set dirty the screen area where the window is covering (not the window itself), then move window off screen. */
89 scw
->left
+= 2 * _screen
.width
;
91 /* Return window to original position. */
92 scw
->left
-= 2 * _screen
.width
;