public TextWordData(List <TextCharData> chars, TextCharData space) { Chars = new List <TextCharData>(chars); Newline = false; Space = space; }
public TextWordData(bool newline) { Chars = null; Newline = newline; Space = null; }
public void DrawLimitedString(int x, int y, int w, int h, FontSize size, Color[] colors, string s) { List <TextCharData> sentence = FormatString(s); List <TextWordData> words = new List <TextWordData>(); List <TextCharData> word = new List <TextCharData>(); for (int i = 0; i <= sentence.Count; i++) { TextCharData c = i < sentence.Count ? sentence[i] : TextCharData.Space(); if (i == sentence.Count || c.Character == ' ' || c.Newline) { if (word.Count > 0) { words.Add(new TextWordData(word, c)); word.Clear(); } if (c.Newline) { words.Add(new TextWordData(true)); } } else { word.Add(c); } } bool nextNewline = false; int x2 = 0; int y2 = 0; for (int i = 0; i < words.Count; i++) { if (words[i].Newline) { y2 += (int)size * 16; x2 = 0; } else { if (x2 + words[i].GetWidth(this) > w || nextNewline) { y2 += (int)size * 16; x2 = 0; nextNewline = false; } if (x2 + (int)size * (words[i].GetWidth(this) + words[i + 1].GetWidth(this)) > w) { // Don't draw space. nextNewline = true; } else if (i == words.Count - 1 || words[i + 1].Newline) { // Don't draw space. } else { // Draw space. words[i].Chars.Add(words[i].Space); } RenderFormattedString(x + x2, y + y2, size, colors, words[i].Chars); x2 += (int)size * words[i].GetWidth(this); } } }