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

Function DispatchMouseWheelEvent

src/window.cpp:820–850  ·  view source on GitHub ↗

* Dispatch the mousewheel-action to the window. * The window will scroll any compatible scrollbars if the mouse is pointed over the bar or its contents * @param w Window * @param nwid the widget where the scrollwheel was used * @param wheel scroll up or down */

Source from the content-addressed store, hash-verified

818 * @param wheel scroll up or down
819 */
820static void DispatchMouseWheelEvent(Window *w, NWidgetCore *nwid, int wheel)
821{
822 if (nwid == nullptr) return;
823
824 /* Using wheel on caption/shade-box shades or unshades the window. */
825 if (nwid->type == WWT_CAPTION || nwid->type == WWT_SHADEBOX) {
826 w->SetShaded(wheel < 0);
827 return;
828 }
829
830 /* Wheeling a vertical scrollbar. */
831 if (nwid->type == NWID_VSCROLLBAR) {
832 NWidgetScrollbar *sb = static_cast<NWidgetScrollbar *>(nwid);
833 if (sb->GetCount() > sb->GetCapacity()) {
834 if (sb->UpdatePosition(wheel)) {
835 w->OnScrollbarScroll(nwid->GetIndex());
836 w->SetDirty();
837 }
838 }
839 return;
840 }
841
842 /* Scroll the widget attached to the scrollbar. */
843 Scrollbar *sb = (nwid->GetScrollbarIndex() >= 0 ? w->GetScrollbar(nwid->GetScrollbarIndex()) : nullptr);
844 if (sb != nullptr && sb->GetCount() > sb->GetCapacity()) {
845 if (sb->UpdatePosition(wheel)) {
846 w->OnScrollbarScroll(nwid->GetScrollbarIndex());
847 w->SetDirty();
848 }
849 }
850}
851
852/**
853 * Returns whether a window may be shown or not.

Callers 1

MouseLoopFunction · 0.85

Calls 9

SetShadedMethod · 0.80
GetScrollbarIndexMethod · 0.80
GetScrollbarMethod · 0.80
GetCountMethod · 0.45
GetCapacityMethod · 0.45
UpdatePositionMethod · 0.45
OnScrollbarScrollMethod · 0.45
GetIndexMethod · 0.45
SetDirtyMethod · 0.45

Tested by

no test coverage detected