aboutsummaryrefslogtreecommitdiffstats
path: root/src/graphui/classes/com/jogamp/graph/ui/Scene.java
diff options
context:
space:
mode:
authorSven Göthel <[email protected]>2024-01-07 04:56:28 +0100
committerSven Göthel <[email protected]>2024-01-07 04:56:28 +0100
commitfa973b03fc1d6af5696cee27e1824c45da3150b4 (patch)
tree68a2f17d0063c0b867fde5283274414907eaa3b4 /src/graphui/classes/com/jogamp/graph/ui/Scene.java
parentcf0c60eaabd7334c0ae2099a1f999032cddf14dd (diff)
GraphUI Shape: Enable Tooltip (currently text only) to be displayed after delay w/o mouse-move (1s)
For efficiency, all Tooltip instances is hooked to Scene via Shape as well as its singleton pop-up HUD tip after delay and no mouse move. TooltipText is a simple text Button implementation, but other more fancy HUD tips can be implemented. Shape adds - 'public Tooltip setToolTip(final CharSequence text, final Font font, final float scaleY, final Scene scene)' Demoed within MediaPlayer widget.
Diffstat (limited to 'src/graphui/classes/com/jogamp/graph/ui/Scene.java')
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/Scene.java47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/Scene.java
index 6d3f77971..c71060db4 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/Scene.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/Scene.java
@@ -36,6 +36,7 @@ import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicReference;
import com.jogamp.opengl.FPSCounter;
import com.jogamp.opengl.GL;
@@ -132,6 +133,8 @@ public final class Scene implements Container, GLEventListener {
private static final boolean DEBUG = false;
private final List<Shape> shapes = new CopyOnWriteArrayList<Shape>();
+ /* pp */ final List<Tooltip> toolTips = new CopyOnWriteArrayList<Tooltip>();
+ private final AtomicReference<GraphShape> toolTipHUD = new AtomicReference<GraphShape>();
private boolean doFrustumCulling = false;
@@ -500,6 +503,15 @@ public final class Scene implements Container, GLEventListener {
displayedOnce = true;
syncDisplayedOnce.notifyAll();
}
+ if( null == toolTipHUD.get() ) {
+ final GraphShape[] t = { null };
+ for(final Tooltip tt : toolTips ) {
+ if( tt.tick() && forOne(pmv, tt.tool, () -> { t[0] = tt.createTip(pmv); }) ) {
+ toolTipHUD.set( t[0] );
+ break; // done
+ }
+ }
+ }
}
private void displayGLSelect(final GLAutoDrawable drawable, final Object[] shapes) {
@@ -1042,6 +1054,7 @@ public final class Scene implements Container, GLEventListener {
private final class SBCGestureListener implements GestureHandler.GestureListener {
@Override
public void gestureDetected(final GestureEvent gh) {
+ clearToolTips();
if( null != activeShape ) {
// gesture .. delegate to active shape!
final InputEvent orig = gh.getTrigger();
@@ -1069,7 +1082,7 @@ public final class Scene implements Container, GLEventListener {
* @param glWinX in GL window coordinates, origin bottom-left
* @param glWinY in GL window coordinates, origin bottom-left
*/
- private final boolean dispatchMouseEventPickShape(final MouseEvent e, final int glWinX, final int glWinY) {
+ private final Shape dispatchMouseEventPickShape(final MouseEvent e, final int glWinX, final int glWinY) {
final PMVMatrix4f pmv = new PMVMatrix4f();
final Vec3f objPos = new Vec3f();
final Shape shape = pickShape(pmv, glWinX, glWinY, objPos, (final Shape s) -> {
@@ -1077,10 +1090,10 @@ public final class Scene implements Container, GLEventListener {
});
if( null != shape ) {
setActiveShape(shape);
- return true;
+ return shape;
} else {
releaseActiveShape();
- return false;
+ return null;
}
}
/**
@@ -1109,6 +1122,7 @@ public final class Scene implements Container, GLEventListener {
@Override
public void mousePressed(final MouseEvent e) {
+ clearToolTips();
if( -1 == lId || e.getPointerId(0) == lId ) {
lx = e.getX();
ly = e.getY();
@@ -1122,6 +1136,7 @@ public final class Scene implements Container, GLEventListener {
@Override
public void mouseReleased(final MouseEvent e) {
+ clearToolTips();
// flip to GL window coordinates, origin bottom-left
final int glWinX = e.getX();
final int glWinY = getHeight() - e.getY() - 1;
@@ -1137,6 +1152,7 @@ public final class Scene implements Container, GLEventListener {
@Override
public void mouseClicked(final MouseEvent e) {
+ clearToolTips();
// flip to GL window coordinates
final int glWinX = e.getX();
final int glWinY = getHeight() - e.getY() - 1;
@@ -1153,6 +1169,7 @@ public final class Scene implements Container, GLEventListener {
@Override
public void mouseDragged(final MouseEvent e) {
+ clearToolTips();
// drag activeShape, if no gesture-activity, only on 1st pointer
if( null != activeShape && activeShape.isInteractive() && !pinchToZoomGesture.isWithinGesture() && e.getPointerId(0) == lId ) {
lx = e.getX();
@@ -1168,6 +1185,7 @@ public final class Scene implements Container, GLEventListener {
@Override
public void mouseWheelMoved(final MouseEvent e) {
+ clearToolTips();
// flip to GL window coordinates
final int glWinX = lx;
final int glWinY = getHeight() - ly - 1;
@@ -1176,6 +1194,7 @@ public final class Scene implements Container, GLEventListener {
@Override
public void mouseMoved(final MouseEvent e) {
+ clearToolTips();
if( -1 == lId || e.getPointerId(0) == lId ) {
lx = e.getX();
ly = e.getY();
@@ -1183,12 +1202,19 @@ public final class Scene implements Container, GLEventListener {
}
final int glWinX = lx;
final int glWinY = getHeight() - ly - 1;
- mouseOver = dispatchMouseEventPickShape(e, glWinX, glWinY);
+ final Shape s = dispatchMouseEventPickShape(e, glWinX, glWinY);
+ if( null != s ) {
+ mouseOver = true;
+ s.startToolTip();
+ } else {
+ mouseOver = false;
+ }
}
@Override
public void mouseEntered(final MouseEvent e) { }
@Override
public void mouseExited(final MouseEvent e) {
+ clearToolTips();
releaseActiveShape();
clear();
}
@@ -1209,6 +1235,19 @@ public final class Scene implements Container, GLEventListener {
}
}
+ private void clearToolTips() {
+ final Shape s = toolTipHUD.getAndSet(null);
+ if( null != s ) {
+ invoke(false, (final GLAutoDrawable drawable) -> {
+ removeShape(drawable.getGL().getGL2ES2(), s);
+ return true;
+ });
+ }
+ for(final Tooltip tt : toolTips) {
+ tt.stop();
+ }
+ }
+
/**
* Return a formatted status string containing avg fps and avg frame duration.
* @param glad GLAutoDrawable instance for FPSCounter, its chosen GLCapabilities and its GL's swap-interval