Skip to content

Commit

Permalink
Improve mouse navigation in overlay menus
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mbarnes committed Jun 25, 2023
1 parent 659b66c commit c1330c3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/fe_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit c1330c3

Please sign in to comment.