From 8df74578481431768b3c26294c6bd64ed7030ae5 Mon Sep 17 00:00:00 2001 From: Sven Göthel Date: Sun, 4 Feb 2024 20:55:39 +0100 Subject: Bug 1498: GraphUI: Adopt RangedSlider to new picking (coming up), simplifies code. --- .../com/jogamp/graph/ui/widgets/RangeSlider.java | 56 +++++++--------------- .../test/junit/graph/FontViewListener01.java | 11 ++--- 2 files changed, 21 insertions(+), 46 deletions(-) diff --git a/src/graphui/classes/com/jogamp/graph/ui/widgets/RangeSlider.java b/src/graphui/classes/com/jogamp/graph/ui/widgets/RangeSlider.java index b2693da3d..32a576a81 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/widgets/RangeSlider.java +++ b/src/graphui/classes/com/jogamp/graph/ui/widgets/RangeSlider.java @@ -146,9 +146,9 @@ public final class RangeSlider extends Widget { this.pageSize = pageSz; this.horizontal = size.x() >= size.y(); barAndKnob = new Group(); - barAndKnob.setInteractive(true).setToggleable(false).setDragAndResizeable(false); + barAndKnob.setInteractive(false); marks = new Group(); - marks.setInteractive(false).setToggleable(false).setDragAndResizeable(false); + marks.setInteractive(false); this.size = new Vec2f(size); if( DEBUG ) { System.err.println("RangeSlider.ctor0 "+getDescription()); } @@ -173,10 +173,8 @@ public final class RangeSlider extends Widget { if( DEBUG ) { System.err.println("RangeSlider.ctor3 "+getDescription()); } setColor(0.80f, 0.80f, 0.80f, 0.7f); - bar.setToggleable(false).setInteractive(true).setDragAndResizeable(false); - - knob.setToggleable(false).setResizable(false); - setName(getName()); + bar.setToggleable(false).setInteractive(true).setDragAndResizable(false).setName("RangeSlider.bar"); + knob.setToggleable(false).setInteractive(true).setResizable(false).setName("RangeSlider.knob"); barAndKnob.addShape( bar ); barAndKnob.addShape( marks ); barAndKnob.addShape( knob ); @@ -197,18 +195,15 @@ public final class RangeSlider extends Widget { l.dragged(RangeSlider.this, old_val, val, old_val_pct, val_pct); }); }); - barAndKnob.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - final float old_val = val; - final float old_val_pct = val_pct; - final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); - setValuePct( getKnobValuePct( shapeEvent.objPos.x(), shapeEvent.objPos.y(), 0 ) ); - dispatchToListener( (final SliderListener l) -> { - l.dragged(RangeSlider.this, old_val, val, old_val_pct, val_pct); - l.clicked(RangeSlider.this, e); - }); - } + bar.onClicked((final Shape s, final Vec3f pos, final MouseEvent e) -> { + final float old_val = val; + final float old_val_pct = val_pct; + setValuePct( getKnobValuePct( pos.x(), pos.y(), 0 ) ); + dispatchToListener( (final SliderListener l) -> { + l.dragged(RangeSlider.this, old_val, val, old_val_pct, val_pct); + }); + }); + final Shape.MouseGestureListener mouseListener = new Shape.MouseGestureAdapter() { @Override public void mouseWheelMoved(final MouseEvent e) { final float old_val = val; @@ -248,27 +243,7 @@ public final class RangeSlider extends Widget { l.dragged(RangeSlider.this, old_val, val, old_val_pct, val_pct); }); } - }); - knob.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - // if( null != sliderListener ) { - // sliderListener.clicked(RangeSlider.this, e); - // } - } - @Override - public void mousePressed(final MouseEvent e) { - dispatchToListener( (final SliderListener l) -> { - l.pressed(RangeSlider.this, e); - }); - } - @Override - public void mouseReleased(final MouseEvent e) { - dispatchToListener( (final SliderListener l) -> { - l.released(RangeSlider.this, e); - }); - } - }); + }; final KeyListener keyListener = new KeyAdapter() { @Override public void keyReleased(final KeyEvent e) { @@ -335,9 +310,10 @@ public final class RangeSlider extends Widget { } } }; - barAndKnob.addKeyListener(keyListener); bar.addKeyListener(keyListener); knob.addKeyListener(keyListener); + bar.addMouseListener(mouseListener); + knob.addMouseListener(mouseListener); final Shape.Listener onActivation = new Shape.Listener() { private final Vec4f origCol = new Vec4f(); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/FontViewListener01.java b/src/test/com/jogamp/opengl/test/junit/graph/FontViewListener01.java index 3a2255a33..624ea0d58 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/FontViewListener01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/FontViewListener01.java @@ -37,7 +37,9 @@ import com.jogamp.graph.ui.layout.BoxLayout; import com.jogamp.graph.ui.layout.Gap; import com.jogamp.graph.ui.layout.GridLayout; import com.jogamp.graph.ui.shapes.GlyphShape; +import com.jogamp.math.Vec3f; import com.jogamp.math.geom.AABBox; +import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.GL; import com.jogamp.opengl.GL2ES2; @@ -145,12 +147,9 @@ public class FontViewListener01 implements GLEventListener { } final GlyphShape glyphShape = new GlyphShape(renderModes, glyph, 0, 0); glyphShape.setColor(0.1f, 0.1f, 0.1f, 1); - glyphShape.setDragAndResizeable(false); - glyphShape.onClicked( new Shape.Listener() { - @Override - public void run(final Shape shape) { - System.err.println( ((GlyphShape)shape).getGlyph().toString() ); - } + glyphShape.setDragAndResizable(false); + glyphShape.onClicked( (final Shape shape, final Vec3f pos, final MouseEvent e) -> { + System.err.println( ((GlyphShape)shape).getGlyph().toString() ); }); glyphShape.validate(gl); -- cgit v1.2.3