summaryrefslogtreecommitdiffstats
path: root/src/graphui
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-03-30 20:55:53 +0200
committerSven Gothel <[email protected]>2023-03-30 20:55:53 +0200
commit4f2e451d9f6d8edadc1dc392d3831d3b25675693 (patch)
tree075ca416bd3a74e590600a52bf5a34e4ea50b36c /src/graphui
parent68092a50c3b5d7fca72b1b9dc01d59b4444bcefb (diff)
GraphUI: Fix debug-box and allow API access in Shape (off, thickness fractional to box size) and Scene for all Shapes.
Diffstat (limited to 'src/graphui')
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/gl/GraphShape.java60
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java26
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java17
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Button.java6
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/gl/shapes/TexSeqButton.java2
5 files changed, 77 insertions, 34 deletions
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);
}
}