# IndustryCargoesWindow Struct Reference

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

Inheritance diagram for IndustryCargoesWindow:

## 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 ICW_PANEL.
uint | ind_cargo
| If less than NUM_INDUSTRYTYPES, an industry type, else a cargo id + NUM_INDUSTRYTYPES.
Scrollbar * | vscroll
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:

- A CFT_HEADER is always at the top of an column of CFT_INDUSTRY fields.
- A CFT_CARGO_LABEL field is also always put in a column of CFT_INDUSTRY fields.
- The top row contains CFT_HEADER and CFT_SMALL_EMPTY fields.
- Cargo connections have a column of their own (CFT_CARGO fields).
- Cargo accepted or produced by an industry, but not carried in a cargo connection, is drawn in the space of a cargo column attached to the industry. The information however is part of the industry.

This results in the following invariants:

- Width of a CFT_INDUSTRY column is large enough to hold all industry type labels, all cargo labels, and all header texts.
- Height of a CFT_INDUSTRY is large enough to hold a header line, or a industry type line, `N` cargo labels (where `N` is the maximum number of cargoes connected between industries), `N` connections of cargo types, and space between two industry types (1/2 above it, and 1/2 underneath it).
- Width of a cargo field (CFT_CARGO) is large enough to hold `N` vertical columns (one for each type of cargo). Also, space is needed between an industry and the leftmost/rightmost column to draw the non-carried cargoes.
- Height of a CFT_CARGO field is equally high as the height of the CFT_INDUSTRY.
- A field at the top (CFT_HEADER or CFT_SMALL_EMPTY) match the width of the fields below them (CFT_INDUSTRY respectively CFT_CARGO), the height should be sufficient to display the header text.

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 2040 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 ICW_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 2482 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().

void IndustryCargoesWindow::ComputeCargoDisplay | ( | CargoID | cid | ) | `[inline]`

Compute what and where to display for cargo id cid.

Parameters:

  | cid | Cargo id to display.

Definition at line 2347 of file industry_gui.cpp.

References _displayed_industries, IndustrySpec::accepts_cargo, SmallVector< T, S >::Append(), CeilDiv(), CFT_EMPTY, CFT_SMALL_EMPTY, SmallVector< T, S >::Clear(), CargoesRow::columns, CountMatchingAcceptingIndustries(), CountMatchingProducingIndustries(), IndustrySpec::enabled, fields, GetIndustrySpec(), HasCommonValidCargo(), HousesCanAccept(), HousesCanSupply(), ind_cargo, lengthof, CargoesField::MakeCargo(), CargoesField::MakeEmpty(), CargoesField::MakeHeader(), max(), NotifySmallmap(), NUM_INDUSTRYTYPES, PlaceIndustry(), NWidgetBase::resize_y, SetBit(), Scrollbar::SetCount(), Window::SetDirty(), ShortenCargoColumn(), WD_FRAMETEXT_BOTTOM, and WD_FRAMETEXT_TOP.

Referenced by OnClick().

void IndustryCargoesWindow::ComputeIndustryDisplay | ( | IndustryType | it | ) | `[inline]`

Compute what and where to display for industry type it.

Parameters:

  | it | Industry type to display.

Definition at line 2269 of file industry_gui.cpp.

References _displayed_industries, IndustrySpec::accepts_cargo, SmallVector< T, S >::Append(), CeilDiv(), CFT_EMPTY, CFT_SMALL_EMPTY, SmallVector< T, S >::Clear(), CargoesRow::columns, CountMatchingAcceptingIndustries(), CountMatchingProducingIndustries(), IndustrySpec::enabled, fields, GetIndustrySpec(), HasCommonValidCargo(), HousesCanAccept(), HousesCanSupply(), ind_cargo, lengthof, CargoesField::MakeCargo(), CargoesField::MakeEmpty(), CargoesField::MakeHeader(), max(), NotifySmallmap(), NUM_INDUSTRYTYPES, PlaceIndustry(), NWidgetBase::resize_y, SetBit(), Scrollbar::SetCount(), Window::SetDirty(), ShortenCargoColumn(), WD_FRAMETEXT_BOTTOM, and WD_FRAMETEXT_TOP.

Referenced by OnClick(), and OnInvalidateData().

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 2185 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 2203 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 2433 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_BOTTOM, WD_FRAMERECT_LEFT, WD_FRAMERECT_TOP, 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 2121 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 2154 of file industry_gui.cpp.

References _settings_game, HouseSpec::accepts_cargo, HouseSpec::building_availability, HouseSpec::enabled, GameSettings::game_creation, HZ_SUBARTC_ABOVE, HZ_SUBARTC_BELOW, HZ_SUBTROPIC, HZ_TEMP, HZ_TOYLND, 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 2139 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 2521 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(), Window::ToggleWidgetLoweredState(), and CargoesField::type.

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 2567 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, and CargoesField::type.

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 2059 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_CARGO, NUM_INDUSTRYTYPES, SetDParam(), VERT_TEXT_PADDING, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, 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 2418 of file industry_gui.cpp.

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

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 2606 of file industry_gui.cpp.

References Scrollbar::SetCapacityFromWidget().

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 2242 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 2100 of file industry_gui.cpp.

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

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 2221 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 2091 of file industry_gui.cpp.

References WD_FRAMETEXT_LEFT, and WD_FRAMETEXT_RIGHT.

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

- src/industry_gui.cpp