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 RebuildCache();
60  void Draw(const DrawPixelInfo *dpi) const;
61  void SetCargoMask(CargoTypes cargo_mask);
62  void SetCompanyMask(uint32 company_mask);
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 
79  Point GetStationMiddle(const Station *st) const;
80 
81  void AddLinks(const Station *sta, const Station *stb);
82  void DrawLinks(const DrawPixelInfo *dpi) const;
83  void DrawStationDots(const DrawPixelInfo *dpi) const;
84  void DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const;
85  bool IsLinkVisible(Point pta, Point ptb, const DrawPixelInfo *dpi, int padding = 0) const;
86  bool IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding = 0) const;
87  void GetWidgetDpi(DrawPixelInfo *dpi) const;
88 
89  static void AddStats(uint new_cap, uint new_usg, uint new_flow, bool new_shared, LinkProperties &cargo);
90  static void DrawVertex(int x, int y, int size, int colour, int border_colour);
91 };
92 
93 void ShowLinkGraphLegend();
94 
99 public:
100  LinkGraphLegendWindow(WindowDesc *desc, int window_number);
101  void SetOverlay(LinkGraphOverlay *overlay);
102 
103  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize);
104  virtual void DrawWidget(const Rect &r, int widget) const;
105  virtual void OnHover(Point pt, int widget);
106  virtual bool OnRightClick(Point pt, int widget);
107  virtual void OnClick(Point pt, int widget, int click_count);
108  virtual void OnInvalidateData(int data = 0, bool gui_scope = true);
109 
110 private:
111  LinkGraphOverlay *overlay;
112 
113  void UpdateOverlayCompanies();
114  void UpdateOverlayCargoes();
115  bool OnHoverCommon(Point pt, int widget, TooltipCloseCondition close_cond);
116 };
117 
118 #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:75
uint32 GetCompanyMask()
Get a bitmask of the currently shown companies.
Definition: linkgraph_gui.h:68
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.
Definition: linkgraph_gui.h:98
uint scale
Width of link lines.
Definition: linkgraph_gui.h:77
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: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:72
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:29
Specification of a rectangle with absolute coordinates of all edges.
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: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:76