簡易なレイアウト計算を行う構造体です。
Ejemplo n.º 1
0
        protected override void LoadContent()
        {
            var titleSafeArea = GraphicsDevice.Viewport.TitleSafeArea;

            // 表示幅を TitleSafeArea から余白を考慮した値に設定。
            width = titleSafeArea.Width - 16;

            // 表示位置を計算。
            // 高さはバーの数で変動するため、Bottom 合わせで固定し、Bottom ラインをベースに描画時に調整。
            var layout = new DebugLayout()
            {
                ContainerBounds     = titleSafeArea,
                Width               = width,
                Height              = 0,
                HorizontalMargin    = 8,
                VerticalMargin      = 8,
                HorizontalAlignment = DebugHorizontalAlignment.Center,
                VerticalAlignment   = DebugVerticalAlignment.Bottom
            };

            layout.Arrange();

            offsetX = layout.ArrangedBounds.X;
            offsetY = layout.ArrangedBounds.Y;

            spriteBatch = new SpriteBatch(GraphicsDevice);
            fillTexture = Texture2DHelper.CreateFillTexture(GraphicsDevice);
            spriteFont  = Game.Content.Load <SpriteFont>(fontAssetName);

            base.LoadContent();
        }
Ejemplo n.º 2
0
        public override void Draw(GameTime gameTime)
        {
            // Draw 呼び出しをサンプリングします。
            sampleFrames++;

            spriteBatch.Begin();

            // 背景領域を計算します。
            var layout = new DebugLayout();

            layout.ContainerBounds     = GraphicsDevice.Viewport.TitleSafeArea;
            layout.Width               = (int)fontSize.X + 4;
            layout.Height              = (int)fontSize.Y + 2;
            layout.HorizontalMargin    = 8;
            layout.VerticalMargin      = 8;
            layout.HorizontalAlignment = HorizontalAlignment;
            layout.VerticalAlignment   = VerticalAlignment;
            layout.Arrange();

            spriteBatch.Draw(fillTexture, layout.ArrangedBounds, BackgroundColor);

            // 文字列表示領域を計算します。
            layout.ContainerBounds     = layout.ArrangedBounds;
            layout.Width               = (int)fontSize.X;
            layout.Height              = (int)fontSize.Y;
            layout.HorizontalMargin    = 2;
            layout.VerticalMargin      = 0;
            layout.HorizontalAlignment = DebugHorizontalAlignment.Center;
            layout.VerticalAlignment   = DebugVerticalAlignment.Center;
            layout.Arrange();

            // 文字色を決定します。
            var color = !gameTime.IsRunningSlowly ? ForegroundColor : RunningSlowlyForegroundColor;

            spriteBatch.DrawString(font, stringBuilder, new Vector2(layout.ArrangedBounds.X, layout.ArrangedBounds.Y), color);

            spriteBatch.End();

            base.Draw(gameTime);
        }
Ejemplo n.º 3
0
        public override void Draw(GameTime gameTime)
        {
            // Draw 呼び出しをサンプリングします。
            sampleFrames++;

            spriteBatch.Begin();

            // 背景領域を計算します。
            var layout = new DebugLayout();
            layout.ContainerBounds = GraphicsDevice.Viewport.TitleSafeArea;
            layout.Width = (int) fontSize.X + 4;
            layout.Height = (int) fontSize.Y + 2;
            layout.HorizontalMargin = 8;
            layout.VerticalMargin = 8;
            layout.HorizontalAlignment = HorizontalAlignment;
            layout.VerticalAlignment = VerticalAlignment;
            layout.Arrange();

            spriteBatch.Draw(fillTexture, layout.ArrangedBounds, BackgroundColor);

            // 文字列表示領域を計算します。
            layout.ContainerBounds = layout.ArrangedBounds;
            layout.Width = (int) fontSize.X;
            layout.Height = (int) fontSize.Y;
            layout.HorizontalMargin = 2;
            layout.VerticalMargin = 0;
            layout.HorizontalAlignment = DebugHorizontalAlignment.Center;
            layout.VerticalAlignment = DebugVerticalAlignment.Center;
            layout.Arrange();

            // 文字色を決定します。
            var color = !gameTime.IsRunningSlowly ? ForegroundColor : RunningSlowlyForegroundColor;

            spriteBatch.DrawString(font, stringBuilder, new Vector2(layout.ArrangedBounds.X, layout.ArrangedBounds.Y), color);

            spriteBatch.End();

            base.Draw(gameTime);
        }
