diff options
author | Rami Santina <[email protected]> | 2011-08-02 16:52:56 +0300 |
---|---|---|
committer | Rami Santina <[email protected]> | 2011-08-02 16:52:56 +0300 |
commit | ecad1c4d31e5f95879914396002437517c97d9dd (patch) | |
tree | 62314a8d27b91340b991569c4f383b9679420448 | |
parent | 6508b1bd4bdc1bb7ef71bfeb96052fae67a2f425 (diff) |
Initial android newt input event transformation
4 files changed, 162 insertions, 35 deletions
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 @@ <target name="java.compile.javase"> <!-- Perform the second pass Java compile; everything. --> <javac destdir="${classes}" - excludes="${java.excludes.all}" + excludes="${java.excludes.all},**/android/**" source="${target.sourcelevel}" fork="yes" includeAntRuntime="false" 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 68378fbca..fe6beceae 100644 --- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java @@ -132,7 +132,6 @@ public class MouseEvent extends InputEvent default: return "unknown (" + type + ")"; } } - private final int x[], y[], clickCount, button, wheelRotation; public static final int EVENT_MOUSE_CLICKED = 200; 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..59bd1872f --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/event/android/AndroidNewtEventFactory.java @@ -0,0 +1,161 @@ +/** + * 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(-1); + + 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); + + 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; + } + + 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(-1 < 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(-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 .. + } +} + |