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 OnDropdownSelect (int widget, int index)
 A dropdown option associated to this window has been selected.
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.
Dimension cargo_textsize
 Size to hold any cargo text, as well as STR_INDUSTRY_CARGOES_SELECT_CARGO.
Dimension ind_textsize
 Size to hold any industry type text, as well as STR_INDUSTRY_CARGOES_SELECT_INDUSTRY.
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 2043 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 2505 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 2208 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 2226 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 2456 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 2144 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 2177 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, lengthof, and NUM_HOUSES.

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

References INVALID_CARGO.

Referenced by ComputeCargoDisplay(), and ComputeIndustryDisplay().

virtual void IndustryCargoesWindow::OnDropdownSelect ( int  widget,
int  index 
) [inline, virtual]

A dropdown option associated to this window has been selected.

Parameters:
widget the widget (button) that the dropdown is associated with.
index the element in the dropdown that is selected.

Reimplemented from Window.

Definition at line 2622 of file industry_gui.cpp.

References ComputeCargoDisplay(), ComputeIndustryDisplay(), WID_IC_CARGO_DROPDOWN, and WID_IC_IND_DROPDOWN.

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

References cargo_textsize, IndustrySpec::enabled, FONT_HEIGHT_NORMAL, CargoSpec::Get(), GetIndustrySpec(), GetStringBoundingBox(), HOR_TEXT_PADDING, ind_textsize, CargoSpec::IsValid(), max(), maxdim(), CargoSpec::name, IndustrySpec::name, NUM_INDUSTRYTYPES, 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 2441 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 2676 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 2265 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 2123 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 2244 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 2104 of file industry_gui.cpp.

References max(), WD_FRAMETEXT_LEFT, WID_IC_CARGO_DROPDOWN, WID_IC_IND_DROPDOWN, and WID_IC_PANEL.


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