Esempio n. 1
0
        private bool CheckIsSimpleZoom(ManipulationDeltaEventArgs e)
        {
            if ((DateTime.Now - this.gestureTime).TotalMilliseconds > 150)
            {
                bool isInTime = this.IsFingersTouchInTime();
                if (this.IsZoom(e.CumulativeManipulation.Scale) && isInTime)
                {
                    double distance = this.GetMinFingerDistance(e);
                    if (distance > GestureConsts.Current.OneFingerSize && e.CumulativeManipulation.Translation.Length < GestureConsts.Current.MultiFingerZoomLimitDrag * 2)
                    {
                        if (this.OnGestureDetector != null)
                        {
                            this.currentResult = GestureResult.Zoom;
                            GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, (TouchDevice)e.Manipulators.First());
                            arg.Tag = e.DeltaManipulation.Scale;
                            this.OnGestureDetector(this.AssociatedObject, arg);
                        }
                        this.isGestureBehavior = true;
                    }
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 2
0
        private void GestureEnd(TouchDevice device)
        {
            if (this.GestureStatus.Count <= 0 || this.AssociatedObject.TouchesOver.Count() <= 1 || this.isGestureBehavior)
            {
                Console.WriteLine("Tap time is " + (DateTime.Now - this.gestTimeRecord).TotalMilliseconds);
                if (this.isGestureBehavior == false && (DateTime.Now - this.gestTimeRecord).TotalMilliseconds < 350)
                {
                    this.isGestureBehavior = true;;
                    this.currentGesture    = GestureResult.Tap;
                    GestureArg arg = new GestureArg(this.AssociatedObject, this.currentGesture, device);
                    this.FireEvent(arg);

                    this.GestureEnd(device);
                }
                else
                {
                    this.isGestureBehavior = false;
                    this.currentGesture    = GestureResult.End;

                    if (this.GestureStatus.Count > 0)
                    {
                        this.GestureStatus.Clear();
                    }
                    this.gestureCount = 0;
                    GestureArg arg = new GestureArg(this.AssociatedObject, this.currentGesture, device);
                    this.FireEvent(arg);
                }
            }
        }
Esempio n. 3
0
        private void ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            if (e.Manipulators != null && e.Manipulators.Count() > 0)
            {
                TouchDevice device = e.Manipulators.First() as TouchDevice;
                if (device == null)
                {
                    return;
                }

                if (this.isGestureBehavior)
                {
                    this.isHold = false;
                    if ((this.currentResult == GestureResult.Drag || this.currentResult == GestureResult.Zoom || this.currentResult == GestureResult.OneFinger) && this.gestureDetalBehavior != null)
                    {
                        GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, device);
                        this.gestureDetalBehavior(arg, e.DeltaManipulation, e.CumulativeManipulation);
                    }
                    return;
                }

                this.CheckOnMultiplefingersTouch();

                this.CheckIsBreakHold(e);

                this.AddManipluations(e);

                //Check other gesturevp
                if (this.CheckIsAreaGesture(e) || this.CheckFiveFingersScrath(e) || this.CheckZoomOrDragGesture(e) || this.CheckIsSimpleZoom(e) || this.CheckIsSimpleDrag(e))
                {
                    return;
                }
            }
        }
Esempio n. 4
0
        private void FireZoomOrScrachEvnet(TouchDevice device, Vector zoomArg)
        {
            GestureArg arg = new GestureArg(this.AssociatedObject, this.currentGesture, device);

            arg.Tag  = zoomArg;
            arg.Info = this.GestureStatus;
            this.FireEvent(arg);
            this.isGestureBehavior = true;
        }
Esempio n. 5
0
 private void FireEvent(GestureArg arg)
 {
     this.AssociatedObject.Dispatcher.BeginInvoke((Action)(() =>
     {
         if (this.OnGestureDetector != null)
         {
             this.OnGestureDetector(this.AssociatedObject, arg);
         }
     }));
 }
Esempio n. 6
0
        private void FireHoldEvent(TouchDevice device, Point newCenter)
        {
            this.currentGesture = GestureResult.Hold;
            GestureArg arg    = new GestureArg(this.AssociatedObject, this.currentGesture, device);
            Vector     vector = this.GetCumulativeTransitionResultParamater(newCenter);

            arg.Tag  = vector;
            arg.Info = this.GestureStatus;
            this.FireEvent(arg);
            this.isGestureBehavior = true;;
        }
