slightly more work on mouse input, but still not really working. trying again tomorrow.
This commit is contained in:
@@ -294,10 +294,10 @@ enum DeviceButton
|
|||||||
MOUSE_LEFT = 700,
|
MOUSE_LEFT = 700,
|
||||||
MOUSE_RIGHT,
|
MOUSE_RIGHT,
|
||||||
MOUSE_MIDDLE,
|
MOUSE_MIDDLE,
|
||||||
// for mice with forward and backwards buttons
|
|
||||||
MOUSE_FORWARD, MOUSE_BACK,
|
|
||||||
// wheel mice
|
// wheel mice
|
||||||
MOUSE_WHEELUP, MOUSE_WHEELDOWN,
|
MOUSE_WHEELUP, MOUSE_WHEELDOWN,
|
||||||
|
// for mice with forward and backwards buttons
|
||||||
|
MOUSE_FORWARD, MOUSE_BACK,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
NUM_DeviceButton,
|
NUM_DeviceButton,
|
||||||
@@ -354,6 +354,7 @@ public:
|
|||||||
void MakeInvalid() { device = InputDevice_Invalid; };
|
void MakeInvalid() { device = InputDevice_Invalid; };
|
||||||
|
|
||||||
bool IsJoystick() const { return ::IsJoystick(device); }
|
bool IsJoystick() const { return ::IsJoystick(device); }
|
||||||
|
//bool IsMouse() const { return ::IsMouse(device); }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef vector<DeviceInput> DeviceInputList;
|
typedef vector<DeviceInput> DeviceInputList;
|
||||||
|
|||||||
@@ -37,12 +37,6 @@ static BOOL CALLBACK EnumDevicesCallback( const DIDEVICEINSTANCE *pdidInstance,
|
|||||||
|
|
||||||
switch( device.type )
|
switch( device.type )
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
case device.MOUSE:
|
|
||||||
device.dev = DEVICE_MOUSE;
|
|
||||||
break;
|
|
||||||
*/
|
|
||||||
|
|
||||||
case device.JOYSTICK:
|
case device.JOYSTICK:
|
||||||
if( g_iNumJoysticks == NUM_JOYSTICKS )
|
if( g_iNumJoysticks == NUM_JOYSTICKS )
|
||||||
return DIENUM_CONTINUE;
|
return DIENUM_CONTINUE;
|
||||||
@@ -54,6 +48,12 @@ static BOOL CALLBACK EnumDevicesCallback( const DIDEVICEINSTANCE *pdidInstance,
|
|||||||
case device.KEYBOARD:
|
case device.KEYBOARD:
|
||||||
device.dev = DEVICE_KEYBOARD;
|
device.dev = DEVICE_KEYBOARD;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/*
|
||||||
|
case device.MOUSE:
|
||||||
|
device.dev = DEVICE_MOUSE;
|
||||||
|
break;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
Devices.push_back(device);
|
Devices.push_back(device);
|
||||||
@@ -383,7 +383,26 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm )
|
|||||||
/*
|
/*
|
||||||
case device.MOUSE:
|
case device.MOUSE:
|
||||||
DIMOUSESTATE state;
|
DIMOUSESTATE state;
|
||||||
|
|
||||||
HRESULT hr = GetDeviceState(device.Device, sizeof(state), &state);
|
HRESULT hr = GetDeviceState(device.Device, sizeof(state), &state);
|
||||||
|
if( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// do button checks here
|
||||||
|
for( unsigned i = 0; i < device.Inputs.size(); ++i )
|
||||||
|
{
|
||||||
|
const input_t &in = device.Inputs[i];
|
||||||
|
const InputDevice dev = device.dev;
|
||||||
|
|
||||||
|
switch(in.type)
|
||||||
|
{
|
||||||
|
case in.BUTTON:
|
||||||
|
DeviceInput di( dev, enum_add2(MOUSE_LEFT, in.num), !!state.rgbButtons[in.ofs - DIMOFS_BUTTON0], tm );
|
||||||
|
ButtonPressed( di );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
@@ -415,6 +434,7 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: update for mouse? -aj
|
||||||
for( int i = 0; i < (int) numevents; ++i )
|
for( int i = 0; i < (int) numevents; ++i )
|
||||||
{
|
{
|
||||||
for(unsigned j = 0; j < device.Inputs.size(); ++j)
|
for(unsigned j = 0; j < device.Inputs.size(); ++j)
|
||||||
@@ -428,38 +448,33 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm
|
|||||||
switch( in.type )
|
switch( in.type )
|
||||||
{
|
{
|
||||||
case in.KEY:
|
case in.KEY:
|
||||||
/*
|
ButtonPressed( DeviceInput(dev, (DeviceButton) in.num, !!(evtbuf[i].dwData & 0x80), tm) );
|
||||||
switch( in.num )
|
|
||||||
{
|
|
||||||
// "Joystick with Keyboard" hack
|
|
||||||
case 115: //s
|
|
||||||
ButtonPressed( DeviceInput(DEVICE_JOY1, JOY_UP, !!(evtbuf[i].dwData & 0x80), tm) );
|
|
||||||
break;
|
|
||||||
case 120: //x
|
|
||||||
ButtonPressed( DeviceInput(DEVICE_JOY1, JOY_DOWN, !!(evtbuf[i].dwData & 0x80), tm) );
|
|
||||||
break;
|
|
||||||
case 122: //z
|
|
||||||
ButtonPressed( DeviceInput(DEVICE_JOY1, JOY_LEFT, !!(evtbuf[i].dwData & 0x80), tm) );
|
|
||||||
break;
|
|
||||||
case 99: //c
|
|
||||||
ButtonPressed( DeviceInput(DEVICE_JOY1, JOY_RIGHT, !!(evtbuf[i].dwData & 0x80), tm) );
|
|
||||||
break;
|
|
||||||
case 100: //d
|
|
||||||
ButtonPressed( DeviceInput(DEVICE_JOY1, JOY_BUTTON_1, !!(evtbuf[i].dwData & 0x80), tm) );
|
|
||||||
break;
|
|
||||||
case 101: //e
|
|
||||||
ButtonPressed( DeviceInput(DEVICE_JOY1, JOY_BUTTON_2, !!(evtbuf[i].dwData & 0x80), tm) );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
*/
|
|
||||||
ButtonPressed( DeviceInput(dev, (DeviceButton) in.num, !!(evtbuf[i].dwData & 0x80), tm) );
|
|
||||||
/*
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case in.BUTTON:
|
case in.BUTTON:
|
||||||
|
/*
|
||||||
|
if(dev == DEVICE_MOUSE)
|
||||||
|
{
|
||||||
|
DeviceButton mouseInput = DeviceButton_Invalid;
|
||||||
|
switch(in.ofs)
|
||||||
|
{
|
||||||
|
case DIMOFS_BUTTON0: mouseInput = MOUSE_LEFT; break;
|
||||||
|
case DIMOFS_BUTTON1: mouseInput = MOUSE_RIGHT; break;
|
||||||
|
case DIMOFS_BUTTON2: mouseInput = MOUSE_MIDDLE; break;
|
||||||
|
case DIMOFS_BUTTON3: break;
|
||||||
|
// todo: handle directions
|
||||||
|
case DIMOFS_X: break;
|
||||||
|
case DIMOFS_Y: break;
|
||||||
|
case DIMOFS_Z: break;
|
||||||
|
default: LOG->MapLog( "unknown input",
|
||||||
|
"Mouse '%s' is returning an unknown mouse offset, %i",
|
||||||
|
device.m_sName.c_str(), in.ofs );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ButtonPressed( DeviceInput(dev, mouseInput, !!evtbuf[i].dwData, tm) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*/
|
||||||
ButtonPressed( DeviceInput(dev, enum_add2(JOY_BUTTON_1, in.num), !!evtbuf[i].dwData, tm) );
|
ButtonPressed( DeviceInput(dev, enum_add2(JOY_BUTTON_1, in.num), !!evtbuf[i].dwData, tm) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +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);
|
static BOOL CALLBACK DIMouse_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data);
|
||||||
|
|
||||||
DIDevice::DIDevice()
|
DIDevice::DIDevice()
|
||||||
{
|
{
|
||||||
@@ -24,6 +24,7 @@ DIDevice::DIDevice()
|
|||||||
dev = InputDevice_Invalid;
|
dev = InputDevice_Invalid;
|
||||||
buffered = true;
|
buffered = true;
|
||||||
memset(&JoystickInst, 0, sizeof(JoystickInst));
|
memset(&JoystickInst, 0, sizeof(JoystickInst));
|
||||||
|
//memset(&MouseInst, 0, sizeof(MouseInst));
|
||||||
Device = NULL;
|
Device = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,8 +52,27 @@ bool DIDevice::Open()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: load mouse
|
// load mouse
|
||||||
|
/*
|
||||||
|
hr = g_dinput->CreateDevice( MouseInst.guidInstance, &tmpdevice, NULL );
|
||||||
|
if ( hr != DI_OK )
|
||||||
|
{
|
||||||
|
LOG->Info( hr_ssprintf(hr, "OpenDevice: IDirectInput_CreateDevice") );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
// is this ok? -aj
|
||||||
|
//hr = tmpdevice->QueryInterface( IID_IDirectInputDevice2, (LPVOID *) &Device );
|
||||||
|
/*
|
||||||
|
tmpdevice->Release();
|
||||||
|
if ( hr != DI_OK )
|
||||||
|
{
|
||||||
|
LOG->Info( hr_ssprintf(hr, "OpenDevice(%s): IDirectInputDevice::QueryInterface", m_sName.c_str()) );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// should mouse be foreground? -aj
|
||||||
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;
|
||||||
@@ -86,27 +106,27 @@ bool DIDevice::Open()
|
|||||||
|
|
||||||
switch( type )
|
switch( type )
|
||||||
{
|
{
|
||||||
case JOYSTICK:
|
case JOYSTICK:
|
||||||
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;
|
||||||
in.type = in.KEY;
|
in.type = in.KEY;
|
||||||
|
|
||||||
in.num = ConvertScancodeToKey(b);
|
in.num = ConvertScancodeToKey(b);
|
||||||
in.ofs = b;
|
in.ofs = b;
|
||||||
buttons++;
|
buttons++;
|
||||||
Inputs.push_back(in);
|
Inputs.push_back(in);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
/*
|
/*
|
||||||
case MOUSE:
|
case MOUSE:
|
||||||
Device->EnumObjects( DIMouse_EnumDevObjectsProc, this, DIDFT_BUTTON );
|
Device->EnumObjects( DIMouse_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_PSHBUTTON );
|
||||||
break;
|
break;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -325,32 +345,29 @@ static int ConvertScancodeToKey( int scancode )
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
static BOOL CALLBACK DIMouse_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data)
|
static BOOL CALLBACK DIMouse_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
DIDevice *device = (DIDevice *) data;
|
DIDevice *device = (DIDevice *) data;
|
||||||
|
|
||||||
input_t in;
|
input_t in;
|
||||||
// todo: check mask for accuracy -aj
|
// todo: check mask for accuracy -aj
|
||||||
const int SupportedMask = DIDFT_BUTTON;
|
const int SupportedMask = DIDFT_BUTTON | DIDFT_PSHBUTTON;
|
||||||
if(!(dev->dwType & SupportedMask))
|
if(!(dev->dwType & SupportedMask))
|
||||||
return DIENUM_CONTINUE; // unsupported
|
return DIENUM_CONTINUE; // unsupported
|
||||||
|
|
||||||
// xxx: does this check for scrollwheels? -aj
|
// xxx: does this check for scrollwheels? -aj
|
||||||
if(dev->dwType & DIDFT_BUTTON) {
|
if(dev->dwType & (DIDFT_BUTTON | DIDFT_PSHBUTTON) ) {
|
||||||
if( device->buttons == 10 )
|
|
||||||
return DIENUM_CONTINUE; // too many buttons
|
|
||||||
|
|
||||||
in.type = in.BUTTON;
|
in.type = in.BUTTON;
|
||||||
in.num = device->buttons;
|
in.num = device->buttons;
|
||||||
device->buttons++;
|
device->buttons++;
|
||||||
}
|
}
|
||||||
|
|
||||||
device->Inputs.push_back(in);
|
device->Inputs.push_back(in);
|
||||||
|
*/
|
||||||
|
|
||||||
return DIENUM_CONTINUE;
|
return DIENUM_CONTINUE;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (c) 2003-2011 Glenn Maynard, AJ Kelly
|
* (c) 2003-2011 Glenn Maynard, AJ Kelly
|
||||||
|
|||||||
@@ -23,11 +23,12 @@ typedef struct input_t
|
|||||||
struct DIDevice
|
struct DIDevice
|
||||||
{
|
{
|
||||||
DIDEVICEINSTANCE JoystickInst;
|
DIDEVICEINSTANCE JoystickInst;
|
||||||
|
DIDEVICEINSTANCE MouseInst;
|
||||||
LPDIRECTINPUTDEVICE2 Device;
|
LPDIRECTINPUTDEVICE2 Device;
|
||||||
RString m_sName;
|
RString m_sName;
|
||||||
|
|
||||||
enum { KEYBOARD, JOYSTICK } type;
|
//enum { KEYBOARD, JOYSTICK } type;
|
||||||
//enum { KEYBOARD, JOYSTICK, MOUSE } type;
|
enum { KEYBOARD, JOYSTICK, MOUSE } type;
|
||||||
|
|
||||||
bool buffered;
|
bool buffered;
|
||||||
int buttons, axes, hats;
|
int buttons, axes, hats;
|
||||||
|
|||||||
Reference in New Issue
Block a user