summaryrefslogtreecommitdiffstats
path: root/src/newt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-02-28 15:24:42 +0100
committerSven Gothel <[email protected]>2013-02-28 15:24:42 +0100
commitb85903ac92be7884e99eb7b85884033d7ea42337 (patch)
tree3ed60852b1148d9aa1984b6744c15eea5fe7026a /src/newt
parent01fdd5c564dcb8a7d4f8347f71728f8c2b657cb3 (diff)
NEWT: Harmonize MouseEvent Pressure (API Change!)
Due to high fluctuation (lack of normalized) pressure values on Android devices, an option to query the normalized value and access to the current known maximum pressure is required. MouseEvent: - getMaxPressure() returning the [self calibrated] known maximum pressure - getPressure(..) -> getPressure(.., boolean normalize) (API Change!) - return normalize ? pressure/maxPressure : pressure;
Diffstat (limited to 'src/newt')
-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
2 files changed, 84 insertions, 18 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 };
}