OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

smallmap_gui.h
Go to the documentation of this file.
1 /* $Id: smallmap_gui.h 27158 2015-02-22 14:10:44Z frosch $ */
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 Point SmallmapRemapCoords(int x, int y) const;
86
93 static inline void DrawVertMapIndicator(int x, int y, int y2)
94 {
95 GfxFillRect(x, y, x, y + 3, PC_VERY_LIGHT_YELLOW);
96 GfxFillRect(x, y2 - 3, x, y2, PC_VERY_LIGHT_YELLOW);
97 }
98
105 static inline void DrawHorizMapIndicator(int x, int x2, int y)
106 {
107 GfxFillRect(x, y, x + 3, y, PC_VERY_LIGHT_YELLOW);
108 GfxFillRect(x2 - 3, y, x2, y, PC_VERY_LIGHT_YELLOW);
109 }
110
115 inline uint GetMinLegendWidth() const
116 {
117 return WD_FRAMERECT_LEFT + this->min_number_of_columns * this->column_width;
118 }
119
124 inline uint GetNumberColumnsLegend(uint width) const
125 {
126 return width / this->column_width;
127 }
128
134 inline uint GetLegendHeight(uint num_columns) const
135 {
136 return WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM +
137 this->GetNumberRowsLegend(num_columns) * FONT_HEIGHT_SMALL;
138 }
139
145 inline uint32 GetOverlayCompanyMask() const
146 {
147 return Company::IsValidID(_local_company) ? 1U << _local_company : 0xffffffff;
148 }
149
150 void RebuildColourIndexIfNecessary();
151 uint GetNumberRowsLegend(uint columns) const;
152 void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item = 0);
153 void SwitchMapType(SmallMapType map_type);
154 void SetNewScroll(int sx, int sy, int sub);
155
156 void DrawMapIndicators() const;
157 void DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos, Blitter *blitter) const;
158 void DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const;
159 void DrawTowns(const DrawPixelInfo *dpi) const;
160 void DrawSmallMap(DrawPixelInfo *dpi) const;
161
162 Point RemapTile(int tile_x, int tile_y) const;
163 Point PixelToTile(int px, int py, int *sub, bool add_sub = true) const;
164 Point ComputeScroll(int tx, int ty, int x, int y, int *sub);
165 void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt);
166 void SetOverlayCargoMask();
167 void SetupWidgetData();
168 uint32 GetTileColours(const TileArea &ta) const;
169
170 int GetPositionOnLegend(Point pt);
171
172 public:
173 friend class NWidgetSmallmapDisplay;
174
175 SmallMapWindow(WindowDesc *desc, int window_number);
176 virtual ~SmallMapWindow() { delete this->overlay; }
177
178 void SmallMapCenterOnCurrentPos();
179 Point GetStationMiddle(const Station *st) const;
180
181 virtual void SetStringParameters(int widget) const;
182 virtual void OnInit();
183 virtual void OnPaint();
184 virtual void DrawWidget(const Rect &r, int widget) const;
185 virtual void OnClick(Point pt, int widget, int click_count);
186 virtual void OnInvalidateData(int data = 0, bool gui_scope = true);
187 virtual bool OnRightClick(Point pt, int widget);
188 virtual void OnMouseWheel(int wheel);
189 virtual void OnTick();
190 virtual void OnScroll(Point delta);
191 virtual void OnMouseOver(Point pt, int widget);
192 };
193
194 #endif /* SMALLMAP_GUI_H */