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

Method GetScrollOffsets

src/widget.cpp:2143–2163  ·  view source on GitHub ↗

* Get the different offsets that are influenced by scrolling. * @param[out] start_x The start position in columns (index of the left-most column, swapped in RTL). * @param[out] start_y The start position in rows. * @param[out] base_offs_x The base horizontal offset in pixels (X position of the column \a start_x). * @param[out] base_offs_y The base vertical offset in pixels (Y position

Source from the content-addressed store, hash-verified

2141 * @param[out] base_offs_y The base vertical offset in pixels (Y position of the column \a start_y).
2142 */
2143void NWidgetMatrix::GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y)
2144{
2145 base_offs_x = _current_text_dir == TD_RTL ? this->widget_w * (this->widgets_x - 1) : 0;
2146 base_offs_y = 0;
2147 start_x = 0;
2148 start_y = 0;
2149 if (this->sb != nullptr) {
2150 if (this->sb->IsVertical()) {
2151 start_y = this->sb->GetPosition() / this->widget_h;
2152 base_offs_y += -this->sb->GetPosition() + start_y * this->widget_h;
2153 } else {
2154 start_x = this->sb->GetPosition() / this->widget_w;
2155 int sub_x = this->sb->GetPosition() - start_x * this->widget_w;
2156 if (_current_text_dir == TD_RTL) {
2157 base_offs_x += sub_x;
2158 } else {
2159 base_offs_x -= sub_x;
2160 }
2161 }
2162 }
2163}
2164
2165/**
2166 * Constructor parent nested widgets.

Callers 2

GetWidgetFromPosMethod · 0.95
DrawMethod · 0.95

Calls 2

IsVerticalMethod · 0.80
GetPositionMethod · 0.80

Tested by

no test coverage detected