# IndustryDirectoryWindow Class Reference

The list of industries. More...

Inheritance diagram for IndustryDirectoryWindow:

## Public Member Functions
| IndustryDirectoryWindow (const WindowDesc *desc, WindowNumber number)
virtual void | SetStringParameters (int widget) const
| Initialize string parameters for a widget.
virtual void | OnPaint ()
| The window must be repainted.
virtual void | DrawWidget (const Rect &r, int widget) const
| Draw the contents of a nested widget.
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 | 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 | OnResize ()
| Called after the window got resized.
virtual void | OnHundredthTick ()
| Called once every 100 (game) ticks.
virtual void | OnInvalidateData (int data)
| Some data on this window has become invalid.
## Protected Member Functions
void | BuildSortIndustriesList ()
| (Re)Build industries list
StringID | GetIndustryString (const Industry *i) const
| Get the StringID to draw and set the appropriate DParams.
## Static Protected Member Functions
static int | GetCargoTransportedPercentsIfValid (const Industry *i, uint id)
| Returns percents of cargo transported if industry produces this cargo, else -1.
static int | GetCargoTransportedSortValue (const Industry *i)
| Returns value representing industry's transported cargo percentage for industry sorting.
static int CDECL | IndustryNameSorter (const Industry *const *a, const Industry *const *b)
| Sort industries by name.
static int CDECL | IndustryTypeSorter (const Industry *const *a, const Industry *const *b)
| Sort industries by type and name.
static int CDECL | IndustryProductionSorter (const Industry *const *a, const Industry *const *b)
| Sort industries by production and name.
static int CDECL | IndustryTransportedCargoSorter (const Industry *const *a, const Industry *const *b)
| Sort industries by transported cargo and name.
## Protected Attributes
GUIIndustryList | industries
## Static Protected Attributes
static Listing | last_sorting = {false, 0}
static const Industry * | last_industry = NULL
static const StringID | sorter_names []
static GUIIndustryList::SortFunction *const | sorter_funcs []

## Detailed Description

The list of industries.

Definition at line 865 of file industry_gui.cpp.

## Member Function Documentation

virtual void IndustryDirectoryWindow::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 1039 of file industry_gui.cpp.

References Window::DrawSortButtonState(), DrawString(), Scrollbar::GetCapacity(), Scrollbar::GetPosition(), GUIList< T, F >::IsDescSortOrder(), SmallVector< T, S >::Length(), Window::resize, SBS_DOWN, SBS_UP, ResizeInfo::step_height, Window::vscroll, WD_FRAMERECT_LEFT, WD_FRAMERECT_RIGHT, and WD_FRAMERECT_TOP.

static int IndustryDirectoryWindow::GetCargoTransportedPercentsIfValid | ( | const Industry * | i,
|  | uint | id |
| ) |  |  | `[inline, static, protected]`

Returns percents of cargo transported if industry produces this cargo, else -1.

Parameters:

  | i | industry to check
  | id | cargo slot

Returns:
  percents of cargo transported, or -1 if industry doesn't use this cargo slot

Definition at line 905 of file industry_gui.cpp.

References CT_INVALID, Industry::last_month_pct_transported, lengthof, Industry::produced_cargo, and ToPercent8().

Referenced by GetCargoTransportedSortValue().

static int IndustryDirectoryWindow::GetCargoTransportedSortValue | ( | const Industry * | i | ) | `[inline, static, protected]`

Returns value representing industry's transported cargo percentage for industry sorting.

Parameters:

  | i | industry to check

Returns:
  value used for sorting

Definition at line 920 of file industry_gui.cpp.

References GetCargoTransportedPercentsIfValid(), and Swap().

Referenced by IndustryTransportedCargoSorter().

StringID IndustryDirectoryWindow::GetIndustryString | ( | const Industry * | i | ) | const`[inline, protected]`

Get the StringID to draw and set the appropriate DParams.

Parameters:

  | i | the industry to get the StringID of.

Returns:
  the StringID.

Definition at line 980 of file industry_gui.cpp.

References CST_DIR, CT_INVALID, GetAllCargoSuffixes(), GetIndustrySpec(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Industry::last_month_pct_transported, Industry::last_month_production, lengthof, Industry::produced_cargo, SetDParam(), SetDParamStr(), ToPercent8(), and Industry::type.

Referenced by UpdateWidgetSize().

virtual void IndustryDirectoryWindow::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 1100 of file industry_gui.cpp.

References _ctrl_pressed, Scrollbar::GetCapacity(), Scrollbar::GetPosition(), IsInsideMM(), SmallVector< T, S >::Length(), Window::resize, Window::SetDirty(), ShowDropDownMenu(), GUIList< T, F >::SortType(), ResizeInfo::step_height, GUIList< T, F >::ToggleSortOrder(), Window::vscroll, and WD_FRAMERECT_TOP.

virtual void IndustryDirectoryWindow::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 1129 of file industry_gui.cpp.

References BuildSortIndustriesList(), GUIList< T, F >::SetSortType(), and GUIList< T, F >::SortType().

virtual void IndustryDirectoryWindow::OnInvalidateData | ( | int | data | ) | `[inline, virtual]`

Some data on this window has become invalid.

Parameters:

  | data | information about the changed data.

Reimplemented from Window.

Definition at line 1148 of file industry_gui.cpp.

References BuildSortIndustriesList(), GUIList< T, F >::ForceRebuild(), and GUIList< T, F >::ForceResort().

virtual void IndustryDirectoryWindow::OnPaint | ( |  | ) | `[inline, virtual]`

The window must be repainted.

Note:
  This method should not change any state, it should only use drawing functions.

Reimplemented from Window.

Definition at line 1034 of file industry_gui.cpp.

References Window::DrawWidgets().

virtual void IndustryDirectoryWindow::OnResize | ( |  | ) | `[inline, virtual]`

Called after the window got resized.

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

Reimplemented from Window.

Definition at line 1137 of file industry_gui.cpp.

References Scrollbar::SetCapacityFromWidget(), and Window::vscroll.

virtual void IndustryDirectoryWindow::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 1029 of file industry_gui.cpp.

References SetDParam(), and GUIList< T, F >::SortType().

virtual void IndustryDirectoryWindow::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 1063 of file industry_gui.cpp.

References GetIndustryString(), GetStringBoundingBox(), INVALID_STRING_ID, SmallVector< T, S >::Length(), maxdim(), WD_FRAMERECT_BOTTOM, WD_FRAMERECT_LEFT, WD_FRAMERECT_RIGHT, WD_FRAMERECT_TOP, and WD_SORTBUTTON_ARROW_WIDTH.

## Field Documentation

GUIIndustryList::SortFunction *const IndustryDirectoryWindow::sorter_funcs`[static, protected]`

Initial value:

     {
      &IndustryNameSorter,
      &IndustryTypeSorter,
      &IndustryProductionSorter,
      &IndustryTransportedCargoSorter
    }

Definition at line 873 of file industry_gui.cpp.

const StringID IndustryDirectoryWindow::sorter_names`[static, protected]`

Initial value:

     {
      STR_SORT_BY_NAME,
      STR_SORT_BY_TYPE,
      STR_SORT_BY_PRODUCTION,
      STR_SORT_BY_TRANSPORTED,
      INVALID_STRING_ID
    }

Definition at line 872 of file industry_gui.cpp.

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

- src/industry_gui.cpp