示例#1
0
 public override void DrawContent(LineBatch lineBatch, SpriteBatch spriteBatch)
 {
     if (_material != null)
     {
         if (_material.Mat[TextureUnit.Texture0] != null)
         {
             spriteBatch.AddSprite(_material.Mat, 0, 0, 0, 0, _material.Mat[TextureUnit.Texture0].Width, _material.Mat[TextureUnit.Texture0].Height);
             lineBatch.AddBox(0, 0, _material.Mat[TextureUnit.Texture0].Width, _material.Mat[TextureUnit.Texture0].Height, Color.Red);
         }
         else
         {
             spriteBatch.AddSprite(_material.Mat, new Vector2(0, 0), new Vector2(256, 256), 0.0f, 0.0f, 1.0f, 1.0f);
             lineBatch.AddBox(0, 0, 256, 256, Color.Red);
         }
     }
     else
     {
         lineBatch.Add(new Vector2(-100, -100), new Vector2(100, 100), Color.Red);
         lineBatch.Add(new Vector2(100, -100), new Vector2(-100, 100), Color.Red);
     }
 }
示例#2
0
文件: Font.cs 项目: Tokter/TokED
        public void CreateSprite(SpriteBatch batch, int px, int py, string text, Color color, HorizontalAlignment horizontal, VerticalAlignment vertical)
        {
            int width = MeasureWidth(text);
            int height = MeasureHeight(text);
            int x = 0, y = 0;
            switch (horizontal)
            {
                case HorizontalAlignment.Left: x = px; break;
                case HorizontalAlignment.Center: x = px - width / 2; break;
                case HorizontalAlignment.Right: x = px - width; break;
            }
            switch (vertical)
            {
                case VerticalAlignment.Top: y = py; break;
                case VerticalAlignment.Center: y = py - height / 2 - 1; break;
                case VerticalAlignment.Bottom: y = py - height; break;
            }

            byte[] bytes = System.Text.Encoding.Default.GetBytes(text);
            for (int i = 0; i < bytes.Length; i++)
            {
                var b = bytes[i];
                if (b != 32)
                {
                    if (i > 0)
                    {
                        x -= _kerning[bytes[i - 1] * 256 + bytes[i]]-1;
                    }

                    batch.AddSprite(_material, new Vector2(x, y + _charInfo[b].YOffset), new Vector2(x + _charInfo[b].Width, y + _charInfo[b].YOffset + _charInfo[b].Height), _charInfo[b].U1, _charInfo[b].V1, _charInfo[b].U2, _charInfo[b].V2, color);
                }
                x += _charInfo[b].Width;
            }
        }