Exemplo n.º 1
0
        protected override void OnGotContext(RenderContext context)
        {
            base.OnGotContext(context);

            var fps        = Game.AsTheaterDays().FindSingleElement <FpsOverlay>();
            var fpsHeight  = fps != null ? (int)DirectWriteHelper.PointToDip(fps.FontSize) : 0;
            var clientSize = context.ClientSize;

            Location = new Point(clientSize.Width - 80, fpsHeight);
        }
Exemplo n.º 2
0
        protected override void OnDraw(GameTime gameTime, RenderContext context)
        {
            base.OnDraw(gameTime, context);

            var text = Text;

            if (!string.IsNullOrWhiteSpace(text))
            {
                var textSize   = DirectWriteHelper.MeasureText(context.DirectWriteFactory, text, _font);
                var lineHeight = DirectWriteHelper.PointToDip(FontSize);
                OnBeforeTextRendering(context, textSize, lineHeight);

                var location = Location;
                context.Begin2D();
                context.DrawText(text, _textBrush, _font, location.X, location.Y);
                context.End2D();
            }
        }
Exemplo n.º 3
0
        private void Initialize(RenderContext context, string text, D2DFont d2dFont, FontFace fontFace)
        {
            Text     = text;
            D2DFont  = d2dFont;
            FontFace = fontFace;

            var fontSizeInEm = DirectWriteHelper.PointToDip(d2dFont.Size);

            LineHeight = fontSizeInEm;

            if (text.IndexOf('\n') >= 0)
            {
                var processedText = text.Replace("\r", string.Empty);
                var lines         = processedText.Split('\n');

                _pathDataArray = new D2DPathData[lines.Length];
                _lineHeights   = new float[lines.Length];

                for (var i = 0; i < lines.Length; ++i)
                {
                    var line = lines[i];
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        var pathData = GetPathData(context, line, fontFace, fontSizeInEm);
                        _pathDataArray[i] = pathData;
                    }
                    _lineHeights[i] = fontSizeInEm;
                }
            }
            else
            {
                var pathData = GetPathData(context, text, fontFace, fontSizeInEm);
                _pathDataArray = new[] { pathData };
                _lineHeights   = new[] { fontSizeInEm };
            }
        }