Example #1
0
        public void Render(IRenderContext renderContext, GameTime dt)
        {
            var message = _stringBuilder.ToString();

            _stringBuilder.Clear();
            Vector2 position;
            Vector2 origin;
            var     screenSize = new Vector2(renderContext.GraphicsDeviceManager.PreferredBackBufferWidth, renderContext.GraphicsDeviceManager.PreferredBackBufferHeight);

            CornerHelper.GetPositionAndOrigin(_corner, screenSize, out position, out origin);
            if (_corner == Corner.BottomLeft || _corner == Corner.TopLeft)
            {
                renderContext.RenderContext2D.DrawString(message, position, origin, _color, FontSize);
            }
            else
            {
                // XNA doesn't support true right-align (will take widest line which results in most lines drawing offset from the right side).
                // rendering each line by itself is a simple fix, not really "cheap" but there won't ever be enough text to cause rendering/performance issues.
                var lines = message.Split(new[]
                {
                    '\n', '\r'
                }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var line in lines)
                {
                    renderContext.RenderContext2D.DrawString(line, position, origin, _color, FontSize);
                    var h = renderContext.RenderContext2D.MeasureString(line, FontSize).Y;
                    // need to move up if we are in the bottom corner, otherwise move down
                    position.Y += _corner == Corner.BottomRight ? -h : h;
                }
            }
        }
Example #2
0
        public void Render(IRenderContext renderContext, GameTime dt)
        {
            Vector2 position;
            Vector2 origin;
            var     screenSize = new Vector2(renderContext.GraphicsDeviceManager.PreferredBackBufferWidth, renderContext.GraphicsDeviceManager.PreferredBackBufferHeight);

            CornerHelper.GetPositionAndOrigin(_corner, screenSize, out position, out origin);

            renderContext.RenderContext2D.DrawString($"FPS: {Math.Round(AverageFramesPerSecond):000}", position, origin, _fontColor, FontSize.Small);
        }