private DrawInternal ( Microsoft.Xna.Framework.Graphics.Texture2D texture, System.Vector4 destinationRectangle, Rectangle sourceRectangle, System.Color color, float rotation, System.Vector2 origin, SpriteEffects effect, float depth, bool autoFlush ) : void | ||
texture | Microsoft.Xna.Framework.Graphics.Texture2D | |
destinationRectangle | System.Vector4 | |
sourceRectangle | Rectangle | |
color | System.Color | |
rotation | float | |
origin | System.Vector2 | |
effect | SpriteEffects | |
depth | float | |
autoFlush | bool | |
Результат | void |
internal void DrawInto( SpriteBatch spriteBatch, ref CharacterSource text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effect, float depth) { var flipAdjustment = Vector2.Zero; var flippedVert = (effect & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically; var flippedHorz = (effect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally; if (flippedVert || flippedHorz) { Vector2 size; MeasureString(ref text, out size); if (flippedHorz) { origin.X *= -1; scale.X *= -1; flipAdjustment.X = -size.X; } if (flippedVert) { origin.Y *= -1; scale.Y *= -1; flipAdjustment.Y = LineSpacing - size.Y; } } // TODO: This looks excessive... i suspect we could do most // of this with simple vector math and avoid this much matrix work. Matrix transformation, temp; Matrix.CreateTranslation(-origin.X, -origin.Y, 0f, out transformation); Matrix.CreateScale(scale.X, scale.Y, 1f, out temp); Matrix.Multiply(ref transformation, ref temp, out transformation); Matrix.CreateTranslation(flipAdjustment.X, flipAdjustment.Y, 0, out temp); Matrix.Multiply(ref temp, ref transformation, out transformation); Matrix.CreateRotationZ(rotation, out temp); Matrix.Multiply(ref transformation, ref temp, out transformation); Matrix.CreateTranslation(position.X, position.Y, 0f, out temp); Matrix.Multiply(ref transformation, ref temp, out transformation); // Get the default glyph here once. Glyph? defaultGlyph = null; if (DefaultCharacter.HasValue) defaultGlyph = _glyphs[DefaultCharacter.Value]; var currentGlyph = Glyph.Empty; var offset = Vector2.Zero; var hasCurrentGlyph = false; for (var i = 0; i < text.Length; ++i) { var c = text[i]; if (c == '\r') { hasCurrentGlyph = false; continue; } if (c == '\n') { offset.X = 0; offset.Y += LineSpacing; hasCurrentGlyph = false; continue; } if (hasCurrentGlyph) offset.X += Spacing + currentGlyph.Width + currentGlyph.RightSideBearing; hasCurrentGlyph = _glyphs.TryGetValue(c, out currentGlyph); if (!hasCurrentGlyph) { if (!defaultGlyph.HasValue) throw new ArgumentException(Errors.TextContainsUnresolvableCharacters, "text"); currentGlyph = defaultGlyph.Value; hasCurrentGlyph = true; } offset.X += currentGlyph.LeftSideBearing; var p = offset; if (flippedHorz) p.X += currentGlyph.BoundsInTexture.Width; p.X += currentGlyph.Cropping.X; if (flippedVert) p.Y += currentGlyph.BoundsInTexture.Height - LineSpacing; p.Y += currentGlyph.Cropping.Y; Vector2.Transform(ref p, ref transformation, out p); var destRect = new Vector4( p.X, p.Y, currentGlyph.BoundsInTexture.Width * scale.X, currentGlyph.BoundsInTexture.Height * scale.Y); // TODO: We're passing SpriteEffects thru here unchanged, but // it seems we're applyting the flips ourselves above. // // This just might be a bug! spriteBatch.DrawInternal( _texture, destRect, currentGlyph.BoundsInTexture, color, rotation, Vector2.Zero, effect, depth); } }
internal void DrawInto( SpriteBatch spriteBatch, ref CharacterSource text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effect, float depth) { var flipAdjustment = Vector2.Zero; var flippedVert = (effect & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically; var flippedHorz = (effect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally; if (flippedVert || flippedHorz) { Vector2 size; MeasureString(ref text, out size); if (flippedHorz) { origin.X *= -1; flipAdjustment.X = -size.X; } if (flippedVert) { origin.Y *= -1; flipAdjustment.Y = LineSpacing - size.Y; } } // TODO: This looks excessive... i suspect we could do most // of this with simple vector math and avoid this much matrix work. Matrix transformation, temp; Matrix.CreateTranslation(-origin.X, -origin.Y, 0f, out transformation); Matrix.CreateScale((flippedHorz ? -scale.X : scale.X), (flippedVert ? -scale.Y : scale.Y), 1f, out temp); Matrix.Multiply(ref transformation, ref temp, out transformation); Matrix.CreateTranslation(flipAdjustment.X, flipAdjustment.Y, 0, out temp); Matrix.Multiply(ref temp, ref transformation, out transformation); Matrix.CreateRotationZ(rotation, out temp); Matrix.Multiply(ref transformation, ref temp, out transformation); Matrix.CreateTranslation(position.X, position.Y, 0f, out temp); Matrix.Multiply(ref transformation, ref temp, out transformation); // Get the default glyph here once. Glyph? defaultGlyph = null; if (DefaultCharacter.HasValue) defaultGlyph = _glyphs[DefaultCharacter.Value]; var currentGlyph = Glyph.Empty; var offset = Vector2.Zero; var hasCurrentGlyph = false; var firstGlyphOfLine = true; for (var i = 0; i < text.Length; ++i) { var c = text[i]; if (c == '\r') { hasCurrentGlyph = false; continue; } if (c == '\n') { offset.X = 0; offset.Y += LineSpacing; hasCurrentGlyph = false; firstGlyphOfLine = true; continue; } if (hasCurrentGlyph) { offset.X += Spacing + currentGlyph.Width + currentGlyph.RightSideBearing; } hasCurrentGlyph = _glyphs.TryGetValue(c, out currentGlyph); if (!hasCurrentGlyph) { if (!defaultGlyph.HasValue) throw new ArgumentException(Errors.TextContainsUnresolvableCharacters, "text"); currentGlyph = defaultGlyph.Value; hasCurrentGlyph = true; } if (hasCurrentGlyph) { // 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(offset.X, 0); firstGlyphOfLine = false; } else { offset.X += currentGlyph.LeftSideBearing; } } var p = offset; if (flippedHorz) p.X += currentGlyph.BoundsInTexture.Width; p.X += currentGlyph.Cropping.X; if (flippedVert) p.Y += currentGlyph.BoundsInTexture.Height - LineSpacing; p.Y += currentGlyph.Cropping.Y; Vector2.Transform(ref p, ref transformation, out p); var destRect = new Vector4( p.X, p.Y, currentGlyph.BoundsInTexture.Width * scale.X, currentGlyph.BoundsInTexture.Height * scale.Y); spriteBatch.DrawInternal( _texture, destRect, currentGlyph.BoundsInTexture, color, rotation, Vector2.Zero, effect, depth, false); } // We need to flush if we're using Immediate sort mode. spriteBatch.FlushIfNeeded(); }
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; } } }
internal void DrawInto( SpriteBatch spriteBatch, ref CharacterSource text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effect, float depth ) { Vector2 flipAdjustment = Vector2.Zero; bool flippedVert = (effect & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically; bool flippedHorz = (effect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally; if (flippedVert || flippedHorz) { Vector2 size; MeasureString(ref text, out size); if (flippedHorz) { origin.X *= -1; flipAdjustment.X = -size.X; } if (flippedVert) { origin.Y *= -1; flipAdjustment.Y = LineSpacing - size.Y; } } /* TODO: This looks excessive... i suspect we could do most * of this with simple vector math and avoid this much matrix work. */ Matrix transformation, temp; Matrix.CreateTranslation(-origin.X, -origin.Y, 0f, out transformation); Matrix.CreateScale((flippedHorz ? -scale.X : scale.X), (flippedVert ? -scale.Y : scale.Y), 1f, out temp); Matrix.Multiply(ref transformation, ref temp, out transformation); Matrix.CreateTranslation(flipAdjustment.X, flipAdjustment.Y, 0, out temp); Matrix.Multiply(ref temp, ref transformation, out transformation); Matrix.CreateRotationZ(rotation, out temp); Matrix.Multiply(ref transformation, ref temp, out transformation); Matrix.CreateTranslation(position.X, position.Y, 0f, out temp); Matrix.Multiply(ref transformation, ref temp, out transformation); // Get the default glyph here once. Glyph?defaultGlyph = null; if (DefaultCharacter.HasValue) { defaultGlyph = _glyphs[DefaultCharacter.Value]; } Glyph currentGlyph = Glyph.Empty; Vector2 offset = Vector2.Zero; bool hasCurrentGlyph = false; bool firstGlyphOfLine = true; for (int i = 0; i < text.Length; i += 1) { char c = text[i]; if (c == '\r') { hasCurrentGlyph = false; continue; } if (c == '\n') { offset.X = 0; offset.Y += LineSpacing; hasCurrentGlyph = false; firstGlyphOfLine = true; continue; } if (hasCurrentGlyph) { offset.X += Spacing + currentGlyph.Width + currentGlyph.RightSideBearing; } hasCurrentGlyph = _glyphs.TryGetValue(c, out currentGlyph); if (!hasCurrentGlyph) { if (!defaultGlyph.HasValue) { throw new ArgumentException(Errors.TextContainsUnresolvableCharacters, "text"); } currentGlyph = defaultGlyph.Value; hasCurrentGlyph = true; } if (hasCurrentGlyph) { /* 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(offset.X, 0); firstGlyphOfLine = false; } else { offset.X += currentGlyph.LeftSideBearing; } } Vector2 p = offset; if (flippedHorz) { p.X += currentGlyph.BoundsInTexture.Width; } p.X += currentGlyph.Cropping.X; if (flippedVert) { p.Y += currentGlyph.BoundsInTexture.Height - LineSpacing; } p.Y += currentGlyph.Cropping.Y; Vector2.Transform(ref p, ref transformation, out p); Vector4 destRect = new Vector4( p.X, p.Y, currentGlyph.BoundsInTexture.Width * scale.X, currentGlyph.BoundsInTexture.Height * scale.Y ); spriteBatch.DrawInternal( _texture, destRect, currentGlyph.BoundsInTexture, color, rotation, Vector2.Zero, effect, depth, false ); } // We need to flush if we're using Immediate sort mode. spriteBatch.FlushIfNeeded(); }
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; } } }
internal void DrawInto(SpriteBatch spriteBatch, ref CharacterSource text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effect, float depth) { var flipAdjustment = Vector2.Zero; var flippedVert = (effect & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically; var flippedHorz = (effect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally; if (flippedVert || flippedHorz) { Vector2 size; MeasureString(ref text, out size); if (flippedHorz) { origin.X *= -1; scale.X *= -1; flipAdjustment.X = -size.X; } if (flippedVert) { origin.Y *= -1; scale.Y *= -1; flipAdjustment.Y = LineSpacing - size.Y; } } // TODO: This looks excessive... i suspect we could do most // of this with simple vector math and avoid this much matrix work. Matrix transformation, temp; Matrix.CreateTranslation(-origin.X, -origin.Y, 0f, out transformation); Matrix.CreateScale(scale.X, scale.Y, 1f, out temp); Matrix.Multiply(ref transformation, ref temp, out transformation); Matrix.CreateTranslation(flipAdjustment.X, flipAdjustment.Y, 0, out temp); Matrix.Multiply(ref temp, ref transformation, out transformation); Matrix.CreateRotationZ(rotation, out temp); Matrix.Multiply(ref transformation, ref temp, out transformation); Matrix.CreateTranslation(position.X, position.Y, 0f, out temp); Matrix.Multiply(ref transformation, ref temp, out transformation); // Get the default glyph here once. Glyph?defaultGlyph = null; if (DefaultCharacter.HasValue) { defaultGlyph = _glyphs[DefaultCharacter.Value]; } var currentGlyph = Glyph.Empty; var offset = Vector2.Zero; var hasCurrentGlyph = false; var firstGlyphOfLine = true; for (var i = 0; i < text.Length; ++i) { var c = text[i]; if (c == '\r') { hasCurrentGlyph = false; continue; } if (c == '\n') { offset.X = 0; offset.Y += LineSpacing; hasCurrentGlyph = false; firstGlyphOfLine = true; continue; } if (hasCurrentGlyph) { offset.X += Spacing + currentGlyph.Width + currentGlyph.RightSideBearing; } hasCurrentGlyph = _glyphs.TryGetValue(c, out currentGlyph); if (!hasCurrentGlyph) { if (!defaultGlyph.HasValue) { throw new ArgumentException(Errors.TextContainsUnresolvableCharacters, "text"); } currentGlyph = defaultGlyph.Value; hasCurrentGlyph = true; } if (hasCurrentGlyph) { // 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(offset.X, 0); firstGlyphOfLine = false; } else { offset.X += currentGlyph.LeftSideBearing; } } var p = offset; if (flippedHorz) { p.X += currentGlyph.BoundsInTexture.Width; } p.X += currentGlyph.Cropping.X; if (flippedVert) { p.Y += currentGlyph.BoundsInTexture.Height - LineSpacing; } p.Y += currentGlyph.Cropping.Y; Vector2.Transform(ref p, ref transformation, out p); var destRect = new Vector4(p.X, p.Y, currentGlyph.BoundsInTexture.Width * scale.X, currentGlyph.BoundsInTexture.Height * scale.Y); // TODO: We're passing SpriteEffects thru here unchanged, but // it seems we're applyting the flips ourselves above. // // This just might be a bug! spriteBatch.DrawInternal( _texture, destRect, currentGlyph.BoundsInTexture, color, rotation, Vector2.Zero, effect, depth); } }