diff options
author | Sven Göthel <[email protected]> | 2024-02-13 22:21:55 +0100 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-02-13 22:21:55 +0100 |
commit | 06e5b0503a0b32b8b1e5985a9da0d5373f8b7096 (patch) | |
tree | 5d644e73e01bcfa00b71488c4701acbd9b63d84a /src/graphui | |
parent | 101ec44f9d6df7faa0695accccfd43f51e48e7a4 (diff) |
Bug 1501: Graph Shape: onInit(ListenerBool) -> onDraw(DrawListener) w/ added capability for code injection to render
Besides the one-shot on-init functionality, this allows us to re-render the shape differently.
Diffstat (limited to 'src/graphui')
4 files changed, 37 insertions, 18 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/GraphShape.java b/src/graphui/classes/com/jogamp/graph/ui/GraphShape.java index 0cc48b627..8f2337f0b 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/GraphShape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/GraphShape.java @@ -151,6 +151,8 @@ public abstract class GraphShape extends Shape { region.draw(gl, renderer); } + public GLRegion getRegion() { return region; } + @Override protected final void drawToSelectImpl0(final GL2ES2 gl, final RegionRenderer renderer) { region.drawToSelect(gl, renderer); diff --git a/src/graphui/classes/com/jogamp/graph/ui/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/Scene.java index 7e45b44b1..56756de18 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Scene.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Scene.java @@ -1377,7 +1377,7 @@ public final class Scene implements Container, GLEventListener { final GLCapabilitiesImmutable caps = glad.getChosenGLCapabilities(); final String modeS = Region.getRenderModeString(renderModes, getAAQuality(), getSampleCount(), caps.getNumSamples()); final String blendStr; - if( getRenderer().isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED) ) { + if( getRenderer().hintBitsSet(RenderState.BITHINT_BLENDING_ENABLED) ) { blendStr = ", blend"; } else { blendStr = ""; diff --git a/src/graphui/classes/com/jogamp/graph/ui/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/Shape.java index bd0983e5d..8eb4d9180 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/Shape.java @@ -144,10 +144,22 @@ public abstract class Shape { void run(final Shape shape); } /** - * {@link Shape} listener action returning a boolean value + * {@link Shape} draw listener action returning a boolean value + * <p> + * If {@link #run(Shape, GL2ES2, RegionRenderer)} returns {@code true}, + * the listener will be removed at {@link Shape#draw(GL2ES2, RegionRenderer)} + * otherwise kept calling. + * </p> */ - public static interface ListenerBool { - boolean run(final Shape shape); + public static interface DrawListener { + /** + * Return {@code true} to remove this {@link DrawListener} at {@link Shape#draw(GL2ES2, RegionRenderer)}, + * otherwise it is being kept and called. + * @param shape The shape + * @param gl the current {@link GL2ES2} object + * @param renderer the {@link RegionRenderer} + */ + boolean run(final Shape shape, GL2ES2 gl, RegionRenderer renderer); } /** @@ -288,7 +300,7 @@ public abstract class Shape { private ArrayList<MouseGestureListener> mouseListeners = new ArrayList<MouseGestureListener>(); private ArrayList<KeyListener> keyListeners = new ArrayList<KeyListener>(); - private ListenerBool onInitListener = null; + private DrawListener onDrawListener = null; private PointerListener onHoverListener = null; private MoveListener onMoveListener = null; private Listener onToggleListener = null; @@ -428,7 +440,7 @@ public abstract class Shape { box.reset(); mouseListeners.clear(); keyListeners.clear(); - onInitListener = null; + onDrawListener = null; onMoveListener = null; onToggleListener = null; activationListeners.clear(); @@ -449,15 +461,20 @@ public abstract class Shape { } /** - * Set a user one-shot initializer callback. + * Set a user one-shot initializer callback or custom {@link #draw(GL2ES2, RegionRenderer)} hook. + * <p> + * {@link #run(Shape, GL2ES2, RegionRenderer)} is called at {@link Shape#draw(GL2ES2, RegionRenderer)} + * and if returning {@code true}, the listener will be removed. + * Otherwise kept calling. + * </p> * <p> - * {@link ListenerBool#run(Shape)} will be called - * after each {@link #draw(GL2ES2, RegionRenderer)} - * until it returns true, signaling user initialization is completed. + * This instrument allows the user either to be signaled when initialization + * of this {@link Shape} is completed, or just too hook-up custom {@link #draw(GL2ES2, RegionRenderer)} + * actions. * </p> - * @param l callback, which shall return true signaling user initialization is done + * @param l callback, which shall return true to be removed, i.e. user initialization is done. */ - public final void onInit(final ListenerBool l) { onInitListener = l; } + public final void onDraw(final DrawListener l) { onDrawListener = l; } /** * Set user callback to be notified when a pointer/mouse is moving over this shape */ @@ -815,9 +832,9 @@ public abstract class Shape { validate(gl); drawImpl0(gl, renderer, rgba); } - if( null != onInitListener ) { - if( onInitListener.run(this) ) { - onInitListener = null; + if( null != onDrawListener ) { + if( onDrawListener.run(this, gl, renderer) ) { + onDrawListener = null; } } } diff --git a/src/graphui/classes/com/jogamp/graph/ui/widgets/RangedGroup.java b/src/graphui/classes/com/jogamp/graph/ui/widgets/RangedGroup.java index 0ebe3a258..ab4b82706 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/widgets/RangedGroup.java +++ b/src/graphui/classes/com/jogamp/graph/ui/widgets/RangedGroup.java @@ -104,7 +104,7 @@ public class RangedGroup extends Widget { horizSlider = new RangeSlider(renderModes, horizSliderParam.size, new Vec2f(0, content.getBounds().getWidth()), horizSliderParam.unitSize, contentSize.x(), 0).setInverted(horizSliderParam.inverted); addShape(horizSlider); - horizSlider.addChangeListener((final RangeSlider w, final float old_val, final float val, final float old_val_pct, final float val_pct, Vec3f pos, MouseEvent e) -> { + horizSlider.addChangeListener((final RangeSlider w, final float old_val, final float val, final float old_val_pct, final float val_pct, final Vec3f pos, final MouseEvent e) -> { final Vec3f oldPos = content.getPosition(); if( horizSlider.isInverted() ) { content.moveTo(contentPosZero.x()-val, oldPos.y(), oldPos.z()); @@ -119,7 +119,7 @@ public class RangedGroup extends Widget { vertSlider = new RangeSlider(renderModes, vertSliderParam.size, new Vec2f(0, content.getBounds().getHeight()), vertSliderParam.unitSize, contentSize.y(), 0).setInverted(vertSliderParam.inverted); addShape(vertSlider); - vertSlider.addChangeListener((final RangeSlider w, final float old_val, final float val, final float old_val_pct, final float val_pct, Vec3f pos, MouseEvent e) -> { + vertSlider.addChangeListener((final RangeSlider w, final float old_val, final float val, final float old_val_pct, final float val_pct, final Vec3f pos, final MouseEvent e) -> { final Vec3f oldPos = content.getPosition(); if( vertSlider.isInverted() ) { content.moveTo(oldPos.x(), contentPosZero.y()+val, oldPos.z()); @@ -130,7 +130,7 @@ public class RangedGroup extends Widget { } else { vertSlider = null; } - this.onInit( (final Shape shape) -> { + this.onDraw( (final Shape shape, final GL2ES2 gl_, final RegionRenderer renderer_) -> { content.moveTo(contentPosZero.x(), contentPosZero.y(), 0); return true; }); |