diff --git a/src/station_gui.cpp b/src/station_gui.cpp --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -535,12 +535,7 @@ public: { switch (widget) { case SLW_LIST: { - uint32 id_v = (pt.y - this->GetWidget(SLW_LIST)->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL; - - if (id_v >= this->vscroll.GetCapacity()) return; // click out of bounds - - id_v += this->vscroll.GetPosition(); - + uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, SLW_LIST, 0, FONT_HEIGHT_NORMAL); if (id_v >= this->stations.Length()) return; // click out of list bound const Station *st = this->stations[id_v]; @@ -1152,7 +1147,7 @@ struct StationViewWindow : public Window { switch (widget) { case SVW_WAITING: - this->HandleCargoWaitingClick((pt.y - this->GetWidget(SVW_WAITING)->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL + this->vscroll.GetPosition()); + this->HandleCargoWaitingClick(this->vscroll.GetScrolledRowFromWidget(pt.y, this, SVW_WAITING, WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL)); break; case SVW_LOCATION: @@ -1416,7 +1411,7 @@ struct SelectStationWindow : Window { { if (widget != JSW_PANEL) return; - uint32 st_index = (pt.y - this->GetWidget(JSW_PANEL)->pos_y - WD_FRAMERECT_TOP) / this->resize.step_height + this->vscroll.GetPosition(); + uint st_index = this->vscroll.GetScrolledRowFromWidget(pt.y, this, JSW_PANEL, WD_FRAMERECT_TOP); bool distant_join = (st_index > 0); if (distant_join) st_index--;