28package com.jogamp.graph.ui;
30import java.util.ArrayList;
31import java.util.Comparator;
32import java.util.concurrent.atomic.AtomicInteger;
34import com.jogamp.nativewindow.NativeWindowException;
35import com.jogamp.opengl.GL2ES2;
36import com.jogamp.opengl.GLProfile;
37import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
38import com.jogamp.graph.curve.opengl.RegionRenderer;
39import com.jogamp.graph.ui.layout.Padding;
40import com.jogamp.math.FloatUtil;
41import com.jogamp.math.Matrix4f;
42import com.jogamp.math.Quaternion;
43import com.jogamp.math.Recti;
44import com.jogamp.math.Vec2f;
45import com.jogamp.math.Vec3f;
46import com.jogamp.math.Vec4f;
47import com.jogamp.math.geom.AABBox;
48import com.jogamp.math.util.PMVMatrix4f;
49import com.jogamp.newt.event.GestureHandler.GestureEvent;
50import com.jogamp.newt.event.GestureHandler.GestureListener;
51import com.jogamp.newt.event.KeyEvent;
52import com.jogamp.newt.event.KeyListener;
53import com.jogamp.newt.event.MouseAdapter;
54import com.jogamp.newt.event.NEWTEvent;
55import com.jogamp.newt.event.PinchToZoomGesture;
56import com.jogamp.newt.event.MouseEvent;
57import com.jogamp.newt.event.MouseListener;
182 private void dispatch(
final KeyEvent e) {
239 private static final boolean DEBUG =
false;
241 private static final int DIRTY_SHAPE = 1 << 0 ;
242 private static final int DIRTY_STATE = 1 << 1 ;
244 private volatile Group parent =
null;
248 private float zOffset = 0;
250 private Vec3f rotPivot =
null;
251 private final Vec3f scale =
new Vec3f(1f, 1f, 1f);
254 private volatile boolean iMatIdent =
true;
255 private volatile boolean iMatDirty =
false;
257 private final AtomicInteger dirty =
new AtomicInteger(DIRTY_SHAPE | DIRTY_STATE);
258 private final Object dirtySync =
new Object();
272 private final Vec4f rgba_tmp =
new Vec4f(0, 0, 0, 1);
273 private final Vec4f cWhite =
new Vec4f(1, 1, 1, 1);
276 private String name =
"noname";
278 private static final int IO_VISIBLE = 1 << 0;
279 private static final int IO_INTERACTIVE = 1 << 1;
280 private static final int IO_ACTIVABLE = 1 << 2;
281 private static final int IO_TOGGLEABLE = 1 << 3;
282 private static final int IO_DRAGGABLE = 1 << 4;
283 private static final int IO_RESIZABLE = 1 << 5;
284 private static final int IO_RESIZE_FIXED_RATIO = 1 << 6;
285 private static final int IO_ACTIVE = 1 << 7;
286 private static final int IO_DISCARDED = 1 << 25;
287 private static final int IO_DOWN = 1 << 26;
288 private static final int IO_TOGGLE = 1 << 27;
289 private static final int IO_DRAG_FIRST = 1 << 28;
290 private static final int IO_IN_MOVE = 1 << 29;
291 private static final int IO_IN_RESIZE_BR = 1 << 30;
292 private static final int IO_IN_RESIZE_BL = 1 << 31;
293 private volatile int ioState = IO_DRAGGABLE | IO_RESIZABLE | IO_INTERACTIVE | IO_ACTIVABLE | IO_VISIBLE;
294 private final boolean isIO(
final int mask) {
return mask == ( ioState & mask ); }
295 private final Shape setIO(
final int mask,
final boolean v) {
if( v ) { ioState |= mask; }
else { ioState &= ~mask; }
return this; }
297 private float borderThickness = 0f;
298 private Padding padding =
null;
299 private final Vec4f borderColor =
new Vec4f(0.0f, 0.0f, 0.0f, 1.0f);
300 private ArrayList<MouseGestureListener> mouseListeners =
new ArrayList<MouseGestureListener>();
301 private ArrayList<KeyListener> keyListeners =
new ArrayList<KeyListener>();
303 private DrawListener onDrawListener =
null;
304 private PointerListener onHoverListener =
null;
305 private MoveListener onMoveListener =
null;
306 private Listener onToggleListener =
null;
307 private ArrayList<Listener> activationListeners =
new ArrayList<Listener>();
308 private PointerListener onClickedListener =
null;
310 private final Vec2f objDraggedFirst =
new Vec2f();
311 private final int[] winDraggedLast = { 0, 0 };
312 private static final float resize_sxy_min = 1f/200f;
313 private static final float resize_section = 1f/5f;
315 private volatile Tooltip tooltip =
null;
334 public final Shape setID(
final int id) { this.id = id;
return this; }
336 public final int getID() {
return this.id; }
339 public Shape setName(
final String name) { this.name = name;
return this; }
341 public final String
getName() {
return this.name; }
353 public final boolean isVisible() {
return isIO(IO_VISIBLE); }
377 this.padding = padding;
390 public boolean hasPadding() {
return null != padding && !padding.zeroSize(); }
403 borderThickness = Math.max(0f, thickness);
415 synchronized ( dirtySync ) {
426 synchronized ( dirtySync ) {
432 private final void resetState() {
433 position.
set(0f, 0f, 0f);
436 scale.
set(1f, 1f, 1f);
441 mouseListeners.clear();
442 keyListeners.clear();
443 onDrawListener =
null;
444 onMoveListener =
null;
445 onToggleListener =
null;
446 activationListeners.clear();
447 onClickedListener =
null;
448 onHoverListener =
null;
515 @SuppressWarnings(
"unchecked")
516 final ArrayList<Listener> clonedListeners = (ArrayList<Listener>) activationListeners.clone();
517 clonedListeners.add(l);
518 activationListeners = clonedListeners;
525 @SuppressWarnings(
"unchecked")
526 final ArrayList<Listener> clonedListeners = (ArrayList<Listener>) activationListeners.clone();
527 clonedListeners.remove(l);
528 activationListeners = clonedListeners;
536 final int sz = activationListeners.size();
537 for(
int i = 0; i < sz; i++ ) {
538 activationListeners.get(i).run(s);
543 public final Shape moveTo(
final float tx,
final float ty,
final float tz) {
544 position.
set(tx, ty, tz);
557 public final Shape move(
final float dtx,
final float dty,
final float dtz) {
558 position.
add(dtx, dty, dtz);
570 private final Shape moveNotify(
final float dtx,
final float dty,
final float dtz,
final MouseEvent e) {
571 forwardMove(position.
copy(), position.
add(dtx, dty, dtz), e);
575 private final void forwardMove(
final Vec3f origin,
final Vec3f dest,
final MouseEvent e) {
576 if( !origin.isEqual(dest) ) {
578 if(
null != onMoveListener ) {
579 onMoveListener.run(
this, origin, dest, e);
621 rotPivot =
new Vec3f(px, py, pz);
631 rotPivot =
new Vec3f(pivot);
651 public final Shape setScale(
final float sx,
final float sy,
final float sz) {
652 scale.
set(sx, sy, sz);
671 public final Shape scale(
final float sx,
final float sy,
final float sz) {
672 scale.
mul(sx, sy, sz);
689 dirty.updateAndGet((
final int pre) -> {
return pre | DIRTY_SHAPE; } );
697 dirty.updateAndGet((
final int pre) -> {
return pre | DIRTY_STATE; } );
702 return 0 != ( dirty.get() & DIRTY_SHAPE ) ;
706 return 0 != ( dirty.get() & DIRTY_STATE ) ;
711 return "dirty[shape, state]";
713 return "dirty[shape]";
715 return "dirty[state]";
784 synchronized ( dirtySync ) {
831 synchronized ( dirtySync ) {
835 if(
null != onDrawListener ) {
836 if( onDrawListener.run(
this, gl, renderer) ) {
837 onDrawListener =
null;
851 synchronized ( dirtySync ) {
870 synchronized ( dirtySync ) {
972 final boolean hasPos = !position.
isZero();
974 final boolean hasRotate = !rotation.
isIdentity();
975 final boolean hasRotPivot =
null != rotPivot;
977 final boolean sameScaleRotatePivot = hasScale && hasRotate && ( !hasRotPivot || rotPivot.
isEqual(ctr) );
979 if( sameScaleRotatePivot ) {
983 iMat.
translate(ctr.x()*scale.x(), ctr.y()*scale.y(), ctr.z()*scale.z(), tmpMat);
984 iMat.
rotate(rotation, tmpMat);
985 iMat.
scale(scale.x(), scale.y(), scale.z(), tmpMat);
986 iMat.
translate(-ctr.x(), -ctr.y(), -ctr.z(), tmpMat);
987 }
else if( hasRotate || hasScale ) {
993 iMat.
translate(rotPivot.x()*scale.x(), rotPivot.y()*scale.y(), rotPivot.z()*scale.z(), tmpMat);
994 iMat.
rotate(rotation, tmpMat);
995 iMat.
translate(-rotPivot.x()*scale.x(), -rotPivot.y()*scale.y(), -rotPivot.z()*scale.z(), tmpMat);
998 iMat.
translate(ctr.x()*scale.x(), ctr.y()*scale.y(), ctr.z()*scale.z(), tmpMat);
999 iMat.
rotate(rotation, tmpMat);
1000 iMat.
translate(-ctr.x()*scale.x(), -ctr.y()*scale.y(), -ctr.z()*scale.z(), tmpMat);
1005 iMat.
translate(ctr.x()*scale.x(), ctr.y()*scale.y(), ctr.z()*scale.z(), tmpMat);
1006 iMat.
scale(scale.x(), scale.y(), scale.z(), tmpMat);
1007 iMat.
translate(-ctr.x(), -ctr.y(), -ctr.z(), tmpMat);
1009 }
else if( hasPos ) {
1034 pmvMatrixSetup.set(pmv, viewport);
1076 surfacePort.
setX( (
int)Math.abs( winCoordLow.x() ) );
1077 surfacePort.
setY( (
int)Math.abs( winCoordLow.y() ) );
1078 surfacePort.
setWidth( (
int)Math.abs( winCoordHigh.x() - winCoordLow.x() ) );
1079 surfacePort.
setHeight( (
int)Math.abs( winCoordHigh.y() - winCoordLow.y() ) );
1110 surfaceSize[0] = (int)Math.abs(winCoordHigh.x() - winCoordLow.x());
1111 surfaceSize[1] = (int)Math.abs(winCoordHigh.y() - winCoordLow.y());
1188 final int[] shapeSizePx =
new int[2];
1213 final int[] shapeSizePx =
new int[2];
1240 if( pmv.
mapObjToWin(objPos, viewport, winCoord) ) {
1241 glWinPos[0] = (int)(winCoord.x());
1242 glWinPos[1] = (int)(winCoord.y());
1309 final float winZ = objPos.z();
1389 public Shape setColor(
final float r,
final float g,
final float b,
final float a) {
1390 this.rgbaColor.
set(r, g, b, a);
1409 this.rgbaColor.
set(c);
1424 this.pressedRGBAModulate.
set(r, g, b, a);
1438 this.toggleOnRGBAModulate.
set(r, g, b, a);
1452 this.toggleOffRGBAModulate.
set(r, g, b, a);
1471 this.activeRGBAModulate.
set(c);
1490 this.borderColor.set(r, g, b, a);
1507 this.borderColor.set(c);
1514 return getClass().getSimpleName()+
"["+
getSubString()+
"]";
1520 iMatS =
"mat-dirty, ";
1521 }
else if( iMatIdent ) {
1522 iMatS =
"mat-ident, ";
1526 final String pivotS;
1527 if(
null != rotPivot ) {
1528 pivotS =
"pivot["+rotPivot+
"], ";
1532 final String scaleS;
1534 scaleS =
"scale["+scale+
"], ";
1536 scaleS =
"scale 1, ";
1538 final String rotateS;
1541 rotateS =
"rot["+euler+
"], ";
1545 final String discS =
isDiscarded()?
", DISCARDED":
"";
1547 final String ps =
hasPadding() ? padding.toString()+
", " :
"";
1549 final String idS = -1 !=
id ?
", id "+id :
"";
1550 final String nameS =
"noname" != name ?
", '"+name+
"'" :
"";
1551 return getDirtyString()+idS+nameS+
", visible "+isIO(IO_VISIBLE)+discS+activeS+
", toggle "+isIO(IO_TOGGLE)+
1553 "], pos["+position+
"], "+pivotS+scaleS+rotateS+iMatS+
1588 setIO(IO_TOGGLE, v);
1590 if(
null != onToggleListener ) {
1591 onToggleListener.run(
this);
1600 if(
null != onToggleListener ) {
1601 onToggleListener.run(
this);
1612 protected final boolean setActive(
final boolean v,
final float zOffset) {
1614 setZOffset(zOffset);
1615 setIO(IO_ACTIVE, v);
1617 releaseInteraction();
1624 System.err.println(
"XXX "+(v?
" Active":
"DeActive")+
" "+
this);
1633 public final boolean isActive() {
return isIO(IO_ACTIVE); }
1635 void setActiveTopLevel(
final boolean v,
final float zOffset) {
1636 setZOffset(zOffset);
1637 setIO(IO_ACTIVE, v);
1642 return position.z() *
getScale().z() + zOffset;
1644 final void setZOffset(
final float v) { zOffset = v; }
1654 final Tooltip oldTT = this.tooltip;
1655 this.tooltip =
null;
1656 if(
null != oldTT ) {
1659 newTooltip.setTool(
this);
1660 this.tooltip = newTooltip;
1671 private void stopToolTip() {
1677 Tooltip startToolTip(
final boolean lookupParents) {
1678 Tooltip tt = tooltip;
1682 }
else if( lookupParents ) {
1684 while(
null != p ) {
1685 tt = p.startToolTip(
false);
1811 @SuppressWarnings(
"unchecked")
1812 final ArrayList<MouseGestureListener> clonedListeners = (ArrayList<MouseGestureListener>) mouseListeners.clone();
1813 clonedListeners.add(l);
1814 mouseListeners = clonedListeners;
1821 @SuppressWarnings(
"unchecked")
1822 final ArrayList<MouseGestureListener> clonedListeners = (ArrayList<MouseGestureListener>) mouseListeners.clone();
1823 clonedListeners.remove(l);
1824 mouseListeners = clonedListeners;
1845 @SuppressWarnings(
"unchecked")
1846 final ArrayList<KeyListener> clonedListeners = (ArrayList<KeyListener>) keyListeners.clone();
1847 clonedListeners.add(l);
1848 keyListeners = clonedListeners;
1855 @SuppressWarnings(
"unchecked")
1856 final ArrayList<KeyListener> clonedListeners = (ArrayList<KeyListener>) keyListeners.clone();
1857 clonedListeners.remove(l);
1858 keyListeners = clonedListeners;
1916 this.winPos =
new int[] { glWinX, glWinY };
1927 private final void releaseInteraction() {
1929 setIO(IO_IN_MOVE,
false);
1930 setIO(IO_IN_RESIZE_BR,
false);
1931 setIO(IO_IN_RESIZE_BL,
false);
1942 final boolean dispatchMouseEvent(
final MouseEvent e,
final int glWinX,
final int glWinY,
final Vec3f objPos) {
1949 final Shape.EventInfo shapeEvent =
new EventInfo(glWinX, glWinY,
this, objPos);
1951 boolean ires =
false;
1952 final short eventType = e.getEventType();
1953 if( 1 == e.getPointerCount() ) {
1954 switch( eventType ) {
1955 case MouseEvent.EVENT_MOUSE_MOVED:
1956 if(
null != onHoverListener ) {
1957 onHoverListener.run(
this, objPos, e);
1961 case MouseEvent.EVENT_MOUSE_PRESSED:
1962 if( resizableOrDraggable ) {
1963 setIO(IO_DRAG_FIRST,
true);
1968 case MouseEvent.EVENT_MOUSE_RELEASED:
1970 releaseInteraction();
1973 case MouseEvent.EVENT_MOUSE_CLICKED:
1977 if(
null != onClickedListener ) {
1978 onClickedListener.run(
this, objPos, e);
1984 if( resizableOrDraggable && MouseEvent.EVENT_MOUSE_DRAGGED == eventType ) {
1986 final Vec3f euler = rotation.
toEuler(
new Vec3f());
1987 final boolean x_flip, y_flip;
1989 final float x_rot = Math.abs(euler.x());
1990 final float y_rot = Math.abs(euler.y());
1991 x_flip = 1f*FloatUtil.HALF_PI <= y_rot && y_rot <= 3f*FloatUtil.HALF_PI;
1992 y_flip = 1f*FloatUtil.HALF_PI <= x_rot && x_rot <= 3f*FloatUtil.HALF_PI;
1995 if( isIO(IO_DRAG_FIRST) ) {
1996 objDraggedFirst.
set(objPos);
1997 winDraggedLast[0] = glWinX;
1998 winDraggedLast[1] = glWinY;
1999 setIO(IO_DRAG_FIRST,
false);
2001 final float ix = x_flip ?
box.
getWidth() - objPos.x() : objPos.x();
2002 final float iy = y_flip ?
box.
getHeight() - objPos.y() : objPos.y();
2007 if( minx_br <= ix && ix <= maxx_br &&
2008 miny_br <= iy && iy <= maxy_br ) {
2010 setIO(IO_IN_RESIZE_BR,
true);
2017 if( minx_bl <= ix && ix <= maxx_bl &&
2018 miny_bl <= iy && iy <= maxy_bl ) {
2020 setIO(IO_IN_RESIZE_BL,
true);
2027 System.err.printf(
"DragFirst: drag %b, resize[br %b, bl %b], obj[%s], flip[x %b, y %b]%n",
2028 isIO(IO_IN_MOVE), isIO(IO_IN_RESIZE_BR), isIO(IO_IN_RESIZE_BL), objPos, x_flip, y_flip);
2029 System.err.printf(
"DragFirst: %s%n",
this);
2033 shapeEvent.objDrag.set( objPos.x() - objDraggedFirst.x(),
2034 objPos.y() - objDraggedFirst.y() );
2035 shapeEvent.objDrag.mul(x_flip ? -1f : 1f, y_flip ? -1f : 1f);
2037 shapeEvent.winDrag[0] = glWinX - winDraggedLast[0];
2038 shapeEvent.winDrag[1] = glWinY - winDraggedLast[1];
2039 winDraggedLast[0] = glWinX;
2040 winDraggedLast[1] = glWinY;
2041 if( 1 == e.getPointerCount() ) {
2042 final float sdx = shapeEvent.objDrag.x() * scale.x();
2043 final float sdy = shapeEvent.objDrag.y() * scale.y();
2044 if( isIO(IO_IN_RESIZE_BR) || isIO(IO_IN_RESIZE_BL) ) {
2047 final float sdy2, sx, sy;
2048 if( isIO(IO_IN_RESIZE_BR) ) {
2049 sx = scale.x() + sdx/bw;
2051 sx = scale.x() - sdx/bw;
2055 sdy2 = bh * ( scale.y() - sy );
2058 sy = scale.y() - sdy2/bh;
2060 if( resize_sxy_min <= sx && resize_sxy_min <= sy ) {
2062 System.err.printf(
"DragZoom: resize[br %b, bl %b], win[%4d, %4d], , flip[x %b, y %b], obj[%s], dxy +[%s], sdxy +[%.4f, %.4f], sdxy2 +[%.4f, %.4f], scale [%s] -> [%.4f, %.4f]%n",
2063 isIO(IO_IN_RESIZE_BR), isIO(IO_IN_RESIZE_BL), glWinX, glWinY, x_flip, y_flip, objPos,
2064 shapeEvent.objDrag, sdx, sdy, sdx, sdy2,
2067 if( isIO(IO_IN_RESIZE_BR) ) {
2068 moveNotify( 0, sdy2, 0f, e);
2070 moveNotify( sdx, sdy2, 0f, e);
2075 }
else if( isIO(IO_IN_MOVE) ) {
2077 System.err.printf(
"DragMove: win[%4d, %4d] +[%2d, %2d], , flip[x %b, y %b], obj[%s] +[%s], rot %s%n",
2078 glWinX, glWinY, shapeEvent.winDrag[0], shapeEvent.winDrag[1],
2079 x_flip, y_flip, objPos, shapeEvent.objDrag, euler);
2081 moveNotify( sdx, sdy, 0f, e);
2086 e.setAttachment(shapeEvent);
2088 return dispatchMouseEvent(e) || ires;
2096 final boolean dispatchMouseEvent(
final MouseEvent e) {
2097 final short eventType = e.getEventType();
2098 for(
int i = 0; !e.isConsumed() && i < mouseListeners.size(); i++ ) {
2099 final MouseGestureListener l = mouseListeners.get(i);
2100 switch( eventType ) {
2101 case MouseEvent.EVENT_MOUSE_CLICKED:
2104 case MouseEvent.EVENT_MOUSE_ENTERED:
2107 case MouseEvent.EVENT_MOUSE_EXITED:
2110 case MouseEvent.EVENT_MOUSE_PRESSED:
2113 case MouseEvent.EVENT_MOUSE_RELEASED:
2116 case MouseEvent.EVENT_MOUSE_MOVED:
2119 case MouseEvent.EVENT_MOUSE_DRAGGED:
2122 case MouseEvent.EVENT_MOUSE_WHEEL_MOVED:
2123 l.mouseWheelMoved(e);
2126 throw new NativeWindowException(
"Unexpected mouse event type " + e.getEventType());
2129 return e.isConsumed();
2140 final void dispatchGestureEvent(
final GestureEvent e,
final int glWinX,
final int glWinY,
final PMVMatrix4f pmv,
final Recti viewport,
final Vec3f objPos) {
2142 final PinchToZoomGesture.ZoomEvent ze = (PinchToZoomGesture.ZoomEvent) e;
2143 final float pixels = ze.getDelta() * ze.getScale();
2144 final int winX2 = glWinX + Math.round(pixels);
2145 final Vec3f objPos2 =
winToShapeCoord(pmv, viewport, winX2, glWinY,
new Vec3f());
2146 if(
null == objPos2 ) {
2149 final float dx = objPos2.x();
2150 final float dy = objPos2.y();
2151 final float sx = scale.x() + ( dx/
box.
getWidth() );
2154 System.err.printf(
"DragZoom: resize[br %b, bl %b], win %4d/%4d, obj %s, %s + %.3f/%.3f -> %.3f/%.3f%n",
2155 isIO(IO_IN_RESIZE_BR), isIO(IO_IN_RESIZE_BL), glWinX, glWinY, objPos, position, dx, dy, sx, sy);
2157 if( resize_sxy_min <= sx && resize_sxy_min <= sy ) {
2159 System.err.printf(
"PinchZoom: pixels %f, win %4d/%4d, obj %s, %s + %.3f/%.3f -> %.3f/%.3f%n",
2160 pixels, glWinX, glWinY, objPos, position, dx, dy, sx, sy);
2167 final Shape.EventInfo shapeEvent =
new EventInfo(glWinX, glWinY,
this, objPos);
2168 e.setAttachment(shapeEvent);
2170 dispatchGestureEvent(e);
2178 final boolean dispatchGestureEvent(
final GestureEvent e) {
2179 for(
int i = 0; !e.isConsumed() && i < mouseListeners.size(); i++ ) {
2180 mouseListeners.get(i).gestureDetected(e);
2182 return e.isConsumed();
2190 final boolean dispatchKeyEvent(
final KeyEvent e) {
2196 final short eventType = e.getEventType();
2197 for(
int i = 0; !e.isConsumed() && i < keyListeners.size(); i++ ) {
2198 final KeyListener l = keyListeners.get(i);
2199 switch( eventType ) {
2200 case KeyEvent.EVENT_KEY_PRESSED:
2203 case KeyEvent.EVENT_KEY_RELEASED:
2207 throw new NativeWindowException(
"Unexpected key event type " + e.getEventType());
2210 return e.isConsumed();
2248 @SuppressWarnings(
"unused")
2249 private static
int compareAsc0(final
float a, final
float b) {
2258 private static int compareAsc1(
final float a,
final float b) {
2267 @SuppressWarnings(
"unused")
2268 private static
int compareDesc0(final
float a, final
float b) {
2269 if( FloatUtil.isEqual2(a, b) ) {
2277 private static int compareDesc1(
final float a,
final float b) {
2289 public int compare(
final Shape s1,
final Shape s2) {
2295 public int compare(
final Shape s1,
final Shape s2) {
Group of Shapes, optionally utilizing a Group.Layout.
final PMVMatrixSetup getPMVMatrixSetup()
Return the default or setPMVMatrixSetup(PMVMatrixSetup) PMVMatrixSetup.
final Recti getViewport(final Recti target)
Copies the current int[4] viewport in given target and returns it for chaining.
Shape event info for propagated NEWTEvents containing reference of the intended shape as well as the ...
final int[] winPos
The GL window coordinates, origin bottom-left.
final Vec3f objPos
The relative object coordinate of glWinX/glWinY to the associated Shape.
final Shape shape
The associated Shape for this event.
final Vec2f objDrag
The drag delta of the relative object coordinate of glWinX/glWinY to the associated Shape.
final int[] winDrag
The drag delta of GL window coordinates, origin bottom-left.
Forward KeyListener, to be attached to a key event source forwarded to the receiver set at constructo...
ForwardKeyListener(final Shape receiver)
ForwardKeyListener Constructor
void keyReleased(final KeyEvent e)
A key has been released, excluding auto-repeat modifier keys.
void keyPressed(final KeyEvent e)
A key has been pressed, excluding auto-repeat modifier keys.
Forward MouseGestureListener, to be attached to a mouse event source forwarded to the receiver set at...
void mouseExited(final MouseEvent e)
Only generated for PointerType#Mouse.
void mouseWheelMoved(final MouseEvent e)
Traditional event name originally produced by a mouse pointer type.
void mouseEntered(final MouseEvent e)
Only generated for PointerType#Mouse.
ForwardMouseListener(final Shape receiver)
ForwardMouseListener Constructor
void mouseClicked(final MouseEvent e)
void mouseMoved(final MouseEvent e)
void mousePressed(final MouseEvent e)
void mouseReleased(final MouseEvent e)
void mouseDragged(final MouseEvent e)
void gestureDetected(final GestureEvent e)
GestureHandler has detected the gesture.
Convenient adapter combining dummy implementation for MouseListener and GestureListener.
void gestureDetected(final GestureEvent gh)
GestureHandler has detected the gesture.
Generic Shape, potentially using a Graph via GraphShape or other means of representing content.
final int[] shapeToWinCoord(final Scene.PMVMatrixSetup pmvMatrixSetup, final Recti viewport, final Vec3f objPos, final PMVMatrix4f pmv, final int[] glWinPos)
Map given object coordinate relative to this shape to window coordinates.
final boolean isMatIdentity()
Returns true if getMat() has not been mutated, i.e.
Padding getPadding()
Returns unscaled Padding of this shape, which is included in unscaled getBounds() and also includes t...
Tooltip setToolTip(final Tooltip newTooltip)
Set's a new Tooltip for this shape.
final boolean isStateDirty()
Returns the rendering dirty state, see markStateDirty().
abstract void drawToSelectImpl0(final GL2ES2 gl, final RegionRenderer renderer)
Actual draw implementation, called by drawToSelect(GL2ES2, RegionRenderer).
final Matrix4f getMat()
Returns the internal Matrix4f reference.
final Shape removeKeyListener(final KeyListener l)
final boolean isDraggable()
Returns if this shape is draggable, a user interaction.
Shape setColor(final float r, final float g, final float b, final float a)
Set base color.
Shape setName(final String name)
Set a symbolic name for this shape for identification.
final Shape setDraggable(final boolean draggable)
Set whether this shape is draggable, i.e.
void receiveMouseEvents(final Shape source)
Forward MouseGestureListener events to this Shape from source using a ForwardMouseListener.
final String getName()
Return the optional symbolic name for this shape, defaults to noname.
final Shape addKeyListener(final KeyListener l)
abstract void destroyImpl0(final GL2ES2 gl, final RegionRenderer renderer)
Custom destroy(GL2ES2, RegionRenderer) task, called 1st.
final Shape move(final float dtx, final float dty, final float dtz)
Move about scaled distance.
final void onHover(final PointerListener l)
Set user callback to be notified when a pointer/mouse is moving over this shape.
Shape()
Create a generic UI Shape.
final Shape setScale(final Vec3f s)
Set scale factor to given scale.
final Shape setInteractive(final boolean v)
Set whether this shape is interactive in general, i.e.
final Shape addActivationListener(final Listener l)
Add user callback to be notified when shape is activated (pointer-over and/or click) or de-activated ...
final Vec3f winToShapeCoord(final Scene.PMVMatrixSetup pmvMatrixSetup, final Recti viewport, final int glWinX, final int glWinY, final PMVMatrix4f pmv, final Vec3f objPos)
Map given gl-window-coordinates to object coordinates relative to this shape and its z-coordinate.
void draw(final GL2ES2 gl, final RegionRenderer renderer)
Renders the shape.
boolean hasPadding()
Returns true if setPaddding(Padding) added a non Padding#zeroSize() spacing to this shape.
final Vec4f activeRGBAModulate
Default active color-factor (dark), modulates base-color.
boolean isGroup()
Returns true if this shape denotes a Group, otherwise false.
final boolean isActive()
Returns true of this shape is active.
final Matrix4f getMat(final Matrix4f out)
Returns a copy of the internal Matrix4f to out.
final int getID()
Return the optional symbolic ID for this shape.
final Shape setDiscarded(final boolean v)
Set whether this shape is discarded in last draw(GL2ES2, RegionRenderer), i.e.
final void onDraw(final DrawListener l)
Set a user one-shot initializer callback or custom draw(GL2ES2, RegionRenderer) hook.
final boolean hasBorder()
Returns true if a border has been enabled via setBorder(float, Padding).
final void onClicked(final PointerListener l)
Set user callback to be notified when shape is clicked.
final Shape setPressed(final boolean b)
final Shape moveTo(final Vec3f t)
Move to scaled position.
final Vec3f winToShapeCoord(final PMVMatrix4f pmv, final Recti viewport, final int glWinX, final int glWinY, final Vec3f objPos)
Map given gl-window-coordinates to object coordinates relative to this shape and its z-coordinate.
final Vec3f getScale()
Returns scale Vec3f reference.
final Shape setFixedARatioResize(final boolean v)
Sets whether aspect-ratio shall be kept at resize, if isResizable().
final Recti getSurfacePort(final PMVMatrix4f pmv, final Recti viewport, final Recti surfacePort)
Retrieve surface (view) port of this shape, i.e.
boolean activeRGBAModulateOn
final void clear(final GL2ES2 gl, final RegionRenderer renderer)
Clears all data and reset all states as if this instance was newly created.
final float getAdjustedZ()
static Comparator< Shape > ZDescendingComparator
final float getBorderThickness()
Returns the border thickness, see setBorder(float, Padding).
final boolean isResizable()
Returns if this shape is resizable, a user interaction.
final Shape setScale(final float sx, final float sy, final float sz)
Set scale factor to given scale.
final Vec4f toggleOnRGBAModulate
Default toggle color-factor (darker), modulates base-color.
boolean isShapeDirty()
Returns the shape's dirty state, see markShapeDirty().
static final boolean DEBUG_DRAW
final void markStateDirty()
Marks the rendering state dirty, causing next draw() to notify the Graph region to reselect shader an...
final Shape setResizable(final boolean resizable)
Set whether this shape is resizable, i.e.
final Shape moveTo(final float tx, final float ty, final float tz)
Move to scaled position.
static Comparator< Shape > ZAscendingComparator
final Shape removeMouseListener(final MouseGestureListener l)
void setParent(final Group c)
final float getScaledWidth()
Returns the scaled width of the bounding AABBox for this shape.
final float getScaledHeight()
Returns the scaled height of the bounding AABBox for this shape.
final Shape validate(final GLProfile glp)
Validates the shape's underlying GLRegion w/o a current GL2ES2 object.
final Shape setToggle(final boolean v)
Set this shape's toggle state, default is off.
abstract void clearImpl0(final GL2ES2 gl, final RegionRenderer renderer)
Custom clear(GL2ES2, RegionRenderer) task, called 1st.
final Vec3f getPosition()
Returns position Vec3f reference, i.e.
final Vec4f toggleOffRGBAModulate
Default toggle color-factor (original), modulates base-color.
final Shape scale(final float sx, final float sy, final float sz)
Multiply current scale factor by given scale.
final Vec3f winToShapeCoord(final Scene scene, final int glWinX, final int glWinY, final PMVMatrix4f pmv, final Vec3f objPos)
Map given gl-window-coordinates to object coordinates relative to this shape and its z-coordinate.
final float[] getPixelPerShapeUnit(final int[] shapeSizePx, final float[] pixPerShape)
Retrieve pixel per scaled shape-coordinate unit, i.e.
final Vec4f getBorderColor()
final AABBox getBounds()
Returns the unscaled bounding AABBox for this shape, borrowing internal instance.
Shape setPressedColorMod(final float r, final float g, final float b, final float a)
Set pressed color, modulating getColor() if isPressed().
Shape setColor(final Vec4f c)
Set base color.
final AABBox getBounds(final GLProfile glp)
Returns the unscaled bounding AABBox for this shape.
final boolean isVisible()
Returns true if this shape is set visible by the user, otherwise false.
final Quaternion getRotation()
Returns Quaternion for rotation.
final Shape move(final Vec3f dt)
Move about scaled distance.
abstract void drawImpl0(final GL2ES2 gl, final RegionRenderer renderer, final Vec4f rgba)
Actual draw implementation, called by draw(GL2ES2, RegionRenderer).
abstract void validateImpl(final GL2ES2 gl, final GLProfile glp)
void drawToSelect(final GL2ES2 gl, final RegionRenderer renderer)
Experimental selection draw command used by Scene.
final Shape removeActivationListener(final Listener l)
final Vec4f getToggleOffColorMod()
Returns modulation color when not isToggleOn().
final Shape setDragAndResizable(final boolean v)
Set whether this shape is draggable and resizable.
Group getParent()
Returns the last parent container Group this shape has been added to or null.
final boolean isToggleOn()
Returns true this shape's toggle state.
final int[] shapeToWinCoord(final Scene scene, final Vec3f objPos, final PMVMatrix4f pmv, final int[] glWinPos)
Map given object coordinate relative to this shape to window coordinates.
final Vec4f getColor()
Returns base-color w/o color channel, will be modulated w/ getPressedColorMod(), getToggleOnColorMod(...
final int[] getSurfaceSize(final Scene.PMVMatrixSetup pmvMatrixSetup, final Recti viewport, final PMVMatrix4f pmv, final int[] surfaceSize)
Retrieve surface (view) size in pixels of this shape.
final boolean isFixedARatioResize()
Returns if aspect-ratio shall be kept at resize, if isResizable().
final Vec4f getActiveColorMod()
Returns modulation color when isActive().
final Shape setToggleOnColorMod(final float r, final float g, final float b, final float a)
Set toggle-on color, modulating getColor() if isToggleOn() and setToggleable(boolean).
final void dispatchActivationEvent(final Shape s)
Dispatch activation event event to this shape.
final Shape setToggleOffColorMod(final float r, final float g, final float b, final float a)
Set toggle-off color, modulating getColor() if !isToggleOn() and setToggleable(boolean).
final Shape validate(final GL2ES2 gl)
Validates the shape's underlying GLRegion.
final boolean isDiscarded()
Returns whether this shape is discarded in last draw(GL2ES2, RegionRenderer), i.e.
void toggleNotify(final boolean on)
final int[] getSurfaceSize(final PMVMatrix4f pmv, final Recti viewport, final int[] surfaceSize)
Retrieve surface (view) size in pixels of this shape.
final PMVMatrix4f setPMVMatrix(final Scene.PMVMatrixSetup pmvMatrixSetup, final Recti viewport, final PMVMatrix4f pmv)
Setup the given PMVMatrix4f and apply this shape's transformation.
final Shape addMouseListener(final MouseGestureListener l)
final Shape setActivable(final boolean v)
Set whether this shape is allowed to be activated, i.e become isActive().
abstract boolean hasColorChannel()
Returns true if implementation uses an extra color channel or texture which will be modulated with th...
final void markShapeDirty()
Marks the shape dirty, causing next draw() to recreate the Graph shape and reset the region.
final boolean isPressed()
final Shape setBorderColor(final Vec4f c)
Set border color.
final Shape setPaddding(final Padding padding)
Sets the unscaled padding for this shape, which is included in unscaled getBounds() and also includes...
final Shape setRotation(final Quaternion q)
Sets the rotation Quaternion.
final void updateMat()
Updates the internal Matrix4f with local position, rotation and scale.
final void runSynced(final Runnable action)
Perform given Runnable action synchronized.
final void destroy(final GL2ES2 gl, final RegionRenderer renderer)
Destroys all data.
final Vec4f rgbaColor
Default base-color w/o color channel, will be modulated w/ pressed- and toggle color.
final int[] getSurfaceSize(final Scene scene, final PMVMatrix4f pmv, final int[] surfaceSize)
Retrieve surface (view) size in pixels of this shape.
final void onToggle(final Listener l)
Set user callback to be notified when shape toggle()'ed.
final int[] shapeToWinCoord(final PMVMatrix4f pmv, final Recti viewport, final Vec3f objPos, final int[] glWinPos)
Map given object coordinate relative to this shape to window coordinates.
final Shape setActiveColorMod(final Vec4f c)
Enable active color, modulation getColor() if isActive() with passing c != null, disable with passing...
final void applyMatToMv(final PMVMatrix4f pmv)
Applies the internal Matrix4f to the given modelview matrix, i.e.
final Shape scale(final Vec3f s)
Multiply current scale factor by given scale.
final Shape setVisible(final boolean v)
Enable (default) or disable this shape's visibility.
boolean isToggleable()
Returns true if this shape is toggable, i.e.
final Shape validate(final GL2ES2 gl, final GLProfile glp)
Validate the shape via validate(GL2ES2) if gl is not null, otherwise uses validate(GLProfile).
final Vec4f getToggleOnColorMod()
Returns modulation color when isToggleOn().
final Shape setRotationPivot(final float px, final float py, final float pz)
Set unscaled rotation origin, aka pivot.
final boolean isInteractive()
Returns if this shape allows user interaction in general, see setInteractive(boolean).
final float[] getPixelPerShapeUnit(final PMVMatrix4f pmv, final Recti viewport, final float[] pixPerShape)
Retrieve pixel per scaled shape-coordinate unit, i.e.
final float getScaledDepth()
final Vec4f getPressedColorMod()
Returns modulation color when isPressed().
final PMVMatrix4f setPMVMatrix(final Scene scene, final PMVMatrix4f pmv)
Setup the given PMVMatrix4f and apply this shape's transformation.
void receiveKeyEvents(final Shape source)
Forward KeyListener events to this Shape from source using a ForwardKeyListener.
final boolean isActivable()
Returns if this shape is allowed to be activated, i.e become isActive().
final void onMove(final MoveListener l)
Set user callback to be notified when shape is move(Vec3f)'ed.
final Shape setBorderColor(final float r, final float g, final float b, final float a)
Set border color.
final Shape setID(final int id)
Set a symbolic ID for this shape for identification.
final boolean setActive(final boolean v, final float zOffset)
final Shape setBorder(final float thickness)
Sets the thickness of the border, which is included in getBounds() and is outside of getPadding().
final float[] getPixelPerShapeUnit(final Scene scene, final PMVMatrix4f pmv, final float[] pixPerShape)
Retrieve pixel per scaled shape-coordinate unit, i.e.
final Shape setToggleable(final boolean toggleable)
Set this shape toggleable, default is off.
final Vec3f getRotationPivot()
Return unscaled rotation origin Vec3f reference, aka pivot.
final String getDirtyString()
final Shape setRotationPivot(final Vec3f pivot)
Set unscaled rotation origin, aka pivot.
final Vec4f pressedRGBAModulate
Default pressed color-factor (darker and slightly transparent), modulates base-color.
GraphUI CSS property Padding, unscaled space belonging to the element and included in the element's s...
Basic Float math utility functions.
static boolean isEqual2(final float a, final float b)
Returns true if both values are equal, i.e.
static boolean isZero(final float a, final float epsilon)
Returns true if value is zero, i.e.
Basic 4x4 float matrix implementation using fields for intensive use-cases (host operations).
static boolean mapObjToWin(final Vec3f obj, final Matrix4f mMv, final Matrix4f mP, final Recti viewport, final Vec3f winPos)
Map object coordinates to window coordinates.
Matrix4f load(final Matrix4f src)
Load the values of the given matrix src to this matrix.
final Matrix4f loadIdentity()
Set this matrix to identity.
final Matrix4f rotate(final float ang_rad, final float x, final float y, final float z, final Matrix4f tmp)
Rotate this matrix about give axis and angle in radians, i.e.
final Matrix4f scale(final float x, final float y, final float z, final Matrix4f tmp)
Scale this matrix, i.e.
final Matrix4f translate(final float x, final float y, final float z, final Matrix4f tmp)
Translate this matrix, i.e.
static boolean mapWinToObj(final float winx, final float winy, final float winz, final Matrix4f mMv, final Matrix4f mP, final Recti viewport, final Vec3f objPos, final Matrix4f mat4Tmp)
Map window coordinates to object coordinates.
final Matrix4f setToTranslation(final float x, final float y, final float z)
Set this matrix to translation.
Quaternion implementation supporting Gimbal-Lock free rotations.
Vec3f toEuler(final Vec3f result)
Transform this quaternion to Euler rotation angles in radians (pitchX, yawY and rollZ).
final Quaternion set(final Quaternion src)
Set all values of this quaternion using the given src.
final Quaternion setIdentity()
final boolean isIdentity()
Returns true if this quaternion has identity.
Rectangle with x, y, width and height integer components.
void setWidth(final int width)
void setHeight(final int height)
2D Vector based upon two float components.
3D Vector based upon three float components.
Vec3f mul(final float val)
Returns this * val; creates new vector.
boolean isZero()
Return true if all components are zero, i.e.
boolean isEqual(final Vec3f o, final float epsilon)
Equals check using a given FloatUtil#EPSILON value and FloatUtil#isEqual(float, float,...
Vec3f set(final Vec3f o)
this = o, returns this.
Vec3f add(final float dx, final float dy, final float dz)
this = this + { dx, dy, dz }, returns this.
4D Vector based upon four float components.
Vec4f set(final Vec4f o)
this = o, returns this.
Vec4f mul(final float val)
Returns this * val; creates new vector.
Axis Aligned Bounding Box.
final Vec3f getHigh()
Returns the maximum right-top-near (xyz) coordinate.
final Vec3f getLow()
Returns the minimum left-bottom-far (xyz) coordinate.
final AABBox reset()
Resets this box to the inverse low/high, allowing the next resize(float, float, float) command to hit...
final Vec3f getCenter()
Returns computed center of this AABBox of getLow() and getHigh().
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
final PMVMatrix4f mulMv(final Matrix4f m)
Multiply the modelview matrix: [c] = [c] x [m].
final Matrix4f getPMv()
Returns the pre-multiplied projection x modelview, P x Mv.
final boolean mapObjToWin(final Vec3f objPos, final Recti viewport, final Vec3f winPos)
Map object coordinates to window coordinates.
final Matrix4f getPMvi()
Returns the pre-multiplied inverse projection x modelview, if Matrix4f#invert(Matrix4f) succeeded,...
Pointer event of type PointerType.
Specifies the the OpenGL profile.
Interface providing a method to setup PMVMatrix4f's GLMatrixFunc#GL_PROJECTION and GLMatrixFunc#GL_MO...
Shape draw listener action returning a boolean value
boolean run(final Shape shape, GL2ES2 gl, RegionRenderer renderer)
Return true to remove this DrawListener at Shape#draw(GL2ES2, RegionRenderer), otherwise it is being ...
General Shape listener action.
void run(final Shape shape)
Combining MouseListener and GestureListener.
void run(Shape s, Vec3f origin, Vec3f dest, MouseEvent e)
Move callback.
Shape pointer listener, e.g.
void run(Shape s, final Vec3f pos, MouseEvent e)
Event callback.
boolean visit(Shape s)
Visitor method.
boolean visit(Shape s, final PMVMatrix4f pmv)
Visitor method.
Listener for GestureEvents.
Listener for MouseEvents.
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.