28package com.jogamp.newt.event;
30import com.jogamp.nativewindow.NativeSurface;
32import com.jogamp.newt.event.MouseEvent.PointerClass;
34import jogamp.newt.Debug;
48 public static final boolean DEBUG = Debug.debug(
"Window.MouseEvent");
51 @SuppressWarnings(
"serial")
53 private final float zoom;
54 private final float delta;
55 private final float scale;
57 final float zoom,
final float delta,
final float scale) {
58 super(source, when, modifiers, handler, pe);
64 public final float getZoom() {
return zoom; }
66 public final float getDelta() {
return delta; }
81 public final float getScale() {
return scale; }
84 return "ZoomEvent[zoom "+zoom+
", delta "+delta+
", scale "+scale+
", trigger "+getTrigger()+
", handler "+getHandler()+
"]";
89 private final boolean allowMorePointer;
91 private int zoomLastEdgeDist;
92 private boolean zoomFirstTouch;
93 private boolean zoomMode;
94 private ZoomEvent zoomEvent;
95 private final short[] pIds =
new short[] { -1, -1 };
103 this.surface = surface;
104 this.allowMorePointer = allowMorePointer;
110 return "PinchZoom[1stTouch "+zoomFirstTouch+
", in "+
isWithinGesture()+
", has "+(
null!=zoomEvent)+
", zoom "+zoom+
"]";
113 private int gesturePointers(
final MouseEvent e,
final int excludeIndex) {
116 if( excludeIndex != i ) {
118 if( pIds[0] ==
id || pIds[1] ==
id ) {
127 public void clear(
final boolean clearStarted) {
130 zoomLastEdgeDist = 0;
131 zoomFirstTouch =
true;
145 return null != zoomEvent;
164 if(
null != zoomEvent || !(in instanceof
MouseEvent) ) {
171 ( !allowMorePointer && pointerDownCount > 2 ) ) {
177 switch ( eventType ) {
179 if( 1 == pointerDownCount ) {
182 }
else if ( 2 <= pointerDownCount ) {
187 System.err.println(
"XXX1: id0 "+pIds[0]+
" -> idx0 "+0+
", id1 "+pIds[1]+
" -> idx1 "+1);
188 System.err.println(
this+
".pressed: down "+pointerDownCount+
", gPtr "+gesturePointers(pe, -1)+
", event "+pe);
193 final int gPtr = gesturePointers(pe, 0);
195 zoomFirstTouch =
true;
197 }
else if( 0 == gPtr ) {
202 System.err.println(
this+
".released: down "+pointerDownCount+
", gPtr "+gPtr+
", event "+pe);
207 if( 2 <= pointerDownCount ) {
208 final int gPtr = gesturePointers(pe, -1);
213 if( 0 <= p0Idx && 0 <= p1Idx ) {
214 final int edge0 = useY ? pe.
getY(p0Idx) : pe.
getX(p0Idx);
215 final int edge1 = useY ? pe.
getY(p1Idx) : pe.
getX(p1Idx);
218 zoomLastEdgeDist = Math.abs(edge0-edge1);
219 zoomFirstTouch=
false;
221 }
else if( zoomMode ) {
222 final int d = Math.abs(edge0-edge1);
223 final int dd = d - zoomLastEdgeDist;
225 final float delta = dd / screenEdge;
227 System.err.println(
"XXX2: id0 "+pIds[0]+
" -> idx0 "+p0Idx+
", id1 "+pIds[1]+
" -> idx1 "+p1Idx);
228 System.err.println(
"XXX3: d "+d+
", ld "+zoomLastEdgeDist+
", dd "+dd+
", screen "+screenEdge+
" -> incr "+delta+
", zoom "+zoom+
" -> "+(zoom+delta));
234 }
else if( 0 > zoom ) {
237 zoomLastEdgeDist = d;
243 System.err.println(
this+
".dragged: down "+pointerDownCount+
", gPtr "+gPtr+
", event "+pe);
250 return null != zoomEvent;
Pointer event of type PointerType.
final PointerType getPointerType(final int index)
See details for multiple-pointer events.
final int getPointerCount()
See details for multiple-pointer events.
static final short EVENT_MOUSE_PRESSED
final short getPointerId(final int index)
Return the pointer id for the given index or -1 if index not available.
final int getPointerIdx(final short id)
See details for multiple-pointer events.
final int getY()
See details for multiple-pointer events.
static final short EVENT_MOUSE_DRAGGED
static final short EVENT_MOUSE_RELEASED
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.
A GestureHandler.GestureEvent denominating zoom.
final float getDelta()
Delta to last zoom value lies within [-1..1].
ZoomEvent(final Object source, final long when, final int modifiers, final GestureHandler handler, final MouseEvent pe, final float zoom, final float delta, final float scale)
final float getScale()
Returns the scale used to determine the zoom and hence it's delta value, which semantics depends on t...
final float getZoom()
Zoom value lies within [0..2], with 1 as 1:1.
static final boolean DEBUG
final void setZoom(final float zoom)
Set zoom value within [0..2], with 1 as 1:1.
boolean process(final InputEvent in)
Process the given InputEvent and returns true if it produced the gesture.
boolean hasGesture()
Returns true if a previous process(InputEvent) command produced a gesture, which has not been cleared...
void clear(final boolean clearStarted)
Clears state of handler, i.e.
InputEvent getGestureEvent()
Returns the corresponding InputEvent for the gesture as detected by a previous process(InputEvent),...
final float getZoom()
Zoom value lies within [0..2], with 1 as 1:1.
boolean isWithinGesture()
Returns true if within a gesture as detected by a previous process(InputEvent) command,...
PinchToZoomGesture(final NativeSurface surface, final boolean allowMorePointer)
PointerClass getPointerClass()
Provides low-level information required for hardware-accelerated rendering using a surface in a platf...
int getSurfaceWidth()
Returns the width of the client area excluding insets (window decorations) in pixel units.
int getSurfaceHeight()
Returns the height of the client area excluding insets (window decorations) in pixel units.
Generic gesture handler interface designed to allow pass-through filtering of InputEvents.