2 * Copyright (c) 2007-2010 SlimDX Group
\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
5 * of this software and associated documentation files (the "Software"), to deal
\r
6 * in the Software without restriction, including without limitation the rights
\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
8 * copies of the Software, and to permit persons to whom the Software is
\r
9 * furnished to do so, subject to the following conditions:
\r
11 * The above copyright notice and this permission notice shall be included in
\r
12 * all copies or substantial portions of the Software.
\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
24 #include "DirectInputException.h"
\r
27 #include "DeviceConstantConverter.h"
\r
28 #include "ObjectProperties.h"
\r
31 using namespace System;
\r
32 using namespace System::Runtime::InteropServices;
\r
36 namespace DirectInput
\r
38 ObjectProperties::ObjectProperties( IDirectInputDevice8W* pointer, String^ name, Type^ dataFormat )
\r
40 this->pointer = pointer;
\r
41 how = DIPH_BYOFFSET;
\r
43 obj = Marshal::OffsetOf( dataFormat, name ).ToInt32();
\r
46 ObjectProperties::ObjectProperties( IDirectInputDevice8W* pointer, int value, bool isUsageCode )
\r
48 this->pointer = pointer;
\r
58 int ObjectProperties::LowerRange::get()
\r
62 dip.diph.dwSize = sizeof( DIPROPRANGE );
\r
63 dip.diph.dwHeaderSize = sizeof( DIPROPHEADER );
\r
64 dip.diph.dwObj = obj;
\r
65 dip.diph.dwHow = how;
\r
67 hr = pointer->GetProperty( DIPROP_RANGE, &dip.diph );
\r
68 RECORD_DINPUT( hr );
\r
76 int ObjectProperties::UpperRange::get()
\r
80 dip.diph.dwSize = sizeof( DIPROPRANGE );
\r
81 dip.diph.dwHeaderSize = sizeof( DIPROPHEADER );
\r
82 dip.diph.dwObj = obj;
\r
83 dip.diph.dwHow = how;
\r
85 hr = pointer->GetProperty( DIPROP_RANGE, &dip.diph );
\r
86 RECORD_DINPUT( hr );
\r
94 void ObjectProperties::SetRange( int lowerRange, int upperRange )
\r
98 dip.diph.dwSize = sizeof( DIPROPRANGE );
\r
99 dip.diph.dwHeaderSize = sizeof( DIPROPHEADER );
\r
100 dip.diph.dwObj = obj;
\r
101 dip.diph.dwHow = how;
\r
102 dip.lMin = lowerRange;
\r
103 dip.lMax = upperRange;
\r
105 hr = pointer->SetProperty( DIPROP_RANGE, &dip.diph );
\r
106 RECORD_DINPUT( hr );
\r
109 Object^ ObjectProperties::ApplicationData::get()
\r
113 dip.diph.dwSize = sizeof( DIPROPPOINTER );
\r
114 dip.diph.dwHeaderSize = sizeof( DIPROPHEADER );
\r
115 dip.diph.dwObj = obj;
\r
116 dip.diph.dwHow = how;
\r
118 hr = pointer->GetProperty( DIPROP_APPDATA, &dip.diph );
\r
119 RECORD_DINPUT( hr );
\r
121 if( FAILED( hr ) || dip.uData == NULL )
\r
124 IntPtr pointer( reinterpret_cast<void*>( dip.uData ) );
\r
125 GCHandle handle = GCHandle::FromIntPtr( pointer );
\r
126 if( !handle.IsAllocated )
\r
129 Object^ obj = handle.Target;
\r
134 void ObjectProperties::ApplicationData::set( Object^ value )
\r
138 dip.diph.dwSize = sizeof( DIPROPPOINTER );
\r
139 dip.diph.dwHeaderSize = sizeof( DIPROPHEADER );
\r
140 dip.diph.dwObj = obj;
\r
141 dip.diph.dwHow = how;
\r
143 GCHandle handle = GCHandle::Alloc( value, GCHandleType::Pinned );
\r
144 dip.uData = reinterpret_cast<UINT_PTR>( handle.ToIntPtr( handle ).ToPointer() );
\r
146 hr = pointer->SetProperty( DIPROP_APPDATA, &dip.diph );
\r
147 RECORD_DINPUT( hr );
\r
152 int ObjectProperties::DeadZone::get()
\r
156 dip.diph.dwSize = sizeof( DIPROPDWORD );
\r
157 dip.diph.dwHeaderSize = sizeof( DIPROPHEADER );
\r
158 dip.diph.dwObj = obj;
\r
159 dip.diph.dwHow = how;
\r
161 hr = pointer->GetProperty( DIPROP_DEADZONE, &dip.diph );
\r
162 RECORD_DINPUT( hr );
\r
170 void ObjectProperties::DeadZone::set( int value )
\r
174 dip.diph.dwSize = sizeof( DIPROPDWORD );
\r
175 dip.diph.dwHeaderSize = sizeof( DIPROPHEADER );
\r
176 dip.diph.dwObj = obj;
\r
177 dip.diph.dwHow = how;
\r
178 dip.dwData = value;
\r
180 hr = pointer->SetProperty( DIPROP_DEADZONE, &dip.diph );
\r
181 RECORD_DINPUT( hr );
\r
184 int ObjectProperties::Granularity::get()
\r
188 dip.diph.dwSize = sizeof( DIPROPDWORD );
\r
189 dip.diph.dwHeaderSize = sizeof( DIPROPHEADER );
\r
190 dip.diph.dwObj = obj;
\r
191 dip.diph.dwHow = how;
\r
193 hr = pointer->GetProperty( DIPROP_GRANULARITY, &dip.diph );
\r
194 RECORD_DINPUT( hr );
\r
202 int ObjectProperties::Saturation::get()
\r
206 dip.diph.dwSize = sizeof( DIPROPDWORD );
\r
207 dip.diph.dwHeaderSize = sizeof( DIPROPHEADER );
\r
208 dip.diph.dwObj = obj;
\r
209 dip.diph.dwHow = how;
\r
211 hr = pointer->GetProperty( DIPROP_SATURATION, &dip.diph );
\r
212 RECORD_DINPUT( hr );
\r
220 void ObjectProperties::Saturation::set( int value )
\r
224 dip.diph.dwSize = sizeof( DIPROPDWORD );
\r
225 dip.diph.dwHeaderSize = sizeof( DIPROPHEADER );
\r
226 dip.diph.dwObj = obj;
\r
227 dip.diph.dwHow = how;
\r
228 dip.dwData = value;
\r
230 hr = pointer->SetProperty( DIPROP_SATURATION, &dip.diph );
\r
231 RECORD_DINPUT( hr );
\r
234 InputRange ObjectProperties::LogicalRange::get()
\r
238 dip.diph.dwSize = sizeof( DIPROPRANGE );
\r
239 dip.diph.dwHeaderSize = sizeof( DIPROPHEADER );
\r
240 dip.diph.dwObj = obj;
\r
241 dip.diph.dwHow = how;
\r
243 hr = pointer->GetProperty( DIPROP_LOGICALRANGE, &dip.diph );
\r
244 if (RECORD_DINPUT(hr).IsFailure)
\r
245 return InputRange();
\r
247 return InputRange(dip.lMin, dip.lMax);
\r
250 InputRange ObjectProperties::PhysicalRange::get()
\r
254 dip.diph.dwSize = sizeof( DIPROPRANGE );
\r
255 dip.diph.dwHeaderSize = sizeof( DIPROPHEADER );
\r
256 dip.diph.dwObj = obj;
\r
257 dip.diph.dwHow = how;
\r
259 hr = pointer->GetProperty( DIPROP_PHYSICALRANGE, &dip.diph );
\r
260 if (RECORD_DINPUT(hr).IsFailure)
\r
261 return InputRange();
\r
263 return InputRange(dip.lMin, dip.lMax);
\r