summaryrefslogtreecommitdiff
path: root/src
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
parent3922860bb9e69281fdaaa48e2347c666728e18ee (diff)
downloadopenttd-3973b1e7cb5d244374e517879ec9f9017c95446f.tar.xz
(svn r16817) -Codechange: Scroll depots horizontally in pixels instead of 1/8 vehicle length.
Diffstat (limited to 'src')
-rw-r--r--src/depot_gui.cpp18
-rw-r--r--src/train_gui.cpp40
-rw-r--r--src/vehicle_gui.cpp2
-rw-r--r--src/vehicle_gui.h2
4 files changed, 27 insertions, 35 deletions
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index 6bd364deb..9081c1336 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -269,7 +269,7 @@ struct DepotWindow : Window {
switch (v->type) {
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) */
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 */
for (; num < maxval; num++, y += 14) {
- const Vehicle *v = this->wagon_list[num - this->vehicle_list.Length()];
- const Vehicle *u;
+ const Train *v = Train::From(this->wagon_list[num - this->vehicle_list.Length()]);
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);
/* Draw the train counter */
i = 0;
- u = v;
- do i++; while ((u = u->Next()) != NULL); // Determine length of train
+ for (const Train *u = v; u != NULL; u = u->Next()) {
+ i++;
+ }
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
}
@@ -443,14 +443,11 @@ struct DepotWindow : Window {
/* 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;
- skip = (skip * 8) / _traininfo_vehicle_width;
- x = (x * 8) / _traininfo_vehicle_width;
-
/* Skip vehicles that are scrolled off the list */
x += skip;
/* 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 */
while (v != NULL && v->IsArticulatedPart()) v = v->Previous();
@@ -458,8 +455,7 @@ struct DepotWindow : Window {
d->wagon = v;
return MODE_DRAG_VEHICLE;
- }
- break;
+ }
case VEH_ROAD:
if (xm >= 24) return MODE_DRAG_VEHICLE;
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
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 407b563cf..a4fcf8811 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -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)
{
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_SHIP: DrawShipImage(v, x, y, selection); break;
case VEH_AIRCRAFT: DrawAircraftImage(v, x, y, selection); break;
diff --git a/src/vehicle_gui.h b/src/vehicle_gui.h
index 3371bd16c..45383341a 100644
--- a/src/vehicle_gui.h
+++ b/src/vehicle_gui.h
@@ -61,7 +61,7 @@ static inline bool ValidVLWFlags(uint16 flags)
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 DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection);
void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection);