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) |
Notify the window about external events. | |
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. |
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 2018 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 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. |
Definition at line 2458 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 2325 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.
it | Industry type to display. |
Definition at line 2247 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.
cargoes | Cargoes to search. | |
length | Number of cargoes in cargoes. |
Definition at line 2163 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 2181 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 2409 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?
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 2099 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 2132 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?
cargoes | Base address of the cargo array. | |
length | Number of cargoes in the array. |
Definition at line 2117 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 2497 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.
pt | The point where the mouse is hovering. | |
widget | The widget where the mouse is hovering. |
Reimplemented from Window.
Definition at line 2543 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.
Reimplemented from Window.
Definition at line 2037 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 | ) | [inline, virtual] |
Notify the window about external events.
data | The event. |
Reimplemented from Window.
Definition at line 2395 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 2582 of file industry_gui.cpp.
References Scrollbar::SetCapacityFromWidget().
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 2220 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 2078 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.
column | Column number of the cargo column. | |
top | Current top row. | |
bottom | Current bottom row. |
Definition at line 2199 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 2069 of file industry_gui.cpp.
References WD_FRAMETEXT_LEFT, and WD_FRAMETEXT_RIGHT.