From ea90460a261fb602af273041f3b226f2b723ebd2 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Wed, 30 Apr 2014 01:00:28 -0400 Subject: joystick: Mask out bits for button axis buttons. When a "button" is actually used as part of a button axis, don't include presses on the button as part of the buttons field posted in joystick events. This avoids situations where button 1 or 2 are part of a D-pad, breaking menu navigation (related to #389). --- src/i_joystick.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src') diff --git a/src/i_joystick.c b/src/i_joystick.c index 8822f288..de10fa08 100644 --- a/src/i_joystick.c +++ b/src/i_joystick.c @@ -159,6 +159,29 @@ void I_InitJoystick(void) I_AtExit(I_ShutdownJoystick, true); } +static int ButtonAxisMask(void) +{ + int result = 0; + + if (IS_BUTTON_AXIS(joystick_x_axis)) + { + result |= 1 << BUTTON_AXIS_NEG(joystick_x_axis); + result |= 1 << BUTTON_AXIS_POS(joystick_x_axis); + } + if (IS_BUTTON_AXIS(joystick_y_axis)) + { + result |= 1 << BUTTON_AXIS_NEG(joystick_y_axis); + result |= 1 << BUTTON_AXIS_POS(joystick_y_axis); + } + if (IS_BUTTON_AXIS(joystick_strafe_axis)) + { + result |= 1 << BUTTON_AXIS_NEG(joystick_strafe_axis); + result |= 1 << BUTTON_AXIS_POS(joystick_strafe_axis); + } + + return result; +} + // Get a bitmask of all currently-pressed buttons static int GetButtonState(void) @@ -176,6 +199,9 @@ static int GetButtonState(void) } } + // Mask out any buttons that are actually used in axes. + result &= ~ButtonAxisMask(); + return result; } -- cgit v1.2.3