# ReplaceVehicleWindow Class Reference

Window for the autoreplacing of vehicles. More...

Inheritance diagram for ReplaceVehicleWindow:

## Public Member Functions
| ReplaceVehicleWindow (const WindowDesc *desc, VehicleType vehicletype, GroupID id_g)
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.
virtual void | DrawWidget (const Rect &r, int widget) const
| Draw the contents of a nested widget.
virtual void | OnPaint ()
| The window must be repainted.
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 | OnInvalidateData (int data)
| Some data on this window has become invalid.
## Private Member Functions
bool | GenerateReplaceRailList (EngineID e, bool draw_left, bool show_engines)
| Figure out if an engine should be added to a list.
void | GenerateReplaceVehList (bool draw_left)
| Generate an engines list.
void | GenerateLists ()
| Generate the lists.
## Private Attributes
EngineID | sel_engine [2]
| Selected engine left and right.
GUIEngineList | engines [2]
| Left and right list of engines.
bool | replace_engines
| If `true`, engines are replaced, if `false`, wagons are replaced (only for trains).
bool | reset_sel_engine
| Also reset sel_engine while updating left and/or right (update_left and/or update_right) and no valid engine selected.
GroupID | sel_group
| Group selected to replace.
int | details_height
| Minimal needed height of the details panels (found so far).
RailType | sel_railtype
| Type of rail tracks selected.

## Detailed Description

Window for the autoreplacing of vehicles.

Definition at line 99 of file autoreplace_gui.cpp.

## Member Function Documentation

bool ReplaceVehicleWindow::GenerateReplaceRailList | ( | EngineID | e,
|  | bool | draw_left,
|  | bool | show_engines |
| ) |  |  | `[inline, private]`

Figure out if an engine should be added to a list.

Parameters:

  | e | The EngineID.
  | draw_left | If `true`, the left list is drawn (the engines specific to the railtype you selected).
  | show_engines | If `true`, the locomotives are drawn, else the wagons are drawn (never both).

Returns:
  `true` if the engine should be in the list (based on this check), else `false`.

Definition at line 114 of file autoreplace_gui.cpp.

References RAILVEH_WAGON.

Referenced by GenerateReplaceVehList().

void ReplaceVehicleWindow::GenerateReplaceVehList | ( | bool | draw_left | ) | `[inline, private]`

Generate an engines list.

Parameters:

  | draw_left | true if generating the left list, otherwise false

Definition at line 132 of file autoreplace_gui.cpp.

References SmallVector< T, S >::Append(), CheckAutoreplaceValidity(), SmallVector< T, S >::Clear(), EngineReplacementForCompany(), engines, EngList_Sort(), GenerateReplaceRailList(), GetGroupNumEngines(), replace_engines, sel_engine, sel_group, VEH_TRAIN, and Window::window_number.

Referenced by GenerateLists().

virtual void ReplaceVehicleWindow::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 231 of file autoreplace_gui.cpp.

References GetEngineListHeight(), GetRailTypeInfo(), GetStringBoundingBox(), Dimension::height, RailtypeInfo::label, maxdim(), RAILTYPE_BEGIN, RailtypeInfo::replace_text, SetDParam(), RailtypeInfo::strings, VEH_ROAD, WD_FRAMERECT_BOTTOM, WD_FRAMERECT_TOP, WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, Dimension::width, and Window::window_number.

virtual void ReplaceVehicleWindow::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 295 of file autoreplace_gui.cpp.

References SetDParam().

virtual void ReplaceVehicleWindow::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 314 of file autoreplace_gui.cpp.

References DrawEngineList(), DrawString(), EngineHasReplacementForCompany(), EngineReplacementForCompany(), Rect::left, min(), Rect::right, SA_CENTER, SetDParam(), Rect::top, WD_FRAMERECT_LEFT, WD_FRAMERECT_RIGHT, WD_FRAMERECT_TOP, WD_FRAMETEXT_LEFT, and WD_FRAMETEXT_RIGHT.

virtual void ReplaceVehicleWindow::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 348 of file autoreplace_gui.cpp.

References _company_colours, NWidgetBase::current_x, DrawVehiclePurchaseInfo(), EngineHasReplacementForCompany(), EngineReplacementForCompany(), GetRailTypeInfo(), max(), NWidgetBase::pos_x, NWidgetBase::pos_y, RailtypeInfo::replace_text, SetDParam(), RailtypeInfo::strings, VEH_TRAIN, WD_FRAMERECT_BOTTOM, WD_FRAMERECT_TOP, WD_FRAMETEXT_LEFT, and WD_FRAMETEXT_RIGHT.

virtual void ReplaceVehicleWindow::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 402 of file autoreplace_gui.cpp.

References CMD_CHANGE_COMPANY_SETTING, CMD_SET_AUTOREPLACE, DoCommandP(), GetCompanySettingIndex(), GetRailTypeInfo(), HasBit(), RailtypeInfo::label, RAILTYPE_BEGIN, RailtypeInfo::replace_text, ShowDropDownList(), RailtypeInfo::strings, and Point::y.

virtual void ReplaceVehicleWindow::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 466 of file autoreplace_gui.cpp.

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

Called after the window got resized.

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

Reimplemented from Window.

Definition at line 481 of file autoreplace_gui.cpp.

References MAT_COL_START, and MAT_ROW_START.

virtual void ReplaceVehicleWindow::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 490 of file autoreplace_gui.cpp.

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

- src/autoreplace_gui.cpp