Desktop/GLFW - Windows Xbox 360 DPad integration
Monkey Forums/Monkey Code/Desktop/GLFW - Windows Xbox 360 DPad integration
| ||
| NO LONGER REQUIRED - FUNCTIONALITY HAS BEEN IMPLEMENTED INTO v77c This code will allow you to enable Xbox 360 DPad integration for the Desktop [GLFW] target for the Windows platform. Works in v77b or better. Replace the following functions in the glfw/src/win32_joystick.c file:
int _glfwPlatformGetJoystickParam( int joy, int param )
{
JOYCAPS jc;
int numbuttons;
// return 0;
// Is joystick present?
if( !_glfwJoystickPresent( joy ) )
{
return 0;
}
// We got this far, the joystick is present
if( param == GLFW_PRESENT )
{
return GL_TRUE;
}
// Get joystick capabilities
_glfw_joyGetDevCaps( joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS) );
switch( param )
{
case GLFW_AXES:
// Return number of joystick axes
return jc.wNumAxes;
case GLFW_BUTTONS:
// Return number of joystick axes
// CHANGE - Validate for DPad
numbuttons = (int) jc.wNumButtons;
if (jc.wCaps & JOYCAPS_HASPOV) numbuttons += 2;
return numbuttons;
default:
break;
}
return 0;
}
int _glfwPlatformGetJoystickButtons( int joy, unsigned char *buttons,
int numbuttons )
{
JOYCAPS jc;
JOYINFOEX ji;
int button;
// return 0;
// Is joystick present?
if( !_glfwJoystickPresent( joy ) )
{
return 0;
}
// Get joystick capabilities
_glfw_joyGetDevCaps( joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS) );
// Get joystick state
ji.dwSize = sizeof( JOYINFOEX );
ji.dwFlags = JOY_RETURNBUTTONS;
_glfw_joyGetPosEx( joy - GLFW_JOYSTICK_1, &ji );
// Get states of all requested buttons
button = 0;
while( button < numbuttons && button < (int) jc.wNumButtons )
{
buttons[ button ] = (unsigned char)
(ji.dwButtons & (1UL << button) ? GLFW_PRESS : GLFW_RELEASE);
button ++;
}
// CHANGE - Get state of DPad
if (jc.wCaps & JOYCAPS_HASPOV)
{
int m, value = ji.dwPOV / 100 / 45;
const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 };
const int mapButton[4] = { 9, 10, 11, 8 };
if (value < 0 || value > 8) value = 8;
// Map to required button index
for (m = 0; m < 4 && button < numbuttons; m++)
{
buttons[mapButton[m]] = directions[value] & (1 << m) ? GLFW_PRESS : GLFW_RELEASE;
}
}
return button;
}
The main changes involve extending the number of found buttons by 2 if the DPad is found (glfwPlatformGetJoystickParam) so we can map the results correctly (glfwPlatformGetJoystickButtons). |