示例#1
0
 private void loadDictionary()
 {
     using (System.IO.StreamReader sr = System.IO.File.OpenText("wordlist.txt"))
     {
         string s = "";
         while ((s = sr.ReadLine()) != null)
         {
             s = s.ToLowerInvariant();
             int          count       = 0;
             WordTreeNode currentNode = InitialNode;
             while (count < s.Length)
             {
                 WordTreeNode next = currentNode.HasChild(s[count]);
                 if (next == null)
                 {
                     next = new WordTreeNode(s[count], false);
                     currentNode.AddChild(next);
                 }
                 currentNode = next;
                 count++;
             }
             currentNode.AddChild(new WordTreeNode('!', false));
         }
     }
 }
 public void SetParent(WordTreeNode st)
 {
     parent = st;
     if (character == '!')
     {
         count++;
         parent.AddCount();
     }
 }
        public int CompareTo(Object obj)
        {
            if (obj.GetType().Equals(this.GetType()))
            {
                WordTreeNode other = (WordTreeNode)(obj);

                return(this.character.CompareTo(other.character));
            }
            else
            {
                return(1);
            }
        }
示例#4
0
        private void ConstructLetterLayout()
        {
            Letters = new List <Bubble>();

            //START TRIGRAM SORTING ----------------------------------------------------

            List <TrigramTrinaryNode> TrigramList = null;

            if (WordStack.Count >= 2)
            {
                string last    = WordStack.Pop();
                string twoback = WordStack.Peek();
                WordStack.Push(last);
                TrigramList = Trigram.GetList(twoback, last);
            }

            if (TrigramList == null)
            {
                TrigramList = new List <TrigramTrinaryNode>();
            }

            string WordSoFar = (string)(CenterBubble_Label.Content);

            List <WordTreeNode> TrigramChars = new List <WordTreeNode>();

            foreach (TrigramTrinaryNode ttn in TrigramList)
            {
                string word = Trigram.MainNodes[ttn.WordIndex].text;
                if (word.StartsWith(WordSoFar, true, null))
                {
                    char next = ' ';
                    if (word.Length > WordSoFar.Length)
                    {
                        next = word[WordSoFar.Length];
                    }
                    bool found = false;
                    foreach (WordTreeNode wtn in TrigramChars)
                    {
                        if (wtn.character == next)
                        {
                            wtn.count += (int)(ttn.frequency);
                            found      = true;
                        }
                    }
                    if (!found)
                    {
                        WordTreeNode newWtn = new WordTreeNode(next, false);
                        newWtn.count = (int)(ttn.frequency);
                        TrigramChars.Add(newWtn);
                    }
                }
            }

            //END TRIGRAM SORTING -----------------------------------------------------

            List <WordTreeNode> finalChars = new List <WordTreeNode>();

            while (finalChars.Count < Math.Min(9, TrigramChars.Count) && TrigramChars.Count > 0)
            {
                WordTreeNode max = TrigramChars[0];
                foreach (WordTreeNode t in TrigramChars)
                {
                    if (t.count > max.count)
                    {
                        max = t;
                    }
                }
                finalChars.Add(max);
                TrigramChars.Remove(max);
            }

            int count = 0;

            CurrentNode.children = Organize(CurrentNode.children);

            while (finalChars.Count < 9 && count < CurrentNode.children.Count)
            {
                char n = CurrentNode.children[count].character;
                if (n != '!')
                {
                    bool alreadyExists = false;
                    foreach (WordTreeNode wtn in finalChars)
                    {
                        if (n == wtn.character)
                        {
                            alreadyExists = true;
                        }
                    }
                    if (!alreadyExists)
                    {
                        finalChars.Add(CurrentNode.children[count]);
                    }
                }
                count++;
            }
            count = 0;
            while (finalChars.Count < 9)
            {
                char n             = InitialNode.children[count].character;
                bool alreadyExists = false;
                foreach (WordTreeNode wtn in finalChars)
                {
                    if (n == wtn.character)
                    {
                        alreadyExists = true;
                    }
                }
                if (!alreadyExists)
                {
                    finalChars.Add(new WordTreeNode(n, false));
                }
                count++;
            }

            WordTreeNode[]      placedChars = new WordTreeNode[9];
            List <WordTreeNode> placeLater  = new List <WordTreeNode>();

            for (int i = 0; i < 9; i++)
            {
                WordTreeNode wtn   = finalChars[i];
                int          place = -1;
                foreach (WordTreeNode a in PreviousCharacterLocation)
                {
                    if (wtn.character == a.character && Sticky.Content.Equals("Turn off Sticky"))
                    {
                        place = a.count;
                    }
                }
                if (place == -1)
                {
                    placeLater.Add(wtn);
                }
                else
                {
                    int ct = 0;
                    while (true)
                    {
                        int position = (((int)(Math.Pow((-1), (ct + 1)))) * ((ct + 1) / 2) + place) % 9;
                        while (position < 0)
                        {
                            position += 9;
                        }
                        ct++;
                        if (placedChars[position] == null)
                        {
                            placedChars[position] = wtn;
                            break;
                        }
                    }
                }
            }

            placeLater.Sort();

            foreach (WordTreeNode wtn in placeLater)
            {
                bool placed = false;
                int  ct     = 0;
                while (!placed)
                {
                    if (placedChars[ct] == null)
                    {
                        placedChars[ct] = wtn;
                        placed          = true;
                    }
                    ct++;
                }
            }

            //Now placedChars contains all the characters in the order they need to be placed -----------

            for (int i = 0; i < 9; i++)
            {
                WordTreeNode wtn     = placedChars[i];
                WordTreeNode listing = null;
                foreach (WordTreeNode position in PreviousCharacterLocation)
                {
                    if (position.character == wtn.character)
                    {
                        listing       = position;
                        listing.count = i;
                    }
                }
                if (listing != null)
                {
                    PreviousCharacterLocation.Remove(listing);
                    PreviousCharacterLocation.Insert(0, listing);
                }
                else
                {
                    WordTreeNode newwtn = new WordTreeNode(wtn.character, false);
                    newwtn.count = i;
                    PreviousCharacterLocation.Insert(0, newwtn);
                }
            }

            double cutTheta = 2 * Math.PI / 9;

            double greatestWords = int.MinValue;

            foreach (WordTreeNode w in placedChars)
            {
                greatestWords = (w.count > greatestWords) ? w.count : greatestWords;
            }


            for (int i = 0; i < 9; i++)
            {
                WordTreeNode wtn = placedChars[i];

                WordTreeNode fromNode = CurrentNode.HasChild(wtn.character);

                Letters.Add(new Bubble(theCanvas,
                                       new Point(Canvas.GetLeft(CenterBubble_Ellipse) + CenterBubble_Ellipse.Width / 2 + RADIUS[0] * Math.Sin(cutTheta * i), Canvas.GetTop(CenterBubble_Ellipse) + CenterBubble_Ellipse.Height / 2 + RADIUS[0] * -Math.Cos(cutTheta * i)),
                                       BUBBLERADIUS[0], fromNode != null ? Brushes.Yellow : Brushes.LightYellow, wtn.character, Bubble.RingStatus.INNER, 30 + (fromNode != null ? (int)(18 * fromNode.count / greatestWords) : 0)));
            }

            cutTheta = 2 * Math.PI / 27;
            for (int i = 0; i < 26; i++)
            {
                Letters.Add(new Bubble(theCanvas, new Point(Canvas.GetLeft(CenterBubble_Ellipse) + CenterBubble_Ellipse.Width / 2 + RADIUS[1] * Math.Sin(cutTheta * i), Canvas.GetTop(CenterBubble_Ellipse) + CenterBubble_Ellipse.Height / 2 + RADIUS[1] * -Math.Cos(cutTheta * i)),
                                       BUBBLERADIUS[1], CurrentNode.HasChild((char)((int)('a') + i)) != null ? Brushes.Yellow : Brushes.LightYellow, (char)((int)('a') + i), Bubble.RingStatus.OUTER, 24));
            }

            Letters.Add(new Bubble(theCanvas, new Point(Canvas.GetLeft(CenterBubble_Ellipse) + CenterBubble_Ellipse.Width / 2 + RADIUS[1] * Math.Sin(26 * cutTheta), Canvas.GetTop(CenterBubble_Ellipse) + CenterBubble_Ellipse.Height / 2 + RADIUS[1] * -Math.Cos(26 * -cutTheta)),
                                   BUBBLERADIUS[1], CurrentNode.HasChild('-') != null ? Brushes.Yellow : Brushes.LightYellow, '-', Bubble.RingStatus.OUTER, 24));
        }
