1
0
Fork 0

(svn r16817) -Codechange: Scroll depots horizontally in pixels instead of 1/8 vehicle length.

release/1.0
frosch 2009-07-13 19:30:37 +00:00
parent 3922860bb9
commit 3973b1e7cb
4 changed files with 26 additions and 34 deletions

View File

@ -269,7 +269,7 @@ struct DepotWindow : Window {
switch (v->type) { switch (v->type) {
case VEH_TRAIN: case VEH_TRAIN:
DrawTrainImage(v, x + 21, sprite_y, this->sel, this->hscroll.cap + 4, this->hscroll.pos); DrawTrainImage(Train::From(v), x + 21, sprite_y, this->sel, this->hscroll.cap + 4, this->hscroll.pos);
/* Number of wagons relative to a standard length wagon (rounded up) */ /* Number of wagons relative to a standard length wagon (rounded up) */
SetDParam(0, (Train::From(v)->tcache.cached_total_length + 7) / 8); SetDParam(0, (Train::From(v)->tcache.cached_total_length + 7) / 8);
@ -366,16 +366,16 @@ struct DepotWindow : Window {
/* draw the train wagons, that do not have an engine in front */ /* draw the train wagons, that do not have an engine in front */
for (; num < maxval; num++, y += 14) { for (; num < maxval; num++, y += 14) {
const Vehicle *v = this->wagon_list[num - this->vehicle_list.Length()]; const Train *v = Train::From(this->wagon_list[num - this->vehicle_list.Length()]);
const Vehicle *u;
DrawTrainImage(v, x + 50, y, this->sel, this->hscroll.cap - 29, 0); DrawTrainImage(v, x + 50, y, this->sel, this->hscroll.cap - 29, 0);
DrawString(x, this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 2, STR_DEPOT_NO_ENGINE); DrawString(x, this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 2, STR_DEPOT_NO_ENGINE);
/* Draw the train counter */ /* Draw the train counter */
i = 0; i = 0;
u = v; for (const Train *u = v; u != NULL; u = u->Next()) {
do i++; while ((u = u->Next()) != NULL); // Determine length of train i++;
}
SetDParam(0, i); // Set the counter SetDParam(0, i); // Set the counter
DrawString(this->widget[DEPOT_WIDGET_MATRIX].left, this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING, SA_RIGHT); // Draw the counter DrawString(this->widget[DEPOT_WIDGET_MATRIX].left, this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING, SA_RIGHT); // Draw the counter
} }
@ -443,14 +443,11 @@ struct DepotWindow : Window {
/* either pressed the flag or the number, but only when it's a loco */ /* either pressed the flag or the number, but only when it's a loco */
if (x < 0 && v->IsFrontEngine()) return (x >= -10) ? MODE_START_STOP : MODE_SHOW_VEHICLE; if (x < 0 && v->IsFrontEngine()) return (x >= -10) ? MODE_START_STOP : MODE_SHOW_VEHICLE;
skip = (skip * 8) / _traininfo_vehicle_width;
x = (x * 8) / _traininfo_vehicle_width;
/* Skip vehicles that are scrolled off the list */ /* Skip vehicles that are scrolled off the list */
x += skip; x += skip;
/* find the vehicle in this row that was clicked */ /* find the vehicle in this row that was clicked */
while (v != NULL && (x -= v->tcache.cached_veh_length) >= 0) v = v->Next(); while (v != NULL && (x -= WagonLengthToPixels(v->tcache.cached_veh_length)) >= 0) v = v->Next();
/* if an articulated part was selected, find its parent */ /* if an articulated part was selected, find its parent */
while (v != NULL && v->IsArticulatedPart()) v = v->Previous(); while (v != NULL && v->IsArticulatedPart()) v = v->Previous();
@ -459,7 +456,6 @@ struct DepotWindow : Window {
return MODE_DRAG_VEHICLE; return MODE_DRAG_VEHICLE;
} }
break;
case VEH_ROAD: case VEH_ROAD:
if (xm >= 24) return MODE_DRAG_VEHICLE; if (xm >= 24) return MODE_DRAG_VEHICLE;

View File

@ -73,41 +73,37 @@ int WagonLengthToPixels(int len)
* @param max_width Number of pixels space for drawing * @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 Vehicle *v, int x, int y, VehicleID selection, int max_width, int skip) void DrawTrainImage(const Train *v, int x, int y, VehicleID selection, int max_width, int skip)
{ {
DrawPixelInfo tmp_dpi, *old_dpi; DrawPixelInfo tmp_dpi, *old_dpi;
int dx = -(skip * 8) / _traininfo_vehicle_width;
/* Position of highlight box */ /* Position of highlight box */
int highlight_l = 0; int highlight_l = 0;
int highlight_r = 0; int highlight_r = 0;
if (!FillDrawPixelInfo(&tmp_dpi, x - 2, y - 1, max_width + 1, 14)) return; if (!FillDrawPixelInfo(&tmp_dpi, x - 2, y - 1, max_width + 1, 14)) return;
int count = (max_width * 8) / _traininfo_vehicle_width;
old_dpi = _cur_dpi; old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi; _cur_dpi = &tmp_dpi;
do { int px = -skip;
int width = Train::From(v)->tcache.cached_veh_length; for (; v != NULL && px < max_width; v = v->Next()) {
int width = WagonLengthToPixels(Train::From(v)->tcache.cached_veh_length);
if (dx + width > 0) { if (px + width > 0) {
if (dx <= count) {
SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
DrawSprite(v->GetImage(DIR_W), pal, 16 + WagonLengthToPixels(dx), 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0)); DrawSprite(v->GetImage(DIR_W), pal, px + 16, 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
}
if (v->index == selection) { if (v->index == selection) {
/* Set the highlight position */ /* Set the highlight position */
highlight_l = WagonLengthToPixels(dx) + 1; highlight_l = px + 1;
highlight_r = WagonLengthToPixels(dx + width) + 1; highlight_r = px + width + 1;
} else if (_cursor.vehchain && highlight_r != 0) { } else if (_cursor.vehchain && highlight_r != 0) {
highlight_r += WagonLengthToPixels(width); highlight_r += width;
} }
}
}
dx += width;
v = v->Next(); px += width;
} while (dx < count && v != NULL); }
if (highlight_l != highlight_r) { if (highlight_l != highlight_r) {
/* Draw the highlight. Now done after drawing all the engines, as /* Draw the highlight. Now done after drawing all the engines, as

View File

@ -811,7 +811,7 @@ static void DrawSmallOrderList(const Vehicle *v, int left, int right, int y)
static void DrawVehicleImage(const Vehicle *v, int x, int y, VehicleID selection, int max_width, int skip) static void DrawVehicleImage(const Vehicle *v, int x, int y, VehicleID selection, int max_width, int skip)
{ {
switch (v->type) { switch (v->type) {
case VEH_TRAIN: DrawTrainImage(v, x, y, selection, max_width, skip); break; 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_ROAD: DrawRoadVehImage(v, x, y, selection, max_width); break;
case VEH_SHIP: DrawShipImage(v, x, y, selection); break; case VEH_SHIP: DrawShipImage(v, x, y, selection); break;
case VEH_AIRCRAFT: DrawAircraftImage(v, x, y, selection); break; case VEH_AIRCRAFT: DrawAircraftImage(v, x, y, selection); break;

View File

@ -61,7 +61,7 @@ static inline bool ValidVLWFlags(uint16 flags)
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number); int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number);
void DrawTrainImage(const Vehicle *v, int x, int y, VehicleID selection, int max_width, int skip); 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 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 DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection);
void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection); void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection);