mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 07:43:01 +01:00
Use (const) references to scrolls where possible
This commit is contained in:
@@ -568,7 +568,6 @@ void window_update_scroll_widgets(rct_window* w)
|
||||
{
|
||||
int32_t scrollIndex, width, height, scrollPositionChanged;
|
||||
rct_widgetindex widgetIndex;
|
||||
rct_scroll* scroll;
|
||||
rct_widget* widget;
|
||||
|
||||
widgetIndex = 0;
|
||||
@@ -579,32 +578,32 @@ void window_update_scroll_widgets(rct_window* w)
|
||||
if (widget->type != WindowWidgetType::Scroll)
|
||||
continue;
|
||||
|
||||
scroll = &w->scrolls[scrollIndex];
|
||||
auto& scroll = w->scrolls[scrollIndex];
|
||||
width = 0;
|
||||
height = 0;
|
||||
window_get_scroll_size(w, scrollIndex, &width, &height);
|
||||
if (height == 0)
|
||||
{
|
||||
scroll->v_top = 0;
|
||||
scroll.v_top = 0;
|
||||
}
|
||||
else if (width == 0)
|
||||
{
|
||||
scroll->h_left = 0;
|
||||
scroll.h_left = 0;
|
||||
}
|
||||
width++;
|
||||
height++;
|
||||
|
||||
scrollPositionChanged = 0;
|
||||
if ((widget->content & SCROLL_HORIZONTAL) && width != scroll->h_right)
|
||||
if ((widget->content & SCROLL_HORIZONTAL) && width != scroll.h_right)
|
||||
{
|
||||
scrollPositionChanged = 1;
|
||||
scroll->h_right = width;
|
||||
scroll.h_right = width;
|
||||
}
|
||||
|
||||
if ((widget->content & SCROLL_VERTICAL) && height != scroll->v_bottom)
|
||||
if ((widget->content & SCROLL_VERTICAL) && height != scroll.v_bottom)
|
||||
{
|
||||
scrollPositionChanged = 1;
|
||||
scroll->v_bottom = height;
|
||||
scroll.v_bottom = height;
|
||||
}
|
||||
|
||||
if (scrollPositionChanged)
|
||||
@@ -1292,8 +1291,9 @@ void window_resize(rct_window* w, int32_t dw, int32_t dh)
|
||||
// Update scroll widgets
|
||||
for (int32_t i = 0; i < 3; i++)
|
||||
{
|
||||
w->scrolls[i].h_right = WINDOW_SCROLL_UNDEFINED;
|
||||
w->scrolls[i].v_bottom = WINDOW_SCROLL_UNDEFINED;
|
||||
auto& scroll = w->scrolls[i];
|
||||
scroll.h_right = WINDOW_SCROLL_UNDEFINED;
|
||||
scroll.v_bottom = WINDOW_SCROLL_UNDEFINED;
|
||||
}
|
||||
window_update_scroll_widgets(w);
|
||||
|
||||
@@ -2183,63 +2183,63 @@ rct_windowclass window_get_classification(rct_window* window)
|
||||
void WidgetScrollUpdateThumbs(rct_window* w, rct_widgetindex widget_index)
|
||||
{
|
||||
const auto& widget = w->widgets[widget_index];
|
||||
rct_scroll* scroll = &w->scrolls[window_get_scroll_data_index(w, widget_index)];
|
||||
auto& scroll = w->scrolls[window_get_scroll_data_index(w, widget_index)];
|
||||
|
||||
if (scroll->flags & HSCROLLBAR_VISIBLE)
|
||||
if (scroll.flags & HSCROLLBAR_VISIBLE)
|
||||
{
|
||||
int32_t view_size = widget.width() - 21;
|
||||
if (scroll->flags & VSCROLLBAR_VISIBLE)
|
||||
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;
|
||||
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)
|
||||
if (scroll.flags & VSCROLLBAR_VISIBLE)
|
||||
x -= 11;
|
||||
x += scroll->h_left;
|
||||
if (scroll->h_right != 0)
|
||||
x = (x * view_size) / scroll->h_right;
|
||||
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);
|
||||
scroll.h_thumb_right = std::min(x, view_size);
|
||||
|
||||
if (scroll->h_thumb_right - scroll->h_thumb_left < 20)
|
||||
if (scroll.h_thumb_right - scroll.h_thumb_left < 20)
|
||||
{
|
||||
double barPosition = (scroll->h_thumb_right * 1.0) / view_size;
|
||||
double barPosition = (scroll.h_thumb_right * 1.0) / view_size;
|
||||
|
||||
scroll->h_thumb_left = static_cast<uint16_t>(std::lround(scroll->h_thumb_left - (20 * barPosition)));
|
||||
scroll->h_thumb_right = static_cast<uint16_t>(std::lround(scroll->h_thumb_right + (20 * (1 - barPosition))));
|
||||
scroll.h_thumb_left = static_cast<uint16_t>(std::lround(scroll.h_thumb_left - (20 * barPosition)));
|
||||
scroll.h_thumb_right = static_cast<uint16_t>(std::lround(scroll.h_thumb_right + (20 * (1 - barPosition))));
|
||||
}
|
||||
}
|
||||
|
||||
if (scroll->flags & VSCROLLBAR_VISIBLE)
|
||||
if (scroll.flags & VSCROLLBAR_VISIBLE)
|
||||
{
|
||||
int32_t view_size = widget.height() - 21;
|
||||
if (scroll->flags & HSCROLLBAR_VISIBLE)
|
||||
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;
|
||||
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)
|
||||
if (scroll.flags & HSCROLLBAR_VISIBLE)
|
||||
y -= 11;
|
||||
y += scroll->v_top;
|
||||
if (scroll->v_bottom != 0)
|
||||
y = (y * view_size) / scroll->v_bottom;
|
||||
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);
|
||||
scroll.v_thumb_bottom = std::min(y, view_size);
|
||||
|
||||
if (scroll->v_thumb_bottom - scroll->v_thumb_top < 20)
|
||||
if (scroll.v_thumb_bottom - scroll.v_thumb_top < 20)
|
||||
{
|
||||
double barPosition = (scroll->v_thumb_bottom * 1.0) / view_size;
|
||||
double barPosition = (scroll.v_thumb_bottom * 1.0) / view_size;
|
||||
|
||||
scroll->v_thumb_top = static_cast<uint16_t>(std::lround(scroll->v_thumb_top - (20 * barPosition)));
|
||||
scroll->v_thumb_bottom = static_cast<uint16_t>(std::lround(scroll->v_thumb_bottom + (20 * (1 - barPosition))));
|
||||
scroll.v_thumb_top = static_cast<uint16_t>(std::lround(scroll.v_thumb_top - (20 * barPosition)));
|
||||
scroll.v_thumb_bottom = static_cast<uint16_t>(std::lround(scroll.v_thumb_bottom + (20 * (1 - barPosition))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user