working on mouse stuff...

This commit is contained in:
AJ Kelly
2011-02-14 01:43:41 -06:00
parent 43431086cd
commit 79533fc40f
3 changed files with 61 additions and 15 deletions
@@ -18,7 +18,7 @@ REGISTER_INPUT_HANDLER_CLASS2( DirectInput, DInput );
static vector<DIDevice> Devices; static vector<DIDevice> Devices;
/* Number of joysticks found: */ // Number of joysticks found:
static int g_iNumJoysticks; static int g_iNumJoysticks;
static BOOL CALLBACK EnumDevicesCallback( const DIDEVICEINSTANCE *pdidInstance, void *pContext ) static BOOL CALLBACK EnumDevicesCallback( const DIDEVICEINSTANCE *pdidInstance, void *pContext )
@@ -120,8 +120,8 @@ InputHandler_DInput::InputHandler_DInput()
if( hr != DI_OK ) if( hr != DI_OK )
RageException::Throw( hr_ssprintf(hr, "InputHandler_DInput: IDirectInput::EnumDevices") ); RageException::Throw( hr_ssprintf(hr, "InputHandler_DInput: IDirectInput::EnumDevices") );
// mouse
/* /*
mouse
LOG->Trace( "InputHandler_DInput: IDirectInput::EnumDevices(DIDEVTYPE_MOUSE)" ); LOG->Trace( "InputHandler_DInput: IDirectInput::EnumDevices(DIDEVTYPE_MOUSE)" );
hr = g_dinput->EnumDevices( DIDEVTYPE_MOUSE, EnumDevicesCallback, NULL, DIEDFL_ATTACHEDONLY ); hr = g_dinput->EnumDevices( DIDEVTYPE_MOUSE, EnumDevicesCallback, NULL, DIEDFL_ATTACHEDONLY );
if( hr != DI_OK ) if( hr != DI_OK )
@@ -237,13 +237,13 @@ static int TranslatePOV(DWORD value)
if( LOWORD(value) == 0xFFFF ) if( LOWORD(value) == 0xFFFF )
return 0; return 0;
/* Round the value up: */ // Round the value up:
value += 4500 / 2; value += 4500 / 2;
value %= 36000; value %= 36000;
value /= 4500; value /= 4500;
if( value >= 8 ) if( value >= 8 )
return 0; /* shouldn't happen */ return 0; // shouldn't happen
return HAT_VALS[value]; return HAT_VALS[value];
} }
@@ -303,7 +303,7 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
if( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED ) if( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED )
return; return;
/* Set each known axis, button and POV. */ // Set each known axis, button and POV.
for( unsigned i = 0; i < device.Inputs.size(); ++i ) for( unsigned i = 0; i < device.Inputs.size(); ++i )
{ {
const input_t &in = device.Inputs[i]; const input_t &in = device.Inputs[i];
@@ -382,6 +382,8 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
break; break;
/* /*
case device.MOUSE: case device.MOUSE:
DIMOUSESTATE state;
HRESULT hr = GetDeviceState(device.Device, sizeof(state), &state);
break; break;
*/ */
} }
@@ -524,7 +526,7 @@ void InputHandler_DInput::PollAndAcquireDevices( bool bBuffered )
void InputHandler_DInput::Update() void InputHandler_DInput::Update()
{ {
/* Handle polled devices. Handle buffered, too, if there's no input thread to do it. */ // Handle polled devices. Handle buffered, too, if there's no input thread to do it.
PollAndAcquireDevices( false ); PollAndAcquireDevices( false );
if( !m_InputThread.IsCreated() ) if( !m_InputThread.IsCreated() )
PollAndAcquireDevices( true ); PollAndAcquireDevices( true );
@@ -683,7 +685,6 @@ static wchar_t ScancodeAndKeysToChar( DWORD scancode, unsigned char keys[256] )
pToUnicodeEx = (TOUNICODEEX *) GetProcAddress( hModule, "ToUnicodeEx" ); pToUnicodeEx = (TOUNICODEEX *) GetProcAddress( hModule, "ToUnicodeEx" );
} }
unsigned short result[2]; // ToAscii writes a max of 2 chars unsigned short result[2]; // ToAscii writes a max of 2 chars
ZERO( result ); ZERO( result );
@@ -16,6 +16,7 @@ LPDIRECTINPUT g_dinput = NULL;
static int ConvertScancodeToKey( int scancode ); static int ConvertScancodeToKey( int scancode );
static BOOL CALLBACK DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data); static BOOL CALLBACK DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data);
//static BOOL CALLBACK DIMouse_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data);
DIDevice::DIDevice() DIDevice::DIDevice()
{ {
@@ -34,13 +35,14 @@ bool DIDevice::Open()
buffered = true; buffered = true;
LPDIRECTINPUTDEVICE tmpdevice; LPDIRECTINPUTDEVICE tmpdevice;
// load joystick
HRESULT hr = g_dinput->CreateDevice( JoystickInst.guidInstance, &tmpdevice, NULL ); HRESULT hr = g_dinput->CreateDevice( JoystickInst.guidInstance, &tmpdevice, NULL );
if ( hr != DI_OK ) if ( hr != DI_OK )
{ {
LOG->Info( hr_ssprintf(hr, "OpenDevice: IDirectInput_CreateDevice") ); LOG->Info( hr_ssprintf(hr, "OpenDevice: IDirectInput_CreateDevice") );
return false; return false;
} }
hr = tmpdevice->QueryInterface( IID_IDirectInputDevice2, (LPVOID *) &Device ); hr = tmpdevice->QueryInterface( IID_IDirectInputDevice2, (LPVOID *) &Device );
tmpdevice->Release(); tmpdevice->Release();
if ( hr != DI_OK ) if ( hr != DI_OK )
@@ -49,6 +51,8 @@ bool DIDevice::Open()
return false; return false;
} }
// todo: load mouse
int coop = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND; int coop = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
if( type == KEYBOARD ) if( type == KEYBOARD )
coop = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND; coop = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
@@ -60,7 +64,20 @@ bool DIDevice::Open()
return false; return false;
} }
hr = Device->SetDataFormat( type == JOYSTICK? &c_dfDIJoystick: &c_dfDIKeyboard ); switch(type)
{
case KEYBOARD:
hr = Device->SetDataFormat( &c_dfDIKeyboard );
break;
case JOYSTICK:
hr = Device->SetDataFormat( &c_dfDIJoystick );
break;
/*
case MOUSE:
hr = Device->SetDataFormat( &c_dfDIMouse );
break;
*/
}
if ( hr != DI_OK ) if ( hr != DI_OK )
{ {
LOG->Info( hr_ssprintf(hr, "OpenDevice(%s): IDirectInputDevice2::SetDataFormat", m_sName.c_str()) ); LOG->Info( hr_ssprintf(hr, "OpenDevice(%s): IDirectInputDevice2::SetDataFormat", m_sName.c_str()) );
@@ -73,7 +90,7 @@ bool DIDevice::Open()
Device->EnumObjects( DIJoystick_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV); Device->EnumObjects( DIJoystick_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV);
break; break;
case KEYBOARD: case KEYBOARD:
/* Always 256-button. */ // Always 256-button.
for( int b = 0; b < 256; ++b ) for( int b = 0; b < 256; ++b )
{ {
input_t in; input_t in;
@@ -87,6 +104,7 @@ bool DIDevice::Open()
break; break;
/* /*
case MOUSE: case MOUSE:
Device->EnumObjects( DIMouse_EnumDevObjectsProc, this, DIDFT_BUTTON );
break; break;
*/ */
} }
@@ -308,7 +326,34 @@ static int ConvertScancodeToKey( int scancode )
} }
/* /*
* (c) 2003-2004 Glenn Maynard static BOOL CALLBACK DIMouse_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data)
{
DIDevice *device = (DIDevice *) data;
input_t in;
// todo: check mask for accuracy -aj
const int SupportedMask = DIDFT_BUTTON;
if(!(dev->dwType & SupportedMask))
return DIENUM_CONTINUE; // unsupported
// xxx: does this check for scrollwheels? -aj
if(dev->dwType & DIDFT_BUTTON) {
if( device->buttons == 10 )
return DIENUM_CONTINUE; // too many buttons
in.type = in.BUTTON;
in.num = device->buttons;
device->buttons++;
}
device->Inputs.push_back(in);
return DIENUM_CONTINUE;
}
*/
/*
* (c) 2003-2011 Glenn Maynard, AJ Kelly
* All rights reserved. * All rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
@@ -11,10 +11,10 @@ extern LPDIRECTINPUT g_dinput;
typedef struct input_t typedef struct input_t
{ {
/* DirectInput offset for this input type: */ // DirectInput offset for this input type:
DWORD ofs; DWORD ofs;
/* Button, axis or hat: */ // Button, axis or hat:
enum Type { KEY, BUTTON, AXIS, HAT } type; enum Type { KEY, BUTTON, AXIS, HAT } type;
int num; int num;