summaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp/opengl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-10-11 02:11:02 +0200
committerSven Gothel <[email protected]>2011-10-11 02:11:02 +0200
commitbdf1876f0fd654be02a9441e3dca7cfd7df26d58 (patch)
treefd5aeb5634f30114f6c12d25bcaad45e77d05c94 /src/test/com/jogamp/opengl
parent565d148d70bac0059b4bd057330b675248f43fe5 (diff)
NEWT Pointer Mods: Propagate 'confined' and 'invisible' to modifier mask of InputEvent (Mouse) ; Test confined navigation w/ GearsES2
InputEvent adds new MASK values: CONFINED_MASK and INVISIBLE_MASK, set at event creation allowing convenient testing of these mods. GearsES2 demonstrates the confined navigation testing the CONFINED_MASK and if having his mode acting on mouseMoved(..) and reset the mouse position.
Diffstat (limited to 'src/test/com/jogamp/opengl')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java58
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java2
2 files changed, 39 insertions, 21 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 a2e470617..7a536d332 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
@@ -269,7 +269,7 @@ public class GearsES2 implements GLEventListener {
pmvMatrix.glPopMatrix();
st.useProgram(gl, false);
}
-
+
class GearsKeyAdapter extends KeyAdapter {
public void keyPressed(KeyEvent e) {
int kc = e.getKeyCode();
@@ -294,30 +294,48 @@ public class GearsES2 implements GLEventListener {
public void mouseReleased(MouseEvent e) {
}
+ public void mouseMoved(MouseEvent e) {
+ if(e.isConfined()) {
+ navigate(e);
+ }
+ }
+
public void mouseDragged(MouseEvent e) {
+ navigate(e);
+ }
+
+ private void navigate(MouseEvent e) {
int x = e.getX();
int y = e.getY();
- int width=0, height=0;
- Object source = e.getSource();
- if(source instanceof Window) {
- 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);
- }
- float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)width);
- float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)height);
-
+
+ // 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);
+ }
+ }
prevMouseX = x;
prevMouseY = y;
-
- view_rotx += thetaX;
- view_roty += thetaY;
}
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
index ddba0569f..9846b2e69 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
@@ -88,7 +88,7 @@ public class TestGearsES2NEWT extends UITestCase {
glWindow.setPointerVisible(mouseVisible);
glWindow.confinePointer(mouseConfined);
- GearsES2 demo = new GearsES2(vsync ? 1 : 0);
+ final GearsES2 demo = new GearsES2(vsync ? 1 : 0);
demo.setPMVUseBackingArray(pmvUseBackingArray);
glWindow.addGLEventListener(demo);
if(waitForKey) {