Skip to content

Commit

Permalink
MouseEvent: Clarify button-number and pointer-ID relation incl. case …
Browse files Browse the repository at this point in the history
…'no button/pointer', i.e. button == 0, pointer-ID == -1

doPointerEvent:
  - allow id==-1 -> button==0 for no button, i.e. mouse move

doMouseEvent:
  - keep button 0 value, i.e. map to pointer-ID -1
  • Loading branch information
sgothel committed Oct 18, 2013
1 parent 77b0adb commit 2ebf1bf
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 23 deletions.
4 changes: 2 additions & 2 deletions make/scripts/tests.sh
Expand Up @@ -335,7 +335,7 @@ function testawtswt() {
#testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingGearsAWT $*
#testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingGearsSwingAWT $*
#testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingGearsSwingAWT2 $*
testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingGearsNewtAWT $*
#testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingGearsNewtAWT $*
#testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingNIOImageSwingAWT $*

#
Expand Down Expand Up @@ -523,7 +523,7 @@ testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingGearsNewtAWT $*
#testawt com.jogamp.opengl.test.junit.newt.event.TestNewtKeyPressReleaseUnmaskRepeatAWT $*
#testawt com.jogamp.opengl.test.junit.newt.event.TestNewtKeyCodesAWT $*
#testawt com.jogamp.opengl.test.junit.newt.event.TestNewtKeyCodeModifiersAWT $*
#testawt com.jogamp.opengl.test.junit.newt.event.TestNewtEventModifiersNEWTWindowAWT $*
testawt com.jogamp.opengl.test.junit.newt.event.TestNewtEventModifiersNEWTWindowAWT $*
#testawt com.jogamp.opengl.test.junit.newt.event.TestNewtEventModifiersAWTCanvas $*
#testawt com.jogamp.opengl.test.junit.newt.event.TestNewtEventModifiersNewtCanvasAWT $*
#testawtswt com.jogamp.opengl.test.junit.newt.event.TestNewtEventModifiersNewtCanvasSWTAWT $*
Expand Down
83 changes: 69 additions & 14 deletions src/newt/classes/com/jogamp/newt/event/MouseEvent.java
Expand Up @@ -49,9 +49,21 @@
* For example {@link #getX(int) e.getX(0)} at {@link #EVENT_MOUSE_PRESSED} returns the data of the pressed pointer, etc.
* </p>
* <p>
* If representing a multiple-pointer event, the {@link #getButton() button number} is equal to the first {@link #getPointerId(int) pointer ID}
* A {@link #getButton() button value} of <code>0</code> denotes no button activity, i.e. {@link PointerType#Mouse} move.
* </p>
* <p>
* A {@link #getPointerId(int) pointer-ID} of -1 denotes no pointer/button activity, i.e. {@link PointerType#Mouse} move.
* </p>
* <p>
* {@link #getButton() Button values} are mapped from and to {@link #getPointerId(int) pointer-IDs} as follows:
* <code>
* getPointerId(0) == getButton() - 1
* </code>.
* </p>
* <p>
* If representing a multiple-pointer event, the {@link #getButton() button number} is mapped to the <i>first {@link #getPointerId(int) pointer ID}</i>
* triggering the event and the {@link InputEvent#BUTTON1_MASK button mask bits} in the {@link #getModifiers() modifiers}
* field represents the pressed pointer IDs.<br>
* field represent the pressed pointer IDs.<br>
* Hence users can query the pressed button count as well as the pressed pointer count via {@link InputEvent#getButtonDownCount()}
* or use the simple query {@link InputEvent#isAnyButtonDown()}.
* </p>
Expand Down Expand Up @@ -162,7 +174,21 @@ public static final short getClickTimeout() {
return 300;
}

/** Constructor for traditional one-pointer event. */
/**
* Constructor for traditional one-pointer event.
*
* @param eventType
* @param source
* @param when
* @param modifiers
* @param x X-axis
* @param y Y-axis
* @param clickCount Mouse-button click-count
* @param button button number, e.g. [{@link #BUTTON1}..{@link #BUTTON_COUNT}-1].
* A button value of <code>0</code> denotes no button activity, i.e. {@link PointerType#Mouse} move.
* @param rotationXYZ Rotation of all axis
* @param rotationScale Rotation scale
*/
public MouseEvent(short eventType, Object source, long when,
int modifiers, int x, int y, short clickCount, short button,
float[] rotationXYZ, float rotationScale)
Expand Down Expand Up @@ -203,6 +229,7 @@ public MouseEvent(short eventType, Object source, long when,
* @param modifiers
* @param pointerType PointerType for each pointer (multiple pointer)
* @param pointerID Pointer ID for each pointer (multiple pointer). IDs start w/ 0 and are consecutive numbers.
* A pointer-ID of -1 may also denote no pointer/button activity, i.e. {@link PointerType#Mouse} move.
* @param x X-axis for each pointer (multiple pointer)
* @param y Y-axis for each pointer (multiple pointer)
* @param pressure Pressure for each pointer (multiple pointer)
Expand Down Expand Up @@ -246,15 +273,16 @@ public MouseEvent createVariant(short newEventType) {
}

/**
* See details for <a href="#multiPtrEvent">multiple-pointer events</a>.
* @return the count of pointers involved in this event
*/
public final int getPointerCount() {
return pointerType.length;
}

/**
* @return the {@link PointerType} for the data at index.
* return null if index not available.
* See details for <a href="#multiPtrEvent">multiple-pointer events</a>.
* @return the {@link PointerType} for the data at index or null if index not available.
*/
public final PointerType getPointerType(int index) {
if(0 > index || index >= pointerType.length) {
Expand All @@ -264,15 +292,24 @@ public final PointerType getPointerType(int index) {
}

/**
* See details for <a href="#multiPtrEvent">multiple-pointer events</a>.
* @return array of all {@link PointerType}s for all pointers
*/
public final PointerType[] getAllPointerTypes() {
return pointerType;
}

/**
* @return the pointer id for the given index.
* return -1 if index not available. IDs start w/ 0 and are consecutive numbers.
* Return the pointer id for the given index or -1 if index not available.
* <p>
* IDs start w/ 0 and are consecutive numbers.
* </p>
* <p>
* A pointer-ID of -1 may also denote no pointer/button activity, i.e. {@link PointerType#Mouse} move.
* </p>
* <p>
* See details for <a href="#multiPtrEvent">multiple-pointer events</a>.
* </p>
*/
public final short getPointerId(int index) {
if(0 > index || index >= pointerID.length) {
Expand All @@ -282,19 +319,22 @@ public final short getPointerId(int index) {
}

/**
* @return the pointer index for the given pointer id.
* return -1 if id not available.
* See details for <a href="#multiPtrEvent">multiple-pointer events</a>.
* @return the pointer index for the given pointer id or -1 if id not available.
*/
public final int getPointerIdx(short id) {
for(int i=pointerID.length-1; i>=0; i--) {
if( pointerID[i] == id ) {
return i;
if( id >= 0 ) {
for(int i=pointerID.length-1; i>=0; i--) {
if( pointerID[i] == id ) {
return i;
}
}
}
return -1;
}

/**
* See details for <a href="#multiPtrEvent">multiple-pointer events</a>.
* @return array of all pointer IDs for all pointers. IDs start w/ 0 and are consecutive numbers.
*/
public final short[] getAllPointerIDs() {
Expand All @@ -304,6 +344,9 @@ public final short[] getAllPointerIDs() {
/**
* Returns the button number, e.g. [{@link #BUTTON1}..{@link #BUTTON_COUNT}-1].
* <p>
* A button value of <code>0</code> denotes no button activity, i.e. {@link PointerType#Mouse} move.
* </p>
* <p>
* See details for <a href="#multiPtrEvent">multiple-pointer events</a>.
* </p>
*/
Expand Down Expand Up @@ -511,7 +554,12 @@ public static String getEventTypeString(short type) {

/** PointerType for each pointer (multiple pointer) */
private final PointerType pointerType[];
/** Pointer-ID for each pointer (multiple pointer). IDs start w/ 0 and are consecutive numbers. */
/**
* Pointer-ID for each pointer (multiple pointer). IDs start w/ 0 and are consecutive numbers.
* <p>
* A pointer-ID of -1 may also denote no pointer/button activity, i.e. {@link PointerType#Mouse} move.
* </p>
*/
private final short pointerID[];
/** X-axis for each pointer (multiple pointer) */
private final int x[];
Expand All @@ -520,7 +568,14 @@ public static String getEventTypeString(short type) {
/** Pressure for each pointer (multiple pointer) */
private final float pressure[];
// private final short tiltX[], tiltY[]; // TODO: A generic way for pointer axis information, see Android MotionEvent!
private final short clickCount, button;
private final short clickCount;
/**
* Returns the button number, e.g. [{@link #BUTTON1}..{@link #BUTTON_COUNT}-1].
* <p>
* A button value of <code>0</code> denotes no button activity, i.e. {@link PointerType#Mouse} move.
* </p>
*/
private final short button;
/** Rotation around the X, Y and X axis */
private final float[] rotationXYZ;
/** Rotation scale */
Expand Down
14 changes: 7 additions & 7 deletions src/newt/classes/jogamp/newt/WindowImpl.java
Expand Up @@ -2381,8 +2381,6 @@ protected void doMouseEvent(boolean enqueue, boolean wait, short eventType, int
int x, int y, short button, final float[] rotationXYZ, float rotationScale) {
if( 0 > button || button > MouseEvent.BUTTON_COUNT ) {
throw new NativeWindowException("Invalid mouse button number" + button);
} else if( 0 == button ) {
button = 1;
}
doPointerEvent(enqueue, wait, constMousePointerTypes, eventType, modifiers,
0 /*actionIdx*/, new short[] { (short)(button-1) },
Expand Down Expand Up @@ -2467,7 +2465,8 @@ public final void doPointerEvent(boolean enqueue, boolean wait,
* @param eventType
* @param modifiers
* @param pActionIdx index of multiple-pointer arrays representing the pointer which triggered the event
* @param pID Pointer ID for each pointer (multiple pointer). We assume consecutive pointerIDs starting w/ 0.
* @param pID Pointer ID for each pointer (multiple pointer). We assume consecutive pointerIDs starting w/ 0.
* A pointer-ID of -1 may also denote no pointer/button activity, i.e. {@link PointerType#Mouse} move.
* @param pX X-axis for each pointer (multiple pointer)
* @param pY Y-axis for each pointer (multiple pointer)
* @param pPressure Pressure for each pointer (multiple pointer)
Expand Down Expand Up @@ -2513,7 +2512,7 @@ public final void doPointerEvent(boolean enqueue, boolean wait,
final short button;
{
final int b = id + 1;
if( com.jogamp.newt.event.MouseEvent.BUTTON1 <= b && b <= com.jogamp.newt.event.MouseEvent.BUTTON_COUNT ) {
if( 0 <= b && b <= com.jogamp.newt.event.MouseEvent.BUTTON_COUNT ) { // we allow id==-1 -> button==0 for no button, i.e. mouse move
button = (short)b;
} else {
button = com.jogamp.newt.event.MouseEvent.BUTTON1;
Expand Down Expand Up @@ -2580,7 +2579,8 @@ public final void doPointerEvent(boolean enqueue, boolean wait,
", mod "+modifiers+", pos "+x+"/"+y+", button "+button+", lastMousePosition: "+movePositionP0);
}

modifiers |= InputEvent.getButtonMask(button); // Always add current button to modifier mask (Bug 571)
final int buttonMask = InputEvent.getButtonMask(button);
modifiers |= buttonMask; // Always add current button to modifier mask (Bug 571)
modifiers |= pState1.buttonPressedMask; // Always add currently pressed mouse buttons to modifier mask

if( isPointerConfined() ) {
Expand Down Expand Up @@ -2609,7 +2609,7 @@ public final void doPointerEvent(boolean enqueue, boolean wait,
if( 0 >= pPressure[0] ) {
pPressure[0] = maxPressure;
}
pState1.buttonPressedMask |= InputEvent.getButtonMask(button);
pState1.buttonPressedMask |= buttonMask;
if( 1 == pCount ) {
if( when - pState1.lastButtonPressTime < MouseEvent.getClickTimeout() ) {
pState1.lastButtonClickCount++;
Expand Down Expand Up @@ -2638,7 +2638,7 @@ public final void doPointerEvent(boolean enqueue, boolean wait,
e = new MouseEvent(eventType, this, when, modifiers, pTypes, pID,
pX, pY, pPressure, maxPressure, button, (short)1, rotationXYZ, rotationScale);
}
pState1.buttonPressedMask &= ~InputEvent.getButtonMask(button);
pState1.buttonPressedMask &= ~buttonMask;
if( null != movePositionP0 ) {
movePositionP0.set(0, 0);
}
Expand Down

0 comments on commit 2ebf1bf

Please sign in to comment.