(svn r18580) -Codechange: Use widget information only for setting scrollbar capacity.

This commit is contained in:
alberth 2009-12-20 20:08:39 +00:00
parent 20debea202
commit 5a083f183e
21 changed files with 53 additions and 39 deletions

View File

@ -906,7 +906,7 @@ struct AIDebugWindow : public Window {
virtual void OnResize()
{
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(AID_WIDGET_LOG_PANEL)->current_y / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, AID_WIDGET_LOG_PANEL);
}
};

View File

@ -480,8 +480,8 @@ public:
virtual void OnResize()
{
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(RVW_WIDGET_LEFT_MATRIX)->current_y / this->resize.step_height);
this->vscroll2.SetCapacity(this->GetWidget<NWidgetBase>(RVW_WIDGET_RIGHT_MATRIX)->current_y / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, RVW_WIDGET_LEFT_MATRIX);
this->vscroll2.SetCapacityFromWidget(this, RVW_WIDGET_RIGHT_MATRIX);
this->GetWidget<NWidgetCore>(RVW_WIDGET_LEFT_MATRIX)->widget_data =
this->GetWidget<NWidgetCore>(RVW_WIDGET_RIGHT_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);

View File

@ -280,7 +280,7 @@ public:
virtual void OnResize()
{
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(BBSW_BRIDGE_LIST)->current_y / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, BBSW_BRIDGE_LIST);
this->GetWidget<NWidgetCore>(BBSW_BRIDGE_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
this->last_size = max(this->vscroll.GetCapacity(), this->last_size);

View File

@ -1176,9 +1176,8 @@ struct BuildVehicleWindow : Window {
virtual void OnResize()
{
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(BUILD_VEHICLE_WIDGET_LIST);
this->vscroll.SetCapacity(nwi->current_y / this->resize.step_height);
nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
this->vscroll.SetCapacityFromWidget(this, BUILD_VEHICLE_WIDGET_LIST);
this->GetWidget<NWidgetCore>(BUILD_VEHICLE_WIDGET_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
}
};

View File

@ -941,12 +941,12 @@ struct DepotWindow : Window {
virtual void OnResize()
{
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX);
this->vscroll.SetCapacity(nwi->current_y / (int)this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, DEPOT_WIDGET_MATRIX);
if (this->type == VEH_TRAIN) {
this->hscroll.SetCapacity(nwi->current_x - this->header_width - this->count_width);
nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
} else {
this->hscroll.SetCapacity(nwi->current_x / (int)this->resize.step_width);
this->hscroll.SetCapacityFromWidget(this, DEPOT_WIDGET_MATRIX);
nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (this->hscroll.GetCapacity() << MAT_COL_START);
}
}

View File

@ -596,7 +596,7 @@ public:
nwi->widget_data = (this->vscroll2.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
nwi = this->GetWidget<NWidgetCore>(GRP_WIDGET_LIST_VEHICLE);
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(GRP_WIDGET_LIST_VEHICLE)->current_y / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, GRP_WIDGET_LIST_VEHICLE);
nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
}

View File

@ -445,7 +445,7 @@ public:
virtual void OnResize()
{
/* Adjust the number of items in the matrix depending of the resize */
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(DPIW_MATRIX_WIDGET)->current_y / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, DPIW_MATRIX_WIDGET);
this->GetWidget<NWidgetCore>(DPIW_MATRIX_WIDGET)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
}
@ -1138,7 +1138,7 @@ public:
virtual void OnResize()
{
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(IDW_INDUSTRY_LIST)->current_y / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, IDW_INDUSTRY_LIST);
}
virtual void OnHundredthTick()

View File

@ -2023,7 +2023,7 @@ public:
virtual void OnResize()
{
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(SLWW_DRIVES_DIRECTORIES_LIST)->current_y / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, SLWW_DRIVES_DIRECTORIES_LIST);
}
virtual void OnInvalidateData(int data)

View File

@ -730,7 +730,7 @@ public:
virtual void OnResize()
{
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(NCLWW_MATRIX)->current_y / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, NCLWW_MATRIX);
this->GetWidget<NWidgetCore>(NCLWW_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
}

View File

