From: <eli...@us...> - 2006-10-27 06:05:03
|
Revision: 2614 http://svn.sourceforge.net/java-game-lib/?rev=2614&view=rev Author: elias_naur Date: 2006-10-26 23:04:55 -0700 (Thu, 26 Oct 2006) Log Message: ----------- Made the AWT setCursorPosition garbage free Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/AWTUtil.java trunk/LWJGL/src/java/org/lwjgl/opengl/AbstractAWTInput.java trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/AWTUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/AWTUtil.java 2006-10-26 21:39:37 UTC (rev 2613) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/AWTUtil.java 2006-10-27 06:04:55 UTC (rev 2614) @@ -92,18 +92,25 @@ } } - public static void setCursorPosition(final Component component, int x, int y) { + public static Robot createRobot(final Component component) { try { Robot robot = (Robot)AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws Exception { return new Robot(component.getGraphicsConfiguration().getDevice()); } }); + return robot; + } catch (PrivilegedActionException e) { + LWJGLUtil.log("Got exception while creating robot: " + e.getCause()); + return null; + } + } + + public static void setCursorPosition(Component component, Robot robot, int x, int y) { + if (robot != null) { int transformed_x = component.getX() + x; int transformed_y = component.getY() + component.getHeight() - 1 - y; robot.mouseMove(transformed_x, transformed_y); - } catch (PrivilegedActionException e) { - LWJGLUtil.log("Got exception while setting mouse cursor position: " + e); } } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/AbstractAWTInput.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/AbstractAWTInput.java 2006-10-26 21:39:37 UTC (rev 2613) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/AbstractAWTInput.java 2006-10-27 06:04:55 UTC (rev 2614) @@ -38,6 +38,7 @@ import org.lwjgl.LWJGLUtil; import java.awt.Cursor; +import java.awt.Robot; /** * @@ -47,6 +48,7 @@ */ abstract class AbstractAWTInput implements AWTCanvasInputImplementation { private AWTGLCanvas canvas; + private Robot robot; private KeyboardEventQueue keyboard_queue; private MouseEventQueue mouse_queue; @@ -54,6 +56,7 @@ protected AbstractAWTInput(AWTGLCanvas canvas) { this.canvas = canvas; + this.robot = AWTUtil.createRobot(canvas); } protected synchronized MouseEventQueue getMouseEventQueue() { @@ -117,7 +120,7 @@ } public void setCursorPosition(int x, int y) { - AWTUtil.setCursorPosition(canvas, x, y); + AWTUtil.setCursorPosition(canvas, robot, x, y); } public void setNativeCursor(Object handle) throws LWJGLException { Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2006-10-26 21:39:37 UTC (rev 2613) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2006-10-27 06:04:55 UTC (rev 2614) @@ -69,6 +69,7 @@ private static final int GAMMA_LENGTH = 256; private MacOSXFrame frame; + private Robot robot; private MacOSXMouseEventQueue mouse_queue; private KeyboardEventQueue keyboard_queue; private java.awt.DisplayMode requested_mode; @@ -85,6 +86,7 @@ close_requested = false; try { frame = new MacOSXFrame(mode, requested_mode, fullscreen, x, y); + robot = AWTUtil.createRobot(frame); } catch (LWJGLException e) { destroyWindow(); throw e; @@ -319,7 +321,7 @@ } public void setCursorPosition(int x, int y) { - AWTUtil.setCursorPosition(frame, x, y); + AWTUtil.setCursorPosition(frame, robot, x, y); } public void setNativeCursor(Object handle) throws LWJGLException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |