diff --git a/src/main_gui.cpp b/src/main_gui.cpp index e31dbf1ea2..df9417f523 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -87,10 +87,11 @@ void CcPlaySound_EXPLOSION(Commands, const CommandCost &result, TileIndex tile) * Zooms a viewport in a window in or out. * @param how Zooming direction. * @param w Window owning the viewport. + * @param stop_following Should we stop following the vehicle in the viewport? * @return Returns \c true if zooming step could be done, \c false if further zooming is not possible. * @note No button handling or what so ever is done. */ -bool DoZoomInOutWindow(ZoomStateChange how, Window *w) +bool DoZoomInOutWindow(ZoomStateChange how, Window *w, bool stop_following) { Viewport *vp; @@ -112,7 +113,7 @@ bool DoZoomInOutWindow(ZoomStateChange how, Window *w) w->viewport->scrollpos_y += vp->virtual_height >> 1; w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x; w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y; - w->viewport->follow_vehicle = INVALID_VEHICLE; + if (stop_following) w->viewport->follow_vehicle = INVALID_VEHICLE; break; case ZOOM_OUT: if (vp->zoom >= _settings_client.gui.zoom_max) return false; @@ -125,7 +126,7 @@ bool DoZoomInOutWindow(ZoomStateChange how, Window *w) vp->virtual_width <<= 1; vp->virtual_height <<= 1; - w->viewport->follow_vehicle = INVALID_VEHICLE; + if (stop_following) w->viewport->follow_vehicle = INVALID_VEHICLE; break; } if (vp != nullptr) { // the vp can be null when how == ZOOM_NONE diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 0a5ac98d30..1b86da51c0 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -3317,6 +3317,13 @@ public: } } + void OnMouseWheel(int wheel) override + { + if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) { + DoZoomInOutWindow(wheel < 0 ? ZOOM_IN : ZOOM_OUT, this, false); + } + } + void OnResize() override { if (this->viewport != nullptr) { diff --git a/src/viewport_func.h b/src/viewport_func.h index 5b1537478c..30fec9d287 100644 --- a/src/viewport_func.h +++ b/src/viewport_func.h @@ -30,7 +30,7 @@ void UpdateViewportPosition(Window *w, uint32_t delta_ms); bool MarkAllViewportsDirty(int left, int top, int right, int bottom); -bool DoZoomInOutWindow(ZoomStateChange how, Window *w); +bool DoZoomInOutWindow(ZoomStateChange how, Window *w, bool stop_following = true); void ZoomInOrOutToCursorWindow(bool in, Window * w); void ConstrainAllViewportsZoom(); Point GetTileZoomCenterWindow(bool in, Window * w);