(svn r20223) -Codechange: Replace scrolled row calculations by a call to GetScrolledRowFromWidget().

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
alberth 14 years ago
parent 97f85f7bfb
commit 4203e641f8

@ -156,7 +156,7 @@ struct AIListWindow : public Window {
{ {
switch (widget) { switch (widget) {
case AIL_WIDGET_LIST: { // Select one of the AIs case AIL_WIDGET_LIST: { // Select one of the AIs
int sel = (pt.y - this->GetWidget<NWidgetBase>(AIL_WIDGET_LIST)->pos_y) / this->line_height + this->vscroll.GetPosition() - 1; int sel = this->vscroll.GetScrolledRowFromWidget(pt.y, this, AIL_WIDGET_LIST, 0, this->line_height) - 1;
if (sel < (int)this->ai_info_list->size()) { if (sel < (int)this->ai_info_list->size()) {
this->selected = sel; this->selected = sel;
this->SetDirty(); this->SetDirty();
@ -597,7 +597,7 @@ struct AIConfigWindow : public Window {
} }
case AIC_WIDGET_LIST: { // Select a slot case AIC_WIDGET_LIST: { // Select a slot
this->selected_slot = (CompanyID)((pt.y - this->GetWidget<NWidgetBase>(widget)->pos_y) / this->line_height + this->vscroll.GetPosition()); this->selected_slot = (CompanyID)this->vscroll.GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height);
this->InvalidateData(); this->InvalidateData();
if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot); if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot);
break; break;

@ -443,25 +443,27 @@ public:
case RVW_WIDGET_LEFT_MATRIX: case RVW_WIDGET_LEFT_MATRIX:
case RVW_WIDGET_RIGHT_MATRIX: { case RVW_WIDGET_RIGHT_MATRIX: {
uint i = (pt.y - this->GetWidget<NWidgetBase>(RVW_WIDGET_LEFT_MATRIX)->pos_y) / this->resize.step_height; uint i;
uint16 click_scroll_pos = widget == RVW_WIDGET_LEFT_MATRIX ? this->vscroll.GetPosition() : this->vscroll2.GetPosition(); byte click_side;
uint16 click_scroll_cap = widget == RVW_WIDGET_LEFT_MATRIX ? this->vscroll.GetCapacity() : this->vscroll2.GetCapacity(); if (widget == RVW_WIDGET_LEFT_MATRIX) {
byte click_side = widget == RVW_WIDGET_LEFT_MATRIX ? 0 : 1; i = this->vscroll.GetScrolledRowFromWidget(pt.y, this, RVW_WIDGET_LEFT_MATRIX);
size_t engine_count = this->engines[click_side].Length(); click_side = 0;
} else {
if (i < click_scroll_cap) { i = this->vscroll2.GetScrolledRowFromWidget(pt.y, this, RVW_WIDGET_RIGHT_MATRIX);
i += click_scroll_pos; click_side = 1;
EngineID e = engine_count > i ? this->engines[click_side][i] : INVALID_ENGINE;
if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
this->sel_engine[click_side] = e;
if (click_side == 0) {
this->engines[1].ForceRebuild();
this->reset_sel_engine = true;
}
this->SetDirty();
}
break;
} }
size_t engine_count = this->engines[click_side].Length();
EngineID e = engine_count > i ? this->engines[click_side][i] : INVALID_ENGINE;
if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
this->sel_engine[click_side] = e;
if (click_side == 0) {
this->engines[1].ForceRebuild();
this->reset_sel_engine = true;
}
this->SetDirty();
break;
}
} }
} }

@ -249,13 +249,10 @@ public:
switch (widget) { switch (widget) {
default: break; default: break;
case BBSW_BRIDGE_LIST: { case BBSW_BRIDGE_LIST: {
uint i = ((int)pt.y - this->GetWidget<NWidgetBase>(BBSW_BRIDGE_LIST)->pos_y) / this->resize.step_height; uint i = this->vscroll.GetScrolledRowFromWidget(pt.y, this, BBSW_BRIDGE_LIST);
if (i < this->vscroll.GetCapacity()) { if (i < this->bridges->Length()) {
i += this->vscroll.GetPosition(); this->BuildBridge(i);
if (i < this->bridges->Length()) { delete this;
this->BuildBridge(i);
delete this;
}
} }
} break; } break;

@ -1055,7 +1055,7 @@ struct BuildVehicleWindow : Window {
break; break;
case BUILD_VEHICLE_WIDGET_LIST: { case BUILD_VEHICLE_WIDGET_LIST: {
uint i = (pt.y - this->GetWidget<NWidgetBase>(BUILD_VEHICLE_WIDGET_LIST)->pos_y) / this->resize.step_height + this->vscroll.GetPosition(); uint i = this->vscroll.GetScrolledRowFromWidget(pt.y, this, BUILD_VEHICLE_WIDGET_LIST);
size_t num_items = this->eng_list.Length(); size_t num_items = this->eng_list.Length();
this->sel_engine = (i < num_items) ? this->eng_list[i] : INVALID_ENGINE; this->sel_engine = (i < num_items) ? this->eng_list[i] : INVALID_ENGINE;
this->SetDirty(); this->SetDirty();

@ -531,9 +531,8 @@ public:
break; break;
case SLWW_DRIVES_DIRECTORIES_LIST: { // Click the listbox case SLWW_DRIVES_DIRECTORIES_LIST: { // Click the listbox
int y = (pt.y - this->GetWidget<NWidgetBase>(SLWW_DRIVES_DIRECTORIES_LIST)->pos_y - WD_FRAMERECT_TOP) / this->resize.step_height; int y = this->vscroll.GetScrolledRowFromWidget(pt.y, this, SLWW_DRIVES_DIRECTORIES_LIST, WD_FRAMERECT_TOP);
if (y == INT_MAX) return;
if (y < 0 || (y += this->vscroll.GetPosition()) >= this->vscroll.GetCount()) return;
const FiosItem *file = _fios_items.Get(y); const FiosItem *file = _fios_items.Get(y);

@ -417,12 +417,7 @@ public:
break; break;
case GRP_WIDGET_LIST_GROUP: { // Matrix Group case GRP_WIDGET_LIST_GROUP: { // Matrix Group
uint16 id_g = (pt.y - this->GetWidget<NWidgetBase>(GRP_WIDGET_LIST_GROUP)->pos_y) / (int)this->tiny_step_height; uint id_g = this->vscroll2.GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_GROUP, 0, this->tiny_step_height);
if (id_g >= this->vscroll2.GetCapacity()) return;
id_g += this->vscroll2.GetPosition();
if (id_g >= this->groups.Length()) return; if (id_g >= this->groups.Length()) return;
this->group_sel = this->groups[id_g]->index; this->group_sel = this->groups[id_g]->index;
@ -433,11 +428,7 @@ public:
} }
case GRP_WIDGET_LIST_VEHICLE: { // Matrix Vehicle case GRP_WIDGET_LIST_VEHICLE: { // Matrix Vehicle
uint32 id_v = (pt.y - this->GetWidget<NWidgetBase>(GRP_WIDGET_LIST_VEHICLE)->pos_y) / (int)this->resize.step_height; uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_VEHICLE);
if (id_v >= this->vscroll.GetCapacity()) return; // click out of bounds
id_v += this->vscroll.GetPosition();
if (id_v >= this->vehicles.Length()) return; // click out of list bound if (id_v >= this->vehicles.Length()) return; // click out of list bound
const Vehicle *v = this->vehicles[id_v]; const Vehicle *v = this->vehicles[id_v];
@ -511,17 +502,11 @@ public:
break; break;
case GRP_WIDGET_LIST_GROUP: { // Maxtrix group case GRP_WIDGET_LIST_GROUP: { // Maxtrix group
uint16 id_g = (pt.y - this->GetWidget<NWidgetBase>(GRP_WIDGET_LIST_GROUP)->pos_y) / (int)this->tiny_step_height;
const VehicleID vindex = this->vehicle_sel; const VehicleID vindex = this->vehicle_sel;
this->vehicle_sel = INVALID_VEHICLE; this->vehicle_sel = INVALID_VEHICLE;
this->SetDirty(); this->SetDirty();
if (id_g >= this->vscroll2.GetCapacity()) return; uint id_g = this->vscroll2.GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_GROUP, 0, this->tiny_step_height);
id_g += this->vscroll2.GetPosition();
if (id_g >= this->groups.Length()) return; if (id_g >= this->groups.Length()) return;
DoCommandP(0, this->groups[id_g]->index, vindex, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE)); DoCommandP(0, this->groups[id_g]->index, vindex, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE));
@ -529,17 +514,11 @@ public:
} }
case GRP_WIDGET_LIST_VEHICLE: { // Maxtrix vehicle case GRP_WIDGET_LIST_VEHICLE: { // Maxtrix vehicle
uint32 id_v = (pt.y - this->GetWidget<NWidgetBase>(GRP_WIDGET_LIST_VEHICLE)->pos_y) / (int)this->resize.step_height;
const VehicleID vindex = this->vehicle_sel; const VehicleID vindex = this->vehicle_sel;
this->vehicle_sel = INVALID_VEHICLE; this->vehicle_sel = INVALID_VEHICLE;
this->SetDirty(); this->SetDirty();
if (id_v >= this->vscroll.GetCapacity()) return; // click out of bounds uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_VEHICLE);
id_v += this->vscroll.GetPosition();
if (id_v >= this->vehicles.Length()) return; // click out of list bound if (id_v >= this->vehicles.Length()) return; // click out of list bound
const Vehicle *v = this->vehicles[id_v]; const Vehicle *v = this->vehicles[id_v];

@ -459,9 +459,8 @@ public:
switch (widget) { switch (widget) {
case DPIW_MATRIX_WIDGET: { case DPIW_MATRIX_WIDGET: {
const IndustrySpec *indsp; const IndustrySpec *indsp;
int y = (pt.y - this->GetWidget<NWidgetBase>(DPIW_MATRIX_WIDGET)->pos_y) / this->resize.step_height + this->vscroll.GetPosition(); int y = this->vscroll.GetScrolledRowFromWidget(pt.y, this, DPIW_MATRIX_WIDGET);
if (y < this->count) { // Is it within the boundaries of available data?
if (y >= 0 && y < count) { // Is it within the boundaries of available data?
this->selected_index = y; this->selected_index = y;
this->selected_type = this->index[y]; this->selected_type = this->index[y];
indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(this->selected_type); indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? NULL : GetIndustrySpec(this->selected_type);
@ -1194,11 +1193,7 @@ public:
break; break;
case IDW_INDUSTRY_LIST: { case IDW_INDUSTRY_LIST: {
int y = (pt.y - this->GetWidget<NWidgetBase>(widget)->pos_y - WD_FRAMERECT_TOP) / this->resize.step_height; uint p = this->vscroll.GetScrolledRowFromWidget(pt.y, this, IDW_INDUSTRY_LIST, WD_FRAMERECT_TOP);
uint16 p;
if (!IsInsideMM(y, 0, this->vscroll.GetCapacity())) return;
p = y + this->vscroll.GetPosition();
if (p < this->industries.Length()) { if (p < this->industries.Length()) {
if (_ctrl_pressed) { if (_ctrl_pressed) {
ShowExtraViewPortWindow(this->industries[p]->location.tile); ShowExtraViewPortWindow(this->industries[p]->location.tile);

@ -590,11 +590,7 @@ public:
{ {
switch (widget) { switch (widget) {
case NCLWW_MATRIX: { case NCLWW_MATRIX: {
uint32 id_v = (pt.y - this->GetWidget<NWidgetBase>(NCLWW_MATRIX)->pos_y) / this->resize.step_height; uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, NCLWW_MATRIX);
if (id_v >= this->vscroll.GetCapacity()) return; // click out of bounds
id_v += this->vscroll.GetPosition();
if (id_v >= this->content.Length()) return; // click out of bounds if (id_v >= this->content.Length()) return; // click out of bounds
this->selected = *this->content.Get(id_v); this->selected = *this->content.Get(id_v);

@ -689,11 +689,7 @@ public:
break; break;
case NGWW_MATRIX: { // Matrix to show networkgames case NGWW_MATRIX: { // Matrix to show networkgames
uint32 id_v = (pt.y - this->GetWidget<NWidgetBase>(NGWW_MATRIX)->pos_y) / this->resize.step_height; uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, NGWW_MATRIX);
if (id_v >= this->vscroll.GetCapacity()) return; // click out of bounds
id_v += this->vscroll.GetPosition();
this->server = (id_v < this->servers.Length()) ? this->servers[id_v] : NULL; this->server = (id_v < this->servers.Length()) ? this->servers[id_v] : NULL;
this->list_pos = (server == NULL) ? SLP_INVALID : id_v; this->list_pos = (server == NULL) ? SLP_INVALID : id_v;
this->SetDirty(); this->SetDirty();
@ -1170,9 +1166,7 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
break; break;
case NSSW_SELMAP: { // Select map case NSSW_SELMAP: { // Select map
int y = (pt.y - this->GetWidget<NWidgetBase>(NSSW_SELMAP)->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL; int y = this->vscroll.GetScrolledRowFromWidget(pt.y, this, NSSW_SELMAP, WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL);
y += this->vscroll.GetPosition();
if (y >= this->vscroll.GetCount()) return; if (y >= this->vscroll.GetCount()) return;
this->map = (y == 0) ? NULL : _fios_items.Get(y - 1); this->map = (y == 0) ? NULL : _fios_items.Get(y - 1);
@ -1631,11 +1625,7 @@ struct NetworkLobbyWindow : public Window {
break; break;
case NLWW_MATRIX: { // Company list case NLWW_MATRIX: { // Company list
uint32 id_v = (pt.y - this->GetWidget<NWidgetBase>(NLWW_MATRIX)->pos_y) / this->resize.step_height; uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, NLWW_MATRIX);
if (id_v >= this->vscroll.GetCapacity()) break;
id_v += this->vscroll.GetPosition();
this->company = (id_v >= this->server->info.companies_on) ? INVALID_COMPANY : NetworkLobbyFindCompanyIndex(id_v); this->company = (id_v >= this->server->info.companies_on) ? INVALID_COMPANY : NetworkLobbyFindCompanyIndex(id_v);
this->SetDirty(); this->SetDirty();

@ -423,9 +423,8 @@ struct NewGRFInspectWindow : Window {
if (nif->variables == NULL) return; if (nif->variables == NULL) return;
/* Get the line, make sure it's within the boundaries. */ /* Get the line, make sure it's within the boundaries. */
int line = (pt.y - this->GetWidget<NWidgetBase>(NIW_MAINPANEL)->pos_y - TOP_OFFSET) / this->resize.step_height; int line = this->vscroll.GetScrolledRowFromWidget(pt.y, this, NIW_MAINPANEL, TOP_OFFSET);
if (line >= this->vscroll.GetCapacity()) return; if (line == INT_MAX) return;
line += this->vscroll.GetPosition();
/* Find the variable related to the line */ /* Find the variable related to the line */
for (const NIVariable *niv = nif->variables; niv->name != NULL; niv++, line--) { for (const NIVariable *niv = nif->variables; niv->name != NULL; niv++, line--) {

@ -482,8 +482,7 @@ struct NewGRFWindow : public QueryStringBaseWindow {
} }
case SNGRFS_FILE_LIST: { // Select an active GRF. case SNGRFS_FILE_LIST: { // Select an active GRF.
NWidgetBase *nw = this->GetWidget<NWidgetBase>(SNGRFS_FILE_LIST); uint i = this->vscroll.GetScrolledRowFromWidget(pt.y, this, SNGRFS_FILE_LIST);
uint i = (pt.y - nw->pos_y) / nw->resize_y + this->vscroll.GetPosition();
GRFConfig *c; GRFConfig *c;
for (c = this->actives; c != NULL && i > 0; c = c->next, i--) {} for (c = this->actives; c != NULL && i > 0; c = c->next, i--) {}
@ -526,8 +525,7 @@ struct NewGRFWindow : public QueryStringBaseWindow {
} }
case SNGRFS_AVAIL_LIST: { // Select a non-active GRF. case SNGRFS_AVAIL_LIST: { // Select a non-active GRF.
NWidgetBase *nw = this->GetWidget<NWidgetBase>(SNGRFS_AVAIL_LIST); uint i = this->vscroll2.GetScrolledRowFromWidget(pt.y, this, SNGRFS_AVAIL_LIST);
uint i = (pt.y - nw->pos_y) / nw->resize_y + this->vscroll2.GetPosition();
this->active_sel = NULL; this->active_sel = NULL;
if (i < this->avails.Length()) { if (i < this->avails.Length()) {
this->avail_sel = this->avails[i]; this->avail_sel = this->avails[i];

@ -1014,7 +1014,7 @@ struct MessageHistoryWindow : Window {
NewsItem *ni = _latest_news; NewsItem *ni = _latest_news;
if (ni == NULL) return; if (ni == NULL) return;
for (int n = (pt.y - this->GetWidget<NWidgetBase>(MHW_BACKGROUND)->pos_y - WD_FRAMERECT_TOP) / this->line_height + this->vscroll.GetPosition(); n > 0; n--) { for (int n = this->vscroll.GetScrolledRowFromWidget(pt.y, this, MHW_BACKGROUND, WD_FRAMERECT_TOP, this->line_height); n > 0; n--) {
ni = ni->prev; ni = ni->prev;
if (ni == NULL) return; if (ni == NULL) return;
} }

@ -1327,10 +1327,7 @@ public:
case BRSW_NEWST_LIST: { case BRSW_NEWST_LIST: {
const StationSpec *statspec; const StationSpec *statspec;
int y = (pt.y - this->GetWidget<NWidgetBase>(BRSW_NEWST_LIST)->pos_y) / this->line_height; int y = this->vscroll.GetScrolledRowFromWidget(pt.y, this, BRSW_NEWST_LIST, 0, this->line_height);
if (y >= this->vscroll.GetCapacity()) return;
y += this->vscroll.GetPosition();
if (y >= _railstation.station_count) return; if (y >= _railstation.station_count) return;
/* Check station availability callback */ /* Check station availability callback */

@ -1550,11 +1550,8 @@ struct GameSettingsWindow : Window {
{ {
if (widget != SETTINGSEL_OPTIONSPANEL) return; if (widget != SETTINGSEL_OPTIONSPANEL) return;
int y = pt.y - this->GetWidget<NWidgetBase>(widget)->pos_y - SETTINGTREE_TOP_OFFSET; // Shift y coordinate uint btn = this->vscroll.GetScrolledRowFromWidget(pt.y, this, SETTINGSEL_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET - 1);
if (y < 0) return; // Clicked above first entry if (btn == INT_MAX) return;
byte btn = this->vscroll.GetPosition() + y / this->resize.step_height; // Compute which setting is selected
if (y % this->resize.step_height > this->resize.step_height - 2) return; // Clicked too low at the setting
uint cur_row = 0; uint cur_row = 0;
SettingEntry *pe = _settings_main_page.FindEntry(btn, &cur_row); SettingEntry *pe = _settings_main_page.FindEntry(btn, &cur_row);

@ -148,11 +148,8 @@ struct SignListWindow : Window, SignList {
virtual void OnClick(Point pt, int widget, int click_count) virtual void OnClick(Point pt, int widget, int click_count)
{ {
if (widget == SLW_LIST) { if (widget == SLW_LIST) {
uint id_v = (pt.y - this->GetWidget<NWidgetBase>(SLW_LIST)->pos_y - WD_FRAMERECT_TOP) / this->resize.step_height; uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, SLW_LIST, WD_FRAMERECT_TOP);
if (id_v == INT_MAX) return;
if (id_v >= this->vscroll.GetCapacity()) return;
id_v += this->vscroll.GetPosition();
if (id_v >= this->vscroll.GetCount()) return;
const Sign *si = this->signs[id_v]; const Sign *si = this->signs[id_v];
ScrollMainWindowToTile(TileVirtXY(si->x, si->y)); ScrollMainWindowToTile(TileVirtXY(si->x, si->y));

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

@ -41,11 +41,7 @@ struct SubsidyListWindow : Window {
{ {
if (widget != SLW_PANEL) return; if (widget != SLW_PANEL) return;
int y = (pt.y - this->GetWidget<NWidgetBase>(SLW_PANEL)->pos_y - WD_FRAMERECT_TOP) / this->resize.step_height; int y = this->vscroll.GetScrolledRowFromWidget(pt.y, this, SLW_PANEL, WD_FRAMERECT_TOP);
if (!IsInsideMM(y, 0, this->vscroll.GetCapacity())) return;
y += this->vscroll.GetPosition();
int num = 0; int num = 0;
const Subsidy *s; const Subsidy *s;
FOR_ALL_SUBSIDIES(s) { FOR_ALL_SUBSIDIES(s) {

@ -873,12 +873,7 @@ public:
break; break;
case TDW_CENTERTOWN: { // Click on Town Matrix case TDW_CENTERTOWN: { // Click on Town Matrix
uint16 id_v = (pt.y - this->GetWidget<NWidgetBase>(widget)->pos_y - WD_FRAMERECT_TOP) / this->resize.step_height; uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, TDW_CENTERTOWN, WD_FRAMERECT_TOP);
if (id_v >= this->vscroll.GetCapacity()) return; // click out of bounds
id_v += this->vscroll.GetPosition();
if (id_v >= this->towns.Length()) return; // click out of town bounds if (id_v >= this->towns.Length()) return; // click out of town bounds
const Town *t = this->towns[id_v]; const Town *t = this->towns[id_v];

@ -528,11 +528,8 @@ struct RefitWindow : public Window {
{ {
switch (widget) { switch (widget) {
case VRW_MATRIX: { // listbox case VRW_MATRIX: { // listbox
int y = pt.y - this->GetWidget<NWidgetBase>(VRW_MATRIX)->pos_y; this->sel = this->vscroll.GetScrolledRowFromWidget(pt.y, this, VRW_MATRIX);
if (y >= 0) { this->InvalidateData(1);
this->sel = (y / (int)this->resize.step_height) + this->vscroll.GetPosition();
this->InvalidateData(1);
}
if (click_count == 1) break; if (click_count == 1) break;
} }
@ -1213,13 +1210,8 @@ public:
return; return;
case VLW_WIDGET_LIST: { // Matrix to show vehicles case VLW_WIDGET_LIST: { // Matrix to show vehicles
uint32 id_v = (pt.y - this->GetWidget<NWidgetBase>(VLW_WIDGET_LIST)->pos_y) / this->resize.step_height;
const Vehicle *v; const Vehicle *v;
uint id_v = this->vscroll.GetScrolledRowFromWidget(pt.y, this, VLW_WIDGET_LIST);
if (id_v >= this->vscroll.GetCapacity()) return; // click out of bounds
id_v += this->vscroll.GetPosition();
if (id_v >= this->vehicles.Length()) return; // click out of list bound if (id_v >= this->vehicles.Length()) return; // click out of list bound
v = this->vehicles[id_v]; v = this->vehicles[id_v];

Loading…
Cancel
Save