Replace tabs with spaces

This commit is contained in:
2015-09-01 13:15:14 +01:00
parent 45f730d9f3
commit c4948c1ff1
43 changed files with 2735 additions and 2735 deletions

View File

@@ -13,55 +13,55 @@ mhWnd( hWnd ),
mDeviceCounter( 0 ) mDeviceCounter( 0 )
{ {
for ( int i = 0; i < MAX_JXINPUTS; ++i ) for ( int i = 0; i < MAX_JXINPUTS; ++i )
{ {
mDevices[ i ] = NULL; mDevices[ i ] = NULL;
} }
if ( FAILED( InitDirectInput( hWnd ) ) ) if ( FAILED( InitDirectInput( hWnd ) ) )
{ {
FreeDirectInput(); FreeDirectInput();
} }
} }
JXInputManager::~JXInputManager() JXInputManager::~JXInputManager()
{ {
for ( int i = 0; i < getNumberOfJXInputs(); ++i ) for ( int i = 0; i < getNumberOfJXInputs(); ++i )
{ {
delete mDevices[ i ]; delete mDevices[ i ];
mDevices[ i ] = NULL; mDevices[ i ] = NULL;
} }
FreeDirectInput(); FreeDirectInput();
} }
int JXInputManager::getNumberOfJXInputs() const int JXInputManager::getNumberOfJXInputs() const
{ {
return mDeviceCounter; return mDeviceCounter;
} }
JXInput& JXInputManager::getJXInput( int idx ) const JXInput& JXInputManager::getJXInput( int idx ) const
{ {
assert( idx < mDeviceCounter ); assert( idx < mDeviceCounter );
return * mDevices[ idx ]; return * mDevices[ idx ];
} }
int JXInputManager::getMaxNumberOfAxes() const int JXInputManager::getMaxNumberOfAxes() const
{ {
return JXINPUT_MAX_AXES; return JXINPUT_MAX_AXES;
} }
int JXInputManager::getMaxNumberOfButtons() const int JXInputManager::getMaxNumberOfButtons() const
{ {
return JXINPUT_MAX_BUTTONS; return JXINPUT_MAX_BUTTONS;
} }
int JXInputManager::getMaxNumberOfDirectionals() const int JXInputManager::getMaxNumberOfDirectionals() const
{ {
return JXINPUT_MAX_DIRECTIONALS; return JXINPUT_MAX_DIRECTIONALS;
} }
@@ -87,7 +87,7 @@ HRESULT JXInputManager::InitDirectInput( HWND hWnd )
(VOID*)this, DIEDFL_ALLDEVICES /*| DIEDFL_INCLUDEPHANTOMS*/ ) ) ) (VOID*)this, DIEDFL_ALLDEVICES /*| DIEDFL_INCLUDEPHANTOMS*/ ) ) )
return hr; return hr;
// Look for a other devices // Look for a other devices
if( FAILED( hr = mpDI->EnumDevices( DI8DEVCLASS_DEVICE, if( FAILED( hr = mpDI->EnumDevices( DI8DEVCLASS_DEVICE,
EnumJoysticksCallback, EnumJoysticksCallback,
(VOID*)this, DIEDFL_ALLDEVICES /*| DIEDFL_INCLUDEPHANTOMS*/ ) ) ) (VOID*)this, DIEDFL_ALLDEVICES /*| DIEDFL_INCLUDEPHANTOMS*/ ) ) )
@@ -104,9 +104,9 @@ HRESULT JXInputManager::InitDirectInput( HWND hWnd )
HRESULT JXInputManager::FreeDirectInput() HRESULT JXInputManager::FreeDirectInput()
{ {
if ( NULL != mpDI ) if ( NULL != mpDI )
mpDI->Release(); mpDI->Release();
mpDI = NULL; mpDI = NULL;
return S_OK; return S_OK;
} }
@@ -120,43 +120,43 @@ BOOL CALLBACK JXInputManager::EnumJoysticksCallback( const DIDEVICEINSTANCE* pdi
VOID* pContext ) VOID* pContext )
{ {
HRESULT hr; HRESULT hr;
LPDIRECTINPUTDEVICE8 pJoystick; LPDIRECTINPUTDEVICE8 pJoystick;
JXInputManager* pThis = (JXInputManager*)pContext; JXInputManager* pThis = (JXInputManager*)pContext;
// //
// if the maximum number of devices is already registered, // if the maximum number of devices is already registered,
// issue a warning and stop enumeration. // issue a warning and stop enumeration.
// //
if( MAX_JXINPUTS == pThis->mDeviceCounter ) if( MAX_JXINPUTS == pThis->mDeviceCounter )
{ {
OutputDebugString( "Max. number of devices exceeded!" ); OutputDebugString( "Max. number of devices exceeded!" );
return DIENUM_STOP; return DIENUM_STOP;
} }
// Obtain an interface to the enumerated joystick. // Obtain an interface to the enumerated joystick.
hr = pThis->mpDI->CreateDevice( pdidInstance->guidInstance, &pJoystick, NULL ); hr = pThis->mpDI->CreateDevice( pdidInstance->guidInstance, &pJoystick, NULL );
// If it failed, then we can't use this joystick. (Maybe the user unplugged // If it failed, then we can't use this joystick. (Maybe the user unplugged
// it while we were in the middle of enumerating it.) // it while we were in the middle of enumerating it.)
if( FAILED(hr) ) if( FAILED(hr) )
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
JXInput* pJ = new JXInput( pJoystick, pThis->mhWnd ); JXInput* pJ = new JXInput( pJoystick, pThis->mhWnd );
// //
// only register useful devices // only register useful devices
// //
if( pJ->getNumberOfAxes() + pJ->getNumberOfButtons() + pJ->getNumberOfDirectionals() > 0 ) if( pJ->getNumberOfAxes() + pJ->getNumberOfButtons() + pJ->getNumberOfDirectionals() > 0 )
{ {
pThis->addJXInput( pJ ); pThis->addJXInput( pJ );
} }
else else
{ {
delete pJ; delete pJ;
} }
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
} }
@@ -167,8 +167,8 @@ BOOL CALLBACK JXInputManager::EnumJoysticksCallback( const DIDEVICEINSTANCE* pdi
*/ */
void JXInputManager::addJXInput( JXInput* pJ ) void JXInputManager::addJXInput( JXInput* pJ )
{ {
assert( mDeviceCounter < MAX_JXINPUTS ); assert( mDeviceCounter < MAX_JXINPUTS );
if( mDeviceCounter < MAX_JXINPUTS ) if( mDeviceCounter < MAX_JXINPUTS )
mDevices[ mDeviceCounter++ ] = pJ; mDevices[ mDeviceCounter++ ] = pJ;
} }

View File

@@ -8,47 +8,47 @@
// //
extern HINSTANCE g_hInst; extern HINSTANCE g_hInst;
static JXInputManager* pJXInputManager = NULL; static JXInputManager* pJXInputManager = NULL;
static JXInput* apJXInput[ MAX_JXINPUTS ]; static JXInput* apJXInput[ MAX_JXINPUTS ];
static HWND hWndJava; static HWND hWndJava;
// //
// IDs of the static Java arrays. // IDs of the static Java arrays.
// //
static jfieldID sAxesFieldID; static jfieldID sAxesFieldID;
static jfieldID sButtonsFieldID; static jfieldID sButtonsFieldID;
static jfieldID sDirectionsFieldID; static jfieldID sDirectionsFieldID;
/** /**
* Remove all resources allocated by the Java binding. * Remove all resources allocated by the Java binding.
*/ */
void shutdownJavaResources() void shutdownJavaResources()
{ {
if ( NULL != pJXInputManager ) if ( NULL != pJXInputManager )
delete pJXInputManager; delete pJXInputManager;
if ( NULL != hWndJava ) if ( NULL != hWndJava )
DestroyWindow( hWndJava ); DestroyWindow( hWndJava );
pJXInputManager = NULL; pJXInputManager = NULL;
for( int i = 0; i < MAX_JXINPUTS; ++i ) for( int i = 0; i < MAX_JXINPUTS; ++i )
apJXInput[ i ] = NULL; apJXInput[ i ] = NULL;
hWndJava = NULL; hWndJava = NULL;
} }
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
{ {
return JNI_VERSION_1_2; return JNI_VERSION_1_2;
} }
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
{ {
shutdownJavaResources(); shutdownJavaResources();
} }
@@ -56,39 +56,39 @@ JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDrive
(JNIEnv * penv, jclass pClazz ) (JNIEnv * penv, jclass pClazz )
{ {
// //
// Create a non-visible window as 'owner' of the DI device. // Create a non-visible window as 'owner' of the DI device.
// //
hWndJava = CreateWindowEx( hWndJava = CreateWindowEx(
0/*WS_EX_APPWINDOW*/, // DWORD dwExStyle, // extended window style 0/*WS_EX_APPWINDOW*/, // DWORD dwExStyle, // extended window style
"STATIC", // LPCTSTR lpClassName, // pointer to registered class name "STATIC", // LPCTSTR lpClassName, // pointer to registered class name
NULL, // LPCTSTR lpWindowName, // pointer to window name NULL, // LPCTSTR lpWindowName, // pointer to window name
0/*WS_CAPTION*/, // DWORD dwStyle, // window style 0/*WS_CAPTION*/, // DWORD dwStyle, // window style
0, // int x, // horizontal position of window 0, // int x, // horizontal position of window
0, // int y, // vertical position of window 0, // int y, // vertical position of window
0, // int nWidth, // window width 0, // int nWidth, // window width
0, // int nHeight, // window height 0, // int nHeight, // window height
NULL, // HWND hWndParent, // handle to parent or owner window NULL, // HWND hWndParent, // handle to parent or owner window
NULL, // HMENU hMenu, // handle to menu, or child-window identifier NULL, // HMENU hMenu, // handle to menu, or child-window identifier
g_hInst, // HINSTANCE hInstance, // handle to application instance g_hInst, // HINSTANCE hInstance, // handle to application instance
NULL // LPVOID lpParam // pointer to window-creation data NULL // LPVOID lpParam // pointer to window-creation data
); );
if ( NULL == pJXInputManager ) if ( NULL == pJXInputManager )
{ {
pJXInputManager = new JXInputManager( hWndJava ); pJXInputManager = new JXInputManager( hWndJava );
for( int i = 0; i < MAX_JXINPUTS; ++i ) for( int i = 0; i < MAX_JXINPUTS; ++i )
apJXInput[ i ] = NULL; apJXInput[ i ] = NULL;
for ( int i = 0; i < pJXInputManager->getNumberOfJXInputs(); ++i ) for ( int i = 0; i < pJXInputManager->getNumberOfJXInputs(); ++i )
{ {
apJXInput[ i ] = & pJXInputManager->getJXInput( i ); apJXInput[ i ] = & pJXInputManager->getJXInput( i );
} }
} }
return true; return true;
} }
@@ -96,7 +96,7 @@ JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDrive
JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_nativeexit JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_nativeexit
(JNIEnv *, jclass ) (JNIEnv *, jclass )
{ {
shutdownJavaResources(); shutdownJavaResources();
} }
@@ -106,111 +106,111 @@ JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_na
JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_bind JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_bind
(JNIEnv * penv, jclass pClazz) (JNIEnv * penv, jclass pClazz)
{ {
// //
// All fields are static. // All fields are static.
// //
sAxesFieldID = penv->GetStaticFieldID( pClazz, "sAxisValues", "[[D" ); sAxesFieldID = penv->GetStaticFieldID( pClazz, "sAxisValues", "[[D" );
sButtonsFieldID = penv->GetStaticFieldID( pClazz, "sButtonStates", "[[Z" ); sButtonsFieldID = penv->GetStaticFieldID( pClazz, "sButtonStates", "[[Z" );
sDirectionsFieldID = penv->GetStaticFieldID( pClazz, "sDirectionalValues", "[[I" ); sDirectionsFieldID = penv->GetStaticFieldID( pClazz, "sDirectionalValues", "[[I" );
} }
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfDevices JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfDevices
(JNIEnv *penv, jclass) (JNIEnv *penv, jclass)
{ {
return pJXInputManager->getNumberOfJXInputs(); return pJXInputManager->getNumberOfJXInputs();
} }
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getName JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getName
(JNIEnv *penv, jclass, jint dev) (JNIEnv *penv, jclass, jint dev)
{ {
return penv->NewStringUTF( apJXInput[ dev ]->getName() ); return penv->NewStringUTF( apJXInput[ dev ]->getName() );
} }
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfAxes JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfAxes
(JNIEnv *, jclass, jint dev) (JNIEnv *, jclass, jint dev)
{ {
return apJXInput[ dev ]->getNumberOfAxes(); return apJXInput[ dev ]->getNumberOfAxes();
} }
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfButtons JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfButtons
(JNIEnv *, jclass, jint dev) (JNIEnv *, jclass, jint dev)
{ {
return apJXInput[ dev ]->getNumberOfButtons(); return apJXInput[ dev ]->getNumberOfButtons();
} }
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfDirectionals JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfDirectionals
(JNIEnv *, jclass, jint dev) (JNIEnv *, jclass, jint dev)
{ {
return apJXInput[ dev ]->getNumberOfDirectionals(); return apJXInput[ dev ]->getNumberOfDirectionals();
} }
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfAxes JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfAxes
(JNIEnv *, jclass) (JNIEnv *, jclass)
{ {
return pJXInputManager->getMaxNumberOfAxes(); return pJXInputManager->getMaxNumberOfAxes();
} }
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfButtons JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfButtons
(JNIEnv *, jclass) (JNIEnv *, jclass)
{ {
return pJXInputManager->getMaxNumberOfButtons(); return pJXInputManager->getMaxNumberOfButtons();
} }
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfDirectionals JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfDirectionals
(JNIEnv *, jclass) (JNIEnv *, jclass)
{ {
return pJXInputManager->getMaxNumberOfDirectionals(); return pJXInputManager->getMaxNumberOfDirectionals();
} }
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isAxisAvailable JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isAxisAvailable
(JNIEnv *, jclass, jint dev, jint idx ) (JNIEnv *, jclass, jint dev, jint idx )
{ {
return apJXInput[ dev ]->isAxisAvailable( idx ); return apJXInput[ dev ]->isAxisAvailable( idx );
} }
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getAxisName JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getAxisName
(JNIEnv *penv, jclass, jint dev, jint idx ) (JNIEnv *penv, jclass, jint dev, jint idx )
{ {
return penv->NewStringUTF( apJXInput[ dev ]->getAxisName( idx ) ); return penv->NewStringUTF( apJXInput[ dev ]->getAxisName( idx ) );
} }
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getAxisType JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getAxisType
(JNIEnv *, jclass, jint dev, jint idx ) (JNIEnv *, jclass, jint dev, jint idx )
{ {
return apJXInput[ dev ]->getAxisType( idx ); return apJXInput[ dev ]->getAxisType( idx );
} }
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isButtonAvailable JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isButtonAvailable
(JNIEnv *, jclass, jint dev, jint idx ) (JNIEnv *, jclass, jint dev, jint idx )
{ {
return apJXInput[ dev ]->isButtonAvailable( idx ); return apJXInput[ dev ]->isButtonAvailable( idx );
} }
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getButtonName JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getButtonName
(JNIEnv *penv, jclass, jint dev, jint idx ) (JNIEnv *penv, jclass, jint dev, jint idx )
{ {
return penv->NewStringUTF( apJXInput[ dev ]->getButtonName( idx ) ); return penv->NewStringUTF( apJXInput[ dev ]->getButtonName( idx ) );
} }
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getButtonType JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getButtonType
(JNIEnv *, jclass, jint dev, jint idx ) (JNIEnv *, jclass, jint dev, jint idx )
{ {
return apJXInput[ dev ]->getButtonType( idx ); return apJXInput[ dev ]->getButtonType( idx );
} }
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isDirectionalAvailable JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isDirectionalAvailable
(JNIEnv *, jclass, jint dev, jint idx ) (JNIEnv *, jclass, jint dev, jint idx )
{ {
return apJXInput[ dev ]->isDirectionalAvailable( idx ); return apJXInput[ dev ]->isDirectionalAvailable( idx );
} }
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getDirectionalName JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getDirectionalName
(JNIEnv *penv, jclass, jint dev, jint idx ) (JNIEnv *penv, jclass, jint dev, jint idx )
{ {
return penv->NewStringUTF( apJXInput[ dev ]->getDirectionalName( idx ) ); return penv->NewStringUTF( apJXInput[ dev ]->getDirectionalName( idx ) );
} }
@@ -223,53 +223,53 @@ JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_na
(JNIEnv * penv, jclass pClazz ) (JNIEnv * penv, jclass pClazz )
{ {
static jdouble axes [ MAX_JXINPUTS ][ JXINPUT_MAX_AXES ]; static jdouble axes [ MAX_JXINPUTS ][ JXINPUT_MAX_AXES ];
static jboolean buttons [ MAX_JXINPUTS ][ JXINPUT_MAX_BUTTONS ]; static jboolean buttons [ MAX_JXINPUTS ][ JXINPUT_MAX_BUTTONS ];
static jint directions [ MAX_JXINPUTS ][ JXINPUT_MAX_DIRECTIONALS ]; static jint directions [ MAX_JXINPUTS ][ JXINPUT_MAX_DIRECTIONALS ];
static jobjectArray axisarrayarray; static jobjectArray axisarrayarray;
static jobjectArray buttonarrayarray; static jobjectArray buttonarrayarray;
static jobjectArray directionarrayarray; static jobjectArray directionarrayarray;
static jdoubleArray axisarray; static jdoubleArray axisarray;
static jbooleanArray buttonarray; static jbooleanArray buttonarray;
static jintArray directionarray; static jintArray directionarray;
axisarrayarray = (jobjectArray)penv->GetStaticObjectField( pClazz, sAxesFieldID ); axisarrayarray = (jobjectArray)penv->GetStaticObjectField( pClazz, sAxesFieldID );
buttonarrayarray = (jobjectArray)penv->GetStaticObjectField( pClazz, sButtonsFieldID ); buttonarrayarray = (jobjectArray)penv->GetStaticObjectField( pClazz, sButtonsFieldID );
directionarrayarray = (jobjectArray)penv->GetStaticObjectField( pClazz, sDirectionsFieldID ); directionarrayarray = (jobjectArray)penv->GetStaticObjectField( pClazz, sDirectionsFieldID );
// //
// For each device.... // For each device....
// //
for ( int dev = 0; dev < pJXInputManager->getNumberOfJXInputs(); ++dev ) for ( int dev = 0; dev < pJXInputManager->getNumberOfJXInputs(); ++dev )
{ {
// Do the update of the device. // Do the update of the device.
apJXInput[ dev ]->update(); apJXInput[ dev ]->update();
// //
// Copy all values into my arrays. // Copy all values into my arrays.
// //
for ( int i = 0; i < JXINPUT_MAX_AXES; ++i ) for ( int i = 0; i < JXINPUT_MAX_AXES; ++i )
axes[ dev ][ i ] = apJXInput[ dev ]->getAxisValue( i ); axes[ dev ][ i ] = apJXInput[ dev ]->getAxisValue( i );
for ( int i = 0; i < JXINPUT_MAX_BUTTONS; ++i ) for ( int i = 0; i < JXINPUT_MAX_BUTTONS; ++i )
buttons[ dev ][ i ] = apJXInput[ dev ]->isButtonDown( i ); buttons[ dev ][ i ] = apJXInput[ dev ]->isButtonDown( i );
for ( int i = 0; i < JXINPUT_MAX_DIRECTIONALS; ++i ) for ( int i = 0; i < JXINPUT_MAX_DIRECTIONALS; ++i )
directions[ dev ][ i ] = apJXInput[ dev ]->getDirection( i ); directions[ dev ][ i ] = apJXInput[ dev ]->getDirection( i );
// //
// Move my arrays to the Java arrays. // Move my arrays to the Java arrays.
// //
axisarray = (jdoubleArray)penv->GetObjectArrayElement( axisarrayarray, dev ); axisarray = (jdoubleArray)penv->GetObjectArrayElement( axisarrayarray, dev );
penv->SetDoubleArrayRegion( axisarray, 0, JXINPUT_MAX_AXES, axes[ dev ] ); penv->SetDoubleArrayRegion( axisarray, 0, JXINPUT_MAX_AXES, axes[ dev ] );
buttonarray = (jbooleanArray)penv->GetObjectArrayElement( buttonarrayarray, dev ); buttonarray = (jbooleanArray)penv->GetObjectArrayElement( buttonarrayarray, dev );
penv->SetBooleanArrayRegion( buttonarray, 0, JXINPUT_MAX_BUTTONS, buttons[ dev ] ); penv->SetBooleanArrayRegion( buttonarray, 0, JXINPUT_MAX_BUTTONS, buttons[ dev ] );
directionarray = (jintArray)penv->GetObjectArrayElement( directionarrayarray, dev ); directionarray = (jintArray)penv->GetObjectArrayElement( directionarrayarray, dev );
penv->SetIntArrayRegion( directionarray, 0, JXINPUT_MAX_DIRECTIONALS, directions[ dev ] ); penv->SetIntArrayRegion( directionarray, 0, JXINPUT_MAX_DIRECTIONALS, directions[ dev ] );
} }
} }

View File

@@ -11,19 +11,19 @@ extern HINSTANCE g_hInst;
* Ctor: Connect with DI * Ctor: Connect with DI
*/ */
JXInput::JXInput( LPDIRECTINPUTDEVICE8 pJoystick, HWND hWnd ) : JXInput::JXInput( LPDIRECTINPUTDEVICE8 pJoystick, HWND hWnd ) :
mpJoystick( pJoystick ), mpJoystick( pJoystick ),
mSliderCount( 0 ), mSliderCount( 0 ),
mPOVCount( 0 ), mPOVCount( 0 ),
mButtonCount( 0 ) mButtonCount( 0 )
{ {
initAxisConfig(); initAxisConfig();
initButtonsConfig(); initButtonsConfig();
initDirectionalsConfig(); initDirectionalsConfig();
if ( FAILED( InitDirectInput( hWnd ) ) ) if ( FAILED( InitDirectInput( hWnd ) ) )
{ {
FreeDirectInput(); FreeDirectInput();
} }
} }
@@ -34,113 +34,113 @@ JXInput::JXInput( LPDIRECTINPUTDEVICE8 pJoystick, HWND hWnd ) :
*/ */
JXInput::~JXInput() JXInput::~JXInput()
{ {
FreeDirectInput(); FreeDirectInput();
} }
void JXInput::update() void JXInput::update()
{ {
UpdateInputState(); UpdateInputState();
} }
TCHAR * const JXInput::getName() const TCHAR * const JXInput::getName() const
{ {
return (TCHAR*)mdiDevInfo.tszInstanceName; return (TCHAR*)mdiDevInfo.tszInstanceName;
} }
int JXInput::getNumberOfAxes() const int JXInput::getNumberOfAxes() const
{ {
return mdiDevCaps.dwAxes; return mdiDevCaps.dwAxes;
} }
int JXInput::getNumberOfButtons() const int JXInput::getNumberOfButtons() const
{ {
return mButtonCount; return mButtonCount;
} }
int JXInput::getNumberOfDirectionals() const int JXInput::getNumberOfDirectionals() const
{ {
return mPOVCount; return mPOVCount;
} }
double JXInput::getAxisValueHelper( LONG val, int idx ) const double JXInput::getAxisValueHelper( LONG val, int idx ) const
{ {
const AxisConfig& cfg = mAxisConfig[ idx ]; const AxisConfig& cfg = mAxisConfig[ idx ];
double span = (double)( cfg.mMaxValue - cfg.mMinValue ); double span = (double)( cfg.mMaxValue - cfg.mMinValue );
double ret = (double)(val - cfg.mMinValue) / span; double ret = (double)(val - cfg.mMinValue) / span;
if ( TYPE_SLIDER != cfg.mType ) if ( TYPE_SLIDER != cfg.mType )
return ret*2.0 - 1.0; return ret*2.0 - 1.0;
return ret; return ret;
} }
double JXInput::getX() const double JXInput::getX() const
{ {
return getAxisValueHelper( mJS.lX, ID_X ); return getAxisValueHelper( mJS.lX, ID_X );
} }
double JXInput::getY() const double JXInput::getY() const
{ {
return getAxisValueHelper( mJS.lY, ID_Y ); return getAxisValueHelper( mJS.lY, ID_Y );
} }
double JXInput::getZ() const double JXInput::getZ() const
{ {
return getAxisValueHelper( mJS.lZ, ID_Z ); return getAxisValueHelper( mJS.lZ, ID_Z );
} }
double JXInput::getRotX() const double JXInput::getRotX() const
{ {
return getAxisValueHelper( mJS.lRx, ID_ROTX ); return getAxisValueHelper( mJS.lRx, ID_ROTX );
} }
double JXInput::getRotY() const double JXInput::getRotY() const
{ {
return getAxisValueHelper( mJS.lRy, ID_ROTY ); return getAxisValueHelper( mJS.lRy, ID_ROTY );
} }
double JXInput::getRotZ() const double JXInput::getRotZ() const
{ {
return getAxisValueHelper( mJS.lRz, ID_ROTZ ); return getAxisValueHelper( mJS.lRz, ID_ROTZ );
} }
double JXInput::getSlider0() const double JXInput::getSlider0() const
{ {
return getAxisValueHelper( mJS.rglSlider[ 0 ], ID_SLIDER0 ); return getAxisValueHelper( mJS.rglSlider[ 0 ], ID_SLIDER0 );
} }
double JXInput::getSlider1() const double JXInput::getSlider1() const
{ {
return getAxisValueHelper( mJS.rglSlider[ 1 ], ID_SLIDER1 ); return getAxisValueHelper( mJS.rglSlider[ 1 ], ID_SLIDER1 );
} }
bool JXInput::isAxisAvailable( int idx ) const bool JXInput::isAxisAvailable( int idx ) const
{ {
assert( idx < JXINPUT_MAX_AXES ); assert( idx < JXINPUT_MAX_AXES );
return mAxisConfig[ idx ].mIsAvailable; return mAxisConfig[ idx ].mIsAvailable;
} }
TCHAR * const JXInput::getAxisName( int idx ) const TCHAR * const JXInput::getAxisName( int idx ) const
{ {
assert( idx < JXINPUT_MAX_AXES ); assert( idx < JXINPUT_MAX_AXES );
return (char*const)mAxisConfig[ idx ].mName; return (char*const)mAxisConfig[ idx ].mName;
} }
int JXInput::getAxisType( int idx ) const int JXInput::getAxisType( int idx ) const
{ {
assert( idx < JXINPUT_MAX_AXES ); assert( idx < JXINPUT_MAX_AXES );
return mAxisConfig[ idx ].mType; return mAxisConfig[ idx ].mType;
} }
double JXInput::getAxisValue( int idx ) const double JXInput::getAxisValue( int idx ) const
{ {
assert( idx < JXINPUT_MAX_AXES ); assert( idx < JXINPUT_MAX_AXES );
// Failsafe if called accidentally // Failsafe if called accidentally
if ( ! mAxisConfig[ idx ].mIsAvailable ) if ( ! mAxisConfig[ idx ].mIsAvailable )
return 0.0; return 0.0;
return (this->*mAxisConfig[ idx ].mGetValueMethod)(); return (this->*mAxisConfig[ idx ].mGetValueMethod)();
} }
@@ -149,45 +149,45 @@ double JXInput::getAxisValue( int idx ) const
bool JXInput::isButtonAvailable( int idx ) const bool JXInput::isButtonAvailable( int idx ) const
{ {
assert( idx < JXINPUT_MAX_BUTTONS ); assert( idx < JXINPUT_MAX_BUTTONS );
return mButtonConfig[ idx ].mIsAvailable; return mButtonConfig[ idx ].mIsAvailable;
} }
TCHAR * const JXInput::getButtonName( int idx ) const TCHAR * const JXInput::getButtonName( int idx ) const
{ {
assert( idx < JXINPUT_MAX_BUTTONS ); assert( idx < JXINPUT_MAX_BUTTONS );
return (char*const)mButtonConfig[ idx ].mName; return (char*const)mButtonConfig[ idx ].mName;
} }
int JXInput::getButtonType( int idx ) const int JXInput::getButtonType( int idx ) const
{ {
assert( idx < JXINPUT_MAX_BUTTONS ); assert( idx < JXINPUT_MAX_BUTTONS );
return mButtonConfig[ idx ].mType; return mButtonConfig[ idx ].mType;
} }
bool JXInput::isButtonDown( int idx ) const bool JXInput::isButtonDown( int idx ) const
{ {
assert( idx < JXINPUT_MAX_BUTTONS ); assert( idx < JXINPUT_MAX_BUTTONS );
return 0 != mJS.rgbButtons[ idx ] ; return 0 != mJS.rgbButtons[ idx ] ;
} }
bool JXInput::isDirectionalAvailable( int idx ) const bool JXInput::isDirectionalAvailable( int idx ) const
{ {
assert( idx < JXINPUT_MAX_DIRECTIONALS ); assert( idx < JXINPUT_MAX_DIRECTIONALS );
return mDirectionalConfig[ idx ].mIsAvailable; return mDirectionalConfig[ idx ].mIsAvailable;
} }
TCHAR * const JXInput::getDirectionalName( int idx ) const TCHAR * const JXInput::getDirectionalName( int idx ) const
{ {
assert( idx < JXINPUT_MAX_DIRECTIONALS ); assert( idx < JXINPUT_MAX_DIRECTIONALS );
return (char*const)mDirectionalConfig[ idx ].mName; return (char*const)mDirectionalConfig[ idx ].mName;
} }
int JXInput::getDirection( int idx ) const int JXInput::getDirection( int idx ) const
{ {
assert( idx < JXINPUT_MAX_DIRECTIONALS ); assert( idx < JXINPUT_MAX_DIRECTIONALS );
return mJS.rgdwPOV[ idx ] ; return mJS.rgdwPOV[ idx ] ;
} }
@@ -196,37 +196,37 @@ int JXInput::getDirection( int idx ) const
*/ */
void JXInput::initAxisConfig() void JXInput::initAxisConfig()
{ {
mAxisConfig[ ID_X ].mIsAvailable = false; mAxisConfig[ ID_X ].mIsAvailable = false;
mAxisConfig[ ID_X ].mType = TYPE_TRANSLATION; mAxisConfig[ ID_X ].mType = TYPE_TRANSLATION;
mAxisConfig[ ID_X ].mGetValueMethod = &JXInput::getX; mAxisConfig[ ID_X ].mGetValueMethod = &JXInput::getX;
mAxisConfig[ ID_Y ].mIsAvailable = false; mAxisConfig[ ID_Y ].mIsAvailable = false;
mAxisConfig[ ID_Y ].mType = TYPE_TRANSLATION; mAxisConfig[ ID_Y ].mType = TYPE_TRANSLATION;
mAxisConfig[ ID_Y ].mGetValueMethod = &JXInput::getY; mAxisConfig[ ID_Y ].mGetValueMethod = &JXInput::getY;
mAxisConfig[ ID_Z ].mIsAvailable = false; mAxisConfig[ ID_Z ].mIsAvailable = false;
mAxisConfig[ ID_Z ].mType = TYPE_TRANSLATION; mAxisConfig[ ID_Z ].mType = TYPE_TRANSLATION;
mAxisConfig[ ID_Z ].mGetValueMethod = &JXInput::getZ; mAxisConfig[ ID_Z ].mGetValueMethod = &JXInput::getZ;
mAxisConfig[ ID_ROTX ].mIsAvailable = false; mAxisConfig[ ID_ROTX ].mIsAvailable = false;
mAxisConfig[ ID_ROTX ].mType = TYPE_ROTATION; mAxisConfig[ ID_ROTX ].mType = TYPE_ROTATION;
mAxisConfig[ ID_ROTX ].mGetValueMethod = &JXInput::getRotX; mAxisConfig[ ID_ROTX ].mGetValueMethod = &JXInput::getRotX;
mAxisConfig[ ID_ROTY ].mIsAvailable = false; mAxisConfig[ ID_ROTY ].mIsAvailable = false;
mAxisConfig[ ID_ROTY ].mType = TYPE_ROTATION; mAxisConfig[ ID_ROTY ].mType = TYPE_ROTATION;
mAxisConfig[ ID_ROTY ].mGetValueMethod = &JXInput::getRotY; mAxisConfig[ ID_ROTY ].mGetValueMethod = &JXInput::getRotY;
mAxisConfig[ ID_ROTZ ].mIsAvailable = false; mAxisConfig[ ID_ROTZ ].mIsAvailable = false;
mAxisConfig[ ID_ROTZ ].mType = TYPE_ROTATION; mAxisConfig[ ID_ROTZ ].mType = TYPE_ROTATION;
mAxisConfig[ ID_ROTZ ].mGetValueMethod = &JXInput::getRotZ; mAxisConfig[ ID_ROTZ ].mGetValueMethod = &JXInput::getRotZ;
mAxisConfig[ ID_SLIDER0 ].mIsAvailable = false; mAxisConfig[ ID_SLIDER0 ].mIsAvailable = false;
mAxisConfig[ ID_SLIDER0 ].mType = TYPE_SLIDER; mAxisConfig[ ID_SLIDER0 ].mType = TYPE_SLIDER;
mAxisConfig[ ID_SLIDER0 ].mGetValueMethod = &JXInput::getSlider0; mAxisConfig[ ID_SLIDER0 ].mGetValueMethod = &JXInput::getSlider0;
mAxisConfig[ ID_SLIDER1 ].mIsAvailable = false; mAxisConfig[ ID_SLIDER1 ].mIsAvailable = false;
mAxisConfig[ ID_SLIDER1 ].mType = TYPE_SLIDER; mAxisConfig[ ID_SLIDER1 ].mType = TYPE_SLIDER;
mAxisConfig[ ID_SLIDER1 ].mGetValueMethod = &JXInput::getSlider1; mAxisConfig[ ID_SLIDER1 ].mGetValueMethod = &JXInput::getSlider1;
} }
@@ -235,12 +235,12 @@ void JXInput::initAxisConfig()
*/ */
void JXInput::initButtonsConfig() void JXInput::initButtonsConfig()
{ {
for ( int i = 0; i < JXINPUT_MAX_BUTTONS; ++i ) for ( int i = 0; i < JXINPUT_MAX_BUTTONS; ++i )
{ {
mButtonConfig[ i ].mIsAvailable = false; mButtonConfig[ i ].mIsAvailable = false;
mButtonConfig[ i ].mName[ 0 ] = '\0'; mButtonConfig[ i ].mName[ 0 ] = '\0';
mButtonConfig[ i ].mType = TYPE_PUSHBUTTON; mButtonConfig[ i ].mType = TYPE_PUSHBUTTON;
} }
} }
@@ -250,11 +250,11 @@ void JXInput::initButtonsConfig()
*/ */
void JXInput::initDirectionalsConfig() void JXInput::initDirectionalsConfig()
{ {
for ( int i = 0; i < JXINPUT_MAX_DIRECTIONALS; ++i ) for ( int i = 0; i < JXINPUT_MAX_DIRECTIONALS; ++i )
{ {
mDirectionalConfig[ i ].mIsAvailable = false; mDirectionalConfig[ i ].mIsAvailable = false;
mDirectionalConfig[ i ].mName[ 0 ] = '\0'; mDirectionalConfig[ i ].mName[ 0 ] = '\0';
} }
} }
@@ -267,46 +267,46 @@ void JXInput::initDirectionalsConfig()
BOOL CALLBACK JXInput::EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, BOOL CALLBACK JXInput::EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
VOID* pContext ) VOID* pContext )
{ {
JXInput* pThis = (JXInput*)pContext; JXInput* pThis = (JXInput*)pContext;
AxisConfig* pAxCfg = NULL; AxisConfig* pAxCfg = NULL;
// Set the UI to reflect what objects the joystick supports // Set the UI to reflect what objects the joystick supports
// Code derived from M$ samples, really sucks, eh? // Code derived from M$ samples, really sucks, eh?
if (pdidoi->guidType == GUID_XAxis) if (pdidoi->guidType == GUID_XAxis)
{ {
pAxCfg = & pThis->mAxisConfig[ ID_X ]; pAxCfg = & pThis->mAxisConfig[ ID_X ];
} }
if (pdidoi->guidType == GUID_YAxis) if (pdidoi->guidType == GUID_YAxis)
{ {
pAxCfg = & pThis->mAxisConfig[ ID_Y ]; pAxCfg = & pThis->mAxisConfig[ ID_Y ];
} }
if (pdidoi->guidType == GUID_ZAxis) if (pdidoi->guidType == GUID_ZAxis)
{ {
pAxCfg = & pThis->mAxisConfig[ ID_Z ]; pAxCfg = & pThis->mAxisConfig[ ID_Z ];
} }
if (pdidoi->guidType == GUID_RxAxis) if (pdidoi->guidType == GUID_RxAxis)
{ {
pAxCfg = & pThis->mAxisConfig[ ID_ROTX ]; pAxCfg = & pThis->mAxisConfig[ ID_ROTX ];
} }
if (pdidoi->guidType == GUID_RyAxis) if (pdidoi->guidType == GUID_RyAxis)
{ {
pAxCfg = & pThis->mAxisConfig[ ID_ROTY ]; pAxCfg = & pThis->mAxisConfig[ ID_ROTY ];
} }
if (pdidoi->guidType == GUID_RzAxis) if (pdidoi->guidType == GUID_RzAxis)
{ {
pAxCfg = & pThis->mAxisConfig[ ID_ROTZ ]; pAxCfg = & pThis->mAxisConfig[ ID_ROTZ ];
} }
if (pdidoi->guidType == GUID_Slider) if (pdidoi->guidType == GUID_Slider)
{ {
switch( pThis->mSliderCount++ ) switch( pThis->mSliderCount++ )
{ {
case 0 : case 0 :
pAxCfg = & pThis->mAxisConfig[ ID_SLIDER0 ]; pAxCfg = & pThis->mAxisConfig[ ID_SLIDER0 ];
break; break;
case 1 : case 1 :
pAxCfg = & pThis->mAxisConfig[ ID_SLIDER1 ]; pAxCfg = & pThis->mAxisConfig[ ID_SLIDER1 ];
break; break;
} }
} }
@@ -316,25 +316,25 @@ BOOL CALLBACK JXInput::EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
// //
// Perform config. // Perform config.
// //
DIPROPRANGE diprg; DIPROPRANGE diprg;
diprg.diph.dwSize = sizeof(DIPROPRANGE); diprg.diph.dwSize = sizeof(DIPROPRANGE);
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER); diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
diprg.diph.dwHow = DIPH_BYID; diprg.diph.dwHow = DIPH_BYID;
diprg.diph.dwObj = pdidoi->dwType; // Specify the enumerated axis diprg.diph.dwObj = pdidoi->dwType; // Specify the enumerated axis
// Get the range for the axis // Get the range for the axis
if( FAILED( pThis->mpJoystick->GetProperty( DIPROP_RANGE, &diprg.diph ) ) ) if( FAILED( pThis->mpJoystick->GetProperty( DIPROP_RANGE, &diprg.diph ) ) )
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
pAxCfg->mMinValue = diprg.lMin; pAxCfg->mMinValue = diprg.lMin;
pAxCfg->mMaxValue = diprg.lMax; pAxCfg->mMaxValue = diprg.lMax;
strcpy( (char*)pAxCfg->mName, (char*)pdidoi->tszName ); strcpy( (char*)pAxCfg->mName, (char*)pdidoi->tszName );
pAxCfg->mIsAvailable = true; pAxCfg->mIsAvailable = true;
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
} }
@@ -348,39 +348,39 @@ BOOL CALLBACK JXInput::EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
BOOL CALLBACK JXInput::EnumButtonsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, BOOL CALLBACK JXInput::EnumButtonsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
VOID* pContext ) VOID* pContext )
{ {
JXInput* pThis = (JXInput*)pContext; JXInput* pThis = (JXInput*)pContext;
// //
// if the maximum number of buttons is already registered, // if the maximum number of buttons is already registered,
// issue a warning and stop enumeration. // issue a warning and stop enumeration.
// //
if( JXINPUT_MAX_BUTTONS == pThis->mButtonCount ) if( JXINPUT_MAX_BUTTONS == pThis->mButtonCount )
{ {
OutputDebugString( "Max. number of buttons exceeded!" ); OutputDebugString( "Max. number of buttons exceeded!" );
return DIENUM_STOP; return DIENUM_STOP;
} }
ButtonConfig* pBtCfg = NULL; ButtonConfig* pBtCfg = NULL;
if ( pdidoi->guidType == GUID_Button ) if ( pdidoi->guidType == GUID_Button )
{ {
assert( JXINPUT_MAX_BUTTONS > pThis->mButtonCount ); assert( JXINPUT_MAX_BUTTONS > pThis->mButtonCount );
pBtCfg = & pThis->mButtonConfig[ pThis->mButtonCount++ ]; pBtCfg = & pThis->mButtonConfig[ pThis->mButtonCount++ ];
} }
// fail-safe // fail-safe
if( NULL == pBtCfg ) // e.g. unknown stuff if( NULL == pBtCfg ) // e.g. unknown stuff
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
assert( NULL != pBtCfg ); assert( NULL != pBtCfg );
// //
// Perform config. // Perform config.
// //
strcpy( (char*)pBtCfg->mName, (char*)pdidoi->tszName ); strcpy( (char*)pBtCfg->mName, (char*)pdidoi->tszName );
pBtCfg->mIsAvailable = true; pBtCfg->mIsAvailable = true;
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
} }
@@ -393,38 +393,38 @@ BOOL CALLBACK JXInput::EnumButtonsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi
BOOL CALLBACK JXInput::EnumPOVsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, BOOL CALLBACK JXInput::EnumPOVsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
VOID* pContext ) VOID* pContext )
{ {
JXInput* pThis = (JXInput*)pContext; JXInput* pThis = (JXInput*)pContext;
// //
// if the maximum number of buttons is already registered, // if the maximum number of buttons is already registered,
// issue a warning and stop enumeration. // issue a warning and stop enumeration.
// //
if( JXINPUT_MAX_DIRECTIONALS == pThis->mPOVCount ) if( JXINPUT_MAX_DIRECTIONALS == pThis->mPOVCount )
{ {
OutputDebugString( "Max. number of POVs exceeded!" ); OutputDebugString( "Max. number of POVs exceeded!" );
return DIENUM_STOP; return DIENUM_STOP;
} }
DirectionalConfig* pDirCfg = NULL; DirectionalConfig* pDirCfg = NULL;
if (pdidoi->guidType == GUID_POV) if (pdidoi->guidType == GUID_POV)
{ {
assert( JXINPUT_MAX_DIRECTIONALS > pThis->mPOVCount ); assert( JXINPUT_MAX_DIRECTIONALS > pThis->mPOVCount );
pDirCfg = & pThis->mDirectionalConfig[ pThis->mPOVCount++ ]; pDirCfg = & pThis->mDirectionalConfig[ pThis->mPOVCount++ ];
} }
// fail-safe // fail-safe
if( NULL == pDirCfg ) // e.g. unknown stuff if( NULL == pDirCfg ) // e.g. unknown stuff
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
assert( NULL != pDirCfg ); assert( NULL != pDirCfg );
// //
// Perform config. // Perform config.
// //
strcpy( (char*)pDirCfg->mName, (char*)pdidoi->tszName ); strcpy( (char*)pDirCfg->mName, (char*)pdidoi->tszName );
pDirCfg->mIsAvailable = true; pDirCfg->mIsAvailable = true;
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
} }
@@ -436,13 +436,13 @@ BOOL CALLBACK JXInput::EnumPOVsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
// Desc: Callback function for enumerating the effects of a joystick // Desc: Callback function for enumerating the effects of a joystick
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
BOOL CALLBACK JXInput::EnumEffectsCallback( const DIEFFECTINFO* pdidoi, BOOL CALLBACK JXInput::EnumEffectsCallback( const DIEFFECTINFO* pdidoi,
VOID* pContext ) VOID* pContext )
{ {
//JXInput* pThis = (JXInput*)pContext; //JXInput* pThis = (JXInput*)pContext;
// //
// Work on that!! // Work on that!!
// //
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
} }
@@ -463,12 +463,12 @@ HRESULT JXInput::InitDirectInput( HWND hWnd )
return E_FAIL; return E_FAIL;
} }
// //
// Ask the device for some useful information. // Ask the device for some useful information.
// //
mdiDevInfo.dwSize = sizeof( DIDEVICEINSTANCE ); mdiDevInfo.dwSize = sizeof( DIDEVICEINSTANCE );
hr = mpJoystick->GetDeviceInfo( &mdiDevInfo ); hr = mpJoystick->GetDeviceInfo( &mdiDevInfo );
if( FAILED(hr) ) if( FAILED(hr) )
return hr; return hr;
@@ -484,10 +484,10 @@ HRESULT JXInput::InitDirectInput( HWND hWnd )
// Set the cooperative level to let DInput know how this device should // Set the cooperative level to let DInput know how this device should
// interact with the system and with other DInput applications. // interact with the system and with other DInput applications.
// hr = g_pJoystick->SetCooperativeLevel( hDlg, DISCL_EXCLUSIVE|DISCL_FOREGROUND ); // hr = g_pJoystick->SetCooperativeLevel( hDlg, DISCL_EXCLUSIVE|DISCL_FOREGROUND );
DWORD mode = ( NULL == hWnd ? DISCL_NONEXCLUSIVE|DISCL_BACKGROUND : DISCL_EXCLUSIVE|DISCL_BACKGROUND ); DWORD mode = ( NULL == hWnd ? DISCL_NONEXCLUSIVE|DISCL_BACKGROUND : DISCL_EXCLUSIVE|DISCL_BACKGROUND );
hr = mpJoystick->SetCooperativeLevel( hWnd, mode ); hr = mpJoystick->SetCooperativeLevel( hWnd, mode );
if( FAILED(hr) ) if( FAILED(hr) )
return hr; return hr;
// Determine how many axis the joystick has (so we don't error out setting // Determine how many axis the joystick has (so we don't error out setting
// properties for unavailable axis) // properties for unavailable axis)
@@ -500,14 +500,14 @@ HRESULT JXInput::InitDirectInput( HWND hWnd )
// Enumerate the axes of the joyctick and set the range of each axis. Note: // Enumerate the axes of the joyctick and set the range of each axis. Note:
// we could just use the defaults, but we're just trying to show an example // we could just use the defaults, but we're just trying to show an example
// of enumerating device objects (axes, buttons, etc.). // of enumerating device objects (axes, buttons, etc.).
mpJoystick->EnumObjects( EnumAxesCallback, (VOID*)this, DIDFT_AXIS ); mpJoystick->EnumObjects( EnumAxesCallback, (VOID*)this, DIDFT_AXIS );
mpJoystick->EnumObjects( EnumButtonsCallback, (VOID*)this, DIDFT_BUTTON ); mpJoystick->EnumObjects( EnumButtonsCallback, (VOID*)this, DIDFT_BUTTON );
mpJoystick->EnumObjects( EnumPOVsCallback, (VOID*)this, DIDFT_POV ); mpJoystick->EnumObjects( EnumPOVsCallback, (VOID*)this, DIDFT_POV );
mpJoystick->EnumEffects( EnumEffectsCallback, (VOID*)this, DIEFT_ALL ); mpJoystick->EnumEffects( EnumEffectsCallback, (VOID*)this, DIEFT_ALL );
// For FF sticks, switch on autocenter as long as we do not use real FF // For FF sticks, switch on autocenter as long as we do not use real FF
SwitchAutoCenter( true ); SwitchAutoCenter( true );
return S_OK; return S_OK;
} }
@@ -527,27 +527,27 @@ HRESULT JXInput::UpdateInputState()
if( mpJoystick ) if( mpJoystick )
{ {
// Poll the device to read the current state // Poll the device to read the current state
hr = mpJoystick->Poll(); hr = mpJoystick->Poll();
if( FAILED(hr) ) if( FAILED(hr) )
{ {
// DInput is telling us that the input stream has been // DInput is telling us that the input stream has been
// interrupted. We aren't tracking any state between polls, so // interrupted. We aren't tracking any state between polls, so
// we don't have any special reset that needs to be done. We // we don't have any special reset that needs to be done. We
// just re-acquire and try again. // just re-acquire and try again.
hr = mpJoystick->Acquire(); hr = mpJoystick->Acquire();
while( hr == DIERR_INPUTLOST ) while( hr == DIERR_INPUTLOST )
hr = mpJoystick->Acquire(); hr = mpJoystick->Acquire();
// hr may be DIERR_OTHERAPPHASPRIO or other errors. This // hr may be DIERR_OTHERAPPHASPRIO or other errors. This
// may occur when the app is minimized or in the process of // may occur when the app is minimized or in the process of
// switching, so just try again later // switching, so just try again later
return S_OK; return S_OK;
} }
// Get the input's device state // Get the input's device state
if( FAILED( hr = mpJoystick->GetDeviceState( sizeof(DIJOYSTATE2), &mJS ) ) ) if( FAILED( hr = mpJoystick->GetDeviceState( sizeof(DIJOYSTATE2), &mJS ) ) )
return hr; // The device should have been acquired during the Poll() return hr; // The device should have been acquired during the Poll()
} }
@@ -570,8 +570,8 @@ HRESULT JXInput::FreeDirectInput()
// the app tried to exit while the device is still acquired. // the app tried to exit while the device is still acquired.
mpJoystick->Unacquire(); mpJoystick->Unacquire();
mpJoystick->Release(); mpJoystick->Release();
mpJoystick = NULL; mpJoystick = NULL;
} }
return S_OK; return S_OK;
@@ -583,14 +583,14 @@ HRESULT JXInput::SwitchAutoCenter( bool onoff )
{ {
HRESULT hr; HRESULT hr;
DIPROPDWORD DIPropAutoCenter; DIPROPDWORD DIPropAutoCenter;
DIPropAutoCenter.diph.dwSize = sizeof(DIPropAutoCenter); DIPropAutoCenter.diph.dwSize = sizeof(DIPropAutoCenter);
DIPropAutoCenter.diph.dwHeaderSize = sizeof(DIPROPHEADER); DIPropAutoCenter.diph.dwHeaderSize = sizeof(DIPROPHEADER);
DIPropAutoCenter.diph.dwObj = 0; DIPropAutoCenter.diph.dwObj = 0;
DIPropAutoCenter.diph.dwHow = DIPH_DEVICE; DIPropAutoCenter.diph.dwHow = DIPH_DEVICE;
DIPropAutoCenter.dwData = ( onoff ? DIPROPAUTOCENTER_ON : DIPROPAUTOCENTER_OFF ); DIPropAutoCenter.dwData = ( onoff ? DIPROPAUTOCENTER_ON : DIPROPAUTOCENTER_OFF );
hr = mpJoystick->SetProperty( DIPROP_AUTOCENTER, &DIPropAutoCenter.diph ); hr = mpJoystick->SetProperty( DIPROP_AUTOCENTER, &DIPropAutoCenter.diph );
return hr; return hr;
} }

