(svn r18133) -Codechange: pass the 'maximum' left/right positions to Draw*Image

This commit is contained in:
rubidium 2009-11-16 22:25:01 +00:00
parent 6204c56d99
commit a808623b24
7 changed files with 60 additions and 42 deletions

View File

@ -69,18 +69,26 @@ void DrawAircraftDetails(const Aircraft *v, int left, int right, int y)
}
void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
/**
* Draws an image of an aircraft
* @param v Front vehicle
* @param left The minimum horizontal position
* @param right The maximum horizontal position
* @param y Vertical position to draw at
* @param selection Selected vehicle to draw a frame around
*/
void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID selection)
{
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
DrawSprite(v->GetImage(DIR_W), pal, x + 25, y + 10);
DrawSprite(v->GetImage(DIR_W), pal, left + 25, y + 10);
if (v->subtype == AIR_HELICOPTER) {
const Aircraft *a = Aircraft::From(v);
SpriteID rotor_sprite = GetCustomRotorSprite(a, true);
if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
DrawSprite(rotor_sprite, PAL_NONE, x + 25, y + 5);
DrawSprite(rotor_sprite, PAL_NONE, left + 25, y + 5);
}
if (v->index == selection) {
DrawFrameRect(x - 1, y - 1, x + 58, y + 21, COLOUR_WHITE, FR_BORDERONLY);
DrawFrameRect(left - 1, y - 1, left + 58, y + 21, COLOUR_WHITE, FR_BORDERONLY);
}
}

View File

@ -263,7 +263,7 @@ struct DepotWindow : Window {
free_wagon = u->IsFreeWagon();
uint x_space = free_wagon ? TRAININFO_DEFAULT_VEHICLE_WIDTH : 0;
DrawTrainImage(u, x + 24 + x_space, sprite_y - 1, this->sel, this->hscroll.GetCapacity() - x_space, this->hscroll.GetPosition());
DrawTrainImage(u, x + 24 + x_space, x + 24 + this->hscroll.GetCapacity() - 1, sprite_y - 1, this->sel, this->hscroll.GetPosition());
/* Number of wagons relative to a standard length wagon (rounded up) */
SetDParam(0, (u->tcache.cached_total_length + 7) / 8);
@ -271,11 +271,11 @@ struct DepotWindow : Window {
break;
}
case VEH_ROAD: DrawRoadVehImage( v, x + 24, sprite_y, this->sel, ROADVEHINFO_DEFAULT_VEHICLE_WIDTH); break;
case VEH_SHIP: DrawShipImage( v, x + 19, sprite_y - 1, this->sel); break;
case VEH_ROAD: DrawRoadVehImage( v, x + 24, x + 24 + ROADVEHINFO_DEFAULT_VEHICLE_WIDTH - 1, sprite_y, this->sel); break;
case VEH_SHIP: DrawShipImage( v, x + 19, right, sprite_y - 1, this->sel); break;
case VEH_AIRCRAFT: {
const Sprite *spr = GetSprite(v->GetImage(DIR_W), ST_NORMAL);
DrawAircraftImage(v, x + 12,
DrawAircraftImage(v, x + 12, right,
y + max(spr->height + spr->y_offs - 14, 0), // tall sprites needs an y offset
this->sel);
} break;

View File

@ -123,27 +123,28 @@ void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y)
/**
* 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 selection Selected vehicle to draw a border around
* @param max_width Number of pixels space for drawing
* @param v Front vehicle
* @param left The minimum horizontal position
* @param right The maximum horizontal position
* @param y Vertical position to draw at
* @param selection Selected vehicle to draw a frame around
*/
void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection, int max_width)
void DrawRoadVehImage(const Vehicle *v, int left, int right, int y, VehicleID selection)
{
const RoadVehicle *u = RoadVehicle::From(v);
int max_width = right - left + 1;
int x_pos = 0;
for (; u != NULL && x_pos < max_width; u = u->Next()) {
Point offset;
int width = u->GetDisplayImageWidth(&offset);
SpriteID pal = (u->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(u);
DrawSprite(u->GetImage(DIR_W), pal, x + x_pos + offset.x, y + 6 + offset.y);
DrawSprite(u->GetImage(DIR_W), pal, left + x_pos + offset.x, y + 6 + offset.y);
x_pos += width;
}
if (v->index == selection) {
DrawFrameRect(x - 1, y - 1, x - 1 + x_pos, y + 12, COLOUR_WHITE, FR_BORDERONLY);
DrawFrameRect(left - 1, y - 1, left - 1 + x_pos, y + 12, COLOUR_WHITE, FR_BORDERONLY);
}
}

View File

@ -19,12 +19,20 @@
#include "table/strings.h"
void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection)
/**
* Draws an image of a ship
* @param v Front vehicle
* @param left The minimum horizontal position
* @param right The maximum horizontal position
* @param y Vertical position to draw at
* @param selection Selected vehicle to draw a frame around
*/
void DrawShipImage(const Vehicle *v, int left, int right, int y, VehicleID selection)
{
DrawSprite(v->GetImage(DIR_W), GetVehiclePalette(v), x + 32, y + 10);
DrawSprite(v->GetImage(DIR_W), GetVehiclePalette(v), left + 32, y + 10);
if (v->index == selection) {
DrawFrameRect(x - 5, y - 1, x + 67, y + 21, COLOUR_WHITE, FR_BORDERONLY);
DrawFrameRect(left - 5, y - 1, left + 67, y + 21, COLOUR_WHITE, FR_BORDERONLY);
}
}

