From bbbf51acf183b6fe696afd009d0ae49f6745bc40 Mon Sep 17 00:00:00 2001 From: Rami Santina Date: Tue, 2 Aug 2011 15:35:09 +0300 Subject: Multitouch proposal MouseEvent --- .../classes/com/jogamp/newt/event/MouseEvent.java | 160 +++++++++++++-------- 1 file changed, 99 insertions(+), 61 deletions(-) diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java index f3f606115..68378fbca 100644 --- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java @@ -36,55 +36,89 @@ package com.jogamp.newt.event; public class MouseEvent extends InputEvent { - public static final int BUTTON1 = 1; - public static final int BUTTON2 = 2; - public static final int BUTTON3 = 3; - public static final int BUTTON4 = 4; - public static final int BUTTON5 = 5; - public static final int BUTTON6 = 6; - public static final int BUTTON_NUMBER = 6; - - public static final int getClickTimeout() { - return 300; - } - - public MouseEvent(int eventType, Object source, long when, - int modifiers, int x, int y, int clickCount, int button, - int rotation) - { - super(eventType, source, when, modifiers); - this.x=x; - this.y=y; - this.clickCount=clickCount; - this.button=button; - this.wheelRotation = rotation; - } - - public int getButton() { - return button; - } - public int getClickCount() { - return clickCount; - } - public int getX() { - return x; - } - public int getY() { - return y; - } - public int getWheelRotation() { - return wheelRotation; - } - - public String toString() { - return "MouseEvent["+getEventTypeString(getEventType())+ - ", "+x+"/"+y+", button "+button+", count "+clickCount+ - ", wheel rotation "+wheelRotation+ - ", "+super.toString()+"]"; - } - - public static String getEventTypeString(int type) { - switch(type) { + public static final int BUTTON1 = 1; + public static final int BUTTON2 = 2; + public static final int BUTTON3 = 3; + public static final int BUTTON4 = 4; + public static final int BUTTON5 = 5; + public static final int BUTTON6 = 6; + public static final int BUTTON_NUMBER = 6; + + public static final int getClickTimeout() { + return 300; + } + + public MouseEvent(int eventType, Object source, long when, + int modifiers, int x, int y, int clickCount, int button, + int rotation) + { + super(eventType, source, when, modifiers); + this.x = new int[1]; + this.y = new int[1]; + + this.x[0]=x; + this.y[0]=y; + + this.clickCount=clickCount; + this.button=button; + this.wheelRotation = rotation; + } + + public MouseEvent(int eventType, Object source, long when, + int modifiers, int[] x, int[] y, int clickCount, int button, + int rotation) + { + super(eventType, source, when, modifiers); + this.x = x; + this.y = y; + + this.clickCount=clickCount; + this.button=button; + this.wheelRotation = rotation; + } + + public int getPointerCount() { + return x.length; + } + + public int getPointerID() { + return x.length; + } + + public int getButton() { + return button; + } + public int getClickCount() { + return clickCount; + } + public int getX() { + return x[0]; + } + public int getY() { + return y[0]; + } + + public int getX(int pointer) { + return x[pointer]; + } + + public int getY(int pointer) { + return y[pointer]; + } + + public int getWheelRotation() { + return wheelRotation; + } + + public String toString() { + return "MouseEvent["+getEventTypeString(getEventType())+ + ", "+x+"/"+y+", button "+button+", count "+clickCount+ + ", wheel rotation "+wheelRotation+ + ", "+super.toString()+"]"; + } + + public static String getEventTypeString(int type) { + switch(type) { case EVENT_MOUSE_CLICKED: return "EVENT_MOUSE_CLICKED"; case EVENT_MOUSE_ENTERED: return "EVENT_MOUSE_ENTERED"; case EVENT_MOUSE_EXITED: return "EVENT_MOUSE_EXITED"; @@ -93,18 +127,22 @@ public class MouseEvent extends InputEvent case EVENT_MOUSE_MOVED: return "EVENT_MOUSE_MOVED"; case EVENT_MOUSE_DRAGGED: return "EVENT_MOUSE_DRAGGED"; case EVENT_MOUSE_WHEEL_MOVED: return "EVENT_MOUSE_WHEEL_MOVED"; + case EVENT_MOUSE_PRESSED_MINOR: return "EVENT_MOUSE_PRESSED_MINOR"; + case EVENT_MOUSE_RELEASED_MINOR: return "EVENT_MOUSE_RELEASED_MINOR"; default: return "unknown (" + type + ")"; + } } - } - - private final int x, y, clickCount, button, wheelRotation; - - public static final int EVENT_MOUSE_CLICKED = 200; - public static final int EVENT_MOUSE_ENTERED = 201; - public static final int EVENT_MOUSE_EXITED = 202; - public static final int EVENT_MOUSE_PRESSED = 203; - public static final int EVENT_MOUSE_RELEASED = 204; - public static final int EVENT_MOUSE_MOVED = 205; - public static final int EVENT_MOUSE_DRAGGED = 206; - public static final int EVENT_MOUSE_WHEEL_MOVED = 207; + + private final int x[], y[], clickCount, button, wheelRotation; + + public static final int EVENT_MOUSE_CLICKED = 200; + public static final int EVENT_MOUSE_ENTERED = 201; + public static final int EVENT_MOUSE_EXITED = 202; + public static final int EVENT_MOUSE_PRESSED = 203; + public static final int EVENT_MOUSE_RELEASED = 204; + public static final int EVENT_MOUSE_MOVED = 205; + public static final int EVENT_MOUSE_DRAGGED = 206; + public static final int EVENT_MOUSE_WHEEL_MOVED = 207; + public static final int EVENT_MOUSE_PRESSED_MINOR = 208; + public static final int EVENT_MOUSE_RELEASED_MINOR = 209; } -- cgit v1.2.3 From ecad1c4d31e5f95879914396002437517c97d9dd Mon Sep 17 00:00:00 2001 From: Rami Santina Date: Tue, 2 Aug 2011 16:52:56 +0300 Subject: Initial android newt input event transformation --- make/build-newt.xml | 2 +- .../classes/com/jogamp/newt/event/InputEvent.java | 33 ----- .../classes/com/jogamp/newt/event/MouseEvent.java | 1 - .../event/android/AndroidNewtEventFactory.java | 161 +++++++++++++++++++++ 4 files changed, 162 insertions(+), 35 deletions(-) create mode 100644 src/newt/classes/com/jogamp/newt/event/android/AndroidNewtEventFactory.java diff --git a/make/build-newt.xml b/make/build-newt.xml index b0600db10..55a535962 100644 --- a/make/build-newt.xml +++ b/make/build-newt.xml @@ -194,7 +194,7 @@ > android.view.MotionEvent.ACTION_POINTER_INDEX_SHIFT; + + return event.getPointerId(pointerIndex); + } + + static final com.jogamp.newt.event.MouseEvent createMouseEvent(android.view.MotionEvent event, com.jogamp.newt.Window newtSource) { + int type = eventTypeANDROID2NEWT.get(event.getAction()); + if(-1 < type) { + int rotation = 0; + + int[] x = new int[event.getPointerCount()]; + int[] y = new int[event.getPointerCount()]; + + int index = 0; + while(index < event.getPointerCount()) { + x[index] = (int)event.getX(index); + y[index] = (int)event.getY(index); + index++; + } + + int pointer = androidActionPointer2Newt(event); + return new com.jogamp.newt.event.MouseEvent( + type, (null==newtSource)?null:(Object)newtSource, event.getEventTime(), + 0 , + x, y, 1, + pointer+1, rotation); + } + return null; // no mapping .. + } +} + -- cgit v1.2.3 From 0ee0e2a933bdd66d382c2745732a60b32b442877 Mon Sep 17 00:00:00 2001 From: Rami Santina Date: Tue, 2 Aug 2011 17:05:04 +0300 Subject: android map motion pressure to newt --- .../classes/com/jogamp/newt/event/MouseEvent.java | 27 +++++++++++++--------- .../event/android/AndroidNewtEventFactory.java | 10 +++++--- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java index fe6beceae..7ad7d6e2d 100644 --- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java @@ -53,11 +53,9 @@ public class MouseEvent extends InputEvent int rotation) { super(eventType, source, when, modifiers); - this.x = new int[1]; - this.y = new int[1]; - - this.x[0]=x; - this.y[0]=y; + this.x = new int[]{x}; + this.y = new int[]{y}; + this.pressure = new float[]{0}; this.clickCount=clickCount; this.button=button; @@ -65,12 +63,13 @@ public class MouseEvent extends InputEvent } public MouseEvent(int eventType, Object source, long when, - int modifiers, int[] x, int[] y, int clickCount, int button, + int modifiers, int[] x, int[] y, float[] pressure, int clickCount, int button, int rotation) { super(eventType, source, when, modifiers); this.x = x; this.y = y; + this.pressure = pressure; this.clickCount=clickCount; this.button=button; @@ -81,10 +80,6 @@ public class MouseEvent extends InputEvent return x.length; } - public int getPointerID() { - return x.length; - } - public int getButton() { return button; } @@ -94,6 +89,7 @@ public class MouseEvent extends InputEvent public int getX() { return x[0]; } + public int getY() { return y[0]; } @@ -105,7 +101,15 @@ public class MouseEvent extends InputEvent public int getY(int pointer) { return y[pointer]; } - + + public float getPressure(){ + return pressure[0]; + } + + public float getPressure(int pointer){ + return pressure[pointer]; + } + public int getWheelRotation() { return wheelRotation; } @@ -133,6 +137,7 @@ public class MouseEvent extends InputEvent } } private final int x[], y[], clickCount, button, wheelRotation; + private final float pressure[]; public static final int EVENT_MOUSE_CLICKED = 200; public static final int EVENT_MOUSE_ENTERED = 201; diff --git a/src/newt/classes/com/jogamp/newt/event/android/AndroidNewtEventFactory.java b/src/newt/classes/com/jogamp/newt/event/android/AndroidNewtEventFactory.java index 59bd1872f..77028c713 100644 --- a/src/newt/classes/com/jogamp/newt/event/android/AndroidNewtEventFactory.java +++ b/src/newt/classes/com/jogamp/newt/event/android/AndroidNewtEventFactory.java @@ -137,24 +137,28 @@ class AndroidNewtEventFactory { int type = eventTypeANDROID2NEWT.get(event.getAction()); if(-1 < type) { int rotation = 0; + int clickCount = 1; + int modifiers = 0; int[] x = new int[event.getPointerCount()]; int[] y = new int[event.getPointerCount()]; + float[] pressure = new float[event.getPointerCount()]; int index = 0; while(index < event.getPointerCount()) { x[index] = (int)event.getX(index); y[index] = (int)event.getY(index); + pressure[index] = event.getPressure(index); index++; } int pointer = androidActionPointer2Newt(event); return new com.jogamp.newt.event.MouseEvent( type, (null==newtSource)?null:(Object)newtSource, event.getEventTime(), - 0 , - x, y, 1, + modifiers , + x, y, pressure, clickCount, pointer+1, rotation); - } + } return null; // no mapping .. } } -- cgit v1.2.3 From d6d4ebf19e46c77dd92181c9e81b5a196c250791 Mon Sep 17 00:00:00 2001 From: Rami Santina Date: Tue, 2 Aug 2011 17:33:26 +0300 Subject: Added accessibility events mapping to newt mapped gained focus event. used 0xFFFFFFFF for unmapped events --- .../newt/event/android/AndroidNewtEventFactory.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/newt/classes/com/jogamp/newt/event/android/AndroidNewtEventFactory.java b/src/newt/classes/com/jogamp/newt/event/android/AndroidNewtEventFactory.java index 77028c713..19588fc1f 100644 --- a/src/newt/classes/com/jogamp/newt/event/android/AndroidNewtEventFactory.java +++ b/src/newt/classes/com/jogamp/newt/event/android/AndroidNewtEventFactory.java @@ -36,7 +36,7 @@ class AndroidNewtEventFactory { static { IntIntHashMap map = new IntIntHashMap(); - map.setKeyNotFoundValue(-1); + map.setKeyNotFoundValue(0xFFFFFFFF); map.put(android.view.KeyEvent.ACTION_DOWN, com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED); map.put(android.view.KeyEvent.ACTION_UP, com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED); @@ -51,6 +51,8 @@ class AndroidNewtEventFactory { map.put(android.view.MotionEvent.ACTION_POINTER_DOWN, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED_MINOR); map.put(android.view.MotionEvent.ACTION_POINTER_UP, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED_MINOR); + map.put(android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + eventTypeANDROID2NEWT = map; } @@ -97,6 +99,14 @@ class AndroidNewtEventFactory { if (android.view.KeyEvent.KEYCODE_AT == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_AT; return 0; } + + static final com.jogamp.newt.event.WindowEvent createWindowEvent(android.view.accessibility.AccessibilityEvent event, com.jogamp.newt.Window newtSource) { + int type = eventTypeANDROID2NEWT.get(event.getEventType()); + if(0xFFFFFFFF != type) { + return new com.jogamp.newt.event.WindowEvent(type, ((null==newtSource)?null:(Object)newtSource), event.getEventTime()); + } + return null; // no mapping .. + } public static final int androidKeyModifiers2Newt(int androidMods) { int newtMods = 0; @@ -109,7 +119,7 @@ class AndroidNewtEventFactory { static final com.jogamp.newt.event.KeyEvent createKeyEvent(android.view.KeyEvent event, com.jogamp.newt.Window newtSource) { int type = eventTypeANDROID2NEWT.get(event.getAction()); - if(-1 < type) { + if(0xFFFFFFFF != type) { return new com.jogamp.newt.event.KeyEvent( type, (null==newtSource)?null:(Object)newtSource, event.getEventTime(), androidKeyModifiers2Newt(event.getMetaState()), @@ -135,7 +145,7 @@ class AndroidNewtEventFactory { static final com.jogamp.newt.event.MouseEvent createMouseEvent(android.view.MotionEvent event, com.jogamp.newt.Window newtSource) { int type = eventTypeANDROID2NEWT.get(event.getAction()); - if(-1 < type) { + if(0xFFFFFFFF != type) { int rotation = 0; int clickCount = 1; int modifiers = 0; -- cgit v1.2.3