OpenTTD Source: src/smallmap_gui.h Source File

OpenTTD Source 13.2.1

smallmap_gui.h
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 #ifndef SMALLMAP_GUI_H
11 #define SMALLMAP_GUI_H
12
13 #include "industry_type.h"
14 #include "company_base.h"
15 #include "window_gui.h"
16 #include "strings_func.h"
17 #include "blitter/factory.hpp"
18 #include "linkgraph/linkgraph_gui.h"
19 #include "widgets/smallmap_widget.h"
20 #include "guitimer_func.h"
21
22 /* set up the cargos to be displayed in the smallmap's route legend */
23 void BuildLinkStatsLegend();
24
25 void BuildIndustriesLegend();
26 void ShowSmallMap();
27 void BuildLandLegend();
28 void BuildOwnerLegend();
29
31 enum class IncludeHeightmap {
32 Never,
33 IfEnabled,
34 Always
35 };
36
37 uint32 GetSmallMapOwnerPixels(TileIndex tile, TileType t, IncludeHeightmap include_heightmap);
38
40 struct LegendAndColour {
41 uint8 colour;
42 StringID legend;
43 IndustryType type;
44 uint8 height;
45 CompanyID company;
46 bool show_on_map;
47 bool end;
48 bool col_break;
49 };
50
52 class SmallMapWindow : public Window {
53 protected:
55 enum SmallMapType {
56 SMT_CONTOUR,
57 SMT_VEHICLES,
58 SMT_INDUSTRY,
59 SMT_LINKSTATS,
60 SMT_ROUTES,
61 SMT_VEGETATION,
62 SMT_OWNER,
63 };
64
66 enum ZoomLevelChange {
67 ZLC_INITIALIZE,
68 ZLC_ZOOM_OUT,
69 ZLC_ZOOM_IN,
70 };
71
72 static SmallMapType map_type;
73 static bool show_towns;
74 static int map_height_limit;
75
76 static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS = 2;
77 static const uint FORCE_REFRESH_PERIOD = 930;
78 static const uint BLINK_PERIOD = 450;
79
80 uint min_number_of_columns;
81 uint min_number_of_fixed_rows;
82 uint column_width;
83 uint legend_width;
84
85 int32 scroll_x;
86 int32 scroll_y;
87 int32 subscroll;
88 int zoom;
89
90 GUITimer refresh;
91 LinkGraphOverlay *overlay;
92
93 static void BreakIndustryChainLink();
94 Point SmallmapRemapCoords(int x, int y) const;
95
102 static inline void DrawVertMapIndicator(int x, int y, int y2)
103 {
104 GfxFillRect(x, y, x, y + 3, PC_VERY_LIGHT_YELLOW);
105 GfxFillRect(x, y2 - 3, x, y2, PC_VERY_LIGHT_YELLOW);
106 }
107
114 static inline void DrawHorizMapIndicator(int x, int x2, int y)
115 {
116 GfxFillRect(x, y, x + 3, y, PC_VERY_LIGHT_YELLOW);
117 GfxFillRect(x2 - 3, y, x2, y, PC_VERY_LIGHT_YELLOW);
118 }
119
124 inline uint GetMinLegendWidth() const
125 {
126 return WidgetDimensions::scaled.framerect.left + this->min_number_of_columns * this->column_width;
127 }
128
133 inline uint GetNumberColumnsLegend(uint width) const
134 {
135 return width / this->column_width;
136 }
137
143 inline uint GetLegendHeight(uint num_columns) const
144 {
145 return WidgetDimensions::scaled.framerect.Vertical() +
146 this->GetNumberRowsLegend(num_columns) * FONT_HEIGHT_SMALL;
147 }
148
154 inline uint32 GetOverlayCompanyMask() const
155 {
156 return Company::IsValidID(_local_company) ? 1U << _local_company : 0xffffffff;
157 }
158
159 void RebuildColourIndexIfNecessary();
160 uint GetNumberRowsLegend(uint columns) const;
161 void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item = 0);
162 void SwitchMapType(SmallMapType map_type);
163 void SetNewScroll(int sx, int sy, int sub);
164
165 void DrawMapIndicators() const;
166 void DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos, Blitter *blitter) const;
167 void DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const;
168 void DrawTowns(const DrawPixelInfo *dpi) const;
169 void DrawSmallMap(DrawPixelInfo *dpi) const;
170
171 Point RemapTile(int tile_x, int tile_y) const;
172 Point PixelToTile(int px, int py, int *sub, bool add_sub = true) const;
173 Point ComputeScroll(int tx, int ty, int x, int y, int *sub);
174 void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt);
175 void SetOverlayCargoMask();
176 void SetupWidgetData();
177 uint32 GetTileColours(const TileArea &ta) const;
178
179 int GetPositionOnLegend(Point pt);
180
181 public:
182 friend class NWidgetSmallmapDisplay;
183
184 SmallMapWindow(WindowDesc *desc, int window_number);
185 virtual ~SmallMapWindow();
186
187 void SmallMapCenterOnCurrentPos();
188 Point GetStationMiddle(const Station *st) const;
189
190 void Close() override;
191 void SetStringParameters(int widget) const override;
192 void OnInit() override;
193 void OnPaint() override;
194 void DrawWidget(const Rect &r, int widget) const override;
195 void OnClick(Point pt, int widget, int click_count) override;
196 void OnInvalidateData(int data = 0, bool gui_scope = true) override;
197 bool OnRightClick(Point pt, int widget) override;
198 void OnMouseWheel(int wheel) override;
199 void OnRealtimeTick(uint delta_ms) override;
200 void OnScroll(Point delta) override;
201 void OnMouseOver(Point pt, int widget) override;
202 };
203
204 #endif /* SMALLMAP_GUI_H */
LegendAndColour::type
IndustryType type
Type of industry. Only valid for industry entries.
Definition: smallmap_gui.h:43
factory.hpp
SmallMapWindow::min_number_of_fixed_rows
uint min_number_of_fixed_rows
Minimal number of rows in the legends for the fixed layouts only (all except #SMT_INDUSTRY).
Definition: smallmap_gui.h:81
SmallMapWindow::map_type
static SmallMapType map_type
Currently displayed legends.
Definition: smallmap_gui.h:72
guitimer_func.h
company_base.h
SmallMapWindow::ZLC_ZOOM_IN
@ ZLC_ZOOM_IN
Zoom in.
Definition: smallmap_gui.h:69
SmallMapWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: smallmap_gui.cpp:1197
Blitter
How all blitters should look like.
Definition: base.hpp:28
Station
Station data structure.
Definition: station_base.h:454
SmallMapWindow::SmallMapCenterOnCurrentPos
void SmallMapCenterOnCurrentPos()
Center the small map on the current center of the viewport.
Definition: smallmap_gui.cpp:1666
SmallMapWindow::DrawHorizMapIndicator
static void DrawHorizMapIndicator(int x, int x2, int y)
Draws horizontal part of map indicator.
Definition: smallmap_gui.h:114
LegendAndColour::company
CompanyID company
Company to display. Only valid for company entries of the owner legend.
Definition: smallmap_gui.h:45
SmallMapWindow::OnRightClick
bool OnRightClick(Point pt, int widget) override
A click with the right mouse button has been made on the window.
Definition: smallmap_gui.cpp:1574
SmallMapWindow::GetOverlayCompanyMask
uint32 GetOverlayCompanyMask() const
Get a bitmask for company links to be displayed.
Definition: smallmap_gui.h:154
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
SmallMapWindow::SetupWidgetData
void SetupWidgetData()
Function to set up widgets depending on the information being shown on the smallmap.
Definition: smallmap_gui.cpp:1037
SmallMapWindow::GetTileColours
uint32 GetTileColours(const TileArea &ta) const
Decide which colours to show to the user for a group of tiles.
Definition: smallmap_gui.cpp:751
SmallMapWindow::zoom
int zoom
Zoom level. Bigger number means more zoom-out (further away).
Definition: smallmap_gui.h:88
SmallMapWindow::SwitchMapType
void SwitchMapType(SmallMapType map_type)
Select a new map type.
Definition: smallmap_gui.cpp:1314
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
NWidgetSmallmapDisplay
Custom container class for displaying smallmap with a vertically resizing legend panel.
Definition: smallmap_gui.cpp:1709
SmallMapWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: smallmap_gui.cpp:1144
SmallMapWindow::column_width
uint column_width
Width of a column in the WID_SM_LEGEND widget.
Definition: smallmap_gui.h:82
SmallMapWindow::min_number_of_columns
uint min_number_of_columns
Minimal number of columns in legends.
Definition: smallmap_gui.h:80
SmallMapWindow::scroll_x
int32 scroll_x
Horizontal world coordinate of the base tile left of the top-left corner of the smallmap display.
Definition: smallmap_gui.h:85
SmallMapWindow
Class managing the smallmap window.
Definition: smallmap_gui.h:52
SmallMapWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: smallmap_gui.cpp:1104
SmallMapWindow::show_towns
static bool show_towns
Display town names in the smallmap.
Definition: smallmap_gui.h:73
IncludeHeightmap::IfEnabled
@ IfEnabled
Only include the heightmap if its enabled in the gui by the player.
SmallMapWindow::GetNumberColumnsLegend
uint GetNumberColumnsLegend(uint width) const
Return number of columns that can be displayed in width pixels.
Definition: smallmap_gui.h:133
SmallMapWindow::DrawSmallMap
void DrawSmallMap(DrawPixelInfo *dpi) const
Draws the small map.
Definition: smallmap_gui.cpp:973
SmallMapWindow::GetStationMiddle
Point GetStationMiddle(const Station *st) const
Get the center of the given station as point on the screen in the smallmap window.
Definition: smallmap_gui.cpp:1684
SmallMapWindow::SetZoomLevel
void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt)
Initialize or change the zoom level.
Definition: smallmap_gui.cpp:702
WindowDesc
High level window description.
Definition: window_gui.h:102
SmallMapWindow::ComputeScroll
Point ComputeScroll(int tx, int ty, int x, int y, int *sub)
Compute base parameters of the smallmap such that tile (tx, ty) starts at pixel (x,...
Definition: smallmap_gui.cpp:674
window_gui.h
PC_VERY_LIGHT_YELLOW
static const uint8 PC_VERY_LIGHT_YELLOW
Almost-white yellow palette colour.
Definition: gfx_func.h:257
SmallMapWindow::GetMinLegendWidth
uint GetMinLegendWidth() const
Compute minimal required width of the legends.
Definition: smallmap_gui.h:124
LinkGraphOverlay
Handles drawing of links into some window.
Definition: linkgraph_gui.h:43
GUITimer
Definition: guitimer_func.h:13
SmallMapWindow::ZoomLevelChange
ZoomLevelChange
Available kinds of zoomlevel changes.
Definition: smallmap_gui.h:66
SmallMapWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: smallmap_gui.cpp:1545
SmallMapWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: smallmap_gui.cpp:1429
SmallMapWindow::GetNumberRowsLegend
uint GetNumberRowsLegend(uint columns) const
Get the number of rows in the legend from the number of columns.
Definition: smallmap_gui.cpp:1335
smallmap_widget.h
SmallMapWindow::ZLC_ZOOM_OUT
@ ZLC_ZOOM_OUT
Zoom out.
Definition: smallmap_gui.h:68
SmallMapWindow::DrawVehicles
void DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const
Adds vehicles to the smallmap.
Definition: smallmap_gui.cpp:880
BuildLinkStatsLegend
void BuildLinkStatsLegend()
Populate legend table for the link stat view.
Definition: smallmap_gui.cpp:199
SmallMapWindow::DrawVertMapIndicator
static void DrawVertMapIndicator(int x, int y, int y2)
Draws vertical part of map indicator.
Definition: smallmap_gui.h:102
ShowSmallMap
void ShowSmallMap()
Show the smallmap window.
Definition: smallmap_gui.cpp:1870
LegendAndColour::col_break
bool col_break
Perform a column break and go further at the next column.
Definition: smallmap_gui.h:48
SmallMapWindow::DrawMapIndicators
void DrawMapIndicators() const
Adds map indicators to the smallmap.
Definition: smallmap_gui.cpp:941
BuildLandLegend
void BuildLandLegend()
(Re)build the colour tables for the legends.
Definition: smallmap_gui.cpp:275
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
linkgraph_gui.h
SmallMapWindow::GetPositionOnLegend
int GetPositionOnLegend(Point pt)
Determines the mouse position on the legend.
Definition: smallmap_gui.cpp:1396
LegendAndColour::legend
StringID legend
String corresponding to the coloured item.
Definition: smallmap_gui.h:42
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
BuildOwnerLegend
void BuildOwnerLegend()
Completes the array for the owned property legend.
Definition: smallmap_gui.cpp:326
BuildIndustriesLegend
void BuildIndustriesLegend()
Fills an array for the industries legends.
Definition: smallmap_gui.cpp:169
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
SmallMapWindow::legend_width
uint legend_width
Width of legend 'blob'.
Definition: smallmap_gui.h:83
IncludeHeightmap::Always
@ Always
Always include the heightmap.
SmallMapWindow::SmallMapType
SmallMapType
Types of legends in the WID_SM_LEGEND widget.
Definition: smallmap_gui.h:55
industry_type.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:241
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:116
RectPadding::Vertical
uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:65
SmallMapWindow::DrawSmallMapColumn
void DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos, Blitter *blitter) const
Draws one column of tiles of the small map in a certain mode onto the screen buffer,...
Definition: smallmap_gui.cpp:840
SmallMapWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: smallmap_gui.cpp:1213
SmallMapWindow::BreakIndustryChainLink
static void BreakIndustryChainLink()
Notify the industry chain window to stop sending newly selected industries.
Definition: smallmap_gui.cpp:599
FONT_HEIGHT_SMALL
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:203
SmallMapWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: smallmap_gui.cpp:1595
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
SmallMapWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: smallmap_gui.cpp:1135
SmallMapWindow::subscroll
int32 subscroll
Number of pixels (0..3) between the right end of the base tile and the pixel at the top-left corner o...
Definition: smallmap_gui.h:87
SmallMapWindow::OnScroll
void OnScroll(Point delta) override
Handle the request for (viewport) scrolling.
Definition: smallmap_gui.cpp:1651
GetSmallMapOwnerPixels
uint32 GetSmallMapOwnerPixels(TileIndex tile, TileType t, IncludeHeightmap include_heightmap)
Return the colour a tile would be displayed with in the small map in mode "Owner".
Definition: smallmap_gui.cpp:565
strings_func.h
SmallMapWindow::OnMouseOver
void OnMouseOver(Point pt, int widget) override
The mouse is currently moving over the window or has just moved outside of the window.
Definition: smallmap_gui.cpp:1412
SmallMapWindow::SetOverlayCargoMask
void SetOverlayCargoMask()
Set the link graph overlay cargo mask from the legend.
Definition: smallmap_gui.cpp:1382
SmallMapWindow::SetNewScroll
void SetNewScroll(int sx, int sy, int sub)
Set new scroll_x, scroll_y, and subscroll values after limiting them such that the center of the smal...
Definition: smallmap_gui.cpp:1621
TileType
TileType
The different types of tiles.
Definition: tile_type.h:47
SmallMapWindow::INDUSTRY_MIN_NUMBER_OF_COLUMNS
static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS
Minimal number of columns in the WID_SM_LEGEND widget for the #SMT_INDUSTRY legend.
Definition: smallmap_gui.h:76
LegendAndColour::height
uint8 height
Height in tiles. Only valid for height legend entries.
Definition: smallmap_gui.h:44
LegendAndColour::colour
uint8 colour
Colour of the item on the map.
Definition: smallmap_gui.h:41
LegendAndColour::show_on_map
bool show_on_map
For filtering industries, if true, industry is shown on the map in colour.
Definition: smallmap_gui.h:46
SmallMapWindow::DrawTowns
void DrawTowns(const DrawPixelInfo *dpi) const
Adds town names to the smallmap.
Definition: smallmap_gui.cpp:918
WidgetDimensions::framerect
RectPadding framerect
Offsets within frame area.
Definition: window_gui.h:47
SmallMapWindow::RemapTile
Point RemapTile(int tile_x, int tile_y) const
Remap tile to location on this smallmap.
Definition: smallmap_gui.cpp:618
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:248
IncludeHeightmap
IncludeHeightmap
Enum for how to include the heightmap pixels/colours in small map related functions.
Definition: smallmap_gui.h:31
SmallMapWindow::refresh
GUITimer refresh
Refresh timer.
Definition: smallmap_gui.h:90
SmallMapWindow::scroll_y
int32 scroll_y
Vertical world coordinate of the base tile left of the top-left corner of the smallmap display.
Definition: smallmap_gui.h:86
Window
Data structure for an opened window.
Definition: window_gui.h:213
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
SmallMapWindow::SelectLegendItem
void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item=0)
Select and toggle a legend item.
Definition: smallmap_gui.cpp:1354
SmallMapWindow::RebuildColourIndexIfNecessary
void RebuildColourIndexIfNecessary()
Rebuilds the colour indices used for fast access to the smallmap contour colours based on the heightl...
Definition: smallmap_gui.cpp:1113
IncludeHeightmap::Never
@ Never
Never include the heightmap.
SmallMapWindow::map_height_limit
static int map_height_limit
Currently used/cached map height limit.
Definition: smallmap_gui.h:74
SmallMapWindow::ZLC_INITIALIZE
@ ZLC_INITIALIZE
Initialize zoom level.
Definition: smallmap_gui.h:67
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
LegendAndColour
Structure for holding relevant data for legends in small map.
Definition: smallmap_gui.h:40
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
LegendAndColour::end
bool end
This is the end of the list.
Definition: smallmap_gui.h:47
SmallMapWindow::PixelToTile
Point PixelToTile(int px, int py, int *sub, bool add_sub=true) const
Determine the tile relative to the base tile of the smallmap, and the pixel position at that tile for...
Definition: smallmap_gui.cpp:642
SmallMapWindow::FORCE_REFRESH_PERIOD
static const uint FORCE_REFRESH_PERIOD
map is redrawn after that many milliseconds.
Definition: smallmap_gui.h:77
SmallMapWindow::GetLegendHeight
uint GetLegendHeight(uint num_columns) const
Compute height given a number of columns.
Definition: smallmap_gui.h:143
SmallMapWindow::OnMouseWheel
void OnMouseWheel(int wheel) override
The mouse wheel has been turned.
Definition: smallmap_gui.cpp:1582
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:151
SmallMapWindow::BLINK_PERIOD
static const uint BLINK_PERIOD
highlight blinking interval in milliseconds.
Definition: smallmap_gui.h:78