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::list< std::pair < StationID, uint > > | StationSupplyList |
Public Member Functions | |
LinkGraphOverlay (const Window *w, uint wid, uint32 cargo_mask=0xFFFFFFFF, uint32 company_mask=1<< _local_company, uint scale=1) | |
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, 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 Window * | window |
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. |
Handles drawing of links into some window.
The window must either be a smallmap or have a valid viewport.
Definition at line 37 of file linkgraph_gui.h.
LinkGraphOverlay::LinkGraphOverlay | ( | const Window * | w, | |
uint | wid, | |||
uint32 | cargo_mask = 0xFFFFFFFF | |||
) | [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 53 of file linkgraph_gui.h.
Add all "interesting" links between the given stations to the cache.
from | The source station. | |
to | The destination station. |
Definition at line 136 of file linkgraph_gui.cpp.
References AddStats(), LinkGraph::ConstNode::Begin(), cached_links, LinkGraph::EdgeWrapper< Tedge >::Capacity(), cargo_mask, LinkGraph::ConstNode::End(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_pool >::Get(), CargoSpec::Get(), GoodsEntry::GetSumFlowVia(), Station::goods, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_pool >::IsValidID(), GoodsEntry::link_graph, LinkGraph::Monthly(), GoodsEntry::node, and LinkGraph::EdgeWrapper< Tedge >::Usage().
Referenced by RebuildCache().
void LinkGraphOverlay::AddStats | ( | uint | new_cap, | |
uint | new_usg, | |||
uint | new_plan, | |||
LinkProperties & | cargo | |||
) | [static, protected] |
Add information from a given pair of link stat and flow stat to the given link properties.
orig_link | Link stat to read the information from. | |
new_plan | Planned flow for the link. | |
cargo | LinkProperties to write the information to. |
Definition at line 160 of file linkgraph_gui.cpp.
References LinkProperties::capacity, max(), LinkProperties::planned, 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.
dpi | Area to be drawn to. |
Definition at line 175 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.
pta | Source of the link. | |
ptb | Destination of the link. | |
cargo | Properties of the link. |
Definition at line 205 of file linkgraph_gui.cpp.
References _colour_gradient, LinkProperties::capacity, lengthof, LINK_COLOURS, max(), min(), LinkProperties::planned, scale, and LinkProperties::usage.
Referenced by DrawLinks().
void LinkGraphOverlay::DrawLinks | ( | const DrawPixelInfo * | dpi | ) | const [protected] |
Draw the cached links or part of them into the given area.
dpi | Area to be drawn to. |
Definition at line 185 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] |
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 223 of file linkgraph_gui.cpp.
References _colour_gradient, cached_stations, DrawVertex(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), SpecializedStation< Station, false >::GetIfValid(), GetStationMiddle(), IsPointVisible(), min(), BaseStation::owner, OWNER_NONE, and scale.
Referenced by Draw().
void LinkGraphOverlay::DrawVertex | ( | int | x, | |
int | y, | |||
int | size, | |||
int | colour, | |||
int | border_colour | |||
) | [static, protected] |
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 | Y and y extend of the vertex. | |
colour | Colour with which the vertex will be filled. | |
border_colour | Colour for the border of the vertex. |
Definition at line 248 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 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 LinkGraphLegendWindow::SetOverlay().
Determine the middle of a station in the current window.
st | The station we're looking for. |
Definition at line 269 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.
dpi | DrawPixelInfo to fill with the desired dimensions. |
Definition at line 39 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 [inline, protected] |
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 121 of file linkgraph_gui.cpp.
Referenced by DrawLinks(), and RebuildCache().
bool LinkGraphOverlay::IsPointVisible | ( | Point | pt, | |
const DrawPixelInfo * | dpi, | |||
int | padding = 0 | |||
) | const [inline, protected] |
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 106 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.
cargo_mask | New cargo mask. |
Definition at line 282 of file linkgraph_gui.cpp.
References 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.
company_mask | New company mask. |
Definition at line 293 of file linkgraph_gui.cpp.
References Window::GetWidget(), RebuildCache(), widget_id, and window.
Referenced by LinkGraphLegendWindow::UpdateOverlayCompanies().
const uint8 LinkGraphOverlay::LINK_COLOURS [static] |
{ 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 43 of file linkgraph_gui.h.
Referenced by BuildLinkStatsLegend(), DrawContent(), and LinkGraphLegendWindow::DrawWidget().