* Highlight the position where a rail vehicle is dragged over by drawing a light gray background. * @param px The current x position to draw from. * @param max_width The maximum space available to draw. * @param y The vertical centre position to draw from. * @param selection Selected vehicle that is dragged. * @param chain Whether a whole chain is dragged. * @return The wi
| 63 | * @return The width of the highlight mark. |
| 64 | */ |
| 65 | static int HighlightDragPosition(int px, int max_width, int y, VehicleID selection, bool chain) |
| 66 | { |
| 67 | bool rtl = _current_text_dir == TD_RTL; |
| 68 | |
| 69 | assert(selection != VehicleID::Invalid()); |
| 70 | int dragged_width = 0; |
| 71 | for (Train *t = Train::Get(selection); t != nullptr; t = chain ? t->Next() : (t->HasArticulatedPart() ? t->GetNextArticulatedPart() : nullptr)) { |
| 72 | dragged_width += t->GetDisplayImageWidth(nullptr); |
| 73 | } |
| 74 | |
| 75 | int drag_hlight_left = rtl ? std::max(px - dragged_width + 1, 0) : px; |
| 76 | int drag_hlight_right = rtl ? px : std::min(px + dragged_width, max_width) - 1; |
| 77 | int drag_hlight_width = std::max(drag_hlight_right - drag_hlight_left + 1, 0); |
| 78 | |
| 79 | if (drag_hlight_width > 0) { |
| 80 | int height = ScaleSpriteTrad(12); |
| 81 | int top = y - height / 2; |
| 82 | Rect r = {drag_hlight_left, top, drag_hlight_right, top + height - 1}; |
| 83 | /* Sprite-scaling is used here as the area is from sprite size */ |
| 84 | GfxFillRect(r.Shrink(ScaleSpriteTrad(1)), GetColourGradient(COLOUR_GREY, SHADE_LIGHTEST)); |
| 85 | } |
| 86 | |
| 87 | return drag_hlight_width; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Draws an image of a whole train |
no test coverage detected