Beispiel #1
0
 void _dispatchOnStartCallbackIfNeeded()
 {
     D.assert(_state == _ScaleState.started);
     if (onStart != null)
     {
         invokeCallback <object>("onStart", () => {
             onStart(new ScaleStartDetails(
                         focalPoint: _currentFocalPoint,
                         localFocalPoint: PointerEvent.transformPosition(_lastTransform, _currentFocalPoint)
                         ));
             return(null);
         });
     }
 }
Beispiel #2
0
        void _handlePointerEvent(PointerEvent evt)
        {
            if (evt is PointerScrollEvent)
            {
                this._handlePointerScrollEvent(evt);
                return;
            }

            if (evt is PointerHoverEvent)
            {
                this._handlePointerHoverEvent(evt);
            }

            HitTestResult result;

            if (evt is PointerDownEvent)
            {
                D.assert(!this._hitTests.ContainsKey(evt.pointer));
                result = new HitTestResult();
                this.hitTest(result, evt.position);

                this._hitTests[evt.pointer] = result;
                D.assert(() => {
                    if (D.debugPrintHitTestResults)
                    {
                        Debug.LogFormat("{0}: {1}", evt, result);
                    }

                    return(true);
                });
            }
            else if (evt is PointerUpEvent || evt is PointerCancelEvent)
            {
                result = this._hitTests.getOrDefault(evt.pointer);
                this._hitTests.Remove(evt.pointer);
            }
            else if (evt.down)
            {
                result = this._hitTests.getOrDefault(evt.pointer);
            }
            else
            {
                return;
            }

            if (result != null)
            {
                this.dispatchEvent(evt, result);
            }
        }
Beispiel #3
0
        void _handlePointerScrollEvent(PointerEvent evt)
        {
            this.pointerRouter.clearScrollRoute(evt.pointer);
            if (!this.pointerRouter.acceptScroll())
            {
                return;
            }

            HitTestResult result = new HitTestResult();

            this.hitTest(result, evt.position);

            this.dispatchEvent(evt, result);
        }
Beispiel #4
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);
                });
            }
        }
Beispiel #5
0
        public override void addAllowedPointer(PointerEvent pEvent)
        {
            var _pEvent = (PointerDownEvent)pEvent;

            D.assert(_pEvent != null);
            D.assert(_pointers != null);
            D.assert(_pEvent.position != null);
            D.assert(!_pointers.ContainsKey(_pEvent.pointer));

            T state = createNewPointerState(_pEvent);

            _pointers[_pEvent.pointer] = state;
            GestureBinding.instance.pointerRouter.addRoute(_pEvent.pointer, _handleEvent);
            state._setArenaEntry(GestureBinding.instance.gestureArena.add(_pEvent.pointer, this));
        }
Beispiel #6
0
 public override void addAllowedPointer(PointerEvent 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);
         }
     }
 }
Beispiel #7
0
 public void handleEvent(PointerEvent evt, HitTestEntry entry)
 {
     this.pointerRouter.route(evt);
     if (evt is PointerDownEvent)
     {
         this.gestureArena.close(evt.pointer);
     }
     else if (evt is PointerUpEvent)
     {
         this.gestureArena.sweep(evt.pointer);
     }
     else if (evt is PointerSignalEvent)
     {
         this.pointerSignalResolver.resolve((PointerSignalEvent)evt);
     }
 }
Beispiel #8
0
 public void _dispatchEventToRoutes(
     PointerEvent evt,
     Dictionary <PointerRoute, Matrix4> referenceRoutes,
     Dictionary <PointerRoute, Matrix4> copiedRoutes
     )
 {
     foreach (var item in copiedRoutes)
     {
         var route     = item.Key;
         var transform = item.Value;
         if (referenceRoutes.ContainsKey(route))
         {
             _dispatch(evt, route, transform);
         }
     }
 }
Beispiel #9
0
        public override void addAllowedPointer(PointerEvent evt)
        {
            var _evt = (PointerDownEvent)evt;

            D.assert(_evt != null);
            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));
                }
            }
        }
