Translations update
[openttd/fttd.git] / src / smallmap_gui.h
blobe2564a819c9d9adb34e73e62227a5fd04b7159ae
1 /* $Id$ */
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 */
10 /** @file smallmap_gui.h Smallmap GUI functions. */
12 #ifndef SMALLMAP_GUI_H
13 #define SMALLMAP_GUI_H
15 #include "industry_type.h"
16 #include "company_base.h"
17 #include "window_gui.h"
18 #include "strings_func.h"
19 #include "blitter/blitter.h"
20 #include "gfx_func.h"
21 #include "linkgraph/linkgraph_gui.h"
22 #include "widgets/smallmap_widget.h"
24 /* set up the cargos to be displayed in the smallmap's route legend */
25 void BuildLinkStatsLegend();
27 void BuildIndustriesLegend();
28 void ShowSmallMap();
29 void BuildLandLegend();
30 void BuildOwnerLegend();
32 /** Structure for holding relevant data for legends in small map */
33 struct LegendAndColour {
34 uint8 colour; ///< Colour of the item on the map.
35 StringID legend; ///< String corresponding to the coloured item.
36 IndustryType type; ///< Type of industry. Only valid for industry entries.
37 uint8 height; ///< Height in tiles. Only valid for height legend entries.
38 CompanyID company; ///< Company to display. Only valid for company entries of the owner legend.
39 bool show_on_map; ///< For filtering industries, if \c true, industry is shown on the map in colour.
40 bool end; ///< This is the end of the list.
41 bool col_break; ///< Perform a column break and go further at the next column.
44 /** Class managing the smallmap window. */
45 class SmallMapWindow : public Window {
46 public:
47 /** Types of legends in the #WID_SM_LEGEND widget. */
48 enum SmallMapType {
49 SMT_CONTOUR,
50 SMT_VEHICLES,
51 SMT_INDUSTRY,
52 SMT_LINKSTATS,
53 SMT_ROUTES,
54 SMT_VEGETATION,
55 SMT_OWNER,
58 protected:
59 /** Available kinds of zoomlevel changes. */
60 enum ZoomLevelChange {
61 ZLC_INITIALIZE, ///< Initialize zoom level.
62 ZLC_ZOOM_OUT, ///< Zoom out.
63 ZLC_ZOOM_IN, ///< Zoom in.
66 static SmallMapType map_type; ///< Currently displayed legends.
67 static bool show_towns; ///< Display town names in the smallmap.
68 static int max_heightlevel; ///< Currently used/cached maximum heightlevel.
70 static const uint LEGEND_BLOB_WIDTH = 8; ///< Width of the coloured blob in front of a line text in the #WID_SM_LEGEND widget.
71 static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS = 2; ///< Minimal number of columns in the #WID_SM_LEGEND widget for the #SMT_INDUSTRY legend.
72 static const uint FORCE_REFRESH_PERIOD = 0x1F; ///< map is redrawn after that many ticks
73 static const uint BLINK_PERIOD = 0x0F; ///< highlight blinking interval
75 LinkGraphOverlay overlay; ///< Link graph overlay.
77 uint min_number_of_columns; ///< Minimal number of columns in legends.
78 uint min_number_of_fixed_rows; ///< Minimal number of rows in the legends for the fixed layouts only (all except #SMT_INDUSTRY).
79 uint column_width; ///< Width of a column in the #WID_SM_LEGEND widget.
81 int32 scroll_x; ///< Horizontal world coordinate of the base tile left of the top-left corner of the smallmap display.
82 int32 scroll_y; ///< Vertical world coordinate of the base tile left of the top-left corner of the smallmap display.
83 int32 subscroll; ///< Number of pixels (0..3) between the right end of the base tile and the pixel at the top-left corner of the smallmap display.
84 int zoom; ///< Zoom level. Bigger number means more zoom-out (further away).
86 uint8 refresh; ///< Refresh counter, zeroed every FORCE_REFRESH_PERIOD ticks.
88 /**
89 * Compute minimal required width of the legends.
90 * @return Minimally needed width for displaying the smallmap legends in pixels.
92 inline uint GetMinLegendWidth() const
94 return WD_FRAMERECT_LEFT + this->min_number_of_columns * this->column_width;
97 /**
98 * Return number of columns that can be displayed in \a width pixels.
99 * @return Number of columns to display.
101 inline uint GetNumberColumnsLegend(uint width) const
103 return width / this->column_width;
107 * Compute height given a number of columns.
108 * @param num_columns Number of columns.
109 * @return Needed height for displaying the smallmap legends in pixels.
111 inline uint GetLegendHeight(uint num_columns) const
113 return WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM +
114 this->GetNumberRowsLegend(num_columns) * FONT_HEIGHT_SMALL;
118 * Get a bitmask for company links to be displayed. Usually this will be
119 * the _local_company. Spectators get to see all companies' links.
120 * @return Company mask.
122 inline uint32 GetOverlayCompanyMask() const
124 return Company::IsValidID(_local_company) ? 1U << _local_company : 0xffffffff;
127 void RebuildColourIndexIfNecessary();
128 uint GetNumberRowsLegend(uint columns) const;
129 void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item = 0);
130 void SwitchMapType(SmallMapType map_type);
131 void SetNewScroll(int sx, int sy, int sub);
133 void DrawMapIndicators (BlitArea *dpi) const;
134 void DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos) const;
135 void DrawVehicles (BlitArea *dpi) const;
136 void DrawTowns (BlitArea *dpi) const;
137 void DrawSmallMap (BlitArea *dpi) const;
139 Point RemapTile(int tile_x, int tile_y) const;
140 Point PixelToTile(int px, int py, int *sub, bool add_sub = true) const;
141 void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt);
142 void SetOverlayCargoMask();
143 void SetupWidgetData();
144 uint32 GetTileColours(const TileArea &ta) const;
146 int GetPositionOnLegend(Point pt);
148 public:
149 friend class NWidgetSmallmapDisplay;
151 SmallMapWindow (const WindowDesc *desc, int window_number);
152 virtual ~SmallMapWindow();
154 void SmallMapCenterOnCurrentPos();
155 Point GetStationMiddle(const Station *st) const;
157 virtual void SetStringParameters(int widget) const;
158 virtual void OnInit();
159 void OnPaint (BlitArea *dpi) OVERRIDE;
160 void DrawWidget (BlitArea *dpi, const Rect &r, int widget) const OVERRIDE;
161 virtual void OnClick(Point pt, int widget, int click_count);
162 virtual void OnInvalidateData(int data = 0, bool gui_scope = true);
163 virtual bool OnRightClick(Point pt, int widget);
164 virtual void OnMouseWheel(int wheel);
165 virtual void OnTick();
166 virtual void OnScroll(Point delta);
167 virtual void OnMouseOver(Point pt, int widget);
170 #endif /* SMALLMAP_GUI_H */