From cf638e836a8bf93d9aaefc1f467ccb4740a948e3 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 8 Mar 2016 19:21:15 +0000 Subject: [PATCH] TBTR: Clip drawing of template vehicles. This fixes long templates running off the side of the window and/or obscuring the train length text. --- src/tbtr_template_gui_main.cpp | 2 +- src/tbtr_template_vehicle_func.cpp | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/tbtr_template_gui_main.cpp b/src/tbtr_template_gui_main.cpp index 2873372b63..3840baa103 100644 --- a/src/tbtr_template_gui_main.cpp +++ b/src/tbtr_template_gui_main.cpp @@ -679,7 +679,7 @@ public: } /* Draw the template */ - DrawTemplate(v, left + ScaleGUITrad(50), right, y); + DrawTemplate(v, left + ScaleGUITrad(36), right - ScaleGUITrad(24), y); /* Draw a notification string for chains that are not runnable */ if (v->IsFreeWagonChain()) { diff --git a/src/tbtr_template_vehicle_func.cpp b/src/tbtr_template_vehicle_func.cpp index 0c0b8d1050..43eb279663 100644 --- a/src/tbtr_template_vehicle_func.cpp +++ b/src/tbtr_template_vehicle_func.cpp @@ -119,16 +119,26 @@ void DrawTemplate(const TemplateVehicle *tv, int left, int right, int y) { if (!tv) return; + DrawPixelInfo tmp_dpi, *old_dpi; + int max_width = right - left + 1; + int height = ScaleGUITrad(14); + if (!FillDrawPixelInfo(&tmp_dpi, left, y, max_width, height)) return; + + old_dpi = _cur_dpi; + _cur_dpi = &tmp_dpi; + const TemplateVehicle *t = tv; - int offset = left; + int offset = 0; while (t) { PaletteID pal = GetEnginePalette(t->engine_type, _current_company); - DrawSprite(t->cur_image, pal, offset, y + ScaleGUITrad(11)); + DrawSprite(t->cur_image, pal, offset + t->image_width / 2, ScaleGUITrad(11)); offset += t->image_width; t = t->Next(); } + + _cur_dpi = old_dpi; } // copy important stuff from the virtual vehicle to the template