(svn r25652) -Fix: Improve text caret movement for complex scripts.
[openttd/fttd.git] / src / ship_gui.cpp
blob10cf78922b669c36dcc3bd535098cdd6d92a1dc0
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file ship_gui.cpp GUI for ships. */
12 #include "stdafx.h"
13 #include "vehicle_base.h"
14 #include "window_gui.h"
15 #include "gfx_func.h"
16 #include "vehicle_gui.h"
17 #include "strings_func.h"
18 #include "vehicle_func.h"
19 #include "spritecache.h"
20 #include "zoom_func.h"
22 #include "table/strings.h"
24 /**
25 * Draws an image of a ship
26 * @param v Front vehicle
27 * @param left The minimum horizontal position
28 * @param right The maximum horizontal position
29 * @param y Vertical position to draw at
30 * @param selection Selected vehicle to draw a frame around
32 void DrawShipImage(const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type)
34 bool rtl = _current_text_dir == TD_RTL;
36 SpriteID sprite = v->GetImage(rtl ? DIR_E : DIR_W, image_type);
37 const Sprite *real_sprite = GetSprite(sprite, ST_NORMAL);
39 int width = UnScaleByZoom(real_sprite->width, ZOOM_LVL_GUI);
40 int x_offs = UnScaleByZoom(real_sprite->x_offs, ZOOM_LVL_GUI);
41 int x = rtl ? right - width - x_offs : left - x_offs;
43 DrawSprite(sprite, GetVehiclePalette(v), x, y + 10);
45 if (v->index == selection) {
46 x += x_offs;
47 y += UnScaleByZoom(real_sprite->y_offs, ZOOM_LVL_GUI) + 10;
48 DrawFrameRect(x - 1, y - 1, x + width + 1, y + UnScaleByZoom(real_sprite->height, ZOOM_LVL_GUI) + 1, COLOUR_WHITE, FR_BORDERONLY);
52 /**
53 * Draw the details for the given vehicle at the given position
55 * @param v current vehicle
56 * @param left The left most coordinate to draw
57 * @param right The right most coordinate to draw
58 * @param y The y coordinate
60 void DrawShipDetails(const Vehicle *v, int left, int right, int y)
62 SetDParam(0, v->engine_type);
63 SetDParam(1, v->build_year);
64 SetDParam(2, v->value);
65 DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE);
67 SetDParam(0, v->cargo_type);
68 SetDParam(1, v->cargo_cap);
69 SetDParam(4, GetCargoSubtypeText(v));
70 DrawString(left, right, y + FONT_HEIGHT_NORMAL, STR_VEHICLE_INFO_CAPACITY);
72 StringID str = STR_VEHICLE_DETAILS_CARGO_EMPTY;
73 if (v->cargo.StoredCount() > 0) {
74 SetDParam(0, v->cargo_type);
75 SetDParam(1, v->cargo.StoredCount());
76 SetDParam(2, v->cargo.Source());
77 str = STR_VEHICLE_DETAILS_CARGO_FROM;
79 DrawString(left, right, y + 2 * FONT_HEIGHT_NORMAL + 1, str);
81 /* Draw Transfer credits text */
82 SetDParam(0, v->cargo.FeederShare());
83 DrawString(left, right, y + 3 * FONT_HEIGHT_NORMAL + 3, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);