예제 #1
0
        public void DrawString(GsFont font, string text, float x, float y, GsColor color)
        {
            var f = GetFont(font);

            TextureData d;

            if (!stringTextures.TryGetValue(text, out d))
            {
                var s   = MeasureString(font, text);
                var bmp = new Bitmap((int)Math.Ceiling(s.Width) + 2, (int)Math.Ceiling(s.Height) + 2);
                using (var gra = Graphics.FromImage(bmp))
                {
                    using (var b = new SolidBrush(Color.FromArgb(color.A, color.R, color.G, color.B)))
                    {
                        gra.SmoothingMode     = SmoothingMode.AntiAlias;
                        gra.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                        gra.Clear(Color.Transparent);
                        gra.DrawString(text, f, b, new RectangleF(0, 0, bmp.Width, bmp.Height), centerCenter);
                    }
                }

                d = new TextureData
                {
                    Bitmap = bmp,
                    ID     = Texture.BindImage(bmp),
                };

                stringTextures[text] = d;
            }

            DrawImage(d, x, y, d.Bitmap.Width, d.Bitmap.Height, color);
        }
        public static void DrawString(this IGsGraphics graphics, GsFont font, string text, float x, float y, float width, float height, GsColor color, GsAlignment alignment)
        {
            var size = GsTextMeasurer.MeasureString(font, text);
            var pos  = CalculatePosition(size, x, y, width, height, alignment);

            graphics.DrawString(font, text, pos.X, pos.Y, color);
        }
예제 #3
0
        public GsSize MeasureString(GsFont font, string text)
        {
            var f = font.Data as SpriteFont;
            var s = f.MeasureString(text);

            return(new GsSize(s.X, s.Y));
        }
예제 #4
0
        private Font GetFont(GsFont font)
        {
            if (font == null)
            {
                return(fonts["Tahoma"]);
            }

            return((font.Data as Font) ?? fonts["Tahoma"]);
        }
예제 #5
0
        protected virtual void DrawCurrentLevel(DrawParams dparams, GsRectangle bounds, GsRectangle inside)
        {
            if (Level < MaxLevel)
            {
                float spacing   = 2f;
                float dimension = (bounds.Width - (spacing * 5f)) / 8f;

                float x = bounds.X + spacing;
                float y = bounds.Bottom - (spacing + dimension);

                GsFont font        = FontProvider.PieceLevelFont;
                var    lineSpacing = FontProvider.GetLineSpacing(font);

                string   text = Level.ToString();
                GsVector pos  = new GsVector(bounds.Left + spacing, bounds.Bottom - (lineSpacing + spacing));

                var graphics = dparams.Graphics;
                graphics.DrawString(font, text, pos, GsColor.Black);
            }
        }
예제 #6
0
        public GsSize MeasureString(GsFont font, string text)
        {
            var sz = measureGraphics.MeasureString(text, GetFont(font));

            return(new GsSize(sz.Width, sz.Height));
        }
예제 #7
0
 public static GsSize MeasureString(GsFont font, string text)
 {
     return(sMeasurer.MeasureString(font, text));
 }
예제 #8
0
        float IFontProvider.GetLineSpacing(GsFont font)
        {
            var f = font.Data as SpriteFont;

            return(f.LineSpacing);
        }
예제 #9
0
 public void DrawString(GsFont font, string text, float x, float y, GsColor color)
 {
     SwitchMode(Mode.Sprites);
     spriteBatch.DrawString(font.Data as SpriteFont, text, new Vector2(x, y), color.ToColor());
 }
예제 #10
0
 public static void DrawString(this IGsGraphics graphics, GsFont font, string text, GsVector pos, GsColor color)
 {
     graphics.DrawString(font, text, pos.X, pos.Y, color);
 }
예제 #11
0
 public static float GetLineSpacing(GsFont font)
 {
     return(sProvider.GetLineSpacing(font));
 }
예제 #12
0
 public float GetLineSpacing(GsFont font)
 {
     return((font.Data as Font).GetHeight());
 }