Пример #1
0
        private static GapBuffer <int> CreateTestGapBuffer()
        {
            GapBuffer <int> buf = new GapBuffer <int>();

            for (int i = 100; i < 125; i++)
            {
                buf.Add(i);
            }

            buf.Insert(16, 999);

            return(buf);
        }
Пример #2
0
        private void Manager_OnTextInput(object sender, TextInputEventArgs e)
        {
            bool NewLine = false; //Was a new line created?

            if (m_HasFocus)
            {
                if (m_Mode != TextEditMode.ReadOnly)
                {
                    if (m_NumLines > 1)
                    {
                        Vector2 MeasuredString = m_Font.MeasureString(GetCurrentLine());
                        //Check that text doesn't go beyond width of control...
                        if (((Position.X + MeasuredString.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;

                                RenderableText2 RenderTxt = new RenderableText2();
                                RenderTxt.Position = m_TextPosition;
                                RenderTxt.Text     = GetCurrentLine();
                                RenderTxt.Visible  = true;
                                m_Lines.Add(RenderTxt);
                                m_CurrentLine.Clear();

                                m_Cursor.Position.Y += m_Font.LineSpacing;
                                m_Cursor.LineIndex++;
                                m_Cursor.CharacterIndex = 0;
                                m_Cursor.Position.X     = Position.X;
                                NewLine = true;
                            }
                            else //Text went beyond the borders of the control...
                            {
                                RenderableText2 RenderTxt = new RenderableText2();
                                RenderTxt.Position = m_TextPosition;
                                RenderTxt.Text     = GetCurrentLine();
                                RenderTxt.Visible  = true;
                                m_Lines.Add(RenderTxt);
                                m_CurrentLine.Clear();

                                m_ScrollbarHeight -= m_Font.LineSpacing; //TODO: Resize scrollbar...

                                m_Cursor.LineIndex++;
                                m_Cursor.CharacterIndex = 0;
                                m_Cursor.Position.X     = Position.X;
                                NewLine = true;
                            }
                        }
                    }
                    else
                    {
                        //Text went beyond the borders of the control...
                        if (m_Font.MeasureString(Text).X >= (m_Size.X -
                                                             m_Font.MeasureString(e.Character.ToString()).X) && !m_RemovingTxt)
                        {
                            m_Cursor.Position.X = m_Size.X;

                            m_Renderer.ScrollTextLeft();
                        }
                    }

                    if (!m_IsUpperCase)
                    {
                        //If the cursor is in the middle of a line, replace the character.
                        if (m_Cursor.CharacterIndex < GetCurrentLine().Length)
                        {
                            m_CurrentLine.RemoveAt(m_Cursor.CharacterIndex);
                            m_Renderer.RemoveAt(m_Cursor.CharacterIndex);

                            m_CurrentLine.Insert(m_Cursor.CharacterIndex, e.Character.ToString());
                            m_Renderer.Insert(m_Cursor.CharacterIndex, e.Character.ToString());
                        }
                        else
                        {
                            m_CurrentLine.Add(e.Character.ToString());
                            m_Renderer.Insert(m_Cursor.CharacterIndex, e.Character.ToString());
                        }
                    }
                    else
                    {
                        //If the cursor is in the middle of a line, replace the character.
                        if (m_Cursor.CharacterIndex < GetCurrentLine().Length)
                        {
                            m_CurrentLine.RemoveAt(m_Cursor.CharacterIndex);
                            m_Renderer.RemoveAt(m_Cursor.CharacterIndex);

                            m_CurrentLine.Insert(m_Cursor.CharacterIndex, e.Character.ToString().ToUpper());
                            m_Renderer.Insert(m_Cursor.CharacterIndex, e.Character.ToString().ToUpper());
                        }
                        else
                        {
                            m_CurrentLine.Add(e.Character.ToString().ToUpper());
                            m_Renderer.Insert(m_Cursor.CharacterIndex, e.Character.ToString());
                        }
                    }
                }

                if (!NewLine)
                {
                    m_Cursor.CharacterIndex++;
                }

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