JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
Tooltips.java
Go to the documentation of this file.
1/**
2 * Copyright 2023 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.opengl.demos.graph.ui.util;
29
30import com.jogamp.graph.curve.Region;
31import com.jogamp.graph.curve.opengl.GLRegion;
32import com.jogamp.graph.ui.Scene;
33import com.jogamp.graph.ui.Shape;
34import com.jogamp.graph.ui.shapes.Button;
35import com.jogamp.graph.ui.shapes.Label;
36import com.jogamp.math.geom.AABBox;
37import com.jogamp.newt.event.MouseEvent;
38import com.jogamp.opengl.GLAutoDrawable;
39import com.jogamp.opengl.GLProfile;
40import com.jogamp.opengl.util.texture.TextureSequence;
41
42public class Tooltips {
43 /**
44 * Shows the {@link Label#getText()} within a given proportion of {@link Scene#getBounds()} height within a rectangular {@link Button} tool-tip on click.
45 * <p>
46 * This {@link Shape.MouseGestureAdapter} must be {@link Shape#addMouseListener(com.jogamp.graph.ui.Shape.MouseGestureListener) added}
47 * to a {@link Label} to be functional.
48 * </p>
49 */
50 public static class ZoomLabelOnClickListener extends Shape.MouseGestureAdapter {
51 private final Scene scene;
52 private final int renderModes;
53 private final float sceneHeightScale;
54 private Button buttonLabel = null;
55
56 /**
57 * Ctor of {@link ZoomLabelOnClickListener}.
58 * @param scene the {@link Scene} to be attached to while pressed
59 * @param renderModes Graph's {@link Region} render modes, see {@link GLRegion#create(GLProfile, int, TextureSequence) create(..)}.
60 * @param sceneHeightScale proportion of {@link Scene#getBounds()} height to cover with this tool-tip
61 */
62 public ZoomLabelOnClickListener(final Scene scene, final int renderModes, final float sceneHeightScale) {
63 this.scene = scene;
64 this.renderModes = renderModes;
65 this.sceneHeightScale = sceneHeightScale;
66 }
67
68 @Override
69 public void mousePressed(final MouseEvent e) {
70 final AABBox sceneDim = scene.getBounds();
71 final float zEps = scene.getZEpsilon(16);
72
73 final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment();
74 if( !( shapeEvent.shape instanceof Label ) ) {
75 return;
76 }
77 final Label label = (Label)shapeEvent.shape;
78 final AABBox textDim = label.getBounds();
79 final float l_sxy = sceneHeightScale * sceneDim.getHeight() / textDim.getHeight(); // text width independent
80 buttonLabel = (Button) new Button(renderModes, label.getFont(), label.getText(), textDim.getWidth()+3, textDim.getHeight(), zEps)
81 .setPerp().scale(l_sxy, l_sxy, 1).move(0, 0, 10*zEps)
82 .setColor(0.97f, 0.97f, 0.97f, 0.92f).setBorder(0.05f).setBorderColor(0, 0, 0, 1)
83 .setInteractive(false);
84 buttonLabel.setLabelColor(0, 0, 0, 1.0f);
86 final Shape s = buttonLabel;
87 scene.invoke(false, (final GLAutoDrawable drawable) -> {
88 s.validate(drawable.getGL().getGL2ES2());
89 s.move(-s.getScaledWidth()/2f, -s.getScaledHeight()/2f, 0);
90 // System.err.println("Add "+s);
91 scene.addShape(s);
92 return true;
93 });
94 }
95 @Override
96 public void mouseReleased(final MouseEvent e) {
97 if( null != buttonLabel ) {
98 final Shape s = buttonLabel;
99 buttonLabel = null;
100 scene.invoke(false, (final GLAutoDrawable drawable) -> {
101 // System.err.println("Remove "+s);
102 scene.removeShape(drawable.getGL().getGL2ES2(), s);
103 return true;
104 });
105 }
106 }
107 };
108
109}
GraphUI Scene.
Definition: Scene.java:102
void addShape(final Shape s)
Adds a Shape.
Definition: Scene.java:287
Shape removeShape(final Shape s)
Removes given shape, w/o Shape#destroy(GL2ES2, RegionRenderer).
Definition: Scene.java:292
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
boolean invoke(final boolean wait, final GLRunnable glRunnable)
Enqueues a one-shot GLRunnable, which will be executed within the next GLAutoDrawable#display() call ...
Definition: Scene.java:428
Shape event info for propagated NEWTEvents containing reference of the intended shape as well as the ...
Definition: Shape.java:1896
Generic Shape, potentially using a Graph via GraphShape or other means of representing content.
Definition: Shape.java:87
Shape setColor(final float r, final float g, final float b, final float a)
Set base color.
Definition: Shape.java:1389
final Shape move(final float dtx, final float dty, final float dtz)
Move about scaled distance.
Definition: Shape.java:557
final Shape setInteractive(final boolean v)
Set whether this shape is interactive in general, i.e.
Definition: Shape.java:1711
final float getScaledWidth()
Returns the scaled width of the bounding AABBox for this shape.
Definition: Shape.java:745
final float getScaledHeight()
Returns the scaled height of the bounding AABBox for this shape.
Definition: Shape.java:760
final AABBox getBounds()
Returns the unscaled bounding AABBox for this shape, borrowing internal instance.
Definition: Shape.java:732
final Shape validate(final GL2ES2 gl)
Validates the shape's underlying GLRegion.
Definition: Shape.java:850
final Shape scale(final Vec3f s)
Multiply current scale factor by given scale.
Definition: Shape.java:661
final Shape setBorderColor(final float r, final float g, final float b, final float a)
Set border color.
Definition: Shape.java:1489
final Shape setBorder(final float thickness)
Sets the thickness of the border, which is included in getBounds() and is outside of getPadding().
Definition: Shape.java:402
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
static final float DEFAULT_SPACING_X
{@value}
Definition: Button.java:63
A GraphUI text label GraphShape.
Definition: Label.java:50
Font getFont()
Returns the Font used to render the text.
Definition: Label.java:137
CharSequence getText()
Returns the label text.
Definition: Label.java:85
Axis Aligned Bounding Box.
Definition: AABBox.java:54
final float getHeight()
Definition: AABBox.java:883
Pointer event of type PointerType.
Definition: MouseEvent.java:74
Shows the Label#getText() within a given proportion of Scene#getBounds() height within a rectangular ...
Definition: Tooltips.java:50
ZoomLabelOnClickListener(final Scene scene, final int renderModes, final float sceneHeightScale)
Ctor of ZoomLabelOnClickListener.
Definition: Tooltips.java:62
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.