(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
authorpeter1138
Mon, 23 Oct 2006 18:45:43 +0000
changeset 4930 fd91a88d6ef6
parent 4929 0eb123d23079
child 4931 6e09e884257d
(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
build_vehicle_gui.c
roadveh_gui.c
ship_gui.c
train_gui.c
vehicle_gui.c
vehicle_gui.h
--- a/build_vehicle_gui.c	Mon Oct 23 18:28:46 2006 +0000
+++ b/build_vehicle_gui.c	Mon Oct 23 18:45:43 2006 +0000
@@ -208,7 +208,7 @@
  * @param x,y location where to draw the info
  * @param engine_number the engine of which to draw the info of
  */
-void DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number)
+void DrawAircraftPurchaseInfo(int x, int y, uint w, EngineID engine_number)
 {
 	const AircraftVehicleInfo *avi = AircraftVehInfo(engine_number);
 	const Engine *e = GetEngine(engine_number);
@@ -255,8 +255,7 @@
 	y += 10;
 
 	/* Additional text from NewGRF */
-	// XXX 227 will become a calculated width...
-	y += ShowAdditionalText(x, y, 227, engine_number);
+	y += ShowAdditionalText(x, y, w, engine_number);
 }
 
 void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
@@ -427,7 +426,8 @@
 		}
 
 		if (selected_id != INVALID_ENGINE) {
-			DrawAircraftPurchaseInfo(x, w->widget[BUILD_VEHICLE_WIDGET_PANEL].top + 1, selected_id);
+			const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
+			DrawAircraftPurchaseInfo(x, wi->top + 1, wi->right - wi->left - 2, selected_id);
 		}
 	}
 	DrawString(85, 15, _aircraft_sort_listing[WP(w,buildvehicle_d).sort_criteria], 0x10);
--- a/roadveh_gui.c	Mon Oct 23 18:28:46 2006 +0000
+++ b/roadveh_gui.c	Mon Oct 23 18:45:43 2006 +0000
@@ -27,7 +27,7 @@
  * @param x,y location where to draw the info
  * @param engine_number the engine of which to draw the info of
  */
-void DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number)
+void DrawRoadVehPurchaseInfo(int x, int y, uint w, EngineID engine_number)
 {
 	const RoadVehicleInfo *rvi = RoadVehInfo(engine_number);
 	const Engine *e = GetEngine(engine_number);
@@ -65,8 +65,7 @@
 	y += 10;
 
 	/* Additional text from NewGRF */
-	// XXX 227 will become a calculated width...
-	y += ShowAdditionalText(x, y, 227, engine_number);
+	y += ShowAdditionalText(x, y, w, engine_number);
 }
 
 void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection)
@@ -432,7 +431,8 @@
 
 	WP(w,buildvehicle_d).sel_engine = selected_id;
 	if (selected_id != INVALID_ENGINE) {
-		DrawRoadVehPurchaseInfo(2, w->widget[4].top + 1, selected_id);
+		const Widget *wi = &w->widget[4];
+		DrawRoadVehPurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, selected_id);
 	}
 }
 
--- a/ship_gui.c	Mon Oct 23 18:28:46 2006 +0000
+++ b/ship_gui.c	Mon Oct 23 18:45:43 2006 +0000
@@ -27,7 +27,7 @@
  * @param x,y location where to draw the info
  * @param engine_number the engine of which to draw the info of
  */
-void DrawShipPurchaseInfo(int x, int y, EngineID engine_number)
+void DrawShipPurchaseInfo(int x, int y, uint w, EngineID engine_number)
 {
 	YearMonthDay ymd;
 	const ShipVehicleInfo *svi = ShipVehInfo(engine_number);
@@ -65,8 +65,7 @@
 	y += 10;
 
 	/* Additional text from NewGRF */
-	// XXX 227 will become a calculated width...
-	y += ShowAdditionalText(x, y, 227, engine_number);
+	y += ShowAdditionalText(x, y, w, engine_number);
 }
 
 void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection)
@@ -284,7 +283,8 @@
 			WP(w,buildvehicle_d).sel_engine = selected_id;
 
 			if (selected_id != INVALID_ENGINE) {
-				DrawShipPurchaseInfo(2, w->widget[4].top + 1, selected_id);
+				const Widget *wi = &w->widget[4];
+				DrawShipPurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, selected_id);
 			}
 			break;
 		}
--- a/train_gui.c	Mon Oct 23 18:28:46 2006 +0000
+++ b/train_gui.c	Mon Oct 23 18:45:43 2006 +0000
@@ -235,7 +235,7 @@
  * @param x,y location where to draw the info
  * @param engine_number the engine of which to draw the info of
  */
-void DrawTrainEnginePurchaseInfo(int x, int y, EngineID engine_number)
+void DrawTrainEnginePurchaseInfo(int x, int y, uint w, EngineID engine_number)
 {
 	const RailVehicleInfo *rvi = RailVehInfo(engine_number);
 	const Engine *e = GetEngine(engine_number);
@@ -292,8 +292,7 @@
 	y += 10;
 
 	/* Additional text from NewGRF */
-	// XXX 227 will become a calculated width...
-	y += ShowAdditionalText(x, y, 227, engine_number);
+	y += ShowAdditionalText(x, y, w, engine_number);
 }
 
 /**
@@ -301,7 +300,7 @@
  * @param x,y location where to draw the info
  * @param engine_number the engine of which to draw the info of
  */
