locked
Does Surface 2.0 support defining new gestures? RRS feed

  • Question

  • For example, how to difine a 3 finger-touched swipe? Just like iPad, I've made a app have different screens, now I switch among them by using tags.

    Can anyone help?

    Thanks

    Regards,

    Frank

    Tuesday, June 19, 2012 5:47 AM

Answers

  • You need to track your finger touch and keep a collection of current touch down, when you get thre of them then you can enable your gesture. In case a touch is remove during manipulation or just before you will have to handle that case also

    regards
    Serge


    Your knowledge is enhanced by that of others.

    Tuesday, June 19, 2012 6:59 AM
  • Thank you Serge,

    Based on your suggestions I have figured it out.

    I leave some code here, in case of anyone have the same problem:

    private Dictionary<TouchDevice, Point> currentTouchDevices = new Dictionary<TouchDevice, Point>();
     private void NavigationPanel_TouchDown(object sender, TouchEventArgs e)
            {
                if (e.TouchDevice.GetIsFingerRecognized())
                    currentTouchDevices.Add(e.TouchDevice, e.TouchDevice.GetPosition(this));
            }
            private void NavigationPanel_TouchUp(object sender, TouchEventArgs e)
            {
                currentTouchDevices.Remove(e.TouchDevice);        
            }
            private void NavigationPanel_TouchMove(object sender, TouchEventArgs e)
            {
                if (currentTouchDevices.Count == 3)
                {
                    int isLeft = 0;
                    int isRight = 0;
                    foreach (KeyValuePair<TouchDevice, Point> td in currentTouchDevices)
                    {
                        if (td.Key != null && e.TouchDevice.GetPosition(this).X - td.Value.X > 100)
                            isRight++;
                        else if (td.Key != null && td.Value.X - e.TouchDevice.GetPosition(this).X > 100)
                            isLeft++;
                        else
                            return;
                    }
                    if (isLeft == 3 && isRight == 0)
                    {
                        if (NavigationPanel.PreviousIsValid)
                        {
                            NavigationPanel.Previous();
                            currentTouchDevices.Clear();
                            return;
                        }
                    }
                    if (isLeft == 0 && isRight == 3)
                    {
                        if (NavigationPanel.NextIsValid)
                        {
                            NavigationPanel.Next();
                            currentTouchDevices.Clear();
                            return;
                        }
                    }
                }
            }

    Thursday, June 28, 2012 3:44 AM

All replies

  • You need to track your finger touch and keep a collection of current touch down, when you get thre of them then you can enable your gesture. In case a touch is remove during manipulation or just before you will have to handle that case also

    regards
    Serge


    Your knowledge is enhanced by that of others.

    Tuesday, June 19, 2012 6:59 AM
  • Thank you Serge,

    Based on your suggestions I have figured it out.

    I leave some code here, in case of anyone have the same problem:

    private Dictionary<TouchDevice, Point> currentTouchDevices = new Dictionary<TouchDevice, Point>();
     private void NavigationPanel_TouchDown(object sender, TouchEventArgs e)
            {
                if (e.TouchDevice.GetIsFingerRecognized())
                    currentTouchDevices.Add(e.TouchDevice, e.TouchDevice.GetPosition(this));
            }
            private void NavigationPanel_TouchUp(object sender, TouchEventArgs e)
            {
                currentTouchDevices.Remove(e.TouchDevice);        
            }
            private void NavigationPanel_TouchMove(object sender, TouchEventArgs e)
            {
                if (currentTouchDevices.Count == 3)
                {
                    int isLeft = 0;
                    int isRight = 0;
                    foreach (KeyValuePair<TouchDevice, Point> td in currentTouchDevices)
                    {
                        if (td.Key != null && e.TouchDevice.GetPosition(this).X - td.Value.X > 100)
                            isRight++;
                        else if (td.Key != null && td.Value.X - e.TouchDevice.GetPosition(this).X > 100)
                            isLeft++;
                        else
                            return;
                    }
                    if (isLeft == 3 && isRight == 0)
                    {
                        if (NavigationPanel.PreviousIsValid)
                        {
                            NavigationPanel.Previous();
                            currentTouchDevices.Clear();
                            return;
                        }
                    }
                    if (isLeft == 0 && isRight == 3)
                    {
                        if (NavigationPanel.NextIsValid)
                        {
                            NavigationPanel.Next();
                            currentTouchDevices.Clear();
                            return;
                        }
                    }
                }
            }

    Thursday, June 28, 2012 3:44 AM