From: <eli...@us...> - 2006-10-26 15:03:55
|
Revision: 2607 http://svn.sourceforge.net/java-game-lib/?rev=2607&view=rev Author: elias_naur Date: 2006-10-26 08:03:47 -0700 (Thu, 26 Oct 2006) Log Message: ----------- Mac OS X: Moved registering and unregistering of AWT listeners from MacOSXDisplay to the input handlers Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/KeyboardEventQueue.java trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/KeyboardEventQueue.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/KeyboardEventQueue.java 2006-10-26 14:47:02 UTC (rev 2606) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/KeyboardEventQueue.java 2006-10-26 15:03:47 UTC (rev 2607) @@ -39,6 +39,7 @@ import java.awt.event.KeyEvent; import java.awt.event.KeyListener; +import java.awt.Component; import java.nio.ByteBuffer; import org.lwjgl.input.Keyboard; @@ -51,6 +52,8 @@ /** Event scratch array */ private final ByteBuffer event = ByteBuffer.allocate(Keyboard.EVENT_SIZE); + private final Component component; + static { KEY_MAP[KeyEvent.VK_0] = Keyboard.KEY_0; KEY_MAP[KeyEvent.VK_1] = Keyboard.KEY_1; @@ -238,10 +241,23 @@ KEY_MAP[KeyEvent.VK_Z] = Keyboard.KEY_Z; } - public KeyboardEventQueue() { + public KeyboardEventQueue(Component component) { super(Keyboard.EVENT_SIZE); + this.component = component; } + public void register() { + component.addKeyListener(this); + } + + public void unregister() { + /* + * This line is commented out to work around AWT bug 4867453: + * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4867453 + */ + //component.removeKeyListener(this); + } + private void putKeyboardEvent(int key_code, byte state, int character, long nanos) { event.clear(); event.putInt(key_code).put(state).putInt(character).putLong(nanos); Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2006-10-26 14:47:02 UTC (rev 2606) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2006-10-26 15:03:47 UTC (rev 2607) @@ -303,17 +303,13 @@ public void createMouse() throws LWJGLException { MacOSXGLCanvas canvas = frame.getCanvas(); - this.mouse_queue = new MouseEventQueue(canvas.getWidth(), canvas.getHeight()); - canvas.addMouseListener(mouse_queue); - canvas.addMouseMotionListener(mouse_queue); - canvas.addMouseWheelListener(mouse_queue); + this.mouse_queue = new MouseEventQueue(canvas); + mouse_queue.register(); } public void destroyMouse() { - MacOSXGLCanvas canvas = frame.getCanvas(); - canvas.removeMouseListener(mouse_queue); - canvas.removeMouseWheelListener(mouse_queue); - canvas.removeMouseMotionListener(mouse_queue); + if (mouse_queue != null) + mouse_queue.unregister(); this.mouse_queue = null; } @@ -359,17 +355,13 @@ /* Keyboard */ public void createKeyboard() throws LWJGLException { MacOSXGLCanvas canvas = frame.getCanvas(); - this.keyboard_queue = new KeyboardEventQueue(); - canvas.addKeyListener(keyboard_queue); + this.keyboard_queue = new KeyboardEventQueue(canvas); + keyboard_queue.register(); } public void destroyKeyboard() { - /* - * This line is commented out to work around AWT bug 4867453: - * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4867453 - */ -// frame.getCanvas().removeKeyListener(keyboard_queue); - + if (keyboard_queue != null) + keyboard_queue.unregister(); this.keyboard_queue = null; } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java 2006-10-26 14:47:02 UTC (rev 2606) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java 2006-10-26 15:03:47 UTC (rev 2607) @@ -32,8 +32,7 @@ package org.lwjgl.opengl; /** - * A java implementation of a LWJGL compatible Mouse event queue. - * Currently only used by the Mac OS X implementation. + * An AWT implementation of a LWJGL compatible Mouse event queue. * @author elias_naur */ @@ -42,6 +41,7 @@ import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; +import java.awt.Component; import java.nio.ByteBuffer; import java.nio.IntBuffer; @@ -52,8 +52,7 @@ private static final int WHEEL_SCALE = 120; public static final int NUM_BUTTONS = 3; - private final int width; - private final int height; + private final Component component; private boolean grabbed; @@ -77,13 +76,24 @@ /** Buttons array */ private final byte[] buttons = new byte[NUM_BUTTONS]; - MouseEventQueue(int width, int height) { + MouseEventQueue(Component component) { super(Mouse.EVENT_SIZE); - this.width = width; - this.height = height; + this.component = component; resetCursorToCenter(); } + public void register() { + component.addMouseListener(this); + component.addMouseMotionListener(this); + component.addMouseWheelListener(this); + } + + public void unregister() { + component.removeMouseListener(this); + component.removeMouseMotionListener(this); + component.removeMouseWheelListener(this); + } + public synchronized void setGrabbed(boolean grabbed) { this.grabbed = grabbed; resetCursorToCenter(); @@ -94,7 +104,7 @@ } private int transformY(int y) { - return height - 1 - y; + return component.getHeight() - 1 - y; } private void resetCursorToCenter() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |