Exemple #1
0
        private void DrawItem(MeshItem mesh, TextMesh text)
        {
            if (text.Text != null && text.Font != null)
            {
                var size = text.Font.MeasureString(text.Text);
                var pos  = mesh.Position;

                switch (text.Align)
                {
                case Alignment.Near: break;

                case Alignment.Center: pos.X -= (int)(size.X / 2); break;

                case Alignment.Far: pos.X -= size.X; break;
                }

                if (text.BackColor.A > 0) //绘制背景
                {
                    var padding = text.Padding;
                    var rect    = new Rectangle((int)(pos.X - padding.Left),
                                                (int)(pos.Y - padding.Top),
                                                (int)(size.X + padding.Left + padding.Right),
                                                (int)(size.Y + padding.Top + padding.Bottom)
                                                );
                    sprite.FillRoundCornerRectangle(rect, text.BackColor);
                }

                if (text.ForeColor.A > 0) //绘制文字
                {
                    sprite.DrawStringEx(text.Font, text.Text, pos, text.ForeColor);
                }
            }
        }
Exemple #2
0
        public override void DrawText(FontBase font, string text, PointF position, Size renderSize, ColorW color, PointF scale, float depth)
        {
            var wcR2Font = (font.GetNativeFont() as IWcR2Font)?.BaseFont;

            if (wcR2Font != null)
            {
                if (wcR2Font is XnaFont)
                {
                    //snap pixels
                    position.X = (float)Math.Round(position.X);
                    position.Y = (float)Math.Round(position.Y);

                    Prepare(DrawState.Sprite);
                    spriteBatch.DrawStringEx((XnaFont)wcR2Font,
                                             text,
                                             new Vector2(position.X, position.Y),
                                             new Vector2(renderSize.Width, renderSize.Height),
                                             new Color(color.R, color.G, color.B, color.A));
                }
                else if (wcR2Font is D2DFont)
                {
                    Prepare(DrawState.D2D);
                    d2dRenderer.DrawString((D2DFont)wcR2Font,
                                           text,
                                           new Vector2(position.X, position.Y),
                                           new Vector2(renderSize.Width, renderSize.Height),
                                           new Color(color.R, color.G, color.B, color.A));
                }
            }
        }
Exemple #3
0
        protected override void Draw()
        {
            base.Draw();

            if (this.ShowInfo && this.XnaFont != null)
            {
                UpdateInfoText();
                sprite.Begin();
                sprite.DrawStringEx(this.XnaFont, this.sbInfo, Vector2.Zero, Color.Black);
                sprite.End();
            }
        }
Exemple #4
0
        public override void DrawText(FontBase font, string text, PointF position, Size renderSize, ColorW color, PointF scale, float depth)
        {
            XnaFont nativeFont = font.GetNativeFont() as XnaFont;

            if (nativeFont != null)
            {
                spriteBatch.DrawStringEx(nativeFont,
                                         text,
                                         new Vector2(position.X, position.Y),
                                         new Color(color.R, color.G, color.B, color.A));
            }
        }
Exemple #5
0
        private void DrawNameTooltip(RenderEnv env, string name, XnaFont font, Vector2 mapPosition, Color color)
        {
            SpriteBatchEx sprite = env.Sprite;
            Vector2       size   = font.MeasureString(name);
            Rectangle     rect   = new Rectangle((int)(mapPosition.X - size.X / 2 - 2), (int)(mapPosition.Y + 2), (int)(size.X + 4), (int)(size.Y + 3));

            sprite.FillRectangle(rect, new Color(Color.Black, 0.7f), env.Camera.Origin);
            sprite.DrawStringEx(
                font,
                name,
                new Vector2(rect.X + 2, rect.Y + 2),
                color,
                env.Camera.Origin);
        }
Exemple #6
0
        private void DrawItem(MeshItem mesh, TextMesh text)
        {
            if (text.Text != null && text.Font != null)
            {
                var size = text.Font.MeasureString(text.Text);
                var pos  = mesh.Position;

                switch (text.Align)
                {
                case Alignment.Near: break;

                case Alignment.Center: pos.X -= (int)(size.X / 2); break;

                case Alignment.Far: pos.X -= size.X; break;
                }

                var padding = text.Padding;
                var rect    = new Rectangle((int)(pos.X - padding.Left),
                                            (int)(pos.Y - padding.Top),
                                            (int)(size.X + padding.Left + padding.Right),
                                            (int)(size.Y + padding.Top + padding.Bottom)
                                            );

                if (this.CullingEnabled)
                {
                    if (!this.IntersectsVP(rect))
                    {
                        return;
                    }
                }

                object baseFont = text.Font.BaseFont ?? text.Font;

                if (baseFont is XnaFont)
                {
                    Prepare(ItemType.Sprite);
                }
                else if (baseFont is D2DFont)
                {
                    Prepare(ItemType.D2DObject);
                }
                else
                {
                    return;
                }

                if (text.BackColor.A > 0) //绘制背景
                {
                    switch (this.lastItem)
                    {
                    case ItemType.Sprite: sprite.FillRoundedRectangle(rect, text.BackColor); break;

                    case ItemType.D2DObject: d2dRender.FillRoundedRectangle(rect, 3, text.BackColor); break;
                    }
                }

                if (text.ForeColor.A > 0) //绘制文字
                {
                    switch (this.lastItem)
                    {
                    case ItemType.Sprite: sprite.DrawStringEx((XnaFont)baseFont, text.Text, pos, text.ForeColor); break;

                    case ItemType.D2DObject: d2dRender.DrawString((D2DFont)baseFont, text.Text, pos, text.ForeColor); break;
                    }
                }
            }
        }