OpenTTD
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes
LinkGraphOverlay Class Reference

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 (const Window *w, uint wid, uint32 cargo_mask, uint32 company_mask, uint scale)
 Create a link graph overlay for the specified window.
void RebuildCache ()
 Rebuild the cache and recalculate which links and stations to be shown.
void Draw (const DrawPixelInfo *dpi) const
 Draw the linkgraph overlay or some part of it, in the area given.
void SetCargoMask (uint32 cargo_mask)
 Set a new cargo mask and rebuild the cache.
void SetCompanyMask (uint32 company_mask)
 Set a new company mask and rebuild the cache.
uint32 GetCargoMask ()
 Get a bitmask of the currently shown cargoes.
uint32 GetCompanyMask ()
 Get a bitmask of the currently shown companies.

Static Public Attributes

static const uint8 LINK_COLOURS []
 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 DrawForwBackLinks (Point pta, StationID sta, Point ptb, StationID stb) const
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.

Static Protected Member Functions

static void AddStats (uint new_cap, uint new_usg, uint new_flow, 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

const Windowwindow
 Window to be drawn into.
const uint widget_id
 ID of Widget in Window to be drawn to.
uint32 cargo_mask
 Bitmask of cargos to be displayed.
uint32 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.

Detailed Description

Handles drawing of links into some window.

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

Definition at line 38 of file linkgraph_gui.h.

Constructor & Destructor Documentation

LinkGraphOverlay::LinkGraphOverlay ( const Window w,
uint  wid,
uint32  cargo_mask,
uint32  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 54 of file linkgraph_gui.h.

Member Function Documentation

void LinkGraphOverlay::AddLinks ( const Station from,
const Station to 
)
protected
void LinkGraphOverlay::AddStats ( uint  new_cap,
uint  new_usg,
uint  new_plan,
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 171 of file linkgraph_gui.cpp.

References LinkProperties::capacity, max(), LinkProperties::planned, LinkProperties::shared, and LinkProperties::usage.

Referenced by AddLinks().

void LinkGraphOverlay::Draw ( const DrawPixelInfo dpi) const

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

Parameters
dpiArea to be drawn to.

Definition at line 187 of file linkgraph_gui.cpp.

References DrawLinks(), and DrawStationDots().

Referenced by SmallMapWindow::DrawSmallMap().

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 217 of file linkgraph_gui.cpp.

References _colour_gradient, _settings_game, abs(), LinkProperties::capacity, lengthof, LINK_COLOURS, max(), min(), LinkProperties::planned, VehicleSettings::road_side, scale, LinkProperties::shared, LinkProperties::usage, and GameSettings::vehicle.

Referenced by 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 197 of file linkgraph_gui.cpp.

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

Referenced by Draw().

void LinkGraphOverlay::DrawStationDots ( const DrawPixelInfo dpi) const
protected
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.
sizeY and y extend of the vertex.
colourColour with which the vertex will be filled.
border_colourColour for the border of the vertex.

Definition at line 266 of file linkgraph_gui.cpp.

References GfxFillRect().

Referenced by DrawStationDots().

uint32 LinkGraphOverlay::GetCargoMask ( )
inline

Get a bitmask of the currently shown cargoes.

Definition at line 64 of file linkgraph_gui.h.

References cargo_mask.

Referenced by MainWindow::OnTick(), and LinkGraphLegendWindow::SetOverlay().

uint32 LinkGraphOverlay::GetCompanyMask ( )
inline

Get a bitmask of the currently shown companies.

Definition at line 67 of file linkgraph_gui.h.

References company_mask.

Referenced by SmallMapWindow::OnTick(), MainWindow::OnTick(), and LinkGraphLegendWindow::SetOverlay().

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 287 of file linkgraph_gui.cpp.

References Window::viewport, and window.

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

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 41 of file linkgraph_gui.cpp.

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

Referenced by RebuildCache().

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 126 of file linkgraph_gui.cpp.

Referenced by DrawLinks(), and RebuildCache().

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 111 of file linkgraph_gui.cpp.

Referenced by DrawStationDots(), and RebuildCache().

void LinkGraphOverlay::SetCargoMask ( uint32  cargo_mask)

Set a new cargo mask and rebuild the cache.

Parameters
cargo_maskNew cargo mask.

Definition at line 301 of file linkgraph_gui.cpp.

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

Referenced by SmallMapWindow::SetOverlayCargoMask(), and LinkGraphLegendWindow::UpdateOverlayCargoes().

void LinkGraphOverlay::SetCompanyMask ( uint32  company_mask)

Set a new company mask and rebuild the cache.

Parameters
company_maskNew company mask.

Definition at line 312 of file linkgraph_gui.cpp.

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

Referenced by SmallMapWindow::OnTick(), and LinkGraphLegendWindow::UpdateOverlayCompanies().

Field Documentation

const uint8 LinkGraphOverlay::LINK_COLOURS
static
Initial value:
{
0x0f, 0xd1, 0xd0, 0x57,
0x55, 0x53, 0xbf, 0xbd,
0xba, 0xb9, 0xb7, 0xb5
}

Colours for the various "load" states of links.

Ordered from "unused" to "overloaded".

Definition at line 44 of file linkgraph_gui.h.

Referenced by BuildLinkStatsLegend(), DrawContent(), and LinkGraphLegendWindow::DrawWidget().


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