Ejemplo n.º 4
0
        protected override void LoadContent()
        {
            var titleSafeArea = GraphicsDevice.Viewport.TitleSafeArea;

            // 表示幅を TitleSafeArea から余白を考慮した値に設定。
            width = titleSafeArea.Width - 16;

            // 表示位置を計算。
            // 高さはバーの数で変動するため、Bottom 合わせで固定し、Bottom ラインをベースに描画時に調整。
            var layout = new DebugLayout()
            {
                ContainerBounds = titleSafeArea,
                Width = width,
                Height = 0,
                HorizontalMargin = 8,
                VerticalMargin = 8,
                HorizontalAlignment = DebugHorizontalAlignment.Center,
                VerticalAlignment = DebugVerticalAlignment.Bottom
            };
            layout.Arrange();

            offsetX = layout.ArrangedBounds.X;
            offsetY = layout.ArrangedBounds.Y;

            spriteBatch = new SpriteBatch(GraphicsDevice);
            fillTexture = Texture2DHelper.CreateFillTexture(GraphicsDevice);
            spriteFont = Game.Content.Load<SpriteFont>(fontAssetName);

            base.LoadContent();
        }
Ejemplo n.º 5
0
        void DrawHelp()
        {
            if (!helpVisible) return;

            spriteBatch.Begin();

            var layout = new DebugLayout();

            int informationWidth = 380;

            // calculate the background area for information.
            layout.ContainerBounds = GraphicsDevice.Viewport.TitleSafeArea;
            layout.Width = informationWidth + 4;
            layout.Height = (int) informationTextFontSize.Y + 2;
            layout.HorizontalMargin = 8;
            layout.VerticalMargin = 8;
            layout.HorizontalAlignment = DebugHorizontalAlignment.Left;
            layout.VerticalAlignment = DebugVerticalAlignment.Top;
            layout.Arrange();
            // draw the rectangle.
            spriteBatch.Draw(fillTexture, layout.ArrangedBounds, Color.Black * 0.5f);

            // calculate the text area for information.
            layout.ContainerBounds = layout.ArrangedBounds;
            layout.Width = informationWidth;
            layout.Height = (int) informationTextFontSize.Y;
            layout.HorizontalMargin = 2;
            layout.VerticalMargin = 0;
            layout.HorizontalAlignment = DebugHorizontalAlignment.Center;
            layout.VerticalAlignment = DebugVerticalAlignment.Center;
            layout.Arrange();
            // draw the text.
            BuildInfoMessage();
            spriteBatch.DrawString(font, stringBuilder, new Vector2(layout.ArrangedBounds.X, layout.ArrangedBounds.Y), Color.Yellow);

            // calculate the background area for help messages.
            layout.ContainerBounds = GraphicsDevice.Viewport.TitleSafeArea;
            layout.Width = (int) helpMessageFontSize.X + 4;
            layout.Height = (int) helpMessageFontSize.Y + 2;
            layout.HorizontalMargin = 8;
            layout.VerticalMargin = 8;
            layout.HorizontalAlignment = DebugHorizontalAlignment.Left;
            layout.VerticalAlignment = DebugVerticalAlignment.Bottom;
            layout.Arrange();
            // draw the rectangle.
            spriteBatch.Draw(fillTexture, layout.ArrangedBounds, Color.Black * 0.5f);

            // calculate the text area for help messages.
            layout.ContainerBounds = layout.ArrangedBounds;
            layout.Width = (int) helpMessageFontSize.X;
            layout.Height = (int) helpMessageFontSize.Y;
            layout.HorizontalMargin = 2;
            layout.VerticalMargin = 0;
            layout.HorizontalAlignment = DebugHorizontalAlignment.Center;
            layout.VerticalAlignment = DebugVerticalAlignment.Center;
            layout.Arrange();
            // draw the text.
            spriteBatch.DrawString(font, helpMessage, new Vector2(layout.ArrangedBounds.X, layout.ArrangedBounds.Y), Color.Yellow);

            spriteBatch.End();
        }