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

Method DrawCargoIcons

src/station_gui.cpp:1773–1787  ·  view source on GitHub ↗

* Draw icons of waiting cargo. * @param cargo type of cargo * @param waiting number of waiting units * @param r Rect to draw within */

Source from the content-addressed store, hash-verified

1771 * @param r Rect to draw within
1772 */
1773 void DrawCargoIcons(CargoType cargo, uint waiting, const Rect &r) const
1774 {
1775 int width = ScaleSpriteTrad(10);
1776 uint num = std::min<uint>((waiting + (width / 2)) / width, r.Width() / width); // maximum is width / 10 icons so it won't overflow
1777 if (num == 0) return;
1778
1779 SpriteID sprite = CargoSpec::Get(cargo)->GetCargoIcon();
1780
1781 int x = _current_text_dir == TD_RTL ? r.left : r.right - num * width;
1782 int y = CentreBounds(r.top, r.bottom, this->cargo_icon_size.height);
1783 do {
1784 DrawSprite(sprite, PAL_NONE, x, y);
1785 x += width;
1786 } while (--num);
1787 }
1788
1789 /**
1790 * Draw the given cargo entries in the station GUI.

Callers 1

DrawEntriesMethod · 0.95

Calls 5

ScaleSpriteTradFunction · 0.85
CentreBoundsFunction · 0.85
DrawSpriteFunction · 0.85
GetCargoIconMethod · 0.80
WidthMethod · 0.45

Tested by

no test coverage detected