* Calculate effective position. * This will update the position field if a vehicle is followed. * @param vp Viewport to calculate position for. * @return Calculated position in the viewport. */
| 76 | * @return Calculated position in the viewport. |
| 77 | */ |
| 78 | Point PositionForViewport(const Viewport &vp) |
| 79 | { |
| 80 | if (this->vehicle != VehicleID::Invalid()) { |
| 81 | const Vehicle *v = Vehicle::Get(this->vehicle); |
| 82 | this->position = RemapCoords(v->x_pos, v->y_pos, v->z_pos); |
| 83 | } |
| 84 | |
| 85 | Point p; |
| 86 | switch (this->align_h) { |
| 87 | case LEFT: p.x = this->position.x; break; |
| 88 | case CENTRE: p.x = this->position.x - vp.virtual_width / 2; break; |
| 89 | case RIGHT: p.x = this->position.x - vp.virtual_width; break; |
| 90 | } |
| 91 | switch (this->align_v) { |
| 92 | case TOP: p.y = this->position.y; break; |
| 93 | case MIDDLE: p.y = this->position.y - vp.virtual_height / 2; break; |
| 94 | case BOTTOM: p.y = this->position.y - vp.virtual_height; break; |
| 95 | } |
| 96 | return p; |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 |
no test coverage detected