示例#5
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 +
                                     "\" />");

                //Setup the default colors of the bubbles
                foreach (Bubble beta in Letters)
                {
                    if (CircleOver(beta.Ellipse))
                    {
                        beta.SetColor(Brushes.LawnGreen);
                    }
                    else
                    {
                        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))
                    {
                        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);
                        }
                        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)
                    {
                        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];

                        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;
                }
            }
        }
 public void AddChild(WordTreeNode st)
 {
     children.Add(st);
     st.SetParent(this);
 }
 public void SetParent(WordTreeNode st)
 {
     parent = st;
     if (character == '!')
     {
         count++;
         parent.AddCount();
     }
 }
 public void AddChild(WordTreeNode st)
 {
     children.Add(st);
     st.SetParent(this);
 }
示例#9
0
        private void ConstructLetterLayout()
        {
            Letters = new List<Bubble>();

            //START TRIGRAM SORTING ----------------------------------------------------

            List<TrigramTrinaryNode> TrigramList = null;
            if (WordStack.Count >= 2)
            {
                string last = WordStack.Pop();
                string twoback = WordStack.Peek();
                WordStack.Push(last);
                TrigramList = Trigram.GetList(twoback, last);
            }

            if (TrigramList == null)
            {
                TrigramList = new List<TrigramTrinaryNode>();
            }

            string WordSoFar = (string)(CenterBubble_Label.Content);

            List<WordTreeNode> TrigramChars = new List<WordTreeNode>();

            foreach (TrigramTrinaryNode ttn in TrigramList)
            {
                string word = Trigram.MainNodes[ttn.WordIndex].text;
                if (word.StartsWith(WordSoFar, true, null))
                {
                    char next = ' ';
                    if (word.Length > WordSoFar.Length)
                    {
                        next = word[WordSoFar.Length];
                    }
                    bool found = false;
                    foreach (WordTreeNode wtn in TrigramChars)
                    {
                        if (wtn.character == next)
                        {
                            wtn.count += (int)(ttn.frequency);
                            found = true;
                        }
                    }
                    if (!found)
                    {
                        WordTreeNode newWtn = new WordTreeNode(next, false);
                        newWtn.count = (int)(ttn.frequency);
                        TrigramChars.Add(newWtn);
                    }
                }
            }

            //END TRIGRAM SORTING -----------------------------------------------------

            List<WordTreeNode> finalChars = new List<WordTreeNode>();

            while (finalChars.Count < Math.Min(9, TrigramChars.Count) && TrigramChars.Count > 0)
            {
                WordTreeNode max = TrigramChars[0];
                foreach (WordTreeNode t in TrigramChars)
                {
                    if (t.count > max.count)
                        max = t;
                }
                finalChars.Add(max);
                TrigramChars.Remove(max);
            }

            int count = 0;

            CurrentNode.children = Organize(CurrentNode.children);

            while (finalChars.Count < 9 && count < CurrentNode.children.Count)
            {
                char n = CurrentNode.children[count].character;
                if (n != '!')
                {
                    bool alreadyExists = false;
                    foreach (WordTreeNode wtn in finalChars)
                    {
                        if (n == wtn.character)
                        {
                            alreadyExists = true;
                        }
                    }
                    if (!alreadyExists)
                    {
                        finalChars.Add(CurrentNode.children[count]);
                    }
                }
                count++;
            }
            count = 0;
            while (finalChars.Count < 9)
            {
                char n = InitialNode.children[count].character;
                bool alreadyExists = false;
                foreach (WordTreeNode wtn in finalChars)
                {
                    if (n == wtn.character)
                    {
                        alreadyExists = true;
                    }
                }
                if (!alreadyExists)
                {
                    finalChars.Add(new WordTreeNode(n, false));
                }
                count++;
            }

            WordTreeNode[] placedChars = new WordTreeNode[9];
            List<WordTreeNode> placeLater = new List<WordTreeNode>();

            for (int i = 0; i < 9; i++)
            {
                WordTreeNode wtn = finalChars[i];
                int place = -1;
                foreach (WordTreeNode a in PreviousCharacterLocation)
                {
                    if (wtn.character == a.character && Sticky.Content.Equals("Turn off Sticky"))
                    {
                        place = a.count;
                    }
                }
                if (place == -1)
                {
                    placeLater.Add(wtn);
                }
                else
                {
                    int ct = 0;
                    while (true)
                    {
                        int position = (((int)(Math.Pow((-1), (ct + 1)))) * ((ct + 1) / 2) + place) % 9;
                        while (position < 0)
                        {
                            position += 9;
                        }
                        ct++;
                        if (placedChars[position] == null)
                        {
                            placedChars[position] = wtn;
                            break;
                        }
                    }
                }
            }

            placeLater.Sort();

            foreach (WordTreeNode wtn in placeLater)
            {
                bool placed = false;
                int ct = 0;
                while (!placed)
                {
                    if (placedChars[ct] == null)
                    {
                        placedChars[ct] = wtn;
                        placed = true;
                    }
                    ct++;
                }
            }

            //Now placedChars contains all the characters in the order they need to be placed -----------

            for (int i = 0; i < 9; i++)
            {
                WordTreeNode wtn = placedChars[i];
                WordTreeNode listing = null;
                foreach (WordTreeNode position in PreviousCharacterLocation)
                {
                    if (position.character == wtn.character)
                    {
                        listing = position;
                        listing.count = i;
                    }
                }
                if (listing != null)
                {
                    PreviousCharacterLocation.Remove(listing);
                    PreviousCharacterLocation.Insert(0, listing);
                }
                else
                {
                    WordTreeNode newwtn = new WordTreeNode(wtn.character, false);
                    newwtn.count = i;
                    PreviousCharacterLocation.Insert(0, newwtn);
                }
            }

            double cutTheta = 2 * Math.PI / 9;

            double greatestWords = int.MinValue;
            foreach (WordTreeNode w in placedChars)
            {
                greatestWords = (w.count > greatestWords) ? w.count : greatestWords;
            }


            for (int i = 0; i < 9; i++)
            {
                WordTreeNode wtn = placedChars[i];

                WordTreeNode fromNode = CurrentNode.HasChild(wtn.character);

                Letters.Add(new Bubble(theCanvas,
                    new Point(Canvas.GetLeft(CenterBubble_Ellipse) + CenterBubble_Ellipse.Width / 2 + RADIUS[0] * Math.Sin(cutTheta * i), Canvas.GetTop(CenterBubble_Ellipse) + CenterBubble_Ellipse.Height / 2 + RADIUS[0] * -Math.Cos(cutTheta * i)),
                    BUBBLERADIUS[0], fromNode != null ? Brushes.Yellow : Brushes.LightYellow, wtn.character, Bubble.RingStatus.INNER, 30 + (fromNode != null ? (int)( 18 * fromNode.count / greatestWords) : 0)));
            }

            cutTheta = 2 * Math.PI / 27;
            for (int i = 0; i < 26; i++)
            {
                Letters.Add(new Bubble(theCanvas, new Point(Canvas.GetLeft(CenterBubble_Ellipse) + CenterBubble_Ellipse.Width / 2 + RADIUS[1] * Math.Sin(cutTheta * i), Canvas.GetTop(CenterBubble_Ellipse) + CenterBubble_Ellipse.Height / 2 + RADIUS[1] * -Math.Cos(cutTheta * i)),
                    BUBBLERADIUS[1], CurrentNode.HasChild((char)((int)('a') + i)) != null ? Brushes.Yellow : Brushes.LightYellow, (char)((int)('a') + i), Bubble.RingStatus.OUTER, 24));
            }

            Letters.Add(new Bubble(theCanvas, new Point(Canvas.GetLeft(CenterBubble_Ellipse) + CenterBubble_Ellipse.Width / 2 + RADIUS[1] * Math.Sin(26 * cutTheta), Canvas.GetTop(CenterBubble_Ellipse) + CenterBubble_Ellipse.Height / 2 + RADIUS[1] * -Math.Cos(26 * -cutTheta)),
                BUBBLERADIUS[1], CurrentNode.HasChild('-') != null ? Brushes.Yellow : Brushes.LightYellow, '-', Bubble.RingStatus.OUTER, 24));

        }
示例#10
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 +
                    "\" />");

                 //Setup the default colors of the bubbles
                foreach (Bubble beta in Letters)
                {
                    if (CircleOver(beta.Ellipse))
                    {
                        beta.SetColor(Brushes.LawnGreen);
                    }
                    else
                    {
                        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))
                    {
                        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);
                        }
                        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)
                    {
                        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];

                        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;
                }
            }
        }
示例#11
0
        private void loadDictionary()
        {

            using (System.IO.StreamReader sr = System.IO.File.OpenText("wordlist.txt"))
            {
                string s = "";
                while ((s = sr.ReadLine()) != null)
                {
                    s = s.ToLowerInvariant();
                    int count = 0;
                    WordTreeNode currentNode = InitialNode;
                    while (count < s.Length)
                    {
                        WordTreeNode next = currentNode.HasChild(s[count]);
                        if (next == null)
                        {
                            next = new WordTreeNode(s[count], false);
                            currentNode.AddChild(next);
                        }
                        currentNode = next;
                        count++;
                    }
                    currentNode.AddChild(new WordTreeNode('!', false));
                }
            }
        }