diff --git a/src/gfx_type.h b/src/gfx_type.h index 44dc47cf98..78f5e15e56 100644 --- a/src/gfx_type.h +++ b/src/gfx_type.h @@ -127,10 +127,10 @@ struct CursorVars { int wheel; ///< mouse wheel movement bool fix_at; ///< mouse is moving, but cursor is not (used for scrolling) - /* We need two different vars to keep track of how far the scrollwheel moved. - * OSX uses this for scrolling around the map. */ - int v_wheel; - int h_wheel; + /* 2D wheel scrolling for moving around the map */ + bool wheel_moved; + float v_wheel; + float h_wheel; /* Mouse appearance */ std::vector sprites; ///< Sprites comprising cursor. diff --git a/src/video/cocoa/cocoa_wnd.mm b/src/video/cocoa/cocoa_wnd.mm index 2d010f8d42..81b547aec4 100644 --- a/src/video/cocoa/cocoa_wnd.mm +++ b/src/video/cocoa/cocoa_wnd.mm @@ -763,8 +763,9 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel deltaY = [ event deltaY ] * 5; } - _cursor.h_wheel -= (int)(deltaX * _settings_client.gui.scrollwheel_multiplier); - _cursor.v_wheel -= (int)(deltaY * _settings_client.gui.scrollwheel_multiplier); + _cursor.h_wheel -= static_cast(deltaX * _settings_client.gui.scrollwheel_multiplier); + _cursor.v_wheel -= static_cast(deltaY * _settings_client.gui.scrollwheel_multiplier); + _cursor.wheel_moved = true; } - (void)magnifyWithEvent:(NSEvent *)event diff --git a/src/window.cpp b/src/window.cpp index 6c04c83727..c97a27e257 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -2355,7 +2355,7 @@ static EventState HandleActiveWidget() */ static EventState HandleViewportScroll() { - bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == SWS_SCROLL_MAP && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0); + bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == SWS_SCROLL_MAP && _cursor.wheel_moved; if (!_scrolling_viewport) return ES_NOT_HANDLED; @@ -2381,10 +2381,13 @@ static EventState HandleViewportScroll() Point delta; if (scrollwheel_scrolling) { /* We are using scrollwheels for scrolling */ - delta.x = _cursor.h_wheel; - delta.y = _cursor.v_wheel; - _cursor.v_wheel = 0; - _cursor.h_wheel = 0; + /* Use the integer part for movement */ + delta.x = static_cast(_cursor.h_wheel); + delta.y = static_cast(_cursor.v_wheel); + /* Keep the fractional part so that subtle movement is accumulated */ + float temp; + _cursor.v_wheel = std::modf(_cursor.v_wheel, &temp); + _cursor.h_wheel = std::modf(_cursor.h_wheel, &temp); } else { if (_settings_client.gui.scroll_mode != VSM_VIEWPORT_RMB_FIXED) { delta.x = -_cursor.delta.x; @@ -2400,6 +2403,7 @@ static EventState HandleViewportScroll() _cursor.delta.x = 0; _cursor.delta.y = 0; + _cursor.wheel_moved = false; return ES_HANDLED; } @@ -2791,7 +2795,7 @@ static void MouseLoop(MouseClick click, int mousewheel) HandleMouseOver(); - bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == SWS_SCROLL_MAP && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0); + bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == SWS_SCROLL_MAP && _cursor.wheel_moved; if (click == MC_NONE && mousewheel == 0 && !scrollwheel_scrolling) return; int x = _cursor.pos.x; @@ -2870,8 +2874,9 @@ static void MouseLoop(MouseClick click, int mousewheel) } /* We're not doing anything with 2D scrolling, so reset the value. */ - _cursor.h_wheel = 0; - _cursor.v_wheel = 0; + _cursor.h_wheel = 0.0f; + _cursor.v_wheel = 0.0f; + _cursor.wheel_moved = false; } /**