Beispiel #10
0
 public override void addAllowedPointer(PointerEvent evt)
 {
     startTrackingPointer(evt.pointer, evt.transform);
     _velocityTrackers[evt.pointer] = new VelocityTracker();
     if (_state == _ScaleState.ready)
     {
         _state                 = _ScaleState.possible;
         _initialSpan           = 0.0f;
         _currentSpan           = 0.0f;
         _initialHorizontalSpan = 0.0f;
         _currentHorizontalSpan = 0.0f;
         _initialVerticalSpan   = 0.0f;
         _currentVerticalSpan   = 0.0f;
         _pointerLocations      = new Dictionary <int, Offset>();
         _pointerQueue          = new List <int>();
     }
 }
Beispiel #11
0
        protected override void handleEvent(PointerEvent evt)
        {
            D.assert(_state != _ScaleState.ready);
            bool didChangeConfiguration = false;
            bool shouldStartIfAccepted  = false;

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

                _pointerLocations[evt.pointer] = evt.position;
                shouldStartIfAccepted          = true;
                _lastTransform = evt.transform;
            }
            else if (evt is PointerDownEvent)
            {
                _pointerLocations[evt.pointer] = evt.position;
                _pointerQueue.Add(evt.pointer);
                didChangeConfiguration = true;
                shouldStartIfAccepted  = true;
                _lastTransform         = evt.transform;
            }
            else if (evt is PointerUpEvent || evt is PointerCancelEvent)
            {
                _pointerLocations.Remove(evt.pointer);
                _pointerQueue.Remove(evt.pointer);
                didChangeConfiguration = true;
                _lastTransform         = evt.transform;
            }

            _updateLines();
            _update();

            if (!didChangeConfiguration || _reconfigure(evt.pointer))
            {
                _advanceStateMachine(shouldStartIfAccepted);
            }

            stopTrackingIfPointerNoLongerDown(evt);
        }
Beispiel #12
0
        protected override void handleEvent(PointerEvent evt)
        {
            D.assert(this.state != GestureRecognizerState.ready);
            if (this.state == GestureRecognizerState.possible && evt.pointer == this.primaryPointer)
            {
                if (evt is PointerMoveEvent && this._getDistance(evt) > Constants.kTouchSlop)
                {
                    this.resolve(GestureDisposition.rejected);
                    this.stopTrackingPointer(this.primaryPointer);
                }
                else
                {
                    this.handlePrimaryPointer(evt);
                }
            }

            this.stopTrackingIfPointerNoLongerDown(evt);
        }
Beispiel #13
0
 public override void addAllowedPointer(PointerEvent evt)
 {
     D.assert(!_gestureMap.ContainsKey(evt.pointer));
     _gestureMap[evt.pointer] = new _TapGesture(
         gestureRecognizer: this,
         evt: evt,
         longTapDelay: longTapDelay
         );
     if (onTapDown != null)
     {
         invokeCallback <object>("onTapDown", () => {
             onTapDown(evt.pointer, new TapDownDetails(globalPosition: evt.position,
                                                       localPosition: evt.localPosition,
                                                       kind: evt.kind
                                                       ));
             return(null);
         });
     }
 }
Beispiel #14
0
        public void route(PointerEvent evt)
        {
            // TODO: update this to latest version
            Dictionary <PointerRoute, Matrix4> routes;

            this._routeMap.TryGetValue(evt.pointer, out routes);

            Dictionary <PointerRoute, Matrix4> copiedGlobalRoutes = new Dictionary <PointerRoute, Matrix4>(this._globalRoutes);

            if (routes != null)
            {
                this._dispatchEventToRoutes(
                    evt,
                    routes,
                    new Dictionary <PointerRoute, Matrix4>(routes)
                    );
            }
            this._dispatchEventToRoutes(evt, this._globalRoutes, copiedGlobalRoutes);
        }
