OpenTTD Source: src/screenshot_gui.cpp Source File

OpenTTD Source 13.1

screenshot_gui.cpp
Go to the documentation of this file.
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 */
7
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"
17
18 struct ScreenshotWindow : Window {
19 ScreenshotWindow(WindowDesc *desc) : Window(desc)
20 {
21 this->CreateNestedTree();
22 this->FinishInitNested();
23 }
24
25 void OnPaint() override
26 {
27 this->DrawWidgets();
28 }
29
30 void OnClick(Point pt, int widget, int click_count) override
31 {
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;
42 }
43 MakeScreenshotWithConfirm(st);
44 }
45 };
46
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(),
62 };
63
64 static WindowDesc _screenshot_window_desc(
65 WDP_AUTO, "take_a_screenshot", 200, 100,
66 WC_SCREENSHOT, WC_NONE,
67 0,
68 _nested_screenshot, lengthof(_nested_screenshot)
69 );
70
71 void ShowScreenshotWindow()
72 {
73 CloseWindowById(WC_SCREENSHOT, 0);
74 new ScreenshotWindow(&_screenshot_window_desc);
75 }
76
81 void SetScreenshotWindowVisibility(bool hide)
82 {
83 ScreenshotWindow *scw = (ScreenshotWindow *)FindWindowById(WC_SCREENSHOT, 0);
84
85 if (scw == nullptr) return;
86
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();
95 }
96 }
ScreenshotType
ScreenshotType
Type of requested screenshot.
Definition: screenshot.h:18
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
ScreenshotWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: screenshot_gui.cpp:25
SC_HEIGHTMAP
@ SC_HEIGHTMAP
Heightmap of the world.
Definition: screenshot.h:24
WID_SC_TAKE_MINIMAP
@ WID_SC_TAKE_MINIMAP
Button for taking a minimap screenshot.
Definition: screenshot_widget.h:21
WID_SC_TAKE
@ WID_SC_TAKE
Button for taking a normal screenshot.
Definition: screenshot_widget.h:16
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1771
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1157
SC_ZOOMEDIN
@ SC_ZOOMEDIN
Fully zoomed in screenshot of the visible area.
Definition: screenshot.h:21
WID_SC_TAKE_DEFAULTZOOM
@ WID_SC_TAKE_DEFAULTZOOM
Button for taking a screenshot at normal zoom.
Definition: screenshot_widget.h:18
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1810
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:973
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1109
WID_SC_TAKE_WORLD
@ WID_SC_TAKE_WORLD
Button for taking a screenshot of the whole world.
Definition: screenshot_widget.h:19
screenshot.h
gfx_func.h
WindowDesc
High level window description.
Definition: window_gui.h:102
window_gui.h
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:467
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:90
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1004
WC_SCREENSHOT
@ WC_SCREENSHOT
Screenshot window; Window numbers:
Definition: window_type.h:698
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:246
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
stdafx.h
WID_SC_TAKE_HEIGHTMAP
@ WID_SC_TAKE_HEIGHTMAP
Button for taking a heightmap "screenshot".
Definition: screenshot_widget.h:20
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
ScreenshotWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: screenshot_gui.cpp:30
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
screenshot_widget.h
SetScreenshotWindowVisibility
void SetScreenshotWindowVisibility(bool hide)
Set the visibility of the screenshot window when taking a screenshot.
Definition: screenshot_gui.cpp:81
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1094
ScreenshotWindow
Definition: screenshot_gui.cpp:18
SC_WORLD
@ SC_WORLD
World screenshot.
Definition: screenshot.h:23
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1227
SC_DEFAULTZOOM
@ SC_DEFAULTZOOM
Zoomed to default zoom level screenshot of the visible area.
Definition: screenshot.h:22
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1787
window_func.h
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
SC_VIEWPORT
@ SC_VIEWPORT
Screenshot of viewport.
Definition: screenshot.h:19
MakeScreenshotWithConfirm
void MakeScreenshotWithConfirm(ScreenshotType t)
Make a screenshot.
Definition: screenshot.cpp:886
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1187
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1078
Window
Data structure for an opened window.
Definition: window_gui.h:213
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:858
SC_MINIMAP
@ SC_MINIMAP
Minimap screenshot.
Definition: screenshot.h:25
WID_SC_TAKE_ZOOMIN
@ WID_SC_TAKE_ZOOMIN
Button for taking a zoomed in screenshot.
Definition: screenshot_widget.h:17
SetMinimalTextLines
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1030
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62