From ead0a6a6e52ff0b538ab5f345bd1ff6a11b30f8d Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 22 Mar 2009 10:37:51 +0000 Subject: (svn r15806) -Codechange: pass both left and right to the vehicle details drawing functions instead of only the left. --- src/ai/ai_gui.cpp | 6 ++--- src/aircraft_gui.cpp | 19 ++++++++-------- src/roadveh_gui.cpp | 22 +++++++++++++------ src/ship_gui.cpp | 19 ++++++++-------- src/train_gui.cpp | 62 +++++++++++++++++++++++++++++++++++++++------------- src/vehicle_gui.cpp | 31 +++++++++++++------------- 6 files changed, 101 insertions(+), 58 deletions(-) (limited to 'src') diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 76340b4ce..931335614 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -95,10 +95,10 @@ struct AIListWindow : public Window { /* Some info about the currently selected AI. */ if (selected_info != NULL) { int y = this->widget[AIL_WIDGET_INFO_BG].top + 6; - int x = DrawString(4, y, STR_AI_AUTHOR, TC_BLACK); + int x = DrawString(this->widget[AIL_WIDGET_LIST].left + 4, this->widget[AIL_WIDGET_LIST].right - 4, y, STR_AI_AUTHOR, TC_BLACK); DrawString(x + 5, this->widget[AIL_WIDGET_LIST].right - 4, y, selected_info->GetAuthor(), TC_BLACK); y += 13; - x = DrawString(4, y, STR_AI_VERSION, TC_BLACK); + x = DrawString(this->widget[AIL_WIDGET_LIST].left + 4, this->widget[AIL_WIDGET_LIST].right - 4, y, STR_AI_VERSION, TC_BLACK); static char buf[8]; sprintf(buf, "%d", selected_info->GetVersion()); DrawString(x + 5, this->widget[AIL_WIDGET_LIST].right - 4, y, buf, TC_BLACK); @@ -461,7 +461,7 @@ struct AIConfigWindow : public Window { byte max_competitors = _settings_newgame.difficulty.max_no_competitors; DrawArrowButtons(10, 18, COLOUR_YELLOW, this->clicked_button ? 1 + !!this->clicked_increase : 0, max_competitors > 0, max_competitors < MAX_COMPANIES - 1); SetDParam(0, _settings_newgame.difficulty.max_no_competitors); - DrawString(36, 18, STR_6805_MAXIMUM_NO_COMPETITORS, TC_FROMSTRING); + DrawString(36, this->widget[AIC_WIDGET_BACKGROUND].right, 18, STR_6805_MAXIMUM_NO_COMPETITORS, TC_FROMSTRING); int y = this->widget[AIC_WIDGET_LIST].top; for (int i = this->vscroll.pos; i < this->vscroll.pos + this->vscroll.cap && i < MAX_COMPANIES; i++) { diff --git a/src/aircraft_gui.cpp b/src/aircraft_gui.cpp index 9b73e5c73..ff0695e1f 100644 --- a/src/aircraft_gui.cpp +++ b/src/aircraft_gui.cpp @@ -15,13 +15,14 @@ #include "table/strings.h" /** - * Draw the details for the given vehicle at the position (x, y) + * Draw the details for the given vehicle at the given position * - * @param v current vehicle - * @param x The x coordinate - * @param y The y coordinate + * @param v current vehicle + * @param left The left most coordinate to draw + * @param right The right most coordinate to draw + * @param y The y coordinate */ -void DrawAircraftDetails(const Vehicle *v, int x, int y) +void DrawAircraftDetails(const Vehicle *v, int left, int right, int y) { int y_offset = (v->Next()->cargo_cap != 0) ? -11 : 0; Money feeder_share = 0; @@ -31,14 +32,14 @@ void DrawAircraftDetails(const Vehicle *v, int x, int y) SetDParam(0, u->engine_type); SetDParam(1, u->build_year); SetDParam(2, u->value); - DrawString(x, y, STR_A011_BUILT_VALUE, TC_FROMSTRING); + DrawString(left, right, y, STR_A011_BUILT_VALUE, TC_FROMSTRING); SetDParam(0, u->cargo_type); SetDParam(1, u->cargo_cap); SetDParam(2, u->Next()->cargo_type); SetDParam(3, u->Next()->cargo_cap); SetDParam(4, GetCargoSubtypeText(u)); - DrawString(x, y + 10, (u->Next()->cargo_cap != 0) ? STR_A019_CAPACITY : STR_A01A_CAPACITY, TC_FROMSTRING); + DrawString(left, right, y + 10, (u->Next()->cargo_cap != 0) ? STR_A019_CAPACITY : STR_A01A_CAPACITY, TC_FROMSTRING); } if (u->cargo_cap != 0) { @@ -50,14 +51,14 @@ void DrawAircraftDetails(const Vehicle *v, int x, int y) SetDParam(0, u->cargo_type); SetDParam(1, cargo_count); SetDParam(2, u->cargo.Source()); - DrawString(x, y + 21 + y_offset, STR_8813_FROM, TC_FROMSTRING); + DrawString(left, right, y + 21 + y_offset, STR_8813_FROM, TC_FROMSTRING); feeder_share += u->cargo.FeederShare(); } } } SetDParam(0, feeder_share); - DrawString(x, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING); + DrawString(left, right, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING); } diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp index 3c6e915e9..aa40c435d 100644 --- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -14,7 +14,15 @@ #include "table/sprites.h" #include "table/strings.h" -void DrawRoadVehDetails(const Vehicle *v, int x, int y) +/** + * Draw the details for the given vehicle at the given position + * + * @param v current vehicle + * @param left The left most coordinate to draw + * @param right The right most coordinate to draw + * @param y The y coordinate + */ +void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y) { uint y_offset = RoadVehHasArticPart(v) ? 15 : 0; StringID str; @@ -23,7 +31,7 @@ void DrawRoadVehDetails(const Vehicle *v, int x, int y) SetDParam(0, v->engine_type); SetDParam(1, v->build_year); SetDParam(2, v->value); - DrawString(x, y + y_offset, STR_9011_BUILT_VALUE, TC_FROMSTRING); + DrawString(left, right, y + y_offset, STR_9011_BUILT_VALUE, TC_FROMSTRING); if (RoadVehHasArticPart(v)) { AcceptedCargo max_cargo; @@ -65,7 +73,7 @@ void DrawRoadVehDetails(const Vehicle *v, int x, int y) } SetDParamStr(0, capacity); - DrawString(x, 300, y + 10 + y_offset, STR_JUST_RAW_STRING, TC_BLUE); + DrawString(left, right, y + 10 + y_offset, STR_JUST_RAW_STRING, TC_BLUE); for (const Vehicle *u = v; u != NULL; u = u->Next()) { if (u->cargo_cap == 0) continue; @@ -78,7 +86,7 @@ void DrawRoadVehDetails(const Vehicle *v, int x, int y) str = STR_8813_FROM; feeder_share += u->cargo.FeederShare(); } - DrawString(x, y + 21 + y_offset, str, TC_FROMSTRING); + DrawString(left, right, y + 21 + y_offset, str, TC_FROMSTRING); y_offset += 11; } @@ -88,7 +96,7 @@ void DrawRoadVehDetails(const Vehicle *v, int x, int y) SetDParam(0, v->cargo_type); SetDParam(1, v->cargo_cap); SetDParam(2, GetCargoSubtypeText(v)); - DrawString(x, y + 10 + y_offset, STR_9012_CAPACITY, TC_FROMSTRING); + DrawString(left, right, y + 10 + y_offset, STR_9012_CAPACITY, TC_FROMSTRING); str = STR_8812_EMPTY; if (!v->cargo.Empty()) { @@ -98,12 +106,12 @@ void DrawRoadVehDetails(const Vehicle *v, int x, int y) str = STR_8813_FROM; feeder_share += v->cargo.FeederShare(); } - DrawString(x, y + 21 + y_offset, str, TC_FROMSTRING); + DrawString(left, right, y + 21 + y_offset, str, TC_FROMSTRING); } /* Draw Transfer credits text */ SetDParam(0, feeder_share); - DrawString(x, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING); + DrawString(left, right, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING); } diff --git a/src/ship_gui.cpp b/src/ship_gui.cpp index b9e24d9f1..63fa751c7 100644 --- a/src/ship_gui.cpp +++ b/src/ship_gui.cpp @@ -35,23 +35,24 @@ void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2) } /** - * Draw the details for the given vehicle at the position (x, y) + * Draw the details for the given vehicle at the given position * - * @param v current vehicle - * @param x The x coordinate - * @param y The y coordinate + * @param v current vehicle + * @param left The left most coordinate to draw + * @param right The right most coordinate to draw + * @param y The y coordinate */ -void DrawShipDetails(const Vehicle *v, int x, int y) +void DrawShipDetails(const Vehicle *v, int left, int right, int y) { SetDParam(0, v->engine_type); SetDParam(1, v->build_year); SetDParam(2, v->value); - DrawString(x, y, STR_9816_BUILT_VALUE, TC_FROMSTRING); + DrawString(left, right, y, STR_9816_BUILT_VALUE, TC_FROMSTRING); SetDParam(0, v->cargo_type); SetDParam(1, v->cargo_cap); SetDParam(2, GetCargoSubtypeText(v)); - DrawString(x, y + 10, STR_9817_CAPACITY, TC_FROMSTRING); + DrawString(left, right, y + 10, STR_9817_CAPACITY, TC_FROMSTRING); StringID str = STR_8812_EMPTY; if (!v->cargo.Empty()) { @@ -60,9 +61,9 @@ void DrawShipDetails(const Vehicle *v, int x, int y) SetDParam(2, v->cargo.Source()); str = STR_8813_FROM; } - DrawString(x, y + 21, str, TC_FROMSTRING); + DrawString(left, right, y + 21, str, TC_FROMSTRING); /* Draw Transfer credits text */ SetDParam(0, v->cargo.FeederShare()); - DrawString(x, y + 33, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING); + DrawString(left, right, y + 33, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING); } diff --git a/src/train_gui.cpp b/src/train_gui.cpp index b36b1484a..e61755fe8 100644 --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -110,7 +110,15 @@ void DrawTrainImage(const Vehicle *v, int x, int y, VehicleID selection, int cou _cur_dpi = old_dpi; } -static void TrainDetailsCargoTab(const Vehicle *v, int x, int y) +/** + * Draw the details cargo tab for the given vehicle at the given position + * + * @param v current vehicle + * @param left The left most coordinate to draw + * @param right The right most coordinate to draw + * @param y The y coordinate + */ +static void TrainDetailsCargoTab(const Vehicle *v, int left, int right, int y) { if (v->cargo_cap != 0) { StringID str = STR_8812_EMPTY; @@ -122,32 +130,48 @@ static void TrainDetailsCargoTab(const Vehicle *v, int x, int y) SetDParam(3, _settings_game.vehicle.freight_trains); str = FreightWagonMult(v->cargo_type) > 1 ? STR_FROM_MULT : STR_8813_FROM; } - DrawString(x, y, str, TC_FROMSTRING); + DrawString(left, right, y, str, TC_FROMSTRING); } } -static void TrainDetailsInfoTab(const Vehicle *v, int x, int y) +/** + * Draw the details info tab for the given vehicle at the given position + * + * @param v current vehicle + * @param left The left most coordinate to draw + * @param right The right most coordinate to draw + * @param y The y coordinate + */ +static void TrainDetailsInfoTab(const Vehicle *v, int left, int right, int y) { if (RailVehInfo(v->engine_type)->railveh_type == RAILVEH_WAGON) { SetDParam(0, v->engine_type); SetDParam(1, v->value); - DrawString(x, y, STR_882D_VALUE, TC_BLACK); + DrawString(left, right, y, STR_882D_VALUE, TC_BLACK); } else { SetDParam(0, v->engine_type); SetDParam(1, v->build_year); SetDParam(2, v->value); - DrawString(x, y, STR_882C_BUILT_VALUE, TC_BLACK); + DrawString(left, right, y, STR_882C_BUILT_VALUE, TC_BLACK); } } -static void TrainDetailsCapacityTab(const Vehicle *v, int x, int y) +/** + * Draw the details capacity tab for the given vehicle at the given position + * + * @param v current vehicle + * @param left The left most coordinate to draw + * @param right The right most coordinate to draw + * @param y The y coordinate + */ +static void TrainDetailsCapacityTab(const Vehicle *v, int left, int right, int y) { if (v->cargo_cap != 0) { SetDParam(0, v->cargo_type); SetDParam(1, v->cargo_cap); SetDParam(2, GetCargoSubtypeText(v)); SetDParam(3, _settings_game.vehicle.freight_trains); - DrawString(x, y, FreightWagonMult(v->cargo_type) > 1 ? STR_CAPACITY_MULT : STR_013F_CAPACITY, TC_FROMSTRING); + DrawString(left, right, y, FreightWagonMult(v->cargo_type) > 1 ? STR_CAPACITY_MULT : STR_013F_CAPACITY, TC_FROMSTRING); } } @@ -182,12 +206,20 @@ int GetTrainDetailsWndVScroll(VehicleID veh_id, byte det_tab) return num; } -void DrawTrainDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint16 vscroll_cap, byte det_tab) +/** + * Draw the details for the given vehicle at the given position + * + * @param v current vehicle + * @param left The left most coordinate to draw + * @param right The right most coordinate to draw + * @param y The y coordinate + */ +void DrawTrainDetails(const Vehicle *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, byte det_tab) { /* draw the first 3 details tabs */ if (det_tab != 3) { const Vehicle *u = v; - x = 1; + int x = 1; for (;;) { if (--vscroll_pos < 0 && vscroll_pos >= -vscroll_cap) { int dx = 0; @@ -204,14 +236,14 @@ void DrawTrainDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint16 vs int py = y + 2; switch (det_tab) { default: NOT_REACHED(); - case 0: TrainDetailsCargoTab( v, px, py); break; + case 0: TrainDetailsCargoTab( v, px, right, py); break; case 1: /* Only show name and value for the 'real' part */ if (!IsArticulatedPart(v)) { - TrainDetailsInfoTab(v, px, py); + TrainDetailsInfoTab(v, px, right, py); } break; - case 2: TrainDetailsCapacityTab(v, px, py); break; + case 2: TrainDetailsCapacityTab(v, px, right, py); break; } y += 14; @@ -239,7 +271,7 @@ void DrawTrainDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint16 vs } /* draw total cargo tab */ - DrawString(x, y + 2, STR_TOTAL_CAPACITY_TEXT, TC_FROMSTRING); + DrawString(left, right, y + 2, STR_TOTAL_CAPACITY_TEXT, TC_FROMSTRING); for (CargoID i = 0; i < NUM_CARGO; i++) { if (max_cargo[i] > 0 && --vscroll_pos < 0 && vscroll_pos > -vscroll_cap) { y += 14; @@ -248,10 +280,10 @@ void DrawTrainDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint16 vs SetDParam(2, i); // {SHORTCARGO} #1 SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2 SetDParam(4, _settings_game.vehicle.freight_trains); - DrawString(x, y + 2, FreightWagonMult(i) > 1 ? STR_TOTAL_CAPACITY_MULT : STR_TOTAL_CAPACITY, TC_FROMSTRING); + DrawString(left, right, y + 2, FreightWagonMult(i) > 1 ? STR_TOTAL_CAPACITY_MULT : STR_TOTAL_CAPACITY, TC_FROMSTRING); } } SetDParam(0, feeder_share); - DrawString(x, y + 15, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING); + DrawString(left, right, y + 15, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING); } } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 923899aad..5362681a6 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1275,10 +1275,10 @@ static const StringID _vehicle_translation_table[][4] = { extern int GetTrainDetailsWndVScroll(VehicleID veh_id, byte det_tab); -extern void DrawTrainDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint16 vscroll_cap, byte det_tab); -extern void DrawRoadVehDetails(const Vehicle *v, int x, int y); -extern void DrawShipDetails(const Vehicle *v, int x, int y); -extern void DrawAircraftDetails(const Vehicle *v, int x, int y); +extern void DrawTrainDetails(const Vehicle *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, byte det_tab); +extern void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y); +extern void DrawShipDetails(const Vehicle *v, int left, int right, int y); +extern void DrawAircraftDetails(const Vehicle *v, int left, int right, int y); struct VehicleDetailsWindow : Window { int tab; @@ -1359,22 +1359,23 @@ struct VehicleDetailsWindow : Window { } /** - * Draw the details for the given vehicle at the position (x, y) of the Details windows + * Draw the details for the given vehicle at the position of the Details windows * - * @param v current vehicle - * @param x The x coordinate - * @param y The y coordinate + * @param v current vehicle + * @param left The left most coordinate to draw + * @param right The right most coordinate to draw + * @param y The y coordinate * @param vscroll_pos (train only) * @param vscroll_cap (train only) * @param det_tab (train only) */ - static void DrawVehicleDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint vscroll_cap, byte det_tab) + static void DrawVehicleDetails(const Vehicle *v, int left, int right, int y, int vscroll_pos, uint vscroll_cap, byte det_tab) { switch (v->type) { - case VEH_TRAIN: DrawTrainDetails(v, x, y, vscroll_pos, vscroll_cap, det_tab); break; - case VEH_ROAD: DrawRoadVehDetails(v, x, y); break; - case VEH_SHIP: DrawShipDetails(v, x, y); break; - case VEH_AIRCRAFT: DrawAircraftDetails(v, x, y); break; + case VEH_TRAIN: DrawTrainDetails(v, left, right, y, vscroll_pos, vscroll_cap, det_tab); break; + case VEH_ROAD: DrawRoadVehDetails(v, left, right, y); break; + case VEH_SHIP: DrawShipDetails(v, left, right, y); break; + case VEH_AIRCRAFT: DrawAircraftDetails(v, left, right, y); break; default: NOT_REACHED(); } } @@ -1457,14 +1458,14 @@ struct VehicleDetailsWindow : Window { switch (v->type) { case VEH_TRAIN: - DrawVehicleDetails(v, 2, 57, this->vscroll.pos, this->vscroll.cap, det_tab); + DrawVehicleDetails(v, 2, this->width - 2, 57, this->vscroll.pos, this->vscroll.cap, det_tab); break; case VEH_ROAD: case VEH_SHIP: case VEH_AIRCRAFT: DrawVehicleImage(v, 3, 57, INVALID_VEHICLE, 0, 0); - DrawVehicleDetails(v, 75, 57, this->vscroll.pos, this->vscroll.cap, det_tab); + DrawVehicleDetails(v, 75, this->width - 2, 57, this->vscroll.pos, this->vscroll.cap, det_tab); break; default: NOT_REACHED(); -- cgit v1.2.3-70-g09d2