コード例 #1
0
 protected virtual void OnHoverDetected(SKHoverDetectedEventArgs e) =>
 HoverDetected?.Invoke(this, e);
コード例 #2
0
        private bool OnTouchMoved(SKTouchEventArgs e)
        {
            var ticks    = DateTime.Now.Ticks;
            var location = e.Location;

            touches[e.Id] = new TouchEvent(e.Id, location, ticks, e.InContact);

            // update the fling tracker
            if (e.InContact)
            {
                flingTracker.AddEvent(e.Id, location, ticks);
            }

            // if this is a mouse or pen hover, then raise an event
            if (!e.InContact)
            {
                var args = new SKHoverDetectedEventArgs(e.Location);
                OnHoverDetected(args);
                return(args.Handled);
            }

            var touchPoints = GetInContactTouchPoints();

            // TODO: potentially handle move events before gestures

            switch (touchMode)
            {
            case TouchMode.Single:
            {
                if (touchPoints.Length != 1)
                {
                    return(false);
                }

                var touchPosition = touchPoints.First();

                if (!previousValues.Center.IsEmpty)
                {
                    var args = new SKTransformDetectedEventArgs(touchPosition, previousValues.Center);
                    OnTransformDetected(args);
                }

                previousValues.Center = touchPosition;
            }
            break;

            case TouchMode.Multiple:
            {
                if (touchPoints.Length != 2)
                {
                    return(false);
                }

                var prevVals   = previousValues;
                var pinchValue = PinchValue.FromLocations(touchPoints);

                var rotationDelta = pinchValue.Angle - prevVals.Angle;
                rotationDelta %= 360;

                if (rotationDelta > 180)
                {
                    rotationDelta -= 360;
                }
                else if (rotationDelta < -180)
                {
                    rotationDelta += 360;
                }

                var args = new SKTransformDetectedEventArgs(pinchValue.Center, prevVals.Center, pinchValue.Radius / prevVals.Radius, rotationDelta);
                OnTransformDetected(args);

                previousValues = pinchValue;
            }
            break;
            }

            return(true);
        }