* Get the width of a train vehicle image in the GUI. * @param offset Additional offset for positioning the sprite; set to nullptr if not needed * @return Width in pixels */
| 458 | * @return Width in pixels |
| 459 | */ |
| 460 | int Train::GetDisplayImageWidth(Point *offset) const |
| 461 | { |
| 462 | int reference_width = TRAININFO_DEFAULT_VEHICLE_WIDTH; |
| 463 | int vehicle_pitch = 0; |
| 464 | |
| 465 | const Engine *e = this->GetEngine(); |
| 466 | if (e->GetGRF() != nullptr && IsCustomVehicleSpriteNum(e->VehInfo<RailVehicleInfo>().image_index)) { |
| 467 | reference_width = e->GetGRF()->traininfo_vehicle_width; |
| 468 | vehicle_pitch = e->GetGRF()->traininfo_vehicle_pitch; |
| 469 | } |
| 470 | |
| 471 | if (offset != nullptr) { |
| 472 | if (this->flags.Test(VehicleRailFlag::Flipped) && !EngInfo(this->engine_type)->misc_flags.Test(EngineMiscFlag::RailFlips)) { |
| 473 | offset->x = ScaleSpriteTrad(((int)this->gcache.cached_veh_length - (int)VEHICLE_LENGTH / 2) * reference_width / (int)VEHICLE_LENGTH); |
| 474 | } else { |
| 475 | offset->x = ScaleSpriteTrad(reference_width) / 2; |
| 476 | } |
| 477 | offset->y = ScaleSpriteTrad(vehicle_pitch); |
| 478 | } |
| 479 | return ScaleSpriteTrad(this->gcache.cached_veh_length * reference_width / VEHICLE_LENGTH); |
| 480 | } |
| 481 | |
| 482 | static SpriteID GetDefaultTrainSprite(uint8_t spritenum, Direction direction) |
| 483 | { |
no test coverage detected