diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/newt/classes/jogamp/newt/WindowImpl.java | 15 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java | 54 |
2 files changed, 40 insertions, 29 deletions
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index caa91fd7c..f0c351048 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -1358,12 +1358,21 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer if(this.pointerConfined != confine) { boolean setVal = 0 == getWindowHandle(); if(!setVal) { - requestFocus(); - warpPointer(width/2, height/2); + if(confine) { + requestFocus(); + warpPointer(width/2, height/2); + } setVal = confinePointerImpl(confine); + if(confine) { + // give time to deliver mouse movements w/o confinement, + // this allows user listener to sync previous position value to the new centered position + try { + Thread.sleep(3 * screen.getDisplay().getEDTUtil().getPollPeriod()); + } catch (InterruptedException e) { } + } } if(setVal) { - this.pointerConfined = confine; + this.pointerConfined = confine; } } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java index 7a536d332..594f427ca 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java @@ -297,6 +297,11 @@ public class GearsES2 implements GLEventListener { public void mouseMoved(MouseEvent e) { if(e.isConfined()) { navigate(e); + } else { + // track prev. position so we don't have 'jumps' + // in case we move to confined navigation. + prevMouseX = e.getX(); + prevMouseY = e.getY(); } } @@ -308,32 +313,29 @@ public class GearsES2 implements GLEventListener { int x = e.getX(); int y = e.getY(); - // skip 'jumps' due to confined mode .. - if(Math.abs(prevMouseX-x)<10 && Math.abs(prevMouseX-x)<10) { - int width, height; - Object source = e.getSource(); - Window window = null; - if(source instanceof Window) { - window = (Window) source; - width=window.getWidth(); - height=window.getHeight(); - } else if (GLProfile.isAWTAvailable() && source instanceof java.awt.Component) { - java.awt.Component comp = (java.awt.Component) source; - width=comp.getWidth(); - height=comp.getHeight(); - } else { - throw new RuntimeException("Event source neither Window nor Component: "+source); - } - final float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)width); - final float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)height); - view_rotx += thetaX; - view_roty += thetaY; - if(e.isConfined() && null!=window) { - x=window.getWidth()/2; - y=window.getHeight()/2; - window.warpPointer(x, y); - } - } + int width, height; + Object source = e.getSource(); + Window window = null; + if(source instanceof Window) { + window = (Window) source; + width=window.getWidth(); + height=window.getHeight(); + } else if (GLProfile.isAWTAvailable() && source instanceof java.awt.Component) { + java.awt.Component comp = (java.awt.Component) source; + width=comp.getWidth(); + height=comp.getHeight(); + } else { + throw new RuntimeException("Event source neither Window nor Component: "+source); + } + final float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)width); + final float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)height); + view_rotx += thetaX; + view_roty += thetaY; + if(e.isConfined() && null!=window) { + x=window.getWidth()/2; + y=window.getHeight()/2; + window.warpPointer(x, y); + } prevMouseX = x; prevMouseY = y; } |