1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

Move Ui window functions into Ui library (#22426)

* Move scroll widget functions

* Move window move functions

* De-snake

* Move further functions to ui

* Move widget function to widget file

* Move window create to ui
This commit is contained in:
Duncan
2024-07-31 15:06:19 +01:00
committed by GitHub
parent 681b54dc87
commit 3393fa36d3
8 changed files with 586 additions and 582 deletions

View File

@@ -1242,4 +1242,72 @@ namespace OpenRCT2::Ui
widget.content &= ~0xFF;
widget.content |= newPercentage;
}
/**
*
* rct2: 0x006EAF26
*/
void WidgetScrollUpdateThumbs(WindowBase& w, WidgetIndex widget_index)
{
const auto& widget = w.widgets[widget_index];
auto& scroll = w.scrolls[WindowGetScrollDataIndex(w, widget_index)];
if (scroll.flags & HSCROLLBAR_VISIBLE)
{
int32_t view_size = widget.width() - 21;
if (scroll.flags & VSCROLLBAR_VISIBLE)
view_size -= 11;
int32_t x = scroll.h_left * view_size;
if (scroll.h_right != 0)
x /= scroll.h_right;
scroll.h_thumb_left = x + 11;
x = widget.width() - 2;
if (scroll.flags & VSCROLLBAR_VISIBLE)
x -= 11;
x += scroll.h_left;
if (scroll.h_right != 0)
x = (x * view_size) / scroll.h_right;
x += 11;
view_size += 10;
scroll.h_thumb_right = std::min(x, view_size);
if (scroll.h_thumb_right - scroll.h_thumb_left < 20)
{
double barPosition = (scroll.h_thumb_right * 1.0) / view_size;
scroll.h_thumb_left = static_cast<int32_t>(std::lround(scroll.h_thumb_left - (20 * barPosition)));
scroll.h_thumb_right = static_cast<int32_t>(std::lround(scroll.h_thumb_right + (20 * (1 - barPosition))));
}
}
if (scroll.flags & VSCROLLBAR_VISIBLE)
{
int32_t view_size = widget.height() - 21;
if (scroll.flags & HSCROLLBAR_VISIBLE)
view_size -= 11;
int32_t y = scroll.v_top * view_size;
if (scroll.v_bottom != 0)
y /= scroll.v_bottom;
scroll.v_thumb_top = y + 11;
y = widget.height() - 2;
if (scroll.flags & HSCROLLBAR_VISIBLE)
y -= 11;
y += scroll.v_top;
if (scroll.v_bottom != 0)
y = (y * view_size) / scroll.v_bottom;
y += 11;
view_size += 10;
scroll.v_thumb_bottom = std::min(y, view_size);
if (scroll.v_thumb_bottom - scroll.v_thumb_top < 20)
{
double barPosition = (scroll.v_thumb_bottom * 1.0) / view_size;
scroll.v_thumb_top = static_cast<int32_t>(std::lround(scroll.v_thumb_top - (20 * barPosition)));
scroll.v_thumb_bottom = static_cast<int32_t>(std::lround(scroll.v_thumb_bottom + (20 * (1 - barPosition))));
}
}
}
} // namespace OpenRCT2::Ui