private void AppendParagraph(string paragraph, string font, float scale, Vector4 color) { m_helperSb.Clear(); m_helperSb.Append(paragraph); float textWidth = MyGuiManager.MeasureString(font, m_helperSb, scale).X; // first we try append all paragraph to current line if (textWidth < m_currentLineRestFreeSpace) { ReallocateRichTexts(); m_richTextsPool[++m_richTextsOffset].Init(m_helperSb.ToString(), font, scale, color); AppendPart(m_richTextsPool[m_richTextsOffset]); } // if there is not enough free space in current line for whole paragraph else { ReallocateRichTexts(); m_richTextsPool[++m_richTextsOffset].Init("", font, scale, color); string[] words = paragraph.Split(m_wordSeparator); int currentWordIndex = 0; while (currentWordIndex < words.Length) { if (words[currentWordIndex].Trim().Length == 0) { currentWordIndex++; continue; } m_helperSb.Clear(); if (m_richTextsPool[m_richTextsOffset].Text.Length > 0) { m_helperSb.Append(m_wordSeparator); } m_helperSb.Append(words[currentWordIndex]); textWidth = MyGuiManager.MeasureString(font, m_helperSb, scale).X; if (textWidth <= m_currentLineRestFreeSpace - m_richTextsPool[m_richTextsOffset].Size.X) { m_richTextsPool[m_richTextsOffset].Append(m_helperSb.ToString()); currentWordIndex++; } else { // if this word is wider than line and it will be only one word at line, we add what fits and leave the rest for other lines if ((m_currentLine == null || m_currentLine.IsEmpty()) && m_richTextsPool[m_richTextsOffset].Text.Length == 0) { int numCharsThatFit = MyGuiManager.ComputeNumCharsThatFit(font, m_helperSb, scale, m_currentLineRestFreeSpace); m_richTextsPool[m_richTextsOffset].Append(words[currentWordIndex].Substring(0, numCharsThatFit)); words[currentWordIndex] = words[currentWordIndex].Substring(numCharsThatFit); } AppendPart(m_richTextsPool[m_richTextsOffset]); ReallocateRichTexts(); m_richTextsPool[++m_richTextsOffset].Init("", font, scale, color); if (currentWordIndex < words.Length) { AppendLine(); } } } if (m_richTextsPool[m_richTextsOffset].Text.Length > 0) { AppendPart(m_richTextsPool[m_richTextsOffset]); } } }