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

Function GetTrainSpriteSize

src/train_cmd.cpp:582–607  ·  view source on GitHub ↗

* Get the size of the sprite of a train sprite heading west, or both heads (used for lists). * @param engine The engine to get the sprite from. * @param[out] width The width of the sprite. * @param[out] height The height of the sprite. * @param[out] xoffs Number of pixels to shift the sprite to the right. * @param[out] yoffs Number of pixels to shift the sprite downwards. * @param image_type

Source from the content-addressed store, hash-verified

580 * @param image_type Context the sprite is used in.
581 */
582void GetTrainSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
583{
584 int y = 0;
585
586 VehicleSpriteSeq seq;
587 GetRailIcon(engine, false, y, image_type, &seq);
588
589 Rect rect;
590 seq.GetBounds(&rect);
591
592 width = UnScaleGUI(rect.Width());
593 height = UnScaleGUI(rect.Height());
594 xoffs = UnScaleGUI(rect.left);
595 yoffs = UnScaleGUI(rect.top);
596
597 if (RailVehInfo(engine)->railveh_type == RAILVEH_MULTIHEAD) {
598 GetRailIcon(engine, true, y, image_type, &seq);
599 seq.GetBounds(&rect);
600
601 /* Calculate values relative to an imaginary center between the two sprites. */
602 width = ScaleSpriteTrad(TRAININFO_DEFAULT_VEHICLE_WIDTH) + UnScaleGUI(rect.right) - xoffs;
603 height = std::max<uint>(height, UnScaleGUI(rect.Height()));
604 xoffs = xoffs - ScaleSpriteTrad(TRAININFO_DEFAULT_VEHICLE_WIDTH) / 2;
605 yoffs = std::min(yoffs, UnScaleGUI(rect.top));
606 }
607}
608
609/**
610 * Get a list of free wagons in a depot.

Callers 2

UpdateWidgetSizeMethod · 0.85
InitBlocksizeForVehiclesFunction · 0.85

Calls 7

GetRailIconFunction · 0.85
UnScaleGUIFunction · 0.85
RailVehInfoFunction · 0.85
ScaleSpriteTradFunction · 0.85
GetBoundsMethod · 0.45
WidthMethod · 0.45
HeightMethod · 0.45

Tested by

no test coverage detected