diff options
author | Sven Gothel <[email protected]> | 2013-05-16 23:53:09 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-05-16 23:53:09 +0200 |
commit | 31e72d2f2d953352b2a8c83368039ecca8139d49 (patch) | |
tree | 5bbd52596aeed9acabbb6d99f2acaf7b8c4439bd | |
parent | 86a5460c5052cdab7b9f6294c46a0b4e30dfa260 (diff) |
NEWT: MouseEvent Ctor: Use proper float[] rotationXYZ and float rotationScale arguments.
6 files changed, 59 insertions, 37 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java index a40b0aa18..18c8285f7 100644 --- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java @@ -92,6 +92,17 @@ public class MouseEvent extends InputEvent /** Maximum number of buttons, value <code>16</code> */ public static final short BUTTON_NUMBER = 16; + /** Returns the 3-axis XYZ rotation array by given rotation on Y axis or X axis (if SHIFT_MASK is given in mods). */ + public static final float[] getRotationXYZ(final float rotationXorY, final int mods) { + final float[] rotationXYZ = new float[] { 0f, 0f, 0f }; + if( 0 != ( mods & InputEvent.SHIFT_MASK ) ) { + rotationXYZ[0] = rotationXorY; + } else { + rotationXYZ[1] = rotationXorY; + } + return rotationXYZ; + } + public static final short getClickTimeout() { return 300; } @@ -99,7 +110,7 @@ public class MouseEvent extends InputEvent /** Constructor for tradition 1-pointer mouse events. */ public MouseEvent(short eventType, Object source, long when, int modifiers, int x, int y, short clickCount, short button, - float rotation) + float[] rotationXYZ, float rotationScale) { super(eventType, source, when, modifiers); this.x = new int[]{x}; @@ -109,13 +120,8 @@ public class MouseEvent extends InputEvent this.pointerIDs = constMousePointerIDs; this.clickCount=clickCount; this.button=button; - this.rotationXYZ = new float[] { 0f, 0f, 0f }; - if( isShiftDown() ) { - this.rotationXYZ[0] = rotation; - } else { - this.rotationXYZ[1] = rotation; - } - this.rotationScale = 1f; + this.rotationXYZ = rotationXYZ; + this.rotationScale = rotationScale; this.pointerTypes = constMousePointerTypes; } diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 16d252ca3..805ad08ad 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -2133,17 +2133,29 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer // // MouseListener/Event Support // - public void sendMouseEvent(short eventType, int modifiers, - int x, int y, short button, float rotation) { + public final void sendMouseEvent(short eventType, int modifiers, + int x, int y, short button, float rotation) { doMouseEvent(false, false, eventType, modifiers, x, y, button, rotation); } - public void enqueueMouseEvent(boolean wait, short eventType, int modifiers, - int x, int y, short button, float rotation) { + public final void enqueueMouseEvent(boolean wait, short eventType, int modifiers, + int x, int y, short button, float rotation) { doMouseEvent(true, wait, eventType, modifiers, x, y, button, rotation); } - + protected final void doMouseEvent(boolean enqueue, boolean wait, short eventType, int modifiers, + int x, int y, short button, float rotation) { + this.doMouseEvent(enqueue, wait, eventType, modifiers, x, y, button, MouseEvent.getRotationXYZ(rotation, modifiers), 1f); + } + /** + public final void sendMouseEvent(short eventType, int modifiers, + int x, int y, short button, float[] rotationXYZ, float rotationScale) { + doMouseEvent(false, false, eventType, modifiers, x, y, button, rotationXYZ, rotationScale); + } + public final void enqueueMouseEvent(boolean wait, short eventType, int modifiers, + int x, int y, short button, float[] rotationXYZ, float rotationScale) { + doMouseEvent(true, wait, eventType, modifiers, x, y, button, rotationXYZ, rotationScale); + } */ protected void doMouseEvent(boolean enqueue, boolean wait, short eventType, int modifiers, - int x, int y, short button, float rotation) { + int x, int y, short button, float[] rotationXYZ, float rotationScale) { if( eventType == MouseEvent.EVENT_MOUSE_ENTERED || eventType == MouseEvent.EVENT_MOUSE_EXITED ) { if( eventType == MouseEvent.EVENT_MOUSE_EXITED && x==-1 && y==-1 ) { x = lastMousePosition.getX(); @@ -2172,7 +2184,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer if(!mouseInWindow) { mouseInWindow = true; eEntered = new MouseEvent(MouseEvent.EVENT_MOUSE_ENTERED, this, when, - modifiers, x, y, (short)0, (short)0, (short)0); + modifiers, x, y, (short)0, (short)0, rotationXYZ, rotationScale); // clear states lastMousePressed = 0; lastMouseClickCount = (short)0; @@ -2213,13 +2225,13 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer mouseButtonPressed = button; mouseButtonModMask |= MouseEvent.getButtonMask(button); e = new MouseEvent(eventType, this, when, - modifiers, x, y, lastMouseClickCount, button, 0); + modifiers, x, y, lastMouseClickCount, button, rotationXYZ, rotationScale); } else if( MouseEvent.EVENT_MOUSE_RELEASED == eventType ) { e = new MouseEvent(eventType, this, when, - modifiers, x, y, lastMouseClickCount, button, 0); + modifiers, x, y, lastMouseClickCount, button, rotationXYZ, rotationScale); if( when - lastMousePressed < MouseEvent.getClickTimeout() ) { eClicked = new MouseEvent(MouseEvent.EVENT_MOUSE_CLICKED, this, when, - modifiers, x, y, lastMouseClickCount, button, 0); + modifiers, x, y, lastMouseClickCount, button, rotationXYZ, rotationScale); } else { lastMouseClickCount = (short)0; lastMousePressed = 0; @@ -2229,15 +2241,15 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } else if( MouseEvent.EVENT_MOUSE_MOVED == eventType ) { if ( mouseButtonPressed > 0 ) { e = new MouseEvent(MouseEvent.EVENT_MOUSE_DRAGGED, this, when, - modifiers, x, y, (short)1, mouseButtonPressed, 0); + modifiers, x, y, (short)1, mouseButtonPressed, rotationXYZ, rotationScale); } else { e = new MouseEvent(eventType, this, when, - modifiers, x, y, (short)0, button, (short)0); + modifiers, x, y, (short)0, button, rotationXYZ, rotationScale); } } else if( MouseEvent.EVENT_MOUSE_WHEEL_MOVED == eventType ) { - e = new MouseEvent(eventType, this, when, modifiers, x, y, (short)0, button, rotation); + e = new MouseEvent(eventType, this, when, modifiers, x, y, (short)0, button, rotationXYZ, rotationScale); } else { - e = new MouseEvent(eventType, this, when, modifiers, x, y, (short)0, button, 0); + e = new MouseEvent(eventType, this, when, modifiers, x, y, (short)0, button, rotationXYZ, rotationScale); } if( null != eEntered ) { if(DEBUG_MOUSE_EVENT) { diff --git a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java index a1aa69e0a..1e15070f8 100644 --- a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java +++ b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java @@ -28,6 +28,8 @@ package jogamp.newt.awt.event; +import com.jogamp.newt.event.MouseEvent; + /** * * <a name="AWTEventModifierMapping"><h5>AWT Event Modifier Mapping</h5></a> @@ -635,7 +637,7 @@ public class AWTNewtEventFactory { return new com.jogamp.newt.event.MouseEvent( newtType, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, event.getWhen(), mods, event.getX(), event.getY(), (short)event.getClickCount(), - newtButton, rotation); + newtButton, MouseEvent.getRotationXYZ(rotation, mods), 1f); } return null; // no mapping .. } diff --git a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java index fcc5b2148..69a09c1f9 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java @@ -228,7 +228,7 @@ public class WindowDriver extends WindowImpl { @Override protected final void doMouseEvent(boolean enqueue, boolean wait, short eventType, int modifiers, - int x, int y, short button, float rotation) { + int x, int y, short button, float[] rotationXYZ, float rotationScale) { switch(eventType) { case MouseEvent.EVENT_MOUSE_PRESSED: switch(button) { @@ -242,32 +242,32 @@ public class WindowDriver extends WindowImpl { break; case MouseEvent.EVENT_MOUSE_RELEASED: switch(button) { - case X11_WHEEL_ONE_UP_BUTTON: + case X11_WHEEL_ONE_UP_BUTTON: // vertical scroll up eventType = MouseEvent.EVENT_MOUSE_WHEEL_MOVED; button = 1; - rotation = 1; + rotationXYZ[1] = 1; break; - case X11_WHEEL_ONE_DOWN_BUTTON: + case X11_WHEEL_ONE_DOWN_BUTTON: // vertical scroll down eventType = MouseEvent.EVENT_MOUSE_WHEEL_MOVED; button = 1; - rotation = -1; + rotationXYZ[1] = -1; break; - case X11_WHEEL_TWO_UP_BUTTON: // vertical scroll left + case X11_WHEEL_TWO_UP_BUTTON: // horizontal scroll left eventType = MouseEvent.EVENT_MOUSE_WHEEL_MOVED; button = 1; - rotation = 1; + rotationXYZ[0] = 1; modifiers |= InputEvent.SHIFT_MASK; break; - case X11_WHEEL_TWO_DOWN_BUTTON: // vertical scroll right + case X11_WHEEL_TWO_DOWN_BUTTON: // horizontal scroll right eventType = MouseEvent.EVENT_MOUSE_WHEEL_MOVED; button = 1; - rotation = -1; + rotationXYZ[0] = -1; modifiers |= InputEvent.SHIFT_MASK; break; } break; } - super.doMouseEvent(enqueue, wait, eventType, modifiers, x, y, button, rotation); + super.doMouseEvent(enqueue, wait, eventType, modifiers, x, y, button, rotationXYZ, rotationScale); } protected final void sendKeyEvent(short eventType, int modifiers, short keyCode, short keySym, char keyChar0, String keyString) { diff --git a/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java b/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java index 24a5c41de..1e99d1ef7 100644 --- a/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java +++ b/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java @@ -33,6 +33,7 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import com.jogamp.newt.event.InputEvent; +import com.jogamp.newt.event.MouseEvent; /** * SWT event translator to NEWT, inclusive dispatch listener. @@ -242,7 +243,7 @@ public class SWTNewtEventFactory { return new com.jogamp.newt.event.MouseEvent( type, (null==source)?(Object)event.data:source, (0xFFFFFFFFL & (long)event.time), - mods, event.x, event.y, (short)event.count, (short)event.button, rotation); + mods, event.x, event.y, (short)event.count, (short)event.button, MouseEvent.getRotationXYZ(rotation, mods), 1f); } return null; // no mapping .. } @@ -297,7 +298,7 @@ public class SWTNewtEventFactory { res.getSource(), res.getWhen(), res.getModifiers(), res.getX(), res.getY(), res.getClickCount(), - res.getButton(), res.getWheelRotation() ); + res.getButton(), res.getRotation(), res.getRotationScale()); l.mouseClicked(res2); } break; @@ -308,7 +309,7 @@ public class SWTNewtEventFactory { res.getSource(), res.getWhen(), res.getModifiers(), res.getX(), res.getY(), res.getClickCount(), - dragButtonDown, res.getWheelRotation() ); + dragButtonDown, res.getRotation(), res.getRotationScale()); l.mouseDragged( res2 ); } else { l.mouseMoved(res); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java b/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java index 05a24272c..3a2c4cc81 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java @@ -134,7 +134,8 @@ public abstract class BaseNewtEventModifiers extends UITestCase { if( _modifierCheckEnabled ) { final MouseEvent expEvent = new MouseEvent(hasEvent.getEventType(), hasEvent.getSource(), hasEvent.getWhen(), _expectedModifiers, - hasEvent.getX(), hasEvent.getY(), hasEvent.getClickCount(), hasEvent.getButton(), hasEvent.getWheelRotation()); + hasEvent.getX(), hasEvent.getY(), hasEvent.getClickCount(), hasEvent.getButton(), + hasEvent.getRotation(), hasEvent.getRotationScale()); _checkModifierMask( expEvent, hasEvent, com.jogamp.newt.event.InputEvent.SHIFT_MASK, "shift" ) ; _checkModifierMask( expEvent, hasEvent, com.jogamp.newt.event.InputEvent.CTRL_MASK, "ctrl" ) ; |