OpenTTD

misc_gui.cpp
Go to the documentation of this file.
1 /* $Id: misc_gui.cpp 27995 2018-03-21 19:34:17Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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 */
9
12 #include "stdafx.h"
13 #include "debug.h"
14 #include "landscape.h"
15 #include "error.h"
16 #include "gui.h"
17 #include "command_func.h"
18 #include "company_func.h"
19 #include "town.h"
20 #include "string_func.h"
21 #include "company_base.h"
22 #include "texteff.hpp"
23 #include "strings_func.h"
24 #include "window_func.h"
25 #include "querystring_gui.h"
26 #include "core/geometry_func.hpp"
27 #include "newgrf_debug.h"
28 #include "zoom_func.h"
29
30 #include "widgets/misc_widget.h"
31
32 #include "table/strings.h"
33
34 #include "safeguards.h"
35
37 enum OskActivation {
38 OSKA_DISABLED,
39 OSKA_DOUBLE_CLICK,
40 OSKA_SINGLE_CLICK,
41 OSKA_IMMEDIATELY,
42 };
43
44
45 static const NWidgetPart _nested_land_info_widgets[] = {
46 NWidget(NWID_HORIZONTAL),
47 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
48 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_LAND_AREA_INFORMATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
49 NWidget(WWT_DEBUGBOX, COLOUR_GREY),
50 EndContainer(),
51 NWidget(WWT_PANEL, COLOUR_GREY, WID_LI_BACKGROUND), EndContainer(),
52 };
53
54 static WindowDesc _land_info_desc(
55 WDP_AUTO, "land_info", 0, 0,
56 WC_LAND_INFO, WC_NONE,
57 0,
58 _nested_land_info_widgets, lengthof(_nested_land_info_widgets)
59 );
60
61 class LandInfoWindow : public Window {
62 enum LandInfoLines {
63 LAND_INFO_CENTERED_LINES = 32,
64 LAND_INFO_MULTICENTER_LINE = LAND_INFO_CENTERED_LINES,
65 LAND_INFO_LINE_END,
66 };
67
68 static const uint LAND_INFO_LINE_BUFF_SIZE = 512;
69
70 public:
71 char landinfo_data[LAND_INFO_LINE_END][LAND_INFO_LINE_BUFF_SIZE];
72 TileIndex tile;
73
74 virtual void DrawWidget(const Rect &r, int widget) const
75 {
76 if (widget != WID_LI_BACKGROUND) return;
77
78 uint y = r.top + WD_TEXTPANEL_TOP;
79 for (uint i = 0; i < LAND_INFO_CENTERED_LINES; i++) {
80 if (StrEmpty(this->landinfo_data[i])) break;
81
82 DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, this->landinfo_data[i], i == 0 ? TC_LIGHT_BLUE : TC_FROMSTRING, SA_HOR_CENTER);
83 y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
84 if (i == 0) y += 4;
85 }
86
87 if (!StrEmpty(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])) {
88 SetDParamStr(0, this->landinfo_data[LAND_INFO_MULTICENTER_LINE]);
89 DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, r.bottom - WD_TEXTPANEL_BOTTOM, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
90 }
91 }
92
93 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
94 {
95 if (widget != WID_LI_BACKGROUND) return;
96
97 size->height = WD_TEXTPANEL_TOP + WD_TEXTPANEL_BOTTOM;
98 for (uint i = 0; i < LAND_INFO_CENTERED_LINES; i++) {
99 if (StrEmpty(this->landinfo_data[i])) break;
100
101 uint width = GetStringBoundingBox(this->landinfo_data[i]).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
102 size->width = max(size->width, width);
103
104 size->height += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
105 if (i == 0) size->height += 4;
106 }
107
108 if (!StrEmpty(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])) {
109 uint width = GetStringBoundingBox(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
110 size->width = max(size->width, min(300u, width));
111 SetDParamStr(0, this->landinfo_data[LAND_INFO_MULTICENTER_LINE]);
112 size->height += GetStringHeight(STR_JUST_RAW_STRING, size->width - WD_FRAMETEXT_LEFT - WD_FRAMETEXT_RIGHT);
113 }
114 }
115
116 LandInfoWindow(TileIndex tile) : Window(&_land_info_desc), tile(tile)
117 {
118 this->InitNested();
119
120 #if defined(_DEBUG)
121 # define LANDINFOD_LEVEL 0
122 #else
123 # define LANDINFOD_LEVEL 1
124 #endif
125 DEBUG(misc, LANDINFOD_LEVEL, "TILE: %#x (%i,%i)", tile, TileX(tile), TileY(tile));
126 DEBUG(misc, LANDINFOD_LEVEL, "type = %#x", _m[tile].type);
127 DEBUG(misc, LANDINFOD_LEVEL, "height = %#x", _m[tile].height);
128 DEBUG(misc, LANDINFOD_LEVEL, "m1 = %#x", _m[tile].m1);
129 DEBUG(misc, LANDINFOD_LEVEL, "m2 = %#x", _m[tile].m2);
130 DEBUG(misc, LANDINFOD_LEVEL, "m3 = %#x", _m[tile].m3);
131 DEBUG(misc, LANDINFOD_LEVEL, "m4 = %#x", _m[tile].m4);
132 DEBUG(misc, LANDINFOD_LEVEL, "m5 = %#x", _m[tile].m5);
133 DEBUG(misc, LANDINFOD_LEVEL, "m6 = %#x", _me[tile].m6);
134 DEBUG(misc, LANDINFOD_LEVEL, "m7 = %#x", _me[tile].m7);
135 #undef LANDINFOD_LEVEL
136 }
137
138 virtual void OnInit()
139 {
140 Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
141
142 /* Because build_date is not set yet in every TileDesc, we make sure it is empty */
143 TileDesc td;
144
145 td.build_date = INVALID_DATE;
146
147 /* Most tiles have only one owner, but
148 * - drivethrough roadstops can be build on town owned roads (up to 2 owners) and
149 * - roads can have up to four owners (railroad, road, tram, 3rd-roadtype "highway").
150 */
151 td.owner_type[0] = STR_LAND_AREA_INFORMATION_OWNER; // At least one owner is displayed, though it might be "N/A".
152 td.owner_type[1] = STR_NULL; // STR_NULL results in skipping the owner
153 td.owner_type[2] = STR_NULL;
154 td.owner_type[3] = STR_NULL;
155 td.owner[0] = OWNER_NONE;
156 td.owner[1] = OWNER_NONE;
157 td.owner[2] = OWNER_NONE;
158 td.owner[3] = OWNER_NONE;
159
160 td.station_class = STR_NULL;
161 td.station_name = STR_NULL;
162 td.airport_class = STR_NULL;
163 td.airport_name = STR_NULL;
164 td.airport_tile_name = STR_NULL;
165 td.railtype = STR_NULL;
166 td.rail_speed = 0;
167 td.road_speed = 0;
168
169 td.grf = NULL;
170
171 CargoArray acceptance;
172 AddAcceptedCargo(tile, acceptance, NULL);
173 GetTileDesc(tile, &td);
174
175 uint line_nr = 0;
176
177 /* Tiletype */
178 SetDParam(0, td.dparam[0]);
179 GetString(this->landinfo_data[line_nr], td.str, lastof(this->landinfo_data[line_nr]));
180 line_nr++;
181
182 /* Up to four owners */
183 for (uint i = 0; i < 4; i++) {
184 if (td.owner_type[i] == STR_NULL) continue;
185
186 SetDParam(0, STR_LAND_AREA_INFORMATION_OWNER_N_A);
187 if (td.owner[i] != OWNER_NONE && td.owner[i] != OWNER_WATER) GetNameOfOwner(td.owner[i], tile);
188 GetString(this->landinfo_data[line_nr], td.owner_type[i], lastof(this->landinfo_data[line_nr]));
189 line_nr++;
190 }
191
192 /* Cost to clear/revenue when cleared */
193 StringID str = STR_LAND_AREA_INFORMATION_COST_TO_CLEAR_N_A;
194 Company *c = Company::GetIfValid(_local_company);
195 if (c != NULL) {
196 Money old_money = c->money;
197 c->money = INT64_MAX;
198 assert(_current_company == _local_company);
199 CommandCost costclear = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
200 c->money = old_money;
201 if (costclear.Succeeded()) {
202 Money cost = costclear.GetCost();
203 if (cost < 0) {
204 cost = -cost; // Negate negative cost to a positive revenue
205 str = STR_LAND_AREA_INFORMATION_REVENUE_WHEN_CLEARED;
206 } else {
207 str = STR_LAND_AREA_INFORMATION_COST_TO_CLEAR;
208 }
209 SetDParam(0, cost);
210 }
211 }
212 GetString(this->landinfo_data[line_nr], str, lastof(this->landinfo_data[line_nr]));
213 line_nr++;
214
215 /* Location */
216 char tmp[16];
217 seprintf(tmp, lastof(tmp), "0x%.4X", tile);
218 SetDParam(0, TileX(tile));
219 SetDParam(1, TileY(tile));
220 SetDParam(2, GetTileZ(tile));
221 SetDParamStr(3, tmp);
222 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_LANDINFO_COORDS, lastof(this->landinfo_data[line_nr]));
223 line_nr++;
224
225 /* Local authority */
226 SetDParam(0, STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE);
227 if (t != NULL) {
228 SetDParam(0, STR_TOWN_NAME);
229 SetDParam(1, t->index);
230 }
231 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY, lastof(this->landinfo_data[line_nr]));
232 line_nr++;
233
234 /* Build date */
235 if (td.build_date != INVALID_DATE) {
236 SetDParam(0, td.build_date);
237 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_BUILD_DATE, lastof(this->landinfo_data[line_nr]));
238 line_nr++;
239 }
240
241 /* Station class */
242 if (td.station_class != STR_NULL) {
243 SetDParam(0, td.station_class);
244 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_STATION_CLASS, lastof(this->landinfo_data[line_nr]));
245 line_nr++;
246 }
247
248 /* Station type name */
249 if (td.station_name != STR_NULL) {
250 SetDParam(0, td.station_name);
251 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_STATION_TYPE, lastof(this->landinfo_data[line_nr]));
252 line_nr++;
253 }
254
255 /* Airport class */
256 if (td.airport_class != STR_NULL) {
257 SetDParam(0, td.airport_class);
258 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORT_CLASS, lastof(this->landinfo_data[line_nr]));
259 line_nr++;
260 }
261
262 /* Airport name */
263 if (td.airport_name != STR_NULL) {
264 SetDParam(0, td.airport_name);
265 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORT_NAME, lastof(this->landinfo_data[line_nr]));
266 line_nr++;
267 }
268
269 /* Airport tile name */
270 if (td.airport_tile_name != STR_NULL) {
271 SetDParam(0, td.airport_tile_name);
272 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORTTILE_NAME, lastof(this->landinfo_data[line_nr]));
273 line_nr++;
274 }
275
276 /* Rail type name */
277 if (td.railtype != STR_NULL) {
278 SetDParam(0, td.railtype);
279 GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_RAIL_TYPE, lastof(this->landinfo_data[line_nr]));
280 line_nr++;
281 }
282
283 /* Rail speed limit */
284 if (td.rail_speed != 0) {
285 SetDParam(0, td.rail_speed);
286 GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_RAIL_SPEED_LIMIT, lastof(this->landinfo_data[line_nr]));
287 line_nr++;
288 }
289
290 /* Road speed limit */
291 if (td.road_speed != 0) {
292 SetDParam(0, td.road_speed);
293 GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_ROAD_SPEED_LIMIT, lastof(this->landinfo_data[line_nr]));
294 line_nr++;
295 }
296
297 /* NewGRF name */
298 if (td.grf != NULL) {
299 SetDParamStr(0, td.grf);
300 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_NEWGRF_NAME, lastof(this->landinfo_data[line_nr]));
301 line_nr++;
302 }
303
304 assert(line_nr < LAND_INFO_CENTERED_LINES);
305
306 /* Mark last line empty */
307 this->landinfo_data[line_nr][0] = '\0';
308
309 /* Cargo acceptance is displayed in a extra multiline */
310 char *strp = GetString(this->landinfo_data[LAND_INFO_MULTICENTER_LINE], STR_LAND_AREA_INFORMATION_CARGO_ACCEPTED, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
311 bool found = false;
312
313 for (CargoID i = 0; i < NUM_CARGO; ++i) {
314 if (acceptance[i] > 0) {
315 /* Add a comma between each item. */
316 if (found) {
317 *strp++ = ',';
318 *strp++ = ' ';
319 }
320 found = true;
321
322 /* If the accepted value is less than 8, show it in 1/8:ths */
323 if (acceptance[i] < 8) {
324 SetDParam(0, acceptance[i]);
325 SetDParam(1, CargoSpec::Get(i)->name);
326 strp = GetString(strp, STR_LAND_AREA_INFORMATION_CARGO_EIGHTS, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
327 } else {
328 strp = GetString(strp, CargoSpec::Get(i)->name, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
329 }
330 }
331 }
332 if (!found) this->landinfo_data[LAND_INFO_MULTICENTER_LINE][0] = '\0';
333 }
334
335 virtual bool IsNewGRFInspectable() const
336 {
337 return ::IsNewGRFInspectable(GetGrfSpecFeature(this->tile), this->tile);
338 }
339
340 virtual void ShowNewGRFInspectWindow() const
341 {
342 ::ShowNewGRFInspectWindow(GetGrfSpecFeature(this->tile), this->tile);
343 }
344
350 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
351 {
352 if (!gui_scope) return;
353 switch (data) {
354 case 1:
355 /* ReInit, "debug" sprite might have changed */
356 this->ReInit();
357 break;
358 }
359 }
360 };
361
366 void ShowLandInfo(TileIndex tile)
367 {
368 DeleteWindowById(WC_LAND_INFO, 0);
369 new LandInfoWindow(tile);
370 }
371
372 static const NWidgetPart _nested_about_widgets[] = {
373 NWidget(NWID_HORIZONTAL),
374 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
375 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_ABOUT_OPENTTD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
376 EndContainer(),
377 NWidget(WWT_PANEL, COLOUR_GREY), SetPIP(4, 2, 4),
378 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_ABOUT_ORIGINAL_COPYRIGHT, STR_NULL),
379 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_ABOUT_VERSION, STR_NULL),
380 NWidget(WWT_FRAME, COLOUR_GREY), SetPadding(0, 5, 1, 5),
381 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_A_SCROLLING_TEXT),
382 EndContainer(),
383 NWidget(WWT_LABEL, COLOUR_GREY, WID_A_WEBSITE), SetDataTip(STR_BLACK_RAW_STRING, STR_NULL),
384 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_ABOUT_COPYRIGHT_OPENTTD, STR_NULL),
385 EndContainer(),
386 };
387
388 static WindowDesc _about_desc(
389 WDP_CENTER, NULL, 0, 0,
390 WC_GAME_OPTIONS, WC_NONE,
391 0,
392 _nested_about_widgets, lengthof(_nested_about_widgets)
393 );
394
395 static const char * const _credits[] = {
396 "Original design by Chris Sawyer",
397 "Original graphics by Simon Foster",
398 "",
399 "The OpenTTD team (in alphabetical order):",
400 " Grzegorz Duczy\xC5\x84ski (adf88) - General coding (since 1.7.2)",
401 " Albert Hofkamp (Alberth) - GUI expert (since 0.7)",
402 " Matthijs Kooijman (blathijs) - Pathfinder-guru, Debian port (since 0.3)",
403 " Ulf Hermann (fonsinchen) - Cargo Distribution (since 1.3)",
404 " Christoph Elsenhans (frosch) - General coding (since 0.6)",
405 " Lo\xC3\xAF""c Guilloux (glx) - General / Windows Expert (since 0.4.5)",
406 " Michael Lutz (michi_cc) - Path based signals (since 0.7)",
407 " Owen Rudge (orudge) - Forum host, OS/2 port (since 0.1)",
408 " Peter Nelson (peter1138) - Spiritual descendant from NewGRF gods (since 0.4.5)",
409 " Ingo von Borstel (planetmaker) - General, Support (since 1.1)",
410 " Remko Bijker (Rubidium) - Lead coder and way more (since 0.4.5)",
411 " Jos\xC3\xA9 Soler (Terkhen) - General coding (since 1.0)",
412 " Leif Linse (Zuu) - AI/Game Script (since 1.2)",
413 "",
414 "Inactive Developers:",
415 " Jean-Fran\xC3\xA7ois Claeys (Belugas) - GUI, NewGRF and more (0.4.5 - 1.0)",
416 " Bjarni Corfitzen (Bjarni) - MacOSX port, coder and vehicles (0.3 - 0.7)",
417 " Victor Fischer (Celestar) - Programming everywhere you need him to (0.3 - 0.6)",
418 " Jaroslav Mazanec (KUDr) - YAPG (Yet Another Pathfinder God) ;) (0.4.5 - 0.6)",
419 " Jonathan Coome (Maedhros) - High priest of the NewGRF Temple (0.5 - 0.6)",
420 " Attila B\xC3\xA1n (MiHaMiX) - Developer WebTranslator 1 and 2 (0.3 - 0.5)",
421 " Zden\xC4\x9Bk Sojka (SmatZ) - Bug finder and fixer (0.6 - 1.3)",
422 " Christoph Mallon (Tron) - Programmer, code correctness police (0.3 - 0.5)",
423 " Patric Stout (TrueBrain) - NoAI, NoGo, Network (0.3 - 1.2), sys op (active)",
424 " Thijs Marinussen (Yexo) - AI Framework, General (0.6 - 1.3)",
425 "",
426 "Retired Developers:",
427 " Tam\xC3\xA1s Farag\xC3\xB3 (Darkvater) - Ex-Lead coder (0.3 - 0.5)",
428 " Dominik Scherer (dominik81) - Lead programmer, GUI expert (0.3 - 0.3)",
429 " Emil Djupfeld (egladil) - MacOSX (0.4.5 - 0.6)",
430 " Simon Sasburg (HackyKid) - Many bugfixes (0.4 - 0.4.5)",
431 " Ludvig Strigeus (ludde) - Original author of OpenTTD, main coder (0.1 - 0.3)",
432 " Cian Duffy (MYOB) - BeOS port / manual writing (0.1 - 0.3)",
433 " Petr Baudi\xC5\xA1 (pasky) - Many patches, NewGRF support (0.3 - 0.3)",
434 " Benedikt Br\xC3\xBCggemeier (skidd13) - Bug fixer and code reworker (0.6 - 0.7)",
435 " Serge Paquet (vurlix) - 2nd contributor after ludde (0.1 - 0.3)",
436 "",
437 "Special thanks go out to:",
438 " Josef Drexler - For his great work on TTDPatch",
439 " Marcin Grzegorczyk - Track foundations and for describing TTD internals",
440 " Stefan Mei\xC3\x9Fner (sign_de) - For his work on the console",
441 " Mike Ragsdale - OpenTTD installer",
442 " Christian Rosentreter (tokai) - MorphOS / AmigaOS port",
443 " Richard Kempton (richK) - additional airports, initial TGP implementation",
444 " Emperor Jake - titlegame",
445 "",
446 " Alberto Demichelis - Squirrel scripting language \xC2\xA9 2003-2008",
447 " L. Peter Deutsch - MD5 implementation \xC2\xA9 1999, 2000, 2002",
448 " Michael Blunck - Pre-signals and semaphores \xC2\xA9 2003",
449 " George - Canal/Lock graphics \xC2\xA9 2003-2004",
450 " Andrew Parkhouse (andythenorth) - River graphics",
451 " David Dallaston (Pikka) - Tram tracks",
452 " All Translators - Who made OpenTTD a truly international game",
453 " Bug Reporters - Without whom OpenTTD would still be full of bugs!",
454 "",
455 "",
456 "And last but not least:",
457 " Chris Sawyer - For an amazing game!"
458 };
459
460 struct AboutWindow : public Window {
461 int text_position;
462 byte counter;
463 int line_height;
464 static const int num_visible_lines = 19;
465
466 AboutWindow() : Window(&_about_desc)
467 {
468 this->InitNested(WN_GAME_OPTIONS_ABOUT);
469
470 this->counter = 5;
471 this->text_position = this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->current_y;
472 }
473
474 virtual void SetStringParameters(int widget) const
475 {
476 if (widget == WID_A_WEBSITE) SetDParamStr(0, "Website: http://www.openttd.org");
477 }
478
479 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
480 {
481 if (widget != WID_A_SCROLLING_TEXT) return;
482
483 this->line_height = FONT_HEIGHT_NORMAL;
484
485 Dimension d;
486 d.height = this->line_height * num_visible_lines;
487
488 d.width = 0;
489 for (uint i = 0; i < lengthof(_credits); i++) {
490 d.width = max(d.width, GetStringBoundingBox(_credits[i]).width);
491 }
492 *size = maxdim(*size, d);
493 }
494
495 virtual void DrawWidget(const Rect &r, int widget) const
496 {
497 if (widget != WID_A_SCROLLING_TEXT) return;
498
499 int y = this->text_position;
500
501 /* Show all scrolling _credits */
502 for (uint i = 0; i < lengthof(_credits); i++) {
503 if (y >= r.top + 7 && y < r.bottom - this->line_height) {
504 DrawString(r.left, r.right, y, _credits[i], TC_BLACK, SA_LEFT | SA_FORCE);
505 }
506 y += this->line_height;
507 }
508 }
509
510 virtual void OnTick()
511 {
512 if (--this->counter == 0) {
513 this->counter = 5;
514 this->text_position--;
515 /* If the last text has scrolled start a new from the start */
516 if (this->text_position < (int)(this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y - lengthof(_credits) * this->line_height)) {
517 this->text_position = this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->current_y;
518 }
519 this->SetDirty();
520 }
521 }
522 };
523
524 void ShowAboutWindow()
525 {
526 DeleteWindowByClass(WC_GAME_OPTIONS);
527 new AboutWindow();
528 }
529
536 void ShowEstimatedCostOrIncome(Money cost, int x, int y)
537 {
538 StringID msg = STR_MESSAGE_ESTIMATED_COST;
539
540 if (cost < 0) {
541 cost = -cost;
542 msg = STR_MESSAGE_ESTIMATED_INCOME;
543 }
544 SetDParam(0, cost);
545 ShowErrorMessage(msg, INVALID_STRING_ID, WL_INFO, x, y);
546 }
547
555 void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
556 {
557 Point pt = RemapCoords(x, y, z);
558 StringID msg = STR_INCOME_FLOAT_COST;
559
560 if (cost < 0) {
561 cost = -cost;
562 msg = STR_INCOME_FLOAT_INCOME;
563 }
564 SetDParam(0, cost);
565 AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING);
566 }
567
576 void ShowFeederIncomeAnimation(int x, int y, int z, Money transfer, Money income)
577 {
578 Point pt = RemapCoords(x, y, z);
579
580 SetDParam(0, transfer);
581 if (income == 0) {
582 AddTextEffect(STR_FEEDER, pt.x, pt.y, DAY_TICKS, TE_RISING);
583 } else {
584 StringID msg = STR_FEEDER_COST;
585 if (income < 0) {
586 income = -income;
587 msg = STR_FEEDER_INCOME;
588 }
589 SetDParam(1, income);
590 AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING);
591 }
592 }
593
603 TextEffectID ShowFillingPercent(int x, int y, int z, uint8 percent, StringID string)
604 {
605 Point pt = RemapCoords(x, y, z);
606
607 assert(string != STR_NULL);
608
609 SetDParam(0, percent);
610 return AddTextEffect(string, pt.x, pt.y, 0, TE_STATIC);
611 }
612
618 void UpdateFillingPercent(TextEffectID te_id, uint8 percent, StringID string)
619 {
620 assert(string != STR_NULL);
621
622 SetDParam(0, percent);
623 UpdateTextEffect(te_id, string);
624 }
625
630 void HideFillingPercent(TextEffectID *te_id)
631 {
632 if (*te_id == INVALID_TE_ID) return;
633
634 RemoveTextEffect(*te_id);
635 *te_id = INVALID_TE_ID;
636 }
637
638 static const NWidgetPart _nested_tooltips_widgets[] = {
639 NWidget(WWT_PANEL, COLOUR_GREY, WID_TT_BACKGROUND), SetMinimalSize(200, 32), EndContainer(),
640 };
641
642 static WindowDesc _tool_tips_desc(
643 WDP_MANUAL, NULL, 0, 0, // Coordinates and sizes are not used,
644 WC_TOOLTIPS, WC_NONE,
645 WDF_NO_FOCUS,
646 _nested_tooltips_widgets, lengthof(_nested_tooltips_widgets)
647 );
648
650 struct TooltipsWindow : public Window
651 {
652 StringID string_id;
653 byte paramcount;
654 uint64 params[5];
655 TooltipCloseCondition close_cond;
656
657 TooltipsWindow(Window *parent, StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip) : Window(&_tool_tips_desc)
658 {
659 this->parent = parent;
660 this->string_id = str;
661 assert_compile(sizeof(this->params[0]) == sizeof(params[0]));
662 assert(paramcount <= lengthof(this->params));
663 memcpy(this->params, params, sizeof(this->params[0]) * paramcount);
664 this->paramcount = paramcount;
665 this->close_cond = close_tooltip;
666
667 this->InitNested();
668
669 CLRBITS(this->flags, WF_WHITE_BORDER);
670 }
671
672 virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
673 {
674 /* Find the free screen space between the main toolbar at the top, and the statusbar at the bottom.
675 * Add a fixed distance 2 so the tooltip floats free from both bars.
676 */
677 int scr_top = GetMainViewTop() + 2;
678 int scr_bot = GetMainViewBottom() - 2;
679
680 Point pt;
681
682 /* Correctly position the tooltip position, watch out for window and cursor size
683 * Clamp value to below main toolbar and above statusbar. If tooltip would
684 * go below window, flip it so it is shown above the cursor */
685 pt.y = Clamp(_cursor.pos.y + _cursor.total_size.y + _cursor.total_offs.y + 5, scr_top, scr_bot);
686 if (pt.y + sm_height > scr_bot) pt.y = min(_cursor.pos.y + _cursor.total_offs.y - 5, scr_bot) - sm_height;
687 pt.x = sm_width >= _screen.width ? 0 : Clamp(_cursor.pos.x - (sm_width >> 1), 0, _screen.width - sm_width);
688
689 return pt;
690 }
691
692 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
693 {
694 /* There is only one widget. */
695 for (uint i = 0; i != this->paramcount; i++) SetDParam(i, this->params[i]);
696
697 size->width = min(GetStringBoundingBox(this->string_id).width, ScaleGUITrad(194));
698 size->height = GetStringHeight(this->string_id, size->width);
699
700 /* Increase slightly to have some space around the box. */
701 size->width += 2 + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
702 size->height += 2 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
703 }
704
705 virtual void DrawWidget(const Rect &r, int widget) const
706 {
707 /* There is only one widget. */
708 GfxFillRect(r.left, r.top, r.right, r.bottom, PC_BLACK);
709 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_LIGHT_YELLOW);
710
711 for (uint arg = 0; arg < this->paramcount; arg++) {
712 SetDParam(arg, this->params[arg]);
713 }
714 DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, this->string_id, TC_FROMSTRING, SA_CENTER);
715 }
716
717 virtual void OnMouseLoop()
718 {
719 /* Always close tooltips when the cursor is not in our window. */
720 if (!_cursor.in_window) {
721 delete this;
722 return;
723 }
724
725 /* We can show tooltips while dragging tools. These are shown as long as
726 * we are dragging the tool. Normal tooltips work with hover or rmb. */
727 switch (this->close_cond) {
728 case TCC_RIGHT_CLICK: if (!_right_button_down) delete this; break;
729 case TCC_LEFT_CLICK: if (!_left_button_down) delete this; break;
730 case TCC_HOVER: if (!_mouse_hovering) delete this; break;
731 }
732 }
733 };
734
743 void GuiShowTooltips(Window *parent, StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip)
744 {
745 DeleteWindowById(WC_TOOLTIPS, 0);
746
747 if (str == STR_NULL) return;
748
749 new TooltipsWindow(parent, str, paramcount, params, close_tooltip);
750 }
751
752 void QueryString::HandleEditBox(Window *w, int wid)
753 {
754 if (w->IsWidgetGloballyFocused(wid) && this->text.HandleCaret()) {
755 w->SetWidgetDirty(wid);
756
757 /* For the OSK also invalidate the parent window */
758 if (w->window_class == WC_OSK) w->InvalidateData();
759 }
760 }
761
762 void QueryString::DrawEditBox(const Window *w, int wid) const
763 {
764 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
765
766 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
767
768 bool rtl = _current_text_dir == TD_RTL;
769 Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
770 int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
771
772 int clearbtn_left = wi->pos_x + (rtl ? 0 : wi->current_x - clearbtn_width);
773 int clearbtn_right = wi->pos_x + (rtl ? clearbtn_width : wi->current_x) - 1;
774 int left = wi->pos_x + (rtl ? clearbtn_width : 0);
775 int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
776
777 int top = wi->pos_y;
778 int bottom = wi->pos_y + wi->current_y - 1;
779
780 DrawFrameRect(clearbtn_left, top, clearbtn_right, bottom, wi->colour, wi->IsLowered() ? FR_LOWERED : FR_NONE);
781 DrawSprite(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, clearbtn_left + WD_IMGBTN_LEFT + (wi->IsLowered() ? 1 : 0), (top + bottom - sprite_size.height) / 2 + (wi->IsLowered() ? 1 : 0));
782 if (this->text.bytes == 1) GfxFillRect(clearbtn_left + 1, top + 1, clearbtn_right - 1, bottom - 1, _colour_gradient[wi->colour & 0xF][2], FILLRECT_CHECKER);
783
784 DrawFrameRect(left, top, right, bottom, wi->colour, FR_LOWERED | FR_DARKENED);
785 GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, PC_BLACK);
786
787 /* Limit the drawing of the string inside the widget boundaries */
788 DrawPixelInfo dpi;
789 if (!FillDrawPixelInfo(&dpi, left + WD_FRAMERECT_LEFT, top + WD_FRAMERECT_TOP, right - left - WD_FRAMERECT_RIGHT, bottom - top - WD_FRAMERECT_BOTTOM)) return;
790
791 DrawPixelInfo *old_dpi = _cur_dpi;
792 _cur_dpi = &dpi;
793
794 /* We will take the current widget length as maximum width, with a small
795 * space reserved at the end for the caret to show */
796 const Textbuf *tb = &this->text;
797 int delta = min(0, (right - left) - tb->pixels - 10);
798
799 if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
800
801 /* If we have a marked area, draw a background highlight. */
802 if (tb->marklength != 0) GfxFillRect(delta + tb->markxoffs, 0, delta + tb->markxoffs + tb->marklength - 1, bottom - top, PC_GREY);
803
804 DrawString(delta, tb->pixels, 0, tb->buf, TC_YELLOW);
805 bool focussed = w->IsWidgetGloballyFocused(wid) || IsOSKOpenedFor(w, wid);
806 if (focussed && tb->caret) {
807 int caret_width = GetStringBoundingBox("_").width;
808 DrawString(tb->caretxoffs + delta, tb->caretxoffs + delta + caret_width, 0, "_", TC_WHITE);
809 }
810
811 _cur_dpi = old_dpi;
812 }
813
820 Point QueryString::GetCaretPosition(const Window *w, int wid) const
821 {
822 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
823
824 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
825
826 bool rtl = _current_text_dir == TD_RTL;
827 Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
828 int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
829
830 int left = wi->pos_x + (rtl ? clearbtn_width : 0);
831 int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
832
833 /* Clamp caret position to be inside out current width. */
834 const Textbuf *tb = &this->text;
835 int delta = min(0, (right - left) - tb->pixels - 10);
836 if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
837
838 Point pt = {left + WD_FRAMERECT_LEFT + tb->caretxoffs + delta, (int)wi->pos_y + WD_FRAMERECT_TOP};
839 return pt;
840 }
841
850 Rect QueryString::GetBoundingRect(const Window *w, int wid, const char *from, const char *to) const
851 {
852 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
853
854 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
855
856 bool rtl = _current_text_dir == TD_RTL;
857 Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
858 int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
859
860 int left = wi->pos_x + (rtl ? clearbtn_width : 0);
861 int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
862
863 int top = wi->pos_y + WD_FRAMERECT_TOP;
864 int bottom = wi->pos_y + wi->current_y - 1 - WD_FRAMERECT_BOTTOM;
865
866 /* Clamp caret position to be inside our current width. */
867 const Textbuf *tb = &this->text;
868 int delta = min(0, (right - left) - tb->pixels - 10);
869 if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
870
871 /* Get location of first and last character. */
872 Point p1 = GetCharPosInString(tb->buf, from, FS_NORMAL);
873 Point p2 = from != to ? GetCharPosInString(tb->buf, to, FS_NORMAL) : p1;
874
875 Rect r = { Clamp(left + p1.x + delta + WD_FRAMERECT_LEFT, left, right), top, Clamp(left + p2.x + delta + WD_FRAMERECT_LEFT, left, right - WD_FRAMERECT_RIGHT), bottom };
876
877 return r;
878 }
879
887 const char *QueryString::GetCharAtPosition(const Window *w, int wid, const Point &pt) const
888 {
889 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
890
891 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
892
893 bool rtl = _current_text_dir == TD_RTL;
894 Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
895 int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
896
897 int left = wi->pos_x + (rtl ? clearbtn_width : 0);
898 int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
899
900 int top = wi->pos_y + WD_FRAMERECT_TOP;
901 int bottom = wi->pos_y + wi->current_y - 1 - WD_FRAMERECT_BOTTOM;
902
903 if (!IsInsideMM(pt.y, top, bottom)) return NULL;
904
905 /* Clamp caret position to be inside our current width. */
906 const Textbuf *tb = &this->text;
907 int delta = min(0, (right - left) - tb->pixels - 10);
908 if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
909
910 return ::GetCharAtPosition(tb->buf, pt.x - delta - left);
911 }
912
913 void QueryString::ClickEditBox(Window *w, Point pt, int wid, int click_count, bool focus_changed)
914 {
915 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
916
917 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
918
919 bool rtl = _current_text_dir == TD_RTL;
920 int clearbtn_width = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT).width;
921
922 int clearbtn_left = wi->pos_x + (rtl ? 0 : wi->current_x - clearbtn_width);
923
924 if (IsInsideBS(pt.x, clearbtn_left, clearbtn_width)) {
925 if (this->text.bytes > 1) {
926 this->text.DeleteAll();
927 w->HandleButtonClick(wid);
928 w->OnEditboxChanged(wid);
929 }
930 return;
931 }
932
933 if (w->window_class != WC_OSK && _settings_client.gui.osk_activation != OSKA_DISABLED &&
934 (!focus_changed || _settings_client.gui.osk_activation == OSKA_IMMEDIATELY) &&
935 (click_count == 2 || _settings_client.gui.osk_activation != OSKA_DOUBLE_CLICK)) {
936 /* Open the OSK window */
937 ShowOnScreenKeyboard(w, wid);
938 }
939 }
940
942 struct QueryStringWindow : public Window
943 {
944 QueryString editbox;
945 QueryStringFlags flags;
946
947 QueryStringWindow(StringID str, StringID caption, uint max_bytes, uint max_chars, WindowDesc *desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) :
948 Window(desc), editbox(max_bytes, max_chars)
949 {
950 char *last_of = &this->editbox.text.buf[this->editbox.text.max_bytes - 1];
951 GetString(this->editbox.text.buf, str, last_of);
952 str_validate(this->editbox.text.buf, last_of, SVS_NONE);
953
954 /* Make sure the name isn't too long for the text buffer in the number of
955 * characters (not bytes). max_chars also counts the '\0' characters. */
956 while (Utf8StringLength(this->editbox.text.buf) + 1 > this->editbox.text.max_chars) {
957 *Utf8PrevChar(this->editbox.text.buf + strlen(this->editbox.text.buf)) = '\0';
958 }
959
960 this->editbox.text.UpdateSize();
961
962 if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->editbox.orig = stredup(this->editbox.text.buf);
963
964 this->querystrings[WID_QS_TEXT] = &this->editbox;
965 this->editbox.caption = caption;
966 this->editbox.cancel_button = WID_QS_CANCEL;
967 this->editbox.ok_button = WID_QS_OK;
968 this->editbox.text.afilter = afilter;
969 this->flags = flags;
970
971 this->InitNested(WN_QUERY_STRING);
972
973 this->parent = parent;
974
975 this->SetFocusedWidget(WID_QS_TEXT);
976 }
977
978 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
979 {
980 if (widget == WID_QS_DEFAULT && (this->flags & QSF_ENABLE_DEFAULT) == 0) {
981 /* We don't want this widget to show! */
982 fill->width = 0;
983 resize->width = 0;
984 size->width = 0;
985 }
986 }
987
988 virtual void SetStringParameters(int widget) const
989 {
990 if (widget == WID_QS_CAPTION) SetDParam(0, this->editbox.caption);
991 }
992
993 void OnOk()
994 {
995 if (this->editbox.orig == NULL || strcmp(this->editbox.text.buf, this->editbox.orig) != 0) {
996 /* If the parent is NULL, the editbox is handled by general function
997 * HandleOnEditText */
998 if (this->parent != NULL) {
999 this->parent->OnQueryTextFinished(this->editbox.text.buf);
1000 } else {
1001 HandleOnEditText(this->editbox.text.buf);
1002 }
1003 this->editbox.handled = true;
1004 }
1005 }
1006
1007 virtual void OnClick(Point pt, int widget, int click_count)
1008 {
1009 switch (widget) {
1010 case WID_QS_DEFAULT:
1011 this->editbox.text.DeleteAll();
1012 FALLTHROUGH;
1013
1014 case WID_QS_OK:
1015 this->OnOk();
1016 FALLTHROUGH;
1017
1018 case WID_QS_CANCEL:
1019 delete this;
1020 break;
1021 }
1022 }
1023
1024 ~QueryStringWindow()
1025 {
1026 if (!this->editbox.handled && this->parent != NULL) {
1027 Window *parent = this->parent;
1028 this->parent = NULL; // so parent doesn't try to delete us again
1029 parent->OnQueryTextFinished(NULL);
1030 }
1031 }
1032 };
1033
1034 static const NWidgetPart _nested_query_string_widgets[] = {
1035 NWidget(NWID_HORIZONTAL),
1036 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1037 NWidget(WWT_CAPTION, COLOUR_GREY, WID_QS_CAPTION), SetDataTip(STR_WHITE_STRING, STR_NULL),
1038 EndContainer(),
1039 NWidget(WWT_PANEL, COLOUR_GREY),
1040 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_QS_TEXT), SetMinimalSize(256, 12), SetFill(1, 1), SetPadding(2, 2, 2, 2),
1041 EndContainer(),
1042 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1043 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_DEFAULT), SetMinimalSize(87, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_DEFAULT, STR_NULL),
1044 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_CANCEL), SetMinimalSize(86, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
1045 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_OK), SetMinimalSize(87, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_OK, STR_NULL),
1046 EndContainer(),
1047 };
1048
1049 static WindowDesc _query_string_desc(
1050 WDP_CENTER, "query_string", 0, 0,
1051 WC_QUERY_STRING, WC_NONE,
1052 0,
1053 _nested_query_string_widgets, lengthof(_nested_query_string_widgets)
1054 );
1055
1066 void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
1067 {
1068 DeleteWindowByClass(WC_QUERY_STRING);
1069 new QueryStringWindow(str, caption, ((flags & QSF_LEN_IN_CHARS) ? MAX_CHAR_LENGTH : 1) * maxsize, maxsize, &_query_string_desc, parent, afilter, flags);
1070 }
1071
1075 struct QueryWindow : public Window {
1076 QueryCallbackProc *proc;
1077 uint64 params[10];
1078 StringID message;
1079 StringID caption;
1080
1081 QueryWindow(WindowDesc *desc, StringID caption, StringID message, Window *parent, QueryCallbackProc *callback) : Window(desc)
1082 {
1083 /* Create a backup of the variadic arguments to strings because it will be
1084 * overridden pretty often. We will copy these back for drawing */
1085 CopyOutDParam(this->params, 0, lengthof(this->params));
1086 this->caption = caption;
1087 this->message = message;
1088 this->proc = callback;
1089
1090 this->InitNested(WN_CONFIRM_POPUP_QUERY);
1091
1092 this->parent = parent;
1093 this->left = parent->left + (parent->width / 2) - (this->width / 2);
1094 this->top = parent->top + (parent->height / 2) - (this->height / 2);
1095 }
1096
1097 ~QueryWindow()
1098 {
1099 if (this->proc != NULL) this->proc(this->parent, false);
1100 }
1101
1102 virtual void SetStringParameters(int widget) const
1103 {
1104 switch (widget) {
1105 case WID_Q_CAPTION:
1106 CopyInDParam(1, this->params, lengthof(this->params));
1107 SetDParam(0, this->caption);
1108 break;
1109
1110 case WID_Q_TEXT:
1111 CopyInDParam(0, this->params, lengthof(this->params));
1112 break;
1113 }
1114 }
1115
1116 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
1117 {
1118 if (widget != WID_Q_TEXT) return;
1119
1120 Dimension d = GetStringMultiLineBoundingBox(this->message, *size);
1121 d.width += WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
1122 d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
1123 *size = d;
1124 }
1125
1126 virtual void DrawWidget(const Rect &r, int widget) const
1127 {
1128 if (widget != WID_Q_TEXT) return;
1129
1130 DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM,
1131 this->message, TC_FROMSTRING, SA_CENTER);
1132 }
1133
1134 virtual void OnClick(Point pt, int widget, int click_count)
1135 {
1136 switch (widget) {
1137 case WID_Q_YES: {
1138 /* in the Generate New World window, clicking 'Yes' causes
1139 * DeleteNonVitalWindows() to be called - we shouldn't be in a window then */
1140 QueryCallbackProc *proc = this->proc;
1141 Window *parent = this->parent;
1142 /* Prevent the destructor calling the callback function */
1143 this->proc = NULL;
1144 delete this;
1145 if (proc != NULL) {
1146 proc(parent, true);
1147 proc = NULL;
1148 }
1149 break;
1150 }
1151 case WID_Q_NO:
1152 delete this;
1153 break;
1154 }
1155 }
1156
1157 virtual EventState OnKeyPress(WChar key, uint16 keycode)
1158 {
1159 /* ESC closes the window, Enter confirms the action */
1160 switch (keycode) {
1161 case WKC_RETURN:
1162 case WKC_NUM_ENTER:
1163 if (this->proc != NULL) {
1164 this->proc(this->parent, true);
1165 this->proc = NULL;
1166 }
1167 FALLTHROUGH;
1168
1169 case WKC_ESC:
1170 delete this;
1171 return ES_HANDLED;
1172 }
1173 return ES_NOT_HANDLED;
1174 }
1175 };
1176
1177 static const NWidgetPart _nested_query_widgets[] = {
1178 NWidget(NWID_HORIZONTAL),
1179 NWidget(WWT_CLOSEBOX, COLOUR_RED),
1180 NWidget(WWT_CAPTION, COLOUR_RED, WID_Q_CAPTION), SetDataTip(STR_JUST_STRING, STR_NULL),
1181 EndContainer(),
1182 NWidget(WWT_PANEL, COLOUR_RED), SetPIP(8, 15, 8),
1183 NWidget(WWT_TEXT, COLOUR_RED, WID_Q_TEXT), SetMinimalSize(200, 12),
1184 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(20, 29, 20),
1185 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_Q_NO), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_QUIT_NO, STR_NULL),
1186 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_Q_YES), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_QUIT_YES, STR_NULL),
1187 EndContainer(),
1188 EndContainer(),
1189 };
1190
1191 static WindowDesc _query_desc(
1192 WDP_CENTER, NULL, 0, 0,
1193 WC_CONFIRM_POPUP_QUERY, WC_NONE,
1194 WDF_MODAL,
1195 _nested_query_widgets, lengthof(_nested_query_widgets)
1196 );
1197
1207 void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
1208 {
1209 if (parent == NULL) parent = FindWindowById(WC_MAIN_WINDOW, 0);
1210
1211 const Window *w;
1212 FOR_ALL_WINDOWS_FROM_BACK(w) {
1213 if (w->window_class != WC_CONFIRM_POPUP_QUERY) continue;
1214
1215 const QueryWindow *qw = (const QueryWindow *)w;
1216 if (qw->parent != parent || qw->proc != callback) continue;
1217
1218 delete qw;
1219 break;
1220 }
1221
1222 new QueryWindow(&_query_desc, caption, message, parent, callback);
1223 }
EventState
EventState
State of handling an event.
Definition: window_type.h:701
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:303
strings_func.h
Functions related to OTTD&#39;s strings.
Window::OnQueryTextFinished
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
Definition: window_gui.h:721
WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:48
newgrf_debug.h
Functions/types related to NewGRF debugging.
AboutWindow::DrawWidget
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: misc_gui.cpp:495
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:257
LandInfoWindow
Definition: misc_gui.cpp:61
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:156
QueryWindow::DrawWidget
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: misc_gui.cpp:1126
OSKA_SINGLE_CLICK
Single click after focus click opens OSK.
Definition: misc_gui.cpp:40
SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_func.h:99
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1843
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:112
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:119
QueryStringWindow::SetStringParameters
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: misc_gui.cpp:988
LandInfoWindow::OnInit
virtual void OnInit()
Notification that the nested widget tree gets initialized.
Definition: misc_gui.cpp:138
TooltipsWindow::OnInitialPosition
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Compute the initial position of the window.
Definition: misc_gui.cpp:672
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:332
OSKA_IMMEDIATELY
Focusing click already opens OSK.
Definition: misc_gui.cpp:41
WindowDesc
High level window description.
Definition: window_gui.h:168
QueryWindow::OnClick
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: misc_gui.cpp:1134
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition: settings_type.h:553
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:305
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:312
RemapCoords
static Point RemapCoords(int x, int y, int z)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap...
Definition: landscape.h:83
IsInsideMM
static bool IsInsideMM(const T x, const uint min, const uint max)
Checks if a value is in an interval.
Definition: math_func.hpp:266
TileDesc::grf
const char * grf
newGRF used for the tile contents
Definition: tile_cmd.h:63
WWT_LABEL
Centered label.
Definition: widget_type.h:57
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:398
_right_button_down
bool _right_button_down
Is right mouse button pressed?
Definition: gfx.cpp:41
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:577
WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
WD_PAR_VSEP_NORMAL
Normal amount of vertical space between two paragraphs of text.
Definition: window_gui.h:139
debug.h
Functions related to debugging.
NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1105
ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:703
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:53
WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX) ...
Definition: widget_type.h:63
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1066
ScaleGUITrad
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:82
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:163
WID_Q_TEXT
Text of the query.
Definition: misc_widget.h:43
AboutWindow
Definition: misc_gui.cpp:460
AboutWindow::line_height
int line_height
The height of a single line.
Definition: misc_gui.cpp:463
WID_QS_OK
OK button.
Definition: misc_widget.h:37
LandInfoWindow::DrawWidget
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: misc_gui.cpp:74
DC_NONE
no flag is set
Definition: command_type.h:341
_m
Tile * _m
Tiles of the map.
Definition: map.cpp:32
GuiShowTooltips
void GuiShowTooltips(Window *parent, StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip)
Shows a tooltip.
Definition: misc_gui.cpp:743
TooltipsWindow::close_cond
TooltipCloseCondition close_cond
Condition for closing the window.
Definition: misc_gui.cpp:655
AboutWindow::text_position
int text_position
The top of the scrolling text.
Definition: misc_gui.cpp:461
LandInfoWindow::OnInvalidateData
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition: misc_gui.cpp:350
Textbuf::DeleteAll
void CDECL void DeleteAll()
Delete every character in the textbuffer.
Definition: textbuf.cpp:118
WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:71
FR_DARKENED
If set the background is darker, allows for lowered frames with normal background colour when used wi...
Definition: window_gui.h:32
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:207
AboutWindow::SetStringParameters
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: misc_gui.cpp:474
QueryString::GetCaretPosition
Point GetCaretPosition(const Window *w, int wid) const
Get the current caret position.
Definition: misc_gui.cpp:820
CopyInDParam
void CopyInDParam(int offs, const uint64 *src, int num)
Copy num string parameters from array src into the global string parameter array. ...
Definition: strings.cpp:138
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:313
IsInsideBS
static bool IsInsideBS(const T x, const uint base, const uint size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:250
LandInfoWindow::LandInfoLines
LandInfoLines
Definition: misc_gui.cpp:62
CMD_LANDSCAPE_CLEAR
demolish a tile
Definition: command_type.h:182
TileDesc
Tile description for the &#39;land area information&#39; tool.
Definition: tile_cmd.h:53
Window::OnEditboxChanged
virtual void OnEditboxChanged(int widget)
The text in an editbox has been edited.
Definition: window_gui.h:713
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
WID_QS_TEXT
Text of the query.
Definition: misc_widget.h:34
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:547
DAY_TICKS
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
Definition: date_type.h:30
WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:69
LandInfoWindow::IsNewGRFInspectable
virtual bool IsNewGRFInspectable() const
Is the data related to this window NewGRF inspectable?
Definition: misc_gui.cpp:335
GUISettings::osk_activation
uint8 osk_activation
Mouse gesture to trigger the OSK.
Definition: settings_type.h:139
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
Window::ReInit
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:970
QSF_ACCEPT_UNCHANGED
return success even when the text didn&#39;t change
Definition: textbuf_gui.h:22
EconomySettings::dist_local_authority
byte dist_local_authority
distance for town local authority, default 20
Definition: settings_type.h:475
Textbuf
Helper/buffer for input fields.
Definition: textbuf_type.h:32
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:84
PC_LIGHT_YELLOW
static const uint8 PC_LIGHT_YELLOW
Light yellow palette colour.
Definition: gfx_func.h:221
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition: bitmath_func.hpp:168
QueryWindow::OnKeyPress
virtual EventState OnKeyPress(WChar key, uint16 keycode)
A key has been pressed.
Definition: misc_gui.cpp:1157
CommandCost
Common return value for all commands.
Definition: command_type.h:25
GetGrfSpecFeature
GrfSpecFeature GetGrfSpecFeature(TileIndex tile)
Get the GrfSpecFeature associated with the tile.
Definition: newgrf_debug_gui.cpp:768
max
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
SVS_NONE
Allow nothing and replace nothing.
Definition: string_type.h:49
OskActivation
OskActivation
Method to open the OSK.
Definition: misc_gui.cpp:37
WID_QS_CAPTION
Caption of the window.
Definition: misc_widget.h:33
WWT_TEXT
Pure simple text.
Definition: widget_type.h:58
TileDesc::rail_speed
uint16 rail_speed
Speed limit of rail (bridges and track)
Definition: tile_cmd.h:66
TileDesc::owner
Owner owner[4]
Name of the owner(s)
Definition: tile_cmd.h:55
FillDrawPixelInfo
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition: gfx.cpp:1480
CursorVars::total_size
Point total_size
union of sprite properties
Definition: gfx_type.h:133
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:177
GetTileZ
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition: tile_map.cpp:182
NWidgetLeaf
Leaf widget.
Definition: widget_type.h:770
SA_FORCE
Force the alignment, i.e. don&#39;t swap for RTL languages.
Definition: gfx_func.h:110
_local_company
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition: window.cpp:2163
QueryStringWindow::OnClick
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: misc_gui.cpp:1007
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
querystring_gui.h
Base for the GUIs that have an edit box in them.
Window
Data structure for an opened window.
Definition: window_gui.h:271
QueryStringWindow::flags
QueryStringFlags flags
Flags controlling behaviour of the window.
Definition: misc_gui.cpp:945
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1046
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1833
ShowFillingPercent
TextEffectID ShowFillingPercent(int x, int y, int z, uint8 percent, StringID string)
Display vehicle loading indicators.
Definition: misc_gui.cpp:603
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=NULL, uint textref_stack_size=0, const uint32 *textref_stack=NULL)
Display an error message in a window.
Definition: error_gui.cpp:378
ClosestTownFromTile
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold...
Definition: town_cmd.cpp:3239
WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:46
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:279
QSF_ENABLE_DEFAULT
enable the &#39;Default&#39; button ("\0" is returned)
Definition: textbuf_gui.h:23
QueryString::GetBoundingRect
Rect GetBoundingRect(const Window *w, int wid, const char *from, const char *to) const
Get the bounding rectangle for a range of the query string.
Definition: misc_gui.cpp:850
string_func.h
Functions related to low-level strings.
MAX_CHAR_LENGTH
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition: strings_type.h:20
Textbuf::caret
bool caret
is the caret ("_") visible or not
Definition: textbuf_type.h:40
WID_LI_BACKGROUND
Background of the window.
Definition: misc_widget.h:17
QueryWindow
Window used for asking the user a YES/NO question.
Definition: misc_gui.cpp:1075
ShowOnScreenKeyboard
void ShowOnScreenKeyboard(Window *parent, int button)
Show the on-screen keyboard (osk) associated with a given textbox.
Definition: osk_gui.cpp:412
error.h
Functions related to errors.
GetNameOfOwner
void GetNameOfOwner(Owner owner, TileIndex tile)
Set the right DParams to get the name of an owner.
Definition: company_cmd.cpp:281
DoCommand
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:436
TileDesc::owner_type
StringID owner_type[4]
Type of each owner.
Definition: tile_cmd.h:56
TooltipsWindow::string_id
StringID string_id
String to display as tooltip.
Definition: misc_gui.cpp:652
NWidgetBase::pos_y
uint pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:178
str_validate
void str_validate(char *str, const char *last, StringValidationSettings settings)
Scans the string for valid characters and if it finds invalid ones, replaces them with a question mar...
Definition: string.cpp:184
WID_TT_BACKGROUND
Background of the window.
Definition: misc_widget.h:22
ShowQuery
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:1207
WC_TOOLTIPS
Tooltip window; Window numbers:
Definition: window_type.h:111
Textbuf::markxoffs
uint16 markxoffs
the start position of the marked area in pixels
Definition: textbuf_type.h:45
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:29
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:175
HideFillingPercent
void HideFillingPercent(TextEffectID *te_id)
Hide vehicle loading indicators.
Definition: misc_gui.cpp:630
Textbuf::pixels
uint16 pixels
the current size of the string in pixels
Definition: textbuf_type.h:39
Window::querystrings
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:323
WC_OSK
On Screen Keyboard; Window numbers:
Definition: window_type.h:157
misc_widget.h
Types related to the misc widgets.
IsOSKOpenedFor
bool IsOSKOpenedFor(const Window *w, int button)
Check whether the OSK is opened for a specific editbox.
Definition: osk_gui.cpp:444
_left_button_down
bool _left_button_down
Is left mouse button pressed?
Definition: gfx.cpp:39
ShowEstimatedCostOrIncome
void ShowEstimatedCostOrIncome(Money cost, int x, int y)
Display estimated costs.
Definition: misc_gui.cpp:536
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:180
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
OSKA_DOUBLE_CLICK
Double click on the edit box opens OSK.
Definition: misc_gui.cpp:39
TooltipsWindow
Window for displaying a tooltip.
Definition: misc_gui.cpp:650
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:22
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:76
QueryWindow::message
StringID message
message shown for query window
Definition: misc_gui.cpp:1078
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:152
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
INVALID_DATE
static const Date INVALID_DATE
Representation of an invalid date.
Definition: date_type.h:110
SA_CENTER
Center both horizontally and vertically.
Definition: gfx_func.h:108
QSF_LEN_IN_CHARS
the length of the string is counted in characters
Definition: textbuf_gui.h:24
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition: window.cpp:2152
QueryStringFlags
QueryStringFlags
Flags used in ShowQueryString() call.
Definition: textbuf_gui.h:20
safeguards.h
A number of safeguards to prevent using unsafe methods.
WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
CopyOutDParam
void CopyOutDParam(uint64 *dst, int offs, int num)
Copy num string parameters from the global string parameter array to the dst array.
Definition: strings.cpp:149
geometry_func.hpp
Geometry functions.
_me
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:33
WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
WD_TEXTPANEL_BOTTOM
Offset at bottom to draw below the text.
Definition: window_gui.h:69
WN_CONFIRM_POPUP_QUERY
Query popup confirm.
Definition: window_type.h:26
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:126
_mouse_hovering
bool _mouse_hovering
The mouse is hovering over the same point.
Definition: window.cpp:76
WWT_FRAME
Frame.
Definition: widget_type.h:60
QueryWindow::caption
StringID caption
title of window
Definition: misc_gui.cpp:1079
WDP_CENTER
Center the window.
Definition: window_gui.h:157
AboutWindow::OnTick
virtual void OnTick()
Called once per (game) tick.
Definition: misc_gui.cpp:510
GetCharPosInString
Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsize)
Get the leading corner of a character in a single-line string relative to the start of the string...
Definition: gfx.cpp:727
NWidget
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:1114
WID_QS_DEFAULT
Default button.
Definition: misc_widget.h:35
OWNER_NONE
The tile has no ownership.
Definition: company_type.h:27
CompanyProperties::money
Money money
Money owned by the company.
Definition: company_base.h:64
WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:499
QueryWindow::SetStringParameters
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: misc_gui.cpp:1102
WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: window_gui.h:73
WN_GAME_OPTIONS_ABOUT
About window.
Definition: window_type.h:18
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
TooltipsWindow::paramcount
byte paramcount
Number of string parameters in string_id.
Definition: misc_gui.cpp:653
min
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
NWidgetBase::pos_x
uint pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:177
TileDesc::railtype
StringID railtype
Type of rail on the tile.
Definition: tile_cmd.h:65
TileDesc::airport_tile_name
StringID airport_tile_name
Name of the airport tile.
Definition: tile_cmd.h:62
WC_LAND_INFO
Land info window; Window numbers:
Definition: window_type.h:145
WD_IMGBTN_RIGHT
Right offset of the image in the button.
Definition: window_gui.h:41
QueryStringWindow::editbox
QueryString editbox
Editbox.
Definition: misc_gui.cpp:944
WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: window_gui.h:72
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:30
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
DeleteWindowByClass
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1150
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:207
WID_Q_YES
No button.
Definition: misc_widget.h:45
TileDesc::station_name
StringID station_name
Type of station within the class.
Definition: tile_cmd.h:59
LandInfoWindow::LAND_INFO_MULTICENTER_LINE
One multicenter line.
Definition: misc_gui.cpp:64
CharSetFilter
CharSetFilter
Valid filter types for IsValidChar.
Definition: string_type.h:26
QueryWindow::proc
QueryCallbackProc * proc
callback function executed on closing of popup. Window* points to parent, bool is true if &#39;yes&#39; click...
Definition: misc_gui.cpp:1076
WD_TEXTPANEL_TOP
Offset at top to draw above the text.
Definition: window_gui.h:68
WDF_MODAL
The window is a modal child of some other window, meaning the parent is &#39;inactive&#39;.
Definition: window_gui.h:211
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:139
Window::IsWidgetGloballyFocused
bool IsWidgetGloballyFocused(byte widget_index) const
Check if given widget has user input focus.
Definition: window_gui.h:438
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:959
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:39
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:699
NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:66
UpdateFillingPercent
void UpdateFillingPercent(TextEffectID te_id, uint8 percent, StringID string)
Update vehicle loading indicators.
Definition: misc_gui.cpp:618
QueryWindow::UpdateWidgetSize
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: misc_gui.cpp:1116
Company
Definition: company_base.h:110
TileDesc::dparam
uint64 dparam[2]
Parameters of the str string.
Definition: tile_cmd.h:64
GetStringMultiLineBoundingBox
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition: gfx.cpp:587
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:24
WID_A_SCROLLING_TEXT
The actually scrolling text.
Definition: misc_widget.h:27
FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:284
WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:40
DeleteWindowById
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1137
PC_GREY
static const uint8 PC_GREY
Grey palette colour.
Definition: gfx_func.h:209
WID_A_WEBSITE
URL of OpenTTD website.
Definition: misc_widget.h:28
company_func.h
Functions related to companies.
IsNewGRFInspectable
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
Definition: newgrf_debug_gui.cpp:756
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:34
WID_QS_CANCEL
Cancel button.
Definition: misc_widget.h:36
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:74
AboutWindow::counter
byte counter
Used to scroll the text every 5 ticks.
Definition: misc_gui.cpp:462
NWidgetCore::IsLowered
bool IsLowered() const
Return whether the widget is lowered.
Definition: widget_type.h:343
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:561
WN_QUERY_STRING
Query string.
Definition: window_type.h:23
Textbuf::max_bytes
uint16 max_bytes
the maximum size of the buffer in bytes (including terminating &#39;\0&#39;)
Definition: textbuf_type.h:35
LandInfoWindow::ShowNewGRFInspectWindow
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
Definition: misc_gui.cpp:340
WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
AboutWindow::UpdateWidgetSize
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: misc_gui.cpp:479
FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed) ...
Definition: window_gui.h:31
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
Utf8StringLength
size_t Utf8StringLength(const char *s)
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes th...
Definition: string.cpp:300
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:118
TileDesc::road_speed
uint16 road_speed
Speed limit of road (bridges)
Definition: tile_cmd.h:67
_current_company
CompanyByte _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:52
WDF_NO_FOCUS
This window won&#39;t get focus/make any other window lose focus when click.
Definition: window_gui.h:212
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:217
Textbuf::caretxoffs
uint16 caretxoffs
the current position of the caret in pixels
Definition: textbuf_type.h:42
EndContainer
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:999
zoom_func.h
Functions related to zooming.
TileDesc::airport_name
StringID airport_name
Name of the airport.
Definition: tile_cmd.h:61
Utf8PrevChar
static char * Utf8PrevChar(char *s)
Retrieve the previous UNICODE character in an UTF-8 encoded string.
Definition: string_func.h:143
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:174
Town
Town data structure.
Definition: town.h:55
Window::SetFocusedWidget
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:484
FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:204
CursorVars::in_window
bool in_window
mouse inside this window, determines drawing logic
Definition: gfx_type.h:143
TooltipsWindow::UpdateWidgetSize
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: misc_gui.cpp:692
QueryCallbackProc
void QueryCallbackProc(Window *, bool)
Callback procedure for the ShowQuery method.
Definition: textbuf_gui.h:30
landscape.h
Functions related to OTTD&#39;s landscape.
command_func.h
Functions related to commands.
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:28
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:768
TE_STATIC
Keep the text effect static.
Definition: texteff.hpp:24
TileDesc::build_date
Date build_date
Date of construction of tile contents.
Definition: tile_cmd.h:57
TE_RISING
Make the text effect slowly go upwards.
Definition: texteff.hpp:23
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:19
Window::HandleButtonClick
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition: window.cpp:615
TooltipsWindow::OnMouseLoop
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
Definition: misc_gui.cpp:717
LandInfoWindow::UpdateWidgetSize
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: misc_gui.cpp:93
ShowFeederIncomeAnimation
void ShowFeederIncomeAnimation(int x, int y, int z, Money transfer, Money income)
Display animated feeder income.
Definition: misc_gui.cpp:576
WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
WC_CONFIRM_POPUP_QUERY
Popup with confirm question; Window numbers:
Definition: window_type.h:125
TileDesc::str
StringID str
Description of the tile.
Definition: tile_cmd.h:54
WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:23
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:314
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
LandInfoWindow::LAND_INFO_CENTERED_LINES
Up to 32 centered lines (arbitrary limit)
Definition: misc_gui.cpp:63
TileDesc::station_class
StringID station_class
Class of station.
Definition: tile_cmd.h:58
town.h
Base of the town class.
Window::window_class
WindowClass window_class
Window class.
Definition: window_gui.h:306
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:40
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
ES_HANDLED
The passed event is handled.
Definition: window_type.h:702
TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:26
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
SA_LEFT
Left align the text.
Definition: gfx_func.h:98
GetCharAtPosition
const char * GetCharAtPosition(const char *str, int x, FontSize start_fontsize)
Get the character from a string that is drawn at a specific position.
Definition: gfx.cpp:740
window_func.h
Window functions not directly related to making/drawing windows.
WDP_AUTO
Find a place automatically.
Definition: window_gui.h:156
ShowCostOrIncomeAnimation
void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
Display animated income or costs on the map.
Definition: misc_gui.cpp:555
Textbuf::afilter
CharSetFilter afilter
Allowed characters.
Definition: textbuf_type.h:33
WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:155
texteff.hpp
Functions related to text effects.
gui.h
GUI functions that shouldn&#39;t be here.
Textbuf::marklength
uint16 marklength
the length of the marked area in pixels
Definition: textbuf_type.h:46
TileDesc::airport_class
StringID airport_class
Name of the airport class.
Definition: tile_cmd.h:60
WID_Q_NO
Yes button.
Definition: misc_widget.h:44
WChar
uint32 WChar
Type for wide characters, i.e.
Definition: string_type.h:35
Window::GetWidget
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:827
WF_WHITE_BORDER
Window white border counter bit mask.
Definition: window_gui.h:242
WD_IMGBTN_LEFT
Left offset of the image in the button.
Definition: window_gui.h:40
QueryStringWindow::UpdateWidgetSize
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: misc_gui.cpp:978
QueryString::GetCharAtPosition
const char * GetCharAtPosition(const Window *w, int wid, const Point &pt) const
Get the character that is rendered at a position.
Definition: misc_gui.cpp:887
OWNER_WATER
The tile/execution is done by "water".
Definition: company_type.h:28
OSKA_DISABLED
The OSK shall not be activated at all.
Definition: misc_gui.cpp:38
WID_Q_CAPTION
Caption of the window.
Definition: misc_widget.h:42
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:34
NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:429
WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:118
ShowLandInfo
void ShowLandInfo(TileIndex tile)
Show land information window.
Definition: misc_gui.cpp:366
WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:608
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
QueryStringWindow
Class for the string query window.
Definition: misc_gui.cpp:942
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:833
TooltipsWindow::DrawWidget
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: misc_gui.cpp:705
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1076
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window&#39;s data as invalid (in need of re-computing)
Definition: window.cpp:3161
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:315
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:620
Textbuf::UpdateSize
void UpdateSize()
Update Textbuf type with its actual physical character and screenlength Get the count of characters i...
Definition: textbuf.cpp:433
WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:55
SetDParam
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:201