/// <summary>
        /// Draws the control.
        /// </summary>
        protected override void Draw()
        {
            UpdateTimer();
            Update();

            // Clear to the default control background color.
            //Color backColor = new Color(BackColor.R, BackColor.G, BackColor.B);
            Color backColor = Color.CornflowerBlue;

            GraphicsDevice.Clear(backColor);

            if (SpriteFont != null && LineBatch != null && Effect != null)
            {
                Matrix viewProjMatrix = viewMatrix * projMatrix;

                lineBatch.NumLinesDrawn = 0;

                float lineRadius = 4;
                lineBatch.BlurThreshold = lineBatch.ComputeBlurThreshold(lineRadius, viewProjMatrix,
                                                                         GraphicsDevice.PresentationParameters.BackBufferWidth);

                float  time             = (float)gameTimer.TotalGameTime.TotalSeconds;
                string curTechniqueName = roundLineTechniqueNames[roundLineTechniqueIndex];

                lineBatch.Draw(blueRoundLines, viewProjMatrix, time, curTechniqueName);
                lineBatch.Draw(greenRoundLines, viewProjMatrix, time, curTechniqueName);

                dude.Pos = new Vector2(cameraX, cameraY);
                lineBatch.Draw(dude, viewProjMatrix, time, "Tubular");

                Vector2 textPos = new Vector2(50, 50);
                spriteBatch.Begin();
                if (gameTimer.IsRunningSlowly)
                {
                    spriteBatch.DrawString(SpriteFont, "IsRunningSlowly", textPos, Color.Red);
                }
                else
                {
                    spriteBatch.DrawString(SpriteFont, "IsRunningNormally", textPos, Color.White);
                }

                textPos += new Vector2(0, 30);
                spriteBatch.DrawString(SpriteFont, string.Format("{0} Lines", lineBatch.NumLinesDrawn), textPos, Color.White);

                textPos += new Vector2(0, 30);
                spriteBatch.DrawString(SpriteFont, string.Format("Technique (Press A): {0}", curTechniqueName), textPos, Color.White);

                spriteBatch.End();
            }
        }
Пример #2
0
        private void DrawGridsAndScale()
        {
            Matrix viewProjMatrix = viewMatrix * projMatrix;

            //var majorlinesPen = new Pen(System.Drawing.Color.Wheat, 1);
            //var minorlinesPen = new Pen(System.Drawing.Color.LightGray, 1);
            majorLines.Clear();
            minorLines.Clear();

            Xorigin = Yorigin = 0;
            ScaleX  = _width;
            ScaleY  = _height;

            _width  = (int)(SizePicture.X);
            _height = (int)(SizePicture.Y);

            var xMajorLines = (int)(_width / MajorIntervals / ScaleDraw.X);
            var yMajorLines = (int)(_height / MajorIntervals / ScaleDraw.Y);

            try
            {
                //draw X Axis major lines
                for (int i = 0; i <= xMajorLines; i++)
                {
                    float x = i * (_width / xMajorLines);
                    minorLines.Add(new XnaLine2d(x, 0.0f, x, _height, 4.0f, Color.LightGray));

                    //draw X Axis minor lines
                    for (int i1 = 1; i1 <= Xdivs; i1++)
                    {
                        float x1 = i1 * MajorIntervals / (Xdivs) * ScaleDraw.X;
                        majorLines.Add(new XnaLine2d(x + x1, 0, x + x1, _height, 4.0f, Color.Wheat));
                    }
                }

                //draw Y Axis major lines
                for (int i = 0; i <= yMajorLines; i++)
                {
                    //y = i * (Height / (yMajorLines));
                    float y = i * MajorIntervals * ScaleDraw.Y;
                    minorLines.Add(new XnaLine2d(0, y, _width, y, 4.0f, Color.LightGray));

                    //draw Y Axis minor lines
                    for (int i1 = 1; i1 <= Ydivs; i1++)
                    {
                        float y1 = i1 * MajorIntervals / (Ydivs) * ScaleDraw.Y;
                        majorLines.Add(new XnaLine2d(0, y + y1, _width, y + y1, 4.0f, Color.Wheat));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            float  time             = (float)gameTimer.TotalGameTime.TotalSeconds;
            string curTechniqueName = roundLineTechniqueNames[0];

            if (LineBatch != null)
            {
                lineBatch.Draw(minorLines, viewProjMatrix, time, curTechniqueName);
                lineBatch.Draw(majorLines, viewProjMatrix, time, curTechniqueName);
            }
        }