示例#1
0
        public void RunWordSearch()
        {
            if (TrackedSkeleton != null)
            {
                Joint MotionHandJoint       = (TrackedSkeleton.Joints[MotionHand]).ScaleTo(222, 1044);
                Joint MotionHandJointScaled = TrackedSkeleton.Joints[MotionHand].ScaleTo(1366, 768, 0.55f, 0.55f);

                Joint SelectionHandJoint       = (TrackedSkeleton.Joints[SelectionHand]).ScaleTo(222, 656);
                Joint SelectionHandJointScaled = (TrackedSkeleton.Joints[SelectionHand]).ScaleTo(1366, 768, 0.55f, 0.55f);
                Point MotionHandPosition       = new Point((MotionHandJointScaled.Position.X), (MotionHandJointScaled.Position.Y));
                Point SelectionHandPosition    = new Point((SelectionHandJointScaled.Position.X), (SelectionHandJointScaled.Position.Y));

                //Move Cursor
                //SetCursorPos((int)(MotionHandPosition.X), (int)(MotionHandPosition.Y));
                Point destination_top_left = theCanvas.PointFromScreen(MotionHandPosition);
                destination_top_left = Point.Add(destination_top_left, new System.Windows.Vector(Pointer_Ellipse.Width / -2, Pointer_Ellipse.Height / -2));
                Canvas.SetTop(Pointer_Ellipse, destination_top_left.Y);
                Canvas.SetLeft(Pointer_Ellipse, destination_top_left.X);

                //Added data position to a queue of positions that will be loaded for each letter
                PositionData.Enqueue("\r\n\t\t\t\t<entry motionhand_x=\"" + MotionHandPosition.X +
                                     "\" motionhand_y=\"" + MotionHandPosition.Y +
                                     "\" selectionhand_x=\"" + SelectionHandPosition.X +
                                     "\" selectionhand_y=\"" + SelectionHandPosition.Y +
                                     "\" relative_timestamp=\"" + DateTime.Now.Subtract(StartTime).TotalMilliseconds +
                                     "\" />");

                Gesture SelectionHandGesture = GestureTracker.track(TrackedSkeleton, TrackedSkeleton.Joints[SelectionHand], nui.NuiCamera.ElevationAngle);

                if (SelectionHandGesture != null && (SelectionHandGesture.id == GestureID.Push))
                {
                    foreach (System.Windows.Controls.Button beta in Buttons)
                    {
                        if (PointerOver(beta))
                        {
                            if ((((string)(beta.Content)).Equals(last_char) && DateTime.Now.Subtract(last_char_time).TotalSeconds > 0.75) || (!((string)(beta.Content)).Equals(last_char)))
                            {
                                SendKeys.SendWait(beta.Content.ToString().ToLowerInvariant());
                                CurrentWord += (beta.Content.ToString().ToLowerInvariant());
                                string letter = ("\r\n\t\t\t<print char=\"" + (beta.Content.ToString().ToLowerInvariant()) + "\" selection_hand_distance=\"" + SelectionHandDistance + "\" motion_hand_distance=\"" + MotionHandDistance +
                                                 "\"");
                                while (PositionData.Count > 0)
                                {
                                    letter += PositionData.Dequeue();
                                }
                                PositionData = new Queue <string>();
                                letter      += ("\r\n\t\t\t</print>");
                                WordData.Enqueue(letter);
                                SelectionHandDistance = 0.0;
                                MotionHandDistance    = 0.0;

                                last_char      = (string)(beta.Content);
                                last_char_time = DateTime.Now;
                            }
                        }
                    }
                    if (PointerOver(Button_Space))
                    {
                        if ((((string)(Button_Space.Content)).Equals(last_char) && DateTime.Now.Subtract(last_char_time).TotalSeconds > 0.75) || (!((string)(Button_Space.Content)).Equals(last_char)))
                        {
                            SendKeys.SendWait(" ");
                            string word = "\r\n\t\t<word text=\"" + CurrentWord + "\">";
                            CurrentWord = "";
                            while (WordData.Count > 0)
                            {
                                word += WordData.Dequeue();
                            }
                            word += "\r\n\t\t</word>";
                            SentenceData.Enqueue(word);
                            WordData       = new Queue <string>();
                            last_char      = (string)(Button_Space.Content);
                            last_char_time = DateTime.Now;
                        }
                    }
                    else if (PointerOver(Button_Backspace))
                    {
                        if ((last_char.Equals("bksp") && DateTime.Now.Subtract(last_char_time).TotalSeconds > 0.75) || (!last_char.Equals("bksp")))
                        {
                            SendKeys.SendWait("{Backspace}");
                            PositionData.Enqueue("\r\n\t\t\t\t<backspace motionhand_x=\"" + MotionHandPosition.X +
                                                 "\" motionhand_y=\"" + MotionHandPosition.Y +
                                                 "\" selectionhand_x=\"" + SelectionHandPosition.X +
                                                 "\" selectionhand_y=\"" + SelectionHandPosition.Y +
                                                 "\" relative_timestamp=\"" + DateTime.Now.Subtract(StartTime).TotalMilliseconds +
                                                 "\" />");
                            last_char      = "bksp";
                            last_char_time = DateTime.Now;
                        }
                    }
                }
            }
        }
