diff options
author | Sven Gothel <[email protected]> | 2011-09-28 17:20:06 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-09-28 17:20:06 +0200 |
commit | 6f30ddc41a71343220c7b1d14c31cdad6fbea907 (patch) | |
tree | 453d17583714ed3598dd2a1a11b68f1e3b110fe9 /src | |
parent | 7fe2ec7b57d76f5b0e45a2382cb374073758cecc (diff) |
NEWT/Android: Send MouseClicked event, MouseEvent enhancement, Demo: real 2 finger zoom
MouseEvent: Check array sizes at cstr. Enhance 'toString()', pointer arrays added.
GPUUISceneGLListener0A now uses 2 finger distance for zoom
Diffstat (limited to 'src')
5 files changed, 155 insertions, 32 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java index 62a8941d7..2c12049c4 100644 --- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java @@ -69,6 +69,11 @@ public class MouseEvent extends InputEvent super(eventType, source, when, modifiers); this.x = x; this.y = y; + if(pointerids.length != pressure.length || + pointerids.length != x.length || + pointerids.length != y.length) { + throw new IllegalArgumentException("All multiple pointer arrays must be of same size"); + } this.pressure = pressure; this.pointerids = pointerids; this.clickCount=clickCount; @@ -138,10 +143,25 @@ public class MouseEvent extends InputEvent } public String toString() { - return "MouseEvent["+getEventTypeString(getEventType())+ - ", "+x+"/"+y+", button "+button+", count "+clickCount+ - ", wheel rotation "+wheelRotation+ - ", "+super.toString()+"]"; + StringBuffer sb = new StringBuffer(); + sb.append("MouseEvent[").append(getEventTypeString(getEventType())) + .append(", ").append(x).append("/").append(y) + .append(", button ").append(button).append(", count ") + .append(clickCount).append(", wheel rotation ").append(wheelRotation); + if(pointerids.length>0) { + sb.append(", pointer<").append(pointerids.length).append(">["); + for(int i=0; i<pointerids.length; i++) { + if(i>0) { + sb.append(", "); + } + sb.append(pointerids[i]).append(": ") + .append(x[i]).append(" / ").append(y[i]).append(" ") + .append(pressure[i]).append("p"); + } + sb.append("]"); + } + sb.append(", ").append(super.toString()).append("]"); + return sb.toString(); } public static String getEventTypeString(int type) { diff --git a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java index 5ce40a05e..f57dc6d0f 100644 --- a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java +++ b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java @@ -46,6 +46,7 @@ import jogamp.opengl.egl.EGLGraphicsConfiguration; import android.content.Context; import android.graphics.PixelFormat; import android.util.Log; +import android.view.MotionEvent; import android.view.Surface; import android.view.SurfaceHolder; import android.view.SurfaceHolder.Callback2; @@ -80,16 +81,29 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { return PixelFormat.RGBA_8888; } + class AndroidEvents implements /* View.OnKeyListener, */ View.OnTouchListener { + + public boolean onTouch(View v, MotionEvent event) { + MouseEvent[] newtEvents = AndroidNewtEventFactory.createMouseEvents(AndroidWindow.this, event); + if(null != newtEvents) { + for(int i=0; i<newtEvents.length; i++) { + AndroidWindow.this.enqueueEvent(false, newtEvents[i]); + } + } + return true; + } + + /** TODO + public boolean onKey(View v, int keyCode, KeyEvent event) { + return false; + } */ + } public AndroidWindow() { nsv = new MSurfaceView(jogamp.common.os.android.StaticContext.getContext()); - nsv.setOnTouchListener(new View.OnTouchListener() { - public boolean onTouch(View v, android.view.MotionEvent aEvent) { - MouseEvent newtEvent = AndroidNewtEventFactory.createMouseEvent(aEvent, AndroidWindow.this); - AndroidWindow.this.enqueueEvent(false, newtEvent); - return true; - } - - }); + AndroidEvents ae = new AndroidEvents(); + nsv.setOnTouchListener(ae); + nsv.setClickable(false); + // nsv.setOnKeyListener(ae); SurfaceHolder sh = nsv.getHolder(); sh.setFormat(getPixelFormat()); sh.setType(SurfaceHolder.SURFACE_TYPE_NORMAL); @@ -105,6 +119,8 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { } protected void createNativeImpl() { + Log.d(MD.TAG, "createNativeImpl 0 - surfaceHandle 0x"+Long.toHexString(surfaceHandle)+ + ", "+x+"/"+y+" "+width+"x"+height); if(0!=getParentWindowHandle()) { throw new NativeWindowException("Window parenting not supported (yet)"); } @@ -136,6 +152,7 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { // propagate data .. config = eglConfig; setWindowHandle(surfaceHandle); + Log.d(MD.TAG, "createNativeImpl X"); } @Override @@ -219,8 +236,16 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { Log.d(MD.TAG, "surfaceCreated - 0 - isValid: "+surface.isValid()+ ", surfaceHandle 0x"+Long.toHexString(surfaceHandle)+ ", "+nsv.getWidth()+"x"+nsv.getHeight()); - sizeChanged(false, width, height, false); + + positionChanged(false, 0, 0); + sizeChanged(false, nsv.getWidth(), nsv.getHeight(), false); windowRepaint(0, 0, nsv.getWidth(), nsv.getHeight()); + + if(isVisible()) { + setVisible(true); + } + + Log.d(MD.TAG, "surfaceCreated - X"); } public void surfaceChanged(SurfaceHolder holder, int format, int width, 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 75b9f8642..9661fc7fb 100644 --- a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java +++ b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java @@ -29,11 +29,15 @@ package jogamp.newt.driver.android.event; import com.jogamp.common.util.IntIntHashMap; +import com.jogamp.newt.Window; public class AndroidNewtEventFactory { protected static final IntIntHashMap eventTypeANDROID2NEWT; + private static final String names[] = { "DOWN" , "UP" , "MOVE" , "CANCEL" , "OUTSIDE" , + "POINTER_DOWN" , "POINTER_UP" , "7?" , "8?" , "9?" }; + static { IntIntHashMap map = new IntIntHashMap(); map.setKeyNotFoundValue(0xFFFFFFFF); @@ -128,7 +132,10 @@ public class AndroidNewtEventFactory { return null; } - public static final com.jogamp.newt.event.MouseEvent createMouseEvent(android.view.MotionEvent event, com.jogamp.newt.Window newtSource) { + public static final com.jogamp.newt.event.MouseEvent[] createMouseEvents(com.jogamp.newt.Window newtSource, android.view.MotionEvent event) { + if(Window.DEBUG_MOUSE_EVENT) { + System.err.println("createMouseEvent: "+toString(event)); + } int type = eventTypeANDROID2NEWT.get(event.getAction()); if(0xFFFFFFFF != type) { int rotation = 0; @@ -148,13 +155,59 @@ public class AndroidNewtEventFactory { index++; } - return new com.jogamp.newt.event.MouseEvent( - type, (null==newtSource)?null:(Object)newtSource, event.getEventTime(), + 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, + 0, rotation); + + if(type == com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED) { + com.jogamp.newt.event.MouseEvent me2 = + 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, 0, rotation); + res = new com.jogamp.newt.event.MouseEvent[2]; + res[0] = me1; + res[1] = me2; + } else { + res = new com.jogamp.newt.event.MouseEvent[1]; + res[0] = me1; + } + return res; } return null; // no mapping .. } + + + public static String toString(android.view.MotionEvent event) { + StringBuilder sb = new StringBuilder(); + int action = event.getAction(); + int actionCode = action & android.view.MotionEvent.ACTION_MASK; + sb.append("ACTION_" ).append(names[actionCode]); + if (actionCode == android.view.MotionEvent.ACTION_POINTER_DOWN + || actionCode == android.view.MotionEvent.ACTION_POINTER_UP) { + sb.append("(pid " ).append( + action >> android.view.MotionEvent.ACTION_POINTER_ID_SHIFT); + sb.append(")" ); + } + sb.append("[" ); + for (int i = 0; i < event.getPointerCount(); i++) { + sb.append("#" ).append(i); + sb.append("(pid " ).append(event.getPointerId(i)); + sb.append(")=" ).append((int) event.getX(i)); + sb.append("," ).append((int) event.getY(i)); + if (i + 1 < event.getPointerCount()) + sb.append(";" ); + } + sb.append("]" ); + return sb.toString(); + } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java index 476bbc04f..63daff27c 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java @@ -178,8 +178,11 @@ public class GPUUISceneGLListener0A implements GLEventListener { public void init(GLAutoDrawable drawable) { if(drawable instanceof GLWindow) { + System.err.println("GPUUISceneGLListener0A: init (1)"); final GLWindow glw = (GLWindow) drawable; attachInputListenerTo(glw); + } else { + System.err.println("GPUUISceneGLListener0A: init (0)"); } final int width = drawable.getWidth(); final int height = drawable.getHeight(); @@ -225,8 +228,11 @@ public class GPUUISceneGLListener0A implements GLEventListener { public void dispose(GLAutoDrawable drawable) { if(drawable instanceof GLWindow) { + System.err.println("GPUUISceneGLListener0A: dispose (1)"); final GLWindow glw = (GLWindow) drawable; detachInputListenerFrom(glw); + } else { + System.err.println("GPUUISceneGLListener0A: dispose (0)"); } GL2ES2 gl = drawable.getGL().getGL2ES2(); @@ -235,6 +241,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { } public void display(GLAutoDrawable drawable) { + // System.err.println("GPUUISceneGLListener0A: display"); final int width = drawable.getWidth(); final int height = drawable.getHeight(); GL2ES2 gl = drawable.getGL().getGL2ES2(); @@ -308,6 +315,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + System.err.println("GPUUISceneGLListener0A: reshape"); GL2ES2 gl = drawable.getGL().getGL2ES2(); gl.glViewport(x, y, width, height); @@ -333,8 +341,7 @@ public class GPUUISceneGLListener0A implements GLEventListener { } private class MultiTouchListener extends MouseAdapter { - int lx = 0; - int ly = 0; + int lv = 0; boolean first = false; @@ -350,22 +357,33 @@ public class GPUUISceneGLListener0A implements GLEventListener { @Override public void mouseDragged(MouseEvent e) { - if(first) { - lx = e.getX(); - ly = e.getY(); - first=false; - return; - } - int dx = lx - e.getX(); - int dy = e.getY() - ly; - if(Math.abs(dx) < Math.abs(dy)) { - zoom += Math.signum(dy); + System.err.println("demo:mousedragged "+e); + if(e.getPointerCount()==2) { + // 2 finger zoom .. + if(first) { + lv = Math.abs(e.getY(0)-e.getY(1)); + first=false; + return; + } + int nv = Math.abs(e.getY(0)-e.getY(1)); + int dy = nv - lv; + + zoom += 2 * Math.signum(dy); + + lv = nv; } else { + // 1 finger drag + if(first) { + lv = e.getX(); + first=false; + return; + } + int nv = e.getX(); + int dx = nv - lv; xTran += Math.signum(dx); + + lv = nv; } - - lx = e.getX(); - ly = e.getY(); } } }
\ No newline at end of file diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java index 9ee1c519e..deefbf783 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java @@ -80,9 +80,11 @@ public class SceneUIController implements GLEventListener{ } public void init(GLAutoDrawable drawable) { + System.err.println("SceneUIController: init"); cDrawable = drawable; } public void display(GLAutoDrawable drawable) { + // System.err.println("SceneUIController: display"); final int width = drawable.getWidth(); final int height = drawable.getHeight(); GL2ES2 gl = drawable.getGL().getGL2ES2(); @@ -91,11 +93,13 @@ public class SceneUIController implements GLEventListener{ } public void dispose(GLAutoDrawable drawable) { - + System.err.println("SceneUIController: dispose"); + cDrawable = null; } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + System.err.println("SceneUIController: reshape"); GL2ES2 gl = drawable.getGL().getGL2ES2(); renderer.reshapePerspective(gl, 45.0f, width, height, 5f, 70.0f); } @@ -206,6 +210,9 @@ public class SceneUIController implements GLEventListener{ } public void mousePressed(MouseEvent e) { + if(null==cDrawable) { + return; + } mouseX = e.getX(); mouseY = e.getY(); |