diff options
author | Sven Gothel <[email protected]> | 2011-10-11 02:11:02 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-10-11 02:11:02 +0200 |
commit | bdf1876f0fd654be02a9441e3dca7cfd7df26d58 (patch) | |
tree | fd5aeb5634f30114f6c12d25bcaad45e77d05c94 /src | |
parent | 565d148d70bac0059b4bd057330b675248f43fe5 (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')
7 files changed, 90 insertions, 36 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/InputEvent.java b/src/newt/classes/com/jogamp/newt/event/InputEvent.java index 40a5c84a8..dcbd1eb94 100644 --- a/src/newt/classes/com/jogamp/newt/event/InputEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/InputEvent.java @@ -34,16 +34,19 @@ package com.jogamp.newt.event; +@SuppressWarnings("serial") public abstract class InputEvent extends NEWTEvent { - public static final int SHIFT_MASK = 1 << 0; - public static final int CTRL_MASK = 1 << 1; - public static final int META_MASK = 1 << 2; - public static final int ALT_MASK = 1 << 3; - public static final int ALT_GRAPH_MASK = 1 << 5; - public static final int BUTTON1_MASK = 1 << 6; - public static final int BUTTON2_MASK = 1 << 7; - public static final int BUTTON3_MASK = 1 << 8; + public static final int SHIFT_MASK = 1 << 0; + public static final int CTRL_MASK = 1 << 1; + public static final int META_MASK = 1 << 2; + public static final int ALT_MASK = 1 << 3; + public static final int ALT_GRAPH_MASK = 1 << 5; + public static final int BUTTON1_MASK = 1 << 6; + public static final int BUTTON2_MASK = 1 << 7; + public static final int BUTTON3_MASK = 1 << 8; + public static final int CONFINED_MASK = 1 << 16; + public static final int INVISIBLE_MASK = 1 << 16; protected InputEvent(int eventType, Object source, long when, int modifiers) { super(eventType, source, when); @@ -68,6 +71,12 @@ public abstract class InputEvent extends NEWTEvent public boolean isShiftDown() { return (modifiers&SHIFT_MASK)!=0; } + public boolean isConfined() { + return (modifiers&CONFINED_MASK)!=0; + } + public boolean isInvisible() { + return (modifiers&INVISIBLE_MASK)!=0; + } /** * @return Array of pressed mouse buttons [{@link MouseEvent#BUTTON1} ..]. @@ -100,7 +109,7 @@ public abstract class InputEvent extends NEWTEvent } public String toString() { - return "InputEvent[modifiers:"+modifiers+", "+super.toString()+"]"; + return "InputEvent[modifiers: 0x"+Integer.toHexString(modifiers)+", "+super.toString()+"]"; } private final int modifiers; diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java index 2c12049c4..ccc674f1d 100644 --- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java @@ -34,6 +34,7 @@ package com.jogamp.newt.event; +@SuppressWarnings("serial") public class MouseEvent extends InputEvent { public static final int BUTTON1 = 1; diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index b5cd3e5fd..637f36594 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -45,6 +45,7 @@ import com.jogamp.newt.Window; import com.jogamp.common.util.locks.LockFactory; import com.jogamp.common.util.locks.RecursiveLock; import com.jogamp.newt.ScreenMode; +import com.jogamp.newt.event.InputEvent; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.KeyListener; import com.jogamp.newt.event.MouseEvent; @@ -1897,6 +1898,13 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer MouseEvent eClicked = null; MouseEvent e = null; + if(isPointerConfined()) { + modifiers |= InputEvent.CONFINED_MASK; + } + if(!isPointerVisible()) { + modifiers |= InputEvent.INVISIBLE_MASK; + } + if(MouseEvent.EVENT_MOUSE_PRESSED==eventType) { if(when-lastMousePressed<MouseEvent.getClickTimeout()) { lastMouseClickCount++; diff --git a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java index b9c8d2c7b..d64cc9359 100644 --- a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java +++ b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java @@ -29,6 +29,7 @@ package jogamp.newt.awt.event; import com.jogamp.common.util.IntIntHashMap; +import com.jogamp.newt.event.InputEvent; public class AWTNewtEventFactory { @@ -122,10 +123,19 @@ public class AWTNewtEventFactory { rotation = ((java.awt.event.MouseWheelEvent)event).getWheelRotation(); } + int mods = awtModifiers2Newt(event.getModifiers(), true); + if(null!=newtSource) { + if(newtSource.isPointerConfined()) { + mods |= InputEvent.CONFINED_MASK; + } + if(!newtSource.isPointerVisible()) { + mods |= InputEvent.INVISIBLE_MASK; + } + } + return new com.jogamp.newt.event.MouseEvent( type, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, event.getWhen(), - awtModifiers2Newt(event.getModifiers(), true), - event.getX(), event.getY(), event.getClickCount(), + mods, event.getX(), event.getY(), event.getClickCount(), awtButton2Newt(event.getButton()), rotation); } return null; // no mapping .. diff --git a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java index ecf1f72cd..863bfd372 100644 --- a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java +++ b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java @@ -32,6 +32,7 @@ import java.awt.event.MouseEvent; import com.jogamp.common.util.IntIntHashMap; import com.jogamp.newt.Window; +import com.jogamp.newt.event.InputEvent; public class AndroidNewtEventFactory { @@ -157,14 +158,22 @@ public class AndroidNewtEventFactory { index++; } + if(null!=newtSource) { + if(newtSource.isPointerConfined()) { + modifiers |= InputEvent.CONFINED_MASK; + } + if(!newtSource.isPointerVisible()) { + modifiers |= InputEvent.INVISIBLE_MASK; + } + } + com.jogamp.newt.event.MouseEvent res[]; com.jogamp.newt.event.MouseEvent me1 = new com.jogamp.newt.event.MouseEvent( type, (null==newtSource)?null:(Object)newtSource, event.getEventTime(), - modifiers , - x, y, pressure, pointers, clickCount, + modifiers, x, y, pressure, pointers, clickCount, pointers.length==1 ? MouseEvent.BUTTON1 : 0, rotation); if(type == com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED) { @@ -172,8 +181,7 @@ public class AndroidNewtEventFactory { new com.jogamp.newt.event.MouseEvent( com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_CLICKED, (null==newtSource)?null:(Object)newtSource, event.getEventTime(), - modifiers , - x, y, pressure, pointers, clickCount, + modifiers, x, y, pressure, pointers, clickCount, pointers.length==1 ? MouseEvent.BUTTON1 : 0, rotation); res = new com.jogamp.newt.event.MouseEvent[2]; res[0] = me1; 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) { |