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