diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index 69fc99e44b..fede79ef85 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -217,7 +217,7 @@ class ReplaceVehicleWindow : public Window { if (this->engines[0].NeedRebuild()) { /* We need to rebuild the left engines list */ this->GenerateReplaceVehList(true); - this->vscroll[0]->SetCount((uint)this->engines[0].size()); + this->vscroll[0]->SetCount(this->engines[0].size()); if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && this->engines[0].size() != 0) { this->sel_engine[0] = this->engines[0][0].engine_id; } @@ -237,7 +237,7 @@ class ReplaceVehicleWindow : public Window { } /* Regenerate the list on the right. Note: This resets sel_engine[1] to INVALID_ENGINE, if it is no longer available. */ this->GenerateReplaceVehList(false); - this->vscroll[1]->SetCount((uint)this->engines[1].size()); + this->vscroll[1]->SetCount(this->engines[1].size()); if (this->reset_sel_engine && this->sel_engine[1] != INVALID_ENGINE) { int position = 0; for (const auto &item : this->engines[1]) { diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index 0ed9ea78cc..f2e20c7b21 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -167,7 +167,7 @@ public: this->bridges->NeedResort(); this->SortBridgeList(); - this->vscroll->SetCount((uint)bl->size()); + this->vscroll->SetCount(bl->size()); } ~BuildBridgeWindow() diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 84ff30fb29..0e9a7d727a 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1787,7 +1787,7 @@ struct BuildVehicleWindow : Window { void OnPaint() override { this->GenerateBuildList(); - this->vscroll->SetCount((uint)this->eng_list.size()); + this->vscroll->SetCount(this->eng_list.size()); this->SetWidgetsDisabledState(this->sel_engine == INVALID_ENGINE, WID_BV_SHOW_HIDE, WID_BV_BUILD, WIDGET_LIST_END); diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index fa8aca26ec..e05682c5a5 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -735,7 +735,7 @@ struct DepotWindow : Window { max_width = std::max(max_width, width); } /* Always have 1 empty row, so people can change the setting of the train */ - this->vscroll->SetCount((uint)this->vehicle_list.size() + (uint)this->wagon_list.size() + 1); + this->vscroll->SetCount(this->vehicle_list.size() + this->wagon_list.size() + 1); /* Always make it longer than the longest train, so you can attach vehicles at the end, and also see the next vertical tile separator line */ this->hscroll->SetCount(max_width + ScaleSpriteTrad(2 * VEHICLEINFO_FULL_VEHICLE_WIDTH + 1)); } else { diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index bfe14e486d..07e55384d7 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -821,7 +821,7 @@ public: _fios_path_changed = true; this->fios_items.BuildFileList(this->abstract_filetype, this->fop); - this->vscroll->SetCount((uint)this->fios_items.size()); + this->vscroll->SetCount(this->fios_items.size()); this->selected = nullptr; _load_check_data.Clear(); diff --git a/src/game/game_gui.cpp b/src/game/game_gui.cpp index 0885f38db6..5ce1c3d7eb 100644 --- a/src/game/game_gui.cpp +++ b/src/game/game_gui.cpp @@ -127,7 +127,7 @@ struct GSConfigWindow : public Window { } } - this->vscroll->SetCount((int)this->visible_settings.size()); + this->vscroll->SetCount(this->visible_settings.size()); } void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 47e596177a..57d6cc9192 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -892,7 +892,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow { this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR); - this->vscroll->SetCount(static_cast(_sorted_standard_cargo_specs.size())); + this->vscroll->SetCount(_sorted_standard_cargo_specs.size()); /* Initialise the dataset */ this->UpdatePaymentRates(); diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 704c41ec91..f6521c34a9 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -364,7 +364,7 @@ public: this->groups.ForceRebuild(); this->groups.NeedResort(); this->BuildGroupList(vli.company); - this->group_sb->SetCount((uint)this->groups.size()); + this->group_sb->SetCount(this->groups.size()); this->GetWidget(WID_GL_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype; this->GetWidget(WID_GL_LIST_VEHICLE)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype; @@ -506,8 +506,8 @@ public: this->BuildGroupList(this->owner); - this->group_sb->SetCount(static_cast(this->groups.size())); - this->vscroll->SetCount(static_cast(this->vehgroups.size())); + this->group_sb->SetCount(this->groups.size()); + this->vscroll->SetCount(this->vehgroups.size()); /* The drop down menu is out, *but* it may not be used, retract it. */ if (this->vehicles.size() == 0 && this->IsWidgetLowered(WID_GL_MANAGE_VEHICLES_DROPDOWN)) { @@ -1087,7 +1087,7 @@ public: } this->groups.ForceRebuild(); this->BuildGroupList(this->owner); - this->group_sb->SetCount((uint)this->groups.size()); + this->group_sb->SetCount(this->groups.size()); id_g = find_index(this->groups, g); } this->group_sb->ScrollTowards(id_g); diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 1d85abbe8e..0b419637ba 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -325,7 +325,7 @@ class BuildIndustryWindow : public Window { this->UpdateAvailability(); - this->vscroll->SetCount((int)this->list.size()); + this->vscroll->SetCount(this->list.size()); } /** Update status of the fund and display-chain widgets. */ @@ -1419,7 +1419,7 @@ protected: IndustryDirectoryWindow::produced_cargo_filter = this->cargo_filter[this->produced_cargo_filter_criteria]; this->industries.Sort(); - this->vscroll->SetCount((uint)this->industries.size()); // Update scrollbar as well. + this->vscroll->SetCount(this->industries.size()); // Update scrollbar as well. this->SetDirty(); } diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 7d53329069..18b5470051 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -423,7 +423,7 @@ class NetworkContentListWindow : public Window, ContentCallback { this->content.RebuildDone(); this->SortContentList(); - this->vscroll->SetCount((int)this->content.size()); // Update the scrollbar + this->vscroll->SetCount(this->content.size()); // Update the scrollbar this->ScrollToSelected(); } diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 63f2284247..72d3d7d94b 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -279,7 +279,7 @@ protected: this->servers.shrink_to_fit(); this->servers.RebuildDone(); - this->vscroll->SetCount((int)this->servers.size()); + this->vscroll->SetCount(this->servers.size()); /* Sort the list of network games as requested. */ this->servers.Sort(); diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index ff927c2952..026768f15e 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -1055,7 +1055,7 @@ struct SpriteAlignerWindow : Window { if (data == 1) { /* Sprite picker finished */ this->RaiseWidget(WID_SA_PICKER); - this->vscroll->SetCount((uint)_newgrf_debug_sprite_picker.sprites.size()); + this->vscroll->SetCount(_newgrf_debug_sprite_picker.sprites.size()); } } diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 663de441c2..a4323dc98f 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -1490,7 +1490,7 @@ private: } } - this->vscroll2->SetCount((uint)this->avails.size()); // Update the scrollbar + this->vscroll2->SetCount(this->avails.size()); // Update the scrollbar } /** @@ -2068,7 +2068,7 @@ struct SavePresetWindow : public Window { this->vscroll = this->GetScrollbar(WID_SVP_SCROLLBAR); this->FinishInitNested(0); - this->vscroll->SetCount((uint)this->presets.size()); + this->vscroll->SetCount(this->presets.size()); this->SetFocusedWidget(WID_SVP_EDITBOX); if (initial_text != nullptr) this->presetname_editbox.text.Assign(initial_text); } diff --git a/src/object_gui.cpp b/src/object_gui.cpp index 414d930e5d..a598853e5b 100644 --- a/src/object_gui.cpp +++ b/src/object_gui.cpp @@ -125,7 +125,7 @@ public: ResetObjectToPlace(); - this->vscroll->SetCount((int)this->object_classes.size()); + this->vscroll->SetCount(this->object_classes.size()); EnsureSelectedObjectClassIsVisible(); @@ -166,7 +166,7 @@ public: this->object_classes.RebuildDone(); this->object_classes.Sort(); - this->vscroll->SetCount((uint)this->object_classes.size()); + this->vscroll->SetCount(this->object_classes.size()); } /** diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 71f7bd5a8a..54e7443825 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -929,7 +929,7 @@ private: if (station_class == _railstation.station_class) break; pos++; } - this->vscroll->SetCount((int)this->station_classes.size()); + this->vscroll->SetCount(this->station_classes.size()); this->vscroll->ScrollTowards(pos); } @@ -1075,7 +1075,7 @@ public: this->station_classes.RebuildDone(); this->station_classes.Sort(); - this->vscroll->SetCount((uint)this->station_classes.size()); + this->vscroll->SetCount(this->station_classes.size()); } } diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 2dc7ec39f9..4731f2e606 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -1135,7 +1135,7 @@ private: if (rs_class == _roadstop_gui_settings.roadstop_class) break; pos++; } - this->vscrollList->SetCount((int)this->roadstop_classes.size()); + this->vscrollList->SetCount(this->roadstop_classes.size()); this->vscrollList->ScrollTowards(pos); } @@ -1281,7 +1281,7 @@ public: this->roadstop_classes.RebuildDone(); this->roadstop_classes.Sort(); - this->vscrollList->SetCount((uint)this->roadstop_classes.size()); + this->vscrollList->SetCount(this->roadstop_classes.size()); } } diff --git a/src/script/script_gui.cpp b/src/script/script_gui.cpp index e77c1c7ede..673747f2cd 100644 --- a/src/script/script_gui.cpp +++ b/src/script/script_gui.cpp @@ -77,7 +77,7 @@ struct ScriptListWindow : public Window { this->vscroll = this->GetScrollbar(WID_SCRL_SCROLLBAR); this->FinishInitNested(); // Initializes 'this->line_height' as side effect. - this->vscroll->SetCount((int)this->info_list->size() + 1); + this->vscroll->SetCount(this->info_list->size() + 1); /* Try if we can find the currently selected AI */ this->selected = -1; @@ -231,7 +231,7 @@ struct ScriptListWindow : public Window { if (!gui_scope) return; - this->vscroll->SetCount((int)this->info_list->size() + 1); + this->vscroll->SetCount(this->info_list->size() + 1); /* selected goes from -1 .. length of ai list - 1. */ this->selected = std::min(this->selected, this->vscroll->GetCount() - 2); @@ -332,7 +332,7 @@ struct ScriptSettingsWindow : public Window { } } - this->vscroll->SetCount((int)this->visible_settings.size()); + this->vscroll->SetCount(this->visible_settings.size()); } void SetStringParameters(int widget) const override @@ -1070,7 +1070,7 @@ struct ScriptDebugWindow : public Window { this->SelectValidDebugCompany(); - this->vscroll->SetCount(script_debug_company != INVALID_COMPANY ? (int)this->GetLogData().size() : 0); + this->vscroll->SetCount(script_debug_company != INVALID_COMPANY ? this->GetLogData().size() : 0); /* Update company buttons */ for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index 925956b93f..070ee6261a 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -308,7 +308,7 @@ struct SignListWindow : Window, SignList { { if (this->signs.NeedRebuild()) { this->BuildSignsList(); - this->vscroll->SetCount((uint)this->signs.size()); + this->vscroll->SetCount(this->signs.size()); this->SetWidgetDirty(WID_SIL_CAPTION); } this->SortSignsList(); diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 052b5f2783..e206aec033 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -252,7 +252,7 @@ protected: this->stations.shrink_to_fit(); this->stations.RebuildDone(); - this->vscroll->SetCount((uint)this->stations.size()); // Update the scrollbar + this->vscroll->SetCount(this->stations.size()); // Update the scrollbar } /** Sort stations by their name */ @@ -2345,7 +2345,7 @@ struct SelectStationWindow : Window { { if (!gui_scope) return; FindStationsNearby(this->area, true); - this->vscroll->SetCount((uint)_stations_nearby_list.size() + 1); + this->vscroll->SetCount(_stations_nearby_list.size() + 1); this->SetDirty(); } diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 54142d1207..c42b92f58c 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -736,7 +736,7 @@ private: this->towns.shrink_to_fit(); this->towns.RebuildDone(); - this->vscroll->SetCount((uint)this->towns.size()); // Update scrollbar as well. + this->vscroll->SetCount(this->towns.size()); // Update scrollbar as well. } /* Always sort the towns. */ this->towns.Sort(); diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 80c9e7218b..50c5267ea9 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -224,7 +224,7 @@ void BaseVehicleListWindow::BuildVehicleList() } this->vehgroups.RebuildDone(); - this->vscroll->SetCount(static_cast(this->vehgroups.size())); + this->vscroll->SetCount(this->vehgroups.size()); } diff --git a/src/widget_type.h b/src/widget_type.h index 7643537aa5..0e8f940c60 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -704,10 +704,11 @@ public: * Set the distance to scroll when using the buttons or the wheel. * @param stepsize Scrolling speed. */ - void SetStepSize(uint16 stepsize) + void SetStepSize(size_t stepsize) { assert(stepsize > 0); - this->stepsize = stepsize; + + this->stepsize = ClampTo(stepsize); } /** @@ -715,12 +716,11 @@ public: * @param num the number of elements in the list * @note updates the position if needed */ - void SetCount(int num) + void SetCount(size_t num) { - assert(num >= 0); assert(num <= MAX_UVALUE(uint16)); - this->count = num; + this->count = ClampTo(num); num -= this->cap; if (num < 0) num = 0; if (num < this->pos) this->pos = num; @@ -731,12 +731,11 @@ public: * @param capacity the new capacity * @note updates the position if needed */ - void SetCapacity(int capacity) + void SetCapacity(size_t capacity) { - assert(capacity > 0); assert(capacity <= MAX_UVALUE(uint16)); - this->cap = capacity; + this->cap = ClampTo(capacity); if (this->cap + this->pos > this->count) this->pos = std::max(0, this->count - this->cap); } diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 1c7a7492e7..a9eb238453 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -172,8 +172,8 @@ struct DropdownWindow : Window { } /* Capacity is the average number of items visible */ - this->vscroll->SetCapacity(size.height * (uint16)this->list.size() / list_height); - this->vscroll->SetCount((uint16)this->list.size()); + this->vscroll->SetCapacity(size.height * this->list.size() / list_height); + this->vscroll->SetCount(this->list.size()); this->parent_wnd_class = parent->window_class; this->parent_wnd_num = parent->window_number;