aboutsummaryrefslogtreecommitdiffstats
path: root/src/graphui/classes
diff options
context:
space:
mode:
authorSven Göthel <[email protected]>2024-02-05 16:50:15 +0100
committerSven Göthel <[email protected]>2024-02-05 16:50:15 +0100
commit0ac7b2e59d5b41302f8e0ec7596d8f44447cf0a1 (patch)
tree3c361927fd3b8ff8d6dd91f40050af3a01de4715 /src/graphui/classes
parent80f226fffcab51f8e46caa48e9dd3a134ca87dd0 (diff)
Bug 1498: Refine Top-Level Widget Mode: Handle active-state by Scene, simplify and reduce runtime costs
Refines commit 43a7899fedf2a570d20b03848bf15710f30b7f26 Scene handles top-level active state via releaseActiveShape() and setActive(), now calling into setActiveTopLevel() -> dispatchActivationEvent(). Drop child's addActivationListener(forwardActivation) and isActive() override.
Diffstat (limited to 'src/graphui/classes')
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/Group.java25
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/Scene.java52
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/Shape.java13
3 files changed, 43 insertions, 47 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Group.java b/src/graphui/classes/com/jogamp/graph/ui/Group.java
index 157881483..245400700 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Group.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Group.java
@@ -495,14 +495,11 @@ public class Group extends Shape implements Container {
* <ul>
* <li>the whole group to be shown on top on (mouse over) activation of one of its elements</li>
* <li>this group's {@link #addActivationListener(Listener)} to handle all it's elements activation events</li>
- * <li>{@link #isActive()} of this group and its sub-groups to return true if one of its elements is active</li>
+ * <li>{@link #isActive()} of this group to return true if one of its elements is active</li>
* </ul>
* </p>
* <p>
- * This method modifies all elements of this group for enabled or disabled top-level widget behavior.
- * </p>
- * <p>
- * Disable this behavior via {@link #disableTopLevelWidget()}, otherwise done per-default
+ * Disable this behavior via {@link #disableTopLevelWidget()}, otherwise done
* at {@link #clear(GL2ES2, RegionRenderer)} or {@link #destroy(GL2ES2, RegionRenderer)}.
* </p>
* @param scene the top-level widget holder where this {@link Group} gets registered
@@ -511,7 +508,6 @@ public class Group extends Shape implements Container {
*/
public final Group enableTopLevelWidget(final Scene scene) {
topLevelHolder = scene;
- setWidgetChilds(true, forwardActivation);
scene.addTopLevel(this);
return this;
}
@@ -521,29 +517,12 @@ public class Group extends Shape implements Container {
topLevelHolder = null;
if( null != tlh ) {
tlh.removeTopLevel(this);
- setWidgetChilds(false, forwardActivation);
}
return this;
}
- private final void setWidgetChilds(final boolean enable, final Listener fwdActivationListener) {
- TreeTool.forAll(this, (final Shape s) -> {
- if( enable ) {
- s.addActivationListener(fwdActivationListener);
- } else {
- s.removeActivationListener(fwdActivationListener);
- }
- return false;
- });
- }
-
/** Returns whether {@link #setTopLevelWidget(boolean)} is enabled or disabled. */
public final boolean isTopLevelWidget() { return null != topLevelHolder; }
- @Override
- public boolean isActive() {
- return super.isActive() || ( isTopLevelWidget() && TreeTool.forAll(this, (final Shape gs) -> { return gs.isActive(); } ) );
- }
-
/**
* {@inheritDoc}
* <p>
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/Scene.java
index aeab6483f..b515a55e6 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Scene.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Scene.java
@@ -112,7 +112,7 @@ public final class Scene implements Container, GLEventListener {
public static final float DEFAULT_Z16_EPSILON = FloatUtil.getZBufferEpsilon(16 /* zBits */, DEFAULT_SCENE_DIST, DEFAULT_ZNEAR);
/** Default Z precision scale, i.e. multiple of {@link #DEFAULT_Z16_EPSILON} for {@link #setActiveShapeZOffsetScale(float)}. Value is {@value}. */
public static final float DEFAULT_ACTIVE_ZOFFSET_SCALE = 10f;
- /** Default Z precision scale, i.e. multiple of {@link #DEFAULT_Z16_EPSILON} for {@link #setActiveShapeZOffsetScale(float)}. Value is {@value}. */
+ /** Default Z precision scale, i.e. multiple of {@link #DEFAULT_Z16_EPSILON} for {@link #setActiveTopLevelZOffsetScale(float)}. Value is {@value}. */
public static final float DEFAULT_ACTIVE_TOPLEVEL_ZOFFSET_SCALE = 100f;
/** Default Z precision on 16-bit depth buffer using {@code -1} z-position and {@link #DEFAULT_ZNEAR}. Value is {@code 1.5256461E-4}. */
// public static final float DIST1_Z16_EPSILON = FloatUtil.getZBufferEpsilon(16 /* zBits */, -1, DEFAULT_ZNEAR);
@@ -843,17 +843,20 @@ public final class Scene implements Container, GLEventListener {
}
public void releaseActiveShape() {
- if( null != activeShape ) {
- if( DEBUG_PICKING ) {
- System.err.println("ACTIVE-RELEASE: "+activeShape);
- }
- activeShape.setActive(false, 0);
+ final Shape lastShape = activeShape;
+ if( null != lastShape ) {
+ final Group lastTL = activeTopLevel;
+ lastShape.setActive(false, 0);
activeShape = null;
- final Group lastTL = activeTopLevel;
activeTopLevel = null;
if( null != lastTL ) {
- lastTL.setZOffset(0);
+ lastTL.setActiveTopLevel(false, 0);
+ }
+ if( DEBUG_PICKING ) {
+ System.err.println("ACTIVE-RELEASE: s 0x"+Integer.toHexString(System.identityHashCode(lastShape))+", "+lastShape);
+ System.err.println("ACTIVE-RELEASE: g 0x"+Integer.toHexString(System.identityHashCode(lastTL))+", "+lastTL);
+ dumpTopLevelParent();
}
}
}
@@ -867,19 +870,19 @@ public final class Scene implements Container, GLEventListener {
final Group lastTL = activeTopLevel;
final Group thisTL = isTopLevel ? (Group)shape : getTopLevelParent(shape);
int mode = 0;
- if( null != lastShape && lastTL != lastShape ) {
+ if( null != lastShape && thisTL != lastShape ) {
lastShape.setActive(false, 0);
mode += 10;
}
if( lastTL != thisTL ) {
mode += 100;
if( null!=lastTL) {
- lastTL.setZOffset(0);
+ lastTL.setActiveTopLevel(false, 0);
mode += 1000;
}
if( null!=thisTL && !isTopLevel ) {
- thisTL.setZOffset(activeTopLevelZOffsetScale * zEpsilon);
- mode += 2000;
+ thisTL.setActiveTopLevel(true, activeTopLevelZOffsetScale * zEpsilon);
+ mode += 10000;
}
activeTopLevel = thisTL;
}
@@ -897,15 +900,20 @@ public final class Scene implements Container, GLEventListener {
}
}
private float activeZOffsetScale = DEFAULT_ACTIVE_ZOFFSET_SCALE;
- private final float activeTopLevelZOffsetScale = DEFAULT_ACTIVE_TOPLEVEL_ZOFFSET_SCALE;
+ private float activeTopLevelZOffsetScale = DEFAULT_ACTIVE_TOPLEVEL_ZOFFSET_SCALE;
/** Returns the active {@link Shape} Z-Offset scale, defaults to {@code 10.0}. */
public float getActiveShapeZOffsetScale() { return activeZOffsetScale; }
/** Sets the active {@link Shape} Z-Offset scale, defaults to {@code 10.0}. */
public void setActiveShapeZOffsetScale(final float v) { activeZOffsetScale = v; }
- protected void addTopLevel(final Group g) { topLevel.add(g); }
- protected void removeTopLevel(final Group g) { topLevel.add(g); }
+ /** Returns the general {@link Group#enableTopLevelWidget(Scene) top-level widget} Z-Offset scale, defaults to {@link #DEFAULT_ACTIVE_ZOFFSET_SCALE}. */
+ public float getActiveTopLevelZOffsetScale() { return activeTopLevelZOffsetScale; }
+ /** Sets the general {@link Group#enableTopLevelWidget(Scene) top-level widget} Z-Offset scale, defaults to {@link #DEFAULT_ACTIVE_TOPLEVEL_ZOFFSET_SCALE}. */
+ public void setActiveTopLevelZOffsetScale(final float v) { activeTopLevelZOffsetScale = v; }
+
+ /* pp */ void addTopLevel(final Group g) { topLevel.add(g); }
+ /* pp */ void removeTopLevel(final Group g) { topLevel.add(g); }
private Group getTopLevelParent(final Shape s) {
for(final Group g : topLevel) {
if(g.contains(s)) {
@@ -914,10 +922,20 @@ public final class Scene implements Container, GLEventListener {
}
return null;
}
- @SuppressWarnings("unused")
private void dumpTopLevelParent() {
+ int idx = 0;
for(final Group g : topLevel) {
- System.err.printf("TL: %s/%s, %s%n", g.getClass().getSimpleName(), g.getName(), g);
+ final boolean a0 = g.isActive();
+ System.err.printf("- %02d: 0x%08x %s %s/%s, %s%n", idx++, System.identityHashCode(g), (a0?"****":"____"), g.getClass().getSimpleName(), g.getName(), g);
+ if( g.isActive() ) {
+ final int idx1 = idx-1;
+ final int[] idx2 = { 0 };
+ TreeTool.forAll(g, (final Shape s) -> {
+ final boolean a1 = s.isActive();
+ System.err.printf("- %02d:%02d: 0x%08x %s %s/%s, %s%n", idx1, idx2[0]++, System.identityHashCode(s), (a1?"****":"____"), s.getClass().getSimpleName(), s.getName(), s);
+ 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 face8fc8f..183f8901e 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java
@@ -1610,14 +1610,13 @@ public abstract class Shape {
}
}
/** Returns true of this shape is active */
- public boolean isActive() { return isIO(IO_ACTIVE); }
+ public final boolean isActive() { return isIO(IO_ACTIVE); }
- protected final Listener forwardActivation = new Listener() {
- @Override
- public void run(final Shape shape) {
- dispatchActivationEvent(shape);
- }
- };
+ /* pp */ void setActiveTopLevel(final boolean v, final float zOffset) {
+ setZOffset(zOffset);
+ setIO(IO_ACTIVE, v);
+ dispatchActivationEvent(this);
+ }
public final float getAdjustedZ() {
return position.z() * getScale().z() + zOffset;