aboutsummaryrefslogtreecommitdiffstats
path: root/src/graphui/classes/com/jogamp/graph/ui
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-12-18 09:11:44 +0100
committerSven Gothel <[email protected]>2023-12-18 09:11:44 +0100
commit47f5e083ba79ac02590a452149e31bf433109346 (patch)
tree64bafcb31731310b79acb56416cd2f26d6a2ec75 /src/graphui/classes/com/jogamp/graph/ui
parentd99c2d8b28470d335ab5b30124ef8b0607b3b90f (diff)
Bug 805: GraphUI: Add Group.replaceShape(..) and Shape.getParent()
Group.replaceShape(..) allows replacing a shape w/o disturbing a layout, e.g. to zoom one element by taking it out of a grid-group and placing it on-top of the Scene while using a placeholder in the grid until returned. Shape.getParent() - depending on use-case (w/o DAG) - allows access and control of a shape's Group.
Diffstat (limited to 'src/graphui/classes/com/jogamp/graph/ui')
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/Container.java1
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/Group.java30
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/Shape.java13
3 files changed, 42 insertions, 2 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Container.java b/src/graphui/classes/com/jogamp/graph/ui/Container.java
index 32da78791..dd8fe99f9 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Container.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Container.java
@@ -79,6 +79,7 @@ public interface Container {
Shape getShapeByID(final int id);
Shape getShapeByName(final String name);
+ /** Returns {@link AABBox} dimension of given {@link Shape} from this container's perspective, i.e. world-bounds if performing from the {@link Scene}. */
AABBox getBounds(final PMVMatrix4f pmv, Shape shape);
/** Enable or disable {@link PMVMatrix4f#getFrustum()} culling per {@link Shape}. Default is disabled. */
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Group.java b/src/graphui/classes/com/jogamp/graph/ui/Group.java
index 1a05f75b5..5548408e0 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Group.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Group.java
@@ -119,6 +119,7 @@ public class Group extends Shape implements Container {
@Override
public void addShape(final Shape s) {
shapes.add(s);
+ s.setParent(this);
markShapeDirty();
}
@@ -126,6 +127,7 @@ public class Group extends Shape implements Container {
@Override
public Shape removeShape(final Shape s) {
if( shapes.remove(s) ) {
+ s.setParent(null);
markShapeDirty();
return s;
} else {
@@ -133,10 +135,32 @@ public class Group extends Shape implements Container {
}
}
+ /**
+ * Atomic replacement of the given {@link Shape} {@code remove} with {@link Shape} {@code replacement}.
+ * @param remove the shape to be replaced
+ * @param replacement the replacement shape to be inserted at same position
+ * @return true if shape {@code remove} is contained and replaced by {@code replacement}, otherwise false.
+ */
+ public boolean replaceShape(final Shape remove, final Shape replacement) {
+ final int idx = shapes.indexOf(remove);
+ if( 0 > idx ) {
+ return false;
+ }
+ if( null == shapes.remove(idx) ) {
+ return false;
+ }
+ remove.setParent(null);
+ shapes.add(idx, replacement);
+ replacement.setParent(this);
+ markShapeDirty();
+ return true;
+ }
+
@Override
public Shape removeShape(final int idx) {
final Shape r = shapes.remove(idx);
if( null != r ) {
+ r.setParent(null);
markShapeDirty();
}
return r;
@@ -151,6 +175,7 @@ public class Group extends Shape implements Container {
*/
public boolean removeShape(final GL2ES2 gl, final RegionRenderer renderer, final Shape s) {
if( shapes.remove(s) ) {
+ s.setParent(null);
markShapeDirty();
s.destroy(gl, renderer);
return true;
@@ -181,7 +206,10 @@ public class Group extends Shape implements Container {
@Override
public void removeAllShapes() {
- shapes.clear();
+ final int count = shapes.size();
+ for(int i=count-1; i>=0; --i) {
+ removeShape(i);
+ }
}
/** Removes all given shapes and destroys them. */
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java
index 125bb1a90..1d49a2b02 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java
@@ -138,7 +138,8 @@ public abstract class Shape {
private static final int DIRTY_SHAPE = 1 << 0 ;
private static final int DIRTY_STATE = 1 << 1 ;
-
+
+ private Group parent;
protected final AABBox box;
private final Vec3f position = new Vec3f();
@@ -206,6 +207,16 @@ public abstract class Shape {
this.box = new AABBox();
}
+ /* pp */ void setParent(final Group c) { parent = c; }
+ /**
+ * Returns the last parent container {@link Group} this shape has been added to or {@code null}.
+ * <p>
+ * Since a shape can be added to multiple container (DAG),
+ * usability of this information depends on usage.
+ * </p>
+ */
+ public Group getParent() { return parent; }
+
/** Set a symbolic ID for this shape for identification. Default is -1 for noname. */
public final Shape setID(final int id) { this.id = id; return this; }
/** Return the optional symbolic ID for this shape. */