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
        public override void acceptGesture(int pointer)
        {
            if (this._state != _DragState.accepted)
            {
                this._state = _DragState.accepted;
                Offset delta     = this._pendingDragOffset;
                var    timestamp = this._lastPendingEventTimestamp;
                this._pendingDragOffset         = Offset.zero;
                this._lastPendingEventTimestamp = default(TimeSpan);
                if (this.onStart != null)
                {
                    this.invokeCallback <object>("onStart", () => {
                        this.onStart(new DragStartDetails(
                                         sourceTimeStamp: timestamp,
                                         globalPosition: this._initialPosition
                                         ));
                        return(null);
                    });
                }

                if (delta != Offset.zero && this.onUpdate != null)
                {
                    this.invokeCallback <object>("onUpdate", () => {
                        this.onUpdate(new DragUpdateDetails(
                                          sourceTimeStamp: timestamp,
                                          delta: this._getDeltaForDetails(delta),
                                          primaryDelta: this._getPrimaryValueFromOffset(delta),
                                          globalPosition: this._initialPosition
                                          ));
                        return(null);
                    });
                }
            }
        }
Example #3
0
        protected override void didStopTrackingLastPointer(int pointer)
        {
            if (_state == _DragState.possible)
            {
                resolve(GestureDisposition.rejected);
                _state = _DragState.ready;
                if (onCancel != null)
                {
                    invokeCallback <object>("onCancel", () => {
                        onCancel();
                        return(null);
                    });
                }

                return;
            }

            bool wasAccepted = _state == _DragState.accepted;

            _state = _DragState.ready;
            if (wasAccepted && onEnd != null)
            {
                var tracker = _velocityTrackers[pointer];
                D.assert(tracker != null);

                var estimate = tracker.getVelocityEstimate();
                if (estimate != null && _isFlingGesture(estimate))
                {
                    Velocity velocity = new Velocity(pixelsPerSecond: estimate.pixelsPerSecond)
                                        .clampMagnitude(minFlingVelocity ?? Constants.kMinFlingVelocity,
                                                        maxFlingVelocity ?? Constants.kMaxFlingVelocity);
                    invokeCallback <object>("onEnd", () => {
                        onEnd(new DragEndDetails(
                                  velocity: velocity,
                                  primaryVelocity: _getPrimaryValueFromOffset(velocity.pixelsPerSecond)
                                  ));
                        return(null);
                    }, debugReport: () =>
                                            $"{estimate}; fling at {velocity}.");
                }
                else
                {
                    invokeCallback <object>("onEnd", () => {
                        onEnd(new DragEndDetails(
                                  velocity: Velocity.zero,
                                  primaryVelocity: 0.0f
                                  ));
                        return(null);
                    }, debugReport: () =>
                                            estimate == null
                                ? "Could not estimate velocity."
                                : estimate + "; judged to not be a fling."
                                            );
                }
            }

            _velocityTrackers.Clear();
        }
Example #4
0
 protected override void didStopTrackingLastScrollerPointer(int pointer)
 {
     _state = _DragState.ready;
     invokeCallback <object>("onEnd", () => {
         onEnd(new DragEndDetails(
                   velocity: Velocity.zero,
                   primaryVelocity: 0.0f
                   ));
         return(null);
     }, debugReport: () => { return("Pointer scroll end"); }
                             );
 }
Example #5
0
        public override void acceptGesture(int pointer)
        {
            if (this._state != _DragState.accepted)
            {
                this._state = _DragState.accepted;
                Offset delta     = this._pendingDragOffset;
                var    timestamp = this._lastPendingEventTimestamp;

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

                case DragStartBehavior.down:
                    updateDelta = this._getDeltaForDetails(delta);
                    break;
                }

                D.assert(updateDelta != null);

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

                if (updateDelta != Offset.zero && this.onUpdate != null)
                {
                    this.invokeCallback <object>("onUpdate", () => {
                        this.onUpdate(new DragUpdateDetails(
                                          sourceTimeStamp: timestamp,
                                          delta: updateDelta,
                                          primaryDelta: this._getPrimaryValueFromOffset(updateDelta),
                                          globalPosition: this._initialPosition + updateDelta
                                          ));
                        return(null);
                    });
                }
            }
        }
Example #6
0
 public override void addScrollPointer(PointerScrollEvent evt)
 {
     this.startTrackingScrollerPointer(evt.pointer);
     if (this._state == _DragState.ready)
     {
         this._state           = _DragState.possible;
         this._initialPosition = evt.position;
         if (this.onStart != null)
         {
             this.invokeCallback <object>("onStart", () => {
                 this.onStart(new DragStartDetails(
                                  sourceTimeStamp: evt.timeStamp,
                                  globalPosition: this._initialPosition
                                  ));
                 return(null);
             });
         }
     }
 }
Example #7
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 #8
0
 public override void addAllowedPointer(PointerDownEvent evt)
 {
     this.startTrackingPointer(evt.pointer);
     this._velocityTrackers[evt.pointer] = new VelocityTracker();
     if (this._state == _DragState.ready)
     {
         this._state                     = _DragState.possible;
         this._initialPosition           = evt.position;
         this._pendingDragOffset         = Offset.zero;
         this._lastPendingEventTimestamp = evt.timeStamp;
         if (this.onDown != null)
         {
             this.invokeCallback <object>("onDown",
                                          () => {
                 this.onDown(new DragDownDetails(globalPosition: this._initialPosition));
                 return(null);
             });
         }
     }
     else if (this._state == _DragState.accepted)
     {
         this.resolve(GestureDisposition.accepted);
     }
 }
Example #9
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 #10
0
        protected override void handleEvent(PointerEvent evt)
        {
            D.assert(this._state != _DragState.ready);
            if (evt is PointerScrollEvent)
            {
                Offset delta = evt.delta;
                if (this.onUpdate != null)
                {
                    this.invokeCallback <object>("onUpdate", () => {
                        this.onUpdate(new DragUpdateDetails(
                                          sourceTimeStamp: evt.timeStamp,
                                          delta: this._getDeltaForDetails(delta),
                                          primaryDelta: this._getPrimaryValueFromOffset(delta),
                                          globalPosition: evt.position,
                                          isScroll: true
                                          ));
                        return(null);
                    });
                }

                this.invokeCallback <object>("onEnd", () => {
                    this.onEnd(new DragEndDetails(
                                   velocity: Velocity.zero,
                                   primaryVelocity: 0.0f
                                   ));
                    return(null);
                }, debugReport: () => { return("Pointer scroll end"); }
                                             );


                this._state = _DragState.ready;
                return;
            }

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

            if (evt is PointerMoveEvent)
            {
                Offset delta = evt.delta;
                if (this._state == _DragState.accepted)
                {
                    if (this.onUpdate != null)
                    {
                        this.invokeCallback <object>("onUpdate", () => {
                            this.onUpdate(new DragUpdateDetails(
                                              sourceTimeStamp: evt.timeStamp,
                                              delta: this._getDeltaForDetails(delta),
                                              primaryDelta: this._getPrimaryValueFromOffset(delta),
                                              globalPosition: evt.position
                                              ));
                            return(null);
                        });
                    }
                }
                else
                {
                    this._pendingDragOffset        += delta;
                    this._lastPendingEventTimestamp = evt.timeStamp;
                    if (this._hasSufficientPendingDragDeltaToAccept)
                    {
                        this.resolve(GestureDisposition.accepted);
                    }
                }
            }

            this.stopTrackingIfPointerNoLongerDown(evt);
        }