diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index b4808061b3..b37bcd17f4 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -205,7 +205,7 @@ struct AIListWindow : public Window { virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / this->line_height); + this->vscroll.SetCapacity(this->GetWidget(AIL_WIDGET_LIST)->current_y / this->line_height); this->GetWidget(AIL_WIDGET_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); } }; @@ -401,7 +401,7 @@ struct AISettingsWindow : public Window { virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / this->line_height); + this->vscroll.SetCapacity(this->GetWidget(AIS_WIDGET_BACKGROUND)->current_y / this->line_height); this->GetWidget(AIS_WIDGET_BACKGROUND)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); } @@ -662,8 +662,6 @@ struct AIDebugWindow : public Window { AIDebugWindow(const WindowDesc *desc, WindowNumber number) : Window() { - this->vscroll.SetCapacity(14); // Minimal number of lines in the log panel. - this->InitNested(desc, number); /* Disable the companies who are not active or not an AI */ for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { @@ -671,6 +669,8 @@ struct AIDebugWindow : public Window { } this->DisableWidget(AID_WIDGET_RELOAD_TOGGLE); + this->vscroll.SetCapacity(this->GetWidget(AID_WIDGET_LOG_PANEL)->current_y / this->resize.step_height); + this->last_vscroll_pos = 0; this->autoscroll = true; @@ -681,7 +681,7 @@ struct AIDebugWindow : public Window { { if (widget == AID_WIDGET_LOG_PANEL) { resize->height = FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL; - size->height = this->vscroll.GetCapacity() * resize->height + this->top_offset + this->bottom_offset; + size->height = 14 * resize->height + this->top_offset + this->bottom_offset; } } @@ -878,7 +878,7 @@ struct AIDebugWindow : public Window { virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity(this->GetWidget(AID_WIDGET_LOG_PANEL)->current_y / this->resize.step_height); } }; diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index 806f1fd2c5..444d428486 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -284,7 +284,7 @@ public: virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity(this->GetWidget(BBSW_BRIDGE_LIST)->current_y / this->resize.step_height); this->GetWidget(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 a6920a9253..a2af9cfe22 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1177,7 +1177,7 @@ struct BuildVehicleWindow : Window { } if (delta.y == 0) return; - this->vscroll.UpdateCapacity(delta.y / (int)GetVehicleListHeight(this->vehicle_type)); + this->vscroll.SetCapacity((this->widget[BUILD_VEHICLE_WIDGET_LIST].bottom - this->widget[BUILD_VEHICLE_WIDGET_LIST].top + 1) / GetVehicleListHeight(this->vehicle_type)); this->widget[BUILD_VEHICLE_WIDGET_LIST].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); } }; diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index d61a3fa874..671a97f6fd 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -906,8 +906,8 @@ struct DepotWindow : Window { virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); - this->hscroll.UpdateCapacity(delta.x / (int)this->resize.step_width); + this->vscroll.SetCapacity(this->GetWidget(DEPOT_WIDGET_MATRIX)->current_y / (int)this->resize.step_height); + this->hscroll.SetCapacity(this->GetWidget(DEPOT_WIDGET_MATRIX)->current_x / (int)this->resize.step_width); this->GetWidget(DEPOT_WIDGET_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + ((this->type == VEH_TRAIN ? 1 : this->hscroll.GetCapacity()) << MAT_COL_START); } diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 8c31e47140..4ec91214e1 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -614,10 +614,10 @@ public: virtual void OnResize(Point delta) { - this->vscroll2.UpdateCapacity(delta.y / PLY_WND_PRC__SIZE_OF_ROW_TINY); - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); - + this->vscroll2.SetCapacity((this->widget[GRP_WIDGET_LIST_GROUP].bottom - this->widget[GRP_WIDGET_LIST_GROUP].top + 1) / PLY_WND_PRC__SIZE_OF_ROW_TINY); this->widget[GRP_WIDGET_LIST_GROUP].data = (this->vscroll2.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); + + this->vscroll.SetCapacity((this->widget[GRP_WIDGET_LIST_VEHICLE].bottom - this->widget[GRP_WIDGET_LIST_VEHICLE].top + 1) / this->resize.step_height); this->widget[GRP_WIDGET_LIST_VEHICLE].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); } diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 84b5b11048..365e2da8e5 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -361,7 +361,7 @@ public: virtual void OnResize(Point delta) { /* Adjust the number of items in the matrix depending of the rezise */ - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity((this->widget[DPIW_MATRIX_WIDGET].bottom - this->widget[DPIW_MATRIX_WIDGET].top + 1) / this->resize.step_height); this->widget[DPIW_MATRIX_WIDGET].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); } @@ -1050,7 +1050,7 @@ public: virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity(this->GetWidget(IDW_INDUSTRY_LIST)->current_y / this->resize.step_height); } virtual void OnHundredthTick() diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 0085e42832..3150e1cae1 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1857,7 +1857,7 @@ public: case SLD_LOAD_SCENARIO: case SLD_LOAD_HEIGHTMAP: - this->vscroll.UpdateCapacity(-1); + this->vscroll.SetCapacity(this->vscroll.GetCapacity() - 1); case SLD_SAVE_GAME: this->GenerateFileName(); break; case SLD_SAVE_SCENARIO: strecpy(this->edit_str_buf, "UNNAMED", &this->edit_str_buf[edit_str_size - 1]); break; @@ -1974,7 +1974,7 @@ public: break; case SLWW_DRIVES_DIRECTORIES_LIST: { // Click the listbox - int y = (pt.y - this->widget[widget].top - 1) / 10; + int y = (pt.y - this->widget[SLWW_DRIVES_DIRECTORIES_LIST].top - 1) / 10; if (y < 0 || (y += this->vscroll.GetPosition()) >= this->vscroll.GetCount()) return; @@ -2092,7 +2092,7 @@ public: this->widget[SLWW_SAVE_GAME].left += diff; } - this->vscroll.UpdateCapacity(delta.y / 10); + this->vscroll.SetCapacity((this->widget[SLWW_DRIVES_DIRECTORIES_LIST].bottom - this->widget[SLWW_DRIVES_DIRECTORIES_LIST].top + 1) / 10); } virtual void OnInvalidateData(int data) diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 906796eb80..1a71964e69 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -692,7 +692,7 @@ public: virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity((this->widget[NCLWW_MATRIX].bottom - this->widget[NCLWW_MATRIX].top + 1) / this->resize.step_height); this->widget[NCLWW_MATRIX].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); /* Make the matrix and details section grow both bigger (or smaller) */ diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 085be44d8f..85ee499b80 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -714,7 +714,7 @@ public: virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity((this->widget[NGWW_MATRIX].bottom - this->widget[NGWW_MATRIX].top + 1) / this->resize.step_height); this->widget[NGWW_MATRIX].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); /* Additional colums in server list */ diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 5f4171c81e..c486e36b59 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -281,7 +281,7 @@ public: virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity(this->GetWidget(ANGRFW_GRF_LIST)->current_y / this->resize.step_height); } virtual void OnPaint() @@ -610,7 +610,7 @@ struct NewGRFWindow : public Window { virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity(this->GetWidget(SNGRFS_FILE_LIST)->current_y / this->resize.step_height); this->GetWidget(SNGRFS_FILE_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); } diff --git a/src/news_gui.cpp b/src/news_gui.cpp index c9992eb1af..ed78df793c 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -993,7 +993,7 @@ struct MessageHistoryWindow : Window { virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / this->line_height); + this->vscroll.SetCapacity(this->GetWidget(MHW_BACKGROUND)->current_y / this->line_height); } }; diff --git a/src/order_gui.cpp b/src/order_gui.cpp index fc6d60cef2..e985b4f215 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -1268,8 +1268,8 @@ public: virtual void OnResize(Point delta) { - /* Update the scroll + matrix */ - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + /* Update the scroll bar */ + this->vscroll.SetCapacity(this->GetWidget(ORDER_WIDGET_ORDER_LIST)->current_y / this->resize.step_height); } virtual void OnTimeout() diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 20864302c1..3315b6428b 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1625,7 +1625,7 @@ struct GameSettingsWindow : Window { virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / SETTING_HEIGHT); + this->vscroll.SetCapacity((this->widget[SETTINGSEL_OPTIONSPANEL].bottom - this->widget[SETTINGSEL_OPTIONSPANEL].top - 8) / SETTING_HEIGHT); } }; diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index 2143455061..1ff7c928bf 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -157,7 +157,7 @@ struct SignListWindow : Window, SignList { virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity((this->GetWidget(SLW_LIST)->current_y - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM) / this->resize.step_height); } virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize) diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 01e1caa630..3ab59320a5 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -566,7 +566,7 @@ public: virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / 10); + this->vscroll.SetCapacity((this->widget[SLW_LIST].bottom - this->widget[SLW_LIST].top + 1) / 10); } virtual void OnInvalidateData(int data) @@ -1052,7 +1052,7 @@ struct StationViewWindow : public Window { virtual void OnResize(Point delta) { if (delta.x != 0) ResizeButtons(this, SVW_LOCATION, SVW_RENAME); - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity((this->widget[SVW_WAITING].bottom - this->widget[SVW_WAITING].top + 1) / this->resize.step_height); } }; @@ -1296,7 +1296,7 @@ struct SelectStationWindow : Window { virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity((this->GetWidget(JSW_PANEL)->current_y - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM) / this->resize.step_height); } virtual void OnInvalidateData(int data) diff --git a/src/subsidy_gui.cpp b/src/subsidy_gui.cpp index 5754464a39..ca8b38a340 100644 --- a/src/subsidy_gui.cpp +++ b/src/subsidy_gui.cpp @@ -222,7 +222,7 @@ struct SubsidyListWindow : Window { virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity(this->GetWidget(SLW_PANEL)->current_y / this->resize.step_height); } virtual void OnInvalidateData(int data) diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 29f4b76af2..65a2dd7b83 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -333,8 +333,8 @@ struct TimetableWindow : Window { virtual void OnResize(Point delta) { - /* Update the scroll + matrix */ - this->vscroll.UpdateCapacity(delta.y / 10); + /* Update the scroll bar */ + this->vscroll.SetCapacity((this->widget[TTV_TIMETABLE_PANEL].bottom - this->widget[TTV_TIMETABLE_PANEL].top + 1) / this->resize.step_height); } }; diff --git a/src/town_gui.cpp b/src/town_gui.cpp index be0a0d4b41..138cb81bb2 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -659,7 +659,7 @@ public: this->BuildSortTownList(); this->InitNested(desc, 0); - this->vscroll.SetCapacity(this->GetWidget(TDW_CENTERTOWN)->current_y / (int)this->resize.step_height); + this->vscroll.SetCapacity(this->GetWidget(TDW_CENTERTOWN)->current_y / this->resize.step_height); } ~TownDirectoryWindow() @@ -803,7 +803,7 @@ public: virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity(this->GetWidget(TDW_CENTERTOWN)->current_y / this->resize.step_height); } virtual void OnInvalidateData(int data) diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 4af37ff2c8..f2cb72cd5e 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -389,7 +389,7 @@ struct RefitWindow : public Window { virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity((this->widget[VRW_MATRIX].bottom - this->widget[VRW_MATRIX].top + 1) / this->resize.step_height); this->widget[VRW_MATRIX].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); } }; @@ -1105,7 +1105,7 @@ struct VehicleListWindow : public BaseVehicleListWindow { virtual void OnResize(Point delta) { - this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->vscroll.SetCapacity((this->widget[VLW_WIDGET_LIST].bottom - this->widget[VLW_WIDGET_LIST].top + 1) / this->resize.step_height); this->widget[VLW_WIDGET_LIST].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); } @@ -1501,7 +1501,7 @@ struct VehicleDetailsWindow : Window { if (delta.x != 0) ResizeButtons(this, VLD_WIDGET_DETAILS_CARGO_CARRIED, VLD_WIDGET_DETAILS_TOTAL_CARGO); if (delta.y == 0) return; - this->vscroll.UpdateCapacity(delta.y / 14); + this->vscroll.SetCapacity((this->widget[VLD_WIDGET_MIDDLE_DETAILS].bottom - this->widget[VLD_WIDGET_MIDDLE_DETAILS].top + 1) / 14); this->widget[VLD_WIDGET_MIDDLE_DETAILS].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); } }; diff --git a/src/window_gui.h b/src/window_gui.h index 2e9b590b85..4204ec9cdf 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -257,17 +257,6 @@ public: if (this->cap + this->pos > this->count) this->pos = max(0, this->count - this->cap); } - /** - * Updates the capacity by adding/removing a number of (visible) elements. - * @param difference the difference in capacity - * @note updates the position if needed - */ - void UpdateCapacity(int difference) - { - if (difference == 0) return; - this->SetCapacity(this->cap + difference); - } - /** * Sets the position of the first visible element * @param position the position of the element