summaryrefslogtreecommitdiffstats
path: root/src/newt/classes/com
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/classes/com
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/classes/com')
-rw-r--r--src/newt/classes/com/jogamp/newt/event/MouseEvent.java63
1 files changed, 50 insertions, 13 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;