diff options
3 files changed, 34 insertions, 28 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo10.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo10.java index f1bdb1e08..9d7a2cc87 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo10.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo10.java @@ -126,13 +126,10 @@ public class UISceneDemo10 { scene.setPMVMatrixSetup(new MyPMVMatrixSetup()); scene.setClearParams(new float[] { 1f, 1f, 1f, 1f}, GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - shape.onMove(new Shape.Listener() { - @Override - public void run(final Shape shape) { + shape.onMove((final Shape s, final Vec3f origin, Vec3f dest) -> { final Vec3f p = shape.getPosition(); - System.err.println("Shape moved: "+p); - } - }); + System.err.println("Shape moved: "+origin+" -> "+p); + } ); shape.addMouseListener(new Shape.MouseGestureAdapter() { @Override public void mouseMoved(final MouseEvent e) { diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java index 1879240ab..18ce9c0e6 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java @@ -744,12 +744,12 @@ public class UISceneDemo20 implements GLEventListener { } }); - button.onMove( (final Shape shape) -> { + button.onMove((final Shape shape, final Vec3f origin, final Vec3f dest) -> { final ALAudioSink aSink = alAudioSink[0]; if( null != aSink ) { setSoundPosition(shape, aSink.getContext(), aSink.getSource()); } - }); + } ); button.onInit( (final Shape shape) -> { final ALAudioSink aSink = alAudioSink[0]; if( null != aSink ) { @@ -821,9 +821,9 @@ public class UISceneDemo20 implements GLEventListener { System.err.println("Sine "+sineSound); } } ); - final Shape.Listener setAudioPosition = new Shape.Listener() { + final Shape.MoveListener setAudioPosition = new Shape.MoveListener() { @Override - public void run(final Shape shape) { + public void run(final Shape shape, final Vec3f origin, final Vec3f dest) { setSoundPosition(shape, aSink.getContext(), aSource); } }; diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java index 657d85caa..961b2cba4 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java @@ -108,6 +108,19 @@ public abstract class Shape { } /** + * {@link Shape} move listener + */ + public static interface MoveListener { + /** + * Move callback + * @param s the moved shape + * @param origin original position + * @param dest new position + */ + void run(Shape s, Vec3f origin, Vec3f dest); + } + + /** * General {@link Shape} listener action */ public static interface Listener { @@ -176,7 +189,7 @@ public abstract class Shape { private ArrayList<MouseGestureListener> mouseListeners = new ArrayList<MouseGestureListener>(); private ListenerBool onInitListener = null; - private Listener onMoveListener = null; + private MoveListener onMoveListener = null; private Listener onToggleListener = null; private Listener onActivationListener = null; private Listener onClickedListener = null; @@ -306,7 +319,7 @@ public abstract class Shape { /** * Set user callback to be notified when shape is {@link #move(Vec3f)}'ed. */ - public final void onMove(final Listener l) { onMoveListener = l; } + public final void onMove(final MoveListener l) { onMoveListener = l; } /** * Set user callback to be notified when shape {@link #toggle()}'ed. * <p> @@ -335,40 +348,36 @@ public abstract class Shape { /** Move to scaled position. Position ends up in PMVMatrix4f unmodified. */ public final Shape moveTo(final float tx, final float ty, final float tz) { - position.set(tx, ty, tz); - if( null != onMoveListener ) { - onMoveListener.run(this); - } + forwardMove(position.copy(), position.set(tx, ty, tz)); return this; } /** Move to scaled position. Position ends up in PMVMatrix4f unmodified. */ public final Shape moveTo(final Vec3f t) { - position.set(t); - if( null != onMoveListener ) { - onMoveListener.run(this); - } + forwardMove(position.copy(), position.set(t)); return this; } /** Move about scaled distance. Position ends up in PMVMatrix4f unmodified. */ public final Shape move(final float dtx, final float dty, final float dtz) { - position.add(dtx, dty, dtz); - if( null != onMoveListener ) { - onMoveListener.run(this); - } + forwardMove(position.copy(), position.add(dtx, dty, dtz)); return this; } /** Move about scaled distance. Position ends up in PMVMatrix4f unmodified. */ public final Shape move(final Vec3f dt) { - position.add(dt); - if( null != onMoveListener ) { - onMoveListener.run(this); - } + forwardMove(position.copy(), position.add(dt)); return this; } + private final void forwardMove(final Vec3f origin, final Vec3f dest) { + if( !origin.isEqual(dest) ) { + if( null != onMoveListener ) { + onMoveListener.run(this, origin, dest); + } + } + } + /** Returns position, i.e. scaled translation as set via {@link #moveTo(float, float, float) or {@link #move(float, float, float)}}. */ public final Vec3f getPosition() { return position; } |