OpenTTD Source 20241224-master-gf74b0cf984
LinkGraphOverlay Class Reference

Handles drawing of links into some window. More...

#include <linkgraph_gui.h>

Public Types

typedef std::map< StationID, LinkPropertiesStationLinkMap
 
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 uint8_t 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 (CargoID 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, int colour, int border_colour)
 Draw a square symbolizing a producer of cargo.
 

Protected Attributes

Windowwindow
 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.
 

Detailed Description

Handles drawing of links into some window.

The window must either be a smallmap or have a valid viewport.

Definition at line 41 of file linkgraph_gui.h.

Member Typedef Documentation

◆ LinkMap

typedef std::map<StationID, StationLinkMap> LinkGraphOverlay::LinkMap

Definition at line 44 of file linkgraph_gui.h.

◆ StationLinkMap

typedef std::map<StationID, LinkProperties> LinkGraphOverlay::StationLinkMap

Definition at line 43 of file linkgraph_gui.h.

◆ StationSupplyList

typedef std::vector<std::pair<StationID, uint> > LinkGraphOverlay::StationSupplyList

Definition at line 45 of file linkgraph_gui.h.

Constructor & Destructor Documentation

◆ LinkGraphOverlay()

LinkGraphOverlay::LinkGraphOverlay ( Window w,
WidgetID  wid,
CargoTypes  cargo_mask,
CompanyMask  company_mask,
uint  scale 
)
inline

Create a link graph overlay for the specified window.

Parameters
wWindow to be drawn into.
widID of the widget to draw into.
cargo_maskBitmask of cargoes to be shown.
company_maskBitmask of companies to be shown.
scaleDesired thickness of lines and size of station dots.

Definition at line 57 of file linkgraph_gui.h.

Member Function Documentation

◆ AddLinks()

◆ AddStats()

void LinkGraphOverlay::AddStats ( CargoID  new_cargo,
uint  new_cap,
uint  new_usg,
uint  new_plan,
uint32_t  time,
bool  new_shared,
LinkProperties cargo 
)
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.

Parameters
new_capCapacity of the new link.
new_usgUsage of the new link.
new_planPlanned flow for the new link.
new_sharedIf the new link is shared.
cargoLinkProperties to write the information to.

Definition at line 244 of file linkgraph_gui.cpp.

References LinkProperties::capacity, LinkProperties::cargo, LinkProperties::planned, LinkProperties::shared, LinkProperties::time, LinkProperties::Usage(), and LinkProperties::usage.

Referenced by AddLinks().

◆ Draw()

void LinkGraphOverlay::Draw ( const DrawPixelInfo dpi)

Draw the linkgraph overlay or some part of it, in the area given.

Parameters
dpiArea to be drawn to.

Definition at line 262 of file linkgraph_gui.cpp.

References dirty, DrawLinks(), DrawStationDots(), and RebuildCache().

◆ DrawContent()

void LinkGraphOverlay::DrawContent ( Point  pta,
Point  ptb,
const LinkProperties cargo 
) const
protected

Draw one specific link.

Parameters
ptaSource of the link.
ptbDestination of the link.
cargoProperties of the link.

Definition at line 297 of file linkgraph_gui.cpp.

References _settings_client, _settings_game, abs(), LinkProperties::capacity, GetColourGradient(), ClientSettings::gui, lengthof, LINK_COLOURS, GUISettings::linkgraph_colours, VehicleSettings::road_side, scale, ScaleGUITrad(), LinkProperties::shared, LinkProperties::Usage(), and GameSettings::vehicle.

Referenced by DrawLinks().

◆ DrawLinks()

void LinkGraphOverlay::DrawLinks ( const DrawPixelInfo dpi) const
protected

Draw the cached links or part of them into the given area.

Parameters
dpiArea to be drawn to.

Definition at line 276 of file linkgraph_gui.cpp.

