From 4f2e451d9f6d8edadc1dc392d3831d3b25675693 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 30 Mar 2023 20:55:53 +0200 Subject: GraphUI: Fix debug-box and allow API access in Shape (off, thickness fractional to box size) and Scene for all Shapes. --- .../classes/com/jogamp/graph/ui/gl/GraphShape.java | 60 +++++++++++++--------- .../classes/com/jogamp/graph/ui/gl/Scene.java | 26 ++++++++-- .../classes/com/jogamp/graph/ui/gl/Shape.java | 17 ++++-- .../com/jogamp/graph/ui/gl/shapes/Button.java | 6 +-- .../jogamp/graph/ui/gl/shapes/TexSeqButton.java | 2 +- 5 files changed, 77 insertions(+), 34 deletions(-) (limited to 'src/graphui/classes/com') diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/GraphShape.java b/src/graphui/classes/com/jogamp/graph/ui/gl/GraphShape.java index 8153d2b23..f2c60a12c 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/gl/GraphShape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/gl/GraphShape.java @@ -147,40 +147,54 @@ public abstract class GraphShape extends Shape { region.clear(gl); } addShapeToRegion(); + if( hasDebugBox() ) { + addDebugOutline(); + } region.setQuality(regionQuality); } else if( isStateDirty() ) { region.markStateDirty(); } } - protected OutlineShape createDebugOutline(final OutlineShape shape, final AABBox box) { - final float d = 0.025f; - final float tw = box.getWidth() + d*2f; - final float th = box.getHeight() + d*2f; - - final float minX = box.getMinX() - d; - final float minY = box.getMinY() - d; - final float z = 0; // box.getMinZ() + 0.025f; - - // CCW! - shape.moveTo(minX, minY, z); - shape.lineTo(minX+tw, minY, z); - shape.lineTo(minX+tw, minY + th, z); - shape.lineTo(minX, minY + th, z); - shape.closePath(); - - // shape.addVertex(minX, minY, z, true); - // shape.addVertex(minX+tw, minY, z, true); - // shape.addVertex(minX+tw, minY + th, z, true); - // shape.addVertex(minX, minY + th, z, true); - // shape.closeLastOutline(true); - - return shape; + private final float[] dbgColor = {0.3f, 0.3f, 0.3f, 0.5f}; + + protected void addDebugOutline() { + final OutlineShape shape = new OutlineShape(vertexFactory); + final float x1 = box.getMinX(); + final float x2 = box.getMaxX(); + final float y1 = box.getMinY(); + final float y2 = box.getMaxY(); + final float z = box.getCenter()[2]; // 0; // box.getMinZ() + 0.025f; + { + // Outer OutlineShape as Winding.CCW. + shape.moveTo(x1, y1, z); + shape.lineTo(x2, y1, z); + shape.lineTo(x2, y2, z); + shape.lineTo(x1, y2, z); + shape.lineTo(x1, y1, z); + shape.closeLastOutline(true); + shape.addEmptyOutline(); + } + { + // Inner OutlineShape as Winding.CW. + final float dxy0 = box.getWidth() < box.getHeight() ? box.getWidth() : box.getHeight(); + final float dxy = dxy0 * getDebugBox(); + shape.moveTo(x1+dxy, y1+dxy, z); + shape.lineTo(x1+dxy, y2-dxy, z); + shape.lineTo(x2-dxy, y2-dxy, z); + shape.lineTo(x2-dxy, y1+dxy, z); + shape.lineTo(x1+dxy, y1+dxy, z); + shape.closeLastOutline(true); + } + shape.setIsQuadraticNurbs(); + shape.setSharpness(oshapeSharpness); + region.addOutlineShape(shape, null, dbgColor); } protected void clearImpl(final GL2ES2 gl, final RegionRenderer renderer) { } protected void destroyImpl(final GL2ES2 gl, final RegionRenderer renderer) { } + protected abstract void addShapeToRegion(); } diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java index 46e75acd5..3326f9e97 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java +++ b/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java @@ -99,6 +99,7 @@ public final class Scene implements GLEventListener { private static final boolean DEBUG = false; private final ArrayList shapes = new ArrayList(); + private float dbgbox_thickness = 0f; private boolean doFrustumCulling = false; private float[] clearColor = null; @@ -203,29 +204,35 @@ public final class Scene implements GLEventListener { return shapes; } public void addShape(final Shape s) { + s.setDebugBox(dbgbox_thickness); shapes.add(s); } /** Removes given shape, keeps it alive. */ public void removeShape(final Shape s) { + s.setDebugBox(0f); shapes.remove(s); } /** Removes all given shapes and destroys them. */ public void removeShape(final GL2ES2 gl, final Shape s) { + s.setDebugBox(0f); shapes.remove(s); s.destroy(gl, renderer); } public void addShapes(final Collection shapes) { - this.shapes.addAll(shapes); + for(final Shape s : shapes) { + addShape(s); + } } /** Removes all given shapes, keeps them alive. */ public void removeShapes(final Collection shapes) { - this.shapes.removeAll(shapes); + for(final Shape s : shapes) { + removeShape(s); + } } /** Removes all given shapes and destroys them. */ public void removeShapes(final GL2ES2 gl, final Collection shapes) { - this.shapes.removeAll(shapes); for(final Shape s : shapes) { - s.destroy(gl, renderer); + removeShape(gl, s); } } public Shape getShapeByIdx(final int id) { @@ -272,6 +279,17 @@ public final class Scene implements GLEventListener { } } + /** + * Sets the {@link #getBounds()} fractional thickness of the debug box ranging [0..1] for all shapes, zero for no debug box (default). + * @param v fractional thickness of {@link #getBounds()} ranging [0..1], zero for no debug box + */ + public final void setDebugBox(final float v) { + dbgbox_thickness = v; + for(int i=0; i mouseListeners = new ArrayList(); private Listener onMoveListener = null; @@ -120,6 +121,18 @@ public abstract class Shape { /** Enable or disable this shape, i.e. its visibility. */ public final void setEnabled(final boolean v) { enabled = v; } + /** + * Sets the {@link #getBounds()} fractional thickness of the debug box ranging [0..1], zero for no debug box (default). + * @param v fractional thickness of {@link #getBounds()} ranging [0..1], zero for no debug box + */ + public final void setDebugBox(final float v) { + dbgbox_thickness = Math.min(1f, Math.max(0f, v)); + } + /** Returns true if a debug box has been enabled via {@link #setDebugBox(float)}. */ + public final boolean hasDebugBox() { return !FloatUtil.isZero(dbgbox_thickness); } + /** Returns the fractional thickness of the debug box ranging [0..1], see {@link #setDebugBox(float)}. */ + public final float getDebugBox() { return dbgbox_thickness; } + /** * Clears all data and reset all states as if this instance was newly created * @param gl TODO @@ -1164,8 +1177,6 @@ public abstract class Shape { protected abstract void destroyImpl0(final GL2ES2 gl, final RegionRenderer renderer); - protected abstract void addShapeToRegion(); - /** * Returns true if implementation uses an extra color channel or texture * which will be modulated with the passed rgba color {@link #drawImpl0(GL2ES2, RegionRenderer, int[], float[])}. diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Button.java b/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Button.java index 90cd11b71..2f2e4c469 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Button.java +++ b/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Button.java @@ -117,7 +117,7 @@ public class Button extends RoundButton { final float[] ctr = box.getCenter(); final float[] ltxy = new float[] { ctr[0] - lctr[0], ctr[1] - lctr[1] }; - if( DRAW_DEBUG_BOX ) { + if( DEBUG_DRAW ) { System.err.println("Button: dim "+width+" x "+height+", spacing "+spacingX+", "+spacingY); System.err.println("Button: net-text "+lw+" x "+lh); System.err.println("Button: shape "+box); @@ -128,13 +128,13 @@ public class Button extends RoundButton { } final AABBox lbox2 = label.addShapeToRegion(lScale, region, ltxy, tempT1, tempT2, tempT3); - if( DRAW_DEBUG_BOX ) { + if( DEBUG_DRAW ) { System.err.printf("Button.X: lbox2 %s%n", lbox2); } setRotationPivot( ctr ); - if( DRAW_DEBUG_BOX ) { + if( DEBUG_DRAW ) { System.err.println("XXX.Button: Added Shape: "+shape+", "+box); } } diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/TexSeqButton.java b/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/TexSeqButton.java index 5afe1c373..5ee164580 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/TexSeqButton.java +++ b/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/TexSeqButton.java @@ -75,7 +75,7 @@ public abstract class TexSeqButton extends RoundButton { setRotationPivot( box.getCenter() ); - if( DRAW_DEBUG_BOX ) { + if( DEBUG_DRAW ) { System.err.println("XXX.UIShape.TextureSeqButton: Added Shape: "+shape+", "+box); } } -- cgit v1.2.3