From 6c11c32f4081e9029eeed281d317894bd179f1e3 Mon Sep 17 00:00:00 2001
From: Sven Göthel
* 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.
+ *
+ * In case user provided {@code tip} is reused within a DAG,
+ * the provided implementation shall do nothing, i.e. use {@link TooltipShape#NoOpDtor}.
*
- * 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. + *
+ *+ * 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)}. + *
+ *+ * In case user provided {@code tip} is reused within a DAG, + * the provided implementation shall do nothing, i.e. use {@link TooltipShape#NoOpDtor}. *
+ * @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_); } } } -- cgit v1.2.3