Exemple #1
0
        private void EndTouch(TouchState touch)
        {
            var index = IndexOfTouch(touch);

            if (index < 0)
            {
                return;
            }
            var duration = _activeTouches[index].Duration;

            _activeTouches.RemoveAt(index);
            if (_activeTouches.Count == 0)
            {
                if (_potentialClick)
                {
                    var contact = _environment.Raycast(touch.ScreenPosition);
                    if (duration > AltClickDuration)
                    {
                        ClickCanceled?.Invoke(this, new SimpleInteractionEventArgs(contact));
                        AltClickComplete?.Invoke(this, new SimpleInteractionEventArgs(contact));
                    }
                    else
                    {
                        ClickComplete?.Invoke(this, new SimpleInteractionEventArgs(contact));
                    }

                    _potentialClick = true;
                }
            }
            else if (_activeTouches.Count >= 2)
            {
                UpdateMultitouch();
            }
        }
Exemple #2
0
        private void StartTouch(TouchState touch)
        {
            var index = IndexOfTouch(touch);

            if (index >= 0)
            {
                MoveTouch(touch);
                return;
            }

            _activeTouches.Add(touch);
            if (_activeTouches.Count == 1)
            {
                ProbablyClick?.Invoke(this, new SimpleInteractionEventArgs(_environment.Raycast(touch.ScreenPosition)));
                _potentialClick = true;
            }
            else if (_activeTouches.Count == 2)
            {
                if (_potentialClick)
                {
                    ClickCanceled?.Invoke(this, new SimpleInteractionEventArgs(_environment.Raycast(_activeTouches[0].ScreenPosition)));
                    _potentialClick = false;
                }

                UpdateMultitouch();
            }
        }
Exemple #3
0
        private void MoveTouch(TouchState touch)
        {
            var index = IndexOfTouch(touch);

            if (index < 0)
            {
                return;
            }
            if (_activeTouches.Count == 1)
            {
                var dist    = touch.ScreenPosition - _activeTouches[index].ScreenPosition;
                var contact = _environment.Raycast(touch.ScreenPosition);
                if (_potentialClick)
                {
                    if (dist.LengthSquared < ClickThresholdSquared)
                    {
                        return;
                    }
                    _potentialClick = false;
                    ClickCanceled?.Invoke(this, new SimpleInteractionEventArgs(contact));
                }

                Pan?.Invoke(this, new PanInteractionEventArgs(Move(contact, _activeTouches[index].ScreenPosition), contact));
            }
            else if (_activeTouches.Count >= 2)
            {
                var center = _multitouchCenter;
                var dist   = _panningDistance;
                var angle  = _panningAngle;
                CalculatePanning(out center, out dist, ref angle);
                if (center != _multitouchCenter)
                {
                    var oldContact = _environment.Raycast(_multitouchCenter);
                    var newContact = _environment.Raycast(center);
                    Pan?.Invoke(this, new PanInteractionEventArgs(oldContact, newContact));
                    _multitouchCenter = center;
                }

                if (angle != _panningAngle)
                {
                    var oldContact = _environment.Raycast(_multitouchCenter);
                    Rotate?.Invoke(this, new RotateInteractionEventArgs(oldContact, angle - _panningAngle));
                    _panningAngle = angle;
                }

                if (dist != _panningDistance)
                {
                    var oldContact = _environment.Raycast(_multitouchCenter);
                    Zoom?.Invoke(this, new ZoomInteractionEventArgs(oldContact, dist - _panningDistance));
                    _panningDistance = dist;
                }
            }

            _activeTouches[index].Update(touch);
        }