OpenTTD Source  1.10.0-RC1
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 "gui.h"
12 #include "viewport_func.h"
13 #include "window_func.h"
14 #include "window_gui.h"
15 #include "screenshot.h"
16 #include "textbuf_gui.h"
17 #include "strings_func.h"
18 
20 
21 #include "table/strings.h"
22 
23 static ScreenshotType _screenshot_type;
24 
26  ScreenshotWindow(WindowDesc *desc) : Window(desc) {
27  this->CreateNestedTree();
28  this->FinishInitNested();
29  }
30 
31  void OnPaint() override {
32  this->DrawWidgets();
33  }
34 
35  void OnClick(Point pt, int widget, int click_count) override {
36  if (widget < 0) return;
37  ScreenshotType st;
38  switch (widget) {
39  default:
40  case WID_SC_TAKE: st = SC_VIEWPORT; break;
41  case WID_SC_TAKE_ZOOMIN: st = SC_ZOOMEDIN; break;
42  case WID_SC_TAKE_DEFAULTZOOM: st = SC_DEFAULTZOOM; break;
43  case WID_SC_TAKE_WORLD: st = SC_WORLD; break;
44  case WID_SC_TAKE_HEIGHTMAP: st = SC_HEIGHTMAP; break;
45  case WID_SC_TAKE_MINIMAP: st = SC_MINIMAP; break;
46  }
47  TakeScreenshot(st);
48  }
49 
55  static void TakeScreenshot(ScreenshotType st) {
56  ViewPort vp;
57  SetupScreenshotViewport(st, &vp);
58  if ((uint64)vp.width * (uint64)vp.height > 8192 * 8192) {
59  /* Ask for confirmation */
60  _screenshot_type = st;
61  SetDParam(0, vp.width);
62  SetDParam(1, vp.height);
63  ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmationCallback);
64  }
65  else {
66  /* Less than 64M pixels, just do it */
67  MakeScreenshot(st, nullptr);
68  }
69  }
70 
76  static void ScreenshotConfirmationCallback(Window *w, bool confirmed) {
77  if (confirmed) MakeScreenshot(_screenshot_type, nullptr);
78  }
79 };
80 
81 static const NWidgetPart _nested_screenshot[] = {
83  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
84  NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_SCREENSHOT_CAPTION, 0),
85  NWidget(WWT_SHADEBOX, COLOUR_GREY),
86  NWidget(WWT_STICKYBOX, COLOUR_GREY),
87  EndContainer(),
89  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
90  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_ZOOMIN), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_ZOOMIN_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
91  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_DEFAULTZOOM), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_DEFAULTZOOM_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
92  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_WORLD), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_WORLD_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
93  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_HEIGHTMAP), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_HEIGHTMAP_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
94  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_MINIMAP), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_MINIMAP_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
95  EndContainer(),
96 };
97 
98 static WindowDesc _screenshot_window_desc(
99  WDP_AUTO, "take_a_screenshot", 200, 100,
101  0,
102  _nested_screenshot, lengthof(_nested_screenshot)
103 );
104 
105 void ShowScreenshotWindow() {
107  new ScreenshotWindow(&_screenshot_window_desc);
108 }
World screenshot.
Definition: screenshot.h:23
Functions related to OTTD&#39;s strings.
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1870
Heightmap of the world.
Definition: screenshot.h:24
High level window description.
Definition: window_gui.h:166
int height
Screen height of the viewport.
Definition: viewport_type.h:26
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:602
Horizontal container.
Definition: widget_type.h:73
Screenshot of viewport.
Definition: screenshot.h:19
Button for taking a heightmap "screenshot".
Close box (at top-left of a window)
Definition: widget_type.h:67
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:963
Stuff related to the text buffer GUI.
Functions to make screenshots.
Fully zoomed in screenshot of the visible area.
Definition: screenshot.h:21
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1831
Functions, definitions and such used only by the GUI.
Types related to the screenshot widgets.
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:908
Functions related to (drawing on) viewports.
void SetupScreenshotViewport(ScreenshotType t, ViewPort *vp)
Configure a ViewPort for rendering (a part of) the map into a screenshot.
Definition: screenshot.cpp:713
Data structure for an opened window.
Definition: window_gui.h:276
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1847
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnPaint() override
The window must be repainted.
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard &#39;yes&#39; and &#39;no&#39; buttons The window is aligned to the ce...
Definition: misc_gui.cpp:1260
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1012
Definition of base types and functions in a cross-platform compatible way.
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1112
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
Button for taking a zoomed in screenshot.
bool MakeScreenshot(ScreenshotType t, const char *name)
Make an actual screenshot.
Definition: screenshot.cpp:840
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1165
static void TakeScreenshot(ScreenshotType st)
Make a screenshot.
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
Button for taking a screenshot of the whole world.
Zoomed to default zoom level screenshot of the visible area.
Definition: screenshot.h:22
Minimap screenshot.
Definition: screenshot.h:25
Button for taking a minimap screenshot.
Button for taking a screenshot at normal zoom.
Vertical container.
Definition: widget_type.h:75
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:997
Coordinates of a point in 2D.
static void ScreenshotConfirmationCallback(Window *w, bool confirmed)
Callback on the confirmation window for huge screenshots.
Button for taking a normal screenshot.
Screenshot window; Window numbers:
Definition: window_type.h:698
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:981
Window functions not directly related to making/drawing windows.
Find a place automatically.
Definition: window_gui.h:154
GUI functions that shouldn&#39;t be here.
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:427
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
ScreenshotType
Type of requested screenshot.
Definition: screenshot.h:18
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
int width
Screen width of the viewport.
Definition: viewport_type.h:25