From 31d430e19fdd6dcd69e652df10ac34dcfa0e7add Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 23 May 2023 02:15:53 +0200 Subject: GraphUI Shape: Add one-shot init callback, will be called after each draw(..) until it returns true. --- src/graphui/classes/com/jogamp/graph/ui/Shape.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/graphui/classes/com/jogamp') diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java index 03dd4b62a..ba1e50b1c 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java @@ -113,6 +113,12 @@ public abstract class Shape { public static interface Listener { void run(final Shape shape); } + /** + * {@link Shape} listener action returning a boolean value + */ + public static interface ListenerBool { + boolean run(final Shape shape); + } protected static final boolean DEBUG_DRAW = false; private static final boolean DEBUG = false; @@ -155,6 +161,7 @@ public abstract class Shape { private final Vec4f borderColor = new Vec4f(0.0f, 0.0f, 0.0f, 1.0f); private ArrayList mouseListeners = new ArrayList(); + private ListenerBool onInitListener = null; private Listener onMoveListener = null; private Listener onToggleListener = null; private Listener onClickedListener = null; @@ -250,6 +257,16 @@ public abstract class Shape { markShapeDirty(); } + /** + * Set a user one-shot initializer callback. + *

+ * {@link ListenerBool#run(Shape)} will be called + * after each {@link #draw(GL2ES2, RegionRenderer, int[])} + * until it returns true, signaling user initialization is completed. + *

+ * @param l callback, which shall return true signaling user initialization is done + */ + public final void onInit(final ListenerBool l) { onInitListener = l; } public final void onMove(final Listener l) { onMoveListener = l; } public final void onToggle(final Listener l) { onToggleListener = l; } public final void onClicked(final Listener l) { onClickedListener = l; } @@ -474,6 +491,11 @@ public abstract class Shape { validate(gl); drawImpl0(gl, renderer, sampleCount, rgba); } + if( null != onInitListener ) { + if( onInitListener.run(this) ) { + onInitListener = null; + } + } } /** -- cgit v1.2.3