Exemplo n.º 1
0
        public static void DrawText(Vector2 scale, RectangleF coords, string text, TextBlockRenderer font, Color color, TextAlignment align)
        {
            var fntSz = font.FontSize * scale.X;
            var pos   = new PointF(coords.X * scale.X, coords.Y * scale.Y);
            var size  = new SizeF(coords.Width * scale.X, coords.Height * scale.Y);

            font.DrawString(text, new RectangleF(pos, size), align, fntSz, color, CoordinateType.Absolute);
        }
Exemplo n.º 2
0
        protected override void DrawSpritesInner()
        {
            if (!VisibleUi)
            {
                return;
            }

            if (_textBlock == null)
            {
                _textBlock = new TextBlockRenderer(Sprite, "Arial", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 24f);
            }

            _textBlock.DrawString($@"
FPS: {FramesPerSecond:F0}{(SyncInterval ? " (limited)" : "")}
FXAA: {(UseFxaa ? "Yes" : "No")}
Bloom: {(UseBloom ? "Yes" : "No")}".Trim(),
                                  new Vector2(Width - 300, 20), 16f, new Color4(1.0f, 1.0f, 1.0f),
                                  CoordinateType.Absolute);
        }
Exemplo n.º 3
0
        /// <summary>
        /// ensure the textblock renderers exist.
        /// </summary>
        /// <param name="t"></param>
        public static void EnsureTypeExists(TextType t)
        {
            if (TextRenderers.ContainsKey(t))
            {
                return;
            }

            switch (t)
            {
            case TextType.BOLD:
                TextRenderers[t] = new TextBlockRenderer(SpriteRenderer, Constants.GlobalFont, FontWeight.Bold, SlimDX.DirectWrite.FontStyle.Normal, FontStretch.Normal, Constants.GlobalFontSize);
                break;

            case TextType.NORMAL:
                TextRenderers[t] = new TextBlockRenderer(SpriteRenderer, Constants.GlobalFont, FontWeight.Normal, SlimDX.DirectWrite.FontStyle.Normal, FontStretch.Normal, Constants.GlobalFontSize);
                break;

            case TextType.COMIC_SANS:
                TextRenderers[t] = new TextBlockRenderer(SpriteRenderer, "Comic Sans", FontWeight.Normal, SlimDX.DirectWrite.FontStyle.Normal, FontStretch.Normal, Constants.GlobalFontSize);
                break;

            case TextType.MASSIVE:
                TextRenderers[t] = new TextBlockRenderer(SpriteRenderer, Constants.GlobalFont, FontWeight.Normal, SlimDX.DirectWrite.FontStyle.Normal, FontStretch.Normal, 50);
                break;

            case TextType.SIZE300FONT:
                TextRenderers[t] = new TextBlockRenderer(SpriteRenderer, Constants.GlobalFont, FontWeight.Normal, SlimDX.DirectWrite.FontStyle.Normal, FontStretch.Normal, 300);
                break;

            case TextType.SMALL:
                TextRenderers[t] = new TextBlockRenderer(SpriteRenderer, Constants.GlobalFont, FontWeight.Normal, SlimDX.DirectWrite.FontStyle.Normal, FontStretch.Normal, 20);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(t), t, null);
            }
        }
Exemplo n.º 4
0
        protected override void DrawSpritesInner() {
            if (!VisibleUi) return;

            if (_textBlock == null) {
                _textBlock = new TextBlockRenderer(Sprite, "Arial", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 24f);
            }

            _textBlock.DrawString($@"
FPS: {FramesPerSecond:F0}{(SyncInterval ? " (limited)" : "")}
Triangles: {TrianglesCount:D}
FXAA: {(UseFxaa ? "Yes" : "No")}
Bloom: {(UseBloom ? "Yes" : "No")}
Magick.NET: {(ImageUtils.IsMagickSupported ? "Yes" : "No")}".Trim(),
                    new Vector2(Width - 300, 20), 16f, new Color4(1.0f, 1.0f, 1.0f),
                    CoordinateType.Absolute);

            if (CarHelper.Skins != null && CarHelper.CurrentSkin != null) {
                _textBlock.DrawString($"{CarHelper.CurrentSkin} ({CarHelper.Skins.IndexOf(CarHelper.CurrentSkin) + 1}/{CarHelper.Skins.Count})",
                        new RectangleF(0f, 0f, Width, Height - 20),
                        TextAlignment.HorizontalCenter | TextAlignment.Bottom, 16f, new Color4(1.0f, 1.0f, 1.0f),
                        CoordinateType.Absolute);
            }
        }
Exemplo n.º 5
0
        protected virtual void DrawSpritesInner() {
            if (!VisibleUi) return;

            if (_textBlock == null) {
                _textBlock = new TextBlockRenderer(Sprite, "Arial", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 20f);
            }

            if (TrianglesCount == 0) {
                _textBlock.DrawString("Nothing found",
                        new RectangleF(0, 0, Width, Height), TextAlignment.VerticalCenter | TextAlignment.HorizontalCenter, 20f,
                        new Color4(1.0f, 1.0f, 1.0f), CoordinateType.Absolute);
            } else {
                _textBlock.DrawString($"Triangles: {TrianglesCount}\nZoom: {Zoom:F3}×\nResult image most likely will be different size",
                        new RectangleF(8, 8, Width - 16, Height - 16), TextAlignment.Bottom | TextAlignment.Left, 12f,
                        new Color4(1.0f, 1.0f, 1.0f), CoordinateType.Absolute);
            }
        }
