Android: added pressure to TouchEvent, fixed trigger handling

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7577 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
kim..ng 14 years ago
parent 7d5adb24c3
commit 443e49925d
  1. 31
      engine/src/core/com/jme3/input/InputManager.java
  2. 6
      engine/src/core/com/jme3/input/controls/TouchTrigger.java
  3. 26
      engine/src/core/com/jme3/input/event/TouchEvent.java

@ -40,6 +40,7 @@ import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.MouseAxisTrigger; import com.jme3.input.controls.MouseAxisTrigger;
import com.jme3.input.controls.MouseButtonTrigger; import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.input.controls.TouchListener; import com.jme3.input.controls.TouchListener;
import com.jme3.input.controls.TouchTrigger;
import com.jme3.input.controls.Trigger; import com.jme3.input.controls.Trigger;
import com.jme3.input.event.InputEvent; import com.jme3.input.event.InputEvent;
import com.jme3.input.event.JoyAxisEvent; import com.jme3.input.event.JoyAxisEvent;
@ -606,6 +607,11 @@ public class InputManager implements RawInputListener {
} else { } else {
assert false; assert false;
} }
// larynx, 2011.06.10 - flag event as reusable because
// the android input uses a non-allocating ringbuffer which
// needs to know when the event is not anymore in inputQueue
// and therefor can be reused.
event.setConsumed();
} }
inputQueue.clear(); inputQueue.clear();
@ -645,17 +651,32 @@ public class InputManager implements RawInputListener {
/** /**
* Dispatches touch events to touch listeners * Dispatches touch events to touch listeners
* @param evt * @param evt The touch event to be dispatched to all onTouch listeners
*/ */
public void onTouchEventQueued(TouchEvent evt) { public void onTouchEventQueued(TouchEvent evt) {
for (Mapping mapping : mappings.values()) { ArrayList<Mapping> maps = bindings.get(TouchTrigger.getHash());
for (InputListener listener : mapping.listeners) { if (maps == null) {
return;
}
int size = maps.size();
for (int i = size - 1; i >= 0; i--) {
Mapping mapping = maps.get(i);
ArrayList<InputListener> listeners = mapping.listeners;
int listenerSize = listeners.size();
for (int j = listenerSize - 1; j >= 0; j--) {
InputListener listener = listeners.get(j);
if (listener instanceof TouchListener) { if (listener instanceof TouchListener) {
((TouchListener) listener).onTouch(mapping.name, evt, frameTPF); ((TouchListener) listener).onTouch(mapping.name, evt, frameTPF);
} }
} }
} }
} }
/**
* Receives the touch events from the touch hardware via the input interface
* @param evt The touch Event received
*/
@Override @Override
public void onTouchEvent(TouchEvent evt) { public void onTouchEvent(TouchEvent evt) {
if (!eventsPermitted) { if (!eventsPermitted) {

@ -40,11 +40,15 @@ public class TouchTrigger implements Trigger {
@Override @Override
public int hashCode(){ public int hashCode(){
return 0xfedcba98; return getHash();
} }
@Override @Override
public String getName() { public String getName() {
return "TouchInput"; return "TouchInput";
} }
public static int getHash() {
return 0xfedcba98;
}
} }

@ -38,24 +38,23 @@ import com.jme3.math.Vector2f;
/** /**
* <code>TouchEvent</code> represents a single event from multi-touch input devices * <code>TouchEvent</code> represents a single event from multi-touch input devices
* @author larynx * @author larynx
*
*/ */
public class TouchEvent extends InputEvent public class TouchEvent extends InputEvent
{ {
public static enum Type public static enum Type
{ {
/** /**
* Touch down event, fields: posX, posY * Touch down event, fields: posX, posY, pressure
*/ */
DOWN, DOWN,
/** /**
* Move/Drag event, fields: posX, posY, deltaX, deltaY * Move/Drag event, fields: posX, posY, deltaX, deltaY, pressure
*/ */
MOVE, MOVE,
/** /**
* Touch up event, fields: posX, posY * Touch up event, fields: posX, posY, pressure
*/ */
UP, UP,
@ -111,6 +110,7 @@ public class TouchEvent extends InputEvent
private float posY; private float posY;
private float deltaX; private float deltaX;
private float deltaY; private float deltaY;
private float pressure;
// Used only with KEY* events // Used only with KEY* events
private int keyCode; private int keyCode;
@ -132,11 +132,7 @@ public class TouchEvent extends InputEvent
public void set(Type type) public void set(Type type)
{ {
this.type = type; set(type, 0f, 0f, 0f, 0f);
this.posX = 0f;
this.posY = 0f;
this.deltaX = 0f;
this.deltaY = 0f;
} }
public void set(Type type, float x, float y, float deltax, float deltay) public void set(Type type, float x, float y, float deltax, float deltay)
@ -146,6 +142,7 @@ public class TouchEvent extends InputEvent
this.posY = y; this.posY = y;
this.deltaX = deltax; this.deltaX = deltax;
this.deltaY = deltay; this.deltaY = deltay;
consumed = false;
} }
@ -173,10 +170,15 @@ public class TouchEvent extends InputEvent
{ {
return deltaY; return deltaY;
} }
public Vector2f getDelta() public float getPressure()
{
return pressure;
}
public void setPressure(float pressure)
{ {
return new Vector2f(deltaX,deltaY); this.pressure = pressure;
} }
public int getPointerId() public int getPointerId()

Loading…
Cancel
Save