-void DrawTrainWagonPurchaseInfo(int x, int y, EngineID engine_number)
+void DrawTrainWagonPurchaseInfo(int x, int y, uint w, EngineID engine_number)
 {
 	const RailVehicleInfo *rvi = RailVehInfo(engine_number);
 	bool refittable = (EngInfo(engine_number)->refit_mask != 0);
@@ -337,7 +336,7 @@
 	}
 
 	/* Additional text from NewGRF */
-	y += ShowAdditionalText(x, y, 227, engine_number);
+	y += ShowAdditionalText(x, y, w, engine_number);
 }
 
 void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
@@ -519,11 +518,12 @@
 
 	if (selected_id != INVALID_ENGINE) {
 		const RailVehicleInfo *rvi = RailVehInfo(selected_id);
+		const Widget *wi = &w->widget[BUILD_TRAIN_WIDGET_PANEL];
 
 		if (rvi->flags & RVI_WAGON) {
-			DrawTrainWagonPurchaseInfo(2, w->widget[BUILD_TRAIN_WIDGET_PANEL].top + 1, selected_id);
+			DrawTrainWagonPurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, selected_id);
 		} else {
-			DrawTrainEnginePurchaseInfo(2, w->widget[BUILD_TRAIN_WIDGET_PANEL].top + 1, selected_id);
+			DrawTrainEnginePurchaseInfo(2, wi->top + 1, wi->right - wi->left - 2, selected_id);
 		}
 	}
 	DrawString(85, 15, _engine_sort_listing[WP(w,buildvehicle_d).sort_criteria], 0x10);
--- a/vehicle_gui.c	Mon Oct 23 18:28:46 2006 +0000
+++ b/vehicle_gui.c	Mon Oct 23 18:45:43 2006 +0000
@@ -990,20 +990,20 @@
 	}
 }
 
-static void DrawVehiclePurchaseInfo(const int x, const int y, const EngineID engine_number)
+static void DrawVehiclePurchaseInfo(const int x, const int y, uint w, const EngineID engine_number)
 {
 	switch (GetEngine(engine_number)->type) {
 		case VEH_Train:
 			if ((RailVehInfo(engine_number)->flags & RVI_WAGON) == 0) {
-				DrawTrainEnginePurchaseInfo(x, y, engine_number);
+				DrawTrainEnginePurchaseInfo(x, y, w, engine_number);
 			} else {
-				DrawTrainWagonPurchaseInfo(x, y, engine_number);
+				DrawTrainWagonPurchaseInfo(x, y, w, engine_number);
 			}
 			break;
 
-		case VEH_Road: DrawRoadVehPurchaseInfo(x, y, engine_number);      break;
-		case VEH_Ship: DrawShipPurchaseInfo(x, y, engine_number);         break;
-		case VEH_Aircraft: DrawAircraftPurchaseInfo(x, y, engine_number); break;
+		case VEH_Road: DrawRoadVehPurchaseInfo(x, y, w, engine_number);      break;
+		case VEH_Ship: DrawShipPurchaseInfo(x, y, w, engine_number);         break;
+		case VEH_Aircraft: DrawAircraftPurchaseInfo(x, y, w, engine_number); break;
 		default: NOT_REACHED();
 	}
 }
@@ -1080,7 +1080,7 @@
 					SetDParam(0, STR_NOT_REPLACING_VEHICLE_SELECTED);
 				}
 
-				DrawString(145, 87 + w->resize.step_height * w->vscroll.cap, STR_02BD, 0x10);
+				DrawString(145, w->widget[5].top + 1, STR_02BD, 0x10);
 
 				/* now we draw the two arrays according to what we just counted */
 				DrawEngineArrayInReplaceWindow(w, x, y, x2, y2, pos, pos2, sel[0], sel[1], selected_id[0], selected_id[1]);
@@ -1090,7 +1090,8 @@
 				/* now we draw the info about the vehicles we selected */
 				for (i = 0 ; i < 2 ; i++) {
 					if (selected_id[i] != INVALID_ENGINE) {
-						DrawVehiclePurchaseInfo((i == 1) ? 230 : 2 , 15 + (w->resize.step_height * w->vscroll.cap), selected_id[i]);
+						const Widget *wi = &w->widget[i == 0 ? 3 : 11];
+						DrawVehiclePurchaseInfo(wi->left + 2 , wi->top + 1, wi->right - wi->left - 2, selected_id[i]);
 					}
 				}
 			} break;   // end of paint
--- a/vehicle_gui.h	Mon Oct 23 18:28:46 2006 +0000
+++ b/vehicle_gui.h	Mon Oct 23 18:45:43 2006 +0000
@@ -32,11 +32,11 @@
 
 void PlayerVehWndProc(Window *w, WindowEvent *e);
 
-void DrawTrainEnginePurchaseInfo(int x, int y, EngineID engine_number);
-void DrawTrainWagonPurchaseInfo(int x, int y, EngineID engine_number);
-void DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number);
-void DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number);
-void DrawShipPurchaseInfo(int x, int y, EngineID engine_number);
+void DrawTrainEnginePurchaseInfo(int x, int y, uint w, EngineID engine_number);
+void DrawTrainWagonPurchaseInfo(int x, int y, uint w, EngineID engine_number);
+void DrawRoadVehPurchaseInfo(int x, int y, uint w, EngineID engine_number);
+void DrawAircraftPurchaseInfo(int x, int y, uint w, EngineID engine_number);
+void DrawShipPurchaseInfo(int x, int y, uint w, EngineID engine_number);
 
 void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection);
 void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection);