Esempio n. 1
0
        public void OnGesture(Gesture gesture)
        {
            switch (gesture.GestureType)
            {
            case GestureType.MouseWheel:

                if (_view.IsPointInsideView(gesture.Position))
                {
                    float offset = -gesture.Offset.Y * _wheelSpeed;

                    if (_wheelScrollsHorizontal)
                    {
                        float maxScroll = _service.ScrolledElement.MaxScrollX - _service.ScrolledElement.ScreenBounds.Width;

                        if ((offset < 0 && _service.ScrollPositionX > 0) || (offset > 0 && _service.ScrollPositionX < maxScroll))
                        {
                            _service.ScrollPositionX += offset;
                        }
                    }
                    else
                    {
                        float maxScroll = _service.ScrolledElement.MaxScrollY - _service.ScrolledElement.ScreenBounds.Height;

                        if ((offset < 0 && _service.ScrollPositionY > 0) || (offset > 0 && _service.ScrollPositionY < maxScroll))
                        {
                            _service.ScrollPositionY += offset;
                        }
                    }
                }

                break;

            case GestureType.Up:
                if (_touchIdX == gesture.TouchId)
                {
                    _touchIdX             = 0;
                    _lastMoveTime         = null;
                    _service.ScrollSpeedX = _scrollSpeed.X;
                }

                if (_touchIdY == gesture.TouchId)
                {
                    _touchIdY             = 0;
                    _lastMoveTime         = null;
                    _service.ScrollSpeedY = _scrollSpeed.Y;
                }
                break;

            case GestureType.HorizontalDrag:
            case GestureType.VerticalDrag:
            case GestureType.FreeDrag:

                if (gesture.PointerCapturedBy == null)
                {
                    if (_touchIdX == 0 && _touchIdY == 0)
                    {
                        if (_view.IsPointInsideView(gesture.Origin))
                        {
                            _touchIdX = _touchIdY = gesture.TouchId;
                            gesture.CapturePointer(_view);
                        }
                    }
                }

                if (_touchIdX == gesture.TouchId || _touchIdY == gesture.TouchId)
                {
                    gesture.SetHandled();

                    if (_touchIdX != 0 && _mode.HasFlag(Mode.HorizontalDrag))
                    {
                        _service.ScrollPositionX -= gesture.Offset.X;
                    }

                    if (_touchIdY != 0 && _mode.HasFlag(Mode.VerticalDrag))
                    {
                        _service.ScrollPositionY -= gesture.Offset.Y;
                    }

                    if (_lastMoveTime != null)
                    {
                        double time = AppMain.Current.TotalGameTime - _lastMoveTime.Value;

                        if (_touchIdX != 0 && _mode.HasFlag(Mode.HorizontalDrag))
                        {
                            _scrollSpeed.X = (_service.ScrollSpeedX + -gesture.Offset.X / (float)time) / 2;
                        }

                        if (_touchIdY != 0 && _mode.HasFlag(Mode.VerticalDrag))
                        {
                            _scrollSpeed.Y = (_service.ScrollSpeedY + -gesture.Offset.Y / (float)time) / 2;
                        }
                    }
                    else
                    {
                        _scrollSpeed.X = 0;
                        _scrollSpeed.Y = 0;
                    }

                    _lastMoveTime = AppMain.Current.TotalGameTime;
                }
                break;
            }
        }
