Migrate to buildable gradle project
* use VisualCpp compiler * move source files to gradle project layout * remove obsolete files
This commit is contained in:
90
native/build.gradle
Normal file
90
native/build.gradle
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
apply plugin: 'cpp'
|
||||||
|
apply plugin: 'java'
|
||||||
|
apply plugin: 'maven'
|
||||||
|
|
||||||
|
task wrapper(type: Wrapper) {
|
||||||
|
gradleVersion = '1.12'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'com.github.boukefalos'
|
||||||
|
project.archivesBaseName = 'jlibxinput'
|
||||||
|
version = '1.0'
|
||||||
|
|
||||||
|
model {
|
||||||
|
platforms {
|
||||||
|
windows_i386 {
|
||||||
|
architecture 'i386'
|
||||||
|
operatingSystem 'windows'
|
||||||
|
}
|
||||||
|
windows_amd64 {
|
||||||
|
architecture 'amd64'
|
||||||
|
operatingSystem 'windows'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toolChains {
|
||||||
|
visualCpp(VisualCpp)
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
libs(PrebuiltLibraries) {
|
||||||
|
dxguid {
|
||||||
|
binaries.withType(StaticLibraryBinary) {
|
||||||
|
staticLibraryFile = file("lib/${targetPlatform.name}/dxguid.lib")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dinput8 {
|
||||||
|
binaries.withType(StaticLibraryBinary) {
|
||||||
|
staticLibraryFile = file("lib/${targetPlatform.name}/dinput8.lib")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
user32 {
|
||||||
|
binaries.withType(StaticLibraryBinary) {
|
||||||
|
staticLibraryFile = file("lib/${targetPlatform.name}/user32.lib")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
libraries {
|
||||||
|
main {
|
||||||
|
baseName project.archivesBaseName
|
||||||
|
}
|
||||||
|
all {
|
||||||
|
binaries.withType(SharedLibraryBinary) { binary ->
|
||||||
|
cppCompiler.define 'JXINPUT_EXPORTS'
|
||||||
|
cppCompiler.args '-Wall'
|
||||||
|
if (targetPlatform.operatingSystem.macOsX) {
|
||||||
|
cppCompiler.args '-I', "/System/Library/Frameworks/JavaVM.framework/Headers"
|
||||||
|
linker.args '-framework', "JavaVM"
|
||||||
|
} else if (targetPlatform.operatingSystem.linux) {
|
||||||
|
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
|
||||||
|
cppCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/linux"
|
||||||
|
} else if (targetPlatform.operatingSystem.windows) {
|
||||||
|
cppCompiler.args "-I${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
|
||||||
|
cppCompiler.args "-I${org.gradle.internal.jvm.Jvm.current().javaHome}/include/win32"
|
||||||
|
}
|
||||||
|
lib library: 'dxguid', linkage: 'static'
|
||||||
|
lib library: 'dinput8', linkage: 'static'
|
||||||
|
lib library: 'user32', linkage: 'static'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
binaries.withType(SharedLibraryBinary) { binary ->
|
||||||
|
if (buildable) {
|
||||||
|
def builderTask = binary.tasks.builder
|
||||||
|
jar.into("native/${targetPlatform.operatingSystem.name}/${targetPlatform.architecture.name}") {
|
||||||
|
from builderTask.outputFile
|
||||||
|
}
|
||||||
|
jar.dependsOn builderTask
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||||
|
classifier = 'sources'
|
||||||
|
from sourceSets.main.java.srcDirs
|
||||||
|
}
|
||||||
|
|
||||||
|
artifacts {
|
||||||
|
archives sourcesJar
|
||||||
|
}
|
||||||
174
native/src/main/cpp/JXInputManager.cpp
Normal file
174
native/src/main/cpp/JXInputManager.cpp
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,275 @@
|
|||||||
|
#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 ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
596
native/src/main/cpp/jxinput.cpp
Normal file
596
native/src/main/cpp/jxinput.cpp
Normal file
@@ -0,0 +1,596 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
24
native/src/main/cpp/main.cpp
Normal file
24
native/src/main/cpp/main.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;
|
||||||
|
}
|
||||||
33
native/src/main/headers/JXInputManager.h
Normal file
33
native/src/main/headers/JXInputManager.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#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 );
|
||||||
|
};
|
||||||
@@ -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
|
||||||
|
|
||||||
4417
native/src/main/headers/dinput.h
Normal file
4417
native/src/main/headers/dinput.h
Normal file
File diff suppressed because it is too large
Load Diff
182
native/src/main/headers/jxinput.h
Normal file
182
native/src/main/headers/jxinput.h
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
#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:
|
||||||
|
|
||||||
|
enum AXISTYPE
|
||||||
|
{
|
||||||
|
TYPE_TRANSLATION,
|
||||||
|
TYPE_ROTATION,
|
||||||
|
TYPE_SLIDER
|
||||||
|
};
|
||||||
|
|
||||||
|
enum BUTTONTYPE
|
||||||
|
{
|
||||||
|
TYPE_PUSHBUTTON,
|
||||||
|
TYPE_TOGGLEBUTTON
|
||||||
|
};
|
||||||
|
|
||||||
|
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();
|
||||||
|
};
|
||||||
|
|
||||||
11
native/src/main/headers/stdafx.h
Normal file
11
native/src/main/headers/stdafx.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#define DIRECTINPUT_VERSION 0x0800
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <dinput.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#ifdef JXINPUT_EXPORTS
|
||||||
|
#define JXINPUT_API __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define JXINPUT_API __declspec(dllimport)
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user