/// <summary> /// Processes the Grid that the user is currently looking at /// </summary> /// <param name="index">The index of the current Grid</param> private void BorderProcessing(string index) { if (composition[composition.Length - 1] != index[0]) { composition += index; } if (!isBlocked) //if the environment is currently not blocked, the character for the current composition is generated { if (isBetsy) //if it's DEL, SPACE or . and the font is already changed { if (composition.Length == 3) { if (index == "6") //if it's a Delete Op { charToPrint = "V"; lbl_aux = (Label)FindName("min" + index); lbl_aux.Content = charToPrint; } else //if it's a '.' Op { charToPrint = "A"; lbl_aux = (Label)FindName("min" + index); lbl_aux.Content = charToPrint; } return; } else //mantain proper charToPrint for each element DEL SPACE . (V D A in Betsy) { lbl_aux = (Label)FindName("min" + index); lbl_aux.Content = charToPrint; } return; } if (composition.Length == 2 && index == "5") //if the first movement is \/ so the font has to change to Betsy { for (int i = 0; i <= 7; i++) { var obj = (Label)FindName("min" + i.ToString()); obj.FontFamily = new FontFamily(new Uri("pack://application:,,,/"), "./Fonts/#Betsy Flanagan 2"); } isBetsy = true; charToPrint = "D"; //space is set as character to be printed (D in betsy format) Label lbl = (Label)FindName("min" + index); lbl.Content = charToPrint; return; } if (composition.Length > 2 && index == composition.Substring(1, 1)) { blockType = 0; isCancelled = true; composition = "ii"; //character won't be written } try { //Prepare to print a character composed of 2 movements charToPrint = composition.Substring(1, 2); } catch { //Prepare to print a character composed of a single movement charToPrint = composition.Substring(1, 1); } charToPrint = CharacterDecoder.generateCharacter(charToPrint, blockType, primaryKeyboard); } else { charToPrint = "-"; //if it's blocked, the character - is print } //Prints the processed character if not blocked or '-' if blocked lbl_aux = (Label)FindName("min" + index); lbl_aux.Content = charToPrint; }
/// <summary> /// Processes the sequence of movements the user performed since the last centre focus /// </summary> private void centreProcessing() { keyboardTimer.Stop(); if (isBetsy) //changing back to the original font { for (int i = 0; i <= 7; i++) { var obj = (Label)FindName("min" + i.ToString()); obj.FontFamily = new FontFamily("Segoe UI"); } isBetsy = false; } string finalChar; lastPanel = ""; if (centreProcessed) //if the centre was already processed (no movement to the borders so far), no operation needed { return; } switch (blockType) { case 1: //Blocked to rest if (composition == "-12345" || composition == "-10765") { stateTransition.Play(); isBlocked = false; blockType = 0; //Restoring default UI locklogo.Visibility = System.Windows.Visibility.Hidden; txtInput.Visibility = System.Windows.Visibility.Visible; for (int i = 8; i < 35; i++) { var obj = (Label)FindName(labelNames[i]); obj.Visibility = System.Windows.Visibility.Visible; } for (int i = 0; i < 4; i++) { suggestionStackPanel[i].Visibility = Visibility.Visible; } } break; case 2: //Blocked to read full text if (composition == "-12345" || composition == "-10765") { stateTransition.Play(); isBlocked = false; blockType = 0; // Restoring default UI txtInput.Margin = new Thickness(txtInput.Margin.Left / textBoxMarginCoefW, txtInput.Margin.Top / textBoxMarginCoefH, txtInput.Margin.Right / textBoxMarginCoefW, txtInput.Margin.Bottom / textBoxMarginCoefH); for (int i = 8; i < 35; i++) { var obj = (Label)FindName(labelNames[i]); obj.Visibility = System.Windows.Visibility.Visible; } for (int i = 0; i < 4; i++) { suggestionStackPanel[i].Visibility = Visibility.Visible; } } break; case 3: if (composition == "-3") { stateTransition.Play(); isBlocked = false; blockType = 0; unblockingEvent(); } break; default: //No Block if (!isCancelled) { if (composition == "-") //if there was no movement to the extremities { goto didntLeaveCentre; //jumps all the character processing } if (composition == "-12345") { stateTransition.Play(); isBlocked = true; blockType = 1; // Blocking Screen to rest mode locklogo.Visibility = System.Windows.Visibility.Visible; txtInput.Visibility = System.Windows.Visibility.Hidden; for (int i = 8; i < 35; i++) { var obj = (Label)FindName(labelNames[i]); obj.Visibility = System.Windows.Visibility.Hidden; } for (int i = 0; i < 4; i++) { suggestionStackPanel[i].Visibility = Visibility.Hidden; } goto hasJustBeenBlocked; //jumps all the character processing } if (composition == "-10765") { stateTransition.Play(); isBlocked = true; blockType = 2; // Block Screen to read mode txtInput.Margin = new Thickness(txtInput.Margin.Left * textBoxMarginCoefW, txtInput.Margin.Top * textBoxMarginCoefH, txtInput.Margin.Right * textBoxMarginCoefW, txtInput.Margin.Bottom * textBoxMarginCoefH); for (int i = 8; i < 35; i++) { var obj = (Label)FindName(labelNames[i]); obj.Visibility = Visibility.Hidden; } for (int i = 0; i < 4; i++) { suggestionStackPanel[i].Visibility = Visibility.Hidden; } goto hasJustBeenBlocked; //jumps all the character processing } //suggestions' acceptance if (composition == "-701" || composition == "-107") { acceptSuggestion(0); goto acceptedSuggestion; } if (composition == "-123" || composition == "-321") { acceptSuggestion(1); goto acceptedSuggestion; } if (composition == "-567" || composition == "-765") { acceptSuggestion(2); goto acceptedSuggestion; } if (composition == "-345" || composition == "-543") { acceptSuggestion(3); goto acceptedSuggestion; } //No suggestion accepted, so go on... for (int i = 0; i < 4; i++) //Clear all the suggestion labels { //suggestionLabel[i].Content = ""; suggestionLabel[i].Text = ""; } try { //Prepare to print a character composed of 2 movements charToPrint = composition.Substring(1, 2); } catch { //Prepare to print a character composed of a single movement charToPrint = composition.Substring(1, 1); } //Process the "character to be concatenated" / "operation to be done" in the TextBox finalChar = CharacterDecoder.generateCharacter(charToPrint, blockType, primaryKeyboard); #region codigoDoColetor /* * //Data colector implementation below * if (!File.Exists(path)) * { * using (StreamWriter writer = new StreamWriter(path)) * { * writer.WriteLine("0"); // Tempo Total * writer.WriteLine("0"); // Caracteres Total * writer.WriteLine("0"); // Erros Total * writer.WriteLine(" "); // Vetor de erros * } * } * using(StreamReader readtext = new StreamReader(path)) * { * arquivo[0] = readtext.ReadLine(); * arquivo[1] = readtext.ReadLine(); * arquivo[2] = readtext.ReadLine(); * arquivo[3] = readtext.ReadLine(); * } * * if (colectorOn == true && finalChar != "ESPAÇO" && finalChar != "." && finalChar != "DEL") * { * caracteresTotal++; * } * * //Erro no coletor aqui! * * //if (colectorOn == true && finalChar == "DEL") * //{ * // erros++; * // arquivo[3] = arquivo[3] + ";" + txtInput.Text.Substring(txtInput.Text.Length - 1); * //} * * if (colectorOn == true && finalChar == "ESPAÇO" || finalChar == ".") * { * timer.Stop(); * colectorOn = false; * * int aux; * long aux2; * aux2 = Int32.Parse(arquivo[0]); * aux2 += timer.ElapsedMilliseconds; * arquivo[0] = aux2.ToString(); * * aux = Int32.Parse(arquivo[1]); * aux += caracteresTotal; * arquivo[1] = aux.ToString(); * * aux = Int32.Parse(arquivo[2]); * aux += erros; * arquivo[2] = aux.ToString(); * * caracteresTotal = 0; * erros = 0; * * } * * if (colectorOn == false && finalChar != "ESPAÇO" && finalChar != "." && finalChar != "DEL") * { * colectorOn = true; * timer.Start(); * caracteresTotal++; * } * * using (StreamWriter writer = new StreamWriter(path)) * { * writer.WriteLine(arquivo[0]); // Tempo Total * writer.WriteLine(arquivo[1]); // Caracteres Total * writer.WriteLine(arquivo[2]); // Erros Total * writer.WriteLine(arquivo[3]); // Vetor de erros * } */ #endregion // enteredCharacter1|number1(milliseconds)-enteredCharacter2|number2(milliseconds) characterTimestampRecord += "char|" + finalChar + "|" + dataTimer.ElapsedMilliseconds.ToString() + "\n"; switch (finalChar) { case "&": goto cancelledCharacter; case "ESPAÇO": finalChar = " "; txtInput.AppendText(finalChar); //append a space Suggester.indexWord(currentWord); currentWord = ""; break; case ".": if (txtInput.Text.Length == 0) { goto didntLeaveCentre; } nextIsUpper = true; if (txtInput.Text.Substring(txtInput.Text.Length - 1) == " ") { txtInput.Text = txtInput.Text.Substring(0, txtInput.Text.Length - 1); } txtInput.AppendText(finalChar + " "); Suggester.indexWord(currentWord); currentWord = ""; MessageBox.Show("pontofinal!"); isBlocked = true; blockType = 3; blockingEvent(txtInput.Text, dataTimer.ElapsedMilliseconds, numberOfDeletions); goto sentenceIsOver; case "DEL": string inputContent = txtInput.Text; string aux; numberOfDeletions++; try { aux = inputContent.Substring(0, inputContent.Length - 1); //delete a character. If it was in upper case, the next character to be written must be written in upper case too if (inputContent.Substring(inputContent.Length - 1) == ".") { nextIsUpper = false; } else { //if the last erased character was a space, do not uppercase the next letter to be inserted if (inputContent.LastIndexOf(" ") != inputContent.Length - 1) { if (inputContent.Substring(inputContent.Length - 1) == inputContent.Substring(inputContent.Length - 1).ToUpper()) { nextIsUpper = true; } if (currentWord.Length > 0) { currentWord = currentWord.Substring(0, currentWord.Length - 1); } } else //if it was a space, so the current word is the whole last word { //aux is the current text written without the last character (space in this case) try { //takes the last written word as current word currentWord = aux.Substring(aux.LastIndexOf(" ") + 1, aux.Length - aux.LastIndexOf(" ") - 1); } catch { currentWord = aux.Substring(0, aux.Length); } //if '.' is the last character, it must be removed too. if (aux[aux.Length - 1] == '.') { currentWord = currentWord.Substring(0, currentWord.Length - 1); aux = aux.Substring(0, aux.Length - 1); nextIsUpper = false; } } } addSuggestionsToLabels(); txtInput.Text = ""; txtInput.AppendText(aux); } catch { Console.WriteLine("txtInput is empty!"); } break; default: //if it's not space, '.' or delete operations, so the character must be simply added to the TextBox if (!nextIsUpper) { finalChar = finalChar.ToLower(); } txtInput.AppendText(finalChar); currentWord += finalChar; //currentWord receives the last char //TODO: fazer sons tocarem quando digitar jj e jjj em loop e parar quando digitar outro simbolo que não j. addSuggestionsToLabels(); nextIsUpper = false; //after the upper case letter has been already entered, the next one will be lower for sure break; } } else { isCancelled = !isCancelled; //the letter that was cancelled wasn't processed and the next may not be cancelled } break; //breaking the default case } acceptedSuggestion: didntLeaveCentre: hasJustBeenBlocked: cancelledCharacter: sentenceIsOver: txtInput.ScrollToEnd(); //always focus the end of the txtBox primaryKeyboard = true; composition = "-"; centreProcessed = true; }
/// <summary> /// Processes the sequence of movements the user performed since the last centre focus /// </summary> private void centreProcessing() { keyboardTimer.Stop(); if (isBetsy) //changing back to the original font { for (int i = 0; i <= 7; i++) { var obj = (Label)FindName("min" + i.ToString()); obj.FontFamily = new FontFamily("Segoe UI"); } isBetsy = false; } string finalChar; lastPanel = ""; if (centreProcessed) //if the centre was already processed (no movement to the borders so far), no operation needed { return; } switch (blockType) { case 1: //Blocked to rest if (composition == "-12345" || composition == "-10765") { stateTransition.Play(); isBlocked = false; blockType = 0; //Restoring default UI locklogo.Visibility = System.Windows.Visibility.Hidden; txtInput.Visibility = System.Windows.Visibility.Visible; for (int i = 8; i < 35; i++) { var obj = (Label)FindName(labelNames[i]); obj.Visibility = System.Windows.Visibility.Visible; } for (int i = 0; i < 4; i++) { suggestionStackPanel[i].Visibility = Visibility.Visible; } } break; case 2: //Blocked to read full text if (composition == "-12345" || composition == "-10765") { stateTransition.Play(); isBlocked = false; blockType = 0; // Restoring default UI txtInput.Margin = new Thickness(txtInput.Margin.Left / textBoxMarginCoefW, txtInput.Margin.Top / textBoxMarginCoefH, txtInput.Margin.Right / textBoxMarginCoefW, txtInput.Margin.Bottom / textBoxMarginCoefH); for (int i = 8; i < 35; i++) { var obj = (Label)FindName(labelNames[i]); obj.Visibility = System.Windows.Visibility.Visible; } for (int i = 0; i < 4; i++) { suggestionStackPanel[i].Visibility = Visibility.Visible; } } break; case 3: if (composition == "-3") { stateTransition.Play(); isBlocked = false; blockType = 0; unblockingEvent(); } break; default: //No Block if (!isCancelled) { if (composition == "-") //if there was no movement to the extremities { goto didntLeaveCentre; //jumps all the character processing } if (composition == "-12345") { stateTransition.Play(); isBlocked = true; blockType = 1; // Blocking Screen to rest mode locklogo.Visibility = System.Windows.Visibility.Visible; txtInput.Visibility = System.Windows.Visibility.Hidden; for (int i = 8; i < 35; i++) { var obj = (Label)FindName(labelNames[i]); obj.Visibility = System.Windows.Visibility.Hidden; } for (int i = 0; i < 4; i++) { suggestionStackPanel[i].Visibility = Visibility.Hidden; } goto hasJustBeenBlocked; //jumps all the character processing } if (composition == "-10765") { stateTransition.Play(); isBlocked = true; blockType = 2; // Block Screen to read mode txtInput.Margin = new Thickness(txtInput.Margin.Left * textBoxMarginCoefW, txtInput.Margin.Top * textBoxMarginCoefH, txtInput.Margin.Right * textBoxMarginCoefW, txtInput.Margin.Bottom * textBoxMarginCoefH); for (int i = 8; i < 35; i++) { var obj = (Label)FindName(labelNames[i]); obj.Visibility = Visibility.Hidden; } for (int i = 0; i < 4; i++) { suggestionStackPanel[i].Visibility = Visibility.Hidden; } goto hasJustBeenBlocked; //jumps all the character processing } //suggestions' acceptance if (composition == "-701" || composition == "-107") { acceptSuggestion(0); goto acceptedSuggestion; } if (composition == "-123" || composition == "-321") { acceptSuggestion(1); goto acceptedSuggestion; } if (composition == "-567" || composition == "-765") { acceptSuggestion(2); goto acceptedSuggestion; } if (composition == "-345" || composition == "-543") { acceptSuggestion(3); goto acceptedSuggestion; } //No suggestion accepted, so go on... for (int i = 0; i < 4; i++) //Clear all the suggestion labels { //suggestionLabel[i].Content = ""; suggestionLabel[i].Text = ""; } try { //Prepare to print a character composed of 2 movements charToPrint = composition.Substring(1, 2); } catch { //Prepare to print a character composed of a single movement charToPrint = composition.Substring(1, 1); } //Process the "character to be concatenated" / "operation to be done" in the TextBox finalChar = CharacterDecoder.generateCharacter(charToPrint, blockType, primaryKeyboard); // enteredCharacter1|number1(milliseconds)-enteredCharacter2|number2(milliseconds) characterTimestampRecord += "char|" + finalChar + "|" + dataTimer.ElapsedMilliseconds.ToString() + "\n"; switch (finalChar) { case "&": goto cancelledCharacter; case "ESPAÇO": finalChar = " "; //if (justAcceptedSuggestion) //if the last word was an accepted suggestion //{ // justAcceptedSuggestion = false; // nextWordInSentence(); //calls next word or sentence //} //else //{ justAddedSpace = true; if (txtInput.Text[txtInput.Text.Length - 1] != ' ') { //if there is no repeated space, calls next word or sentence nextWordInSentence(); } //} txtInput.AppendText(finalChar); //append a space Suggester.indexWord(currentWord); currentWord = ""; break; case ".": if (txtInput.Text.Length == 0) { goto didntLeaveCentre; } nextIsUpper = false; if (txtInput.Text.Substring(txtInput.Text.Length - 1) == " ") { txtInput.Text = txtInput.Text.Substring(0, txtInput.Text.Length - 1); } txtInput.AppendText(finalChar + " "); Suggester.indexWord(currentWord); justAcceptedSuggestion = false; justAddedSpace = false; nextWordInSentence(); currentWord = ""; break; //append a point and a space case "DEL": nDeletions++; string inputContent = txtInput.Text; string aux; try { if (justAcceptedSuggestion) { justAcceptedSuggestion = false; justAddedSpace = false; inputContent = textBeforeAcceptance + " "; //DIMINUIR O PESO DA CHOSENWORD } aux = inputContent.Substring(0, inputContent.Length - 1); //delete a character. If it was in upper case, the next character to be written must be written in upper case too if (inputContent.Substring(inputContent.Length - 1) == ".") { nextIsUpper = false; } else { //if the last erased character was a space, do not uppercase the next letter to be inserted if (inputContent.LastIndexOf(" ") != inputContent.Length - 1) { if (inputContent.Substring(inputContent.Length - 1) == inputContent.Substring(inputContent.Length - 1).ToUpper()) { nextIsUpper = false; } if (currentWord.Length > 0) { currentWord = currentWord.Substring(0, currentWord.Length - 1); } } else //if it was a space, so the current word is the whole last word { //aux is the current text written without the last character (space in this case) if (inputContent[inputContent.Length - 2] != ' ') { previousWordInSentence(); } try { //takes the last written word as current word currentWord = aux.Substring(aux.LastIndexOf(" ") + 1, aux.Length - aux.LastIndexOf(" ") - 1); } catch { currentWord = aux.Substring(0, aux.Length); } //if '.' is the last character, it must be removed too. if (aux[aux.Length - 1] == '.') { currentWord = currentWord.Substring(0, currentWord.Length - 1); aux = aux.Substring(0, aux.Length - 1); nextIsUpper = false; } } } addSuggestionsToLabels(); txtInput.Text = ""; txtInput.AppendText(aux); } catch { Console.WriteLine("txtInput is empty!"); } break; default: //if it's not space, '.' or delete operations, so the character must be simply added to the TextBox justAcceptedSuggestion = false; justAddedSpace = false; if (!nextIsUpper) { finalChar = finalChar.ToLower(); } txtInput.AppendText(finalChar); currentWord += finalChar; //currentWord receives the last char //TODO: fazer sons tocarem quando digitar jj e jjj em loop e parar quando digitar outro simbolo que não j. addSuggestionsToLabels(); nextIsUpper = false; //after the upper case letter has been already entered, the next one will be lower for sure break; } } else { isCancelled = !isCancelled; //the letter that was cancelled wasn't processed and the next may not be cancelled } break; //breaking the default case } acceptedSuggestion: didntLeaveCentre: hasJustBeenBlocked: cancelledCharacter: txtInput.ScrollToEnd(); //always focus the end of the txtBox primaryKeyboard = true; composition = "-"; centreProcessed = true; }