Beispiel #15
0
        void _handlePointerHoverEvent(PointerEvent evt)
        {
            HitTestResult result = new HitTestResult();

            this.hitTest(result, evt.position);

            // enter event
            foreach (var hitTestEntry in result.path)
            {
                if (this.lastMoveTargets.Contains(hitTestEntry.target))
                {
                    hitTestEntry.target.handleEvent(evt, hitTestEntry);
                    this.lastMoveTargets.Remove(hitTestEntry.target);
                }
                else
                {
                    hitTestEntry.target.handleEvent(new PointerEnterEvent(
                                                        timeStamp: evt.timeStamp,
                                                        pointer: evt.pointer,
                                                        device: evt.device,
                                                        kind: evt.kind
                                                        ), hitTestEntry);
                }
            }

            foreach (var lastMoveTarget in this.lastMoveTargets)
            {
                lastMoveTarget.handleEvent(new PointerLeaveEvent(
                                               timeStamp: evt.timeStamp,
                                               pointer: evt.pointer,
                                               device: evt.device,
                                               kind: evt.kind
                                               ), null);
            }

            this.lastMoveTargets.Clear();
            foreach (var hitTestEntry in result.path)
            {
                this.lastMoveTargets.Add(hitTestEntry.target);
            }

            this.dispatchEvent(evt, result);
        }
Beispiel #16
0
        // Handler for events coming from the PointerRouter.
        void _handleEvent(PointerEvent evt)
        {
            if (evt.kind != PointerDeviceKind.mouse)
            {
                return;
            }

            int deviceId = evt.device;

            if (this._trackedAnnotations.isEmpty())
            {
                // If we are adding the device again, then we're not removing it anymore.
                this._lastMouseEvent.Remove(deviceId);
                return;
            }

            if (evt is PointerRemovedEvent)
            {
                this._lastMouseEvent.Remove(deviceId);
                // If the mouse was removed, then we need to schedule one more check to
                // exit any annotations that were active.
                this._scheduleMousePositionCheck();
            }
            else
            {
                if (evt is PointerMoveEvent ||
                    evt is PointerHoverEvent ||
                    evt is PointerDownEvent)
                {
                    if (!this._lastMouseEvent.ContainsKey(deviceId) ||
                        this._lastMouseEvent[deviceId].position != evt.position)
                    {
                        this._scheduleMousePositionCheck();
                    }

                    this._lastMouseEvent[deviceId] = evt;
                }
            }

#if UNITY_EDITOR
            this._handleDragFromEditorEvent(evt, deviceId);
#endif
        }
Beispiel #17
0
        void _advanceStateMachine(bool shouldStartIfAccepted)
        {
            if (_state == _ScaleState.ready)
            {
                _state = _ScaleState.possible;
            }

            if (_state == _ScaleState.possible)
            {
                float spanDelta       = (_currentSpan - _initialSpan).abs();
                float focalPointDelta = (_currentFocalPoint - _initialFocalPoint).distance;
                if (spanDelta > Constants.kScaleSlop || focalPointDelta > Constants.kPanSlop)
                {
                    resolve(GestureDisposition.accepted);
                }
            }
            else if (_state >= _ScaleState.accepted)
            {
                resolve(GestureDisposition.accepted);
            }

            if (_state == _ScaleState.accepted && shouldStartIfAccepted)
            {
                _state = _ScaleState.started;
                _dispatchOnStartCallbackIfNeeded();
            }

            if (_state == _ScaleState.started && onUpdate != null)
            {
                invokeCallback <object>("onUpdate", () => {
                    onUpdate(new ScaleUpdateDetails(
                                 scale: _scaleFactor,
                                 horizontalScale: _horizontalScaleFactor,
                                 verticalScale: _verticalScaleFactor,
                                 focalPoint: _currentFocalPoint,
                                 localFocalPoint: PointerEvent.transformPosition(_lastTransform, _currentFocalPoint),
                                 rotation: _computeRotationFactor()
                                 ));
                    return(null);
                });
            }
        }
Beispiel #18
0
        public static bool _shouldMarkStateDirty(_MouseState state, PointerEvent value)
        {
            if (state == null)
            {
                return(true);
            }
            D.assert(value != null);
            PointerEvent lastEvent = state.latestEvent;

            D.assert(value.device == lastEvent.device);

            D.assert((value is PointerAddedEvent) == (lastEvent is PointerRemovedEvent));
            if (value is PointerSignalEvent)
            {
                return(false);
            }
            return(lastEvent is PointerAddedEvent ||
                   value is PointerRemovedEvent ||
                   lastEvent.position != value.position);
        }
