public TextBox(string text, Font font, Color4 color, int left, int top, int width, int height, UITextAlign halign, UIVerticalAlign valign, int voffset, TextType type) { m_Text = text; m_Font = font; m_Color = color; m_Left = left; m_Top = top; m_Width = width; m_Height = height; m_HAlign = halign; m_VAlign = valign; m_VerticalOffset = voffset; m_BoxType = type; m_CurrentBoxType = (type == TextType.Static) ? TextType.Static : TextType.Dynamic; }
public TextLine[] GetLines() { List <TextLine> lines = new List <TextLine>(); if (m_Font != null) { int curLeftWidth = 0, curCenterWidth = 0, curRightWidth = 0, curLineWidth = 0, curChunkWidth = 0; List <TextLine.Chunk> curLeftChunks = new List <TextLine.Chunk>(); List <TextLine.Chunk> curCenterChunks = new List <TextLine.Chunk>(); List <TextLine.Chunk> curRightChunks = new List <TextLine.Chunk>(); UITextAlign curAlign = m_HAlign; Color4 curColor = m_Color; StringBuilder curText = new StringBuilder(); StringBuilder curEscape = new StringBuilder(); byte state = 0; int pos = 0, len = m_Text.Length, spaceWidth = m_Font[' '].Width; char chr; StoreChunkDelegate storeChunk = () => { if (curText.Length == 0) { return; } TextLine.Chunk chunk = new TextLine.Chunk { Width = curChunkWidth, Color = curColor, Value = curText.ToString() }; if (curAlign == UITextAlign.Left) { curLeftChunks.Add(chunk); curLeftWidth += curChunkWidth; } else if (curAlign == UITextAlign.Center) { curCenterChunks.Add(chunk); curCenterWidth += curChunkWidth; } else { curRightChunks.Add(chunk); curRightWidth += curChunkWidth; } curLineWidth += curChunkWidth; curChunkWidth = 0; curText.Clear(); }; StoreLineDelegate storeLine = (storeEmpty) => { storeChunk(); if (!storeEmpty && curLineWidth == 0) { return; } lines.Add(new TextLine { LineWidth = curLineWidth, LeftWidth = curLeftWidth, CenterWidth = curCenterWidth, RightWidth = curRightWidth, LeftChunks = curLeftChunks.ToArray(), CenterChunks = curCenterChunks.ToArray(), RightChunks = curRightChunks.ToArray() }); curLineWidth = curLeftWidth = curCenterWidth = curRightWidth = 0; curLeftChunks.Clear(); curCenterChunks.Clear(); curRightChunks.Clear(); }; for (pos = 0; pos < len; pos++) { chr = m_Text[pos]; if (state == 0) { if (chr == '⌂') { state = 1; } else { if (chr == '\t') { curText.Append(" "); curChunkWidth += spaceWidth * 4; } else if (chr == '\n') { storeLine(true); } else if (chr != '\r') { curText.Append(chr); curChunkWidth += m_Font[chr].Width; } } } else { if (chr == '⌂') { state = 0; if (curEscape.Length == 0) { curText.Append('⌂'); curChunkWidth += m_Font['⌂'].Width; } else { string escapeStr = curEscape.ToString(); if (escapeStr.Equals("<")) { if (curAlign != UITextAlign.Left) { storeChunk(); curAlign = UITextAlign.Left; } } else if (escapeStr.Equals("|")) { if (curAlign != UITextAlign.Center) { storeChunk(); curAlign = UITextAlign.Center; } } else if (escapeStr.Equals(">")) { if (curAlign != UITextAlign.Right) { storeChunk(); curAlign = UITextAlign.Right; } } else { Color4 col; if (Color4.TryParse(escapeStr, out col) && !col.Equals(curColor)) { storeChunk(); curColor = col; } } } curEscape.Clear(); } else { curEscape.Append(chr); } } } storeLine(false); } return(lines.ToArray()); }
public TextBox(string text, Font font, Color4 color, int left, int top, int width, int height, UITextAlign halign, UIVerticalAlign valign, int voffset) : this(text, font, color, left, top, width, height, halign, valign, voffset, TextType.Auto) { }