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
@@ -16,6 +16,7 @@ LPDIRECTINPUT g_dinput = NULL;
static int ConvertScancodeToKey( int scancode );
static BOOL CALLBACK DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data);
//static BOOL CALLBACK DIMouse_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data);
DIDevice::DIDevice()
{
@@ -34,13 +35,14 @@ bool DIDevice::Open()
buffered = true;
LPDIRECTINPUTDEVICE tmpdevice;
// load joystick
HRESULT hr = g_dinput->CreateDevice( JoystickInst.guidInstance, &tmpdevice, NULL );
if ( hr != DI_OK )
{
LOG->Info( hr_ssprintf(hr, "OpenDevice: IDirectInput_CreateDevice") );
return false;
}
hr = tmpdevice->QueryInterface( IID_IDirectInputDevice2, (LPVOID *) &Device );
tmpdevice->Release();
if ( hr != DI_OK )
@@ -49,6 +51,8 @@ bool DIDevice::Open()
return false;
}
// todo: load mouse
int coop = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
if( type == KEYBOARD )
coop = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
@@ -60,7 +64,20 @@ bool DIDevice::Open()
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 )
{
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);
break;
case KEYBOARD:
/* Always 256-button. */
// Always 256-button.
for( int b = 0; b < 256; ++b )
{
input_t in;
@@ -87,6 +104,7 @@ bool DIDevice::Open()
break;
/*
case MOUSE:
Device->EnumObjects( DIMouse_EnumDevObjectsProc, this, DIDFT_BUTTON );
break;
*/
}
@@ -137,7 +155,7 @@ static BOOL CALLBACK DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev
input_t in;
const int SupportedMask = DIDFT_BUTTON | DIDFT_POV | DIDFT_AXIS;
if(!(dev->dwType & SupportedMask))
return DIENUM_CONTINUE; // unsupported
return DIENUM_CONTINUE; // unsupported
in.ofs = dev->dwOfs;
@@ -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.
*
* Permission is hereby granted, free of charge, to any person obtaining a