References cached_links, DrawContent(), SpecializedStation< Station, false >::Get(), GetStationMiddle(), IsLinkVisible(), SpecializedStation< Station, false >::IsValidID(), scale, and ScaleGUITrad().

Referenced by Draw().

◆ DrawStationDots()

void LinkGraphOverlay::DrawStationDots ( const DrawPixelInfo dpi) const
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.

Definition at line 322 of file linkgraph_gui.cpp.

References cached_stations, DrawVertex(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), GetColourGradient(), SpecializedStation< Station, false >::GetIfValid(), GetStationMiddle(), IsPointVisible(), BaseStation::owner, OWNER_NONE, scale, and ScaleGUITrad().

Referenced by Draw().

◆ DrawVertex()

void LinkGraphOverlay::DrawVertex ( int  x,
int  y,
int  size,
int  colour,
int  border_colour 
)
staticprotected

Draw a square symbolizing a producer of cargo.

Parameters
xX coordinate of the middle of the vertex.
yY coordinate of the middle of the vertex.
sizex and y extent of the vertex.
colourColour with which the vertex will be filled.
border_colourColour for the border of the vertex.

Definition at line 348 of file linkgraph_gui.cpp.

References GfxFillRect(), and ScaleGUITrad().

Referenced by DrawStationDots().

◆ GetCargoMask()

CargoTypes LinkGraphOverlay::GetCargoMask ( )
inline

Get a bitmask of the currently shown cargoes.

Definition at line 71 of file linkgraph_gui.h.

References cargo_mask.

◆ GetCompanyMask()

CompanyMask LinkGraphOverlay::GetCompanyMask ( )
inline

Get a bitmask of the currently shown companies.

Definition at line 74 of file linkgraph_gui.h.

References company_mask.

◆ GetStationMiddle()

Point LinkGraphOverlay::GetStationMiddle ( const Station st) const
protected

Determine the middle of a station in the current window.

Parameters
stThe station we're looking for.
Returns
Middle point of the station in the current window.

Definition at line 421 of file linkgraph_gui.cpp.

References GetSmallMapStationMiddle(), Window::viewport, and window.

Referenced by DrawLinks(), DrawStationDots(), and RebuildCache().

◆ GetWidgetDpi()

void LinkGraphOverlay::GetWidgetDpi ( DrawPixelInfo dpi) const
protected

Get a DPI for the widget we will be drawing to.

Parameters
dpiDrawPixelInfo to fill with the desired dimensions.

Definition at line 60 of file linkgraph_gui.cpp.

References NWidgetBase::current_x, NWidgetBase::current_y, Window::GetWidget(), widget_id, and window.

Referenced by RebuildCache().

◆ IsLinkVisible()

bool LinkGraphOverlay::IsLinkVisible ( Point  pta,
Point  ptb,
const DrawPixelInfo dpi,
int  padding = 0 
) const
inlineprotected

Determine if a certain link crosses through the area given by the dpi with some lee way.

Parameters
ptaFirst end of the link.
ptbSecond end of the link.
dpiVisible area.
paddingWidth or thickness of the link.
Returns
If the link or any of its "thickness" is visible. This may return false positives.

Definition at line 143 of file linkgraph_gui.cpp.

Referenced by DrawLinks(), and RebuildCache().

◆ IsPointVisible()

bool LinkGraphOverlay::IsPointVisible ( Point  pt,
const DrawPixelInfo dpi,
int  padding = 0 
) const
inlineprotected

Determine if a certain point is inside the given DPI, with some lee way.

Parameters
ptPoint we are looking for.
dpiVisible area.
paddingExtent of the point.
Returns
If the point or any of its 'extent' is inside the dpi.

Definition at line 128 of file linkgraph_gui.cpp.

Referenced by DrawStationDots(), and RebuildCache().

◆ RebuildCache()

◆ SetCargoMask()

void LinkGraphOverlay::SetCargoMask ( CargoTypes  cargo_mask)

Set a new cargo mask and rebuild the cache.

