コード例 #1
0
        private TouchTrackingPoint GetScreenPointerCoordinates(
            int[] screenLocation, MotionEvent motionEvent, int pointerIndex)
        {
            var screenPointerCoords =
                new TouchTrackingPoint(
                    screenLocation[0] + motionEvent.GetX(pointerIndex),
                    screenLocation[1] + motionEvent.GetY(pointerIndex));

            return(screenPointerCoords);
        }
コード例 #2
0
        private void FireEvent(TouchHandler touchEffect, int id, TouchActionType actionType, TouchTrackingPoint pointerLocation, bool isInContact)
        {
            // Get the location of the pointer within the view
            touchEffect._view.GetLocationOnScreen(_twoIntArray);
            double             x     = pointerLocation.X - _twoIntArray[0];
            double             y     = pointerLocation.Y - _twoIntArray[1];
            TouchTrackingPoint point = new TouchTrackingPoint((float)_fromPixels(x), (float)_fromPixels(y));

            // Call the method
            OnTouchAction(touchEffect._view,
                          new TouchActionEventArgs(id, actionType, point, isInContact));
        }
コード例 #3
0
        private void FireEvent(TouchRecognizer recognizer, long id, TouchActionType actionType, UITouch touch, bool isInContact)
        {
            // Convert touch location to Xamarin.Forms Point value
            CGPoint            cgPoint = touch.LocationInView(recognizer.View);
            TouchTrackingPoint xfPoint = new TouchTrackingPoint((float)cgPoint.X, (float)cgPoint.Y);

            // Get the method to call for firing events
            Action <UIView, TouchActionEventArgs> onTouchAction = recognizer._touchHandler.OnTouchAction;

            // Call that method
            onTouchAction(recognizer._view,
                          new TouchActionEventArgs(id, actionType, xfPoint, isInContact));
        }
コード例 #4
0
        private void CheckForBoundaryHop(int id, TouchTrackingPoint pointerLocation)
        {
            TouchHandler touchEffectHit = null;

            foreach (View view in _viewDictionary.Keys)
            {
                // Get the view rectangle
                try
                {
                    view.GetLocationOnScreen(_twoIntArray);
                }
                catch // System.ObjectDisposedException: Cannot access a disposed object.
                {
                    continue;
                }
                TouchTrackingRect viewRect = new TouchTrackingRect(_twoIntArray[0], _twoIntArray[1], view.Width, view.Height);

                if (viewRect.Contains(pointerLocation))
                {
                    touchEffectHit = _viewDictionary[view];
                }
            }

            if (touchEffectHit != _idToTouchHandlerDictionary[id])
            {
                if (_idToTouchHandlerDictionary[id] != null)
                {
                    FireEvent(_idToTouchHandlerDictionary[id], id, TouchActionType.Exited, pointerLocation, true);
                }
                if (touchEffectHit != null)
                {
                    FireEvent(touchEffectHit, id, TouchActionType.Entered, pointerLocation, true);
                }
                _idToTouchHandlerDictionary[id] = touchEffectHit;
            }
        }
コード例 #5
0
 SKPoint ConvertToPixel(TouchTrackingPoint pt)
 {
     return(new SKPoint((float)(canvasView.CanvasSize.Width * pt.X / canvasView.Width),
                        (float)(canvasView.CanvasSize.Height * pt.Y / canvasView.Height)));
 }
コード例 #6
0
        private void OnTouch(object sender, View.TouchEventArgs args)
        {
            // Two object common to all the events
            View        senderView  = sender as View;
            MotionEvent motionEvent = args.Event;

            // Get the pointer index
            int pointerIndex = motionEvent.ActionIndex;

            // Get the id that identifies a finger over the course of its progress
            int id = motionEvent.GetPointerId(pointerIndex);


            senderView.GetLocationOnScreen(_twoIntArray);
            TouchTrackingPoint screenPointerCoords = new TouchTrackingPoint(_twoIntArray[0] + motionEvent.GetX(pointerIndex),
                                                                            _twoIntArray[1] + motionEvent.GetY(pointerIndex));


            // Use ActionMasked here rather than Action to reduce the number of possibilities
            switch (args.Event.ActionMasked)
            {
            case MotionEventActions.Down:
            case MotionEventActions.PointerDown:
                FireEvent(this, id, TouchActionType.Pressed, screenPointerCoords, true);

                _idToTouchHandlerDictionary.Add(id, this);

                _capture = Capture;
                break;

            case MotionEventActions.Move:
                // Multiple Move events are bundled, so handle them in a loop
                for (pointerIndex = 0; pointerIndex < motionEvent.PointerCount; pointerIndex++)
                {
                    id = motionEvent.GetPointerId(pointerIndex);

                    if (_capture)
                    {
                        senderView.GetLocationOnScreen(_twoIntArray);

                        screenPointerCoords = new TouchTrackingPoint(_twoIntArray[0] + motionEvent.GetX(pointerIndex),
                                                                     _twoIntArray[1] + motionEvent.GetY(pointerIndex));

                        FireEvent(this, id, TouchActionType.Moved, screenPointerCoords, true);
                    }
                    else
                    {
                        CheckForBoundaryHop(id, screenPointerCoords);

                        if (_idToTouchHandlerDictionary[id] != null)
                        {
                            FireEvent(_idToTouchHandlerDictionary[id], id, TouchActionType.Moved, screenPointerCoords, true);
                        }
                    }
                }
                break;

            case MotionEventActions.Up:
            case MotionEventActions.Pointer1Up:
                if (_capture)
                {
                    FireEvent(this, id, TouchActionType.Released, screenPointerCoords, false);
                }
                else
                {
                    CheckForBoundaryHop(id, screenPointerCoords);

                    if (_idToTouchHandlerDictionary[id] != null)
                    {
                        FireEvent(_idToTouchHandlerDictionary[id], id, TouchActionType.Released, screenPointerCoords, false);
                    }
                }
                _idToTouchHandlerDictionary.Remove(id);
                break;

            case MotionEventActions.Cancel:
                if (_capture)
                {
                    FireEvent(this, id, TouchActionType.Cancelled, screenPointerCoords, false);
                }
                else
                {
                    if (_idToTouchHandlerDictionary[id] != null)
                    {
                        FireEvent(_idToTouchHandlerDictionary[id], id, TouchActionType.Cancelled, screenPointerCoords, false);
                    }
                }
                _idToTouchHandlerDictionary.Remove(id);
                break;
            }
        }
