public void AttemptWriteChar(char c) { int row = Cursor.Row; int column = Cursor.Column; BrailleCharacter newChar = GetBrailleCharacter(c); if (newChar != null) { int symbolCount = Symbols[row].Count; //Primary check if room available if (symbolCount < CHARACTER_COLUMNS) { //Find current character index or select last one List <BrailleCharacter> characters = Characters[row]; if (characters.Count == 0) { characters.Add(newChar); RecalculateSymbolSlots(row); AttemptCursorPositionOffset(0, newChar.GetSymbols(BlankCharacter, BlankCharacter, BlankCharacter).Count); DataChanged(); return; } else { BrailleSymbolSlotPosition previous = GetSymbolSlotPositionBefore(); //Calculate new list of symbol slot position and check if it fits List <BrailleCharacter> newCharacters = characters.ToList(); int index = previous != null ? previous.i + 1 : 0; newCharacters.Insert(index, newChar); int newSymbolsCount = GetNewSymbolSlots(newCharacters).Count; if (newSymbolsCount <= CHARACTER_COLUMNS) { Characters[row] = newCharacters; RecalculateSymbolSlots(row); AttemptCursorPositionChange(row, GetLastSymbolFromCharacterColumn(index, row)); DataChanged(); return; } } } } }
private void CharacterList_SelectionChanged(object sender, SelectionChangedEventArgs e) { char character = ((char)((ListViewItem)CharacterList.SelectedItem).Content); this.Character.Text = character.ToString(); BrailleCharacter braille = GetBrailleCharacter(character); List <BrailleSymbolSlot> slots = braille.GetSymbols(BlankCharacter, BlankCharacter, BlankCharacter); if (slots.Count == 1) { this.firstSymbol.UpdateDots(slots[0].GetSymbol().Points); this.secondSymbol.DotCanvas.Visibility = Visibility.Collapsed; } if (slots.Count == 2) { this.firstSymbol.UpdateDots(slots[0].GetSymbol().Points); this.secondSymbol.DotCanvas.Visibility = Visibility.Visible; this.secondSymbol.UpdateDots(slots[1].GetSymbol().Points); } }