+++ /dev/null
-#include "stdafx.h"\r
-/*\r
-* Copyright (c) 2007-2010 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-#include "Controller.h"\r
-\r
-#include "../DirectInput/Guids.h"\r
-\r
-#include "XInputException.h"\r
-\r
-#include "ResultCodeXI.h"\r
-\r
-using namespace System;\r
-\r
-namespace SlimDX\r
-{\r
-namespace XInput\r
-{\r
- Controller::Controller( UserIndex userIndex )\r
- {\r
- m_UserIndex = static_cast<System::UInt32>( userIndex );\r
- }\r
- \r
- bool Controller::IsConnected::get()\r
- {\r
- XINPUT_STATE state;\r
- UInt32 result = XInputGetState( m_UserIndex, &state );\r
-\r
- if( result == ERROR_DEVICE_NOT_CONNECTED )\r
- return false;\r
- return true;\r
- }\r
- \r
- Guid Controller::SoundRenderGuid::get()\r
- {\r
- GUID renderGuid;\r
- GUID captureGuid;\r
- RECORD_XINPUT( XInputGetDSoundAudioDeviceGuids( m_UserIndex, &renderGuid, &captureGuid ) );\r
- \r
- return Utilities::ConvertNativeGuid( renderGuid );\r
- }\r
-\r
- Guid Controller::SoundCaptureGuid::get()\r
- {\r
- GUID renderGuid;\r
- GUID captureGuid;\r
- RECORD_XINPUT( XInputGetDSoundAudioDeviceGuids( m_UserIndex, &renderGuid, &captureGuid ) );\r
-\r
- return Utilities::ConvertNativeGuid( captureGuid );\r
- }\r
- \r
- BatteryInformation Controller::GetBatteryInformation( BatteryDeviceType battery )\r
- {\r
- XINPUT_BATTERY_INFORMATION information;\r
- if( RECORD_XINPUT( ConvertError( XInputGetBatteryInformation( m_UserIndex, static_cast<BYTE>( battery ), &information) ) ).IsFailure )\r
- return BatteryInformation();\r
- \r
- return BatteryInformation( information );\r
- }\r
- \r
- Capabilities Controller::GetCapabilities( DeviceQueryType device )\r
- {\r
- XINPUT_CAPABILITIES capabilities;\r
- if( RECORD_XINPUT( ConvertError( XInputGetCapabilities( m_UserIndex, static_cast<DWORD>( device ), &capabilities) ) ).IsFailure )\r
- return Capabilities();\r
- \r
- return Capabilities( capabilities );\r
- }\r
- \r
- State Controller::GetState()\r
- {\r
- XINPUT_STATE state;\r
- if( RECORD_XINPUT( ConvertError( XInputGetState( m_UserIndex, &state ) ) ).IsFailure )\r
- return State();\r
- \r
- return State( state ); \r
- }\r
- \r
- Result Controller::GetKeystroke( DeviceQueryType device, Keystroke% result )\r
- {\r
- XINPUT_KEYSTROKE keystroke;\r
- if( RECORD_XINPUT( ConvertError( XInputGetKeystroke( m_UserIndex, static_cast<DWORD>( device ), &keystroke ) ) ).IsSuccess )\r
- result = Keystroke( keystroke );\r
- \r
- return Result::Last;\r
- }\r
- \r
- Result Controller::SetVibration( Vibration vibration )\r
- {\r
- XINPUT_VIBRATION nativeVibration = vibration.CreateNativeVersion();\r
- return RECORD_XINPUT( ConvertError( XInputSetState( m_UserIndex, &nativeVibration ) ) );\r
- }\r
- \r
- void Controller::SetReporting( bool value )\r
- {\r
- XInputEnable( value );\r
- }\r
-\r
- int Controller::ConvertError( int errorCode )\r
- {\r
- return HRESULT_FROM_WIN32( errorCode );\r
- }\r
-}\r
-}\r