diff options
author | Sven Gothel <[email protected]> | 2013-10-15 15:36:03 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-10-15 15:36:03 +0200 |
commit | bc72e232a4b74c2be8c91c540a7b6153bfefb8c0 (patch) | |
tree | a96ef243eb96fad1ca9d304eae6b3479c8d1facd /src/test | |
parent | 5ac6d508c7208ac4fe5d057a9ea1bdcba5f7b998 (diff) |
Bug 861 - NEWT: Unify MouseEvent Processing incl. gesture processing
We processed MouseEvents within NEWT as follows:
sendMouseEvent/enqueueMouseEvent -> doMouseEvent,
- called by native code to be delivered via consumeMouseEvent (now or later)
- events are validated (move/drag, boundaries)
- missing events are synthesized (click, enter, ..)
as well as in several factories, i.e.:
- AWTNewtEventFactory (1:1)
- AndroidNewtEventFactory
- synthesized events .. (click, ..)
- android typed gesture detection (drag -> 1 finger scroll..)
The latter enqueues events do Window/Display directly to be consumed by WindowImpl.
Then users may have their own gesture detection etc.
+++
This change unifies mouse/pointer event processing within NEWT within consumeEvent(..)
which represents a common entry point.
Gesture processing is now realized w/ a public API
- GestureHandler
- GestureHandler.GestureListener
- GestureHandler.GesureEvent
which supplies:
- default impl. of optional gesture handlers (scroll, .. - default: enabled)
- public API to add/remove gesture-handler and -listener
+++
This allows our impl. to scale better in support of
more multiple pointer devices (-> Win7/Win8, X11, ..).
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java | 124 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java | 6 |
2 files changed, 41 insertions, 89 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 bea761a35..50037ebf3 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 @@ -22,11 +22,14 @@ package com.jogamp.opengl.test.junit.jogl.demos.es2; import com.jogamp.common.nio.Buffers; import com.jogamp.newt.Window; +import com.jogamp.newt.event.GestureHandler; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.KeyListener; import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.event.MouseListener; +import com.jogamp.newt.event.PinchToZoomGesture; +import com.jogamp.newt.event.GestureHandler.GestureEvent; import com.jogamp.opengl.JoglVersion; import com.jogamp.opengl.test.junit.jogl.demos.GearsObject; import com.jogamp.opengl.util.PMVMatrix; @@ -59,7 +62,6 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL private GLUniformData colorU = null; private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f; private float panX = 0.0f, panY = 0.0f, panZ=0.0f; - private int drawableHeight = 1; private GearsObjectES2 gear1=null, gear2=null, gear3=null; private FloatBuffer gear1Color=GearsObject.red, gear2Color=GearsObject.green, gear3Color=GearsObject.blue; private float angle = 0.0f; @@ -76,6 +78,9 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL private float[] clearColor = null; private boolean clearBuffers = true; private boolean verbose = true; + + private PinchToZoomGesture pinchToZoomGesture = null; + public GearsES2(int swapInterval) { this.swapInterval = swapInterval; @@ -235,15 +240,28 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL final Window window = (Window) upstreamWidget; window.addMouseListener(gearsMouse); window.addKeyListener(gearsKeys); + window.addGestureListener(pinchToZoomListener); + pinchToZoomGesture = new PinchToZoomGesture(drawable.getNativeSurface()); + window.addGestureHandler(pinchToZoomGesture); } else if (GLProfile.isAWTAvailable() && upstreamWidget instanceof java.awt.Component) { final java.awt.Component comp = (java.awt.Component) upstreamWidget; new com.jogamp.newt.event.awt.AWTMouseAdapter(gearsMouse).addTo(comp); new com.jogamp.newt.event.awt.AWTKeyAdapter(gearsKeys).addTo(comp); } + st.useProgram(gl, false); System.err.println(Thread.currentThread()+" GearsES2.init FIN"); } + + private final GestureHandler.GestureListener pinchToZoomListener = new GestureHandler.GestureListener() { + @Override + public void gestureDetected(GestureEvent gh) { + final PinchToZoomGesture.ZoomEvent ze = (PinchToZoomGesture.ZoomEvent) gh; + final float zoom = ze.getZoom() * ( ze.getTrigger().getPointerCount() - 1 ); + panZ = zoom * 30f - 30f; // [0 .. 2] -> [-30f .. 30f] + } + }; @Override public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { @@ -266,7 +284,6 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL void reshapeImpl(GL2ES2 gl, int tileX, int tileY, int tileWidth, int tileHeight, int imageWidth, int imageHeight) { final boolean msaa = gl.getContext().getGLDrawable().getChosenGLCapabilities().getSampleBuffers(); System.err.println(Thread.currentThread()+" GearsES2.reshape "+tileX+"/"+tileY+" "+tileWidth+"x"+tileHeight+" of "+imageWidth+"x"+imageHeight+", swapInterval "+swapInterval+", drawable 0x"+Long.toHexString(gl.getContext().getGLDrawable().getHandle())+", msaa "+msaa+", tileRendererInUse "+tileRendererInUse); - drawableHeight = imageHeight; if( !gl.hasGLSL() ) { return; @@ -326,6 +343,9 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL final Window window = (Window) upstreamWidget; window.removeMouseListener(gearsMouse); window.removeKeyListener(gearsKeys); + window.removeGestureHandler(pinchToZoomGesture); + pinchToZoomGesture = null; + window.removeGestureListener(pinchToZoomListener); } final GL2ES2 gl = drawable.getGL().getGL2ES2(); if( !gl.hasGLSL() ) { @@ -432,69 +452,6 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL } } - interface GestureHandler { - /** Returns true if within the gesture */ - public boolean isWithinGesture(); - /** Returns true if within the gesture */ - public boolean onReleased(MouseEvent e); - /** Returns true if within the gesture */ - public boolean onDragged(MouseEvent e); - } - final GestureHandler gesture2PtrZoom = new GestureHandler() { - private int zoomLastYDist; - private boolean zoomFirstTouch = true; - private boolean zoomMode = false; - - @Override - public boolean isWithinGesture() { - return zoomMode; - } - - @Override - public boolean onReleased(MouseEvent e) { - if( zoomMode && e.getPointerCount()==1 ) { - zoomFirstTouch = true; - zoomMode = false; - System.err.println("panZ.X: "+e); - } - return zoomMode; - } - - @Override - public boolean onDragged(MouseEvent e) { - if( e.getPointerCount() >=2 ) { - // 2 pointers zoom .. [ -15 .. 15 ], range 30 - /** - // Simple 1:1 Zoom: finger-distance to screen-coord - final int dy = Math.abs(e.getY(0)-e.getY(1)); - float scale = (float)dy / (float)drawableHeight; - panZ = 30f * scale - 15f; - System.err.println("panZ: scale "+scale+" ["+dy+"/"+drawableHeight+"] -> "+panZ); - */ - // Diff. 1:1 Zoom: finger-distance to screen-coord - if(zoomFirstTouch) { - zoomLastYDist = Math.abs(e.getY(0)-e.getY(1)); - zoomFirstTouch=false; - zoomMode = true; - System.err.println("panZ: 1st pinch "+zoomLastYDist+", "+e); - } else if( zoomMode ) { - final int dy = Math.abs(e.getY(0)-e.getY(1)); - final int ddy = dy - zoomLastYDist; - - final float incr = ( (float)ddy / (float)drawableHeight ) * 15.0f; - panZ += incr; - if( e.getPointerCount() > 2 ) { - panZ += incr; - } - System.err.println("panZ.1: ddy "+ddy+", incr "+incr+" ["+dy+"/"+drawableHeight+"], dblZoom "+(e.getPointerCount() > 2)+" -> "+panZ); - - zoomLastYDist = dy; - } - } - return zoomMode; - } - }; - class GearsMouseAdapter implements MouseListener{ private int prevMouseX, prevMouseY; @@ -526,40 +483,33 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL } public void mousePressed(MouseEvent e) { - if( !gesture2PtrZoom.isWithinGesture() ) { - if( e.getPointerCount()==1 ) { - prevMouseX = e.getX(); - prevMouseY = e.getY(); - } else if( e.getPointerCount() == 4 ) { - final Object src = e.getSource(); - if( e.getPressure(true) > 0.7f && src instanceof Window) { // show Keyboard - ((Window) src).setKeyboardVisible(true); - } + if( e.getPointerCount()==1 ) { + prevMouseX = e.getX(); + prevMouseY = e.getY(); + } else if( e.getPointerCount() == 4 ) { + final Object src = e.getSource(); + if( e.getPressure(true) > 0.7f && src instanceof Window) { // show Keyboard + ((Window) src).setKeyboardVisible(true); } } } public void mouseReleased(MouseEvent e) { - gesture2PtrZoom.onReleased(e); } public void mouseMoved(MouseEvent e) { - if( !gesture2PtrZoom.isWithinGesture() && e.getPointerCount()==1 ) { - 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(); - } + 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(); } } public void mouseDragged(MouseEvent e) { - if( !gesture2PtrZoom.onDragged(e) && e.getPointerCount()==1 ) { - navigate(e); - } + navigate(e); } private void navigate(MouseEvent e) { 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 fe2c0f31a..74be176da 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 @@ -266,8 +266,10 @@ public class TestGearsES2NEWT extends UITestCase { }); glWindow.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { - glWindow.setFullscreen(!glWindow.isFullscreen()); - System.err.println("setFullscreen: "+glWindow.isFullscreen()); + if(e.getClickCount() == 2 && e.getPointerCount() == 1) { + glWindow.setFullscreen(!glWindow.isFullscreen()); + System.err.println("setFullscreen: "+glWindow.isFullscreen()); + } } }); |