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