Exemplo n.º 1
0
        protected override void LoadContent()
        {
            logs = new FrameLog[2];
            for (int i = 0; i < logs.Length; ++i)
            {
                logs[i] = new FrameLog();
            }

            sampleFrames = targetSampleFrames = 1;

            var vp = GraphicsDevice.Viewport;
            var layout = new Layout(new Rectangle(vp.X, vp.Y, vp.Width, vp.Height), vp.TitleSafeArea);

            width = (int) (layout.ClientArea.Width * 0.8f);

            position = layout.Place(
                new Vector2(width, BarHeight),
                0.0f,
                0.01f,
                LayoutAlignment.BottomCenter);

            base.LoadContent();
        }
        public override void Draw(GameTime gameTime)
        {
            sampleFrames++;

            // FPS 表示の周りに半透明の黒い矩形のサイズ計算と配置
            var size = Font.MeasureString("X");
            var rect = new Rectangle(0, 0, (int) (size.X * 14f), (int) (size.Y * 1.3f));

            var vp = GraphicsDevice.Viewport;
            var layout = new Layout(new Rectangle(vp.X, vp.Y, vp.Width, vp.Height), vp.TitleSafeArea);
            rect = layout.Place(rect, 0.01f, 0.01f, LayoutAlignment.TopLeft);

            // FPS 表示を矩形の中で配置
            size = Font.MeasureString(stringBuilder);
            layout.ClientArea = rect;
            var position = layout.Place(size, 0.0f, 0.1f, LayoutAlignment.Center);

            var fColor = !gameTime.IsRunningSlowly ? fontColor : runningSlowlyFontColor;

            SpriteBatch.Begin();
            SpriteBatch.Draw(FillTexture, rect, windowColor);
            SpriteBatch.DrawString(Font, stringBuilder, position, fColor);
            SpriteBatch.End();
        }
        public override void Draw(GameTime gameTime)
        {
            // コマンドウィンドウが完全に閉じている場合は描画処理をしない
            if (state == DebugCommandState.Closed)
            {
                return;
            }

            // コマンドウィンドウのサイズ計算と描画
            var vp = GraphicsDevice.Viewport;
            var layout = new Layout(new Rectangle(vp.X, vp.Y, vp.Width, vp.Height), vp.TitleSafeArea);
            var clientArea = layout.ClientArea;
            float w = clientArea.Width;
            float h = clientArea.Height;
            float topMargin = h * 0.1f;
            float leftMargin = w * 0.1f;

            var rect = new Rectangle();
            rect.X = (int) leftMargin;
            rect.Y = (int) topMargin;
            rect.Width = (int) (w * 0.8f);
            rect.Height = (int) (MaxLineCount * Font.LineSpacing);

            var transform = Matrix.CreateTranslation(new Vector3(0, -rect.Height * (1.0f - stateTransition), 0));

            SpriteBatch.Begin(
                SpriteSortMode.Deferred,
                null,
                null,
                null,
                null,
                null,
                transform);
            {
                // ウィンドウの背景を塗り潰します。
                SpriteBatch.Draw(FillTexture, rect, windowColor);

                // 文字列の描画
                var position = new Vector2(leftMargin, topMargin);
                foreach (string line in lines)
                {
                    //var builder = new System.Text.StringBuilder();
                    //foreach (var c in line)
                    //{
                    //    if (Font.Characters.Contains(c))
                    //    {
                    //        builder.Append(c);
                    //    }
                    //    else
                    //    {
                    //        builder.Append('*');
                    //    }
                    //}

                    SpriteBatch.DrawString(Font, line, position, fontColor);
                    //SpriteBatch.DrawString(Font, builder.ToString(), position, fontColor);
                    position.Y += Font.LineSpacing;
                }

                // プロンプト文字列の描画
                var leftPart = prompt + commandLine.Substring(0, cursorIndex);
                Vector2 cursorPos = position + Font.MeasureString(leftPart);
                cursorPos.Y = position.Y;

                SpriteBatch.DrawString(Font, string.Format("{0}{1}", prompt, commandLine), position, fontColor);
                SpriteBatch.DrawString(Font, Cursor, cursorPos, fontColor);
            }
            SpriteBatch.End();
        }