Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes

# BuildBridgeWindow Class Reference

Window class for handling the bridge-build GUI. More...

Inheritance diagram for BuildBridgeWindow:

## Public Member Functions
| BuildBridgeWindow (const WindowDesc *desc, TileIndex start, TileIndex end, uint32 br_type, GUIBridgeList *bl)
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 Point | OnInitialPosition (const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number)
| Compute the initial position of the window.
virtual void | DrawWidget (const Rect &r, int widget) const
| Draw the contents of a nested widget.
virtual EventState | OnKeyPress (uint16 key, uint16 keycode)
| A key has been pressed.
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.
## Private Member Functions
void | BuildBridge (uint8 i)
void | SortBridgeList ()
| Sort the builable bridges.
## Static Private Member Functions
static int CDECL | BridgeIndexSorter (const BuildBridgeData *a, const BuildBridgeData *b)
| Sort the bridges by their index.
static int CDECL | BridgePriceSorter (const BuildBridgeData *a, const BuildBridgeData *b)
| Sort the bridges by their price.
static int CDECL | BridgeSpeedSorter (const BuildBridgeData *a, const BuildBridgeData *b)
| Sort the bridges by their maximum speed.
## Private Attributes
TileIndex | start_tile
TileIndex | end_tile
uint32 | type
GUIBridgeList * | bridges
int | bridgetext_offset
| Horizontal offset of the text describing the bridge properties in WID_BBS_BRIDGE_LIST relative to the left edge.
Scrollbar * | vscroll
## Static Private Attributes
static uint16 | last_size = 4
| Last size of the bridge GUI window.
static Listing | last_sorting = {true, 2}
| Last setting of the sort.
static const StringID | sorter_names []
| Names of the sorting functions.
static GUIBridgeList::SortFunction *const | sorter_funcs []
| Available bridge sorting functions.

## Detailed Description

Window class for handling the bridge-build GUI.

Definition at line 76 of file bridge_gui.cpp.

## Member Function Documentation

virtual void BuildBridgeWindow::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 226 of file bridge_gui.cpp.

References Window::DrawSortButtonState(), DrawSprite(), DrawStringMultiLine(), SmallVector< T, S >::Get(), Scrollbar::GetPosition(), GetSpriteSize(), GUIList< T, F >::IsDescSortOrder(), Scrollbar::IsVisible(), SmallVector< T, S >::Length(), BridgeSpec::material, BridgeSpec::pal, Window::resize, SBS_DOWN, SetDParam(), BridgeSpec::speed, BridgeSpec::sprite, ResizeInfo::step_height, WD_MATRIX_LEFT, WID_BBS_BRIDGE_LIST, and WID_BBS_DROPDOWN_ORDER.

virtual void BuildBridgeWindow::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 264 of file bridge_gui.cpp.

References Scrollbar::GetScrolledRowFromWidget(), SmallVector< T, S >::Length(), Window::SetDirty(), ShowDropDownMenu(), sorter_names, GUIList< T, F >::SortType(), GUIList< T, F >::ToggleSortOrder(), WID_BBS_BRIDGE_LIST, WID_BBS_DROPDOWN_CRITERIA, and WID_BBS_DROPDOWN_ORDER.

virtual void BuildBridgeWindow::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 288 of file bridge_gui.cpp.

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

virtual Point BuildBridgeWindow::OnInitialPosition | ( | const WindowDesc * | desc,
|  | int16 | sm_width,
|  | int16 | sm_height,
|  | int | window_number |
| ) |  |  | `[inline, virtual]`

Compute the initial position of the window.

Parameters:

  | *desc | The pointer to the WindowDesc of the window to create.
  | sm_width | Smallest width of the window.
  | sm_height | Smallest height of the window.
  | window_number | The window number of the new window.

Returns:
  Initial position of the top-left corner of the window.

Reimplemented from Window.

Definition at line 216 of file bridge_gui.cpp.

References Clamp(), GetMainViewBottom(), GetMainViewTop(), NWidgetBase::pos_x, and NWidgetBase::pos_y.

virtual EventState BuildBridgeWindow::OnKeyPress | ( | uint16 | key,
|  | uint16 | keycode |
| ) |  |  | `[inline, virtual]`

A key has been pressed.

Parameters:

  | key | the Unicode value of the key.
  | keycode | the untranslated key code including shift state.

Returns:
  ES_HANDLED if the key press has been handled and no other window should receive the event.

Reimplemented from Window.

Definition at line 252 of file bridge_gui.cpp.

References SmallVector< T, S >::Length().

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

Called after the window got resized.

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

Reimplemented from Window.

Definition at line 297 of file bridge_gui.cpp.

References Scrollbar::GetCapacity(), last_size, MAT_COL_START, max(), Scrollbar::SetCapacityFromWidget(), and WID_BBS_BRIDGE_LIST.

virtual void BuildBridgeWindow::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 172 of file bridge_gui.cpp.

References bridgetext_offset, SmallVector< T, S >::Get(), GetSpriteSize(), GetStringBoundingBox(), INVALID_STRING_ID, SmallVector< T, S >::Length(), BridgeSpec::material, max(), maxdim(), SetDParam(), sorter_names, BridgeSpec::speed, BridgeSpec::sprite, WD_MATRIX_LEFT, WD_SORTBUTTON_ARROW_WIDTH, WID_BBS_BRIDGE_LIST, WID_BBS_DROPDOWN_CRITERIA, and WID_BBS_DROPDOWN_ORDER.

## Field Documentation

uint16 BuildBridgeWindow::last_size = 4`[static, private]`

Last size of the bridge GUI window.

Set the default size of the Build Bridge Window.

Definition at line 79 of file bridge_gui.cpp.

Referenced by OnResize().

Listing BuildBridgeWindow::last_sorting = {true, 2}`[static, private]`

Last setting of the sort.

Set the default sorting for the bridges.

Definition at line 80 of file bridge_gui.cpp.

GUIBridgeList::SortFunction *const BuildBridgeWindow::sorter_funcs`[static, private]`

Initial value:

     {
      &BridgeIndexSorter,
      &BridgePriceSorter,
      &BridgeSpeedSorter
    }

Available bridge sorting functions.

Definition at line 84 of file bridge_gui.cpp.

const StringID BuildBridgeWindow::sorter_names`[static, private]`

Initial value:

     {
      STR_SORT_BY_NUMBER,
      STR_SORT_BY_COST,
      STR_SORT_BY_MAX_SPEED,
      INVALID_STRING_ID
    }

Names of the sorting functions.

Definition at line 83 of file bridge_gui.cpp.

Referenced by OnClick(), SortBridgeList(), and UpdateWidgetSize().

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

- src/bridge_gui.cpp