changeset 13621:495608777888 draft

(svn r18145) -Codechange: pass the 'proper' left and right values to DrawVehicleInDepot
author rubidium <rubidium@openttd.org>
date Tue, 17 Nov 2009 16:03:51 +0000
parents 9f8a77b7c0e9
children ce894b771417
files src/depot_gui.cpp src/roadveh_gui.cpp
diffstat 2 files changed, 20 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -247,15 +247,15 @@
 
 	/** Draw a vehicle in the depot window in the box with the top left corner at x,y.
 	 * @param v     Vehicle to draw.
-	 * @param x     Left side of the box to draw in.
+	 * @param left  Left side of the box to draw in.
+	 * @param right Right side of the box to draw in.
 	 * @param y     Top of the box to draw in.
-	 * @param left  Left edge of the widget.
-	 * @param right Right edge of the widget.
 	 */
-	void DrawVehicleInDepot(const Vehicle *v, int x, int y, int left, int right) const
+	void DrawVehicleInDepot(const Vehicle *v, int left, int right, int y) const
 	{
 		bool free_wagon = false;
 		int sprite_y = y + this->resize.step_height - GetVehicleHeight(v->type);
+		int x = left + 2;
 
 		switch (v->type) {
 			case VEH_TRAIN: {
@@ -263,7 +263,7 @@
 				free_wagon = u->IsFreeWagon();
 
 				uint x_space = free_wagon ? TRAININFO_DEFAULT_VEHICLE_WIDTH : 0;
-				DrawTrainImage(u, x + 24 + x_space, x + 24 + this->hscroll.GetCapacity() - 1, sprite_y - 1, this->sel, this->hscroll.GetPosition());
+				DrawTrainImage(u, x + 24 + x_space, right - 10, 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,8 +271,8 @@
 				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_ROAD:     DrawRoadVehImage( v, x + 24, right, sprite_y, this->sel); break;
+			case VEH_SHIP:     DrawShipImage(    v, x + 12, right, sprite_y - 1, this->sel); break;
 			case VEH_AIRCRAFT: {
 				const Sprite *spr = GetSprite(v->GetImage(DIR_W), ST_NORMAL);
 				DrawAircraftImage(v, x + 12, right,
@@ -313,12 +313,13 @@
 
 		uint16 num = this->vscroll.GetPosition() * boxes_in_each_row;
 		int maxval = min(this->vehicle_list.Length(), num + (rows_in_display * boxes_in_each_row));
-		int x, y;
-		for (x = r.left + 2, y = r.top + 1; num < maxval; y += this->resize.step_height, x = r.left + 2) { // Draw the rows
+		int y;
+		for (y = r.top + 1; num < maxval; y += this->resize.step_height) { // Draw the rows
+			int x = r.left;
 			for (byte i = 0; i < boxes_in_each_row && num < maxval; i++, num++, x += this->resize.step_width) {
 				/* Draw all vehicles in the current row */
 				const Vehicle *v = this->vehicle_list[num];
-				this->DrawVehicleInDepot(v, x, y, r.left, r.right);
+				this->DrawVehicleInDepot(v, x, (boxes_in_each_row == 1) ? r.right : x + this->resize.step_width - 1, y);
 			}
 		}
 
@@ -327,7 +328,7 @@
 		/* draw the train wagons, that do not have an engine in front */
 		for (; num < maxval; num++, y += 14) {
 			const Vehicle *v = this->wagon_list[num - this->vehicle_list.Length()];
-			this->DrawVehicleInDepot(v, x, y, r.left, r.right);
+			this->DrawVehicleInDepot(v, r.left, r.right, y);
 		}
 	}
 
@@ -898,9 +899,13 @@
 	virtual void OnResize()
 	{
 		this->vscroll.SetCapacity(this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->current_y / (int)this->resize.step_height);
-		this->hscroll.SetCapacity(this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->current_x / (int)this->resize.step_width);
-		this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) +
-											((this->type == VEH_TRAIN ? 1 : this->hscroll.GetCapacity()) << MAT_COL_START);
+		if (this->type == VEH_TRAIN) {
+			this->hscroll.SetCapacity(this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->current_x - 36);
+			this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
+		} else {
+			this->hscroll.SetCapacity(this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->current_x / (int)this->resize.step_width);
+			this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (this->hscroll.GetCapacity() << MAT_COL_START);
+		}
 	}
 
 	virtual EventState OnCTRLStateChange()
--- a/src/roadveh_gui.cpp
+++ b/src/roadveh_gui.cpp
@@ -147,6 +147,7 @@
 		DrawSprite(u->GetImage(dir), pal, pos + (rtl ? -offset.x : offset.x), y + 6 + offset.y);
 
 		pos += rtl ? -width : width;
+		spent_width += max_width;
 	}
 
 	if (v->index == selection) {