Beispiel #19
0
 void _handleEvent(PointerEvent evt) {
     _TapTracker tracker = this._trackers[evt.pointer];
     D.assert(tracker != null);
     if (evt is PointerUpEvent) {
         if (this._firstTap == null) {
             this._registerFirstTap(tracker);
         }
         else {
             this._registerSecondTap(tracker);
         }
     }
     else if (evt is PointerMoveEvent) {
         if (!tracker.isWithinTolerance(evt, Constants.kDoubleTapTouchSlop)) {
             this._reject(tracker);
         }
     }
     else if (evt is PointerCancelEvent) {
         this._reject(tracker);
     }
 }
Beispiel #20
0
        public void dispatchEvent(PointerEvent evt, HitTestResult hitTestResult)
        {
            if (hitTestResult == null)
            {
                D.assert(evt is PointerHoverEvent ||
                         evt is PointerAddedEvent ||
                         evt is PointerRemovedEvent ||
                         evt is PointerDragFromEditorHoverEvent ||
                         evt is PointerDragFromEditorReleaseEvent
                         );
                try {
                    pointerRouter.route(evt);
                }
                catch (Exception ex) {
                    IEnumerable <DiagnosticsNode> infoCollector()
                    {
                        yield return(new DiagnosticsProperty <PointerEvent>("Event", evt, style: DiagnosticsTreeStyle.errorProperty));
                    }

                    UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                                   exception: ex,
                                                   library: "gesture library",
                                                   context: new ErrorDescription("while dispatching a non-hit-tested pointer event"),
                                                   informationCollector: infoCollector
                                                   )
                                               );
                }

                return;
            }

            foreach (HitTestEntry entry in hitTestResult.path)
            {
                try {
                    entry.target.handleEvent(evt.transformed(entry.transform), entry);
                }
                catch (Exception ex) {
                    D.logError("Error while dispatching a pointer event: ", ex);
                }
            }
        }
Beispiel #21
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);
         });
     }
 }
Beispiel #22
0
        protected override void handlePrimaryPointer(PointerEvent evt)
        {
            if (evt is PointerUpEvent)
            {
                this._finalPosition = evt.position;

                if (this._wonArenaForPrimaryPointer)
                {
                    this.resolve(GestureDisposition.accepted);
                    this._checkUp();
                }
            }
            else if (evt is PointerCancelEvent)
            {
                if (this._sentTapDown && this.onTapCancel != null)
                {
                    this.invokeCallback <object>("onTapCancel", () => this.onTapCancel);
                }

                this._reset();
            }
        }
Beispiel #23
0
        public void dispatchEvent(PointerEvent evt, HitTestResult hitTestResult)
        {
            if (hitTestResult == null)
            {
                D.assert(evt is PointerHoverEvent ||
                         evt is PointerAddedEvent ||
                         evt is PointerRemovedEvent ||
                         evt is PointerDragFromEditorHoverEvent ||
                         evt is PointerDragFromEditorReleaseEvent
                         );
                try {
                    this.pointerRouter.route(evt);
                }
                catch (Exception ex) {
                    UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                                   exception: ex,
                                                   library: "gesture library",
                                                   context: "while dispatching a non-hit-tested pointer event",
                                                   informationCollector: information => {
                        information.AppendLine("Event: ");
                        information.AppendFormat(" {0}", evt);
                    }
                                                   )
                                               );
                }

                return;
            }

            foreach (HitTestEntry entry in hitTestResult.path)
            {
                try {
                    entry.target.handleEvent(evt.transformed(entry.transform), entry);
                }
                catch (Exception ex) {
                    D.logError("Error while dispatching a pointer event: ", ex);
                }
            }
        }
Beispiel #24
0
 protected override void handlePrimaryPointer(PointerEvent evt)
 {
     if (evt is PointerUpEvent)
     {
         if (this._longPressAccepted && this.onLongPressUp != null)
         {
             this._longPressAccepted = false;
             this.invokeCallback <object>("onLongPressUp", () => {
                 this.onLongPressUp();
                 return(null);
             });
         }
         else
         {
             this.resolve(GestureDisposition.rejected);
         }
     }
     else if (evt is PointerDownEvent || evt is PointerCancelEvent)
     {
         this._longPressAccepted = false;
     }
 }
