예제 #1
0
 public void UnregisterControl(IKinectUiControl control)
 {
     lock (controlDictionarySync)
     {
         controlDictionary.Remove(control.GetHashCode());
     }
 }
예제 #2
0
 public void RegisterControl(IKinectUiControl control)
 {
     lock (controlDictionarySync)
     {
         controlDictionary[control.GetHashCode()] = control;
     }
 }
예제 #3
0
 /// <summary>
 /// Captures the cursor, causing the UiService to notify the Kinect movement only to the KinectUiControl that is currently active, regardless of the hit testing process.
 /// </summary>
 /// <param name="element">Element that will capture the cursor.</param>
 public void CaptureCursor(IKinectUiControl element = null)
 {
     lock (isCursorCapturedSync)
     {
         currentActiveControl = element;
         isCursorCaptured     = true;
     }
 }
예제 #4
0
        /// <summary>
        /// Notifies the user interface registered controls based on the current state and the new position of the cursor position.
        /// </summary>
        /// <param name="normalizedX">New X position of the kinect cursor</param>
        /// <param name="normalizedY">New Y position of the kinect cursor</param>
        /// <param name="hasCursorPositionChanged">Boolean that indicates whether the normalizedX and normalizedY values are identical to the previous values</param>
        protected void UpdateControls(double normalizedX, double normalizedY, bool hasCursorPositionChanged)
        {
            UiDispatcher.BeginInvoke(new Action(() =>
            {
                var newActiveControl = GetActiveControl(normalizedX, normalizedY);

                if (newActiveControl == currentActiveControl)
                {
                    if (newActiveControl != null && hasCursorPositionChanged)
                    {
                        newActiveControl.TriggerCursorMove(new KinectUiEventArgs()
                        {
                            NormalizedX = normalizedX, NormalizedY = normalizedY
                        });
                    }
                    if (newActiveControl != null && newActiveControl.IsActivationEnabled)
                    {
                        var elapsed        = DateTime.Now - this.ActiveControlEnterTime;
                        var normalizedTime = Math.Min(1.0, elapsed.TotalMilliseconds / newActiveControl.ActivationTime.Value);
                        if (!IsControlActivated)
                        {
                            this.UpdateCursorsActivationProgress(normalizedTime);
                        }
                        if (normalizedTime == 1.0 && !IsControlActivated)
                        {
                            newActiveControl.TriggerActivation(new KinectUiEventArgs()
                            {
                                NormalizedX = normalizedX, NormalizedY = normalizedY
                            });
                            IsControlActivated = true;
                        }
                    }
                }
                else
                {
                    if (newActiveControl != null)
                    {
                        newActiveControl.TriggerCursorEnter(new KinectUiEventArgs()
                        {
                            NormalizedX = normalizedX, NormalizedY = normalizedY
                        });
                        this.ActiveControlEnterTime = DateTime.Now;
                    }

                    if (currentActiveControl != null)
                    {
                        currentActiveControl.TriggerCursorLeave(new KinectUiEventArgs()
                        {
                            NormalizedX = normalizedX, NormalizedY = normalizedY
                        });
                        this.StopCursorsActivationCountdown();
                    }
                    IsControlActivated = false;
                    this.UpdateCursorsActivationProgress(0.0);
                }
                currentActiveControl = newActiveControl;
            }));
        }
예제 #5
0
 public IKinectUiElementController Initialize(IKinectUiControl element)
 {
     this.associatedFrameworkElementReference = new WeakReference(element);
     this.AssociatedControl = element;
     if (AssociatedFrameworkElement == null)
     {
         throw new InvalidOperationException("IKinectUiControl must be a FrameworkElement");
     }
     this.KinectUiService.RegisterControl(this.AssociatedControl);
     return(this);
 }