View File

@@ -6,19 +6,19 @@ HINSTANCE g_hInst;
BOOL APIENTRY DllMain( HANDLE hModule, BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call, DWORD ul_reason_for_call,
LPVOID lpReserved LPVOID lpReserved
) )
{ {
switch (ul_reason_for_call) switch (ul_reason_for_call)
{ {
case DLL_PROCESS_ATTACH: case DLL_PROCESS_ATTACH:
g_hInst = (HINSTANCE)hModule; g_hInst = (HINSTANCE)hModule;
break; break;
case DLL_THREAD_ATTACH: case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH: case DLL_THREAD_DETACH:
break; break;
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
g_hInst = NULL; g_hInst = NULL;
break; break;
} }
return TRUE; return TRUE;
} }

View File

@@ -5,29 +5,29 @@ class JXInput;
class JXINPUT_API JXInputManager class JXINPUT_API JXInputManager
{ {
public: public:
JXInputManager( HWND hWnd ); JXInputManager( HWND hWnd );
virtual ~JXInputManager(); virtual ~JXInputManager();
int getNumberOfJXInputs() const; int getNumberOfJXInputs() const;
JXInput& getJXInput( int idx ) const; JXInput& getJXInput( int idx ) const;
// //
// Numbering methods // Numbering methods
// //
int getMaxNumberOfAxes() const; int getMaxNumberOfAxes() const;
int getMaxNumberOfButtons() const; int getMaxNumberOfButtons() const;
int getMaxNumberOfDirectionals() const; int getMaxNumberOfDirectionals() const;
private: private:
LPDIRECTINPUT8 mpDI; LPDIRECTINPUT8 mpDI;
HWND mhWnd; HWND mhWnd;
JXInput* mDevices[ MAX_JXINPUTS ]; JXInput* mDevices[ MAX_JXINPUTS ];
int mDeviceCounter; int mDeviceCounter;
HRESULT InitDirectInput( HWND hWnd = NULL ); HRESULT InitDirectInput( HWND hWnd = NULL );
HRESULT FreeDirectInput(); HRESULT FreeDirectInput();
static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance,
VOID* pContext ); VOID* pContext );
void addJXInput( JXInput* pJ ); void addJXInput( JXInput* pJ );
}; };

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 19. Dezember 2001, 21:58 // Created on 19. Dezember 2001, 21:58
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput; package de.hardcode.jxinput;
@@ -15,49 +15,49 @@ package de.hardcode.jxinput;
*/ */
public interface Axis extends Feature public interface Axis extends Feature
{ {
// Enumeration of axes. // Enumeration of axes.
final static int ID_X = 0; final static int ID_X = 0;
final static int ID_Y = 1; final static int ID_Y = 1;
final static int ID_Z = 2; final static int ID_Z = 2;
final static int ID_ROTX = 3; final static int ID_ROTX = 3;
final static int ID_ROTY = 4; final static int ID_ROTY = 4;
final static int ID_ROTZ = 5; final static int ID_ROTZ = 5;
final static int ID_SLIDER0 = 6; final static int ID_SLIDER0 = 6;
final static int ID_SLIDER1 = 7; final static int ID_SLIDER1 = 7;
final static int NUMBER_OF_ID = 8; final static int NUMBER_OF_ID = 8;
// Enumeration of axis types // Enumeration of axis types
final static int TRANSLATION = 0; final static int TRANSLATION = 0;
final static int ROTATION = 1; final static int ROTATION = 1;
final static int SLIDER = 2; final static int SLIDER = 2;
/** /**
* Retrieve the type of the axis. * Retrieve the type of the axis.
* The type is describes the meaning and the range of values of the axis. * The type is describes the meaning and the range of values of the axis.
* <p> * <p>
* <code>TRANSLATION</code> typed axes denote a translational deviation from a center * <code>TRANSLATION</code> typed axes denote a translational deviation from a center
* position. This can be e.g. the common, basic joystick axes. * position. This can be e.g. the common, basic joystick axes.
* The range of <code>getValue()</code> is <code>[-1.0,1.0]</code>. * The range of <code>getValue()</code> is <code>[-1.0,1.0]</code>.
* <p> * <p>
* <code>ROTATION</code> typed axes denote a rotational deviation from a center * <code>ROTATION</code> typed axes denote a rotational deviation from a center
* position. Something on the stick is turned or twisted. * position. Something on the stick is turned or twisted.
* The range of <code>getValue()</code> is <code>[-1.0,1.0]</code>. * The range of <code>getValue()</code> is <code>[-1.0,1.0]</code>.
* <p> * <p>
* <code>SLIDER</code> typed axes denote a shifting device without a center position. * <code>SLIDER</code> typed axes denote a shifting device without a center position.
* A good sample is a throttle control. * A good sample is a throttle control.
* The range of <code>getValue()</code> is <code>[0.0,1.0]</code>. * The range of <code>getValue()</code> is <code>[0.0,1.0]</code>.
* *
* @return [ TRANSLATION | ROTATION | SLIDER ] * @return [ TRANSLATION | ROTATION | SLIDER ]
*/ */
int getType(); int getType();
/** /**
* Returns the current value of the axis. * Returns the current value of the axis.
* The range of the result depends on the axis type. * The range of the result depends on the axis type.
* *
* @return value [-1.0,1.0] or [0.0,1.0] * @return value [-1.0,1.0] or [0.0,1.0]
*/ */
double getValue(); double getValue();
/** /**

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 19. Dezember 2001, 21:58 // Created on 19. Dezember 2001, 21:58
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput; package de.hardcode.jxinput;
@@ -14,22 +14,22 @@ package de.hardcode.jxinput;
*/ */
public interface Button extends Feature public interface Button extends Feature
{ {
// Enumeration of button types // Enumeration of button types
final static int PUSHBUTTON = 0; final static int PUSHBUTTON = 0;
final static int TOGGLEBUTTON = 1; final static int TOGGLEBUTTON = 1;
/** /**
* Retrieve the type of the button. * Retrieve the type of the button.
* Pushbutton will deliver <code>true==getState()</code> as long as they are pressed down. * Pushbutton will deliver <code>true==getState()</code> as long as they are pressed down.
* Togglebuttons will change their state once they are pressed and keep that state * Togglebuttons will change their state once they are pressed and keep that state
* until they are pressed again. * until they are pressed again.
* @return [ PUSHBUTTON | TOGGLEBUTTON ] * @return [ PUSHBUTTON | TOGGLEBUTTON ]
*/ */
int getType(); int getType();
/** /**
* Tells the state of the button at last update. * Tells the state of the button at last update.
*/ */
boolean getState(); boolean getState();
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 27. Dezember 2001, 23:33 // Created on 27. Dezember 2001, 23:33
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput; package de.hardcode.jxinput;
@@ -14,32 +14,32 @@ package de.hardcode.jxinput;
*/ */
public interface Directional extends Feature public interface Directional extends Feature
{ {
/** /**
* If the Directional has a center position where it points to no direction, this * If the Directional has a center position where it points to no direction, this
* flag is true when this position is reached. * flag is true when this position is reached.
*/ */
boolean isCentered(); boolean isCentered();
/** /**
* Retrieve the direction pointed to. * Retrieve the direction pointed to.
* Value is given in 1/100 degree, [0,36000] * Value is given in 1/100 degree, [0,36000]
*/ */
int getDirection(); int getDirection();
/** /**
* Retrieve the analog value pointing to the angle described by * Retrieve the analog value pointing to the angle described by
* <code>getDirection()</code>. * <code>getDirection()</code>.
* For coolie hats this will be either 1,0 for any direction or 0.0 * For coolie hats this will be either 1,0 for any direction or 0.0
* when <code>isCentered()==true</code>. * when <code>isCentered()==true</code>.
*/ */
double getValue(); double getValue();
/** /**
* Inform about the resolution of the value returned by <code>getValue()</code>. * Inform about the resolution of the value returned by <code>getValue()</code>.
* *
* @return resolution, e.g. 1.0 for coolie hats * @return resolution, e.g. 1.0 for coolie hats
*/ */
double getResolution(); double getResolution();
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 27. Dezember 2001, 00:19 // Created on 27. Dezember 2001, 00:19
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput; package de.hardcode.jxinput;
@@ -24,15 +24,15 @@ package de.hardcode.jxinput;
*/ */
public abstract interface Feature public abstract interface Feature
{ {
/** /**
* Features may have a name provided e.g. by the driver. * Features may have a name provided e.g. by the driver.
*/ */
String getName(); String getName();
/** /**
* Denote wether this feature has changed beyond it's resolution since it got last * Denote wether this feature has changed beyond it's resolution since it got last
* updated. * updated.
*/ */
boolean hasChanged(); boolean hasChanged();
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 19. Dezember 2001, 21:47 // Created on 19. Dezember 2001, 21:47
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput; package de.hardcode.jxinput;
@@ -30,42 +30,42 @@ package de.hardcode.jxinput;
*/ */
public interface JXInputDevice public interface JXInputDevice
{ {
/** /**
* @directed * @directed
*/ */
/*#Features lnkFeatures;*/ /*#Features lnkFeatures;*/
/** /**
*@link aggregationByValue *@link aggregationByValue
*/ */
/*#Feature lnkFeature;*/ /*#Feature lnkFeature;*/
/** /**
* Devices may have a name. * Devices may have a name.
* This name might be provided by a system dependant driver. * This name might be provided by a system dependant driver.
*/ */
String getName(); String getName();
/** Actual number of available axes. */ /** Actual number of available axes. */
int getNumberOfAxes(); int getNumberOfAxes();
/** Actual number of available buttons. */ /** Actual number of available buttons. */
int getNumberOfButtons(); int getNumberOfButtons();
/** Actual number of available directional features. */ /** Actual number of available directional features. */
int getNumberOfDirectionals(); int getNumberOfDirectionals();
/** Maximum number of axes as an upper bound for index values. */ /** Maximum number of axes as an upper bound for index values. */
int getMaxNumberOfAxes(); int getMaxNumberOfAxes();
/** Maximum number of buttons as an upper bound for index values. */ /** Maximum number of buttons as an upper bound for index values. */
int getMaxNumberOfButtons(); int getMaxNumberOfButtons();
/** Maximum number of directional features as an upper bound for index values. */ /** Maximum number of directional features as an upper bound for index values. */
int getMaxNumberOfDirectionals(); int getMaxNumberOfDirectionals();
Axis getAxis( int idx ); Axis getAxis( int idx );
Button getButton( int idx ); Button getButton( int idx );
Directional getDirectional( int idx ); Directional getDirectional( int idx );
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 29. Dezember 2001, 02:17 // Created on 29. Dezember 2001, 02:17
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput; package de.hardcode.jxinput;
@@ -29,44 +29,44 @@ import java.awt.Component;
*/ */
public class JXInputManager public class JXInputManager
{ {
/** Remember when the last update took place. */ /** Remember when the last update took place. */
private static long mTimeOfLastUpdate; private static long mTimeOfLastUpdate;
/** Maintain a list of devices. */ /** Maintain a list of devices. */
private final static ArrayList mDevices = new ArrayList(); private final static ArrayList mDevices = new ArrayList();
/** Maintain a list of direct input devices. */ /** Maintain a list of direct input devices. */
private final static ArrayList mDIDevices = new ArrayList(); private final static ArrayList mDIDevices = new ArrayList();
/** Maintain a list of virtual devices. */ /** Maintain a list of virtual devices. */
private final static ArrayList mVirtualDevices = new ArrayList(); private final static ArrayList mVirtualDevices = new ArrayList();
/** Maintain a list of keyboard devices. */ /** Maintain a list of keyboard devices. */
private final static ArrayList mKBDevices = new ArrayList(); private final static ArrayList mKBDevices = new ArrayList();
/** /**
* Statically retrieve all DirectInputDevices available. * Statically retrieve all DirectInputDevices available.
*/ */
static static
{ {
reset(); reset();
} }
/** /**
* @directed * @directed
*/ */
/*#JXInputDevice lnkJXInputDevice;*/ /*#JXInputDevice lnkJXInputDevice;*/
/** /**
* Creates a new instance of JXInputManager. * Creates a new instance of JXInputManager.
* This is prohibited - it only has static members. * This is prohibited - it only has static members.
*/ */
private JXInputManager() private JXInputManager()
{ {
} }
/** /**
* Retrieve the number of available input devices. * Retrieve the number of available input devices.
@@ -76,158 +76,158 @@ public class JXInputManager
return mDevices.size(); return mDevices.size();
} }
/** /**
* Delivers the JXInputDevice with the desired index. * Delivers the JXInputDevice with the desired index.
* <p> * <p>
* Take care that <code>idx < getNumberOfDevices()</code>! * Take care that <code>idx < getNumberOfDevices()</code>!
*/ */
public static JXInputDevice getJXInputDevice( int idx ) public static JXInputDevice getJXInputDevice( int idx )
{ {
// //
// Be well-behaved even if idx is out of range. // Be well-behaved even if idx is out of range.
// //
if ( idx >= mDevices.size() ) if ( idx >= mDevices.size() )
return null; return null;
return (JXInputDevice)mDevices.get( idx ); return (JXInputDevice)mDevices.get( idx );
} }
/** /**
* Master reset for all devices and events. * Master reset for all devices and events.
* After calling reset(), better forget all devices created or retrieved. * After calling reset(), better forget all devices created or retrieved.
* They are no longer valid. * They are no longer valid.
* Event listeners will no longer be called and should be discarded. * Event listeners will no longer be called and should be discarded.
*/ */
synchronized public static void reset() synchronized public static void reset()
{ {
JXInputEventManager.reset(); JXInputEventManager.reset();
mDevices.clear(); mDevices.clear();
mVirtualDevices.clear(); mVirtualDevices.clear();
mDIDevices.clear(); mDIDevices.clear();
DirectInputDevice.reset(); DirectInputDevice.reset();
for ( int i = 0; i < DirectInputDevice.getNumberOfDevices(); ++i ) for ( int i = 0; i < DirectInputDevice.getNumberOfDevices(); ++i )
{ {
DirectInputDevice dev = new DirectInputDevice( i ); DirectInputDevice dev = new DirectInputDevice( i );
mDevices.add( dev ); mDevices.add( dev );
mDIDevices.add( dev ); mDIDevices.add( dev );
} }
// I have to call updateFeatures one time here during initialization // I have to call updateFeatures one time here during initialization
// bc. I experienced difficulties otherwise while running with the // bc. I experienced difficulties otherwise while running with the
// J3D sensoring stuff! // J3D sensoring stuff!
// updateFeatures(); // updateFeatures();
DirectInputDevice.update(); DirectInputDevice.update();
int n = mKBDevices.size(); int n = mKBDevices.size();
for ( int i = 0; i < n; ++i ) for ( int i = 0; i < n; ++i )
((JXKeyboardInputDevice)mKBDevices.get( i )).shutdown(); ((JXKeyboardInputDevice)mKBDevices.get( i )).shutdown();
mKBDevices.clear(); mKBDevices.clear();
} }
/** /**
* Update the (shared) state of all features in one step. * Update the (shared) state of all features in one step.
* This method asks the actual device for a consistant state. * This method asks the actual device for a consistant state.
* After calling this method, all features may have new values. * After calling this method, all features may have new values.
* updateFeatures() is meant to be called e.g. once per frame in a gaming environment. * updateFeatures() is meant to be called e.g. once per frame in a gaming environment.
*/ */
public static void updateFeatures() public static void updateFeatures()
{ {
// Get timing // Get timing
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long deltaT = now - mTimeOfLastUpdate; long deltaT = now - mTimeOfLastUpdate;
// Update available driver
DirectInputDevice.update();
// // Update available driver
// Update the virtual devices. DirectInputDevice.update();
//
Iterator vdevices = mVirtualDevices.iterator(); //
while ( vdevices.hasNext() ) // Update the virtual devices.
{ //
((JXVirtualInputDevice)vdevices.next()).update( deltaT ); Iterator vdevices = mVirtualDevices.iterator();
} while ( vdevices.hasNext() )
{
((JXVirtualInputDevice)vdevices.next()).update( deltaT );
}
// Remember time // Remember time
mTimeOfLastUpdate = now; mTimeOfLastUpdate = now;
// Fire all events. // Fire all events.
JXInputEventManager.trigger(); JXInputEventManager.trigger();
} }
/** /**
* Get time when last update occurred. * Get time when last update occurred.
* @return tickervalue in milliseconds * @return tickervalue in milliseconds
*/ */
public static long getLastUpdateTime() public static long getLastUpdateTime()
{ {
return mTimeOfLastUpdate; return mTimeOfLastUpdate;
} }
/** /**
* Create a new pseudo-device. * Create a new pseudo-device.
*/ */
public static JXKeyboardInputDevice createKeyboardDevice() public static JXKeyboardInputDevice createKeyboardDevice()
{ {
JXKeyboardInputDevice d = new JXKeyboardInputDevice(); JXKeyboardInputDevice d = new JXKeyboardInputDevice();
mDevices.add( d ); mDevices.add( d );
mKBDevices.add( d ); mKBDevices.add( d );
return d; return d;
} }
/** /**
* Create a new pseudo-device listening to a Swing component. * Create a new pseudo-device listening to a Swing component.
* Make sure that the component also has the keyboard focus!! * Make sure that the component also has the keyboard focus!!
*/ */
public static JXKeyboardInputDevice createKeyboardDevice( Component comp ) public static JXKeyboardInputDevice createKeyboardDevice( Component comp )
{ {
JXKeyboardInputDevice d = new JXKeyboardInputDevice( comp ); JXKeyboardInputDevice d = new JXKeyboardInputDevice( comp );
mDevices.add( d ); mDevices.add( d );
mKBDevices.add( d ); mKBDevices.add( d );
return d; return d;
} }
/** /**
* Delete a keyboard device again e.g. when the corresponding * Delete a keyboard device again e.g. when the corresponding
* JComponent gets deleted. * JComponent gets deleted.
*/ */
public static void deleteKeyboardDevice( JXKeyboardInputDevice dev ) public static void deleteKeyboardDevice( JXKeyboardInputDevice dev )
{ {
mDevices.remove( dev ); mDevices.remove( dev );
mKBDevices.remove( dev ); mKBDevices.remove( dev );
((JXKeyboardInputDevice)dev).shutdown(); ((JXKeyboardInputDevice)dev).shutdown();
} }
/** /**
* Create a new pseudo-device. * Create a new pseudo-device.
*/ */
public static JXVirtualInputDevice createVirtualDevice() public static JXVirtualInputDevice createVirtualDevice()
{ {
JXVirtualInputDevice d = new JXVirtualInputDevice(); JXVirtualInputDevice d = new JXVirtualInputDevice();
mDevices.add( d ); mDevices.add( d );
mVirtualDevices.add( d ); mVirtualDevices.add( d );
return d; return d;
} }
/** /**
* Delete a virtual device again. * Delete a virtual device again.
*/ */
public static void deleteVirtualDevice( JXVirtualInputDevice dev ) public static void deleteVirtualDevice( JXVirtualInputDevice dev )
{ {
mDevices.remove( dev ); mDevices.remove( dev );
mVirtualDevices.remove( dev ); mVirtualDevices.remove( dev );
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 27. Dezember 2001, 00:14 // Created on 27. Dezember 2001, 00:14
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.directinput; package de.hardcode.jxinput.directinput;
@@ -17,53 +17,53 @@ import de.hardcode.jxinput.Axis;
class DIAxis implements Axis class DIAxis implements Axis
{ {
private final int mDeviceIdx; private final int mDeviceIdx;
private final int mIdx; private final int mIdx;
/** /**
* Creates a new instance of DIAxis. * Creates a new instance of DIAxis.
*/ */
DIAxis( int devidx, int idx ) DIAxis( int devidx, int idx )
{ {
mDeviceIdx = devidx; mDeviceIdx = devidx;
mIdx = idx; mIdx = idx;
} }
public String getName() public String getName()
{ {
return DirectInputDriver.getAxisName( mDeviceIdx, mIdx ); return DirectInputDriver.getAxisName( mDeviceIdx, mIdx );
} }
/** /**
* Denote wether this feature has changed beyond it's resolution since it got last * Denote wether this feature has changed beyond it's resolution since it got last
* updated. * updated.
*/ */
public boolean hasChanged() public boolean hasChanged()
{ {
return true; return true;
} }
public double getValue() public double getValue()
{ {
return DirectInputDriver.getAxisValue( mDeviceIdx, mIdx ); return DirectInputDriver.getAxisValue( mDeviceIdx, mIdx );
} }
public int getType() public int getType()
{ {
return DirectInputDriver.getAxisType( mDeviceIdx, mIdx ); return DirectInputDriver.getAxisType( mDeviceIdx, mIdx );
} }
/** /**
* Inform about the resolution of the axis. * Inform about the resolution of the axis.
* *
* @return resolution, e.g. 2^-16 * @return resolution, e.g. 2^-16
*/ */
public double getResolution() public double getResolution()
{ {
// extend the driver here!! // extend the driver here!!
// Here I assume typical 16 bit resolution // Here I assume typical 16 bit resolution
return ( getType() == Axis.SLIDER ? 1.0/65536.0 : 2.0/65536.0 ) ; return ( getType() == Axis.SLIDER ? 1.0/65536.0 : 2.0/65536.0 ) ;
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 27. Dezember 2001, 00:14 // Created on 27. Dezember 2001, 00:14
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.directinput; package de.hardcode.jxinput.directinput;
@@ -18,38 +18,38 @@ import de.hardcode.jxinput.Button;
class DIButton implements Button class DIButton implements Button
{ {
private final int mDeviceIdx; private final int mDeviceIdx;
private final int mIdx; private final int mIdx;
/** /**
* Creates a new instance of DIButton. * Creates a new instance of DIButton.
*/ */
DIButton( int devidx, int idx ) DIButton( int devidx, int idx )
{ {
mDeviceIdx = devidx; mDeviceIdx = devidx;
mIdx = idx; mIdx = idx;
} }
public String getName() public String getName()
{ {
return DirectInputDriver.getButtonName( mDeviceIdx, mIdx ); return DirectInputDriver.getButtonName( mDeviceIdx, mIdx );
} }
/** /**
* Denote wether this feature has changed beyond it's resolution since it got last * Denote wether this feature has changed beyond it's resolution since it got last
* updated. * updated.
*/ */
public boolean hasChanged() public boolean hasChanged()
{ {
return true; return true;
} }
public int getType() public int getType()
{ {
return DirectInputDriver.getButtonType( mDeviceIdx, mIdx ); return DirectInputDriver.getButtonType( mDeviceIdx, mIdx );
} }
public boolean getState() public boolean getState()
{ {
return DirectInputDriver.getButtonState( mDeviceIdx, mIdx ); return DirectInputDriver.getButtonState( mDeviceIdx, mIdx );
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 27. Dezember 2001, 23:40 // Created on 27. Dezember 2001, 23:40
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.directinput; package de.hardcode.jxinput.directinput;
@@ -17,62 +17,62 @@ import de.hardcode.jxinput.Directional;
class DIDirectional implements Directional class DIDirectional implements Directional
{ {
private final int mDeviceIdx; private final int mDeviceIdx;
private final int mIdx; private final int mIdx;
/** /**
* Creates a new instance of DIDirectional. * Creates a new instance of DIDirectional.
*/ */
DIDirectional( int devidx, int idx ) DIDirectional( int devidx, int idx )
{ {
mDeviceIdx = devidx; mDeviceIdx = devidx;
mIdx = idx; mIdx = idx;
} }
/** Features may have a name provided e.g. by the driver. */ /** Features may have a name provided e.g. by the driver. */
public String getName() public String getName()
{ {
return DirectInputDriver.getDirectionalName( mDeviceIdx, mIdx ); return DirectInputDriver.getDirectionalName( mDeviceIdx, mIdx );
} }
/** /**
* Denote wether this feature has changed beyond it's resolution since it got last * Denote wether this feature has changed beyond it's resolution since it got last
* updated. * updated.
*/ */
public boolean hasChanged() public boolean hasChanged()
{ {
return true; return true;
} }
public boolean isCentered() public boolean isCentered()
{ {
return ( 0xffff == (DirectInputDriver.getDirection( mDeviceIdx, mIdx ) & 0xffff) ); return ( 0xffff == (DirectInputDriver.getDirection( mDeviceIdx, mIdx ) & 0xffff) );
} }
public int getDirection() public int getDirection()
{ {
return isCentered() ? 0 : DirectInputDriver.getDirection( mDeviceIdx, mIdx ); return isCentered() ? 0 : DirectInputDriver.getDirection( mDeviceIdx, mIdx );
} }
public double getValue() public double getValue()
{ {
if ( isCentered() ) if ( isCentered() )
return 0.0; return 0.0;
return 1.0; return 1.0;
} }
/** /**
* Inform about the resolution of the value returned by <code>getValue()</code>. * Inform about the resolution of the value returned by <code>getValue()</code>.
* *
* @return resolution, e.g. 1.0 for coolie hats * @return resolution, e.g. 1.0 for coolie hats
*/ */
public double getResolution() public double getResolution()
{ {
// DI POV always return 0.0 or 1.0, so the resolution is 1.0. // DI POV always return 0.0 or 1.0, so the resolution is 1.0.
return 1.0; return 1.0;
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 26. Dezember 2001, 00:40 // Created on 26. Dezember 2001, 00:40
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.directinput; package de.hardcode.jxinput.directinput;
@@ -18,151 +18,151 @@ import de.hardcode.jxinput.Button;
* @author Herkules * @author Herkules
*/ */
public class DirectInputDevice implements JXInputDevice public class DirectInputDevice implements JXInputDevice
{ {
int mDeviceIdx; int mDeviceIdx;
private DIAxis[] mAxes; private DIAxis[] mAxes;
private DIButton[] mButtons; private DIButton[] mButtons;
private DIDirectional[] mDirectionals; private DIDirectional[] mDirectionals;
/** /**
* The number of DirectInput devices available with the driver. * The number of DirectInput devices available with the driver.
*/ */
public static int getNumberOfDevices() public static int getNumberOfDevices()
{ {
if ( DirectInputDriver.isAvailable() ) if ( DirectInputDriver.isAvailable() )
return DirectInputDriver.getNumberOfDevices(); return DirectInputDriver.getNumberOfDevices();
return 0; return 0;
} }
/** /**
* Update the state of all devices. * Update the state of all devices.
*/ */
public static void update() public static void update()
{ {
if ( DirectInputDriver.isAvailable() ) if ( DirectInputDriver.isAvailable() )
DirectInputDriver.nativeupdate(); DirectInputDriver.nativeupdate();
} }
/** /**
* Creates a new instance of DirectInputDevice. * Creates a new instance of DirectInputDevice.
*/ */
public DirectInputDevice( int devidx ) public DirectInputDevice( int devidx )
{ {
mDeviceIdx = devidx; mDeviceIdx = devidx;
init(); init();
} }
/** /**
* Reset the DirectInput connection. * Reset the DirectInput connection.
*/ */
public static void reset() public static void reset()
{ {
if ( DirectInputDriver.isAvailable() ) if ( DirectInputDriver.isAvailable() )
DirectInputDriver.reset(); DirectInputDriver.reset();
} }
/** /**
* Initialisation of fields. * Initialisation of fields.
*/ */
private final void init() private final void init()
{ {
// //
// Allocate arrays for max. number of features // Allocate arrays for max. number of features
// //
mAxes = new DIAxis [ getMaxNumberOfAxes() ]; mAxes = new DIAxis [ getMaxNumberOfAxes() ];
mButtons = new DIButton [ getMaxNumberOfButtons() ]; mButtons = new DIButton [ getMaxNumberOfButtons() ];
mDirectionals = new DIDirectional [ getMaxNumberOfDirectionals() ]; mDirectionals = new DIDirectional [ getMaxNumberOfDirectionals() ];
// //
// Fill arrays due to the state of the driver. // Fill arrays due to the state of the driver.
// //
for ( int i = 0; i < mAxes.length; ++i ) for ( int i = 0; i < mAxes.length; ++i )
{ {
if ( DirectInputDriver.isAxisAvailable( mDeviceIdx, i ) ) if ( DirectInputDriver.isAxisAvailable( mDeviceIdx, i ) )
mAxes[ i ] = new DIAxis( mDeviceIdx, i ); mAxes[ i ] = new DIAxis( mDeviceIdx, i );
} }
for ( int i = 0; i < mButtons.length; ++i ) for ( int i = 0; i < mButtons.length; ++i )
{ {
if ( DirectInputDriver.isButtonAvailable( mDeviceIdx, i ) ) if ( DirectInputDriver.isButtonAvailable( mDeviceIdx, i ) )
mButtons[ i ] = new DIButton( mDeviceIdx, i ); mButtons[ i ] = new DIButton( mDeviceIdx, i );
} }
for ( int i = 0; i < mDirectionals.length; ++i ) for ( int i = 0; i < mDirectionals.length; ++i )
{ {
if ( DirectInputDriver.isDirectionalAvailable( mDeviceIdx, i ) ) if ( DirectInputDriver.isDirectionalAvailable( mDeviceIdx, i ) )
mDirectionals[ i ] = new DIDirectional( mDeviceIdx, i ); mDirectionals[ i ] = new DIDirectional( mDeviceIdx, i );
} }
} }
/** Devices may have a name. */ /** Devices may have a name. */
public String getName() public String getName()
{ {
String name = DirectInputDriver.getName( mDeviceIdx ); String name = DirectInputDriver.getName( mDeviceIdx );
if ( null == name ) if ( null == name )
return "Win32 DirectInput Joystick"; return "Win32 DirectInput Joystick";
return name; return name;
} }
/** Actual number of available buttons. */
public int getNumberOfButtons()
{
return DirectInputDriver.getNumberOfButtons( mDeviceIdx );
}
/** Actual number of available axes. */
public int getNumberOfAxes()
{
return DirectInputDriver.getNumberOfAxes( mDeviceIdx );
}
/** Actual number of available directional features. */
public int getNumberOfDirectionals()
{
return DirectInputDriver.getNumberOfDirectionals( mDeviceIdx );
}
/** Maximum number of buttons as an upper bound for index values. */
public int getMaxNumberOfButtons()
{
return DirectInputDriver.getMaxNumberOfButtons();
}
/** Maximum number of axes as an upper bound for index values. */
public int getMaxNumberOfAxes()
{
return DirectInputDriver.getMaxNumberOfAxes();
}
/** Maximum number of available directional features. */
public int getMaxNumberOfDirectionals()
{
return DirectInputDriver.getMaxNumberOfDirectionals();
}
public Axis getAxis(int idx) /** Actual number of available buttons. */
{ public int getNumberOfButtons()
return mAxes[ idx ]; {
} return DirectInputDriver.getNumberOfButtons( mDeviceIdx );
}
public Button getButton(int idx) /** Actual number of available axes. */
{ public int getNumberOfAxes()
return mButtons[ idx ]; {
} return DirectInputDriver.getNumberOfAxes( mDeviceIdx );
}
public Directional getDirectional(int idx) /** Actual number of available directional features. */
{ public int getNumberOfDirectionals()
return mDirectionals[ idx ]; {
} return DirectInputDriver.getNumberOfDirectionals( mDeviceIdx );
}
/** Maximum number of buttons as an upper bound for index values. */
public int getMaxNumberOfButtons()
{
return DirectInputDriver.getMaxNumberOfButtons();
}
/** Maximum number of axes as an upper bound for index values. */
public int getMaxNumberOfAxes()
{
return DirectInputDriver.getMaxNumberOfAxes();
}
/** Maximum number of available directional features. */
public int getMaxNumberOfDirectionals()
{
return DirectInputDriver.getMaxNumberOfDirectionals();
}
public Axis getAxis(int idx)
{
return mAxes[ idx ];
}
public Button getButton(int idx)
{
return mButtons[ idx ];
}
public Directional getDirectional(int idx)
{
return mDirectionals[ idx ];
}
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 19. Dezember 2001, 22:44 // Created on 19. Dezember 2001, 22:44
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.directinput; package de.hardcode.jxinput.directinput;
@@ -27,115 +27,115 @@ import com.github.boukefalos.jlibloader.Native;
*/ */
class DirectInputDriver class DirectInputDriver
{ {
private final static String NATIVE_LIB_NAME = "jxinput"; private final static String NATIVE_LIB_NAME = "jxinput";
/** Remember wether nativeinit() succeeded. */ /** Remember wether nativeinit() succeeded. */
static boolean sIsOperational = false; static boolean sIsOperational = false;
// //
// Static arrays to hold the values. // Static arrays to hold the values.
// //
private static double [][] sAxisValues; private static double [][] sAxisValues;
private static boolean [][] sButtonStates; private static boolean [][] sButtonStates;
private static int [][] sDirectionalValues; private static int [][] sDirectionalValues;
/** /**
* Perform the static initialization. * Perform the static initialization.
*/ */
static static
{ {
try try
{ {
Native.load("com.github.boukefalos", "jlibxinput"); Native.load("com.github.boukefalos", "jlibxinput");
init(); init();
} }
catch( SecurityException e ) catch( SecurityException e )
{ {
Log.logger.warning("Native library jxinput not loaded due to a SecurityException."); Log.logger.warning("Native library jxinput not loaded due to a SecurityException.");
} }
catch( UnsatisfiedLinkError e ) catch( UnsatisfiedLinkError e )
{ {
Log.logger.info("Native library jxinput not loaded due to an UnsatisfiedLinkError."); Log.logger.info("Native library jxinput not loaded due to an UnsatisfiedLinkError.");
} }
} }
private final static void init() private final static void init()
{ {
sIsOperational = false; sIsOperational = false;
// //
// Initialize it. // Initialize it.
// //
if ( nativeinit() ) if ( nativeinit() )
{ {
int devs = getNumberOfDevices(); int devs = getNumberOfDevices();
sAxisValues = new double [ devs ][ DirectInputDriver.getMaxNumberOfAxes() ]; sAxisValues = new double [ devs ][ DirectInputDriver.getMaxNumberOfAxes() ];
sButtonStates = new boolean [ devs ][ DirectInputDriver.getMaxNumberOfButtons() ]; sButtonStates = new boolean [ devs ][ DirectInputDriver.getMaxNumberOfButtons() ];
sDirectionalValues = new int [ devs ][ DirectInputDriver.getMaxNumberOfDirectionals() ]; sDirectionalValues = new int [ devs ][ DirectInputDriver.getMaxNumberOfDirectionals() ];
// Bind the native lib to my variables. // Bind the native lib to my variables.
bind(); bind();
// Remember I am fine. // Remember I am fine.
sIsOperational = true; sIsOperational = true;
} }
} }
/** /**
* Static ctor of DirectInputDriver. * Static ctor of DirectInputDriver.
* No object will be created due to the static layout. * No object will be created due to the static layout.
*/ */
private DirectInputDriver() private DirectInputDriver()
{ {
} }
// Administration // Administration
private static native boolean nativeinit(); private static native boolean nativeinit();
private static native void nativeexit(); private static native void nativeexit();
private static native void bind(); private static native void bind();
static native int getNumberOfDevices(); static native int getNumberOfDevices();
// Configuration // Configuration
static native String getName( int dev ); static native String getName( int dev );
static native int getNumberOfAxes( int dev ); static native int getNumberOfAxes( int dev );
static native int getNumberOfButtons( int dev ); static native int getNumberOfButtons( int dev );
static native int getNumberOfDirectionals( int dev ); static native int getNumberOfDirectionals( int dev );
static native int getMaxNumberOfAxes(); static native int getMaxNumberOfAxes();
static native int getMaxNumberOfButtons(); static native int getMaxNumberOfButtons();
static native int getMaxNumberOfDirectionals(); static native int getMaxNumberOfDirectionals();
static native boolean isAxisAvailable( int dev, int idx ); static native boolean isAxisAvailable( int dev, int idx );
static native String getAxisName( int dev, int idx ); static native String getAxisName( int dev, int idx );
static native int getAxisType( int dev, int idx ); static native int getAxisType( int dev, int idx );
static native boolean isButtonAvailable( int dev, int idx ); static native boolean isButtonAvailable( int dev, int idx );
static native String getButtonName( int dev, int idx ); static native String getButtonName( int dev, int idx );
static native int getButtonType( int dev, int idx ); static native int getButtonType( int dev, int idx );
static native boolean isDirectionalAvailable( int dev, int idx ); static native boolean isDirectionalAvailable( int dev, int idx );
static native String getDirectionalName( int dev, int idx ); static native String getDirectionalName( int dev, int idx );
// Operation // Operation
static native void nativeupdate(); static native void nativeupdate();
public static boolean isAvailable() public static boolean isAvailable()
{ {
return sIsOperational; return sIsOperational;
} }
/** /**
* Shutdown the device and free all Win32 resources. * Shutdown the device and free all Win32 resources.
* It is not a good idea to access any joystick features after * It is not a good idea to access any joystick features after
* <code>shutdown()</code>. * <code>shutdown()</code>.
*/ */
static void shutdown() static void shutdown()
{ {
nativeexit(); nativeexit();
sAxisValues = null; sAxisValues = null;
sButtonStates = null; sButtonStates = null;
sDirectionalValues = null; sDirectionalValues = null;
@@ -145,40 +145,40 @@ class DirectInputDriver
/** /**
* Reset the device and free all Win32 resources. * Reset the device and free all Win32 resources.
*/ */
static void reset() static void reset()
{ {
shutdown(); shutdown();
init(); init();
} }
static double getAxisValue( int dev, int idx ) static double getAxisValue( int dev, int idx )
{ {
return sAxisValues[ dev ][ idx ]; return sAxisValues[ dev ][ idx ];
} }
static boolean getButtonState( int dev, int idx ) static boolean getButtonState( int dev, int idx )
{ {
return sButtonStates[ dev ][ idx ]; return sButtonStates[ dev ][ idx ];
} }
static int getDirection( int dev, int idx ) static int getDirection( int dev, int idx )
{ {
return sDirectionalValues[ dev ][ idx ]; return sDirectionalValues[ dev ][ idx ];
} }
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main (String args[]) public static void main (String args[])
{ {
if ( ! sIsOperational ) if ( ! sIsOperational )
return; return;
for( int i = 0; i < 5000; ++i ) for( int i = 0; i < 5000; ++i )
nativeupdate(); nativeupdate();
shutdown(); shutdown();
} }
} }

View File

@@ -1,8 +1,8 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 29. Oktober 2002, 22:57 // Created on 29. Oktober 2002, 22:57
//********************************************************************************************** //**********************************************************************************************

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 31. Januar 2002, 23:33 // Created on 31. Januar 2002, 23:33
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.event; package de.hardcode.jxinput.event;
@@ -18,15 +18,15 @@ import de.hardcode.jxinput.Axis;
public class JXInputAxisEvent public class JXInputAxisEvent
{ {
private final Axis mAxis; private final Axis mAxis;
double mDelta; double mDelta;
/** /**
* Creates a new instance of JXInputEvent. * Creates a new instance of JXInputEvent.
*/ */
JXInputAxisEvent( Axis axis ) JXInputAxisEvent( Axis axis )
{ {
mAxis = axis; mAxis = axis;
} }
/** /**
* The feature that caused the event. * The feature that caused the event.

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 31. Januar 2002, 23:54 // Created on 31. Januar 2002, 23:54
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.event; package de.hardcode.jxinput.event;
@@ -14,6 +14,6 @@ package de.hardcode.jxinput.event;
*/ */
public interface JXInputAxisEventListener public interface JXInputAxisEventListener
{ {
void changed( JXInputAxisEvent ev ); void changed( JXInputAxisEvent ev );
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 31. Januar 2002, 23:33 // Created on 31. Januar 2002, 23:33
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.event; package de.hardcode.jxinput.event;
@@ -18,14 +18,14 @@ import de.hardcode.jxinput.Button;
public class JXInputButtonEvent public class JXInputButtonEvent
{ {
final Button mButton; final Button mButton;
/** /**
* Creates a new instance of JXInputEvent. * Creates a new instance of JXInputEvent.
*/ */
JXInputButtonEvent( Button button ) JXInputButtonEvent( Button button )
{ {
mButton = button; mButton = button;
} }
/** /**
* The feature that caused the event. * The feature that caused the event.

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 31. Januar 2002, 23:54 // Created on 31. Januar 2002, 23:54
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.event; package de.hardcode.jxinput.event;
@@ -14,6 +14,6 @@ package de.hardcode.jxinput.event;
*/ */
public interface JXInputButtonEventListener public interface JXInputButtonEventListener
{ {
void changed( JXInputButtonEvent ev ); void changed( JXInputButtonEvent ev );
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 31. Januar 2002, 23:33 // Created on 31. Januar 2002, 23:33
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.event; package de.hardcode.jxinput.event;
@@ -18,16 +18,16 @@ import de.hardcode.jxinput.Directional;
public class JXInputDirectionalEvent public class JXInputDirectionalEvent
{ {
private final Directional mDirectional; private final Directional mDirectional;
double mValueDelta; double mValueDelta;
int mDirectionDelta; int mDirectionDelta;
/** /**
* Creates a new instance of JXInputEvent. * Creates a new instance of JXInputEvent.
*/ */
JXInputDirectionalEvent( Directional directional ) JXInputDirectionalEvent( Directional directional )
{ {
mDirectional = directional; mDirectional = directional;
} }
/** /**
* The feature that caused the event. * The feature that caused the event.
@@ -45,7 +45,7 @@ public class JXInputDirectionalEvent
return mValueDelta; return mValueDelta;
} }
/** /**
* Return the change in direction that caused the event. * Return the change in direction that caused the event.
*/ */
public int getDirectionDelta() public int getDirectionDelta()

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 31. Januar 2002, 23:54 // Created on 31. Januar 2002, 23:54
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.event; package de.hardcode.jxinput.event;
@@ -14,6 +14,6 @@ package de.hardcode.jxinput.event;
*/ */
public interface JXInputDirectionalEventListener public interface JXInputDirectionalEventListener
{ {
void changed( JXInputDirectionalEvent ev ); void changed( JXInputDirectionalEvent ev );
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 31. Januar 2002, 23:42 // Created on 31. Januar 2002, 23:42
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.event; package de.hardcode.jxinput.event;
@@ -24,13 +24,13 @@ import de.hardcode.jxinput.Directional;
*/ */
public class JXInputEventManager public class JXInputEventManager
{ {
private final static ArrayList mAxisEventListeners = new ArrayList(); private final static ArrayList mAxisEventListeners = new ArrayList();
private final static ArrayList mButtonEventListeners = new ArrayList(); private final static ArrayList mButtonEventListeners = new ArrayList();
private final static ArrayList mDirectionalEventListeners = new ArrayList(); private final static ArrayList mDirectionalEventListeners = new ArrayList();
private static autotrigger mAutoTrigger = null; private static autotrigger mAutoTrigger = null;
/** /**
* Inner class combining a listener with its scheduling parameters. * Inner class combining a listener with its scheduling parameters.
*/ */
@@ -39,29 +39,29 @@ public class JXInputEventManager
final JXInputAxisEventListener mListener; final JXInputAxisEventListener mListener;
final double mTreshold; final double mTreshold;
final JXInputAxisEvent mEvent; final JXInputAxisEvent mEvent;
double mLastValueFired = 0.0; double mLastValueFired = 0.0;
axislistener( JXInputAxisEventListener l, Axis axis, double treshold ) axislistener( JXInputAxisEventListener l, Axis axis, double treshold )
{ {
mListener = l; mListener = l;
mTreshold = treshold; mTreshold = treshold;
mEvent = new JXInputAxisEvent( axis ); mEvent = new JXInputAxisEvent( axis );
} }
final void checkTrigger() final void checkTrigger()
{ {
double curval = mEvent.getAxis().getValue(); double curval = mEvent.getAxis().getValue();
double delta = curval - mLastValueFired; double delta = curval - mLastValueFired;
if ( Math.abs( delta ) >= mTreshold ) if ( Math.abs( delta ) >= mTreshold )
{ {
mLastValueFired = curval; mLastValueFired = curval;
mEvent.mDelta = delta; mEvent.mDelta = delta;
mListener.changed( mEvent ); mListener.changed( mEvent );
} }
} }
} }
/** /**
* Inner class combining a listener with its scheduling parameters. * Inner class combining a listener with its scheduling parameters.
*/ */
@@ -69,142 +69,142 @@ public class JXInputEventManager
{ {
final JXInputButtonEventListener mListener; final JXInputButtonEventListener mListener;
final JXInputButtonEvent mEvent; final JXInputButtonEvent mEvent;
boolean mLastValueFired = false; boolean mLastValueFired = false;
buttonlistener( JXInputButtonEventListener l, Button button ) buttonlistener( JXInputButtonEventListener l, Button button )
{ {
mListener = l; mListener = l;
mEvent = new JXInputButtonEvent( button ); mEvent = new JXInputButtonEvent( button );
} }
final void checkTrigger() final void checkTrigger()
{ {
boolean curstate = mEvent.getButton().getState(); boolean curstate = mEvent.getButton().getState();
if ( curstate != mLastValueFired ) if ( curstate != mLastValueFired )
{ {
mLastValueFired = curstate; mLastValueFired = curstate;
mListener.changed( mEvent ); mListener.changed( mEvent );
} }
} }
} }
private static class directionallistener private static class directionallistener
{ {
final JXInputDirectionalEventListener mListener; final JXInputDirectionalEventListener mListener;
final double mValueTreshold; final double mValueTreshold;
final JXInputDirectionalEvent mEvent; final JXInputDirectionalEvent mEvent;
double mLastValueFired = 0.0; double mLastValueFired = 0.0;
boolean mLastCenteredFired = true; boolean mLastCenteredFired = true;
int mLastDirectionFired = 0; int mLastDirectionFired = 0;
directionallistener( JXInputDirectionalEventListener l, Directional directional, double valuetreshold ) directionallistener( JXInputDirectionalEventListener l, Directional directional, double valuetreshold )
{ {
mListener = l; mListener = l;
mValueTreshold = valuetreshold; mValueTreshold = valuetreshold;
mEvent = new JXInputDirectionalEvent( directional ); mEvent = new JXInputDirectionalEvent( directional );
} }
final void checkTrigger() final void checkTrigger()
{ {
double curval = mEvent.getDirectional().getValue(); double curval = mEvent.getDirectional().getValue();
int curdir = mEvent.getDirectional().getDirection(); int curdir = mEvent.getDirectional().getDirection();
boolean curctr = mEvent.getDirectional().isCentered(); boolean curctr = mEvent.getDirectional().isCentered();
double delta = curval - mLastValueFired; double delta = curval - mLastValueFired;
int dirdelta = curdir - mLastDirectionFired; int dirdelta = curdir - mLastDirectionFired;
boolean centeredchanged = mLastCenteredFired != curctr; boolean centeredchanged = mLastCenteredFired != curctr;
if ( Math.abs( delta ) >= mValueTreshold if ( Math.abs( delta ) >= mValueTreshold
|| Math.abs( dirdelta ) > 0 || Math.abs( dirdelta ) > 0
|| centeredchanged ) || centeredchanged )
{ {
mLastValueFired = curval; mLastValueFired = curval;
mLastDirectionFired = curdir; mLastDirectionFired = curdir;
mLastCenteredFired = curctr; mLastCenteredFired = curctr;
mEvent.mValueDelta = delta; mEvent.mValueDelta = delta;
mEvent.mDirectionDelta = dirdelta; mEvent.mDirectionDelta = dirdelta;
mListener.changed( mEvent ); mListener.changed( mEvent );
} }
} }
} }
/** /**
* Creates a new instance of JXInputEventManager. * Creates a new instance of JXInputEventManager.
*/ */
private JXInputEventManager() private JXInputEventManager()
{ {
} }
/**
* Remove all listeners at once.
*/
public static void reset()
{
mAxisEventListeners.clear();
mButtonEventListeners.clear();
mDirectionalEventListeners.clear();
}
/**
* Remove all listeners at once.
*/
public static void reset()
{
mAxisEventListeners.clear();
mButtonEventListeners.clear();
mDirectionalEventListeners.clear();
}
/** /**
* Query devices and fire all occuring events. * Query devices and fire all occuring events.
* <code>trigger()</code> is thought to be called by <code>JXInputManager#updateFeatures()</code>. * <code>trigger()</code> is thought to be called by <code>JXInputManager#updateFeatures()</code>.
*/ */
public static void trigger() public static void trigger()
{ {
int n = mAxisEventListeners.size(); int n = mAxisEventListeners.size();
for ( int i = 0; i < n; i++ ) for ( int i = 0; i < n; i++ )
{ {
axislistener l = (axislistener)mAxisEventListeners.get( i ); axislistener l = (axislistener)mAxisEventListeners.get( i );
l.checkTrigger(); l.checkTrigger();
} }
n = mButtonEventListeners.size(); n = mButtonEventListeners.size();
for ( int i = 0; i < n; i++ ) for ( int i = 0; i < n; i++ )
{ {
buttonlistener l = (buttonlistener)mButtonEventListeners.get( i ); buttonlistener l = (buttonlistener)mButtonEventListeners.get( i );
l.checkTrigger(); l.checkTrigger();
} }
n = mDirectionalEventListeners.size(); n = mDirectionalEventListeners.size();
for ( int i = 0; i < n; i++ ) for ( int i = 0; i < n; i++ )
{ {
directionallistener l = (directionallistener)mDirectionalEventListeners.get( i ); directionallistener l = (directionallistener)mDirectionalEventListeners.get( i );
l.checkTrigger(); l.checkTrigger();
} }
} }
private final static class autotrigger extends Thread private final static class autotrigger extends Thread
{ {
boolean mFinish = false; boolean mFinish = false;
final int mDelay; final int mDelay;
autotrigger( int delay ) autotrigger( int delay )
{ {
mDelay = delay; mDelay = delay;
} }
public void run() public void run()
{ {
while ( ! mFinish ) while ( ! mFinish )
{ {
try try
{ {
Thread.sleep( mDelay ); Thread.sleep( mDelay );
JXInputManager.updateFeatures(); JXInputManager.updateFeatures();
} }
catch ( InterruptedException ex ) catch ( InterruptedException ex )
{ {
} }
} }
} }
} }
/** /**
* Set the intervall in ms that is used to check for new values of the features. * Set the intervall in ms that is used to check for new values of the features.
* Set it to <= 0 to prohibit automatic triggering. Events will then only be fired * Set it to <= 0 to prohibit automatic triggering. Events will then only be fired
@@ -212,30 +212,30 @@ public class JXInputEventManager
*/ */
public static void setTriggerIntervall( int ms ) public static void setTriggerIntervall( int ms )
{ {
// //
// Kill current thread, if any // Kill current thread, if any
// //
if ( null != mAutoTrigger ) if ( null != mAutoTrigger )
{ {
mAutoTrigger.mFinish = true; mAutoTrigger.mFinish = true;
try try
{ {
mAutoTrigger.join(); mAutoTrigger.join();
} }
catch ( InterruptedException ex ) catch ( InterruptedException ex )
{ {
} }
} }
mAutoTrigger = null; mAutoTrigger = null;
if ( ms > 0 ) if ( ms > 0 )
{ {
mAutoTrigger = new autotrigger( ms ); mAutoTrigger = new autotrigger( ms );
mAutoTrigger.start(); mAutoTrigger.start();
} }
} }
@@ -245,40 +245,40 @@ public class JXInputEventManager
mAxisEventListeners.add( new JXInputEventManager.axislistener( l, axis, treshold ) ); mAxisEventListeners.add( new JXInputEventManager.axislistener( l, axis, treshold ) );
} }
public static void addListener( JXInputAxisEventListener l, Axis axis ) public static void addListener( JXInputAxisEventListener l, Axis axis )
{ {
mAxisEventListeners.add( new JXInputEventManager.axislistener( l, axis, axis.getResolution() ) ); mAxisEventListeners.add( new JXInputEventManager.axislistener( l, axis, axis.getResolution() ) );
} }
public static void removeListener( JXInputAxisEventListener l ) public static void removeListener( JXInputAxisEventListener l )
{ {
mAxisEventListeners.remove( l ); mAxisEventListeners.remove( l );
} }
public static void addListener( JXInputButtonEventListener l, Button button ) public static void addListener( JXInputButtonEventListener l, Button button )
{ {
mButtonEventListeners.add( new JXInputEventManager.buttonlistener( l, button ) ); mButtonEventListeners.add( new JXInputEventManager.buttonlistener( l, button ) );
} }
public static void removeListener( JXInputButtonEventListener l ) public static void removeListener( JXInputButtonEventListener l )
{ {
mButtonEventListeners.remove( l ); mButtonEventListeners.remove( l );
} }
public static void addListener( JXInputDirectionalEventListener l, Directional directional, double valuetreshold ) public static void addListener( JXInputDirectionalEventListener l, Directional directional, double valuetreshold )
{ {
mDirectionalEventListeners.add( new JXInputEventManager.directionallistener( l, directional, valuetreshold ) ); mDirectionalEventListeners.add( new JXInputEventManager.directionallistener( l, directional, valuetreshold ) );
} }
public static void addListener( JXInputDirectionalEventListener l, Directional directional ) public static void addListener( JXInputDirectionalEventListener l, Directional directional )
{ {
mDirectionalEventListeners.add( new JXInputEventManager.directionallistener( l, directional, directional.getResolution() ) ); mDirectionalEventListeners.add( new JXInputEventManager.directionallistener( l, directional, directional.getResolution() ) );
} }
public static void removeListener( JXInputDirectionalEventListener l ) public static void removeListener( JXInputDirectionalEventListener l )
{ {
mDirectionalEventListeners.remove( l ); mDirectionalEventListeners.remove( l );
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 23. Februar 2002, 14:05 // Created on 23. Februar 2002, 14:05
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.j3d; package de.hardcode.jxinput.j3d;
@@ -18,78 +18,78 @@ import de.hardcode.jxinput.Axis;
*/ */
public class DeviceConfiguration public class DeviceConfiguration
{ {
public final static int AXIS_X = 0; public final static int AXIS_X = 0;
public final static int AXIS_Y = 1; public final static int AXIS_Y = 1;
public final static int AXIS_Z = 2; public final static int AXIS_Z = 2;
private final static class axisvalue private final static class axisvalue
{ {
private final Axis mAxis; private final Axis mAxis;
private final IsActiveCondition mIsActive; private final IsActiveCondition mIsActive;
private final IsActiveCondition mIsIncremental; private final IsActiveCondition mIsIncremental;
private final double mScale; private final double mScale;
private final double mOffset; private final double mOffset;
private double mValue; private double mValue;
axisvalue( Axis axis, IsActiveCondition active, IsActiveCondition incremental, double offset, double scale ) axisvalue( Axis axis, IsActiveCondition active, IsActiveCondition incremental, double offset, double scale )
{ {
mAxis = axis; mAxis = axis;
mIsActive = active; mIsActive = active;
mIsIncremental = incremental; mIsIncremental = incremental;
mValue = mOffset = offset; mValue = mOffset = offset;
mScale = scale; mScale = scale;
} }
double value() double value()
{ {
if ( mIsActive.isActive() ) if ( mIsActive.isActive() )
{ {
double newval = mAxis.getValue() * mScale; double newval = mAxis.getValue() * mScale;
if ( mIsIncremental.isActive() ) if ( mIsIncremental.isActive() )
mValue += newval; mValue += newval;
else else
mValue = newval + mOffset; mValue = newval + mOffset;
} }
return mValue; return mValue;
} }
} }
DeviceConfiguration.axisvalue [] mAxisTrans = new DeviceConfiguration.axisvalue[ 3 ]; DeviceConfiguration.axisvalue [] mAxisTrans = new DeviceConfiguration.axisvalue[ 3 ];
DeviceConfiguration.axisvalue [] mAxisRot = new DeviceConfiguration.axisvalue[ 3 ]; DeviceConfiguration.axisvalue [] mAxisRot = new DeviceConfiguration.axisvalue[ 3 ];
/** /**
* Creates a new instance of DeviceConfiguration. * Creates a new instance of DeviceConfiguration.
*/ */
public DeviceConfiguration() public DeviceConfiguration()
{ {
} }
double getTranslational( int axisid ) double getTranslational( int axisid )
{ {
DeviceConfiguration.axisvalue val = mAxisTrans[ axisid ]; DeviceConfiguration.axisvalue val = mAxisTrans[ axisid ];
return null == val ? 0.0 : val.value(); return null == val ? 0.0 : val.value();
} }
double getRotational( int axisid ) double getRotational( int axisid )
{ {
DeviceConfiguration.axisvalue val = mAxisRot[ axisid ]; DeviceConfiguration.axisvalue val = mAxisRot[ axisid ];
return null == val ? 0.0 : val.value(); return null == val ? 0.0 : val.value();
} }
public void setTranslational( int axisid, Axis axis, IsActiveCondition active, IsActiveCondition incremental, double offset, double scale ) public void setTranslational( int axisid, Axis axis, IsActiveCondition active, IsActiveCondition incremental, double offset, double scale )
{ {
if ( axisid < 0 || axisid > AXIS_Z ) if ( axisid < 0 || axisid > AXIS_Z )
throw new IllegalArgumentException(); throw new IllegalArgumentException();
mAxisTrans[ axisid ] = new DeviceConfiguration.axisvalue( axis, active, incremental, offset, scale ); mAxisTrans[ axisid ] = new DeviceConfiguration.axisvalue( axis, active, incremental, offset, scale );
} }
public void setRotational( int axisid, Axis axis, IsActiveCondition active, IsActiveCondition incremental, double offset, double scale ) public void setRotational( int axisid, Axis axis, IsActiveCondition active, IsActiveCondition incremental, double offset, double scale )
{ {
if ( axisid < 0 || axisid > AXIS_Z ) if ( axisid < 0 || axisid > AXIS_Z )
throw new IllegalArgumentException(); throw new IllegalArgumentException();
mAxisRot[ axisid ] = new DeviceConfiguration.axisvalue( axis, active, incremental, offset, scale ); mAxisRot[ axisid ] = new DeviceConfiguration.axisvalue( axis, active, incremental, offset, scale );
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 25. Februar 2002, 22:41 // Created on 25. Februar 2002, 22:41
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.j3d; package de.hardcode.jxinput.j3d;
@@ -14,12 +14,12 @@ package de.hardcode.jxinput.j3d;
*/ */
public interface IsActiveCondition public interface IsActiveCondition
{ {
public final static IsActiveCondition ALWAYS = IsAlwaysActiveCondition.ALWAYS; public final static IsActiveCondition ALWAYS = IsAlwaysActiveCondition.ALWAYS;
public final static IsActiveCondition NEVER = IsAlwaysActiveCondition.NEVER; public final static IsActiveCondition NEVER = IsAlwaysActiveCondition.NEVER;
/** /**
* Tell wether a certain thing is active. * Tell wether a certain thing is active.
*/ */
boolean isActive(); boolean isActive();
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 25. Februar 2002, 22:43 // Created on 25. Februar 2002, 22:43
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.j3d; package de.hardcode.jxinput.j3d;
@@ -15,25 +15,25 @@ import de.hardcode.jxinput.Button;
* @author Herkules * @author Herkules
*/ */
public class IsActiveOnButtonCondition implements IsActiveCondition public class IsActiveOnButtonCondition implements IsActiveCondition
{ {
private final boolean mActiveState; private final boolean mActiveState;
private final Button mButton; private final Button mButton;
/** /**
* Creates a new instance of IsAlwayActiveCondition. * Creates a new instance of IsAlwayActiveCondition.
*/ */
public IsActiveOnButtonCondition( Button button, boolean activestate ) public IsActiveOnButtonCondition( Button button, boolean activestate )
{ {
mActiveState = activestate; mActiveState = activestate;
mButton = button; mButton = button;
} }
/** /**
* Tell wether a certain thing is active. * Tell wether a certain thing is active.
*/ */
public boolean isActive() public boolean isActive()
{ {
return mButton.getState() == mActiveState; return mButton.getState() == mActiveState;
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 25. Februar 2002, 22:43 // Created on 25. Februar 2002, 22:43
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.j3d; package de.hardcode.jxinput.j3d;
@@ -14,25 +14,25 @@ package de.hardcode.jxinput.j3d;
*/ */
final class IsAlwaysActiveCondition implements IsActiveCondition final class IsAlwaysActiveCondition implements IsActiveCondition
{ {
private final boolean mIsActive; private final boolean mIsActive;
public final static IsActiveCondition ALWAYS = new IsAlwaysActiveCondition( true ); public final static IsActiveCondition ALWAYS = new IsAlwaysActiveCondition( true );
public final static IsActiveCondition NEVER = new IsAlwaysActiveCondition( false ); public final static IsActiveCondition NEVER = new IsAlwaysActiveCondition( false );
/** /**
* Creates a new instance of IsAlwayActiveCondition. * Creates a new instance of IsAlwayActiveCondition.
*/ */
private IsAlwaysActiveCondition(boolean isactive) private IsAlwaysActiveCondition(boolean isactive)
{ {
mIsActive = isactive; mIsActive = isactive;
} }
/** /**
* Tell wether a certain thing is active. * Tell wether a certain thing is active.
*/ */
public boolean isActive() public boolean isActive()
{ {
return mIsActive; return mIsActive;
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 22. Februar 2002, 13:21 // Created on 22. Februar 2002, 13:21
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.j3d; package de.hardcode.jxinput.j3d;
@@ -22,121 +22,121 @@ import de.hardcode.jxinput.JXInputManager;
* @author Herkules * @author Herkules
*/ */
public class J3DInputDevice public class J3DInputDevice
implements InputDevice implements InputDevice
{ {
private Vector3d mPosition = new Vector3d(); private Vector3d mPosition = new Vector3d();
private Transform3D mNewTransform = new Transform3D(); private Transform3D mNewTransform = new Transform3D();
private Transform3D mRotTransX = new Transform3D(); private Transform3D mRotTransX = new Transform3D();
private Transform3D mRotTransY = new Transform3D(); private Transform3D mRotTransY = new Transform3D();
private Transform3D mRotTransZ = new Transform3D(); private Transform3D mRotTransZ = new Transform3D();
private Vector3d mInitPos = new Vector3d( 0.0, 0.0, 0.0 ); private Vector3d mInitPos = new Vector3d( 0.0, 0.0, 0.0 );
private Sensor mSensor = new Sensor( this ); private Sensor mSensor = new Sensor( this );
private SensorRead mSensorRead = new SensorRead(); private SensorRead mSensorRead = new SensorRead();
private DeviceConfiguration mConfig; private DeviceConfiguration mConfig;
/** /**
* Creates a new instance of J3DInputDevice. * Creates a new instance of J3DInputDevice.
*/ */
public J3DInputDevice( DeviceConfiguration config ) public J3DInputDevice( DeviceConfiguration config )
{ {
mConfig = config; mConfig = config;
setNominalPositionAndOrientation(); setNominalPositionAndOrientation();
} }
public void close() public void close()
{ {
// Intentionally empty // Intentionally empty
} }
/** /**
* Retrieve processing mode. * Retrieve processing mode.
* For this device, it always is NON_BLOCKING. * For this device, it always is NON_BLOCKING.
*/ */
public int getProcessingMode() public int getProcessingMode()
{ {
return InputDevice.NON_BLOCKING; return InputDevice.NON_BLOCKING;
} }
/** /**
* Don't care for the index, I only support one sensor. * Don't care for the index, I only support one sensor.
* And I deliver that. * And I deliver that.
*/ */
public Sensor getSensor( int param ) public Sensor getSensor( int param )
{ {
return mSensor; return mSensor;
} }
/** /**
* Tell the world about the only one sensor I support. * Tell the world about the only one sensor I support.
*/ */
public int getSensorCount() public int getSensorCount()
{ {
return 1; return 1;
} }
/** /**
* Well - initialize! * Well - initialize!
* Nothing to do here. * Nothing to do here.
*/ */
public boolean initialize() public boolean initialize()
{ {
return true; return true;
} }
/** /**
* The main update method. * The main update method.
*/ */
public void pollAndProcessInput() public void pollAndProcessInput()
{ {
JXInputManager.updateFeatures(); JXInputManager.updateFeatures();
mSensorRead.setTime( JXInputManager.getLastUpdateTime() ); mSensorRead.setTime( JXInputManager.getLastUpdateTime() );
mRotTransX.rotX( mConfig.getRotational( DeviceConfiguration.AXIS_X ) ); mRotTransX.rotX( mConfig.getRotational( DeviceConfiguration.AXIS_X ) );
mRotTransY.rotY( mConfig.getRotational( DeviceConfiguration.AXIS_Y ) ); mRotTransY.rotY( mConfig.getRotational( DeviceConfiguration.AXIS_Y ) );
mRotTransZ.rotZ( mConfig.getRotational( DeviceConfiguration.AXIS_Z ) ); mRotTransZ.rotZ( mConfig.getRotational( DeviceConfiguration.AXIS_Z ) );
mPosition.set( mPosition.set(
mConfig.getTranslational( DeviceConfiguration.AXIS_X ), mConfig.getTranslational( DeviceConfiguration.AXIS_X ),
mConfig.getTranslational( DeviceConfiguration.AXIS_Y ), mConfig.getTranslational( DeviceConfiguration.AXIS_Y ),
mConfig.getTranslational( DeviceConfiguration.AXIS_Z ) mConfig.getTranslational( DeviceConfiguration.AXIS_Z )
); );
mNewTransform.set( mPosition ); mNewTransform.set( mPosition );
mNewTransform.mul( mRotTransX ); mNewTransform.mul( mRotTransX );
mNewTransform.mul( mRotTransY ); mNewTransform.mul( mRotTransY );
mNewTransform.mul( mRotTransZ ); mNewTransform.mul( mRotTransZ );
mSensorRead.set( mNewTransform ); mSensorRead.set( mNewTransform );
mSensor.setNextSensorRead( mSensorRead ); mSensor.setNextSensorRead( mSensorRead );
} }
/** /**
* Not called by current j3d implementation. * Not called by current j3d implementation.
*/ */
public void processStreamInput() public void processStreamInput()
{ {
// Intentionally empty // Intentionally empty
} }
/** /**
* Reset state. * Reset state.
*/ */
public void setNominalPositionAndOrientation() public void setNominalPositionAndOrientation()
{ {
mSensorRead.setTime( JXInputManager.getLastUpdateTime() ); mSensorRead.setTime( JXInputManager.getLastUpdateTime() );
mRotTransX.rotX( 0.0 ); mRotTransX.rotX( 0.0 );
@@ -153,19 +153,19 @@ public class J3DInputDevice
mSensorRead.set( mNewTransform ); mSensorRead.set( mNewTransform );
mSensor.setNextSensorRead( mSensorRead ); mSensor.setNextSensorRead( mSensorRead );
} }
/** /**
* Set the processing mode. * Set the processing mode.
* Only NON_BLOCKING is allowed! * Only NON_BLOCKING is allowed!
*/ */
public void setProcessingMode(int param) public void setProcessingMode(int param)
{ {
if ( param != InputDevice.NON_BLOCKING ) if ( param != InputDevice.NON_BLOCKING )
throw new IllegalArgumentException("Processing mode must be NON_BLOCKING"); throw new IllegalArgumentException("Processing mode must be NON_BLOCKING");
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 16. April 2002, 23:31 // Created on 16. April 2002, 23:31
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.keyboard; package de.hardcode.jxinput.keyboard;
@@ -14,22 +14,22 @@ package de.hardcode.jxinput.keyboard;
* @author Herkules * @author Herkules
*/ */
public class InvalidKeyCodeException public class InvalidKeyCodeException
extends IllegalArgumentException extends IllegalArgumentException
{ {
/** /**
* Creates a new instance of InvalidKeyCodeException. * Creates a new instance of InvalidKeyCodeException.
*/ */
public InvalidKeyCodeException() public InvalidKeyCodeException()
{ {
} }
/** /**
* Creates a new instance of InvalidKeyCodeException. * Creates a new instance of InvalidKeyCodeException.
*/ */
public InvalidKeyCodeException( String s ) public InvalidKeyCodeException( String s )
{ {
super( s ); super( s );
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 9. April 2002, 22:40 // Created on 9. April 2002, 22:40
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.keyboard; package de.hardcode.jxinput.keyboard;
@@ -19,157 +19,157 @@ import java.awt.Component;
* @author Herkules * @author Herkules
*/ */
public class JXKeyboardInputDevice public class JXKeyboardInputDevice
implements JXInputDevice implements JXInputDevice
{ {
private static final String DEVICENAME = "Swing Keyboard"; private static final String DEVICENAME = "Swing Keyboard";
/** The driver doing all the real work. */ /** The driver doing all the real work. */
private final KeyboardDriver mDriver = new KeyboardDriver(); private final KeyboardDriver mDriver = new KeyboardDriver();
/** The Component I am listening to. */ /** The Component I am listening to. */
private Component mComponent = null; private Component mComponent = null;
/** Hold the biggest keycode for which a button has been created. */ /** Hold the biggest keycode for which a button has been created. */
private int mMaxIdxCreated = 0; private int mMaxIdxCreated = 0;
/** /**
* Creates a new instance of JXKeyboardInputDevice. * Creates a new instance of JXKeyboardInputDevice.
*/ */
public JXKeyboardInputDevice() public JXKeyboardInputDevice()
{ {
} }
/** /**
* Creates a new instance of JXKeyboardInputDevice * Creates a new instance of JXKeyboardInputDevice
* immediately listening to a JComponent. * immediately listening to a JComponent.
*/ */
public JXKeyboardInputDevice( Component comp ) public JXKeyboardInputDevice( Component comp )
{ {
listenTo( comp ); listenTo( comp );
} }
/** /**
* Makes this device listen to a certain JComponent. * Makes this device listen to a certain JComponent.
*/ */
public final void listenTo( Component comp ) public final void listenTo( Component comp )
{ {
shutdown(); shutdown();
mComponent = comp; mComponent = comp;
mComponent.addKeyListener( mDriver ); mComponent.addKeyListener( mDriver );
} }
/** /**
* Shut down. No longer listen to my JComponent. * Shut down. No longer listen to my JComponent.
*/ */
public final void shutdown() public final void shutdown()
{ {
if ( null != mComponent ) if ( null != mComponent )
mComponent.removeKeyListener( mDriver ); mComponent.removeKeyListener( mDriver );
} }
/** /**
* Create a button object for a certain keycode. * Create a button object for a certain keycode.
*/ */
public Button createButton( int keycode ) public Button createButton( int keycode )
{ {
if ( 0 > keycode || 0x100 < keycode ) if ( 0 > keycode || 0x100 < keycode )
throw new InvalidKeyCodeException(); throw new InvalidKeyCodeException();
KeyButton b; KeyButton b;
if ( null == (b = mDriver.getButton( keycode ) ) ) if ( null == (b = mDriver.getButton( keycode ) ) )
{ {
b = new KeyButton( keycode ); b = new KeyButton( keycode );
mDriver.registerKeyButton( b ); mDriver.registerKeyButton( b );
if ( keycode > mMaxIdxCreated ) if ( keycode > mMaxIdxCreated )
mMaxIdxCreated = keycode; mMaxIdxCreated = keycode;
} }
return b; return b;
} }
public void removeButton( Button b ) public void removeButton( Button b )
{ {
mDriver.unregisterKeyButton( (KeyButton) b ); mDriver.unregisterKeyButton( (KeyButton) b );
} }
//********************************************************************************************* //*********************************************************************************************
// //
// Implement JXInputDevice // Implement JXInputDevice
// //
//********************************************************************************************* //*********************************************************************************************
public Axis getAxis(int idx) public Axis getAxis(int idx)
{ {
// No axes on keyboard. // No axes on keyboard.
return null; return null;
} }
public Button getButton(int idx) public Button getButton(int idx)
{ {
// idx is interpreted as the keycode // idx is interpreted as the keycode
return mDriver.getButton( idx ); return mDriver.getButton( idx );
} }
public Directional getDirectional(int idx) public Directional getDirectional(int idx)
{ {
// No directionals on keyboard. // No directionals on keyboard.
return null; return null;
} }
/** Maximum number of axes as an upper bound for index values. */ /** Maximum number of axes as an upper bound for index values. */
public int getMaxNumberOfAxes() public int getMaxNumberOfAxes()
{ {
// No axes on keyboard. // No axes on keyboard.
return 0; return 0;
} }
/** Maximum number of buttons as an upper bound for index values. */ /** Maximum number of buttons as an upper bound for index values. */
public int getMaxNumberOfButtons() public int getMaxNumberOfButtons()
{ {
// Return biggest keycode (inclusive). // Return biggest keycode (inclusive).
return mMaxIdxCreated + 1; return mMaxIdxCreated + 1;
} }
/** Maximum number of directional features as an upper bound for index values. */ /** Maximum number of directional features as an upper bound for index values. */
public int getMaxNumberOfDirectionals() public int getMaxNumberOfDirectionals()
{ {
// No directionals on keyboard. // No directionals on keyboard.
return 0; return 0;
} }
/** /**
* Devices may have a name. * Devices may have a name.
* This name might be provided by a system dependant driver. * This name might be provided by a system dependant driver.
*/ */
public String getName() public String getName()
{ {
return DEVICENAME; return DEVICENAME;
} }
/** Actual number of available axes. */ /** Actual number of available axes. */
public int getNumberOfAxes() public int getNumberOfAxes()
{ {
// No axes on keyboard. // No axes on keyboard.
return 0; return 0;
} }
/** Actual number of available buttons. */ /** Actual number of available buttons. */
public int getNumberOfButtons() public int getNumberOfButtons()
{ {
return mDriver.getNumberOfButtons(); return mDriver.getNumberOfButtons();
} }
/** Actual number of available directional features. */ /** Actual number of available directional features. */
public int getNumberOfDirectionals() public int getNumberOfDirectionals()
{ {
// No directionals on keyboard. // No directionals on keyboard.
return 0; return 0;
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 9. April 2002, 22:51 // Created on 9. April 2002, 22:51
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.keyboard; package de.hardcode.jxinput.keyboard;
@@ -18,77 +18,77 @@ import java.awt.event.KeyEvent;
* @author Herkules * @author Herkules
*/ */
class KeyButton class KeyButton
implements Button implements Button
{ {
private final int mKeyCode; private final int mKeyCode;
private boolean mIsPressed; private boolean mIsPressed;
private boolean mHasChanged; private boolean mHasChanged;
/** /**
* Creates a new instance of KeyButton. * Creates a new instance of KeyButton.
*/ */
public KeyButton( int keycode ) public KeyButton( int keycode )
{ {
mKeyCode = keycode; mKeyCode = keycode;
} }
/** /**
* Return the keycode assigned with this button. * Return the keycode assigned with this button.
*/ */
public final int getKeyCode() public final int getKeyCode()
{ {
return mKeyCode; return mKeyCode;
} }
final void setIsPressed( boolean flag ) final void setIsPressed( boolean flag )
{ {
mIsPressed = flag; mIsPressed = flag;
} }
//********************************************************************************************* //*********************************************************************************************
// //
// Implement Button // Implement Button
// //
//********************************************************************************************* //*********************************************************************************************
/** /**
* Features may have a name provided e.g. by the driver. * Features may have a name provided e.g. by the driver.
*/ */
public String getName() public String getName()
{ {
return KeyEvent.getKeyText( mKeyCode ); return KeyEvent.getKeyText( mKeyCode );
} }
/** /**
* Tells the state of the button at last update. * Tells the state of the button at last update.
*/ */
public boolean getState() public boolean getState()
{ {
return mIsPressed; return mIsPressed;
} }
/** /**
* Retrieve the type of the button. * Retrieve the type of the button.
* Pushbutton will deliver <code>true==getState()</code> as long as they are pressed down. * Pushbutton will deliver <code>true==getState()</code> as long as they are pressed down.
* Togglebuttons will change their state once they are pressed and keep that state * Togglebuttons will change their state once they are pressed and keep that state
* until they are pressed again. * until they are pressed again.
* @return [ PUSHBUTTON | TOGGLEBUTTON ] * @return [ PUSHBUTTON | TOGGLEBUTTON ]
*/ */
public int getType() public int getType()
{ {
return Button.PUSHBUTTON; return Button.PUSHBUTTON;
} }
/** /**
* Denote wether this feature has changed beyond it's resolution since it got last * Denote wether this feature has changed beyond it's resolution since it got last
* updated. * updated.
*/ */
public boolean hasChanged() public boolean hasChanged()
{ {
return true; return true;
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 9. April 2002, 22:43 // Created on 9. April 2002, 22:43
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.keyboard; package de.hardcode.jxinput.keyboard;
@@ -23,119 +23,119 @@ import java.security.InvalidParameterException;
*/ */
class KeyboardDriver implements KeyListener class KeyboardDriver implements KeyListener
{ {
// HashMap mKeysToObserveMap = new HashMap(); // HashMap mKeysToObserveMap = new HashMap();
int mNumberOfKeysObserved = 0; int mNumberOfKeysObserved = 0;
KeyButton [] mKeysObserved = new KeyButton [ 0x100 ]; KeyButton [] mKeysObserved = new KeyButton [ 0x100 ];
/** /**
* Creates a new instance of KeyboardDriver. * Creates a new instance of KeyboardDriver.
*/ */
public KeyboardDriver() public KeyboardDriver()
{ {
} }
/** /**
* How many buttons are registered? * How many buttons are registered?
*/ */
final int getNumberOfButtons() final int getNumberOfButtons()
{ {
return mNumberOfKeysObserved; return mNumberOfKeysObserved;
// return mKeysToObserveMap.size(); // return mKeysToObserveMap.size();
} }
/** /**
* Place a new button under my observation. * Place a new button under my observation.
*/ */
final boolean registerKeyButton( KeyButton b ) final boolean registerKeyButton( KeyButton b )
{ {
final int keycode = b.getKeyCode(); final int keycode = b.getKeyCode();
if ( 0 > keycode || 0x100 < keycode ) if ( 0 > keycode || 0x100 < keycode )
throw new InvalidKeyCodeException(); throw new InvalidKeyCodeException();
if ( null == mKeysObserved[ keycode ] ) if ( null == mKeysObserved[ keycode ] )
{ {
mKeysObserved[ keycode ] = b; mKeysObserved[ keycode ] = b;
mNumberOfKeysObserved++; mNumberOfKeysObserved++;
return true; return true;
} }
else else
{ {
return false; return false;
} }
// Integer code = new Integer( b.getKeyCode() ); // Integer code = new Integer( b.getKeyCode() );
// if ( ! mKeysToObserveMap.containsKey( code ) ) // if ( ! mKeysToObserveMap.containsKey( code ) )
// { // {
// mKeysToObserveMap.put( code, b ); // mKeysToObserveMap.put( code, b );
// return true; // return true;
// } // }
// else // else
// { // {
// return false; // return false;
// } // }
} }
final void unregisterKeyButton( KeyButton b ) final void unregisterKeyButton( KeyButton b )
{ {
final int keycode = b.getKeyCode(); final int keycode = b.getKeyCode();
if ( 0 > keycode || 0x100 < keycode ) if ( 0 > keycode || 0x100 < keycode )
throw new InvalidKeyCodeException(); throw new InvalidKeyCodeException();
if ( null != mKeysObserved[ b.getKeyCode() ] ) if ( null != mKeysObserved[ b.getKeyCode() ] )
{ {
mKeysObserved[ keycode ] = null; mKeysObserved[ keycode ] = null;
mNumberOfKeysObserved--; mNumberOfKeysObserved--;
} }
// Integer code = new Integer( b.getKeyCode() ); // Integer code = new Integer( b.getKeyCode() );
// mKeysToObserveMap.remove( code ); // mKeysToObserveMap.remove( code );
} }
/** /**
* Retrieve the button from its keycode. * Retrieve the button from its keycode.
*/ */
final KeyButton getButton( int keycode ) final KeyButton getButton( int keycode )
{ {
if ( 0 > keycode || 0x100 < keycode ) if ( 0 > keycode || 0x100 < keycode )
throw new InvalidKeyCodeException(); throw new InvalidKeyCodeException();
return mKeysObserved[ keycode ]; return mKeysObserved[ keycode ];
// Integer code = new Integer( keycode ); // Integer code = new Integer( keycode );
// return (KeyButton)mKeysToObserveMap.get( code ); // return (KeyButton)mKeysToObserveMap.get( code );
} }
//********************************************************************************************* //*********************************************************************************************
// //
// Implement KeyListener // Implement KeyListener
// //
//********************************************************************************************* //*********************************************************************************************
public void keyPressed( KeyEvent keyEvent ) public void keyPressed( KeyEvent keyEvent )
{ {
KeyButton b = getButton( keyEvent.getKeyCode() ); KeyButton b = getButton( keyEvent.getKeyCode() );
if ( null != b ) if ( null != b )
b.setIsPressed( true ); b.setIsPressed( true );
} }
public void keyReleased( KeyEvent keyEvent ) public void keyReleased( KeyEvent keyEvent )
{ {
KeyButton b = getButton( keyEvent.getKeyCode() ); KeyButton b = getButton( keyEvent.getKeyCode() );
if ( null != b ) if ( null != b )
b.setIsPressed( false ); b.setIsPressed( false );
} }
public void keyTyped( KeyEvent keyEvent ) public void keyTyped( KeyEvent keyEvent )
{ {
// Intentionally empty. // Intentionally empty.
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 20. Februar 2002, 22:19 // Created on 20. Februar 2002, 22:19
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.test; package de.hardcode.jxinput.test;
@@ -19,21 +19,21 @@ import de.hardcode.jxinput.Axis;
* @author Herkules * @author Herkules
*/ */
public class AxisListener public class AxisListener
implements JXInputAxisEventListener implements JXInputAxisEventListener
{ {
/** /**
* Creates a new instance of AxisListener. * Creates a new instance of AxisListener.
*/ */
public AxisListener( Axis axis ) public AxisListener( Axis axis )
{ {
JXInputEventManager.addListener( this, axis, 0.1 ); JXInputEventManager.addListener( this, axis, 0.1 );
} }
public void changed( JXInputAxisEvent ev ) public void changed( JXInputAxisEvent ev )
{ {
System.out.println( "Axis " + ev.getAxis().getName() + " changed : value=" + ev.getAxis().getValue() + ", event causing delta=" + ev.getDelta() ); System.out.println( "Axis " + ev.getAxis().getName() + " changed : value=" + ev.getAxis().getValue() + ", event causing delta=" + ev.getDelta() );
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 20. Februar 2002, 22:19 // Created on 20. Februar 2002, 22:19
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.test; package de.hardcode.jxinput.test;
@@ -20,19 +20,19 @@ import de.hardcode.jxinput.Button;
*/ */
public class ButtonListener implements JXInputButtonEventListener public class ButtonListener implements JXInputButtonEventListener
{ {
/** /**
* Creates a new instance of AxisListener. * Creates a new instance of AxisListener.
*/ */
public ButtonListener( Button button ) public ButtonListener( Button button )
{ {
JXInputEventManager.addListener( this, button ); JXInputEventManager.addListener( this, button );
} }
public void changed( JXInputButtonEvent ev ) public void changed( JXInputButtonEvent ev )
{ {
System.out.println( "Button " + ev.getButton().getName() + " changed : state=" + ev.getButton().getState() ); System.out.println( "Button " + ev.getButton().getName() + " changed : state=" + ev.getButton().getState() );
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 20. Februar 2002, 22:19 // Created on 20. Februar 2002, 22:19
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.test; package de.hardcode.jxinput.test;
@@ -20,18 +20,18 @@ import de.hardcode.jxinput.Directional;
*/ */
public class DirectionalListener implements JXInputDirectionalEventListener public class DirectionalListener implements JXInputDirectionalEventListener
{ {
/** /**
* Creates a new instance of AxisListener. * Creates a new instance of AxisListener.
*/ */
public DirectionalListener( Directional directional ) public DirectionalListener( Directional directional )
{ {
JXInputEventManager.addListener( this, directional, 1.0 ); JXInputEventManager.addListener( this, directional, 1.0 );
} }
public void changed( JXInputDirectionalEvent ev ) public void changed( JXInputDirectionalEvent ev )
{ {
System.out.println( "Directional " + ev.getDirectional().getName() + " changed : direction=" + ev.getDirectional().getDirection() + ", value=" + ev.getDirectional().getValue() + ", event causing delta=" + ev.getDirectionDelta() ); System.out.println( "Directional " + ev.getDirectional().getName() + " changed : direction=" + ev.getDirectional().getDirection() + ", value=" + ev.getDirectional().getValue() + ", event causing delta=" + ev.getDirectionDelta() );
} }
} }

View File

@@ -28,34 +28,34 @@ public class JXInputDevicePanel extends javax.swing.JPanel
{ {
private static final Font AXIS_SLIDER_FONT = new Font( "Verdana", Font.PLAIN, 9 ); private static final Font AXIS_SLIDER_FONT = new Font( "Verdana", Font.PLAIN, 9 );
private final JXInputDevice mDev; private final JXInputDevice mDev;
private final ArrayList mAxisSliders = new ArrayList(); private final ArrayList mAxisSliders = new ArrayList();
private final ArrayList mButtonCheckboxes = new ArrayList(); private final ArrayList mButtonCheckboxes = new ArrayList();
private final ArrayList mDirectionalLabels = new ArrayList(); private final ArrayList mDirectionalLabels = new ArrayList();
/** Creates new form JXInputDevicePanel */ /** Creates new form JXInputDevicePanel */
public JXInputDevicePanel( JXInputDevice dev ) public JXInputDevicePanel( JXInputDevice dev )
{ {
mDev = dev; mDev = dev;
initComponents(); initComponents();
initFromDevice(); initFromDevice();
} }
/** /**
* Helper class connecting a JSlider with an Axis. * Helper class connecting a JSlider with an Axis.
*/ */
private class AxisSlider extends JSlider private class AxisSlider extends JSlider
{ {
Axis mAxis; Axis mAxis;
AxisSlider( Axis axis ) AxisSlider( Axis axis )
{ {
super( ( Axis.SLIDER == axis.getType() ? 0 : -100 ), 100 ); super( ( Axis.SLIDER == axis.getType() ? 0 : -100 ), 100 );
this.setMajorTickSpacing( Axis.SLIDER == axis.getType() ? 25 : 50 ); this.setMajorTickSpacing( Axis.SLIDER == axis.getType() ? 25 : 50 );
this.setMinorTickSpacing( 5 ); this.setMinorTickSpacing( 5 );
this.setPaintTicks( true ); this.setPaintTicks( true );
this.setPaintLabels( true ); this.setPaintLabels( true );
this.setEnabled( false ); this.setEnabled( false );
Dictionary labeldict = this.getLabelTable(); Dictionary labeldict = this.getLabelTable();
Enumeration labels = labeldict.elements(); Enumeration labels = labeldict.elements();
@@ -67,166 +67,166 @@ public class JXInputDevicePanel extends javax.swing.JPanel
label.setHorizontalAlignment( SwingConstants.LEFT ); label.setHorizontalAlignment( SwingConstants.LEFT );
} }
mAxis = axis; mAxis = axis;
} }
void update() void update()
{ {
int ax = (int)(mAxis.getValue() * 100.0); int ax = (int)(mAxis.getValue() * 100.0);
// //
// Only if value really changes // Only if value really changes
// //
if ( ax != this.getValue() ) if ( ax != this.getValue() )
{ {
this.setValue( ax ); this.setValue( ax );
this.setToolTipText( mAxis.getName() + ": " + Double.toString( mAxis.getValue() ) ); this.setToolTipText( mAxis.getName() + ": " + Double.toString( mAxis.getValue() ) );
} }
} }
} }
private class ButtonCheckbox extends JCheckBox
{
Button mButton;
ButtonCheckbox( Button button )
{
super( button.getName() );
this.setEnabled( false );
mButton = button;
}
void update()
{
boolean state = mButton.getState();
//
// Only if value really changes
//
if ( state != this.isSelected() )
{
this.setSelected( state );
}
}
}
private class DirectionalLabel extends JLabel
{
Directional mDirectional;
int mCurrent = 0;
DirectionalLabel( Directional directional )
{
super( directional.getName() );
mDirectional = directional;
}
void update()
{
int dir = mDirectional.getDirection();
//
// Only if value really changes
//
if ( dir != mCurrent )
{
this.setText( mDirectional.getName() + ": " + ( mDirectional.isCentered() ? "-" : Integer.toString( dir ) ) );
mCurrent = dir;
}
}
}
/** private class ButtonCheckbox extends JCheckBox
* Setup the dialogs content from the JXInputDevice. {
*/ Button mButton;
void initFromDevice() ButtonCheckbox( Button button )
{ {
if ( null != mDev ) super( button.getName() );
{ this.setEnabled( false );
((GridLayout)mAxesPanel.getLayout()).setRows( mDev.getNumberOfAxes() ); mButton = button;
}
for ( int i = 0; i < mDev.getMaxNumberOfAxes(); ++i )
{ void update()
if ( null != mDev.getAxis( i ) ) {
{ boolean state = mButton.getState();
AxisSlider slider = new AxisSlider( mDev.getAxis( i ) );
//
// Only if value really changes
//
if ( state != this.isSelected() )
{
this.setSelected( state );
}
}
}
private class DirectionalLabel extends JLabel
{
Directional mDirectional;
int mCurrent = 0;
DirectionalLabel( Directional directional )
{
super( directional.getName() );
mDirectional = directional;
}
void update()
{
int dir = mDirectional.getDirection();
//
// Only if value really changes
//
if ( dir != mCurrent )
{
this.setText( mDirectional.getName() + ": " + ( mDirectional.isCentered() ? "-" : Integer.toString( dir ) ) );
mCurrent = dir;
}
}
}
/**
* Setup the dialogs content from the JXInputDevice.
*/
void initFromDevice()
{
if ( null != mDev )
{
((GridLayout)mAxesPanel.getLayout()).setRows( mDev.getNumberOfAxes() );
for ( int i = 0; i < mDev.getMaxNumberOfAxes(); ++i )
{
if ( null != mDev.getAxis( i ) )
{
AxisSlider slider = new AxisSlider( mDev.getAxis( i ) );
JLabel name = new JLabel( mDev.getAxis( i ).getName() ); JLabel name = new JLabel( mDev.getAxis( i ).getName() );
name.setVerticalAlignment( SwingConstants.TOP ); name.setVerticalAlignment( SwingConstants.TOP );
name.setHorizontalAlignment( SwingConstants.CENTER ); name.setHorizontalAlignment( SwingConstants.CENTER );
name.setPreferredSize( new java.awt.Dimension( 90, 0 ) ); name.setPreferredSize( new java.awt.Dimension( 90, 0 ) );
JPanel p = new JPanel(); JPanel p = new JPanel();
p.setLayout( new BorderLayout() ); p.setLayout( new BorderLayout() );
p.add( name, BorderLayout.WEST ); p.add( name, BorderLayout.WEST );
p.add( slider, BorderLayout.CENTER ); p.add( slider, BorderLayout.CENTER );
mAxesPanel.add( p ); mAxesPanel.add( p );
// Add to list of all AxisSlider controls // Add to list of all AxisSlider controls
mAxisSliders.add( slider ); mAxisSliders.add( slider );
// Add an event listener: // Add an event listener:
new AxisListener( mDev.getAxis( i ) ); new AxisListener( mDev.getAxis( i ) );
} }
} }
((GridLayout)mButtonsPanel.getLayout()).setRows( mDev.getNumberOfButtons() ); ((GridLayout)mButtonsPanel.getLayout()).setRows( mDev.getNumberOfButtons() );
for ( int i = 0; i < mDev.getMaxNumberOfButtons(); ++i ) for ( int i = 0; i < mDev.getMaxNumberOfButtons(); ++i )
{ {
if ( null != mDev.getButton( i ) ) if ( null != mDev.getButton( i ) )
{ {
ButtonCheckbox chk = new ButtonCheckbox( mDev.getButton( i ) ); ButtonCheckbox chk = new ButtonCheckbox( mDev.getButton( i ) );
mButtonCheckboxes.add( chk ); mButtonCheckboxes.add( chk );
mButtonsPanel.add( chk ); mButtonsPanel.add( chk );
// Add an event listener: // Add an event listener:
new ButtonListener( mDev.getButton( i ) ); new ButtonListener( mDev.getButton( i ) );
} }
} }
((GridLayout)mDirectionalPanel.getLayout()).setRows( mDev.getNumberOfDirectionals() / 2 ); ((GridLayout)mDirectionalPanel.getLayout()).setRows( mDev.getNumberOfDirectionals() / 2 );
for ( int i = 0; i < mDev.getMaxNumberOfDirectionals(); ++i ) for ( int i = 0; i < mDev.getMaxNumberOfDirectionals(); ++i )
{ {
if ( null != mDev.getDirectional( i ) ) if ( null != mDev.getDirectional( i ) )
{ {
DirectionalLabel lbl = new DirectionalLabel( mDev.getDirectional( i ) ); DirectionalLabel lbl = new DirectionalLabel( mDev.getDirectional( i ) );
mDirectionalLabels.add( lbl ); mDirectionalLabels.add( lbl );
mDirectionalPanel.add( lbl ); mDirectionalPanel.add( lbl );
// Add an event listener: // Add an event listener:
new DirectionalListener( mDev.getDirectional( i ) ); new DirectionalListener( mDev.getDirectional( i ) );
} }
} }
} }
} }
public void update() public void update()
{ {
Iterator it = mAxisSliders.iterator(); Iterator it = mAxisSliders.iterator();
while ( it.hasNext() ) while ( it.hasNext() )
{ {
((AxisSlider)it.next()).update(); ((AxisSlider)it.next()).update();
} }
it = mButtonCheckboxes.iterator(); it = mButtonCheckboxes.iterator();
while ( it.hasNext() ) while ( it.hasNext() )
{ {
((ButtonCheckbox)it.next()).update(); ((ButtonCheckbox)it.next()).update();
} }
it = mDirectionalLabels.iterator(); it = mDirectionalLabels.iterator();
while ( it.hasNext() ) while ( it.hasNext() )
{ {
((DirectionalLabel)it.next()).update(); ((DirectionalLabel)it.next()).update();
} }
} }
/** This method is called from within the constructor to /** This method is called from within the constructor to
@@ -276,12 +276,12 @@ public class JXInputDevicePanel extends javax.swing.JPanel
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void OnShow(java.awt.event.ComponentEvent evt)//GEN-FIRST:event_OnShow private void OnShow(java.awt.event.ComponentEvent evt)//GEN-FIRST:event_OnShow
{//GEN-HEADEREND:event_OnShow {//GEN-HEADEREND:event_OnShow
// Commented: the focus is held by a parent component // Commented: the focus is held by a parent component
// System.out.println("OnShow"); // System.out.println("OnShow");
// this.requestFocus(); // this.requestFocus();
}//GEN-LAST:event_OnShow }//GEN-LAST:event_OnShow

View File

@@ -22,143 +22,143 @@ import java.awt.event.KeyEvent;
* @author Herkules * @author Herkules
*/ */
public class JXInputTestDialog extends javax.swing.JDialog public class JXInputTestDialog extends javax.swing.JDialog
implements ActionListener implements ActionListener
{ {
private JXKeyboardInputDevice mKeyboardDevice = null; private JXKeyboardInputDevice mKeyboardDevice = null;
private JXVirtualInputDevice mVirtualDevice = null; private JXVirtualInputDevice mVirtualDevice = null;
Button mButtonUp; Button mButtonUp;
Button mButtonDown; Button mButtonDown;
Button mButtonLeft; Button mButtonLeft;
Button mButtonRight; Button mButtonRight;
Button mButtonFire; Button mButtonFire;
Button mButtonSpace; Button mButtonSpace;
/** Creates new form JXInputTestDialog */ /** Creates new form JXInputTestDialog */
public JXInputTestDialog(java.awt.Frame parent, boolean modal) public JXInputTestDialog(java.awt.Frame parent, boolean modal)
{ {
super(parent, modal); super(parent, modal);
initComponents(); initComponents();
configureKeyboardInputDevice(); configureKeyboardInputDevice();
configureVirtualInputDevice(); configureVirtualInputDevice();
initDevicePanels(); initDevicePanels();
pack(); pack();
// Request the focus so that the keyboarddevice can work // Request the focus so that the keyboarddevice can work
mMainPanel.requestFocus(); mMainPanel.requestFocus();
new Timer( 50, this ).start(); new Timer( 50, this ).start();
// Uncomment this line as an alternative to the Timer above. // Uncomment this line as an alternative to the Timer above.
// Don't use both!! // Don't use both!!
//JXInputEventManager.setTriggerIntervall( 50 ); //JXInputEventManager.setTriggerIntervall( 50 );
} }
/** /**
* Implement ActionListener#actionPerformed(). * Implement ActionListener#actionPerformed().
* This is called by the Timer. * This is called by the Timer.
*/ */
public void actionPerformed( ActionEvent e ) public void actionPerformed( ActionEvent e )
{ {
JXInputManager.updateFeatures(); JXInputManager.updateFeatures();
SwingUtilities.invokeLater( SwingUtilities.invokeLater(
new Runnable() new Runnable()
{ {
public void run() public void run()
{ {
for ( int i = 0; i < mDevicesTabbedPane.getComponentCount(); ++i ) for ( int i = 0; i < mDevicesTabbedPane.getComponentCount(); ++i )
{ {
((JXInputDevicePanel)mDevicesTabbedPane.getComponent( i )).update(); ((JXInputDevicePanel)mDevicesTabbedPane.getComponent( i )).update();
} }
} }
} }
); );
} }
/** /**
* Configure a test JXKeyboardInputdevice. * Configure a test JXKeyboardInputdevice.
*/ */
void configureKeyboardInputDevice() void configureKeyboardInputDevice()
{ {
mKeyboardDevice = JXInputManager.createKeyboardDevice(); mKeyboardDevice = JXInputManager.createKeyboardDevice();
mKeyboardDevice.createButton( KeyEvent.VK_ESCAPE );
mKeyboardDevice.createButton( KeyEvent.VK_F1 );
mKeyboardDevice.createButton( KeyEvent.VK_F2 );
mKeyboardDevice.createButton( KeyEvent.VK_F3 );
mKeyboardDevice.createButton( KeyEvent.VK_F4 );
mKeyboardDevice.createButton( KeyEvent.VK_LEFT );
mKeyboardDevice.createButton( KeyEvent.VK_RIGHT );
mKeyboardDevice.createButton( KeyEvent.VK_UP );
mKeyboardDevice.createButton( KeyEvent.VK_DOWN );
mKeyboardDevice.createButton( KeyEvent.VK_PAGE_UP );
mKeyboardDevice.createButton( KeyEvent.VK_PAGE_DOWN );
mButtonSpace = mKeyboardDevice.createButton( KeyEvent.VK_SPACE );
mButtonLeft = mKeyboardDevice.createButton( KeyEvent.VK_A );
mButtonRight = mKeyboardDevice.createButton( KeyEvent.VK_D );
mButtonDown = mKeyboardDevice.createButton( KeyEvent.VK_S );
mButtonUp = mKeyboardDevice.createButton( KeyEvent.VK_W );
// Configure it to make it listen to the main panel.
// I try to keep the kbd focus on it.
mKeyboardDevice.listenTo( mMainPanel );
}
/**
* Configure a test JXVirtualInputdevice.
*/
void configureVirtualInputDevice()
{
mVirtualDevice = JXInputManager.createVirtualDevice();
Button firebutton;
//
// Remember 'fire' button of first device for use
// in the virtual device.
// For we ran configureKeyboardInputDevice() before,
// getJXInputDevice( 0 ) should not return null
//
firebutton = JXInputManager.getJXInputDevice( 0 ).getButton( 0 );
VirtualAxis x = mVirtualDevice.createAxis( Axis.ID_X );
x.setButtons( mButtonRight, mButtonLeft );
x.setName( "x: A-D" );
VirtualAxis y = mVirtualDevice.createAxis( Axis.ID_Y );
y.setButtons( mButtonUp, mButtonDown );
y.setSpringSpeed( 0.0 );
y.setName( "y: S|W" );
VirtualAxis slider = mVirtualDevice.createAxis( Axis.ID_SLIDER0 );
slider.setIncreaseButton( mButtonSpace );
slider.setTimeFor0To1( 2000 );
slider.setName( "<space>" );
slider.setType( Axis.SLIDER );
if ( null != firebutton ) mKeyboardDevice.createButton( KeyEvent.VK_ESCAPE );
{
slider = mVirtualDevice.createAxis( Axis.ID_SLIDER1 );
slider.setIncreaseButton( firebutton );
slider.setTimeFor0To1( 2000 );
slider.setName( "JoyButton 0" );
}
mKeyboardDevice.createButton( KeyEvent.VK_F1 );
} mKeyboardDevice.createButton( KeyEvent.VK_F2 );
mKeyboardDevice.createButton( KeyEvent.VK_F3 );
mKeyboardDevice.createButton( KeyEvent.VK_F4 );
/**
* Initialize one panel for each device available. mKeyboardDevice.createButton( KeyEvent.VK_LEFT );
*/ mKeyboardDevice.createButton( KeyEvent.VK_RIGHT );
void initDevicePanels() mKeyboardDevice.createButton( KeyEvent.VK_UP );
mKeyboardDevice.createButton( KeyEvent.VK_DOWN );
mKeyboardDevice.createButton( KeyEvent.VK_PAGE_UP );
mKeyboardDevice.createButton( KeyEvent.VK_PAGE_DOWN );
mButtonSpace = mKeyboardDevice.createButton( KeyEvent.VK_SPACE );
mButtonLeft = mKeyboardDevice.createButton( KeyEvent.VK_A );
mButtonRight = mKeyboardDevice.createButton( KeyEvent.VK_D );
mButtonDown = mKeyboardDevice.createButton( KeyEvent.VK_S );
mButtonUp = mKeyboardDevice.createButton( KeyEvent.VK_W );
// Configure it to make it listen to the main panel.
// I try to keep the kbd focus on it.
mKeyboardDevice.listenTo( mMainPanel );
}
/**
* Configure a test JXVirtualInputdevice.
*/
void configureVirtualInputDevice()
{
mVirtualDevice = JXInputManager.createVirtualDevice();
Button firebutton;
//
// Remember 'fire' button of first device for use
// in the virtual device.
// For we ran configureKeyboardInputDevice() before,
// getJXInputDevice( 0 ) should not return null
//
firebutton = JXInputManager.getJXInputDevice( 0 ).getButton( 0 );
VirtualAxis x = mVirtualDevice.createAxis( Axis.ID_X );
x.setButtons( mButtonRight, mButtonLeft );
x.setName( "x: A-D" );
VirtualAxis y = mVirtualDevice.createAxis( Axis.ID_Y );
y.setButtons( mButtonUp, mButtonDown );
y.setSpringSpeed( 0.0 );
y.setName( "y: S|W" );
VirtualAxis slider = mVirtualDevice.createAxis( Axis.ID_SLIDER0 );
slider.setIncreaseButton( mButtonSpace );
slider.setTimeFor0To1( 2000 );
slider.setName( "<space>" );
slider.setType( Axis.SLIDER );
if ( null != firebutton )
{
slider = mVirtualDevice.createAxis( Axis.ID_SLIDER1 );
slider.setIncreaseButton( firebutton );
slider.setTimeFor0To1( 2000 );
slider.setName( "JoyButton 0" );
}
}
/**
* Initialize one panel for each device available.
*/
void initDevicePanels()
{ {
int cnt = JXInputManager.getNumberOfDevices(); int cnt = JXInputManager.getNumberOfDevices();
@@ -167,25 +167,25 @@ public class JXInputTestDialog extends javax.swing.JDialog
for ( int i = 0; i < cnt; ++i ) for ( int i = 0; i < cnt; ++i )
{ {
JXInputDevice dev = JXInputManager.getJXInputDevice( i ); JXInputDevice dev = JXInputManager.getJXInputDevice( i );
if ( null != dev ) if ( null != dev )
{ {
// //
// Setup an own panel for each device. // Setup an own panel for each device.
// //
JPanel panel = new JXInputDevicePanel( dev ); JPanel panel = new JXInputDevicePanel( dev );
mDevicesTabbedPane.addTab( dev.getName(), panel ); mDevicesTabbedPane.addTab( dev.getName(), panel );
} }
} }
} }
/** This method is called from within the constructor to /** This method is called from within the constructor to
* initialize the form. * initialize the form.
* WARNING: Do NOT modify this code. The content of this method is * WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor. * always regenerated by the Form Editor.
*/ */
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() private void initComponents()
{ {
@@ -243,44 +243,44 @@ public class JXInputTestDialog extends javax.swing.JDialog
this.mDevicesTabbedPane.removeTabAt( 0 ); this.mDevicesTabbedPane.removeTabAt( 0 );
JXInputManager.reset(); JXInputManager.reset();
configureKeyboardInputDevice(); configureKeyboardInputDevice();
configureVirtualInputDevice(); configureVirtualInputDevice();
initDevicePanels(); initDevicePanels();
pack(); pack();
// Request the focus so that the keyboarddevice can work // Request the focus so that the keyboarddevice can work
mMainPanel.requestFocus(); mMainPanel.requestFocus();
}//GEN-LAST:event_mButtonResetActionPerformed }//GEN-LAST:event_mButtonResetActionPerformed
private void mDevicesTabbedPaneFocusGained(java.awt.event.FocusEvent evt)//GEN-FIRST:event_mDevicesTabbedPaneFocusGained private void mDevicesTabbedPaneFocusGained(java.awt.event.FocusEvent evt)//GEN-FIRST:event_mDevicesTabbedPaneFocusGained
{//GEN-HEADEREND:event_mDevicesTabbedPaneFocusGained {//GEN-HEADEREND:event_mDevicesTabbedPaneFocusGained
// Switch focus back to main panel! // Switch focus back to main panel!
this.mMainPanel.requestFocus(); this.mMainPanel.requestFocus();
}//GEN-LAST:event_mDevicesTabbedPaneFocusGained }//GEN-LAST:event_mDevicesTabbedPaneFocusGained
/** Closes the dialog */ /** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
setVisible(false); setVisible(false);
dispose(); dispose();
System.exit( 0 ); System.exit( 0 );
}//GEN-LAST:event_closeDialog }//GEN-LAST:event_closeDialog
/** /**
* Allow the dialog to run standalone. * Allow the dialog to run standalone.
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String args[]) public static void main(String args[])
{ {
new JXInputTestDialog(new javax.swing.JFrame(), true).setVisible(true); new JXInputTestDialog(new javax.swing.JFrame(), true).setVisible(true);
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton mButtonReset; private javax.swing.JButton mButtonReset;
private javax.swing.JTabbedPane mDevicesTabbedPane; private javax.swing.JTabbedPane mDevicesTabbedPane;
private javax.swing.JLabel mLabelNoDevice; private javax.swing.JLabel mLabelNoDevice;
private javax.swing.JPanel mMainPanel; private javax.swing.JPanel mMainPanel;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 17. April 2002, 23:24 // Created on 17. April 2002, 23:24
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.util; package de.hardcode.jxinput.util;
@@ -16,62 +16,62 @@ import de.hardcode.jxinput.Axis;
*/ */
public class LatestChangedValueAxis implements Axis public class LatestChangedValueAxis implements Axis
{ {
private final Axis mAxis1; private final Axis mAxis1;
private final Axis mAxis2; private final Axis mAxis2;
private Axis mAxisInUse; private Axis mAxisInUse;
private double mSaved1; private double mSaved1;
private double mSaved2; private double mSaved2;
/** /**
* Creates a new instance of MeanValueAxis. * Creates a new instance of MeanValueAxis.
*/ */
public LatestChangedValueAxis(Axis a1, Axis a2) public LatestChangedValueAxis(Axis a1, Axis a2)
{ {
mAxis1 = a1; mAxis1 = a1;
mAxis2 = a2; mAxis2 = a2;
mAxisInUse = a1; mAxisInUse = a1;
mSaved1 = a1.getValue(); mSaved1 = a1.getValue();
mSaved2 = a2.getValue(); mSaved2 = a2.getValue();
} }
/** /**
* Features may have a name provided e.g. by the driver. * Features may have a name provided e.g. by the driver.
*/ */
public String getName() public String getName()
{ {
return mAxis1.getName(); return mAxis1.getName();
} }
/** Inform about the resolution of the axis. /** Inform about the resolution of the axis.
* *
* @return resolution, e.g. 2^-16 * @return resolution, e.g. 2^-16
*/ */
public double getResolution() public double getResolution()
{ {
return mAxis1.getResolution(); return mAxis1.getResolution();
} }
/** /**
* Retrieve the type of the axis. * Retrieve the type of the axis.
* *
* @return [ TRANSLATION | ROTATION | SLIDER ] * @return [ TRANSLATION | ROTATION | SLIDER ]
*/ */
public int getType() public int getType()
{ {
return mAxis1.getType(); return mAxis1.getType();
} }
/** Returns the current value of the axis. /** Returns the current value of the axis.
* The range of the result depends on the axis type. * The range of the result depends on the axis type.
*s *s
* @return value [-1.0,1.0] or [0.0,1.0] * @return value [-1.0,1.0] or [0.0,1.0]
*/ */
public double getValue() public double getValue()
{ {
double v1 = mAxis1.getValue(); double v1 = mAxis1.getValue();
double v2 = mAxis2.getValue(); double v2 = mAxis2.getValue();
if ( Math.abs( v2 - mSaved2 ) > 0.2 ) if ( Math.abs( v2 - mSaved2 ) > 0.2 )
{ {
@@ -85,14 +85,14 @@ public class LatestChangedValueAxis implements Axis
} }
return mAxisInUse.getValue(); return mAxisInUse.getValue();
} }
/** Denote wether this feature has changed beyond it's resolution since it got last /** Denote wether this feature has changed beyond it's resolution since it got last
* updated. * updated.
*/ */
public boolean hasChanged() public boolean hasChanged()
{ {
return true; return true;
} }
} }

View File

@@ -1,8 +1,8 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 23. Dezember 2002, 19:21 // Created on 23. Dezember 2002, 19:21
//********************************************************************************************** //**********************************************************************************************

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 9. April 2002, 22:40 // Created on 9. April 2002, 22:40
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.virtual; package de.hardcode.jxinput.virtual;
@@ -19,122 +19,122 @@ import de.hardcode.jxinput.*;
*/ */
public class JXVirtualInputDevice implements JXInputDevice public class JXVirtualInputDevice implements JXInputDevice
{ {
private static final String DEVICENAME = "Virtual Device"; private static final String DEVICENAME = "Virtual Device";
/** The driver doing all the real work. */ /** The driver doing all the real work. */
private final VirtualDriver mDriver = new VirtualDriver(); private final VirtualDriver mDriver = new VirtualDriver();
/** /**
* Creates a new instance of JXKeyboardInputDevice. * Creates a new instance of JXKeyboardInputDevice.
*/ */
public JXVirtualInputDevice() public JXVirtualInputDevice()
{ {
} }
/** /**
* The virtual input device needs to be updated regularly. * The virtual input device needs to be updated regularly.
*/ */
public final void update( long deltaT ) public final void update( long deltaT )
{ {
// //
// Delegate the update call to the driver. // Delegate the update call to the driver.
// //
mDriver.update( deltaT ); mDriver.update( deltaT );
} }
/** /**
* Create a virtual axis object with a certain ID, e.g. Axis.ID_X. * Create a virtual axis object with a certain ID, e.g. Axis.ID_X.
*/ */
public VirtualAxis createAxis( int id ) public VirtualAxis createAxis( int id )
{ {
VirtualAxis a; VirtualAxis a;
a = new VirtualAxis( id ); a = new VirtualAxis( id );
mDriver.registerVirtualAxis( id, a ); mDriver.registerVirtualAxis( id, a );
return a; return a;
} }
public void removeAxis( VirtualAxis a ) public void removeAxis( VirtualAxis a )
{ {
mDriver.unregisterVirtualAxis( a ); mDriver.unregisterVirtualAxis( a );
} }
//********************************************************************************************* //*********************************************************************************************
// //
// Implement JXInputDevice // Implement JXInputDevice
// //
//********************************************************************************************* //*********************************************************************************************
public Axis getAxis(int idx) public Axis getAxis(int idx)
{ {
return mDriver.getAxis( idx ); return mDriver.getAxis( idx );
} }
public Button getButton(int idx) public Button getButton(int idx)
{ {
// No virtual buttons. // No virtual buttons.
return null; return null;
} }
public Directional getDirectional(int idx) public Directional getDirectional(int idx)
{ {
// No virtual directionals. // No virtual directionals.
return null; return null;
} }
/** Maximum number of axes as an upper bound for index values. */ /** Maximum number of axes as an upper bound for index values. */
public int getMaxNumberOfAxes() public int getMaxNumberOfAxes()
{ {
return Axis.NUMBER_OF_ID; return Axis.NUMBER_OF_ID;
} }
/** Maximum number of buttons as an upper bound for index values. */ /** Maximum number of buttons as an upper bound for index values. */
public int getMaxNumberOfButtons() public int getMaxNumberOfButtons()
{ {
// No virtual buttons. // No virtual buttons.
return 0; return 0;
} }
/** Maximum number of directional features as an upper bound for index values. */ /** Maximum number of directional features as an upper bound for index values. */
public int getMaxNumberOfDirectionals() public int getMaxNumberOfDirectionals()
{ {
// No virtual directionals. // No virtual directionals.
return 0; return 0;
} }
/** /**
* Devices may have a name. * Devices may have a name.
* This name might be provided by a system dependant driver. * This name might be provided by a system dependant driver.
*/ */
public String getName() public String getName()
{ {
return DEVICENAME; return DEVICENAME;
} }
/** Actual number of available axes. */ /** Actual number of available axes. */
public int getNumberOfAxes() public int getNumberOfAxes()
{ {
// No axes on keyboard. // No axes on keyboard.
return mDriver.getNumberOfAxes(); return mDriver.getNumberOfAxes();
} }
/** Actual number of available buttons. */ /** Actual number of available buttons. */
public int getNumberOfButtons() public int getNumberOfButtons()
{ {
return 0; return 0;
} }
/** Actual number of available directional features. */ /** Actual number of available directional features. */
public int getNumberOfDirectionals() public int getNumberOfDirectionals()
{ {
// No directionals on keyboard. // No directionals on keyboard.
return 0; return 0;
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 11. April 2002, 23:40 // Created on 11. April 2002, 23:40
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.virtual; package de.hardcode.jxinput.virtual;
@@ -17,191 +17,191 @@ import java.security.InvalidParameterException;
* @author J<>rg Plewe * @author J<>rg Plewe
*/ */
public class VirtualAxis public class VirtualAxis
implements Axis implements Axis
{ {
private int mType = Axis.TRANSLATION; private int mType = Axis.TRANSLATION;
private final int mID; private final int mID;
private String mName = "VirtualAxis"; private String mName = "VirtualAxis";
private double mCurrentValue = 0; private double mCurrentValue = 0;
private Button mButtonIncrease = null; private Button mButtonIncrease = null;
private Button mButtonDecrease = null; private Button mButtonDecrease = null;
private double mSpeed = 1.0 / 500.0; private double mSpeed = 1.0 / 500.0;
private double mSpringSpeed = 1.0 / 500.0; private double mSpringSpeed = 1.0 / 500.0;
/** /**
* Creates a new instance of VirtualAxis. * Creates a new instance of VirtualAxis.
*/ */
public VirtualAxis( int id ) public VirtualAxis( int id )
{ {
mID = id; mID = id;
} }
/** /**
* Set the type of this axis to be either <code>Axis.ROTATION</code>, * Set the type of this axis to be either <code>Axis.ROTATION</code>,
* <code>Axis.TRANSLATION</code> or <code>Axis.SLIDER</code>. * <code>Axis.TRANSLATION</code> or <code>Axis.SLIDER</code>.
*/ */
public void setType( int type ) public void setType( int type )
{ {
if ( Axis.ROTATION != type if ( Axis.ROTATION != type
&& Axis.TRANSLATION != type && Axis.TRANSLATION != type
&& Axis.SLIDER != type && Axis.SLIDER != type
) )
throw new InvalidParameterException( "Invalid type for axis!" ); throw new InvalidParameterException( "Invalid type for axis!" );
mType = type; mType = type;
} }
/** /**
* Update features under my control. * Update features under my control.
*/ */
final void update( long deltaT ) final void update( long deltaT )
{ {
double change = mSpeed * deltaT; double change = mSpeed * deltaT;
double springchange = mSpringSpeed * deltaT; double springchange = mSpringSpeed * deltaT;
boolean doincrease = ( null != mButtonIncrease && mButtonIncrease.getState() ); boolean doincrease = ( null != mButtonIncrease && mButtonIncrease.getState() );
boolean dodecrease = ( null != mButtonDecrease && mButtonDecrease.getState() ); boolean dodecrease = ( null != mButtonDecrease && mButtonDecrease.getState() );
boolean iscontrolled = doincrease || dodecrease; boolean iscontrolled = doincrease || dodecrease;
double controlledchange = 0.0; double controlledchange = 0.0;
if ( doincrease ) if ( doincrease )
controlledchange += change; controlledchange += change;
if ( dodecrease ) if ( dodecrease )
controlledchange -= change; controlledchange -= change;
mCurrentValue += controlledchange; mCurrentValue += controlledchange;
if ( mCurrentValue > 0.0 && ! doincrease ) if ( mCurrentValue > 0.0 && ! doincrease )
{ {
springchange = Math.min( mCurrentValue, springchange ); springchange = Math.min( mCurrentValue, springchange );
mCurrentValue -= springchange; mCurrentValue -= springchange;
} }
if ( mCurrentValue < 0.0 && ! dodecrease ) if ( mCurrentValue < 0.0 && ! dodecrease )
{ {
springchange = Math.min( -mCurrentValue, springchange ); springchange = Math.min( -mCurrentValue, springchange );
mCurrentValue += springchange; mCurrentValue += springchange;
} }
// //
// Hold value within range // Hold value within range
// //
if ( mCurrentValue > 1.0 ) if ( mCurrentValue > 1.0 )
mCurrentValue = 1.0; mCurrentValue = 1.0;
double lowerlimit = Axis.SLIDER == mType ? 0.0 : -1.0; double lowerlimit = Axis.SLIDER == mType ? 0.0 : -1.0;
if ( mCurrentValue < lowerlimit ) if ( mCurrentValue < lowerlimit )
mCurrentValue = lowerlimit; mCurrentValue = lowerlimit;
} }
/** /**
* Set the button to increase the axis for a single button axis. * Set the button to increase the axis for a single button axis.
*/ */
public final void setIncreaseButton( Button b ) public final void setIncreaseButton( Button b )
{ {
if ( null == b ) if ( null == b )
throw new InvalidParameterException( "Button may not be null!" ); throw new InvalidParameterException( "Button may not be null!" );
mButtonIncrease = b; mButtonIncrease = b;
} }
/** /**
* Set the buttons to increase and descrease the axis. * Set the buttons to increase and descrease the axis.
*/ */
public final void setButtons( Button increase, Button decrease ) public final void setButtons( Button increase, Button decrease )
{ {
if ( null == increase || null == decrease ) if ( null == increase || null == decrease )
throw new InvalidParameterException( "Buttons may not be null!" ); throw new InvalidParameterException( "Buttons may not be null!" );
mButtonIncrease = increase; mButtonIncrease = increase;
mButtonDecrease = decrease; mButtonDecrease = decrease;
} }
public final void setSpeed( double speed ) public final void setSpeed( double speed )
{ {
mSpeed = speed; mSpeed = speed;
} }
public final void setSpringSpeed( double springspeed ) public final void setSpringSpeed( double springspeed )
{ {
mSpringSpeed = springspeed; mSpringSpeed = springspeed;
} }
public final void setTimeFor0To1( int ms ) public final void setTimeFor0To1( int ms )
{ {
if ( 0 >= ms ) if ( 0 >= ms )
mSpeed = 0.0; mSpeed = 0.0;
else else
mSpeed = 1.0/ ms; mSpeed = 1.0/ ms;
} }
public final void setTimeFor1To0( int ms ) public final void setTimeFor1To0( int ms )
{ {
if ( 0 >= ms ) if ( 0 >= ms )
mSpringSpeed = 0.0; mSpringSpeed = 0.0;
else else
mSpringSpeed = 1.0/ ms; mSpringSpeed = 1.0/ ms;
} }
public final void setName( String name ) public final void setName( String name )
{ {
mName = name; mName = name;
} }
//********************************************************************************************* //*********************************************************************************************
// //
// Implement Axis // Implement Axis
// //
//********************************************************************************************* //*********************************************************************************************
/** /**
* Features may have a name provided e.g. by the driver. * Features may have a name provided e.g. by the driver.
*/ */
public String getName() public String getName()
{ {
return mName; return mName;
} }
/** /**
* Inform about the resolution of the axis. * Inform about the resolution of the axis.
* *
* @return resolution, e.g. 2^-16 * @return resolution, e.g. 2^-16
*/ */
public double getResolution() public double getResolution()
{ {
return 1.0/65536.0; return 1.0/65536.0;
} }
/** /**
* Retrieve the type of the axis. * Retrieve the type of the axis.
* @return [ TRANSLATION | ROTATION | SLIDER ] * @return [ TRANSLATION | ROTATION | SLIDER ]
*/ */
public int getType() public int getType()
{ {
return mType; return mType;
} }
/** Returns the current value of the axis. /** Returns the current value of the axis.
* The range of the result depends on the axis type. * The range of the result depends on the axis type.
* *
* @return value [-1.0,1.0] or [0.0,1.0] * @return value [-1.0,1.0] or [0.0,1.0]
*/ */
public double getValue() public double getValue()
{ {
return mCurrentValue; return mCurrentValue;
} }
/** Denote wether this feature has changed beyond it's resolution since it got last /** Denote wether this feature has changed beyond it's resolution since it got last
* updated. * updated.
*/ */
public boolean hasChanged() public boolean hasChanged()
{ {
return true; return true;
} }
} }

View File

@@ -1,10 +1,10 @@
//********************************************************************************************** //**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development // (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification, // All rights reserved. Copying, modification,
// distribution or publication without the prior written // distribution or publication without the prior written
// consent of the author is prohibited. // consent of the author is prohibited.
// //
// Created on 9. April 2002, 22:43 // Created on 9. April 2002, 22:43
//********************************************************************************************** //**********************************************************************************************
package de.hardcode.jxinput.virtual; package de.hardcode.jxinput.virtual;
@@ -19,77 +19,77 @@ import de.hardcode.jxinput.Axis;
* @author Herkules * @author Herkules
*/ */
class VirtualDriver class VirtualDriver
{ {
private final VirtualAxis[] mVAxes = new VirtualAxis[ Axis.NUMBER_OF_ID ]; private final VirtualAxis[] mVAxes = new VirtualAxis[ Axis.NUMBER_OF_ID ];
/** /**
* Creates a new instance of KeyboardDriver. * Creates a new instance of KeyboardDriver.
*/ */
VirtualDriver() VirtualDriver()
{ {
} }
/** /**
* Update features under my control. * Update features under my control.
*/ */
final void update( long deltaT ) final void update( long deltaT )
{ {
// //
// Delegate the update call to the axes in use. // Delegate the update call to the axes in use.
// //
for ( int i = 0; i < mVAxes.length; i++ ) for ( int i = 0; i < mVAxes.length; i++ )
{ {
if ( null != mVAxes[ i ] ) if ( null != mVAxes[ i ] )
mVAxes[ i ].update( deltaT ); mVAxes[ i ].update( deltaT );
} }
} }
/** /**
* How many axes are registered? * How many axes are registered?
*/ */
final int getNumberOfAxes() final int getNumberOfAxes()
{ {
int ctr = 0; int ctr = 0;
for ( int i = 0; i < mVAxes.length; i++ ) for ( int i = 0; i < mVAxes.length; i++ )
{ {
if ( null != mVAxes[ i ] ) if ( null != mVAxes[ i ] )
ctr++; ctr++;
} }
return ctr; return ctr;
} }
Axis getAxis(int idx) Axis getAxis(int idx)
{ {
return mVAxes[ idx ]; return mVAxes[ idx ];
} }
/** /**
* Place a new axis under my observation. * Place a new axis under my observation.
*/ */
final void registerVirtualAxis( int id, VirtualAxis a ) final void registerVirtualAxis( int id, VirtualAxis a )
{ {
mVAxes[ id ] = a; mVAxes[ id ] = a;
} }
/** /**
* Remove an axis from my control. * Remove an axis from my control.
*/ */
final void unregisterVirtualAxis( VirtualAxis a ) final void unregisterVirtualAxis( VirtualAxis a )
{ {
for ( int i = 0; i < mVAxes.length; ++i ) for ( int i = 0; i < mVAxes.length; ++i )
{ {
if ( mVAxes[ i ] == a ) if ( mVAxes[ i ] == a )
{ {
mVAxes[ i ] = null; mVAxes[ i ] = null;
break; break;
} }
} }
} }
} }