Esempio n. 2
0
        public void OnGesture(Gesture gesture)
        {
            switch (gesture.GestureType)
            {
            case GestureType.MouseWheel:

                if (_view.IsPointInsideView(gesture.Position))
                {
                    float offset = -gesture.Offset.Y * _wheelSpeed;

                    if (_wheelScrollsHorizontal)
                    {
                        float maxScroll = _service.ScrolledElement.MaxScrollX - _service.ScrolledElement.ScreenBounds.Width;

                        if ((offset < 0 && _service.ScrollPositionX > 0) || (offset > 0 && _service.ScrollPositionX < maxScroll))
                        {
                            _service.ScrollPositionX += offset;
                        }
                    }
                    else
                    {
                        float maxScroll = _service.ScrolledElement.MaxScrollY - _service.ScrolledElement.ScreenBounds.Height;

                        if ((offset < 0 && _service.ScrollPositionY > 0) || (offset > 0 && _service.ScrollPositionY < maxScroll))
                        {
                            _service.ScrollPositionY += offset;
                        }
                    }
                }

                break;

            case GestureType.Up:
            case GestureType.CapturedByOther:
                if (_touchIdX == gesture.TouchId)
                {
                    _touchIdX             = 0;
                    _lastMoveTime         = null;
                    _service.ScrollSpeedX = _scrollSpeed.X;
                    AppMain.Redraw(_view);
                }

                if (_touchIdY == gesture.TouchId)
                {
                    _touchIdY             = 0;
                    _lastMoveTime         = null;
                    _service.ScrollSpeedY = _scrollSpeed.Y;
                    AppMain.Redraw(_view);
                }
                break;

            case GestureType.HorizontalDrag:
            case GestureType.VerticalDrag:
            case GestureType.FreeDrag:

                if (gesture.PointerCapturedBy == null)
                {
                    if (_touchIdX == 0 && _touchIdY == 0)
                    {
                        if (_view.IsPointInsideView(gesture.Origin))
                        {
                            _touchIdX = _touchIdY = gesture.TouchId;
                            gesture.CapturePointer(_view);
                        }
                    }
                }

                if (_touchIdX == gesture.TouchId || _touchIdY == gesture.TouchId)
                {
                    float maxExceed = (float)_service.MaxExceed.ComputeDouble();

                    gesture.SetHandled();

                    if (_touchIdX != 0 && _mode.HasFlag(Mode.HorizontalDrag))
                    {
                        if (_service.ScrollPositionX < -maxExceed && gesture.Offset.X > 0)
                        {
                            _service.ScrollPositionX = -maxExceed;
                        }
                        else if (_service.ScrollPositionX > _service.ScrolledElement.MaxScrollX + maxExceed && gesture.Offset.X < 0)
                        {
                            _service.ScrollPositionX = _service.ScrolledElement.MaxScrollX + maxExceed;
                        }
                        else
                        {
                            _service.ScrollPositionX -= gesture.Offset.X;
                        }

                        if (gesture.Offset.X != 0)
                        {
                            AppMain.Redraw(_view);
                        }
                    }

                    if (_touchIdY != 0 && _mode.HasFlag(Mode.VerticalDrag))
                    {
                        if (_service.ScrollPositionY < -maxExceed && gesture.Offset.Y > 0)
                        {
                            _service.ScrollPositionY = -maxExceed;
                        }
                        else if (_service.ScrollPositionY > _service.ScrolledElement.MaxScrollY + maxExceed && gesture.Offset.Y < 0)
                        {
                            _service.ScrollPositionY = _service.ScrolledElement.MaxScrollY + maxExceed;
                        }
                        else
                        {
                            _service.ScrollPositionY -= gesture.Offset.Y;
                        }

                        if (gesture.Offset.Y != 0)
                        {
                            AppMain.Redraw(_view);
                        }
                    }

                    if (_lastMoveTime != null)
                    {
                        double time = (gesture.Time - _lastMoveTime.Value).TotalSeconds;

                        time = Math.Max(time, 0.016f);

                        if (_touchIdX != 0 && _mode.HasFlag(Mode.HorizontalDrag))
                        {
                            _scrollSpeed.X = (_service.ScrollSpeedX - gesture.Offset.X / (float)time) / 2;
                        }

                        if (_touchIdY != 0 && _mode.HasFlag(Mode.VerticalDrag))
                        {
                            _scrollSpeed.Y = (_service.ScrollSpeedY - gesture.Offset.Y / (float)time) / 2;
                        }
                    }
                    else
                    {
                        _scrollSpeed.X = 0;
                        _scrollSpeed.Y = 0;
                    }

                    _lastMoveTime = gesture.Time;
                }
                break;
            }

            _service.IsDraggingX = _touchIdX != 0;
            _service.IsDraggingY = _touchIdY != 0;
        }