Exemplo n.º 6
0
        public static void DrawTextList(Vector2 scale, RectangleF coords, Array text1, Array text2, TextBlockRenderer font, Color color, TextAlignment align, String gap = "   ")
        {
            var fntSz = font.FontSize * scale.X;

            string[] str = new string[2];
            foreach (dynamic item in text1)
            {
                str[0] += "\n\r" + item.ToString();
            }
            foreach (dynamic item in text2)
            {
                str[1] += "\n\r" + item.ToString();
            }
            var region = new RectangleF(new PointF(coords.X * scale.X, coords.Y * scale.Y), new SizeF(coords.Width * scale.X, coords.Height * scale.Y));
            var col1_w = (float)Math.Ceiling(font.MeasureString(str[0], fntSz, CoordinateType.Absolute).Size.X);
            var gap_w  = (float)Math.Ceiling(font.MeasureString(gap, fntSz, CoordinateType.Absolute).Size.X);

            font.DrawString(str[0], region, align, fntSz, color, CoordinateType.Absolute);
            region.Offset(col1_w + gap_w, 0);
            font.DrawString(str[1], region, align, fntSz, color, CoordinateType.Absolute);
        }
Exemplo n.º 7
0
        public static void DrawTextList(Vector2 scale, RectangleF coords, List <String> text, TextBlockRenderer font, Color color, TextAlignment align)
        {
            var fntSz = font.FontSize * scale.X;
            var pos   = new PointF(coords.X * scale.X, coords.Y * scale.Y);
            var size  = new SizeF(coords.Width * scale.X, coords.Height / text.Count() * scale.Y);

            for (var i = 0; i < text.Count(); i++)
            {
                var region = new RectangleF(pos, size);
                region.Offset(0, size.Height * i);
                font.DrawString(text[i], region, align, fntSz, color, CoordinateType.Absolute);
            }
        }
Exemplo n.º 8
0
        public static void DrawIconWithText(Vector2 scale, RectangleF coords, SpriteRenderer sprite, ShaderResourceView image, List <String> text, TextBlockRenderer font, List <Color> color, TextAlignment align, Point offset, int sep = 0, String measure = "000")
        {
            var fntSz = font.FontSize * scale.X;
            var loc   = new Vector2(coords.X * scale.X, coords.Y * scale.Y);
            var size  = new Vector2(coords.Width * scale.X, coords.Height * scale.X); // to avoid img distortion

            sprite.Draw(image, loc, size, new Vector2(0, 0), 0, CoordinateType.Absolute);
            List <RectangleF> regions = new List <RectangleF>()
            {
                new RectangleF(
                    PointF.Add(
                        new PointF(loc.X, loc.Y), new SizeF(size.X + offset.X * scale.X, size.Y / 2 + offset.Y * scale.Y - ((float)Math.Ceiling(font.MeasureString(measure, fntSz, CoordinateType.Absolute).Size.Y) * text.Count() + (sep * (text.Count() - 1)) * scale.X) / 2)),
                    new SizeF((float)Math.Ceiling(font.MeasureString(measure, fntSz, CoordinateType.Absolute).Size.X), (float)Math.Ceiling(font.MeasureString(measure, fntSz, CoordinateType.Absolute).Size.Y)
                              )
                    )
            };

            for (var i = 1; i < text.Count(); i++)
            {
                regions.Add(new RectangleF(PointF.Add(regions[0].Location, new SizeF(0, (regions[0].Height + sep) * i)), regions[0].Size));
            }
            for (var i = 0; i < text.Count(); i++)
            {
                font.DrawString(text[i], regions[i], align, fntSz, color[i % text.Count()], CoordinateType.Absolute);
            }
        }
Exemplo n.º 9
0
        //probably a better way to organise this

        public static void DrawIconWithText(Vector2 scale, RectangleF coords, SpriteRenderer sprite, ShaderResourceView image, String text, TextBlockRenderer font, Color color, TextAlignment align, Point offset)
        {
            var fntSz = font.FontSize * scale.X;
            var loc   = new Vector2(coords.X * scale.X, coords.Y * scale.Y);
            var size  = new Vector2(coords.Width * scale.X, coords.Height * scale.X); // to avoid img distortion

            sprite.Draw(image, loc, size, new Vector2(0, 0), 0, CoordinateType.Absolute);
            var region = new RectangleF(
                PointF.Add(new PointF(loc.X, loc.Y), new SizeF(size.X + offset.X * scale.X, size.Y / 2 + offset.Y * scale.Y - (float)Math.Ceiling(font.MeasureString(text, fntSz, CoordinateType.Absolute).Size.Y) / 2)),
                new SizeF(
                    (float)Math.Ceiling(font.MeasureString(text, fntSz, CoordinateType.Absolute).Size.X),
                    (float)Math.Ceiling(font.MeasureString(text, fntSz, CoordinateType.Absolute).Size.Y)
                    )
                );

            font.DrawString(text, region, align, fntSz, color, CoordinateType.Absolute);
        }
Exemplo n.º 10
0
        protected override void ResizeInner() {
            base.ResizeInner();

            if (_textBlock != null) return;
            _textBlock = new TextBlockRenderer(Sprite, "Arial", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 24f);
        }