Example #1
0
 public override void addAllowedPointer(PointerDownEvent evt)
 {
     startTrackingPointer(evt.pointer, evt.transform);
     _velocityTrackers[evt.pointer] = new VelocityTracker();
     if (_state == _DragState.ready)
     {
         _state                     = _DragState.possible;
         _initialPosition           = new OffsetPair(global: evt.position, local: evt.localPosition);
         _pendingDragOffset         = OffsetPair.zero;
         _globalDistanceMoved       = 0f;
         _lastPendingEventTimestamp = evt.timeStamp;
         _lastTransform             = evt.transform;
         if (onDown != null)
         {
             invokeCallback <object>("onDown",
                                     () => {
                 onDown(new DragDownDetails(
                            globalPosition: _initialPosition.global,
                            localPosition: _initialPosition.local));
                 return(null);
             });
         }
     }
     else if (_state == _DragState.accepted)
     {
         resolve(GestureDisposition.accepted);
     }
 }
Example #2
0
 void handleEvent(PointerEvent evt)
 {
     D.assert(evt.pointer == this.pointer);
     if (evt is PointerMoveEvent)
     {
         if (!this.isWithinGlobalTolerance(evt, Constants.kTouchSlop))
         {
             this.cancel();
         }
         else
         {
             this._lastPosition = OffsetPair.fromEventPosition(evt);
         }
     }
     else if (evt is PointerCancelEvent)
     {
         this.cancel();
     }
     else if (evt is PointerUpEvent)
     {
         this.stopTrackingPointer(this.handleEvent);
         this._finalPosition = OffsetPair.fromEventPosition(evt);
         this._check();
     }
 }
Example #3
0
        protected override void handlePrimaryPointer(PointerEvent evt)
        {
            if (evt is PointerUpEvent)
            {
                _up            = (PointerUpEvent)evt;
                _finalPosition = new OffsetPair(global: evt.position, local: evt.localPosition);

                _checkUp();
            }
            else if (evt is PointerCancelEvent)
            {
                resolve(GestureDisposition.rejected);
                if (_sentTapDown)
                {
                    _checkCancel((PointerCancelEvent)evt, "");
                }

                _reset();
            }
            else if (evt.buttons != _down?.buttons)
            {
                resolve(GestureDisposition.rejected);
                stopTrackingPointer(primaryPointer);
            }
        }
Example #4
0
 public void _dispatchLongTap(int pointer, OffsetPair lastPosition)
 {
     D.assert(this._gestureMap.ContainsKey(pointer));
     if (this.onLongTapDown != null)
     {
         this.invokeCallback <object>("onLongTapDown",
                                      () => {
             this.onLongTapDown(pointer, new TapDownDetails(
                                    globalPosition: lastPosition.global,
                                    localPosition: lastPosition.local));
             return(null);
         });
     }
 }
 public override void addAllowedPointer(PointerDownEvent evt)
 {
     startTrackingPointer(evt.pointer, evt.transform);
     if (state == GestureRecognizerState.ready)
     {
         state           = GestureRecognizerState.possible;
         primaryPointer  = evt.pointer;
         initialPosition = new OffsetPair(local: evt.localPosition, global: evt.position);
         if (deadline != null)
         {
             _timer = Timer.create(deadline.Value, () => didExceedDeadlineWithEvent(evt));
         }
     }
 }
Example #6
0
 public override void addAllowedPointer(PointerDownEvent evt)
 {
     this.startTrackingPointer(evt.pointer, evt.transform);
     if (this.state == GestureRecognizerState.ready)
     {
         this.state           = GestureRecognizerState.possible;
         this.primaryPointer  = evt.pointer;
         this.initialPosition = new OffsetPair(local: evt.localPosition, global: evt.position);
         if (this.deadline != null)
         {
             this._timer = Window.instance.run(this.deadline.Value, () => didExceedDeadlineWithEvent(evt));
         }
     }
 }
