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

Function DrawShipImage

src/ship_gui.cpp:29–54  ·  view source on GitHub ↗

* Draws an image of a ship * @param v Front vehicle * @param r Rect to draw at * @param selection Selected vehicle to draw a frame around */

Source from the content-addressed store, hash-verified

27 * @param selection Selected vehicle to draw a frame around
28 */
29void DrawShipImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type)
30{
31 bool rtl = _current_text_dir == TD_RTL;
32
33 VehicleSpriteSeq seq;
34 v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq);
35
36 Rect rect;
37 seq.GetBounds(&rect);
38
39 int width = UnScaleGUI(rect.Width());
40 int x_offs = UnScaleGUI(rect.left);
41 int x = rtl ? r.right - width - x_offs : r.left - x_offs;
42 /* This magic -1 offset is related to the sprite_y_offsets in build_vehicle_gui.cpp */
43 int y = ScaleSpriteTrad(-1) + CentreBounds(r.top, r.bottom, 0);
44
45 seq.Draw(x, y, GetVehiclePalette(v), false);
46 if (v->cargo_cap > 0) DrawCargoIconOverlay(x, y, v->cargo_type);
47
48 if (v->index == selection) {
49 x += x_offs;
50 y += UnScaleGUI(rect.top);
51 Rect hr = {x, y, x + width - 1, y + UnScaleGUI(rect.Height()) - 1};
52 DrawFrameRect(hr.Expand(WidgetDimensions::scaled.bevel), COLOUR_WHITE, FrameFlag::BorderOnly);
53 }
54}
55
56/**
57 * Draw the details for the given vehicle at the given position

Callers 2

DrawVehicleInDepotMethod · 0.85
DrawVehicleImageFunction · 0.85

Calls 12

UnScaleGUIFunction · 0.85
ScaleSpriteTradFunction · 0.85
CentreBoundsFunction · 0.85
GetVehiclePaletteFunction · 0.85
DrawCargoIconOverlayFunction · 0.85
ExpandMethod · 0.80
DrawFrameRectFunction · 0.70
GetImageMethod · 0.45
GetBoundsMethod · 0.45
WidthMethod · 0.45
DrawMethod · 0.45
HeightMethod · 0.45

Tested by

no test coverage detected