@ -895,9 +895,8 @@ public:
virtual void OnResize()
{
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(NGWW_MATRIX);
this->vscroll.SetCapacity(nwi->current_y / this->resize.step_height);
nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
this->vscroll.SetCapacityFromWidget(this, NGWW_MATRIX);
this->GetWidget<NWidgetCore>(NGWW_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
}
};
@ -1673,9 +1672,8 @@ struct NetworkLobbyWindow : public Window {
virtual void OnResize()
{
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(NLWW_MATRIX);
this->vscroll.SetCapacity(nwi->current_y / this->resize.step_height);
nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
this->vscroll.SetCapacityFromWidget(this, NLWW_MATRIX);
this->GetWidget<NWidgetCore>(NLWW_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
}
};

View File

@ -297,7 +297,7 @@ public:
virtual void OnResize()
{
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(ANGRFW_GRF_LIST)->current_y / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, ANGRFW_GRF_LIST);
}
virtual void OnPaint()
@ -621,9 +621,8 @@ struct NewGRFWindow : public Window {
virtual void OnResize()
{
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(SNGRFS_FILE_LIST);
this->vscroll.SetCapacity(nwi->current_y / this->resize.step_height);
nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
this->vscroll.SetCapacityFromWidget(this, SNGRFS_FILE_LIST);
this->GetWidget<NWidgetCore>(SNGRFS_FILE_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
}
virtual void SetStringParameters(int widget) const
@ -970,7 +969,7 @@ struct NewGRFWindow : public Window {
for (c = this->list, i = 0; c != NULL; c = c->next, i++) {}
this->vscroll.SetCapacity((this->GetWidget<NWidgetBase>(SNGRFS_FILE_LIST)->current_y) / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, SNGRFS_FILE_LIST);
this->GetWidget<NWidgetCore>(SNGRFS_FILE_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
this->vscroll.SetCount(i);
break;

View File

@ -1289,7 +1289,7 @@ public:
virtual void OnResize()
{
/* Update the scroll bar */
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(ORDER_WIDGET_ORDER_LIST)->current_y / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, ORDER_WIDGET_ORDER_LIST);
}
virtual void OnTimeout()

View File

@ -1625,7 +1625,7 @@ struct GameSettingsWindow : Window {
virtual void OnResize()
{
this->vscroll.SetCapacity((this->GetWidget<NWidgetBase>(SETTINGSEL_OPTIONSPANEL)->current_y - SETTINGTREE_TOP_OFFSET - SETTINGTREE_BOTTOM_OFFSET) / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, SETTINGSEL_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET);
}
};

View File

@ -158,7 +158,7 @@ struct SignListWindow : Window, SignList {
virtual void OnResize()
{
this->vscroll.SetCapacity((this->GetWidget<NWidgetBase>(SLW_LIST)->current_y - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM) / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, SLW_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)

View File

@ -604,7 +604,7 @@ public:
virtual void OnResize()
{
this->vscroll.SetCapacity((this->GetWidget<NWidgetBase>(SLW_LIST)->current_y - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM) / FONT_HEIGHT_NORMAL);
this->vscroll.SetCapacityFromWidget(this, SLW_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
}
virtual void OnInvalidateData(int data)
@ -1118,7 +1118,7 @@ struct StationViewWindow : public Window {
virtual void OnResize()
{
this->vscroll.SetCapacity((this->GetWidget<NWidgetBase>(SVW_WAITING)->current_y - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM) / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, SVW_WAITING, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
}
};
@ -1359,7 +1359,7 @@ struct SelectStationWindow : Window {
virtual void OnResize()
{
this->vscroll.SetCapacity((this->GetWidget<NWidgetBase>(JSW_PANEL)->current_y - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM) / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, JSW_PANEL, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
}
virtual void OnInvalidateData(int data)

View File

@ -217,7 +217,7 @@ struct SubsidyListWindow : Window {
virtual void OnResize()
{
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(SLW_PANEL)->current_y / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, SLW_PANEL);
}
virtual void OnInvalidateData(int data)

View File

@ -585,7 +585,7 @@ struct TimetableWindow : Window {
virtual void OnResize()
{
/* Update the scroll bar */
this->vscroll.SetCapacity((this->GetWidget<NWidgetBase>(TTV_TIMETABLE_PANEL)->current_y - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM) / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, TTV_TIMETABLE_PANEL, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
}
/**

View File

@ -845,7 +845,7 @@ public:
virtual void OnResize()
{
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(TDW_CENTERTOWN)->current_y / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, TDW_CENTERTOWN);
}
virtual void OnInvalidateData(int data)

View File

@ -494,9 +494,8 @@ struct RefitWindow : public Window {
virtual void OnResize()
{
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(VRW_MATRIX);
this->vscroll.SetCapacity(nwi->current_y / this->resize.step_height);
nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
this->vscroll.SetCapacityFromWidget(this, VRW_MATRIX);
this->GetWidget<NWidgetCore>(VRW_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
}
};
@ -1243,7 +1242,7 @@ public:
virtual void OnResize()
{
this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(VLW_WIDGET_LIST)->current_y / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, VLW_WIDGET_LIST);
this->GetWidget<NWidgetCore>(VLW_WIDGET_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
}
@ -1683,7 +1682,7 @@ struct VehicleDetailsWindow : Window {
{
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(VLD_WIDGET_MATRIX);
if (nwi != NULL) {
this->vscroll.SetCapacity(nwi->current_y / this->resize.step_height);
this->vscroll.SetCapacityFromWidget(this, VLD_WIDGET_MATRIX);
nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
}
}

View File

@ -78,6 +78,23 @@ WindowDesc::~WindowDesc()
{
}
/**
* Set capacity of visible elements from the size and resize properties of a widget.
* @param w Window.
* @param widget Widget with size and resize properties.
* @param padding Padding to subtract from the size.
* @note Updates the position if needed.
*/
void Scrollbar::SetCapacityFromWidget(Window *w, int widget, int padding)
{
NWidgetBase *nwid = w->GetWidget<NWidgetBase>(widget);
if (this->is_vertical) {
this->SetCapacity(((int)nwid->current_y - padding) / (int)nwid->resize_y);
} else {
this->SetCapacity(((int)nwid->current_x - padding) / (int)nwid->resize_x);
}
}
/**
* Set the window that has the focus
* @param w The window to set the focus on

View File

@ -247,6 +247,8 @@ public:
if (this->cap + this->pos > this->count) this->pos = max(0, this->count - this->cap);
}
void SetCapacityFromWidget(Window *w, int widget, int padding = 0);
/**
* Sets the position of the first visible element
* @param position the position of the element