Codechange: Use GetScrolled(Row/Item)FromWidget in more places.

In many instances the clicked row position is 'manually' calculated
instead of using the GetScrolledRowFromWidget helper function, with
variations on checks. Replace with the two helpers where possible.
This commit is contained in:
2023-05-03 11:17:52 +01:00
committed by PeterN
parent 941dbadf9e
commit 531d1ae8bc
9 changed files with 34 additions and 40 deletions

View File

@@ -560,14 +560,10 @@ private:
*/
VehicleOrderID GetOrderFromPt(int y)
{
NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST);
uint sel = (y - nwid->pos_y - WidgetDimensions::scaled.framerect.top) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel.
if (sel >= this->vscroll->GetCapacity()) return INVALID_VEH_ORDER_ID;
sel += this->vscroll->GetPosition();
return (sel <= vehicle->GetNumOrders()) ? sel : INVALID_VEH_ORDER_ID;
int sel = this->vscroll->GetScrolledRowFromWidget(y, this, WID_O_ORDER_LIST, WidgetDimensions::scaled.framerect.top);
if (sel == INT_MAX) return INVALID_VEH_ORDER_ID;
assert(IsInsideBS(sel, 0, vehicle->GetNumOrders()));
return sel;
}
/**