public void GapBuffer_RealAndVirtualTest() { GapBuffer <int> buf = CreateTestGapBuffer(); Assert.AreEqual(26, buf.Count); Assert.AreEqual(17, buf.Gap); Assert.AreEqual(23, buf.AfterGap); Assert.AreEqual(6, buf.GapCount); Assert.AreEqual(32, buf.AllocatedCount); Assert.AreEqual(26, buf.Count); Assert.AreEqual(0, buf.ToReal(0)); Assert.AreEqual(16, buf.ToReal(16)); Assert.AreEqual(23, buf.ToReal(17)); Assert.AreEqual(32, buf.ToReal(26)); Assert.AreEqual(0, buf.ToVirtual(0)); Assert.AreEqual(16, buf.ToVirtual(16)); Assert.AreEqual(17, buf.ToVirtual(23)); Assert.AreEqual(26, buf.ToVirtual(32)); buf.Clear(); Assert.AreEqual(0, buf.Count); Assert.AreEqual(0, buf.ToReal(0)); Assert.AreEqual(0, buf.ToVirtual(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; } }