summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ai/ai_gui.cpp2
-rw-r--r--src/autoreplace_gui.cpp4
-rw-r--r--src/bridge_gui.cpp2
-rw-r--r--src/build_vehicle_gui.cpp5
-rw-r--r--src/depot_gui.cpp4
-rw-r--r--src/group_gui.cpp2
-rw-r--r--src/industry_gui.cpp4
-rw-r--r--src/misc_gui.cpp2
-rw-r--r--src/network/network_content_gui.cpp2
-rw-r--r--src/network/network_gui.cpp10
-rw-r--r--src/newgrf_gui.cpp9
-rw-r--r--src/order_gui.cpp2
-rw-r--r--src/settings_gui.cpp2
-rw-r--r--src/signs_gui.cpp2
-rw-r--r--src/station_gui.cpp6
-rw-r--r--src/subsidy_gui.cpp2
-rw-r--r--src/timetable_gui.cpp2
-rw-r--r--src/town_gui.cpp2
-rw-r--r--src/vehicle_gui.cpp9
-rw-r--r--src/window.cpp17
-rw-r--r--src/window_gui.h2
21 files changed, 53 insertions, 39 deletions
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp
index aa8ee1179..5aab3eaff 100644
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -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);
}
};
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp
index be39297f3..9bcde4c02 100644
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -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);
diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp
index 5f1c91967..e64fcd8ff 100644
--- a/src/bridge_gui.cpp
+++ b/src/bridge_gui.cpp
@@ -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);
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index f6b7a4dfe..d99bdea13 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -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);
}
};
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index c053fffc4..171d437d3 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -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);
}
}
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index 1c321c4b3..657a1e39e 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -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);
}
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 28697ae2f..73a6aa7f1 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -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()
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 156fc2b3e..d0f0690e0 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -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)
diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp
index b91aa02f2..7d3c223db 100644
--- a/src/network/network_content_gui.cpp
+++ b/src/network/network_content_gui.cpp
@@ -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);
}
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 4ba226266..514f38521 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -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);
}
};
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index 1515e4ba5..8b7e58ded 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -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;
diff --git a/src/order_gui.cpp b/src/order_gui.cpp
index 608ac3d62..8a1068c46 100644
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -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()
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index 37856e305..82c45a53d 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -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);
}
};
diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp
index 3b69bb0cb..67dab304d 100644
--- a/src/signs_gui.cpp
+++ b/src/signs_gui.cpp
@@ -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)
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index 9d2dfb26a..875689f4f 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -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)
diff --git a/src/subsidy_gui.cpp b/src/subsidy_gui.cpp
index 5798494fd..8f63615f9 100644
--- a/src/subsidy_gui.cpp
+++ b/src/subsidy_gui.cpp
@@ -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)
diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp
index 8bf59bb99..df9f28574 100644
--- a/src/timetable_gui.cpp
+++ b/src/timetable_gui.cpp
@@ -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);
}
/**
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index ff1b9baa6..e4cb0ab7a 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -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)
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 830c022b5..0e40b94e8 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -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);
}
}
diff --git a/src/window.cpp b/src/window.cpp
index 48f934f7b..29ddcdff6 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -79,6 +79,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
*/
diff --git a/src/window_gui.h b/src/window_gui.h
index 3cc9f45ea..d2635d881 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -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