aboutsummaryrefslogtreecommitdiffstats
path: root/src/graphui/classes
diff options
context:
space:
mode:
authorSven Göthel <[email protected]>2024-01-22 08:37:26 +0100
committerSven Göthel <[email protected]>2024-01-22 08:37:26 +0100
commit6c11c32f4081e9029eeed281d317894bd179f1e3 (patch)
tree7b338bf48fb698aac9e71a638920c4b22a4947af /src/graphui/classes
parent6cf158cc59e901b49ab54681e363d23492421a9d (diff)
Simplify TooltipShape: Create own wrapper Group to not mutate user given Shape (if reused in DAG); Fix FontView01 TooltipShape instance, use NoOp DestroyCallback
Diffstat (limited to 'src/graphui/classes')
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/Tooltip.java7
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/TooltipShape.java100
2 files changed, 80 insertions, 27 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Tooltip.java b/src/graphui/classes/com/jogamp/graph/ui/Tooltip.java
index b7a79b4ca..91e67dbb7 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Tooltip.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Tooltip.java
@@ -37,6 +37,8 @@ import com.jogamp.math.geom.AABBox;
import com.jogamp.math.util.PMVMatrix4f;
import com.jogamp.opengl.GL2ES2;
import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLProfile;
+import com.jogamp.opengl.util.texture.TextureSequence;
/** A HUD tooltip for {@link Shape}, see {@link Shape#setToolTip(Tooltip)}. */
public abstract class Tooltip {
@@ -51,6 +53,7 @@ public abstract class Tooltip {
private volatile boolean forced;
/** Shape 'tool' owning this tooltip. */
private Shape tool;
+ /** Graph's {@link Region} render modes, see {@link GLRegion#create(GLProfile, int, TextureSequence) create(..)}. */
protected final int renderModes;
protected final Vec4f backColor = new Vec4f(1, 1, 0, 1);
protected final Vec4f frontColor = new Vec4f(0.1f, 0.1f, 0.1f, 1);
@@ -185,8 +188,8 @@ public abstract class Tooltip {
* <p>
* This default implementation simply calls {@link Shape#destroy(GL2ES2, RegionRenderer)}.
* </p>
- * @param gl
- * @param renderer
+ * @param gl current {@link GL2ES2}
+ * @param renderModes Graph's {@link Region} render modes, see {@link GLRegion#create(GLProfile, int, TextureSequence) create(..)}.
* @param tip
* @see #createTip(GLAutoDrawable, Scene, PMVMatrix4f, AABBox)
*/
diff --git a/src/graphui/classes/com/jogamp/graph/ui/TooltipShape.java b/src/graphui/classes/com/jogamp/graph/ui/TooltipShape.java
index 40cc8c66d..be73252fd 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/TooltipShape.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/TooltipShape.java
@@ -27,9 +27,12 @@
*/
package com.jogamp.graph.ui;
+import com.jogamp.graph.curve.Region;
+import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.ui.layout.Alignment;
import com.jogamp.graph.ui.layout.BoxLayout;
+import com.jogamp.graph.ui.layout.Padding;
import com.jogamp.graph.ui.shapes.Rectangle;
import com.jogamp.math.Vec2f;
import com.jogamp.math.Vec4f;
@@ -37,30 +40,47 @@ import com.jogamp.math.geom.AABBox;
import com.jogamp.math.util.PMVMatrix4f;
import com.jogamp.opengl.GL2ES2;
import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLProfile;
+import com.jogamp.opengl.util.texture.TextureSequence;
/** A HUD {@link Shape} {@link Tooltip} for {@link Shape}, see {@link Shape#setToolTip(Tooltip)}. */
public class TooltipShape extends Tooltip {
/**
- * Optional HUD tip destroy callback for the user provided {@link Shape}, see {@link #Tooltip#destroyTip(GL2ES2, RegionRenderer, Shape)}.
+ * Optional HUD tip {@link #destroy(TooltipShape, GL2ES2, RegionRenderer, Shape) destroy callback}
+ * for the user provided {@link Shape}, see {@link Tooltip#destroyTip(GL2ES2, RegionRenderer, Shape)}.
* <p>
* In case no callback is being set via {@link TooltipShape#TooltipShape(Vec2f, long, Shape, DestroyCallback)}
- * {@link #Tooltip#destroyTip(GL2ES2, RegionRenderer, Shape)} destroys the shape.
- * Otherwise the callback gets invoked.
+ * {@link Tooltip#destroyTip(GL2ES2, RegionRenderer, Shape)} destroys the shape.
+ * Otherwise this callback gets invoked.
+ * </p>
+ * <p>
+ * In case user provided {@code tip} is reused within a DAG,
+ * the provided implementation shall do nothing, i.e. use {@link TooltipShape#NoOpDtor}.
* </p>
- * @param gl
- * @param renderer
- * @param tip the user provided {@link Shape} as passed via {@link TooltipShape#TooltipShape(Vec4f, Vec4f, float, Vec2f, long, int, Shape, DestroyCallback)}.
* @see TooltipShape#TooltipShape(Vec2f, long, Shape, DestroyCallback)
* @see TooltipShape#createTip(GLAutoDrawable, Scene, PMVMatrix4f, AABBox)
*/
public static interface DestroyCallback {
- public void destroyTip(final GL2ES2 gl, final RegionRenderer renderer, final Shape tip);
+ /**
+ * The custom destroy method of {@link DestroyCallback}
+ * @param tts the {#link TooltipShape} instance
+ * @param gl current {@link GL2ES2}
+ * @param renderer used {@link RegionRenderer}
+ * @param tip the user provided {@link Shape} as passed via {@link TooltipShape#TooltipShape(Vec4f, Vec4f, float, Vec2f, long, int, Shape, DestroyCallback)}.
+ */
+ public void destroy(TooltipShape tts, final GL2ES2 gl, final RegionRenderer renderer, final Shape tip);
}
+ /** No operation {@link DestroyCallback}, e.g. for a user provide {@code tip} {@link Shape}, reused within a DAG. */
+ public static DestroyCallback NoOpDtor = new DestroyCallback() {
+ @Override
+ public void destroy(final TooltipShape tts, final GL2ES2 gl, final RegionRenderer renderer, final Shape tip) { }
+ };
- /** Text of this tooltip */
- private final Shape tip;
+ /** Shape of this tooltip */
+ private volatile Shape tip;
private final Vec2f scale;
private final float borderThickness;
+ private final Padding padding;
private final DestroyCallback dtorCallback;
/**
@@ -71,32 +91,53 @@ public class TooltipShape extends Tooltip {
* </p>
* @param scale HUD tip scale for the tip shape
* @param delayMS delay until HUD tip is visible after timer start (mouse moved)
+ * @param renderModes Graph's {@link Region} render modes, see {@link GLRegion#create(GLProfile, int, TextureSequence) create(..)}.
* @param tip HUD tip shape
*/
public TooltipShape(final Vec2f scale, final long delayMS, final int renderModes, final Shape tip) {
- this(null, null, 0, scale, delayMS, renderModes, tip, null);
+ this(null, null, 0, null, scale, delayMS, renderModes, tip, null);
}
/**
* Ctor of {@link TooltipShape}.
* <p>
- * The {@link Shape} is not destroyed via {@link #destroyTip(GL2ES2, RegionRenderer, Shape)},
- * if {@link DestroyCallback} {@code dtor} is not {@code null}, otherwise it is destroyed.
+ * The {@link Shape} is destroyed via provided {@link DestroyCallback} {@code dtor} if not {@code null},
+ * otherwise the default {@link Tooltip#destroyTip(GL2ES2, RegionRenderer, Shape)} gets called.
+ * </p>
+ * <p>
+ * In case {@link DestroyCallback} {@code dtor} is being used, the user {@code tip}
+ * is removed from internal layout shapes before they get destroyed and the single {@code tip}
+ * gets passed to {@link DestroyCallback#destroy(TooltipShape, GL2ES2, RegionRenderer, Shape)}.
+ * </p>
+ * <p>
+ * In case user provided {@code tip} is reused within a DAG,
+ * the provided implementation shall do nothing, i.e. use {@link TooltipShape#NoOpDtor}.
* </p>
+ * @param backColor optional background color
+ * @param borderColor optional border color
+ * @param borderThickness border thickness
+ * @param padding optional padding for the given {@code tip} for the internal wrapper group
* @param scale HUD tip scale for the tip shape
* @param delayMS delay until HUD tip is visible after timer start (mouse moved)
+ * @param renderModes Graph's {@link Region} render modes, see {@link GLRegion#create(GLProfile, int, TextureSequence) create(..)}.
* @param tip HUD tip shape
- * @param dtor
+ * @param dtor optional {@link DestroyCallback}
*/
public TooltipShape(final Vec4f backColor, final Vec4f borderColor, final float borderThickness,
- final Vec2f scale, final long delayMS, final int renderModes, final Shape tip, final DestroyCallback dtor) {
+ final Padding padding, final Vec2f scale,
+ final long delayMS, final int renderModes, final Shape tip, final DestroyCallback dtor) {
super(backColor, borderColor, delayMS, renderModes);
this.tip = tip;
this.scale = scale;
this.borderThickness = borderThickness;
+ this.padding = padding;
this.dtorCallback = dtor;
}
+ public void setTip(final Shape tip) {
+ this.tip = tip;
+ }
+
@Override
public Shape createTip(final GLAutoDrawable drawable, final Scene scene, final PMVMatrix4f pmv, final AABBox toolMvBounds) {
final float zEps = scene.getZEpsilon(16);
@@ -104,26 +145,35 @@ public class TooltipShape extends Tooltip {
final float w = toolMvBounds.getWidth()*scale.x();
final float h = toolMvBounds.getHeight()*scale.y();
- final Group g = new Group(new BoxLayout(w, h, Alignment.FillCenter));
- g.addShape(new Rectangle(renderModes, 1*w/h, 1, 0).setColor(backColor).setBorder(borderThickness).setBorderColor(frontColor).move(0, 0, -zEps));
- g.setName("TooltipShapeGroup");
- g.addShape(tip);
- g.setInteractive(false);
+ // tipWrapper ensures user 'tip' shape won't get mutated (scale, move) for DAG
+ final Group tipWrapper = new Group("TTSWrapper", null, null, tip);
+ if( null != padding ) {
+ tipWrapper.setPaddding(padding);
+ }
+ final Group tipGroup = new Group(new BoxLayout(w, h, Alignment.FillCenter));
+ tipGroup.addShape(new Rectangle(renderModes, 1*w/h, 1, 0).setColor(backColor).setBorder(borderThickness).setBorderColor(frontColor).move(0, 0, -zEps));
+ tipGroup.setName("TTSGroup");
+ tipGroup.addShape(tipWrapper);
+ tipGroup.setInteractive(false);
final Vec2f pos = getTipMvPosition(scene, toolMvBounds, w, h);
- g.moveTo(pos.x(), pos.y(), 100*zEps);
- return g;
+ tipGroup.moveTo(pos.x(), pos.y(), 100*zEps);
+ return tipGroup;
}
@Override
- public void destroyTip(final GL2ES2 gl, final RegionRenderer renderer, final Shape tipGroup) {
+ public void destroyTip(final GL2ES2 gl, final RegionRenderer renderer, final Shape tipGroup_) {
if( null != dtorCallback ) {
// Remove user tip from our layout group first and dtor our group
// This allows the user to receive its own passed tip
- ((Group)tipGroup).removeShape(tip);
+ final Group tipGroup = (Group)tipGroup_;
+ final Group tipWrapper = (Group)tipGroup.getShapeByIdx(1);
+ if( null == tipWrapper.removeShape(tip) ) {
+ throw new RuntimeException("Tip "+tip.getName()+" not contained in "+tipWrapper.getName());
+ }
tipGroup.destroy(gl, renderer);
- dtorCallback.destroyTip(gl, renderer, tip);
+ dtorCallback.destroy(this, gl, renderer, tip);
} else {
- super.destroyTip(gl, renderer, tipGroup);
+ super.destroyTip(gl, renderer, tipGroup_);
}
}
}