Parameters
cargo_maskNew cargo mask.

Definition at line 435 of file linkgraph_gui.cpp.

References cargo_mask, Window::GetWidget(), RebuildCache(), SetDirty(), widget_id, and window.

◆ SetCompanyMask()

void LinkGraphOverlay::SetCompanyMask ( CompanyMask  company_mask)

Set a new company mask and rebuild the cache.

Parameters
company_maskNew company mask.

Definition at line 446 of file linkgraph_gui.cpp.

References company_mask, Window::GetWidget(), RebuildCache(), SetDirty(), widget_id, and window.

◆ SetDirty()

void LinkGraphOverlay::SetDirty ( )
inline

Mark the linkgraph dirty to be rebuilt next time Draw() is called.

Definition at line 68 of file linkgraph_gui.h.

References dirty.

Referenced by SetCargoMask(), and SetCompanyMask().

◆ ShowTooltip()

bool LinkGraphOverlay::ShowTooltip ( Point  pt,
TooltipCloseCondition  close_cond 
)

Definition at line 359 of file linkgraph_gui.cpp.

Field Documentation

◆ cached_links

LinkMap LinkGraphOverlay::cached_links
protected

Cache for links to reduce recalculation.

Definition at line 81 of file linkgraph_gui.h.

Referenced by DrawLinks(), and RebuildCache().

◆ cached_stations

StationSupplyList LinkGraphOverlay::cached_stations
protected

Cache for stations to be drawn.

Definition at line 82 of file linkgraph_gui.h.

Referenced by DrawStationDots(), and RebuildCache().

◆ cargo_mask

CargoTypes LinkGraphOverlay::cargo_mask
protected

Bitmask of cargos to be displayed.

Definition at line 79 of file linkgraph_gui.h.

Referenced by AddLinks(), GetCargoMask(), RebuildCache(), and SetCargoMask().

◆ company_mask

CompanyMask LinkGraphOverlay::company_mask
protected

Bitmask of companies to be displayed.

Definition at line 80 of file linkgraph_gui.h.

Referenced by GetCompanyMask(), RebuildCache(), and SetCompanyMask().

◆ dirty

bool LinkGraphOverlay::dirty
protected

Set if overlay should be rebuilt.

Definition at line 84 of file linkgraph_gui.h.

Referenced by Draw(), and SetDirty().

◆ LINK_COLOURS

const uint8_t LinkGraphOverlay::LINK_COLOURS
static
Initial value:
= {
{
0x0f, 0xd1, 0xd0, 0x57,
0x55, 0x53, 0xbf, 0xbd,
0xba, 0xb9, 0xb7, 0xb5
},
{
0x0f, 0xd1, 0xd0, 0x57,
0x55, 0x53, 0x96, 0x95,
0x94, 0x93, 0x92, 0x91
},
{
0x0f, 0x0b, 0x09, 0x07,
0x05, 0x03, 0xbf, 0xbd,
0xba, 0xb9, 0xb7, 0xb5
},
{
0x0f, 0x0b, 0x0a, 0x09,
0x08, 0x07, 0x06, 0x05,
0x04, 0x03, 0x02, 0x01
}
}

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().

◆ scale

uint LinkGraphOverlay::scale
protected

Width of link lines.

Definition at line 83 of file linkgraph_gui.h.

Referenced by DrawContent(), DrawLinks(), and DrawStationDots().

◆ widget_id

const WidgetID LinkGraphOverlay::widget_id
protected

ID of Widget in Window to be drawn to.

Definition at line 78 of file linkgraph_gui.h.

Referenced by GetWidgetDpi(), SetCargoMask(), and SetCompanyMask().

◆ window

Window* LinkGraphOverlay::window
protected

Window to be drawn into.

Definition at line 77 of file linkgraph_gui.h.

Referenced by GetStationMiddle(), GetWidgetDpi(), SetCargoMask(), and SetCompanyMask().


The documentation for this class was generated from the following files: