mirror of https://github.com/OpenTTD/OpenTTD
Fix: Odd drawing and crash if scrollbar is not tall enough. (#14052)
Under certain conditions the scrollbar "tab" could be too large for the scrollbar, and cause issues. Caused by an off-by-one in height calculation.pull/14018/head
parent
0efbb3a7a7
commit
e9a92b8795
|
@ -156,18 +156,18 @@ static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom, bo
|
||||||
button_size = NWidgetScrollbar::GetVerticalDimension().height;
|
button_size = NWidgetScrollbar::GetVerticalDimension().height;
|
||||||
}
|
}
|
||||||
top += button_size; // top points to just below the up-button
|
top += button_size; // top points to just below the up-button
|
||||||
bottom -= button_size; // bottom points to top of the down-button
|
bottom -= button_size; // bottom points to just before the down-button
|
||||||
|
|
||||||
int count = sb->GetCount();
|
int count = sb->GetCount();
|
||||||
int cap = sb->GetCapacity();
|
int cap = sb->GetCapacity();
|
||||||
|
|
||||||
if (count > cap) {
|
if (count > cap) {
|
||||||
int height = (bottom - top);
|
int height = bottom + 1 - top;
|
||||||
int slider_height = std::max(button_size, cap * height / count);
|
int slider_height = std::max(button_size, cap * height / count);
|
||||||
height -= slider_height;
|
height -= slider_height;
|
||||||
|
|
||||||
top += height * sb->GetPosition() / (count - cap);
|
top += height * sb->GetPosition() / (count - cap);
|
||||||
bottom = top + slider_height;
|
bottom = top + slider_height - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Point pt;
|
Point pt;
|
||||||
|
|
|
@ -2315,7 +2315,7 @@ static void HandleScrollbarScrolling(Window *w)
|
||||||
int range = sb->GetCount() - sb->GetCapacity();
|
int range = sb->GetCount() - sb->GetCapacity();
|
||||||
if (range <= 0) return;
|
if (range <= 0) return;
|
||||||
|
|
||||||
int pos = RoundDivSU((i + _scrollbar_start_pos) * range, _scrollbar_size);
|
int pos = RoundDivSU((i + _scrollbar_start_pos) * range, std::max(1, _scrollbar_size));
|
||||||
if (rtl) pos = range - pos;
|
if (rtl) pos = range - pos;
|
||||||
if (sb->SetPosition(pos)) w->SetDirty();
|
if (sb->SetPosition(pos)) w->SetDirty();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue