private Touch.Event[] parseMotionEvent (MotionEvent event, Touch.Event.Kind kind) { int actionType = event.getActionMasked(); boolean isChanged = (actionType == MotionEvent.ACTION_POINTER_UP || actionType == MotionEvent.ACTION_POINTER_DOWN); int changedIdx = isChanged ? event.getActionIndex() : 0; int count = event.getPointerCount(); Touch.Event[] touches = new Touch.Event[isChanged ? 1 : count]; double time = event.getEventTime(); int tidx = 0; for (int tt = 0; tt < count; tt++) { // if this is a pointer up/down, we only want the changed touch if (isChanged && tt != changedIdx) continue; IPoint xy = plat.graphics().transformTouch(event.getX(tt), event.getY(tt)); float pressure = event.getPressure(tt); float size = event.getSize(tt); int id = event.getPointerId(tt)+1; touches[tidx++] = new Touch.Event(0, time, xy.x(), xy.y(), kind, id, pressure, size); } return touches; }
@Override public void onTouchStart(Touch.Event[] touches) { if (currentTest != null && currentTest.usesPositionalInputs()) return; // Android and iOS handle touch events rather differently, so we need to do this finagling // to determine whether there is an active two or three finger touch for (Touch.Event event : touches) _active.add(event.id()); if (_active.size() > 1) displayMenuLater(); } @Override
platform.touch().onTouchStart(touches); platform.pointer().onPointerStart( new Pointer.Event.Impl(flags, time, pointerEvent.x(), pointerEvent.y(), true)); break; case MotionEvent.ACTION_UP: platform.touch().onTouchEnd(touches); platform.pointer().onPointerEnd( new Pointer.Event.Impl(flags, time, pointerEvent.x(), pointerEvent.y(), true)); break; case MotionEvent.ACTION_POINTER_DOWN: platform.touch().onTouchMove(touches); platform.pointer().onPointerDrag( new Pointer.Event.Impl(flags, time, pointerEvent.x(), pointerEvent.y(), true)); break; case MotionEvent.ACTION_CANCEL: platform.touch().onTouchCancel(touches); platform.pointer().onPointerCancel( new Pointer.Event.Impl(flags, time, pointerEvent.x(), pointerEvent.y(), true)); break;
platform.touch().onTouchStart(touches); platform.pointer().onPointerStart( new Pointer.Event.Impl(flags, time, pointerEvent.x(), pointerEvent.y(), true)); break; case MotionEvent.ACTION_UP: platform.touch().onTouchEnd(touches); platform.pointer().onPointerEnd( new Pointer.Event.Impl(flags, time, pointerEvent.x(), pointerEvent.y(), true)); break; case MotionEvent.ACTION_POINTER_DOWN: platform.touch().onTouchMove(touches); platform.pointer().onPointerDrag( new Pointer.Event.Impl(flags, time, pointerEvent.x(), pointerEvent.y(), true)); break; case MotionEvent.ACTION_CANCEL: platform.touch().onTouchCancel(touches); platform.pointer().onPointerCancel( new Pointer.Event.Impl(flags, time, pointerEvent.x(), pointerEvent.y(), true)); break;
private Touch.Event[] toTouchEvents (Touch.Event.Kind kind, NativeEvent nevent) { // Convert the JsArray<Native Touch> to an array of Touch.Events JsArray<com.google.gwt.dom.client.Touch> nativeTouches = nevent.getChangedTouches(); int nativeTouchesLen = nativeTouches.length(); Touch.Event[] touches = new Touch.Event[nativeTouchesLen]; double time = plat.time(); for (int t = 0; t < nativeTouchesLen; t++) { com.google.gwt.dom.client.Touch touch = nativeTouches.get(t); float x = touch.getRelativeX(rootElement); float y = touch.getRelativeY(rootElement); Point xy = plat.graphics().transformMouse(x, y); int id = getTouchIdentifier(nevent, t); touches[t] = new Touch.Event(0, time, xy.x, xy.y, kind, id); } return touches; }
private Touch.Event[] toTouchEvents (Touch.Event.Kind kind, NativeEvent nevent) { // Convert the JsArray<Native Touch> to an array of Touch.Events JsArray<com.google.gwt.dom.client.Touch> nativeTouches = nevent.getChangedTouches(); int nativeTouchesLen = nativeTouches.length(); Touch.Event[] touches = new Touch.Event[nativeTouchesLen]; double time = plat.time(); for (int t = 0; t < nativeTouchesLen; t++) { com.google.gwt.dom.client.Touch touch = nativeTouches.get(t); float x = touch.getRelativeX(rootElement); float y = touch.getRelativeY(rootElement); Point xy = plat.graphics().transformMouse(x, y); int id = getTouchIdentifier(nevent, t); touches[t] = new Touch.Event(0, time, xy.x, xy.y, kind, id); } return touches; }
private Touch.Event[] toEvents (NSSet<UITouch> touches, UIEvent event, Touch.Event.Kind kind) { final Touch.Event[] events = new Touch.Event[touches.size()]; int idx = 0; for (UITouch touch : touches) { CGPoint loc = touch.getLocationInView(touch.getView()); // transform the point based on our current scale IPoint xloc = plat.graphics().transformTouch((float)loc.getX(), (float)loc.getY()); // on iOS the memory address of the UITouch object is the unique id int id = (int)touch.getHandle(); events[idx++] = new Touch.Event(0, touch.getTimestamp() * 1000, xloc.x(), xloc.y(), kind, id); } return events; } }
private void dispatch (Touch.Event[] events, NativeEvent nevent) { if (touchEnabled) { try { plat.dispatchEvent(touchEvents, events); } finally { // TODO: is there a better alternative to being so extravagant? I don't want to go back to // having all touch events share a mutable Flags instance for (Touch.Event event : events) { if (event.isSet(Event.F_PREVENT_DEFAULT)) nevent.preventDefault(); } } } }
private Touch.Event toTouch (double time, float x, float y, Touch.Event.Kind kind, int idoff) { return new Touch.Event(0, time, x, y, kind, currentId+idoff); } }
private void dispatch (Touch.Event[] events, NativeEvent nevent) { if (touchEnabled) { try { plat.dispatchEvent(touchEvents, events); } finally { // TODO: is there a better alternative to being so extravagant? I don't want to go back to // having all touch events share a mutable Flags instance for (Touch.Event event : events) { if (event.isSet(Event.F_PREVENT_DEFAULT)) nevent.preventDefault(); } } } }
private Touch.Event toTouch (double time, float x, float y, Touch.Event.Kind kind, int idoff) { return new Touch.Event(0, time, x, y, kind, currentId+idoff); } }
@Override public void onStart(Touch.Interaction iact) { Touch.Event event = iact.event; _lstart = label.transform().translation(); _pstart = new Vector(event.x(), event.y()); label.setAlpha(0.5f); modify(event); logger.log(describe(event, "touch start")); } @Override public void onMove(Touch.Interaction iact) {
protected void clearTouches(Touch.Event[] touches) { for (Touch.Event event : touches) _active.remove(event.id()); } protected Set<Integer> _active = new HashSet<Integer>();