aboutsummaryrefslogtreecommitdiffstats
path: root/src/graphui/classes/com/jogamp/graph/ui
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-09-23 20:38:50 +0200
committerSven Gothel <[email protected]>2023-09-23 20:38:50 +0200
commit84b26f9efcd62cc8c41bf3cd867482080d16d7a0 (patch)
treedef9df15c9c97ceac107ec41814eed6fc26e3f17 /src/graphui/classes/com/jogamp/graph/ui
parent3ecb8e9d1bfd1149f32b05c13c5ec1be6c0cab54 (diff)
Bug 1454 - GraphUI Scene: Elevate active (selected) shape (add z-offset) and select (pick) in Z descending order
Picking (select) a shape shall process all shapes in Z descending order, i.e. top shape first. This is a bug currently. Note: Picking (selecting) a shape using a (mouse-)pointer device is active by mouse-moved and not only mouse-clicked. Therefor, we select shapes by mouse-over. The active selected shape shall have an elevated Z offset to be rendered on top of the others on same plane. - This avoids them being rendered below others while moving them around etc. - This also avoids flickering of overlapping shapes with mouse over. - This stabilizes the UI experience
Diffstat (limited to 'src/graphui/classes/com/jogamp/graph/ui')
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/Scene.java15
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/Shape.java14
2 files changed, 28 insertions, 1 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/Scene.java
index 388b7c1e1..25733a21d 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Scene.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Scene.java
@@ -560,7 +560,7 @@ public final class Scene implements Container, GLEventListener {
final Ray ray = new Ray();
shape[0] = null;
- forSortedAll(Shape.ZAscendingComparator, pmv, (final Shape s, final PMVMatrix4f pmv2) -> {
+ forSortedAll(Shape.ZDescendingComparator, pmv, (final Shape s, final PMVMatrix4f pmv2) -> {
final boolean ok = s.isInteractive() && pmv.mapWinToRay(glWinX, glWinY, winZ0, winZ1, viewport, ray);
if( ok ) {
final AABBox sbox = s.getBounds();
@@ -916,11 +916,24 @@ public final class Scene implements Container, GLEventListener {
}
public void releaseActiveShape() {
+ if( null != activeShape && !FloatUtil.isZero(lastActiveZOffset) ) {
+ activeShape.move(0, 0, -lastActiveZOffset);
+ lastActiveZOffset = 0f;
+ }
activeShape = null;
}
private void setActiveShape(final Shape shape) {
+ if( activeShape != shape ) {
+ releaseActiveShape();
+ lastActiveZOffset = zOffsetScale * getZEpsilon(16);
+ if( null != shape && !FloatUtil.isZero(lastActiveZOffset) ) {
+ shape.move(0, 0, +lastActiveZOffset);
+ }
+ }
activeShape = shape;
}
+ private float lastActiveZOffset = 0f;
+ private static final float zOffsetScale = 10f;
private final class SBCGestureListener implements GestureHandler.GestureListener {
@Override
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java
index 70ceb9f95..db7d7d9c2 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java
@@ -1559,6 +1559,20 @@ public abstract class Shape {
}
} };
+ 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;
+ }
+ } };
+
//
//
//