From: <eli...@us...> - 2006-06-26 13:52:08
|
Revision: 2386 Author: elias_naur Date: 2006-06-26 06:50:48 -0700 (Mon, 26 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2386&view=rev Log Message: ----------- Windows: LWJGL didn't work well with jinput, but compatibility could be greatly improved if LWJGL used DirectInput 8 (like jinput). This can't be done unconditionally, since we need the DX3 support for older versions of windows. So, I've moved most Mouse and Keyboard stuff from native to java side and generalized DirectInput access through an abstract base class, with two concrete subclasses, one for dx3 and one for dx8. Modified Paths: -------------- trunk/LWJGL/build.xml trunk/LWJGL/platform_build/win32_ms_cmdline/build.bat trunk/LWJGL/src/java/org/lwjgl/BufferUtils.java trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java trunk/LWJGL/src/java/org/lwjgl/opengl/EventQueue.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java trunk/LWJGL/src/native/common/common_tools.c trunk/LWJGL/src/native/common/common_tools.h trunk/LWJGL/src/native/win32/LWJGL.c trunk/LWJGL/src/native/win32/Window.h trunk/LWJGL/src/native/win32/org_lwjgl_opengl_Display.c Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput3.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput8.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice3.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice8.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDeviceObjectCallback.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java trunk/LWJGL/src/native/win32/dinputhelper.c trunk/LWJGL/src/native/win32/dinputhelper.h trunk/LWJGL/src/native/win32/org_lwjgl_opengl_WindowsDirectInput3.c trunk/LWJGL/src/native/win32/org_lwjgl_opengl_WindowsDirectInput8.c trunk/LWJGL/src/native/win32/org_lwjgl_opengl_WindowsDirectInputDevice3.c trunk/LWJGL/src/native/win32/org_lwjgl_opengl_WindowsDirectInputDevice8.c trunk/LWJGL/src/native/win32/org_lwjgl_opengl_WindowsKeyboard.c Removed Paths: ------------- trunk/LWJGL/src/native/win32/org_lwjgl_input_Keyboard.c trunk/LWJGL/src/native/win32/org_lwjgl_input_Mouse.c Modified: trunk/LWJGL/build.xml =================================================================== --- trunk/LWJGL/build.xml 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/build.xml 2006-06-26 13:50:48 UTC (rev 2386) @@ -420,6 +420,11 @@ </javah> <javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/win32" force="yes"> + <class name="org.lwjgl.opengl.WindowsKeyboard" /> + <class name="org.lwjgl.opengl.WindowsDirectInput8" /> + <class name="org.lwjgl.opengl.WindowsDirectInputDevice8" /> + <class name="org.lwjgl.opengl.WindowsDirectInput3" /> + <class name="org.lwjgl.opengl.WindowsDirectInputDevice3" /> <class name="org.lwjgl.opengl.Win32PbufferPeerInfo" /> <class name="org.lwjgl.opengl.Win32Display" /> <class name="org.lwjgl.opengl.Win32Registry" /> Modified: trunk/LWJGL/platform_build/win32_ms_cmdline/build.bat =================================================================== --- trunk/LWJGL/platform_build/win32_ms_cmdline/build.bat 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/platform_build/win32_ms_cmdline/build.bat 2006-06-26 13:50:48 UTC (rev 2386) @@ -9,7 +9,7 @@ set COPTIONS=/Wp64 /I"%CHOME%\include" /I"%PLTSDKHOME%\include" /I"%DXSDK_DIR%\include" /I"%JAVA_HOME%\include" /I"%JAVA_HOME%\include\win32" /I"%ALHOME%\include" /I"..\..\src\native\common" /Ox /Ob2 /Oi /Ot /Oy /FD /EHsc /MT /Gy /W2 /nologo /c /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "LWJGL_EXPORTS" /D "_WINDLL" set LINKEROPTS=/link /LIBPATH:"%JAVA_HOME%\lib" /LIBPATH:"%ALHOME%\libs" /LIBPATH:"%DXSDK_DIR%\Lib\x86" /LIBPATH:"%PLTSDKHOME%\Lib" /LIBPATH:"%CHOME%\Lib" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /MACHINE:X86 /NOLOGO /DLL /DELAYLOAD:jawt.dll -set LIBS=Kernel32.lib dinput.lib dxguid.lib OpenGL32.Lib Version.lib user32.lib Gdi32.lib Advapi32.lib jawt.lib delayimp.lib winmm.lib +set LIBS=Kernel32.lib ole32.lib dinput.lib dxguid.lib OpenGL32.Lib Version.lib user32.lib Gdi32.lib Advapi32.lib jawt.lib delayimp.lib winmm.lib for %%x in (..\..\src\native\win32\*.c) do cl %COPTIONS% %%x for %%x in (..\..\src\native\common\*.c) do cl %COPTIONS% %%x Modified: trunk/LWJGL/src/java/org/lwjgl/BufferUtils.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/BufferUtils.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/BufferUtils.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -71,6 +71,16 @@ } /** + * Construct a direct native-order charbuffer with the specified number + * of elements. + * @param size The size, in chars + * @return an CharBuffer + */ + public static CharBuffer createCharBuffer(int size) { + return createByteBuffer(size << 1).asCharBuffer(); + } + + /** * Construct a direct native-order intbuffer with the specified number * of elements. * @param size The size, in ints @@ -81,10 +91,10 @@ } /** - * Construct a direct native-order intbuffer with the specified number + * Construct a direct native-order longbuffer with the specified number * of elements. - * @param size The size, in ints - * @return an IntBuffer + * @param size The size, in longs + * @return an LongBuffer */ public static LongBuffer createLongBuffer(int size) { return createByteBuffer(size << 3).asLongBuffer(); Modified: trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/input/Keyboard.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -348,7 +348,7 @@ private static void read() { readBuffer.compact(); - int numEvents = Display.getImplementation().readKeyboard(readBuffer, readBuffer.position()); + int numEvents = Display.getImplementation().readKeyboard(readBuffer); readBuffer.position(readBuffer.position() + numEvents*EVENT_SIZE); readBuffer.flip(); } Modified: trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -306,7 +306,7 @@ private static void read() { readBuffer.compact(); - int numEvents = Display.getImplementation().readMouse(readBuffer, readBuffer.position()); + int numEvents = Display.getImplementation().readMouse(readBuffer); readBuffer.position(readBuffer.position() + numEvents * EVENT_SIZE); readBuffer.flip(); } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -153,9 +153,8 @@ * * @return the total number of events read. */ - int readMouse(IntBuffer buffer, int buffer_position); + int readMouse(IntBuffer buffer); - void grabMouse(boolean grab); /** @@ -201,7 +200,7 @@ * Method to read the keyboard buffer * @return the total number of events read. */ - int readKeyboard(IntBuffer buffer, int buffer_position); + int readKeyboard(IntBuffer buffer); // int isStateKeySet(int key); Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/EventQueue.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/EventQueue.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/EventQueue.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -40,7 +40,7 @@ import java.nio.ByteBuffer; import java.nio.IntBuffer; -abstract class EventQueue { +class EventQueue { private static final int QUEUE_SIZE = 200; Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -513,10 +513,10 @@ } private static native void nPollMouse(IntBuffer coord_buffer, ByteBuffer buttons); - public int readMouse(IntBuffer buffer, int buffer_position) { + public int readMouse(IntBuffer buffer) { update(); lockAWT(); - int count = nReadMouse(buffer, buffer_position); + int count = nReadMouse(buffer, buffer.position()); unlockAWT(); return count; } @@ -616,10 +616,10 @@ } private static native void nPollKeyboard(ByteBuffer keyDownBuffer); - public int readKeyboard(IntBuffer buffer, int buffer_position) { + public int readKeyboard(IntBuffer buffer) { update(); lockAWT(); - int count = nReadKeyboard(buffer, buffer_position); + int count = nReadKeyboard(buffer, buffer.position()); unlockAWT(); return count; } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -321,8 +321,7 @@ mouse_queue.poll(coord_buffer, buttons_buffer); } - public int readMouse(IntBuffer buffer, int buffer_position) { - assert buffer_position == buffer.position(); + public int readMouse(IntBuffer buffer) { return mouse_queue.copyEvents(buffer); } @@ -408,8 +407,7 @@ keyboard_queue.poll(keyDownBuffer); } - public int readKeyboard(IntBuffer buffer, int buffer_position) { - assert buffer_position == buffer.position(); + public int readKeyboard(IntBuffer buffer) { return keyboard_queue.copyEvents(buffer); } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -48,9 +48,23 @@ final class Win32Display implements DisplayImplementation { private final static int GAMMA_LENGTH = 256; + private final static int WM_MOUSEMOVE = 0x0200; + private final static int WM_LBUTTONDOWN = 0x0201; + private final static int WM_LBUTTONUP = 0x0202; + private final static int WM_LBUTTONDBLCLK = 0x0203; + private final static int WM_RBUTTONDOWN = 0x0204; + private final static int WM_RBUTTONUP = 0x0205; + private final static int WM_RBUTTONDBLCLK = 0x0206; + private final static int WM_MBUTTONDOWN = 0x0207; + private final static int WM_MBUTTONUP = 0x0208; + private final static int WM_MBUTTONDBLCLK = 0x0209; + private final static int WM_MOUSEWHEEL = 0x020A; private static Win32DisplayPeerInfo peer_info; + private static WindowsKeyboard keyboard; + private static WindowsMouse mouse; + public void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException { nCreateWindow(mode, fullscreen, x, y); peer_info.initDC(); @@ -126,47 +140,70 @@ public native DisplayMode[] getAvailableDisplayModes() throws LWJGLException; /* Mouse */ - public native boolean hasWheel(); - public native int getButtonCount(); - public native void createMouse() throws LWJGLException; - public native void destroyMouse(); + public boolean hasWheel() { + return mouse.hasWheel(); + } + + public int getButtonCount() { + return mouse.getButtonCount(); + } + + public void createMouse() throws LWJGLException { + mouse = new WindowsMouse(createDirectInput(), getHwnd()); + } + + public void destroyMouse() { + mouse.destroy(); + mouse = null; + } + public void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons) { update(); - nPollMouse(coord_buffer, buttons); + mouse.poll(coord_buffer, buttons); } - private native void nPollMouse(IntBuffer coord_buffer, ByteBuffer buttons); - public int readMouse(IntBuffer buffer, int buffer_position) { + public int readMouse(IntBuffer buffer) { update(); - return nReadMouse(buffer, buffer_position); + return mouse.read(buffer); } - private native int nReadMouse(IntBuffer buffer, int buffer_position); - public native void grabMouse(boolean grab); + public void grabMouse(boolean grab) { + mouse.grab(grab); + } + public int getNativeCursorCapabilities() { return Cursor.CURSOR_ONE_BIT_TRANSPARENCY; } public native void setCursorPosition(int x, int y); + public native void setNativeCursor(Object handle) throws LWJGLException; + public native int getMinCursorSize(); public native int getMaxCursorSize(); + private static native long getDllInstance(); + private static native long getHwnd(); + /* Keyboard */ - public native void createKeyboard() throws LWJGLException; - public native void destroyKeyboard(); + public void createKeyboard() throws LWJGLException { + keyboard = new WindowsKeyboard(createDirectInput(), getHwnd()); + } + + public void destroyKeyboard() { + keyboard.destroy(); + keyboard = null; + } public void pollKeyboard(ByteBuffer keyDownBuffer) { update(); - nPollKeyboard(keyDownBuffer); + keyboard.poll(keyDownBuffer); } - private native void nPollKeyboard(ByteBuffer keyDownBuffer); - public int readKeyboard(IntBuffer buffer, int buffer_position) { + public int readKeyboard(IntBuffer buffer) { update(); - return nReadKeyboard(buffer, buffer_position); + return keyboard.read(buffer); } - private native int nReadKeyboard(IntBuffer buffer, int buffer_position); // public native int isStateKeySet(int key); @@ -249,4 +286,64 @@ private static native int nSetWindowIcon16(IntBuffer icon); private static native int nSetWindowIcon32(IntBuffer icon); + + private static void handleMouseButton(int button, int state) { + if (mouse != null) + mouse.handleMouseButton(button, state); + } + + private static void handleMouseMoved(int x, int y) { + if (mouse != null) + mouse.handleMouseMoved(x, y); + } + + private static void handleMouseScrolled(int amount) { + if (mouse != null) + mouse.handleMouseScrolled(amount); + } + + private static native int transformY(long hwnd, int y); + + private static boolean handleMessage(long hwnd, int msg, long wParam, long lParam) { + switch (msg) { + case WM_MOUSEMOVE: + int xPos = (int)(short)(lParam & 0xFFFF); + int yPos = transformY(getHwnd(), (int)(short)((lParam >> 16) & 0xFFFF)); + handleMouseMoved(xPos, yPos); + return true; + case WM_MOUSEWHEEL: + int dwheel = (int)(short)((wParam >> 16) & 0xFFFF); + handleMouseScrolled(dwheel); + return true; + case WM_LBUTTONDOWN: + handleMouseButton(0, 1); + return true; + case WM_LBUTTONUP: + handleMouseButton(0, 0); + return true; + case WM_RBUTTONDOWN: + handleMouseButton(1, 1); + return true; + case WM_RBUTTONUP: + handleMouseButton(1, 0); + return true; + case WM_MBUTTONDOWN: + handleMouseButton(2, 1); + return true; + case WM_MBUTTONUP: + handleMouseButton(2, 0); + return true; + default: + return false; + } + } + + private static WindowsDirectInput createDirectInput() throws LWJGLException { + try { + return new WindowsDirectInput8(getDllInstance()); + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to create DirectInput 8 interface, falling back to DirectInput 3"); + return new WindowsDirectInput3(getDllInstance()); + } + } } Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the DirectInput base class + * @author elias_naur + */ + +import org.lwjgl.LWJGLException; + +abstract class WindowsDirectInput { + public final static int KEYBOARD_TYPE = 1; + public final static int MOUSE_TYPE = 2; + + /* DirectInput constants */ + public final static int DI_OK = 0x00000000; + public final static int DI_NOEFFECT = 0x00000001; + public final static int DI_PROPNOEFFECT = 0x00000001; + + public final static int DI_DOWNLOADSKIPPED = 0x00000003; + public final static int DI_EFFECTRESTARTED = 0x00000004; + public final static int DI_TRUNCATED = 0x00000008; + public final static int DI_SETTINGSNOTSAVED = 0x0000000B; + public final static int DI_TRUNCATEDANDRESTARTED = 0x0000000C; + + public final static int DI_BUFFEROVERFLOW = 0x00000001; + public final static int DIERR_INPUTLOST = 0x8007001E; + public final static int DIERR_NOTACQUIRED = 0x8007001C; + public final static int DIERR_OTHERAPPHASPRIO = 0x80070005; + + private final long di_interface; + + public WindowsDirectInput(long hinst) throws LWJGLException { + di_interface = createDirectInput(hinst); + } + protected abstract long createDirectInput(long hinst) throws LWJGLException; + + public WindowsDirectInputDevice createDevice(int type) throws LWJGLException { + return createDevice(di_interface, type); + } + protected abstract WindowsDirectInputDevice createDevice(long di_interface, int type) throws LWJGLException; + + public void release() { + release(di_interface); + } + protected abstract void release(long di_interface); +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput3.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput3.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput3.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the DirectInput3 interface + * @author elias_naur + */ + +import org.lwjgl.LWJGLException; + +final class WindowsDirectInput3 extends WindowsDirectInput { + /* Re-define device types to get them included in the native headers */ + public final static int KEYBOARD_TYPE = WindowsDirectInput.KEYBOARD_TYPE; + public final static int MOUSE_TYPE = WindowsDirectInput.MOUSE_TYPE; + + public WindowsDirectInput3(long hinst) throws LWJGLException { + super(hinst); + } + + protected native long createDirectInput(long hinst) throws LWJGLException; + + protected WindowsDirectInputDevice createDevice(long di_interface, int type) throws LWJGLException { + long device = nCreateDevice(di_interface, type); + return new WindowsDirectInputDevice3(device); + } + private static native long nCreateDevice(long di_interface, int type) throws LWJGLException; + + protected native void release(long di_interface); +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput3.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput8.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput8.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput8.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the DirectInput8 interface + * @author elias_naur + */ + +import org.lwjgl.LWJGLException; + +final class WindowsDirectInput8 extends WindowsDirectInput { + /* Re-define device types to get them included in the native headers */ + public final static int KEYBOARD_TYPE = WindowsDirectInput.KEYBOARD_TYPE; + public final static int MOUSE_TYPE = WindowsDirectInput.MOUSE_TYPE; + + public WindowsDirectInput8(long hinst) throws LWJGLException { + super(hinst); + } + + protected native long createDirectInput(long hinst) throws LWJGLException; + + protected WindowsDirectInputDevice createDevice(long di_interface, int type) throws LWJGLException { + long device = nCreateDevice(di_interface, type); + return new WindowsDirectInputDevice8(device); + } + private static native long nCreateDevice(long di_interface, int type) throws LWJGLException; + + protected native void release(long di_interface); +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInput8.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the DirectInputDevice interface + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import org.lwjgl.LWJGLException; +import org.lwjgl.BufferUtils; + +abstract class WindowsDirectInputDevice { + public final static int DISCL_EXCLUSIVE = 0x00000001; + public final static int DISCL_NONEXCLUSIVE = 0x00000002; + public final static int DISCL_FOREGROUND = 0x00000004; + public final static int DISCL_BACKGROUND = 0x00000008; + public final static int DISCL_NOWINKEY = 0x00000010; + + public final static int GUID_XAxis = 1; + public final static int GUID_YAxis = 2; + public final static int GUID_ZAxis = 3; + public final static int GUID_Button = 4; + public final static int GUID_Unknown = 5; + + private final long di_device; + private ByteBuffer event_buffer; + + public WindowsDirectInputDevice(long di_device) { + this.di_device = di_device; + } + + public void release() { + release(di_device); + } + protected abstract void release(long di_device); + + public int poll() { + return poll(di_device); + } + protected abstract int poll(long di_device); + + public void setDataFormat(int type) throws LWJGLException { + int ret = setDataFormat(di_device, type); + if (ret != WindowsDirectInput.DI_OK) + throw new LWJGLException("Failed to set data format (" + ret + ")"); + } + protected abstract int setDataFormat(long di_device, int type); + + public void setCooperateLevel(long hwnd, int flags) throws LWJGLException { + int ret = setCooperativeLevel(di_device, hwnd, flags); + if (ret != WindowsDirectInput.DI_OK) + throw new LWJGLException("Failed to set cooperative level (" + ret + ")"); + } + protected abstract int setCooperativeLevel(long di_device, long hwnd, int flags); + + public int acquire() { + return acquire(di_device); + } + protected abstract int acquire(long di_device); + + public void setBufferSize(int buffer_size) throws LWJGLException { + int ret = setBufferSize(di_device, buffer_size); + if (ret != WindowsDirectInput.DI_OK) + throw new LWJGLException("Failed to set buffer size (" + ret + ")"); + int event_buffer_size = getEventSize()*buffer_size; + event_buffer = BufferUtils.createByteBuffer(event_buffer_size); + } + protected abstract int setBufferSize(long di_device, int buffer_size); + + public int getDeviceData(IntBuffer buffer) { + int events_remaining = buffer.remaining()/2; + if (event_buffer == null || events_remaining > event_buffer.remaining()/getEventSize()) + event_buffer = BufferUtils.createByteBuffer(events_remaining*getEventSize()); + return getDeviceData(di_device, event_buffer, event_buffer.capacity(), buffer, buffer.position(), buffer.remaining()); + } + protected abstract int getDeviceData(long di_device, ByteBuffer event_buffer, int event_buffer_size, IntBuffer buffer, int position, int size); + + /** + * Device data is returned in tuples of the form <dwOfs, dwData>. + * buffer position() is moved accordingly to number of events. + */ + public int getDeviceState(ByteBuffer buffer) { + return getDeviceState(di_device, buffer, buffer.position(), buffer.remaining()); + } + protected abstract int getDeviceState(long di_device, ByteBuffer buffer, int position, int size); + + public void unacquire() { + unacquire(di_device); + } + protected abstract int unacquire(long di_device); + + public int enumObjects(WindowsDirectInputDeviceObjectCallback enumerator) { + return enumObjects(di_device, enumerator); + } + protected abstract int enumObjects(long di_device, WindowsDirectInputDeviceObjectCallback enumerator); + + protected abstract int getEventSize(); +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice3.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice3.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice3.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the DirectInputDevice3 interface + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import org.lwjgl.LWJGLException; + +final class WindowsDirectInputDevice3 extends WindowsDirectInputDevice { + /** Re-declare to get the constants into the native headers */ + public final static int GUID_XAxis = WindowsDirectInputDevice.GUID_XAxis; + public final static int GUID_YAxis = WindowsDirectInputDevice.GUID_YAxis; + public final static int GUID_ZAxis = WindowsDirectInputDevice.GUID_ZAxis; + public final static int GUID_Button = WindowsDirectInputDevice.GUID_Button; + public final static int GUID_Unknown = WindowsDirectInputDevice.GUID_Unknown; + + public WindowsDirectInputDevice3(long di_device) { + super(di_device); + } + + protected native int setDataFormat(long di_device, int type); + + protected native int setCooperativeLevel(long di_device, long hwnd, int flags); + + protected native int acquire(long di_device); + + protected native int getDeviceState(long di_device, ByteBuffer buffer, int position, int size); + + protected native int getDeviceData(long di_device, ByteBuffer event_buffer, int event_buffer_size, IntBuffer buffer, int position, int size); + + protected native int unacquire(long di_device); + + protected int poll(long di_device) { + return WindowsDirectInput.DI_OK; + } + + protected native int setBufferSize(long di_device, int buffer_size); + protected native int getEventSize(); + + protected native void release(long di_device); + + protected native int enumObjects(long di_device, WindowsDirectInputDeviceObjectCallback enumerator); +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice3.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice8.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice8.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice8.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the DirectInputDevice3 interface + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import org.lwjgl.LWJGLException; + +final class WindowsDirectInputDevice8 extends WindowsDirectInputDevice { + /** Re-declare to get the constants into the native headers */ + public final static int GUID_XAxis = WindowsDirectInputDevice.GUID_XAxis; + public final static int GUID_YAxis = WindowsDirectInputDevice.GUID_YAxis; + public final static int GUID_ZAxis = WindowsDirectInputDevice.GUID_ZAxis; + public final static int GUID_Button = WindowsDirectInputDevice.GUID_Button; + public final static int GUID_Unknown = WindowsDirectInputDevice.GUID_Unknown; + + public WindowsDirectInputDevice8(long di_device) { + super(di_device); + } + + protected native int setDataFormat(long di_device, int type); + + protected native int setCooperativeLevel(long di_device, long hwnd, int flags); + + protected native int acquire(long di_device); + + protected native int getDeviceState(long di_device, ByteBuffer buffer, int position, int size); + + protected native int getDeviceData(long di_device, ByteBuffer event_buffer, int event_buffer_size, IntBuffer buffer, int position, int size); + + protected native int unacquire(long di_device); + + protected native int poll(long di_device); + + protected native int setBufferSize(long di_device, int buffer_size); + protected native int getEventSize(); + + protected native void release(long di_device); + + protected native int enumObjects(long di_device, WindowsDirectInputDeviceObjectCallback enumerator); +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDevice8.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDeviceObjectCallback.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDeviceObjectCallback.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDeviceObjectCallback.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the DirectInputDevice callback interface + * @author elias_naur + */ + +interface WindowsDirectInputDeviceObjectCallback { + public boolean nextObject(int type, String name); +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputDeviceObjectCallback.java ___________________________________________________________________ Name: svn:executable + * Copied: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java (from rev 2382, trunk/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java) =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the Windows implementation of the Keyboard. + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.CharBuffer; + +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; +import org.lwjgl.BufferUtils; + +final class WindowsKeyboard { + private final static int BUFFER_SIZE = 50; + + private final WindowsDirectInput dinput; + private final WindowsDirectInputDevice keyboard; + private final IntBuffer temp_data_buffer; + private final ByteBuffer keyboard_state; + private final CharBuffer unicode_buffer; + + public WindowsKeyboard(WindowsDirectInput dinput, long hwnd) throws LWJGLException { + this.dinput = dinput; + try { + keyboard = dinput.createDevice(WindowsDirectInput.KEYBOARD_TYPE); + try { + keyboard.setCooperateLevel(hwnd, WindowsDirectInputDevice.DISCL_NONEXCLUSIVE | WindowsDirectInputDevice.DISCL_FOREGROUND); + keyboard.setDataFormat(WindowsDirectInput.KEYBOARD_TYPE); + keyboard.setBufferSize(BUFFER_SIZE); + } catch (LWJGLException e) { + keyboard.release(); + throw e; + } + } catch (LWJGLException e) { + dinput.release(); + throw e; + } + keyboard.acquire(); + temp_data_buffer = BufferUtils.createIntBuffer(BUFFER_SIZE*2); + keyboard_state = BufferUtils.createByteBuffer(256); + unicode_buffer = BufferUtils.createCharBuffer(BUFFER_SIZE); + } + + public void destroy() { + keyboard.unacquire(); + keyboard.release(); + dinput.release(); + } + + public void poll(ByteBuffer keyDownBuffer) { + int ret = keyboard.acquire(); + if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT) + return; + keyboard.poll(); + ret = keyboard.getDeviceState(keyDownBuffer); + switch (ret) { + case WindowsDirectInput.DI_OK: + break; + case WindowsDirectInput.DI_BUFFEROVERFLOW: + LWJGLUtil.log("Keyboard buffer overflow"); + break; + case WindowsDirectInput.DIERR_INPUTLOST: + break; + case WindowsDirectInput.DIERR_NOTACQUIRED: + break; + default: + LWJGLUtil.log("Failed to poll keyboard (0x" + Integer.toHexString(ret) + ")"); + break; + } + } + + private int translateData(IntBuffer src, IntBuffer dst) { + int dst_index = dst.position(); + int num_events = 0; + while (dst_index < dst.limit() && src.hasRemaining()) { + num_events++; + int dwOfs = src.get(); + dst.put(dst_index++, dwOfs); + int dwData = src.get(); + dst.put(dst_index++, dwData); + boolean key_down = (dwData & 0x80) != 0; + if (key_down) { + int virt_key = MapVirtualKey(dwOfs, 1); + if (virt_key != 0 && GetKeyboardState(keyboard_state) != 0) { + // Mark key down in the scan code + dwOfs = dwOfs & 0x7fff; + unicode_buffer.clear(); + int num_chars = ToUnicode(virt_key, + dwOfs, + keyboard_state, + unicode_buffer, + unicode_buffer.capacity(), 0); + if (num_chars > 0) { + int current_char = 0; + do { + if (current_char >= 1) { + num_events++; + dst.put(dst_index++, 0); + dst.put(dst_index++, 0); + } + int char_int = ((int)unicode_buffer.get()) & 0xFFFF; + dst.put(dst_index++, char_int); + current_char++; + } while (dst_index < dst.limit() && current_char < num_chars); + } else { + dst.put(dst_index++, 0); + } + } else { + dst.put(dst_index++, 0); + } + } else + dst.put(dst_index++, 0); + } + return num_events; + } + private static native int MapVirtualKey(int uCode, int uMapType); + private static native int ToUnicode(int wVirtKey, int wScanCode, ByteBuffer lpKeyState, CharBuffer pwszBuff, int cchBuff, int flags); + private static native int GetKeyboardState(ByteBuffer lpKeyState); + + public int read(IntBuffer buffer) { + int ret = keyboard.acquire(); + if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT) + return 0; + keyboard.poll(); + temp_data_buffer.clear(); + ret = keyboard.getDeviceData(temp_data_buffer); + switch (ret) { + case WindowsDirectInput.DI_OK: + break; + case WindowsDirectInput.DI_BUFFEROVERFLOW: + LWJGLUtil.log("Keyboard buffer overflow"); + break; + case WindowsDirectInput.DIERR_INPUTLOST: + break; + case WindowsDirectInput.DIERR_NOTACQUIRED: + break; + default: + LWJGLUtil.log("Failed to read keyboard (0x" + Integer.toHexString(ret) + ")"); + break; + } + temp_data_buffer.flip(); + return translateData(temp_data_buffer, buffer); + } +} Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java 2006-06-26 13:50:48 UTC (rev 2386) @@ -0,0 +1,341 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl.opengl; + +/** + * This is the Windows implementation of the Mouse. + * @author elias_naur + */ + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.CharBuffer; + +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; +import org.lwjgl.BufferUtils; + +final class WindowsMouse { + private final static int BUFFER_SIZE = 50; + private final static int BUTTON_STATES_SIZE = 7; + private final static int MOUSE_EVENT_SIZE = 5; + + private final static int DIMOFS_X = 0; + private final static int DIMOFS_Y = 4; + private final static int DIMOFS_Z = 8; + private final static int DIMOFS_BUTTON0 = 12; + private final static int DIMOFS_BUTTON1 = 13; + private final static int DIMOFS_BUTTON2 = 14; + private final static int DIMOFS_BUTTON3 = 15; + + private final long hwnd; + private final WindowsDirectInput dinput; + private final WindowsDirectInputDevice mouse; + + private final int mouse_button_count; + private final boolean has_wheel; + + private final EventQueue event_queue = new EventQueue(MOUSE_EVENT_SIZE); + /* Buffer to hold a DIMOUSESTATE */ + private final ByteBuffer mouse_state; + private final IntBuffer temp_data_buffer; + + private final int[] mouse_event = new int[MOUSE_EVENT_SIZE]; + + private boolean mouse_grabbed; + private byte[] win32_message_button_states = new byte[BUTTON_STATES_SIZE]; + private int accum_dwheel; + private int last_x; + private int last_y; + + public WindowsMouse(WindowsDirectInput dinput, long hwnd) throws LWJGLException { + this.hwnd = hwnd; + this.dinput = dinput; + try { + mouse = dinput.createDevice(WindowsDirectInput.MOUSE_TYPE); + try { + mouse.setDataFormat(WindowsDirectInput.MOUSE_TYPE); + mouse.setBufferSize(BUFFER_SIZE); + if (!acquireNonExclusive()) + throw new LWJGLException("Failed to acquire mouse non-exclusive"); + } catch (LWJGLException e) { + mouse.release(); + throw e; + } + } catch (LWJGLException e) { + dinput.release(); + throw e; + } + MouseEnumerator enumerator = new MouseEnumerator(); + mouse.enumObjects(enumerator); + this.mouse_button_count = Math.min(enumerator.getButtonCount(), 4); + this.has_wheel = enumerator.hasWheel(); + mouse_state = BufferUtils.createByteBuffer(3*4 + 4); + temp_data_buffer = BufferUtils.createIntBuffer(BUFFER_SIZE*2); + } + + public boolean hasWheel() { + return has_wheel; + } + + public int getButtonCount() { + return mouse_button_count; + } + + private boolean acquire(int flags) { + try { + mouse.setCooperateLevel(hwnd, flags); + mouse.acquire(); + return true; + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to acquire mouse: " + e); + return false; + } + } + + private boolean acquireNonExclusive() { + return acquire(WindowsDirectInputDevice.DISCL_NONEXCLUSIVE | WindowsDirectInputDevice.DISCL_FOREGROUND) || + acquire(WindowsDirectInputDevice.DISCL_NONEXCLUSIVE | WindowsDirectInputDevice.DISCL_BACKGROUND); + } + + public void destroy() { + mouse.unacquire(); + mouse.release(); + dinput.release(); + } + + public void poll(IntBuffer coord_buffer, ByteBuffer buttons) { + int ret = mouse.acquire(); + if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT) + return; + mouse.poll(); + for (int i = 0; i < coord_buffer.remaining(); i++) + coord_buffer.put(coord_buffer.position() + i, 0); + mouse_state.clear(); + ret = mouse.getDeviceState(mouse_state); + int mouse_state_lx = mouse_state.getInt(); + int mouse_state_ly = mouse_state.getInt(); + int mouse_state_lz = mouse_state.getInt(); + int num_buttons = mouse_button_count; + if (mouse_grabbed || ret == WindowsDirectInput.DI_OK) { + if (ret != WindowsDirectInput.DI_OK) { + LWJGLUtil.log("Error getting mouse state: (0x" + Integer.toHexString(ret) + ")"); + return; + } + + coord_buffer.put(coord_buffer.position() + 2, mouse_state_lz); + if (num_buttons > buttons.remaining()) + num_buttons = buttons.remaining(); + for (int j = 0; j < num_buttons; j++) { + byte button_state = (mouse_state.get() & 0x80) != 0 ? (byte)1 : (byte)0; + buttons.put(buttons.position() + j, button_state); + // track the button state in the windows message buffer state array + // to get accurate button information when releasing a grab + win32_message_button_states[j] = button_state; + } + } else { + coord_buffer.put(coord_buffer.position() + 2, accum_dwheel); + if (num_buttons > win32_message_button_states.length) + num_buttons = win32_message_button_states.length; + for (int j = 0; j < num_buttons; j++) { + buttons.put(buttons.position() + j, win32_message_button_states[j]); + } + } + accum_dwheel = 0; + if (mouse_grabbed) { + coord_buffer.put(coord_buffer.position() + 0, mouse_state_lx); + coord_buffer.put(coord_buffer.position() + 1, -mouse_state_ly); + } else { + coord_buffer.put(coord_buffer.position() + 0, last_x); + coord_buffer.put(coord_buffer.position() + 1, last_y); + } + } + + private boolean putMouseEventWithCoords(int button, int state, int coord1, int coord2, int dz) { + mouse_event[0] = button; + mouse_event[1] = state; + mouse_event[2] = coord1; + mouse_event[3] = coord2; + mouse_event[4] = dz; + return event_queue.putEvent(mouse_event); + } + + private boolean putMouseEvent(int button, int state, int dz) { + if (mouse_grabbed) + return putMouseEventWithCoords(button, state, 0, 0, dz); + else + return putMouseEventWithCoords(button, state, last_x, last_y, dz); + } + + private void copyDXEvents(IntBuffer buffer) { + int buffer_index = 0; + int dx = 0, dy = 0, dwheel = 0; + int button_state; + int i; + while (buffer.hasRemaining()) { + int dwOfs = buffer.get(); + int dwData = buffer.get(); + button_state = (dwData & 0x80) != 0 ? 1 : 0; + switch (dwOfs) { + case DIMOFS_BUTTON0: + putMouseEventWithCoords(0, button_state, dx, -dy, dwheel); + dx = dy = dwheel = 0; + break; + case DIMOFS_BUTTON1: + putMouseEventWithCoords(1, button_state, dx, -dy, dwheel); + dx = dy = dwheel = 0; + break; + case DIMOFS_BUTTON2: + putMouseEventWithCoords(2, button_state, dx, -dy, dwheel); + dx = dy = dwheel = 0; + break; + case DIMOFS_BUTTON3: + putMouseEventWithCoords(3, button_state, dx, -dy, dwheel); + dx = dy = dwheel = 0; + break; + case DIMOFS_X: + dx += dwData; + break; + case DIMOFS_Y: + dy += dwData; + break; + case DIMOFS_Z: + dwheel += dwData; + break; + } + } + if (dx != 0 || dy != 0 || dwheel != 0) + putMouseEventWithCoords(-1, 0, dx, -dy, dwheel); + } + + private void readDXBuffer() { + int ret = mouse.acquire(); + if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT) + return; + mouse.poll(); + temp_data_buffer.clear(); + ret = mouse.getDeviceData(temp_data_buffer); + + if (ret == WindowsDirectInput.DI_OK) { + if (mouse_grabbed) { + temp_data_buffer.flip(); + copyDXEvents(temp_data_buffer); + } + } else if (ret == WindowsDirectInput.DI_BUFFEROVERFLOW) { + LWJGLUtil.log("Mouse buffer overflowed"); + } else if (ret == WindowsDirectInput.DIERR_INPUTLOST) { + LWJGLUtil.log("Mouse input lost"); + } else if (ret == WindowsDirectInput.DIERR_NOTACQUIRED) { + LWJGLUtil.log("Mouse not acquired"); + } else { + LWJGLUtil.log("unknown mouse error (" + Integer.toHexString(ret) + ")"); + } + } + + public int read(IntBuffer buffer) { + readDXBuffer(); + return event_queue.copyEvents(buffer); + } + + public void grab(boolean grab) { + if(grab) { + if (!mouse_grabbed) { + // flush DX event buffer + readDXBuffer(); + mouse_grabbed = true; + mouse.unacquire(); + if (!acquire(WindowsDirectInputDevice.DISCL_EXCLUSIVE | WindowsDirectInputDevice.DISCL_FOREGROUND)) + LWJGLUtil.log("Failed to reset cooperative mode"); + } + } else { + if (mouse_grabbed) { + mouse_grabbed = false; + mouse.unacquire(); + acquireNonExclusive(); + } + } + event_queue.clearEvents(); + } + + public void handleMouseScrolled(int event_dwheel) { + accum_dwheel += event_dwheel; + putMouseEvent(-1, 0, event_dwheel); + } + + public void handleMouseMoved(int x, int y) { + int dx; + int dy; + dx = x - last_x; + dy = y - last_y; + last_x = x; + last_y = y; + if (mouse_grabbed) { + putMouseEventWithCoords(-1, 0, dx, dy, 0); + } else { + putMouseEventWithCoords(-1, 0, x, y, 0); + } + } + + public void handleMouseButton(int button, int state) { + putMouseEvent(button, state, 0); + if (button < BUTTON_STATES_SIZE) + win32_message_button_states[button] = state != 0 ? (byte)1 : (byte)0; + } + + private static class MouseEnumerator implements WindowsDirectInputDeviceObjectCallback { + private int button_count; + private boolean has_wheel; + + public int getButtonCount() { + return button_count; + } + + public boolean hasWheel() { + return has_wheel; + } + + public boolean nextObject(int type, String name) { + LWJGLUtil.log("Found mouse object: " + name); + switch (type) { + case WindowsDirectInputDevice.GUID_ZAxis: + has_wheel = true; + break; + case WindowsDirectInputDevice.GUID_Button: + button_count++; + break; + default: + break; + } + return true; + } + } +} Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java ___________________________________________________________________ Name: svn:executable + * Modified: trunk/LWJGL/src/native/common/common_tools.c =================================================================== --- trunk/LWJGL/src/native/common/common_tools.c 2006-06-23 16:45:21 UTC (rev 2385) +++ trunk/LWJGL/src/native/common/common_tools.c 2006-06-26 13:50:48 UTC (rev 2386) @@ -97,12 +97,16 @@ jclass org_lwjgl_LWJGLUtil_class; jmethodID log_method; va_list ap; - if (isDebugEnabled()) { + if (isDebugEnabled() && !(*env)->ExceptionOccurred(env)) { va_start(ap, format);... [truncated message content] |