Public Types | Public Member Functions | Static Public Member Functions | Data Fields | Static Public Attributes

IndustryCargoesWindow Struct Reference

Window displaying the cargo connections around an industry (or cargo). More...

Inheritance diagram for IndustryCargoesWindow:
Window ZeroedMemoryAllocator

Public Types

typedef SmallVector
< CargoesRow, 4 > 
Fields

Public Member Functions

 IndustryCargoesWindow (int id)
virtual void OnInit ()
 Notification that the nested widget tree gets initialized.
virtual void UpdateWidgetSize (int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 Update size and resize step of a widget in the window.
virtual void SetStringParameters (int widget) const
 Initialize string parameters for a widget.
void ShortenCargoColumn (int column, int top, int bottom)
 Shorten the cargo column to just the part between industries.
void PlaceIndustry (int row, int col, IndustryType it)
 Place an industry in the fields.
void NotifySmallmap ()
 Notify smallmap that new displayed industries have been selected (in _displayed_industries).
void ComputeIndustryDisplay (IndustryType it)
 Compute what and where to display for industry type it.
void ComputeCargoDisplay (CargoID cid)
 Compute what and where to display for cargo id cid.
virtual void OnInvalidateData (int data=0, bool gui_scope=true)
 Some data on this window has become invalid.
virtual void DrawWidget (const Rect &r, int widget) const
 Draw the contents of a nested widget.
bool CalculatePositionInWidget (Point pt, Point *fieldxy, Point *xy)
 Calculate in which field was clicked, and within the field, at what position.
virtual void OnClick (Point pt, int widget, int click_count)
 A click with the left mouse button has been made on the window.
virtual void OnHover (Point pt, int widget)
 The mouse is hovering over a widget in the window, perform an action for it, like opening a custom tooltip.
virtual void OnResize ()
 Called after the window got resized.

Static Public Member Functions

static bool HasCommonValidCargo (const CargoID *cargoes1, uint length1, const CargoID *cargoes2, uint length2)
 Do the two sets of cargoes have a valid cargo in common?
static bool HousesCanSupply (const CargoID *cargoes, uint length)
 Can houses be used to supply one of the cargoes?
static bool HousesCanAccept (const CargoID *cargoes, uint length)
 Can houses be used as customers of the produced cargoes?
static int CountMatchingAcceptingIndustries (const CargoID *cargoes, uint length)
 Count how many industries have accepted cargoes in common with one of the supplied set.
static int CountMatchingProducingIndustries (const CargoID *cargoes, uint length)
 Count how many industries have produced cargoes in common with one of the supplied set.

Data Fields

Fields fields
 Fields to display in the WID_IC_PANEL.
uint ind_cargo
 If less than NUM_INDUSTRYTYPES, an industry type, else a cargo id + NUM_INDUSTRYTYPES.
Scrollbarvscroll
CargoesFieldType type
 Type of field.

Static Public Attributes

static const int HOR_TEXT_PADDING = 5
 Horizontal padding around the industry type text.
static const int VERT_TEXT_PADDING = 5
 Vertical padding around the industry type text.

Detailed Description

Window displaying the cargo connections around an industry (or cargo).

The main display is constructed from 'fields', rectangles that contain an industry, piece of the cargo connection, cargo labels, or headers. For a nice display, the following should be kept in mind:

This results in the following invariants:

When displaying the cargoes around an industry type, five columns are needed (supplying industries, accepted cargoes, the industry, produced cargoes, customer industries). Displaying the industries around a cargo needs three columns (supplying industries, the cargo, customer industries). The remaining two columns are set to CFT_EMPTY with a width equal to the average of a cargo and an industry column.

Definition at line 2020 of file industry_gui.cpp.


Member Function Documentation

bool IndustryCargoesWindow::CalculatePositionInWidget ( Point  pt,
Point fieldxy,
Point xy 
) [inline]

Calculate in which field was clicked, and within the field, at what position.

Parameters:
pt Clicked position in the WID_IC_PANEL widget.
fieldxy If true is returned, field x/y coordinate of pt.
xy If true is returned, x/y coordinate with in the field.
Returns:
Clicked at a valid position.

Definition at line 2462 of file industry_gui.cpp.

References _current_text_dir, fields, Scrollbar::GetPosition(), ind_cargo, SmallVector< T, S >::Length(), NUM_INDUSTRYTYPES, NWidgetBase::pos_x, NWidgetBase::pos_y, NWidgetBase::resize_y, TD_RTL, WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, and Window::width.

Referenced by OnClick(), and OnHover().

static int IndustryCargoesWindow::CountMatchingAcceptingIndustries ( const CargoID cargoes,
uint  length 
) [inline, static]

Count how many industries have accepted cargoes in common with one of the supplied set.

Parameters:
cargoes Cargoes to search.
length Number of cargoes in cargoes.
Returns:
Number of industries that have an accepted cargo in common with the supplied set.

Definition at line 2165 of file industry_gui.cpp.

References IndustrySpec::accepts_cargo, IndustrySpec::enabled, GetIndustrySpec(), HasCommonValidCargo(), lengthof, and NUM_INDUSTRYTYPES.

Referenced by ComputeCargoDisplay(), and ComputeIndustryDisplay().

static int IndustryCargoesWindow::CountMatchingProducingIndustries ( const CargoID cargoes,
uint  length 
) [inline, static]

Count how many industries have produced cargoes in common with one of the supplied set.

Parameters:
cargoes Cargoes to search.
length Number of cargoes in cargoes.
Returns:
Number of industries that have a produced cargo in common with the supplied set.

Definition at line 2183 of file industry_gui.cpp.

References IndustrySpec::enabled, GetIndustrySpec(), HasCommonValidCargo(), lengthof, and NUM_INDUSTRYTYPES.

Referenced by ComputeCargoDisplay(), and ComputeIndustryDisplay().

virtual void IndustryCargoesWindow::DrawWidget ( const Rect r,
int  widget 
) const [inline, virtual]

Draw the contents of a nested widget.

Parameters:
r Rectangle occupied by the widget.
widget Number of the widget to draw.
Note:
This method may not change any state, it may only use drawing functions.

Reimplemented from Window.

Definition at line 2413 of file industry_gui.cpp.

References _current_text_dir, fields, FillDrawPixelInfo(), Scrollbar::GetPosition(), Window::height, ind_cargo, SmallVector< T, S >::Length(), NUM_INDUSTRYTYPES, NWidgetBase::resize_y, TD_RTL, WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, WID_IC_PANEL, and Window::width.

static bool IndustryCargoesWindow::HasCommonValidCargo ( const CargoID cargoes1,
uint  length1,
const CargoID cargoes2,
uint  length2 
) [inline, static]

Do the two sets of cargoes have a valid cargo in common?

Parameters:
cargoes1 Base address of the first cargo array.
length1 Number of cargoes in the first cargo array.
cargoes2 Base address of the second cargo array.
length2 Number of cargoes in the second cargo array.
Returns:
Arrays have at least one valid cargo in common.

Definition at line 2101 of file industry_gui.cpp.

References INVALID_CARGO.

Referenced by ComputeCargoDisplay(), ComputeIndustryDisplay(), CountMatchingAcceptingIndustries(), and CountMatchingProducingIndustries().

static bool IndustryCargoesWindow::HousesCanAccept ( const CargoID cargoes,
uint  length 
) [inline, static]

Can houses be used as customers of the produced cargoes?

Parameters:
cargoes Base address of the cargo array.
length Number of cargoes in the array.
Returns:
Houses can accept at least one of the cargoes.

Definition at line 2134 of file industry_gui.cpp.

References _settings_game, HouseSpec::accepts_cargo, HouseSpec::building_availability, HouseSpec::enabled, GameSettings::game_creation, HZ_SUBARTC_ABOVE, INVALID_CARGO, GameCreationSettings::landscape, and lengthof.

Referenced by ComputeCargoDisplay(), and ComputeIndustryDisplay().

static bool IndustryCargoesWindow::HousesCanSupply ( const CargoID cargoes,
uint  length 
) [inline, static]

Can houses be used to supply one of the cargoes?

Parameters:
cargoes Base address of the cargo array.
length Number of cargoes in the array.
Returns:
Houses can supply at least one of the cargoes.

Definition at line 2119 of file industry_gui.cpp.

References INVALID_CARGO.

Referenced by ComputeCargoDisplay(), and ComputeIndustryDisplay().

virtual void IndustryCargoesWindow::OnClick ( Point  pt,
int  widget,
int  click_count 
) [inline, virtual]

A click with the left mouse button has been made on the window.

Parameters:
pt the point inside the window that has been clicked.
widget the clicked widget.
click_count Number of fast consecutive clicks at same position

Reimplemented from Window.

Definition at line 2501 of file industry_gui.cpp.

References CalculatePositionInWidget(), CargoesField::CargoClickedAt(), CargoesField::CargoLabelClickedAt(), CFT_CARGO, CFT_CARGO_LABEL, CFT_INDUSTRY, ComputeCargoDisplay(), ComputeIndustryDisplay(), fields, FindWindowByClass(), CargoesField::industry, INVALID_CARGO, Window::IsWidgetLowered(), NotifySmallmap(), NUM_INDUSTRYTYPES, Window::SetWidgetDirty(), ShowSmallMap(), Window::ToggleWidgetLoweredState(), CargoesField::type, WC_SMALLMAP, WID_IC_NOTIFY, and WID_IC_PANEL.

virtual void IndustryCargoesWindow::OnHover ( Point  pt,
int  widget 
) [inline, virtual]

The mouse is hovering over a widget in the window, perform an action for it, like opening a custom tooltip.

Parameters:
pt The point where the mouse is hovering.
widget The widget where the mouse is hovering.

Reimplemented from Window.

Definition at line 2547 of file industry_gui.cpp.

References CalculatePositionInWidget(), CargoesField::CargoClickedAt(), CargoesField::CargoLabelClickedAt(), CFT_CARGO, CFT_CARGO_LABEL, CFT_INDUSTRY, fields, CargoSpec::Get(), GuiShowTooltips(), ind_cargo, CargoesField::industry, INVALID_CARGO, CargoSpec::name, NUM_INDUSTRYTYPES, CargoesField::type, and WID_IC_PANEL.

virtual void IndustryCargoesWindow::OnInit (  )  [inline, virtual]

Notification that the nested widget tree gets initialized.

The event can be used to perform general computations.

Note:
nested_root and/or nested_array (normally accessed via GetWidget()) may not exist during this call.

Reimplemented from Window.

Definition at line 2039 of file industry_gui.cpp.

References IndustrySpec::enabled, FONT_HEIGHT_NORMAL, CargoSpec::Get(), GetIndustrySpec(), GetStringBoundingBox(), HOR_TEXT_PADDING, CargoSpec::IsValid(), max(), maxdim(), CargoSpec::name, IndustrySpec::name, NUM_INDUSTRYTYPES, SetDParam(), VERT_TEXT_PADDING, WD_FRAMETEXT_LEFT, and WD_FRAMETEXT_TOP.

virtual void IndustryCargoesWindow::OnInvalidateData ( int  data = 0,
bool  gui_scope = true 
) [inline, virtual]

Some data on this window has become invalid.

Parameters:
data Information about the changed data.

  • data = 0 .. NUM_INDUSTRYTYPES - 1: Display the chain around the given industry.
  • data = NUM_INDUSTRYTYPES: Stop sending updates to the smallmap window.
gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See InvalidateWindowData() for details.

Reimplemented from Window.

Definition at line 2398 of file industry_gui.cpp.

References ComputeIndustryDisplay(), Window::IsWidgetLowered(), NUM_INDUSTRYTYPES, Window::RaiseWidget(), Window::SetWidgetDirty(), and WID_IC_NOTIFY.

virtual void IndustryCargoesWindow::OnResize (  )  [inline, virtual]

Called after the window got resized.

For nested windows with a viewport, call NWidgetViewport::UpdateViewportCoordinates.

Reimplemented from Window.

Definition at line 2586 of file industry_gui.cpp.

References Scrollbar::SetCapacityFromWidget(), and WID_IC_PANEL.

void IndustryCargoesWindow::PlaceIndustry ( int  row,
int  col,
IndustryType  it 
) [inline]

Place an industry in the fields.

Parameters:
row Row of the new industry.
col Column of the new industry.
it Industry to place.

Definition at line 2222 of file industry_gui.cpp.

References CFT_EMPTY, fields, and type.

Referenced by ComputeCargoDisplay(), and ComputeIndustryDisplay().

virtual void IndustryCargoesWindow::SetStringParameters ( int  widget  )  const [inline, virtual]

Initialize string parameters for a widget.

Calls to this function are made during initialization to measure the size (that is as part of InitNested()), during drawing, and while re-initializing the window. Only for widgets that render text initializing is requested.

Parameters:
widget Widget number.

Reimplemented from Window.

Definition at line 2080 of file industry_gui.cpp.

References CargoSpec::Get(), GetIndustrySpec(), ind_cargo, CargoSpec::name, IndustrySpec::name, NUM_INDUSTRYTYPES, SetDParam(), and WID_IC_CAPTION.

void IndustryCargoesWindow::ShortenCargoColumn ( int  column,
int  top,
int  bottom 
) [inline]

Shorten the cargo column to just the part between industries.

Parameters:
column Column number of the cargo column.
top Current top row.
bottom Current bottom row.

Definition at line 2201 of file industry_gui.cpp.

References CFT_EMPTY, and fields.

Referenced by ComputeCargoDisplay(), and ComputeIndustryDisplay().

virtual void IndustryCargoesWindow::UpdateWidgetSize ( int  widget,
Dimension size,
const Dimension padding,
Dimension fill,
Dimension resize 
) [inline, virtual]

Update size and resize step of a widget in the window.

After retrieval of the minimal size and the resize-steps of a widget, this function is called to allow further refinement, typically by computing the real maximal size of the content. Afterwards, size is taken to be the minimal size of the widget and resize is taken to contain the resize steps. For the convenience of the callee, padding contains the amount of padding between the content and the edge of the widget. This should be added to the returned size.

Parameters:
widget Widget number.
size Size of the widget.
padding Recommended amount of space between the widget content and the widget edge.
fill Fill step of the widget.
resize Resize step of the widget.

Reimplemented from Window.

Definition at line 2071 of file industry_gui.cpp.

References WD_FRAMETEXT_LEFT, and WID_IC_PANEL.


The documentation for this struct was generated from the following file: