public TextBox(Texture2D texture, V2DInstance inst) : base(texture, inst) { if (inst.Definition is V2DText) { sb = new StringBuilder(); V2DText t = (V2DText)inst.Definition; textAtoms = new List<TextAtom>(); for (int i = 0; i < t.TextRuns.Count; i++) { TextAtom ta = new TextAtom(this.X, this.Y, t.TextRuns[i]); textAtoms.Add(ta); sb.Append(ta.Text); } RecreateTextRuns(); } }
//private void EnsureTextRuns() //{ // for (int i = 0; i < textRuns.Count; i++) // { // TextAtom tr = textRuns[i]; // tr.XnaText = tr.Text; // tr.XnaFont = FontManager.Instance.GetFont(tr.FontName); // tr.XnaOrigin = new Microsoft.Xna.Framework.Vector2(X + tr.Left, Y + tr.Top); // uint c = tr.Color; // byte a = (byte)(c >> 24); // byte r = (byte)(c >> 16); // byte g = (byte)(c >> 8); // byte b = (byte)(c >> 0); // tr.XnaColor = new Color(r, g, b, a); // } //} private void RecreateTextRuns() { // todo: html, spacing, multiline etc etc if (textAtoms == null) { textAtoms = new List<TextAtom>(); } TextAtom ta = null; if(textAtoms.Count > 0) { ta = textAtoms[0]; } textAtoms.Clear(); if (ta == null) { ta = new TextAtom(); ta.FontName = FontManager.Instance.defaultFontName; ta.Font = FontManager.Instance.GetFont(ta.FontName); //ta.Origin = new Microsoft.Xna.Framework.Vector2(X + ta.Left, Y + ta.Top); ta.Origin = ta.TopLeft; ta.Color = color; } ta.Text = sb.ToString(); if (ta.Align == TextAlign.Center) { Vector2 tw = ta.Font.MeasureString(ta.Text); ta.TopLeft.X = (DefinedWidth() - ta.Font.MeasureString(ta.Text).X) / 2; } else if (ta.Align == TextAlign.Right) { ta.TopLeft.X = (DefinedWidth() - ta.Font.MeasureString(ta.Text).X); } textAtoms.Add(ta); }