From ed2fd91fc9dbc5518fdf79218ea2d44f4693d0b4 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Thu, 22 Jun 2023 11:13:12 -0400 Subject: [PATCH] Improve mouse navigation in overlay menus Two changes to FeOverlay::event_loop(): - In the event of a mouse move, reset the mouse position to the middle of the window if it strays outside the mouse capture area. - Do not wrap around the selected menu item if the first or last menu item was reached by a mouse move event. This makes overlay menus easier to navigate using a trackball or rotary spinner that presents as a mouse device. --- src/fe_overlay.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/fe_overlay.cpp b/src/fe_overlay.cpp index 2509d56e..ba374ec2 100644 --- a/src/fe_overlay.cpp +++ b/src/fe_overlay.cpp @@ -1390,6 +1390,15 @@ bool FeOverlay::event_loop( FeEventLoopCtx &ctx ) && ( c == ctx.extra_exit )) c = FeInputMap::Exit; + if ( ev.type == sf::Event::MouseMoved ) + { + if ( m_feSettings.test_mouse_reset( ev.mouseMove.x, ev.mouseMove.y ) ) + { + sf::Vector2u s = m_wnd.get_win().getSize(); + sf::Mouse::setPosition( sf::Vector2i( s.x / 2, s.y / 2 ), m_wnd.get_win() ); + } + } + switch( c ) { case FeInputMap::Back: @@ -1407,7 +1416,7 @@ bool FeOverlay::event_loop( FeEventLoopCtx &ctx ) if ( ctx.sel > 0 ) ctx.sel--; - else + else if ( ev.type != sf::Event::MouseMoved ) ctx.sel=ctx.max_sel; ctx.move_event = ev; @@ -1423,7 +1432,7 @@ bool FeOverlay::event_loop( FeEventLoopCtx &ctx ) if ( ctx.sel < ctx.max_sel ) ctx.sel++; - else + else if ( ev.type != sf::Event::MouseMoved ) ctx.sel = 0; ctx.move_event = ev;