OpenTTD Source 20260911-master-gee2b2ac12a
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "stdafx.h"
11#include "debug.h"
12#include "landscape.h"
13#include "error.h"
14#include "gui.h"
15#include "gfx_layout.h"
16#include "tilehighlight_func.h"
17#include "command_func.h"
18#include "company_func.h"
19#include "town.h"
20#include "string_func.h"
21#include "company_base.h"
22#include "station_base.h"
23#include "waypoint_base.h"
24#include "texteff.hpp"
25#include "strings_func.h"
26#include "window_func.h"
27#include "querystring_gui.h"
29#include "newgrf_debug.h"
30#include "zoom_func.h"
31#include "viewport_func.h"
32#include "landscape_cmd.h"
33#include "station_cmd.h"
34#include "waypoint_cmd.h"
35#include "rev.h"
36#include "timer/timer.h"
37#include "timer/timer_window.h"
39
40#include "widgets/misc_widget.h"
41
42#include "table/strings.h"
43
44#include "safeguards.h"
45
46
47static constexpr std::initializer_list<NWidgetPart> _nested_land_info_widgets = {
50 NWidget(WWT_CAPTION, Colours::Grey), SetStringTip(STR_LAND_AREA_INFORMATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
51 NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_LI_LOCATION), SetAspect(WidgetDimensions::ASPECT_LOCATION), SetSpriteTip(SPR_GOTO_LOCATION, STR_LAND_AREA_INFORMATION_LOCATION_TOOLTIP),
55};
56
60 WindowClass::LandInfo, WindowClass::None,
61 {},
62 _nested_land_info_widgets
63);
64
65class LandInfoWindow : public Window {
67 std::string cargo_acceptance{};
68
69public:
71
72 void DrawWidget(const Rect &r, WidgetID widget) const override
73 {
74 if (widget != WID_LI_BACKGROUND) return;
75
76 Rect ir = r.Shrink(WidgetDimensions::scaled.frametext);
77 for (size_t i = 0; i < this->landinfo_data.size(); i++) {
78 DrawString(ir, this->landinfo_data[i], i == 0 ? TextColour::LightBlue : TextColour::FromString, AlignmentH::Centre);
79 ir.top += GetCharacterHeight(FontSize::Normal) + (i == 0 ? WidgetDimensions::scaled.vsep_wide : WidgetDimensions::scaled.vsep_normal);
80 }
81
82 if (!this->cargo_acceptance.empty()) {
83 DrawStringMultiLine(ir, GetString(STR_JUST_RAW_STRING, this->cargo_acceptance), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle});
84 }
85 }
86
87 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
88 {
89 if (widget != WID_LI_BACKGROUND) return;
90
91 size.height = WidgetDimensions::scaled.frametext.Vertical();
92 for (size_t i = 0; i < this->landinfo_data.size(); i++) {
93 uint width = GetStringBoundingBox(this->landinfo_data[i]).width + WidgetDimensions::scaled.frametext.Horizontal();
94 size.width = std::max(size.width, width);
95
96 size.height += GetCharacterHeight(FontSize::Normal) + (i == 0 ? WidgetDimensions::scaled.vsep_wide : WidgetDimensions::scaled.vsep_normal);
97 }
98
99 if (!this->cargo_acceptance.empty()) {
100 uint width = GetStringBoundingBox(this->cargo_acceptance).width + WidgetDimensions::scaled.frametext.Horizontal();
101 size.width = std::max(size.width, std::min(static_cast<uint>(ScaleGUITrad(300)), width));
102 size.height += GetStringHeight(GetString(STR_JUST_RAW_STRING, this->cargo_acceptance), size.width - WidgetDimensions::scaled.frametext.Horizontal());
103 }
104 }
105
106 LandInfoWindow(Tile tile) : Window(_land_info_desc), tile(tile)
107 {
108 this->InitNested();
109
110#if defined(_DEBUG)
111 static constexpr Severity severity = Severity::Critical;
112#else
113 static constexpr Severity severity = Severity::Error;
114#endif
115 Debug(Facility::Misc, severity, "TILE: {0} (0x{0:x}) ({1},{2})", (TileIndex)tile, TileX(tile), TileY(tile));
116 Debug(Facility::Misc, severity, "type = 0x{:x}", tile.type());
117 Debug(Facility::Misc, severity, "height = 0x{:x}", tile.height());
118 Debug(Facility::Misc, severity, "m1 = 0x{:x}", tile.m1());
119 Debug(Facility::Misc, severity, "m2 = 0x{:x}", tile.m2());
120 Debug(Facility::Misc, severity, "m3 = 0x{:x}", tile.m3());
121 Debug(Facility::Misc, severity, "m4 = 0x{:x}", tile.m4());
122 Debug(Facility::Misc, severity, "m5 = 0x{:x}", tile.m5());
123 Debug(Facility::Misc, severity, "m6 = 0x{:x}", tile.m6());
124 Debug(Facility::Misc, severity, "m7 = 0x{:x}", tile.m7());
125 Debug(Facility::Misc, severity, "m8 = 0x{:x}", tile.m8());
126
127 PrintWaterRegionDebugInfo(tile);
128 }
129
130 void OnInit() override
131 {
132 Town *t = ClosestTownFromTile(this->tile, _settings_game.economy.dist_local_authority);
133
134 TileDesc td{};
135 td.owner_type[0] = STR_LAND_AREA_INFORMATION_OWNER; // At least one owner is displayed, though it might be "N/A".
136
137 CargoArray acceptance{};
138 CargoTypes always_accepted{};
139 AddAcceptedCargo(this->tile, acceptance, always_accepted);
140 GetTileDesc(this->tile, td);
141
142 this->landinfo_data.clear();
143
144 /* Tiletype */
145 this->landinfo_data.push_back(GetString(td.str, td.dparam));
146
147 /* Up to four owners */
148 for (uint i = 0; i < 4; i++) {
149 if (td.owner_type[i] == STR_NULL) continue;
150
151 if (td.owner[i] == OWNER_NONE || td.owner[i] == OWNER_WATER) {
152 this->landinfo_data.push_back(GetString(td.owner_type[i], STR_LAND_AREA_INFORMATION_OWNER_N_A, std::monostate{}));
153 } else {
154 auto params = GetParamsForOwnedBy(td.owner[i], this->tile);
155 this->landinfo_data.push_back(GetStringWithArgs(td.owner_type[i], params));
156 }
157 }
158
159 /* Cost to clear/revenue when cleared */
161 if (c != nullptr) {
163 CommandCost costclear = Command<Commands::LandscapeClear>::Do(DoCommandFlag::QueryCost, this->tile);
164 if (costclear.Succeeded()) {
165 Money cost = costclear.GetCost();
166 StringID str;
167 if (cost < 0) {
168 cost = -cost; // Negate negative cost to a positive revenue
169 str = STR_LAND_AREA_INFORMATION_REVENUE_WHEN_CLEARED;
170 } else {
171 str = STR_LAND_AREA_INFORMATION_COST_TO_CLEAR;
172 }
173 this->landinfo_data.push_back(GetString(str, cost));
174 } else {
175 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_COST_TO_CLEAR_N_A));
176 }
177 } else {
178 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_COST_TO_CLEAR_N_A));
179 }
180
181 /* Location */
182 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_LANDINFO_COORDS, TileX(this->tile), TileY(this->tile), GetTileZ(this->tile)));
183
184 /* Tile index */
185 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_LANDINFO_INDEX, this->tile, this->tile));
186
187 /* Local authority */
188 if (t == nullptr) {
189 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY, STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE, std::monostate{}));
190 } else {
191 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY, STR_TOWN_NAME, t->index));
192 }
193
194 /* Build date */
196 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_BUILD_DATE, td.build_date));
197 }
198
199 /* Station class */
200 if (td.station_class != STR_NULL) {
201 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_STATION_CLASS, td.station_class));
202 }
203
204 /* Station type name */
205 if (td.station_name != STR_NULL) {
206 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_STATION_TYPE, td.station_name));
207 }
208
209 /* Airport class */
210 if (td.airport_class != STR_NULL) {
211 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_AIRPORT_CLASS, td.airport_class));
212 }
213
214 /* Airport name */
215 if (td.airport_name != STR_NULL) {
216 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_AIRPORT_NAME, td.airport_name));
217 }
218
219 /* Airport tile name */
220 if (td.airport_tile_name != STR_NULL) {
221 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_AIRPORTTILE_NAME, td.airport_tile_name));
222 }
223
224 /* Rail type name */
225 if (td.railtype != STR_NULL) {
226 this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_RAIL_TYPE, td.railtype));
227 }
228
229 /* Rail speed limit */
230 if (td.rail_speed != 0) {
231 this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_RAIL_SPEED_LIMIT, PackVelocity(td.rail_speed, VehicleType::Train)));
232 }
233
234 /* Road type name */
235 if (td.roadtype != STR_NULL) {
236 this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_ROAD_TYPE, td.roadtype));
237 }
238
239 /* Road speed limit */
240 if (td.road_speed != 0) {
241 this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_ROAD_SPEED_LIMIT, PackVelocity(td.road_speed, VehicleType::Road)));
242 }
243
244 /* Tram type name */
245 if (td.tramtype != STR_NULL) {
246 this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_TRAM_TYPE, td.tramtype));
247 }
248
249 /* Tram speed limit */
250 if (td.tram_speed != 0) {
251 this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_TRAM_SPEED_LIMIT, PackVelocity(td.tram_speed, VehicleType::Road)));
252 }
253
254 /* Tile protection status */
255 if (td.town_can_upgrade.has_value()) {
256 this->landinfo_data.push_back(GetString(td.town_can_upgrade.value() ? STR_LAND_AREA_INFORMATION_TOWN_CAN_UPGRADE : STR_LAND_AREA_INFORMATION_TOWN_CANNOT_UPGRADE));
257 }
258
259 /* NewGRF name */
260 if (td.grf.has_value()) {
261 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_NEWGRF_NAME, std::move(*td.grf)));
262 }
263
264 /* Cargo acceptance is displayed in a extra multiline */
265 auto line = BuildCargoAcceptanceString(acceptance, STR_LAND_AREA_INFORMATION_CARGO_ACCEPTED);
266 if (line.has_value()) {
267 this->cargo_acceptance = std::move(*line);
268 } else {
269 this->cargo_acceptance.clear();
270 }
271 }
272
273 bool IsNewGRFInspectable() const override
274 {
275 return ::IsNewGRFInspectable(GetGrfSpecFeature(this->tile), this->tile.base());
276 }
277
278 void ShowNewGRFInspectWindow() const override
279 {
280 ::ShowNewGRFInspectWindow(GetGrfSpecFeature(this->tile), this->tile.base());
281 }
282
283 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
284 {
285 switch (widget) {
286 case WID_LI_LOCATION:
287 if (_ctrl_pressed) {
288 ShowExtraViewportWindow(this->tile);
289 } else {
290 ScrollMainWindowToTile(this->tile);
291 }
292 break;
293 }
294 }
295
301 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
302 {
303 if (!gui_scope) return;
304
305 /* ReInit, "debug" sprite might have changed */
306 if (data == 1) this->ReInit();
307 }
308};
309
315{
316 CloseWindowById(WindowClass::LandInfo, 0);
317 new LandInfoWindow(tile);
318}
319
320static constexpr std::initializer_list<NWidgetPart> _nested_about_widgets = {
323 NWidget(WWT_CAPTION, Colours::Grey), SetStringTip(STR_ABOUT_OPENTTD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
324 EndContainer(),
326 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_ABOUT_ORIGINAL_COPYRIGHT),
327 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_ABOUT_VERSION),
330 EndContainer(),
333 EndContainer(),
334};
335
338 WindowPosition::Center, {}, 0, 0,
339 WindowClass::GameOptions, WindowClass::None,
340 {},
341 _nested_about_widgets
342);
343
344static const std::initializer_list<const std::string_view> _credits = {
345 "Original design by Chris Sawyer",
346 "Original graphics by Simon Foster",
347 "",
348 "The OpenTTD team (in alphabetical order):",
349 " Matthijs Kooijman (blathijs) - Pathfinder-guru, Debian port (since 0.3)",
350 " Christoph Elsenhans (frosch) - General coding (since 0.6)",
351 " Lo\u00efc Guilloux (glx) - General / Windows Expert (since 0.4.5)",
352 " Koen Bussemaker (Kuhnovic) - General / Ship pathfinder (since 14)",
353 " Charles Pigott (LordAro) - General / Correctness police (since 1.9)",
354 " Michael Lutz (michi_cc) - Path based signals (since 0.7)",
355 " Niels Martin Hansen (nielsm) - Music system, general coding (since 1.9)",
356 " Owen Rudge (orudge) - Forum host, OS/2 port (since 0.1)",
357 " Peter Nelson (peter1138) - Spiritual descendant from NewGRF gods (since 0.4.5)",
358 " Remko Bijker (Rubidium) - Coder and way more (since 0.4.5)",
359 " Patric Stout (TrueBrain) - NoProgrammer (since 0.3), sys op",
360 " Tyler Trahan (2TallTyler) - General / Time Lord (since 13)",
361 " Richard Wheeler (zephyris) - Precision pixel production (since 15)",
362 "",
363 "Inactive Developers:",
364 " Grzegorz Duczy\u0144ski (adf88) - General coding (1.7 - 1.8)",
365 " Albert Hofkamp (Alberth) - GUI expert (0.7 - 1.9)",
366 " Jean-Fran\u00e7ois Claeys (Belugas) - GUI, NewGRF and more (0.4.5 - 1.0)",
367 " Bjarni Corfitzen (Bjarni) - MacOSX port, coder and vehicles (0.3 - 0.7)",
368 " Victor Fischer (Celestar) - Programming everywhere you need him to (0.3 - 0.6)",
369 " Ulf Hermann (fonsinchen) - Cargo Distribution (1.3 - 1.6)",
370 " Jaroslav Mazanec (KUDr) - YAPG (Yet Another Pathfinder God) ;) (0.4.5 - 0.6)",
371 " Jonathan Coome (Maedhros) - High priest of the NewGRF Temple (0.5 - 0.6)",
372 " Attila B\u00e1n (MiHaMiX) - Developer WebTranslator 1 and 2 (0.3 - 0.5)",
373 " Ingo von Borstel (planetmaker) - General coding, Support (1.1 - 1.9)",
374 " Zden\u011bk Sojka (SmatZ) - Bug finder and fixer (0.6 - 1.3)",
375 " Jos\u00e9 Soler (Terkhen) - General coding (1.0 - 1.4)",
376 " Christoph Mallon (Tron) - Programmer, code correctness police (0.3 - 0.5)",
377 " Thijs Marinussen (Yexo) - AI Framework, General (0.6 - 1.3)",
378 " Leif Linse (Zuu) - AI/Game Script (1.2 - 1.6)",
379 "",
380 "Retired Developers:",
381 " Tam\u00e1s Farag\u00f3 (Darkvater) - Ex-Lead coder (0.3 - 0.5)",
382 " Dominik Scherer (dominik81) - Lead programmer, GUI expert (0.3 - 0.3)",
383 " Emil Djupfeld (egladil) - MacOSX (0.4.5 - 0.6)",
384 " Simon Sasburg (HackyKid) - Many bugfixes (0.4 - 0.4.5)",
385 " Ludvig Strigeus (ludde) - Original author of OpenTTD, main coder (0.1 - 0.3)",
386 " Cian Duffy (MYOB) - BeOS port / manual writing (0.1 - 0.3)",
387 " Petr Baudi\u0161 (pasky) - Many patches, NewGRF support (0.3 - 0.3)",
388 " Benedikt Br\u00fcggemeier (skidd13) - Bug fixer and code reworker (0.6 - 0.7)",
389 " Serge Paquet (vurlix) - 2nd contributor after ludde (0.1 - 0.3)",
390 "",
391 "Special thanks go out to:",
392 " Josef Drexler - For his great work on TTDPatch",
393 " Marcin Grzegorczyk - Track foundations and for describing TTD internals",
394 " Stefan Mei\u00dfner (sign_de) - For his work on the console",
395 " Mike Ragsdale - OpenTTD installer",
396 " Christian Rosentreter (tokai) - MorphOS / AmigaOS port",
397 " Richard Kempton (richK) - additional airports, initial TGP implementation",
398 " Alberto Demichelis - Squirrel scripting language \u00a9 2003-2008",
399 " L. Peter Deutsch - MD5 implementation \u00a9 1999, 2000, 2002",
400 " Michael Blunck - Pre-signals and semaphores \u00a9 2003",
401 " George - Canal/Lock graphics \u00a9 2003-2004",
402 " Andrew Parkhouse (andythenorth) - River graphics",
403 " David Dallaston (Pikka) - Tram tracks",
404 " All Translators - Who made OpenTTD a truly international game",
405 " Bug Reporters - Without whom OpenTTD would still be full of bugs!",
406 "",
407 "",
408 "And last but not least:",
409 " Chris Sawyer - For an amazing game!"
410};
411
412struct AboutWindow : public Window {
414 int line_height = 0;
415 static const int num_visible_lines = 19;
416
417 AboutWindow() : Window(_about_desc)
418 {
420
421 this->text_position = this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->current_y;
422 }
423
424 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
425 {
426 if (widget == WID_A_WEBSITE) return "Website: https://www.openttd.org";
427 if (widget == WID_A_COPYRIGHT) return GetString(STR_ABOUT_COPYRIGHT_OPENTTD, _openttd_revision_year);
428 return this->Window::GetWidgetString(widget, stringid);
429 }
430
431 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
432 {
433 if (widget != WID_A_SCROLLING_TEXT) return;
434
435 this->line_height = GetCharacterHeight(FontSize::Normal);
436
437 Dimension d;
438 d.height = this->line_height * num_visible_lines;
439
440 d.width = 0;
441 for (const auto &str : _credits) {
442 d.width = std::max(d.width, GetStringBoundingBox(str).width);
443 }
444 size = maxdim(size, d);
445 }
446
447 void DrawWidget(const Rect &r, WidgetID widget) const override
448 {
449 if (widget != WID_A_SCROLLING_TEXT) return;
450
451 int y = this->text_position;
452
453 /* Show all scrolling _credits */
454 for (const auto &str : _credits) {
455 if (y >= r.top + 7 && y < r.bottom - this->line_height) {
456 DrawString(r.left, r.right, y, str, TextColour::Black, AlignmentH::ForceLeft);
457 }
458 y += this->line_height;
459 }
460 }
461
467 const IntervalTimer<TimerWindow> scroll_interval = {std::chrono::milliseconds(2100) / GetCharacterHeight(FontSize::Normal), [this](uint count) {
468 this->text_position -= count;
469 /* If the last text has scrolled start a new from the start */
470 if (this->text_position < (int)(this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y - std::size(_credits) * this->line_height)) {
471 this->text_position = this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->current_y;
472 }
474 }};
475};
476
477void ShowAboutWindow()
478{
479 CloseWindowByClass(WindowClass::GameOptions);
480 new AboutWindow();
481}
482
489void ShowEstimatedCostOrIncome(Money cost, int x, int y)
490{
491 StringID msg = STR_MESSAGE_ESTIMATED_COST;
492
493 if (cost < 0) {
494 cost = -cost;
495 msg = STR_MESSAGE_ESTIMATED_INCOME;
496 }
498}
499
507void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
508{
509 if (cost == 0) {
510 return;
511 }
512 Point pt = RemapCoords(x, y, z);
513 StringID msg = STR_INCOME_FLOAT_COST;
514
515 if (cost < 0) {
516 cost = -cost;
517 msg = STR_INCOME_FLOAT_INCOME;
518 }
519 AddTextEffect(GetEncodedString(msg, cost), pt.x, pt.y, Ticks::DAY_TICKS, TextEffectMode::Rising);
520}
521
530void ShowFeederIncomeAnimation(int x, int y, int z, Money transfer, Money income)
531{
532 Point pt = RemapCoords(x, y, z);
533
534 if (income == 0) {
535 AddTextEffect(GetEncodedString(STR_FEEDER, transfer), pt.x, pt.y, Ticks::DAY_TICKS, TextEffectMode::Rising);
536 } else {
537 StringID msg = STR_FEEDER_COST;
538 if (income < 0) {
539 income = -income;
540 msg = STR_FEEDER_INCOME;
541 }
542 AddTextEffect(GetEncodedString(msg, transfer, income), pt.x, pt.y, Ticks::DAY_TICKS, TextEffectMode::Rising);
543 }
544}
545
555TextEffectID ShowFillingPercent(int x, int y, int z, uint8_t percent, StringID string)
556{
557 Point pt = RemapCoords(x, y, z);
558
559 assert(string != STR_NULL);
560
561 return AddTextEffect(GetEncodedString(string, percent), pt.x, pt.y, 0, TextEffectMode::Static);
562}
563
570void UpdateFillingPercent(TextEffectID te_id, uint8_t percent, StringID string)
571{
572 assert(string != STR_NULL);
573
574 UpdateTextEffect(te_id, GetEncodedString(string, percent));
575}
576
581void HideFillingPercent(TextEffectID *te_id)
582{
583 if (*te_id == INVALID_TE_ID) return;
584
585 RemoveTextEffect(*te_id);
586 *te_id = INVALID_TE_ID;
587}
588
589static constexpr std::initializer_list<NWidgetPart> _nested_tooltips_widgets = {
591};
592
595 WindowPosition::Manual, {}, 0, 0, // Coordinates and sizes are not used,
596 WindowClass::ToolTips, WindowClass::None,
598 _nested_tooltips_widgets
599);
600
602struct TooltipsWindow : public Window
603{
606
608 {
609 this->parent = parent;
610 this->close_cond = close_tooltip;
611
612 this->InitNested();
613
615 }
616
617 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
618 {
619 /* Find the free screen space between the main toolbar at the top, and the statusbar at the bottom.
620 * Add a fixed distance 2 so the tooltip floats free from both bars.
621 */
622 int scr_top = GetMainViewTop() + 2;
623 int scr_bot = GetMainViewBottom() - 2;
624
625 Point pt;
626
627 /* Correctly position the tooltip position, watch out for window and cursor size
628 * Clamp value to below main toolbar and above statusbar. If tooltip would
629 * go below window, flip it so it is shown above the cursor */
630 pt.y = SoftClamp(_cursor.pos.y + _cursor.total_size.y + _cursor.total_offs.y + 5, scr_top, scr_bot);
631 if (pt.y + sm_height > scr_bot) pt.y = std::min(_cursor.pos.y + _cursor.total_offs.y - 5, scr_bot) - sm_height;
632 pt.x = sm_width >= _screen.width ? 0 : SoftClamp(_cursor.pos.x - (sm_width >> 1), 0, _screen.width - sm_width);
633
634 return pt;
635 }
636
637 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
638 {
639 if (widget != WID_TT_BACKGROUND) return;
640
641 auto str = this->text.GetDecodedString();
642 size.width = std::min<uint>(GetStringBoundingBox(str).width, ScaleGUITrad(194));
643 size.height = GetStringHeight(str, size.width);
644
645 /* Increase slightly to have some space around the box. */
646 size.width += WidgetDimensions::scaled.framerect.Horizontal() + WidgetDimensions::scaled.fullbevel.Horizontal();
647 size.height += WidgetDimensions::scaled.framerect.Vertical() + WidgetDimensions::scaled.fullbevel.Vertical();
648 }
649
650 void DrawWidget(const Rect &r, WidgetID widget) const override
651 {
652 if (widget != WID_TT_BACKGROUND) return;
655
656 DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect).Shrink(WidgetDimensions::scaled.fullbevel), this->text.GetDecodedString(), TextColour::Black, {AlignmentH::Centre, AlignmentV::Middle});
657 }
658
659 void OnMouseLoop() override
660 {
661 /* Always close tooltips when the cursor is not in our window. */
662 if (!_cursor.in_window) {
663 this->Close();
664 return;
665 }
666
667 /* We can show tooltips while dragging tools. These are shown as long as
668 * we are dragging the tool. Normal tooltips work with hover or rmb. */
669 switch (this->close_cond) {
671 case TooltipCloseCondition::Hover: if (!_mouse_hovering) this->Close(); break;
672 case TooltipCloseCondition::None: break;
673
675 Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
676 if (w == nullptr || IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y) == nullptr) this->Close();
677 break;
678 }
679 }
680 }
681};
682
689void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
690{
691 CloseWindowById(WindowClass::ToolTips, 0);
692
693 if (text.empty() || !_cursor.in_window) return;
694
695 new TooltipsWindow(parent, std::move(text), close_tooltip);
696}
697
698void QueryString::HandleEditBox(Window *w, WidgetID wid)
699{
700 if (w->IsWidgetGloballyFocused(wid) && this->text.HandleCaret()) {
701 w->SetWidgetDirty(wid);
702
703 /* For the OSK also invalidate the parent window */
704 if (w->window_class == WindowClass::OnScreenKeyboard) w->InvalidateData();
705 }
706}
707
708static int GetCaretWidth()
709{
711}
712
720{
721 const int linewidth = tb.pixels + GetCaretWidth();
722 const int boxwidth = r.Width();
723 if (linewidth <= boxwidth) return r;
724
725 /* Extend to cover whole string. This is left-aligned, adjusted by caret position. */
726 r = r.WithWidth(linewidth, false);
727
728 /* Slide so that the caret is at the centre unless limited by bounds of the line, i.e. near either end. */
729 return r.Translate(-std::clamp(tb.caretxoffs - (boxwidth / 2), 0, linewidth - boxwidth), 0);
730}
731
732void QueryString::DrawEditBox(const Window *w, WidgetID wid) const
733{
734 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
735
736 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
737
738 bool rtl = _current_text_dir == TD_RTL;
739 Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
740 int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal();
741
742 Rect r = wi->GetCurrentRect();
743 Rect cr = r.WithWidth(clearbtn_width, !rtl);
744 Rect fr = r.Indent(clearbtn_width, !rtl);
745
747 DrawSpriteIgnorePadding(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, cr, {AlignmentH::Centre, AlignmentV::Middle});
749
750 DrawFrameRect(fr, wi->colour, {FrameFlag::Lowered, FrameFlag::Darkened});
752
753 fr = fr.Shrink(WidgetDimensions::scaled.framerect);
754 /* Limit the drawing of the string inside the widget boundaries */
755 DrawPixelInfo dpi;
756 if (!FillDrawPixelInfo(&dpi, fr)) return;
757 /* Keep coordinates relative to the window. */
758 dpi.left += fr.left;
759 dpi.top += fr.top;
760
761 AutoRestoreBackup dpi_backup(_cur_dpi, &dpi);
762
763 /* We will take the current widget length as maximum width, with a small
764 * space reserved at the end for the caret to show */
765 const Textbuf *tb = &this->text;
766 fr = ScrollEditBoxTextRect(fr, *tb);
767
768 /* If we have a marked area, draw a background highlight. */
769 if (tb->marklength != 0) GfxFillRect(fr.left + tb->markxoffs, fr.top, fr.left + tb->markxoffs + tb->marklength - 1, fr.bottom, PC_GREY);
770
771 DrawString(fr.left, fr.right, CentreBounds(fr.top, fr.bottom, GetCharacterHeight(FontSize::Normal)), tb->GetText(), TextColour::Yellow);
772 bool focussed = w->IsWidgetGloballyFocused(wid) || IsOSKOpenedFor(w, wid);
773 if (focussed && tb->caret) {
774 int caret_width = GetCaretWidth();
775 if (rtl) {
776 DrawString(fr.right - tb->pixels + tb->caretxoffs - caret_width, fr.right - tb->pixels + tb->caretxoffs, CentreBounds(fr.top, fr.bottom, GetCharacterHeight(FontSize::Normal)), "_", TextColour::White);
777 } else {
778 DrawString(fr.left + tb->caretxoffs, fr.left + tb->caretxoffs + caret_width, CentreBounds(fr.top, fr.bottom, GetCharacterHeight(FontSize::Normal)), "_", TextColour::White);
779 }
780 }
781}
782
790{
791 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
792
793 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
794
795 bool rtl = _current_text_dir == TD_RTL;
796 Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
797 int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal();
798
799 Rect r = wi->GetCurrentRect().Indent(clearbtn_width, !rtl).Shrink(WidgetDimensions::scaled.framerect);
800
801 /* Clamp caret position to be inside out current width. */
802 const Textbuf *tb = &this->text;
803 r = ScrollEditBoxTextRect(r, *tb);
804
805 Point pt = {r.left + tb->caretxoffs, r.top};
806 return pt;
807}
808
817Rect QueryString::GetBoundingRect(const Window *w, WidgetID wid, size_t from, size_t to) const
818{
819 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
820
821 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
822
823 bool rtl = _current_text_dir == TD_RTL;
824 Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
825 int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal();
826
827 Rect r = wi->GetCurrentRect().Indent(clearbtn_width, !rtl).Shrink(WidgetDimensions::scaled.framerect);
828
829 /* Clamp caret position to be inside our current width. */
830 const Textbuf *tb = &this->text;
831 r = ScrollEditBoxTextRect(r, *tb);
832
833 /* Get location of first and last character. */
834 const auto p1 = GetCharPosInString(tb->GetText(), from, FontSize::Normal);
835 const auto p2 = from != to ? GetCharPosInString(tb->GetText(), to, FontSize::Normal) : p1;
836
837 return r.WithX(Clamp(r.left + p1.left, r.left, r.right), Clamp(r.left + p2.right, r.left, r.right));
838}
839
847ptrdiff_t QueryString::GetCharAtPosition(const Window *w, WidgetID wid, const Point &pt) const
848{
849 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
850
851 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
852
853 bool rtl = _current_text_dir == TD_RTL;
854 Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
855 int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal();
856
857 Rect r = wi->GetCurrentRect().Indent(clearbtn_width, !rtl).Shrink(WidgetDimensions::scaled.framerect);
858
859 if (!IsInsideMM(pt.y, r.top, r.bottom)) return -1;
860
861 /* Clamp caret position to be inside our current width. */
862 const Textbuf *tb = &this->text;
863 r = ScrollEditBoxTextRect(r, *tb);
864
865 return ::GetCharAtPosition(tb->GetText(), pt.x - r.left);
866}
867
868void QueryString::ClickEditBox(Window *w, Point pt, WidgetID wid, int click_count, bool focus_changed)
869{
870 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
871
872 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
873
874 bool rtl = _current_text_dir == TD_RTL;
875 Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
876 int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal();
877
878 Rect cr = wi->GetCurrentRect().WithWidth(clearbtn_width, !rtl);
879
880 if (IsInsideMM(pt.x, cr.left, cr.right)) {
881 if (!this->text.GetText().empty()) {
882 this->text.DeleteAll();
883 w->HandleButtonClick(wid);
884 w->OnEditboxChanged(wid);
885 }
886 return;
887 }
888
889 if (w->window_class != WindowClass::OnScreenKeyboard && _settings_client.gui.osk_activation != OskActivation::Disabled &&
892 /* Open the OSK window */
893 ShowOnScreenKeyboard(w, wid);
894 }
895}
896
898struct QueryStringWindow : public Window
899{
902
904
905 QueryStringWindow(std::string_view str, StringID caption, uint max_bytes, uint max_chars, WindowDesc &desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) :
906 Window(desc), editbox(max_bytes, max_chars)
907 {
908 this->editbox.text.Assign(str);
909
910 if (!flags.Test(QueryStringFlag::AcceptUnchanged)) this->editbox.orig = this->editbox.text.GetText();
911
912 this->querystrings[WID_QS_TEXT] = &this->editbox;
913 this->editbox.caption = caption;
914 this->editbox.cancel_button = WID_QS_CANCEL;
915 this->editbox.ok_button = WID_QS_OK;
916 this->editbox.text.afilter = afilter;
917 this->flags = flags;
918
919 this->CreateNestedTree();
921 this->GetWidget<NWidgetStacked>(WID_QS_MOVE_SEL)->SetDisplayedPlane((this->flags.Test(QueryStringFlag::EnableMove)) ? 0 : SZSP_NONE);
922 this->FinishInitNested(QueryStringWindowNumber::Default);
923
924 this->parent = parent;
925
926 this->SetFocusedWidget(WID_QS_TEXT);
927 }
928
929 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
930 {
931 if (widget == WID_QS_CAPTION) return GetString(this->editbox.caption);
932
933 return this->Window::GetWidgetString(widget, stringid);
934 }
935
936 void OnOk()
937 {
938 if (!this->editbox.orig.has_value() || this->editbox.text.GetText() != this->editbox.orig) {
939 assert(this->parent != nullptr);
940
941 this->parent->OnQueryTextFinished(std::string{this->editbox.text.GetText()});
942 this->editbox.handled = true;
943 }
944 }
945
946 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
947 {
948 switch (widget) {
949 case WID_QS_DEFAULT:
950 this->editbox.text.DeleteAll();
951 [[fallthrough]];
952
953 case WID_QS_OK:
954 this->OnOk();
955 [[fallthrough]];
956
957 case WID_QS_CANCEL:
958 this->Close();
959 break;
960
961 case WID_QS_MOVE:
962 this->last_user_action = widget;
963
964 if (Station::IsExpected(Station::Get(this->parent->window_number))) {
965 /* this is a station */
966 SetViewportStationRect(Station::Get(this->parent->window_number), !this->IsWidgetLowered(WID_QS_MOVE));
967 } else {
968 /* this is a waypoint */
969 SetViewportWaypointRect(Waypoint::Get(this->parent->window_number), !this->IsWidgetLowered(WID_QS_MOVE));
970 }
971
973 break;
974 }
975 }
976
977 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
978 {
979 switch (this->last_user_action) {
980 case WID_QS_MOVE: // Move name button
981 if (Station::IsExpected(Station::Get(this->parent->window_number))) {
982 /* this is a station */
983 Command<Commands::MoveStationName>::Post(STR_ERROR_CAN_T_MOVE_STATION_NAME, CcMoveStationName, this->parent->window_number, tile);
984 } else {
985 /* this is a waypoint */
986 Command<Commands::MoveWaypointNAme>::Post(STR_ERROR_CAN_T_MOVE_WAYPOINT_NAME, CcMoveWaypointName, this->parent->window_number, tile);
987 }
988 break;
989
990 default: NOT_REACHED();
991 }
992 }
993
994private:
997 {
998 if (this->parent->window_class == WindowClass::StationView) SetViewportStationRect(Station::Get(this->parent->window_number), false);
999 if (this->parent->window_class == WindowClass::WaypointView) SetViewportWaypointRect(Waypoint::Get(this->parent->window_number), false);
1000 }
1001
1002public:
1003 void OnPlaceObjectAbort() override
1004 {
1005 if (this->parent != nullptr) {
1006 this->ClearViewportRect();
1007 }
1008
1009 this->RaiseButtons();
1010 }
1011
1012 void Close([[maybe_unused]] int data = 0) override
1013 {
1014 if (this->parent != nullptr) {
1015 this->ClearViewportRect();
1016
1017 if (!this->editbox.handled) {
1018 Window *parent = this->parent;
1019 this->parent = nullptr; // so parent doesn't try to close us again
1020 parent->OnQueryTextFinished(std::nullopt);
1021 }
1022 }
1023
1024 this->Window::Close();
1025 }
1026};
1027
1028static constexpr std::initializer_list<NWidgetPart> _nested_query_string_widgets = {
1032 EndContainer(),
1035 EndContainer(),
1038 NWidget(WWT_TEXTBTN, Colours::Grey, WID_QS_DEFAULT), SetMinimalSize(65, 12), SetFill(1, 1), SetStringTip(STR_BUTTON_DEFAULT),
1039 EndContainer(),
1040 NWidget(WWT_TEXTBTN, Colours::Grey, WID_QS_CANCEL), SetMinimalSize(65, 12), SetFill(1, 1), SetStringTip(STR_BUTTON_CANCEL),
1043 NWidget(WWT_TEXTBTN, Colours::Grey, WID_QS_MOVE), SetMinimalSize(65, 12), SetFill(1, 1), SetStringTip(STR_BUTTON_MOVE),
1044 EndContainer(),
1045 EndContainer(),
1046};
1047
1050 WindowPosition::Center, {}, 0, 0,
1051 WindowClass::QueryString, WindowClass::None,
1052 {},
1053 _nested_query_string_widgets
1054);
1055
1065void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
1066{
1067 assert(parent != nullptr);
1068
1069 CloseWindowByClass(WindowClass::QueryString);
1070 new QueryStringWindow(str, caption, (flags.Test(QueryStringFlag::LengthIsInChars) ? MAX_CHAR_LENGTH : 1) * maxsize, maxsize, _query_string_desc, parent, afilter, flags);
1071}
1072
1077void UpdateQueryStringDefault(std::string_view str)
1078{
1079 QueryStringWindow *w = dynamic_cast<QueryStringWindow *>(FindWindowByClass(WindowClass::QueryString));
1080 if (w != nullptr) w->editbox.orig = str;
1081}
1082
1086struct QueryWindow : public Window {
1090
1092 : Window(desc), proc(callback), caption(std::move(caption)), message(std::move(message))
1093 {
1094 this->parent = parent;
1095
1096 this->CreateNestedTree();
1098 }
1099
1100 void Close([[maybe_unused]] int data = 0) override
1101 {
1102 if (this->proc != nullptr) this->proc(this->parent, false);
1103 this->Window::Close();
1104 }
1105
1106 void FindWindowPlacementAndResize(int, int, bool) override
1107 {
1108 /* Position query window over the calling window, ensuring it's within screen bounds. */
1109 this->left = SoftClamp(parent->left + (parent->width / 2) - (this->width / 2), 0, _screen.width - this->width);
1110 this->top = SoftClamp(parent->top + (parent->height / 2) - (this->height / 2), 0, _screen.height - this->height);
1111 this->SetDirty();
1112 }
1113
1114 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
1115 {
1116 switch (widget) {
1117 case WID_Q_CAPTION:
1118 return this->caption.GetDecodedString();
1119
1120 default:
1121 return this->Window::GetWidgetString(widget, stringid);
1122 }
1123 }
1124
1125 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1126 {
1127 if (widget != WID_Q_TEXT) return;
1128
1129 size = GetStringMultiLineBoundingBox(this->message.GetDecodedString(), size);
1130 }
1131
1132 void DrawWidget(const Rect &r, WidgetID widget) const override
1133 {
1134 if (widget != WID_Q_TEXT) return;
1135
1136 DrawStringMultiLine(r, this->message.GetDecodedString(), TextColour::FromString, {AlignmentH::Centre, AlignmentV::Middle});
1137 }
1138
1139 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1140 {
1141 switch (widget) {
1142 case WID_Q_YES: {
1143 /* in the Generate New World window, clicking 'Yes' causes
1144 * CloseNonVitalWindows() to be called - we shouldn't be in a window then */
1145 QueryCallbackProc *proc = this->proc;
1146 Window *parent = this->parent;
1147 /* Prevent the destructor calling the callback function */
1148 this->proc = nullptr;
1149 this->Close();
1150 if (proc != nullptr) {
1151 proc(parent, true);
1152 proc = nullptr;
1153 }
1154 break;
1155 }
1156 case WID_Q_NO:
1157 this->Close();
1158 break;
1159 }
1160 }
1161
1162 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode) override
1163 {
1164 /* ESC closes the window, Enter confirms the action */
1165 switch (keycode) {
1166 case WKC_RETURN:
1167 case WKC_NUM_ENTER:
1168 if (this->proc != nullptr) {
1169 this->proc(this->parent, true);
1170 this->proc = nullptr;
1171 }
1172 [[fallthrough]];
1173
1174 case WKC_ESC:
1175 this->Close();
1176 return EventState::Handled;
1177 }
1179 }
1180};
1181
1182static constexpr std::initializer_list<NWidgetPart> _nested_query_widgets = {
1186 EndContainer(),
1193 EndContainer(),
1194 EndContainer(),
1195 EndContainer(),
1196};
1197
1200 WindowPosition::Center, {}, 0, 0,
1201 WindowClass::ConfirmPopupQuery, WindowClass::None,
1203 _nested_query_widgets
1204);
1205
1216void ShowQuery(EncodedString &&caption, EncodedString &&message, Window *parent, QueryCallbackProc *callback, bool focus)
1217{
1218 if (parent == nullptr) parent = GetMainWindow();
1219
1220 for (Window *w : Window::Iterate()) {
1221 if (w->window_class != WindowClass::ConfirmPopupQuery) continue;
1222
1223 QueryWindow *qw = dynamic_cast<QueryWindow *>(w);
1224 assert(qw != nullptr);
1225 if (qw->parent != parent || qw->proc != callback) continue;
1226
1227 qw->Close();
1228 break;
1229 }
1230
1231 QueryWindow *q = new QueryWindow(_query_desc, std::move(caption), std::move(message), parent, callback);
1232 if (focus) SetFocusedWindow(q);
1233}
EnumBitSet< CargoType, uint64_t > CargoTypes
Bitset of CargoType elements.
Definition cargo_type.h:113
std::optional< std::string > BuildCargoAcceptanceString(const CargoArray &acceptance, StringID label)
Build comma-separated cargo acceptance string.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Reset()
Reset all bits.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
Money GetCost() const
The costs as made up to this moment.
Container for an encoded string, created by GetEncodedString.
std::string GetDecodedString() const
Decode the encoded string.
Definition strings.cpp:207
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition misc_gui.cpp:72
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition misc_gui.cpp:301
StringList landinfo_data
Info lines to show.
Definition misc_gui.cpp:66
std::string cargo_acceptance
Centered multi-line string for cargo acceptance.
Definition misc_gui.cpp:67
bool IsNewGRFInspectable() const override
Is the data related to this window NewGRF inspectable?
Definition misc_gui.cpp:273
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition misc_gui.cpp:130
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition misc_gui.cpp:283
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition misc_gui.cpp:87
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection window.
Definition misc_gui.cpp:278
WidgetType type
Type of the widget / nested widget.
Colours colour
Colour of this widget.
bool IsLowered() const
Return whether the widget is lowered.
Leaf widget.
Stacked widgets, widgets all occupying the same space in the window.
bool SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition widget.cpp:1458
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
Wrapper class to abstract away the way the tiles are stored.
Definition map_func.h:25
static constexpr TimerGame< struct Calendar >::Date INVALID_DATE
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
RectPadding imgbtn
Padding around image button image.
Definition window_gui.h:36
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:95
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition window_gui.h:40
Functions related to commands.
@ QueryCost
query cost only, don't build.
Definition of stuff that is very close to a company, like the company struct itself.
std::array< StringParameter, 2 > GetParamsForOwnedBy(Owner owner, TileIndex tile)
Get the right StringParameters for STR_ERROR_OWNED_BY.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
static constexpr Owner OWNER_NONE
The tile has no ownership.
static constexpr Owner OWNER_WATER
The tile/execution is done by "water".
Functions related to debugging.
#define Debug(facility, severity, format_string,...)
Output a line of debugging information.
Definition debug.h:37
@ Misc
Misc message facility.
Definition debug_type.h:32
Severity
Debug message severity levels.
Definition debug_type.h:14
@ Critical
Critical, user should know about this.
Definition debug_type.h:15
@ Error
Error, but we are recovering.
Definition debug_type.h:16
Functions related to errors.
@ Info
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition error.h:22
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
@ Centre
Align to the centre.
@ ForceLeft
Force align to the left.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
@ Middle
Align to the middle.
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition gfx.cpp:716
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:899
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:39
uint8_t GetCharacterWidth(FontSize size, char32_t key)
Return width of character glyph.
Definition gfx.cpp:1277
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition gfx.cpp:752
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:116
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:787
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:668
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:1572
bool _right_button_down
Is right mouse button pressed?
Definition gfx.cpp:44
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition widget.cpp:70
void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, Alignment align)
Draw a sprite within a Rect, ignoring the sprite's padding.
Definition widget.cpp:350
ParagraphLayouter::Position GetCharPosInString(std::string_view str, size_t pos, FontSize start_fontsize)
Get the leading corner of a character in a single-line string relative to the start of the string.
Functions related to laying out the texts.
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ Yellow
Yellow.
Definition gfx_type.h:288
@ Grey
Grey.
Definition gfx_type.h:299
@ Red
Red.
Definition gfx_type.h:289
@ White
White colour.
Definition gfx_type.h:330
@ LightBlue
Light blue colour.
Definition gfx_type.h:331
@ Yellow
Yellow colour.
Definition gfx_type.h:326
@ FromString
Marker for telling to use the colour from the string.
Definition gfx_type.h:317
@ Black
Black colour.
Definition gfx_type.h:334
@ Checker
Draw only every second pixel, used for greying-out.
Definition gfx_type.h:393
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FontSize::Normal)
Widget part function for setting the text style.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
static const CursorID SPR_CURSOR_SIGN
Definition sprites.h:1574
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:975
GUI functions that shouldn't be here.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Functions related to OTTD's landscape.
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:81
Command definitions related to landscape (slopes etc.).
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition main_gui.cpp:63
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:429
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:419
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
constexpr T SoftClamp(const T a, const T min, const T max)
Clamp a value between an interval.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
Shows a tooltip.
Definition misc_gui.cpp:689
void ShowQuery(EncodedString &&caption, EncodedString &&message, Window *parent, QueryCallbackProc *callback, bool focus)
Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre o...
void HideFillingPercent(TextEffectID *te_id)
Hide vehicle loading indicators.
Definition misc_gui.cpp:581
void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
Display animated income or costs on the map.
Definition misc_gui.cpp:507
static WindowDesc _query_desc(WindowPosition::Center, {}, 0, 0, WindowClass::ConfirmPopupQuery, WindowClass::None, WindowDefaultFlag::Modal, _nested_query_widgets)
Window definition for the query window.
void ShowEstimatedCostOrIncome(Money cost, int x, int y)
Display estimated costs.
Definition misc_gui.cpp:489
static WindowDesc _tool_tips_desc(WindowPosition::Manual, {}, 0, 0, WindowClass::ToolTips, WindowClass::None, {WindowDefaultFlag::NoFocus, WindowDefaultFlag::NoClose}, _nested_tooltips_widgets)
Window definition for the tool tip window.
void ShowLandInfo(TileIndex tile)
Show land information window.
Definition misc_gui.cpp:314
void ShowFeederIncomeAnimation(int x, int y, int z, Money transfer, Money income)
Display animated feeder income.
Definition misc_gui.cpp:530
static WindowDesc _query_string_desc(WindowPosition::Center, {}, 0, 0, WindowClass::QueryString, WindowClass::None, {}, _nested_query_string_widgets)
Window definition for the string query window.
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
static WindowDesc _land_info_desc(WindowPosition::Automatic, {}, 0, 0, WindowClass::LandInfo, WindowClass::None, {}, _nested_land_info_widgets)
Window definition for the land information window.
static WindowDesc _about_desc(WindowPosition::Center, {}, 0, 0, WindowClass::GameOptions, WindowClass::None, {}, _nested_about_widgets)
Window definition for the about window.
void UpdateFillingPercent(TextEffectID te_id, uint8_t percent, StringID string)
Update vehicle loading indicators.
Definition misc_gui.cpp:570
TextEffectID ShowFillingPercent(int x, int y, int z, uint8_t percent, StringID string)
Display vehicle loading indicators.
Definition misc_gui.cpp:555
void UpdateQueryStringDefault(std::string_view str)
Updates default text value of query strign window.
static Rect ScrollEditBoxTextRect(Rect r, const Textbuf &tb)
Reposition edit text box rect based on textbuf length can caret position.
Definition misc_gui.cpp:719
Types related to the misc widgets.
@ WID_TT_BACKGROUND
Background of the window.
Definition misc_widget.h:21
@ WID_QS_MOVE_SEL
Container for move button, which can be hidden.
Definition misc_widget.h:40
@ WID_QS_DEFAULT
Default button.
Definition misc_widget.h:35
@ WID_QS_CAPTION
Caption of the window.
Definition misc_widget.h:33
@ WID_QS_TEXT
Text of the query.
Definition misc_widget.h:34
@ WID_QS_MOVE
Move button.
Definition misc_widget.h:39
@ WID_QS_CANCEL
Cancel button.
Definition misc_widget.h:37
@ WID_QS_DEFAULT_SEL
Container for default button, which can be hidden.
Definition misc_widget.h:36
@ WID_QS_OK
OK button.
Definition misc_widget.h:38
@ WID_A_WEBSITE
URL of OpenTTD website.
Definition misc_widget.h:27
@ WID_A_COPYRIGHT
Copyright string.
Definition misc_widget.h:28
@ WID_A_SCROLLING_TEXT
The actually scrolling text.
Definition misc_widget.h:26
@ WID_Q_NO
Yes button.
Definition misc_widget.h:47
@ WID_Q_YES
No button.
Definition misc_widget.h:48
@ WID_Q_CAPTION
Caption of the window.
Definition misc_widget.h:45
@ WID_Q_TEXT
Text of the query.
Definition misc_widget.h:46
@ WID_LI_BACKGROUND
Background of the window.
Definition misc_widget.h:16
@ WID_LI_LOCATION
Scroll to location.
Definition misc_widget.h:15
GrfSpecFeature GetGrfSpecFeature(VehicleType type)
Get the GrfSpecFeature associated with a VehicleType.
Definition newgrf.cpp:1889
Functions/types related to NewGRF debugging.
PixelColour GetColourGradient(Colours colour, Shade shade)
Get colour gradient palette index.
Definition palette.cpp:393
@ Darker
Darker colour shade.
static constexpr PixelColour PC_GREY
Grey palette colour.
static constexpr PixelColour PC_BLACK
Black palette colour.
static constexpr PixelColour PC_LIGHT_YELLOW
Light yellow palette colour.
Base for the GUIs that have an edit box in them.
void ShowOnScreenKeyboard(Window *parent, WidgetID button)
Show the on-screen keyboard (osk) associated with a given textbox.
Definition osk_gui.cpp:396
bool IsOSKOpenedFor(const Window *w, WidgetID button)
Check whether the OSK is opened for a specific editbox.
Definition osk_gui.cpp:427
Declaration of OTTD revision dependent variables.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
@ DoubleClick
Double click on the edit box opens OSK.
@ Disabled
The OSK shall not be activated at all.
@ Immediately
Focusing click already opens OSK.
Base classes/functions for stations.
void CcMoveStationName(Commands, const CommandCost &result, StationID station_id)
Callback function that is called after a name is moved.
Command definitions related to stations.
Definition of base types and functions in a cross-platform compatible way.
Functions related to low-level strings.
CharSetFilter
Valid filter types for IsValidChar.
Definition string_type.h:24
std::vector< std::string > StringList
Type for a list of strings.
Definition string_type.h:61
void GetStringWithArgs(StringBuilder &builder, StringID string, StringParameters &args, uint case_index, bool game_script)
Get a parsed string with most special stringcodes replaced by the string parameters.
Definition strings.cpp:336
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
Functions related to OTTD's strings.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition misc_gui.cpp:447
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition misc_gui.cpp:431
const IntervalTimer< TimerWindow > scroll_interval
Scroll the text in the about window slow.
Definition misc_gui.cpp:467
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition misc_gui.cpp:424
int text_position
The top of the scrolling text.
Definition misc_gui.cpp:413
static const int num_visible_lines
The number of lines visible simultaneously.
Definition misc_gui.cpp:415
int line_height
The height of a single line.
Definition misc_gui.cpp:414
Class for storing amounts of cargo.
Definition cargo_type.h:118
GUISettings gui
settings related to the GUI
T y
Y coordinate.
T x
X coordinate.
Dimensions (a width and height) of a rectangle in 2D.
OskActivation osk_activation
Mouse gesture to trigger the OSK.
static Company * GetIfValid(auto index)
Class for the string query window.
Definition misc_gui.cpp:899
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition misc_gui.cpp:946
void ClearViewportRect()
Clear parent window station/waypoint viewport rect.
Definition misc_gui.cpp:996
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Definition misc_gui.cpp:977
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
QueryString editbox
Editbox.
Definition misc_gui.cpp:900
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition misc_gui.cpp:929
QueryStringFlags flags
Flags controlling behaviour of the window.
Definition misc_gui.cpp:901
WidgetID last_user_action
Last started user action.
Definition misc_gui.cpp:903
Data stored about a string that can be modified in the GUI.
ptrdiff_t GetCharAtPosition(const Window *w, WidgetID wid, const Point &pt) const
Get the character that is rendered at a position.
Definition misc_gui.cpp:847
Point GetCaretPosition(const Window *w, WidgetID wid) const
Get the current caret position.
Definition misc_gui.cpp:789
Rect GetBoundingRect(const Window *w, WidgetID wid, size_t from, size_t to) const
Get the bounding rectangle for a range of the query string.
Definition misc_gui.cpp:817
Window used for asking the user a YES/NO question.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
QueryCallbackProc * proc
callback function executed on closing of popup. Window* points to parent, bool is true if 'yes' click...
EventState OnKeyPress(char32_t key, uint16_t keycode) override
A key has been pressed.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
EncodedString caption
caption for query window.
EncodedString message
message for query window.
void FindWindowPlacementAndResize(int, int, bool) override
Resize window towards the default size.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Rect WithX(int new_left, int new_right) const
Create a new Rect, replacing the left and right coordinates.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
static bool IsExpected(const BaseStation *st)
static Station * Get(auto index)
Helper/buffer for input fields.
uint16_t pixels
the current size of the string in pixels
uint16_t markxoffs
the start position of the marked area in pixels
void DeleteAll()
Delete every character in the textbuffer.
Definition textbuf.cpp:112
std::string_view GetText() const
Get the current text.
Definition textbuf.cpp:284
uint16_t caretxoffs
the current position of the caret in pixels
uint16_t marklength
the length of the marked area in pixels
void Assign(std::string_view text)
Copy a string into the textbuffer.
Definition textbuf.cpp:420
bool caret
is the caret ("_") visible or not
Tile description for the 'land area information' tool.
Definition tile_cmd.h:40
uint16_t rail_speed
Speed limit of rail (bridges and track).
Definition tile_cmd.h:53
std::optional< std::string > grf
newGRF used for the tile contents
Definition tile_cmd.h:51
StringID station_name
Type of station within the class.
Definition tile_cmd.h:47
StringID str
Description of the tile.
Definition tile_cmd.h:41
TimerGameCalendar::Date build_date
Date of construction of tile contents.
Definition tile_cmd.h:45
std::array< Owner, 4 > owner
Name of the owner(s).
Definition tile_cmd.h:43
uint64_t dparam
Parameter of the str string.
Definition tile_cmd.h:42
StringID airport_class
Name of the airport class.
Definition tile_cmd.h:48
StringID airport_name
Name of the airport.
Definition tile_cmd.h:49
uint16_t tram_speed
Speed limit of tram (bridges and track).
Definition tile_cmd.h:57
StringID roadtype
Type of road on the tile.
Definition tile_cmd.h:54
StringID tramtype
Type of tram on the tile.
Definition tile_cmd.h:56
StringID railtype
Type of rail on the tile.
Definition tile_cmd.h:52
uint16_t road_speed
Speed limit of road (bridges and track).
Definition tile_cmd.h:55
std::array< StringID, 4 > owner_type
Type of each owner.
Definition tile_cmd.h:44
std::optional< bool > town_can_upgrade
Whether the town can upgrade this house during town growth.
Definition tile_cmd.h:58
StringID airport_tile_name
Name of the airport tile.
Definition tile_cmd.h:50
StringID station_class
Class of station.
Definition tile_cmd.h:46
Window for displaying a tooltip.
Definition misc_gui.cpp:603
TooltipCloseCondition close_cond
Condition for closing the window.
Definition misc_gui.cpp:605
EncodedString text
String to display as tooltip.
Definition misc_gui.cpp:604
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
Definition misc_gui.cpp:659
Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number) override
Compute the initial position of the window.
Definition misc_gui.cpp:617
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition misc_gui.cpp:637
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition misc_gui.cpp:650
Town data structure.
Definition town.h:64
High level window description.
Definition window_gui.h:172
Data structure for an opened window.
Definition window_gui.h:273
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:987
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1112
bool IsWidgetGloballyFocused(WidgetID widget_index) const
Check if given widget has user input focus.
Definition window_gui.h:431
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1817
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Definition window.cpp:3274
Window * parent
Parent window.
Definition window_gui.h:328
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:565
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:513
ResizeInfo resize
Resize information.
Definition window_gui.h:314
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1807
WindowClass window_class
Window class.
Definition window_gui.h:301
virtual void OnQueryTextFinished(std::optional< std::string > str)
The query window opened from this window has closed.
Definition window_gui.h:791
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:539
int left
x position of left edge of the window
Definition window_gui.h:309
virtual void OnEditboxChanged(WidgetID widget)
The text in an editbox has been edited.
Definition window_gui.h:783
int top
y position of top edge of the window
Definition window_gui.h:310
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1841
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:989
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition window.cpp:604
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1831
WindowFlags flags
Window flags.
Definition window_gui.h:300
AllWindows< false > Iterate
Iterate all windows in whatever order is easiest.
Definition window_gui.h:939
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:311
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:302
@ EnableMove
enable the 'Move' button
Definition textbuf_gui.h:22
@ AcceptUnchanged
return success even when the text didn't change
Definition textbuf_gui.h:19
@ EnableDefault
enable the 'Default' button ("\0" is returned)
Definition textbuf_gui.h:20
@ LengthIsInChars
the length of the string is counted in characters
Definition textbuf_gui.h:21
void QueryCallbackProc(Window *, bool)
Callback procedure for the ShowQuery method.
Definition textbuf_gui.h:29
EnumBitSet< QueryStringFlag, uint8_t > QueryStringFlags
Bitset of QueryStringFlag elements.
Definition textbuf_gui.h:26
Functions related to text effects.
@ Rising
Make the text effect slowly go upwards.
Definition texteff.hpp:22
@ Static
Keep the text effect static.
Definition texteff.hpp:23
void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
Obtain cargo acceptance of a tile.
Definition tile_cmd.h:245
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition tile_map.cpp:115
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
Functions related to tile highlights.
@ HT_RECT
rectangle (stations, depots, ...)
Definition of Interval and OneShot timers.
Definition of the Window system.
Base of the town class.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
@ Road
Road vehicle type.
@ Train
Train vehicle type.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
void SetViewportStationRect(const Station *st, bool sel)
Select or deselect station for rectangle area highlight.
Viewport * IsPtInWindowViewport(const Window *w, int x, int y)
Is a xy position inside the viewport of the window?
Definition viewport.cpp:408
void SetViewportWaypointRect(const Waypoint *wp, bool sel)
Select or deselect waypoint for rectangle area highlight.
Functions related to (drawing on) viewports.
Handles dividing the water in the map into regions to assist pathfinding.
Base of waypoints.
void CcMoveWaypointName(Commands, const CommandCost &result, StationID waypoint_id)
Callback function that is called after a name is moved.
Command definitions related to waypoints.
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition widget.cpp:308
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:49
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:62
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_FRAME
Frame.
Definition widget_type.h:51
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:49
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX).
Definition widget_type.h:54
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
@ EqualSize
Containers should keep all their (resizing) children equally large.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1204
Window * GetMainWindow()
Get the main window, i.e.
Definition window.cpp:1190
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition window.cpp:430
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition window.cpp:1176
Window * FindWindowFromPt(int x, int y)
Do a search for a window at specific coordinates.
Definition window.cpp:1853
int GetMainViewTop()
Return the top of the main view available for general use.
Definition window.cpp:2148
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1217
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition window.cpp:2159
bool _mouse_hovering
The mouse is hovering over the same point.
Definition window.cpp:89
Window functions not directly related to making/drawing windows.
@ NoClose
This window can't be interactively closed.
Definition window_gui.h:158
@ NoFocus
This window won't get focus/make any other window lose focus when click.
Definition window_gui.h:157
@ Modal
The window is a modal child of some other window, meaning the parent is 'inactive'.
Definition window_gui.h:156
TooltipCloseCondition
Definition window_gui.h:263
@ RightClick
Close the tooltip when releasing the right mouse button.
Definition window_gui.h:264
@ ExitViewport
Close the tooltip when leaving the viewport.
Definition window_gui.h:267
@ None
Do not automatically close the tooltip.
Definition window_gui.h:266
@ Hover
Close the tooltip when stopping to hovering, i.e. moving the mouse.
Definition window_gui.h:265
EnumBitSet< FrameFlag, uint8_t > FrameFlags
Bitset of FrameFlag elements.
Definition window_gui.h:32
@ Lowered
If set the frame is lowered and the background colour brighter (ie. buttons when pressed).
Definition window_gui.h:27
@ WhiteBorder
Window white border counter bit mask.
Definition window_gui.h:232
@ Automatic
Find a place automatically.
Definition window_gui.h:146
@ Center
Center the window.
Definition window_gui.h:147
@ Manual
Manually align the window (so no automatic location finding).
Definition window_gui.h:145
int WidgetID
Widget ID.
Definition window_type.h:21
EventState
State of handling an event.
@ Handled
The passed event is handled.
@ NotHandled
The passed event is not handled.
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
Definition window_type.h:24
@ Default
Query popup confirm.
Definition window_type.h:43
@ Default
Query string.
Definition window_type.h:37
@ About
About window.
Definition window_type.h:30
Functions related to zooming.