28package com.jogamp.newt.event;
30import com.jogamp.common.util.PropertyAccess;
32import jogamp.newt.Debug;
86 Debug.initSingleton();
88 SCROLL_SLOP_PIXEL = PropertyAccess.getIntProperty(
"newt.event.scroll_slop_pixel",
true, 16);
90 SCROLL_SLOP_MM = PropertyAccess.getIntProperty(
"newt.event.scroll_slop_mm",
true, 3);
91 DOUBLE_TAP_SLOP_MM = PropertyAccess.getIntProperty(
"newt.event.double_tap_slop_mm",
true, 20);
94 private static final int ST_NONE = 0;
95 private static final int ST_1PRESS = 1;
96 private static final int ST_2PRESS_T = 2;
97 private static final int ST_2PRESS_C = 3;
98 private static final int ST_SCROLL = 4;
100 private final int scrollSlop, scrollSlopSquare, doubleTapSlop, doubleTapSlopSquare;
101 private final float[] scrollDistance =
new float[] { 0f, 0f };
102 private final int[] pIds =
new int[] { -1, -1 };
104 private int gestureState;
105 private int sqStartDist;
106 private int lastX, lastY;
107 private int pointerDownCount;
108 private MouseEvent hitGestureEvent;
110 private static final int getSquareDistance(
final float x1,
final float y1,
final float x2,
final float y2) {
111 final int deltaX = (int) x1 - (
int) x2;
112 final int deltaY = (int) y1 - (
int) y2;
113 return deltaX * deltaX + deltaY * deltaY;
116 private int gesturePointers(
final MouseEvent e,
final int excludeIndex) {
118 for(
int i=e.getPointerCount()-1; i>=0; i--) {
119 if( excludeIndex != i ) {
120 final int id = e.getPointerId(i);
121 if( pIds[0] ==
id || pIds[1] ==
id ) {
135 scrollSlop = scaledScrollSlop;
136 scrollSlopSquare = scaledScrollSlop * scaledScrollSlop;
137 doubleTapSlop = scaledDoubleTapSlop;
138 doubleTapSlopSquare = scaledDoubleTapSlop * scaledDoubleTapSlop;
139 pointerDownCount = 0;
142 System.err.println(
"DoubleTapScroll scrollSlop (scaled) "+scrollSlop);
143 System.err.println(
"DoubleTapScroll doubleTapSlop (scaled) "+doubleTapSlop);
149 return "DoubleTapScroll[state "+gestureState+
", in "+
isWithinGesture()+
", has "+(
null!=hitGestureEvent)+
", pc "+pointerDownCount+
"]";
153 public void clear(
final boolean clearStarted) {
154 scrollDistance[0] = 0f;
155 scrollDistance[1] = 0f;
156 hitGestureEvent =
null;
158 gestureState = ST_NONE;
169 return ST_2PRESS_C <= gestureState;
174 return null != hitGestureEvent;
179 if(
null != hitGestureEvent ) {
183 rotationXYZ[0] = scrollDistance[0] / scrollSlop;
184 rotationXYZ[1] = scrollDistance[1] / scrollSlop;
185 if( rotationXYZ[0]*rotationXYZ[0] > rotationXYZ[1]*rotationXYZ[1] ) {
187 modifiers |= com.jogamp.newt.event.InputEvent.SHIFT_MASK;
198 return scrollDistance;
203 if(
null != hitGestureEvent || !(in instanceof
MouseEvent) ) {
212 final int x0 = pe.
getX(0);
213 final int y0 = pe.
getY(0);
214 switch ( eventType ) {
217 if( ST_NONE == gestureState && 1 == pointerDownCount ) {
220 gestureState = ST_1PRESS;
221 }
else if( ST_NONE < gestureState && 2 == pointerDownCount && 1 == gesturePointers(pe, 0) ) {
222 final int x1 = pe.
getX(1);
223 final int y1 = pe.
getY(1);
224 final int xm = (x0+x1)/2;
225 final int ym = (y0+y1)/2;
227 if( ST_1PRESS == gestureState ) {
228 final int sqDist = getSquareDistance(x0, y0, x1, y1);
229 final boolean isDistWithinDoubleTapSlop = sqDist < doubleTapSlopSquare;
230 if( isDistWithinDoubleTapSlop ) {
237 sqStartDist = sqDist;
238 gestureState = ST_2PRESS_T;
241 final int dist = (int)Math.round(Math.sqrt(sqDist));
242 System.err.println(
this+
".pressed.1: dist "+dist+
", gPtr "+gPtr+
", distWithin2DTSlop "+isDistWithinDoubleTapSlop+
", last "+lastX+
"/"+lastY+
", "+pe);
244 }
else if( ST_2PRESS_C == gestureState ) {
245 gPtr = gesturePointers(pe, -1);
257 System.err.println(
this+
".pressed: gPtr "+gPtr+
", this "+lastX+
"/"+lastY+
", "+pe);
263 final int gPtr = gesturePointers(pe, 0);
266 gestureState = ST_2PRESS_C;
267 }
else if( 0 == gPtr ) {
272 System.err.println(
this+
".released: gPtr "+gPtr+
", "+pe);
277 if( 2 == pointerDownCount && ST_1PRESS < gestureState ) {
278 final int gPtr = gesturePointers(pe, -1);
281 final int x1 = pe.
getX(1);
282 final int y1 = pe.
getY(1);
283 final int xm = (x0+x1)/2;
284 final int ym = (y0+y1)/2;
285 final int sqDist = getSquareDistance(x0, y0, x1, y1);
286 final boolean isDistDiffWithinDoubleTapSlop = Math.abs(sqDist - sqStartDist) <= doubleTapSlopSquare;
287 if( isDistDiffWithinDoubleTapSlop ) {
288 switch( gestureState ) {
290 final int sqScrollLen = getSquareDistance(lastX, lastY, xm, ym);
291 if( sqScrollLen > scrollSlopSquare ) {
292 gestureState = ST_SCROLL;
297 gestureState = ST_SCROLL;
301 scrollDistance[0] = lastX - xm;
302 scrollDistance[1] = lastY - ym;
303 hitGestureEvent = pe;
307 final boolean isDistWithinDoubleTapSlop = sqDist < doubleTapSlopSquare;
308 final int dist = (int)Math.round(Math.sqrt(sqDist));
309 final int sqScrollLen = getSquareDistance(lastX, lastY, xm, ym);
310 final int scrollLen = (int)Math.round(Math.sqrt(sqScrollLen));
311 System.err.println(
this+
".dragged.1: pDist "+dist+
", scrollLen "+scrollLen+
", gPtr "+gPtr+
" ["+pIds[0]+
", "+pIds[1]+
"]"+
312 ", diffDistWithinTapSlop "+isDistDiffWithinDoubleTapSlop+
313 ", distWithin2DTSlop "+isDistWithinDoubleTapSlop+
314 ", this "+xm+
"/"+ym+
", last "+lastX+
"/"+lastY+
", d "+scrollDistance[0]+
"/"+scrollDistance[1]);
319 final boolean isDistWithinDoubleTapSlop = sqDist < doubleTapSlopSquare;
320 final int dist = (int)Math.round(Math.sqrt(sqDist));
321 final int startDist = (int)Math.round(Math.sqrt(sqStartDist));
322 System.err.println(
this+
".dragged.X1: pDist "+dist+
", distStart "+startDist+
", gPtr "+gPtr+
" ["+pIds[0]+
", "+pIds[1]+
"]"+
323 ", diffDistWithinTapSlop "+isDistDiffWithinDoubleTapSlop+
324 ", distWithin2DTSlop "+isDistWithinDoubleTapSlop+
325 ", this "+xm+
"/"+ym+
", last "+lastX+
"/"+lastY+
", d "+scrollDistance[0]+
"/"+scrollDistance[1]);
329 if( ST_2PRESS_T < gestureState ) {
337 System.err.println(
this+
".dragged.X2: gPtr "+gPtr+
" ["+pIds[0]+
", "+pIds[1]+
"]"+
338 ", last "+lastX+
"/"+lastY+
", d "+scrollDistance[0]+
"/"+scrollDistance[1]);
347 return null != hitGestureEvent;
Pointer event of type PointerType.
final short[] getAllPointerIDs()
See details for multiple-pointer events.
final PointerType getPointerType(final int index)
See details for multiple-pointer events.
final int getPointerCount()
See details for multiple-pointer events.
final PointerType[] getAllPointerTypes()
See details for multiple-pointer events.
static final short EVENT_MOUSE_PRESSED
final short getButton()
Returns the button number, e.g.
final short getPointerId(final int index)
Return the pointer id for the given index or -1 if index not available.
static final short EVENT_MOUSE_WHEEL_MOVED
final float getMaxPressure()
Returns the maximum pressure known for the input device generating this event.
final float[] getAllPressures()
See details for multiple-pointer events.
final short getClickCount()
final int[] getAllX()
See details for multiple-pointer events.
final int getY()
See details for multiple-pointer events.
final int[] getAllY()
See details for multiple-pointer events.
static final short EVENT_MOUSE_DRAGGED
static final short EVENT_MOUSE_RELEASED
final float[] getRotation()
Returns a 3-component float array filled with the values of the rotational axis in the following orde...
final int getX()
See details for multiple-pointer events.
final short getEventType()
Returns the event type of this event.
final long getWhen()
Returns the timestamp, in milliseconds, of this event.
PointerClass getPointerClass()
Generic gesture handler interface designed to allow pass-through filtering of InputEvents.
static final boolean DEBUG