From 79533fc40fda510221d97d6feae93bbfdac7f692 Mon Sep 17 00:00:00 2001 From: AJ Kelly Date: Mon, 14 Feb 2011 01:43:41 -0600 Subject: [PATCH] working on mouse stuff... --- .../InputHandler/InputHandler_DirectInput.cpp | 17 +++--- .../InputHandler_DirectInputHelper.cpp | 55 +++++++++++++++++-- .../InputHandler_DirectInputHelper.h | 4 +- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/src/arch/InputHandler/InputHandler_DirectInput.cpp b/src/arch/InputHandler/InputHandler_DirectInput.cpp index ea30f2617e..f941745b81 100644 --- a/src/arch/InputHandler/InputHandler_DirectInput.cpp +++ b/src/arch/InputHandler/InputHandler_DirectInput.cpp @@ -18,7 +18,7 @@ REGISTER_INPUT_HANDLER_CLASS2( DirectInput, DInput ); static vector Devices; -/* Number of joysticks found: */ +// Number of joysticks found: static int g_iNumJoysticks; static BOOL CALLBACK EnumDevicesCallback( const DIDEVICEINSTANCE *pdidInstance, void *pContext ) @@ -120,8 +120,8 @@ InputHandler_DInput::InputHandler_DInput() if( hr != DI_OK ) RageException::Throw( hr_ssprintf(hr, "InputHandler_DInput: IDirectInput::EnumDevices") ); + // mouse /* - mouse LOG->Trace( "InputHandler_DInput: IDirectInput::EnumDevices(DIDEVTYPE_MOUSE)" ); hr = g_dinput->EnumDevices( DIDEVTYPE_MOUSE, EnumDevicesCallback, NULL, DIEDFL_ATTACHEDONLY ); if( hr != DI_OK ) @@ -237,14 +237,14 @@ static int TranslatePOV(DWORD value) if( LOWORD(value) == 0xFFFF ) return 0; - /* Round the value up: */ + // Round the value up: value += 4500 / 2; value %= 36000; value /= 4500; if( value >= 8 ) - return 0; /* shouldn't happen */ - + return 0; // shouldn't happen + return HAT_VALS[value]; } @@ -303,7 +303,7 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm ) if( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED ) return; - /* Set each known axis, button and POV. */ + // Set each known axis, button and POV. for( unsigned i = 0; i < device.Inputs.size(); ++i ) { const input_t &in = device.Inputs[i]; @@ -382,6 +382,8 @@ void InputHandler_DInput::UpdatePolled( DIDevice &device, const RageTimer &tm ) break; /* case device.MOUSE: + DIMOUSESTATE state; + HRESULT hr = GetDeviceState(device.Device, sizeof(state), &state); break; */ } @@ -524,7 +526,7 @@ void InputHandler_DInput::PollAndAcquireDevices( bool bBuffered ) 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 ); if( !m_InputThread.IsCreated() ) PollAndAcquireDevices( true ); @@ -683,7 +685,6 @@ static wchar_t ScancodeAndKeysToChar( DWORD scancode, unsigned char keys[256] ) pToUnicodeEx = (TOUNICODEEX *) GetProcAddress( hModule, "ToUnicodeEx" ); } - unsigned short result[2]; // ToAscii writes a max of 2 chars ZERO( result ); diff --git a/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp b/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp index b11733a6fc..d07cb4ed8c 100644 --- a/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp +++ b/src/arch/InputHandler/InputHandler_DirectInputHelper.cpp @@ -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 diff --git a/src/arch/InputHandler/InputHandler_DirectInputHelper.h b/src/arch/InputHandler/InputHandler_DirectInputHelper.h index f14b3e82b6..ba88f0f5e6 100644 --- a/src/arch/InputHandler/InputHandler_DirectInputHelper.h +++ b/src/arch/InputHandler/InputHandler_DirectInputHelper.h @@ -11,10 +11,10 @@ extern LPDIRECTINPUT g_dinput; typedef struct input_t { - /* DirectInput offset for this input type: */ + // DirectInput offset for this input type: DWORD ofs; - /* Button, axis or hat: */ + // Button, axis or hat: enum Type { KEY, BUTTON, AXIS, HAT } type; int num;