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