OpenTTD
linkgraph_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 LINKGRAPH_GUI_H
11 #define LINKGRAPH_GUI_H
12 
13 #include "../company_func.h"
14 #include "../station_base.h"
15 #include "../widget_type.h"
16 #include "../window_gui.h"
17 #include "linkgraph_base.h"
18 #include <map>
19 #include <vector>
20 
25  LinkProperties() : capacity(0), usage(0), planned(0), shared(false) {}
26 
27  uint capacity;
28  uint usage;
29  uint planned;
30  bool shared;
31 };
32 
38 public:
39  typedef std::map<StationID, LinkProperties> StationLinkMap;
40  typedef std::map<StationID, StationLinkMap> LinkMap;
41  typedef std::vector<std::pair<StationID, uint> > StationSupplyList;
42 
43  static const uint8 LINK_COLOURS[];
44 
53  LinkGraphOverlay(const Window *w, uint wid, CargoTypes cargo_mask, uint32 company_mask, uint scale) :
54  window(w), widget_id(wid), cargo_mask(cargo_mask), company_mask(company_mask), scale(scale)
55  {}
56 
57  void Draw(const DrawPixelInfo *dpi);
58  void SetCargoMask(CargoTypes cargo_mask);
59  void SetCompanyMask(uint32 company_mask);
60 
62  void SetDirty() { this->dirty = true; }
63 
65  CargoTypes GetCargoMask() { return this->cargo_mask; }
66 
68  uint32 GetCompanyMask() { return this->company_mask; }
69 
70 protected:
71  const Window *window;
72  const uint widget_id;
73  CargoTypes cargo_mask;
74  uint32 company_mask;
75  LinkMap cached_links;
76  StationSupplyList cached_stations;
77  uint scale;
78  bool dirty;
79 
80  Point GetStationMiddle(const Station *st) const;
81 
82  void AddLinks(const Station *sta, const Station *stb);
83  void DrawLinks(const DrawPixelInfo *dpi) const;
84  void DrawStationDots(const DrawPixelInfo *dpi) const;
85  void DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const;
86  bool IsLinkVisible(Point pta, Point ptb, const DrawPixelInfo *dpi, int padding = 0) const;
87  bool IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding = 0) const;
88  void GetWidgetDpi(DrawPixelInfo *dpi) const;
89  void RebuildCache();
90 
91  static void AddStats(uint new_cap, uint new_usg, uint new_flow, bool new_shared, LinkProperties &cargo);
92  static void DrawVertex(int x, int y, int size, int colour, int border_colour);
93 };
94 
95 void ShowLinkGraphLegend();
96 
101 public:
102  LinkGraphLegendWindow(WindowDesc *desc, int window_number);
103  void SetOverlay(LinkGraphOverlay *overlay);
104 
105  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override;
106  void DrawWidget(const Rect &r, int widget) const override;
107  bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override;
108  void OnClick(Point pt, int widget, int click_count) override;
109  void OnInvalidateData(int data = 0, bool gui_scope = true) override;
110 
111 private:
112  LinkGraphOverlay *overlay;
113 
114  void UpdateOverlayCompanies();
115  void UpdateOverlayCargoes();
116 };
117 
118 #endif /* LINKGRAPH_GUI_H */
Properties of a link between two stations.
Definition: linkgraph_gui.h:24
Data about how and where to blit pixels.
Definition: gfx_type.h:154
Some typedefs for the main game.
LinkMap cached_links
Cache for links to reduce recalculation.
Definition: linkgraph_gui.h:75
uint32 GetCompanyMask()
Get a bitmask of the currently shown companies.
Definition: linkgraph_gui.h:68
High level window description.
Definition: window_gui.h:166
uint usage
Actual usage of the link.
Definition: linkgraph_gui.h:28
void ShowLinkGraphLegend()
Open a link graph legend window.
Menu window to select cargoes and companies to show in a link graph overlay.
uint scale
Width of link lines.
Definition: linkgraph_gui.h:77
Data structure for an opened window.
Definition: window_gui.h:276
bool shared
If this is a shared link to be drawn dashed.
Definition: linkgraph_gui.h:30
LinkGraphOverlay(const Window *w, uint wid, CargoTypes cargo_mask, uint32 company_mask, uint scale)
Create a link graph overlay for the specified window.
Definition: linkgraph_gui.h:53
const uint widget_id
ID of Widget in Window to be drawn to.
Definition: linkgraph_gui.h:72
bool dirty
Set if overlay should be rebuilt.
Definition: linkgraph_gui.h:78
uint32 company_mask
Bitmask of companies to be displayed.
Definition: linkgraph_gui.h:74
const Window * window
Window to be drawn into.
Definition: linkgraph_gui.h:71
CargoTypes cargo_mask
Bitmask of cargos to be displayed.
Definition: linkgraph_gui.h:73
Coordinates of a point in 2D.
uint capacity
Capacity of the link.
Definition: linkgraph_gui.h:27
Specification of a rectangle with absolute coordinates of all edges.
void SetDirty()
Mark the linkgraph dirty to be rebuilt next time Draw() is called.
Definition: linkgraph_gui.h:62
CargoTypes GetCargoMask()
Get a bitmask of the currently shown cargoes.
Definition: linkgraph_gui.h:65
Dimensions (a width and height) of a rectangle in 2D.
Station data structure.
Definition: station_base.h:450
Handles drawing of links into some window.
Definition: linkgraph_gui.h:37
uint planned
Planned usage of the link.
Definition: linkgraph_gui.h:29
StationSupplyList cached_stations
Cache for stations to be drawn.
Definition: linkgraph_gui.h:76