Add support for more than 4 joystick buttons under MSW

Use polling thread instead of relying on MM_JOYXXX events to allow
receiving events from all the supported buttons.

See https://github.com/wxWidgets/wxWidgets/pull/942

Closes #1142.
This commit is contained in:
Vadim Zeitlin
2018-09-25 01:01:20 +02:00
parent 7872b9fd38
commit a02ed536e6
4 changed files with 152 additions and 113 deletions

View File

@@ -3133,19 +3133,6 @@ wxWindowMSW::MSWHandleMessage(WXLRESULT *result,
}
break;
case MM_JOY1MOVE:
case MM_JOY2MOVE:
case MM_JOY1ZMOVE:
case MM_JOY2ZMOVE:
case MM_JOY1BUTTONDOWN:
case MM_JOY2BUTTONDOWN:
case MM_JOY1BUTTONUP:
case MM_JOY2BUTTONUP:
processed = HandleJoystickEvent(message,
LOWORD(lParam),
HIWORD(lParam),
wParam);
break;
case WM_COMMAND:
{
@@ -6162,92 +6149,6 @@ bool wxWindowMSW::HandleClipboardEvent(WXUINT nMsg)
return HandleWindowEvent(evt);
}
// ---------------------------------------------------------------------------
// joystick
// ---------------------------------------------------------------------------
bool wxWindowMSW::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags)
{
int change = 0;
if ( flags & JOY_BUTTON1CHG )
change = wxJOY_BUTTON1;
if ( flags & JOY_BUTTON2CHG )
change = wxJOY_BUTTON2;
if ( flags & JOY_BUTTON3CHG )
change = wxJOY_BUTTON3;
if ( flags & JOY_BUTTON4CHG )
change = wxJOY_BUTTON4;
int buttons = 0;
if ( flags & JOY_BUTTON1 )
buttons |= wxJOY_BUTTON1;
if ( flags & JOY_BUTTON2 )
buttons |= wxJOY_BUTTON2;
if ( flags & JOY_BUTTON3 )
buttons |= wxJOY_BUTTON3;
if ( flags & JOY_BUTTON4 )
buttons |= wxJOY_BUTTON4;
// the event ids aren't consecutive so we can't use table based lookup
int joystick;
wxEventType eventType;
switch ( msg )
{
case MM_JOY1MOVE:
joystick = 1;
eventType = wxEVT_JOY_MOVE;
break;
case MM_JOY2MOVE:
joystick = 2;
eventType = wxEVT_JOY_MOVE;
break;
case MM_JOY1ZMOVE:
joystick = 1;
eventType = wxEVT_JOY_ZMOVE;
break;
case MM_JOY2ZMOVE:
joystick = 2;
eventType = wxEVT_JOY_ZMOVE;
break;
case MM_JOY1BUTTONDOWN:
joystick = 1;
eventType = wxEVT_JOY_BUTTON_DOWN;
break;
case MM_JOY2BUTTONDOWN:
joystick = 2;
eventType = wxEVT_JOY_BUTTON_DOWN;
break;
case MM_JOY1BUTTONUP:
joystick = 1;
eventType = wxEVT_JOY_BUTTON_UP;
break;
case MM_JOY2BUTTONUP:
joystick = 2;
eventType = wxEVT_JOY_BUTTON_UP;
break;
default:
wxFAIL_MSG(wxT("no such joystick event"));
return false;
}
wxJoystickEvent event(eventType, buttons, joystick, change);
if ( eventType == wxEVT_JOY_ZMOVE )
event.SetZPosition(x);
else
event.SetPosition(wxPoint(x, y));
event.SetEventObject(this);
return HandleWindowEvent(event);
}
// ---------------------------------------------------------------------------
// scrolling