View File

@ -61,21 +61,22 @@ void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2)
/**
* 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 v Front vehicle
* @param left The minimum horizontal position
* @param right The maximum horizontal position
* @param y Vertical position to draw at
* @param selection 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)
* @param skip Number of pixels to skip at the front (for scrolling)
*/
void DrawTrainImage(const Train *v, int x, int y, VehicleID selection, int max_width, int skip)
void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID selection, int skip)
{
DrawPixelInfo tmp_dpi, *old_dpi;
/* Position of highlight box */
int highlight_l = 0;
int highlight_r = 0;
int max_width = right - left + 1;
if (!FillDrawPixelInfo(&tmp_dpi, x, y, max_width, 14)) return;
if (!FillDrawPixelInfo(&tmp_dpi, left, y, max_width, 14)) return;
old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi;

View File

@ -777,20 +777,20 @@ static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y)
/**
* 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 v Front vehicle
* @param left The minimum horizontal position
* @param right The maximum horizontal position
* @param y Vertical position to draw at
* @param selection 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)
* @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)
static void DrawVehicleImage(const Vehicle *v, int left, int right, int y, VehicleID selection, int skip)
{
switch (v->type) {
case VEH_TRAIN: DrawTrainImage(Train::From(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;
case VEH_TRAIN: DrawTrainImage(Train::From(v), left, right, y, selection, skip); break;
case VEH_ROAD: DrawRoadVehImage(v, left, right, y, selection); break;
case VEH_SHIP: DrawShipImage(v, left, right, y, selection); break;
case VEH_AIRCRAFT: DrawAircraftImage(v, left, right, y, selection); break;
default: NOT_REACHED();
}
}
@ -844,7 +844,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
SetDParam(0, v->GetDisplayProfitThisYear());
SetDParam(1, v->GetDisplayProfitLastYear());
DrawVehicleImage(v, text_left, y + FONT_HEIGHT_SMALL - 1, selected_vehicle, text_right - text_left + 1, 0);
DrawVehicleImage(v, text_left, text_right, y + FONT_HEIGHT_SMALL - 1, selected_vehicle, 0);
DrawString(text_left, text_right, y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 1, STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR);
if (v->name != NULL) {
@ -1490,7 +1490,7 @@ struct VehicleDetailsWindow : Window {
case VLD_WIDGET_MIDDLE_DETAILS:
/* For other vehicles, at the place of the matrix. */
DrawVehicleImage(v, r.left + 3, r.top + WD_FRAMERECT_TOP, INVALID_VEHICLE, r.right - r.left + 1 - 6, 0);
DrawVehicleImage(v, r.left + 3, r.right - 3, r.top + WD_FRAMERECT_TOP, INVALID_VEHICLE, 0);
DrawVehicleDetails(v, r.left + 75, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, this->vscroll.GetPosition(), this->vscroll.GetCapacity(), this->tab);
break;

View File

@ -70,10 +70,10 @@ static inline bool ValidVLWFlags(uint16 flags)
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number);
void DrawTrainImage(const Train *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);
void DrawTrainImage(const Train *v, int left, int right, int y, VehicleID selection, int skip);
void DrawRoadVehImage(const Vehicle *v, int left, int right, int y, VehicleID selection);
void DrawShipImage(const Vehicle *v, int left, int right, int y, VehicleID selection);
void DrawAircraftImage(const Vehicle *v, int left, int right, int y, VehicleID selection);
void ShowBuildVehicleWindow(TileIndex tile, VehicleType type);