2013-05-19 15:30:40 +01:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file linkgraph_gui.h Declaration of linkgraph overlay GUI. */
|
|
|
|
|
|
|
|
#ifndef LINKGRAPH_GUI_H
|
|
|
|
#define LINKGRAPH_GUI_H
|
|
|
|
|
|
|
|
#include "../company_func.h"
|
|
|
|
#include "../station_base.h"
|
|
|
|
#include "../widget_type.h"
|
2018-06-24 12:00:41 +01:00
|
|
|
#include "../window_gui.h"
|
2013-05-19 15:30:40 +01:00
|
|
|
#include "linkgraph_base.h"
|
|
|
|
|
|
|
|
/**
|
2021-08-18 15:52:42 +01:00
|
|
|
* Monthly statistics for a link between two stations.
|
|
|
|
* Only the cargo type of the most saturated linkgraph is taken into account.
|
2013-05-19 15:30:40 +01:00
|
|
|
*/
|
|
|
|
struct LinkProperties {
|
2024-01-06 15:15:37 +00:00
|
|
|
LinkProperties() : cargo(INVALID_CARGO), capacity(0), usage(0), planned(0), shared(false) {}
|
2013-05-19 15:30:40 +01:00
|
|
|
|
2021-08-18 15:52:42 +01:00
|
|
|
/** Return the usage of the link to display. */
|
|
|
|
uint Usage() const { return std::max(this->usage, this->planned); }
|
|
|
|
|
|
|
|
CargoID cargo; ///< Cargo type of the link.
|
2013-05-19 15:30:40 +01:00
|
|
|
uint capacity; ///< Capacity of the link.
|
|
|
|
uint usage; ///< Actual usage of the link.
|
2013-06-09 14:07:53 +01:00
|
|
|
uint planned; ///< Planned usage of the link.
|
2023-05-08 18:01:06 +01:00
|
|
|
uint32_t time; ///< Travel time of the link.
|
2013-10-23 20:42:17 +01:00
|
|
|
bool shared; ///< If this is a shared link to be drawn dashed.
|
2013-05-19 15:30:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles drawing of links into some window.
|
|
|
|
* The window must either be a smallmap or have a valid viewport.
|
|
|
|
*/
|
|
|
|
class LinkGraphOverlay {
|
|
|
|
public:
|
|
|
|
typedef std::map<StationID, LinkProperties> StationLinkMap;
|
|
|
|
typedef std::map<StationID, StationLinkMap> LinkMap;
|
2016-07-10 12:57:16 +01:00
|
|
|
typedef std::vector<std::pair<StationID, uint> > StationSupplyList;
|
2013-05-19 15:30:40 +01:00
|
|
|
|
2023-05-08 18:01:06 +01:00
|
|
|
static const uint8_t LINK_COLOURS[][12];
|
2013-05-19 15:30:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a link graph overlay for the specified window.
|
|
|
|
* @param w Window to be drawn into.
|
|
|
|
* @param wid ID of the widget to draw into.
|
|
|
|
* @param cargo_mask Bitmask of cargoes to be shown.
|
|
|
|
* @param company_mask Bitmask of companies to be shown.
|
|
|
|
* @param scale Desired thickness of lines and size of station dots.
|
|
|
|
*/
|
2023-12-29 19:11:59 +00:00
|
|
|
LinkGraphOverlay(Window *w, WidgetID wid, CargoTypes cargo_mask, CompanyMask company_mask, uint scale) :
|
2013-05-19 15:30:40 +01:00
|
|
|
window(w), widget_id(wid), cargo_mask(cargo_mask), company_mask(company_mask), scale(scale)
|
|
|
|
{}
|
|
|
|
|
2019-02-23 19:19:41 +00:00
|
|
|
void Draw(const DrawPixelInfo *dpi);
|
2018-05-21 22:08:39 +01:00
|
|
|
void SetCargoMask(CargoTypes cargo_mask);
|
2023-04-07 10:12:29 +01:00
|
|
|
void SetCompanyMask(CompanyMask company_mask);
|
2013-05-19 15:30:40 +01:00
|
|
|
|
2021-08-18 15:52:42 +01:00
|
|
|
bool ShowTooltip(Point pt, TooltipCloseCondition close_cond);
|
|
|
|
|
2019-02-23 19:19:41 +00:00
|
|
|
/** Mark the linkgraph dirty to be rebuilt next time Draw() is called. */
|
|
|
|
void SetDirty() { this->dirty = true; }
|
|
|
|
|
2013-05-19 15:30:40 +01:00
|
|
|
/** Get a bitmask of the currently shown cargoes. */
|
2018-05-21 22:08:39 +01:00
|
|
|
CargoTypes GetCargoMask() { return this->cargo_mask; }
|
2013-05-19 15:30:40 +01:00
|
|
|
|
|
|
|
/** Get a bitmask of the currently shown companies. */
|
2023-04-07 10:12:29 +01:00
|
|
|
CompanyMask GetCompanyMask() { return this->company_mask; }
|
2013-05-19 15:30:40 +01:00
|
|
|
|
|
|
|
protected:
|
2021-08-18 15:52:42 +01:00
|
|
|
Window *window; ///< Window to be drawn into.
|
2023-12-29 19:11:59 +00:00
|
|
|
const WidgetID widget_id; ///< ID of Widget in Window to be drawn to.
|
2018-05-21 22:08:39 +01:00
|
|
|
CargoTypes cargo_mask; ///< Bitmask of cargos to be displayed.
|
2023-04-07 10:12:29 +01:00
|
|
|
CompanyMask company_mask; ///< Bitmask of companies to be displayed.
|
2013-05-19 15:30:40 +01:00
|
|
|
LinkMap cached_links; ///< Cache for links to reduce recalculation.
|
|
|
|
StationSupplyList cached_stations; ///< Cache for stations to be drawn.
|
|
|
|
uint scale; ///< Width of link lines.
|
2019-02-23 19:19:41 +00:00
|
|
|
bool dirty; ///< Set if overlay should be rebuilt.
|
2013-05-19 15:30:40 +01:00
|
|
|
|
|
|
|
Point GetStationMiddle(const Station *st) const;
|
|
|
|
|
|
|
|
void AddLinks(const Station *sta, const Station *stb);
|
|
|
|
void DrawLinks(const DrawPixelInfo *dpi) const;
|
|
|
|
void DrawStationDots(const DrawPixelInfo *dpi) const;
|
|
|
|
void DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const;
|
|
|
|
bool IsLinkVisible(Point pta, Point ptb, const DrawPixelInfo *dpi, int padding = 0) const;
|
|
|
|
bool IsPointVisible(Point pt, const DrawPixelInfo *dpi, int padding = 0) const;
|
|
|
|
void GetWidgetDpi(DrawPixelInfo *dpi) const;
|
2019-02-23 19:19:41 +00:00
|
|
|
void RebuildCache();
|
2013-05-19 15:30:40 +01:00
|
|
|
|
2023-05-08 18:01:06 +01:00
|
|
|
static void AddStats(CargoID new_cargo, uint new_cap, uint new_usg, uint new_flow, uint32_t time, bool new_shared, LinkProperties &cargo);
|
2013-05-19 15:30:40 +01:00
|
|
|
static void DrawVertex(int x, int y, int size, int colour, int border_colour);
|
|
|
|
};
|
|
|
|
|
2013-05-19 15:43:23 +01:00
|
|
|
void ShowLinkGraphLegend();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Menu window to select cargoes and companies to show in a link graph overlay.
|
|
|
|
*/
|
|
|
|
struct LinkGraphLegendWindow : Window {
|
|
|
|
public:
|
2024-06-11 08:58:03 +01:00
|
|
|
LinkGraphLegendWindow(WindowDesc &desc, int window_number);
|
2023-03-31 16:06:36 +01:00
|
|
|
void SetOverlay(std::shared_ptr<LinkGraphOverlay> overlay);
|
2013-05-19 15:43:23 +01:00
|
|
|
|
2024-04-09 08:34:45 +01:00
|
|
|
void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override;
|
2023-12-29 19:11:59 +00:00
|
|
|
void DrawWidget(const Rect &r, WidgetID widget) const override;
|
|
|
|
bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override;
|
|
|
|
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override;
|
2019-03-04 07:49:37 +00:00
|
|
|
void OnInvalidateData(int data = 0, bool gui_scope = true) override;
|
2013-05-19 15:43:23 +01:00
|
|
|
|
|
|
|
private:
|
2023-03-31 16:06:36 +01:00
|
|
|
std::shared_ptr<LinkGraphOverlay> overlay;
|
2023-05-29 06:48:43 +01:00
|
|
|
size_t num_cargo;
|
2013-05-19 15:43:23 +01:00
|
|
|
|
|
|
|
void UpdateOverlayCompanies();
|
|
|
|
void UpdateOverlayCargoes();
|
|
|
|
};
|
|
|
|
|
2013-05-19 15:30:40 +01:00
|
|
|
#endif /* LINKGRAPH_GUI_H */
|