Example #7
0
        protected override void handlePrimaryPointer(PointerEvent evt)
        {
            if (evt is PointerUpEvent)
            {
                if (this._longPressAccepted)
                {
                    if (this.onLongPressUp != null)
                    {
                        this.invokeCallback <object>("onLongPressUp", () => {
                            this.onLongPressUp();
                            return(null);
                        });
                    }

                    if (this.onLongPressEnd != null)
                    {
                        this.invokeCallback <object>("onLongPressEnd", () => {
                            this.onLongPressEnd(new LongPressEndDetails(
                                                    globalPosition: evt.position,
                                                    localPosition: evt.localPosition));
                            return(null);
                        });
                    }

                    this._longPressAccepted = true;
                }
                else
                {
                    this.resolve(GestureDisposition.rejected);
                }
            }
            else if (evt is PointerDownEvent || evt is PointerCancelEvent)
            {
                this._longPressAccepted = false;
                this._longPressOrigin   = OffsetPair.fromEventPosition(evt);
            }
            else if (evt is PointerMoveEvent && this._longPressAccepted && this.onLongPressMoveUpdate != null)
            {
                this.invokeCallback <object>("onLongPressMoveUpdate", () => {
                    this.onLongPressMoveUpdate(new LongPressMoveUpdateDetails(
                                                   globalPosition: evt.position,
                                                   localPosition: evt.localPosition,
                                                   offsetFromOrigin: evt.position - this._longPressOrigin.global,
                                                   localOffsetFromOrigin: evt.localPosition - this._longPressOrigin.local
                                                   ));
                    return(null);
                });
            }
        }
 public override void addAllowedPointer(PointerDownEvent Event)
 {
     if (!(Event is PointerUpEvent) && Event.pressureMax <= 1.0f)
     {
         resolve(GestureDisposition.rejected);
     }
     else
     {
         startTrackingPointer(Event.pointer, Event.transform);
         if (_state == _ForceState.ready)
         {
             _state        = _ForceState.possible;
             _lastPosition = OffsetPair.fromEventPosition(Event);
         }
     }
 }
Example #9
0
 public override void addScrollPointer(PointerScrollEvent evt)
 {
     startTrackingScrollerPointer(evt.pointer);
     if (_state == _DragState.ready)
     {
         _state           = _DragState.possible;
         _initialPosition = new OffsetPair(global: evt.position, local: evt.localPosition);
         if (onStart != null)
         {
             invokeCallback <object>("onStart", () => {
                 onStart(new DragStartDetails(
                             sourceTimeStamp: evt.timeStamp,
                             globalPosition: _initialPosition.global,
                             localPosition: _initialPosition.local
                             ));
                 return(null);
             });
         }
     }
 }
Example #10
0
        public void _dispatchTap(int pointer, OffsetPair position)
        {
            D.assert(this._gestureMap.ContainsKey(pointer));
            this._gestureMap.Remove(pointer);
            if (this.onTapUp != null)
            {
                this.invokeCallback <object>("onTapUp",
                                             () => {
                    this.onTapUp(pointer, new TapUpDetails(globalPosition: position.global, localPosition: position.local));
                    return(null);
                });
            }

            if (this.onTap != null)
            {
                this.invokeCallback <object>("onTap", () => {
                    this.onTap(pointer);
                    return(null);
                });
            }
        }
Example #11
0
 public _TapGesture(
     MultiTapGestureRecognizer gestureRecognizer,
     PointerEvent evt,
     TimeSpan longTapDelay
     ) : base(
         evt: (PointerDownEvent)evt,
         entry: GestureBinding.instance.gestureArena.add(evt.pointer, gestureRecognizer),
         doubleTapMinTime: Constants.kDoubleTapMinTime
         )
 {
     this.gestureRecognizer = gestureRecognizer;
     this._lastPosition     = OffsetPair.fromEventPosition(evt);
     this.startTrackingPointer(this.handleEvent, evt.transform);
     if (longTapDelay > TimeSpan.Zero)
     {
         this._timer = Window.instance.run(longTapDelay, () => {
             this._timer = null;
             this.gestureRecognizer._dispatchLongTap(evt.pointer, this._lastPosition);
         });
     }
 }
