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

Function HandleScrollbarScrolling

src/window.cpp:2367–2401  ·  view source on GitHub ↗

* Handle scrollbar scrolling with the mouse. * @param w window with active scrollbar. */

Source from the content-addressed store, hash-verified

2365 * @param w window with active scrollbar.
2366 */
2367static void HandleScrollbarScrolling(Window *w)
2368{
2369 int i;
2370 NWidgetScrollbar *sb = w->GetWidget<NWidgetScrollbar>(w->mouse_capture_widget);
2371 bool rtl = false;
2372
2373 if (sb->type == NWID_HSCROLLBAR) {
2374 i = _cursor.pos.x - _cursorpos_drag_start.x;
2375 rtl = _current_text_dir == TD_RTL;
2376 } else {
2377 i = _cursor.pos.y - _cursorpos_drag_start.y;
2378 }
2379
2380 if (sb->disp_flags.Any({NWidgetDisplayFlag::ScrollbarUp, NWidgetDisplayFlag::ScrollbarDown})) {
2381 if (_scroller_click_timeout == 1) {
2382 _scroller_click_timeout = 3;
2383 if (sb->UpdatePosition(rtl == sb->disp_flags.Test(NWidgetDisplayFlag::ScrollbarUp) ? 1 : -1)) {
2384 w->OnScrollbarScroll(w->mouse_capture_widget);
2385 w->SetDirty();
2386 }
2387 }
2388 return;
2389 }
2390
2391 /* Find the item we want to move to. SetPosition will make sure it's inside bounds. */
2392 int range = sb->GetCount() - sb->GetCapacity();
2393 if (range <= 0) return;
2394
2395 int pos = RoundDivSU((i + _scrollbar_start_pos) * range, std::max(1, _scrollbar_size));
2396 if (rtl) pos = range - pos;
2397 if (sb->SetPosition(pos)) {
2398 w->OnScrollbarScroll(w->mouse_capture_widget);
2399 w->SetDirty();
2400 }
2401}
2402
2403/**
2404 * Handle active widget (mouse dragging on widget) with the mouse.

Callers 1

HandleActiveWidgetFunction · 0.85

Calls 9

RoundDivSUFunction · 0.85
AnyMethod · 0.80
TestMethod · 0.80
SetPositionMethod · 0.80
UpdatePositionMethod · 0.45
OnScrollbarScrollMethod · 0.45
SetDirtyMethod · 0.45
GetCountMethod · 0.45
GetCapacityMethod · 0.45

Tested by

no test coverage detected