public override Pointf MeasureText(string text, GameFont gameFont, float fontScale) { if (gameFont == null) { return(Pointf.Empty); } var font = (SpriteFont)gameFont.GetFont(); if (font == null) { return(Pointf.Empty); } foreach (var chr in text) { if (!font.Characters.Contains(chr)) { text = text.Replace(chr, ' '); } } var size = font.MeasureString(text); return(new Pointf(size.X * fontScale, size.Y * fontScale)); }
public override void DrawString( string text, GameFont gameFont, float x, float y, float fontScale, Color fontColor, bool worldPos = true, GameRenderTexture renderTexture = null, Color borderColor = null ) { if (gameFont == null) { return; } var font = (SpriteFont)gameFont.GetFont(); if (font == null) { return; } StartSpritebatch(mCurrentView, GameBlendModes.None, null, renderTexture, false, null); foreach (var chr in text) { if (!font.Characters.Contains(chr)) { text = text.Replace(chr, ' '); } } if (borderColor != null && borderColor != Color.Transparent) { mSpriteBatch.DrawString( font, text, new Vector2(x, y - 1), ConvertColor(borderColor), 0f, Vector2.Zero, new Vector2(fontScale, fontScale), SpriteEffects.None, 0 ); mSpriteBatch.DrawString( font, text, new Vector2(x - 1, y), ConvertColor(borderColor), 0f, Vector2.Zero, new Vector2(fontScale, fontScale), SpriteEffects.None, 0 ); mSpriteBatch.DrawString( font, text, new Vector2(x + 1, y), ConvertColor(borderColor), 0f, Vector2.Zero, new Vector2(fontScale, fontScale), SpriteEffects.None, 0 ); mSpriteBatch.DrawString( font, text, new Vector2(x, y + 1), ConvertColor(borderColor), 0f, Vector2.Zero, new Vector2(fontScale, fontScale), SpriteEffects.None, 0 ); } mSpriteBatch.DrawString(font, text, new Vector2(x, y), ConvertColor(fontColor)); }
public override void DrawString( string text, GameFont gameFont, float x, float y, float fontScale, Color fontColor, bool worldPos, GameRenderTexture renderTexture, FloatRect clipRect, Color borderColor = null ) { if (gameFont == null) { return; } x += mCurrentView.X; y += mCurrentView.Y; //clipRect.X += _currentView.X; //clipRect.Y += _currentView.Y; var font = (SpriteFont)gameFont.GetFont(); if (font == null) { return; } var clr = ConvertColor(fontColor); //Copy the current scissor rect so we can restore it after var currentRect = mSpriteBatch.GraphicsDevice.ScissorRectangle; StartSpritebatch(mCurrentView, GameBlendModes.None, null, renderTexture, false, mRasterizerState, true); //Set the current scissor rectangle mSpriteBatch.GraphicsDevice.ScissorRectangle = new Microsoft.Xna.Framework.Rectangle( (int)clipRect.X, (int)clipRect.Y, (int)clipRect.Width, (int)clipRect.Height ); foreach (var chr in text) { if (!font.Characters.Contains(chr)) { text = text.Replace(chr, ' '); } } if (borderColor != null && borderColor != Color.Transparent) { mSpriteBatch.DrawString( font, text, new Vector2(x, y - 1), ConvertColor(borderColor), 0f, Vector2.Zero, new Vector2(fontScale, fontScale), SpriteEffects.None, 0 ); mSpriteBatch.DrawString( font, text, new Vector2(x - 1, y), ConvertColor(borderColor), 0f, Vector2.Zero, new Vector2(fontScale, fontScale), SpriteEffects.None, 0 ); mSpriteBatch.DrawString( font, text, new Vector2(x + 1, y), ConvertColor(borderColor), 0f, Vector2.Zero, new Vector2(fontScale, fontScale), SpriteEffects.None, 0 ); mSpriteBatch.DrawString( font, text, new Vector2(x, y + 1), ConvertColor(borderColor), 0f, Vector2.Zero, new Vector2(fontScale, fontScale), SpriteEffects.None, 0 ); } mSpriteBatch.DrawString( font, text, new Vector2(x, y), clr, 0f, Vector2.Zero, new Vector2(fontScale, fontScale), SpriteEffects.None, 0 ); EndSpriteBatch(); //Reset scissor rectangle to the saved value mSpriteBatch.GraphicsDevice.ScissorRectangle = currentRect; }