summaryrefslogtreecommitdiffstats
path: root/src/newt/classes/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-08-02 17:51:00 +0200
committerSven Gothel <[email protected]>2011-08-02 17:51:00 +0200
commit4e6d8fba40dc56008d3059c43b758238c9756d97 (patch)
tree3d8b703313e9c006e15cb1c3db828093a9afedbe /src/newt/classes/com
parentaad86420584d91e0e3faf220d317e25fc4db68a0 (diff)
parentd6d4ebf19e46c77dd92181c9e81b5a196c250791 (diff)
solve conflict ; use gluegen's android.jar for Eclipse classpath
Diffstat (limited to 'src/newt/classes/com')
-rw-r--r--src/newt/classes/com/jogamp/newt/event/InputEvent.java33
-rw-r--r--src/newt/classes/com/jogamp/newt/event/MouseEvent.java193
-rw-r--r--src/newt/classes/com/jogamp/newt/event/android/AndroidNewtEventFactory.java175
3 files changed, 274 insertions, 127 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/InputEvent.java b/src/newt/classes/com/jogamp/newt/event/InputEvent.java
index 1d13ee505..40a5c84a8 100644
--- a/src/newt/classes/com/jogamp/newt/event/InputEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/InputEvent.java
@@ -44,9 +44,6 @@ public abstract class InputEvent extends NEWTEvent
public static final int BUTTON1_MASK = 1 << 6;
public static final int BUTTON2_MASK = 1 << 7;
public static final int BUTTON3_MASK = 1 << 8;
- public static final int POINTER1_MASK = 1 << 16;
- public static final int POINTER2_MASK = 1 << 17;
- public static final int POINTER3_MASK = 1 << 18;
protected InputEvent(int eventType, Object source, long when, int modifiers) {
super(eventType, source, when);
@@ -102,36 +99,6 @@ public abstract class InputEvent extends NEWTEvent
return (modifiers&BUTTON3_MASK)!=0;
}
- /**
- * @return Array of involved pointer [{@link MouseEvent#POINTER1} ..].
- * If none is down, the resulting array is of length 0.
- */
- public final int[] getPointers() {
- int len = 0;
- if(isPointer1()) { len++; }
- if(isPointer2()) { len++; }
- if(isPointer3()) { len++; }
-
- int[] res = new int[len];
- int i=0;
- if(isPointer1()) { res[i++] = MouseEvent.POINTER1; }
- if(isPointer2()) { res[i++] = MouseEvent.POINTER2; }
- if(isPointer3()) { res[i++] = MouseEvent.POINTER3; }
- return res;
- }
-
- public final boolean isPointer1() {
- return (modifiers&POINTER1_MASK)!=0;
- }
-
- public final boolean isPointer2() {
- return (modifiers&POINTER2_MASK)!=0;
- }
-
- public final boolean isPointer3() {
- return (modifiers&POINTER3_MASK)!=0;
- }
-
public String toString() {
return "InputEvent[modifiers:"+modifiers+", "+super.toString()+"]";
}
diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java
index cb2138b8f..7ad7d6e2d 100644
--- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java
@@ -36,91 +36,93 @@ package com.jogamp.newt.event;
public class MouseEvent extends InputEvent
{
- /** Mouse button 1 name. Button names start with 1. */
- 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;
- /** Maximal number of supported mouse buttons. */
- public static final int BUTTON_NUMBER = 6;
+ 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;
- /** Pointer device 1 name. Pointer names start with 0. */
- public static final int POINTER1 = 0;
- public static final int POINTER2 = 1;
- public static final int POINTER3 = 2;
- /** Maximal number of supported pointer devices. */
- public static final int POINTER_NUMBER = 3;
-
- public static final int getClickTimeout() {
- return 300;
- }
+ 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[]{x};
+ this.y = new int[]{y};
+ this.pressure = new float[]{0};
+
+ this.clickCount=clickCount;
+ this.button=button;
+ this.wheelRotation = rotation;
+ }
+
+ public MouseEvent(int eventType, Object source, long when,
+ 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;
- 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.pointerCount=1;
- this.x=new int[1]; this.x[0] = x;
- this.y=new int[1]; this.y[0] = y;
- this.button=new int[1]; this.button[0] = button;
- this.clickCount=clickCount;
- this.wheelRotation = rotation;
- }
-
- public MouseEvent(int eventType, Object source, long when,
- int modifiers, int pointerCount, int[] x, int[] y, int[] button, int[] pressure,
- int clickCount, int rotation)
- {
- super(eventType, source, when, modifiers);
- this.pointerCount=pointerCount;
- this.x=x;
- this.y=y;
- this.button=button;
- this.clickCount=clickCount;
- this.wheelRotation = rotation;
- }
-
- public int getPointerCount() {
- return pointerCount;
- }
- public int getButton() {
- return button[0];
- }
- public int getX() {
- return x[0];
- }
- public int getY() {
- return y[0];
- }
- public int getButton(int pointerIdx) {
- return button[pointerIdx];
- }
- public int getX(int pointerIdx) {
- return x[pointerIdx];
- }
- public int getY(int pointerIdx) {
- return y[pointerIdx];
- }
- public int getClickCount() {
- return clickCount;
- }
- public int getWheelRotation() {
- return wheelRotation;
- }
-
- public String toString() {
- return "MouseEvent["+getEventTypeString(getEventType())+
- ", "+x+"/"+y+", button "+button+", count "+clickCount+
- ", wheel rotation "+wheelRotation+
- ", "+super.toString()+"]";
- }
+ this.clickCount=clickCount;
+ this.button=button;
+ this.wheelRotation = rotation;
+ }
+
+ public int getPointerCount() {
+ 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 static String getEventTypeString(int type) {
- switch(type) {
+ public int getX(int pointer) {
+ return x[pointer];
+ }
+
+ 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;
+ }
+
+ 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";
@@ -129,19 +131,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 pointerCount, clickCount, wheelRotation;
- private final int x[], y[], button[];
+ 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;
- 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_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;
}
diff --git a/src/newt/classes/com/jogamp/newt/event/android/AndroidNewtEventFactory.java b/src/newt/classes/com/jogamp/newt/event/android/AndroidNewtEventFactory.java
new file mode 100644
index 000000000..19588fc1f
--- /dev/null
+++ b/src/newt/classes/com/jogamp/newt/event/android/AndroidNewtEventFactory.java
@@ -0,0 +1,175 @@
+/**
+ * Copyright 2011 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.newt.event.android;
+
+import com.jogamp.common.util.IntIntHashMap;
+
+class AndroidNewtEventFactory {
+
+ protected static final IntIntHashMap eventTypeANDROID2NEWT;
+
+ static {
+ IntIntHashMap map = new IntIntHashMap();
+ 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);
+ map.put(android.view.KeyEvent.ACTION_MULTIPLE, com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED);
+
+ map.put(android.view.MotionEvent.ACTION_DOWN, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED);
+ map.put(android.view.MotionEvent.ACTION_UP, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED);
+ map.put(android.view.MotionEvent.ACTION_CANCEL, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED);
+ map.put(android.view.MotionEvent.ACTION_MOVE, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_DRAGGED);
+ map.put(android.view.MotionEvent.ACTION_OUTSIDE, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_MOVED);
+
+ 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;
+ }
+
+ public static final int androidKeyCode2Newt(int androidKeyCode) {
+ //safest ...but ugly
+ if (android.view.KeyEvent.KEYCODE_0 == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_0;
+ if (android.view.KeyEvent.KEYCODE_1 == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_1;
+ if (android.view.KeyEvent.KEYCODE_2 == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_2;
+ if (android.view.KeyEvent.KEYCODE_3 == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_3;
+ if (android.view.KeyEvent.KEYCODE_4 == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_4;
+ if (android.view.KeyEvent.KEYCODE_5 == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_5;
+ if (android.view.KeyEvent.KEYCODE_6 == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_6;
+ if (android.view.KeyEvent.KEYCODE_7 == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_7;
+ if (android.view.KeyEvent.KEYCODE_8 == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_8;
+ if (android.view.KeyEvent.KEYCODE_9 == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_9;
+
+ if (android.view.KeyEvent.KEYCODE_A == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_A;
+ if (android.view.KeyEvent.KEYCODE_B == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_B;
+ if (android.view.KeyEvent.KEYCODE_C == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_C;
+ if (android.view.KeyEvent.KEYCODE_D == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_D;
+ if (android.view.KeyEvent.KEYCODE_E == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_E;
+ if (android.view.KeyEvent.KEYCODE_F == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_F;
+ if (android.view.KeyEvent.KEYCODE_G == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_G;
+ if (android.view.KeyEvent.KEYCODE_H == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_H;
+ if (android.view.KeyEvent.KEYCODE_I == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_I;
+ if (android.view.KeyEvent.KEYCODE_J == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_J;
+ if (android.view.KeyEvent.KEYCODE_K == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_K;
+ if (android.view.KeyEvent.KEYCODE_L == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_L;
+ if (android.view.KeyEvent.KEYCODE_M == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_M;
+ if (android.view.KeyEvent.KEYCODE_N == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_N;
+ if (android.view.KeyEvent.KEYCODE_O == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_O;
+ if (android.view.KeyEvent.KEYCODE_P == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_P;
+ if (android.view.KeyEvent.KEYCODE_Q == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_Q;
+ if (android.view.KeyEvent.KEYCODE_R == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_R;
+ if (android.view.KeyEvent.KEYCODE_S == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_S;
+ if (android.view.KeyEvent.KEYCODE_T == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_T;
+ if (android.view.KeyEvent.KEYCODE_U == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_U;
+ if (android.view.KeyEvent.KEYCODE_V == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_V;
+ if (android.view.KeyEvent.KEYCODE_W == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_W;
+ if (android.view.KeyEvent.KEYCODE_X == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_X;
+ if (android.view.KeyEvent.KEYCODE_Y == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_Y;
+ if (android.view.KeyEvent.KEYCODE_Z == androidKeyCode) return com.jogamp.newt.event.KeyEvent.VK_Z;
+
+ 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;
+ if ((androidMods & android.view.KeyEvent.META_SYM_ON) != 0) newtMods |= com.jogamp.newt.event.InputEvent.META_MASK;
+ if ((androidMods & android.view.KeyEvent.META_SHIFT_ON) != 0) newtMods |= com.jogamp.newt.event.InputEvent.SHIFT_MASK;
+ if ((androidMods & android.view.KeyEvent.META_ALT_ON) != 0) newtMods |= com.jogamp.newt.event.InputEvent.ALT_MASK;
+
+ return newtMods;
+ }
+
+ static final com.jogamp.newt.event.KeyEvent createKeyEvent(android.view.KeyEvent event, com.jogamp.newt.Window newtSource) {
+ int type = eventTypeANDROID2NEWT.get(event.getAction());
+ if(0xFFFFFFFF != type) {
+ return new com.jogamp.newt.event.KeyEvent(
+ type, (null==newtSource)?null:(Object)newtSource, event.getEventTime(),
+ androidKeyModifiers2Newt(event.getMetaState()),
+ androidKeyCode2Newt(event.getKeyCode()), event.getDisplayLabel());
+ }
+ return null;
+ }
+
+ public static final int androidActionPointer2Newt(android.view.MotionEvent event) {
+ int action = event.getAction();
+ int androidMods = event.getMetaState();
+
+ if ((android.view.MotionEvent.ACTION_POINTER_UP != action)
+ || (android.view.MotionEvent.ACTION_POINTER_DOWN != action)) {
+ return 0;
+ }
+
+ int pointerIndex = (androidMods & android.view.MotionEvent.ACTION_POINTER_INDEX_MASK);
+ pointerIndex = pointerIndex >> 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(0xFFFFFFFF != 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(),
+ modifiers ,
+ x, y, pressure, clickCount,
+ pointer+1, rotation);
+ }
+ return null; // no mapping ..
+ }
+}
+