MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / SetCount

Method SetCount

src/widget.cpp:1974–1992  ·  view source on GitHub ↗

* Set the number of elements in this matrix. * @note Updates the number of elements/capacity of the real scrollbar. * @param count The number of elements. */

Source from the content-addressed store, hash-verified

1972 * @param count The number of elements.
1973 */
1974void NWidgetMatrix::SetCount(int count)
1975{
1976 this->count = count;
1977
1978 if (this->sb == nullptr || this->widgets_x == 0) return;
1979
1980 /* We need to get the number of pixels the matrix is high/wide.
1981 * So, determine the number of rows/columns based on the number of
1982 * columns/rows (one is constant/unscrollable).
1983 * Then multiply that by the height of a widget, and add the pre
1984 * and post spacing "offsets". */
1985 count = CeilDiv(count, this->sb->IsVertical() ? this->widgets_x : this->widgets_y);
1986 count *= (this->sb->IsVertical() ? this->children.front()->smallest_y : this->children.front()->smallest_x) + this->pip_inter;
1987 if (count > 0) count -= this->pip_inter; // We counted an inter too much in the multiplication above
1988 count += this->pip_pre + this->pip_post;
1989 this->sb->SetCount(count);
1990 this->sb->SetCapacity(this->sb->IsVertical() ? this->current_y : this->current_x);
1991 this->sb->SetStepSize(this->sb->IsVertical() ? this->widget_h : this->widget_w);
1992}
1993
1994/**
1995 * Assign a scrollbar to this matrix.

Callers 15

AssignSizePositionMethod · 0.95
OnInvalidateDataMethod · 0.45
BuildSortSignListMethod · 0.45
BuildDisplayListMethod · 0.45
GenerateListsMethod · 0.45
OnInvalidateDataMethod · 0.45
OnInvalidateDataMethod · 0.45
UpdateScrollBarsMethod · 0.45
BuildAvailablesMethod · 0.45
SavePresetWindowMethod · 0.45
NewGRFInspectWindowMethod · 0.45
DrawMainPanelWidgetMethod · 0.45

Calls 4

CeilDivFunction · 0.85
IsVerticalMethod · 0.80
SetCapacityMethod · 0.80
SetStepSizeMethod · 0.80

Tested by

no test coverage detected