public Vector2 MeasureString(StringBuilder text) { SpriteFont.CharacterSource text1 = new SpriteFont.CharacterSource(text); Vector2 size; this.MeasureString(ref text1, out size); return size; }
/// <summary> /// Submit a text string of sprites for drawing in the current batch. /// </summary> /// <param name="spriteFont">A font.</param> /// <param name="text">The text which will be drawn.</param> /// <param name="position">The drawing location on screen.</param> /// <param name="color">A color mask.</param> /// <param name="rotation">A rotation of this string.</param> /// <param name="origin">Center of the rotation. 0,0 by default.</param> /// <param name="scale">A scaling of this string.</param> /// <param name="effects">Modificators for drawing. Can be combined.</param> /// <param name="layerDepth">A depth of the layer of this string.</param> public void DrawString( SpriteFont spriteFont, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { CheckValid(spriteFont, text); var source = new SpriteFont.CharacterSource(text); spriteFont.DrawInto(this, ref source, position, color, rotation, origin, scale, effects, layerDepth); }
public void DrawString( SpriteFont spriteFont, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float depth) { CheckValid(spriteFont, text); var scaleVec = new Vector2(scale, scale); var source = new SpriteFont.CharacterSource(text); spriteFont.DrawInto(this, ref source, position, color, rotation, origin, scaleVec, effects, depth); }
public void DrawString( SpriteFont spriteFont, StringBuilder text, Vector2 position, Color color ) { CheckValid(spriteFont, text); SpriteFont.CharacterSource source = new SpriteFont.CharacterSource(text); spriteFont.DrawInto( this, ref source, position, color, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f ); }
public void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effect, float depth) { this.CheckValid(spriteFont, text); SpriteFont.CharacterSource text1 = new SpriteFont.CharacterSource(text); spriteFont.DrawInto(this, ref text1, position, color, rotation, origin, scale, effect, depth); }
public void DrawString(SpriteFont spriteFont, string text, Vector2 position, Color color) { this.CheckValid(spriteFont, text); SpriteFont.CharacterSource text1 = new SpriteFont.CharacterSource(text); spriteFont.DrawInto(this, ref text1, position, color, 0.0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0.0f); }
public void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2 position, Color color) { this.CheckValid(spriteFont, text); SpriteFont.CharacterSource text1 = new SpriteFont.CharacterSource(text); spriteFont.DrawInto(this, ref text1, position, color, 0.0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0.0f); }
public void DrawString ( SpriteFont spriteFont, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float depth) { CheckValid(spriteFont, text); var scaleVec = new Vector2 (scale, scale); var source = new SpriteFont.CharacterSource(text); spriteFont.DrawInto(this, ref source, position, color, rotation, origin, scaleVec, effects, depth); }
public void DrawString (SpriteFont spriteFont, string text, Vector2 position, Color color) { CheckValid(spriteFont, text); var source = new SpriteFont.CharacterSource(text); spriteFont.DrawInto ( this, ref source, position, color, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f); }
/// <summary> /// Submit a text string of sprites for drawing in the current batch. /// </summary> /// <param name="spriteFont">A font.</param> /// <param name="text">The text which will be drawn.</param> /// <param name="position">The drawing location on screen.</param> /// <param name="color">A color mask.</param> /// <param name="rotation">A rotation of this string.</param> /// <param name="origin">Center of the rotation. 0,0 by default.</param> /// <param name="scale">A scaling of this string.</param> /// <param name="effects">Modificators for drawing. Can be combined.</param> /// <param name="layerDepth">A depth of the layer of this string.</param> public void DrawString ( SpriteFont spriteFont, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { CheckValid(spriteFont, text); var source = new SpriteFont.CharacterSource(text); spriteFont.DrawInto(this, ref source, position, color, rotation, origin, scale, effects, layerDepth); }
private void MeasureString(ref SpriteFont.CharacterSource text, out Vector2 size) { if (text.Length == 0) { size = Vector2.Zero; } else { SpriteFont.Glyph?nullable = new SpriteFont.Glyph?(); if (this.DefaultCharacter.HasValue) { nullable = new SpriteFont.Glyph?(this._glyphs[this.DefaultCharacter.Value]); } float num1 = 0.0f; float num2 = (float)this.LineSpacing; int num3 = 0; SpriteFont.Glyph glyph = SpriteFont.Glyph.Empty; Vector2 zero = Vector2.Zero; bool flag = false; for (int index = 0; index < text.Length; ++index) { char key = text[index]; switch (key) { case '\r': flag = false; break; case '\n': ++num3; num2 = (float)this.LineSpacing; zero.X = 0.0f; zero.Y = (float)(this.LineSpacing * num3); flag = false; break; default: if (flag) { zero.X += this.Spacing + glyph.WidthIncludingBearings; } flag = this._glyphs.TryGetValue(key, out glyph); if (!flag) { if (!nullable.HasValue) { throw new ArgumentException("Text contains characters that cannot be resolved by this SpriteFont.", "text"); } glyph = nullable.Value; flag = true; } float num4 = zero.X + glyph.WidthIncludingBearings; if ((double)num4 > (double)num1) { num1 = num4; } if ((double)glyph.Cropping.Height > (double)num2) { num2 = (float)glyph.Cropping.Height; break; } else { break; } } } size.X = num1; size.Y = (float)(num3 * this.LineSpacing) + num2; } }
internal void DrawInto(SpriteBatch spriteBatch, ref SpriteFont.CharacterSource text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effect, float depth) { Vector2 zero1 = Vector2.Zero; bool flag1 = (effect & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically; bool flag2 = (effect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally; if (flag1 || flag2) { Vector2 size; this.MeasureString(ref text, out size); if (flag2) { origin.X *= -1f; scale.X *= -1f; zero1.X = -size.X; } if (flag1) { origin.Y *= -1f; scale.Y *= -1f; zero1.Y = (float)this.LineSpacing - size.Y; } } Matrix result1; Matrix.CreateTranslation(-origin.X, -origin.Y, 0.0f, out result1); Matrix result2; Matrix.CreateScale(scale.X, scale.Y, 1f, out result2); Matrix.Multiply(ref result1, ref result2, out result1); Matrix.CreateTranslation(zero1.X, zero1.Y, 0.0f, out result2); Matrix.Multiply(ref result2, ref result1, out result1); Matrix.CreateRotationZ(rotation, out result2); Matrix.Multiply(ref result1, ref result2, out result1); Matrix.CreateTranslation(position.X, position.Y, 0.0f, out result2); Matrix.Multiply(ref result1, ref result2, out result1); SpriteFont.Glyph?nullable = new SpriteFont.Glyph?(); if (this.DefaultCharacter.HasValue) { nullable = new SpriteFont.Glyph?(this._glyphs[this.DefaultCharacter.Value]); } SpriteFont.Glyph glyph = SpriteFont.Glyph.Empty; Vector2 zero2 = Vector2.Zero; bool flag3 = false; for (int index = 0; index < text.Length; ++index) { char key = text[index]; switch (key) { case '\r': flag3 = false; break; case '\n': zero2.X = 0.0f; zero2.Y += (float)this.LineSpacing; flag3 = false; break; default: if (flag3) { zero2.X += this.Spacing + glyph.Width + glyph.RightSideBearing; } flag3 = this._glyphs.TryGetValue(key, out glyph); if (!flag3) { if (!nullable.HasValue) { throw new ArgumentException("Text contains characters that cannot be resolved by this SpriteFont.", "text"); } glyph = nullable.Value; flag3 = true; } zero2.X += glyph.LeftSideBearing; Vector2 result3 = zero2; if (flag2) { result3.X += (float)glyph.BoundsInTexture.Width; } result3.X += (float)glyph.Cropping.X; if (flag1) { result3.Y += (float)(glyph.BoundsInTexture.Height - this.LineSpacing); } result3.Y += (float)glyph.Cropping.Y; Vector2.Transform(ref result3, ref result1, out result3); Vector4 destinationRectangle = new Vector4(result3.X, result3.Y, (float)glyph.BoundsInTexture.Width * scale.X, (float)glyph.BoundsInTexture.Height * scale.Y); spriteBatch.DrawInternal(this._texture, destinationRectangle, new Rectangle?(glyph.BoundsInTexture), color, rotation, Vector2.Zero, effect, depth); break; } } }
/// <summary> /// Submit a text string of sprites for drawing in the current batch. /// </summary> /// <param name="spriteFont">A font.</param> /// <param name="text">The text which will be drawn.</param> /// <param name="position">The drawing location on screen.</param> /// <param name="color">A color mask.</param> /// <param name="rotation">A rotation of this string.</param> /// <param name="origin">Center of the rotation. 0,0 by default.</param> /// <param name="scale">A scaling of this string.</param> /// <param name="effects">Modificators for drawing. Can be combined.</param> /// <param name="layerDepth">A depth of the layer of this string.</param> public unsafe void DrawString( SpriteFont spriteFont, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { CheckValid(spriteFont, text); float sortKey = 0; // set SortKey based on SpriteSortMode. switch (_sortMode) { // Comparison of Texture objects. case SpriteSortMode.Texture: sortKey = spriteFont.Texture.SortingKey; break; // Comparison of Depth case SpriteSortMode.FrontToBack: sortKey = layerDepth; break; // Comparison of Depth in reverse case SpriteSortMode.BackToFront: sortKey = -layerDepth; break; } var flipAdjustment = Vector2.Zero; var flippedVert = (effects & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically; var flippedHorz = (effects & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally; if (flippedVert || flippedHorz) { Vector2 size; var source = new SpriteFont.CharacterSource(text); spriteFont.MeasureString(ref source, out size); if (flippedHorz) { origin.X *= -1; flipAdjustment.X = -size.X; } if (flippedVert) { origin.Y *= -1; flipAdjustment.Y = spriteFont.LineSpacing - size.Y; } } Matrix transformation = Matrix.Identity; float cos = 0, sin = 0; if (rotation == 0) { transformation.M11 = (flippedHorz ? -scale.X : scale.X); transformation.M22 = (flippedVert ? -scale.Y : scale.Y); transformation.M41 = ((flipAdjustment.X - origin.X) * transformation.M11) + position.X; transformation.M42 = ((flipAdjustment.Y - origin.Y) * transformation.M22) + position.Y; } else { cos = (float)Math.Cos(rotation); sin = (float)Math.Sin(rotation); transformation.M11 = (flippedHorz ? -scale.X : scale.X) * cos; transformation.M12 = (flippedHorz ? -scale.X : scale.X) * sin; transformation.M21 = (flippedVert ? -scale.Y : scale.Y) * (-sin); transformation.M22 = (flippedVert ? -scale.Y : scale.Y) * cos; transformation.M41 = (((flipAdjustment.X - origin.X) * transformation.M11) + (flipAdjustment.Y - origin.Y) * transformation.M21) + position.X; transformation.M42 = (((flipAdjustment.X - origin.X) * transformation.M12) + (flipAdjustment.Y - origin.Y) * transformation.M22) + position.Y; } var offset = Vector2.Zero; var firstGlyphOfLine = true; fixed(SpriteFont.Glyph *pGlyphs = spriteFont.Glyphs) for (var i = 0; i < text.Length; ++i) { var c = text[i]; if (c == '\r') { continue; } if (c == '\n') { offset.X = 0; offset.Y += spriteFont.LineSpacing; firstGlyphOfLine = true; continue; } var currentGlyphIndex = spriteFont.GetGlyphIndexOrDefault(c); var pCurrentGlyph = pGlyphs + currentGlyphIndex; // The first character on a line might have a negative left side bearing. // In this scenario, SpriteBatch/SpriteFont normally offset the text to the right, // so that text does not hang off the left side of its rectangle. if (firstGlyphOfLine) { offset.X = Math.Max(pCurrentGlyph->LeftSideBearing, 0); firstGlyphOfLine = false; } else { offset.X += spriteFont.Spacing + pCurrentGlyph->LeftSideBearing; } var p = offset; if (flippedHorz) { p.X += pCurrentGlyph->BoundsInTexture.Width; } p.X += pCurrentGlyph->Cropping.X; if (flippedVert) { p.Y += pCurrentGlyph->BoundsInTexture.Height - spriteFont.LineSpacing; } p.Y += pCurrentGlyph->Cropping.Y; Vector2.Transform(ref p, ref transformation, out p); var item = _batcher.CreateBatchItem(); item.Texture = spriteFont.Texture; item.SortKey = sortKey; _texCoordTL.X = pCurrentGlyph->BoundsInTexture.X * spriteFont.Texture.TexelWidth; _texCoordTL.Y = pCurrentGlyph->BoundsInTexture.Y * spriteFont.Texture.TexelHeight; _texCoordBR.X = (pCurrentGlyph->BoundsInTexture.X + pCurrentGlyph->BoundsInTexture.Width) * spriteFont.Texture.TexelWidth; _texCoordBR.Y = (pCurrentGlyph->BoundsInTexture.Y + pCurrentGlyph->BoundsInTexture.Height) * spriteFont.Texture.TexelHeight; if ((effects & SpriteEffects.FlipVertically) != 0) { var temp = _texCoordBR.Y; _texCoordBR.Y = _texCoordTL.Y; _texCoordTL.Y = temp; } if ((effects & SpriteEffects.FlipHorizontally) != 0) { var temp = _texCoordBR.X; _texCoordBR.X = _texCoordTL.X; _texCoordTL.X = temp; } if (rotation == 0f) { item.Set(p.X, p.Y, pCurrentGlyph->BoundsInTexture.Width * scale.X, pCurrentGlyph->BoundsInTexture.Height * scale.Y, color, _texCoordTL, _texCoordBR, layerDepth); } else { item.Set(p.X, p.Y, 0, 0, pCurrentGlyph->BoundsInTexture.Width * scale.X, pCurrentGlyph->BoundsInTexture.Height * scale.Y, sin, cos, color, _texCoordTL, _texCoordBR, layerDepth); } offset.X += pCurrentGlyph->Width + pCurrentGlyph->RightSideBearing; } // We need to flush if we're using Immediate sort mode. FlushIfNeeded(); }