diff options
author | Sven Göthel <[email protected]> | 2024-01-19 00:30:04 +0100 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-01-19 00:30:04 +0100 |
commit | 30369089cd02e9a0a4875c2a5f5958bcf497c701 (patch) | |
tree | 3482d60d2d4e43f4d7aba07f89518ca95c1ca11d /src/graphui/classes/com/jogamp/graph/ui/TooltipText.java | |
parent | f6ae0ff2e4bad67c929a53d705af02e7d92368bc (diff) |
GraphUI Tooltip*: Generalize Tooltip base (more versatile) and add TooltipShape supporting general Shapes to be added
Diffstat (limited to 'src/graphui/classes/com/jogamp/graph/ui/TooltipText.java')
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/TooltipText.java | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/TooltipText.java b/src/graphui/classes/com/jogamp/graph/ui/TooltipText.java index b421604c9..77386d224 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/TooltipText.java +++ b/src/graphui/classes/com/jogamp/graph/ui/TooltipText.java @@ -31,10 +31,12 @@ import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.font.Font; import com.jogamp.graph.ui.shapes.Button; +import com.jogamp.math.Vec2f; import com.jogamp.math.Vec4f; import com.jogamp.math.geom.AABBox; import com.jogamp.math.geom.plane.AffineTransform; import com.jogamp.math.util.PMVMatrix4f; +import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLProfile; /** A HUD text {@link Tooltip} for {@link Shape}, see {@link Shape#setToolTip(Tooltip)}. */ @@ -44,9 +46,6 @@ public class TooltipText extends Tooltip { /** Font of this tooltip */ private final Font tipFont; private final float scaleY; - private final int renderModes; - private final Vec4f backColor = new Vec4f(); - private final Vec4f labelColor = new Vec4f(); /** * Ctor of {@link TooltipText}. @@ -61,13 +60,10 @@ public class TooltipText extends Tooltip { public TooltipText(final CharSequence tipText, final Font tipFont, final Vec4f backColor, final Vec4f labelColor, final float scaleY, final long delayMS, final int renderModes) { - super(delayMS); + super(backColor, labelColor, delayMS, renderModes); this.tipText = tipText; this.tipFont = tipFont; this.scaleY = scaleY; - this.renderModes = renderModes; - this.backColor.set(backColor); - this.labelColor.set(labelColor); } /** * Ctor of {@link TooltipText} using {@link Tooltip#DEFAULT_DELAY}, {@link Region#VBAA_RENDERING_BIT} @@ -78,43 +74,37 @@ public class TooltipText extends Tooltip { * @param tool the tool shape for this tip */ public TooltipText(final CharSequence tipText, final Font tipFont, final float scaleY) { - this(tipText, tipFont, new Vec4f(1, 1, 0, 0.80f), new Vec4f(0.1f, 0.1f, 0.1f, 1), scaleY, Tooltip.DEFAULT_DELAY, Region.VBAA_RENDERING_BIT); + this(tipText, tipFont, null, null, scaleY, Tooltip.DEFAULT_DELAY, Region.VBAA_RENDERING_BIT); } @Override - public Shape createTip(final Scene scene, final PMVMatrix4f pmv) { + public Shape createTip(final GLAutoDrawable gl, final Scene scene, final PMVMatrix4f pmv, final AABBox toolMvBounds) { final float zEps = scene.getZEpsilon(16); // Precompute text-box size .. guessing pixelSize + final AABBox sceneAABox = scene.getBounds(); final AffineTransform tempT1 = new AffineTransform(); final AffineTransform tempT2 = new AffineTransform(); final AABBox tipBox_em = tipFont.getGlyphBounds(tipText, tempT1, tempT2); - // final AABBox toolAABox = scene.getBounds(new PMVMatrix4f(), tool); - final AABBox toolAABox = getTool().getBounds().transform(pmv.getMv(), new AABBox()); - - final float h = toolAABox.getHeight() * scaleY; - final float w = tipBox_em.getWidth() / tipBox_em.getHeight() * h; - - final AABBox sceneAABox = scene.getBounds(); - final float xpos, ypos; - if( toolAABox.getCenter().x()-w/2 < sceneAABox.getLow().x() ) { - xpos = sceneAABox.getLow().x(); - } else { - xpos = toolAABox.getCenter().x()-w/2; - } - if( toolAABox.getHigh().y() > sceneAABox.getHigh().y() - h ) { - ypos = sceneAABox.getHigh().y() - h; - } else { - ypos = toolAABox.getHigh().y(); + float h = toolMvBounds.getHeight() * scaleY; + float w = tipBox_em.getWidth() * h / tipBox_em.getHeight(); + if( w > sceneAABox.getWidth() * 0.9f) { + w = sceneAABox.getWidth() * 0.9f; + h = tipBox_em.getHeight() * w / tipBox_em.getWidth(); + } else if( h > sceneAABox.getHeight() * 0.9f) { + h = sceneAABox.getHeight() * 0.9f; + w = tipBox_em.getWidth() * h / tipBox_em.getHeight(); } + final Vec2f pos = getTipMvPosition(scene, toolMvBounds, w, h); + final Button ntip = (Button) new Button(renderModes, tipFont, tipText, w, h, zEps) .setPerp() - .moveTo(xpos, ypos, 100*zEps) + .moveTo(pos.x(), pos.y(), 100*zEps) .setColor(backColor) // .setBorder(0.05f).setBorderColor(0, 0, 0, 1) .setInteractive(false); - ntip.setLabelColor(labelColor); + ntip.setLabelColor(frontColor); ntip.setSpacing(0.10f, 0.10f); return ntip; } |