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

Function HandleActiveWidget

src/window.cpp:2407–2434  ·  view source on GitHub ↗

* Handle active widget (mouse dragging on widget) with the mouse. * @return State of handling the event. */

Source from the content-addressed store, hash-verified

2405 * @return State of handling the event.
2406 */
2407static EventState HandleActiveWidget()
2408{
2409 for (Window *w : Window::Iterate()) {
2410 if (w->mouse_capture_widget >= 0) {
2411 /* Abort if no button is clicked any more. */
2412 if (!_left_button_down) {
2413 w->SetWidgetDirty(w->mouse_capture_widget);
2414 w->mouse_capture_widget = INVALID_WIDGET;
2415 return ES_HANDLED;
2416 }
2417
2418 /* Handle scrollbar internally, or dispatch click event */
2419 WidgetType type = w->GetWidget<NWidgetBase>(w->mouse_capture_widget)->type;
2420 if (type == NWID_VSCROLLBAR || type == NWID_HSCROLLBAR) {
2421 HandleScrollbarScrolling(w);
2422 } else {
2423 /* If cursor hasn't moved, there is nothing to do. */
2424 if (_cursor.delta.x == 0 && _cursor.delta.y == 0) return ES_HANDLED;
2425
2426 Point pt = { _cursor.pos.x - w->left, _cursor.pos.y - w->top };
2427 w->OnClick(pt, w->mouse_capture_widget, 0);
2428 }
2429 return ES_HANDLED;
2430 }
2431 }
2432
2433 return ES_NOT_HANDLED;
2434}
2435
2436/**
2437 * Handle viewport scrolling with the mouse.

Callers 1

MouseLoopFunction · 0.85

Calls 4

HandleScrollbarScrollingFunction · 0.85
SetWidgetDirtyMethod · 0.80
OnClickMethod · 0.45

Tested by

no test coverage detected