diff options
author | frosch <frosch@openttd.org> | 2009-07-12 16:00:11 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2009-07-12 16:00:11 +0000 |
commit | 78eccd05befe40a006974daf0b29dfb1b2382b65 (patch) | |
tree | dfc209ba6db7b370111bda05a1b8649de8667821 | |
parent | 9efd32d13ce11aedf020cd2ce9eddc2ccaa72d32 (diff) | |
download | openttd-78eccd05befe40a006974daf0b29dfb1b2382b65.tar.xz |
(svn r16799) -Codechange: When drawing articulated road vehicles in the vehicle details window, draw as many parts as the window fits instead of always up to a vehicle length of 80/8.
-rw-r--r-- | src/depot_gui.cpp | 2 | ||||
-rw-r--r-- | src/roadveh_gui.cpp | 15 | ||||
-rw-r--r-- | src/train_gui.cpp | 15 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 21 | ||||
-rw-r--r-- | src/vehicle_gui.h | 4 |
5 files changed, 40 insertions, 17 deletions
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 354ac8057..6bd364deb 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -276,7 +276,7 @@ struct DepotWindow : Window { DrawString(this->widget[DEPOT_WIDGET_MATRIX].left, this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING, SA_RIGHT); // Draw the counter break; - case VEH_ROAD: DrawRoadVehImage( v, x + 24, sprite_y, this->sel, 1); break; + case VEH_ROAD: DrawRoadVehImage( v, x + 24, sprite_y, this->sel, 28); break; case VEH_SHIP: DrawShipImage( v, x + 19, sprite_y - 1, this->sel); break; case VEH_AIRCRAFT: { const Sprite *spr = GetSprite(v->GetImage(DIR_W), ST_NORMAL); diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp index 11e8f3eca..d09792e2f 100644 --- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -120,12 +120,17 @@ static inline int RoadVehLengthToPixels(int length) return (length * 28) / 8; } -void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection, int count) +/** + * Draws an image of a road vehicle chain + * @param v Front vehicle + + @param x x Position to start at + * @param y y Position to draw at + * @param seletion Selected vehicle to draw a border around + * @param max_width Number of pixels space for drawing + */ +void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection, int max_width) { - /* Road vehicle lengths are measured in eighths of the standard length, so - * count is the number of standard vehicles that should be drawn. If it is - * 0, we draw enough vehicles for 10 standard vehicle lengths. */ - int max_length = (count == 0) ? 80 : count * 8; + int max_length = max_width / 28; /* Width of highlight box */ int highlight_w = 0; diff --git a/src/train_gui.cpp b/src/train_gui.cpp index fb4230fb7..9591da258 100644 --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -64,7 +64,16 @@ int WagonLengthToPixels(int len) return (len * _traininfo_vehicle_width) / 8; } -void DrawTrainImage(const Vehicle *v, int x, int y, VehicleID selection, int count, int skip) +/** + * Draws an image of a whole train + * @param v Front vehicle + + @param x x Position to start at + * @param y y Position to draw at + * @param seletion Selected vehicle to draw a frame around + * @param max_width Number of pixels space for drawing + * @param skip Number of pixels to skip at the front (for scrolling) + */ +void DrawTrainImage(const Vehicle *v, int x, int y, VehicleID selection, int max_width, int skip) { DrawPixelInfo tmp_dpi, *old_dpi; int dx = -(skip * 8) / _traininfo_vehicle_width; @@ -72,9 +81,9 @@ void DrawTrainImage(const Vehicle *v, int x, int y, VehicleID selection, int cou int highlight_l = 0; int highlight_r = 0; - if (!FillDrawPixelInfo(&tmp_dpi, x - 2, y - 1, count + 1, 14)) return; + if (!FillDrawPixelInfo(&tmp_dpi, x - 2, y - 1, max_width + 1, 14)) return; - count = (count * 8) / _traininfo_vehicle_width; + int count = (max_width * 8) / _traininfo_vehicle_width; old_dpi = _cur_dpi; _cur_dpi = &tmp_dpi; diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 17b225b38..7f55f3b24 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -798,13 +798,22 @@ static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y) } } -static void DrawVehicleImage(const Vehicle *v, int x, int y, VehicleID selection, int count, int skip) +/** + * Draws an image of a vehicle chain + * @param v Front vehicle + + @param x x Position to start at + * @param y y Position to draw at + * @param seletion Selected vehicle to draw a frame around + * @param max_width Number of pixels space for drawing + * @param skip Number of pixels to skip at the front (for scrolling) + */ +static void DrawVehicleImage(const Vehicle *v, int x, int y, VehicleID selection, int max_width, int skip) { switch (v->type) { - case VEH_TRAIN: DrawTrainImage(v, x, y, selection, count, skip); break; - case VEH_ROAD: DrawRoadVehImage(v, x, y, selection, count); break; - case VEH_SHIP: DrawShipImage(v, x, y, selection); break; - case VEH_AIRCRAFT: DrawAircraftImage(v, x, y, selection); break; + case VEH_TRAIN: DrawTrainImage(v, x, y, selection, max_width, skip); break; + case VEH_ROAD: DrawRoadVehImage(v, x, y, selection, max_width); break; + case VEH_SHIP: DrawShipImage(v, x, y, selection); break; + case VEH_AIRCRAFT: DrawAircraftImage(v, x, y, selection); break; default: NOT_REACHED(); } } @@ -1517,7 +1526,7 @@ struct VehicleDetailsWindow : Window { case VEH_ROAD: case VEH_SHIP: case VEH_AIRCRAFT: - DrawVehicleImage(v, matrix->left + 3, matrix->top + 1, INVALID_VEHICLE, 0, 0); + DrawVehicleImage(v, matrix->left + 3, matrix->top + 1, INVALID_VEHICLE, matrix->right - matrix->left - 5, 0); DrawVehicleDetails(v, matrix->left + 75, matrix->right - 2, matrix->top + 1, this->vscroll.pos, this->vscroll.cap, det_tab); break; diff --git a/src/vehicle_gui.h b/src/vehicle_gui.h index fb3516ec4..3371bd16c 100644 --- a/src/vehicle_gui.h +++ b/src/vehicle_gui.h @@ -61,8 +61,8 @@ static inline bool ValidVLWFlags(uint16 flags) int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number); -void DrawTrainImage(const Vehicle *v, int x, int y, VehicleID selection, int count, int skip); -void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection, int count); +void DrawTrainImage(const Vehicle *v, int x, int y, VehicleID selection, int max_width, int skip); +void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection, int max_width); void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection); void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection); |