Update: Translations from eints
[openttd-github.git] / src / linkgraph / linkgraph_gui.h
blobad732eb098aca28d1bb46da3b6f9178da5749a8c
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file linkgraph_gui.h Declaration of linkgraph overlay GUI. */
10 #ifndef LINKGRAPH_GUI_H
11 #define LINKGRAPH_GUI_H
13 #include "../company_func.h"
14 #include "../station_base.h"
15 #include "../widget_type.h"
16 #include "../window_gui.h"
17 #include "linkgraph_base.h"
19 /**
20 * Monthly statistics for a link between two stations.
21 * Only the cargo type of the most saturated linkgraph is taken into account.
23 struct LinkProperties {
24 LinkProperties() : cargo(INVALID_CARGO), capacity(0), usage(0), planned(0), shared(false) {}
26 /** Return the usage of the link to display. */
27 uint Usage() const { return std::max(this->usage, this->planned); }
29 CargoID cargo; ///< Cargo type of the link.
30 uint capacity; ///< Capacity of the link.
31 uint usage; ///< Actual usage of the link.
32 uint planned; ///< Planned usage of the link.
33 uint32_t time; ///< Travel time of the link.
34 bool shared; ///< If this is a shared link to be drawn dashed.
37 /**
38 * Handles drawing of links into some window.
39 * The window must either be a smallmap or have a valid viewport.
41 class LinkGraphOverlay {
42 public:
43 typedef std::map<StationID, LinkProperties> StationLinkMap;
44 typedef std::map<StationID, StationLinkMap> LinkMap;
45 typedef std::vector<std::pair<StationID, uint> > StationSupplyList;
47 static const uint8_t LINK_COLOURS[][12];
49 /**
50 * Create a link graph overlay for the specified window.
51 * @param w Window to be drawn into.
52 * @param wid ID of the widget to draw into.
53 * @param cargo_mask Bitmask of cargoes to be shown.
54 * @param company_mask Bitmask of companies to be shown.
55 * @param scale Desired thickness of lines and size of station dots.
57 LinkGraphOverlay(Window *w, WidgetID wid, CargoTypes cargo_mask, CompanyMask company_mask, uint scale) :
58 window(w), widget_id(wid), cargo_mask(cargo_mask), company_mask(company_mask), scale(scale), dirty(true)
61 void Draw(const DrawPixelInfo *dpi);
62 void SetCargoMask(CargoTypes cargo_mask);
63 void SetCompanyMask(CompanyMask company_mask);
65 bool ShowTooltip(Point pt, TooltipCloseCondition close_cond);
67 /** Mark the linkgraph dirty to be rebuilt next time Draw() is called. */
68 void SetDirty() { this->dirty = true; }
70 /** Get a bitmask of the currently shown cargoes. */
71 CargoTypes GetCargoMask() { return this->cargo_mask; }
73 /** Get a bitmask of the currently shown companies. */
74 CompanyMask GetCompanyMask() { return this->company_mask; }
76 protected:
77 Window *window; ///< Window to be drawn into.
78 const WidgetID widget_id; ///< ID of Widget in Window to be drawn to.
79 CargoTypes cargo_mask; ///< Bitmask of cargos to be displayed.
80 CompanyMask company_mask; ///< Bitmask of companies to be displayed.
81 LinkMap cached_links; ///< Cache for links to reduce recalculation.
82 StationSupplyList cached_stations; ///< Cache for stations to be drawn.
83 uint scale; ///< Width of link lines.
84 bool dirty; ///< Set if overlay should be rebuilt.
86 Point GetStationMiddle(const Station *st) const;
88 void AddLinks(const Station *sta, const Station *stb);
89 void DrawLinks(const DrawPixelInfo *dpi) const;
90 void DrawStationDots(const DrawPixelInfo *dpi) const;
91 void DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const;
92 bool IsLinkVisible(Point pta, Point ptb, const DrawPixelInfo *dpi, int padding = 0) const;
93 bool IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding = 0) const;
94 void GetWidgetDpi(DrawPixelInfo *dpi) const;
95 void RebuildCache();
97 static void AddStats(CargoID new_cargo, uint new_cap, uint new_usg, uint new_flow, uint32_t time, bool new_shared, LinkProperties &cargo);
98 static void DrawVertex(int x, int y, int size, int colour, int border_colour);
101 void ShowLinkGraphLegend();
104 * Menu window to select cargoes and companies to show in a link graph overlay.
106 struct LinkGraphLegendWindow : Window {
107 public:
108 LinkGraphLegendWindow(WindowDesc &desc, int window_number);
109 void SetOverlay(std::shared_ptr<LinkGraphOverlay> overlay);
111 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override;
112 void DrawWidget(const Rect &r, WidgetID widget) const override;
113 bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override;
114 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override;
115 void OnInvalidateData(int data = 0, bool gui_scope = true) override;
117 private:
118 std::shared_ptr<LinkGraphOverlay> overlay;
119 size_t num_cargo;
121 void UpdateOverlayCompanies();
122 void UpdateOverlayCargoes();
125 #endif /* LINKGRAPH_GUI_H */