Import from http://drts.cvs.sourceforge.net/viewvc/drts/projects/jxinput/ tarball
This commit is contained in:
8
win32/.cvsignore
Normal file
8
win32/.cvsignore
Normal file
@@ -0,0 +1,8 @@
|
||||
*.ncb
|
||||
Release
|
||||
*.plg
|
||||
Debug
|
||||
*~
|
||||
jxinput.vcproj.HERKBOOK.Herkules.user
|
||||
jxinput.suo
|
||||
*.opt
|
||||
175
win32/JXInputManager.cpp
Normal file
175
win32/JXInputManager.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "JXInputManager.h"
|
||||
#include "JXInput.h"
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
extern HINSTANCE g_hInst;
|
||||
|
||||
|
||||
JXInputManager::JXInputManager( HWND hWnd ) :
|
||||
mhWnd( hWnd ),
|
||||
mDeviceCounter( 0 )
|
||||
{
|
||||
|
||||
for ( int i = 0; i < MAX_JXINPUTS; ++i )
|
||||
{
|
||||
mDevices[ i ] = NULL;
|
||||
}
|
||||
|
||||
|
||||
if ( FAILED( InitDirectInput( hWnd ) ) )
|
||||
{
|
||||
FreeDirectInput();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
JXInputManager::~JXInputManager()
|
||||
{
|
||||
for ( int i = 0; i < getNumberOfJXInputs(); ++i )
|
||||
{
|
||||
delete mDevices[ i ];
|
||||
mDevices[ i ] = NULL;
|
||||
}
|
||||
|
||||
FreeDirectInput();
|
||||
}
|
||||
|
||||
int JXInputManager::getNumberOfJXInputs() const
|
||||
{
|
||||
return mDeviceCounter;
|
||||
}
|
||||
|
||||
JXInput& JXInputManager::getJXInput( int idx ) const
|
||||
{
|
||||
assert( idx < mDeviceCounter );
|
||||
return * mDevices[ idx ];
|
||||
}
|
||||
|
||||
|
||||
int JXInputManager::getMaxNumberOfAxes() const
|
||||
{
|
||||
return JXINPUT_MAX_AXES;
|
||||
}
|
||||
|
||||
int JXInputManager::getMaxNumberOfButtons() const
|
||||
{
|
||||
return JXINPUT_MAX_BUTTONS;
|
||||
}
|
||||
|
||||
int JXInputManager::getMaxNumberOfDirectionals() const
|
||||
{
|
||||
return JXINPUT_MAX_DIRECTIONALS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: InitDirectInput()
|
||||
// Desc: Initialize the DirectInput variables.
|
||||
//-----------------------------------------------------------------------------
|
||||
HRESULT JXInputManager::InitDirectInput( HWND hWnd )
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
// Register with the DirectInput subsystem and get a pointer
|
||||
// to a IDirectInput interface we can use.
|
||||
// Create a DInput object
|
||||
if( FAILED( hr = DirectInput8Create( g_hInst, DIRECTINPUT_VERSION,
|
||||
IID_IDirectInput8, (VOID**)&mpDI, NULL ) ) )
|
||||
return hr;
|
||||
|
||||
// Look for a simple joystick we can use for this sample program.
|
||||
if( FAILED( hr = mpDI->EnumDevices( DI8DEVCLASS_GAMECTRL,
|
||||
EnumJoysticksCallback,
|
||||
(VOID*)this, DIEDFL_ALLDEVICES /*| DIEDFL_INCLUDEPHANTOMS*/ ) ) )
|
||||
return hr;
|
||||
|
||||
// Look for a other devices
|
||||
if( FAILED( hr = mpDI->EnumDevices( DI8DEVCLASS_DEVICE,
|
||||
EnumJoysticksCallback,
|
||||
(VOID*)this, DIEDFL_ALLDEVICES /*| DIEDFL_INCLUDEPHANTOMS*/ ) ) )
|
||||
return hr;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: FreeDirectInput()
|
||||
// Desc: Initialize the DirectInput variables.
|
||||
//-----------------------------------------------------------------------------
|
||||
HRESULT JXInputManager::FreeDirectInput()
|
||||
{
|
||||
|
||||
if ( NULL != mpDI )
|
||||
mpDI->Release();
|
||||
mpDI = NULL;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: EnumJoysticksCallback()
|
||||
// Desc: Called once for each enumerated joystick. If we find one, create a
|
||||
// device interface on it so we can play with it.
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL CALLBACK JXInputManager::EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance,
|
||||
VOID* pContext )
|
||||
{
|
||||
HRESULT hr;
|
||||
LPDIRECTINPUTDEVICE8 pJoystick;
|
||||
|
||||
JXInputManager* pThis = (JXInputManager*)pContext;
|
||||
|
||||
//
|
||||
// if the maximum number of devices is already registered,
|
||||
// issue a warning and stop enumeration.
|
||||
//
|
||||
if( MAX_JXINPUTS == pThis->mDeviceCounter )
|
||||
{
|
||||
OutputDebugString( "Max. number of devices exceeded!" );
|
||||
return DIENUM_STOP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Obtain an interface to the enumerated joystick.
|
||||
hr = pThis->mpDI->CreateDevice( pdidInstance->guidInstance, &pJoystick, NULL );
|
||||
|
||||
// If it failed, then we can't use this joystick. (Maybe the user unplugged
|
||||
// it while we were in the middle of enumerating it.)
|
||||
if( FAILED(hr) )
|
||||
return DIENUM_CONTINUE;
|
||||
|
||||
JXInput* pJ = new JXInput( pJoystick, pThis->mhWnd );
|
||||
|
||||
//
|
||||
// only register useful devices
|
||||
//
|
||||
if( pJ->getNumberOfAxes() + pJ->getNumberOfButtons() + pJ->getNumberOfDirectionals() > 0 )
|
||||
{
|
||||
pThis->addJXInput( pJ );
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pJ;
|
||||
}
|
||||
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register a JXInput device.
|
||||
*/
|
||||
void JXInputManager::addJXInput( JXInput* pJ )
|
||||
{
|
||||
assert( mDeviceCounter < MAX_JXINPUTS );
|
||||
|
||||
if( mDeviceCounter < MAX_JXINPUTS )
|
||||
mDevices[ mDeviceCounter++ ] = pJ;
|
||||
}
|
||||
47
win32/JXInputManager.h
Normal file
47
win32/JXInputManager.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// JXInputManager.h: Schnittstelle f<>r die Klasse JXInputManager.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_JXINPUTMANAGER_H__24862402_14C9_407D_8532_A16A6E3A7D64__INCLUDED_)
|
||||
#define AFX_JXINPUTMANAGER_H__24862402_14C9_407D_8532_A16A6E3A7D64__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
|
||||
#define MAX_JXINPUTS 10
|
||||
|
||||
class JXInput;
|
||||
|
||||
class JXINPUT_API JXInputManager
|
||||
{
|
||||
public:
|
||||
JXInputManager( HWND hWnd );
|
||||
virtual ~JXInputManager();
|
||||
|
||||
int getNumberOfJXInputs() const;
|
||||
JXInput& getJXInput( int idx ) const;
|
||||
|
||||
//
|
||||
// Numbering methods
|
||||
//
|
||||
int getMaxNumberOfAxes() const;
|
||||
int getMaxNumberOfButtons() const;
|
||||
int getMaxNumberOfDirectionals() const;
|
||||
|
||||
private:
|
||||
LPDIRECTINPUT8 mpDI;
|
||||
HWND mhWnd;
|
||||
JXInput* mDevices[ MAX_JXINPUTS ];
|
||||
int mDeviceCounter;
|
||||
|
||||
HRESULT InitDirectInput( HWND hWnd = NULL );
|
||||
HRESULT FreeDirectInput();
|
||||
|
||||
static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance,
|
||||
VOID* pContext );
|
||||
void addJXInput( JXInput* pJ );
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_JXINPUTMANAGER_H__24862402_14C9_407D_8532_A16A6E3A7D64__INCLUDED_)
|
||||
37
win32/ReadMe.txt
Normal file
37
win32/ReadMe.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
========================================================================
|
||||
DYNAMIC LINK LIBRARY : jxinput
|
||||
========================================================================
|
||||
|
||||
|
||||
Diese jxinput-DLL hat der Anwendungs-Assistent f<>r Sie erstellt.
|
||||
|
||||
Diese Datei enth<74>lt eine Zusammenfassung dessen, was Sie in jeder der Dateien
|
||||
finden, die Ihre jxinput-Anwendung bilden.
|
||||
|
||||
jxinput.dsp
|
||||
Diese Datei (Projektdatei) enth<74>lt Informationen auf Projektebene und wird zur
|
||||
Erstellung eines einzelnen Projekts oder Teilprojekts verwendet. Andere Benutzer k<>nnen
|
||||
die Projektdatei (.dsp) gemeinsam nutzen, sollten aber die Makefiles lokal exportieren.
|
||||
|
||||
jxinput.cpp
|
||||
Dies ist die Hauptquellcodedatei f<>r die DLL.
|
||||
|
||||
jxinput.h
|
||||
Diese Datei enth<74>lt Ihre DLL-Exporte.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
Weitere Standarddateien:
|
||||
|
||||
StdAfx.h, StdAfx.cpp
|
||||
Diese Dateien werden zum Erstellen einer vorkompilierten Header-Datei (PCH) namens
|
||||
jxinput.pch und einer vorkompilierten Typdatei namens StdAfx.obj verwendet.
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
Weitere Hinweise:
|
||||
|
||||
Der Anwendungs-Assistent verwendet "ZU ERLEDIGEN:", um Bereiche des Quellcodes zu
|
||||
kennzeichnen, die Sie hinzuf<75>gen oder anpassen sollten.
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
9
win32/StdAfx.cpp
Normal file
9
win32/StdAfx.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
// stdafx.cpp : Quelltextdatei, die nur die Standard-Includes einbindet
|
||||
// jxinput.pch ist die vorkompilierte Header-Datei
|
||||
// stdafx.obj enth<74>lt die vorkompilierte Typinformation
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// ZU ERLEDIGEN: Verweis auf alle zus<75>tzlichen Header-Dateien, die Sie in STDAFX.H
|
||||
// und nicht in dieser Datei ben<65>tigen
|
||||
|
||||
32
win32/StdAfx.h
Normal file
32
win32/StdAfx.h
Normal file
@@ -0,0 +1,32 @@
|
||||
// stdafx.h : Include-Datei f<>r Standard-System-Include-Dateien,
|
||||
// oder projektspezifische Include-Dateien, die h<>ufig benutzt, aber
|
||||
// in unregelm<6C><6D>igen Abst<73>nden ge<67>ndert werden.
|
||||
//
|
||||
|
||||
#if !defined(AFX_STDAFX_H__68E14C76_098F_47ED_932B_4C01E8E9EFFB__INCLUDED_)
|
||||
#define AFX_STDAFX_H__68E14C76_098F_47ED_932B_4C01E8E9EFFB__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
|
||||
// F<>gen Sie hier Ihre Header-Dateien ein
|
||||
#define WIN32_LEAN_AND_MEAN // Selten benutzte Teile der Windows-Header nicht einbinden
|
||||
#define STRICT
|
||||
#include <windows.h>
|
||||
|
||||
// ZU ERLEDIGEN: Verweisen Sie hier auf zus<75>tzliche Header-Dateien, die Ihr Programm ben<65>tigt
|
||||
#ifdef JXINPUT_EXPORTS
|
||||
#define JXINPUT_API __declspec(dllexport)
|
||||
#else
|
||||
#define JXINPUT_API __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
#include <dinput.h>
|
||||
#include <assert.h>
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Visual C++ f<>gt zus<75>tzliche Deklarationen unmittelbar vor der vorherigen Zeile ein.
|
||||
|
||||
#endif // !defined(AFX_STDAFX_H__68E14C76_098F_47ED_932B_4C01E8E9EFFB__INCLUDED_)
|
||||
279
win32/de_hardcode_jxinput_directinput_DirectInputDriver.cpp
Normal file
279
win32/de_hardcode_jxinput_directinput_DirectInputDriver.cpp
Normal file
@@ -0,0 +1,279 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "de_hardcode_jxinput_directinput_DirectInputDriver.h"
|
||||
#include "jxinput.h"
|
||||
#include "JXInputManager.h"
|
||||
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
extern HINSTANCE g_hInst;
|
||||
|
||||
static JXInputManager* pJXInputManager = NULL;
|
||||
static JXInput* apJXInput[ MAX_JXINPUTS ];
|
||||
static HWND hWndJava;
|
||||
|
||||
//
|
||||
// IDs of the static Java arrays.
|
||||
//
|
||||
static jfieldID sAxesFieldID;
|
||||
static jfieldID sButtonsFieldID;
|
||||
static jfieldID sDirectionsFieldID;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Remove all resources allocated by the Java binding.
|
||||
*/
|
||||
void shutdownJavaResources()
|
||||
{
|
||||
if ( NULL != pJXInputManager )
|
||||
delete pJXInputManager;
|
||||
|
||||
if ( NULL != hWndJava )
|
||||
DestroyWindow( hWndJava );
|
||||
|
||||
pJXInputManager = NULL;
|
||||
|
||||
for( int i = 0; i < MAX_JXINPUTS; ++i )
|
||||
apJXInput[ i ] = NULL;
|
||||
|
||||
hWndJava = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||
{
|
||||
return JNI_VERSION_1_2;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
|
||||
{
|
||||
shutdownJavaResources();
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_nativeinit
|
||||
(JNIEnv * penv, jclass pClazz )
|
||||
{
|
||||
|
||||
//
|
||||
// Create a non-visible window as 'owner' of the DI device.
|
||||
//
|
||||
hWndJava = CreateWindowEx(
|
||||
0/*WS_EX_APPWINDOW*/, // DWORD dwExStyle, // extended window style
|
||||
"STATIC", // LPCTSTR lpClassName, // pointer to registered class name
|
||||
NULL, // LPCTSTR lpWindowName, // pointer to window name
|
||||
0/*WS_CAPTION*/, // DWORD dwStyle, // window style
|
||||
0, // int x, // horizontal position of window
|
||||
0, // int y, // vertical position of window
|
||||
0, // int nWidth, // window width
|
||||
0, // int nHeight, // window height
|
||||
NULL, // HWND hWndParent, // handle to parent or owner window
|
||||
NULL, // HMENU hMenu, // handle to menu, or child-window identifier
|
||||
g_hInst, // HINSTANCE hInstance, // handle to application instance
|
||||
NULL // LPVOID lpParam // pointer to window-creation data
|
||||
);
|
||||
|
||||
|
||||
if ( NULL == pJXInputManager )
|
||||
{
|
||||
pJXInputManager = new JXInputManager( hWndJava );
|
||||
|
||||
for( int i = 0; i < MAX_JXINPUTS; ++i )
|
||||
apJXInput[ i ] = NULL;
|
||||
|
||||
for ( int i = 0; i < pJXInputManager->getNumberOfJXInputs(); ++i )
|
||||
{
|
||||
apJXInput[ i ] = & pJXInputManager->getJXInput( i );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_nativeexit
|
||||
(JNIEnv *, jclass )
|
||||
{
|
||||
shutdownJavaResources();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Bind my field IDs to the Java variables.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_bind
|
||||
(JNIEnv * penv, jclass pClazz)
|
||||
{
|
||||
//
|
||||
// All fields are static.
|
||||
//
|
||||
sAxesFieldID = penv->GetStaticFieldID( pClazz, "sAxisValues", "[[D" );
|
||||
sButtonsFieldID = penv->GetStaticFieldID( pClazz, "sButtonStates", "[[Z" );
|
||||
sDirectionsFieldID = penv->GetStaticFieldID( pClazz, "sDirectionalValues", "[[I" );
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfDevices
|
||||
(JNIEnv *penv, jclass)
|
||||
{
|
||||
return pJXInputManager->getNumberOfJXInputs();
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getName
|
||||
(JNIEnv *penv, jclass, jint dev)
|
||||
{
|
||||
return penv->NewStringUTF( apJXInput[ dev ]->getName() );
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfAxes
|
||||
(JNIEnv *, jclass, jint dev)
|
||||
{
|
||||
return apJXInput[ dev ]->getNumberOfAxes();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfButtons
|
||||
(JNIEnv *, jclass, jint dev)
|
||||
{
|
||||
return apJXInput[ dev ]->getNumberOfButtons();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfDirectionals
|
||||
(JNIEnv *, jclass, jint dev)
|
||||
{
|
||||
return apJXInput[ dev ]->getNumberOfDirectionals();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfAxes
|
||||
(JNIEnv *, jclass)
|
||||
{
|
||||
return pJXInputManager->getMaxNumberOfAxes();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfButtons
|
||||
(JNIEnv *, jclass)
|
||||
{
|
||||
return pJXInputManager->getMaxNumberOfButtons();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfDirectionals
|
||||
(JNIEnv *, jclass)
|
||||
{
|
||||
return pJXInputManager->getMaxNumberOfDirectionals();
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isAxisAvailable
|
||||
(JNIEnv *, jclass, jint dev, jint idx )
|
||||
{
|
||||
return apJXInput[ dev ]->isAxisAvailable( idx );
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getAxisName
|
||||
(JNIEnv *penv, jclass, jint dev, jint idx )
|
||||
{
|
||||
return penv->NewStringUTF( apJXInput[ dev ]->getAxisName( idx ) );
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getAxisType
|
||||
(JNIEnv *, jclass, jint dev, jint idx )
|
||||
{
|
||||
return apJXInput[ dev ]->getAxisType( idx );
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isButtonAvailable
|
||||
(JNIEnv *, jclass, jint dev, jint idx )
|
||||
{
|
||||
return apJXInput[ dev ]->isButtonAvailable( idx );
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getButtonName
|
||||
(JNIEnv *penv, jclass, jint dev, jint idx )
|
||||
{
|
||||
return penv->NewStringUTF( apJXInput[ dev ]->getButtonName( idx ) );
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getButtonType
|
||||
(JNIEnv *, jclass, jint dev, jint idx )
|
||||
{
|
||||
return apJXInput[ dev ]->getButtonType( idx );
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isDirectionalAvailable
|
||||
(JNIEnv *, jclass, jint dev, jint idx )
|
||||
{
|
||||
return apJXInput[ dev ]->isDirectionalAvailable( idx );
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getDirectionalName
|
||||
(JNIEnv *penv, jclass, jint dev, jint idx )
|
||||
{
|
||||
return penv->NewStringUTF( apJXInput[ dev ]->getDirectionalName( idx ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The main update method.
|
||||
* Here, the actual work is done.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_nativeupdate
|
||||
(JNIEnv * penv, jclass pClazz )
|
||||
{
|
||||
|
||||
static jdouble axes [ MAX_JXINPUTS ][ JXINPUT_MAX_AXES ];
|
||||
static jboolean buttons [ MAX_JXINPUTS ][ JXINPUT_MAX_BUTTONS ];
|
||||
static jint directions [ MAX_JXINPUTS ][ JXINPUT_MAX_DIRECTIONALS ];
|
||||
|
||||
static jobjectArray axisarrayarray;
|
||||
static jobjectArray buttonarrayarray;
|
||||
static jobjectArray directionarrayarray;
|
||||
|
||||
static jdoubleArray axisarray;
|
||||
static jbooleanArray buttonarray;
|
||||
static jintArray directionarray;
|
||||
|
||||
axisarrayarray = (jobjectArray)penv->GetStaticObjectField( pClazz, sAxesFieldID );
|
||||
buttonarrayarray = (jobjectArray)penv->GetStaticObjectField( pClazz, sButtonsFieldID );
|
||||
directionarrayarray = (jobjectArray)penv->GetStaticObjectField( pClazz, sDirectionsFieldID );
|
||||
|
||||
//
|
||||
// For each device....
|
||||
//
|
||||
for ( int dev = 0; dev < pJXInputManager->getNumberOfJXInputs(); ++dev )
|
||||
{
|
||||
// Do the update of the device.
|
||||
apJXInput[ dev ]->update();
|
||||
|
||||
//
|
||||
// Copy all values into my arrays.
|
||||
//
|
||||
for ( int i = 0; i < JXINPUT_MAX_AXES; ++i )
|
||||
axes[ dev ][ i ] = apJXInput[ dev ]->getAxisValue( i );
|
||||
for ( int i = 0; i < JXINPUT_MAX_BUTTONS; ++i )
|
||||
buttons[ dev ][ i ] = apJXInput[ dev ]->isButtonDown( i );
|
||||
for ( int i = 0; i < JXINPUT_MAX_DIRECTIONALS; ++i )
|
||||
directions[ dev ][ i ] = apJXInput[ dev ]->getDirection( i );
|
||||
|
||||
|
||||
//
|
||||
// Move my arrays to the Java arrays.
|
||||
//
|
||||
axisarray = (jdoubleArray)penv->GetObjectArrayElement( axisarrayarray, dev );
|
||||
penv->SetDoubleArrayRegion( axisarray, 0, JXINPUT_MAX_AXES, axes[ dev ] );
|
||||
|
||||
buttonarray = (jbooleanArray)penv->GetObjectArrayElement( buttonarrayarray, dev );
|
||||
penv->SetBooleanArrayRegion( buttonarray, 0, JXINPUT_MAX_BUTTONS, buttons[ dev ] );
|
||||
|
||||
directionarray = (jintArray)penv->GetObjectArrayElement( directionarrayarray, dev );
|
||||
penv->SetIntArrayRegion( directionarray, 0, JXINPUT_MAX_DIRECTIONALS, directions[ dev ] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
183
win32/de_hardcode_jxinput_directinput_DirectInputDriver.h
Normal file
183
win32/de_hardcode_jxinput_directinput_DirectInputDriver.h
Normal file
@@ -0,0 +1,183 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
|
||||
/* Header for class de_hardcode_jxinput_directinput_DirectInputDriver */
|
||||
|
||||
#ifndef _Included_de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
#define _Included_de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Inaccessible static: sIsOperational */
|
||||
/* Inaccessible static: sAxisValues */
|
||||
/* Inaccessible static: sButtonStates */
|
||||
/* Inaccessible static: sDirectionalValues */
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: nativeinit
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_nativeinit
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: nativeexit
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_nativeexit
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: bind
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_bind
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: getNumberOfDevices
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfDevices
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: getName
|
||||
* Signature: (I)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getName
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: getNumberOfAxes
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfAxes
|
||||
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: getNumberOfButtons
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfButtons
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: getNumberOfDirectionals
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getNumberOfDirectionals
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: getMaxNumberOfAxes
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfAxes
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: getMaxNumberOfButtons
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfButtons
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: getMaxNumberOfDirectionals
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getMaxNumberOfDirectionals
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: isAxisAvailable
|
||||
* Signature: (II)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isAxisAvailable
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: getAxisName
|
||||
* Signature: (II)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getAxisName
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: getAxisType
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getAxisType
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: isButtonAvailable
|
||||
* Signature: (II)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isButtonAvailable
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: getButtonName
|
||||
* Signature: (II)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getButtonName
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: getButtonType
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getButtonType
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: isDirectionalAvailable
|
||||
* Signature: (II)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_isDirectionalAvailable
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: getDirectionalName
|
||||
* Signature: (II)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_getDirectionalName
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: de_hardcode_jxinput_directinput_DirectInputDriver
|
||||
* Method: nativeupdate
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_de_hardcode_jxinput_directinput_DirectInputDriver_nativeupdate
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
24
win32/dllmain.cpp
Normal file
24
win32/dllmain.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
HINSTANCE g_hInst;
|
||||
|
||||
|
||||
BOOL APIENTRY DllMain( HANDLE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
{
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
g_hInst = (HINSTANCE)hModule;
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
g_hInst = NULL;
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
600
win32/jxinput.cpp
Normal file
600
win32/jxinput.cpp
Normal file
@@ -0,0 +1,600 @@
|
||||
//
|
||||
// jxinput.cpp
|
||||
//
|
||||
#include "stdafx.h"
|
||||
#include "jxinput.h"
|
||||
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
extern HINSTANCE g_hInst;
|
||||
|
||||
|
||||
/**
|
||||
* Ctor: Connect with DI
|
||||
*/
|
||||
JXInput::JXInput( LPDIRECTINPUTDEVICE8 pJoystick, HWND hWnd ) :
|
||||
mpJoystick( pJoystick ),
|
||||
mSliderCount( 0 ),
|
||||
mPOVCount( 0 ),
|
||||
mButtonCount( 0 )
|
||||
{
|
||||
initAxisConfig();
|
||||
initButtonsConfig();
|
||||
initDirectionalsConfig();
|
||||
|
||||
if ( FAILED( InitDirectInput( hWnd ) ) )
|
||||
{
|
||||
FreeDirectInput();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Destructor:
|
||||
* Free DirectInput.
|
||||
*/
|
||||
JXInput::~JXInput()
|
||||
{
|
||||
FreeDirectInput();
|
||||
}
|
||||
|
||||
|
||||
void JXInput::update()
|
||||
{
|
||||
UpdateInputState();
|
||||
}
|
||||
|
||||
|
||||
TCHAR * const JXInput::getName() const
|
||||
{
|
||||
return (TCHAR*)mdiDevInfo.tszInstanceName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int JXInput::getNumberOfAxes() const
|
||||
{
|
||||
return mdiDevCaps.dwAxes;
|
||||
}
|
||||
|
||||
int JXInput::getNumberOfButtons() const
|
||||
{
|
||||
return mButtonCount;
|
||||
}
|
||||
|
||||
int JXInput::getNumberOfDirectionals() const
|
||||
{
|
||||
return mPOVCount;
|
||||
}
|
||||
|
||||
|
||||
double JXInput::getAxisValueHelper( LONG val, int idx ) const
|
||||
{
|
||||
const AxisConfig& cfg = mAxisConfig[ idx ];
|
||||
|
||||
double span = (double)( cfg.mMaxValue - cfg.mMinValue );
|
||||
double ret = (double)(val - cfg.mMinValue) / span;
|
||||
|
||||
if ( TYPE_SLIDER != cfg.mType )
|
||||
return ret*2.0 - 1.0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
double JXInput::getX() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.lX, ID_X );
|
||||
}
|
||||
double JXInput::getY() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.lY, ID_Y );
|
||||
}
|
||||
double JXInput::getZ() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.lZ, ID_Z );
|
||||
}
|
||||
double JXInput::getRotX() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.lRx, ID_ROTX );
|
||||
}
|
||||
double JXInput::getRotY() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.lRy, ID_ROTY );
|
||||
}
|
||||
double JXInput::getRotZ() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.lRz, ID_ROTZ );
|
||||
}
|
||||
double JXInput::getSlider0() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.rglSlider[ 0 ], ID_SLIDER0 );
|
||||
}
|
||||
double JXInput::getSlider1() const
|
||||
{
|
||||
return getAxisValueHelper( mJS.rglSlider[ 1 ], ID_SLIDER1 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool JXInput::isAxisAvailable( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_AXES );
|
||||
return mAxisConfig[ idx ].mIsAvailable;
|
||||
}
|
||||
|
||||
TCHAR * const JXInput::getAxisName( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_AXES );
|
||||
return (char*const)mAxisConfig[ idx ].mName;
|
||||
}
|
||||
|
||||
int JXInput::getAxisType( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_AXES );
|
||||
return mAxisConfig[ idx ].mType;
|
||||
}
|
||||
|
||||
double JXInput::getAxisValue( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_AXES );
|
||||
|
||||
// Failsafe if called accidentally
|
||||
if ( ! mAxisConfig[ idx ].mIsAvailable )
|
||||
return 0.0;
|
||||
|
||||
return (this->*mAxisConfig[ idx ].mGetValueMethod)();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool JXInput::isButtonAvailable( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||
return mButtonConfig[ idx ].mIsAvailable;
|
||||
}
|
||||
|
||||
TCHAR * const JXInput::getButtonName( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||
return (char*const)mButtonConfig[ idx ].mName;
|
||||
}
|
||||
|
||||
int JXInput::getButtonType( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||
return mButtonConfig[ idx ].mType;
|
||||
}
|
||||
|
||||
bool JXInput::isButtonDown( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_BUTTONS );
|
||||
return 0 != mJS.rgbButtons[ idx ] ;
|
||||
}
|
||||
|
||||
|
||||
bool JXInput::isDirectionalAvailable( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_DIRECTIONALS );
|
||||
return mDirectionalConfig[ idx ].mIsAvailable;
|
||||
}
|
||||
|
||||
TCHAR * const JXInput::getDirectionalName( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_DIRECTIONALS );
|
||||
return (char*const)mDirectionalConfig[ idx ].mName;
|
||||
}
|
||||
|
||||
int JXInput::getDirection( int idx ) const
|
||||
{
|
||||
assert( idx < JXINPUT_MAX_DIRECTIONALS );
|
||||
return mJS.rgdwPOV[ idx ] ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize axis configuration array.
|
||||
*/
|
||||
void JXInput::initAxisConfig()
|
||||
{
|
||||
mAxisConfig[ ID_X ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_X ].mType = TYPE_TRANSLATION;
|
||||
mAxisConfig[ ID_X ].mGetValueMethod = &JXInput::getX;
|
||||
|
||||
mAxisConfig[ ID_Y ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_Y ].mType = TYPE_TRANSLATION;
|
||||
mAxisConfig[ ID_Y ].mGetValueMethod = &JXInput::getY;
|
||||
|
||||
mAxisConfig[ ID_Z ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_Z ].mType = TYPE_TRANSLATION;
|
||||
mAxisConfig[ ID_Z ].mGetValueMethod = &JXInput::getZ;
|
||||
|
||||
mAxisConfig[ ID_ROTX ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_ROTX ].mType = TYPE_ROTATION;
|
||||
mAxisConfig[ ID_ROTX ].mGetValueMethod = &JXInput::getRotX;
|
||||
|
||||
mAxisConfig[ ID_ROTY ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_ROTY ].mType = TYPE_ROTATION;
|
||||
mAxisConfig[ ID_ROTY ].mGetValueMethod = &JXInput::getRotY;
|
||||
|
||||
mAxisConfig[ ID_ROTZ ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_ROTZ ].mType = TYPE_ROTATION;
|
||||
mAxisConfig[ ID_ROTZ ].mGetValueMethod = &JXInput::getRotZ;
|
||||
|
||||
mAxisConfig[ ID_SLIDER0 ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_SLIDER0 ].mType = TYPE_SLIDER;
|
||||
mAxisConfig[ ID_SLIDER0 ].mGetValueMethod = &JXInput::getSlider0;
|
||||
|
||||
mAxisConfig[ ID_SLIDER1 ].mIsAvailable = false;
|
||||
mAxisConfig[ ID_SLIDER1 ].mType = TYPE_SLIDER;
|
||||
mAxisConfig[ ID_SLIDER1 ].mGetValueMethod = &JXInput::getSlider1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize buttons configuration array.
|
||||
*/
|
||||
void JXInput::initButtonsConfig()
|
||||
{
|
||||
for ( int i = 0; i < JXINPUT_MAX_BUTTONS; ++i )
|
||||
{
|
||||
mButtonConfig[ i ].mIsAvailable = false;
|
||||
mButtonConfig[ i ].mName[ 0 ] = '\0';
|
||||
mButtonConfig[ i ].mType = TYPE_PUSHBUTTON;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize directionals configuration array.
|
||||
*/
|
||||
void JXInput::initDirectionalsConfig()
|
||||
{
|
||||
for ( int i = 0; i < JXINPUT_MAX_DIRECTIONALS; ++i )
|
||||
{
|
||||
mDirectionalConfig[ i ].mIsAvailable = false;
|
||||
mDirectionalConfig[ i ].mName[ 0 ] = '\0';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: EnumAxesCallback()
|
||||
// Desc: Callback function for enumerating the axes on a joystick
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL CALLBACK JXInput::EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||
VOID* pContext )
|
||||
{
|
||||
JXInput* pThis = (JXInput*)pContext;
|
||||
|
||||
AxisConfig* pAxCfg = NULL;
|
||||
|
||||
// Set the UI to reflect what objects the joystick supports
|
||||
// Code derived from M$ samples, really sucks, eh?
|
||||
if (pdidoi->guidType == GUID_XAxis)
|
||||
{
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_X ];
|
||||
}
|
||||
if (pdidoi->guidType == GUID_YAxis)
|
||||
{
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_Y ];
|
||||
}
|
||||
if (pdidoi->guidType == GUID_ZAxis)
|
||||
{
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_Z ];
|
||||
}
|
||||
if (pdidoi->guidType == GUID_RxAxis)
|
||||
{
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_ROTX ];
|
||||
}
|
||||
if (pdidoi->guidType == GUID_RyAxis)
|
||||
{
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_ROTY ];
|
||||
}
|
||||
if (pdidoi->guidType == GUID_RzAxis)
|
||||
{
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_ROTZ ];
|
||||
}
|
||||
if (pdidoi->guidType == GUID_Slider)
|
||||
{
|
||||
switch( pThis->mSliderCount++ )
|
||||
{
|
||||
case 0 :
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_SLIDER0 ];
|
||||
break;
|
||||
|
||||
case 1 :
|
||||
pAxCfg = & pThis->mAxisConfig[ ID_SLIDER1 ];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// fail-safe
|
||||
if( NULL == pAxCfg ) // e.g. GUID_Unknown
|
||||
return DIENUM_CONTINUE;
|
||||
|
||||
|
||||
//
|
||||
// Perform config.
|
||||
//
|
||||
|
||||
DIPROPRANGE diprg;
|
||||
diprg.diph.dwSize = sizeof(DIPROPRANGE);
|
||||
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||
diprg.diph.dwHow = DIPH_BYID;
|
||||
diprg.diph.dwObj = pdidoi->dwType; // Specify the enumerated axis
|
||||
|
||||
// Get the range for the axis
|
||||
if( FAILED( pThis->mpJoystick->GetProperty( DIPROP_RANGE, &diprg.diph ) ) )
|
||||
return DIENUM_CONTINUE;
|
||||
|
||||
pAxCfg->mMinValue = diprg.lMin;
|
||||
pAxCfg->mMaxValue = diprg.lMax;
|
||||
|
||||
strcpy( (char*)pAxCfg->mName, (char*)pdidoi->tszName );
|
||||
pAxCfg->mIsAvailable = true;
|
||||
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: EnumButtonsCallback()
|
||||
// Desc: Callback function for enumerating the axes on a joystick
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL CALLBACK JXInput::EnumButtonsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||
VOID* pContext )
|
||||
{
|
||||
JXInput* pThis = (JXInput*)pContext;
|
||||
|
||||
//
|
||||
// if the maximum number of buttons is already registered,
|
||||
// issue a warning and stop enumeration.
|
||||
//
|
||||
if( JXINPUT_MAX_BUTTONS == pThis->mButtonCount )
|
||||
{
|
||||
OutputDebugString( "Max. number of buttons exceeded!" );
|
||||
return DIENUM_STOP;
|
||||
}
|
||||
|
||||
|
||||
ButtonConfig* pBtCfg = NULL;
|
||||
|
||||
if ( pdidoi->guidType == GUID_Button )
|
||||
{
|
||||
assert( JXINPUT_MAX_BUTTONS > pThis->mButtonCount );
|
||||
pBtCfg = & pThis->mButtonConfig[ pThis->mButtonCount++ ];
|
||||
}
|
||||
|
||||
|
||||
// fail-safe
|
||||
if( NULL == pBtCfg ) // e.g. unknown stuff
|
||||
return DIENUM_CONTINUE;
|
||||
assert( NULL != pBtCfg );
|
||||
|
||||
//
|
||||
// Perform config.
|
||||
//
|
||||
|
||||
strcpy( (char*)pBtCfg->mName, (char*)pdidoi->tszName );
|
||||
pBtCfg->mIsAvailable = true;
|
||||
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: EnumPOVsCallback()
|
||||
// Desc: Callback function for enumerating the axes on a joystick
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL CALLBACK JXInput::EnumPOVsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||
VOID* pContext )
|
||||
{
|
||||
JXInput* pThis = (JXInput*)pContext;
|
||||
|
||||
//
|
||||
// if the maximum number of buttons is already registered,
|
||||
// issue a warning and stop enumeration.
|
||||
//
|
||||
if( JXINPUT_MAX_DIRECTIONALS == pThis->mPOVCount )
|
||||
{
|
||||
OutputDebugString( "Max. number of POVs exceeded!" );
|
||||
return DIENUM_STOP;
|
||||
}
|
||||
|
||||
DirectionalConfig* pDirCfg = NULL;
|
||||
|
||||
|
||||
if (pdidoi->guidType == GUID_POV)
|
||||
{
|
||||
assert( JXINPUT_MAX_DIRECTIONALS > pThis->mPOVCount );
|
||||
pDirCfg = & pThis->mDirectionalConfig[ pThis->mPOVCount++ ];
|
||||
}
|
||||
|
||||
// fail-safe
|
||||
if( NULL == pDirCfg ) // e.g. unknown stuff
|
||||
return DIENUM_CONTINUE;
|
||||
assert( NULL != pDirCfg );
|
||||
|
||||
//
|
||||
// Perform config.
|
||||
//
|
||||
|
||||
strcpy( (char*)pDirCfg->mName, (char*)pdidoi->tszName );
|
||||
pDirCfg->mIsAvailable = true;
|
||||
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: EnumEffectsCallback()
|
||||
// Desc: Callback function for enumerating the effects of a joystick
|
||||
//-----------------------------------------------------------------------------
|
||||
BOOL CALLBACK JXInput::EnumEffectsCallback( const DIEFFECTINFO* pdidoi,
|
||||
VOID* pContext )
|
||||
{
|
||||
JXInput* pThis = (JXInput*)pContext;
|
||||
|
||||
//
|
||||
// Work on that!!
|
||||
//
|
||||
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: InitDirectInput()
|
||||
// Desc: Initialize the DirectInput variables.
|
||||
//-----------------------------------------------------------------------------
|
||||
HRESULT JXInput::InitDirectInput( HWND hWnd )
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
// Make sure we got a joystick
|
||||
if( NULL == mpJoystick )
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Ask the device for some useful information.
|
||||
//
|
||||
mdiDevInfo.dwSize = sizeof( DIDEVICEINSTANCE );
|
||||
hr = mpJoystick->GetDeviceInfo( &mdiDevInfo );
|
||||
if( FAILED(hr) )
|
||||
return hr;
|
||||
|
||||
// Set the data format to "simple joystick" - a predefined data format
|
||||
//
|
||||
// A data format specifies which controls on a device we are interested in,
|
||||
// and how they should be reported. This tells DInput that we will be
|
||||
// passing a DIJOYSTATE structure to IDirectInputDevice::GetDeviceState().
|
||||
hr = mpJoystick->SetDataFormat( &c_dfDIJoystick2 );
|
||||
if( FAILED(hr) )
|
||||
return hr;
|
||||
|
||||
// Set the cooperative level to let DInput know how this device should
|
||||
// interact with the system and with other DInput applications.
|
||||
// hr = g_pJoystick->SetCooperativeLevel( hDlg, DISCL_EXCLUSIVE|DISCL_FOREGROUND );
|
||||
DWORD mode = ( NULL == hWnd ? DISCL_NONEXCLUSIVE|DISCL_BACKGROUND : DISCL_EXCLUSIVE|DISCL_BACKGROUND );
|
||||
hr = mpJoystick->SetCooperativeLevel( hWnd, mode );
|
||||
if( FAILED(hr) )
|
||||
return hr;
|
||||
|
||||
// Determine how many axis the joystick has (so we don't error out setting
|
||||
// properties for unavailable axis)
|
||||
mdiDevCaps.dwSize = sizeof(DIDEVCAPS);
|
||||
hr = mpJoystick->GetCapabilities(&mdiDevCaps);
|
||||
if ( FAILED(hr) )
|
||||
return hr;
|
||||
|
||||
|
||||
// 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
|
||||
// of enumerating device objects (axes, buttons, etc.).
|
||||
mpJoystick->EnumObjects( EnumAxesCallback, (VOID*)this, DIDFT_AXIS );
|
||||
mpJoystick->EnumObjects( EnumButtonsCallback, (VOID*)this, DIDFT_BUTTON );
|
||||
mpJoystick->EnumObjects( EnumPOVsCallback, (VOID*)this, DIDFT_POV );
|
||||
|
||||
mpJoystick->EnumEffects( EnumEffectsCallback, (VOID*)this, DIEFT_ALL );
|
||||
|
||||
// For FF sticks, switch on autocenter as long as we do not use real FF
|
||||
SwitchAutoCenter( true );
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: UpdateInputState()
|
||||
// Desc: Get the input device's state and display it.
|
||||
//-----------------------------------------------------------------------------
|
||||
HRESULT JXInput::UpdateInputState()
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
if( mpJoystick )
|
||||
{
|
||||
|
||||
// Poll the device to read the current state
|
||||
hr = mpJoystick->Poll();
|
||||
if( FAILED(hr) )
|
||||
{
|
||||
// DInput is telling us that the input stream has been
|
||||
// interrupted. We aren't tracking any state between polls, so
|
||||
// we don't have any special reset that needs to be done. We
|
||||
// just re-acquire and try again.
|
||||
hr = mpJoystick->Acquire();
|
||||
while( hr == DIERR_INPUTLOST )
|
||||
hr = mpJoystick->Acquire();
|
||||
|
||||
// hr may be DIERR_OTHERAPPHASPRIO or other errors. This
|
||||
// may occur when the app is minimized or in the process of
|
||||
// switching, so just try again later
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// Get the input's device state
|
||||
if( FAILED( hr = mpJoystick->GetDeviceState( sizeof(DIJOYSTATE2), &mJS ) ) )
|
||||
return hr; // The device should have been acquired during the Poll()
|
||||
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: FreeDirectInput()
|
||||
// Desc: Initialize the DirectInput variables.
|
||||
//-----------------------------------------------------------------------------
|
||||
HRESULT JXInput::FreeDirectInput()
|
||||
{
|
||||
// Unacquire and release any DirectInputDevice objects.
|
||||
if( NULL != mpJoystick )
|
||||
{
|
||||
// Unacquire the device one last time just in case
|
||||
// the app tried to exit while the device is still acquired.
|
||||
mpJoystick->Unacquire();
|
||||
|
||||
mpJoystick->Release();
|
||||
mpJoystick = NULL;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HRESULT JXInput::SwitchAutoCenter( bool onoff )
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
DIPROPDWORD DIPropAutoCenter;
|
||||
|
||||
DIPropAutoCenter.diph.dwSize = sizeof(DIPropAutoCenter);
|
||||
DIPropAutoCenter.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||
DIPropAutoCenter.diph.dwObj = 0;
|
||||
DIPropAutoCenter.diph.dwHow = DIPH_DEVICE;
|
||||
DIPropAutoCenter.dwData = ( onoff ? DIPROPAUTOCENTER_ON : DIPROPAUTOCENTER_OFF );
|
||||
|
||||
hr = mpJoystick->SetProperty( DIPROP_AUTOCENTER, &DIPropAutoCenter.diph );
|
||||
return hr;
|
||||
}
|
||||
175
win32/jxinput.dsp
Normal file
175
win32/jxinput.dsp
Normal file
@@ -0,0 +1,175 @@
|
||||
# Microsoft Developer Studio Project File - Name="jxinput" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** NICHT BEARBEITEN **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=jxinput - Win32 Debug
|
||||
!MESSAGE Dies ist kein g<>ltiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
|
||||
!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und f<>hren Sie den Befehl
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "jxinput.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE Sie k<>nnen beim Ausf<73>hren von NMAKE eine Konfiguration angeben
|
||||
!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "jxinput.mak" CFG="jxinput - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE F<>r die Konfiguration stehen zur Auswahl:
|
||||
!MESSAGE
|
||||
!MESSAGE "jxinput - Win32 Release" (basierend auf "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "jxinput - Win32 Debug" (basierend auf "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "jxinput - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "JXINPUT_EXPORTS" /Yu"stdafx.h" /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /I "C:\j2sdk1.4.2\include" /I "C:\j2sdk1.4.2\include\win32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "JXINPUT_EXPORTS" /FR /Yu"stdafx.h" /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x407 /d "NDEBUG"
|
||||
# ADD RSC /l 0x407 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 dxguid.lib dinput8.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\build\jxinput.dll"
|
||||
|
||||
!ELSEIF "$(CFG)" == "jxinput - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "JXINPUT_EXPORTS" /Yu"stdafx.h" /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "C:\j2sdk1.4.2\include" /I "C:\j2sdk1.4.2\include\win32" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "JXINPUT_EXPORTS" /FR /Yu"stdafx.h" /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x407 /d "_DEBUG"
|
||||
# ADD RSC /l 0x407 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 dxguid.lib dinput8.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"..\Classes\jxinput.dll" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "jxinput - Win32 Release"
|
||||
# Name "jxinput - Win32 Debug"
|
||||
# Begin Group "Quellcodedateien"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\de_hardcode_jxinput_directinput_DirectInputDriver.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\dllmain.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jxinput.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\JXInputManager.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.cpp
|
||||
# ADD CPP /Yc"stdafx.h"
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header-Dateien"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\de_hardcode_jxinput_directinput_DirectInputDriver.h
|
||||
|
||||
!IF "$(CFG)" == "jxinput - Win32 Release"
|
||||
|
||||
# PROP Ignore_Default_Tool 1
|
||||
USERDEP__DE_HA="..\classes\de\hardcode\jxinput\directinput\DirectInputDriver.class"
|
||||
# Begin Custom Build
|
||||
InputPath=.\de_hardcode_jxinput_directinput_DirectInputDriver.h
|
||||
|
||||
"de_hardcode_jxinput_directinput_DirectInputDriver.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
cd ..\Classes
|
||||
C:\j2sdk1.4.2\bin\javah -classpath . -d ..\win32 de.hardcode.jxinput.directinput.DirectInputDriver
|
||||
cd ..\win32
|
||||
|
||||
# End Custom Build
|
||||
|
||||
!ELSEIF "$(CFG)" == "jxinput - Win32 Debug"
|
||||
|
||||
# PROP Ignore_Default_Tool 1
|
||||
USERDEP__DE_HA="..\classes\de\hardcode\jxinput\directinput\DirectInputDriver.class"
|
||||
# Begin Custom Build
|
||||
InputPath=.\de_hardcode_jxinput_directinput_DirectInputDriver.h
|
||||
|
||||
"de_hardcode_jxinput_directinput_DirectInputDriver.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
cd ..\Classes
|
||||
C:\j2sdk1.4.2\bin\javah -classpath . -d ..\win32 de.hardcode.jxinput.directinput.DirectInputDriver
|
||||
cd ..\win32
|
||||
|
||||
# End Custom Build
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jxinput.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\JXInputManager.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Ressourcendateien"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ReadMe.txt
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
29
win32/jxinput.dsw
Normal file
29
win32/jxinput.dsw
Normal file
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GEL<45>SCHT WERDEN!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "jxinput"=".\jxinput.dsp" - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
183
win32/jxinput.h
Normal file
183
win32/jxinput.h
Normal file
@@ -0,0 +1,183 @@
|
||||
|
||||
#define JXINPUT_MAX_AXES 8
|
||||
#define JXINPUT_MAX_BUTTONS 256
|
||||
#define JXINPUT_MAX_DIRECTIONALS 4
|
||||
|
||||
|
||||
/**
|
||||
* This class will be exported by jxinput.dll.
|
||||
*/
|
||||
class JXINPUT_API JXInput
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
typedef enum AXISTYPE
|
||||
{
|
||||
TYPE_TRANSLATION,
|
||||
TYPE_ROTATION,
|
||||
TYPE_SLIDER
|
||||
};
|
||||
|
||||
typedef enum BUTTONTYPE
|
||||
{
|
||||
TYPE_PUSHBUTTON,
|
||||
TYPE_TOGGLEBUTTON
|
||||
};
|
||||
|
||||
typedef enum AXISID
|
||||
{
|
||||
ID_X, ID_Y, ID_Z,
|
||||
ID_ROTX, ID_ROTY, ID_ROTZ,
|
||||
ID_SLIDER0, ID_SLIDER1
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Ctor
|
||||
//
|
||||
JXInput( LPDIRECTINPUTDEVICE8 pJoystick, HWND hWnd = NULL );
|
||||
|
||||
//
|
||||
// Dtor
|
||||
//
|
||||
virtual ~JXInput();
|
||||
|
||||
//
|
||||
// Operational methods
|
||||
//
|
||||
void update();
|
||||
|
||||
// Ask for the name
|
||||
TCHAR * const getName() const;
|
||||
|
||||
//
|
||||
// Numbering methods
|
||||
//
|
||||
int getNumberOfAxes() const;
|
||||
int getNumberOfButtons() const;
|
||||
int getNumberOfDirectionals() const;
|
||||
|
||||
|
||||
//
|
||||
// Access axes
|
||||
//
|
||||
double getX() const; /** -1.0 .... 1.0 */
|
||||
double getY() const; /** -1.0 .... 1.0 */
|
||||
double getZ() const; /** -1.0 .... 1.0 */
|
||||
double getRotX() const; /** -1.0 .... 1.0 */
|
||||
double getRotY() const; /** -1.0 .... 1.0 */
|
||||
double getRotZ() const; /** -1.0 .... 1.0 */
|
||||
double getSlider0() const; /** 0.0 .... 1.0 */
|
||||
double getSlider1() const; /** 0.0 .... 1.0 */
|
||||
|
||||
|
||||
//
|
||||
// Axis methods
|
||||
//
|
||||
bool isAxisAvailable( int idx ) const;
|
||||
TCHAR* const getAxisName( int idx ) const;
|
||||
int getAxisType( int idx ) const;
|
||||
double getAxisValue( int idx ) const;
|
||||
|
||||
//
|
||||
// Button methods
|
||||
//
|
||||
bool isButtonAvailable( int idx ) const;
|
||||
TCHAR* const getButtonName( int idx ) const;
|
||||
int getButtonType( int idx ) const;
|
||||
bool isButtonDown( int idx ) const;
|
||||
|
||||
//
|
||||
// Directional methods
|
||||
//
|
||||
bool isDirectionalAvailable( int idx ) const;
|
||||
TCHAR* const getDirectionalName( int idx ) const;
|
||||
int getDirection( int idx ) const;
|
||||
|
||||
private://-----------------------------------------------------------------------------------------
|
||||
LPDIRECTINPUTDEVICE8 mpJoystick;
|
||||
|
||||
DIDEVICEINSTANCE mdiDevInfo;
|
||||
DIDEVCAPS mdiDevCaps;
|
||||
DIJOYSTATE2 mJS; // DInput joystick state
|
||||
|
||||
int mSliderCount;
|
||||
int mPOVCount;
|
||||
int mButtonCount;
|
||||
|
||||
double getAxisValueHelper( LONG val, int idx ) const;
|
||||
|
||||
HRESULT SwitchAutoCenter( bool onoff = true );
|
||||
|
||||
HRESULT InitDirectInput( HWND hWnd = NULL );
|
||||
HRESULT FreeDirectInput();
|
||||
HRESULT UpdateInputState();
|
||||
|
||||
|
||||
static BOOL CALLBACK EnumAxesCallback
|
||||
(
|
||||
const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||
VOID* pContext
|
||||
);
|
||||
|
||||
static BOOL CALLBACK EnumButtonsCallback
|
||||
(
|
||||
const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||
VOID* pContext
|
||||
);
|
||||
|
||||
static BOOL CALLBACK EnumPOVsCallback
|
||||
(
|
||||
const DIDEVICEOBJECTINSTANCE* pdidoi,
|
||||
VOID* pContext
|
||||
);
|
||||
|
||||
static BOOL CALLBACK EnumEffectsCallback
|
||||
(
|
||||
const DIEFFECTINFO* pdidoi,
|
||||
VOID* pContext
|
||||
);
|
||||
|
||||
|
||||
class JXINPUT_API AxisConfig
|
||||
{
|
||||
|
||||
public:
|
||||
bool mIsAvailable;
|
||||
CHAR mName[MAX_PATH];
|
||||
AXISTYPE mType;
|
||||
LONG mMinValue;
|
||||
LONG mMaxValue;
|
||||
double (JXInput::*mGetValueMethod)() const;
|
||||
|
||||
} mAxisConfig [ JXINPUT_MAX_AXES ];
|
||||
|
||||
void initAxisConfig();
|
||||
|
||||
|
||||
class JXINPUT_API ButtonConfig
|
||||
{
|
||||
|
||||
public:
|
||||
bool mIsAvailable;
|
||||
CHAR mName[MAX_PATH];
|
||||
BUTTONTYPE mType;
|
||||
|
||||
} mButtonConfig[ JXINPUT_MAX_BUTTONS ];
|
||||
|
||||
void initButtonsConfig();
|
||||
|
||||
|
||||
class JXINPUT_API DirectionalConfig
|
||||
{
|
||||
|
||||
public:
|
||||
bool mIsAvailable;
|
||||
CHAR mName[MAX_PATH];
|
||||
|
||||
} mDirectionalConfig[ JXINPUT_MAX_DIRECTIONALS ];
|
||||
|
||||
void initDirectionalsConfig();
|
||||
};
|
||||
|
||||
20
win32/jxinput.sln
Normal file
20
win32/jxinput.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual C++ Express 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jxinput", "jxinput.vcproj", "{8AEA84DC-D8F0-4425-BEBF-A84E91115F76}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{8AEA84DC-D8F0-4425-BEBF-A84E91115F76}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{8AEA84DC-D8F0-4425-BEBF-A84E91115F76}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{8AEA84DC-D8F0-4425-BEBF-A84E91115F76}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{8AEA84DC-D8F0-4425-BEBF-A84E91115F76}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
367
win32/jxinput.vcproj
Normal file
367
win32/jxinput.vcproj
Normal file
@@ -0,0 +1,367 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8,00"
|
||||
Name="jxinput"
|
||||
ProjectGUID="{8AEA84DC-D8F0-4425-BEBF-A84E91115F76}"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\Release"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="2"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
MkTypLibCompatible="true"
|
||||
SuppressStartupBanner="true"
|
||||
TargetEnvironment="1"
|
||||
TypeLibraryName=".\Release/jxinput.tlb"
|
||||
HeaderFileName=""
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="C:\Programme\Java\jdk1.5.0_06\include;C:\Programme\Java\jdk1.5.0_06\include\win32"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;JXINPUT_EXPORTS"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="2"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
PrecompiledHeaderFile=".\Release/jxinput.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
BrowseInformation="1"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1031"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="dxguid.lib dinput8.lib user32.lib"
|
||||
OutputFile="..\build\jxinput.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="true"
|
||||
ProgramDatabaseFile=".\Release/jxinput.pdb"
|
||||
ImportLibrary=".\Release/jxinput.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile=".\Release/jxinput.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="..\classes"
|
||||
IntermediateDirectory=".\Debug"
|
||||
ConfigurationType="2"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
MkTypLibCompatible="true"
|
||||
SuppressStartupBanner="true"
|
||||
TargetEnvironment="1"
|
||||
TypeLibraryName=".\Debug/jxinput.tlb"
|
||||
HeaderFileName=""
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="C:\Programme\Java\jdk1.5.0_06\include;C:\Programme\Java\jdk1.5.0_06\include\win32"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;JXINPUT_EXPORTS"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="2"
|
||||
PrecompiledHeaderThrough="stdafx.h"
|
||||
PrecompiledHeaderFile=".\Debug/jxinput.pch"
|
||||
AssemblerListingLocation=".\Debug/"
|
||||
ObjectFile=".\Debug/"
|
||||
ProgramDataBaseFileName=".\Debug/"
|
||||
BrowseInformation="1"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1031"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="dxguid.lib dinput8.lib user32.lib"
|
||||
OutputFile="..\Classes\jxinput.dll"
|
||||
LinkIncremental="2"
|
||||
SuppressStartupBanner="true"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile=".\Debug/jxinput.pdb"
|
||||
ImportLibrary=".\Debug/jxinput.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
SuppressStartupBanner="true"
|
||||
OutputFile=".\Debug/jxinput.bsc"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Quellcodedateien"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
>
|
||||
<File
|
||||
RelativePath="de_hardcode_jxinput_directinput_DirectInputDriver.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="dllmain.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="jxinput.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="JXInputManager.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="StdAfx.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header-Dateien"
|
||||
Filter="h;hpp;hxx;hm;inl"
|
||||
>
|
||||
<File
|
||||
RelativePath="de_hardcode_jxinput_directinput_DirectInputDriver.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="jxinput.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="JXInputManager.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="StdAfx.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Ressourcendateien"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath="ReadMe.txt"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
Reference in New Issue
Block a user