From c8ec6fa7cc16a0777db16af8b4d0d0b898f8b546 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 3 Oct 2023 02:37:32 +0200 Subject: GraphUI Shape: 'int name' -> 'int id' and add 'String name', change get/set methods accordingly --- .../classes/com/jogamp/graph/ui/Container.java | 4 ++ src/graphui/classes/com/jogamp/graph/ui/Group.java | 46 ++++++++++++++++------ src/graphui/classes/com/jogamp/graph/ui/Shape.java | 25 +++++++++--- .../com/jogamp/graph/ui/layout/BoxLayout.java | 8 ++-- 4 files changed, 60 insertions(+), 23 deletions(-) (limited to 'src/graphui') diff --git a/src/graphui/classes/com/jogamp/graph/ui/Container.java b/src/graphui/classes/com/jogamp/graph/ui/Container.java index d4bd6c9f8..32da78791 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Container.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Container.java @@ -75,6 +75,10 @@ public interface Container { boolean contains(Shape s); + Shape getShapeByIdx(final int id); + Shape getShapeByID(final int id); + Shape getShapeByName(final String name); + 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 fc29b5eb2..38e1fd12e 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Group.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Group.java @@ -272,12 +272,10 @@ public class Group extends Shape implements Container { firstGS = (GraphShape)s; } layouter.preValidate(s); - if( s.isShapeDirty() ) { - if( null != gl ) { - s.validate(gl); - } else { - s.validate(glp); - } + if( null != gl ) { + s.validate(gl); + } else { + s.validate(glp); } } layouter.layout(this, box, pmv); @@ -287,12 +285,10 @@ public class Group extends Shape implements Container { if( needsRMs && null == firstGS && s instanceof GraphShape ) { firstGS = (GraphShape)s; } - if( s.isShapeDirty() ) { - if( null != gl ) { - s.validate(gl); - } else { - s.validate(glp); - } + if( null != gl ) { + s.validate(gl); + } else { + s.validate(glp); } pmv.pushMv(); s.setTransformMv(pmv); @@ -340,6 +336,32 @@ public class Group extends Shape implements Container { return false; } + @Override + public Shape getShapeByIdx(final int id) { + if( 0 > id ) { + return null; + } + return shapes.get(id); + } + @Override + public Shape getShapeByID(final int id) { + for(final Shape b : shapes) { + if(b.getID() == id ) { + return b; + } + } + return null; + } + @Override + public Shape getShapeByName(final String name) { + for(final Shape b : shapes) { + if( b.getName().equals(name) ) { + return b; + } + } + return null; + } + @Override public AABBox getBounds(final PMVMatrix4f pmv, final Shape shape) { pmv.reset(); diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java index 254f0ae5c..ee32dbf7e 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java @@ -149,7 +149,8 @@ public abstract class Shape { private final Vec4f rgba_tmp = new Vec4f(0, 0, 0, 1); private final Vec4f cWhite = new Vec4f(1, 1, 1, 1); - private int name = -1; + private int id = -1; + private String name = "noname"; private static final int IO_ENABLED = 1 << 0; private static final int IO_INTERACTIVE = 1 << 1; @@ -191,10 +192,15 @@ public abstract class Shape { this.box = new AABBox(); } - /** Set a symbolic name for this shape for identification. Default is -1 for noname. */ - public final Shape setName(final int name) { this.name = name; return this; } + /** 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. */ + public final int getID() { return this.id; } + + /** Set a symbolic name for this shape for identification. Default is noname. */ + public final Shape setName(final String name) { this.name = name; return this; } /** Return the optional symbolic name for this shape. */ - public final int getName() { return this.name; } + public final String getName() { return this.name; } /** Returns true if this shape is enabled and hence visible, otherwise false. */ public final boolean isEnabled() { return isIO(IO_ENABLED); } @@ -1149,7 +1155,9 @@ public abstract class Shape { final String activeS = isIO(IO_ACTIVE) ? ", active" : ""; final String ps = hasPadding() ? padding.toString()+", " : ""; final String bs = hasBorder() ? "border[l "+getBorderThickness()+", c "+getBorderColor()+"], " : ""; - return getDirtyString()+", id "+name+", enabled "+isIO(IO_ENABLED)+activeS+", toggle "+isIO(IO_TOGGLE)+ + final String idS = -1 != id ? ", id "+id : ""; + final String nameS = "noname" != name ? ", '"+name+"'" : ""; + return getDirtyString()+idS+nameS+", enabled "+isIO(IO_ENABLED)+activeS+", toggle "+isIO(IO_TOGGLE)+ ", able[toggle "+isIO(IO_TOGGLEABLE)+", iactive "+isInteractive()+", resize "+isResizable()+", move "+this.isDraggable()+ "], pos["+position+"], "+pivotS+scaleS+rotateS+ ps+bs+"box"+box; @@ -1167,7 +1175,7 @@ public abstract class Shape { public final boolean isPressed() { return isIO(IO_DOWN); } /** - * + * Set this shape toggleable, default is off. * @param toggleable * @see #isInteractive() */ @@ -1180,6 +1188,11 @@ public abstract class Shape { */ public boolean isToggleable() { return isIO(IO_TOGGLEABLE); } + /** + * Set this shape's toggle state, default is off. + * @param v + * @return + */ public final Shape setToggle(final boolean v) { setIO(IO_TOGGLE, v); toggleNotify(v); diff --git a/src/graphui/classes/com/jogamp/graph/ui/layout/BoxLayout.java b/src/graphui/classes/com/jogamp/graph/ui/layout/BoxLayout.java index 80d9d0d50..a507e5de1 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/layout/BoxLayout.java +++ b/src/graphui/classes/com/jogamp/graph/ui/layout/BoxLayout.java @@ -189,7 +189,7 @@ public class BoxLayout implements Group.Layout { s.getBounds().transform(pmv.getMv(), sbox); pmv.popMv(); - final int x = 0, y = 0; + final float x = 0, y = 0; if( TRACE_LAYOUT ) { System.err.println("bl("+i+").0: sbox "+sbox+", s "+s); } @@ -245,10 +245,8 @@ public class BoxLayout implements Group.Layout { } // Position and scale shape { - // New shape position, relative to previous position - final float aX = x + dxh; - final float aY = y + dyh; - s.moveTo( aX, aY, s.getPosition().z() ); + // New shape position + s.moveTo( x + dxh, y + dyh, s.getPosition().z() ); // Remove the negative or positive delta on centered axis. // Only remove negative offset of non-centered axis (i.e. underline) -- cgit v1.2.3