diff options
author | Sven Gothel <[email protected]> | 2023-03-30 20:55:53 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-03-30 20:55:53 +0200 |
commit | 4f2e451d9f6d8edadc1dc392d3831d3b25675693 (patch) | |
tree | 075ca416bd3a74e590600a52bf5a34e4ea50b36c | |
parent | 68092a50c3b5d7fca72b1b9dc01d59b4444bcefb (diff) |
GraphUI: Fix debug-box and allow API access in Shape (off, thickness fractional to box size) and Scene for all Shapes.
7 files changed, 79 insertions, 34 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java index 242c94dcd..c690d14ae 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo03.java @@ -126,6 +126,7 @@ public class UISceneDemo03 { final Scene scene = new Scene(); scene.setClearParams(new float[] { 1f, 1f, 1f, 1f }, GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); scene.setPMVMatrixSetup(new MyPMVMatrixSetup()); + scene.setDebugBox(options.debugBoxThickness); final Animator animator = new Animator(); animator.setUpdateFPSFrames(1 * 60, null); // System.err); diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java index 5f4d7ae76..6751ffa6c 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java @@ -303,6 +303,7 @@ public class UISceneDemo20 implements GLEventListener { scene.setPMVMatrixSetup(new MyPMVMatrixSetup()); scene.getRenderState().setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED); // scene.setSampleCount(3); // easy on embedded devices w/ just 3 samples (default is 4)? + scene.setDebugBox(options.debugBoxThickness); } private void rotateButtons(float[] angdeg) { 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<Shape> shapes = new ArrayList<Shape>(); + 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<? extends Shape> shapes) { - this.shapes.addAll(shapes); + for(final Shape s : shapes) { + addShape(s); + } } /** Removes all given shapes, keeps them alive. */ public void removeShapes(final Collection<? extends Shape> 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<? extends Shape> 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<shapes.size(); i++) { + shapes.get(i).setDebugBox(v); + } + } + @Override public void init(final GLAutoDrawable drawable) { cDrawable = drawable; diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java index 43d174916..2eecd0862 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java @@ -69,7 +69,7 @@ public abstract class Shape { public static interface Listener { void run(final Shape shape); } - protected static final boolean DRAW_DEBUG_BOX = false; + protected static final boolean DEBUG_DRAW = false; private static final boolean DEBUG = false; private static final int DIRTY_SHAPE = 1 << 0 ; @@ -102,6 +102,7 @@ public abstract class Shape { private boolean draggable = true; private boolean resizable = true; private boolean enabled = true; + private float dbgbox_thickness = 0f; // fractional thickness of bounds, 0f for no debug box private ArrayList<MouseGestureListener> mouseListeners = new ArrayList<MouseGestureListener>(); private Listener onMoveListener = null; @@ -121,6 +122,18 @@ public abstract class Shape { 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 * @param renderer 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); } } |