Ejemplo n.º 1
0
        /// <summary>
        /// Adds a gesture to the graph
        /// </summary>
        /// <param name="g">the gesture to add to the graph</param>
        public void AddGesture(Gesture g)
        {
            ReturnToRoot();
            //travel through tree, adding nodes as necessary
            int[] sequence = g.GetSequence();
            for (int i = 0; i < sequence.Length; i++)
            {
                if (!NextDirExists(sequence[i]))
                {
                    currentNode.leafNodes[sequence[i]] = new Node(null);
                    SelectNode(sequence[i]);
                }
                else
                {
                    SelectNode(sequence[i]);
                }
            }
            //will now be at the final node
            currentNode.gesture = g;

            //adds gesture to list of all gestures. Basically a lazy way of finding all gestures without traversing the tree
            if (g != null)
            {
                allGestures.Add(g);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes a gesture from the graph
        /// </summary>
        /// <param name="g">the gesture to remove from the graph</param>
        public void RemoveGesture(Gesture g)
        {
            ReturnToRoot();
            //travel through tree, adding nodes as necessary
            int[] sequence = g.GetSequence();
            for (int i = 0; i < sequence.Length; i++)
            {
                SelectNode(sequence[i]);
            }
            //will now be at the final node
            //remove the gesture
            currentNode.gesture = null;

            //remove gesture from list
            if (g != null)
            {
                allGestures.Remove(g);
            }
        }
Ejemplo n.º 3
0
        //
        /// <summary>
        /// creates a gesture based on the info provided by the user
        /// </summary>
        /// <param name="name">the name of the gesture</param>
        /// <param name="method">the method name for the gesture to invoke</param>
        /// <param name="seq">the movement sequence required to activate the gesture</param>
        private void CreateGesture(string name, string method, string description, int[] seq)
        {
            //validate input
            MethodInfo theMethod = typeof(Methods).GetMethod(method);
            bool isValid = true;
            if (theMethod == null) //method doesn't exist
            {
                MessageBox.Show("METHOD DOESN'T EXIST");
                isValid = false;
            }
            else if (name == "") //no gesture name entered
            {
                MessageBox.Show("NO NAME ENTERED");
                isValid = false;
            }
            else if (seq.Length == 0) //no sequence entered
            {
                MessageBox.Show("NO SEQUENCE ENTERED");
                isValid = false;
            }
            else
            {
                //make sure name and sequence don't match pre-existing gestures
                foreach (Gesture g in myGestures.ReturnAllGestures())
                {
                    if (g.GetName() == name) //name already exists
                    {
                        MessageBox.Show("A GESTURE WITH THIS NAME ALREADY EXISTS");
                        isValid = false;
                        break;
                    }
                    else if (g.GetSequence().Length == seq.Length) //test that the sequence isn't already in use
                    {
                        int[] gSeq = g.GetSequence();
                        isValid = false;
                        for (int i = 0; i < gSeq.Length; i++)
                        {
                            if (gSeq[i] != seq[i])
                            {
                                isValid = true;
                                break;
                            }
                        }
                        if (!isValid) //sequence already exists
                        {
                            MessageBox.Show("A GESTURE WITH THIS SEQUENCE ALREADY EXISTS");
                        }
                    }
                }
            }

            //input valid
            if(isValid)
            {
                //create gesture
                Gesture newGesture = new Gesture(name, method, description);
                newGesture.SetSequence(seq);
                myGestures.AddGesture(newGesture);

                //add new gesture to GestureListBox
                GestureListBox.Items.Add(name);

                //reset textboxes
                GestureMethodBox.Text = "";
                GestureNameBox.Text = "";
                GestureDescriptionBox.Text = "";
                //reset gesture sequence
                gestureSequenceCreationList = new LinkedList<int>();
                DisplayGestureSequence(GestureCreatorSequenceVar, gestureSequenceCreationList.ToArray());
                gestureSequenceCreationList.AddFirst(10);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Node constructor
 /// </summary>
 /// <param name="g">The gesture assigned to the Node</param>
 /// <param name="d">the direction of this node from the previous node</param>
 /// <param name="bNode">the previous node</param>
 public Node(Gesture g = null)
 {
     gesture = g;
     leafNodes = new Node[8];
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates the 'initialization' node
 /// </summary>
 private void InitializeNodes()
 {
     Gesture initialize = new Gesture("Initialize", "N/A", "Must be performed before any other gesture");
     initialize.SetSequence(new int[]{4, 0});
     myGestures.AddGesture(initialize);
     GestureListBox.Items.Add("Initialize");
 }