Beispiel #1
0
 void _handgestures_HandExit(object sender, HandEventArgs e)
 {
     if (!_hands.ContainsKey("HAND_" + e.HandData.HandId)) return;
     //
     _targetelement.Dispatcher.BeginInvoke(() =>
     {
         HandManager hand = _hands["HAND_" + e.HandData.HandId];
         //
         hand.HandGestures.HandEnter -= new HandEnterEventHandler(_handgestures_HandEnter);
         hand.HandGestures.HandMove -= new HandMoveEventHandler(_handgestures_HandMove);
         hand.HandGestures.HandExit -= new HandExitEventHandler(_handgestures_HandExit);
         hand.HandGestures.GestureRecognized -= new GestureRecognizedEventHandler(_handgestures_GestureRecognized);
         //
         if (hand.PushedElement != null) // && hand.PushedElement.GetType() != typeof(UIKit.ScrollView))
         {
             ((Touchable)hand.PushedElement).FingerUp(this, new FingerTouchEventArgs(new Finger("KINECTHAND:" + e.HandData.HandId, e.HandLocation)));
         }
         _overlay.LayoutRoot.Children.Remove(hand.HandShape);
         _overlay.LayoutRoot.Children.Remove(hand.HandPushPoint);
         _hands.Remove("HAND_" + e.HandData.HandId);
     });
 }
