aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/wintab/src/native
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/wintab/src/native')
-rw-r--r--plugins/wintab/src/native/build.xml70
-rw-r--r--plugins/wintab/src/native/net_java_games_input_WinTabContext.c85
-rw-r--r--plugins/wintab/src/native/net_java_games_input_WinTabDevice.c107
3 files changed, 262 insertions, 0 deletions
diff --git a/plugins/wintab/src/native/build.xml b/plugins/wintab/src/native/build.xml
new file mode 100644
index 0000000..152ef24
--- /dev/null
+++ b/plugins/wintab/src/native/build.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0"?>
+
+<project name="JInput wintab port, Native code" basedir="." default="compile">
+ <property environment="env"/>
+ <property name="wintabhome" location="${env.WINTAB_DIR}"/>
+ <property name="sdkhome" location="c:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2"/>
+
+ <target name="compile_dir">
+ <echo message="${compiledir}"/>
+ <echo message="wintab: ${wintabhome}"/>
+ <apply dir="${compiledir}" failonerror="true" executable="cl" dest="${compiledir}" skipemptyfilesets="true">
+ <arg line="/Ox /Wp64 /W2 /nologo /c"/>
+ <arg value="/I${sdkhome}\include"/>
+ <arg value="/I${wintabhome}\include"/>
+ <arg value="/I${java.home}\..\include"/>
+ <arg value="/I${java.home}\..\include\win32"/>
+ <arg value="/I${commonhome}/src/native"/>
+ <arg value="/I.."/>
+ <srcfile/>
+ <fileset dir="${compiledir}" includes="*.c"/>
+ <mapper type="glob" from="*.c" to="*.obj"/>
+ </apply>
+ </target>
+
+ <!-- <target name="link" unless="nolink">-->
+ <target name="link">
+ <apply dir="." parallel="true" executable="cl" failonerror="true">
+ <arg line="/LD /nologo"/>
+ <srcfile/>
+ <arg line="/Fe${dllname} /link"/>
+ <arg value="/LIBPATH:${java.home}\lib"/>
+ <arg value="/LIBPATH:${wintabhome}\lib\I386"/>
+ <arg value="/LIBPATH:${sdkhome}\lib"/>
+ <arg line="/DLL ${libs}"/>
+ <fileset dir="${commonhome}/src/native" includes="*.obj"/>
+ <fileset dir="." includes="*.obj"/>
+ <fileset dir="../../../windows/src/native" includes="*.obj"/>
+ </apply>
+ </target>
+
+ <target name="clean">
+ <delete>
+ <fileset dir="." includes="*.obj"/>
+ <fileset dir="." includes="*.dll"/>
+ </delete>
+ </target>
+
+ <target name="compile">
+ <property name="wintablibs" value="Kernel32.lib WINTAB32.LIB User32.lib"/>
+ <property name="commonhome" location="../../../common"/>
+ <property name="dllname" value="jinput-wintab.dll"/>
+ <antcall target="compile_dir">
+ <param name="compiledir" location="${commonhome}/src/native"/>
+ </antcall>
+ <antcall target="compile_dir">
+ <param name="compiledir" location="."/>
+ </antcall>
+ <antcall target="compile_dir">
+ <param name="compiledir" location="../../../windows/src/native"/>
+ </antcall>
+ <!-- <uptodate property="nolink" targetfile="${dllname}">
+ <srcfiles dir="." includes="*.obj"/>
+ </uptodate>-->
+ <antcall target="link">
+ <param name="dllname" value="${dllname}"/>
+ <param name="libs" value="${wintablibs}"/>
+ </antcall>
+ </target>
+</project>
+
diff --git a/plugins/wintab/src/native/net_java_games_input_WinTabContext.c b/plugins/wintab/src/native/net_java_games_input_WinTabContext.c
new file mode 100644
index 0000000..10863f9
--- /dev/null
+++ b/plugins/wintab/src/native/net_java_games_input_WinTabContext.c
@@ -0,0 +1,85 @@
+#include <windows.h>
+#include <stdio.h>
+
+#include <jni.h>
+#include "net_java_games_input_WinTabContext.h"
+#include <wintab.h>
+//#define PACKETDATA ( PK_X | PK_Y | PK_Z | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ROTATION | PK_ORIENTATION | PK_CURSOR )
+#define PACKETDATA ( PK_TIME | PK_X | PK_Y | PK_Z | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_CURSOR )
+#define PACKETMODE 0
+#include <pktdef.h>
+#include <util.h>
+
+#define MAX_PACKETS 20
+
+JNIEXPORT jlong JNICALL Java_net_java_games_input_WinTabContext_nOpen(JNIEnv *env, jclass unused, jlong hWnd_long) {
+ LOGCONTEXT context;
+ HWND hWnd = (HWND)(INT_PTR)hWnd_long;
+ HCTX hCtx = NULL;
+
+ /* get default region */
+ WTInfo(WTI_DEFCONTEXT, 0, &context);
+
+ wsprintf(context.lcName, "JInput Digitizing");
+ context.lcPktData = PACKETDATA;
+ context.lcPktMode = PACKETMODE;
+ context.lcMoveMask = PACKETDATA;
+ context.lcBtnUpMask = context.lcBtnDnMask;
+
+ /* open the region */
+ hCtx = WTOpen(hWnd, &context, TRUE);
+
+ return (jlong)(intptr_t)hCtx;
+}
+
+JNIEXPORT void JNICALL Java_net_java_games_input_WinTabContext_nClose(JNIEnv *env, jclass unused, jlong hCtx_long) {
+ WTClose((HCTX)(INT_PTR)hCtx_long);
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_WinTabContext_nGetNumberOfSupportedDevices(JNIEnv *env, jclass unused) {
+ int numDevices;
+ WTInfo(WTI_INTERFACE, IFC_NDEVICES, &numDevices);
+ return numDevices;
+}
+
+JNIEXPORT jobjectArray JNICALL Java_net_java_games_input_WinTabContext_nGetPackets(JNIEnv *env, jclass unused, jlong hCtx_long) {
+
+ jobjectArray retval;
+ int i=0;
+ PACKET packets[MAX_PACKETS];
+ int numberRead = WTPacketsGet((HCTX)(INT_PTR)hCtx_long, MAX_PACKETS, packets);
+ jclass winTabPacketClass = (*env)->FindClass(env, "net/java/games/input/WinTabPacket");
+ jfieldID packetTimeField = (*env)->GetFieldID(env, winTabPacketClass, "PK_TIME", "J");
+ jfieldID packetXAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_X", "I");
+ jfieldID packetYAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_Y", "I");
+ jfieldID packetZAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_Z", "I");
+ jfieldID packetButtonsField = (*env)->GetFieldID(env, winTabPacketClass, "PK_BUTTONS", "I");
+ jfieldID packetNPressureAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_NORMAL_PRESSURE", "I");
+ jfieldID packetTPressureAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_TANGENT_PRESSURE", "I");
+ jfieldID packetCursorField = (*env)->GetFieldID(env, winTabPacketClass, "PK_CURSOR", "I");
+ jfieldID packetOrientationAltAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_ORIENTATION_ALT", "I");
+ jfieldID packetOrientationAzAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_ORIENTATION_AZ", "I");
+ jfieldID packetOrientationTwistAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_ORIENTATION_TWIST", "I");
+ jobject prototypePacket = newJObject(env, "net/java/games/input/WinTabPacket", "()V");
+
+ retval = (*env)->NewObjectArray(env, numberRead, winTabPacketClass, NULL);
+ for(i=0;i<numberRead;i++) {
+ jobject tempPacket = newJObject(env, "net/java/games/input/WinTabPacket", "()V");
+
+ (*env)->SetLongField(env, tempPacket, packetTimeField, packets[i].pkTime);
+ (*env)->SetIntField(env, tempPacket, packetXAxisField, packets[i].pkX);
+ (*env)->SetIntField(env, tempPacket, packetYAxisField, packets[i].pkY);
+ (*env)->SetIntField(env, tempPacket, packetZAxisField, packets[i].pkZ);
+ (*env)->SetIntField(env, tempPacket, packetButtonsField, packets[i].pkButtons);
+ (*env)->SetIntField(env, tempPacket, packetNPressureAxisField, packets[i].pkNormalPressure);
+ (*env)->SetIntField(env, tempPacket, packetTPressureAxisField, packets[i].pkTangentPressure);
+ (*env)->SetIntField(env, tempPacket, packetCursorField, packets[i].pkCursor);
+ (*env)->SetIntField(env, tempPacket, packetOrientationAltAxisField, packets[i].pkOrientation.orAzimuth);
+ (*env)->SetIntField(env, tempPacket, packetOrientationAzAxisField, packets[i].pkOrientation.orAltitude);
+ (*env)->SetIntField(env, tempPacket, packetOrientationTwistAxisField, packets[i].pkOrientation.orTwist);
+
+ (*env)->SetObjectArrayElement(env, retval, i, tempPacket);
+ }
+
+ return retval;
+}
diff --git a/plugins/wintab/src/native/net_java_games_input_WinTabDevice.c b/plugins/wintab/src/native/net_java_games_input_WinTabDevice.c
new file mode 100644
index 0000000..45f202e
--- /dev/null
+++ b/plugins/wintab/src/native/net_java_games_input_WinTabDevice.c
@@ -0,0 +1,107 @@
+#include <windows.h>
+#include <stdio.h>
+
+#include <jni.h>
+#include "net_java_games_input_WinTabDevice.h"
+#include "net_java_games_input_WinTabComponent.h"
+#include "util.h"
+#include <wintab.h>
+#include <malloc.h>
+#define PACKETDATA ( PK_X | PK_Y | PK_Z | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_CURSOR )
+#define PACKETMODE 0
+#include <pktdef.h>
+
+JNIEXPORT jstring JNICALL Java_net_java_games_input_WinTabDevice_nGetName(JNIEnv *env, jclass unused, jint deviceIndex) {
+ char name[50];
+ WTInfo(WTI_DEVICES + deviceIndex, DVC_NAME, name);
+ return (*env)->NewStringUTF(env, name);
+}
+
+JNIEXPORT jintArray JNICALL Java_net_java_games_input_WinTabDevice_nGetAxisDetails(JNIEnv *env, jclass unused, jint deviceIndex, jint axisId) {
+ UINT type;
+ AXIS threeAxisArray[3];
+ AXIS axis;
+ long threeAxisData[6];
+ long axisData[2];
+ int res;
+ jintArray retVal = NULL;
+
+ if(axisId==net_java_games_input_WinTabComponent_XAxis) type = DVC_X;
+ else if(axisId==net_java_games_input_WinTabComponent_YAxis) type = DVC_Y;
+ else if(axisId==net_java_games_input_WinTabComponent_ZAxis) type = DVC_Z;
+ else if(axisId==net_java_games_input_WinTabComponent_NPressureAxis) type = DVC_NPRESSURE;
+ else if(axisId==net_java_games_input_WinTabComponent_TPressureAxis) type = DVC_TPRESSURE;
+ else if(axisId==net_java_games_input_WinTabComponent_OrientationAxis) type = DVC_ORIENTATION;
+ else if(axisId==net_java_games_input_WinTabComponent_RotationAxis) type = DVC_ROTATION;
+
+ if(axisId==net_java_games_input_WinTabComponent_RotationAxis || axisId==net_java_games_input_WinTabComponent_OrientationAxis) {
+ res = WTInfo(WTI_DEVICES + deviceIndex, type, &threeAxisArray);
+ if(res!=0) {
+ threeAxisData[0] = threeAxisArray[0].axMin;
+ threeAxisData[1] = threeAxisArray[0].axMax;
+ threeAxisData[2] = threeAxisArray[1].axMin;
+ threeAxisData[3] = threeAxisArray[1].axMax;
+ threeAxisData[4] = threeAxisArray[2].axMin;
+ threeAxisData[5] = threeAxisArray[2].axMax;
+ retVal = (*env)->NewIntArray(env, 6);
+ (*env)->SetIntArrayRegion(env, retVal, 0, 6, threeAxisData);
+ }
+ } else {
+ res = WTInfo(WTI_DEVICES + deviceIndex, type, &axis);
+ if(res!=0) {
+ axisData[0] = axis.axMin;
+ axisData[1] = axis.axMax;
+ retVal = (*env)->NewIntArray(env, 2);
+ (*env)->SetIntArrayRegion(env, retVal, 0, 2, axisData);
+ }
+ }
+
+ if(retVal==NULL) {
+ retVal = (*env)->NewIntArray(env, 0);
+ }
+
+ return retVal;
+}
+
+JNIEXPORT jobjectArray JNICALL Java_net_java_games_input_WinTabDevice_nGetCursorNames(JNIEnv *env, jclass unused, jint deviceId) {
+ int numberCursorTypes;
+ int firstCursorType;
+ char name[50];
+ int i;
+ jclass stringClass = (*env)->FindClass(env, "java/lang/String");
+ jstring nameString;
+ jobjectArray retval;
+
+ WTInfo(WTI_DEVICES + deviceId, DVC_NCSRTYPES, &numberCursorTypes);
+ WTInfo(WTI_DEVICES + deviceId, DVC_FIRSTCSR, &firstCursorType);
+
+ retval = (*env)->NewObjectArray(env, numberCursorTypes, stringClass, NULL);
+
+ for(i=0;i<numberCursorTypes;i++) {
+ WTInfo(WTI_CURSORS + i + firstCursorType, CSR_NAME, name);
+ nameString = (*env)->NewStringUTF(env, name);
+ (*env)->SetObjectArrayElement(env, retval, i-firstCursorType, nameString);
+ }
+
+ return retval;
+}
+
+JNIEXPORT jint JNICALL Java_net_java_games_input_WinTabDevice_nGetMaxButtonCount(JNIEnv *env, jclass unused, jint deviceId) {
+ int numberCursorTypes;
+ int firstCursorType;
+ byte buttonCount;
+ int i;
+ byte retval=0;
+
+ WTInfo(WTI_DEVICES + deviceId, DVC_NCSRTYPES, &numberCursorTypes);
+ WTInfo(WTI_DEVICES + deviceId, DVC_FIRSTCSR, &firstCursorType);
+
+ for(i=0;i<numberCursorTypes;i++) {
+ WTInfo(WTI_CURSORS + i + firstCursorType, CSR_BUTTONS, &buttonCount);
+ if(buttonCount>retval) {
+ retval = buttonCount;
+ }
+ }
+
+ return (jint)retval;
+}