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