summaryrefslogtreecommitdiff
path: root/src/train_gui.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-07-13 19:30:37 +0000
committerfrosch <frosch@openttd.org>2009-07-13 19:30:37 +0000
commit3973b1e7cb5d244374e517879ec9f9017c95446f (patch)
tree7769354c7c21a3e878c093d85b843194e54bb189 /src/train_gui.cpp
parent3922860bb9e69281fdaaa48e2347c666728e18ee (diff)
downloadopenttd-3973b1e7cb5d244374e517879ec9f9017c95446f.tar.xz
(svn r16817) -Codechange: Scroll depots horizontally in pixels instead of 1/8 vehicle length.
Diffstat (limited to 'src/train_gui.cpp')
-rw-r--r--src/train_gui.cpp40
1 files changed, 18 insertions, 22 deletions
diff --git a/src/train_gui.cpp b/src/train_gui.cpp
index 9591da258..9ccf03eb0 100644
--- a/src/train_gui.cpp
+++ b/src/train_gui.cpp
@@ -73,41 +73,37 @@ int WagonLengthToPixels(int len)
* @param max_width Number of pixels space for drawing
* @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;
- int dx = -(skip * 8) / _traininfo_vehicle_width;
/* Position of highlight box */
int highlight_l = 0;
int highlight_r = 0;
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;
_cur_dpi = &tmp_dpi;
- do {
- int width = Train::From(v)->tcache.cached_veh_length;
-
- if (dx + width > 0) {
- if (dx <= count) {
- 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));
- if (v->index == selection) {
- /* Set the highlight position */
- highlight_l = WagonLengthToPixels(dx) + 1;
- highlight_r = WagonLengthToPixels(dx + width) + 1;
- } else if (_cursor.vehchain && highlight_r != 0) {
- highlight_r += WagonLengthToPixels(width);
- }
- }
+ int px = -skip;
+ for (; v != NULL && px < max_width; v = v->Next()) {
+ int width = WagonLengthToPixels(Train::From(v)->tcache.cached_veh_length);
+
+ if (px + width > 0) {
+ SpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
+ DrawSprite(v->GetImage(DIR_W), pal, px + 16, 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0));
}
- dx += width;
- v = v->Next();
- } while (dx < count && v != NULL);
+ if (v->index == selection) {
+ /* Set the highlight position */
+ highlight_l = px + 1;
+ highlight_r = px + width + 1;
+ } else if (_cursor.vehchain && highlight_r != 0) {
+ highlight_r += width;
+ }
+
+ px += width;
+ }
if (highlight_l != highlight_r) {
/* Draw the highlight. Now done after drawing all the engines, as