OpenTTD
Data Structures | Typedefs | Functions | Variables
train_gui.cpp File Reference

GUI for trains. More...

#include "stdafx.h"
#include "window_gui.h"
#include "command_func.h"
#include "train.h"
#include "strings_func.h"
#include "vehicle_func.h"
#include "zoom_func.h"
#include "table/strings.h"
#include "safeguards.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. More...
 

Functions

void CcBuildWagon (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 Callback for building wagons. More...
 
static int HighlightDragPosition (int px, int max_width, VehicleID selection, bool chain)
 Highlight the position where a rail vehicle is dragged over by drawing a light gray background. More...
 
void DrawTrainImage (const Train *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest)
 Draws an image of a whole train. More...
 
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. More...
 
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. More...
 
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. More...
 
static void GetCargoSummaryOfArticulatedVehicle (const Train *v, CargoSummary *summary)
 Collects the cargo transported. More...
 
static uint GetLengthOfArticulatedVehicle (const Train *v)
 Get the length of an articulated vehicle. More...
 
int GetTrainDetailsWndVScroll (VehicleID veh_id, TrainDetailsWindowTabs det_tab)
 Determines the number of lines in the train details window. More...
 
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. More...
 

Variables

static const uint TRAIN_DETAILS_MIN_INDENT = 32
 Minimum indent level in the train details window.
 
static const uint TRAIN_DETAILS_MAX_INDENT = 72
 Maximum indent level in the train details window; wider than this and we start on a new line.
 
static CargoSummary _cargo_summary
 Reused container of cargo details.
 

Detailed Description

GUI for trains.

Definition in file train_gui.cpp.

Typedef Documentation

◆ CargoSummary

Container for the cargo summary information.

Definition at line 183 of file train_gui.cpp.

Function Documentation

◆ CcBuildWagon()

void CcBuildWagon ( const CommandCost result,
TileIndex  tile,
uint32  p1,
uint32  p2 
)

Callback for building wagons.

Parameters
resultThe result of the command.
tileThe tile the command was executed on.
p1Additional data for the command (for the CommandProc)
p2Additional data for the command (for the CommandProc)

Definition at line 31 of file train_gui.cpp.

References CommandCost::Failed().

◆ DrawTrainDetails()

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
vcurrent vehicle
leftThe left most coordinate to draw
rightThe right most coordinate to draw
yThe y coordinate
vscroll_posPosition of scrollbar
vscroll_capNumber of lines currently displayed
det_tabSelected details tab

Definition at line 356 of file train_gui.cpp.

◆ DrawTrainImage()

void DrawTrainImage ( const Train v,
int  left,
int  right,
int  y,
VehicleID  selection,
EngineImageType  image_type,
int  skip,
VehicleID  drag_dest 
)

Draws an image of a whole train.

Parameters
vFront vehicle
leftThe minimum horizontal position
rightThe maximum horizontal position
yVertical position to draw at
selectionSelected vehicle to draw a frame around
skipNumber of pixels to skip at the front (for scrolling)
drag_destThe vehicle another one is dragged over, INVALID_VEHICLE if none.

Definition at line 94 of file train_gui.cpp.

◆ GetCargoSummaryOfArticulatedVehicle()

static void GetCargoSummaryOfArticulatedVehicle ( const Train v,
CargoSummary summary 
)
static

◆ GetLengthOfArticulatedVehicle()

static uint GetLengthOfArticulatedVehicle ( const Train v)
static

Get the length of an articulated vehicle.

Parameters
vthe vehicle to get the length of.
Returns
the length in pixels.

Definition at line 296 of file train_gui.cpp.

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

Referenced by GetTrainDetailsWndVScroll().

◆ GetTrainDetailsWndVScroll()

int GetTrainDetailsWndVScroll ( VehicleID  veh_id,
TrainDetailsWindowTabs  det_tab 
)

◆ HighlightDragPosition()

static int HighlightDragPosition ( int  px,
int  max_width,
VehicleID  selection,
bool  chain 
)
static

Highlight the position where a rail vehicle is dragged over by drawing a light gray background.

Parameters
pxThe current x position to draw from.
max_widthThe maximum space available to draw.
selectionSelected vehicle that is dragged.
chainWhether a whole chain is dragged.
Returns
The width of the highlight mark.

Definition at line 62 of file train_gui.cpp.

References _current_text_dir, and TD_RTL.

◆ TrainDetailsCapacityTab()

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
itemData to draw
leftThe left most coordinate to draw
rightThe right most coordinate to draw
yThe y coordinate

Definition at line 242 of file train_gui.cpp.

◆ TrainDetailsCargoTab()

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
itemData to draw
leftThe left most coordinate to draw
rightThe right most coordinate to draw
yThe y coordinate

Definition at line 195 of file train_gui.cpp.

◆ TrainDetailsInfoTab()

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
vcurrent vehicle
leftThe left most coordinate to draw
rightThe right most coordinate to draw
yThe y coordinate

Definition at line 220 of file train_gui.cpp.