Changeset - r13599:f6ef46132fe6
[Not reviewed]
master
0 7 0
rubidium - 15 years ago 2009-11-16 22:25:01
rubidium@openttd.org
(svn r18133) -Codechange: pass the 'maximum' left/right positions to Draw*Image
7 files changed with 60 insertions and 42 deletions:
0 comments (0 inline, 0 general)
src/aircraft_gui.cpp
Show inline comments
 
@@ -66,24 +66,32 @@ void DrawAircraftDetails(const Aircraft 
 

	
 
	SetDParam(0, feeder_share);
 
	DrawString(left, right, y + 3 * FONT_HEIGHT_NORMAL + 3 + y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
 
}
 

	
 

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

	
 
/**
 
 * This is the Callback method after the construction attempt of an aircraft
 
 * @param success indicates completion (or not) of the operation
src/depot_gui.cpp
Show inline comments
 
@@ -260,25 +260,25 @@ struct DepotWindow : Window {
 
		switch (v->type) {
 
			case VEH_TRAIN: {
 
				const Train *u = Train::From(v);
 
				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);
 
				DrawString(left, right - 1, y + 4, STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT); // Draw the counter
 
				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;
 
			default: NOT_REACHED();
 
		}
 

	
src/roadveh_gui.cpp
Show inline comments
 
@@ -120,33 +120,34 @@ void DrawRoadVehDetails(const Vehicle *v
 
	SetDParam(0, feeder_share);
 
	DrawString(left, right, y + 3 * FONT_HEIGHT_NORMAL + 3 + y_offset, STR_VEHICLE_INFO_FEEDER_CARGO_VALUE);
 
}
 

	
 
/**
 
 * 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);
 
	}
 
}
 

	
 
void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	const Vehicle *v;
src/ship_gui.cpp
Show inline comments
 
@@ -16,18 +16,26 @@
 
#include "vehicle_gui.h"
 
#include "strings_func.h"
 
#include "vehicle_func.h"
 

	
 
#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);
 
	}
 
}
 

	
 
void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2)
 
{
 
	const Vehicle *v;
src/train_gui.cpp
Show inline comments
 
@@ -58,27 +58,28 @@ void CcBuildLoco(bool success, TileIndex
 
	}
 
	ShowVehicleViewWindow(v);
 
}
 

	
 
/**
 
 * 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;
 

	
 
	int px = -skip;
 
	bool sel_articulated = false;
src/vehicle_gui.cpp
Show inline comments
 
@@ -774,26 +774,26 @@ static void DrawSmallOrderList(const Veh
 
		}
 
	}
 
}
 

	
 
/**
 
 * 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();
 
	}
 
}
 

	
 
/**
 
 * Get the height of a vehicle in the vehicle list GUIs.
 
@@ -841,13 +841,13 @@ void BaseVehicleListWindow::DrawVehicleL
 
		const Vehicle *v = this->vehicles[i];
 
		StringID str;
 

	
 
		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) {
 
			/* The vehicle got a name so we will print it */
 
			SetDParam(0, v->index);
 
			DrawString(text_left, text_right, y, STR_TINY_BLACK_VEHICLE);
 
@@ -1487,13 +1487,13 @@ struct VehicleDetailsWindow : Window {
 
				/* For trains only. */
 
				DrawVehicleDetails(v, r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, r.top + WD_MATRIX_TOP, this->vscroll.GetPosition(), this->vscroll.GetCapacity(), this->tab);
 
				break;
 

	
 
			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;
 

	
 
			case VLD_WIDGET_SERVICING_INTERVAL:
 
				/* Draw service interval text */
 
				SetDParam(0, v->service_interval);
src/vehicle_gui.h
Show inline comments
 
@@ -67,16 +67,16 @@ static inline bool ValidVLWFlags(uint16 
 
{
 
	return (flags == VLW_STANDARD || flags == VLW_SHARED_ORDERS || flags == VLW_STATION_LIST || flags == VLW_DEPOT_LIST || flags == VLW_GROUP_LIST);
 
}
 

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

	
 
uint ShowRefitOptionsList(int left, int right, int y, EngineID engine);
 
StringID GetCargoSubtypeText(const Vehicle *v);
 

	
0 comments (0 inline, 0 general)