Example #12
0
        public override void acceptGesture(int pointer)
        {
            if (_state != _DragState.accepted)
            {
                _state = _DragState.accepted;
                OffsetPair delta     = _pendingDragOffset;
                var        timestamp = _lastPendingEventTimestamp;
                Matrix4    transform = _lastTransform;

                Offset localUpdateDelta = null;
                switch (dragStartBehavior)
                {
                case DragStartBehavior.start:
                    _initialPosition = _initialPosition + delta;
                    localUpdateDelta = Offset.zero;
                    break;

                case DragStartBehavior.down:
                    localUpdateDelta = _getDeltaForDetails(delta.local);
                    break;
                }

                D.assert(localUpdateDelta != null);

                _pendingDragOffset         = OffsetPair.zero;
                _lastPendingEventTimestamp = default(TimeSpan);
                _lastTransform             = null;
                if (onStart != null)
                {
                    invokeCallback <object>("onStart", () => {
                        onStart(new DragStartDetails(
                                    sourceTimeStamp: timestamp,
                                    globalPosition: _initialPosition.global,
                                    localPosition: _initialPosition.local
                                    ));
                        return(null);
                    });
                }

                if (localUpdateDelta != Offset.zero && onUpdate != null)
                {
                    Matrix4 localToGlobal = transform != null?Matrix4.tryInvert(transform) : null;

                    Offset correctedLocalPosition = _initialPosition.local + localUpdateDelta;
                    Offset globalUpdateDelta      = PointerEvent.transformDeltaViaPositions(
                        untransformedEndPosition: correctedLocalPosition,
                        untransformedDelta: localUpdateDelta,
                        transform: localToGlobal
                        );
                    OffsetPair updateDelta       = new OffsetPair(local: localUpdateDelta, global: globalUpdateDelta);
                    OffsetPair correctedPosition = _initialPosition + updateDelta; // Only adds delta for down behaviour
                    invokeCallback <object>("onUpdate", () => {
                        onUpdate(new DragUpdateDetails(
                                     sourceTimeStamp: timestamp,
                                     delta: localUpdateDelta,
                                     primaryDelta: _getPrimaryValueFromOffset(localUpdateDelta),
                                     globalPosition: _initialPosition.global,
                                     localPosition: _initialPosition.local
                                     ));
                        return(null);
                    });
                }
            }
        }
