# train_gui.cpp File Reference

GUI for trains. More...

`#include "stdafx.h"`
`#include "window_gui.h"`
`#include "gfx_func.h"`
`#include "command_func.h"`
`#include "vehicle_gui.h"`
`#include "train.h"`
`#include "strings_func.h"`
`#include "vehicle_func.h"`
`#include "engine_base.h"`
`#include "window_func.h"`
`#include "settings_type.h"`
`#include "table/sprites.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Data Structures
struct | CargoSummaryItem
| Helper struct for the cargo details information. More...
## Typedefs
typedef SmallVector < CargoSummaryItem, 2 > | CargoSummary
| Container for the cargo summary information.
## Enumerations
enum | { TRAIN_DETAILS_MIN_INDENT = 32, TRAIN_DETAILS_MAX_INDENT = 72 }
## Functions
void | CcBuildWagon (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
void | DrawTrainImage (const Train *v, int left, int right, int y, VehicleID selection, int skip)
| Draws an image of a whole train.
static void | TrainDetailsCargoTab (const CargoSummaryItem *item, int left, int right, int y)
| Draw the details cargo tab for the given vehicle at the given position.
static void | TrainDetailsInfoTab (const Vehicle *v, int left, int right, int y)
| Draw the details info tab for the given vehicle at the given position.
static void | TrainDetailsCapacityTab (const CargoSummaryItem *item, int left, int right, int y)
| Draw the details capacity tab for the given vehicle at the given position.
static void | GetCargoSummaryOfArticulatedVehicle (const Train *v, CargoSummary *summary)
| Collects the cargo transportet.
static uint | GetLengthOfArticulatedVehicle (const Train *v)
| Get the length of an articulated vehicle.
int | GetTrainDetailsWndVScroll (VehicleID veh_id, TrainDetailsWindowTabs det_tab)
| Determines the number of lines in the train details window.
void | DrawTrainDetails (const Train *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab)
| Draw the details for the given vehicle at the given position.
## Variables
static CargoSummary | _cargo_summary
| Reused container of cargo details.

## Detailed Description

GUI for trains.

Definition in file train_gui.cpp.

## Typedef Documentation

typedef SmallVector<CargoSummaryItem, 2> CargoSummary

Container for the cargo summary information.

Definition at line 135 of file train_gui.cpp.

## Enumeration Type Documentation

anonymous enum

Enumerator:

  TRAIN_DETAILS_MIN_INDENT | Minimum indent level in the train details window.
  TRAIN_DETAILS_MAX_INDENT | Maximum indent level in the train details window; wider than this and we start on a new line.

Definition at line 129 of file train_gui.cpp.

## Function Documentation

void DrawTrainDetails | ( | const Train * | v,
|  | int | left,
|  | int | right,
|  | int | y,
|  | int | vscroll_pos,
|  | uint16 | vscroll_cap,
|  | TrainDetailsWindowTabs | det_tab |
| ) |  |  |

Draw the details for the given vehicle at the given position.

Parameters:

  | v | current vehicle
  | left | The left most coordinate to draw
  | right | The right most coordinate to draw
  | y | The y coordinate
  | vscroll_pos | Position of scrollbar
  | vscroll_cap | Number of lines currently displayed
  | det_tab | Selected details tab

Definition at line 297 of file train_gui.cpp.

References _colour_gradient, _dynlang, _settings_game, DIR_E, DIR_W, DrawSprite(), DrawString(), FONT_HEIGHT_NORMAL, VehicleSettings::freight_trains, FreightWagonMult(), GetCargoSummaryOfArticulatedVehicle(), Train::GetDisplayImageWidth(), Train::GetImage(), Train::GetNextVehicle(), GetVehiclePalette(), GfxFillRect(), Train::IsArticulatedPart(), SmallVector< T, S >::Length(), max(), SpecializedVehicle< T, Type >::Next(), NUM_CARGO, SetDParam(), TD_RTL, TDW_TAB_CAPACITY, TDW_TAB_CARGO, TDW_TAB_INFO, TDW_TAB_TOTALS, DynamicLanguages::text_dir, TRAIN_DETAILS_MAX_INDENT, TRAIN_DETAILS_MIN_INDENT, TrainDetailsCapacityTab(), TrainDetailsCargoTab(), TrainDetailsInfoTab(), GameSettings::vehicle, Vehicle::vehstatus, WD_MATRIX_BOTTOM, and WD_MATRIX_TOP.

Referenced by VehicleDetailsWindow::DrawVehicleDetails().

void DrawTrainImage | ( | const Train * | v,
|  | int | left,
|  | int | right,
|  | int | y,
|  | VehicleID | selection,
|  | int | skip |
| ) |  |  |

Draws an image of a whole train.

Parameters:

  | v | Front vehicle
  | left | The minimum horizontal position
  | right | The maximum horizontal position
  | y | Vertical position to draw at
  | selection | Selected vehicle to draw a frame around
  | skip | Number of pixels to skip at the front (for scrolling)

Definition at line 60 of file train_gui.cpp.

References _dynlang, DIR_E, DIR_W, DrawFrameRect(), DrawSprite(), FillDrawPixelInfo(), FR_BORDERONLY, SpecializedVehicle< Train, VEH_TRAIN >::From(), Train::GetDisplayImageWidth(), GetVehiclePalette(), SpecializedVehicle< T, Type >::Next(), TD_RTL, DynamicLanguages::text_dir, and CursorVars::vehchain.

Referenced by DrawVehicleImage(), and DepotWindow::DrawVehicleInDepot().

static void GetCargoSummaryOfArticulatedVehicle | ( | const Train * | v,
|  | CargoSummary * | summary |
| ) |  |  | `[static]`

Collects the cargo transportet.

Parameters:

  | v | Vehicle to process
  | summary | Space for the result

Definition at line 206 of file train_gui.cpp.

References CargoSummaryItem::amount, SmallVector< T, S >::Append(), CargoSummaryItem::capacity, Vehicle::cargo, CargoSummaryItem::cargo, Vehicle::cargo_cap, Vehicle::cargo_type, SmallVector< T, S >::Clear(), CargoList< Tinst >::Count(), SmallVector< T, S >::End(), SmallVector< T, S >::Find(), GetCargoSubtypeText(), Train::IsArticulatedPart(), SpecializedVehicle< T, Type >::Next(), CargoList< Tinst >::Source(), CargoSummaryItem::source, and CargoSummaryItem::subtype.

Referenced by DrawTrainDetails(), and GetTrainDetailsWndVScroll().

static uint GetLengthOfArticulatedVehicle | ( | const Train * | v | ) | `[static]`

Get the length of an articulated vehicle.

Parameters:

  | v | the vehicle to get the length of.

Returns:
  the length in pixels.

Definition at line 237 of file train_gui.cpp.

References Train::GetDisplayImageWidth(), Train::IsArticulatedPart(), and SpecializedVehicle< T, Type >::Next().

Referenced by GetTrainDetailsWndVScroll().

int GetTrainDetailsWndVScroll | ( | VehicleID | veh_id,
|  | TrainDetailsWindowTabs | det_tab |
| ) |  |  |

Determines the number of lines in the train details window.

Parameters:

  | veh_id | Train
  | det_tab | Selected details tab

Returns:
  Number of line

Definition at line 254 of file train_gui.cpp.

References SpecializedVehicle< Train, VEH_TRAIN >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), GetCargoSummaryOfArticulatedVehicle(), GetLengthOfArticulatedVehicle(), Train::GetNextVehicle(), SmallVector< T, S >::Length(), max(), NUM_CARGO, TDW_TAB_TOTALS, and TRAIN_DETAILS_MAX_INDENT.

Referenced by VehicleDetailsWindow::OnPaint().

static void TrainDetailsCapacityTab | ( | const CargoSummaryItem * | item,
|  | int | left,
|  | int | right,
|  | int | y |
| ) |  |  | `[static]`

Draw the details capacity tab for the given vehicle at the given position.

Parameters:

  | item | Data to draw
  | left | The left most coordinate to draw
  | right | The right most coordinate to draw
  | y | The y coordinate

Definition at line 192 of file train_gui.cpp.

References _settings_game, CargoSummaryItem::capacity, CargoSummaryItem::cargo, DrawString(), VehicleSettings::freight_trains, FreightWagonMult(), SetDParam(), CargoSummaryItem::subtype, and GameSettings::vehicle.

Referenced by DrawTrainDetails().

static void TrainDetailsCargoTab | ( | const CargoSummaryItem * | item,
|  | int | left,
|  | int | right,
|  | int | y |
| ) |  |  | `[static]`

Draw the details cargo tab for the given vehicle at the given position.

Parameters:

  | item | Data to draw
  | left | The left most coordinate to draw
  | right | The right most coordinate to draw
  | y | The y coordinate

Definition at line 147 of file train_gui.cpp.

References _settings_game, CargoSummaryItem::amount, CargoSummaryItem::cargo, DrawString(), VehicleSettings::freight_trains, FreightWagonMult(), SetDParam(), CargoSummaryItem::source, and GameSettings::vehicle.

Referenced by DrawTrainDetails().

static void TrainDetailsInfoTab | ( | const Vehicle * | v,
|  | int | left,
|  | int | right,
|  | int | y |
| ) |  |  | `[static]`

Draw the details info tab for the given vehicle at the given position.

Parameters:

  | v | current vehicle
  | left | The left most coordinate to draw
  | right | The right most coordinate to draw
  | y | The y coordinate

Definition at line 170 of file train_gui.cpp.

References DrawString(), RAILVEH_WAGON, SA_LEFT, SA_STRIP, SetDParam(), and Vehicle::value.

Referenced by DrawTrainDetails().