From 2aae33b94cea15b2fc0c54479277611c67cdaf13 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 20 Apr 2023 22:00:11 +0200 Subject: GraphUI GraphShape: createGLRegion() -> updateGLRegion(), called by addShapeToRegion() impl to utilize OutlineShape -> GLRegion ctor w/ proper buffer-size This way we avoid unnecessary buffer growth and allow creation of 'always' fitting buffer sizes. +++ Update or freshly create the GLRegion, while allocating its buffers with given initial `vertexCount` and `indexCount`. Method shall be invoked by the addShapeToRegion(GLProfile, GL2ES2) implementation before actually adding the OutlineShape to the GLRegion. addShapeToRegion(GLProfile, GL2ES2) is capable to determine initial `vertexCount` and `indexCount` buffer sizes, as it composes the OutlineShapes to be added. updateGLRegion(GLProfile, GL2ES2, TextureSequence, OutlineShape) maybe used for convenience. In case GLRegion is `null`, a new instance is being created. In case the GLRegion already exists, it will be either cleared if the GL2ES2 `gl` instance is not `null` or earmarked for deletion at a later time and a new instance is being created. --- src/graphui/classes/com/jogamp/graph/ui/Shape.java | 51 ++++++++++++++++------ 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'src/graphui/classes/com/jogamp/graph/ui/Shape.java') diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java index a8e3196c9..5ef40a57f 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java @@ -53,7 +53,7 @@ import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.opengl.util.PMVMatrix; /** - * Generic UI Shape, potentially using a Graph via {@link GraphShape} or other means of representing content. + * Generic Shape, potentially using a Graph via {@link GraphShape} or other means of representing content. *

* A shape includes the following build-in user-interactions * - drag shape w/ 1-pointer click, see {@link #setDraggable(boolean)} @@ -136,7 +136,8 @@ public abstract class Shape { private boolean resizable = true; private boolean interactive = true; private boolean enabled = true; - private float dbgbox_thickness = 0f; // fractional thickness of bounds, 0f for no debug box + private float border_thickness = 0f; + protected final Vec4f borderColor = new Vec4f(0.75f, 0.75f, 0.75f, 1.0f); private ArrayList mouseListeners = new ArrayList(); private Listener onMoveListener = null; @@ -158,17 +159,18 @@ public abstract class Shape { public final Shape setEnabled(final boolean v) { enabled = v; return this; } /** - * 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 + * Sets the thickness of the debug box, zero for no border (default). + * @param v border thickness, zero for no debug box */ - public final Shape setDebugBox(final float v) { - dbgbox_thickness = Math.min(1f, Math.max(0f, v)); + public final Shape setBorder(final float v) { + border_thickness = Math.max(0f, v); return this; } - /** 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; } + /** Returns true if a border has been enabled via {@link #setBorder(float)}. */ + public final boolean hasBorder() { return !FloatUtil.isZero(border_thickness); } + + /** Returns the border thickness, see {@link #setBorder(float)}. */ + public final float getBorderThickness() { return border_thickness; } /** * Clears all data and reset all states as if this instance was newly created @@ -760,9 +762,7 @@ public abstract class Shape { return this.winToShapeCoord(scene.getPMVMatrixSetup(), scene.getViewport(), glWinX, glWinY, pmv, objPos); } - public Vec4f getColor() { - return rgbaColor; - } + public Vec4f getColor() { return rgbaColor; } /** * Set base color. @@ -775,6 +775,17 @@ public abstract class Shape { return this; } + /** + * Set base color. + *

+ * Default base-color w/o color channel, will be modulated w/ pressed- and toggle color + *

+ */ + public final Shape setColor(final Vec4f c) { + this.rgbaColor.set(c); + return this; + } + /** * Set pressed color. *

@@ -808,6 +819,20 @@ public abstract class Shape { return this; } + public Vec4f getBorderColor() { return borderColor; } + + /** Set border color. */ + public final Shape setBorderColor(final float r, final float g, final float b, final float a) { + this.borderColor.set(r, g, b, a); + return this; + } + + /** Set border color. */ + public final Shape setBorderColor(final Vec4f c) { + this.borderColor.set(c); + return this; + } + @Override public final String toString() { return getClass().getSimpleName()+"["+getSubString()+"]"; -- cgit v1.2.3