diff --git a/src/console_gui.cpp b/src/console_gui.cpp index d9e3064b35..ad670390b1 100644 --- a/src/console_gui.cpp +++ b/src/console_gui.cpp @@ -361,8 +361,9 @@ struct IConsoleWindow : Window return GetCharAtPosition(_iconsole_cmdline.GetText(), pt.x - delta); } - void OnMouseWheel(int wheel) override + void OnMouseWheel(int wheel, WidgetID widget) override { + if (widget != WID_C_BACKGROUND) return; this->Scroll(-wheel); } diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 9186aa0a8d..2af39379fe 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1131,8 +1131,9 @@ public: } } - void OnMouseWheel(int wheel) override + void OnMouseWheel(int wheel, WidgetID widget) override { + if (widget != WID_IV_VIEWPORT) return; if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) { DoZoomInOutWindow(wheel < 0 ? ZOOM_IN : ZOOM_OUT, this); } diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 11432809a5..e07bc35621 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -433,8 +433,9 @@ struct MainWindow : Window this->refresh_timeout.Reset(); } - void OnMouseWheel(int wheel) override + void OnMouseWheel(int wheel, WidgetID widget) override { + if (widget != WID_M_VIEWPORT) return; if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) { bool in = wheel < 0; diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index eb4521be95..caba502d1e 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -1857,16 +1857,15 @@ public: return true; } - void OnMouseWheel(int wheel) override + void OnMouseWheel(int wheel, WidgetID widget) override { + if (widget != WID_SM_MAP) return; if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) { const NWidgetBase *wid = this->GetWidget(WID_SM_MAP); int cursor_x = _cursor.pos.x - this->left - wid->pos_x; int cursor_y = _cursor.pos.y - this->top - wid->pos_y; - if (IsInsideMM(cursor_x, 0, wid->current_x) && IsInsideMM(cursor_y, 0, wid->current_y)) { - Point pt = {cursor_x, cursor_y}; - this->SetZoomLevel((wheel < 0) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &pt); - } + Point pt = {cursor_x, cursor_y}; + this->SetZoomLevel((wheel < 0) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &pt); } } diff --git a/src/town_gui.cpp b/src/town_gui.cpp index bb1d25b9ae..4606a2fd44 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -577,8 +577,9 @@ public: } } - void OnMouseWheel(int wheel) override + void OnMouseWheel(int wheel, WidgetID widget) override { + if (widget != WID_TV_VIEWPORT) return; if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) { DoZoomInOutWindow(wheel < 0 ? ZOOM_IN : ZOOM_OUT, this); } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 8313be7a18..5d4f60122c 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -3332,8 +3332,9 @@ public: } } - void OnMouseWheel(int wheel) override + void OnMouseWheel(int wheel, WidgetID widget) override { + if (widget != WID_VV_VIEWPORT) return; if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) { DoZoomInOutWindow(wheel < 0 ? ZOOM_IN : ZOOM_OUT, this); } diff --git a/src/viewport_gui.cpp b/src/viewport_gui.cpp index 635be527cc..0ea8b683da 100644 --- a/src/viewport_gui.cpp +++ b/src/viewport_gui.cpp @@ -124,8 +124,9 @@ public: return widget == WID_EV_VIEWPORT; } - void OnMouseWheel(int wheel) override + void OnMouseWheel(int wheel, WidgetID widget) override { + if (widget != WID_EV_VIEWPORT) return; if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) { ZoomInOrOutToCursorWindow(wheel < 0, this); } diff --git a/src/window.cpp b/src/window.cpp index 650ab1591a..3386cc1d42 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -2823,7 +2823,11 @@ static void MouseLoop(MouseClick click, int mousewheel) if (mousewheel != 0) { /* Send mousewheel event to window, unless we're scrolling a viewport or the map */ - if (!scrollwheel_scrolling || (vp == nullptr && w->window_class != WC_SMALLMAP)) w->OnMouseWheel(mousewheel); + if (!scrollwheel_scrolling || (vp == nullptr && w->window_class != WC_SMALLMAP)) { + if (NWidgetCore *nwid = w->nested_root->GetWidgetFromPos(x - w->left, y - w->top); nwid != nullptr) { + w->OnMouseWheel(mousewheel, nwid->GetIndex()); + } + } /* Dispatch a MouseWheelEvent for widgets if it is not a viewport */ if (vp == nullptr) DispatchMouseWheelEvent(w, w->nested_root->GetWidgetFromPos(x - w->left, y - w->top), mousewheel); diff --git a/src/window_gui.h b/src/window_gui.h index 35289253b7..41fa29f5db 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -720,8 +720,9 @@ public: /** * The mouse wheel has been turned. * @param wheel the amount of movement of the mouse wheel. + * @param widget the widget the mouse hovers over. */ - virtual void OnMouseWheel([[maybe_unused]] int wheel) {} + virtual void OnMouseWheel([[maybe_unused]] int wheel, [[maybe_unused]] WidgetID widget) {} /**