Example #13
0
        protected override void handleEvent(PointerEvent evt)
        {
            D.assert(_state != _DragState.ready);
            if (evt is PointerScrollEvent)
            {
                var    scrollEvt = (PointerScrollEvent)evt;
                Offset delta     = scrollEvt.scrollDelta;
                if (onUpdate != null)
                {
                    invokeCallback <object>("onUpdate", () => {
                        onUpdate(new DragUpdateDetails(
                                     sourceTimeStamp: evt.timeStamp,
                                     delta: _getDeltaForDetails(delta),
                                     primaryDelta: _getPrimaryValueFromOffset(delta),
                                     globalPosition: evt.position,
                                     localPosition: evt.localPosition,
                                     isScroll: true
                                     ));
                        return(null);
                    });
                }

                stopTrackingScrollerPointer(evt.pointer);
                return;
            }

            if (!evt.synthesized &&
                (evt is PointerDownEvent || evt is PointerMoveEvent))
            {
                var tracker = _velocityTrackers[evt.pointer];
                D.assert(tracker != null);
                tracker.addPosition(evt.timeStamp, evt.localPosition);
            }

            if (evt is PointerMoveEvent)
            {
                if (_state == _DragState.accepted)
                {
                    if (onUpdate != null)
                    {
                        invokeCallback <object>("onUpdate", () => {
                            onUpdate(new DragUpdateDetails(
                                         sourceTimeStamp: evt.timeStamp,
                                         delta: _getDeltaForDetails(evt.localDelta),
                                         primaryDelta: _getPrimaryValueFromOffset(evt.localDelta),
                                         globalPosition: evt.position,
                                         localPosition: evt.localPosition
                                         ));
                            return(null);
                        });
                    }
                }
                else
                {
                    _pendingDragOffset        += new OffsetPair(local: evt.localDelta, global: evt.delta);
                    _lastPendingEventTimestamp = evt.timeStamp;
                    _lastTransform             = evt.transform;
                    Offset  movedLocally           = _getDeltaForDetails(evt.localDelta);
                    Matrix4 localToGlobalTransform = evt.transform == null ? null : Matrix4.tryInvert(evt.transform);
                    _globalDistanceMoved += PointerEvent.transformDeltaViaPositions(
                        transform: localToGlobalTransform,
                        untransformedDelta: movedLocally,
                        untransformedEndPosition: evt.localPosition
                        ).distance *(_getPrimaryValueFromOffset(movedLocally) ?? 1).sign();
                    if (_hasSufficientGlobalDistanceToAccept)
                    {
                        resolve(GestureDisposition.accepted);
                    }
                }
            }

            stopTrackingIfPointerNoLongerDown(evt);
        }
        protected override void handleEvent(PointerEvent Event)
        {
            D.assert(_state != _ForceState.ready);
            if (Event is PointerMoveEvent || Event is PointerDownEvent)
            {
                if (Event.pressure > Event.pressureMax || Event.pressure < Event.pressureMin)
                {
                    //debugPrint(
                    UnityEngine.Debug.Log(
                        "The reported device pressure " + Event.pressure.ToString() +
                        " is outside of the device pressure range where: " +
                        Event.pressureMin.ToString() + " <= pressure <= " + Event.pressureMax.ToString()
                        );
                }

                float pressure = interpolation(Event.pressureMin, Event.pressureMax, Event.pressure);
                D.assert((pressure >= 0.0 && pressure <= 1.0) || pressure.isNaN());
                _lastPosition = OffsetPair.fromEventPosition(Event);
                _lastPressure = pressure;
                if (_state == _ForceState.possible)
                {
                    if (pressure > startPressure)
                    {
                        _state = _ForceState.started;
                        resolve(GestureDisposition.accepted);
                    }
                    else if (Event.delta.distanceSquared > 18.0f)
                    {
                        resolve(GestureDisposition.rejected);
                    }
                }

                if (pressure > startPressure && _state == _ForceState.accepted)
                {
                    _state = _ForceState.started;
                    if (onStart != null)
                    {
                        invokeCallback("onStart", () => onStart(
                                           new ForcePressDetails(
                                               pressure: pressure,
                                               globalPosition: _lastPosition.global,
                                               localPosition: _lastPosition.local)));
                    }
                }

                if (onPeak != null && pressure > peakPressure && (_state == _ForceState.started))
                {
                    _state = _ForceState.peaked;
                    if (onPeak != null)
                    {
                        invokeCallback("onPeak", () => onPeak(new ForcePressDetails(
                                                                  pressure: pressure,
                                                                  globalPosition: Event.position,
                                                                  localPosition: Event.localPosition
                                                                  )));
                    }
                }

                if (onUpdate != null && !pressure.isNaN() &&
                    (_state == _ForceState.started || _state == _ForceState.peaked))
                {
                    if (onUpdate != null)
                    {
                        invokeCallback("onUpdate", () => onUpdate(new ForcePressDetails(
                                                                      pressure: pressure,
                                                                      globalPosition: Event.position,
                                                                      localPosition: Event.localPosition
                                                                      )));
                    }
                }
            }

            stopTrackingIfPointerNoLongerDown(Event);
        }