Exemple #1
0
        private List <BrailleSymbolSlotPosition> GetNewSymbolSlots(List <BrailleCharacter> characters)
        {
            List <BrailleSymbolSlotPosition> symbols = new List <BrailleSymbolSlotPosition>();
            int i      = 0;
            int length = characters.Count;
            BrailleCharacter before       = BlankCharacter;
            BrailleCharacter beforebefore = BlankCharacter;
            BrailleCharacter after;

            foreach (BrailleCharacter character in characters)
            {
                if (i < length - 1)
                {
                    after = characters[i + 1];
                }
                else
                {
                    after = BlankCharacter;
                }

                foreach (BrailleSymbolSlot slot in character.GetSymbols(beforebefore, before, after))
                {
                    BrailleSymbolSlotPosition s = new BrailleSymbolSlotPosition(slot, 0, i);
                    symbols.Add(s);
                }

                //Next
                beforebefore = before;
                before       = character;
                i++;
            }
            return(symbols);
        }
Exemple #2
0
 public void SetSymbolAtPosition(int row, int column, BrailleSymbolSlotPosition symbol)
 {
     if (symbol != null)
     {
         BrailleSymbolSlot slot = symbol.Symbol;
         setLetter(row, column, slot.DisplayLettter);
         setFillerCase(row, column, slot.Filler);
     }
     else
     {
         setLetter(row, column, ' ');
         setFillerCase(row, column, false);
     }
 }
Exemple #3
0
        private void RecalculateSymbolSlots(int row)
        {
            List <BrailleCharacter>          characters = Characters[row];
            List <BrailleSymbolSlotPosition> symbols    = new List <BrailleSymbolSlotPosition>();
            int i      = 0;
            int length = characters.Count;
            BrailleCharacter before       = BlankCharacter;
            BrailleCharacter beforebefore = BlankCharacter;
            BrailleCharacter after;

            int symbolCountBefore = Symbols[row].Count;
            int k = 0;

            foreach (BrailleCharacter character in characters)
            {
                if (i < length - 1)
                {
                    after = characters[i + 1];
                }
                else
                {
                    after = BlankCharacter;
                }

                foreach (BrailleSymbolSlot slot in character.GetSymbols(beforebefore, before, after))
                {
                    BrailleSymbolSlotPosition s = new BrailleSymbolSlotPosition(slot, row, i);
                    symbols.Add(s);

                    //Directly update graphics for performance
                    SetSymbolAtPosition(row, k, s);
                    k++;
                }

                //Next
                beforebefore = before;
                before       = character;
                i++;
            }
            Symbols[row] = symbols;

            for (int j = k; j < symbolCountBefore; j++)
            {
                SetSymbolAtPosition(row, j, null);
            }
        }
Exemple #4
0
        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;
                        }
                    }
                }
            }
        }
Exemple #5
0
        public void AttemptSplitLine()
        {
            //If last line empty
            bool isLastEmpty = true;

            foreach (BrailleCharacter c in Characters[CHARACTER_ROWS - 1])
            {
                if (c.Type != BrailleCharacterType.WHITESPACE)
                {
                    isLastEmpty = false;
                    break;
                }
            }

            if (isLastEmpty && Cursor.Row < CHARACTER_ROWS - 1)
            {
                List <BrailleCharacter> remaining = Characters[Cursor.Row];
                List <BrailleCharacter> cut       = new List <BrailleCharacter>();

                //If cursor is at eol
                BrailleSymbolSlotPosition s = GetSymbolSlotPositionCurrent();
                if (s != null)
                {
                    int characterIndex = s.i;
                    remaining = Characters[Cursor.Row].GetRange(0, s.i);
                    cut       = Characters[Cursor.Row].GetRange(s.i, Characters[Cursor.Row].Count - s.i);
                }

                for (int i = CHARACTER_ROWS - 1; i > Cursor.Row; i--)
                {
                    Characters[i] = Characters[i - 1];
                }

                Characters[Cursor.Row]     = remaining;
                Characters[Cursor.Row + 1] = cut;

                AttemptCursorPositionChange(Cursor.Row + 1, 0);
                for (int i = 0; i < CHARACTER_ROWS; i++)
                {
                    RecalculateSymbolSlots(i);
                }

                DataChanged();
            }
        }
Exemple #6
0
        public void AttemptEraseBack()
        {
            BrailleSymbolSlotPosition symbol = GetSymbolSlotPositionBefore();

            if (symbol != null && symbol.Symbol.Filler)
            {
                AttemptCursorPositionOffset(0, -1);
            }
            else if (symbol == null && Cursor.Row > 0)
            {
                if (Symbols[Cursor.Row - 1].Count == 0)
                {
                    for (int i = Cursor.Row - 1; i < CHARACTER_ROWS - 1; i++)
                    {
                        Characters[i] = Characters[i + 1];
                    }
                    Characters[CHARACTER_ROWS - 1] = new List <BrailleCharacter>();
                    AttemptCursorPositionChange(Cursor.Row - 1, CHARACTER_COLUMNS);

                    for (int i = Cursor.Row; i < CHARACTER_ROWS; i++)
                    {
                        RecalculateSymbolSlots(i);
                    }
                }
                else if (Symbols[Cursor.Row].Count == 0)
                {
                    for (int i = Cursor.Row; i < CHARACTER_ROWS - 1; i++)
                    {
                        Characters[i] = Characters[i + 1];
                    }
                    AttemptCursorPositionChange(Cursor.Row - 1, CHARACTER_COLUMNS);
                    for (int i = Cursor.Row; i < CHARACTER_ROWS; i++)
                    {
                        RecalculateSymbolSlots(i);
                    }
                }

                DataChanged();
            }
            else if (symbol != null)
            {
                int row = symbol.row;
                Characters[row].RemoveAt(symbol.i);
                RecalculateSymbolSlots(row);

                if (symbol.i == 0)
                {
                    AttemptCursorPositionChange(row, 0);
                }
                else if (Characters[row].Count >= symbol.i)
                {
                    AttemptCursorPositionChange(row, GetLastSymbolFromCharacterColumn(symbol.i - 1, row));
                }
                else if (Characters[row].Count > 0)
                {
                    AttemptCursorPositionChange(row, Characters[row].Count);
                }

                DataChanged();
            }
        }
Exemple #7
0
        private bool IsSymbolOffsetFiller(int o, int row, int column)
        {
            BrailleSymbolSlotPosition s = getSymbolSlotPosition(o, row, column);

            return(s == null ? false : s.Symbol.Filler);
        }