MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetDisplayImageWidth

Method GetDisplayImageWidth

src/train_cmd.cpp:460–480  ·  view source on GitHub ↗

* 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 */

Source from the content-addressed store, hash-verified

458 * @return Width in pixels
459 */
460int 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
482static SpriteID GetDefaultTrainSprite(uint8_t spritenum, Direction direction)
483{

Callers 11

OnPaintMethod · 0.45
DrawRoadVehImageFunction · 0.45
DrawWidgetMethod · 0.45
SetSelectedVehiclesMethod · 0.45
GetSingleVehicleWidthFunction · 0.45
HighlightDragPositionFunction · 0.45
DrawTrainImageFunction · 0.45
DrawTrainDetailsFunction · 0.45

Calls 6

IsCustomVehicleSpriteNumFunction · 0.85
EngInfoFunction · 0.85
ScaleSpriteTradFunction · 0.85
TestMethod · 0.80
GetEngineMethod · 0.45
GetGRFMethod · 0.45

Tested by

no test coverage detected