OpenTTD: src/linkgraph/linkgraph_gui.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

linkgraph_gui.h
Go to the documentation of this file.
1 /* $Id: linkgraph_gui.h 26266 2014-01-19 09:26:56Z fonsinchen $ */
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 <list>
21
25 struct LinkProperties {
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
38 class LinkGraphOverlay {
39 public:
40 typedef std::map<StationID, LinkProperties> StationLinkMap;
41 typedef std::map<StationID, StationLinkMap> LinkMap;
42 typedef std::list<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 DrawForwBackLinks(Point pta, StationID sta, Point ptb, StationID stb) const;
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
98 struct LinkGraphLegendWindow : Window {
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 OnClick(Point pt, int widget, int click_count);
106 virtual void OnInvalidateData(int data = 0, bool gui_scope = true);
107
108 private:
109 LinkGraphOverlay *overlay;
110
111 void UpdateOverlayCompanies();
112 void UpdateOverlayCargoes();
113 };
114
115 #endif /* LINKGRAPH_GUI_H */