summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-10-23 18:45:43 +0000
committerpeter1138 <peter1138@openttd.org>2006-10-23 18:45:43 +0000
commit4c11b5aef574087fa43159e5e4ee0f0cdc1d6fd4 (patch)
treee73bc759e69d13e07ce73c600d8ac0c7f1536fe8
parentf1b57ead1b26eb7e172e90c864b080d46a2e3412 (diff)
downloadopenttd-4c11b5aef574087fa43159e5e4ee0f0cdc1d6fd4.tar.xz
(svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
-rw-r--r--build_vehicle_gui.c8
-rw-r--r--roadveh_gui.c8
-rw-r--r--ship_gui.c8
-rw-r--r--train_gui.c14
-rw-r--r--vehicle_gui.c17
-rw-r--r--vehicle_gui.h10
6 files changed, 33 insertions, 32 deletions
diff --git a/build_vehicle_gui.c b/build_vehicle_gui.c
index 9fe1d97bc..a1cfe4755 100644
--- a/build_vehicle_gui.c
+++ b/build_vehicle_gui.c
@@ -208,7 +208,7 @@ static const StringID _aircraft_sort_listing[] = {
* @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 @@ void DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number)
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 @@ static void DrawBuildAircraftWindow(Window *w)
}
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);
diff --git a/roadveh_gui.c b/roadveh_gui.c
index 93863a63b..49adbea55 100644
--- a/roadveh_gui.c
+++ b/roadveh_gui.c
@@ -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 @@ void DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number)
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 @@ static void DrawNewRoadVehWindow(Window *w)
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);
}
}
diff --git a/ship_gui.c b/ship_gui.c
index 9c7a68686..e1762623e 100644
--- a/ship_gui.c
+++ b/ship_gui.c
@@ -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 @@ void DrawShipPurchaseInfo(int x, int y, EngineID engine_number)
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 @@ static void NewShipWndProc(Window *w, WindowEvent *e)
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;
}
diff --git a/train_gui.c b/train_gui.c
index 1c52d719b..118fb5a5c 100644
--- a/train_gui.c
+++ b/train_gui.c
@@ -235,7 +235,7 @@ static const StringID _engine_sort_listing[] = {
* @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 @@ void DrawTrainEnginePurchaseInfo(int x, int y, EngineID engine_number)
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 @@ void DrawTrainEnginePurchaseInfo(int x, int y, EngineID engine_number)
* @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 @@ void DrawTrainWagonPurchaseInfo(int x, int y, EngineID engine_number)
}
/* 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 @@ static void DrawTrainBuildWindow(Window *w)
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);
diff --git a/vehicle_gui.c b/vehicle_gui.c
index f171e8435..6a4ea4c42 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -990,20 +990,20 @@ static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int
}
}
-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 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
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 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
/* 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
diff --git a/vehicle_gui.h b/vehicle_gui.h
index 1b23a6399..7cc25ae3c 100644
--- a/vehicle_gui.h
+++ b/vehicle_gui.h
@@ -32,11 +32,11 @@ static inline bool ValidVLWFlags(uint16 flags)
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);