aboutsummaryrefslogtreecommitdiffstats
path: root/src/graphui/classes/com/jogamp/graph/ui
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-03-13 06:05:47 +0100
committerSven Gothel <[email protected]>2023-03-13 06:05:47 +0100
commit6b39e7be037f13a72d7ba1ead24f01697823d779 (patch)
tree137e287b959611f3768e8858478f50d2e5af1a85 /src/graphui/classes/com/jogamp/graph/ui
parent9fd84fa482aa354f0636fcd006edd7b71b27c02d (diff)
GraphUI: Cleanup 1-pointer zoom, add generic PinchToZoom-Gesture for 2-pointer zoom; Scene: Align method names..
Diffstat (limited to 'src/graphui/classes/com/jogamp/graph/ui')
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java28
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java108
2 files changed, 88 insertions, 48 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java b/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java
index 834c1abbc..558b13aba 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/gl/Scene.java
@@ -310,14 +310,14 @@ public class Scene implements GLEventListener{
/**
* Calling {@link Shape#winToObjCoord(RegionRenderer, int, int, float[])}, retrieving its object position.
- * @param activeShape
+ * @param shape
* @param glWinX in GL window coordinates, origin bottom-left
* @param glWinY in GL window coordinates, origin bottom-left
* @param objPos resulting object position
* @param runnable action
*/
- public void windowToShapeCoords(final Shape activeShape, final int glWinX, final int glWinY, final float[] objPos, final Runnable runnable) {
- if( null == cDrawable || null == activeShape ) {
+ public void winToObjCoord(final Shape shape, final int glWinX, final int glWinY, final float[] objPos, final Runnable runnable) {
+ if( null == cDrawable || null == shape ) {
return;
}
cDrawable.invoke(false, new GLRunnable() {
@@ -328,8 +328,8 @@ public class Scene implements GLEventListener{
final PMVMatrix pmv = renderer.getMatrix();
pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
pmv.glPushMatrix();
- activeShape.setTransform(pmv);
- ok = activeShape.winToObjCoord(renderer, glWinX, glWinY, objPos);
+ shape.setTransform(pmv);
+ ok = shape.winToObjCoord(renderer, glWinX, glWinY, objPos);
pmv.glPopMatrix();
}
if( ok ) {
@@ -367,10 +367,10 @@ public class Scene implements GLEventListener{
}
}
- public static void mapWin2ObjectCoords(final PMVMatrix pmv, final int[] view,
- final float zNear, final float zFar,
- final float orthoX, final float orthoY, final float orthoDist,
- final float[] winZ, final float[] objPos) {
+ public static void mapWin2ObjCoord(final PMVMatrix pmv, final int[] view,
+ final float zNear, final float zFar,
+ final float orthoX, final float orthoY, final float orthoDist,
+ final float[] winZ, final float[] objPos) {
winZ[0] = FloatUtil.getOrthoWinZ(orthoDist, zNear, zFar);
pmv.gluUnProject(orthoX, orthoY, winZ[0], view, 0, objPos, 0);
}
@@ -395,10 +395,10 @@ public class Scene implements GLEventListener{
final float[] obj11Coord = new float[3];
final float[] winZ = new float[1];
- mapWin2ObjectCoords(pmv, viewport, zNear, zFar, 0f, 0f, orthoDist, winZ, obj00Coord);
+ mapWin2ObjCoord(pmv, viewport, zNear, zFar, 0f, 0f, orthoDist, winZ, obj00Coord);
System.err.printf("Reshape: mapped.00: [%f, %f, %f], winZ %f -> [%f, %f, %f]%n", 0f, 0f, orthoDist, winZ[0], obj00Coord[0], obj00Coord[1], obj00Coord[2]);
- mapWin2ObjectCoords(pmv, viewport, zNear, zFar, width, height, orthoDist, winZ, obj11Coord);
+ mapWin2ObjCoord(pmv, viewport, zNear, zFar, width, height, orthoDist, winZ, obj11Coord);
System.err.printf("Reshape: mapped.11: [%f, %f, %f], winZ %f -> [%f, %f, %f]%n", (float)width, (float)height, orthoDist, winZ[0], obj11Coord[0], obj11Coord[1], obj11Coord[2]);
nearPlane1Box.setSize( obj00Coord[0], // lx
@@ -449,10 +449,10 @@ public class Scene implements GLEventListener{
final int glWinY = viewport[3] - e.getY() - 1;
final float[] objPos = new float[3];
final Shape shape = activeShape;
- windowToShapeCoords(shape, glWinX, glWinY, objPos, new Runnable() {
+ winToObjCoord(shape, glWinX, glWinY, objPos, new Runnable() {
@Override
public void run() {
- shape.dispatchGestureEvent(gh, glWinX, glWinY, objPos);
+ shape.dispatchGestureEvent(renderer, gh, glWinX, glWinY, objPos);
} } );
}
}
@@ -500,7 +500,7 @@ public class Scene implements GLEventListener{
*/
final void dispatchMouseEventForShape(final Shape shape, final MouseEvent e, final int glWinX, final int glWinY) {
final float[] objPos = new float[3];
- windowToShapeCoords(shape, glWinX, glWinY, objPos, new Runnable() {
+ winToObjCoord(shape, glWinX, glWinY, objPos, new Runnable() {
@Override
public void run() {
shape.dispatchMouseEvent(e, glWinX, glWinY, objPos);
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 b38fef279..15c16cd13 100644
--- a/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java
+++ b/src/graphui/classes/com/jogamp/graph/ui/gl/Shape.java
@@ -37,6 +37,7 @@ import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.GLRegion;
import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.font.Font;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
import com.jogamp.graph.geom.plane.AffineTransform;
@@ -44,7 +45,9 @@ import com.jogamp.newt.event.GestureHandler.GestureEvent;
import com.jogamp.newt.event.GestureHandler.GestureListener;
import com.jogamp.newt.event.MouseAdapter;
import com.jogamp.newt.event.NEWTEvent;
+import com.jogamp.newt.event.PinchToZoomGesture;
import com.jogamp.newt.event.MouseEvent;
+import com.jogamp.newt.event.MouseEvent.PointerClass;
import com.jogamp.newt.event.MouseListener;
import com.jogamp.opengl.math.FloatUtil;
import com.jogamp.opengl.math.Quaternion;
@@ -661,18 +664,6 @@ public abstract class Shape {
}
}
- /**
- * @param e original Newt {@link GestureEvent}
- * @param glWinX x-position in OpenGL model space
- * @param glWinY y-position in OpenGL model space
- */
- /* pp */ final void dispatchGestureEvent(final GestureEvent e, final int glWinX, final int glWinY, final float[] objPos) {
- e.setAttachment(new EventInfo(glWinX, glWinY, this, objPos));
- for(int i = 0; !e.isConsumed() && i < mouseListeners.size(); i++ ) {
- mouseListeners.get(i).gestureDetected(e);
- }
- }
-
private boolean dragFirst = false;
private final float[] objDraggedFirst = { 0f, 0f }; // b/c its relative to Shape and we stick to it
private final int[] winDraggedLast = { 0, 0 }; // b/c its absolute window pos
@@ -691,7 +682,6 @@ public abstract class Shape {
*/
/* pp */ final void dispatchMouseEvent(final MouseEvent e, final int glWinX, final int glWinY, final float[] objPos) {
final Shape.EventInfo shapeEvent = new EventInfo(glWinX, glWinY, this, objPos);
- e.setAttachment(shapeEvent);
final short eventType = e.getEventType();
if( 1 == e.getPointerCount() ) {
@@ -709,7 +699,7 @@ public abstract class Shape {
}
switch( eventType ) {
case MouseEvent.EVENT_MOUSE_PRESSED:
- dragFirst = true;
+ dragFirst = 1 == e.getPointerCount();
break;
case MouseEvent.EVENT_MOUSE_RELEASED:
dragFirst = false;
@@ -746,17 +736,21 @@ public abstract class Shape {
inDrag = true;
}
}
- System.err.printf("Drag: drag %b, resize %b, obj %.3f/%.3f, %.3f/%.3f + %.3f/%.3f, %s%n",
- inDrag, inResize,
- ix, iy,
- objPos[0], objPos[1],
- shapeEvent.objDrag[0], shapeEvent.objDrag[1], box.toString());
+ if( DEBUG ) {
+ System.err.printf("Drag: drag %b, resize %b, obj %.3f/%.3f, %.3f/%.3f + %.3f/%.3f, %s%n",
+ inDrag, inResize,
+ ix, iy,
+ objPos[0], objPos[1],
+ shapeEvent.objDrag[0], shapeEvent.objDrag[1], box.toString());
+ }
return;
}
shapeEvent.objDrag[0] = objPos[0] - objDraggedFirst[0];
shapeEvent.objDrag[1] = objPos[1] - objDraggedFirst[1];
shapeEvent.winDrag[0] = glWinX - winDraggedLast[0];
shapeEvent.winDrag[1] = glWinY - winDraggedLast[1];
+ winDraggedLast[0] = glWinX;
+ winDraggedLast[1] = glWinY;
if( 1 == e.getPointerCount() ) {
if( 0 != inResize && resizable ) {
final float dx = shapeEvent.objDrag[0]/2f;
@@ -769,31 +763,28 @@ public abstract class Shape {
}
final float sy = scale[1] + ( -2f*dy/box.getHeight() );
if( resize_sxy_min <= sx && sx <= resize_sxy_max && resize_sxy_min <= sy && sy <= resize_sxy_max ) {
+ if( DEBUG ) {
+ System.err.printf("DragZoom: resize %b, obj %4d/%4d, %.3f/%.3f/%.3f %.3f/%.3f/%.3f + %.3f/%.3f -> %.3f/%.3f%n",
+ inResize, glWinX, glWinY, objPos[0], objPos[1], objPos[2], position[0], position[1], position[2],
+ dx, dy, sx, sy);
+ }
move(dx, dy, 0f);
setScale(sx, sy, scale[2]);
- } else {
- System.err.println("XXX: out");
- // inResize = false;
}
- System.err.printf("DragZoom: resize %b, obj %4d/%4d, %.3f/%.3f/%.3f %.3f/%.3f/%.3f + %.3f/%.3f -> %.3f/%.3f%n",
- inResize,
- glWinX, glWinY,
- objPos[0], objPos[1], objPos[2],
- position[0], position[1], position[2],
- dx, dy,
- sx, sy);
+ return; // FIXME: pass through event? Issue zoom event?
} else if( inDrag && draggable ) {
- System.err.printf("Drag: obj %.3f/%.3f + %.3f/%.3f%n",
- objPos[0], objPos[1],
- shapeEvent.objDrag[0], shapeEvent.objDrag[1]);
+ if( DEBUG ) {
+ System.err.printf("Drag: obj %.3f/%.3f + %.3f/%.3f%n",
+ objPos[0], objPos[1], shapeEvent.objDrag[0], shapeEvent.objDrag[1]);
+ }
move(shapeEvent.objDrag[0], shapeEvent.objDrag[1], 0f);
+ // FIXME: Pass through event? Issue move event?
}
}
- winDraggedLast[0] = glWinX;
- winDraggedLast[1] = glWinY;
}
break;
}
+ e.setAttachment(shapeEvent);
for(int i = 0; !e.isConsumed() && i < mouseListeners.size(); i++ ) {
final MouseGestureListener l = mouseListeners.get(i);
@@ -828,6 +819,55 @@ public abstract class Shape {
}
}
+ /**
+ * @param renderer TODO
+ * @param e original Newt {@link GestureEvent}
+ * @param glWinX x-position in OpenGL model space
+ * @param glWinY y-position in OpenGL model space
+ */
+ /* pp */ final void dispatchGestureEvent(final RegionRenderer renderer, final GestureEvent e, final int glWinX, final int glWinY, final float[] objPos) {
+ if( resizable && e instanceof PinchToZoomGesture.ZoomEvent ) {
+ final PinchToZoomGesture.ZoomEvent ze = (PinchToZoomGesture.ZoomEvent) e;
+ final float pixels = ze.getDelta() * ze.getScale(); //
+ final float[] objPos2 = { 0f, 0f, 0f };
+ final int winX2 = glWinX + Math.round(pixels);
+ final boolean ok;
+ {
+ final PMVMatrix pmv = renderer.getMatrix();
+ pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ pmv.glPushMatrix();
+ setTransform(pmv);
+ ok = winToObjCoord(null, winX2, glWinY, objPos2);
+ pmv.glPopMatrix();
+ }
+ final float dx = objPos2[0];
+ final float dy = objPos2[1];
+ final float sx = scale[0] + ( dx/box.getWidth() ); // bottom-right
+ final float sy = scale[1] + ( dy/box.getHeight() );
+ if( DEBUG ) {
+ System.err.printf("DragZoom: resize %b, obj %4d/%4d, %.3f/%.3f/%.3f %.3f/%.3f/%.3f + %.3f/%.3f -> %.3f/%.3f%n",
+ inResize, glWinX, glWinY, objPos[0], objPos[1], objPos[2], position[0], position[1], position[2],
+ dx, dy, sx, sy);
+ }
+ if( resize_sxy_min <= sx && sx <= resize_sxy_max && resize_sxy_min <= sy && sy <= resize_sxy_max ) {
+ if( DEBUG ) {
+ System.err.printf("PinchZoom: pixels %f, obj %4d/%4d, %.3f/%.3f/%.3f %.3f/%.3f/%.3f + %.3f/%.3f -> %.3f/%.3f%n",
+ pixels, glWinX, glWinY, objPos[0], objPos[1], objPos[2], position[0], position[1], position[2],
+ dx, dy, sx, sy);
+ }
+ // move(dx, dy, 0f);
+ setScale(sx, sy, scale[2]);
+ }
+ return; // FIXME: pass through event? Issue zoom event?
+ }
+ final Shape.EventInfo shapeEvent = new EventInfo(glWinX, glWinY, this, objPos);
+ e.setAttachment(shapeEvent);
+
+ for(int i = 0; !e.isConsumed() && i < mouseListeners.size(); i++ ) {
+ mouseListeners.get(i).gestureDetected(e);
+ }
+ }
+
//
//
//