Added mapping of Android Scale Gesture (ie PinchZoom) to mouse wheel. If mouseEventsEnabled is set, mouse wheel reacts to the gesture.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9758 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
iwg..ic 13 years ago
parent bdb715e527
commit 47cb989c63
  1. 35
      engine/src/android/com/jme3/input/android/AndroidInput.java
  2. 21
      engine/src/core/com/jme3/input/event/TouchEvent.java

@ -12,6 +12,7 @@ import com.jme3.math.Vector2f;
import com.jme3.system.AppSettings; import com.jme3.system.AppSettings;
import com.jme3.util.RingBuffer; import com.jme3.util.RingBuffer;
import java.util.HashMap; import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
@ -42,6 +43,7 @@ public class AndroidInput implements
// Internal // Internal
private View view; private View view;
private ScaleGestureDetector scaledetector; private ScaleGestureDetector scaledetector;
private boolean scaleInProgress = false;
private GestureDetector detector; private GestureDetector detector;
private int lastX; private int lastX;
private int lastY; private int lastY;
@ -276,6 +278,7 @@ public class AndroidInput implements
touch.setPointerId(event.getPointerId(p)); touch.setPointerId(event.getPointerId(p));
touch.setTime(event.getEventTime()); touch.setTime(event.getEventTime());
touch.setPressure(event.getPressure(p)); touch.setPressure(event.getPressure(p));
touch.setScaleSpanInProgress(scaleInProgress);
processEvent(touch); processEvent(touch);
lastPos.set(event.getX(p), view.getHeight() - event.getY(p)); lastPos.set(event.getX(p), view.getHeight() - event.getY(p));
} }
@ -404,6 +407,7 @@ public class AndroidInput implements
if (listener != null) { if (listener != null) {
TouchEvent event; TouchEvent event;
MouseButtonEvent btn; MouseButtonEvent btn;
MouseMotionEvent mot;
int newX; int newX;
int newY; int newY;
@ -448,7 +452,26 @@ public class AndroidInput implements
lastY = -1; lastY = -1;
break; break;
case SCALE_MOVE:
if (lastX != -1 && lastY != -1) {
newX = lastX;
newY = lastY;
}
int wheel = (int) (event.getScaleSpan() / 4f); // scale to match mouse wheel
int dwheel = (int) (event.getDeltaScaleSpan() / 4f); // scale to match mouse wheel
mot = new MouseMotionEvent(newX, newX, 0, 0, wheel, dwheel);
mot.setTime(event.getTime());
listener.onMouseMotionEvent(mot);
lastX = newX;
lastY = newY;
break;
case MOVE: case MOVE:
if (event.isScaleSpanInProgress()) {
break;
}
int dx; int dx;
int dy; int dy;
if (lastX != -1) { if (lastX != -1) {
@ -458,11 +481,13 @@ public class AndroidInput implements
dx = 0; dx = 0;
dy = 0; dy = 0;
} }
MouseMotionEvent mot = new MouseMotionEvent(newX, newY, dx, dy, 0, 0);
mot = new MouseMotionEvent(newX, newY, dx, dy, (int)event.getScaleSpan(), (int)event.getDeltaScaleSpan());
mot.setTime(event.getTime()); mot.setTime(event.getTime());
listener.onMouseMotionEvent(mot); listener.onMouseMotionEvent(mot);
lastX = newX; lastX = newX;
lastY = newY; lastY = newY;
break; break;
} }
} }
@ -526,12 +551,15 @@ public class AndroidInput implements
} }
public boolean onScaleBegin(ScaleGestureDetector scaleGestureDetector) { public boolean onScaleBegin(ScaleGestureDetector scaleGestureDetector) {
scaleInProgress = true;
TouchEvent touch = getNextFreeTouchEvent(); TouchEvent touch = getNextFreeTouchEvent();
touch.set(Type.SCALE_START, scaleGestureDetector.getFocusX(), scaleGestureDetector.getFocusY(), 0f, 0f); touch.set(Type.SCALE_START, scaleGestureDetector.getFocusX(), scaleGestureDetector.getFocusY(), 0f, 0f);
touch.setPointerId(0); touch.setPointerId(0);
touch.setTime(scaleGestureDetector.getEventTime()); touch.setTime(scaleGestureDetector.getEventTime());
touch.setScaleSpan(scaleGestureDetector.getCurrentSpan()); touch.setScaleSpan(scaleGestureDetector.getCurrentSpan());
touch.setDeltaScaleSpan(scaleGestureDetector.getCurrentSpan() - scaleGestureDetector.getPreviousSpan());
touch.setScaleFactor(scaleGestureDetector.getScaleFactor()); touch.setScaleFactor(scaleGestureDetector.getScaleFactor());
touch.setScaleSpanInProgress(scaleInProgress);
processEvent(touch); processEvent(touch);
// System.out.println("scaleBegin"); // System.out.println("scaleBegin");
@ -544,7 +572,9 @@ public class AndroidInput implements
touch.setPointerId(0); touch.setPointerId(0);
touch.setTime(scaleGestureDetector.getEventTime()); touch.setTime(scaleGestureDetector.getEventTime());
touch.setScaleSpan(scaleGestureDetector.getCurrentSpan()); touch.setScaleSpan(scaleGestureDetector.getCurrentSpan());
touch.setDeltaScaleSpan(scaleGestureDetector.getCurrentSpan() - scaleGestureDetector.getPreviousSpan());
touch.setScaleFactor(scaleGestureDetector.getScaleFactor()); touch.setScaleFactor(scaleGestureDetector.getScaleFactor());
touch.setScaleSpanInProgress(scaleInProgress);
processEvent(touch); processEvent(touch);
// System.out.println("scale"); // System.out.println("scale");
@ -552,12 +582,15 @@ public class AndroidInput implements
} }
public void onScaleEnd(ScaleGestureDetector scaleGestureDetector) { public void onScaleEnd(ScaleGestureDetector scaleGestureDetector) {
scaleInProgress = false;
TouchEvent touch = getNextFreeTouchEvent(); TouchEvent touch = getNextFreeTouchEvent();
touch.set(Type.SCALE_END, scaleGestureDetector.getFocusX(), view.getHeight() - scaleGestureDetector.getFocusY(), 0f, 0f); touch.set(Type.SCALE_END, scaleGestureDetector.getFocusX(), view.getHeight() - scaleGestureDetector.getFocusY(), 0f, 0f);
touch.setPointerId(0); touch.setPointerId(0);
touch.setTime(scaleGestureDetector.getEventTime()); touch.setTime(scaleGestureDetector.getEventTime());
touch.setScaleSpan(scaleGestureDetector.getCurrentSpan()); touch.setScaleSpan(scaleGestureDetector.getCurrentSpan());
touch.setDeltaScaleSpan(scaleGestureDetector.getCurrentSpan() - scaleGestureDetector.getPreviousSpan());
touch.setScaleFactor(scaleGestureDetector.getScaleFactor()); touch.setScaleFactor(scaleGestureDetector.getScaleFactor());
touch.setScaleSpanInProgress(scaleInProgress);
processEvent(touch); processEvent(touch);
} }

