Example #1
0
        /// <summary>
        /// Handle touch events to move the stencil points
        /// </summary>
        /// <param name="inkCanvasView">the ink canvas view</param>
        /// <param name="stencil">the equirectangular stencil</param>
        /// <param name="e">the touch event arguments</param>
        internal void Touch(IInkCanvasView inkCanvasView, EquirectangularStencil stencil, SKTouchEventArgs e)
        {
            if (inkCanvasView == null)
            {
                throw new ArgumentNullException(nameof(inkCanvasView));
            }

            if (stencil == null || stencil.Mode != EquirectangularStencilMode.TwoPoint)
            {
                return;
            }

            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            var location = inkCanvasView.GetCanvasPosition(e.Location);

            var deltaX = location.X - _startPoint.X;

            var deltaY = location.Y - _startPoint.Y;

            if (e.InContact)
            {
                switch (e.ActionType)
                {
                case SKTouchAction.Pressed:
                    if (Distance(location, Point1) < Radius / inkCanvasView.ZoomFactor)
                    {
                        _touchingPoint = 1;

                        _startPoint = location;

                        e.Handled = true;
                    }
                    else if (Distance(location, Point2) < Radius / inkCanvasView.ZoomFactor)
                    {
                        _touchingPoint = 2;

                        _startPoint = location;

                        e.Handled = true;
                    }
                    else
                    {
                        _touchingPoint = 0;
                    }
                    break;

                case SKTouchAction.Moved:

                    switch (_touchingPoint)
                    {
                    case 1:
                        Point1    = Point1.Offset(deltaX, deltaY);
                        e.Handled = true;
                        UpdateApex(inkCanvasView, stencil);
                        break;

                    case 2:
                        Point2    = Point2.Offset(deltaX, deltaY);
                        e.Handled = true;
                        UpdateApex(inkCanvasView, stencil);
                        break;
                    }
                    _startPoint = location;
                    break;
                }
            }
            else if (e.ActionType == SKTouchAction.Released)
            {
                switch (_touchingPoint)
                {
                case 1:
                    Point1    = Point1.Offset(deltaX, deltaY);
                    e.Handled = true;
                    UpdateApex(inkCanvasView, stencil);
                    break;

                case 2:
                    Point2    = Point2.Offset(deltaX, deltaY);
                    e.Handled = true;
                    UpdateApex(inkCanvasView, stencil);
                    break;
                }

                _touchingPoint = 0;
            }
        }