/// <summary> /// Draws the content. /// </summary> /// <param name="spriteBatch">Sprite batch.</param> public void Draw(SpriteBatch spriteBatch) { Vector2 origin = new Vector2(SourceRectangle.Width / 2, SourceRectangle.Height / 2); if (!string.IsNullOrEmpty(Text)) { DrawString(spriteBatch, font, StringUtils.WrapText(font, Text, SpriteSize.Width), ClientRectangle.ToXnaRectangle(), TextHorizontalAlignment, TextVerticalAlignment, Tint.ToXnaColor() * Opacity); } // TODO: Do not do this for every Draw call Texture2D textureToDraw = texture; // TODO: Find a better way to do this, because this one doesn't keep the mipmaps if (alphaMask != null) { textureToDraw = TextureBlend(texture, alphaMask); } if (TextureLayout == TextureLayout.Stretch) { spriteBatch.Draw(textureToDraw, new Vector2(Location.X + ClientRectangle.Width / 2, Location.Y + ClientRectangle.Height / 2), SourceRectangle.ToXnaRectangle(), Tint.ToXnaColor() * Opacity, Rotation, origin, Scale.ToXnaVector2() * Zoom, SpriteEffects.None, 0.0f); } else if (TextureLayout == TextureLayout.Tile) { GraphicsDevice gd = GraphicsManager.Instance.Graphics.GraphicsDevice; Rectangle rec = new Rectangle(0, 0, ClientRectangle.Width, ClientRectangle.Height); // TODO: Is it ok to End and Begin again? Does it affect performance? spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null); spriteBatch.Draw(textureToDraw, new Vector2(Location.X, Location.Y), rec, Tint.ToXnaColor() * Opacity); spriteBatch.End(); spriteBatch.Begin(); } }