OpenTTD Source  14.0-beta1
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 "core/backup_type.hpp"
12 #include "clear_map.h"
13 #include "industry.h"
14 #include "station_map.h"
15 #include "landscape.h"
16 #include "tree_map.h"
17 #include "viewport_func.h"
18 #include "town.h"
19 #include "tunnelbridge_map.h"
20 #include "core/endian_func.hpp"
21 #include "vehicle_base.h"
22 #include "sound_func.h"
23 #include "window_func.h"
24 #include "company_base.h"
25 #include "zoom_func.h"
26 #include "strings_func.h"
27 #include "blitter/factory.hpp"
30 #include "timer/timer.h"
31 #include "timer/timer_window.h"
32 #include "smallmap_gui.h"
33 
34 #include "table/strings.h"
35 
36 #include <bitset>
37 
38 #include "safeguards.h"
39 
43 
46  uint8_t colour;
48  IndustryType type;
49  uint8_t height;
51  bool show_on_map;
52  bool end;
53  bool col_break;
54 };
55 
57 static uint8_t _linkstat_colours_in_legenda[] = {0, 1, 3, 5, 7, 9, 11};
58 
59 static const int NUM_NO_COMPANY_ENTRIES = 4;
60 
62 #define MK(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, false}
63 
65 #define MC(col_break) {0, STR_TINY_BLACK_HEIGHT, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, col_break}
66 
68 #define MO(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, false}
69 
71 #define MOEND() {0, 0, INVALID_INDUSTRYTYPE, 0, OWNER_NONE, true, true, false}
72 
74 #define MKEND() {0, STR_NULL, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, true, false}
75 
80 #define MS(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, true}
81 
84  MK(PC_BLACK, STR_SMALLMAP_LEGENDA_ROADS),
85  MK(PC_GREY, STR_SMALLMAP_LEGENDA_RAILROADS),
86  MK(PC_LIGHT_BLUE, STR_SMALLMAP_LEGENDA_STATIONS_AIRPORTS_DOCKS),
87  MK(PC_DARK_RED, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES),
88  MK(PC_WHITE, STR_SMALLMAP_LEGENDA_VEHICLES),
89 
90  /* Placeholders for the colours and heights of the legend.
91  * The following values are set at BuildLandLegend() based
92  * on each colour scheme and the maximum map height. */
93  MC(true),
94  MC(false),
95  MC(false),
96  MC(false),
97  MC(false),
98  MC(false),
99  MC(true),
100  MC(false),
101  MC(false),
102  MC(false),
103  MC(false),
104  MC(false),
105  MKEND()
106 };
107 
108 static const LegendAndColour _legend_vehicles[] = {
109  MK(PC_RED, STR_SMALLMAP_LEGENDA_TRAINS),
110  MK(PC_YELLOW, STR_SMALLMAP_LEGENDA_ROAD_VEHICLES),
111  MK(PC_LIGHT_BLUE, STR_SMALLMAP_LEGENDA_SHIPS),
112  MK(PC_WHITE, STR_SMALLMAP_LEGENDA_AIRCRAFT),
113 
114  MS(PC_BLACK, STR_SMALLMAP_LEGENDA_TRANSPORT_ROUTES),
115  MK(PC_DARK_RED, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES),
116  MKEND()
117 };
118 
119 static const LegendAndColour _legend_routes[] = {
120  MK(PC_BLACK, STR_SMALLMAP_LEGENDA_ROADS),
121  MK(PC_GREY, STR_SMALLMAP_LEGENDA_RAILROADS),
122  MK(PC_DARK_RED, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES),
123 
124  MS(PC_VERY_DARK_BROWN, STR_SMALLMAP_LEGENDA_RAILROAD_STATION),
125  MK(PC_ORANGE, STR_SMALLMAP_LEGENDA_TRUCK_LOADING_BAY),
126  MK(PC_YELLOW, STR_SMALLMAP_LEGENDA_BUS_STATION),
127  MK(PC_RED, STR_SMALLMAP_LEGENDA_AIRPORT_HELIPORT),
128  MK(PC_LIGHT_BLUE, STR_SMALLMAP_LEGENDA_DOCK),
129  MKEND()
130 };
131 
132 static const LegendAndColour _legend_vegetation[] = {
133  MK(PC_ROUGH_LAND, STR_SMALLMAP_LEGENDA_ROUGH_LAND),
134  MK(PC_GRASS_LAND, STR_SMALLMAP_LEGENDA_GRASS_LAND),
135  MK(PC_BARE_LAND, STR_SMALLMAP_LEGENDA_BARE_LAND),
136  MK(PC_RAINFOREST, STR_SMALLMAP_LEGENDA_RAINFOREST),
137  MK(PC_FIELDS, STR_SMALLMAP_LEGENDA_FIELDS),
138  MK(PC_TREES, STR_SMALLMAP_LEGENDA_TREES),
139 
140  MS(PC_GREEN, STR_SMALLMAP_LEGENDA_FOREST),
141  MK(PC_GREY, STR_SMALLMAP_LEGENDA_ROCKS),
142  MK(PC_ORANGE, STR_SMALLMAP_LEGENDA_DESERT),
143  MK(PC_LIGHT_BLUE, STR_SMALLMAP_LEGENDA_SNOW),
144  MK(PC_BLACK, STR_SMALLMAP_LEGENDA_TRANSPORT_ROUTES),
145  MK(PC_DARK_RED, STR_SMALLMAP_LEGENDA_BUILDINGS_INDUSTRIES),
146  MKEND()
147 };
148 
149 static LegendAndColour _legend_land_owners[NUM_NO_COMPANY_ENTRIES + MAX_COMPANIES + 1] = {
150  MO(PC_WATER, STR_SMALLMAP_LEGENDA_WATER),
151  MO(0x00, STR_SMALLMAP_LEGENDA_NO_OWNER), // This colour will vary depending on settings.
152  MO(PC_DARK_RED, STR_SMALLMAP_LEGENDA_TOWNS),
153  MO(PC_DARK_GREY, STR_SMALLMAP_LEGENDA_INDUSTRIES),
154  /* The legend will be terminated the first time it is used. */
155  MOEND(),
156 };
157 
158 #undef MK
159 #undef MC
160 #undef MS
161 #undef MO
162 #undef MOEND
163 #undef MKEND
164 
175 static bool _smallmap_show_heightmap = false;
182 
187 {
188  uint j = 0;
189 
190  /* Add each name */
191  for (IndustryType ind : _sorted_industry_types) {
192  const IndustrySpec *indsp = GetIndustrySpec(ind);
193  if (indsp->enabled) {
194  _legend_from_industries[j].legend = indsp->name;
196  _legend_from_industries[j].type = ind;
199  _legend_from_industries[j].end = false;
200 
201  /* Store widget number for this industry type. */
202  _industry_to_list_pos[ind] = j;
203  j++;
204  }
205  }
206  /* Terminate the list */
207  _legend_from_industries[j].end = true;
208 
209  /* Store number of enabled industries */
211 }
212 
217 {
218  /* Clear the legend */
219  memset(_legend_linkstats, 0, sizeof(_legend_linkstats));
220 
221  uint i = 0;
222  for (; i < _sorted_cargo_specs.size(); ++i) {
223  const CargoSpec *cs = _sorted_cargo_specs[i];
224 
225  _legend_linkstats[i].legend = cs->name;
226  _legend_linkstats[i].colour = cs->legend_colour;
227  _legend_linkstats[i].type = cs->Index();
228  _legend_linkstats[i].show_on_map = true;
229  }
230 
231  _legend_linkstats[i].col_break = true;
233 
235  _legend_linkstats[i].legend = STR_EMPTY;
237  _legend_linkstats[i].show_on_map = true;
238  }
239 
240  _legend_linkstats[_smallmap_cargo_count].legend = STR_LINKGRAPH_LEGEND_UNUSED;
241  _legend_linkstats[i - 1].legend = STR_LINKGRAPH_LEGEND_OVERLOADED;
242  _legend_linkstats[(_smallmap_cargo_count + i - 1) / 2].legend = STR_LINKGRAPH_LEGEND_SATURATED;
243  _legend_linkstats[i].end = true;
244 }
245 
246 static const LegendAndColour * const _legend_table[] = {
248  _legend_vehicles,
251  _legend_routes,
252  _legend_vegetation,
253  _legend_land_owners,
254 };
255 
256 #define MKCOLOUR(x) TO_LE32X(x)
257 
258 #define MKCOLOUR_XXXX(x) (MKCOLOUR(0x01010101) * (uint)(x))
259 #define MKCOLOUR_X0X0(x) (MKCOLOUR(0x01000100) * (uint)(x))
260 #define MKCOLOUR_0X0X(x) (MKCOLOUR(0x00010001) * (uint)(x))
261 #define MKCOLOUR_0XX0(x) (MKCOLOUR(0x00010100) * (uint)(x))
262 #define MKCOLOUR_X00X(x) (MKCOLOUR(0x01000001) * (uint)(x))
263 
264 #define MKCOLOUR_XYXY(x, y) (MKCOLOUR_X0X0(x) | MKCOLOUR_0X0X(y))
265 #define MKCOLOUR_XYYX(x, y) (MKCOLOUR_X00X(x) | MKCOLOUR_0XX0(y))
266 
267 #define MKCOLOUR_0000 MKCOLOUR_XXXX(0x00)
268 #define MKCOLOUR_0FF0 MKCOLOUR_0XX0(0xFF)
269 #define MKCOLOUR_F00F MKCOLOUR_X00X(0xFF)
270 #define MKCOLOUR_FFFF MKCOLOUR_XXXX(0xFF)
271 
272 #include "table/heightmap_colours.h"
273 
276  uint32_t *height_colours;
277  const uint32_t *height_colours_base;
278  size_t colour_count;
279  uint32_t default_colour;
280 };
281 
284  {nullptr, _green_map_heights, lengthof(_green_map_heights), MKCOLOUR_XXXX(0x54)},
285  {nullptr, _dark_green_map_heights, lengthof(_dark_green_map_heights), MKCOLOUR_XXXX(0x62)},
286  {nullptr, _violet_map_heights, lengthof(_violet_map_heights), MKCOLOUR_XXXX(0x81)},
287 };
288 
293 {
294  /* The smallmap window has never been initialized, so no need to change the legend. */
295  if (_heightmap_schemes[0].height_colours == nullptr) return;
296 
297  /*
298  * The general idea of this function is to fill the legend with an appropriate evenly spaced
299  * selection of height levels. All entries with STR_TINY_BLACK_HEIGHT are reserved for this.
300  * At the moment there are twelve of these.
301  *
302  * The table below defines up to which height level a particular delta in the legend should be
303  * used. One could opt for just dividing the maximum height and use that as delta, but that
304  * creates many "ugly" legend labels, e.g. once every 950 meter. As a result, this table will
305  * reduce the number of deltas to 7: every 100m, 200m, 300m, 500m, 750m, 1000m and 1250m. The
306  * deltas are closer together at the lower numbers because going from 12 entries to just 4, as
307  * would happen when replacing 200m and 300m by 250m, would mean the legend would be short and
308  * that might not be considered appropriate.
309  *
310  * The current method yields at least 7 legend entries and at most 12. It can be increased to
311  * 8 by adding a 150m and 400m option, but especially 150m creates ugly heights.
312  *
313  * It tries to evenly space the legend items over the two columns that are there for the legend.
314  */
315 
316  /* Table for delta; if max_height is less than the first column, use the second column as value. */
317  uint deltas[][2] = { { 24, 2 }, { 48, 4 }, { 72, 6 }, { 120, 10 }, { 180, 15 }, { 240, 20 }, { MAX_TILE_HEIGHT + 1, 25 }};
318  uint i = 0;
319  for (; _settings_game.construction.map_height_limit >= deltas[i][0]; i++) {
320  /* Nothing to do here. */
321  }
322  uint delta = deltas[i][1];
323 
324  int total_entries = (_settings_game.construction.map_height_limit / delta) + 1;
325  int rows = CeilDiv(total_entries, 2);
326  int j = 0;
327 
328  for (i = 0; i < lengthof(_legend_land_contours) - 1 && j < total_entries; i++) {
329  if (_legend_land_contours[i].legend != STR_TINY_BLACK_HEIGHT) continue;
330 
331  _legend_land_contours[i].col_break = j % rows == 0;
332  _legend_land_contours[i].end = false;
333  _legend_land_contours[i].height = j * delta;
335  j++;
336  }
337  _legend_land_contours[i].end = true;
338 }
339 
344 {
346 
347  int i = NUM_NO_COMPANY_ENTRIES;
348  for (const Company *c : Company::Iterate()) {
349  _legend_land_owners[i].colour = _colour_gradient[c->colour][5];
350  _legend_land_owners[i].company = c->index;
351  _legend_land_owners[i].show_on_map = true;
352  _legend_land_owners[i].col_break = false;
353  _legend_land_owners[i].end = false;
354  _company_to_list_pos[c->index] = i;
355  i++;
356  }
357 
358  /* Terminate the list */
359  _legend_land_owners[i].end = true;
360 
361  /* Store maximum amount of owner legend entries. */
363 }
364 
365 struct AndOr {
366  uint32_t mor;
367  uint32_t mand;
368 };
369 
370 static inline uint32_t ApplyMask(uint32_t colour, const AndOr *mask)
371 {
372  return (colour & mask->mand) | mask->mor;
373 }
374 
375 
377 static const AndOr _smallmap_contours_andor[] = {
378  {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_CLEAR
379  {MKCOLOUR_0XX0(PC_GREY ), MKCOLOUR_F00F}, // MP_RAILWAY
380  {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F}, // MP_ROAD
381  {MKCOLOUR_0XX0(PC_DARK_RED ), MKCOLOUR_F00F}, // MP_HOUSE
382  {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_TREES
383  {MKCOLOUR_XXXX(PC_LIGHT_BLUE), MKCOLOUR_0000}, // MP_STATION
384  {MKCOLOUR_XXXX(PC_WATER ), MKCOLOUR_0000}, // MP_WATER
385  {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_VOID
386  {MKCOLOUR_XXXX(PC_DARK_RED ), MKCOLOUR_0000}, // MP_INDUSTRY
387  {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_TUNNELBRIDGE
388  {MKCOLOUR_0XX0(PC_DARK_RED ), MKCOLOUR_F00F}, // MP_OBJECT
389  {MKCOLOUR_0XX0(PC_GREY ), MKCOLOUR_F00F},
390 };
391 
393 static const AndOr _smallmap_vehicles_andor[] = {
394  {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_CLEAR
395  {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F}, // MP_RAILWAY
396  {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F}, // MP_ROAD
397  {MKCOLOUR_0XX0(PC_DARK_RED ), MKCOLOUR_F00F}, // MP_HOUSE
398  {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_TREES
399  {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F}, // MP_STATION
400  {MKCOLOUR_XXXX(PC_WATER ), MKCOLOUR_0000}, // MP_WATER
401  {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_VOID
402  {MKCOLOUR_XXXX(PC_DARK_RED ), MKCOLOUR_0000}, // MP_INDUSTRY
403  {MKCOLOUR_0000 , MKCOLOUR_FFFF}, // MP_TUNNELBRIDGE
404  {MKCOLOUR_0XX0(PC_DARK_RED ), MKCOLOUR_F00F}, // MP_OBJECT
405  {MKCOLOUR_0XX0(PC_BLACK ), MKCOLOUR_F00F},
406 };
407 
409 static const byte _tiletype_importance[] = {
410  2, // MP_CLEAR
411  8, // MP_RAILWAY
412  7, // MP_ROAD
413  5, // MP_HOUSE
414  2, // MP_TREES
415  9, // MP_STATION
416  2, // MP_WATER
417  1, // MP_VOID
418  6, // MP_INDUSTRY
419  8, // MP_TUNNELBRIDGE
420  2, // MP_OBJECT
421  0,
422 };
423 
424 
431 static inline uint32_t GetSmallMapContoursPixels(TileIndex tile, TileType t)
432 {
434  return ApplyMask(cs->height_colours[TileHeight(tile)], &_smallmap_contours_andor[t]);
435 }
436 
444 static inline uint32_t GetSmallMapVehiclesPixels(TileIndex, TileType t)
445 {
447  return ApplyMask(cs->default_colour, &_smallmap_vehicles_andor[t]);
448 }
449 
457 static inline uint32_t GetSmallMapIndustriesPixels(TileIndex tile, TileType t)
458 {
461 }
462 
470 static inline uint32_t GetSmallMapRoutesPixels(TileIndex tile, TileType t)
471 {
472  switch (t) {
473  case MP_STATION:
474  switch (GetStationType(tile)) {
475  case STATION_RAIL: return MKCOLOUR_XXXX(PC_VERY_DARK_BROWN);
476  case STATION_AIRPORT: return MKCOLOUR_XXXX(PC_RED);
477  case STATION_TRUCK: return MKCOLOUR_XXXX(PC_ORANGE);
478  case STATION_BUS: return MKCOLOUR_XXXX(PC_YELLOW);
479  case STATION_DOCK: return MKCOLOUR_XXXX(PC_LIGHT_BLUE);
480  default: return MKCOLOUR_FFFF;
481  }
482 
483  case MP_RAILWAY: {
484  AndOr andor = {
485  MKCOLOUR_0XX0(GetRailTypeInfo(GetRailType(tile))->map_colour),
487  };
488 
490  return ApplyMask(cs->default_colour, &andor);
491  }
492 
493  case MP_ROAD: {
494  const RoadTypeInfo *rti = nullptr;
495  if (GetRoadTypeRoad(tile) != INVALID_ROADTYPE) {
496  rti = GetRoadTypeInfo(GetRoadTypeRoad(tile));
497  } else {
498  rti = GetRoadTypeInfo(GetRoadTypeTram(tile));
499  }
500  if (rti != nullptr) {
501  AndOr andor = {
502  MKCOLOUR_0XX0(rti->map_colour),
504  };
505 
507  return ApplyMask(cs->default_colour, &andor);
508  }
509  [[fallthrough]];
510  }
511 
512  default:
513  /* Ground colour */
515  return ApplyMask(cs->default_colour, &_smallmap_contours_andor[t]);
516  }
517 }
518 
526 static inline uint32_t GetSmallMapLinkStatsPixels(TileIndex tile, TileType t)
527 {
529 }
530 
531 static const uint32_t _vegetation_clear_bits[] = {
532  MKCOLOUR_XXXX(PC_GRASS_LAND),
533  MKCOLOUR_XXXX(PC_ROUGH_LAND),
534  MKCOLOUR_XXXX(PC_GREY),
535  MKCOLOUR_XXXX(PC_FIELDS),
536  MKCOLOUR_XXXX(PC_LIGHT_BLUE),
537  MKCOLOUR_XXXX(PC_ORANGE),
538  MKCOLOUR_XXXX(PC_GRASS_LAND),
539  MKCOLOUR_XXXX(PC_GRASS_LAND),
540 };
541 
549 static inline uint32_t GetSmallMapVegetationPixels(TileIndex tile, TileType t)
550 {
551  switch (t) {
552  case MP_CLEAR:
553  if (IsClearGround(tile, CLEAR_GRASS)) {
554  if (GetClearDensity(tile) < 3) return MKCOLOUR_XXXX(PC_BARE_LAND);
555  if (GetTropicZone(tile) == TROPICZONE_RAINFOREST) return MKCOLOUR_XXXX(PC_RAINFOREST);
556  }
557  return _vegetation_clear_bits[GetClearGround(tile)];
558 
559  case MP_INDUSTRY:
560  return IsTileForestIndustry(tile) ? MKCOLOUR_XXXX(PC_GREEN) : MKCOLOUR_XXXX(PC_DARK_RED);
561 
562  case MP_TREES:
564  return (_settings_game.game_creation.landscape == LT_ARCTIC) ? MKCOLOUR_XYYX(PC_LIGHT_BLUE, PC_TREES) : MKCOLOUR_XYYX(PC_ORANGE, PC_TREES);
565  }
566  return (GetTropicZone(tile) == TROPICZONE_RAINFOREST) ? MKCOLOUR_XYYX(PC_RAINFOREST, PC_TREES) : MKCOLOUR_XYYX(PC_GRASS_LAND, PC_TREES);
567 
568  default:
569  return ApplyMask(MKCOLOUR_XXXX(PC_GRASS_LAND), &_smallmap_vehicles_andor[t]);
570  }
571 }
572 
582 uint32_t GetSmallMapOwnerPixels(TileIndex tile, TileType t, IncludeHeightmap include_heightmap)
583 {
584  Owner o;
585 
586  switch (t) {
587  case MP_VOID: return MKCOLOUR_XXXX(PC_BLACK);
588  case MP_INDUSTRY: return MKCOLOUR_XXXX(PC_DARK_GREY);
589  case MP_HOUSE: return MKCOLOUR_XXXX(PC_DARK_RED);
590  default: o = GetTileOwner(tile); break;
591  /* FIXME: For MP_ROAD there are multiple owners.
592  * GetTileOwner returns the rail owner (level crossing) resp. the owner of ROADTYPE_ROAD (normal road),
593  * even if there are no ROADTYPE_ROAD bits on the tile.
594  */
595  }
596 
597  if ((o < MAX_COMPANIES && !_legend_land_owners[_company_to_list_pos[o]].show_on_map) || o == OWNER_NONE || o == OWNER_WATER) {
598  if (t == MP_WATER) return MKCOLOUR_XXXX(PC_WATER);
600  return ((include_heightmap == IncludeHeightmap::IfEnabled && _smallmap_show_heightmap) || include_heightmap == IncludeHeightmap::Always)
601  ? cs->height_colours[TileHeight(tile)] : cs->default_colour;
602  } else if (o == OWNER_TOWN) {
603  return MKCOLOUR_XXXX(PC_DARK_RED);
604  }
605 
606  return MKCOLOUR_XXXX(_legend_land_owners[_company_to_list_pos[o]].colour);
607 }
608 
610 static const byte _vehicle_type_colours[6] = {
612 };
613 
615 enum SmallMapType : byte {
616  SMT_CONTOUR,
617  SMT_VEHICLES,
618  SMT_INDUSTRY,
619  SMT_LINKSTATS,
620  SMT_ROUTES,
621  SMT_VEGETATION,
622  SMT_OWNER,
623 };
625 
626 
627 class SmallMapWindow : public Window {
628 protected:
634  };
635 
637  static bool show_towns;
638  static int map_height_limit;
639 
640  static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS = 2;
641 
646 
647  int32_t scroll_x;
648  int32_t scroll_y;
649  int32_t subscroll;
650  int zoom;
651 
652  std::unique_ptr<LinkGraphOverlay> overlay;
653 
656  {
658  }
659 
660  static inline Point SmallmapRemapCoords(int x, int y)
661  {
662  Point pt;
663  pt.x = (y - x) * 2;
664  pt.y = y + x;
665  return pt;
666  }
667 
674  static inline void DrawVertMapIndicator(int x, int y, int y2)
675  {
676  GfxFillRect(x, y, x, y + 3, PC_VERY_LIGHT_YELLOW);
677  GfxFillRect(x, y2 - 3, x, y2, PC_VERY_LIGHT_YELLOW);
678  }
679 
686  static inline void DrawHorizMapIndicator(int x, int x2, int y)
687  {
688  GfxFillRect(x, y, x + 3, y, PC_VERY_LIGHT_YELLOW);
689  GfxFillRect(x2 - 3, y, x2, y, PC_VERY_LIGHT_YELLOW);
690  }
691 
696  inline uint GetMinLegendWidth() const
697  {
698  return WidgetDimensions::scaled.framerect.left + this->min_number_of_columns * this->column_width;
699  }
700 
705  inline uint GetNumberColumnsLegend(uint width) const
706  {
707  return width / this->column_width;
708  }
709 
715  inline uint GetLegendHeight(uint num_columns) const
716  {
718  this->GetNumberRowsLegend(num_columns) * GetCharacterHeight(FS_SMALL);
719  }
720 
726  inline CompanyMask GetOverlayCompanyMask() const
727  {
728  return Company::IsValidID(_local_company) ? 1U << _local_company : MAX_UVALUE(CompanyMask);
729  }
730 
732  IntervalTimer<TimerWindow> blink_interval = {std::chrono::milliseconds(450), [this](auto) {
733  Blink();
734  }};
735 
737  IntervalTimer<TimerWindow> refresh_interval = {std::chrono::milliseconds(930), [this](auto) {
738  ForceRefresh();
739  }};
740 
745  {
746  /* Rebuild colour indices if necessary. */
748 
749  for (uint n = 0; n < lengthof(_heightmap_schemes); n++) {
750  /* The heights go from 0 up to and including maximum. */
751  int heights = _settings_game.construction.map_height_limit + 1;
752  _heightmap_schemes[n].height_colours = ReallocT<uint32_t>(_heightmap_schemes[n].height_colours, heights);
753 
754  for (int z = 0; z < heights; z++) {
755  size_t access_index = (_heightmap_schemes[n].colour_count * z) / heights;
756 
757  /* Choose colour by mapping the range (0..max heightlevel) on the complete colour table. */
759  }
760  }
761 
763  BuildLandLegend();
764  }
765 
774  uint GetNumberRowsLegend(uint columns) const
775  {
776  /* Reserve one column for link colours */
777  uint num_rows_linkstats = CeilDiv(_smallmap_cargo_count, columns - 1);
778  uint num_rows_others = CeilDiv(std::max(_smallmap_industry_count, _smallmap_company_count), columns);
779  return std::max({this->min_number_of_fixed_rows, num_rows_linkstats, num_rows_others});
780  }
781 
793  void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item = 0)
794  {
795  if (_ctrl_pressed) {
796  /* Disable all, except the clicked one */
797  bool changes = false;
798  for (int i = begin_legend_item; i != end_legend_item; i++) {
799  bool new_state = (i == click_pos);
800  if (legend[i].show_on_map != new_state) {
801  changes = true;
802  legend[i].show_on_map = new_state;
803  }
804  }
805  if (!changes) {
806  /* Nothing changed? Then show all (again). */
807  for (int i = begin_legend_item; i != end_legend_item; i++) {
808  legend[i].show_on_map = true;
809  }
810  }
811  } else {
812  legend[click_pos].show_on_map = !legend[click_pos].show_on_map;
813  }
814 
815  if (this->map_type == SMT_INDUSTRY) this->BreakIndustryChainLink();
816  }
817 
823  {
824  this->RaiseWidget(WID_SM_CONTOUR + this->map_type);
825  this->map_type = map_type;
826  this->LowerWidget(WID_SM_CONTOUR + this->map_type);
827 
828  this->SetupWidgetData();
829 
830  if (map_type == SMT_LINKSTATS) this->overlay->SetDirty();
831  if (map_type != SMT_INDUSTRY) this->BreakIndustryChainLink();
832  this->SetDirty();
833  }
834 
842  void SetNewScroll(int sx, int sy, int sub)
843  {
844  const NWidgetBase *wi = this->GetWidget<NWidgetBase>(WID_SM_MAP);
845  Point hv = InverseRemapCoords(wi->current_x * ZOOM_LVL_BASE * TILE_SIZE / 2, wi->current_y * ZOOM_LVL_BASE * TILE_SIZE / 2);
846  hv.x *= this->zoom;
847  hv.y *= this->zoom;
848 
849  if (sx < -hv.x) {
850  sx = -hv.x;
851  sub = 0;
852  }
853  if (sx > (int)(Map::MaxX() * TILE_SIZE) - hv.x) {
854  sx = Map::MaxX() * TILE_SIZE - hv.x;
855  sub = 0;
856  }
857  if (sy < -hv.y) {
858  sy = -hv.y;
859  sub = 0;
860  }
861  if (sy > (int)(Map::MaxY() * TILE_SIZE) - hv.y) {
862  sy = Map::MaxY() * TILE_SIZE - hv.y;
863  sub = 0;
864  }
865 
866  this->scroll_x = sx;
867  this->scroll_y = sy;
868  this->subscroll = sub;
869  if (this->map_type == SMT_LINKSTATS) this->overlay->SetDirty();
870  }
871 
875  void DrawMapIndicators() const
876  {
877  /* Find main viewport. */
878  const Viewport *vp = GetMainWindow()->viewport;
879 
880  Point upper_left_smallmap_coord = InverseRemapCoords2(vp->virtual_left, vp->virtual_top);
881  Point lower_right_smallmap_coord = InverseRemapCoords2(vp->virtual_left + vp->virtual_width - 1, vp->virtual_top + vp->virtual_height - 1);
882 
883  Point upper_left = this->RemapTile(upper_left_smallmap_coord.x / (int)TILE_SIZE, upper_left_smallmap_coord.y / (int)TILE_SIZE);
884  upper_left.x -= this->subscroll;
885 
886  Point lower_right = this->RemapTile(lower_right_smallmap_coord.x / (int)TILE_SIZE, lower_right_smallmap_coord.y / (int)TILE_SIZE);
887  lower_right.x -= this->subscroll;
888 
889  SmallMapWindow::DrawVertMapIndicator(upper_left.x, upper_left.y, lower_right.y);
890  SmallMapWindow::DrawVertMapIndicator(lower_right.x, upper_left.y, lower_right.y);
891 
892  SmallMapWindow::DrawHorizMapIndicator(upper_left.x, lower_right.x, upper_left.y);
893  SmallMapWindow::DrawHorizMapIndicator(upper_left.x, lower_right.x, lower_right.y);
894  }
895 
909  void DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos, Blitter *blitter) const
910  {
911  void *dst_ptr_abs_end = blitter->MoveTo(_screen.dst_ptr, 0, _screen.height);
912  uint min_xy = _settings_game.construction.freeform_edges ? 1 : 0;
913 
914  do {
915  /* Check if the tile (xc,yc) is within the map range */
916  if (xc >= Map::MaxX() || yc >= Map::MaxY()) continue;
917 
918  /* Check if the dst pointer points to a pixel inside the screen buffer */
919  if (dst < _screen.dst_ptr) continue;
920  if (dst >= dst_ptr_abs_end) continue;
921 
922  /* Construct tilearea covered by (xc, yc, xc + this->zoom, yc + this->zoom) such that it is within min_xy limits. */
923  TileArea ta;
924  if (min_xy == 1 && (xc == 0 || yc == 0)) {
925  if (this->zoom == 1) continue; // The tile area is empty, don't draw anything.
926 
927  ta = TileArea(TileXY(std::max(min_xy, xc), std::max(min_xy, yc)), this->zoom - (xc == 0), this->zoom - (yc == 0));
928  } else {
929  ta = TileArea(TileXY(xc, yc), this->zoom, this->zoom);
930  }
931  ta.ClampToMap(); // Clamp to map boundaries (may contain MP_VOID tiles!).
932 
933  uint32_t val = this->GetTileColours(ta);
934  uint8_t *val8 = (uint8_t *)&val;
935  int idx = std::max(0, -start_pos);
936  for (int pos = std::max(0, start_pos); pos < end_pos; pos++) {
937  blitter->SetPixel(dst, idx, 0, val8[idx]);
938  idx++;
939  }
940  /* Switch to next tile in the column */
941  } while (xc += this->zoom, yc += this->zoom, dst = blitter->MoveTo(dst, pitch, 0), --reps != 0);
942  }
943 
949  void DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const
950  {
951  for (const Vehicle *v : Vehicle::Iterate()) {
952  if (v->type == VEH_EFFECT) continue;
953  if (v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) continue;
954 
955  /* Remap into flat coordinates. */
956  Point pt = this->RemapTile(v->x_pos / (int)TILE_SIZE, v->y_pos / (int)TILE_SIZE);
957 
958  int y = pt.y - dpi->top;
959  if (!IsInsideMM(y, 0, dpi->height)) continue; // y is out of bounds.
960 
961  bool skip = false; // Default is to draw both pixels.
962  int x = pt.x - this->subscroll - 3 - dpi->left; // Offset X coordinate.
963  if (x < 0) {
964  /* if x+1 is 0, that means we're on the very left edge,
965  * and should thus only draw a single pixel */
966  if (++x != 0) continue;
967  skip = true;
968  } else if (x >= dpi->width - 1) {
969  /* Check if we're at the very right edge, and if so draw only a single pixel */
970  if (x != dpi->width - 1) continue;
971  skip = true;
972  }
973 
974  /* Calculate pointer to pixel and the colour */
975  byte colour = (this->map_type == SMT_VEHICLES) ? _vehicle_type_colours[v->type] : PC_WHITE;
976 
977  /* And draw either one or two pixels depending on clipping */
978  blitter->SetPixel(dpi->dst_ptr, x, y, colour);
979  if (!skip) blitter->SetPixel(dpi->dst_ptr, x + 1, y, colour);
980  }
981  }
982 
987  void DrawTowns(const DrawPixelInfo *dpi) const
988  {
989  for (const Town *t : Town::Iterate()) {
990  /* Remap the town coordinate */
991  Point pt = this->RemapTile(TileX(t->xy), TileY(t->xy));
992  int x = pt.x - this->subscroll - (t->cache.sign.width_small >> 1);
993  int y = pt.y;
994 
995  /* Check if the town sign is within bounds */
996  if (x + t->cache.sign.width_small > dpi->left &&
997  x < dpi->left + dpi->width &&
998  y + GetCharacterHeight(FS_SMALL) > dpi->top &&
999  y < dpi->top + dpi->height) {
1000  /* And draw it. */
1001  SetDParam(0, t->index);
1002  DrawString(x, x + t->cache.sign.width_small, y, STR_SMALLMAP_TOWN);
1003  }
1004  }
1005  }
1006 
1018  void DrawSmallMap(DrawPixelInfo *dpi) const
1019  {
1021  AutoRestoreBackup dpi_backup(_cur_dpi, dpi);
1022 
1023  /* Clear it */
1024  GfxFillRect(dpi->left, dpi->top, dpi->left + dpi->width - 1, dpi->top + dpi->height - 1, PC_BLACK);
1025 
1026  /* Which tile is displayed at (dpi->left, dpi->top)? */
1027  int dx;
1028  Point tile = this->PixelToTile(dpi->left, dpi->top, &dx);
1029  int tile_x = this->scroll_x / (int)TILE_SIZE + tile.x;
1030  int tile_y = this->scroll_y / (int)TILE_SIZE + tile.y;
1031 
1032  void *ptr = blitter->MoveTo(dpi->dst_ptr, -dx - 4, 0);
1033  int x = - dx - 4;
1034  int y = 0;
1035 
1036  for (;;) {
1037  /* Distance from left edge */
1038  if (x >= -3) {
1039  if (x >= dpi->width) break; // Exit the loop.
1040 
1041  int end_pos = std::min(dpi->width, x + 4);
1042  int reps = (dpi->height - y + 1) / 2; // Number of lines.
1043  if (reps > 0) {
1044  this->DrawSmallMapColumn(ptr, tile_x, tile_y, dpi->pitch * 2, reps, x, end_pos, blitter);
1045  }
1046  }
1047 
1048  if (y == 0) {
1049  tile_y += this->zoom;
1050  y++;
1051  ptr = blitter->MoveTo(ptr, 0, 1);
1052  } else {
1053  tile_x -= this->zoom;
1054  y--;
1055  ptr = blitter->MoveTo(ptr, 0, -1);
1056  }
1057  ptr = blitter->MoveTo(ptr, 2, 0);
1058  x += 2;
1059  }
1060 
1061  /* Draw vehicles */
1062  if (this->map_type == SMT_CONTOUR || this->map_type == SMT_VEHICLES) this->DrawVehicles(dpi, blitter);
1063 
1064  /* Draw link stat overlay */
1065  if (this->map_type == SMT_LINKSTATS) this->overlay->Draw(dpi);
1066 
1067  /* Draw town names */
1068  if (this->show_towns) this->DrawTowns(dpi);
1069 
1070  /* Draw map indicators */
1071  this->DrawMapIndicators();
1072  }
1073 
1080  Point RemapTile(int tile_x, int tile_y) const
1081  {
1082  int x_offset = tile_x - this->scroll_x / (int)TILE_SIZE;
1083  int y_offset = tile_y - this->scroll_y / (int)TILE_SIZE;
1084 
1085  if (this->zoom == 1) return SmallmapRemapCoords(x_offset, y_offset);
1086 
1087  /* For negative offsets, round towards -inf. */
1088  if (x_offset < 0) x_offset -= this->zoom - 1;
1089  if (y_offset < 0) y_offset -= this->zoom - 1;
1090 
1091  return SmallmapRemapCoords(x_offset / this->zoom, y_offset / this->zoom);
1092  }
1093 
1104  Point PixelToTile(int px, int py, int *sub, bool add_sub = true) const
1105  {
1106  if (add_sub) px += this->subscroll; // Total horizontal offset.
1107 
1108  /* For each two rows down, add a x and a y tile, and
1109  * For each four pixels to the right, move a tile to the right. */
1110  Point pt = {((py >> 1) - (px >> 2)) * this->zoom, ((py >> 1) + (px >> 2)) * this->zoom};
1111  px &= 3;
1112 
1113  if (py & 1) { // Odd number of rows, handle the 2 pixel shift.
1114  if (px < 2) {
1115  pt.x += this->zoom;
1116  px += 2;
1117  } else {
1118  pt.y += this->zoom;
1119  px -= 2;
1120  }
1121  }
1122 
1123  *sub = px;
1124  return pt;
1125  }
1126 
1136  Point ComputeScroll(int tx, int ty, int x, int y, int *sub) const
1137  {
1138  assert(x >= 0 && y >= 0);
1139 
1140  int new_sub;
1141  Point tile_xy = PixelToTile(x, y, &new_sub, false);
1142  tx -= tile_xy.x;
1143  ty -= tile_xy.y;
1144 
1145  Point scroll;
1146  if (new_sub == 0) {
1147  *sub = 0;
1148  scroll.x = (tx + this->zoom) * TILE_SIZE;
1149  scroll.y = (ty - this->zoom) * TILE_SIZE;
1150  } else {
1151  *sub = 4 - new_sub;
1152  scroll.x = (tx + 2 * this->zoom) * TILE_SIZE;
1153  scroll.y = (ty - 2 * this->zoom) * TILE_SIZE;
1154  }
1155  return scroll;
1156  }
1157 
1164  void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt)
1165  {
1166  static const int zoomlevels[] = {1, 2, 4, 6, 8}; // Available zoom levels. Bigger number means more zoom-out (further away).
1167  static const int MIN_ZOOM_INDEX = 0;
1168  static const int MAX_ZOOM_INDEX = lengthof(zoomlevels) - 1;
1169 
1170  int new_index, cur_index, sub;
1171  Point tile;
1172  switch (change) {
1173  case ZLC_INITIALIZE:
1174  cur_index = - 1; // Definitely different from new_index.
1175  new_index = MIN_ZOOM_INDEX;
1176  tile.x = tile.y = 0;
1177  break;
1178 
1179  case ZLC_ZOOM_IN:
1180  case ZLC_ZOOM_OUT:
1181  for (cur_index = MIN_ZOOM_INDEX; cur_index <= MAX_ZOOM_INDEX; cur_index++) {
1182  if (this->zoom == zoomlevels[cur_index]) break;
1183  }
1184  assert(cur_index <= MAX_ZOOM_INDEX);
1185 
1186  tile = this->PixelToTile(zoom_pt->x, zoom_pt->y, &sub);
1187  new_index = Clamp(cur_index + ((change == ZLC_ZOOM_IN) ? -1 : 1), MIN_ZOOM_INDEX, MAX_ZOOM_INDEX);
1188  break;
1189 
1190  default: NOT_REACHED();
1191  }
1192 
1193  if (new_index != cur_index) {
1194  this->zoom = zoomlevels[new_index];
1195  if (cur_index >= 0) {
1196  Point new_tile = this->PixelToTile(zoom_pt->x, zoom_pt->y, &sub);
1197  this->SetNewScroll(this->scroll_x + (tile.x - new_tile.x) * TILE_SIZE,
1198  this->scroll_y + (tile.y - new_tile.y) * TILE_SIZE, sub);
1199  } else if (this->map_type == SMT_LINKSTATS) {
1200  this->overlay->SetDirty();
1201  }
1202  this->SetWidgetDisabledState(WID_SM_ZOOM_IN, this->zoom == zoomlevels[MIN_ZOOM_INDEX]);
1203  this->SetWidgetDisabledState(WID_SM_ZOOM_OUT, this->zoom == zoomlevels[MAX_ZOOM_INDEX]);
1204  this->SetDirty();
1205  }
1206  }
1207 
1212  {
1213  CargoTypes cargo_mask = 0;
1214  for (int i = 0; i != _smallmap_cargo_count; ++i) {
1215  if (_legend_linkstats[i].show_on_map) SetBit(cargo_mask, _legend_linkstats[i].type);
1216  }
1217  this->overlay->SetCargoMask(cargo_mask);
1218  }
1219 
1224  {
1225  StringID legend_tooltip;
1226  StringID enable_all_tooltip;
1227  StringID disable_all_tooltip;
1228  int plane;
1229  switch (this->map_type) {
1230  case SMT_INDUSTRY:
1231  legend_tooltip = STR_SMALLMAP_TOOLTIP_INDUSTRY_SELECTION;
1232  enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_INDUSTRIES;
1233  disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_INDUSTRIES;
1234  plane = 0;
1235  break;
1236 
1237  case SMT_OWNER:
1238  legend_tooltip = STR_SMALLMAP_TOOLTIP_COMPANY_SELECTION;
1239  enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_COMPANIES;
1240  disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_COMPANIES;
1241  plane = 0;
1242  break;
1243 
1244  case SMT_LINKSTATS:
1245  legend_tooltip = STR_SMALLMAP_TOOLTIP_CARGO_SELECTION;
1246  enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_CARGOS;
1247  disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_CARGOS;
1248  plane = 0;
1249  break;
1250 
1251  default:
1252  legend_tooltip = STR_NULL;
1253  enable_all_tooltip = STR_NULL;
1254  disable_all_tooltip = STR_NULL;
1255  plane = 1;
1256  break;
1257  }
1258 
1259  this->GetWidget<NWidgetCore>(WID_SM_LEGEND)->SetDataTip(STR_NULL, legend_tooltip);
1260  this->GetWidget<NWidgetCore>(WID_SM_ENABLE_ALL)->SetDataTip(STR_SMALLMAP_ENABLE_ALL, enable_all_tooltip);
1261  this->GetWidget<NWidgetCore>(WID_SM_DISABLE_ALL)->SetDataTip(STR_SMALLMAP_DISABLE_ALL, disable_all_tooltip);
1262  this->GetWidget<NWidgetStacked>(WID_SM_SELECT_BUTTONS)->SetDisplayedPlane(plane);
1263  }
1264 
1270  uint32_t GetTileColours(const TileArea &ta) const
1271  {
1272  int importance = 0;
1273  TileIndex tile = INVALID_TILE; // Position of the most important tile.
1274  TileType et = MP_VOID; // Effective tile type at that position.
1275 
1276  for (TileIndex ti : ta) {
1277  TileType ttype = GetTileType(ti);
1278 
1279  switch (ttype) {
1280  case MP_TUNNELBRIDGE: {
1282 
1283  switch (tt) {
1284  case TRANSPORT_RAIL: ttype = MP_RAILWAY; break;
1285  case TRANSPORT_ROAD: ttype = MP_ROAD; break;
1286  default: ttype = MP_WATER; break;
1287  }
1288  break;
1289  }
1290 
1291  case MP_INDUSTRY:
1292  /* Special handling of industries while in "Industries" smallmap view. */
1293  if (this->map_type == SMT_INDUSTRY) {
1294  /* If industry is allowed to be seen, use its colour on the map.
1295  * This has the highest priority above any value in _tiletype_importance. */
1296  IndustryType type = Industry::GetByTile(ti)->type;
1297  if (_legend_from_industries[_industry_to_list_pos[type]].show_on_map) {
1298  if (type == _smallmap_industry_highlight) {
1299  if (_smallmap_industry_highlight_state) return MKCOLOUR_XXXX(PC_WHITE);
1300  } else {
1301  return GetIndustrySpec(type)->map_colour * 0x01010101;
1302  }
1303  }
1304  /* Otherwise make it disappear */
1305  ttype = IsTileOnWater(ti) ? MP_WATER : MP_CLEAR;
1306  }
1307  break;
1308 
1309  default:
1310  break;
1311  }
1312 
1313  if (_tiletype_importance[ttype] > importance) {
1314  importance = _tiletype_importance[ttype];
1315  tile = ti;
1316  et = ttype;
1317  }
1318  }
1319 
1320  switch (this->map_type) {
1321  case SMT_CONTOUR:
1322  return GetSmallMapContoursPixels(tile, et);
1323 
1324  case SMT_VEHICLES:
1325  return GetSmallMapVehiclesPixels(tile, et);
1326 
1327  case SMT_INDUSTRY:
1328  return GetSmallMapIndustriesPixels(tile, et);
1329 
1330  case SMT_LINKSTATS:
1331  return GetSmallMapLinkStatsPixels(tile, et);
1332 
1333  case SMT_ROUTES:
1334  return GetSmallMapRoutesPixels(tile, et);
1335 
1336  case SMT_VEGETATION:
1337  return GetSmallMapVegetationPixels(tile, et);
1338 
1339  case SMT_OWNER:
1341 
1342  default: NOT_REACHED();
1343  }
1344  }
1345 
1352  {
1353  const NWidgetBase *wi = this->GetWidget<NWidgetBase>(WID_SM_LEGEND);
1354  uint line = (pt.y - wi->pos_y - WidgetDimensions::scaled.framerect.top) / GetCharacterHeight(FS_SMALL);
1355  uint columns = this->GetNumberColumnsLegend(wi->current_x);
1356  uint number_of_rows = this->GetNumberRowsLegend(columns);
1357  if (line >= number_of_rows) return -1;
1358 
1359  bool rtl = _current_text_dir == TD_RTL;
1360  int x = pt.x - wi->pos_x;
1361  if (rtl) x = wi->current_x - x;
1362  uint column = (x - WidgetDimensions::scaled.framerect.left) / this->column_width;
1363 
1364  return (column * number_of_rows) + line;
1365  }
1366 
1369  {
1370  if (this->map_type == SMT_LINKSTATS) {
1371  CompanyMask company_mask = this->GetOverlayCompanyMask();
1372  if (this->overlay->GetCompanyMask() != company_mask) {
1373  this->overlay->SetCompanyMask(company_mask);
1374  } else {
1375  this->overlay->SetDirty();
1376  }
1377  }
1378  }
1379 
1381  void Blink()
1382  {
1384 
1386 
1387  this->UpdateLinks();
1388  this->SetDirty();
1389  }
1390 
1393  {
1395 
1396  this->UpdateLinks();
1397  this->SetDirty();
1398  }
1399 
1400 public:
1401  friend class NWidgetSmallmapDisplay;
1402 
1403  SmallMapWindow(WindowDesc *desc, int window_number) : Window(desc)
1404  {
1406  this->overlay = std::make_unique<LinkGraphOverlay>(this, WID_SM_MAP, 0, this->GetOverlayCompanyMask(), 1);
1407  this->InitNested(window_number);
1408  this->LowerWidget(WID_SM_CONTOUR + this->map_type);
1409 
1410  this->RebuildColourIndexIfNecessary();
1411 
1412  this->SetWidgetLoweredState(WID_SM_SHOW_HEIGHT, _smallmap_show_heightmap);
1413 
1414  this->SetWidgetLoweredState(WID_SM_TOGGLETOWNNAME, this->show_towns);
1415 
1416  this->SetupWidgetData();
1417 
1418  this->SetZoomLevel(ZLC_INITIALIZE, nullptr);
1419  this->SmallMapCenterOnCurrentPos();
1420  this->SetOverlayCargoMask();
1421  }
1422 
1427  {
1428  const Viewport *vp = GetMainWindow()->viewport;
1429  Point viewport_center = InverseRemapCoords2(vp->virtual_left + vp->virtual_width / 2, vp->virtual_top + vp->virtual_height / 2);
1430 
1431  int sub;
1432  const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
1433  Point sxy = this->ComputeScroll(viewport_center.x / (int)TILE_SIZE, viewport_center.y / (int)TILE_SIZE,
1434  std::max(0, (int)wid->current_x / 2 - 2), wid->current_y / 2, &sub);
1435  this->SetNewScroll(sxy.x, sxy.y, sub);
1436  this->SetDirty();
1437  }
1438 
1444  Point GetStationMiddle(const Station *st) const
1445  {
1446  int x = CenterBounds(st->rect.left, st->rect.right, 0);
1447  int y = CenterBounds(st->rect.top, st->rect.bottom, 0);
1448  Point ret = this->RemapTile(x, y);
1449 
1450  /* Same magic 3 as in DrawVehicles; that's where I got it from.
1451  * No idea what it is, but without it the result looks bad.
1452  */
1453  ret.x -= 3 + this->subscroll;
1454  return ret;
1455  }
1456 
1457  void Close([[maybe_unused]] int data) override
1458  {
1459  this->BreakIndustryChainLink();
1460  this->Window::Close();
1461  }
1462 
1463  void SetStringParameters(WidgetID widget) const override
1464  {
1465  switch (widget) {
1466  case WID_SM_CAPTION:
1467  SetDParam(0, STR_SMALLMAP_TYPE_CONTOURS + this->map_type);
1468  break;
1469  }
1470  }
1471 
1472  void OnInit() override
1473  {
1474  uint min_width = 0;
1475  this->min_number_of_columns = INDUSTRY_MIN_NUMBER_OF_COLUMNS;
1476  this->min_number_of_fixed_rows = lengthof(_linkstat_colours_in_legenda);
1477  for (uint i = 0; i < lengthof(_legend_table); i++) {
1478  uint height = 0;
1479  uint num_columns = 1;
1480  for (const LegendAndColour *tbl = _legend_table[i]; !tbl->end; ++tbl) {
1481  StringID str;
1482  if (i == SMT_INDUSTRY) {
1483  SetDParam(0, tbl->legend);
1485  str = STR_SMALLMAP_INDUSTRY;
1486  } else if (i == SMT_LINKSTATS) {
1487  SetDParam(0, tbl->legend);
1488  str = STR_SMALLMAP_LINKSTATS;
1489  } else if (i == SMT_OWNER) {
1490  if (tbl->company != INVALID_COMPANY) {
1491  if (!Company::IsValidID(tbl->company)) {
1492  /* Rebuild the owner legend. */
1493  BuildOwnerLegend();
1494  this->OnInit();
1495  return;
1496  }
1497  /* Non-fixed legend entries for the owner view. */
1498  SetDParam(0, tbl->company);
1499  str = STR_SMALLMAP_COMPANY;
1500  } else {
1501  str = tbl->legend;
1502  }
1503  } else {
1504  if (tbl->col_break) {
1505  this->min_number_of_fixed_rows = std::max(this->min_number_of_fixed_rows, height);
1506  height = 0;
1507  num_columns++;
1508  }
1509  height++;
1510  str = tbl->legend;
1511  }
1512  min_width = std::max(GetStringBoundingBox(str).width, min_width);
1513  }
1514  this->min_number_of_fixed_rows = std::max(this->min_number_of_fixed_rows, height);
1515  this->min_number_of_columns = std::max(this->min_number_of_columns, num_columns);
1516  }
1517 
1518  /* Width of the legend blob. */
1519  this->legend_width = GetCharacterHeight(FS_SMALL) * 9 / 6;
1520 
1521  /* The width of a column is the minimum width of all texts + the size of the blob + some spacing */
1522  this->column_width = min_width + WidgetDimensions::scaled.hsep_normal + this->legend_width + WidgetDimensions::scaled.framerect.Horizontal();
1523  }
1524 
1525  void OnPaint() override
1526  {
1527  if (this->map_type == SMT_OWNER) {
1528  for (const LegendAndColour *tbl = _legend_table[this->map_type]; !tbl->end; ++tbl) {
1529  if (tbl->company != INVALID_COMPANY && !Company::IsValidID(tbl->company)) {
1530  /* Rebuild the owner legend. */
1531  BuildOwnerLegend();
1532  this->InvalidateData(1);
1533  break;
1534  }
1535  }
1536  }
1537 
1538  this->DrawWidgets();
1539  }
1540 
1541  void DrawWidget(const Rect &r, WidgetID widget) const override
1542  {
1543  switch (widget) {
1544  case WID_SM_MAP: {
1545  Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
1546  DrawPixelInfo new_dpi;
1547  if (!FillDrawPixelInfo(&new_dpi, ir)) return;
1548  this->DrawSmallMap(&new_dpi);
1549  break;
1550  }
1551 
1552  case WID_SM_LEGEND: {
1553  uint columns = this->GetNumberColumnsLegend(r.Width());
1554  uint number_of_rows = this->GetNumberRowsLegend(columns);
1555  bool rtl = _current_text_dir == TD_RTL;
1556  uint i = 0; // Row counter for industry legend.
1557  uint row_height = GetCharacterHeight(FS_SMALL);
1558  int padding = ScaleGUITrad(1);
1559 
1560  Rect origin = r.WithWidth(this->column_width, rtl).Shrink(WidgetDimensions::scaled.framerect).WithHeight(row_height);
1561  Rect text = origin.Indent(this->legend_width + WidgetDimensions::scaled.hsep_normal, rtl);
1562  Rect icon = origin.WithWidth(this->legend_width, rtl).Shrink(0, padding, 0, 0);
1563 
1564  StringID string = STR_NULL;
1565  switch (this->map_type) {
1566  case SMT_INDUSTRY:
1567  string = STR_SMALLMAP_INDUSTRY;
1568  break;
1569  case SMT_LINKSTATS:
1570  string = STR_SMALLMAP_LINKSTATS;
1571  break;
1572  case SMT_OWNER:
1573  string = STR_SMALLMAP_COMPANY;
1574  break;
1575  default:
1576  break;
1577  }
1578 
1579  for (const LegendAndColour *tbl = _legend_table[this->map_type]; !tbl->end; ++tbl) {
1580  if (tbl->col_break || ((this->map_type == SMT_INDUSTRY || this->map_type == SMT_OWNER || this->map_type == SMT_LINKSTATS) && i++ >= number_of_rows)) {
1581  /* Column break needed, continue at top, COLUMN_WIDTH pixels
1582  * (one "row") to the right. */
1583  int x = rtl ? -(int)this->column_width : this->column_width;
1584  int y = origin.top - text.top;
1585  text = text.Translate(x, y);
1586  icon = icon.Translate(x, y);
1587  i = 1;
1588  }
1589 
1590  uint8_t legend_colour = tbl->colour;
1591 
1592  switch (this->map_type) {
1593  case SMT_INDUSTRY:
1594  /* Industry name must be formatted, since it's not in tiny font in the specs.
1595  * So, draw with a parameter and use the STR_SMALLMAP_INDUSTRY string, which is tiny font */
1596  SetDParam(0, tbl->legend);
1598  if (tbl->show_on_map && tbl->type == _smallmap_industry_highlight) {
1600  }
1601  [[fallthrough]];
1602 
1603  case SMT_LINKSTATS:
1604  SetDParam(0, tbl->legend);
1605  [[fallthrough]];
1606 
1607  case SMT_OWNER:
1608  if (this->map_type != SMT_OWNER || tbl->company != INVALID_COMPANY) {
1609  if (this->map_type == SMT_OWNER) SetDParam(0, tbl->company);
1610  if (!tbl->show_on_map) {
1611  /* Simply draw the string, not the black border of the legend colour.
1612  * This will enforce the idea of the disabled item */
1613  DrawString(text, string, TC_GREY);
1614  } else {
1615  DrawString(text, string, TC_BLACK);
1616  GfxFillRect(icon, PC_BLACK); // Outer border of the legend colour
1617  }
1618  break;
1619  }
1620  [[fallthrough]];
1621 
1622  default:
1623  if (this->map_type == SMT_CONTOUR) SetDParam(0, tbl->height * TILE_HEIGHT_STEP);
1624  /* Anything that is not an industry or a company is using normal process */
1625  GfxFillRect(icon, PC_BLACK);
1626  DrawString(text, tbl->legend);
1627  break;
1628  }
1629  GfxFillRect(icon.Shrink(WidgetDimensions::scaled.bevel), legend_colour); // Legend colour
1630 
1631  text = text.Translate(0, row_height);
1632  icon = icon.Translate(0, row_height);
1633  }
1634  }
1635  }
1636  }
1637 
1638  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1639  {
1640  switch (widget) {
1641  case WID_SM_MAP: { // Map window
1642  if (click_count > 0) this->mouse_capture_widget = widget;
1643 
1644  const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
1645  Window *w = GetMainWindow();
1646  int sub;
1647  pt = this->PixelToTile(pt.x - wid->pos_x, pt.y - wid->pos_y, &sub);
1648  ScrollWindowTo(this->scroll_x + pt.x * TILE_SIZE, this->scroll_y + pt.y * TILE_SIZE, -1, w);
1649 
1650  this->SetDirty();
1651  break;
1652  }
1653 
1654  case WID_SM_ZOOM_IN:
1655  case WID_SM_ZOOM_OUT: {
1656  const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
1657  Point zoom_pt = { (int)wid->current_x / 2, (int)wid->current_y / 2};
1658  this->SetZoomLevel((widget == WID_SM_ZOOM_IN) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &zoom_pt);
1659  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1660  break;
1661  }
1662 
1663  case WID_SM_CONTOUR: // Show land contours
1664  case WID_SM_VEHICLES: // Show vehicles
1665  case WID_SM_INDUSTRIES: // Show industries
1666  case WID_SM_LINKSTATS: // Show route map
1667  case WID_SM_ROUTES: // Show transport routes
1668  case WID_SM_VEGETATION: // Show vegetation
1669  case WID_SM_OWNERS: // Show land owners
1670  this->SwitchMapType((SmallMapType)(widget - WID_SM_CONTOUR));
1671  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1672  break;
1673 
1674  case WID_SM_CENTERMAP: // Center the smallmap again
1675  this->SmallMapCenterOnCurrentPos();
1676  this->HandleButtonClick(WID_SM_CENTERMAP);
1677  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1678  break;
1679 
1680  case WID_SM_TOGGLETOWNNAME: // Toggle town names
1681  this->show_towns = !this->show_towns;
1682  this->SetWidgetLoweredState(WID_SM_TOGGLETOWNNAME, this->show_towns);
1683 
1684  this->SetDirty();
1685  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1686  break;
1687 
1688  case WID_SM_LEGEND: // Legend
1689  if (this->map_type == SMT_INDUSTRY || this->map_type == SMT_LINKSTATS || this->map_type == SMT_OWNER) {
1690  int click_pos = this->GetPositionOnLegend(pt);
1691  if (click_pos < 0) break;
1692 
1693  /* If industry type small map*/
1694  if (this->map_type == SMT_INDUSTRY) {
1695  /* If click on industries label, find right industry type and enable/disable it. */
1696  if (click_pos < _smallmap_industry_count) {
1697  this->SelectLegendItem(click_pos, _legend_from_industries, _smallmap_industry_count);
1698  }
1699  } else if (this->map_type == SMT_LINKSTATS) {
1700  if (click_pos < _smallmap_cargo_count) {
1701  this->SelectLegendItem(click_pos, _legend_linkstats, _smallmap_cargo_count);
1702  this->SetOverlayCargoMask();
1703  }
1704  } else if (this->map_type == SMT_OWNER) {
1705  if (click_pos < _smallmap_company_count) {
1706  this->SelectLegendItem(click_pos, _legend_land_owners, _smallmap_company_count, NUM_NO_COMPANY_ENTRIES);
1707  }
1708  }
1709  this->SetDirty();
1710  }
1711  break;
1712 
1713  case WID_SM_ENABLE_ALL:
1714  case WID_SM_DISABLE_ALL: {
1715  LegendAndColour *tbl = nullptr;
1716  switch (this->map_type) {
1717  case SMT_INDUSTRY:
1719  this->BreakIndustryChainLink();
1720  break;
1721  case SMT_OWNER:
1722  tbl = &(_legend_land_owners[NUM_NO_COMPANY_ENTRIES]);
1723  break;
1724  case SMT_LINKSTATS:
1725  tbl = _legend_linkstats;
1726  break;
1727  default:
1728  NOT_REACHED();
1729  }
1730  for (;!tbl->end && tbl->legend != STR_LINKGRAPH_LEGEND_UNUSED; ++tbl) {
1731  tbl->show_on_map = (widget == WID_SM_ENABLE_ALL);
1732  }
1733  if (this->map_type == SMT_LINKSTATS) this->SetOverlayCargoMask();
1734  this->SetDirty();
1735  break;
1736  }
1737 
1738  case WID_SM_SHOW_HEIGHT: // Enable/disable showing of heightmap.
1740  this->SetWidgetLoweredState(WID_SM_SHOW_HEIGHT, _smallmap_show_heightmap);
1741  this->SetDirty();
1742  break;
1743  }
1744  }
1745 
1754  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1755  {
1756  if (!gui_scope) return;
1757 
1758  switch (data) {
1759  case 1:
1760  /* The owner legend has already been rebuilt. */
1761  this->ReInit();
1762  break;
1763 
1764  case 0: {
1765  extern std::bitset<NUM_INDUSTRYTYPES> _displayed_industries;
1766  if (this->map_type != SMT_INDUSTRY) this->SwitchMapType(SMT_INDUSTRY);
1767 
1768  for (int i = 0; i != _smallmap_industry_count; i++) {
1770  }
1771  break;
1772  }
1773 
1774  case 2:
1775  this->RebuildColourIndexIfNecessary();
1776  break;
1777 
1778  default: NOT_REACHED();
1779  }
1780  this->SetDirty();
1781  }
1782 
1783  bool OnRightClick(Point, WidgetID widget) override
1784  {
1785  if (widget != WID_SM_MAP || _scrolling_viewport) return false;
1786 
1787  _scrolling_viewport = true;
1788  return true;
1789  }
1790 
1791  void OnMouseWheel(int wheel) override
1792  {
1794  const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
1795  int cursor_x = _cursor.pos.x - this->left - wid->pos_x;
1796  int cursor_y = _cursor.pos.y - this->top - wid->pos_y;
1797  if (IsInsideMM(cursor_x, 0, wid->current_x) && IsInsideMM(cursor_y, 0, wid->current_y)) {
1798  Point pt = {cursor_x, cursor_y};
1799  this->SetZoomLevel((wheel < 0) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &pt);
1800  }
1801  }
1802  }
1803 
1804  void OnScroll(Point delta) override
1805  {
1807 
1808  /* While tile is at (delta.x, delta.y)? */
1809  int sub;
1810  Point pt = this->PixelToTile(delta.x, delta.y, &sub);
1811  this->SetNewScroll(this->scroll_x + pt.x * TILE_SIZE, this->scroll_y + pt.y * TILE_SIZE, sub);
1812 
1813  this->SetDirty();
1814  }
1815 
1816  void OnMouseOver([[maybe_unused]] Point pt, WidgetID widget) override
1817  {
1818  IndustryType new_highlight = INVALID_INDUSTRYTYPE;
1819  if (widget == WID_SM_LEGEND && this->map_type == SMT_INDUSTRY) {
1820  int industry_pos = GetPositionOnLegend(pt);
1821  if (industry_pos >= 0 && industry_pos < _smallmap_industry_count) {
1822  new_highlight = _legend_from_industries[industry_pos].type;
1823  }
1824  }
1825  if (new_highlight != _smallmap_industry_highlight) {
1826  _smallmap_industry_highlight = new_highlight;
1828  this->SetDirty();
1829  }
1830  }
1831 
1832 };
1833 
1835 bool SmallMapWindow::show_towns = true;
1837 
1848 public:
1850  {
1851  this->smallmap_window = nullptr;
1852  }
1853 
1854  void SetupSmallestSize(Window *w) override
1855  {
1856  assert(this->children.size() == 2);
1857  NWidgetBase *display = this->children.front().get();
1858  NWidgetBase *bar = this->children.back().get();
1859 
1860  display->SetupSmallestSize(w);
1861  bar->SetupSmallestSize(w);
1862 
1863  this->smallmap_window = dynamic_cast<SmallMapWindow *>(w);
1864  assert(this->smallmap_window != nullptr);
1865  this->smallest_x = std::max(display->smallest_x, bar->smallest_x + smallmap_window->GetMinLegendWidth());
1867  this->fill_x = std::max(display->fill_x, bar->fill_x);
1868  this->fill_y = (display->fill_y == 0 && bar->fill_y == 0) ? 0 : std::min(display->fill_y, bar->fill_y);
1869  this->resize_x = std::max(display->resize_x, bar->resize_x);
1870  this->resize_y = std::min(display->resize_y, bar->resize_y);
1871  }
1872 
1873  void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
1874  {
1875  this->pos_x = x;
1876  this->pos_y = y;
1877  this->current_x = given_width;
1878  this->current_y = given_height;
1879 
1880  assert(this->children.size() == 2);
1881  NWidgetBase *display = this->children.front().get();
1882  NWidgetBase *bar = this->children.back().get();
1883 
1884  if (sizing == ST_SMALLEST) {
1885  this->smallest_x = given_width;
1886  this->smallest_y = given_height;
1887  /* Make display and bar exactly equal to their minimal size. */
1888  display->AssignSizePosition(ST_SMALLEST, x, y, display->smallest_x, display->smallest_y, rtl);
1889  bar->AssignSizePosition(ST_SMALLEST, x, y + display->smallest_y, bar->smallest_x, bar->smallest_y, rtl);
1890  }
1891 
1892  uint bar_height = std::max(bar->smallest_y, this->smallmap_window->GetLegendHeight(this->smallmap_window->GetNumberColumnsLegend(given_width - bar->smallest_x)));
1893  uint display_height = given_height - bar_height;
1894  display->AssignSizePosition(ST_RESIZE, x, y, given_width, display_height, rtl);
1895  bar->AssignSizePosition(ST_RESIZE, x, y + display_height, given_width, bar_height, rtl);
1896  }
1897 };
1898 
1901  NWidget(WWT_PANEL, COLOUR_BROWN, WID_SM_MAP_BORDER),
1902  NWidget(WWT_INSET, COLOUR_BROWN, WID_SM_MAP), SetMinimalSize(346, 140), SetResize(1, 1), SetPadding(2, 2, 2, 2), EndContainer(),
1903  EndContainer(),
1904 };
1905 
1907 static constexpr NWidgetPart _nested_smallmap_bar[] = {
1908  NWidget(WWT_PANEL, COLOUR_BROWN),
1910  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SM_LEGEND), SetResize(1, 1),
1912  /* Top button row. */
1914  NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_SM_ZOOM_IN),
1915  SetDataTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN), SetFill(1, 1),
1916  NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_SM_CENTERMAP),
1917  SetDataTip(SPR_IMG_SMALLMAP, STR_SMALLMAP_CENTER), SetFill(1, 1),
1918  NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_BLANK),
1919  SetDataTip(SPR_EMPTY, STR_NULL), SetFill(1, 1),
1920  NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_CONTOUR),
1921  SetDataTip(SPR_IMG_SHOW_COUNTOURS, STR_SMALLMAP_TOOLTIP_SHOW_LAND_CONTOURS_ON_MAP), SetFill(1, 1),
1922  NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_VEHICLES),
1923  SetDataTip(SPR_IMG_SHOW_VEHICLES, STR_SMALLMAP_TOOLTIP_SHOW_VEHICLES_ON_MAP), SetFill(1, 1),
1924  NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_INDUSTRIES),
1925  SetDataTip(SPR_IMG_INDUSTRY, STR_SMALLMAP_TOOLTIP_SHOW_INDUSTRIES_ON_MAP), SetFill(1, 1),
1926  EndContainer(),
1927  /* Bottom button row. */
1929  NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_SM_ZOOM_OUT),
1930  SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT), SetFill(1, 1),
1931  NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_TOGGLETOWNNAME),
1932  SetDataTip(SPR_IMG_TOWN, STR_SMALLMAP_TOOLTIP_TOGGLE_TOWN_NAMES_ON_OFF), SetFill(1, 1),
1933  NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_LINKSTATS),
1934  SetDataTip(SPR_IMG_CARGOFLOW, STR_SMALLMAP_TOOLTIP_SHOW_LINK_STATS_ON_MAP), SetFill(1, 1),
1935  NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_ROUTES),
1936  SetDataTip(SPR_IMG_SHOW_ROUTES, STR_SMALLMAP_TOOLTIP_SHOW_TRANSPORT_ROUTES_ON), SetFill(1, 1),
1937  NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_VEGETATION),
1938  SetDataTip(SPR_IMG_PLANTTREES, STR_SMALLMAP_TOOLTIP_SHOW_VEGETATION_ON_MAP), SetFill(1, 1),
1939  NWidget(WWT_IMGBTN, COLOUR_BROWN, WID_SM_OWNERS),
1940  SetDataTip(SPR_IMG_COMPANY_GENERAL, STR_SMALLMAP_TOOLTIP_SHOW_LAND_OWNERS_ON_MAP), SetFill(1, 1),
1941  EndContainer(),
1942  NWidget(NWID_SPACER), SetResize(0, 1),
1943  EndContainer(),
1944  EndContainer(),
1945  EndContainer(),
1946 };
1947 
1948 static std::unique_ptr<NWidgetBase> SmallMapDisplay()
1949 {
1950  std::unique_ptr<NWidgetBase> map_display = std::make_unique<NWidgetSmallmapDisplay>();
1951 
1952  map_display = MakeNWidgets(std::begin(_nested_smallmap_display), std::end(_nested_smallmap_display), std::move(map_display));
1953  map_display = MakeNWidgets(std::begin(_nested_smallmap_bar), std::end(_nested_smallmap_bar), std::move(map_display));
1954  return map_display;
1955 }
1956 
1957 
1958 static constexpr NWidgetPart _nested_smallmap_widgets[] = {
1960  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1961  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_SM_CAPTION), SetDataTip(STR_SMALLMAP_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1962  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
1963  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
1964  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
1965  EndContainer(),
1966  NWidgetFunction(SmallMapDisplay), // Smallmap display and legend bar + image buttons.
1967  /* Bottom button row and resize box. */
1969  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SM_SELECT_BUTTONS),
1971  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_SM_ENABLE_ALL), SetDataTip(STR_SMALLMAP_ENABLE_ALL, STR_NULL),
1972  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_SM_DISABLE_ALL), SetDataTip(STR_SMALLMAP_DISABLE_ALL, STR_NULL),
1973  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_SM_SHOW_HEIGHT), SetDataTip(STR_SMALLMAP_SHOW_HEIGHT, STR_SMALLMAP_TOOLTIP_SHOW_HEIGHT),
1974  NWidget(WWT_PANEL, COLOUR_BROWN), SetFill(1, 0), SetResize(1, 0),
1975  EndContainer(),
1976  EndContainer(),
1977  NWidget(WWT_PANEL, COLOUR_BROWN), SetFill(1, 0), SetResize(1, 0),
1978  EndContainer(),
1979  EndContainer(),
1980  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
1981  EndContainer(),
1982 };
1983 
1984 static WindowDesc _smallmap_desc(__FILE__, __LINE__,
1985  WDP_AUTO, "smallmap", 484, 314,
1987  0,
1988  std::begin(_nested_smallmap_widgets), std::end(_nested_smallmap_widgets)
1989 );
1990 
1995 {
1996  AllocateWindowDescFront<SmallMapWindow>(&_smallmap_desc, 0);
1997 }
1998 
2007 bool ScrollMainWindowTo(int x, int y, int z, bool instant)
2008 {
2009  bool res = ScrollWindowTo(x, y, z, GetMainWindow(), instant);
2010 
2011  /* If a user scrolls to a tile (via what way what so ever) and already is on
2012  * that tile (e.g.: pressed twice), move the smallmap to that location,
2013  * so you directly see where you are on the smallmap. */
2014 
2015  if (res) return res;
2016 
2017  SmallMapWindow *w = dynamic_cast<SmallMapWindow*>(FindWindowById(WC_SMALLMAP, 0));
2018  if (w != nullptr) w->SmallMapCenterOnCurrentPos();
2019 
2020  return res;
2021 }
2022 
2029 {
2030  return static_cast<const SmallMapWindow *>(w)->GetStationMiddle(st);
2031 }
_sorted_industry_types
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
Definition: industry_gui.cpp:220
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
SmallMapColourScheme::default_colour
uint32_t default_colour
Default colour of the land.
Definition: smallmap_gui.cpp:279
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
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1141
NWidgetContainer::children
std::vector< std::unique_ptr< NWidgetBase > > children
Child widgets in contaier.
Definition: widget_type.h:462
BuildOwnerLegend
void BuildOwnerLegend()
Completes the array for the owned property legend.
Definition: smallmap_gui.cpp:343
WID_SM_OWNERS
@ WID_SM_OWNERS
Button to select the owners view.
Definition: smallmap_widget.h:28
LegendAndColour::type
IndustryType type
Type of industry. Only valid for industry entries.
Definition: smallmap_gui.cpp:48
GetSmallMapVehiclesPixels
static uint32_t GetSmallMapVehiclesPixels(TileIndex, TileType t)
Return the colour a tile would be displayed with in the small map in mode "Vehicles".
Definition: smallmap_gui.cpp:444
RoadTypeInfo
Definition: road.h:78
sound_func.h
factory.hpp
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
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.cpp:643
IsClearGround
bool IsClearGround(Tile t, ClearGround ct)
Set the type of clear tile.
Definition: clear_map.h:71
IndustrySpec::map_colour
byte map_colour
colour used for the small map
Definition: industrytype.h:124
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
_smallmap_show_heightmap
static bool _smallmap_show_heightmap
Show heightmap in industry and owner mode of smallmap window.
Definition: smallmap_gui.cpp:175
WC_INDUSTRY_CARGOES
@ WC_INDUSTRY_CARGOES
Industry cargoes chain; Window numbers:
Definition: window_type.h:516
PC_VERY_DARK_BROWN
static const uint8_t PC_VERY_DARK_BROWN
Almost-black brown palette colour.
Definition: palette_func.h:64
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:2463
SmallMapWindow::BreakIndustryChainLink
static void BreakIndustryChainLink()
Notify the industry chain window to stop sending newly selected industries.
Definition: smallmap_gui.cpp:655
NWidgetBase::AssignSizePosition
virtual void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)=0
IsInsideMM
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:268
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
endian_func.hpp
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
GetTreeGround
TreeGround GetTreeGround(Tile t)
Returns the groundtype for tree tiles.
Definition: tree_map.h:88
PC_RAINFOREST
static const uint8_t PC_RAINFOREST
Pale green palette colour for rainforest.
Definition: palette_func.h:81
GetRailTypeInfo
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:307
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
smallmap_gui.h
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:356
Map::MaxX
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:297
_sorted_cargo_specs
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:161
MOEND
#define MOEND()
Macro used for forcing a rebuild of the owner legend the first time it is used.
Definition: smallmap_gui.cpp:71
company_base.h
SmallMapWindow::ZLC_ZOOM_IN
@ ZLC_ZOOM_IN
Zoom in.
Definition: smallmap_gui.cpp:633
tunnelbridge_map.h
SmallMapWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: smallmap_gui.cpp:1525
Blitter
How all blitters should look like.
Definition: base.hpp:29
_smallmap_cargo_count
static int _smallmap_cargo_count
Number of cargos in the link stats legend.
Definition: smallmap_gui.cpp:42
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
Station
Station data structure.
Definition: station_base.h:442
SmallMapWindow::SmallMapCenterOnCurrentPos
void SmallMapCenterOnCurrentPos()
Center the small map on the current center of the viewport.
Definition: smallmap_gui.cpp:1426
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
SmallMapColourScheme::height_colours
uint32_t * height_colours
Cached colours for each level in a map.
Definition: smallmap_gui.cpp:276
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition: widget_type.h:54
PC_WHITE
static const uint8_t PC_WHITE
White palette colour.
Definition: palette_func.h:58
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:312
SmallMapWindow::DrawHorizMapIndicator
static void DrawHorizMapIndicator(int x, int x2, int y)
Draws horizontal part of map indicator.
Definition: smallmap_gui.cpp:686
LegendAndColour::company
CompanyID company
Company to display. Only valid for company entries of the owner legend.
Definition: smallmap_gui.cpp:50
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
MS
#define MS(a, b)
Macro for break marker in arrays of LegendAndColour.
Definition: smallmap_gui.cpp:80
IntervalTimer< TimerWindow >
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
SmallMapWindow::scroll_x
int32_t scroll_x
Horizontal world coordinate of the base tile left of the top-left corner of the smallmap display.
Definition: smallmap_gui.cpp:647
TROPICZONE_RAINFOREST
@ TROPICZONE_RAINFOREST
Rainforest tile.
Definition: tile_type.h:79
Blitter::SetPixel
virtual void SetPixel(void *video, int x, int y, uint8_t colour)=0
Draw a pixel with a given colour on the video-buffer.
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1048
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1099
SmallMapWindow::subscroll
int32_t 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.cpp:649
GUISettings::smallmap_land_colour
uint8_t smallmap_land_colour
colour used for land and heightmap at the smallmap
Definition: settings_type.h:143
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
CLEAR_GRASS
@ CLEAR_GRASS
0-3
Definition: clear_map.h:20
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
SmallMapWindow::SetupWidgetData
void SetupWidgetData()
Function to set up widgets depending on the information being shown on the smallmap.
Definition: smallmap_gui.cpp:1223
SmallMapWindow::GetOverlayCompanyMask
CompanyMask GetOverlayCompanyMask() const
Get a bitmask for company links to be displayed.
Definition: smallmap_gui.cpp:726
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
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
zoom_func.h
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
CeilDiv
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:320
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:71
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:122
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:50
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:56
town.h
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:69
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
_smallmap_industry_count
static int _smallmap_industry_count
Number of used industries.
Definition: smallmap_gui.cpp:40
SmallMapWindow::zoom
int zoom
Zoom level. Bigger number means more zoom-out (further away).
Definition: smallmap_gui.cpp:650
MAX_TILE_HEIGHT
static const uint MAX_TILE_HEIGHT
Maximum allowed tile height.
Definition: tile_type.h:24
clear_map.h
NWidgetFunction
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1279
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
GetRailType
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
SmallMapWindow::scroll_y
int32_t scroll_y
Vertical world coordinate of the base tile left of the top-left corner of the smallmap display.
Definition: smallmap_gui.cpp:648
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:822
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:231
NWidgetSmallmapDisplay
Custom container class for displaying smallmap with a vertically resizing legend panel.
Definition: smallmap_gui.cpp:1846
SmallMapWindow::UpdateLinks
void UpdateLinks()
Update all the links on the map.
Definition: smallmap_gui.cpp:1368
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:50
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:211
SmallMapWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: smallmap_gui.cpp:1472
SmallMapWindow::column_width
uint column_width
Width of a column in the WID_SM_LEGEND widget.
Definition: smallmap_gui.cpp:644
SmallMapWindow::min_number_of_columns
uint min_number_of_columns
Minimal number of columns in legends.
Definition: smallmap_gui.cpp:642
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:30
WID_SM_ENABLE_ALL
@ WID_SM_ENABLE_ALL
Button to enable display of all legend entries.
Definition: smallmap_widget.h:32
SmallMapWindow
Class managing the smallmap window.
Definition: smallmap_gui.cpp:627
PC_FIELDS
static const uint8_t PC_FIELDS
Light brown palette colour for fields.
Definition: palette_func.h:82
SmallMapWindow::show_towns
static bool show_towns
Display town names in the smallmap.
Definition: smallmap_gui.cpp:637
WID_SM_VEGETATION
@ WID_SM_VEGETATION
Button to select the vegetation view.
Definition: smallmap_widget.h:27
IncludeHeightmap::IfEnabled
@ IfEnabled
Only include the heightmap if its enabled in the gui by the player.
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: palette.cpp:26
_linkstat_colours_in_legenda
static uint8_t _linkstat_colours_in_legenda[]
Link stat colours shown in legenda.
Definition: smallmap_gui.cpp:57
WID_SM_CENTERMAP
@ WID_SM_CENTERMAP
Button to move smallmap center to main window center.
Definition: smallmap_widget.h:29
WID_SM_ZOOM_OUT
@ WID_SM_ZOOM_OUT
Button to zoom out one step.
Definition: smallmap_widget.h:21
SmallMapWindow::GetNumberColumnsLegend
uint GetNumberColumnsLegend(uint width) const
Return number of columns that can be displayed in width pixels.
Definition: smallmap_gui.cpp:705
SmallMapWindow::DrawSmallMap
void DrawSmallMap(DrawPixelInfo *dpi) const
Draws the small map.
Definition: smallmap_gui.cpp:1018
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:619
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:1444
SmallMapWindow::SetZoomLevel
void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt)
Initialize or change the zoom level.
Definition: smallmap_gui.cpp:1164
GetTileType
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
WID_SM_CONTOUR
@ WID_SM_CONTOUR
Button to select the contour view (height map).
Definition: smallmap_widget.h:22
_smallmap_industry_highlight_state
static bool _smallmap_industry_highlight_state
State of highlight blinking.
Definition: smallmap_gui.cpp:179
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:63
Pool::MAX_SIZE
static constexpr size_t MAX_SIZE
Make template parameter accessible from outside.
Definition: pool_type.hpp:84
ScaleGUITrad
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:117
WID_SM_ROUTES
@ WID_SM_ROUTES
Button to select the routes view.
Definition: smallmap_widget.h:26
_dark_green_map_heights
static const uint32_t _dark_green_map_heights[]
Height map colours for the dark green colour scheme, ordered by height.
Definition: heightmap_colours.h:132
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:508
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1188
SmallMapWindow::GetMinLegendWidth
uint GetMinLegendWidth() const
Compute minimal required width of the legends.
Definition: smallmap_gui.cpp:696
VS_HIDDEN
@ VS_HIDDEN
Vehicle is not visible.
Definition: vehicle_base.h:33
CargoSpec::Index
CargoID Index() const
Determines index of this cargospec.
Definition: cargotype.h:105
PC_GREEN
static const uint8_t PC_GREEN
Green palette colour.
Definition: palette_func.h:72
Viewport
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
SmallMapWindow::ZoomLevelChange
ZoomLevelChange
Available kinds of zoomlevel changes.
Definition: smallmap_gui.cpp:630
SmallMapWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: smallmap_gui.cpp:1754
SmallMapWindow::GetNumberRowsLegend
uint GetNumberRowsLegend(uint columns) const
Get the number of rows in the legend from the number of columns.
Definition: smallmap_gui.cpp:774
smallmap_widget.h
SmallMapWindow::ZLC_ZOOM_OUT
@ ZLC_ZOOM_OUT
Zoom out.
Definition: smallmap_gui.cpp:632
ST_SMALLEST
@ ST_SMALLEST
Initialize nested widget tree to smallest size. Also updates current_x and current_y.
Definition: widget_type.h:118
SmallMapWindow::DrawVehicles
void DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const
Adds vehicles to the smallmap.
Definition: smallmap_gui.cpp:949
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:639
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:174
WID_SM_BLANK
@ WID_SM_BLANK
Empty button as placeholder.
Definition: smallmap_widget.h:19
Industry::GetByTile
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:207
_vehicle_type_colours
static const byte _vehicle_type_colours[6]
Vehicle colours in #SMT_VEHICLES mode.
Definition: smallmap_gui.cpp:610
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:222
SmallMapWindow::DrawVertMapIndicator
static void DrawVertMapIndicator(int x, int y, int y2)
Draws vertical part of map indicator.
Definition: smallmap_gui.cpp:674
Viewport::virtual_left
int virtual_left
Virtual left coordinate.
Definition: viewport_type.h:28
Industry::type
IndustryType type
type of industry.
Definition: industry.h:104
BaseStation::rect
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Definition: base_station_base.h:90
LegendAndColour::col_break
bool col_break
Perform a column break and go further at the next column.
Definition: smallmap_gui.cpp:53
GetSmallMapVegetationPixels
static uint32_t GetSmallMapVegetationPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the smallmap in mode "Vegetation".
Definition: smallmap_gui.cpp:549
WID_SM_MAP_BORDER
@ WID_SM_MAP_BORDER
Border around the smallmap.
Definition: smallmap_widget.h:16
NWidgetBase::smallest_x
uint smallest_x
Smallest horizontal size of the widget in a filled window.
Definition: widget_type.h:230
ConstructionSettings::map_height_limit
uint8_t map_height_limit
the maximum allowed heightlevel
Definition: settings_type.h:370
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:83
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:204
SmallMapWindow::DrawMapIndicators
void DrawMapIndicators() const
Adds map indicators to the smallmap.
Definition: smallmap_gui.cpp:875
heightmap_colours.h
WID_SM_INDUSTRIES
@ WID_SM_INDUSTRIES
Button to select the industries view.
Definition: smallmap_widget.h:24
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:377
GetSmallMapRoutesPixels
static uint32_t 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:470
SmallMapColourScheme
Colour scheme of the smallmap.
Definition: smallmap_gui.cpp:275
GetClearGround
ClearGround GetClearGround(Tile t)
Get the type of clear tile.
Definition: clear_map.h:59
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:135
_smallmap_company_count
static int _smallmap_company_count
Number of entries in the owner legend.
Definition: smallmap_gui.cpp:41
_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:409
_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:171
_smallmap_industry_highlight
static IndustryType _smallmap_industry_highlight
Highlight a specific industry type.
Definition: smallmap_gui.cpp:177
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
WID_SM_SHOW_HEIGHT
@ WID_SM_SHOW_HEIGHT
Show heightmap toggle button.
Definition: smallmap_widget.h:34
MC
#define MC(col_break)
Macro for a height legend entry with configurable colour.
Definition: smallmap_gui.cpp:65
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
linkgraph_gui.h
BlitterFactory::GetCurrentBlitter
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition: factory.hpp:138
IsTileOnWater
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
Definition: water_map.h:139
SmallMapWindow::GetPositionOnLegend
int GetPositionOnLegend(Point pt)
Determines the mouse position on the legend.
Definition: smallmap_gui.cpp:1351
LegendAndColour::legend
StringID legend
String corresponding to the coloured item.
Definition: smallmap_gui.cpp:47
GUISettings::linkgraph_colours
uint8_t linkgraph_colours
linkgraph overlay colours
Definition: settings_type.h:144
GetSmallMapStationMiddle
Point GetSmallMapStationMiddle(const Window *w, const Station *st)
Determine the middle of a station in the smallmap window.
Definition: smallmap_gui.cpp:2028
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:49
industry.h
safeguards.h
timer.h
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition: settings_type.h:383
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
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:173
_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:56
LegendAndColour::colour
uint8_t colour
Colour of the item on the map.
Definition: smallmap_gui.cpp:46
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition: tile_map.h:178
PC_GRASS_LAND
static const uint8_t PC_GRASS_LAND
Dark green palette colour for grass land.
Definition: palette_func.h:79
_smallmap_vehicles_andor
static const AndOr _smallmap_vehicles_andor[]
Colour masks for "Vehicles", "Industry", and "Vegetation" modes.
Definition: smallmap_gui.cpp:393
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:283
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:123
PC_VERY_LIGHT_YELLOW
static const uint8_t PC_VERY_LIGHT_YELLOW
Almost-white yellow palette colour.
Definition: palette_func.h:70
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:2007
WID_SM_TOGGLETOWNNAME
@ WID_SM_TOGGLETOWNNAME
Toggle button to display town names.
Definition: smallmap_widget.h:30
SmallMapWindow::legend_width
uint legend_width
Width of legend 'blob'.
Definition: smallmap_gui.cpp:645
IncludeHeightmap::Always
@ Always
Always include the heightmap.
CenterBounds
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:166
SmallMapWindow::ForceRefresh
void ForceRefresh()
Force a full refresh of the map.
Definition: smallmap_gui.cpp:1392
GUISettings::scroll_mode
uint8_t scroll_mode
viewport scroll mode
Definition: settings_type.h:145
stdafx.h
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:113
landscape.h
_nested_smallmap_display
static constexpr NWidgetPart _nested_smallmap_display[]
Widget parts of the smallmap display.
Definition: smallmap_gui.cpp:1900
IndustrySpec
Defines the data structure for constructing industry.
Definition: industrytype.h:105
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:909
viewport_func.h
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:234
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
GetStationType
StationType GetStationType(Tile t)
Get the station type of this tile.
Definition: station_map.h:44
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
DECLARE_ENUM_AS_ADDABLE
#define DECLARE_ENUM_AS_ADDABLE(EnumType)
Operator that allows this enumeration to be added to any other enumeration.
Definition: enum_type.hpp:41
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
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:1571
BuildIndustriesLegend
void BuildIndustriesLegend()
Fills an array for the industries legends.
Definition: smallmap_gui.cpp:186
IsTileForestIndustry
bool IsTileForestIndustry(TileIndex tile)
Check whether the tile is a forest.
Definition: industry_cmd.cpp:974
MP_TREES
@ MP_TREES
Tile got trees.
Definition: tile_type.h:52
GetRoadTypeInfo
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:227
MakeNWidgets
std::unique_ptr< NWidgetBase > MakeNWidgets(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, std::unique_ptr< NWidgetBase > &&container)
Construct a nested widget tree from an array of parts.
Definition: widget.cpp:3137
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
MK
#define MK(a, b)
Macro for ordinary entry of LegendAndColour.
Definition: smallmap_gui.cpp:62
IndustrySpec::enabled
bool enabled
entity still available (by default true).newgrf can disable it, though
Definition: industrytype.h:138
MKEND
#define MKEND()
Macro for end of list marker in arrays of LegendAndColour.
Definition: smallmap_gui.cpp:74
PC_YELLOW
static const uint8_t PC_YELLOW
Yellow palette colour.
Definition: palette_func.h:68
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:111
NWidgetBase::fill_y
uint fill_y
Vertical fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:224
NWidgetSmallmapDisplay::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: smallmap_gui.cpp:1873
PC_DARK_RED
static const uint8_t PC_DARK_RED
Dark red palette colour.
Definition: palette_func.h:61
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:384
Map::MaxY
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:306
strings_func.h
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:236
MP_VOID
@ MP_VOID
Invisible tiles at the SW and SE border.
Definition: tile_type.h:55
ST_RESIZE
@ ST_RESIZE
Resize the nested widget tree.
Definition: widget_type.h:119
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...
PC_TREES
static const uint8_t PC_TREES
Green palette colour for trees.
Definition: palette_func.h:83
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:1211
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:842
TileType
TileType
The different types of tiles.
Definition: tile_type.h:47
WID_SM_VEHICLES
@ WID_SM_VEHICLES
Button to select the vehicles view.
Definition: smallmap_widget.h:23
WID_SM_MAP
@ WID_SM_MAP
Panel containing the smallmap.
Definition: smallmap_widget.h:17
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
NWidgetBase::fill_x
uint fill_x
Horizontal fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:223
GetMainWindow
Window * GetMainWindow()
Get the main window, i.e.
Definition: window.cpp:1128
PC_ORANGE
static const uint8_t PC_ORANGE
Orange palette colour.
Definition: palette_func.h:66
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:3217
NWidgetBase::SetupSmallestSize
virtual void SetupSmallestSize(Window *w)=0
tree_map.h
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
WID_SM_DISABLE_ALL
@ WID_SM_DISABLE_ALL
Button to disable display of all legend entries.
Definition: smallmap_widget.h:33
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition: backup_type.hpp:153
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:226
ShowSmallMap
void ShowSmallMap()
Show the smallmap window.
Definition: smallmap_gui.cpp:1994
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.cpp:51
RoadTypeInfo::map_colour
byte map_colour
Colour on mini-map.
Definition: road.h:157
Industry::GetIndustryTypeCount
static uint16_t GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
Definition: industry.h:242
SmallMapWindow::DrawTowns
void DrawTowns(const DrawPixelInfo *dpi) const
Adds town names to the smallmap.
Definition: smallmap_gui.cpp:987
GetTunnelBridgeTransportType
TransportType GetTunnelBridgeTransportType(Tile 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
PC_GREY
static const uint8_t PC_GREY
Grey palette colour.
Definition: palette_func.h:57
MAX_UVALUE
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
Definition: stdafx.h:388
_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:181
PC_WATER
static const uint8_t PC_WATER
Dark blue palette colour for water.
Definition: palette_func.h:84
GUISettings::scrollwheel_scrolling
uint8_t scrollwheel_scrolling
scrolling using the scroll wheel?
Definition: settings_type.h:169
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:88
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition: palette_func.h:55
SmallMapWindow::map_type
static SmallMapType map_type
Currently displayed legends.
Definition: smallmap_gui.cpp:636
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:81
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:53
NWidgetContainer
Baseclass for container widgets.
Definition: widget_type.h:445
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:1080
NWidgetBase::SetDirty
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:903
_violet_map_heights
static const uint32_t _violet_map_heights[]
Height map colours for the violet colour scheme, ordered by height.
Definition: heightmap_colours.h:235
SmallMapWindow::Blink
void Blink()
Blink the industries (if hover over an industry).
Definition: smallmap_gui.cpp:1381
VS_UNCLICKABLE
@ VS_UNCLICKABLE
Vehicle is not clickable by the user (shadow vehicles).
Definition: vehicle_base.h:35
station_map.h
window_func.h
_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:166
SoundSettings::click_beep
bool click_beep
Beep on a random selection of buttons.
Definition: settings_type.h:241
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
Town
Town data structure.
Definition: town.h:50
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1097
TileXY
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:385
SmallMapWindow::GetTileColours
uint32_t GetTileColours(const TileArea &ta) const
Decide which colours to show to the user for a group of tiles.
Definition: smallmap_gui.cpp:1270
_green_map_heights
static const uint32_t _green_map_heights[]
Height map colours for the green colour scheme, ordered by height.
Definition: heightmap_colours.h:13
PC_ROUGH_LAND
static const uint8_t PC_ROUGH_LAND
Dark green palette colour for rough land.
Definition: palette_func.h:78
TileHeight
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
Definition: tile_map.h:29
GetSmallMapIndustriesPixels
static uint32_t 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:457
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:237
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:658
timer_window.h
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:20
NWidgetSmallmapDisplay::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: smallmap_gui.cpp:1854
GetSmallMapLinkStatsPixels
static uint32_t 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:526
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition: window_gui.h:40
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:365
IncludeHeightmap
IncludeHeightmap
Enum for how to include the heightmap pixels/colours in small map related functions.
Definition: smallmap_gui.h:27
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:620
GetIndustrySpec
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Definition: industry_cmd.cpp:123
Window
Data structure for an opened window.
Definition: window_gui.h:267
SizingType
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition()
Definition: widget_type.h:117
WID_SM_LINKSTATS
@ WID_SM_LINKSTATS
Button to select the link stats view.
Definition: smallmap_widget.h:25
IndustrySpec::name
StringID name
Displayed name of the industry.
Definition: industrytype.h:125
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:324
WID_SM_LEGEND
@ WID_SM_LEGEND
Bottom panel to display smallmap legends.
Definition: smallmap_widget.h:18
PC_RED
static const uint8_t PC_RED
Red palette colour.
Definition: palette_func.h:62
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:793
PC_DARK_GREY
static const uint8_t PC_DARK_GREY
Dark grey palette colour.
Definition: palette_func.h:56
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
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:744
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
WID_SM_SELECT_BUTTONS
@ WID_SM_SELECT_BUTTONS
Selection widget for the buttons present in some smallmap modes.
Definition: smallmap_widget.h:31
Viewport::virtual_height
int virtual_height
height << zoom
Definition: viewport_type.h:31
NUM_CARGO
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
Definition: cargo_type.h:68
SmallMapWindow::map_height_limit
static int map_height_limit
Currently used/cached map height limit.
Definition: smallmap_gui.cpp:638
SmallMapWindow::ZLC_INITIALIZE
@ ZLC_INITIALIZE
Initialize zoom level.
Definition: smallmap_gui.cpp:631
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1162
InverseRemapCoords
Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
Definition: landscape.h:112
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:85
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:82
OrthogonalTileArea::ClampToMap
void ClampToMap()
Clamp the tile area to map borders.
Definition: tilearea.cpp:142
SmallMapWindow::ComputeScroll
Point ComputeScroll(int tx, int ty, int x, int y, int *sub) const
Compute base parameters of the smallmap such that tile (tx, ty) starts at pixel (x,...
Definition: smallmap_gui.cpp:1136
MO
#define MO(a, b)
Macro for non-company owned property entry of LegendAndColour.
Definition: smallmap_gui.cpp:68
LegendAndColour
Structure for holding relevant data for legends in small map.
Definition: smallmap_gui.cpp:45
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:117
Company
Definition: company_base.h:116
WID_SM_ZOOM_IN
@ WID_SM_ZOOM_IN
Button to zoom in one step.
Definition: smallmap_widget.h:20
LinkGraphOverlay::LINK_COLOURS
static const uint8_t LINK_COLOURS[][12]
Colours for the various "load" states of links.
Definition: linkgraph_gui.h:47
LegendAndColour::end
bool end
This is the end of the list.
Definition: smallmap_gui.cpp:52
NWidgetBase::resize_x
uint resize_x
Horizontal resize step (0 means not resizable).
Definition: widget_type.h:225
GetSmallMapContoursPixels
static uint32_t 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:431
OWNER_WATER
@ OWNER_WATER
The tile/execution is done by "water".
Definition: company_type.h:26
GetTropicZone
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
Definition: tile_map.h:238
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:233
_nested_smallmap_bar
static constexpr NWidgetPart _nested_smallmap_bar[]
Widget parts of the smallmap legend bar + image buttons.
Definition: smallmap_gui.cpp:1907
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
BuildLinkStatsLegend
void BuildLinkStatsLegend()
Populate legend table for the link stat view.
Definition: smallmap_gui.cpp:216
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
GetSmallMapOwnerPixels
uint32_t 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:582
_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:104
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:1104
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:56
SmallMapColourScheme::height_colours_base
const uint32_t * height_colours_base
Base table for determining the colours.
Definition: smallmap_gui.cpp:277
GetClearDensity
uint GetClearDensity(Tile t)
Get the density of a non-field clear tile.
Definition: clear_map.h:83
PC_LIGHT_BLUE
static const uint8_t PC_LIGHT_BLUE
Light blue palette colour.
Definition: palette_func.h:76
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:59
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:852
OWNER_TOWN
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
NWidgetBase::padding
RectPadding padding
Padding added to the widget. Managed by parent container widget. (parent container may swap left and ...
Definition: widget_type.h:239
WID_SM_CAPTION
@ WID_SM_CAPTION
Caption of the window.
Definition: smallmap_widget.h:15
SmallMapWindow::GetLegendHeight
uint GetLegendHeight(uint num_columns) const
Compute height given a number of columns.
Definition: smallmap_gui.cpp:715
SmallMapType
SmallMapType
Types of legends in the WID_SM_LEGEND widget.
Definition: smallmap_gui.cpp:615
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:636
LegendAndColour::height
uint8_t height
Height in tiles. Only valid for height legend entries.
Definition: smallmap_gui.cpp:49
BuildLandLegend
void BuildLandLegend()
(Re)build the colour tables for the legends.
Definition: smallmap_gui.cpp:292
SmallMapColourScheme::colour_count
size_t colour_count
The number of colours.
Definition: smallmap_gui.cpp:278
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:151
NWidgetSmallmapDisplay::smallmap_window
const SmallMapWindow * smallmap_window
Window manager instance.
Definition: smallmap_gui.cpp:1847
PC_BARE_LAND
static const uint8_t PC_BARE_LAND
Brown palette colour for bare land.
Definition: palette_func.h:80
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
backup_type.hpp
TREE_GROUND_ROUGH_SNOW
@ TREE_GROUND_ROUGH_SNOW
A snow tile that is rough underneath.
Definition: tree_map.h:57