Esempio n. 7
0
        private bool CheckIsDoubleTap(TouchDevice device)
        {
            if (this.AssociatedObject.TouchesOver.Count() == 1)
            {
                if (this.preTouchUpInfo != null && this.lastTouchUpInfo == null)
                {
                    bool isVaild = this.preTouchUpInfo.IsVaild(DateTime.Now);
                    if (isVaild == false)
                    {
                        this.preTouchUpInfo = null;
                        return(false);
                    }
                }
                else if (this.lastTouchUpInfo != null)
                {
                    bool isVaild = this.lastTouchUpInfo.IsVaild(DateTime.Now);
                    if (isVaild == false)
                    {
                        this.preTouchUpInfo  = null;
                        this.lastTouchUpInfo = null;

                        return(false);
                    }
                    else
                    {
                        double diffTime = (this.lastTouchUpInfo.TouchTime - this.preTouchUpInfo.TouchTime).TotalMilliseconds;
                        if (diffTime < GestureConsts.Current.VaildDoubleTapTimeDiff)
                        {
                            double diff = this.GetPowDis(this.lastTouchUpInfo.TouchPoint, this.preTouchUpInfo.TouchPoint);
                            if (diff < GestureConsts.Current.DoubleTapDistance)
                            {
                                this.currentResult = GestureResult.DoubleTap;
                                GestureArg   arg     = new GestureArg(this.AssociatedObject, this.currentResult, device);
                                List <Point> posInfo = new List <Point>();
                                posInfo.Add(this.preTouchUpInfo.TouchPoint);
                                posInfo.Add(this.lastTouchUpInfo.TouchPoint);
                                arg.Tag = posInfo;
                                if (this.OnGestureDetector != null)
                                {
                                    this.OnGestureDetector(this.AssociatedObject, arg);
                                }
                                this.isGestureBehavior = true;
                                this.preTouchUpInfo    = null;
                                this.lastTouchUpInfo   = null;
                                return(true);
                            }
                        }
                        this.preTouchUpInfo  = this.lastTouchUpInfo;
                        this.lastTouchUpInfo = null;
                    }
                }
            }
            return(false);
        }
Esempio n. 8
0
        private void CheckOnMultiplefingersTouch()
        {
            IEnumerable <TouchDevice> devices = this.AssociatedObject.TouchesOver;

            if (this.gestureFingerCount >= 2 || devices.Count() >= 2)
            {
                if (this.gestureStatusBehavior != null)
                {
                    if (devices.Count() > 0)
                    {
                        GestureArg arg = new GestureArg(this.AssociatedObject, GestureResult.MultipleFingers, devices.First());
                        arg.Info = devices;
                        this.gestureStatusBehavior(arg);
                    }
                }
            }
        }
