public static FormattedLine operator +(FormattedLine a, PieceInfo piece) { FormattedLine nl = new FormattedLine(a); nl.Add(piece); return(nl); }
public static FormattedLine[] FormatLines(int width, string message, SpriteFont font) { List <FormattedLine> lines = new List <FormattedLine>(); // Do all requested line breaks int start = 0; int idx = message.IndexOf('\n'); while (idx >= 0) { string line = message.Substring(start, idx - start); start = idx + 1; lines.Add(new FormattedLine(line)); idx = message.IndexOf('\n', start); } lines.Add(new FormattedLine(message.Substring(start, message.Length - start))); // Now wrap all lines that are to long FormattedLine[] longLines = lines.ToArray(); lines = new List <FormattedLine>(); foreach (FormattedLine line in longLines) { Vector2 size = line.Size(font);//font.MeasureString(line); if (size.X > width) { // this line is to long, wrap it FormattedLine.PieceInfo[] words = line.Split(); FormattedLine smallLine = new FormattedLine(); foreach (FormattedLine.PieceInfo word in words) { FormattedLine testLine = smallLine + word; size = testLine.Size(font);//font.MeasureString(testLine); if (size.X > width) { // Adding this word doesnt fit, add a line break right before this word smallLine.Merge(); lines.Add(smallLine); smallLine = new FormattedLine(); smallLine.Add(word); } else { // This line still fits, keep going smallLine = testLine; } } smallLine.Merge(); lines.Add(smallLine); } else { // this line fits, just add it lines.Add(line); } } return(lines.ToArray()); }
FormattedLine(FormattedLine other) { List<PieceInfo> pieces = new List<PieceInfo>(); foreach (PieceInfo p in other.m_Pieces) { if (p.m_Str != null) pieces.Add(new PieceInfo(p.m_Str)); else pieces.Add(new PieceInfo(p.m_Icon)); } m_Pieces = pieces; }
FormattedLine(FormattedLine other) { List <PieceInfo> pieces = new List <PieceInfo>(); foreach (PieceInfo p in other.m_Pieces) { if (p.m_Str != null) { pieces.Add(new PieceInfo(p.m_Str)); } else { pieces.Add(new PieceInfo(p.m_Icon)); } } m_Pieces = pieces; }
public static FormattedLine operator +(FormattedLine a, PieceInfo piece) { FormattedLine nl = new FormattedLine(a); nl.Add(piece); return nl; }
public static FormattedLine[] FormatLines(int width, string message, SpriteFont font) { List<FormattedLine> lines = new List<FormattedLine>(); // Do all requested line breaks int start = 0; int idx = message.IndexOf('\n'); while (idx >= 0) { string line = message.Substring(start, idx - start); start = idx + 1; lines.Add(new FormattedLine(line)); idx = message.IndexOf('\n', start); } lines.Add(new FormattedLine(message.Substring(start, message.Length - start))); // Now wrap all lines that are to long FormattedLine[] longLines = lines.ToArray(); lines = new List<FormattedLine>(); foreach (FormattedLine line in longLines) { Vector2 size = line.Size(font);//font.MeasureString(line); if (size.X > width) { // this line is to long, wrap it FormattedLine.PieceInfo[] words = line.Split(); FormattedLine smallLine = new FormattedLine(); foreach (FormattedLine.PieceInfo word in words) { FormattedLine testLine = smallLine + word; size = testLine.Size(font);//font.MeasureString(testLine); if (size.X > width) { // Adding this word doesnt fit, add a line break right before this word smallLine.Merge(); lines.Add(smallLine); smallLine = new FormattedLine(); smallLine.Add(word); } else { // This line still fits, keep going smallLine = testLine; } } smallLine.Merge(); lines.Add(smallLine); } else { // this line fits, just add it lines.Add(line); } } return lines.ToArray(); }