Exemple #1
0
        public void InvokeHoverClick(HandPosition hand)
        {
            if (hand != null)
            {
                hand.IsInteracting = false;

                HandHoverTimer timer = this.trackedHandHovers.FirstOrDefault(h => h.Hand.Equals(hand));
                if (timer != null)
                {
                    timer.Stop();
                    this.trackedHandHovers.Remove(timer);
                }
            }

            this.IsSelected = true;

            if (this.soundPlayerOnClick != null)
            {
                this.soundPlayerOnClick.Play();
            }

            var t = new DispatcherTimer();

            t.Interval = TimeSpan.FromSeconds(0.6);

            t.Tick += (o, s) =>
            {
                t.Stop();
                var clickArgs = new HandInputEventArgs(HoverClickEvent, this, hand);
                this.RaiseEvent(clickArgs);
                this.IsSelected = false;
            };
            t.Start();
        }
Exemple #2
0
        public TimeSpan GetTimeRemaining(HandPosition hand)
        {
            HandHoverTimer timer = this.trackedHandHovers.FirstOrDefault(h => h.Hand.Equals(hand));

            if (timer != null)
            {
                return(timer.TimeRemaining);
            }

            return(TimeSpan.MaxValue);
        }
Exemple #3
0
        private void RemoveHand(HandPosition hand)
        {
            this.IsHoveredOver = false;
            hand.IsInteracting = false;
            hand.Magnetized    = false;

            // Stop active hover timer (if it exists) for this hand.
            HandHoverTimer timer = this.trackedHandHovers.FirstOrDefault(h => h.Hand.Equals(hand));

            if (timer != null)
            {
                timer.Stop();
                this.trackedHandHovers.Remove(timer);
            }
        }
        /// <summary>
        /// 当空气鼠标进入这个HoverDwellButton时引发的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnPreviewHandEnter(object sender, HandInputEventArgs args)
        {
            if (this.trackedHandHovers.FirstOrDefault(t => t.Hand.Equals(args.Hand)) == null)
            {
                this.IsHoveredOver = true;
                //发出空气鼠标的EnterSound
                if (this.SoundOnEnter.Length > 0)
                {
                    if (this.soundPlayerOnEnter == null)
                    {
                        Assembly a = Assembly.GetExecutingAssembly();

                        Stream s = a.GetManifestResourceStream("Microsoft.Samples.Kinect.BasicInteractions.Resources.Sounds." + this.SoundOnEnter);

                        this.soundPlayerOnEnter = new SoundPlayer(s);
                    }

                    this.soundPlayerOnEnter.Play();
                }

                args.Hand.IsInteracting = true;
                if (this.Magnetic)
                {
                    // set the X and Y of the hand so it is centered over the button
                    var element = this.Content as FrameworkElement;

                    if (element != null)
                    {
                        var   pt          = new Point(element.ActualWidth / 2, element.ActualHeight / 2);
                        Point lockedPoint = element.PointToScreen(pt);
                        args.Hand.X = (int)lockedPoint.X;
                        args.Hand.Y = (int)lockedPoint.Y;
                    }

                    args.Hand.Magnetized = true;
                }

                var timer = new HandHoverTimer(DispatcherPriority.Normal, this.Dispatcher);
                timer.Hand = args.Hand;

                timer.Interval = TimeSpan.FromMilliseconds(Settings.Default.SelectionTime);
                timer.Tick    += (o, s) => { this.InvokeHoverClick(args.Hand); };
                this.trackedHandHovers.Add(timer);
                timer.Start();
            }

            args.Handled = true;
        }
        private void OnPreviewHandEnter(object sender, HandInputEventArgs args)
        {
            if (this.trackedHandHovers.FirstOrDefault(t => t.Hand.Equals(args.Hand)) == null)
            {
                this.IsHoveredOver = true;
                if (this.SoundOnEnter.Length > 0)
                {
                    if (this.soundPlayerOnEnter == null)
                    {
                        Assembly a = Assembly.GetExecutingAssembly();

                        Stream s = a.GetManifestResourceStream("Microsoft.Samples.Kinect.BasicInteractions.Resources.Sounds." + this.SoundOnEnter);

                        this.soundPlayerOnEnter = new SoundPlayer(s);
                    }

                    this.soundPlayerOnEnter.Play();
                }

                args.Hand.IsInteracting = true;
                if (this.Magnetic)
                {
                    // set the X and Y of the hand so it is centered over the button
                    var element = this.Content as FrameworkElement;

                    if (element != null)
                    {
                        var pt = new Point(element.ActualWidth / 2, element.ActualHeight / 2);
                        Point lockedPoint = element.PointToScreen(pt);
                        args.Hand.X = (int)lockedPoint.X;
                        args.Hand.Y = (int)lockedPoint.Y;
                    }

                    args.Hand.Magnetized = true;
                }

                var timer = new HandHoverTimer(DispatcherPriority.Normal, this.Dispatcher);
                timer.Hand = args.Hand;

                timer.Interval = TimeSpan.FromMilliseconds(Settings.Default.SelectionTime);
                timer.Tick += (o, s) => { this.InvokeHoverClick(args.Hand); };
                this.trackedHandHovers.Add(timer);
                timer.Start();
            }

            args.Handled = true;
        }