Gonzo.Elements.UITextEdit.Manager_OnTextInput C# (CSharp) Method

Manager_OnTextInput() private method

private Manager_OnTextInput ( object sender, Microsoft.Xna.Framework.TextInputEventArgs e ) : void
sender object
e Microsoft.Xna.Framework.TextInputEventArgs
return void
        private void Manager_OnTextInput(object sender, TextInputEventArgs e)
        {
            if (m_HasFocus)
            {
                if (m_Mode != TextEditMode.ReadOnly)
                {
                    if (m_NumLines > 1)
                    {
                        //Check that text doesn't go beyond width of control...
                        if ((m_Font.MeasureString(m_Lines[m_Cursor.LineIndex].SBuilder.ToString()).X >=
                            m_Size.X) && !m_RemovingTxt && !m_MovingCursor)
                        {
                            if (m_TextPosition.Y <= Position.Y + ((m_NumLines - 2) * m_Font.LineSpacing))
                            {
                                m_TextPosition.Y += m_Font.LineSpacing;
                                m_Lines.Add(new RenderableText() { SBuilder = new StringBuilder(), Position = m_TextPosition });

                                m_Cursor.Position.Y += m_Font.LineSpacing;
                                m_Cursor.LineIndex++;
                                m_Cursor.CharacterIndex = 0;
                            }
                            else //Text went beyond the borders of the control...
                            {
                                foreach (RenderableText Txt in m_Lines)
                                    Txt.Position.Y -= m_Font.LineSpacing;

                                m_Lines.Add(new RenderableText() { SBuilder = new StringBuilder(), Position = m_TextPosition });
                                m_ScrollbarHeight -= m_Font.LineSpacing; //TODO: Resize scrollbar...

                                m_Cursor.LineIndex++;
                                m_Cursor.CharacterIndex = 0;

                                m_Lines[m_VisibilityIndex].Visible = false;
                                m_VisibilityIndex++;
                            }

                            m_Cursor.Position.X = Position.X;
                        }
                    }
                    else
                    {
                        //Text went beyond the borders of the control...
                        if (m_Font.MeasureString(CurrentInput).X >= (m_Size.X -
                            m_Font.MeasureString(e.Character.ToString()).X) && !m_RemovingTxt)
                        {
                            m_Lines.Add(new RenderableText() { SBuilder = new StringBuilder(), Position = m_Cursor.Position, Visible = true });
                            m_Cursor.Position.X = m_Size.X;
                            //In a single line control, each "line" will hold one character.
                            m_Cursor.LineIndex++;

                            foreach (RenderableText Txt in m_Lines)
                            {
                                Txt.Position.X -= m_Font.MeasureString(e.Character.ToString()).X;

                                if (Txt.Position.X < Position.X)
                                    Txt.Visible = false;
                            }
                        }
                        else
                        {
                            m_Lines.Add(new RenderableText() { SBuilder = new StringBuilder(), Position = m_Cursor.Position, Visible = true});
                            //In a single line control, each "line" will hold one character.
                            m_Cursor.LineIndex++;
                        }
                    }
                }

                if (!m_IsUpperCase)
                {
                    //If the cursor is in the middle of a line, replace the character.
                    if (m_NumLines > 1)
                    {
                        if (m_Cursor.CharacterIndex < m_Lines[m_Cursor.LineIndex].SBuilder.Length)
                            m_Lines[m_Cursor.LineIndex].SBuilder[m_Cursor.CharacterIndex] = e.Character;
                        else
                            m_Lines[m_Cursor.LineIndex].SBuilder.Append(e.Character);
                    }
                    else
                    {
                        if (m_Cursor.CharacterIndex < CurrentInput.Length)
                            m_Lines[m_Cursor.LineIndex].SBuilder[0] = e.Character;
                        else
                        {
                            RenderableText Txt = new RenderableText();
                            Txt.SBuilder = new StringBuilder(e.Character.ToString());
                            Txt.Position = m_Cursor.Position;
                            Txt.Visible = true;
                            m_Lines.Insert(m_Cursor.LineIndex, Txt);
                        }
                    }
                }
                else
                {
                    if (m_NumLines > 1)
                    {
                        //If the cursor is in the middle of a line, replace the character.
                        if (m_Cursor.CharacterIndex < m_Lines[m_Cursor.LineIndex].SBuilder.Length)
                            m_Lines[m_Cursor.LineIndex].SBuilder[m_Cursor.CharacterIndex] = e.Character.ToString().ToUpper().ToCharArray()[0];
                        else
                            m_Lines[m_Cursor.LineIndex].SBuilder.Append(e.Character.ToString().ToUpper());
                    }
                    else
                    {
                        if ((m_Cursor.CharacterIndex < CurrentInput.Length) && m_MovingCursor)
                            m_Lines[m_Cursor.LineIndex].SBuilder[0] = e.Character;
                        else
                        {
                            RenderableText Txt = new RenderableText();
                            Txt.SBuilder = new StringBuilder(e.Character.ToString().ToUpper());
                            Txt.Position = m_Cursor.Position;
                            Txt.Visible = true;
                            m_Lines.Insert(m_Cursor.LineIndex, Txt);
                        }
                    }
                }

                m_Cursor.CharacterIndex++;
                m_RemovingTxt = false;
                m_MovingCursor = false;
                m_Cursor.Position.X += m_Font.MeasureString(e.Character.ToString()).X;
            }
        }