(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.

This commit is contained in:
frosch 2009-07-12 16:00:11 +00:00
parent 95ac767add
commit fb9ec40e44
5 changed files with 40 additions and 17 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);