コード例 #7
0
 public bool Contains(TouchTrackingPoint point)
 {
     return(Contains(point.X, point.Y));
 }
コード例 #8
0
        private void OnTouch(object sender, View.TouchEventArgs args)
        {
            // Two object common to all the events
            View        senderView  = sender as View;
            MotionEvent motionEvent = args.Event;

            // Get the pointer index
            int pointerIndex = motionEvent.ActionIndex;

            // Get the id that identifies a finger over the course of its progress
            int id = motionEvent.GetPointerId(pointerIndex);

            senderView.GetLocationOnScreen(_locationOnScreen);
            TouchTrackingPoint screenPointerCoords =
                GetScreenPointerCoordinates(_locationOnScreen, motionEvent, pointerIndex);


            // Use ActionMasked here rather than Action to reduce the number of possibilities
            switch (args.Event.ActionMasked)
            {
            case MotionEventActions.Down:
            case MotionEventActions.PointerDown:
                FireEvent(this, id, TouchActionType.Pressed, screenPointerCoords, true);

                _idToTouchHandlerDictionary.Add(id, this);

                _capture = Capture;

                if (UseTouchSlop)
                {
                    _lastX = args.Event.GetX();
                    _lastY = args.Event.GetY();
                }
                break;

            case MotionEventActions.Move:
                if (motionEvent.PointerCount == 1 && UseTouchSlop)
                {
                    id = motionEvent.GetPointerId(0);
                    senderView.GetLocationOnScreen(_locationOnScreen);

                    if (!_moveInProgress)
                    {
                        var x = args.Event.GetX();
                        var y = args.Event.GetY();

                        var xDiff = Math.Abs(_lastX - x);
                        var yDiff = Math.Abs(_lastY - y);

                        if (xDiff > _slop || yDiff > _slop)
                        {
                            _moveInProgress = true;
                        }
                    }

                    if (_moveInProgress)
                    {
                        screenPointerCoords = GetScreenPointerCoordinates(_locationOnScreen, motionEvent, pointerIndex);
                        FireEvent(this, id, TouchActionType.Moved, screenPointerCoords, true);
                    }

                    break;
                }

                _moveInProgress = false;
                _lastX          = 0;
                _lastY          = 0;

                // Multiple Move events are bundled, so handle them in a loop
                for (pointerIndex = 0; pointerIndex < motionEvent.PointerCount; pointerIndex++)
                {
                    id = motionEvent.GetPointerId(pointerIndex);

                    if (_capture)
                    {
                        senderView.GetLocationOnScreen(_locationOnScreen);

                        screenPointerCoords = GetScreenPointerCoordinates(_locationOnScreen, motionEvent, pointerIndex);
                        FireEvent(this, id, TouchActionType.Moved, screenPointerCoords, true);
                    }
                    else
                    {
                        CheckForBoundaryHop(id, screenPointerCoords);

                        if (_idToTouchHandlerDictionary[id] != null)
                        {
                            FireEvent(_idToTouchHandlerDictionary[id], id, TouchActionType.Moved, screenPointerCoords, true);
                        }
                    }
                }
                break;

            case MotionEventActions.Up:
            case MotionEventActions.Pointer1Up:
                if (_capture)
                {
                    FireEvent(this, id, TouchActionType.Released, screenPointerCoords, false);
                }
                else
                {
                    CheckForBoundaryHop(id, screenPointerCoords);

                    if (_idToTouchHandlerDictionary[id] != null)
                    {
                        FireEvent(_idToTouchHandlerDictionary[id], id, TouchActionType.Released, screenPointerCoords, false);
                    }
                }
                _idToTouchHandlerDictionary.Remove(id);

                _moveInProgress = false;
                _lastX          = 0;
                _lastY          = 0;
                break;

            case MotionEventActions.Cancel:
                if (_capture)
                {
                    FireEvent(this, id, TouchActionType.Cancelled, screenPointerCoords, false);
                }
                else
                {
                    if (_idToTouchHandlerDictionary[id] != null)
                    {
                        FireEvent(_idToTouchHandlerDictionary[id], id, TouchActionType.Cancelled, screenPointerCoords, false);
                    }
                }
                _idToTouchHandlerDictionary.Remove(id);

                _moveInProgress = false;
                _lastX          = 0;
                _lastY          = 0;
                break;
            }
        }