From 69ee8a84808b1c1505e6c672023198584e0c3ab1 Mon Sep 17 00:00:00 2001 From: Eri the Switch Date: Fri, 13 Dec 2024 12:21:30 +0300 Subject: [PATCH] Add: Implement 2D map scrolling under SDL2 (#13167) Use a base multiplier to keep the existing option range (1-15). SDL2 >= 2.18 allows for considerably smoother scrolling, but basic support for earlier versions is included. --- src/video/sdl2_v.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index a546e136b0..8cea6be506 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -404,13 +404,25 @@ bool VideoDriver_SDL_Base::PollEvent() break; } - case SDL_MOUSEWHEEL: + case SDL_MOUSEWHEEL: { if (ev.wheel.y > 0) { _cursor.wheel--; } else if (ev.wheel.y < 0) { _cursor.wheel++; } + + /* Handle 2D scrolling. */ + const float SCROLL_BUILTIN_MULTIPLIER = 14.0f; +#if SDL_VERSION_ATLEAST(2, 18, 0) + _cursor.v_wheel -= ev.wheel.preciseY * SCROLL_BUILTIN_MULTIPLIER * _settings_client.gui.scrollwheel_multiplier; + _cursor.h_wheel += ev.wheel.preciseX * SCROLL_BUILTIN_MULTIPLIER * _settings_client.gui.scrollwheel_multiplier; +#else + _cursor.v_wheel -= static_cast(ev.wheel.y * SCROLL_BUILTIN_MULTIPLIER * _settings_client.gui.scrollwheel_multiplier); + _cursor.h_wheel += static_cast(ev.wheel.x * SCROLL_BUILTIN_MULTIPLIER * _settings_client.gui.scrollwheel_multiplier); +#endif + _cursor.wheel_moved = true; break; + } case SDL_MOUSEBUTTONDOWN: if (_rightclick_emulate && SDL_GetModState() & KMOD_CTRL) {