Beispiel #25
0
        public override void addAllowedPointer(PointerEvent evt)
        {
            if (_firstTap != null)
            {
                if (!_firstTap.isWithinGlobalTolerance(evt, Constants.kDoubleTapSlop))
                {
                    // Ignore out-of-bounds second taps.
                    return;
                }
                else if (!_firstTap.hasElapsedMinTime() ||
                         !_firstTap.hasSameButton(evt as PointerDownEvent))
                {
                    // Restart when the second tap is too close to the first, or when buttons
                    // mismatch.
                    _reset();
                    _trackFirstTap(evt);
                    return;
                }
            }

            _trackFirstTap(evt);
        }
Beispiel #26
0
 protected override void handlePrimaryPointer(PointerEvent e)
 {
     if (e is PointerUpEvent)
     {
         if (this._longPressAccepted == true && this.onLongPressUp != null)
         {
             this._longPressAccepted = false;
             this.invokeCallback <object>("onLongPressUp", () => {
                 this.onLongPressUp(new GestureLongPressDragUpDetails(
                                        sourceTimeStamp: e.timeStamp,
                                        globalPosition: e.position
                                        ));
                 return(null);
             });
         }
         else
         {
             this.resolve(GestureDisposition.rejected);
         }
     }
     else if (e is PointerDownEvent)
     {
         this._longPressAccepted       = false;
         this._longPressStartTimestamp = e.timeStamp;
         this._longPressOrigin         = e.position;
     }
     else if (e is PointerMoveEvent && this._longPressAccepted && this.onLongPressDragUpdate != null)
     {
         this.invokeCallback <object>("onLongPressDrag", () => {
             this.onLongPressDragUpdate(new GestureLongPressDragUpdateDetails(
                                            sourceTimeStamp: e.timeStamp,
                                            globalPosition: e.position,
                                            offsetFromOrigin: e.position - this._longPressOrigin
                                            ));
             return(null);
         });
     }
 }
Beispiel #27
0
        protected override void handlePrimaryPointer(PointerEvent evt)
        {
            if (evt is PointerUpEvent)
            {
                this._up = (PointerUpEvent)evt;
                this._checkUp();
            }
            else if (evt is PointerCancelEvent)
            {
                this.resolve(GestureDisposition.rejected);
                if (this._sentTapDown)
                {
                    this._checkCancel((PointerCancelEvent)evt, "");
                }

                this._reset();
            }
            else if (evt.buttons != this._down?.buttons)
            {
                this.resolve(GestureDisposition.rejected);
                this.stopTrackingPointer(this.primaryPointer);
            }
        }
Beispiel #28
0
        public void route(PointerEvent evt)
        {
            HashSet <PointerRoute> routes;

            this._routeMap.TryGetValue(evt.pointer, out routes);
            if (routes != null)
            {
                foreach (PointerRoute route in new List <PointerRoute>(routes))
                {
                    if (routes.Contains(route))
                    {
                        this._dispatch(evt, route);
                    }
                }
            }

            foreach (PointerRoute route in new List <PointerRoute>(this._globalRoutes))
            {
                if (this._globalRoutes.Contains(route))
                {
                    this._dispatch(evt, route);
                }
            }
        }
Beispiel #29
0
        void _handleEvent(PointerEvent evt)
        {
            if (evt.kind != PointerDeviceKind.mouse)
            {
                return;
            }

            int deviceId = evt.device;

            if (this._trackedAnnotations.isEmpty())
            {
                this._lastMouseEvent.Remove(deviceId);
                return;
            }

            if (evt is PointerRemovedEvent)
            {
                this._lastMouseEvent.Remove(deviceId);
                this._scheduleMousePositionCheck();
            }
            else
            {
                if (evt is PointerMoveEvent ||
                    evt is PointerHoverEvent ||
                    evt is PointerDownEvent)
                {
                    if (!this._lastMouseEvent.ContainsKey(deviceId) ||
                        this._lastMouseEvent[deviceId].position != evt.position)
                    {
                        this._scheduleMousePositionCheck();
                    }

                    this._lastMouseEvent[deviceId] = evt;
                }
            }
        }
Beispiel #30
0
 public bool isWithinTolerance(PointerEvent evt, float tolerance) {
     Offset offset = evt.position - this._initialPosition;
     return offset.distance <= tolerance;
 }