@ -103,6 +103,8 @@ public class TouchEvent extends InputEvent {
// Used only with SCALE* events // Used only with SCALE* events
private float scaleFactor; private float scaleFactor;
private float scaleSpan; private float scaleSpan;
private float deltaScaleSpan;
private boolean scaleSpanInProgress;
public TouchEvent() { public TouchEvent() {
set(Type.IDLE, 0f, 0f, 0f, 0f); set(Type.IDLE, 0f, 0f, 0f, 0f);
@ -127,6 +129,8 @@ public class TouchEvent extends InputEvent {
keyCode = 0; keyCode = 0;
scaleFactor = 0; scaleFactor = 0;
scaleSpan = 0; scaleSpan = 0;
deltaScaleSpan = 0;
scaleSpanInProgress = false;
characters = ""; characters = "";
consumed = false; consumed = false;
} }
@ -206,4 +210,21 @@ public class TouchEvent extends InputEvent {
public void setScaleSpan(float scaleSpan) { public void setScaleSpan(float scaleSpan) {
this.scaleSpan = scaleSpan; this.scaleSpan = scaleSpan;
} }
public float getDeltaScaleSpan() {
return deltaScaleSpan;
}
public void setDeltaScaleSpan(float deltaScaleSpan) {
this.deltaScaleSpan = deltaScaleSpan;
}
public boolean isScaleSpanInProgress() {
return scaleSpanInProgress;
}
public void setScaleSpanInProgress(boolean scaleSpanInProgress) {
this.scaleSpanInProgress = scaleSpanInProgress;
}
} }

Loading…
Cancel
Save