Change: Let AI developers edit non-editable AI/Game Script Parameters (#8895)
[openttd-github.git] / src / screenshot_gui.cpp
blobb6d68d09199b6f06bcd652dd642430eaf216d53b
1 /*
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/>.
6 */
8 /** @file screenshot_gui.cpp GUI functions related to screenshots. */
10 #include "stdafx.h"
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"
16 #include "gfx_func.h"
18 struct ScreenshotWindow : Window {
19 ScreenshotWindow(WindowDesc *desc) : Window(desc)
21 this->CreateNestedTree();
22 this->FinishInitNested();
25 void OnPaint() override
27 this->DrawWidgets();
30 void OnClick(Point pt, int widget, int click_count) override
32 if (widget < 0) return;
33 ScreenshotType st;
34 switch (widget) {
35 default:
36 case WID_SC_TAKE: st = SC_VIEWPORT; break;
37 case WID_SC_TAKE_ZOOMIN: st = SC_ZOOMEDIN; break;
38 case WID_SC_TAKE_DEFAULTZOOM: st = SC_DEFAULTZOOM; break;
39 case WID_SC_TAKE_WORLD: st = SC_WORLD; break;
40 case WID_SC_TAKE_HEIGHTMAP: st = SC_HEIGHTMAP; break;
41 case WID_SC_TAKE_MINIMAP: st = SC_MINIMAP; break;
43 MakeScreenshotWithConfirm(st);
47 static const NWidgetPart _nested_screenshot[] = {
48 NWidget(NWID_HORIZONTAL),
49 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
50 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_SCREENSHOT_CAPTION, 0),
51 NWidget(WWT_SHADEBOX, COLOUR_GREY),
52 NWidget(WWT_STICKYBOX, COLOUR_GREY),
53 EndContainer(),
54 NWidget(NWID_VERTICAL, NC_EQUALSIZE),
55 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
56 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_ZOOMIN), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_ZOOMIN_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
57 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_DEFAULTZOOM), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_DEFAULTZOOM_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
58 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_WORLD), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_WORLD_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
59 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_HEIGHTMAP), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_HEIGHTMAP_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
60 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_MINIMAP), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_MINIMAP_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
61 EndContainer(),
64 static WindowDesc _screenshot_window_desc(
65 WDP_AUTO, "take_a_screenshot", 200, 100,
66 WC_SCREENSHOT, WC_NONE,
68 _nested_screenshot, lengthof(_nested_screenshot)
71 void ShowScreenshotWindow()
73 CloseWindowById(WC_SCREENSHOT, 0);
74 new ScreenshotWindow(&_screenshot_window_desc);
77 /**
78 * Set the visibility of the screenshot window when taking a screenshot.
79 * @param hide Are we hiding the window or showing it again after the screenshot is taken?
81 void SetScreenshotWindowVisibility(bool hide)
83 ScreenshotWindow *scw = (ScreenshotWindow *)FindWindowById(WC_SCREENSHOT, 0);
85 if (scw == nullptr) return;
87 if (hide) {
88 /* Set dirty the screen area where the window is covering (not the window itself), then move window off screen. */
89 scw->SetDirty();
90 scw->left += 2 * _screen.width;
91 } else {
92 /* Return window to original position. */
93 scw->left -= 2 * _screen.width;
94 scw->SetDirty();