* Draws an image of an aircraft * @param v Front vehicle * @param r Rect to draw at * @param selection Selected vehicle to draw a frame around */
| 68 | * @param selection Selected vehicle to draw a frame around |
| 69 | */ |
| 70 | void DrawAircraftImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type) |
| 71 | { |
| 72 | bool rtl = _current_text_dir == TD_RTL; |
| 73 | |
| 74 | VehicleSpriteSeq seq; |
| 75 | v->GetImage(rtl ? DIR_E : DIR_W, image_type, &seq); |
| 76 | |
| 77 | Rect rect; |
| 78 | seq.GetBounds(&rect); |
| 79 | |
| 80 | int width = UnScaleGUI(rect.Width()); |
| 81 | int x_offs = UnScaleGUI(rect.left); |
| 82 | int x = rtl ? r.right - width - x_offs : r.left - x_offs; |
| 83 | /* This magic -1 offset is related to the sprite_y_offsets in build_vehicle_gui.cpp */ |
| 84 | int y = ScaleSpriteTrad(-1) + CentreBounds(r.top, r.bottom, 0); |
| 85 | bool helicopter = v->subtype == AIR_HELICOPTER; |
| 86 | |
| 87 | int heli_offs = 0; |
| 88 | |
| 89 | PaletteID pal = v->vehstatus.Test(VehState::Crashed) ? PALETTE_CRASH : GetVehiclePalette(v); |
| 90 | seq.Draw(x, y, pal, v->vehstatus.Test(VehState::Crashed)); |
| 91 | |
| 92 | /* Aircraft can store cargo in their shadow, show this if present. */ |
| 93 | const Vehicle *u = v->Next(); |
| 94 | assert(u != nullptr); |
| 95 | int dx = 0; |
| 96 | if (u->cargo_cap > 0 && u->cargo_type != v->cargo_type) { |
| 97 | dx = GetLargestCargoIconSize().width / 2; |
| 98 | DrawCargoIconOverlay(x + dx, y, u->cargo_type); |
| 99 | } |
| 100 | if (v->cargo_cap > 0) DrawCargoIconOverlay(x - dx, y, v->cargo_type); |
| 101 | |
| 102 | if (helicopter) { |
| 103 | const Aircraft *a = Aircraft::From(v); |
| 104 | VehicleSpriteSeq rotor_seq; |
| 105 | GetCustomRotorSprite(a, image_type, &rotor_seq); |
| 106 | if (!rotor_seq.IsValid()) rotor_seq.Set(SPR_ROTOR_STOPPED); |
| 107 | heli_offs = ScaleSpriteTrad(5); |
| 108 | rotor_seq.Draw(x, y - heli_offs, PAL_NONE, false); |
| 109 | } |
| 110 | if (v->index == selection) { |
| 111 | x += x_offs; |
| 112 | y += UnScaleGUI(rect.top) - heli_offs; |
| 113 | Rect hr = {x, y, x + width - 1, y + UnScaleGUI(rect.Height()) + heli_offs - 1}; |
| 114 | DrawFrameRect(hr.Expand(WidgetDimensions::scaled.bevel), COLOUR_WHITE, FrameFlag::BorderOnly); |
| 115 | } |
| 116 | } |
no test coverage detected