From 641777ddf7fc06b21f1892b4c67bff4df7257f71 Mon Sep 17 00:00:00 2001 From: AJ Kelly Date: Mon, 14 Feb 2011 17:08:29 -0600 Subject: [PATCH] Found 2 DirectInput devices: 0: 'Keyboard' axes: 0, hats: 0, buttons: 256 (buffered) 1: 'Mouse' axes: 3, hats: 0, buttons: 8 (buffered) So let's get this straight: Left, Right, and Middle clicks work. Wheel Up and Wheel Down work. X/Y axis doesn't seem to work yet. --- src/InputMapper.cpp | 2 - src/RageInput.cpp | 12 +- src/RageInputDevice.cpp | 4 +- src/RageInputDevice.h | 5 + src/ScreenDebugOverlay.cpp | 4 +- .../InputHandler/InputHandler_DirectInput.cpp | 201 +++++++++++------- .../InputHandler_DirectInputHelper.cpp | 39 +++- .../InputHandler_DirectInputHelper.h | 2 - 8 files changed, 168 insertions(+), 101 deletions(-) diff --git a/src/InputMapper.cpp b/src/InputMapper.cpp index bc247c5552..e0eb9c88b7 100644 --- a/src/InputMapper.cpp +++ b/src/InputMapper.cpp @@ -559,9 +559,7 @@ void InputMapper::AutoMapJoysticksForCurrentGame() vector vDevices; INPUTMAN->GetDevicesAndDescriptions(vDevices); - // // fill vector with all auto mappings - // vector vAutoMappings; { // file automaps - Add these first so that they can match before the hard-coded mappings diff --git a/src/RageInput.cpp b/src/RageInput.cpp index ed34519072..99c9d6eba5 100644 --- a/src/RageInput.cpp +++ b/src/RageInput.cpp @@ -38,7 +38,7 @@ RageInput::RageInput() RageInput::~RageInput() { - /* Delete optional devices. */ + // Delete optional devices. for( unsigned i = 0; i < m_InputHandlers.size(); ++i ) delete m_InputHandlers[i].m_pDevice; m_InputHandlers.clear(); @@ -55,28 +55,28 @@ void RageInput::LoadDrivers() m_InputHandlers.clear(); g_mapDeviceToHandler.clear(); - /* Init optional devices. */ + // Init optional devices. vector apDevices; InputHandler::Create( g_sInputDrivers, apDevices ); for( unsigned i = 0; i < apDevices.size(); ++i ) AddHandler( apDevices[i] ); - /* If no input devices are loaded, the user won't be able to input anything. */ + // If no input devices are loaded, the user won't be able to input anything. if( apDevices.size() == 0 ) LOG->Warn( "No input devices were loaded." ); } void RageInput::Update() { - /* Update optional devices. */ + // Update optional devices. for( unsigned i = 0; i < m_InputHandlers.size(); ++i ) m_InputHandlers[i].m_pDevice->Update(); } bool RageInput::DevicesChanged() { - /* Update optional devices. */ + // Update optional devices. for( unsigned i = 0; i < m_InputHandlers.size(); ++i ) { if( m_InputHandlers[i].m_pDevice->DevicesChanged() ) @@ -111,7 +111,7 @@ void RageInput::AddHandler( InputHandler *pHandler ) g_mapDeviceToHandler[idi->id] = pHandler; } -/* Return the first InputDriver for the requested InputDevice. */ +/** @brief Return the first InputDriver for the requested InputDevice. */ InputHandler *RageInput::GetHandlerForDevice( const InputDevice id ) { map::iterator it = g_mapDeviceToHandler.find(id); diff --git a/src/RageInputDevice.cpp b/src/RageInputDevice.cpp index 7109c2c8c3..2bc1ae3979 100644 --- a/src/RageInputDevice.cpp +++ b/src/RageInputDevice.cpp @@ -130,10 +130,10 @@ static void InitNames() g_mapNamesToString[MOUSE_LEFT] = "left mouse button"; g_mapNamesToString[MOUSE_RIGHT] = "right mouse button"; g_mapNamesToString[MOUSE_MIDDLE] = "middle mouse button"; - g_mapNamesToString[MOUSE_FORWARD] = "forward mouse button"; - g_mapNamesToString[MOUSE_BACK] = "back mouse button"; g_mapNamesToString[MOUSE_WHEELUP] = "mousewheel up"; g_mapNamesToString[MOUSE_WHEELDOWN] = "mousewheel down"; + g_mapNamesToString[MOUSE_FORWARD] = "forward mouse button"; + g_mapNamesToString[MOUSE_BACK] = "back mouse button"; FOREACHM( DeviceButton, RString, g_mapNamesToString, m ) g_mapStringToNames[m->second] = m->first; diff --git a/src/RageInputDevice.h b/src/RageInputDevice.h index 3ced992701..09066df405 100644 --- a/src/RageInputDevice.h +++ b/src/RageInputDevice.h @@ -297,6 +297,11 @@ enum DeviceButton MOUSE_WHEELUP, MOUSE_WHEELDOWN, // for mice with forward and backwards buttons MOUSE_FORWARD, MOUSE_BACK, + // axis + MOUSE_X_LEFT, MOUSE_X_RIGHT, + MOUSE_Y_UP, MOUSE_Y_DOWN, + // mousewheel? + MOUSE_Z_UP, MOUSE_Z_DOWN, NUM_DeviceButton, DeviceButton_Invalid diff --git a/src/ScreenDebugOverlay.cpp b/src/ScreenDebugOverlay.cpp index 972ff0747d..f4610870d6 100644 --- a/src/ScreenDebugOverlay.cpp +++ b/src/ScreenDebugOverlay.cpp @@ -163,7 +163,7 @@ static LocalizedString DEBUG_MENU( "ScreenDebugOverlay", "Debug Menu" ); void ScreenDebugOverlay::Init() { Screen::Init(); - + // Init debug mappings // TODO: Arch-specific? { @@ -539,7 +539,6 @@ void ChangeVisualDelay( float fDelta ) pRet->Set( fSecs ); } - // DebugLines static LocalizedString AUTO_PLAY ( "ScreenDebugOverlay", "AutoPlay" ); static LocalizedString ASSIST ( "ScreenDebugOverlay", "Assist" ); @@ -579,7 +578,6 @@ static LocalizedString SONG ( "ScreenDebugOverlay", "Song" ); static LocalizedString MACHINE ( "ScreenDebugOverlay", "Machine" ); static LocalizedString SYNC_TEMPO ( "ScreenDebugOverlay", "Tempo" ); - class DebugLineAutoplay : public IDebugLine { virtual RString GetDisplayTitle() { return AUTO_PLAY.GetValue() + " (+Shift = AI) (+Alt = hide)"; } diff --git a/src/arch/InputHandler/InputHandler_DirectInput.cpp b/src/arch/InputHandler/InputHandler_DirectInput.cpp index eb9173e408..15aa64e2ae 100644 --- a/src/arch/InputHandler/InputHandler_DirectInput.cpp +++ b/src/arch/InputHandler/InputHandler_DirectInput.cpp @@ -307,71 +307,71 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm ) switch(in.type) { - case in.BUTTON: - { - DeviceInput di( dev, enum_add2(JOY_BUTTON_1, in.num), !!state.rgbButtons[in.ofs - DIJOFS_BUTTON0], tm ); - ButtonPressed( di ); - break; - } - - case in.AXIS: - { - DeviceButton neg = DeviceButton_Invalid, pos = DeviceButton_Invalid; - int val = 0; - switch( in.ofs ) + case in.BUTTON: { - case DIJOFS_X: neg = JOY_LEFT; pos = JOY_RIGHT; - val = state.lX; - break; - case DIJOFS_Y: neg = JOY_UP; pos = JOY_DOWN; - val = state.lY; - break; - case DIJOFS_Z: neg = JOY_Z_UP; pos = JOY_Z_DOWN; - val = state.lZ; - break; - case DIJOFS_RX: neg = JOY_ROT_LEFT; pos = JOY_ROT_RIGHT; - val = state.lRx; - break; - case DIJOFS_RY: neg = JOY_ROT_UP; pos = JOY_ROT_DOWN; - val = state.lRy; - break; - case DIJOFS_RZ: neg = JOY_ROT_Z_UP; pos = JOY_ROT_Z_DOWN; - val = state.lRz; - break; - case DIJOFS_SLIDER(0): - neg = JOY_AUX_1; pos = JOY_AUX_2; - val = state.rglSlider[0]; - break; - case DIJOFS_SLIDER(1): - neg = JOY_AUX_3; pos = JOY_AUX_4; - val = state.rglSlider[1]; - break; - default: LOG->MapLog( "unknown input", - "Controller '%s' is returning an unknown joystick offset, %i", - device.m_sName.c_str(), in.ofs ); - continue; - } - if( neg != DeviceButton_Invalid ) - { - float l = SCALE( int(val), 0.0f, 100.0f, 0.0f, 1.0f ); - ButtonPressed( DeviceInput(dev, neg, max(-l,0), tm) ); - ButtonPressed( DeviceInput(dev, pos, max(+l,0), tm) ); + DeviceInput di( dev, enum_add2(JOY_BUTTON_1, in.num), !!state.rgbButtons[in.ofs - DIJOFS_BUTTON0], tm ); + ButtonPressed( di ); + break; } - break; - } - - case in.HAT: - if( in.num == 0 ) + case in.AXIS: { - const int pos = TranslatePOV( state.rgdwPOV[in.ofs - DIJOFS_POV(0)] ); - ButtonPressed( DeviceInput(dev, JOY_HAT_UP, !!(pos & HAT_UP_MASK), tm) ); - ButtonPressed( DeviceInput(dev, JOY_HAT_DOWN, !!(pos & HAT_DOWN_MASK), tm) ); - ButtonPressed( DeviceInput(dev, JOY_HAT_LEFT, !!(pos & HAT_LEFT_MASK), tm) ); - ButtonPressed( DeviceInput(dev, JOY_HAT_RIGHT, !!(pos & HAT_RIGHT_MASK), tm) ); + DeviceButton neg = DeviceButton_Invalid, pos = DeviceButton_Invalid; + int val = 0; + switch( in.ofs ) + { + case DIJOFS_X: neg = JOY_LEFT; pos = JOY_RIGHT; + val = state.lX; + break; + case DIJOFS_Y: neg = JOY_UP; pos = JOY_DOWN; + val = state.lY; + break; + case DIJOFS_Z: neg = JOY_Z_UP; pos = JOY_Z_DOWN; + val = state.lZ; + break; + case DIJOFS_RX: neg = JOY_ROT_LEFT; pos = JOY_ROT_RIGHT; + val = state.lRx; + break; + case DIJOFS_RY: neg = JOY_ROT_UP; pos = JOY_ROT_DOWN; + val = state.lRy; + break; + case DIJOFS_RZ: neg = JOY_ROT_Z_UP; pos = JOY_ROT_Z_DOWN; + val = state.lRz; + break; + case DIJOFS_SLIDER(0): + neg = JOY_AUX_1; pos = JOY_AUX_2; + val = state.rglSlider[0]; + break; + case DIJOFS_SLIDER(1): + neg = JOY_AUX_3; pos = JOY_AUX_4; + val = state.rglSlider[1]; + break; + default: LOG->MapLog( "unknown input", + "Controller '%s' is returning an unknown joystick offset, %i", + device.m_sName.c_str(), in.ofs ); + continue; + } + if( neg != DeviceButton_Invalid ) + { + float l = SCALE( int(val), 0.0f, 100.0f, 0.0f, 1.0f ); + ButtonPressed( DeviceInput(dev, neg, max(-l,0), tm) ); + ButtonPressed( DeviceInput(dev, pos, max(+l,0), tm) ); + } + + break; } - break; + case in.HAT: + if( in.num == 0 ) + { + const int pos = TranslatePOV( state.rgdwPOV[in.ofs - DIJOFS_POV(0)] ); + ButtonPressed( DeviceInput(dev, JOY_HAT_UP, !!(pos & HAT_UP_MASK), tm) ); + ButtonPressed( DeviceInput(dev, JOY_HAT_DOWN, !!(pos & HAT_DOWN_MASK), tm) ); + ButtonPressed( DeviceInput(dev, JOY_HAT_LEFT, !!(pos & HAT_LEFT_MASK), tm) ); + ButtonPressed( DeviceInput(dev, JOY_HAT_RIGHT, !!(pos & HAT_RIGHT_MASK), tm) ); + } + + break; } } } @@ -383,7 +383,6 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm ) 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]; @@ -392,9 +391,40 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm ) 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; + } + case in.AXIS: + { + DeviceButton neg = DeviceButton_Invalid, pos = DeviceButton_Invalid; + int val = 0; + switch( in.ofs ) + { + case DIMOFS_X: neg = MOUSE_X_LEFT; pos = MOUSE_X_RIGHT; + val = state.lX; + break; + case DIMOFS_Y: neg = MOUSE_Y_UP; pos = MOUSE_Y_DOWN; + val = state.lY; + break; + case DIMOFS_Z: neg = MOUSE_Z_UP; pos = MOUSE_Z_DOWN; + val = state.lZ; + break; + default: LOG->MapLog( "unknown input", + "Mouse '%s' is returning an unknown mouse offset, %i", + device.m_sName.c_str(), in.ofs ); + continue; + } + + if( neg != DeviceButton_Invalid ) + { + float l = SCALE( int(val), 0.0f, 100.0f, 0.0f, 1.0f ); + ButtonPressed( DeviceInput(dev, neg, max(-l,0), tm) ); + ButtonPressed( DeviceInput(dev, pos, max(+l,0), tm) ); + } + break; + } } } break; @@ -427,7 +457,6 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm return; } - // todo: update for mouse? -aj for( int i = 0; i < (int) numevents; ++i ) { for(unsigned j = 0; j < device.Inputs.size(); ++j) @@ -445,7 +474,6 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm break; case in.BUTTON: - // hope this works... if(dev == DEVICE_MOUSE) { DeviceButton mouseInput = DeviceButton_Invalid; @@ -455,12 +483,8 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm 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", + "Mouse '%s' is returning an unknown mouse offset [button], %i", device.m_sName.c_str(), in.ofs ); continue; } @@ -473,20 +497,37 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm case in.AXIS: { DeviceButton up = DeviceButton_Invalid, down = DeviceButton_Invalid; - switch(in.ofs) + if(dev == DEVICE_MOUSE) { - case DIJOFS_X: up = JOY_LEFT; down = JOY_RIGHT; break; - case DIJOFS_Y: up = JOY_UP; down = JOY_DOWN; break; - case DIJOFS_Z: up = JOY_Z_UP; down = JOY_Z_DOWN; break; - case DIJOFS_RX: up = JOY_ROT_UP; down = JOY_ROT_DOWN; break; - case DIJOFS_RY: up = JOY_ROT_LEFT; down = JOY_ROT_RIGHT; break; - case DIJOFS_RZ: up = JOY_ROT_Z_UP; down = JOY_ROT_Z_DOWN; break; - case DIJOFS_SLIDER(0): up = JOY_AUX_1; down = JOY_AUX_2; break; - case DIJOFS_SLIDER(1): up = JOY_AUX_3; down = JOY_AUX_4; break; - default: LOG->MapLog( "unknown input", - "Controller '%s' is returning an unknown joystick offset, %i", - device.m_sName.c_str(), in.ofs ); - continue; + switch(in.ofs) + { + case DIMOFS_X: up = MOUSE_X_LEFT; down = MOUSE_X_RIGHT; break; + case DIMOFS_Y: up = MOUSE_Y_UP; down = MOUSE_Y_DOWN; break; + case DIMOFS_Z: up = MOUSE_Z_UP; down = MOUSE_Z_DOWN; break; + default: LOG->MapLog( "unknown input", + "Controller '%s' is returning an unknown mouse offset [axis], %i", + device.m_sName.c_str(), in.ofs ); + continue; + } + } + else + { + switch(in.ofs) + { + // joystick + case DIJOFS_X: up = JOY_LEFT; down = JOY_RIGHT; break; + case DIJOFS_Y: up = JOY_UP; down = JOY_DOWN; break; + case DIJOFS_Z: up = JOY_Z_UP; down = JOY_Z_DOWN; break; + case DIJOFS_RX: up = JOY_ROT_UP; down = JOY_ROT_DOWN; break; + case DIJOFS_RY: up = JOY_ROT_LEFT; down = JOY_ROT_RIGHT; break; + case DIJOFS_RZ: up = JOY_ROT_Z_UP; down = JOY_ROT_Z_DOWN; break; + case DIJOFS_SLIDER(0): up = JOY_AUX_1; down = JOY_AUX_2; break; + case DIJOFS_SLIDER(1): up = JOY_AUX_3; down = JOY_AUX_4; break; + default: LOG->MapLog( "unknown input", + "Controller '%s' is returning an unknown joystick offset, %i", + device.m_sName.c_str(), in.ofs ); + continue; + } } float l = SCALE( int(evtbuf[i].dwData), 0.0f, 100.0f, 0.0f, 1.0f ); diff --git a/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp b/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp index b2a887cd34..5ac087bfeb 100644 --- a/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp +++ b/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp @@ -24,7 +24,6 @@ DIDevice::DIDevice() dev = InputDevice_Invalid; buffered = true; memset(&JoystickInst, 0, sizeof(JoystickInst)); - memset(&MouseInst, 0, sizeof(MouseInst)); Device = NULL; } @@ -100,7 +99,7 @@ bool DIDevice::Open() } break; case MOUSE: - Device->EnumObjects( DIMouse_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_PSHBUTTON ); + Device->EnumObjects( DIMouse_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_AXIS ); break; } @@ -191,7 +190,7 @@ static BOOL CALLBACK DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev dilong.dwData = 0; hr = device->Device->SetProperty( DIPROP_DEADZONE, &dilong.diph ); if ( hr != DI_OK ) - return DIENUM_CONTINUE; /* don't use this axis */ + return DIENUM_CONTINUE; // don't use this axis device->axes++; } @@ -323,21 +322,49 @@ static int ConvertScancodeToKey( int scancode ) static BOOL CALLBACK DIMouse_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID data) { DIDevice *device = (DIDevice *) data; + //HRESULT hr; input_t in; - // todo: check mask for accuracy -aj - const int SupportedMask = DIDFT_BUTTON; + const int SupportedMask = DIDFT_BUTTON | DIDFT_AXIS; if(!(dev->dwType & SupportedMask)) return DIENUM_CONTINUE; // unsupported in.ofs = dev->dwOfs; // xxx: does this check for scrollwheels? -aj - if(dev->dwType & DIDFT_BUTTON ) { + if(dev->dwType & DIDFT_BUTTON) + { in.type = in.BUTTON; in.num = device->buttons; device->buttons++; } + else if(dev->dwType & DIDFT_AXIS) + { + LOG->Trace("found a mouse axis"); + // todo: how to handle this correctly? -aj + //DIPROPRANGE diprg; + + in.type = in.AXIS; + in.num = device->axes; + + /* + diprg.diph.dwSize = sizeof(diprg); + diprg.diph.dwHeaderSize = sizeof(diprg.diph); + diprg.diph.dwObj = dev->dwOfs; + diprg.diph.dwHow = DIPH_BYOFFSET; + diprg.lMin = -100; + diprg.lMax = 100; + + hr = device->Device->SetProperty( DIPROP_RANGE, &diprg.diph ); + if ( hr != DI_OK ) + { + LOG->Trace("error setting properties on mouse axis"); + return DIENUM_CONTINUE; // don't use this axis + } + */ + + device->axes++; + } device->Inputs.push_back(in); diff --git a/src/arch/InputHandler/InputHandler_DirectInputHelper.h b/src/arch/InputHandler/InputHandler_DirectInputHelper.h index 8519a2dbf2..60ddc6982f 100644 --- a/src/arch/InputHandler/InputHandler_DirectInputHelper.h +++ b/src/arch/InputHandler/InputHandler_DirectInputHelper.h @@ -23,11 +23,9 @@ typedef struct input_t struct DIDevice { DIDEVICEINSTANCE JoystickInst; - DIDEVICEINSTANCE MouseInst; LPDIRECTINPUTDEVICE2 Device; RString m_sName; - //enum { KEYBOARD, JOYSTICK } type; enum { KEYBOARD, JOYSTICK, MOUSE } type; bool buffered;