From 32f7a476770d0a4ef853eab8f3c78a7ea801a180 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 19 Mar 2023 08:06:01 +0100 Subject: Graph Shape: Add onMove(Shape.Listener), allowing user to track Shape movement --- src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/graphui') diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java b/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java index 56ba928d7..626e25beb 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java +++ b/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java @@ -69,6 +69,9 @@ import com.jogamp.opengl.util.PMVMatrix; * @see Scene */ public abstract class Shape { + public static interface Listener { + void run(final Shape shape); + } public static final boolean DRAW_DEBUG_BOX = false; private static final boolean DEBUG = false; @@ -114,6 +117,8 @@ public abstract class Shape { private boolean enabled = true; private ArrayList mouseListeners = new ArrayList(); + private Listener onMoveListener = null; + public Shape(final Factory factory, final int renderModes) { this.vertexFactory = factory; this.renderModes = renderModes; @@ -174,17 +179,25 @@ public abstract class Shape { markShapeDirty(); } + public final void onMove(final Listener l) { onMoveListener = l; } + public final void moveTo(final float tx, final float ty, final float tz) { position[0] = tx; position[1] = ty; position[2] = tz; - // System.err.println("UIShape.setTranslate: "+tx+"/"+ty+"/"+tz+": "+toString()); + if( null != onMoveListener ) { + onMoveListener.run(this); + } + // System.err.println("Shape.setTranslate: "+tx+"/"+ty+"/"+tz+": "+toString()); } public final void move(final float tx, final float ty, final float tz) { position[0] += tx; position[1] += ty; position[2] += tz; - // System.err.println("UIShape.translate: "+tx+"/"+ty+"/"+tz+": "+toString()); + if( null != onMoveListener ) { + onMoveListener.run(this); + } + // System.err.println("Shape.translate: "+tx+"/"+ty+"/"+tz+": "+toString()); } /** Returns float[3] position, i.e. translation. */ -- cgit v1.2.3