/// <inheritdoc />
 /// <summary>
 /// If the action of selecting scene nodes at the scene is active 
 /// we will draw selecting rectangle.
 /// </summary>
 public override void Draw(SceneBatch sceneBatch)
 {
     // If the action of selecting objects at the scene is active
     // we will draw selecting rectangle.
     if (SelectingNodes)
     {
         sceneBatch.ApplyBasicEffect();
         sceneBatch.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, drawSelectingRectangle, 0, 2);
     }
 }
Example #2
0
        /// <summary>
        /// Called when the <see cref="SceneScreen"/> needs to be drawn.
        /// </summary>
        /// <remarks>
        /// Draws in this order:
        /// <list type="bullet">
        /// <item><description>background</description></item>
        /// <item><description>grid, if visible</description></item>
        /// <item><description>visible scene nodes</description></item>
        /// <item><description>shapes of visible scene nodes, if visible</description></item>
        /// <item><description>hands the drawing over to the <see cref="State"/> (<see cref="SceneState.Draw"/> method) of the SceneScreen control</description></item>
        /// <item><description>information box at the upper right corner, information about the position under the mouse at the bottom right corner and
        /// simulation units measure information at the bottom left corner</description></item>
        /// </list>
        /// </remarks>
        /// <param name="gameTime">Time passed since the last call to Draw.</param>
        protected override void Draw(GameTime gameTime)
        {
            // clear with background color
            GraphicsDevice.Clear(ColorSettings.BackgroundColor);

            sceneBatch.SceneSize     = new Vector2(Width * ScaleInversFactor, Height * ScaleInversFactor);
            sceneBatch.ScenePosition = Position;

            // draw grid
            if (ShowGrid)
            {
                sceneBatch.Begin(ref projection, ref identity, ref world, ScaleFactor, ScaleInversFactor, ref gameTime);

                float gridGapSize = GridGapSize * ScaleInversFactor;
                float sceneWidth  = Width * ScaleInversFactor;
                float sceneHeight = Height * ScaleInversFactor;

                for (float i = -Position.Y % gridGapSize; i <= sceneHeight; i += gridGapSize)
                {
                    sceneBatch.DrawLine(new Vector3(Position.X, Position.Y + i, 0f), new Vector3(Position.X + sceneWidth, Position.Y + i, 0f), ColorSettings.GridLineColor);
                }

                for (float i = -Position.X % gridGapSize; i <= sceneWidth; i += gridGapSize)
                {
                    sceneBatch.DrawLine(new Vector3(Position.X + i, Position.Y, 0f), new Vector3(Position.X + i, Position.Y + sceneHeight, 0f), ColorSettings.GridLineColor);
                }

                sceneBatch.End();
            }

            // draw scene (game objects)
            sceneBatch.Begin(ref projection, ref identity, ref world, ScaleFactor, ScaleInversFactor, ref gameTime);

            foreach (SceneNode node in GetAllSceneNodesReverse(true))
            {
                node.Draw(sceneBatch);
            }

            sceneBatch.End();

            // draw scene (game objects) shapes
            if (ShowShapes)
            {
                sceneBatch.Begin(ref projection, ref identity, ref world, ScaleFactor, ScaleInversFactor, ref gameTime);

                foreach (SceneNode node in GetAllSceneNodesReverse(true))
                {
                    node.DrawShapes(sceneBatch);
                }

                sceneBatch.End();
            }

            State.Draw(sceneBatch);

            // draw front (like hud)
            sceneBatch.Begin(ref projection, ref identity, ref identity, ScaleFactor, ScaleInversFactor, ref gameTime);

            // draw info box background and border
            sceneBatch.ApplyBasicEffect();
            sceneBatch.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, infoBoxRectangle, 0, 2);
            sceneBatch.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineStrip, infoBoxBorder, 0, 2);

            // draw simulation units measure
            sceneBatch.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, simulationUnitsLine, 0, 1);
            sceneBatch.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, simulationUnitsArrows, 0, 2);

            // draw rotating update icon
            sceneBatch.Apply2D();
            sceneBatch.Draw(updateIcon, new Vector2(Width - 90, 18), null, Color.White, (float)lastTime.TotalSeconds * 2f, new Vector2(updateIcon.Width / 2f, updateIcon.Height / 2f), 1f, SpriteEffects.None, 0f);

            // draw fps text
            sceneBatch.DrawString(font, String.Format("{0,9} FPS", Fps), new Vector2(Width - 80, 10), ColorSettings.InfoBoxTextColor);

            // draw mouse scene position in simulation units
            sceneBatch.DrawString(font, String.Format("X: {0,-6:0.###}", GameEngine.ConvertUnits.ToSimUnits(MouseScenePosition.X)), new Vector2(Width - 70, Height - 40), ColorSettings.InfoBoxTextColor);
            sceneBatch.DrawString(font, String.Format("Y: {0,-6:0.###}", GameEngine.ConvertUnits.ToSimUnits(MouseScenePosition.Y)), new Vector2(Width - 70, Height - 20), ColorSettings.InfoBoxTextColor);

            // draw simulation units text
            sceneBatch.DrawString(font, "1 meter", new Vector2(10, Height - 30), ColorSettings.InfoBoxTextColor);

            sceneBatch.End();
        }