From 8955f719b7c25e1f0fcd567faafee957d25d6616 Mon Sep 17 00:00:00 2001 From: "kim..ng" Date: Tue, 14 Jun 2011 12:58:12 +0000 Subject: [PATCH] Touch: Added keycode to touchtrigger, 0 for all events git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7623 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../src/core/com/jme3/input/InputManager.java | 2 +- .../src/core/com/jme3/input/TouchInput.java | 34 +++++++++++++++++-- .../com/jme3/input/controls/TouchTrigger.java | 32 +++++++++++++---- .../core/com/jme3/input/event/TouchEvent.java | 6 ++++ 4 files changed, 65 insertions(+), 9 deletions(-) diff --git a/engine/src/core/com/jme3/input/InputManager.java b/engine/src/core/com/jme3/input/InputManager.java index 7df18a99e..4f3fea86d 100644 --- a/engine/src/core/com/jme3/input/InputManager.java +++ b/engine/src/core/com/jme3/input/InputManager.java @@ -846,7 +846,7 @@ public class InputManager implements RawInputListener { * @param evt The touch event to be dispatched to all onTouch listeners */ public void onTouchEventQueued(TouchEvent evt) { - ArrayList maps = bindings.get(TouchTrigger.touchHash()); + ArrayList maps = bindings.get(TouchTrigger.touchHash(evt.getKeyCode())); if (maps == null) { return; } diff --git a/engine/src/core/com/jme3/input/TouchInput.java b/engine/src/core/com/jme3/input/TouchInput.java index 780ea85ef..1d0ee2c38 100644 --- a/engine/src/core/com/jme3/input/TouchInput.java +++ b/engine/src/core/com/jme3/input/TouchInput.java @@ -37,17 +37,47 @@ package com.jme3.input; */ public interface TouchInput extends Input { + /** + * No filter, get all events + */ + public static final int ALL = 0x00; + /** + * Home key + */ + public static final int KEYCODE_HOME = 0x03; + /** + * Escape key. + */ + public static final int KEYCODE_BACK = 0x04; + /** + * Context Menu key. + */ + public static final int KEYCODE_MENU = 0x52; + /** + * Search key. + */ + public static final int KEYCODE_SEARCH = 0x54; + /** + * Volume up key. + */ + public static final int KEYCODE_VOLUME_UP = 0x18; + /** + * Volume down key. + */ + public static final int KEYCODE_VOLUME_DOWN = 0x19; + + /** * Set whether mouse events should be generated * - * @param simulate Whether mouse events should be generated + * @param simulate if mouse events should be generated */ public void setSimulateMouse(boolean simulate); /** * Set whether keyboard events should be generated * - * @param simulate Whether keyboard events should be generated + * @param simulate if keyboard events should be generated */ public void setSimulateKeyboard(boolean simulate); diff --git a/engine/src/core/com/jme3/input/controls/TouchTrigger.java b/engine/src/core/com/jme3/input/controls/TouchTrigger.java index a68299289..25124ab5f 100644 --- a/engine/src/core/com/jme3/input/controls/TouchTrigger.java +++ b/engine/src/core/com/jme3/input/controls/TouchTrigger.java @@ -32,22 +32,42 @@ package com.jme3.input.controls; +/** + * Class to trigger TouchEvents, keycode can be TouchInput.ALL(=0) or TouchInput.KEYCODE_* + * @author larynx + * + */ public class TouchTrigger implements Trigger { - - public TouchTrigger() { + + private final int keyCode; + + /** + * Constructor + * @param keyCode can be zero to get all events or TouchInput.KEYCODE_* + */ + public TouchTrigger(int keyCode) { super(); + this.keyCode = keyCode; } @Override public String getName() { - return "TouchInput"; + if (keyCode != 0) + return "TouchInput"; + else + return "TouchInput KeyCode " + keyCode; } - public static int touchHash(){ - return 0xfedcba98; + public static int touchHash(int keyCode){ + assert keyCode >= 0 && keyCode <= 255; + return 0xfedcba98 + keyCode; } public int triggerHashCode() { - return touchHash(); + return touchHash(keyCode); + } + + public int getKeyCode(){ + return keyCode; } } diff --git a/engine/src/core/com/jme3/input/event/TouchEvent.java b/engine/src/core/com/jme3/input/event/TouchEvent.java index 538064142..2b77c7fc6 100644 --- a/engine/src/core/com/jme3/input/event/TouchEvent.java +++ b/engine/src/core/com/jme3/input/event/TouchEvent.java @@ -124,6 +124,12 @@ public class TouchEvent extends InputEvent { this.posY = y; this.deltaX = deltax; this.deltaY = deltay; + pointerId = 0; + pressure = 0; + keyCode = 0; + scaleFactor = 0; + scaleSpan = 0; + characters = ""; consumed = false; }