OpenTTD

smallmap_gui.h
Go to the documentation of this file.
1 /* $Id: smallmap_gui.h 27905 2017-08-31 06:48:55Z adf88 $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef SMALLMAP_GUI_H
13 #define SMALLMAP_GUI_H
14
15 #include "industry_type.h"
16 #include "company_base.h"
17 #include "window_gui.h"
18 #include "strings_func.h"
19 #include "blitter/factory.hpp"
20 #include "linkgraph/linkgraph_gui.h"
21 #include "widgets/smallmap_widget.h"
22
23 /* set up the cargos to be displayed in the smallmap's route legend */
24 void BuildLinkStatsLegend();
25
26 void BuildIndustriesLegend();
27 void ShowSmallMap();
28 void BuildLandLegend();
29 void BuildOwnerLegend();
30
32 struct LegendAndColour {
33 uint8 colour;
34 StringID legend;
35 IndustryType type;
36 uint8 height;
37 CompanyID company;
38 bool show_on_map;
39 bool end;
40 bool col_break;
41 };
42
44 class SmallMapWindow : public Window {
45 protected:
47 enum SmallMapType {
48 SMT_CONTOUR,
49 SMT_VEHICLES,
50 SMT_INDUSTRY,
51 SMT_LINKSTATS,
52 SMT_ROUTES,
53 SMT_VEGETATION,
54 SMT_OWNER,
55 };
56
58 enum ZoomLevelChange {
59 ZLC_INITIALIZE,
60 ZLC_ZOOM_OUT,
61 ZLC_ZOOM_IN,
62 };
63
64 static SmallMapType map_type;
65 static bool show_towns;
66 static int max_heightlevel;
67
68 static const uint LEGEND_BLOB_WIDTH = 8;
69 static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS = 2;
70 static const uint FORCE_REFRESH_PERIOD = 0x1F;
71 static const uint BLINK_PERIOD = 0x0F;
72
73 uint min_number_of_columns;
74 uint min_number_of_fixed_rows;
75 uint column_width;
76
77 int32 scroll_x;
78 int32 scroll_y;
79 int32 subscroll;
80 int zoom;
81
82 uint8 refresh;
83 LinkGraphOverlay *overlay;
84
85 static void BreakIndustryChainLink();
86 Point SmallmapRemapCoords(int x, int y) const;
87
94 static inline void DrawVertMapIndicator(int x, int y, int y2)
95 {
96 GfxFillRect(x, y, x, y + 3, PC_VERY_LIGHT_YELLOW);
97 GfxFillRect(x, y2 - 3, x, y2, PC_VERY_LIGHT_YELLOW);
98 }
99
106 static inline void DrawHorizMapIndicator(int x, int x2, int y)
107 {
108 GfxFillRect(x, y, x + 3, y, PC_VERY_LIGHT_YELLOW);
109 GfxFillRect(x2 - 3, y, x2, y, PC_VERY_LIGHT_YELLOW);
110 }
111
116 inline uint GetMinLegendWidth() const
117 {
118 return WD_FRAMERECT_LEFT + this->min_number_of_columns * this->column_width;
119 }
120
125 inline uint GetNumberColumnsLegend(uint width) const
126 {
127 return width / this->column_width;
128 }
129
135 inline uint GetLegendHeight(uint num_columns) const
136 {
137 return WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM +
138 this->GetNumberRowsLegend(num_columns) * FONT_HEIGHT_SMALL;
139 }
140
146 inline uint32 GetOverlayCompanyMask() const
147 {
148 return Company::IsValidID(_local_company) ? 1U << _local_company : 0xffffffff;
149 }
150
151 void RebuildColourIndexIfNecessary();
152 uint GetNumberRowsLegend(uint columns) const;
153 void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item = 0);
154 void SwitchMapType(SmallMapType map_type);
155 void SetNewScroll(int sx, int sy, int sub);
156
157 void DrawMapIndicators() const;
158 void DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos, Blitter *blitter) const;
159 void DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const;
160 void DrawTowns(const DrawPixelInfo *dpi) const;
161 void DrawSmallMap(DrawPixelInfo *dpi) const;
162
163 Point RemapTile(int tile_x, int tile_y) const;
164 Point PixelToTile(int px, int py, int *sub, bool add_sub = true) const;
165 Point ComputeScroll(int tx, int ty, int x, int y, int *sub);
166 void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt);
167 void SetOverlayCargoMask();
168 void SetupWidgetData();
169 uint32 GetTileColours(const TileArea &ta) const;
170
171 int GetPositionOnLegend(Point pt);
172
173 public:
174 friend class NWidgetSmallmapDisplay;
175
176 SmallMapWindow(WindowDesc *desc, int window_number);
177 virtual ~SmallMapWindow();
178
179 void SmallMapCenterOnCurrentPos();
180 Point GetStationMiddle(const Station *st) const;
181
182 virtual void SetStringParameters(int widget) const;
183 virtual void OnInit();
184 virtual void OnPaint();
185 virtual void DrawWidget(const Rect &r, int widget) const;
186 virtual void OnClick(Point pt, int widget, int click_count);
187 virtual void OnInvalidateData(int data = 0, bool gui_scope = true);
188 virtual bool OnRightClick(Point pt, int widget);
189 virtual void OnMouseWheel(int wheel);
190 virtual void OnTick();
191 virtual void OnScroll(Point delta);
192 virtual void OnMouseOver(Point pt, int widget);
193 };
194
195 #endif /* SMALLMAP_GUI_H */
strings_func.h
Functions related to OTTD&#39;s strings.
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:156
LegendAndColour::colour
uint8 colour
Colour of the item on the map.
Definition: smallmap_gui.h:33
industry_type.h
Types related to the industry.
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:112
SmallMapWindow::zoom
int zoom
Zoom level. Bigger number means more zoom-out (further away).
Definition: smallmap_gui.h:80
WindowDesc
High level window description.
Definition: window_gui.h:168
SmallMapWindow::ZLC_INITIALIZE
Initialize zoom level.
Definition: smallmap_gui.h:59
SmallMapWindow::column_width
uint column_width
Width of a column in the WID_SM_LEGEND widget.
Definition: smallmap_gui.h:75
WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
SmallMapWindow::DrawVertMapIndicator
static void DrawVertMapIndicator(int x, int y, int y2)
Draws vertical part of map indicator.
Definition: smallmap_gui.h:94
SmallMapWindow::GetNumberColumnsLegend
uint GetNumberColumnsLegend(uint width) const
Return number of columns that can be displayed in width pixels.
Definition: smallmap_gui.h:125
SmallMapWindow::GetMinLegendWidth
uint GetMinLegendWidth() const
Compute minimal required width of the legends.
Definition: smallmap_gui.h:116
SmallMapWindow::ZLC_ZOOM_OUT
Zoom out.
Definition: smallmap_gui.h:60
SmallMapWindow::refresh
uint8 refresh
Refresh counter, zeroed every FORCE_REFRESH_PERIOD ticks.
Definition: smallmap_gui.h:82
SmallMapWindow::ZoomLevelChange
ZoomLevelChange
Available kinds of zoomlevel changes.
Definition: smallmap_gui.h:58
LegendAndColour
Structure for holding relevant data for legends in small map.
Definition: smallmap_gui.h:32
SmallMapWindow::GetLegendHeight
uint GetLegendHeight(uint num_columns) const
Compute height given a number of columns.
Definition: smallmap_gui.h:135
LegendAndColour::height
uint8 height
Height in tiles. Only valid for height legend entries.
Definition: smallmap_gui.h:36
Blitter
How all blitters should look like.
Definition: base.hpp:30
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:38
window_gui.h
Functions, definitions and such used only by the GUI.
_local_company
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
SmallMapWindow::DrawHorizMapIndicator
static void DrawHorizMapIndicator(int x, int x2, int y)
Draws horizontal part of map indicator.
Definition: smallmap_gui.h:106
linkgraph_gui.h
Declaration of linkgraph overlay GUI.
Window
Data structure for an opened window.
Definition: window_gui.h:271
SmallMapWindow::map_type
static SmallMapType map_type
Currently displayed legends.
Definition: smallmap_gui.h:64
SmallMapWindow::SmallMapType
SmallMapType
Types of legends in the WID_SM_LEGEND widget.
Definition: smallmap_gui.h:47
LegendAndColour::end
bool end
This is the end of the list.
Definition: smallmap_gui.h:39
LegendAndColour::type
IndustryType type
Type of industry. Only valid for industry entries.
Definition: smallmap_gui.h:35
FONT_HEIGHT_SMALL
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:177
SmallMapWindow
Class managing the smallmap window.
Definition: smallmap_gui.h:44
BuildLandLegend
void BuildLandLegend()
(Re)build the colour tables for the legends.
Definition: smallmap_gui.cpp:282
ShowSmallMap
void ShowSmallMap()
Show the smallmap window.
Definition: smallmap_gui.cpp:1848
BuildOwnerLegend
void BuildOwnerLegend()
Completes the array for the owned property legend.
Definition: smallmap_gui.cpp:333
SmallMapWindow::GetOverlayCompanyMask
uint32 GetOverlayCompanyMask() const
Get a bitmask for company links to be displayed.
Definition: smallmap_gui.h:146
SmallMapWindow::min_number_of_columns
uint min_number_of_columns
Minimal number of columns in legends.
Definition: smallmap_gui.h:73
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:77
LegendAndColour::company
CompanyID company
Company to display. Only valid for company entries of the owner legend.
Definition: smallmap_gui.h:37
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
BuildLinkStatsLegend
void BuildLinkStatsLegend()
Populate legend table for the link stat view.
Definition: smallmap_gui.cpp:206
WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
SmallMapWindow::show_towns
static bool show_towns
Display town names in the smallmap.
Definition: smallmap_gui.h:65
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:78
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
SmallMapWindow::max_heightlevel
static int max_heightlevel
Currently used/cached maximum heightlevel.
Definition: smallmap_gui.h:66
smallmap_widget.h
Types related to the smallmap widgets.
BuildIndustriesLegend
void BuildIndustriesLegend()
Fills an array for the industries legends.
Definition: smallmap_gui.cpp:175
NWidgetSmallmapDisplay
Custom container class for displaying smallmap with a vertically resizing legend panel.
Definition: smallmap_gui.cpp:1687
LegendAndColour::col_break
bool col_break
Perform a column break and go further at the next column.
Definition: smallmap_gui.h:40
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:28
SmallMapWindow::subscroll
int32 subscroll
Number of pixels (0..3) between the right end of the base tile and the pixel at the top-left corner o...
Definition: smallmap_gui.h:79
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
Definition: pool_type.hpp:235
LegendAndColour::legend
StringID legend
String corresponding to the coloured item.
Definition: smallmap_gui.h:34
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:74
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:40
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:20
SmallMapWindow::ZLC_ZOOM_IN
Zoom in.
Definition: smallmap_gui.h:61
PC_VERY_LIGHT_YELLOW
static const uint8 PC_VERY_LIGHT_YELLOW
Almost-white yellow palette colour.
Definition: gfx_func.h:222
WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
Station
Station data structure.
Definition: station_base.h:446
factory.hpp
Factory to &#39;query&#39; all available blitters.
LinkGraphOverlay
Handles drawing of links into some window.
Definition: linkgraph_gui.h:38