(svn r27724) -Cleanup: Remove pointless usage of IsOpenTTDBaseGRF. System GRFs are...
[openttd.git] / src / linkgraph / linkgraph_gui.h
blob1e306a44d4d48aedaad41b80850c549a6f231aa2
1 /* $Id$ */
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 */
10 /** @file linkgraph_gui.h Declaration of linkgraph overlay GUI. */
12 #ifndef LINKGRAPH_GUI_H
13 #define LINKGRAPH_GUI_H
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>
22 /**
23 * Properties of a link between two stations.
25 struct LinkProperties {
26 LinkProperties() : capacity(0), usage(0), planned(0), shared(false) {}
28 uint capacity; ///< Capacity of the link.
29 uint usage; ///< Actual usage of the link.
30 uint planned; ///< Planned usage of the link.
31 bool shared; ///< If this is a shared link to be drawn dashed.
34 /**
35 * Handles drawing of links into some window.
36 * The window must either be a smallmap or have a valid viewport.
38 class LinkGraphOverlay {
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;
44 static const uint8 LINK_COLOURS[];
46 /**
47 * Create a link graph overlay for the specified window.
48 * @param w Window to be drawn into.
49 * @param wid ID of the widget to draw into.
50 * @param cargo_mask Bitmask of cargoes to be shown.
51 * @param company_mask Bitmask of companies to be shown.
52 * @param scale Desired thickness of lines and size of station dots.
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)
58 void RebuildCache();
59 void Draw(const DrawPixelInfo *dpi) const;
60 void SetCargoMask(uint32 cargo_mask);
61 void SetCompanyMask(uint32 company_mask);
63 /** Get a bitmask of the currently shown cargoes. */
64 uint32 GetCargoMask() { return this->cargo_mask; }
66 /** Get a bitmask of the currently shown companies. */
67 uint32 GetCompanyMask() { return this->company_mask; }
69 protected:
70 const Window *window; ///< Window to be drawn into.
71 const uint widget_id; ///< ID of Widget in Window to be drawn to.
72 uint32 cargo_mask; ///< Bitmask of cargos to be displayed.
73 uint32 company_mask; ///< Bitmask of companies to be displayed.
74 LinkMap cached_links; ///< Cache for links to reduce recalculation.
75 StationSupplyList cached_stations; ///< Cache for stations to be drawn.
76 uint scale; ///< Width of link lines.
78 Point GetStationMiddle(const Station *st) const;
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;
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);
93 void ShowLinkGraphLegend();
95 /**
96 * Menu window to select cargoes and companies to show in a link graph overlay.
98 struct LinkGraphLegendWindow : Window {
99 public:
100 LinkGraphLegendWindow(WindowDesc *desc, int window_number);
101 void SetOverlay(LinkGraphOverlay *overlay);
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);
108 private:
109 LinkGraphOverlay *overlay;
111 void UpdateOverlayCompanies();
112 void UpdateOverlayCargoes();
115 #endif /* LINKGRAPH_GUI_H */