From 6f30ddc41a71343220c7b1d14c31cdad6fbea907 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 28 Sep 2011 17:20:06 +0200 Subject: 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 --- .../classes/com/jogamp/newt/event/MouseEvent.java | 28 ++++++++-- .../jogamp/newt/driver/android/AndroidWindow.java | 43 ++++++++++++---- .../android/event/AndroidNewtEventFactory.java | 59 ++++++++++++++++++++-- 3 files changed, 114 insertions(+), 16 deletions(-) (limited to 'src/newt/classes') 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; i0) { + 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> 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(); + } } -- cgit v1.2.3