Window displaying the cargo connections around an industry (or cargo). More...
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. | |
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. |
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:
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).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.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 2044 of file industry_gui.cpp.
bool IndustryCargoesWindow::CalculatePositionInWidget | ( | Point | pt, | |
Point * | fieldxy, | |||
Point * | xy | |||
) | [inline] |
Calculate in which field was clicked, and within the field, at what position.
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. |
Definition at line 2506 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.
void IndustryCargoesWindow::ComputeCargoDisplay | ( | CargoID | cid | ) | [inline] |
Compute what and where to display for cargo id cid.
cid | Cargo id to display. |
Definition at line 2371 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 OnDropdownSelect().
void IndustryCargoesWindow::ComputeIndustryDisplay | ( | IndustryType | it | ) | [inline] |
Compute what and where to display for industry type it.
it | Industry type to display. |
Definition at line 2293 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(), OnDropdownSelect(), 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.
cargoes | Cargoes to search. | |
length | Number of cargoes in cargoes. |
Definition at line 2209 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.
cargoes | Cargoes to search. | |
length | Number of cargoes in cargoes. |
Definition at line 2227 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.
r | Rectangle occupied by the widget. | |
widget | Number of the widget to draw. |
Reimplemented from Window.
Definition at line 2457 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?
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. |
Definition at line 2145 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?
cargoes | Base address of the cargo array. | |
length | Number of cargoes in the array. |
Definition at line 2178 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?
cargoes | Base address of the cargo array. | |
length | Number of cargoes in the array. |
Definition at line 2163 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.
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 2545 of file industry_gui.cpp.
References _settings_client, _sorted_industry_types, SmallVector< T, S >::Append(), CalculatePositionInWidget(), CargoesField::CargoClickedAt(), CargoesField::CargoLabelClickedAt(), CFT_CARGO, CFT_CARGO_LABEL, CFT_INDUSTRY, SoundSettings::click_beep, ComputeCargoDisplay(), ComputeIndustryDisplay(), IndustrySpec::enabled, fields, FindWindowByClass(), FOR_ALL_SORTED_STANDARD_CARGOSPECS, GetIndustrySpec(), ind_cargo, CargoSpec::Index(), CargoesField::industry, INVALID_CARGO, Window::IsWidgetLowered(), SmallVector< T, S >::Length(), IndustrySpec::name, CargoSpec::name, NotifySmallmap(), NUM_INDUSTRYTYPES, Window::SetWidgetDirty(), ShowDropDownList(), ShowSmallMap(), ClientSettings::sound, Window::ToggleWidgetLoweredState(), CargoesField::type, WC_SMALLMAP, WID_IC_CARGO_DROPDOWN, WID_IC_IND_DROPDOWN, WID_IC_NOTIFY, and WID_IC_PANEL.
virtual void IndustryCargoesWindow::OnDropdownSelect | ( | int | widget, | |
int | index | |||
) | [inline, virtual] |
A dropdown option associated to this window has been selected.
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 2623 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.
pt | The point where the mouse is hovering. | |
widget | The widget where the mouse is hovering. |
Reimplemented from Window.
Definition at line 2638 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.
Reimplemented from Window.
Definition at line 2064 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.
data | Information about the changed data.
| |
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 2442 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 2677 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.
row | Row of the new industry. | |
col | Column of the new industry. | |
it | Industry to place. |
Definition at line 2266 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.
widget | Widget number. |
Reimplemented from Window.
Definition at line 2124 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.
column | Column number of the cargo column. | |
top | Current top row. | |
bottom | Current bottom row. |
Definition at line 2245 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.
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 2105 of file industry_gui.cpp.
References max(), WD_FRAMETEXT_LEFT, WID_IC_CARGO_DROPDOWN, WID_IC_IND_DROPDOWN, and WID_IC_PANEL.