|
OpenTTD Source 20260218-master-g2123fca5ea
|
Handles drawing of links into some window. More...
#include <linkgraph_gui.h>
Public Types | |
| typedef std::map< StationID, LinkProperties > | StationLinkMap |
| typedef std::map< StationID, StationLinkMap > | LinkMap |
| typedef std::vector< std::pair< StationID, uint > > | StationSupplyList |
Public Member Functions | |
| LinkGraphOverlay (Window *w, WidgetID wid, CargoTypes cargo_mask, CompanyMask company_mask, uint scale) | |
| Create a link graph overlay for the specified window. | |
| void | Draw (const DrawPixelInfo *dpi) |
| Draw the linkgraph overlay or some part of it, in the area given. | |
| void | SetCargoMask (CargoTypes cargo_mask) |
| Set a new cargo mask and rebuild the cache. | |
| void | SetCompanyMask (CompanyMask company_mask) |
| Set a new company mask and rebuild the cache. | |
| bool | ShowTooltip (Point pt, TooltipCloseCondition close_cond) |
| void | SetDirty () |
| Mark the linkgraph dirty to be rebuilt next time Draw() is called. | |
| CargoTypes | GetCargoMask () |
| Get a bitmask of the currently shown cargoes. | |
| CompanyMask | GetCompanyMask () |
| Get a bitmask of the currently shown companies. | |
Static Public Attributes | |
| static const PixelColour | LINK_COLOURS [][12] |
| Colours for the various "load" states of links. | |
Protected Member Functions | |
| Point | GetStationMiddle (const Station *st) const |
| Determine the middle of a station in the current window. | |
| void | AddLinks (const Station *sta, const Station *stb) |
| Add all "interesting" links between the given stations to the cache. | |
| void | DrawLinks (const DrawPixelInfo *dpi) const |
| Draw the cached links or part of them into the given area. | |
| void | DrawStationDots (const DrawPixelInfo *dpi) const |
| Draw dots for stations into the smallmap. | |
| void | DrawContent (Point pta, Point ptb, const LinkProperties &cargo) const |
| Draw one specific link. | |
| bool | IsLinkVisible (Point pta, Point ptb, const DrawPixelInfo *dpi, int padding=0) const |
| Determine if a certain link crosses through the area given by the dpi with some lee way. | |
| bool | IsPointVisible (Point pt, const DrawPixelInfo *dpi, int padding=0) const |
| Determine if a certain point is inside the given DPI, with some lee way. | |
| void | GetWidgetDpi (DrawPixelInfo *dpi) const |
| Get a DPI for the widget we will be drawing to. | |
| void | RebuildCache () |
| Rebuild the cache and recalculate which links and stations to be shown. | |
Static Protected Member Functions | |
| static void | AddStats (CargoType new_cargo, uint new_cap, uint new_usg, uint new_flow, uint32_t time, bool new_shared, LinkProperties &cargo) |
| Add information from a given pair of link stat and flow stat to the given link properties. | |
| static void | DrawVertex (int x, int y, int size, PixelColour colour, PixelColour border_colour) |
| Draw a square symbolizing a producer of cargo. | |
Protected Attributes | |
| Window * | window |
| Window to be drawn into. | |
| const WidgetID | widget_id |
| ID of Widget in Window to be drawn to. | |
| CargoTypes | cargo_mask |
| Bitmask of cargos to be displayed. | |
| CompanyMask | company_mask |
| Bitmask of companies to be displayed. | |
| LinkMap | cached_links |
| Cache for links to reduce recalculation. | |
| StationSupplyList | cached_stations |
| Cache for stations to be drawn. | |
| uint | scale |
| Width of link lines. | |
| bool | dirty |
| Set if overlay should be rebuilt. | |
Handles drawing of links into some window.
The window must either be a smallmap or have a valid viewport.
Definition at line 44 of file linkgraph_gui.h.
| typedef std::map<StationID, StationLinkMap> LinkGraphOverlay::LinkMap |
Definition at line 47 of file linkgraph_gui.h.
| typedef std::map<StationID, LinkProperties> LinkGraphOverlay::StationLinkMap |
Definition at line 46 of file linkgraph_gui.h.
| typedef std::vector<std::pair<StationID, uint> > LinkGraphOverlay::StationSupplyList |
Definition at line 48 of file linkgraph_gui.h.
|
inline |
Create a link graph overlay for the specified window.
| w | Window to be drawn into. |
| wid | ID of the widget to draw into. |
| cargo_mask | Bitmask of cargoes to be shown. |
| company_mask | Bitmask of companies to be shown. |
| scale | Desired thickness of lines and size of station dots. |
Definition at line 60 of file linkgraph_gui.h.
References cargo_mask, company_mask, dirty, scale, widget_id, and window.
Add all "interesting" links between the given stations to the cache.
| from | The source station. |
| to | The destination station. |
Definition at line 213 of file linkgraph_gui.cpp.
References AddStats(), LinkGraph::BaseEdge::capacity, cargo_mask, Ticks::DAY_TICKS, GoodsEntry::GoodsEntryData::flows, CargoSpec::Get(), GoodsEntry::GetData(), FlowStatMap::GetFlowVia(), Station::goods, GoodsEntry::HasData(), GoodsEntry::link_graph, LinkGraph::Monthly(), GoodsEntry::node, BaseStation::owner, OWNER_NONE, LinkGraph::BaseEdge::TravelTime(), and LinkGraph::BaseEdge::usage.
Referenced by RebuildCache().
|
staticprotected |
Add information from a given pair of link stat and flow stat to the given link properties.
The shown usage or plan is always the maximum of all link stats involved.
| new_cargo | Cargo type of the new link. |
| new_cap | Capacity of the new link. |
| new_usg | Usage of the new link. |
| new_plan | Planned flow for the new link. |
| time | Travel time of the new link. |
| new_shared | If the new link is shared. |
| cargo | LinkProperties to write the information to. |
Definition at line 246 of file linkgraph_gui.cpp.
References LinkProperties::capacity, LinkProperties::cargo, LinkProperties::planned, LinkProperties::shared, LinkProperties::time, LinkProperties::Usage(), and LinkProperties::usage.
Referenced by AddLinks().
| void LinkGraphOverlay::Draw | ( | const DrawPixelInfo * | dpi | ) |
Draw the linkgraph overlay or some part of it, in the area given.
| dpi | Area to be drawn to. |
Definition at line 264 of file linkgraph_gui.cpp.
References dirty, DrawLinks(), DrawStationDots(), and RebuildCache().
|
protected |
Draw one specific link.
| pta | Source of the link. |
| ptb | Destination of the link. |
| cargo | Properties of the link. |
Definition at line 299 of file linkgraph_gui.cpp.
References _settings_client, _settings_game, abs(), LinkProperties::capacity, GetColourGradient(), lengthof, LINK_COLOURS, Point, scale, ScaleGUITrad(), LinkProperties::shared, LinkProperties::Usage(), Coord2D< T >::x, and Coord2D< T >::y.
Referenced by DrawLinks().
|
protected |
Draw the cached links or part of them into the given area.
| dpi | Area to be drawn to. |
Definition at line 278 of file linkgraph_gui.cpp.
References cached_links, DrawContent(), SpecializedStation< Station, false >::Get(), GetStationMiddle(), IsLinkVisible(), SpecializedStation< Station, false >::IsValidID(), Point, scale, and ScaleGUITrad().
Referenced by Draw().
|
protected |
Draw dots for stations into the smallmap.
The dots' sizes are determined by the amount of cargo produced there, their colours by the type of cargo produced.
| dpi | The context to draw the overlay in. |
Definition at line 325 of file linkgraph_gui.cpp.
References cached_stations, DrawVertex(), GetColourGradient(), SpecializedStation< Station, false >::GetIfValid(), GetStationMiddle(), IsPointVisible(), BaseStation::owner, OWNER_NONE, Point, scale, ScaleGUITrad(), Coord2D< T >::x, and Coord2D< T >::y.
Referenced by Draw().
|
staticprotected |
Draw a square symbolizing a producer of cargo.
| x | X coordinate of the middle of the vertex. |
| y | Y coordinate of the middle of the vertex. |
| size | x and y extent of the vertex. |
| colour | Colour with which the vertex will be filled. |
| border_colour | Colour for the border of the vertex. |
Definition at line 351 of file linkgraph_gui.cpp.
References GfxFillRect(), and ScaleGUITrad().
Referenced by DrawStationDots().
|
inline |
Get a bitmask of the currently shown cargoes.
Definition at line 77 of file linkgraph_gui.h.
References cargo_mask.
|
inline |
Get a bitmask of the currently shown companies.
Definition at line 83 of file linkgraph_gui.h.
References company_mask.
Determine the middle of a station in the current window.
| st | The station we're looking for. |
Definition at line 417 of file linkgraph_gui.cpp.
References GetSmallMapStationMiddle(), Point, and window.
Referenced by DrawLinks(), DrawStationDots(), and RebuildCache().
|
protected |
Get a DPI for the widget we will be drawing to.
| dpi | DrawPixelInfo to fill with the desired dimensions. |
Definition at line 60 of file linkgraph_gui.cpp.
References NWidgetBase::current_x, NWidgetBase::current_y, widget_id, and window.
Referenced by RebuildCache().
|
inlineprotected |
Determine if a certain link crosses through the area given by the dpi with some lee way.
| pta | First end of the link. |
| ptb | Second end of the link. |
| dpi | Visible area. |
| padding | Width or thickness of the link. |
Definition at line 143 of file linkgraph_gui.cpp.
References Point, Coord2D< T >::x, and Coord2D< T >::y.
Referenced by DrawLinks(), and RebuildCache().
|
inlineprotected |
Determine if a certain point is inside the given DPI, with some lee way.
| pt | Point we are looking for. |
| dpi | Visible area. |
| padding | Extent of the point. |
Definition at line 128 of file linkgraph_gui.cpp.
References Point, Coord2D< T >::x, and Coord2D< T >::y.
Referenced by DrawStationDots(), and RebuildCache().
|
protected |
Rebuild the cache and recalculate which links and stations to be shown.
Definition at line 71 of file linkgraph_gui.cpp.
References AddLinks(), cached_links, cached_stations, cargo_mask, company_mask, LinkGraph::BaseEdge::dest_node, LinkGraph::BaseNode::edges, CargoSpec::Get(), SpecializedStation< Station, false >::Get(), GetStationMiddle(), GetWidgetDpi(), IsLinkVisible(), IsPointVisible(), SpecializedStation< Station, false >::IsValidID(), SpecializedStation< Station, false >::Iterate(), LinkGraph::Monthly(), BaseStation::owner, OWNER_NONE, Point, BaseStation::rect, and LinkGraph::BaseNode::supply.
Referenced by Draw(), SetCargoMask(), and SetCompanyMask().
| void LinkGraphOverlay::SetCargoMask | ( | CargoTypes | cargo_mask | ) |
Set a new cargo mask and rebuild the cache.
| cargo_mask | New cargo mask. |
Definition at line 431 of file linkgraph_gui.cpp.
References cargo_mask, RebuildCache(), SetDirty(), widget_id, and window.
| void LinkGraphOverlay::SetCompanyMask | ( | CompanyMask | company_mask | ) |
Set a new company mask and rebuild the cache.
| company_mask | New company mask. |
Definition at line 442 of file linkgraph_gui.cpp.
References company_mask, RebuildCache(), SetDirty(), widget_id, and window.
|
inline |
Mark the linkgraph dirty to be rebuilt next time Draw() is called.
Definition at line 71 of file linkgraph_gui.h.
References dirty.
Referenced by SetCargoMask(), and SetCompanyMask().
| bool LinkGraphOverlay::ShowTooltip | ( | Point | pt, |
| TooltipCloseCondition | close_cond ) |
Definition at line 362 of file linkgraph_gui.cpp.
|
protected |
Cache for links to reduce recalculation.
Definition at line 90 of file linkgraph_gui.h.
Referenced by DrawLinks(), and RebuildCache().
|
protected |
Cache for stations to be drawn.
Definition at line 91 of file linkgraph_gui.h.
Referenced by DrawStationDots(), and RebuildCache().
|
protected |
Bitmask of cargos to be displayed.
Definition at line 88 of file linkgraph_gui.h.
Referenced by AddLinks(), GetCargoMask(), LinkGraphOverlay(), RebuildCache(), and SetCargoMask().
|
protected |
Bitmask of companies to be displayed.
Definition at line 89 of file linkgraph_gui.h.
Referenced by GetCompanyMask(), LinkGraphOverlay(), RebuildCache(), and SetCompanyMask().
|
protected |
Set if overlay should be rebuilt.
Definition at line 93 of file linkgraph_gui.h.
Referenced by Draw(), LinkGraphOverlay(), and SetDirty().
|
static |
Colours for the various "load" states of links.
Ordered from "unused" to "overloaded".
Definition at line 33 of file linkgraph_gui.h.
Referenced by BuildLinkStatsLegend(), DrawContent(), and LinkGraphLegendWindow::DrawWidget().
|
protected |
Width of link lines.
Definition at line 92 of file linkgraph_gui.h.
Referenced by DrawContent(), DrawLinks(), DrawStationDots(), and LinkGraphOverlay().
|
protected |
ID of Widget in Window to be drawn to.
Definition at line 87 of file linkgraph_gui.h.
Referenced by GetWidgetDpi(), LinkGraphOverlay(), SetCargoMask(), and SetCompanyMask().
|
protected |
Window to be drawn into.
Definition at line 86 of file linkgraph_gui.h.
Referenced by GetStationMiddle(), GetWidgetDpi(), LinkGraphOverlay(), SetCargoMask(), and SetCompanyMask().