diff options
author | Sven Gothel <[email protected]> | 2023-12-18 03:19:31 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-12-18 03:19:31 +0100 |
commit | 7ae9dae12553f2f8f0e6dcd494f972a50c62cb1f (patch) | |
tree | 26d0503a5c5680b360155c4e4fef7ef237f683d8 | |
parent | d0e77a9d3fee687011d0ff0d610f49262cc2834f (diff) |
GraphUI Container: Cleanup or Group/Scene add*/remove* methods
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Group.java | 32 | ||||
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Scene.java | 40 |
2 files changed, 55 insertions, 17 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Group.java b/src/graphui/classes/com/jogamp/graph/ui/Group.java index 6d3ff6e8c..77854b74a 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Group.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Group.java @@ -125,22 +125,38 @@ public class Group extends Shape implements Container { /** Removes given shape, keeps it alive. */ @Override public Shape removeShape(final Shape s) { - final Shape r = shapes.remove(s) ? s : null; - markShapeDirty(); - return r; + if( shapes.remove(s) ) { + markShapeDirty(); + return s; + } else { + return null; + } } @Override public Shape removeShape(final int idx) { final Shape r = shapes.remove(idx); - markShapeDirty(); + if( null != r ) { + markShapeDirty(); + } return r; } - /** Removes given shape and destroy it. */ - public void removeShape(final GL2ES2 gl, final RegionRenderer renderer, final Shape s) { - shapes.remove(s); - s.destroy(gl, renderer); + /** + * Removes given shape and destroy it, if contained. + * @param gl GL2ES2 context + * @param renderer + * @param s the shape to be removed + * @return true if given Shape is removed and destroyed + */ + public boolean removeShape(final GL2ES2 gl, final RegionRenderer renderer, final Shape s) { + if( shapes.remove(s) ) { + markShapeDirty(); + s.destroy(gl, renderer); + return true; + } else { + return false; + } } @Override diff --git a/src/graphui/classes/com/jogamp/graph/ui/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/Scene.java index ea5e98b84..55c9ac680 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Scene.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Scene.java @@ -268,19 +268,36 @@ public final class Scene implements Container, GLEventListener { } @Override public Shape removeShape(final Shape s) { - s.setBorder(0f); - return shapes.remove(s) ? s : null; + if( shapes.remove(s) ) { + s.setBorder(0f); + return s; + } else { + return null; + } } @Override public Shape removeShape(final int idx) { - return shapes.remove(idx); + final Shape r = shapes.remove(idx); + if( null != r ) { + r.setBorder(0f); + } + return r; } - /** Removes given shape and destroy it. */ - public void removeShape(final GL2ES2 gl, final Shape s) { - s.setBorder(0f); - shapes.remove(s); - s.destroy(gl, renderer); + /** + * Removes given shape and destroy it, if contained. + * @param gl GL2ES2 context + * @param s the shape to be removed + * @return true if given Shape is removed and destroyed + */ + public boolean removeShape(final GL2ES2 gl, final Shape s) { + if( shapes.remove(s) ) { + s.setBorder(0f); + s.destroy(gl, renderer); + return true; + } else { + return false; + } } @Override public void addShapes(final Collection<? extends Shape> shapes) { @@ -302,7 +319,12 @@ public final class Scene implements Container, GLEventListener { } @Override public void removeAllShapes() { - shapes.clear(); + final int count = shapes.size(); + for(int i=count-1; i>=0; --i) { + final Shape s = shapes.get(i); + s.setBorder(0f); + shapes.remove(s); + } } /** Removes all given shapes and destroys them. */ public void removeAllShapes(final GL2ES2 gl) { |