JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TooltipText.java
Go to the documentation of this file.
1/**
2 * Copyright 2023-2024 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.graph.ui;
29
30import com.jogamp.common.util.StringUtil;
31import com.jogamp.graph.curve.Region;
32import com.jogamp.graph.curve.opengl.GLRegion;
33import com.jogamp.graph.font.Font;
34import com.jogamp.graph.ui.shapes.Button;
35import com.jogamp.math.Vec2f;
36import com.jogamp.math.Vec4f;
37import com.jogamp.math.geom.AABBox;
38import com.jogamp.math.geom.plane.AffineTransform;
39import com.jogamp.opengl.GLProfile;
40
41/** A round {@link Button HUD text} {@link Tooltip} for {@link Shape}, see {@link Shape#setToolTip(Tooltip)}. */
42public class TooltipText extends Tooltip {
43 /** Text of this tooltip */
44 private final CharSequence tipText;
45 /** Font of this tooltip */
46 private final Font tipFont;
47 private final float scaleY;
48
49 /**
50 * Ctor of {@link TooltipText}.
51 * @param tipText HUD tip text
52 * @param tipFont HUD tip font
53 * @param backColor optional HUD tip background color, if null a slightly transparent white background is used
54 * @param labelColor optional HUD tip front color, if null an opaque almost-black is used
55 * @param scaleY HUD tip vertical scale against tool height
56 * @param delayMS delay until HUD tip is visible after timer start (mouse moved)
57 * @param renderModes Graph's {@link Region} render modes, see {@link GLRegion#create(GLProfile, int, TextureSequence) create(..)}.
58 */
59 public TooltipText(final CharSequence tipText, final Font tipFont, final Vec4f backColor, final Vec4f labelColor,
60 final float scaleY, final long delayMS, final int renderModes)
61 {
62 super(backColor, labelColor, delayMS, renderModes);
63 this.tipText = tipText;
64 this.tipFont = tipFont;
65 this.scaleY = scaleY;
66 }
67 /**
68 * Ctor of {@link TooltipText} using {@link Tooltip#DEFAULT_DELAY}, {@link Region#VBAA_RENDERING_BIT}
69 * and a slightly transparent white background with an opaque almost-black text color.
70 * @param tipText HUD tip text
71 * @param tipFont HUD tip font
72 * @param scaleY HUD tip vertical scale against tool height
73 * @param tool the tool shape for this tip
74 */
75 public TooltipText(final CharSequence tipText, final Font tipFont, final float scaleY) {
76 this(tipText, tipFont, null, null, scaleY, Tooltip.DEFAULT_DELAY, Region.VBAA_RENDERING_BIT);
77 }
78
79 @Override
80 public Shape createTip(final Scene scene, final AABBox toolMvBounds) {
81 final float zEps = scene.getZEpsilon(16);
82
83 // Precompute text-box size .. guessing pixelSize
84 final AABBox sceneAABox = scene.getBounds();
85 final AffineTransform tempT1 = new AffineTransform();
86 final AffineTransform tempT2 = new AffineTransform();
87 final AABBox tipBox_em = tipFont.getGlyphBounds(tipText, tempT1, tempT2);
88 final float dys;
89 {
90 // lineHeight = tipBox_em.getHeight() / StringUtil.getLineCount(tipText);
91 final float totalH = tipBox_em.getHeight() * ( 1 + 0.5f/StringUtil.getLineCount(tipText) );
92 dys = totalH / tipBox_em.getHeight() - 1;
93 }
94 float h = toolMvBounds.getHeight() * scaleY * ( 1 + dys );
95 float w = ( tipBox_em.getWidth() * h / tipBox_em.getHeight() ) * ( 1 - dys );
96 if( w > sceneAABox.getWidth() * 0.9f) {
97 w = sceneAABox.getWidth() * 0.9f;
98 h = tipBox_em.getHeight() * w / tipBox_em.getWidth();
99 } else if( h > sceneAABox.getHeight() * 0.9f) {
100 h = sceneAABox.getHeight() * 0.9f;
101 w = tipBox_em.getWidth() * h / tipBox_em.getHeight();
102 }
103 final Vec2f pos = getTipMvPosition(scene, toolMvBounds, w, h);
104
105 final Button ntip = (Button) new Button(renderModes, tipFont, tipText, w, h, zEps)
106 .moveTo(pos.x(), pos.y(), 100*zEps)
107 .setColor(backColor)
108 // .setBorder(0.05f).setBorderColor(0, 0, 0, 0.5f)
109 .setInteractive(false);
111 ntip.setSpacing(0.075f, dys);
112 ntip.setCorner(0.75f);
113 return ntip;
114 }
115}
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
Definition: Region.java:62
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:115
GraphUI Scene.
Definition: Scene.java:102
static float getZEpsilon(final int zBits, final PMVMatrixSetup setup)
Default Z precision on 16-bit depth buffer using -1 z-position and DEFAULT_ZNEAR.
Definition: Scene.java:126
AABBox getBounds(final PMVMatrix4f pmv, final Shape shape)
Returns AABBox dimension of given Shape from this container's perspective, i.e.
Definition: Scene.java:676
Generic Shape, potentially using a Graph via GraphShape or other means of representing content.
Definition: Shape.java:87
final Shape setInteractive(final boolean v)
Set whether this shape is interactive in general, i.e.
Definition: Shape.java:1711
final Shape moveTo(final float tx, final float ty, final float tz)
Move to scaled position.
Definition: Shape.java:543
A round HUD text Tooltip for Shape, see Shape#setToolTip(Tooltip).
TooltipText(final CharSequence tipText, final Font tipFont, final float scaleY)
Ctor of TooltipText using Tooltip#DEFAULT_DELAY, Region#VBAA_RENDERING_BIT and a slightly transparent...
TooltipText(final CharSequence tipText, final Font tipFont, final Vec4f backColor, final Vec4f labelColor, final float scaleY, final long delayMS, final int renderModes)
Ctor of TooltipText.
Shape createTip(final Scene scene, final AABBox toolMvBounds)
Create a new HUD tip shape, usually called by Scene.
A HUD tooltip for Shape, see Shape#setToolTip(Tooltip).
Definition: Tooltip.java:44
static final long DEFAULT_DELAY
Default tooltip delay is {@value}ms.
Definition: Tooltip.java:47
Vec2f getTipMvPosition(final Scene scene, final PMVMatrix4f pmv, final float tipWidth, final float tipHeight)
Little helper for createTip(Scene, AABBox) returning the Mv position of the tip within Scene Mv space...
Definition: Tooltip.java:158
final int renderModes
Graph's Region render modes, see create(..).
Definition: Tooltip.java:58
BaseButton setCorner(final float corner)
Set corner size with range [0.01 .
Definition: BaseButton.java:95
A GraphUI text labeled BaseButton GraphShape.
Definition: Button.java:61
final Button setLabelColor(final Vec4f c)
Sets the label color, consider using alpha 1.
Definition: Button.java:333
final Button setSpacing(final float spacingX, final float spacingY)
Sets spacing in percent of text label, clipped to range [0 .
Definition: Button.java:300
2D Vector based upon two float components.
Definition: Vec2f.java:37
4D Vector based upon four float components.
Definition: Vec4f.java:37
Axis Aligned Bounding Box.
Definition: AABBox.java:54
final float getWidth()
Definition: AABBox.java:879
final float getHeight()
Definition: AABBox.java:883
Interface wrapper for font implementation.
Definition: Font.java:60
AABBox getGlyphBounds(final CharSequence string)
Try using getGlyphBounds(CharSequence, AffineTransform, AffineTransform) to reuse AffineTransform ins...