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:
Peter Nelson
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

@@ -215,13 +215,10 @@ struct TimetableWindow : Window {
int GetOrderFromTimetableWndPt(int y, const Vehicle *v)
{
uint sel = (y - this->GetWidget<NWidgetBase>(WID_VT_TIMETABLE_PANEL)->pos_y - WidgetDimensions::scaled.framerect.top) / FONT_HEIGHT_NORMAL;
if (sel >= this->vscroll->GetCapacity()) return INVALID_ORDER;
sel += this->vscroll->GetPosition();
return (sel < v->GetNumOrders() * 2u) ? sel : INVALID_ORDER;
int sel = this->vscroll->GetScrolledRowFromWidget(y, this, WID_VT_TIMETABLE_PANEL, WidgetDimensions::scaled.framerect.top);
if (sel == INT_MAX) return INVALID_ORDER;
assert(IsInsideBS(sel, 0, v->GetNumOrders() * 2));
return sel;
}
/**