OpenTTD
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"
20 #include "guitimer_func.h"
21 
22 /* set up the cargos to be displayed in the smallmap's route legend */
24 
26 void ShowSmallMap();
27 void BuildLandLegend();
28 void BuildOwnerLegend();
29 
32  uint8 colour;
34  IndustryType type;
35  uint8 height;
37  bool show_on_map;
38  bool end;
39  bool col_break;
40 };
41 
43 class SmallMapWindow : public Window {
44 protected:
46  enum SmallMapType {
47  SMT_CONTOUR,
48  SMT_VEHICLES,
49  SMT_INDUSTRY,
50  SMT_LINKSTATS,
51  SMT_ROUTES,
52  SMT_VEGETATION,
53  SMT_OWNER,
54  };
55 
61  };
62 
64  static bool show_towns;
65  static int max_heightlevel;
66 
67  static const uint LEGEND_BLOB_WIDTH = 8;
68  static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS = 2;
69  static const uint FORCE_REFRESH_PERIOD = 930;
70  static const uint BLINK_PERIOD = 450;
71 
74  uint column_width;
75 
76  int32 scroll_x;
77  int32 scroll_y;
78  int32 subscroll;
79  int zoom;
80 
82  LinkGraphOverlay *overlay;
83 
84  static void BreakIndustryChainLink();
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  {
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();
177 
178  void SmallMapCenterOnCurrentPos();
179  Point GetStationMiddle(const Station *st) const;
180 
181  void SetStringParameters(int widget) const override;
182  void OnInit() override;
183  void OnPaint() override;
184  void DrawWidget(const Rect &r, int widget) const override;
185  void OnClick(Point pt, int widget, int click_count) override;
186  void OnInvalidateData(int data = 0, bool gui_scope = true) override;
187  bool OnRightClick(Point pt, int widget) override;
188  void OnMouseWheel(int wheel) override;
189  void OnRealtimeTick(uint delta_ms) override;
190  void OnScroll(Point delta) override;
191  void OnMouseOver(Point pt, int widget) override;
192 };
193 
194 #endif /* SMALLMAP_GUI_H */
Functions related to OTTD&#39;s strings.
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Definition of stuff that is very close to a company, like the company struct itself.
Data about how and where to blit pixels.
Definition: gfx_type.h:154
uint8 colour
Colour of the item on the map.
Definition: smallmap_gui.h:32
Types related to the industry.
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:110
int zoom
Zoom level. Bigger number means more zoom-out (further away).
Definition: smallmap_gui.h:79
High level window description.
Definition: window_gui.h:166
Initialize zoom level.
Definition: smallmap_gui.h:58
uint column_width
Width of a column in the WID_SM_LEGEND widget.
Definition: smallmap_gui.h:74
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
static void DrawVertMapIndicator(int x, int y, int y2)
Draws vertical part of map indicator.
Definition: smallmap_gui.h:93
uint GetNumberColumnsLegend(uint width) const
Return number of columns that can be displayed in width pixels.
Definition: smallmap_gui.h:124
uint GetMinLegendWidth() const
Compute minimal required width of the legends.
Definition: smallmap_gui.h:115
ZoomLevelChange
Available kinds of zoomlevel changes.
Definition: smallmap_gui.h:57
Structure for holding relevant data for legends in small map.
Definition: smallmap_gui.h:31
uint GetLegendHeight(uint num_columns) const
Compute height given a number of columns.
Definition: smallmap_gui.h:134
uint8 height
Height in tiles. Only valid for height legend entries.
Definition: smallmap_gui.h:35
How all blitters should look like.
Definition: base.hpp:28
bool show_on_map
For filtering industries, if true, industry is shown on the map in colour.
Definition: smallmap_gui.h:37
Functions, definitions and such used only by the GUI.
static void DrawHorizMapIndicator(int x, int x2, int y)
Draws horizontal part of map indicator.
Definition: smallmap_gui.h:105
Declaration of linkgraph overlay GUI.
Data structure for an opened window.
Definition: window_gui.h:276
static SmallMapType map_type
Currently displayed legends.
Definition: smallmap_gui.h:63
SmallMapType
Types of legends in the WID_SM_LEGEND widget.
Definition: smallmap_gui.h:46
bool end
This is the end of the list.
Definition: smallmap_gui.h:38
GUI Timers.
IndustryType type
Type of industry. Only valid for industry entries.
Definition: smallmap_gui.h:34
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:173
Class managing the smallmap window.
Definition: smallmap_gui.h:43
void BuildLandLegend()
(Re)build the colour tables for the legends.
void ShowSmallMap()
Show the smallmap window.
void BuildOwnerLegend()
Completes the array for the owned property legend.
uint32 GetOverlayCompanyMask() const
Get a bitmask for company links to be displayed.
Definition: smallmap_gui.h:145
uint min_number_of_columns
Minimal number of columns in legends.
Definition: smallmap_gui.h:72
int32 scroll_x
Horizontal world coordinate of the base tile left of the top-left corner of the smallmap display...
Definition: smallmap_gui.h:76
CompanyID company
Company to display. Only valid for company entries of the owner legend.
Definition: smallmap_gui.h:36
Represents the covered area of e.g.
Definition: tilearea_type.h:16
void BuildLinkStatsLegend()
Populate legend table for the link stat view.
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
static bool show_towns
Display town names in the smallmap.
Definition: smallmap_gui.h:64
GUITimer refresh
Refresh timer.
Definition: smallmap_gui.h:81
int32 scroll_y
Vertical world coordinate of the base tile left of the top-left corner of the smallmap display...
Definition: smallmap_gui.h:77
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
static int max_heightlevel
Currently used/cached maximum heightlevel.
Definition: smallmap_gui.h:65
Types related to the smallmap widgets.
void BuildIndustriesLegend()
Fills an array for the industries legends.
Custom container class for displaying smallmap with a vertically resizing legend panel.
bool col_break
Perform a column break and go further at the next column.
Definition: smallmap_gui.h:39
Coordinates of a point in 2D.
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:78
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:280
StringID legend
String corresponding to the coloured item.
Definition: smallmap_gui.h:33
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:73
Specification of a rectangle with absolute coordinates of all edges.
static const uint8 PC_VERY_LIGHT_YELLOW
Almost-white yellow palette colour.
Definition: gfx_func.h:218
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:44
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
Station data structure.
Definition: station_base.h:450
Factory to &#39;query&#39; all available blitters.
Handles drawing of links into some window.
Definition: linkgraph_gui.h:37