OpenTTD Source: src/bootstrap_gui.cpp Source File

OpenTTD Source 15.0-beta1

bootstrap_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 "base_media_base.h"
12#include "blitter/factory.hpp"
13#include "error_func.h"
14
15#if defined(WITH_FREETYPE) || defined(WITH_UNISCRIBE) || defined(WITH_COCOA)
16
17#include "core/geometry_func.hpp"
18#include "error.h"
19#include "fontcache.h"
20#include "gfx_func.h"
21#include "network/network.h"
22#include "network/network_content_gui.h"
23#include "openttd.h"
24#include "strings_func.h"
25#include "video/video_driver.hpp"
26#include "window_func.h"
27
28#include "widgets/bootstrap_widget.h"
29
30#include "table/strings.h"
31
32#include "safeguards.h"
33
35 static constexpr NWidgetPart _background_widgets[] = {
36 NWidget(WWT_PANEL, COLOUR_DARK_BLUE, WID_BB_BACKGROUND), SetResize(1, 1),
37 EndContainer(),
38};
39
43 static WindowDesc _background_desc(
44 WDP_MANUAL, nullptr, 0, 0,
45 WC_BOOTSTRAP, WC_NONE,
46 WDF_NO_CLOSE,
47 _background_widgets
48);
49
51 class BootstrapBackground : public Window {
52public:
53 BootstrapBackground() : Window(_background_desc)
54 {
55 this->InitNested(0);
56 CLRBITS(this->flags, WF_WHITE_BORDER);
57 ResizeWindow(this, _screen.width, _screen.height);
58 }
59
60 void DrawWidget(const Rect &r, WidgetID) const override
61 {
62 GfxFillRect(r.left, r.top, r.right, r.bottom, 4, FILLRECT_OPAQUE);
63 GfxFillRect(r.left, r.top, r.right, r.bottom, 0, FILLRECT_CHECKER);
64 }
65};
66
68 static constexpr NWidgetPart _nested_bootstrap_errmsg_widgets[] = {
69 NWidget(NWID_HORIZONTAL),
70 NWidget(WWT_CAPTION, COLOUR_GREY, WID_BEM_CAPTION), SetDataTip(STR_MISSING_GRAPHICS_ERROR_TITLE, STR_NULL),
71 EndContainer(),
72 NWidget(WWT_PANEL, COLOUR_GREY, WID_BEM_MESSAGE), EndContainer(),
73 NWidget(NWID_HORIZONTAL),
74 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BEM_QUIT), SetDataTip(STR_MISSING_GRAPHICS_ERROR_QUIT, STR_NULL), SetFill(1, 0),
75 EndContainer(),
76};
77
79 static WindowDesc _bootstrap_errmsg_desc(
80 WDP_CENTER, nullptr, 0, 0,
81 WC_BOOTSTRAP, WC_NONE,
82 WDF_MODAL | WDF_NO_CLOSE,
83 _nested_bootstrap_errmsg_widgets
84);
85
87 class BootstrapErrorWindow : public Window {
88public:
89 BootstrapErrorWindow() : Window(_bootstrap_errmsg_desc)
90 {
91 this->InitNested(1);
92 }
93
94 void Close([[maybe_unused]] int data = 0) override
95 {
96 _exit_game = true;
97 this->Window::Close();
98 }
99
100 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
101 {
102 if (widget == WID_BEM_MESSAGE) {
103 size = GetStringBoundingBox(STR_MISSING_GRAPHICS_ERROR);
104 size.width += WidgetDimensions::scaled.frametext.Horizontal();
105 size.height += WidgetDimensions::scaled.frametext.Vertical();
106 }
107 }
108
109 void DrawWidget(const Rect &r, WidgetID widget) const override
110 {
111 if (widget == WID_BEM_MESSAGE) {
112 DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_MISSING_GRAPHICS_ERROR, TC_FROMSTRING, SA_CENTER);
113 }
114 }
115
116 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
117 {
118 if (widget == WID_BEM_QUIT) {
119 _exit_game = true;
120 }
121 }
122};
123
125 static constexpr NWidgetPart _nested_bootstrap_download_status_window_widgets[] = {
126 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CONTENT_DOWNLOAD_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
127 NWidget(WWT_PANEL, COLOUR_GREY),
128 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup),
129 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_NCDS_PROGRESS_BAR), SetFill(1, 0),
130 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_NCDS_PROGRESS_TEXT), SetFill(1, 0), SetMinimalSize(350, 0),
131 EndContainer(),
132 EndContainer(),
133};
134
136 static WindowDesc _bootstrap_download_status_window_desc(
137 WDP_CENTER, nullptr, 0, 0,
138 WC_NETWORK_STATUS_WINDOW, WC_NONE,
139 WDF_MODAL | WDF_NO_CLOSE,
140 _nested_bootstrap_download_status_window_widgets
141);
142
143
145 struct BootstrapContentDownloadStatusWindow : public BaseNetworkContentDownloadStatusWindow {
146public:
148 BootstrapContentDownloadStatusWindow() : BaseNetworkContentDownloadStatusWindow(_bootstrap_download_status_window_desc)
149 {
150 }
151
152 void Close([[maybe_unused]] int data = 0) override
153 {
154 /* If we are not set to exit the game, it means the bootstrap failed. */
155 if (!_exit_game) {
156 new BootstrapErrorWindow();
157 }
158 this->BaseNetworkContentDownloadStatusWindow::Close();
159 }
160
161 void OnDownloadComplete(ContentID) override
162 {
163 /* We have completed downloading. We can trigger finding the right set now. */
164 BaseGraphics::FindSets();
165
166 /* And continue going into the menu. */
167 _game_mode = GM_MENU;
168
169 /* _exit_game is used to break out of the outer video driver's MainLoop. */
170 _exit_game = true;
171 this->Close();
172 }
173};
174
176 static constexpr NWidgetPart _bootstrap_query_widgets[] = {
177 NWidget(NWID_HORIZONTAL),
178 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_MISSING_GRAPHICS_SET_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
179 EndContainer(),
180 NWidget(WWT_PANEL, COLOUR_GREY, WID_BAFD_QUESTION), EndContainer(),
181 NWidget(NWID_HORIZONTAL),
182 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BAFD_YES), SetDataTip(STR_MISSING_GRAPHICS_YES_DOWNLOAD, STR_NULL),
183 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BAFD_NO), SetDataTip(STR_MISSING_GRAPHICS_NO_QUIT, STR_NULL),
184 EndContainer(),
185};
186
188 static WindowDesc _bootstrap_query_desc(
189 WDP_CENTER, nullptr, 0, 0,
190 WC_CONFIRM_POPUP_QUERY, WC_NONE,
191 WDF_NO_CLOSE,
192 _bootstrap_query_widgets
193);
194
196 class BootstrapAskForDownloadWindow : public Window, ContentCallback {
197 Dimension button_size;
198
199public:
201 BootstrapAskForDownloadWindow() : Window(_bootstrap_query_desc)
202 {
203 this->InitNested(WN_CONFIRM_POPUP_QUERY_BOOTSTRAP);
204 _network_content_client.AddCallback(this);
205 }
206
208 void Close([[maybe_unused]] int data = 0) override
209 {
210 _network_content_client.RemoveCallback(this);
211 this->Window::Close();
212 }
213
214 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
215 {
216 /* We cache the button size. This is safe as no reinit can happen here. */
217 if (this->button_size.width == 0) {
218 this->button_size = maxdim(GetStringBoundingBox(STR_MISSING_GRAPHICS_YES_DOWNLOAD), GetStringBoundingBox(STR_MISSING_GRAPHICS_NO_QUIT));
219 this->button_size.width += WidgetDimensions::scaled.frametext.Horizontal();
220 this->button_size.height += WidgetDimensions::scaled.frametext.Vertical();
221 }
222
223 switch (widget) {
224 case WID_BAFD_QUESTION:
225 /* The question is twice as wide as the buttons, and determine the height based on the width. */
226 size.width = this->button_size.width * 2;
227 size.height = GetStringHeight(STR_MISSING_GRAPHICS_SET_MESSAGE, size.width - WidgetDimensions::scaled.frametext.Horizontal()) + WidgetDimensions::scaled.frametext.Vertical();
228 break;
229
230 case WID_BAFD_YES:
231 case WID_BAFD_NO:
232 size = this->button_size;
233 break;
234 }
235 }
236
237 void DrawWidget(const Rect &r, WidgetID widget) const override
238 {
239 if (widget != WID_BAFD_QUESTION) return;
240
241 DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.frametext), STR_MISSING_GRAPHICS_SET_MESSAGE, TC_FROMSTRING, SA_CENTER);
242 }
243
244 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
245 {
246 switch (widget) {
247 case WID_BAFD_YES:
248 /* We got permission to connect! Yay! */
249 _network_content_client.Connect();
250 break;
251
252 case WID_BAFD_NO:
253 _exit_game = true;
254 break;
255
256 default:
257 break;
258 }
259 }
260
261 void OnConnect(bool success) override
262 {
263 if (!success) {
264 UserError("Failed to connect to content server. Please acquire a graphics set for OpenTTD. See section 1.4 of README.md.");
265 /* _exit_game is used to break out of the outer video driver's MainLoop. */
266 _exit_game = true;
267 this->Close();
268 return;
269 }
270
271 /* Once connected, request the metadata. */
272 _network_content_client.RequestContentList(CONTENT_TYPE_BASE_GRAPHICS);
273 }
274
275 void OnReceiveContentInfo(const ContentInfo *ci) override
276 {
277 /* And once the meta data is received, start downloading it. */
278 _network_content_client.Select(ci->id);
279 new BootstrapContentDownloadStatusWindow();
280 this->Close();
281 }
282};
283
284#endif /* defined(WITH_FREETYPE) */
285
286#if defined(__EMSCRIPTEN__)
287# include <emscripten.h>
288# include "network/network.h"
289# include "network/network_content.h"
290# include "openttd.h"
291# include "video/video_driver.hpp"
292
293class BootstrapEmscripten : public ContentCallback {
294 bool downloading = false;
295 uint total_files = 0;
296 uint total_bytes = 0;
297 uint downloaded_bytes = 0;
298
299public:
300 BootstrapEmscripten()
301 {
302 _network_content_client.AddCallback(this);
303 _network_content_client.Connect();
304 }
305
306 ~BootstrapEmscripten()
307 {
308 _network_content_client.RemoveCallback(this);
309 }
310
311 void OnConnect(bool success) override
312 {
313 if (!success) {
314 EM_ASM({ if (window["openttd_bootstrap_failed"]) openttd_bootstrap_failed(); });
315 return;
316 }
317
318 /* Once connected, request the metadata. */
319 _network_content_client.RequestContentList(CONTENT_TYPE_BASE_GRAPHICS);
320 }
321
322 void OnReceiveContentInfo(const ContentInfo *ci) override
323 {
324 if (this->downloading) return;
325
326 /* And once the metadata is received, start downloading it. */
327 _network_content_client.Select(ci->id);
328 _network_content_client.DownloadSelectedContent(this->total_files, this->total_bytes);
329 this->downloading = true;
330
331 EM_ASM({ if (window["openttd_bootstrap"]) openttd_bootstrap($0, $1); }, this->downloaded_bytes, this->total_bytes);
332 }
333
334 void OnDownloadProgress(const ContentInfo *, int bytes) override
335 {
336 /* A negative value means we are resetting; for example, when retrying or using a fallback. */
337 if (bytes < 0) {
338 this->downloaded_bytes = 0;
339 } else {
340 this->downloaded_bytes += bytes;
341 }
342
343 EM_ASM({ if (window["openttd_bootstrap"]) openttd_bootstrap($0, $1); }, this->downloaded_bytes, this->total_bytes);
344 }
345
346 void OnDownloadComplete(ContentID) override
347 {
348 /* _exit_game is used to break out of the outer video driver's MainLoop. */
349 _exit_game = true;
350
351 delete this;
352 }
353};
354#endif /* __EMSCRIPTEN__ */
355
362 bool HandleBootstrap()
363{
364 if (BaseGraphics::GetUsedSet() != nullptr) return true;
365
366 /* No user interface, bail out with an error. */
367 if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) goto failure;
368
369 /* If there is no network or no non-sprite font, then there is nothing we can do. Go straight to failure. */
370#if defined(__EMSCRIPTEN__) || (defined(_WIN32) && defined(WITH_UNISCRIBE)) || (defined(WITH_FREETYPE) && (defined(WITH_FONTCONFIG) || defined(__APPLE__))) || defined(WITH_COCOA)
371 if (!_network_available) goto failure;
372
373 /* First tell the game we're bootstrapping. */
374 _game_mode = GM_BOOTSTRAP;
375
376#if defined(__EMSCRIPTEN__)
377 new BootstrapEmscripten();
378#else
379 /* Initialise the font cache. */
380 InitializeUnicodeGlyphMap();
381 /* Next "force" finding a suitable non-sprite font as the local font is missing. */
382 CheckForMissingGlyphs(false);
383
384 /* Initialise the palette. The biggest step is 'faking' some recolour sprites.
385 * This way the mauve and gray colours work and we can show the user interface. */
386 GfxInitPalettes();
387 static const int offsets[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0, 0, 0x04, 0x08 };
388 for (Colours i = COLOUR_BEGIN; i != COLOUR_END; i++) {
389 for (ColourShade j = SHADE_BEGIN; j < SHADE_END; j++) {
390 SetColourGradient(i, j, offsets[i] + j);
391 }
392 }
393
394 /* Finally ask the question. */
395 new BootstrapBackground();
396 new BootstrapAskForDownloadWindow();
397#endif /* __EMSCRIPTEN__ */
398
399 /* Process the user events. */
400 VideoDriver::GetInstance()->MainLoop();
401
402 /* _exit_game is used to get out of the video driver's main loop.
403 * In case GM_BOOTSTRAP is still set we did not exit it via the
404 * "download complete" event, so it was a manual exit. Obey it. */
405 _exit_game = _game_mode == GM_BOOTSTRAP;
406 if (_exit_game) return false;
407
408 /* Try to probe the graphics. Should work this time. */
409 if (!BaseGraphics::SetSet({})) goto failure;
410
411 /* Finally we can continue heading for the menu. */
412 _game_mode = GM_MENU;
413 return true;
414#endif
415
416 /* Failure to get enough working to get a graphics set. */
417failure:
418 UserError("Failed to find a graphics set. Please acquire a graphics set for OpenTTD. See section 1.4 of README.md.");
419 return false;
420}
base_media_base.h
Generic functions for replacing base data (graphics, sounds).
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition bitmath_func.hpp:166
_background_widgets
static constexpr NWidgetPart _background_widgets[]
Widgets for the background window to prevent smearing.
Definition bootstrap_gui.cpp:35
_bootstrap_download_status_window_desc
static WindowDesc _bootstrap_download_status_window_desc(WDP_CENTER, nullptr, 0, 0, WC_NETWORK_STATUS_WINDOW, WC_NONE, WDF_MODAL|WDF_NO_CLOSE, _nested_bootstrap_download_status_window_widgets)
Window description for the download window.
_bootstrap_query_widgets
static constexpr NWidgetPart _bootstrap_query_widgets[]
The widgets for the query.
Definition bootstrap_gui.cpp:176
_nested_bootstrap_errmsg_widgets
static constexpr NWidgetPart _nested_bootstrap_errmsg_widgets[]
Nested widgets for the error window.
Definition bootstrap_gui.cpp:68
_bootstrap_errmsg_desc
static WindowDesc _bootstrap_errmsg_desc(WDP_CENTER, nullptr, 0, 0, WC_BOOTSTRAP, WC_NONE, WDF_MODAL|WDF_NO_CLOSE, _nested_bootstrap_errmsg_widgets)
Window description for the error window.
_background_desc
static WindowDesc _background_desc(WDP_MANUAL, nullptr, 0, 0, WC_BOOTSTRAP, WC_NONE, WDF_NO_CLOSE, _background_widgets)
Window description for the background window to prevent smearing.
HandleBootstrap
bool HandleBootstrap()
Handle all procedures for bootstrapping OpenTTD without a base graphics set.
Definition bootstrap_gui.cpp:362
_bootstrap_query_desc
static WindowDesc _bootstrap_query_desc(WDP_CENTER, nullptr, 0, 0, WC_CONFIRM_POPUP_QUERY, WC_NONE, WDF_NO_CLOSE, _bootstrap_query_widgets)
The window description for the query.
_nested_bootstrap_download_status_window_widgets
static constexpr NWidgetPart _nested_bootstrap_download_status_window_widgets[]
Nested widgets for the download window.
Definition bootstrap_gui.cpp:125
bootstrap_widget.h
Types related to the bootstrap widgets.
WID_BAFD_QUESTION
@ WID_BAFD_QUESTION
The question whether to download.
Definition bootstrap_widget.h:27
WID_BAFD_NO
@ WID_BAFD_NO
An negative answer to the question.
Definition bootstrap_widget.h:29
WID_BAFD_YES
@ WID_BAFD_YES
An affirmative answer to the question.
Definition bootstrap_widget.h:28
WID_BB_BACKGROUND
@ WID_BB_BACKGROUND
Background of the window.
Definition bootstrap_widget.h:15
WID_BEM_MESSAGE
@ WID_BEM_MESSAGE
Error message.
Definition bootstrap_widget.h:21
WID_BEM_QUIT
@ WID_BEM_QUIT
Quit button.
Definition bootstrap_widget.h:22
WID_BEM_CAPTION
@ WID_BEM_CAPTION
Caption of the window.
Definition bootstrap_widget.h:20
BaseMedia< GraphicsSet >::GetUsedSet
static const GraphicsSet * GetUsedSet()
Return the used set.
Definition base_media_func.h:394
BaseMedia< GraphicsSet >::FindSets
static uint FindSets()
Do the scan for files.
Definition base_media_base.h:198
BaseMedia< GraphicsSet >::SetSet
static bool SetSet(const GraphicsSet *set)
Set the set to be used.
Definition base_media_func.h:241
BaseNetworkContentDownloadStatusWindow
Base window for showing the download status of content.
Definition network_content_gui.h:18
BaseNetworkContentDownloadStatusWindow::Close
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition network_content_gui.cpp:113
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition factory.hpp:138
BootstrapAskForDownloadWindow
The window for the query.
Definition bootstrap_gui.cpp:196
BootstrapAskForDownloadWindow::OnConnect
void OnConnect(bool success) override
Callback for when the connection has finished.
Definition bootstrap_gui.cpp:261
BootstrapAskForDownloadWindow::button_size
Dimension button_size
The dimension of the button.
Definition bootstrap_gui.cpp:197
BootstrapAskForDownloadWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition bootstrap_gui.cpp:214
BootstrapAskForDownloadWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition bootstrap_gui.cpp:244
BootstrapAskForDownloadWindow::OnReceiveContentInfo
void OnReceiveContentInfo(const ContentInfo *ci) override
We received a content info.
Definition bootstrap_gui.cpp:275
BootstrapAskForDownloadWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition bootstrap_gui.cpp:237
BootstrapAskForDownloadWindow::Close
void Close(int data=0) override
Stop listening to the content client events.
Definition bootstrap_gui.cpp:208
BootstrapAskForDownloadWindow::BootstrapAskForDownloadWindow
BootstrapAskForDownloadWindow()
Start listening to the content client events.
Definition bootstrap_gui.cpp:201
BootstrapBackground
The background for the game.
Definition bootstrap_gui.cpp:51
BootstrapBackground::DrawWidget
void DrawWidget(const Rect &r, WidgetID) const override
Draw the contents of a nested widget.
Definition bootstrap_gui.cpp:60
BootstrapErrorWindow
The window for a failed bootstrap.
Definition bootstrap_gui.cpp:87
BootstrapErrorWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition bootstrap_gui.cpp:100
BootstrapErrorWindow::Close
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition bootstrap_gui.cpp:94
BootstrapErrorWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition bootstrap_gui.cpp:109
BootstrapErrorWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition bootstrap_gui.cpp:116
ClientNetworkContentSocketHandler::DownloadSelectedContent
void DownloadSelectedContent(uint &files, uint &bytes, bool fallback=false)
Actually begin downloading the content we selected.
Definition network_content.cpp:305
ClientNetworkContentSocketHandler::RemoveCallback
void RemoveCallback(ContentCallback *cb)
Remove a callback.
Definition network_content.h:149
ClientNetworkContentSocketHandler::Select
void Select(ContentID cid)
Select a specific content id.
Definition network_content.cpp:865
ClientNetworkContentSocketHandler::RequestContentList
void RequestContentList(ContentType type)
Request the content list for the given type.
Definition network_content.cpp:188
ClientNetworkContentSocketHandler::AddCallback
void AddCallback(ContentCallback *cb)
Add a callback to this class.
Definition network_content.h:147
ClientNetworkContentSocketHandler::Connect
void Connect()
Connect with the content server.
Definition network_content.cpp:776
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition video_driver.hpp:201
VideoDriver::MainLoop
virtual void MainLoop()=0
Perform the actual drawing.
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition window_gui.h:43
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:28
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:96
error.h
Functions related to errors.
error_func.h
Error reporting related functions.
factory.hpp
Factory to 'query' all available blitters.
fontcache.h
Functions to read fonts from files and cache them.
InitializeUnicodeGlyphMap
void InitializeUnicodeGlyphMap()
Initialize the glyph map.
Definition fontcache.h:158
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition geometry_func.cpp:22
geometry_func.hpp
Geometry functions.
GetStringHeight
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition gfx.cpp:704
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:851
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:114
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:774
gfx_func.h
Functions related to the gfx engine.
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:353
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition gfx_type.h:299
FILLRECT_OPAQUE
@ FILLRECT_OPAQUE
Fill rectangle with a single colour.
Definition gfx_type.h:298
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1181
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition widget_type.h:1271
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition widget_type.h:1228
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition widget_type.h:1202
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1137
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1320
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1191
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1126
_network_available
bool _network_available
is network mode available?
Definition network.cpp:67
network.h
Basic functions/variables used all over the place.
_network_content_client
ClientNetworkContentSocketHandler _network_content_client
The client we use to connect to the server.
Definition network_content.cpp:36
network_content.h
Part of the network protocol handling content distribution.
network_content_gui.h
User interface for downloading files.
WID_NCDS_PROGRESS_TEXT
@ WID_NCDS_PROGRESS_TEXT
Text explaining what is happening.
Definition network_content_widget.h:18
WID_NCDS_PROGRESS_BAR
@ WID_NCDS_PROGRESS_BAR
Simple progress bar.
Definition network_content_widget.h:17
openttd.h
Some generic types.
SetColourGradient
void SetColourGradient(Colours colour, ColourShade shade, uint8_t palette_index)
Set colour gradient palette index.
Definition palette.cpp:325
safeguards.h
A number of safeguards to prevent using unsafe methods.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
CheckForMissingGlyphs
void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
Check whether the currently loaded language pack uses characters that the currently loaded font does ...
Definition strings.cpp:2291
strings_func.h
Functions related to OTTD's strings.
BootstrapContentDownloadStatusWindow
Window for showing the download status of content.
Definition bootstrap_gui.cpp:145
BootstrapContentDownloadStatusWindow::BootstrapContentDownloadStatusWindow
BootstrapContentDownloadStatusWindow()
Simple call the constructor of the superclass.
Definition bootstrap_gui.cpp:148
BootstrapContentDownloadStatusWindow::OnDownloadComplete
void OnDownloadComplete(ContentID) override
We have finished downloading a file.
Definition bootstrap_gui.cpp:161
BootstrapContentDownloadStatusWindow::Close
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition bootstrap_gui.cpp:152
ContentCallback
Callbacks for notifying others about incoming data.
Definition network_content.h:29
ContentCallback::OnDownloadProgress
virtual void OnDownloadProgress(const ContentInfo *ci, int bytes)
We have progress in the download of a file.
Definition network_content.h:52
ContentCallback::OnDownloadComplete
virtual void OnDownloadComplete(ContentID cid)
We have finished downloading a file.
Definition network_content.h:58
ContentCallback::OnConnect
virtual void OnConnect(bool success)
Callback for when the connection has finished.
Definition network_content.h:34
ContentCallback::OnReceiveContentInfo
virtual void OnReceiveContentInfo(const ContentInfo *ci)
We received a content info.
Definition network_content.h:45
ContentInfo
Container for all important information about a piece of content.
Definition tcp_content_type.h:52
ContentInfo::id
ContentID id
Unique (server side) ID for the content.
Definition tcp_content_type.h:64
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:30
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition widget_type.h:1075
Point
Coordinates of a point in 2D.
Definition geometry_type.hpp:21
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition geometry_type.hpp:63
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition geometry_type.hpp:69
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:75
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:98
WindowDesc
High level window description.
Definition window_gui.h:159
Window
Data structure for an opened window.
Definition window_gui.h:273
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1047
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:314
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:977
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1746
Window::flags
WindowFlags flags
Window flags.
Definition window_gui.h:300
CONTENT_TYPE_BASE_GRAPHICS
@ CONTENT_TYPE_BASE_GRAPHICS
The content consists of base graphics.
Definition tcp_content_type.h:20
ContentID
ContentID
Unique identifier for the content.
Definition tcp_content_type.h:47
video_driver.hpp
Base of all video drivers.
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:113
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:75
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:50
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:61
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:77
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:48
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
Definition window.cpp:2022
window_func.h
Window functions not directly related to making/drawing windows.
WF_WHITE_BORDER
@ WF_WHITE_BORDER
Window white border counter bit mask.
Definition window_gui.h:236
WDF_NO_CLOSE
@ WDF_NO_CLOSE
This window can't be interactively closed.
Definition window_gui.h:206
WDF_MODAL
@ WDF_MODAL
The window is a modal child of some other window, meaning the parent is 'inactive'.
Definition window_gui.h:204
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition window_gui.h:148
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition window_gui.h:146
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:18
WN_CONFIRM_POPUP_QUERY_BOOTSTRAP
@ WN_CONFIRM_POPUP_QUERY_BOOTSTRAP
Query popup confirm for bootstrap.
Definition window_type.h:33
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:45
WC_CONFIRM_POPUP_QUERY
@ WC_CONFIRM_POPUP_QUERY
Popup with confirm question; Window numbers:
Definition window_type.h:130
WC_BOOTSTRAP
@ WC_BOOTSTRAP
Bootstrap; Window numbers:
Definition window_type.h:655
WC_NETWORK_STATUS_WINDOW
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers:
Definition window_type.h:491