OpenTTD
linkgraph_gui.h
Go to the documentation of this file.
1 /* $Id$ */
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 "../window_gui.h"
19 #include "linkgraph_base.h"
20 #include <map>
21 #include <vector>
22 
27  LinkProperties() : capacity(0), usage(0), planned(0), shared(false) {}
28 
29  uint capacity;
30  uint usage;
31  uint planned;
32  bool shared;
33 };
34 
40 public:
41  typedef std::map<StationID, LinkProperties> StationLinkMap;
42  typedef std::map<StationID, StationLinkMap> LinkMap;
43  typedef std::vector<std::pair<StationID, uint> > StationSupplyList;
44 
45  static const uint8 LINK_COLOURS[];
46 
55  LinkGraphOverlay(const Window *w, uint wid, CargoTypes cargo_mask, uint32 company_mask, uint scale) :
56  window(w), widget_id(wid), cargo_mask(cargo_mask), company_mask(company_mask), scale(scale)
57  {}
58 
59  void Draw(const DrawPixelInfo *dpi);
60  void SetCargoMask(CargoTypes cargo_mask);
61  void SetCompanyMask(uint32 company_mask);
62 
64  void SetDirty() { this->dirty = true; }
65 
67  CargoTypes GetCargoMask() { return this->cargo_mask; }
68 
70  uint32 GetCompanyMask() { return this->company_mask; }
71 
72 protected:
73  const Window *window;
74  const uint widget_id;
75  CargoTypes cargo_mask;
76  uint32 company_mask;
77  LinkMap cached_links;
78  StationSupplyList cached_stations;
79  uint scale;
80  bool dirty;
81 
82  Point GetStationMiddle(const Station *st) const;
83 
84  void AddLinks(const Station *sta, const Station *stb);
85  void DrawLinks(const DrawPixelInfo *dpi) const;
86  void DrawStationDots(const DrawPixelInfo *dpi) const;
87  void DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const;
88  bool IsLinkVisible(Point pta, Point ptb, const DrawPixelInfo *dpi, int padding = 0) const;
89  bool IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding = 0) const;
90  void GetWidgetDpi(DrawPixelInfo *dpi) const;
91  void RebuildCache();
92 
93  static void AddStats(uint new_cap, uint new_usg, uint new_flow, bool new_shared, LinkProperties &cargo);
94  static void DrawVertex(int x, int y, int size, int colour, int border_colour);
95 };
96 
97 void ShowLinkGraphLegend();
98 
103 public:
104  LinkGraphLegendWindow(WindowDesc *desc, int window_number);
105  void SetOverlay(LinkGraphOverlay *overlay);
106 
107  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize);
108  virtual void DrawWidget(const Rect &r, int widget) const;
109  virtual bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond);
110  virtual void OnClick(Point pt, int widget, int click_count);
111  virtual void OnInvalidateData(int data = 0, bool gui_scope = true);
112 
113 private:
114  LinkGraphOverlay *overlay;
115 
116  void UpdateOverlayCompanies();
117  void UpdateOverlayCargoes();
118 };
119 
120 #endif /* LINKGRAPH_GUI_H */
Properties of a link between two stations.
Definition: linkgraph_gui.h:26
Data about how and where to blit pixels.
Definition: gfx_type.h:156
Some typedefs for the main game.
LinkMap cached_links
Cache for links to reduce recalculation.
Definition: linkgraph_gui.h:77
uint32 GetCompanyMask()
Get a bitmask of the currently shown companies.
Definition: linkgraph_gui.h:70
High level window description.
Definition: window_gui.h:168
uint usage
Actual usage of the link.
Definition: linkgraph_gui.h:30
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:79
Data structure for an opened window.
Definition: window_gui.h:278
bool shared
If this is a shared link to be drawn dashed.
Definition: linkgraph_gui.h:32
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:55
const uint widget_id
ID of Widget in Window to be drawn to.
Definition: linkgraph_gui.h:74
bool dirty
Set if overlay should be rebuilt.
Definition: linkgraph_gui.h:80
uint32 company_mask
Bitmask of companies to be displayed.
Definition: linkgraph_gui.h:76
const Window * window
Window to be drawn into.
Definition: linkgraph_gui.h:73
CargoTypes cargo_mask
Bitmask of cargos to be displayed.
Definition: linkgraph_gui.h:75
Coordinates of a point in 2D.
uint capacity
Capacity of the link.
Definition: linkgraph_gui.h:29
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:64
CargoTypes GetCargoMask()
Get a bitmask of the currently shown cargoes.
Definition: linkgraph_gui.h:67
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:39
uint planned
Planned usage of the link.
Definition: linkgraph_gui.h:31
StationSupplyList cached_stations
Cache for stations to be drawn.
Definition: linkgraph_gui.h:78