public TextSprite(TextSprite clone) { _name = clone._name + "_clone"; _transform = clone._transform; _tint = clone._tint; _hAlign = clone.HorizontalAlignment; _vAlign = clone.VerticalAlignment; _font = clone._font; _text = clone._text; _size = clone._size; _flipMode = clone._flipMode; }
public TextSpriteAnimationManager(TextSprite textSprite) { TextSprite = textSprite; ClockManager = new ClockManager(); }
protected void InitArrows() { _leftArrow = new TextSprite(string.Format("{0}_{1}", Name, "lArrow"), FontManager.MessageFont, "<"); _leftArrow.HorizontalAlignment = TextHorizontalAlignment.Center; _leftArrow.Position = new Vector2(-_arrowOffset, 0); _leftArrow.IsVisible = ShowArrows; _leftArrow.Load(); _rightArrow = new TextSprite(string.Format("{0}_{1}", Name, "rArrow"), FontManager.MessageFont, ">"); _rightArrow.HorizontalAlignment = TextHorizontalAlignment.Center; _rightArrow.Position = new Vector2(_arrowOffset + Size.X, 0); _rightArrow.IsVisible = ShowArrows; _rightArrow.Load(); AddChild(_leftArrow); AddChild(_rightArrow); }
protected override void InvalidateMeasure() { // No Text, Nothing to Build if (string.IsNullOrEmpty(Text)) { return; } Width = 0; textLines.Clear(); string[] lines = Text.Split('\n'); string line; for (int i = 0; i < lines.Length; i++) { line = lines[i]; if (float.IsNaN(MaxWidth) || Font.MeasureString(line).X * Scale.X <= MaxWidth) { TextSprite textSprite = new TextSprite(string.Format("{0}_{1}", Name, i), Font, line); textSprite.HorizontalAlignment = this.HorizontalAlignment; textSprite.VerticalAlignment = this.VerticalAlignment; textSprite.Load(); textLines.Add(textSprite); Width = Math.Max(Width, Font.MeasureString(line).X); } else { // break the text up into words string[] words = line.Split(' '); // add words until they go over the length int currentWord = 0; while (currentWord < words.Length) { int wordsThisLine = 0; string newLine = String.Empty; while (currentWord < words.Length) { string testLine = newLine; if (testLine.Length < 1) { testLine += words[currentWord]; } else if ((testLine[testLine.Length - 1] == '.') || (testLine[testLine.Length - 1] == '?') || (testLine[testLine.Length - 1] == '!')) { testLine += " " + words[currentWord]; } else { testLine += " " + words[currentWord]; } if (wordsThisLine > 0 && Font.MeasureString(testLine).X > MaxWidth) { break; } newLine = testLine; wordsThisLine++; currentWord++; } TextSprite textSprite = new TextSprite(string.Format("{0}_{1}", Name, i), Font, newLine); textSprite.HorizontalAlignment = this.HorizontalAlignment; textSprite.VerticalAlignment = this.VerticalAlignment; textSprite.Load(); textLines.Add(textSprite); Width = Math.Max(Width, Font.MeasureString(newLine).X); } } } }