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/Tooltip.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/Tooltip.java')
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/Tooltip.java | 79 |
1 files changed, 76 insertions, 3 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Tooltip.java b/src/graphui/classes/com/jogamp/graph/ui/Tooltip.java index b8e2467fe..7bed984f5 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Tooltip.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Tooltip.java @@ -28,7 +28,15 @@ package com.jogamp.graph.ui; import com.jogamp.common.os.Clock; +import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.GLRegion; +import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.math.Vec2f; +import com.jogamp.math.Vec4f; +import com.jogamp.math.geom.AABBox; import com.jogamp.math.util.PMVMatrix4f; +import com.jogamp.opengl.GL2ES2; +import com.jogamp.opengl.GLAutoDrawable; /** A HUD tooltip for {@link Shape}, see {@link Shape#setToolTip(Tooltip)}. */ public abstract class Tooltip { @@ -41,13 +49,30 @@ public abstract class Tooltip { private volatile long delayT1; /** Shape 'tool' owning this tooltip. */ private Shape tool; + 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); - protected Tooltip(final long delayMS) { + /** + * + * @param backColor optional HUD tip background color + * @param frontColor optional HUD tip front color + * @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(..)}. + */ + protected Tooltip(final Vec4f backColor, final Vec4f frontColor, final long delayMS, final int renderModes) { this.delayMS = delayMS; this.delayT1 = 0; this.tool = null; + this.renderModes = renderModes; + if( null != backColor ) { + this.backColor.set(backColor); + } + if( null != frontColor ) { + this.frontColor.set(frontColor); + } } - /* pp */ final void setToolOwner(final Shape owner) { tool = owner; } + /* pp */ final void setTool(final Shape tool) { this.tool = tool; } /** Returns {@link Shape} 'tool' owning this tooltip, set after {@link Shape#setToolTip(Tooltip)}. */ public final Shape getTool() { @@ -79,12 +104,60 @@ public abstract class Tooltip { return true; } + /** Little helper for {@link #createTip(GLAutoDrawable, Scene, PMVMatrix4f, AABBox)} returning the Mv {@link AABBox} of the tool within {@link Scene} Mv space. */ + public AABBox getToolMvBounds(final PMVMatrix4f pmv) { + return getTool().getBounds().transform(pmv.getMv(), new AABBox()); + } + /** Little helper for {@link #createTip(GLAutoDrawable, Scene, PMVMatrix4f, AABBox)} returning the Mv position of the tip within {@link Scene} Mv space. */ + public Vec2f getTipMvPosition(final Scene scene, final PMVMatrix4f pmv, final float tipWidth, final float tipHeight) { + return getTipMvPosition(scene, getToolMvBounds(pmv), tipWidth, tipHeight); + } + /** Little helper for {@link #createTip(GLAutoDrawable, Scene, PMVMatrix4f, AABBox)} returning the Mv position of the tip within {@link Scene} Mv space. */ + public Vec2f getTipMvPosition(final Scene scene, final AABBox toolMvBounds, final float tipWidth, final float tipHeight) { + final AABBox sceneAABox = scene.getBounds(); + final Vec2f pos = new Vec2f(); + if( toolMvBounds.getCenter().x() - tipWidth/2 >= sceneAABox.getLow().x() ) { + pos.setX( toolMvBounds.getCenter().x()-tipWidth/2 ); + } else { + pos.setX( sceneAABox.getLow().x() ); + } + if( toolMvBounds.getHigh().y() + tipHeight <= sceneAABox.getHigh().y() ) { + pos.setY( toolMvBounds.getHigh().y() ); + } else if( toolMvBounds.getHigh().y() >= tipHeight ) { + pos.setY( toolMvBounds.getHigh().y() - tipHeight ); + } else { + pos.setY( sceneAABox.getHigh().y() - tipHeight ); + } + return pos; + } + /** * Create a new HUD tip shape, usually called by {@link Scene} + * @param drawable current {@link GLAutoDrawable} * @param scene the {@link Scene} caller for which this HUD tip shape is created * @param pmv {@link PMVMatrix4f}, which shall be properly initialized, e.g. via {@link Scene#setupMatrix(PMVMatrix4f)} + * @param toolMvBounds TODO * @return newly created HUD tip shape + * @see #destroyTip(GL2ES2, RegionRenderer, Shape) */ - public abstract Shape createTip(final Scene scene, final PMVMatrix4f pmv); + public abstract Shape createTip(final GLAutoDrawable drawable, final Scene scene, final PMVMatrix4f pmv, AABBox toolMvBounds); + + /** + * Destroy a {@link #createTip(GLAutoDrawable, Scene, PMVMatrix4f, AABBox) created} HUD tip. + * <p> + * Called after {@link Scene#removeShape(Shape)}, allowing implementation to perform certain + * resource cleanup tasks. Even keeping the {@link Shape} tip alive is possible. + * </p> + * <p> + * This default implementation simply calls {@link Shape#destroy(GL2ES2, RegionRenderer)}. + * </p> + * @param gl + * @param renderer + * @param tip + * @see #createTip(GLAutoDrawable, Scene, PMVMatrix4f, AABBox) + */ + public void destroyTip(final GL2ES2 gl, final RegionRenderer renderer, final Shape tip) { + tip.destroy(gl, renderer); + } }
\ No newline at end of file |