OpenTTD Source: src/smallmap_gui.cpp Source File

OpenTTD Source 13.1

smallmap_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 "clear_map.h"
12 #include "industry.h"
13 #include "station_map.h"
14 #include "landscape.h"
15 #include "tree_map.h"
16 #include "viewport_func.h"
17 #include "town.h"
18 #include "tunnelbridge_map.h"
19 #include "core/endian_func.hpp"
20 #include "vehicle_base.h"
21 #include "sound_func.h"
22 #include "window_func.h"
23 #include "company_base.h"
24 #include "guitimer_func.h"
25 #include "zoom_func.h"
26
27 #include "smallmap_gui.h"
28
29 #include "table/strings.h"
30
31 #include <bitset>
32
33 #include "safeguards.h"
34
35 static int _smallmap_industry_count;
36 static int _smallmap_company_count;
37 static int _smallmap_cargo_count;
38
40 static uint8 _linkstat_colours_in_legenda[] = {0, 1, 3, 5, 7, 9, 11};
41
42 static const int NUM_NO_COMPANY_ENTRIES = 4;
43
45 #define MK(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, false}
46
48 #define MC(col_break) {0, STR_TINY_BLACK_HEIGHT, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, col_break}
49
51 #define MO(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, false}
52
54 #define MOEND() {0, 0, INVALID_INDUSTRYTYPE, 0, OWNER_NONE, true, true, false}
55
57 #define MKEND() {0, STR_NULL, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, true, false}
58
63 #define MS(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, true}
64
66 static LegendAndColour _legend_land_contours[] = {
67 MK(PC_BLACK, STR_SMALLMAP_LEGENDA_ROADS),
68 MK(PC_GREY, STR_SMALLMAP_LEGENDA_RAILROADS),
69 MK(PC_LIGHT_BLUE, STR_SMALLMAP_LEGENDA_STATIONS_AIRPORTS_DOCKS),
70 MK(PC_DARK_RED, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES),
71 MK(PC_WHITE, STR_SMALLMAP_LEGENDA_VEHICLES),
72
73 /* Placeholders for the colours and heights of the legend.
74 * The following values are set at BuildLandLegend() based
75 * on each colour scheme and the maximum map height. */
76 MC(true),
77 MC(false),
78 MC(false),
79 MC(false),
80 MC(false),
81 MC(false),
82 MC(true),
83 MC(false),
84 MC(false),
85 MC(false),
86 MC(false),
87 MC(false),
88 MKEND()
89 };
90
91 static const LegendAndColour _legend_vehicles[] = {
92 MK(PC_RED, STR_SMALLMAP_LEGENDA_TRAINS),
93 MK(PC_YELLOW, STR_SMALLMAP_LEGENDA_ROAD_VEHICLES),
94 MK(PC_LIGHT_BLUE, STR_SMALLMAP_LEGENDA_SHIPS),
95 MK(PC_WHITE, STR_SMALLMAP_LEGENDA_AIRCRAFT),
96
97 MS(PC_BLACK, STR_SMALLMAP_LEGENDA_TRANSPORT_ROUTES),
98 MK(PC_DARK_RED, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES),
99 MKEND()
100 };
101
102 static const LegendAndColour _legend_routes[] = {
103 MK(PC_BLACK, STR_SMALLMAP_LEGENDA_ROADS),
104 MK(PC_GREY, STR_SMALLMAP_LEGENDA_RAILROADS),
105 MK(PC_DARK_RED, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES),
106
107 MS(PC_VERY_DARK_BROWN, STR_SMALLMAP_LEGENDA_RAILROAD_STATION),
108 MK(PC_ORANGE, STR_SMALLMAP_LEGENDA_TRUCK_LOADING_BAY),
109 MK(PC_YELLOW, STR_SMALLMAP_LEGENDA_BUS_STATION),
110 MK(PC_RED, STR_SMALLMAP_LEGENDA_AIRPORT_HELIPORT),
111 MK(PC_LIGHT_BLUE, STR_SMALLMAP_LEGENDA_DOCK),
112 MKEND()
113 };
114
115 static const LegendAndColour _legend_vegetation[] = {
116 MK(PC_ROUGH_LAND, STR_SMALLMAP_LEGENDA_ROUGH_LAND),
117 MK(PC_GRASS_LAND, STR_SMALLMAP_LEGENDA_GRASS_LAND),
118 MK(PC_BARE_LAND, STR_SMALLMAP_LEGENDA_BARE_LAND),
119 MK(PC_RAINFOREST, STR_SMALLMAP_LEGENDA_RAINFOREST),
120 MK(PC_FIELDS, STR_SMALLMAP_LEGENDA_FIELDS),
121 MK(PC_TREES, STR_SMALLMAP_LEGENDA_TREES),
122
123 MS(PC_GREEN, STR_SMALLMAP_LEGENDA_FOREST),
124 MK(PC_GREY, STR_SMALLMAP_LEGENDA_ROCKS),
125 MK(PC_ORANGE, STR_SMALLMAP_LEGENDA_DESERT),
126 MK(PC_LIGHT_BLUE, STR_SMALLMAP_LEGENDA_SNOW),
127 MK(PC_BLACK, STR_SMALLMAP_LEGENDA_TRANSPORT_ROUTES),
128 MK(PC_DARK_RED, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES),
129 MKEND()
130 };
131
132 static LegendAndColour _legend_land_owners[NUM_NO_COMPANY_ENTRIES + MAX_COMPANIES + 1] = {
133 MO(PC_WATER, STR_SMALLMAP_LEGENDA_WATER),
134 MO(0x00, STR_SMALLMAP_LEGENDA_NO_OWNER), // This colour will vary depending on settings.
135 MO(PC_DARK_RED, STR_SMALLMAP_LEGENDA_TOWNS),
136 MO(PC_DARK_GREY, STR_SMALLMAP_LEGENDA_INDUSTRIES),
137 /* The legend will be terminated the first time it is used. */
138 MOEND(),
139 };
140
141 #undef MK
142 #undef MC
143 #undef MS
144 #undef MO
145 #undef MOEND
146 #undef MKEND
147
149 static LegendAndColour _legend_linkstats[NUM_CARGO + lengthof(_linkstat_colours_in_legenda) + 1];
154 static LegendAndColour _legend_from_industries[NUM_INDUSTRYTYPES + 1];
156 static uint _industry_to_list_pos[NUM_INDUSTRYTYPES];
158 static bool _smallmap_show_heightmap = false;
160 static IndustryType _smallmap_industry_highlight = INVALID_INDUSTRYTYPE;
162 static bool _smallmap_industry_highlight_state;
164 static uint _company_to_list_pos[MAX_COMPANIES];
165
169 void BuildIndustriesLegend()
170 {
171 uint j = 0;
172
173 /* Add each name */
174 for (IndustryType ind : _sorted_industry_types) {
175 const IndustrySpec *indsp = GetIndustrySpec(ind);
176 if (indsp->enabled) {
177 _legend_from_industries[j].legend = indsp->name;
178 _legend_from_industries[j].colour = indsp->map_colour;
179 _legend_from_industries[j].type = ind;
180 _legend_from_industries[j].show_on_map = true;
181 _legend_from_industries[j].col_break = false;
182 _legend_from_industries[j].end = false;
183
184 /* Store widget number for this industry type. */
185 _industry_to_list_pos[ind] = j;
186 j++;
187 }
188 }
189 /* Terminate the list */
190 _legend_from_industries[j].end = true;
191
192 /* Store number of enabled industries */
193 _smallmap_industry_count = j;
194 }
195
199 void BuildLinkStatsLegend()
200 {
201 /* Clear the legend */
202 memset(_legend_linkstats, 0, sizeof(_legend_linkstats));
203
204 uint i = 0;
205 for (; i < _sorted_cargo_specs.size(); ++i) {
206 const CargoSpec *cs = _sorted_cargo_specs[i];
207
208 _legend_linkstats[i].legend = cs->name;
209 _legend_linkstats[i].colour = cs->legend_colour;
210 _legend_linkstats[i].type = cs->Index();
211 _legend_linkstats[i].show_on_map = true;
212 }
213
214 _legend_linkstats[i].col_break = true;
215 _smallmap_cargo_count = i;
216
217 for (; i < _smallmap_cargo_count + lengthof(_linkstat_colours_in_legenda); ++i) {
218 _legend_linkstats[i].legend = STR_EMPTY;
219 _legend_linkstats[i].colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][_linkstat_colours_in_legenda[i - _smallmap_cargo_count]];
220 _legend_linkstats[i].show_on_map = true;
221 }
222
223 _legend_linkstats[_smallmap_cargo_count].legend = STR_LINKGRAPH_LEGEND_UNUSED;
224 _legend_linkstats[i - 1].legend = STR_LINKGRAPH_LEGEND_OVERLOADED;
225 _legend_linkstats[(_smallmap_cargo_count + i - 1) / 2].legend = STR_LINKGRAPH_LEGEND_SATURATED;
226 _legend_linkstats[i].end = true;
227 }
228
229 static const LegendAndColour * const _legend_table[] = {
230 _legend_land_contours,
231 _legend_vehicles,
232 _legend_from_industries,
233 _legend_linkstats,
234 _legend_routes,
235 _legend_vegetation,
236 _legend_land_owners,
237 };
238
239 #define MKCOLOUR(x) TO_LE32X(x)
240
241 #define MKCOLOUR_XXXX(x) (MKCOLOUR(0x01010101) * (uint)(x))
242 #define MKCOLOUR_X0X0(x) (MKCOLOUR(0x01000100) * (uint)(x))
243 #define MKCOLOUR_0X0X(x) (MKCOLOUR(0x00010001) * (uint)(x))
244 #define MKCOLOUR_0XX0(x) (MKCOLOUR(0x00010100) * (uint)(x))
245 #define MKCOLOUR_X00X(x) (MKCOLOUR(0x01000001) * (uint)(x))
246
247 #define MKCOLOUR_XYXY(x, y) (MKCOLOUR_X0X0(x) | MKCOLOUR_0X0X(y))
248 #define MKCOLOUR_XYYX(x, y) (MKCOLOUR_X00X(x) | MKCOLOUR_0XX0(y))
249
250 #define MKCOLOUR_0000 MKCOLOUR_XXXX(0x00)
251 #define MKCOLOUR_0FF0 MKCOLOUR_0XX0(0xFF)
252 #define MKCOLOUR_F00F MKCOLOUR_X00X(0xFF)
253 #define MKCOLOUR_FFFF MKCOLOUR_XXXX(0xFF)
254
255 #include "table/heightmap_colours.h"
256
258 struct SmallMapColourScheme {
259 uint32 *height_colours;
260 const uint32 *height_colours_base;
261 size_t colour_count;
262 uint32 default_colour;
263 };
264
266 static SmallMapColourScheme _heightmap_schemes[] = {
267 {nullptr, _green_map_heights, lengthof(_green_map_heights), MKCOLOUR_XXXX(0x54)},
268 {nullptr, _dark_green_map_heights, lengthof(_dark_green_map_heights), MKCOLOUR_XXXX(0x62)},
269 {nullptr, _violet_map_heights, lengthof(_violet_map_heights), MKCOLOUR_XXXX(0x81)},
270 };
271
275 void BuildLandLegend()
276 {
277 /* The smallmap window has never been initialized, so no need to change the legend. */
278 if (_heightmap_schemes[0].height_colours == nullptr) return;
279
280 /*
281 * The general idea of this function is to fill the legend with an appropriate evenly spaced
282 * selection of height levels. All entries with STR_TINY_BLACK_HEIGHT are reserved for this.
283 * At the moment there are twelve of these.
284 *
285 * The table below defines up to which height level a particular delta in the legend should be
286 * used. One could opt for just dividing the maximum height and use that as delta, but that
287 * creates many "ugly" legend labels, e.g. once every 950 meter. As a result, this table will
288 * reduce the number of deltas to 7: every 100m, 200m, 300m, 500m, 750m, 1000m and 1250m. The
289 * deltas are closer together at the lower numbers because going from 12 entries to just 4, as
290 * would happen when replacing 200m and 300m by 250m, would mean the legend would be short and
291 * that might not be considered appropriate.
292 *
293 * The current method yields at least 7 legend entries and at most 12. It can be increased to
294 * 8 by adding a 150m and 400m option, but especially 150m creates ugly heights.
295 *
296 * It tries to evenly space the legend items over the two columns that are there for the legend.
297 */
298
299 /* Table for delta; if max_height is less than the first column, use the second column as value. */
300 uint deltas[][2] = { { 24, 2 }, { 48, 4 }, { 72, 6 }, { 120, 10 }, { 180, 15 }, { 240, 20 }, { MAX_TILE_HEIGHT + 1, 25 }};
301 uint i = 0;
302 for (; _settings_game.construction.map_height_limit >= deltas[i][0]; i++) {
303 /* Nothing to do here. */
304 }
305 uint delta = deltas[i][1];
306
307 int total_entries = (_settings_game.construction.map_height_limit / delta) + 1;
308 int rows = CeilDiv(total_entries, 2);
309 int j = 0;
310
311 for (i = 0; i < lengthof(_legend_land_contours) - 1 && j < total_entries; i++) {
312 if (_legend_land_contours[i].legend != STR_TINY_BLACK_HEIGHT) continue;
313
314 _legend_land_contours[i].col_break = j % rows == 0;
315 _legend_land_contours[i].end = false;
316 _legend_land_contours[i].height = j * delta;
317 _legend_land_contours[i].colour = _heightmap_schemes[_settings_client.gui.smallmap_land_colour].height_colours[j * delta];
318 j++;
319 }
320 _legend_land_contours[i].end = true;
321 }
322
326 void BuildOwnerLegend()
327 {
328 _legend_land_owners[1].colour = _heightmap_schemes[_settings_client.gui.smallmap_land_colour].default_colour;
329
330 int i = NUM_NO_COMPANY_ENTRIES;
331 for (const Company *c : Company::Iterate()) {
332 _legend_land_owners[i].colour = _colour_gradient[c->colour][5];
333 _legend_land_owners[i].company = c->index;
334 _legend_land_owners[i].show_on_map = true;
335 _legend_land_owners[i].col_break = false;
336 _legend_land_owners[i].end = false;
337 _company_to_list_pos[c->index] = i;
338 i++;
339 }
340
341 /* Terminate the list */
342 _legend_land_owners[i].end = true;
343
344 /* Store maximum amount of owner legend entries. */
345 _smallmap_company_count = i;
346 }
347
348 struct AndOr {
349 uint32 mor;
350 uint32 mand;
351 };
352
353 static inline uint32 ApplyMask(uint32 colour, const AndOr *mask)
354 {
355 return (colour & mask->mand) | mask->mor;
356 }
357
358
360 static const AndOr _smallmap_contours_andor[] = {
361 {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_CLEAR
362 {MKCOLOUR_0XX0(PC_GREY ), MKCOLOUR_F00F}, // MP_RAILWAY
363 {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F}, // MP_ROAD
364 {MKCOLOUR_0XX0(PC_DARK_RED ), MKCOLOUR_F00F}, // MP_HOUSE
365 {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_TREES
366 {MKCOLOUR_XXXX(PC_LIGHT_BLUE), MKCOLOUR_0000}, // MP_STATION
367 {MKCOLOUR_XXXX(PC_WATER ), MKCOLOUR_0000}, // MP_WATER
368 {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_VOID
369 {MKCOLOUR_XXXX(PC_DARK_RED ), MKCOLOUR_0000}, // MP_INDUSTRY
370 {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_TUNNELBRIDGE
371 {MKCOLOUR_0XX0(PC_DARK_RED ), MKCOLOUR_F00F}, // MP_OBJECT
372 {MKCOLOUR_0XX0(PC_GREY ), MKCOLOUR_F00F},
373 };
374
376 static const AndOr _smallmap_vehicles_andor[] = {
377 {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_CLEAR
378 {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F}, // MP_RAILWAY
379 {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F}, // MP_ROAD
380 {MKCOLOUR_0XX0(PC_DARK_RED ), MKCOLOUR_F00F}, // MP_HOUSE
381 {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_TREES
382 {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F}, // MP_STATION
383 {MKCOLOUR_XXXX(PC_WATER ), MKCOLOUR_0000}, // MP_WATER
384 {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_VOID
385 {MKCOLOUR_XXXX(PC_DARK_RED ), MKCOLOUR_0000}, // MP_INDUSTRY
386 {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_TUNNELBRIDGE
387 {MKCOLOUR_0XX0(PC_DARK_RED ), MKCOLOUR_F00F}, // MP_OBJECT
388 {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F},
389 };
390
392 static const byte _tiletype_importance[] = {
393 2, // MP_CLEAR
394 8, // MP_RAILWAY
395 7, // MP_ROAD
396 5, // MP_HOUSE
397 2, // MP_TREES
398 9, // MP_STATION
399 2, // MP_WATER
400 1, // MP_VOID
401 6, // MP_INDUSTRY
402 8, // MP_TUNNELBRIDGE
403 2, // MP_OBJECT
404 0,
405 };
406
407
414 static inline uint32 GetSmallMapContoursPixels(TileIndex tile, TileType t)
415 {
416 const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
417 return ApplyMask(cs->height_colours[TileHeight(tile)], &_smallmap_contours_andor[t]);
418 }
419
427 static inline uint32 GetSmallMapVehiclesPixels(TileIndex tile, TileType t)
428 {
429 const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
430 return ApplyMask(cs->default_colour, &_smallmap_vehicles_andor[t]);
431 }
432
440 static inline uint32 GetSmallMapIndustriesPixels(TileIndex tile, TileType t)
441 {
442 const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
443 return ApplyMask(_smallmap_show_heightmap ? cs->height_colours[TileHeight(tile)] : cs->default_colour, &_smallmap_vehicles_andor[t]);
444 }
445
453 static inline uint32 GetSmallMapRoutesPixels(TileIndex tile, TileType t)
454 {
455 switch (t) {
456 case MP_STATION:
457 switch (GetStationType(tile)) {
458 case STATION_RAIL: return MKCOLOUR_XXXX(PC_VERY_DARK_BROWN);
459 case STATION_AIRPORT: return MKCOLOUR_XXXX(PC_RED);
460 case STATION_TRUCK: return MKCOLOUR_XXXX(PC_ORANGE);
461 case STATION_BUS: return MKCOLOUR_XXXX(PC_YELLOW);
462 case STATION_DOCK: return MKCOLOUR_XXXX(PC_LIGHT_BLUE);
463 default: return MKCOLOUR_FFFF;
464 }
465
466 case MP_RAILWAY: {
467 AndOr andor = {
468 MKCOLOUR_0XX0(GetRailTypeInfo(GetRailType(tile))->map_colour),
469 _smallmap_contours_andor[t].mand
470 };
471
472 const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
473 return ApplyMask(cs->default_colour, &andor);
474 }
475
476 case MP_ROAD: {
477 const RoadTypeInfo *rti = nullptr;
478 if (GetRoadTypeRoad(tile) != INVALID_ROADTYPE) {
479 rti = GetRoadTypeInfo(GetRoadTypeRoad(tile));
480 } else {
481 rti = GetRoadTypeInfo(GetRoadTypeTram(tile));
482 }
483 if (rti != nullptr) {
484 AndOr andor = {
485 MKCOLOUR_0XX0(rti->map_colour),
486 _smallmap_contours_andor[t].mand
487 };
488
489 const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
490 return ApplyMask(cs->default_colour, &andor);
491 }
492 FALLTHROUGH;
493 }
494
495 default:
496 /* Ground colour */
497 const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
498 return ApplyMask(cs->default_colour, &_smallmap_contours_andor[t]);
499 }
500 }
501
509 static inline uint32 GetSmallMapLinkStatsPixels(TileIndex tile, TileType t)
510 {
511 return _smallmap_show_heightmap ? GetSmallMapContoursPixels(tile, t) : GetSmallMapRoutesPixels(tile, t);
512 }
513
514 static const uint32 _vegetation_clear_bits[] = {
515 MKCOLOUR_XXXX(PC_GRASS_LAND),
516 MKCOLOUR_XXXX(PC_ROUGH_LAND),
517 MKCOLOUR_XXXX(PC_GREY),
518 MKCOLOUR_XXXX(PC_FIELDS),
519 MKCOLOUR_XXXX(PC_LIGHT_BLUE),
520 MKCOLOUR_XXXX(PC_ORANGE),
521 MKCOLOUR_XXXX(PC_GRASS_LAND),
522 MKCOLOUR_XXXX(PC_GRASS_LAND),
523 };
524
532 static inline uint32 GetSmallMapVegetationPixels(TileIndex tile, TileType t)
533 {
534 switch (t) {
535 case MP_CLEAR:
536 if (IsClearGround(tile, CLEAR_GRASS)) {
537 if (GetClearDensity(tile) < 3) return MKCOLOUR_XXXX(PC_BARE_LAND);
538 if (GetTropicZone(tile) == TROPICZONE_RAINFOREST) return MKCOLOUR_XXXX(PC_RAINFOREST);
539 }
540 return _vegetation_clear_bits[GetClearGround(tile)];
541
542 case MP_INDUSTRY:
543 return IsTileForestIndustry(tile) ? MKCOLOUR_XXXX(PC_GREEN) : MKCOLOUR_XXXX(PC_DARK_RED);
544
545 case MP_TREES:
546 if (GetTreeGround(tile) == TREE_GROUND_SNOW_DESERT || GetTreeGround(tile) == TREE_GROUND_ROUGH_SNOW) {
547 return (_settings_game.game_creation.landscape == LT_ARCTIC) ? MKCOLOUR_XYYX(PC_LIGHT_BLUE, PC_TREES) : MKCOLOUR_XYYX(PC_ORANGE, PC_TREES);
548 }
549 return (GetTropicZone(tile) == TROPICZONE_RAINFOREST) ? MKCOLOUR_XYYX(PC_RAINFOREST, PC_TREES) : MKCOLOUR_XYYX(PC_GRASS_LAND, PC_TREES);
550
551 default:
552 return ApplyMask(MKCOLOUR_XXXX(PC_GRASS_LAND), &_smallmap_vehicles_andor[t]);
553 }
554 }
555
565 uint32 GetSmallMapOwnerPixels(TileIndex tile, TileType t, IncludeHeightmap include_heightmap)
566 {
567 Owner o;
568
569 switch (t) {
570 case MP_VOID: return MKCOLOUR_XXXX(PC_BLACK);
571 case MP_INDUSTRY: return MKCOLOUR_XXXX(PC_DARK_GREY);
572 case MP_HOUSE: return MKCOLOUR_XXXX(PC_DARK_RED);
573 default: o = GetTileOwner(tile); break;
574 /* FIXME: For MP_ROAD there are multiple owners.
575 * GetTileOwner returns the rail owner (level crossing) resp. the owner of ROADTYPE_ROAD (normal road),
576 * even if there are no ROADTYPE_ROAD bits on the tile.
577 */
578 }
579
580 if ((o < MAX_COMPANIES && !_legend_land_owners[_company_to_list_pos[o]].show_on_map) || o == OWNER_NONE || o == OWNER_WATER) {
581 if (t == MP_WATER) return MKCOLOUR_XXXX(PC_WATER);
582 const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
583 return ((include_heightmap == IncludeHeightmap::IfEnabled && _smallmap_show_heightmap) || include_heightmap == IncludeHeightmap::Always)
584 ? cs->height_colours[TileHeight(tile)] : cs->default_colour;
585 } else if (o == OWNER_TOWN) {
586 return MKCOLOUR_XXXX(PC_DARK_RED);
587 }
588
589 return MKCOLOUR_XXXX(_legend_land_owners[_company_to_list_pos[o]].colour);
590 }
591
593 static const byte _vehicle_type_colours[6] = {
594 PC_RED, PC_YELLOW, PC_LIGHT_BLUE, PC_WHITE, PC_BLACK, PC_RED
595 };
596
597
599 /* static */ void SmallMapWindow::BreakIndustryChainLink()
600 {
601 InvalidateWindowClassesData(WC_INDUSTRY_CARGOES, NUM_INDUSTRYTYPES);
602 }
603
604 inline Point SmallMapWindow::SmallmapRemapCoords(int x, int y) const
605 {
606 Point pt;
607 pt.x = (y - x) * 2;
608 pt.y = y + x;
609 return pt;
610 }
611
618 inline Point SmallMapWindow::RemapTile(int tile_x, int tile_y) const
619 {
620 int x_offset = tile_x - this->scroll_x / (int)TILE_SIZE;
621 int y_offset = tile_y - this->scroll_y / (int)TILE_SIZE;
622
623 if (this->zoom == 1) return SmallmapRemapCoords(x_offset, y_offset);
624
625 /* For negative offsets, round towards -inf. */
626 if (x_offset < 0) x_offset -= this->zoom - 1;
627 if (y_offset < 0) y_offset -= this->zoom - 1;
628
629 return SmallmapRemapCoords(x_offset / this->zoom, y_offset / this->zoom);
630 }
631
642 inline Point SmallMapWindow::PixelToTile(int px, int py, int *sub, bool add_sub) const
643 {
644 if (add_sub) px += this->subscroll; // Total horizontal offset.
645
646 /* For each two rows down, add a x and a y tile, and
647 * For each four pixels to the right, move a tile to the right. */
648 Point pt = {((py >> 1) - (px >> 2)) * this->zoom, ((py >> 1) + (px >> 2)) * this->zoom};
649 px &= 3;
650
651 if (py & 1) { // Odd number of rows, handle the 2 pixel shift.
652 if (px < 2) {
653 pt.x += this->zoom;
654 px += 2;
655 } else {
656 pt.y += this->zoom;
657 px -= 2;
658 }
659 }
660
661 *sub = px;
662 return pt;
663 }
664
674 Point SmallMapWindow::ComputeScroll(int tx, int ty, int x, int y, int *sub)
675 {
676 assert(x >= 0 && y >= 0);
677
678 int new_sub;
679 Point tile_xy = PixelToTile(x, y, &new_sub, false);
680 tx -= tile_xy.x;
681 ty -= tile_xy.y;
682
683 Point scroll;
684 if (new_sub == 0) {
685 *sub = 0;
686 scroll.x = (tx + this->zoom) * TILE_SIZE;
687 scroll.y = (ty - this->zoom) * TILE_SIZE;
688 } else {
689 *sub = 4 - new_sub;
690 scroll.x = (tx + 2 * this->zoom) * TILE_SIZE;
691 scroll.y = (ty - 2 * this->zoom) * TILE_SIZE;
692 }
693 return scroll;
694 }
695
702 void SmallMapWindow::SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt)
703 {
704 static const int zoomlevels[] = {1, 2, 4, 6, 8}; // Available zoom levels. Bigger number means more zoom-out (further away).
705 static const int MIN_ZOOM_INDEX = 0;
706 static const int MAX_ZOOM_INDEX = lengthof(zoomlevels) - 1;
707
708 int new_index, cur_index, sub;
709 Point tile;
710 switch (change) {
711 case ZLC_INITIALIZE:
712 cur_index = - 1; // Definitely different from new_index.
713 new_index = MIN_ZOOM_INDEX;
714 tile.x = tile.y = 0;
715 break;
716
717 case ZLC_ZOOM_IN:
718 case ZLC_ZOOM_OUT:
719 for (cur_index = MIN_ZOOM_INDEX; cur_index <= MAX_ZOOM_INDEX; cur_index++) {
720 if (this->zoom == zoomlevels[cur_index]) break;
721 }
722 assert(cur_index <= MAX_ZOOM_INDEX);
723
724 tile = this->PixelToTile(zoom_pt->x, zoom_pt->y, &sub);
725 new_index = Clamp(cur_index + ((change == ZLC_ZOOM_IN) ? -1 : 1), MIN_ZOOM_INDEX, MAX_ZOOM_INDEX);
726 break;
727
728 default: NOT_REACHED();
729 }
730
731 if (new_index != cur_index) {
732 this->zoom = zoomlevels[new_index];
733 if (cur_index >= 0) {
734 Point new_tile = this->PixelToTile(zoom_pt->x, zoom_pt->y, &sub);
735 this->SetNewScroll(this->scroll_x + (tile.x - new_tile.x) * TILE_SIZE,
736 this->scroll_y + (tile.y - new_tile.y) * TILE_SIZE, sub);
737 } else if (this->map_type == SMT_LINKSTATS) {
738 this->overlay->SetDirty();
739 }
740 this->SetWidgetDisabledState(WID_SM_ZOOM_IN, this->zoom == zoomlevels[MIN_ZOOM_INDEX]);
741 this->SetWidgetDisabledState(WID_SM_ZOOM_OUT, this->zoom == zoomlevels[MAX_ZOOM_INDEX]);
742 this->SetDirty();
743 }
744 }
745
751 inline uint32 SmallMapWindow::GetTileColours(const TileArea &ta) const
752 {
753 int importance = 0;
754 TileIndex tile = INVALID_TILE; // Position of the most important tile.
755 TileType et = MP_VOID; // Effective tile type at that position.
756
757 for (TileIndex ti : ta) {
758 TileType ttype = GetTileType(ti);
759
760 switch (ttype) {
761 case MP_TUNNELBRIDGE: {
762 TransportType tt = GetTunnelBridgeTransportType(ti);
763
764 switch (tt) {
765 case TRANSPORT_RAIL: ttype = MP_RAILWAY; break;
766 case TRANSPORT_ROAD: ttype = MP_ROAD; break;
767 default: ttype = MP_WATER; break;
768 }
769 break;
770 }
771
772 case MP_INDUSTRY:
773 /* Special handling of industries while in "Industries" smallmap view. */
774 if (this->map_type == SMT_INDUSTRY) {
775 /* If industry is allowed to be seen, use its colour on the map.
776 * This has the highest priority above any value in _tiletype_importance. */
777 IndustryType type = Industry::GetByTile(ti)->type;
778 if (_legend_from_industries[_industry_to_list_pos[type]].show_on_map) {
779 if (type == _smallmap_industry_highlight) {
780 if (_smallmap_industry_highlight_state) return MKCOLOUR_XXXX(PC_WHITE);
781 } else {
782 return GetIndustrySpec(type)->map_colour * 0x01010101;
783 }
784 }
785 /* Otherwise make it disappear */
786 ttype = IsTileOnWater(ti) ? MP_WATER : MP_CLEAR;
787 }
788 break;
789
790 default:
791 break;
792 }
793
794 if (_tiletype_importance[ttype] > importance) {
795 importance = _tiletype_importance[ttype];
796 tile = ti;
797 et = ttype;
798 }
799 }
800
801 switch (this->map_type) {
802 case SMT_CONTOUR:
803 return GetSmallMapContoursPixels(tile, et);
804
805 case SMT_VEHICLES:
806 return GetSmallMapVehiclesPixels(tile, et);
807
808 case SMT_INDUSTRY:
809 return GetSmallMapIndustriesPixels(tile, et);
810
811 case SMT_LINKSTATS:
812 return GetSmallMapLinkStatsPixels(tile, et);
813
814 case SMT_ROUTES:
815 return GetSmallMapRoutesPixels(tile, et);
816
817 case SMT_VEGETATION:
818 return GetSmallMapVegetationPixels(tile, et);
819
820 case SMT_OWNER:
821 return GetSmallMapOwnerPixels(tile, et, IncludeHeightmap::IfEnabled);
822
823 default: NOT_REACHED();
824 }
825 }
826
840 void SmallMapWindow::DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos, Blitter *blitter) const
841 {
842 void *dst_ptr_abs_end = blitter->MoveTo(_screen.dst_ptr, 0, _screen.height);
843 uint min_xy = _settings_game.construction.freeform_edges ? 1 : 0;
844
845 do {
846 /* Check if the tile (xc,yc) is within the map range */
847 if (xc >= MapMaxX() || yc >= MapMaxY()) continue;
848
849 /* Check if the dst pointer points to a pixel inside the screen buffer */
850 if (dst < _screen.dst_ptr) continue;
851 if (dst >= dst_ptr_abs_end) continue;
852
853 /* Construct tilearea covered by (xc, yc, xc + this->zoom, yc + this->zoom) such that it is within min_xy limits. */
854 TileArea ta;
855 if (min_xy == 1 && (xc == 0 || yc == 0)) {
856 if (this->zoom == 1) continue; // The tile area is empty, don't draw anything.
857
858 ta = TileArea(TileXY(std::max(min_xy, xc), std::max(min_xy, yc)), this->zoom - (xc == 0), this->zoom - (yc == 0));
859 } else {
860 ta = TileArea(TileXY(xc, yc), this->zoom, this->zoom);
861 }
862 ta.ClampToMap(); // Clamp to map boundaries (may contain MP_VOID tiles!).
863
864 uint32 val = this->GetTileColours(ta);
865 uint8 *val8 = (uint8 *)&val;
866 int idx = std::max(0, -start_pos);
867 for (int pos = std::max(0, start_pos); pos < end_pos; pos++) {
868 blitter->SetPixel(dst, idx, 0, val8[idx]);
869 idx++;
870 }
871 /* Switch to next tile in the column */
872 } while (xc += this->zoom, yc += this->zoom, dst = blitter->MoveTo(dst, pitch, 0), --reps != 0);
873 }
874
880 void SmallMapWindow::DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const
881 {
882 for (const Vehicle *v : Vehicle::Iterate()) {
883 if (v->type == VEH_EFFECT) continue;
884 if (v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) continue;
885
886 /* Remap into flat coordinates. */
887 Point pt = this->RemapTile(v->x_pos / (int)TILE_SIZE, v->y_pos / (int)TILE_SIZE);
888
889 int y = pt.y - dpi->top;
890 if (!IsInsideMM(y, 0, dpi->height)) continue; // y is out of bounds.
891
892 bool skip = false; // Default is to draw both pixels.
893 int x = pt.x - this->subscroll - 3 - dpi->left; // Offset X coordinate.
894 if (x < 0) {
895 /* if x+1 is 0, that means we're on the very left edge,
896 * and should thus only draw a single pixel */
897 if (++x != 0) continue;
898 skip = true;
899 } else if (x >= dpi->width - 1) {
900 /* Check if we're at the very right edge, and if so draw only a single pixel */
901 if (x != dpi->width - 1) continue;
902 skip = true;
903 }
904
905 /* Calculate pointer to pixel and the colour */
906 byte colour = (this->map_type == SMT_VEHICLES) ? _vehicle_type_colours[v->type] : PC_WHITE;
907
908 /* And draw either one or two pixels depending on clipping */
909 blitter->SetPixel(dpi->dst_ptr, x, y, colour);
910 if (!skip) blitter->SetPixel(dpi->dst_ptr, x + 1, y, colour);
911 }
912 }
913
918 void SmallMapWindow::DrawTowns(const DrawPixelInfo *dpi) const
919 {
920 for (const Town *t : Town::Iterate()) {
921 /* Remap the town coordinate */
922 Point pt = this->RemapTile(TileX(t->xy), TileY(t->xy));
923 int x = pt.x - this->subscroll - (t->cache.sign.width_small >> 1);
924 int y = pt.y;
925
926 /* Check if the town sign is within bounds */
927 if (x + t->cache.sign.width_small > dpi->left &&
928 x < dpi->left + dpi->width &&
929 y + FONT_HEIGHT_SMALL > dpi->top &&
930 y < dpi->top + dpi->height) {
931 /* And draw it. */
932 SetDParam(0, t->index);
933 DrawString(x, x + t->cache.sign.width_small, y, STR_SMALLMAP_TOWN);
934 }
935 }
936 }
937
941 void SmallMapWindow::DrawMapIndicators() const
942 {
943 /* Find main viewport. */
944 const Viewport *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
945
946 Point upper_left_smallmap_coord = InverseRemapCoords2(vp->virtual_left, vp->virtual_top);
947 Point lower_right_smallmap_coord = InverseRemapCoords2(vp->virtual_left + vp->virtual_width - 1, vp->virtual_top + vp->virtual_height - 1);
948
949 Point upper_left = this->RemapTile(upper_left_smallmap_coord.x / (int)TILE_SIZE, upper_left_smallmap_coord.y / (int)TILE_SIZE);
950 upper_left.x -= this->subscroll;
951
952 Point lower_right = this->RemapTile(lower_right_smallmap_coord.x / (int)TILE_SIZE, lower_right_smallmap_coord.y / (int)TILE_SIZE);
953 lower_right.x -= this->subscroll;
954
955 SmallMapWindow::DrawVertMapIndicator(upper_left.x, upper_left.y, lower_right.y);
956 SmallMapWindow::DrawVertMapIndicator(lower_right.x, upper_left.y, lower_right.y);
957
958 SmallMapWindow::DrawHorizMapIndicator(upper_left.x, lower_right.x, upper_left.y);
959 SmallMapWindow::DrawHorizMapIndicator(upper_left.x, lower_right.x, lower_right.y);
960 }
961
973 void SmallMapWindow::DrawSmallMap(DrawPixelInfo *dpi) const
974 {
975 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
976 DrawPixelInfo *old_dpi;
977
978 old_dpi = _cur_dpi;
979 _cur_dpi = dpi;
980
981 /* Clear it */
982 GfxFillRect(dpi->left, dpi->top, dpi->left + dpi->width - 1, dpi->top + dpi->height - 1, PC_BLACK);
983
984 /* Which tile is displayed at (dpi->left, dpi->top)? */
985 int dx;
986 Point tile = this->PixelToTile(dpi->left, dpi->top, &dx);
987 int tile_x = this->scroll_x / (int)TILE_SIZE + tile.x;
988 int tile_y = this->scroll_y / (int)TILE_SIZE + tile.y;
989
990 void *ptr = blitter->MoveTo(dpi->dst_ptr, -dx - 4, 0);
991 int x = - dx - 4;
992 int y = 0;
993
994 for (;;) {
995 /* Distance from left edge */
996 if (x >= -3) {
997 if (x >= dpi->width) break; // Exit the loop.
998
999 int end_pos = std::min(dpi->width, x + 4);
1000 int reps = (dpi->height - y + 1) / 2; // Number of lines.
1001 if (reps > 0) {
1002 this->DrawSmallMapColumn(ptr, tile_x, tile_y, dpi->pitch * 2, reps, x, end_pos, blitter);
1003 }
1004 }
1005
1006 if (y == 0) {
1007 tile_y += this->zoom;
1008 y++;
1009 ptr = blitter->MoveTo(ptr, 0, 1);
1010 } else {
1011 tile_x -= this->zoom;
1012 y--;
1013 ptr = blitter->MoveTo(ptr, 0, -1);
1014 }
1015 ptr = blitter->MoveTo(ptr, 2, 0);
1016 x += 2;
1017 }
1018
1019 /* Draw vehicles */
1020 if (this->map_type == SMT_CONTOUR || this->map_type == SMT_VEHICLES) this->DrawVehicles(dpi, blitter);
1021
1022 /* Draw link stat overlay */
1023 if (this->map_type == SMT_LINKSTATS) this->overlay->Draw(dpi);
1024
1025 /* Draw town names */
1026 if (this->show_towns) this->DrawTowns(dpi);
1027
1028 /* Draw map indicators */
1029 this->DrawMapIndicators();
1030
1031 _cur_dpi = old_dpi;
1032 }
1033
1037 void SmallMapWindow::SetupWidgetData()
1038 {
1039 StringID legend_tooltip;
1040 StringID enable_all_tooltip;
1041 StringID disable_all_tooltip;
1042 int plane;
1043 switch (this->map_type) {
1044 case SMT_INDUSTRY:
1045 legend_tooltip = STR_SMALLMAP_TOOLTIP_INDUSTRY_SELECTION;
1046 enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_INDUSTRIES;
1047 disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_INDUSTRIES;
1048 plane = 0;
1049 break;
1050
1051 case SMT_OWNER:
1052 legend_tooltip = STR_SMALLMAP_TOOLTIP_COMPANY_SELECTION;
1053 enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_COMPANIES;
1054 disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_COMPANIES;
1055 plane = 0;
1056 break;
1057
1058 case SMT_LINKSTATS:
1059 legend_tooltip = STR_SMALLMAP_TOOLTIP_CARGO_SELECTION;
1060 enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_CARGOS;
1061 disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_CARGOS;
1062 plane = 0;
1063 break;
1064
1065 default:
1066 legend_tooltip = STR_NULL;
1067 enable_all_tooltip = STR_NULL;
1068 disable_all_tooltip = STR_NULL;
1069 plane = 1;
1070 break;
1071 }
1072
1073 this->GetWidget<NWidgetCore>(WID_SM_LEGEND)->SetDataTip(STR_NULL, legend_tooltip);
1074 this->GetWidget<NWidgetCore>(WID_SM_ENABLE_ALL)->SetDataTip(STR_SMALLMAP_ENABLE_ALL, enable_all_tooltip);
1075 this->GetWidget<NWidgetCore>(WID_SM_DISABLE_ALL)->SetDataTip(STR_SMALLMAP_DISABLE_ALL, disable_all_tooltip);
1076 this->GetWidget<NWidgetStacked>(WID_SM_SELECT_BUTTONS)->SetDisplayedPlane(plane);
1077 }
1078
1079 SmallMapWindow::SmallMapWindow(WindowDesc *desc, int window_number) : Window(desc), refresh(GUITimer(FORCE_REFRESH_PERIOD))
1080 {
1081 _smallmap_industry_highlight = INVALID_INDUSTRYTYPE;
1082 this->overlay = new LinkGraphOverlay(this, WID_SM_MAP, 0, this->GetOverlayCompanyMask(), 1);
1083 this->InitNested(window_number);
1084 this->LowerWidget(this->map_type + WID_SM_CONTOUR);
1085
1086 this->RebuildColourIndexIfNecessary();
1087
1088 this->SetWidgetLoweredState(WID_SM_SHOW_HEIGHT, _smallmap_show_heightmap);
1089
1090 this->SetWidgetLoweredState(WID_SM_TOGGLETOWNNAME, this->show_towns);
1091
1092 this->SetupWidgetData();
1093
1094 this->SetZoomLevel(ZLC_INITIALIZE, nullptr);
1095 this->SmallMapCenterOnCurrentPos();
1096 this->SetOverlayCargoMask();
1097 }
1098
1099 SmallMapWindow::~SmallMapWindow()
1100 {
1101 delete this->overlay;
1102 }
1103
1104 /* virtual */ void SmallMapWindow::Close()
1105 {
1106 this->BreakIndustryChainLink();
1107 this->Window::Close();
1108 }
1109
1113 void SmallMapWindow::RebuildColourIndexIfNecessary()
1114 {
1115 /* Rebuild colour indices if necessary. */
1116 if (SmallMapWindow::map_height_limit == _settings_game.construction.map_height_limit) return;
1117
1118 for (uint n = 0; n < lengthof(_heightmap_schemes); n++) {
1119 /* The heights go from 0 up to and including maximum. */
1120 int heights = _settings_game.construction.map_height_limit + 1;
1121 _heightmap_schemes[n].height_colours = ReallocT<uint32>(_heightmap_schemes[n].height_colours, heights);
1122
1123 for (int z = 0; z < heights; z++) {
1124 size_t access_index = (_heightmap_schemes[n].colour_count * z) / heights;
1125
1126 /* Choose colour by mapping the range (0..max heightlevel) on the complete colour table. */
1127 _heightmap_schemes[n].height_colours[z] = _heightmap_schemes[n].height_colours_base[access_index];
1128 }
1129 }
1130
1131 SmallMapWindow::map_height_limit = _settings_game.construction.map_height_limit;
1132 BuildLandLegend();
1133 }
1134
1135 /* virtual */ void SmallMapWindow::SetStringParameters(int widget) const
1136 {
1137 switch (widget) {
1138 case WID_SM_CAPTION:
1139 SetDParam(0, STR_SMALLMAP_TYPE_CONTOURS + this->map_type);
1140 break;
1141 }
1142 }
1143
1144 /* virtual */ void SmallMapWindow::OnInit()
1145 {
1146 uint min_width = 0;
1147 this->min_number_of_columns = INDUSTRY_MIN_NUMBER_OF_COLUMNS;
1148 this->min_number_of_fixed_rows = lengthof(_linkstat_colours_in_legenda);
1149 for (uint i = 0; i < lengthof(_legend_table); i++) {
1150 uint height = 0;
1151 uint num_columns = 1;
1152 for (const LegendAndColour *tbl = _legend_table[i]; !tbl->end; ++tbl) {
1153 StringID str;
1154 if (i == SMT_INDUSTRY) {
1155 SetDParam(0, tbl->legend);
1156 SetDParam(1, IndustryPool::MAX_SIZE);
1157 str = STR_SMALLMAP_INDUSTRY;
1158 } else if (i == SMT_LINKSTATS) {
1159 SetDParam(0, tbl->legend);
1160 str = STR_SMALLMAP_LINKSTATS;
1161 } else if (i == SMT_OWNER) {
1162 if (tbl->company != INVALID_COMPANY) {
1163 if (!Company::IsValidID(tbl->company)) {
1164 /* Rebuild the owner legend. */
1165 BuildOwnerLegend();
1166 this->OnInit();
1167 return;
1168 }
1169 /* Non-fixed legend entries for the owner view. */
1170 SetDParam(0, tbl->company);
1171 str = STR_SMALLMAP_COMPANY;
1172 } else {
1173 str = tbl->legend;
1174 }
1175 } else {
1176 if (tbl->col_break) {
1177 this->min_number_of_fixed_rows = std::max(this->min_number_of_fixed_rows, height);
1178 height = 0;
1179 num_columns++;
1180 }
1181 height++;
1182 str = tbl->legend;
1183 }
1184 min_width = std::max(GetStringBoundingBox(str).width, min_width);
1185 }
1186 this->min_number_of_fixed_rows = std::max(this->min_number_of_fixed_rows, height);
1187 this->min_number_of_columns = std::max(this->min_number_of_columns, num_columns);
1188 }
1189
1190 /* Width of the legend blob. */
1191 this->legend_width = (FONT_HEIGHT_SMALL - ScaleGUITrad(1)) * 8 / 5;
1192
1193 /* The width of a column is the minimum width of all texts + the size of the blob + some spacing */
1194 this->column_width = min_width + this->legend_width + WidgetDimensions::scaled.framerect.Horizontal();
1195 }
1196
1197 /* virtual */ void SmallMapWindow::OnPaint()
1198 {
1199 if (this->map_type == SMT_OWNER) {
1200 for (const LegendAndColour *tbl = _legend_table[this->map_type]; !tbl->end; ++tbl) {
1201 if (tbl->company != INVALID_COMPANY && !Company::IsValidID(tbl->company)) {
1202 /* Rebuild the owner legend. */
1203 BuildOwnerLegend();
1204 this->InvalidateData(1);
1205 break;
1206 }
1207 }
1208 }
1209
1210 this->DrawWidgets();
1211 }
1212
1213 /* virtual */ void SmallMapWindow::DrawWidget(const Rect &r, int widget) const
1214 {
1215 switch (widget) {
1216 case WID_SM_MAP: {
1217 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
1218 DrawPixelInfo new_dpi;
1219 if (!FillDrawPixelInfo(&new_dpi, ir.left, ir.top, ir.Width(), ir.Height())) return;
1220 this->DrawSmallMap(&new_dpi);
1221 break;
1222 }
1223
1224 case WID_SM_LEGEND: {
1225 uint columns = this->GetNumberColumnsLegend(r.Width());
1226 uint number_of_rows = this->GetNumberRowsLegend(columns);
1227 bool rtl = _current_text_dir == TD_RTL;
1228 uint i = 0; // Row counter for industry legend.
1229 uint row_height = FONT_HEIGHT_SMALL;
1230 int padding = WidgetDimensions::scaled.hsep_normal;
1231
1232 Rect origin = r.WithWidth(this->column_width, rtl).Shrink(WidgetDimensions::scaled.framerect).WithHeight(row_height);
1233 Rect text = origin.Indent(this->legend_width + WidgetDimensions::scaled.hsep_normal, rtl);
1234 Rect icon = origin.WithWidth(this->legend_width, rtl).Shrink(0, padding, 0, 0);
1235
1236 StringID string = STR_NULL;
1237 switch (this->map_type) {
1238 case SMT_INDUSTRY:
1239 string = STR_SMALLMAP_INDUSTRY;
1240 break;
1241 case SMT_LINKSTATS:
1242 string = STR_SMALLMAP_LINKSTATS;
1243 break;
1244 case SMT_OWNER:
1245 string = STR_SMALLMAP_COMPANY;
1246 break;
1247 default:
1248 break;
1249 }
1250
1251 for (const LegendAndColour *tbl = _legend_table[this->map_type]; !tbl->end; ++tbl) {
1252 if (tbl->col_break || ((this->map_type == SMT_INDUSTRY || this->map_type == SMT_OWNER || this->map_type == SMT_LINKSTATS) && i++ >= number_of_rows)) {
1253 /* Column break needed, continue at top, COLUMN_WIDTH pixels
1254 * (one "row") to the right. */
1255 int x = rtl ? -(int)this->column_width : this->column_width;
1256 int y = origin.top - text.top;
1257 text = text.Translate(x, y);
1258 icon = icon.Translate(x, y);
1259 i = 1;
1260 }
1261
1262 uint8 legend_colour = tbl->colour;
1263
1264 switch (this->map_type) {
1265 case SMT_INDUSTRY:
1266 /* Industry name must be formatted, since it's not in tiny font in the specs.
1267 * So, draw with a parameter and use the STR_SMALLMAP_INDUSTRY string, which is tiny font */
1268 SetDParam(0, tbl->legend);
1269 SetDParam(1, Industry::GetIndustryTypeCount(tbl->type));
1270 if (tbl->show_on_map && tbl->type == _smallmap_industry_highlight) {
1271 legend_colour = _smallmap_industry_highlight_state ? PC_WHITE : PC_BLACK;
1272 }
1273 FALLTHROUGH;
1274
1275 case SMT_LINKSTATS:
1276 SetDParam(0, tbl->legend);
1277 FALLTHROUGH;
1278
1279 case SMT_OWNER:
1280 if (this->map_type != SMT_OWNER || tbl->company != INVALID_COMPANY) {
1281 if (this->map_type == SMT_OWNER) SetDParam(0, tbl->company);
1282 if (!tbl->show_on_map) {
1283 /* Simply draw the string, not the black border of the legend colour.
1284 * This will enforce the idea of the disabled item */
1285 DrawString(text, string, TC_GREY);
1286 } else {
1287 DrawString(text, string, TC_BLACK);
1288 GfxFillRect(icon, PC_BLACK); // Outer border of the legend colour
1289 }
1290 break;
1291 }
1292 FALLTHROUGH;
1293
1294 default:
1295 if (this->map_type == SMT_CONTOUR) SetDParam(0, tbl->height * TILE_HEIGHT_STEP);
1296 /* Anything that is not an industry or a company is using normal process */
1297 GfxFillRect(icon, PC_BLACK);
1298 DrawString(text, tbl->legend);
1299 break;
1300 }
1301 GfxFillRect(icon.Shrink(WidgetDimensions::scaled.bevel), legend_colour); // Legend colour
1302
1303 text = text.Translate(0, row_height);
1304 icon = icon.Translate(0, row_height);
1305 }
1306 }
1307 }
1308 }
1309
1314 void SmallMapWindow::SwitchMapType(SmallMapType map_type)
1315 {
1316 this->RaiseWidget(this->map_type + WID_SM_CONTOUR);
1317 this->map_type = map_type;
1318 this->LowerWidget(this->map_type + WID_SM_CONTOUR);
1319
1320 this->SetupWidgetData();
1321
1322 if (map_type == SMT_LINKSTATS) this->overlay->SetDirty();
1323 if (map_type != SMT_INDUSTRY) this->BreakIndustryChainLink();
1324 this->SetDirty();
1325 }
1326
1335 inline uint SmallMapWindow::GetNumberRowsLegend(uint columns) const
1336 {
1337 /* Reserve one column for link colours */
1338 uint num_rows_linkstats = CeilDiv(_smallmap_cargo_count, columns - 1);
1339 uint num_rows_others = CeilDiv(std::max(_smallmap_industry_count, _smallmap_company_count), columns);
1340 return std::max({this->min_number_of_fixed_rows, num_rows_linkstats, num_rows_others});
1341 }
1342
1354 void SmallMapWindow::SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item)
1355 {
1356 if (_ctrl_pressed) {
1357 /* Disable all, except the clicked one */
1358 bool changes = false;
1359 for (int i = begin_legend_item; i != end_legend_item; i++) {
1360 bool new_state = (i == click_pos);
1361 if (legend[i].show_on_map != new_state) {
1362 changes = true;
1363 legend[i].show_on_map = new_state;
1364 }
1365 }
1366 if (!changes) {
1367 /* Nothing changed? Then show all (again). */
1368 for (int i = begin_legend_item; i != end_legend_item; i++) {
1369 legend[i].show_on_map = true;
1370 }
1371 }
1372 } else {
1373 legend[click_pos].show_on_map = !legend[click_pos].show_on_map;
1374 }
1375
1376 if (this->map_type == SMT_INDUSTRY) this->BreakIndustryChainLink();
1377 }
1378
1382 void SmallMapWindow::SetOverlayCargoMask()
1383 {
1384 CargoTypes cargo_mask = 0;
1385 for (int i = 0; i != _smallmap_cargo_count; ++i) {
1386 if (_legend_linkstats[i].show_on_map) SetBit(cargo_mask, _legend_linkstats[i].type);
1387 }
1388 this->overlay->SetCargoMask(cargo_mask);
1389 }
1390
1396 int SmallMapWindow::GetPositionOnLegend(Point pt)
1397 {
1398 const NWidgetBase *wi = this->GetWidget<NWidgetBase>(WID_SM_LEGEND);
1399 uint line = (pt.y - wi->pos_y - WidgetDimensions::scaled.framerect.top) / FONT_HEIGHT_SMALL;
1400 uint columns = this->GetNumberColumnsLegend(wi->current_x);
1401 uint number_of_rows = this->GetNumberRowsLegend(columns);
1402 if (line >= number_of_rows) return -1;
1403
1404 bool rtl = _current_text_dir == TD_RTL;
1405 int x = pt.x - wi->pos_x;
1406 if (rtl) x = wi->current_x - x;
1407 uint column = (x - WidgetDimensions::scaled.framerect.left) / this->column_width;
1408
1409 return (column * number_of_rows) + line;
1410 }
1411
1412 /* virtual */ void SmallMapWindow::OnMouseOver(Point pt, int widget)
1413 {
1414 IndustryType new_highlight = INVALID_INDUSTRYTYPE;
1415 if (widget == WID_SM_LEGEND && this->map_type == SMT_INDUSTRY) {
1416 int industry_pos = GetPositionOnLegend(pt);
1417 if (industry_pos >= 0 && industry_pos < _smallmap_industry_count) {
1418 new_highlight = _legend_from_industries[industry_pos].type;
1419 }
1420 }
1421 if (new_highlight != _smallmap_industry_highlight) {
1422 _smallmap_industry_highlight = new_highlight;
1423 this->refresh.SetInterval(_smallmap_industry_highlight != INVALID_INDUSTRYTYPE ? BLINK_PERIOD : FORCE_REFRESH_PERIOD);
1424 _smallmap_industry_highlight_state = true;
1425 this->SetDirty();
1426 }
1427 }
1428
1429 /* virtual */ void SmallMapWindow::OnClick(Point pt, int widget, int click_count)
1430 {
1431 switch (widget) {
1432 case WID_SM_MAP: { // Map window
1433 if (click_count > 0) this->mouse_capture_widget = widget;
1434
1435 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
1436 Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
1437 int sub;
1438 pt = this->PixelToTile(pt.x - wid->pos_x, pt.y - wid->pos_y, &sub);
1439 ScrollWindowTo(this->scroll_x + pt.x * TILE_SIZE, this->scroll_y + pt.y * TILE_SIZE, -1, w);
1440
1441 this->SetDirty();
1442 break;
1443 }
1444
1445 case WID_SM_ZOOM_IN:
1446 case WID_SM_ZOOM_OUT: {
1447 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
1448 Point zoom_pt = { (int)wid->current_x / 2, (int)wid->current_y / 2};
1449 this->SetZoomLevel((widget == WID_SM_ZOOM_IN) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &zoom_pt);
1450 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1451 break;
1452 }
1453
1454 case WID_SM_CONTOUR: // Show land contours
1455 case WID_SM_VEHICLES: // Show vehicles
1456 case WID_SM_INDUSTRIES: // Show industries
1457 case WID_SM_LINKSTATS: // Show route map
1458 case WID_SM_ROUTES: // Show transport routes
1459 case WID_SM_VEGETATION: // Show vegetation
1460 case WID_SM_OWNERS: // Show land owners
1461 this->SwitchMapType((SmallMapType)(widget - WID_SM_CONTOUR));
1462 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1463 break;
1464
1465 case WID_SM_CENTERMAP: // Center the smallmap again
1466 this->SmallMapCenterOnCurrentPos();
1467 this->HandleButtonClick(WID_SM_CENTERMAP);
1468 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1469 break;
1470
1471 case WID_SM_TOGGLETOWNNAME: // Toggle town names
1472 this->show_towns = !this->show_towns;
1473 this->SetWidgetLoweredState(WID_SM_TOGGLETOWNNAME, this->show_towns);
1474
1475 this->SetDirty();
1476 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1477 break;
1478
1479 case WID_SM_LEGEND: // Legend
1480 if (this->map_type == SMT_INDUSTRY || this->map_type == SMT_LINKSTATS || this->map_type == SMT_OWNER) {
1481 int click_pos = this->GetPositionOnLegend(pt);
1482 if (click_pos < 0) break;
1483
1484 /* If industry type small map*/
1485 if (this->map_type == SMT_INDUSTRY) {
1486 /* If click on industries label, find right industry type and enable/disable it. */
1487 if (click_pos < _smallmap_industry_count) {
1488 this->SelectLegendItem(click_pos, _legend_from_industries, _smallmap_industry_count);
1489 }
1490 } else if (this->map_type == SMT_LINKSTATS) {
1491 if (click_pos < _smallmap_cargo_count) {
1492 this->SelectLegendItem(click_pos, _legend_linkstats, _smallmap_cargo_count);
1493 this->SetOverlayCargoMask();
1494 }
1495 } else if (this->map_type == SMT_OWNER) {
1496 if (click_pos < _smallmap_company_count) {
1497 this->SelectLegendItem(click_pos, _legend_land_owners, _smallmap_company_count, NUM_NO_COMPANY_ENTRIES);
1498 }
1499 }
1500 this->SetDirty();
1501 }
1502 break;
1503
1504 case WID_SM_ENABLE_ALL:
1505 case WID_SM_DISABLE_ALL: {
1506 LegendAndColour *tbl = nullptr;
1507 switch (this->map_type) {
1508 case SMT_INDUSTRY:
1509 tbl = _legend_from_industries;
1510 this->BreakIndustryChainLink();
1511 break;
1512 case SMT_OWNER:
1513 tbl = &(_legend_land_owners[NUM_NO_COMPANY_ENTRIES]);
1514 break;
1515 case SMT_LINKSTATS:
1516 tbl = _legend_linkstats;
1517 break;
1518 default:
1519 NOT_REACHED();
1520 }
1521 for (;!tbl->end && tbl->legend != STR_LINKGRAPH_LEGEND_UNUSED; ++tbl) {
1522 tbl->show_on_map = (widget == WID_SM_ENABLE_ALL);
1523 }
1524 if (this->map_type == SMT_LINKSTATS) this->SetOverlayCargoMask();
1525 this->SetDirty();
1526 break;
1527 }
1528
1529 case WID_SM_SHOW_HEIGHT: // Enable/disable showing of heightmap.
1530 _smallmap_show_heightmap = !_smallmap_show_heightmap;
1531 this->SetWidgetLoweredState(WID_SM_SHOW_HEIGHT, _smallmap_show_heightmap);
1532 this->SetDirty();
1533 break;
1534 }
1535 }
1536
1545 /* virtual */ void SmallMapWindow::OnInvalidateData(int data, bool gui_scope)
1546 {
1547 if (!gui_scope) return;
1548
1549 switch (data) {
1550 case 1:
1551 /* The owner legend has already been rebuilt. */
1552 this->ReInit();
1553 break;
1554
1555 case 0: {
1556 extern std::bitset<NUM_INDUSTRYTYPES> _displayed_industries;
1557 if (this->map_type != SMT_INDUSTRY) this->SwitchMapType(SMT_INDUSTRY);
1558
1559 for (int i = 0; i != _smallmap_industry_count; i++) {
1560 _legend_from_industries[i].show_on_map = _displayed_industries.test(_legend_from_industries[i].type);
1561 }
1562 break;
1563 }
1564
1565 case 2:
1566 this->RebuildColourIndexIfNecessary();
1567 break;
1568
1569 default: NOT_REACHED();
1570 }
1571 this->SetDirty();
1572 }
1573
1574 /* virtual */ bool SmallMapWindow::OnRightClick(Point pt, int widget)
1575 {
1576 if (widget != WID_SM_MAP || _scrolling_viewport) return false;
1577
1578 _scrolling_viewport = true;
1579 return true;
1580 }
1581
1582 /* virtual */ void SmallMapWindow::OnMouseWheel(int wheel)
1583 {
1584 if (_settings_client.gui.scrollwheel_scrolling != 2) {
1585 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
1586 int cursor_x = _cursor.pos.x - this->left - wid->pos_x;
1587 int cursor_y = _cursor.pos.y - this->top - wid->pos_y;
1588 if (IsInsideMM(cursor_x, 0, wid->current_x) && IsInsideMM(cursor_y, 0, wid->current_y)) {
1589 Point pt = {cursor_x, cursor_y};
1590 this->SetZoomLevel((wheel < 0) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &pt);
1591 }
1592 }
1593 }
1594
1595 /* virtual */ void SmallMapWindow::OnRealtimeTick(uint delta_ms)
1596 {
1597 /* Update the window every now and then */
1598 if (!this->refresh.Elapsed(delta_ms)) return;
1599
1600 if (this->map_type == SMT_LINKSTATS) {
1601 uint32 company_mask = this->GetOverlayCompanyMask();
1602 if (this->overlay->GetCompanyMask() != company_mask) {
1603 this->overlay->SetCompanyMask(company_mask);
1604 } else {
1605 this->overlay->SetDirty();
1606 }
1607 }
1608 _smallmap_industry_highlight_state = !_smallmap_industry_highlight_state;
1609
1610 this->refresh.SetInterval(_smallmap_industry_highlight != INVALID_INDUSTRYTYPE ? BLINK_PERIOD : FORCE_REFRESH_PERIOD);
1611 this->SetDirty();
1612 }
1613
1621 void SmallMapWindow::SetNewScroll(int sx, int sy, int sub)
1622 {
1623 const NWidgetBase *wi = this->GetWidget<NWidgetBase>(WID_SM_MAP);
1624 Point hv = InverseRemapCoords(wi->current_x * ZOOM_LVL_BASE * TILE_SIZE / 2, wi->current_y * ZOOM_LVL_BASE * TILE_SIZE / 2);
1625 hv.x *= this->zoom;
1626 hv.y *= this->zoom;
1627
1628 if (sx < -hv.x) {
1629 sx = -hv.x;
1630 sub = 0;
1631 }
1632 if (sx > (int)(MapMaxX() * TILE_SIZE) - hv.x) {
1633 sx = MapMaxX() * TILE_SIZE - hv.x;
1634 sub = 0;
1635 }
1636 if (sy < -hv.y) {
1637 sy = -hv.y;
1638 sub = 0;
1639 }
1640 if (sy > (int)(MapMaxY() * TILE_SIZE) - hv.y) {
1641 sy = MapMaxY() * TILE_SIZE - hv.y;
1642 sub = 0;
1643 }
1644
1645 this->scroll_x = sx;
1646 this->scroll_y = sy;
1647 this->subscroll = sub;
1648 if (this->map_type == SMT_LINKSTATS) this->overlay->SetDirty();
1649 }
1650
1651 /* virtual */ void SmallMapWindow::OnScroll(Point delta)
1652 {
1653 if (_settings_client.gui.scroll_mode == VSM_VIEWPORT_RMB_FIXED || _settings_client.gui.scroll_mode == VSM_MAP_RMB_FIXED) _cursor.fix_at = true;
1654
1655 /* While tile is at (delta.x, delta.y)? */
1656 int sub;
1657 Point pt = this->PixelToTile(delta.x, delta.y, &sub);
1658 this->SetNewScroll(this->scroll_x + pt.x * TILE_SIZE, this->scroll_y + pt.y * TILE_SIZE, sub);
1659
1660 this->SetDirty();
1661 }
1662
1666 void SmallMapWindow::SmallMapCenterOnCurrentPos()
1667 {
1668 const Viewport *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
1669 Point viewport_center = InverseRemapCoords2(vp->virtual_left + vp->virtual_width / 2, vp->virtual_top + vp->virtual_height / 2);
1670
1671 int sub;
1672 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
1673 Point sxy = this->ComputeScroll(viewport_center.x / (int)TILE_SIZE, viewport_center.y / (int)TILE_SIZE,
1674 std::max(0, (int)wid->current_x / 2 - 2), wid->current_y / 2, &sub);
1675 this->SetNewScroll(sxy.x, sxy.y, sub);
1676 this->SetDirty();
1677 }
1678
1684 Point SmallMapWindow::GetStationMiddle(const Station *st) const
1685 {
1686 int x = CenterBounds(st->rect.left, st->rect.right, 0);
1687 int y = CenterBounds(st->rect.top, st->rect.bottom, 0);
1688 Point ret = this->RemapTile(x, y);
1689
1690 /* Same magic 3 as in DrawVehicles; that's where I got it from.
1691 * No idea what it is, but without it the result looks bad.
1692 */
1693 ret.x -= 3 + this->subscroll;
1694 return ret;
1695 }
1696
1697 SmallMapWindow::SmallMapType SmallMapWindow::map_type = SMT_CONTOUR;
1698 bool SmallMapWindow::show_towns = true;
1699 int SmallMapWindow::map_height_limit = -1;
1700
1709 class NWidgetSmallmapDisplay : public NWidgetContainer {
1710 const SmallMapWindow *smallmap_window;
1711 public:
1712 NWidgetSmallmapDisplay() : NWidgetContainer(NWID_VERTICAL)
1713 {
1714 this->smallmap_window = nullptr;
1715 }
1716
1717 void SetupSmallestSize(Window *w, bool init_array) override
1718 {
1719 NWidgetBase *display = this->head;
1720 NWidgetBase *bar = display->next;
1721
1722 display->SetupSmallestSize(w, init_array);
1723 bar->SetupSmallestSize(w, init_array);
1724
1725 this->smallmap_window = dynamic_cast<SmallMapWindow *>(w);
1726 assert(this->smallmap_window != nullptr);
1727 this->smallest_x = std::max(display->smallest_x, bar->smallest_x + smallmap_window->GetMinLegendWidth());
1728 this->smallest_y = display->smallest_y + std::max(bar->smallest_y, smallmap_window->GetLegendHeight(smallmap_window->min_number_of_columns));
1729 this->fill_x = std::max(display->fill_x, bar->fill_x);
1730 this->fill_y = (display->fill_y == 0 && bar->fill_y == 0) ? 0 : std::min(display->fill_y, bar->fill_y);
1731 this->resize_x = std::max(display->resize_x, bar->resize_x);
1732 this->resize_y = std::min(display->resize_y, bar->resize_y);
1733 }
1734
1735 void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
1736 {
1737 this->pos_x = x;
1738 this->pos_y = y;
1739 this->current_x = given_width;
1740 this->current_y = given_height;
1741
1742 NWidgetBase *display = this->head;
1743 NWidgetBase *bar = display->next;
1744
1745 if (sizing == ST_SMALLEST) {
1746 this->smallest_x = given_width;
1747 this->smallest_y = given_height;
1748 /* Make display and bar exactly equal to their minimal size. */
1749 display->AssignSizePosition(ST_SMALLEST, x, y, display->smallest_x, display->smallest_y, rtl);
1750 bar->AssignSizePosition(ST_SMALLEST, x, y + display->smallest_y, bar->smallest_x, bar->smallest_y, rtl);
1751 }
1752
1753 uint bar_height = std::max(bar->smallest_y, this->smallmap_window->GetLegendHeight(this->smallmap_window->GetNumberColumnsLegend(given_width - bar->smallest_x)));
1754 uint display_height = given_height - bar_height;
1755 display->AssignSizePosition(ST_RESIZE, x, y, given_width, display_height, rtl);
1756 bar->AssignSizePosition(ST_RESIZE, x, y + display_height, given_width, bar_height, rtl);
1757 }
1758
1759 NWidgetCore *GetWidgetFromPos(int x, int y) override
1760 {
1761 if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1762 for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1763 NWidgetCore *widget = child_wid->GetWidgetFromPos(x, y);
1764 if (widget != nullptr) return widget;
1765 }
1766 return nullptr;
1767 }
1768
1769 void Draw(const Window *w) override
1770 {
1771 for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) child_wid->Draw(w);
1772 }
1773 };
1774
1776 static const NWidgetPart _nested_smallmap_display[] = {
1777 NWidget(WWT_PANEL, COLOUR_BROWN, WID_SM_MAP_BORDER),
1778 NWidget(WWT_INSET, COLOUR_BROWN, WID_SM_MAP), SetMinimalSize(346, 140), SetResize(1, 1), SetPadding(2, 2, 2, 2), EndContainer(),
1779 EndContainer(),
1780 };
1781
1783 static const NWidgetPart _nested_smallmap_bar[] = {
1784 NWidget(WWT_PANEL, COLOUR_BROWN),
1785 NWidget(NWID_HORIZONTAL),
1786 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SM_LEGEND), SetResize(1, 1),
1787 NWidget(NWID_VERTICAL),
1788 /* Top button row. */
1789 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1790 NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_SM_ZOOM_IN),
1791 SetDataTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN), SetFill(1, 1),
1792 NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_SM_CENTERMAP),
1793 SetDataTip(SPR_IMG_SMALLMAP, STR_SMALLMAP_CENTER), SetFill(1, 1),
1794 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_BLANK),
1795 SetDataTip(SPR_DOT_SMALL, STR_NULL), SetFill(1, 1),
1796 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_CONTOUR),
1797 SetDataTip(SPR_IMG_SHOW_COUNTOURS, STR_SMALLMAP_TOOLTIP_SHOW_LAND_CONTOURS_ON_MAP), SetFill(1, 1),
1798 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_VEHICLES),
1799 SetDataTip(SPR_IMG_SHOW_VEHICLES, STR_SMALLMAP_TOOLTIP_SHOW_VEHICLES_ON_MAP), SetFill(1, 1),
1800 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_INDUSTRIES),
1801 SetDataTip(SPR_IMG_INDUSTRY, STR_SMALLMAP_TOOLTIP_SHOW_INDUSTRIES_ON_MAP), SetFill(1, 1),
1802 EndContainer(),
1803 /* Bottom button row. */
1804 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1805 NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_SM_ZOOM_OUT),
1806 SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT), SetFill(1, 1),
1807 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_TOGGLETOWNNAME),
1808 SetDataTip(SPR_IMG_TOWN, STR_SMALLMAP_TOOLTIP_TOGGLE_TOWN_NAMES_ON_OFF), SetFill(1, 1),
1809 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_LINKSTATS),
1810 SetDataTip(SPR_IMG_CARGOFLOW, STR_SMALLMAP_TOOLTIP_SHOW_LINK_STATS_ON_MAP), SetFill(1, 1),
1811 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_ROUTES),
1812 SetDataTip(SPR_IMG_SHOW_ROUTES, STR_SMALLMAP_TOOLTIP_SHOW_TRANSPORT_ROUTES_ON), SetFill(1, 1),
1813 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_VEGETATION),
1814 SetDataTip(SPR_IMG_PLANTTREES, STR_SMALLMAP_TOOLTIP_SHOW_VEGETATION_ON_MAP), SetFill(1, 1),
1815 NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_OWNERS),
1816 SetDataTip(SPR_IMG_COMPANY_GENERAL, STR_SMALLMAP_TOOLTIP_SHOW_LAND_OWNERS_ON_MAP), SetFill(1, 1),
1817 EndContainer(),
1818 NWidget(NWID_SPACER), SetResize(0, 1),
1819 EndContainer(),
1820 EndContainer(),
1821 EndContainer(),
1822 };
1823
1824 static NWidgetBase *SmallMapDisplay(int *biggest_index)
1825 {
1826 NWidgetContainer *map_display = new NWidgetSmallmapDisplay;
1827
1828 MakeNWidgets(_nested_smallmap_display, lengthof(_nested_smallmap_display), biggest_index, map_display);
1829 MakeNWidgets(_nested_smallmap_bar, lengthof(_nested_smallmap_bar), biggest_index, map_display);
1830 return map_display;
1831 }
1832
1833
1834 static const NWidgetPart _nested_smallmap_widgets[] = {
1835 NWidget(NWID_HORIZONTAL),
1836 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1837 NWidget(WWT_CAPTION, COLOUR_BROWN, WID_SM_CAPTION), SetDataTip(STR_SMALLMAP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1838 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1839 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1840 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1841 EndContainer(),
1842 NWidgetFunction(SmallMapDisplay), // Smallmap display and legend bar + image buttons.
1843 /* Bottom button row and resize box. */
1844 NWidget(NWID_HORIZONTAL),
1845 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SM_SELECT_BUTTONS),
1846 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1847 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_SM_ENABLE_ALL), SetDataTip(STR_SMALLMAP_ENABLE_ALL, STR_NULL),
1848 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_SM_DISABLE_ALL), SetDataTip(STR_SMALLMAP_DISABLE_ALL, STR_NULL),
1849 NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_SM_SHOW_HEIGHT), SetDataTip(STR_SMALLMAP_SHOW_HEIGHT, STR_SMALLMAP_TOOLTIP_SHOW_HEIGHT),
1850 NWidget(WWT_PANEL, COLOUR_BROWN), SetFill(1, 0), SetResize(1, 0),
1851 EndContainer(),
1852 EndContainer(),
1853 NWidget(WWT_PANEL, COLOUR_BROWN), SetFill(1, 0), SetResize(1, 0),
1854 EndContainer(),
1855 EndContainer(),
1856 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1857 EndContainer(),
1858 };
1859
1860 static WindowDesc _smallmap_desc(
1861 WDP_AUTO, "smallmap", 484, 314,
1862 WC_SMALLMAP, WC_NONE,
1863 0,
1864 _nested_smallmap_widgets, lengthof(_nested_smallmap_widgets)
1865 );
1866
1870 void ShowSmallMap()
1871 {
1872 AllocateWindowDescFront<SmallMapWindow>(&_smallmap_desc, 0);
1873 }
1874
1883 bool ScrollMainWindowTo(int x, int y, int z, bool instant)
1884 {
1885 bool res = ScrollWindowTo(x, y, z, FindWindowById(WC_MAIN_WINDOW, 0), instant);
1886
1887 /* If a user scrolls to a tile (via what way what so ever) and already is on
1888 * that tile (e.g.: pressed twice), move the smallmap to that location,
1889 * so you directly see where you are on the smallmap. */
1890
1891 if (res) return res;
1892
1893 SmallMapWindow *w = dynamic_cast<SmallMapWindow*>(FindWindowById(WC_SMALLMAP, 0));
1894 if (w != nullptr) w->SmallMapCenterOnCurrentPos();
1895
1896 return res;
1897 }
_sorted_industry_types
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
Definition: industry_gui.cpp:187
PC_WHITE
static const uint8 PC_WHITE
White palette colour.
Definition: gfx_func.h:245
MP_CLEAR
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:48
MP_HOUSE
@ MP_HOUSE
A house by a town.
Definition: tile_type.h:51
BuildOwnerLegend
void BuildOwnerLegend()
Completes the array for the owned property legend.
Definition: smallmap_gui.cpp:326
LegendAndColour::type
IndustryType type
Type of industry. Only valid for industry entries.
Definition: smallmap_gui.h:43
RoadTypeInfo
Definition: road.h:76
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:204
sound_func.h
GetSmallMapRoutesPixels
static uint32 GetSmallMapRoutesPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the small map in mode "Routes".
Definition: smallmap_gui.cpp:453
NUM_INDUSTRYTYPES
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
Definition: industry_type.h:26
_green_map_heights
static const uint32 _green_map_heights[]
Height map colours for the green colour scheme, ordered by height.
Definition: heightmap_colours.h:13
SmallMapWindow::min_number_of_fixed_rows
uint min_number_of_fixed_rows
Minimal number of rows in the legends for the fixed layouts only (all except #SMT_INDUSTRY).
Definition: smallmap_gui.h:81
IndustrySpec::map_colour
byte map_colour
colour used for the small map
Definition: industrytype.h:126
_smallmap_show_heightmap
static bool _smallmap_show_heightmap
Show heightmap in industry and owner mode of smallmap window.
Definition: smallmap_gui.cpp:158
NWidgetFunction
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1259
Blitter::SetPixel
virtual void SetPixel(void *video, int x, int y, uint8 colour)=0
Draw a pixel with a given colour on the video-buffer.
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:85
WC_INDUSTRY_CARGOES
@ WC_INDUSTRY_CARGOES
Industry cargoes chain; Window numbers:
Definition: window_type.h:503
WID_SM_ROUTES
@ WID_SM_ROUTES
Button to select the routes view.
Definition: smallmap_widget.h:26
SmallMapWindow::map_type
static SmallMapType map_type
Currently displayed legends.
Definition: smallmap_gui.h:72
ScrollWindowTo
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Definition: viewport.cpp:2410
NWidgetSmallmapDisplay::Draw
void Draw(const Window *w) override
Definition: smallmap_gui.cpp:1769
WID_SM_VEGETATION
@ WID_SM_VEGETATION
Button to select the vegetation view.
Definition: smallmap_widget.h:27
endian_func.hpp
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
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:1141
PC_YELLOW
static const uint8 PC_YELLOW
Yellow palette colour.
Definition: gfx_func.h:255
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
PC_DARK_RED
static const uint8 PC_DARK_RED
Dark red palette colour.
Definition: gfx_func.h:248
smallmap_gui.h
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:328
guitimer_func.h
SmallMapColourScheme::height_colours_base
const uint32 * height_colours_base
Base table for determining the colours.
Definition: smallmap_gui.cpp:260
_sorted_cargo_specs
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:153
MOEND
#define MOEND()
Macro used for forcing a rebuild of the owner legend the first time it is used.
Definition: smallmap_gui.cpp:54
Window::ReInit
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:1015
company_base.h
SmallMapWindow::ZLC_ZOOM_IN
@ ZLC_ZOOM_IN
Zoom in.
Definition: smallmap_gui.h:69
tunnelbridge_map.h
SmallMapWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: smallmap_gui.cpp:1197
Blitter
How all blitters should look like.
Definition: base.hpp:28
_smallmap_cargo_count
static int _smallmap_cargo_count
Number of cargos in the link stats legend.
Definition: smallmap_gui.cpp:37
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
Station
Station data structure.
Definition: station_base.h:454
SmallMapWindow::SmallMapCenterOnCurrentPos
void SmallMapCenterOnCurrentPos()
Center the small map on the current center of the viewport.
Definition: smallmap_gui.cpp:1666
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition: widget_type.h:50
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:255
PC_ORANGE
static const uint8 PC_ORANGE
Orange palette colour.
Definition: gfx_func.h:253
PC_RED
static const uint8 PC_RED
Red palette colour.
Definition: gfx_func.h:249
SmallMapWindow::DrawHorizMapIndicator
static void DrawHorizMapIndicator(int x, int x2, int y)
Draws horizontal part of map indicator.
Definition: smallmap_gui.h:114
ConstructionSettings::map_height_limit
uint8 map_height_limit
the maximum allowed heightlevel
Definition: settings_type.h:342
LegendAndColour::company
CompanyID company
Company to display. Only valid for company entries of the owner legend.
Definition: smallmap_gui.h:45
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
MS
#define MS(a, b)
Macro for break marker in arrays of LegendAndColour.
Definition: smallmap_gui.cpp:63
SmallMapWindow::OnRightClick
bool OnRightClick(Point pt, int widget) override
A click with the right mouse button has been made on the window.
Definition: smallmap_gui.cpp:1574
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
PC_RAINFOREST
static const uint8 PC_RAINFOREST
Pale green palette colour for rainforest.
Definition: gfx_func.h:268
TROPICZONE_RAINFOREST
@ TROPICZONE_RAINFOREST
Rainforest tile.
Definition: tile_type.h:79
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1157
SmallMapWindow::GetOverlayCompanyMask
uint32 GetOverlayCompanyMask() const
Get a bitmask for company links to be displayed.
Definition: smallmap_gui.h:154
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
CLEAR_GRASS
@ CLEAR_GRASS
0-3
Definition: clear_map.h:20
IsClearGround
static bool IsClearGround(TileIndex t, ClearGround ct)
Set the type of clear tile.
Definition: clear_map.h:71
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
SmallMapWindow::SetupWidgetData
void SetupWidgetData()
Function to set up widgets depending on the information being shown on the smallmap.
Definition: smallmap_gui.cpp:1037
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:49
SND_15_BEEP
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition: sound_type.h:58
vehicle_base.h
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:995
zoom_func.h
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
WID_SM_LEGEND
@ WID_SM_LEGEND
Bottom panel to display smallmap legends.
Definition: smallmap_widget.h:18
SmallMapWindow::GetTileColours
uint32 GetTileColours(const TileArea &ta) const
Decide which colours to show to the user for a group of tiles.
Definition: smallmap_gui.cpp:751
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
WID_SM_CONTOUR
@ WID_SM_CONTOUR
Button to select the contour view (height map).
Definition: smallmap_widget.h:22
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
SmallMapColourScheme::default_colour
uint32 default_colour
Default colour of the land.
Definition: smallmap_gui.cpp:262
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:57
VSM_VIEWPORT_RMB_FIXED
@ VSM_VIEWPORT_RMB_FIXED
Viewport moves with mouse movement on holding right mouse button, cursor position is fixed.
Definition: settings_type.h:99
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:56
town.h
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
_smallmap_industry_count
static int _smallmap_industry_count
Number of used industries.
Definition: smallmap_gui.cpp:35
SmallMapWindow::zoom
int zoom
Zoom level. Bigger number means more zoom-out (further away).
Definition: smallmap_gui.h:88
MAX_TILE_HEIGHT
static const uint MAX_TILE_HEIGHT
Maximum allowed tile height.
Definition: tile_type.h:24
WID_SM_SHOW_HEIGHT
@ WID_SM_SHOW_HEIGHT
Show heightmap toggle button.
Definition: smallmap_widget.h:34
clear_map.h
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
PC_GRASS_LAND
static const uint8 PC_GRASS_LAND
Dark green palette colour for grass land.
Definition: gfx_func.h:266
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:657
Viewport::virtual_top
int virtual_top
Virtual top coordinate.
Definition: viewport_type.h:29
SmallMapWindow::SwitchMapType
void SwitchMapType(SmallMapType map_type)
Select a new map type.
Definition: smallmap_gui.cpp:1314
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
NWidgetBase::smallest_y
uint smallest_y
Smallest vertical size of the widget in a filled window.
Definition: widget_type.h:194
MakeNWidgets
NWidgetContainer * MakeNWidgets(const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container)
Construct a nested widget tree from an array of parts.
Definition: widget.cpp:3250
NWidgetSmallmapDisplay
Custom container class for displaying smallmap with a vertically resizing legend panel.
Definition: smallmap_gui.cpp:1709
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:50
_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
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:205
SmallMapWindow::column_width
uint column_width
Width of a column in the WID_SM_LEGEND widget.
Definition: smallmap_gui.h:82
SmallMapWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: smallmap_gui.cpp:1144
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
SmallMapWindow::min_number_of_columns
uint min_number_of_columns
Minimal number of columns in legends.
Definition: smallmap_gui.h:80
_dark_green_map_heights
static const uint32 _dark_green_map_heights[]
Height map colours for the dark green colour scheme, ordered by height.
Definition: heightmap_colours.h:132
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:973
SmallMapWindow::scroll_x
int32 scroll_x
Horizontal world coordinate of the base tile left of the top-left corner of the smallmap display.
Definition: smallmap_gui.h:85
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:27
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1109
SmallMapWindow
Class managing the smallmap window.
Definition: smallmap_gui.h:52
SmallMapWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: smallmap_gui.cpp:1104
SmallMapWindow::show_towns
static bool show_towns
Display town names in the smallmap.
Definition: smallmap_gui.h:73
IncludeHeightmap::IfEnabled
@ IfEnabled
Only include the heightmap if its enabled in the gui by the player.
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
GetClearGround
static ClearGround GetClearGround(TileIndex t)
Get the type of clear tile.
Definition: clear_map.h:59
LinkGraphOverlay::SetCompanyMask
void SetCompanyMask(uint32 company_mask)
Set a new company mask and rebuild the cache.
Definition: linkgraph_gui.cpp:445
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
SmallMapWindow::GetNumberColumnsLegend
uint GetNumberColumnsLegend(uint width) const
Return number of columns that can be displayed in width pixels.
Definition: smallmap_gui.h:133
SmallMapWindow::DrawSmallMap
void DrawSmallMap(DrawPixelInfo *dpi) const
Draws the small map.
Definition: smallmap_gui.cpp:973
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:587
SmallMapWindow::GetStationMiddle
Point GetStationMiddle(const Station *st) const
Get the center of the given station as point on the screen in the smallmap window.
Definition: smallmap_gui.cpp:1684
SmallMapWindow::SetZoomLevel
void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt)
Initialize or change the zoom level.
Definition: smallmap_gui.cpp:702
IsTileOnWater
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
Definition: water_map.h:141
_smallmap_industry_highlight_state
static bool _smallmap_industry_highlight_state
State of highlight blinking.
Definition: smallmap_gui.cpp:162
WindowDesc
High level window description.
Definition: window_gui.h:102
SmallMapWindow::ComputeScroll
Point ComputeScroll(int tx, int ty, int x, int y, int *sub)
Compute base parameters of the smallmap such that tile (tx, ty) starts at pixel (x,...
Definition: smallmap_gui.cpp:674
Pool::MAX_SIZE
static constexpr size_t MAX_SIZE
Make template parameter accessible from outside.
Definition: pool_type.hpp:85
GetRailTypeInfo
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:304
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:467
SmallMapWindow::GetMinLegendWidth
uint GetMinLegendWidth() const
Compute minimal required width of the legends.
Definition: smallmap_gui.h:124
GUISettings::scrollwheel_scrolling
uint8 scrollwheel_scrolling
scrolling using the scroll wheel?
Definition: settings_type.h:146
WID_SM_SELECT_BUTTONS
@ WID_SM_SELECT_BUTTONS
Selection widget for the buttons present in some smallmap modes.
Definition: smallmap_widget.h:31
LinkGraphOverlay
Handles drawing of links into some window.
Definition: linkgraph_gui.h:43
VS_HIDDEN
@ VS_HIDDEN
Vehicle is not visible.
Definition: vehicle_base.h:34
CargoSpec::Index
CargoID Index() const
Determines index of this cargospec.
Definition: cargotype.h:89
Viewport
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
LinkGraphOverlay::LINK_COLOURS
static const uint8 LINK_COLOURS[][12]
Colours for the various "load" states of links.
Definition: linkgraph_gui.h:49
GUITimer
Definition: guitimer_func.h:13
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
_nested_smallmap_bar
static const NWidgetPart _nested_smallmap_bar[]
Widget parts of the smallmap legend bar + image buttons.
Definition: smallmap_gui.cpp:1783
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:90
SmallMapWindow::ZoomLevelChange
ZoomLevelChange
Available kinds of zoomlevel changes.
Definition: smallmap_gui.h:66
GetClearDensity
static uint GetClearDensity(TileIndex t)
Get the density of a non-field clear tile.
Definition: clear_map.h:83
SmallMapWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: smallmap_gui.cpp:1545
SmallMapWindow::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: smallmap_gui.cpp:1429
SmallMapWindow::GetNumberRowsLegend
uint GetNumberRowsLegend(uint columns) const
Get the number of rows in the legend from the number of columns.
Definition: smallmap_gui.cpp:1335
InverseRemapCoords
static Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Definition: landscape.h:112
SmallMapWindow::ZLC_ZOOM_OUT
@ ZLC_ZOOM_OUT
Zoom out.
Definition: smallmap_gui.h:68
ST_SMALLEST
@ ST_SMALLEST
Initialize nested widget tree to smallest size. Also updates current_x and current_y.
Definition: widget_type.h:112
SmallMapWindow::DrawVehicles
void DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const
Adds vehicles to the smallmap.
Definition: smallmap_gui.cpp:880
TileHeight
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
Definition: tile_map.h:29
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:607
WID_SM_LINKSTATS
@ WID_SM_LINKSTATS
Button to select the link stats view.
Definition: smallmap_widget.h:25
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:168
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1800
Industry::GetByTile
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:144
_vehicle_type_colours
static const byte _vehicle_type_colours[6]
Vehicle colours in #SMT_VEHICLES mode.
Definition: smallmap_gui.cpp:593
LinkGraphOverlay::SetCargoMask
void SetCargoMask(CargoTypes cargo_mask)
Set a new cargo mask and rebuild the cache.
Definition: linkgraph_gui.cpp:434
SmallMapWindow::DrawVertMapIndicator
static void DrawVertMapIndicator(int x, int y, int y2)
Draws vertical part of map indicator.
Definition: smallmap_gui.h:102
Viewport::virtual_left
int virtual_left
Virtual left coordinate.
Definition: viewport_type.h:28
Industry::type
IndustryType type
type of industry.
Definition: industry.h:83
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:249
BaseStation::rect
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Definition: base_station_base.h:75
LegendAndColour::col_break
bool col_break
Perform a column break and go further at the next column.
Definition: smallmap_gui.h:48
WID_SM_ZOOM_IN
@ WID_SM_ZOOM_IN
Button to zoom in one step.
Definition: smallmap_widget.h:20
WID_SM_VEHICLES
@ WID_SM_VEHICLES
Button to select the vehicles view.
Definition: smallmap_widget.h:23
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1004
NWidgetBase::smallest_x
uint smallest_x
Smallest horizontal size of the widget in a filled window.
Definition: widget_type.h:193
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
_legend_land_contours
static LegendAndColour _legend_land_contours[]
Legend text giving the colours to look for on the minimap.
Definition: smallmap_gui.cpp:66
SmallMapWindow::DrawMapIndicators
void DrawMapIndicators() const
Adds map indicators to the smallmap.
Definition: smallmap_gui.cpp:941
heightmap_colours.h
NWidgetBase::AssignSizePosition
virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)=0
WID_SM_DISABLE_ALL
@ WID_SM_DISABLE_ALL
Button to disable display of all legend entries.
Definition: smallmap_widget.h:33
IsInsideBS
static bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:188
RectPadding::Horizontal
uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:59
MP_WATER
@ MP_WATER
Water tile.
Definition: tile_type.h:54
_smallmap_contours_andor
static const AndOr _smallmap_contours_andor[]
Colour masks for "Contour" and "Routes" modes.
Definition: smallmap_gui.cpp:360
SmallMapColourScheme
Colour scheme of the smallmap.
Definition: smallmap_gui.cpp:258
GetStationType
static StationType GetStationType(TileIndex t)
Get the station type of this tile.
Definition: station_map.h:44
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
_smallmap_company_count
static int _smallmap_company_count
Number of entries in the owner legend.
Definition: smallmap_gui.cpp:36
_tiletype_importance
static const byte _tiletype_importance[]
Mapping of tile type to importance of the tile (higher number means more interesting to show).
Definition: smallmap_gui.cpp:392
_legend_from_industries
static LegendAndColour _legend_from_industries[NUM_INDUSTRYTYPES+1]
Allow room for all industries, plus a terminator entry This is required in order to have the industry...
Definition: smallmap_gui.cpp:154
_smallmap_industry_highlight
static IndustryType _smallmap_industry_highlight
Highlight a specific industry type.
Definition: smallmap_gui.cpp:160
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
VEH_EFFECT
@ VEH_EFFECT
Effect vehicle type (smoke, explosions, sparks, bubbles)
Definition: vehicle_type.h:31
MC
#define MC(col_break)
Macro for a height legend entry with configurable colour.
Definition: smallmap_gui.cpp:48
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:141
GetTropicZone
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
Definition: tile_map.h:238
SmallMapWindow::GetPositionOnLegend
int GetPositionOnLegend(Point pt)
Determines the mouse position on the legend.
Definition: smallmap_gui.cpp:1396
LegendAndColour::legend
StringID legend
String corresponding to the coloured item.
Definition: smallmap_gui.h:42
WID_SM_BLANK
@ WID_SM_BLANK
Empty button as placeholder.
Definition: smallmap_widget.h:19
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:321
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
industry.h
safeguards.h
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:246
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition: settings_type.h:354
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:192
CursorVars::fix_at
bool fix_at
mouse is moving, but cursor is not (used for scrolling)
Definition: gfx_type.h:120
_industry_to_list_pos
static uint _industry_to_list_pos[NUM_INDUSTRYTYPES]
For connecting industry type to position in industries list(small map legend)
Definition: smallmap_gui.cpp:156
_displayed_industries
std::bitset< NUM_INDUSTRYTYPES > _displayed_industries
Communication from the industry chain window to the smallmap window about what industries to display.
Definition: industry_gui.cpp:51
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:179
_smallmap_vehicles_andor
static const AndOr _smallmap_vehicles_andor[]
Colour masks for "Vehicles", "Industry", and "Vegetation" modes.
Definition: smallmap_gui.cpp:376
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:57
_heightmap_schemes
static SmallMapColourScheme _heightmap_schemes[]
Available colour schemes for height maps.
Definition: smallmap_gui.cpp:266
VSM_MAP_RMB_FIXED
@ VSM_MAP_RMB_FIXED
Map moves with mouse movement on holding right mouse button, cursor position is fixed.
Definition: settings_type.h:100
Viewport::virtual_width
int virtual_width
width << zoom
Definition: viewport_type.h:30
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
ScrollMainWindowTo
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
Definition: smallmap_gui.cpp:1883
GetSmallMapIndustriesPixels
static uint32 GetSmallMapIndustriesPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the small map in mode "Industries".
Definition: smallmap_gui.cpp:440
SmallMapWindow::legend_width
uint legend_width
Width of legend 'blob'.
Definition: smallmap_gui.h:83
IncludeHeightmap::Always
@ Always
Always include the heightmap.
SmallMapWindow::SmallMapType
SmallMapType
Types of legends in the WID_SM_LEGEND widget.
Definition: smallmap_gui.h:55
NWidgetContainer::head
NWidgetBase * head
Pointer to first widget in container.
Definition: widget_type.h:418
stdafx.h
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:242
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
IndustrySpec
Defines the data structure for constructing industry.
Definition: industrytype.h:107
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:3192
SmallMapWindow::DrawSmallMapColumn
void DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos, Blitter *blitter) const
Draws one column of tiles of the small map in a certain mode onto the screen buffer,...
Definition: smallmap_gui.cpp:840
viewport_func.h
Window::mouse_capture_widget
int mouse_capture_widget
Widgetindex of current mouse capture widget (e.g. dragged scrollbar). -1 if no widget has mouse captu...
Definition: window_gui.h:264
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:197
SmallMapWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: smallmap_gui.cpp:1213
PC_TREES
static const uint8 PC_TREES
Green palette colour for trees.
Definition: gfx_func.h:270
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
InverseRemapCoords2
Point InverseRemapCoords2(int x, int y, bool clamp_to_map, bool *clamped)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Definition: landscape.cpp:107
PC_GREY
static const uint8 PC_GREY
Grey palette colour.
Definition: gfx_func.h:244
SmallMapWindow::BreakIndustryChainLink
static void BreakIndustryChainLink()
Notify the industry chain window to stop sending newly selected industries.
Definition: smallmap_gui.cpp:599
NWidgetBase::next
NWidgetBase * next
Pointer to next widget in container. Managed by parent container widget.
Definition: widget_type.h:202
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
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
FONT_HEIGHT_SMALL
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:203
SmallMapWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: smallmap_gui.cpp:1595
PC_FIELDS
static const uint8 PC_FIELDS
Light brown palette colour for fields.
Definition: gfx_func.h:269
BuildIndustriesLegend
void BuildIndustriesLegend()
Fills an array for the industries legends.
Definition: smallmap_gui.cpp:169
IsTileForestIndustry
bool IsTileForestIndustry(TileIndex tile)
Check whether the tile is a forest.
Definition: industry_cmd.cpp:964
MP_TREES
@ MP_TREES
Tile got trees.
Definition: tile_type.h:52
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
MK
#define MK(a, b)
Macro for ordinary entry of LegendAndColour.
Definition: smallmap_gui.cpp:45
PC_VERY_DARK_BROWN
static const uint8 PC_VERY_DARK_BROWN
Almost-black brown palette colour.
Definition: gfx_func.h:251
WID_SM_ZOOM_OUT
@ WID_SM_ZOOM_OUT
Button to zoom out one step.
Definition: smallmap_widget.h:21
IndustrySpec::enabled
bool enabled
entity still available (by default true).newgrf can disable it, though
Definition: industrytype.h:140
GetSmallMapOwnerPixels
uint32 GetSmallMapOwnerPixels(TileIndex tile, TileType t, IncludeHeightmap include_heightmap)
Return the colour a tile would be displayed with in the small map in mode "Owner".
Definition: smallmap_gui.cpp:565
MKEND
#define MKEND()
Macro for end of list marker in arrays of LegendAndColour.
Definition: smallmap_gui.cpp:57
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
NWidgetBase::fill_y
uint fill_y
Vertical fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:187
SmallMapWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: smallmap_gui.cpp:1135
WID_SM_OWNERS
@ WID_SM_OWNERS
Button to select the owners view.
Definition: smallmap_widget.h:28
SmallMapWindow::subscroll
int32 subscroll
Number of pixels (0..3) between the right end of the base tile and the pixel at the top-left corner o...
Definition: smallmap_gui.h:87
SmallMapWindow::OnScroll
void OnScroll(Point delta) override
Handle the request for (viewport) scrolling.
Definition: smallmap_gui.cpp:1651
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1094
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:386
Industry::GetIndustryTypeCount
static uint16 GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
Definition: industry.h:179
NWidgetSmallmapDisplay::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: smallmap_gui.cpp:1735
MapMaxY
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:111
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:199
GetSmallMapLinkStatsPixels
static uint32 GetSmallMapLinkStatsPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the small map in mode "link stats".
Definition: smallmap_gui.cpp:509
MP_VOID
@ MP_VOID
Invisible tiles at the SW and SE border.
Definition: tile_type.h:55
SmallMapWindow::OnMouseOver
void OnMouseOver(Point pt, int widget) override
The mouse is currently moving over the window or has just moved outside of the window.
Definition: smallmap_gui.cpp:1412
ST_RESIZE
@ ST_RESIZE
Resize the nested widget tree.
Definition: widget_type.h:113
Blitter::MoveTo
virtual void * MoveTo(void *video, int x, int y)=0
Move the destination pointer the requested amount x and y, keeping in mind any pitch and bpp of the r...
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
INVALID_INDUSTRYTYPE
static const IndustryType INVALID_INDUSTRYTYPE
one above amount is considered invalid
Definition: industry_type.h:27
SmallMapWindow::SetOverlayCargoMask
void SetOverlayCargoMask()
Set the link graph overlay cargo mask from the legend.
Definition: smallmap_gui.cpp:1382
SmallMapWindow::SetNewScroll
void SetNewScroll(int sx, int sy, int sub)
Set new scroll_x, scroll_y, and subscroll values after limiting them such that the center of the smal...
Definition: smallmap_gui.cpp:1621
_violet_map_heights
static const uint32 _violet_map_heights[]
Height map colours for the violet colour scheme, ordered by height.
Definition: heightmap_colours.h:235
TileType
TileType
The different types of tiles.
Definition: tile_type.h:47
SmallMapWindow::INDUSTRY_MIN_NUMBER_OF_COLUMNS
static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS
Minimal number of columns in the WID_SM_LEGEND widget for the #SMT_INDUSTRY legend.
Definition: smallmap_gui.h:76
PC_ROUGH_LAND
static const uint8 PC_ROUGH_LAND
Dark green palette colour for rough land.
Definition: gfx_func.h:265
LegendAndColour::height
uint8 height
Height in tiles. Only valid for height legend entries.
Definition: smallmap_gui.h:44
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1227
NWidgetBase::fill_x
uint fill_x
Horizontal fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:186
LegendAndColour::colour
uint8 colour
Colour of the item on the map.
Definition: smallmap_gui.h:41
LinkGraphOverlay::Draw
void Draw(const DrawPixelInfo *dpi)
Draw the linkgraph overlay or some part of it, in the area given.
Definition: linkgraph_gui.cpp:259
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3269
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1012
tree_map.h
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
GetRailType
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:189
ShowSmallMap
void ShowSmallMap()
Show the smallmap window.
Definition: smallmap_gui.cpp:1870
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
LegendAndColour::show_on_map
bool show_on_map
For filtering industries, if true, industry is shown on the map in colour.
Definition: smallmap_gui.h:46
RoadTypeInfo::map_colour
byte map_colour
Colour on mini-map.
Definition: road.h:155
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
NWidgetSmallmapDisplay::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: smallmap_gui.cpp:1717
WID_SM_INDUSTRIES
@ WID_SM_INDUSTRIES
Button to select the industries view.
Definition: smallmap_widget.h:24
SmallMapWindow::DrawTowns
void DrawTowns(const DrawPixelInfo *dpi) const
Adds town names to the smallmap.
Definition: smallmap_gui.cpp:918
WidgetDimensions::bevel
RectPadding bevel
Widths of bevel border.
Definition: window_gui.h:45
GetRoadTypeInfo
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:225
_company_to_list_pos
static uint _company_to_list_pos[MAX_COMPANIES]
For connecting company ID to position in owner list (small map legend)
Definition: smallmap_gui.cpp:164
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:71
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition: window_type.h:44
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:49
MapMaxX
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
PC_WATER
static const uint8 PC_WATER
Dark blue palette colour for water.
Definition: gfx_func.h:271
NWidgetContainer
Baseclass for container widgets.
Definition: widget_type.h:403
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:247
GetTreeGround
static TreeGround GetTreeGround(TileIndex t)
Returns the groundtype for tree tiles.
Definition: tree_map.h:88
WidgetDimensions::framerect
RectPadding framerect
Offsets within frame area.
Definition: window_gui.h:47
GUITimer::Elapsed
bool Elapsed(uint delta)
Test if a timer has elapsed.
Definition: guitimer_func.h:55
TileArea
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition: tilearea_type.h:102
SmallMapWindow::RemapTile
Point RemapTile(int tile_x, int tile_y) const
Remap tile to location on this smallmap.
Definition: smallmap_gui.cpp:618
GUISettings::smallmap_land_colour
uint8 smallmap_land_colour
colour used for land and heightmap at the smallmap
Definition: settings_type.h:120
VS_UNCLICKABLE
@ VS_UNCLICKABLE
Vehicle is not clickable by the user (shadow vehicles).
Definition: vehicle_base.h:36
WID_SM_TOGGLETOWNNAME
@ WID_SM_TOGGLETOWNNAME
Toggle button to display town names.
Definition: smallmap_widget.h:30
LinkGraphOverlay::SetDirty
void SetDirty()
Mark the linkgraph dirty to be rebuilt next time Draw() is called.
Definition: linkgraph_gui.h:70
station_map.h
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
_legend_linkstats
static LegendAndColour _legend_linkstats[NUM_CARGO+lengthof(_linkstat_colours_in_legenda)+1]
Legend entries for the link stats view.
Definition: smallmap_gui.cpp:149
SoundSettings::click_beep
bool click_beep
Beep on a random selection of buttons.
Definition: settings_type.h:217
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
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
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:200
LinkGraphOverlay::GetCompanyMask
uint32 GetCompanyMask()
Get a bitmask of the currently shown companies.
Definition: linkgraph_gui.h:76
WID_SM_MAP
@ WID_SM_MAP
Panel containing the smallmap.
Definition: smallmap_widget.h:17
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:28
TILE_HEIGHT_STEP
static const int TILE_HEIGHT_STEP
One Z unit tile height difference is displayed as 50m.
Definition: viewport_func.h:19
GUISettings::linkgraph_colours
uint8 linkgraph_colours
linkgraph overlay colours
Definition: settings_type.h:121
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1078
TREE_GROUND_SNOW_DESERT
@ TREE_GROUND_SNOW_DESERT
a desert or snow tile, depend on landscape
Definition: tree_map.h:55
AndOr
Definition: smallmap_gui.cpp:348
CeilDiv
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:254
IncludeHeightmap
IncludeHeightmap
Enum for how to include the heightmap pixels/colours in small map related functions.
Definition: smallmap_gui.h:31
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:588
SmallMapWindow::refresh
GUITimer refresh
Refresh timer.
Definition: smallmap_gui.h:90
GetIndustrySpec
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Definition: industry_cmd.cpp:123
WID_SM_MAP_BORDER
@ WID_SM_MAP_BORDER
Border around the smallmap.
Definition: smallmap_widget.h:16
SmallMapWindow::scroll_y
int32 scroll_y
Vertical world coordinate of the base tile left of the top-left corner of the smallmap display.
Definition: smallmap_gui.h:86
Window
Data structure for an opened window.
Definition: window_gui.h:213
SizingType
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition()
Definition: widget_type.h:111
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
IndustrySpec::name
StringID name
Displayed name of the industry.
Definition: industrytype.h:127
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
Window::RaiseWidget
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:412
SmallMapWindow::SelectLegendItem
void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item=0)
Select and toggle a legend item.
Definition: smallmap_gui.cpp:1354
GUISettings::scroll_mode
uint8 scroll_mode
viewport scroll mode
Definition: settings_type.h:122
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:858
SmallMapWindow::RebuildColourIndexIfNecessary
void RebuildColourIndexIfNecessary()
Rebuilds the colour indices used for fast access to the smallmap contour colours based on the heightl...
Definition: smallmap_gui.cpp:1113
PC_DARK_GREY
static const uint8 PC_DARK_GREY
Dark grey palette colour.
Definition: gfx_func.h:243
Viewport::virtual_height
int virtual_height
height << zoom
Definition: viewport_type.h:31
SmallMapWindow::map_height_limit
static int map_height_limit
Currently used/cached map height limit.
Definition: smallmap_gui.h:74
SmallMapWindow::ZLC_INITIALIZE
@ ZLC_INITIALIZE
Initialize zoom level.
Definition: smallmap_gui.h:67
SmallMapColourScheme::height_colours
uint32 * height_colours
Cached colours for each level in a map.
Definition: smallmap_gui.cpp:259
PC_LIGHT_BLUE
static const uint8 PC_LIGHT_BLUE
Light blue palette colour.
Definition: gfx_func.h:263
GetSmallMapVehiclesPixels
static uint32 GetSmallMapVehiclesPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the small map in mode "Vehicles".
Definition: smallmap_gui.cpp:427
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
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
OrthogonalTileArea::ClampToMap
void ClampToMap()
Clamp the tile area to map borders.
Definition: tilearea.cpp:142
MO
#define MO(a, b)
Macro for non-company owned property entry of LegendAndColour.
Definition: smallmap_gui.cpp:51
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:314
GetTunnelBridgeTransportType
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Definition: tunnelbridge_map.h:39
LegendAndColour
Structure for holding relevant data for legends in small map.
Definition: smallmap_gui.h:40
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
Window::LowerWidget
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:403
Company
Definition: company_base.h:117
LegendAndColour::end
bool end
This is the end of the list.
Definition: smallmap_gui.h:47
NWidgetBase::resize_x
uint resize_x
Horizontal resize step (0 means not resizable).
Definition: widget_type.h:188
OWNER_WATER
@ OWNER_WATER
The tile/execution is done by "water".
Definition: company_type.h:26
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:196
_linkstat_colours_in_legenda
static uint8 _linkstat_colours_in_legenda[]
Link stat colours shown in legenda.
Definition: smallmap_gui.cpp:40
WID_SM_CENTERMAP
@ WID_SM_CENTERMAP
Button to move smallmap center to main window center.
Definition: smallmap_widget.h:29
BuildLinkStatsLegend
void BuildLinkStatsLegend()
Populate legend table for the link stat view.
Definition: smallmap_gui.cpp:199
_scrolling_viewport
bool _scrolling_viewport
A viewport is being scrolled with the mouse.
Definition: window.cpp:90
WC_SMALLMAP
@ WC_SMALLMAP
Small map; Window numbers:
Definition: window_type.h:97
PC_GREEN
static const uint8 PC_GREEN
Green palette colour.
Definition: gfx_func.h:259
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:382
SmallMapWindow::PixelToTile
Point PixelToTile(int px, int py, int *sub, bool add_sub=true) const
Determine the tile relative to the base tile of the smallmap, and the pixel position at that tile for...
Definition: smallmap_gui.cpp:642
NWidgetCore::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1214
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:49
NUM_NO_COMPANY_ENTRIES
static const int NUM_NO_COMPANY_ENTRIES
Number of entries in the owner legend that are not companies.
Definition: smallmap_gui.cpp:42
SmallMapWindow::FORCE_REFRESH_PERIOD
static const uint FORCE_REFRESH_PERIOD
map is redrawn after that many milliseconds.
Definition: smallmap_gui.h:77
WID_SM_ENABLE_ALL
@ WID_SM_ENABLE_ALL
Button to enable display of all legend entries.
Definition: smallmap_widget.h:32
OWNER_TOWN
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
SmallMapWindow::GetLegendHeight
uint GetLegendHeight(uint num_columns) const
Compute height given a number of columns.
Definition: smallmap_gui.h:143
SmallMapWindow::OnMouseWheel
void OnMouseWheel(int wheel) override
The mouse wheel has been turned.
Definition: smallmap_gui.cpp:1582
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:604
PC_BARE_LAND
static const uint8 PC_BARE_LAND
Brown palette colour for bare land.
Definition: gfx_func.h:267
BuildLandLegend
void BuildLandLegend()
(Re)build the colour tables for the legends.
Definition: smallmap_gui.cpp:275
SmallMapColourScheme::colour_count
size_t colour_count
The number of colours.
Definition: smallmap_gui.cpp:261
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:155
GetSmallMapVegetationPixels
static uint32 GetSmallMapVegetationPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the smallmap in mode "Vegetation".
Definition: smallmap_gui.cpp:532
NWidgetSmallmapDisplay::smallmap_window
const SmallMapWindow * smallmap_window
Window manager instance.
Definition: smallmap_gui.cpp:1710
_nested_smallmap_display
static const NWidgetPart _nested_smallmap_display[]
Widget parts of the smallmap display.
Definition: smallmap_gui.cpp:1776
WID_SM_CAPTION
@ WID_SM_CAPTION
Caption of the window.
Definition: smallmap_widget.h:15
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition: widget.cpp:168
SmallMapWindow::BLINK_PERIOD
static const uint BLINK_PERIOD
highlight blinking interval in milliseconds.
Definition: smallmap_gui.h:78
GetSmallMapContoursPixels
static uint32 GetSmallMapContoursPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the small map in mode "Contour".
Definition: smallmap_gui.cpp:414
NWidgetSmallmapDisplay::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: smallmap_gui.cpp:1759
NWidgetBase::SetupSmallestSize
virtual void SetupSmallestSize(Window *w, bool init_array)=0
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1103
TREE_GROUND_ROUGH_SNOW
@ TREE_GROUND_ROUGH_SNOW
A snow tile that is rough underneath.
Definition: tree_map.h:57