Esempio n. 9
0
        private void TheProcessAfterGestureDetermined(TouchDevice device, Point newCenter, double newRadius)
        {
            if (this.gestureDetalBehavior != null)
            {
                GestureArg arg = new GestureArg(this.AssociatedObject, this.currentGesture, device);
                arg.Info = this.GestureStatus;
                if (this.currentGesture == GestureResult.Zoom)
                {
                    Vector zoomResult           = GetZoomResultParamater(newRadius);
                    Vector zoomCumulativeResult = GetCumulativeZoomResultParamater(newRadius);

                    this.gestureDetalBehavior(arg, zoomCumulativeResult, zoomResult);
                }
                else
                {
                    Vector transition           = GetTransitionResultParamater(newCenter);
                    Vector transitionCumulative = this.GetCumulativeTransitionResultParamater(newCenter);
                    this.gestureDetalBehavior(arg, transitionCumulative, transition);
                }
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Fire the Hold event
 /// </summary>
 void Tmer_Hold(object sender, EventArgs e)
 {
     timer.Stop();
     if (this.AssociatedObject.TouchesOver.Count() > 0)
     {
         TouchDevice device   = this.AssociatedObject.TouchesOver.First();
         TouchPoint  point    = device.GetTouchPoint(Application.Current.MainWindow);
         Point       startPos = (Point)timer.Tag;
         if (point.Position.Sub(startPos).Length() < GestureConsts.Current.ShakedThreshold)
         {
             if (this.isHold && this.OnGestureDetector != null)
             {
                 this.currentResult = GestureResult.Hold;
                 GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, null);
                 arg.Tag = this.timer.Tag;
                 this.OnGestureDetector(this.AssociatedObject, arg);
                 this.isGestureBehavior = true;
                 this.isHold            = false;
             }
         }
     }
 }
Esempio n. 11
0
        private bool CheckIsSimpleDrag(ManipulationDeltaEventArgs e)
        {
            if ((DateTime.Now - this.gestureTime).TotalMilliseconds > 150)
            {
                bool isSimpleDrag = this.IsSimpleDrag(e, this.sensitiveFactor.DragFactor);
                bool isInTime     = this.IsFingersTouchInTime();
                if (e.Manipulators.Count() == 2 && isSimpleDrag && isInTime)
                {
                    if (this.OnGestureDetector != null)
                    {
                        this.currentResult = GestureResult.Drag;
                        GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, (TouchDevice)e.Manipulators.First());
                        arg.Tag = e.DeltaManipulation.Translation;
                        this.OnGestureDetector(this.AssociatedObject, arg);
                    }
                    this.isGestureBehavior = true;
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 12
0
        private bool CheckZoomOrDragGesture(ManipulationDeltaEventArgs e)
        {
            double costTime = (DateTime.Now - this.gestureTime).TotalMilliseconds;

            TraceLog("Cost time:" + costTime);
            if (costTime > 60)
            {
                GestureResult result = this.GetDragOrZoomGestureResult(e);
                if (result == GestureResult.Drag)
                {
                    if (this.OnGestureDetector != null)
                    {
                        this.currentResult = GestureResult.Drag;
                        GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, (TouchDevice)e.Manipulators.First());
                        arg.Tag = e.CumulativeManipulation.Translation;
                        this.OnGestureDetector(this.AssociatedObject, arg);
                    }
                    this.isGestureBehavior = true;
                    return(true);
                }
                else if (result == GestureResult.Zoom)
                {
                    if (this.OnGestureDetector != null)
                    {
                        this.currentResult = GestureResult.Zoom;
                        GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, (TouchDevice)e.Manipulators.First());
                        arg.Tag = e.DeltaManipulation.Scale;
                        this.OnGestureDetector(this.AssociatedObject, arg);
                    }
                    this.isGestureBehavior = true;
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 13
0
        private bool CheckIsAreaGesture(ManipulationDeltaEventArgs e)
        {
            int fingerCount = this.AssociatedObject.TouchesOver.Count();

            if (fingerCount > this.gestureFingerCount)
            {
                this.gestureFingerCount = fingerCount;
            }

            TouchDevice device       = (TouchDevice)e.Manipulators.First();
            TouchPoint  point        = device.GetTouchPoint(Application.Current.MainWindow);
            double      mendedHeight = GestureDetector.GetMendedHeight(point.Size.Width, point.Size.Height);

            if (GestureDetector.IsErase(point.Size.Width, mendedHeight))
            {
                if (this.OnGestureDetector != null)
                {
                    this.currentResult = GestureResult.Brush;
                    GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, device);
                    arg.Tag = new Rect(point.Position.X, point.Position.Y, point.Size.Width, mendedHeight);
                    this.OnGestureDetector(this.AssociatedObject, arg);
                }
                this.isGestureBehavior = true;
                return(true);
            }
            else
            {
                if (this.gestureFingerCount == 1)
                {
                    double checkWidht  = point.Size.Width;
                    double checkHeight = mendedHeight;
                    double checkRadio  = checkHeight / checkWidht;
                    bool   isZoom      = this.IsZoom(e.CumulativeManipulation.Scale);
                    if (
                        (checkRadio > GestureConsts.Current.FingerHeightWidhtRatio || checkWidht < (1 / GestureConsts.Current.FingerHeightWidhtRatio)) &&
                        (Math.Min(checkWidht, checkHeight) > GestureConsts.Current.OneFingerSize)
                        )
                    {
                        if (this.gestureStatusBehavior != null)
                        {
                            this.gestureStatusBehavior(new GestureArg(this.AssociatedObject, GestureResult.MultipleFingers, device));
                        }
                        if (e.CumulativeManipulation.Translation.Length > GestureConsts.Current.MultiFingerDragThreshold && isZoom == false)
                        {
                            if (this.OnGestureDetector != null)
                            {
                                this.currentResult = GestureResult.Drag;
                                GestureArg arg = new GestureArg(this.AssociatedObject, this.currentResult, device);
                                arg.Tag = e.CumulativeManipulation.Translation;
                                this.OnGestureDetector(this.AssociatedObject, arg);
                            }
                            this.isGestureBehavior = true;
                            return(true);
                        }
                    }

                    else if (e.CumulativeManipulation.Translation.Length > GestureConsts.Current.MultiFingerDragThreshold && isZoom == false)
                    {
                        if (this.OnGestureDetector != null)
                        {
                            this.currentResult = GestureResult.OneFinger;
                            this.OnGestureDetector(this.AssociatedObject, new GestureArg(this.AssociatedObject, this.currentResult, device));
                        }
                        this.isGestureBehavior = true;
                        return(true);
                    }
                }
            }
            return(false);
        }