Beispiel #2
0
        void _handgestures_HandMove(object sender, HandEventArgs e)
        {
            if (_handupdatemutex == null)
            {
                _handupdatemutex = new ManualResetEvent(false);
            }
            _handupdatemutex.Reset();
            //
            DispatcherOperation dope = _targetelement.Dispatcher.BeginInvoke(() =>
            {
                HandManager hand = _hands["HAND_" + e.HandData.HandId];
                Point p = new Point((int)(e.HandLocation.X / 7) * 7, (int)(e.HandLocation.Y / 5) * 5);
                hand.TransformHelper.Delay = 0.75;
                hand.TransformHelper.Translate = p;

                if (_handupdatemutex != null)
                {
                    HandUpdate(this, e);
                }

                if (hand.PushedElement != null)
                {

                    /*if (hand.PushedElement.GetType() == typeof(UIKit.ScrollView))
                    {

                        UIKit.ScrollView sv = (hand.PushedElement as UIKit.ScrollView);
                        //if (!sv.ScrollerTransformHelper.IsRunning)
                        {
                            sv.ScrollerTransformHelper.Delay = 60.0 / Utility.Vector2D.Distance(new Point(e.HandData.PushLocation.X, e.HandData.PushLocation.Y), e.HandLocation);
                            if (e.HandData.PushShift.Y < -20)
                            {
                                //sv.ScrollerTransformHelper.Translate = new Point(sv.ScrollerTransformHelper.Translate.X, sv.ScrollerTransformHelper.Translate.Y - (e.HandData.PushLocation.Y - e.HandLocation.Y) / 10);

                                sv.Move(new Point(0, e.HandData.PushShift.Y / 2D));
                                //sv._checkscrollerbound();

                                //sv._simulategesture(Gestures.TouchGesture.MOVE_NORTH);
                            }
                            else if (e.HandData.PushShift.Y > 20)
                            {
                                //sv.ScrollerTransformHelper.Translate = new Point(sv.ScrollerTransformHelper.Translate.X, sv.ScrollerTransformHelper.Translate.Y - (e.HandData.PushLocation.Y - e.HandLocation.Y) / 10);

                                sv.Move(new Point(0, e.HandData.PushShift.Y / 2D));
                                //sv._checkscrollerbound();

                                //sv._simulategesture(Gestures.TouchGesture.MOVE_SOUTH);
                            }
                            else if (e.HandData.PushShift.X < -20)
                            {
                                sv.Move(new Point(e.HandData.PushShift.X / 2D, 0));
                                //sv._simulategesture(Gestures.TouchGesture.MOVE_WEST);
                            }
                            else if (e.HandData.PushShift.X > 20)
                            {
                                sv.Move(new Point(e.HandData.PushShift.X / 2D, 0));
                                //sv._simulategesture(Gestures.TouchGesture.MOVE_EAST);
                            }
                        }

                    }
                    else if (hand.PushedElement.GetType() == typeof(UIKit.TButton) && !(hand.PushedElement as UIKit.TButton).IsPressed)
                    {
                    //    TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - e.HandData.PushDateTime.Ticks);
                    //    //if (ts.TotalMilliseconds > 750)
                    //    //{
                    //    //    ((UIKit.TButton)hand.PushedElement).TransformHelper.Delay = 0;
                    //    //    ((Touchable)hand.PushedElement).FingerMove(this, new FingerTouchEventArgs(new Finger("KINECTHAND:" + e.HandData.HandId, e.HandLocation)));
                    //    //}
                        hand.PushedElement = null;
                        //
                        _handupdatemutex.Set();
                        //
                        return;
                    }
                    else*/
                    {
                        ((Touchable)hand.PushedElement).FingerMove(this, new FingerTouchEventArgs(new Finger("KINECTHAND:" + e.HandData.HandId, e.HandLocation)));
                    }
                }
                else
                {
                    UIElement curelement = null;
                    List<UIElement> cls = Utility.Transform2d.GetCollisionsAt(_targetelement, hand.TransformHelper.Translate, new Size(hand.HandShape.Width, hand.HandShape.Height));
                    foreach (UIElement uiel in cls)
                    {
                        if (typeof(Touchable).IsAssignableFrom(uiel.GetType()))
                        {
                            curelement = uiel;
                            break;
                        }
                    }

                    // HAND JUST OVER A NEW ELEMENT
                    if ((hand.CurrentElement == null && curelement != null) || (hand.CurrentElement != null && !hand.CurrentElement.Equals(curelement)))
                    {
                        hand.TappingTs = DateTime.Now;
                        //
                        if (hand.CurrentElement != null) // && hand.CurrentElement.GetType() == typeof(UIKit.ScrollView) && _currentscrollview == null)
                        {
                            //_currentscrollview = hand.CurrentElement as ScrollView;
                            //_showarrows();
                        }
            //                        else if (hand.CurrentElement != null && hand.CurrentElement.GetType() == typeof(UIKit.ScrollView)) //if (_currentscrollview != null && !_currentscrollview.ScrollerTransformHelper.IsRunning) //(hand.CurrentElement != null && hand.CurrentElement.GetType() == typeof(UIKit.TButton))
            //                        {
                            /*
                            if (_currentscrollview != null && !_currentscrollview.ScrollerTransformHelper.IsRunning)
                            {

                                TButton tb = hand.CurrentElement as TButton;
                                if (tb.Equals(_overlay.ScrollRight))
                                {
                                    _currentscrollview._simulategesture(TouchGesture.MOVE_WEST);
                                }
                                else if (tb.Equals(_overlay.ScrollLeft))
                                {
                                    _currentscrollview._simulategesture(TouchGesture.MOVE_EAST);
                                }
                            }
                            */

            //System.Diagnostics.Debug.WriteLine(hand.TransformHelper.Translate.Y + " # " + _targetsize.Height);
            /*                            if (hand.TransformHelper.Translate.X > (_targetsize.Width - (_targetsize.Width / 5D)))
                            {
                                _currentscrollview.ScrollerTransformHelper.Delay = 1.0;
                                _currentscrollview._simulategesture(TouchGesture.MOVE_WEST);
                            }
                            else if (hand.TransformHelper.Translate.X < (_targetsize.Width / 5D))
                            {
                                _currentscrollview.ScrollerTransformHelper.Delay = 1.0;
                                _currentscrollview._simulategesture(TouchGesture.MOVE_EAST);
                            }

                            if (hand.TransformHelper.Translate.Y < ((_targetsize.Height / 5D)))
                            {
                                _currentscrollview.ScrollerTransformHelper.Delay = 1.0;
                                _currentscrollview._simulategesture(TouchGesture.MOVE_NORTH);
                                //_currentscrollview.ScrollerTransformHelper.Translate = new Point(_currentscrollview.ScrollerTransformHelper.Translate.X, _currentscrollview.ScrollerTransformHelper.Translate.Y - 1000);
                            }
                            else if (hand.TransformHelper.Translate.Y > (_targetsize.Height - (_targetsize.Height / 5D)))
                            {
                                _currentscrollview.ScrollerTransformHelper.Delay = 1.0;
                                _currentscrollview._simulategesture(TouchGesture.MOVE_SOUTH);
                                //_currentscrollview.ScrollerTransformHelper.Translate = new Point(_currentscrollview.ScrollerTransformHelper.Translate.X, _currentscrollview.ScrollerTransformHelper.Translate.Y - 1000);
                            }*/
            //                        }
                    }
                    /*
                    if (curelement != null)
                    {
                        if ((hand.CurrentElement == null || !hand.CurrentElement.Equals(curelement)) && curelement.GetType() == typeof(UIKit.TButton))
                        {
                            //((UIKit.TButton)curelement).TransformHelper.Delay = 0.5;
                            //((UIKit.TButton)curelement).TransformHelper.Scale = 1.5;
                        }
                        if (hand.CurrentElement != null && hand.CurrentElement.Equals(curelement) && curelement.GetType() == typeof(UIKit.TButton))
                        {
                            //((UIKit.TButton)curelement).TransformHelper.Delay = 0.5;
                            //((UIKit.TButton)curelement).TransformHelper.Scale = 1.5;
                            UIKit.TButton tb = curelement as UIKit.TButton;
                            if (!double.IsInfinity(tb.DragRadius))
                            {
                                hand.PushedElement = curelement;
                                tb.FingerDown(this, new FingerTouchEventArgs(new Finger("KINECTHAND:" + e.HandData.HandId, e.HandLocation)));
                                //
                                Point c = tb.TransformToVisual(_targetelement).Transform(new Point(tb.RenderSize.Width / 4, tb.RenderSize.Height / 4));
                                hand.TransformHelper.Translate = c;
                                //
                                _handupdatemutex.Set();
                                //
                                return;
                            }
                        }
                    }*/
                    //
                    //
                    if (hand.CurrentElement != null && !hand.CurrentElement.Equals(curelement))
                    {
                        /*if (hand.CurrentElement.GetType() == typeof(UIKit.TButton))
                        {
                            //((UIKit.TButton)hand.CurrentElement).TransformHelper.Delay = 0.5;
                            //((UIKit.TButton)hand.CurrentElement).TransformHelper.Scale = 1.0;
                            ((UIKit.TButton)hand.CurrentElement)._simulateleave();
                        }
                        else if (hand.CurrentElement.GetType() == typeof(UIKit.ScrollView) && (hand.CurrentElement as ScrollView).ScrollerTransformHelper.IsRunning == false)
                        {
                            if (hand.TransformHelper.Translate.Y > 200 && hand.TransformHelper.Translate.Y < (_targetsize.Height - 200))
                            {
                                if (hand.TransformHelper.Translate.X > (_targetsize.Width - (_targetsize.Width / 4D)))
                                {
                                    (hand.CurrentElement as ScrollView).ScrollerTransformHelper.Delay = 0.75;
                                    (hand.CurrentElement as ScrollView).SimulateGesture(TouchGesture.MOVE_WEST);
                                }
                                else if (hand.TransformHelper.Translate.X < (_targetsize.Width / 4D))
                                {
                                    (hand.CurrentElement as ScrollView).ScrollerTransformHelper.Delay = 0.75;
                                    (hand.CurrentElement as ScrollView).SimulateGesture(TouchGesture.MOVE_EAST);
                                }
                            }
                            //if (hand.TransformHelper.Translate.X > 200 && hand.TransformHelper.Translate.X < (_targetsize.Width - 200))
                            //{
                            //    if (hand.TransformHelper.Translate.Y > (_targetsize.Height - (_targetsize.Height / 4D)))
                            //    {
                            //        (hand.CurrentElement as ScrollView).ScrollerTransformHelper.Delay = 0.75;
                            //        (hand.CurrentElement as ScrollView)._simulategesture(TouchGesture.MOVE_NORTH);
                            //    }
                            //    else if (hand.TransformHelper.Translate.Y < (_targetsize.Height / 4D))
                            //    {
                            //        (hand.CurrentElement as ScrollView).ScrollerTransformHelper.Delay = 0.75;
                            //        (hand.CurrentElement as ScrollView)._simulategesture(TouchGesture.MOVE_SOUTH);
                            //    }
                            //}

                        }*/
                    }
                    //
                    /*
                    if (hand.CurrentElement != null && hand.CurrentElement.GetType() == typeof(UIKit.TButton))
                    {
                        TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - hand.TappingTs.Ticks);
                        if (ts.TotalMilliseconds % 300 < 150)
                        {
                            hand.HandShape.CircleSelectO.Visibility = Visibility.Visible;
                            hand.HandShape.CircleSelectI.Visibility = Visibility.Collapsed;
                        }
                        else
                        {
                            hand.HandShape.CircleSelectO.Visibility = Visibility.Collapsed;
                            hand.HandShape.CircleSelectI.Visibility = Visibility.Visible;
                        }
                        if (ts.TotalSeconds > _overclickdelay || !hand.CurrentElement.Equals(curelement))
                        {
                            if (ts.TotalSeconds > _overclickdelay)
                            {
                                hand.TappingTs = DateTime.Now;
                                // simulate click over TButton
                                ((UIKit.TButton)hand.CurrentElement).FingerDown(this, new FingerTouchEventArgs(new Finger("KHAND:0", e.HandData.GetRelativeLocation2d(new Point()))));
                                ((UIKit.TButton)hand.CurrentElement).FingerUp(this, new FingerTouchEventArgs(new Finger("KHAND:0", e.HandData.GetRelativeLocation2d(new Point()))));
                            }
                            //
                            hand.HandShape.TextLabel.Text = "";
                            hand.HandShape.CircleSelectO.Visibility = Visibility.Collapsed;
                            hand.HandShape.CircleSelectI.Visibility = Visibility.Collapsed;
                        }
                        else
                        {
                            hand.HandShape.TextLabel.Text = (_overclickdelay - Math.Round(ts.TotalSeconds, 0)).ToString();
                        }
                    }*/
                    //
                    hand.CurrentElement = curelement;
                }
                _handupdatemutex.Set();
            });
            //
            _handupdatemutex.WaitOne();
        }
Beispiel #3
0
 void _handgestures_HandEnter(object sender, HandEventArgs e)
 {
     _targetelement.Dispatcher.BeginInvoke(() =>
     {
         HandManager hand = _hands["HAND_" + e.HandData.HandId];
         _overlay.LayoutRoot.Children.Add(hand.HandShape);
         _overlay.LayoutRoot.Children.Add(hand.HandPushPoint);
         hand.TransformHelper.Translate = e.HandLocation;
     });
     //
     if (HandAdded != null) HandAdded(this, e);
 }