示例#2
0
        public void RunWordSearch()
        {
            if (TrackedSkeleton != null)
            {
                Joint MotionHandJoint       = (TrackedSkeleton.Joints[MotionHand]).ScaleTo(222, 1044);
                Joint MotionHandJointScaled = TrackedSkeleton.Joints[MotionHand].ScaleTo(1366, 768, 0.55f, 0.55f);

                Joint SelectionHandJoint       = (TrackedSkeleton.Joints[SelectionHand]).ScaleTo(222, 656);
                Joint SelectionHandJointScaled = (TrackedSkeleton.Joints[SelectionHand]).ScaleTo(1366, 768, 0.55f, 0.55f);
                Point MotionHandPosition       = new Point((MotionHandJointScaled.Position.X), (MotionHandJointScaled.Position.Y));
                Point SelectionHandPosition    = new Point((SelectionHandJointScaled.Position.X), (SelectionHandJointScaled.Position.Y));

                //Move Cursor
                //SetCursorPos((int)(MotionHandPosition.X), (int)(MotionHandPosition.Y));
                Point destination_top_left = theCanvas.PointFromScreen(MotionHandPosition);

                if (selected.Count > 0)
                {
                    Pointer_Ellipse.Visibility = Visibility.Hidden;
                    int best = 0;

                    for (int i = 1; i < selected.Count; i++)
                    {
                        if (selected_time[i][1].Subtract(selected_time[i][0]).TotalDays > selected_time[best][1].Subtract(selected_time[best][0]).TotalDays)
                        {
                            best = i;
                        }
                    }

                    Bubble select = selected[best];
                    if (halo != null)
                    {
                        halo.RemoveFromParent();
                    }
                    halo        = select.ConstructClone(destination_top_left);
                    halo_parent = select;
                }
                else
                {
                    Pointer_Ellipse.Visibility = Visibility.Visible;
                    if (halo != null)
                    {
                        halo.RemoveFromParent();
                        halo        = null;
                        halo_parent = null;
                    }
                }
                destination_top_left = Point.Add(destination_top_left, new System.Windows.Vector(Pointer_Ellipse.Width / -2, Pointer_Ellipse.Height / -2));
                Canvas.SetTop(Pointer_Ellipse, destination_top_left.Y);
                Canvas.SetLeft(Pointer_Ellipse, destination_top_left.X);

                //Added data position to a queue of positions that will be loaded for each letter
                PositionData.Enqueue("\r\n\t\t\t\t<entry motionhand_x=\"" + MotionHandPosition.X +
                                     "\" motionhand_y=\"" + MotionHandPosition.Y +
                                     "\" selectionhand_x=\"" + SelectionHandPosition.X +
                                     "\" selectionhand_y=\"" + SelectionHandPosition.Y +
                                     "\" relative_timestamp=\"" + DateTime.Now.Subtract(StartTime).TotalMilliseconds +
                                     "\" />");

                //Setup the default colors of the bubbles
                foreach (Bubble beta in Letters)
                {
                    if (CurrentNode.HasChild(beta.Word()) != null)
                    {
                        beta.SetColor(Brushes.Yellow);
                    }
                    else
                    {
                        beta.SetColor(Brushes.LightYellow);
                    }
                }

                for (int i = 0; i < selected.Count; i++)
                {
                    if (!selected_off[i] && !CircleOver(selected[i].Ellipse))
                    {
                        selected_off[i]     = true;
                        selected_time[i][1] = DateTime.Now;
                    }
                    else if (!selected_off[i] && CircleOver(selected[i].Ellipse))
                    {
                        selected_time[i][1] = DateTime.Now;
                    }
                    else if (selected_off[i] && CircleOver(selected[i].Ellipse))
                    {
                        TimeSpan t = selected_time[i][1].Subtract(selected_time[i][0]);
                        selected_time[i][0] = DateTime.Now.Subtract(t);
                        selected_time[i][1] = DateTime.Now;
                        selected_off[i]     = false;
                    }
                }

                //Starting Case (only occurs once)
                if (SelectionHandLast == null)
                {
                    SelectionHandLast = SelectionHandPosition;
                }
                else
                {
                    //Measures the distance traveled by the selection hand
                    SelectionHandDistance += Point.Subtract(SelectionHandLast, SelectionHandPosition).Length;
                    SelectionHandLast      = SelectionHandPosition;
                }
                //Measures the distance traveled by the motion hand
                if (MotionHandLast == null)
                {
                    MotionHandLast = MotionHandPosition;
                }
                else
                {
                    MotionHandDistance += Point.Subtract(MotionHandLast, MotionHandPosition).Length;
                    MotionHandLast      = MotionHandPosition;
                }

                //foreach (Bubble beta in Letters)
                //{
                //    if (Shift)
                //    {
                //        beta.setText(beta.Word().ToString().ToUpperInvariant()[0]);
                //    }
                //    else
                //    {
                //        beta.setText(beta.Word().ToString().ToLowerInvariant()[0]);
                //    }
                //}

                Gesture MotionHandGesture    = keyboardGestureTracker.track(TrackedSkeleton, TrackedSkeleton.Joints[MotionHand], nui.NuiCamera.ElevationAngle);
                Gesture SelectionHandGesture = regularGestureTracker.track(TrackedSkeleton, TrackedSkeleton.Joints[SelectionHand], nui.NuiCamera.ElevationAngle);

                if (CircleOver(CenterBubble_Ellipse))
                {
                    ReturnedToCenter = true;

                    if (!EnterCenterFirst)
                    {
                        PositionData     = new Queue <string>();
                        EnterCenterFirst = true;
                    }
                    if (SelectionHandGesture != null && ((SelectionHandGesture.id == GestureID.SwipeLeft && SelectionHand == JointID.HandRight) || (SelectionHandGesture.id == GestureID.SwipeRight && SelectionHand == JointID.HandLeft)))
                    {
                        SendKeys.SendWait("{Backspace}");
                        if (CenterBubble_Label.Content.ToString().Length > 0)
                        {
                            CenterBubble_Label.Content = CenterBubble_Label.Content.ToString().Substring(0, CenterBubble_Label.Content.ToString().Length - 1);
                            CurrentNode = (CurrentNode.parent != null ? CurrentNode.parent : CurrentNode);
                        }
                        RemoveLayout();
                        ConstructLetterLayout();
                        PositionData.Enqueue("\r\n\t\t\t\t<backspace motionhand_x=\"" + MotionHandPosition.X +
                                             "\" motionhand_y=\"" + MotionHandPosition.Y +
                                             "\" selectionhand_x=\"" + SelectionHandPosition.X +
                                             "\" selectionhand_y=\"" + SelectionHandPosition.Y +
                                             "\" relative_timestamp=\"" + DateTime.Now.Subtract(StartTime).TotalMilliseconds +
                                             "\" />");
                    }
                    else if (SelectionHandGesture != null && SelectionHandGesture.id == GestureID.Push)
                    {
                        if (DateTime.Now.Subtract(last_space).TotalSeconds > 0.75)
                        {
                            RemoveLayout();
                            CurrentNode = InitialNode;
                            ConstructLetterLayout();
                            SendKeys.SendWait(" ");
                            WordStack.Push(CenterBubble_Label.Content.ToString());
                            string word = "\r\n\t\t<word text=\"" + WordStack.Peek() + "\">";
                            while (WordData.Count > 0)
                            {
                                word += WordData.Dequeue();
                            }
                            word += "\r\n\t\t</word>";
                            SentenceData.Enqueue(word);
                            WordData = new Queue <string>();
                            CenterBubble_Label.Content = "";
                            last_space = DateTime.Now;
                        }
                    }
                    //if ((SelectionHandGesture != null && SelectionHandGesture.id == GestureID.SwipeUp) || Shift == true)
                    //{
                    //    Shift = true;
                    //    foreach (Bubble beta in Letters)
                    //    {
                    //        beta.setText(beta.Word().ToString().ToUpperInvariant()[0]);
                    //    }
                    //}
                    //if ((SelectionHandGesture != null && SelectionHandGesture.id == GestureID.SwipeDown) || Shift == false)
                    //{
                    //    Shift = false;
                    //    foreach (Bubble beta in Letters)
                    //    {
                    //        beta.setText(beta.Word().ToString().ToLowerInvariant()[0]);
                    //    }
                    //}

                    if (selected.Count > 0 && MotionHandGesture != null && MotionHandGesture.id == GestureID.Still)
                    {
                        Bubble select = halo;

                        //Shift = false;
                        ReturnedToCenter = false;
                        char c = select.GetCharacter();
                        RemoveLayout();
                        WordTreeNode NextNode = CurrentNode.HasChild(c);
                        if (NextNode == null)
                        {
                            NextNode        = new WordTreeNode(c, false);
                            NextNode.parent = CurrentNode;
                        }
                        CurrentNode = NextNode;
                        ConstructLetterLayout();
                        SendKeys.SendWait(c.ToString());
                        CenterBubble_Label.Content = CenterBubble_Label.Content.ToString() + c.ToString();
                        string letter    = "";
                        string InnerRing = (select.r == Bubble.RingStatus.INNER ? "true" : (PreviousCharacterLocation.Contains(CurrentNode) ? "false" : "outside"));
                        letter += ("\r\n\t\t\t<print char=\"" + c + "\" selection_hand_distance=\"" + SelectionHandDistance + "\" motion_hand_distance=\"" + MotionHandDistance +
                                   "\" InnerRing=\"" + InnerRing + "\"");
                        while (PositionData.Count > 0)
                        {
                            letter += PositionData.Dequeue();
                        }
                        PositionData = new Queue <string>();
                        letter      += ("\r\n\t\t\t</print>");
                        WordData.Enqueue(letter);
                        SelectionHandDistance = 0.0;
                        MotionHandDistance    = 0.0;

                        if (CurrentNode.HasChild('!') != null)
                        {
                            CenterBubble_Ellipse.Fill = Brushes.AntiqueWhite;
                        }
                        else
                        {
                            CenterBubble_Ellipse.Fill = Brushes.GreenYellow;
                        }

                        selected      = new List <Bubble>();
                        selected_time = new List <DateTime[]>();
                        selected_off  = new List <bool> ();
                    }
                }
                // We can make changes to the layout
                if (ReturnedToCenter)
                {
                    if (MotionHandGesture.id == GestureID.Still)
                    {
                        foreach (Bubble beta in Letters)
                        {
                            if (CircleOver(beta.Ellipse) && !selected.Contains(beta))
                            {
                                selected.Add(beta);
                                DateTime[] arr = new DateTime[2];
                                arr[0] = DateTime.Now;
                                arr[1] = DateTime.Now;
                                selected_time.Add(arr);
                                selected_off.Add(false);
                            }
                            if (CurrentNode.HasChild(beta.Word()) != null)
                            {
                                beta.SetColor(Brushes.Yellow);
                            }
                            else
                            {
                                beta.SetColor(Brushes.LightYellow);
                            }
                        }
                    }
                }
            }

            if (DateTime.Now.Subtract(BlueFlash).TotalMilliseconds < 500)
            {
                CenterBubble_Ellipse.Fill = Brushes.LightBlue;
            }
            else
            {
                if (CurrentNode.HasChild('!') != null)
                {
                    CenterBubble_Ellipse.Fill = Brushes.AntiqueWhite;
                }
                else
                {
                    CenterBubble_Ellipse.Fill = Brushes.GreenYellow;
                }
            }

            if (halo_parent != null)
            {
                halo_parent.SetColor(Brushes.LightGreen);
            }
        }