diff options
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Scene.java | 26 | ||||
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Shape.java | 52 |
2 files changed, 43 insertions, 35 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/Scene.java index 305b9babc..22eb653de 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Scene.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Scene.java @@ -917,28 +917,19 @@ public final class Scene implements Container, GLEventListener { public void releaseActiveShape() { if( null != activeShape ) { - if( !FloatUtil.isZero(lastActiveZOffset) ) { - activeShape.move(0, 0, -lastActiveZOffset); - lastActiveZOffset = 0f; - } - activeShape.setActive(false); + activeShape.setActive(false, 0); activeShape = null; } } private void setActiveShape(final Shape shape) { if( activeShape != shape ) { releaseActiveShape(); - lastActiveZOffset = activeZOffsetScale * getZEpsilon(16); - if( null != shape && !FloatUtil.isZero(lastActiveZOffset) ) { - shape.move(0, 0, +lastActiveZOffset); + if( null != shape ) { + shape.setActive(true, activeZOffsetScale * getZEpsilon(16)); } + activeShape = shape; } - if( null != shape ) { - shape.setActive(true); - } - activeShape = shape; } - private float lastActiveZOffset = 0f; private float activeZOffsetScale = 10f; /** Returns the active {@link Shape} Z-Offset scale, defaults to {@code 10.0}. */ @@ -989,16 +980,19 @@ public final class Scene implements Container, GLEventListener { * @param glWinX in GL window coordinates, origin bottom-left * @param glWinY in GL window coordinates, origin bottom-left */ - final void dispatchMouseEventPickShape(final MouseEvent e, final int glWinX, final int glWinY) { + final boolean dispatchMouseEventPickShape(final MouseEvent e, final int glWinX, final int glWinY) { final PMVMatrix4f pmv = new PMVMatrix4f(); final Vec3f objPos = new Vec3f(); final Shape[] shape = { null }; - if( null == pickShape(pmv, glWinX, glWinY, objPos, shape, () -> { - setActiveShape(shape[0]); + if( null != pickShape(pmv, glWinX, glWinY, objPos, shape, () -> { shape[0].dispatchMouseEvent(e, glWinX, glWinY, objPos); } ) ) { + setActiveShape(shape[0]); + return true; + } else { releaseActiveShape(); + return false; } } /** diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java index 0244b2876..001f4295f 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java @@ -129,6 +129,7 @@ public abstract class Shape { protected final AABBox box; private final Vec3f position = new Vec3f(); + private float zOffset = 0; private final Quaternion rotation = new Quaternion(); private Vec3f rotPivot = null; private final Vec3f scale = new Vec3f(1f, 1f, 1f); @@ -1202,7 +1203,8 @@ public abstract class Shape { /** Returns true this shape's toggle state. */ public final boolean isToggleOn() { return isIO(IO_TOGGLE); } - protected final void setActive(final boolean v) { + protected final void setActive(final boolean v, final float zOffset) { + this.zOffset = zOffset; setIO(IO_ACTIVE, v); if( null != onActivationListener ) { onActivationListener.run(this); @@ -1614,32 +1616,44 @@ public abstract class Shape { */ public abstract boolean hasColorChannel(); + public final float getAscendingZ() { + return getScaledMinZ() + position.z() + zOffset; + } + public final float getDescendingZ() { + return getScaledMinZ() + position.z() + zOffset; + } + + private static int compare0(final float a, final float b) { + if( FloatUtil.isEqual2(a, b) ) { + return 0; + } else if( a < b ){ + return -1; + } else { + return 1; + } + } + private static int compare1(final float a, final float b) { + if (a < b) { + return -1; // Neither is NaN, a is smaller + } + if (a > b) { + return 1; // Neither is NaN, a is larger + } + return 0; + } + public static Comparator<Shape> ZAscendingComparator = new Comparator<Shape>() { @Override public int compare(final Shape s1, final Shape s2) { - final float s1Z = s1.getScaledMinZ()+s1.getPosition().z(); - final float s2Z = s2.getScaledMinZ()+s2.getPosition().z(); - if( FloatUtil.isEqual2(s1Z, s2Z) ) { - return 0; - } else if( s1Z < s2Z ){ - return -1; - } else { - return 1; - } + return compare1( s1.getAscendingZ(), s2.getAscendingZ() ); + // return Float.compare( s1.getAscendingZ(), s2.getAscendingZ() ); } }; public static Comparator<Shape> ZDescendingComparator = new Comparator<Shape>() { @Override public int compare(final Shape s1, final Shape s2) { - final float s1Z = s1.getScaledMinZ()+s1.getPosition().z(); - final float s2Z = s2.getScaledMinZ()+s2.getPosition().z(); - if( FloatUtil.isEqual2(s1Z, s2Z) ) { - return 0; - } else if( s1Z < s2Z ){ - return 1; - } else { - return -1; - } + return compare1( s2.getDescendingZ(), s1.getDescendingZ() ); + // return Float.compare( s2.getDescendingZ(), s1.getDescendingZ() ); } }; // |