示例#1
0
 public void Reset()
 {
     this.incrementalTranslation = Swipe.Id();
     this.incrementalScaling     = Swipe.Id();
     this.lastPinchPan           = Swipe.Id();
     this.dragging           = false;
     this.swiping            = false;
     this.displayPinchOrigin = false;
     this.pinchOrigin        = new SKPoint(0, 0);
     this.setManualPinchPan(Swipe.Id());
 }
示例#2
0
        public static void OnTouchEffectAction(object sender, TouchActionEventArgs e)
        {
            KTouchClient     kTouchClient = sender as KTouchClient;
            KTouchClientData data         = kTouchClient.data;
            // Touch location is given in Xamarin independent display units, and must be multiplied by display density to work at all platforms and resolutions
            // e.Location comes from Android TouchEffect.Droid.FireEvent and iOS TouchRecognizer.FireEvent
            double  density  = DeviceDisplay.MainDisplayInfo.Density;
            SKPoint location = new SKPoint((float)(e.Location.X * density), (float)(e.Location.Y * density));

            if (e.Type == TouchActionType.Pressed)
            {
                if (data.fingers.PressedOne(e.Id, location, e.IsInContact))
                {
                    data.displayPinchOrigin = true;
                }
                else if (data.fingers.PressedTwo(e.Id, location, e.IsInContact))
                {
                    data.incrementalTranslation = Swipe.Id();
                    data.incrementalScaling     = Swipe.Id();
                    data.displayPinchOrigin     = true;
                    data.swiping = true;
                }
            }
            else if (e.Type == TouchActionType.Moved)
            {
                if (data.fingers.Moved(e.Id, location, e.IsInContact))
                {
                    if (data.fingers.OneContact())
                    {
                        data.pinchOrigin = location; // display the location of swiping
                        data.onTouchSwipeOrMouseDrag?.Invoke(data.fingers.fingerOne.initialLocation, location);
                        data.dragging = true;
                    }
                    else if (data.fingers.TwoContacts())
                    {
                        SKPoint translation   = data.fingers.Translation();
                        SKPoint scalingOrigin = data.fingers.Center();
                        float   scaling       = data.fingers.Scaling();
                        data.incrementalTranslation = new Swipe(1, translation);
                        data.incrementalScaling     = new Swipe(scaling, new SKPoint((1 - scaling) * scalingOrigin.X, (1 - scaling) * scalingOrigin.Y)); // scaling around the scaleOrigin
                        data.pinchOrigin            = scalingOrigin;                                                                                     // display the center of scaling
                        data.setManualPinchPan?.Invoke(data.lastPinchPan * data.incrementalScaling * data.incrementalTranslation);
                        data.invalidateSurface();
                    }
                }
            }
            else if (e.Type == TouchActionType.Released)
            {
                if (data.fingers.TwoFingerTapped(e.Id))
                {
                    data.lastPinchPan = Swipe.Id();
                    data.setManualPinchPan?.Invoke(data.lastPinchPan);
                    data.invalidateSurface();
                }
                if (data.fingers.ReleasingTwo(e.Id, location, e.IsInContact))
                {
                }
                else if (data.fingers.ReleasingOne(e.Id, location, e.IsInContact))
                {
                    if (data.swiping)
                    {
                        data.swiping      = false;
                        data.lastPinchPan = data.lastPinchPan * data.incrementalScaling * data.incrementalTranslation;
                        data.lastPinchPan = new Swipe(Math.Max(0.1f, data.lastPinchPan.scale), data.lastPinchPan.translate);
                        data.setManualPinchPan?.Invoke(data.lastPinchPan);
                        data.invalidateSurface();
                    }
                    else
                    {
                        if (data.fingers.DoubleTapped(e.Id))
                        {
                            data.onTouchDoubletapOrMouseClick?.Invoke(location);
                        }
                        else if (data.fingers.Tapped(e.Id))
                        {
                            data.onTouchTapOrMouseMove?.Invoke(location);
                        }
                        if (data.dragging)
                        {
                            data.dragging = false;
                            data.onTouchSwipeOrMouseDragEnd?.Invoke(data.fingers.fingerOne.initialLocation, location);
                        }
                    }
                }
                if (data.fingers.Released(e.Id))
                {
                    data.displayPinchOrigin = false;
                }
            }
            else if (e.Type == TouchActionType.Entered)
            {
            }
            else if (e.Type == TouchActionType.Exited)
            {
            }
            else if (e.Type == TouchActionType.Cancelled)
            {
            }
        }