train_gui.c
changeset 4049 d65bf8f154bc
parent 4041 72276cd8ee2b
child 4077 d4d440dd8925
equal deleted inserted replaced
4048:5d653b47d349 4049:d65bf8f154bc
   357 
   357 
   358 static void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
   358 static void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
   359 {
   359 {
   360 	DrawPixelInfo tmp_dpi, *old_dpi;
   360 	DrawPixelInfo tmp_dpi, *old_dpi;
   361 	int dx = -(skip * 8) / _traininfo_vehicle_width;
   361 	int dx = -(skip * 8) / _traininfo_vehicle_width;
   362 
   362 	/* Position of highlight box */
   363 	if (!FillDrawPixelInfo(&tmp_dpi, NULL, x - 1, y - 1, count, 14)) return;
   363 	int highlight_l = 0;
       
   364 	int highlight_r = 0;
       
   365 
       
   366 	if (!FillDrawPixelInfo(&tmp_dpi, NULL, x - 2, y - 1, count + 1, 14)) return;
   364 
   367 
   365 	count = (count * 8) / _traininfo_vehicle_width;
   368 	count = (count * 8) / _traininfo_vehicle_width;
   366 
   369 
   367 	old_dpi = _cur_dpi;
   370 	old_dpi = _cur_dpi;
   368 	_cur_dpi = &tmp_dpi;
   371 	_cur_dpi = &tmp_dpi;
   371 		int width = v->u.rail.cached_veh_length;
   374 		int width = v->u.rail.cached_veh_length;
   372 
   375 
   373 		if (dx + width > 0) {
   376 		if (dx + width > 0) {
   374 			if (dx <= count) {
   377 			if (dx <= count) {
   375 				PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
   378 				PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
   376 				DrawSprite(GetTrainImage(v, DIR_W) | pal, 15 + WagonLengthToPixels(dx), 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
   379 				DrawSprite(GetTrainImage(v, DIR_W) | pal, 16 + WagonLengthToPixels(dx), 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
   377 				if (v->index == selection)
   380 				if (v->index == selection) {
   378 					DrawFrameRect(WagonLengthToPixels(dx), 0, WagonLengthToPixels(dx + width), 13, 15, FR_BORDERONLY);
   381 					/* Set the highlight position */
       
   382 					highlight_l = WagonLengthToPixels(dx) + 1;
       
   383 					highlight_r = WagonLengthToPixels(dx + width) + 1;
       
   384 				}
   379 			}
   385 			}
   380 		}
   386 		}
   381 		dx += width;
   387 		dx += width;
   382 
   388 
   383 		v = v->next;
   389 		v = v->next;
   384 	} while (dx < count && v != NULL);
   390 	} while (dx < count && v != NULL);
       
   391 
       
   392 	if (highlight_l != highlight_r) {
       
   393 		/* Draw the highlight. Now done after drawing all the engines, as
       
   394 		 * the next engine after the highlight could overlap it. */
       
   395 		DrawFrameRect(highlight_l, 0, highlight_r, 13, 15, FR_BORDERONLY);
       
   396 	}
   385 
   397 
   386 	_cur_dpi = old_dpi;
   398 	_cur_dpi = old_dpi;
   387 }
   399 }
   388 
   400 
   389 static void DrawTrainDepotWindow(Window *w)
   401 static void DrawTrainDepotWindow(Window *w)