aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/newt/classes/com/jogamp/newt/event/MouseEvent.java63
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java39
-rw-r--r--src/test/com/jogamp/opengl/test/android/MovieCubeActivity0.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java2
4 files changed, 86 insertions, 20 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java
index 23549533e..8ad1f3f24 100644
--- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java
@@ -70,7 +70,8 @@ public class MouseEvent extends InputEvent
super(eventType, source, when, modifiers);
this.x = new int[]{x};
this.y = new int[]{y};
- this.pressure = new float[]{0};
+ this.pressure = new float[]{0f};
+ this.maxPressure= 1.0f;
this.pointerids = new short[]{-1};
this.clickCount=clickCount;
this.button=button;
@@ -78,8 +79,8 @@ public class MouseEvent extends InputEvent
}
public MouseEvent(short eventType, Object source, long when,
- int modifiers, int[] x, int[] y, float[] pressure, short[] pointerids, short clickCount, short button,
- float rotation)
+ int modifiers, int[] x, int[] y, float[] pressure, float maxPressure, short[] pointerids, short clickCount,
+ short button, float rotation)
{
super(eventType, source, when, modifiers);
this.x = x;
@@ -89,7 +90,11 @@ public class MouseEvent extends InputEvent
pointerids.length != y.length) {
throw new IllegalArgumentException("All multiple pointer arrays must be of same size");
}
+ if( 0.0f >= maxPressure ) {
+ throw new IllegalArgumentException("maxPressure must be > 0.0f");
+ }
this.pressure = pressure;
+ this.maxPressure= maxPressure;
this.pointerids = pointerids;
this.clickCount=clickCount;
this.button=button;
@@ -129,28 +134,59 @@ public class MouseEvent extends InputEvent
}
/**
- * @return x-coord at index where index refers to the
- * data coming from a pointer.
+ * @param index pointer-index within [0 .. {@link #getPointerCount()}-1]
+ * @return X-Coord associated with the pointer-index.
* @see getPointerId(index)
*/
public int getX(int index) {
return x[index];
}
+ /**
+ * @param index pointer-index within [0 .. {@link #getPointerCount()}-1]
+ * @return Y-Coord associated with the pointer-index.
+ * @see getPointerId(index)
+ */
public int getY(int index) {
return y[index];
}
- public float getPressure(){
- return pressure[0];
+ /**
+ * @param normalized if true, method returns the normalized pressure, i.e. <code>pressure / maxPressure</code>
+ * @return The pressure associated with the pointer-index 0.
+ * The value of zero is return if not available.
+ * @see #getMaxPressure()
+ */
+ public float getPressure(boolean normalized){
+ return normalized ? pressure[0] / maxPressure : pressure[0];
+ }
+
+ /**
+ * Returns the maximum pressure known for the input device generating this event.
+ * <p>
+ * This value may be self calibrating on devices/OS, where no known maximum pressure is known.
+ * Hence subsequent events may return a higher value.
+ * </p>
+ * <p>
+ * Self calibrating maximum pressure is performed on:
+ * <ul>
+ * <li>Android</li>
+ * </ul>
+ * </p>
+ */
+ public float getMaxPressure() {
+ return maxPressure;
}
/**
- * @return the pressure associated with the pointer at index.
- * the value of zero is return if not available.
+ * @param index pointer-index within [0 .. {@link #getPointerCount()}-1]
+ * @param normalized if true, method returns the normalized pressure, i.e. <code>pressure / maxPressure</code>
+ * @return The pressure associated with the pointer-index.
+ * The value of zero is return if not available.
+ * @see #getMaxPressure()
*/
- public float getPressure(int index){
- return pressure[index];
+ public float getPressure(int index, boolean normalized){
+ return normalized ? pressure[index] / maxPressure : pressure[index];
}
/**
@@ -199,8 +235,8 @@ public class MouseEvent extends InputEvent
sb.append(", ");
}
sb.append(pointerids[i]).append(": ")
- .append(x[i]).append(" / ").append(y[i]).append(" ")
- .append(pressure[i]).append("p");
+ .append(x[i]).append("/").append(y[i]).append(", ")
+ .append("p[").append(pressure[i]).append("/").append(maxPressure).append("=").append(pressure[i]/maxPressure).append("]");
}
sb.append("]");
}
@@ -225,6 +261,7 @@ public class MouseEvent extends InputEvent
private final short clickCount, button;
private final float wheelRotation;
private final float pressure[];
+ private final float maxPressure;
private final short pointerids[];
public static final short EVENT_MOUSE_CLICKED = 200;
diff --git a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
index a9c642d8c..1f78bd578 100644
--- a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
+++ b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
@@ -196,6 +196,28 @@ public class AndroidNewtEventFactory {
return null;
}
+ private static float maxPressure = 0.7f; // experienced maximum value (Amazon HD = 0.8f)
+
+ /**
+ * Dynamic calibration of maximum MotionEvent pressure, starting from 0.7f
+ * <p>
+ * Specification says no pressure is 0.0f and
+ * normal pressure is 1.0f, where &gt; 1.0f denominates very high pressure.
+ * </p>
+ * <p>
+ * Some devices exceed this spec, or better, most devices do.
+ * <ul>
+ * <li>Asus TF2*: Pressure always &gt; 1.0f</li>
+ * <li>Amazon HD: Pressure always &le; 0.8f</li>
+ * </ul>
+ * </p>
+ *
+ * @return
+ */
+ public static float getMaxPressure() {
+ return maxPressure;
+ }
+
private final NewtGestureListener gestureListener;
private final android.view.GestureDetector gestureDetector;
private final float touchSlop;
@@ -209,13 +231,17 @@ public class AndroidNewtEventFactory {
}
private int gestureScrollPointerDown = 0;
-
+
public com.jogamp.newt.event.MouseEvent[] createMouseEvents(boolean isOnTouchEvent,
android.view.MotionEvent event, com.jogamp.newt.Window newtSource) {
if(Window.DEBUG_MOUSE_EVENT) {
System.err.println("createMouseEvent: "+toString(event));
}
+ if( event.getPressure() > maxPressure ) {
+ maxPressure = event.getPressure();
+ }
+
//
// Prefilter Android Event (Gesture, ..) and determine final type
//
@@ -340,6 +366,9 @@ public class AndroidNewtEventFactory {
y[j] = (int)event.getY(i);
pressure[j] = event.getPressure(i);
pointerIds[j] = (short)event.getPointerId(i);
+ if( pressure[j] > maxPressure ) {
+ maxPressure = pressure[j];
+ }
if(Window.DEBUG_MOUSE_EVENT) {
System.err.println("createMouseEvent: ptr-data["+i+" -> "+j+"] "+x[j]+"/"+y[j]+", pressure "+pressure[j]+", id "+pointerIds[j]);
}
@@ -362,15 +391,15 @@ public class AndroidNewtEventFactory {
final com.jogamp.newt.event.MouseEvent me1 = new com.jogamp.newt.event.MouseEvent(
nType, src, unixTime,
- modifiers, x, y, pressure, pointerIds, clickCount,
- button, rotation);
+ modifiers, x, y, pressure, maxPressure, pointerIds,
+ clickCount, button, rotation);
if( com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED == nType ) {
return new com.jogamp.newt.event.MouseEvent[] { me1,
new com.jogamp.newt.event.MouseEvent(
com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_CLICKED,
- src, unixTime, modifiers, x, y, pressure, pointerIds, clickCount,
- button, rotation) };
+ src, unixTime, modifiers, x, y, pressure, maxPressure, pointerIds,
+ clickCount, button, rotation) };
} else {
return new com.jogamp.newt.event.MouseEvent[] { me1 };
}
diff --git a/src/test/com/jogamp/opengl/test/android/MovieCubeActivity0.java b/src/test/com/jogamp/opengl/test/android/MovieCubeActivity0.java
index 0c65b6d53..b1ab90a88 100644
--- a/src/test/com/jogamp/opengl/test/android/MovieCubeActivity0.java
+++ b/src/test/com/jogamp/opengl/test/android/MovieCubeActivity0.java
@@ -54,7 +54,7 @@ public class MovieCubeActivity0 extends NewtBaseActivity {
MouseAdapter showKeyboardMouseListener = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
- if(e.getPressure()>0.6f) {
+ if(e.getPressure(true)>0.8f) {
((com.jogamp.newt.Window) e.getSource()).setKeyboardVisible(true);
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
index 14c6a0cda..99df7c102 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
@@ -367,7 +367,7 @@ public class GearsES2 implements GLEventListener {
prevMouseX = e.getX();
prevMouseY = e.getY();
Object src = e.getSource();
- if(e.getPressure()>0.6f && src instanceof Window) { // show Keyboard
+ if(e.getPressure(true)>0.8f && src instanceof Window) { // show Keyboard
((Window) src).setKeyboardVisible(true);
}
}