diff options
author | Sven Gothel <sgothel@jausoft.com> | 2011-10-15 07:34:06 +0200 |
---|---|---|
committer | Sven Gothel <sgothel@jausoft.com> | 2011-10-15 07:34:06 +0200 |
commit | 50dca7ef60f28711397d40d8daeb8a24dff41dc2 (patch) | |
tree | f9830fb69f82ffd6e162c462255f858a52914d0f /src/test/com/jogamp | |
parent | d7e47e58b5b33f3ead939d3c630ea13568dfe74c (diff) |
NEWT/Pointer Confined: Dispatch mouse move events before enabled; Only request-focus/warp-ptr if enabled
Dispatch mouse move events before enabled
- Allows user app listener to track to the new centered mouse position
before using the confined position. This is important for position change usage.
See simplified demo GearsES2
Only request-focus/warp-ptr if enabled
- No need to request focus and center mouse if leaving confinement
Demo GearsES2:
- No need to assume some position changes are erroneous (jumps)
due to confinement.
- Track unconfined mouse position, allowing confined navigation
to have the proper position change value
Diffstat (limited to 'src/test/com/jogamp')
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java | 54 |
1 files changed, 28 insertions, 26 deletions
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; } |