Feature: [Linkgraph] Show a tooltip with statistics when hovering a link

This commit is contained in:
Nicolas Chappe
2021-08-18 16:52:42 +02:00
committed by Michael Lutz
parent 7c79a2a767
commit 864771ca09
5 changed files with 84 additions and 10 deletions

View File

@@ -19,14 +19,20 @@
#include <vector>
/**
* Properties of a link between two stations.
* Monthly statistics for a link between two stations.
* Only the cargo type of the most saturated linkgraph is taken into account.
*/
struct LinkProperties {
LinkProperties() : capacity(0), usage(0), planned(0), shared(false) {}
LinkProperties() : cargo(CT_INVALID), capacity(0), usage(0), planned(0), shared(false) {}
/** 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.
uint capacity; ///< Capacity of the link.
uint usage; ///< Actual usage of the link.
uint planned; ///< Planned usage of the link.
uint32 time; ///< Travel time of the link.
bool shared; ///< If this is a shared link to be drawn dashed.
};
@@ -50,7 +56,7 @@ public:
* @param company_mask Bitmask of companies to be shown.
* @param scale Desired thickness of lines and size of station dots.
*/
LinkGraphOverlay(const Window *w, uint wid, CargoTypes cargo_mask, uint32 company_mask, uint scale) :
LinkGraphOverlay(Window *w, uint wid, CargoTypes cargo_mask, uint32 company_mask, uint scale) :
window(w), widget_id(wid), cargo_mask(cargo_mask), company_mask(company_mask), scale(scale)
{}
@@ -58,6 +64,8 @@ public:
void SetCargoMask(CargoTypes cargo_mask);
void SetCompanyMask(uint32 company_mask);
bool ShowTooltip(Point pt, TooltipCloseCondition close_cond);
/** Mark the linkgraph dirty to be rebuilt next time Draw() is called. */
void SetDirty() { this->dirty = true; }
@@ -68,7 +76,7 @@ public:
uint32 GetCompanyMask() { return this->company_mask; }
protected:
const Window *window; ///< Window to be drawn into.
Window *window; ///< Window to be drawn into.
const uint widget_id; ///< ID of Widget in Window to be drawn to.
CargoTypes cargo_mask; ///< Bitmask of cargos to be displayed.
uint32 company_mask; ///< Bitmask of companies to be displayed.
@@ -88,7 +96,7 @@ protected:
void GetWidgetDpi(DrawPixelInfo *dpi) const;
void RebuildCache();
static void AddStats(uint new_cap, uint new_usg, uint new_flow, bool new_shared, LinkProperties &cargo);
static void AddStats(CargoID new_cargo, uint new_cap, uint new_usg, uint new_flow, uint32 time, bool new_shared, LinkProperties &cargo);
static void DrawVertex(int x, int y, int size, int colour, int border_colour);
};