aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/classes')
-rw-r--r--src/newt/classes/com/jogamp/newt/event/MouseEvent.java28
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java43
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java59
3 files changed, 114 insertions, 16 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();
+ }
}