Changeset - r22424:a25b9a5bc66b
[Not reviewed]
master
0 2 0
frosch - 8 years ago 2016-08-15 18:34:09
frosch@openttd.org
(svn r27631) -Codechange: Split GetSingleVehicleWidth from GetVehicleWidth.
2 files changed with 25 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/vehicle_gui.cpp
Show inline comments
 
@@ -2826,43 +2826,49 @@ void CcBuildPrimaryVehicle(const Command
 

	
 
	const Vehicle *v = Vehicle::Get(_new_vehicle_id);
 
	ShowVehicleViewWindow(v);
 
}
 

	
 
/**
 
 * Get the width of a vehicle (including all parts of the consist) in pixels.
 
 * Get the width of a vehicle (part) in pixels.
 
 * @param v Vehicle to get the width for.
 
 * @return Width of the vehicle.
 
 */
 
int GetVehicleWidth(Vehicle *v, EngineImageType image_type)
 
int GetSingleVehicleWidth(const Vehicle *v, EngineImageType image_type)
 
{
 
	int vehicle_width = 0;
 

	
 
	switch (v->type) {
 
		case VEH_TRAIN:
 
			for (const Train *u = Train::From(v); u != NULL; u = u->Next()) {
 
				vehicle_width += u->GetDisplayImageWidth();
 
			}
 
			break;
 
			return Train::From(v)->GetDisplayImageWidth();
 

	
 
		case VEH_ROAD:
 
			for (const RoadVehicle *u = RoadVehicle::From(v); u != NULL; u = u->Next()) {
 
				vehicle_width += u->GetDisplayImageWidth();
 
			}
 
			break;
 
			return RoadVehicle::From(v)->GetDisplayImageWidth();
 

	
 
		default:
 
			bool rtl = _current_text_dir == TD_RTL;
 
			SpriteID sprite = v->GetImage(rtl ? DIR_E : DIR_W, image_type);
 
			const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL);
 
			vehicle_width = UnScaleGUI(real_sprite->width);
 

	
 
			break;
 
			return UnScaleGUI(real_sprite->width);
 
	}
 

	
 
	return vehicle_width;
 
}
 

	
 
/**
 
 * Get the width of a vehicle (including all parts of the consist) in pixels.
 
 * @param v Vehicle to get the width for.
 
 * @return Width of the vehicle.
 
 */
 
int GetVehicleWidth(const Vehicle *v, EngineImageType image_type)
 
{
 
	if (v->type == VEH_TRAIN || v->type == VEH_ROAD) {
 
		int vehicle_width = 0;
 
		for (const Vehicle *u = v; u != NULL; u = u->Next()) {
 
			vehicle_width += GetSingleVehicleWidth(u, image_type);
 
		}
 
		return vehicle_width;
 
	} else {
 
		return GetSingleVehicleWidth(v, image_type);
 
	}
 
}
 

	
 
/**
 
 * Set the mouse cursor to look like a vehicle.
 
 * @param v Vehicle
 
 * @param image_type Type of vehicle image to use.
src/vehicle_gui.h
Show inline comments
 
@@ -61,13 +61,14 @@ void ShowVehicleListWindow(CompanyID com
 
 */
 
static inline uint GetVehicleHeight(VehicleType type)
 
{
 
	return (type == VEH_TRAIN || type == VEH_ROAD) ? 14 : 24;
 
}
 

	
 
int GetVehicleWidth(Vehicle *v, EngineImageType image_type);
 
int GetSingleVehicleWidth(const Vehicle *v, EngineImageType image_type);
 
int GetVehicleWidth(const Vehicle *v, EngineImageType image_type);
 

	
 
/** Dimensions of a cell in the purchase/depot windows. */
 
struct VehicleCellSize {
 
	uint height;       ///< Vehicle cell height.
 
	uint extend_left;  ///< Extend of the cell to the left.
 
	uint extend_right; ///< Extend of the cell to the right.
0 comments (0 inline, 0 general)