예제 #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            bool found = false;

            MonoMenu.Engine.Monitor.DrawCalled();

            MatrixD  cameraTransf = Camera.Instance.Transform;
            Vector3D transl       = cameraTransf.Translation;
            Vector2D mClkPos      = new Vector2D(clickPos.X - GraphicsDevice.PresentationParameters.BackBufferWidth / 2, clickPos.Y - GraphicsDevice.PresentationParameters.BackBufferHeight / 2);

            mClkPos /= Camera.Instance.Zoom;
            mClkPos += Camera.Instance.Position;
            string fps = "FPS: " + (1 / gameTime.ElapsedGameTime.TotalSeconds);
            string bods = "Bodies: " + (Galaxy.Instance.Stars.Count + Galaxy.Instance.Planets.Count);
            string markedToRemove = "Marked to be removed: " + Galaxy.Instance.ToRemove;
            string iterations = "Iterations: " + Galaxy.Instance.Iterations;
            string memoryusg = "Memory Usage: " + (MonoMenu.Engine.Monitor.MemoryUsage / 10e5);
            string camerapos = "Camera position: " + (int)Camera.Instance.Position.X + " " + (int)Camera.Instance.Position.Y;
            string mousepos = "Mouse position: " + (int)mClkPos.X + " " + (int)mClkPos.Y;
            string zoomlvl = "Zoom level: " + Camera.Instance.Zoom;
            string following = string.Empty, mass = string.Empty, pxpy = string.Empty, vxvy = string.Empty;

            if (Camera.Instance.Following != null)
            {
                following = "Following: " + Camera.Instance.Following.id;
                if (Camera.Instance.Following is Star)
                {
                    double m = Camera.Instance.Following.mass / Constants.SUN_MASS;
                    mass = "Mass: " + m.ToString("0.##E+0", CultureInfo.InvariantCulture) + " SM";
                }
                else
                {
                    double m = Camera.Instance.Following.mass / Constants.EARTH_SIZE;
                    mass       = "Mass: " + m.ToString("0.##E+0", CultureInfo.InvariantCulture) + " EM + Size: " + Camera.Instance.Following.size;
                    following += " Star: " + (Camera.Instance.Following as Planet).Star.id;
                }
                pxpy = "pX: " + Camera.Instance.Following.posX + " - pY: " + Camera.Instance.Following.posY;
                vxvy = "vX: " + Camera.Instance.Following.vX + " - vY: " + Camera.Instance.Following.vY;
            }
            Menu["fpsRect"].Text    = fps;
            Menu["bodsRect"].Text   = bods;
            Menu["markedRect"].Text = markedToRemove;
            Menu["itRect"].Text     = iterations;
            Menu["memRect"].Text    = memoryusg;
            Menu["camRect"].Text    = camerapos;
            Menu["mouseRect"].Text  = mousepos;
            Menu["zoomRect"].Text   = zoomlvl;
            Menu["followRect"].Text = following;
            Menu["massRect"].Text   = mass;
            Menu["pxpyRect"].Text   = pxpy;
            Menu["vxvyRect"].Text   = vxvy;
            Menu.Draw(spriteBatch, monoRenderTarget);


            GraphicsDevice.SetRenderTarget(preProcessRenderTarget);
            // TODO: Add your drawing code here
            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, null);

            GraphicsDevice.Clear(Color.Black);
            if (Camera.Instance.Zoom * Constants.SUN_SIZE * 10 >= 1)
            {
                while (!System.Threading.Monitor.TryEnter(Galaxy.Instance.starListLock))
                {
                    ;
                }
                foreach (Star body in Galaxy.Instance.Stars)
                {
                    RectangleD destRect = new RectangleD(body.posX - body.size / 2, body.posY - body.size / 2, body.size, body.size);
                    if (Camera.Instance.VisibleArea.Contains(destRect) || Camera.Instance.VisibleArea.Intersects(destRect))
                    {
                        if (destRect.Contains(mClkPos) && leftMousePressed)
                        {
                            found = true;
                            Camera.Instance.Follow(body);
                        }
                        Color  color = GetStarColor(body);
                        double size  = body.size * Camera.Instance.Zoom;
                        double posX  = (body.posX * Camera.Instance.Zoom) + transl.X - size / 2;
                        double posY  = (body.posY * Camera.Instance.Zoom) + transl.Y - size / 2;
                        spriteBatch.Draw(circle.CircleText, new Rectangle((int)posX, (int)posY, (int)size, (int)size), color);
                        //spriteBatch.Draw(circle.CircleText, new Microsoft.Xna.Framework.Rectangle((int)(body.Position.X + graphics.PreferredBackBufferWidth / 2 - 2.5), (int)(body.Position.Y + graphics.PreferredBackBufferHeight / 2 - 2.5), 5, 5), Color.Red);
                    }
                }
                System.Threading.Monitor.Exit(Galaxy.Instance.starListLock);
            }
            spriteBatch.End();

            Texture2D bloom = bloomFilter.Draw(preProcessRenderTarget, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);

            GraphicsDevice.SetRenderTarget(planetRenderTarget);

            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, null);
            GraphicsDevice.Clear(Color.Black);

            while (!System.Threading.Monitor.TryEnter(Galaxy.Instance.planetListLock))
            {
                ;
            }
            foreach (Planet body in Galaxy.Instance.Planets)
            {
                RectangleD destRect = new RectangleD(body.posX - body.size / 2, body.posY - body.size / 2, body.size, body.size);
                if (Camera.Instance.VisibleArea.Contains(destRect) || Camera.Instance.VisibleArea.Intersects(destRect))
                {
                    if (destRect.Contains(mClkPos) && leftMousePressed)
                    {
                        found = true;
                        Camera.Instance.Follow(body);
                    }
                    Color  color = GetPlanetColor(body);
                    double size  = body.size * Camera.Instance.Zoom;
                    double posX  = (body.posX * Camera.Instance.Zoom) + transl.X - size / 2;
                    double posY  = (body.posY * Camera.Instance.Zoom) + transl.Y - size / 2;
                    spriteBatch.Draw(circle.CircleText, new Rectangle((int)Math.Round(posX), (int)Math.Round(posY), (int)Math.Round(size), (int)Math.Round(size)), color);
                    //spriteBatch.Draw(circle.CircleText, new Microsoft.Xna.Framework.Rectangle((int)(body.Position.X + graphics.PreferredBackBufferWidth / 2 - 2.5), (int)(body.Position.Y + graphics.PreferredBackBufferHeight / 2 - 2.5), 5, 5), Color.Red);
                }
            }
            System.Threading.Monitor.Exit(Galaxy.Instance.planetListLock);
            if (leftMousePressed && !found)
            {
                Camera.Instance.Follow(null);
            }

            spriteBatch.End();

            #region Draw quad outline
            if (pause)
            {
                while (!System.Threading.Monitor.TryEnter(Galaxy.Instance.quadLock))
                {
                }
                GraphicsDevice.SetRenderTarget(gridRenderTarget);
                spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, null);
                Galaxy.Instance.root.DrawOutline(spriteBatch, pixel, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, Camera.Instance.VisibleArea, transl);
                System.Threading.Monitor.Exit(Galaxy.Instance.quadLock);
                spriteBatch.End();
            }
            #endregion


            GraphicsDevice.SetRenderTarget(null);
            spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive);
            spriteBatch.Draw(preProcessRenderTarget, new Vector2(0, 0), Color.White);
            spriteBatch.Draw(bloom, new Vector2(-3f, -3f), Color.White);
            spriteBatch.Draw(planetRenderTarget, new Vector2(0, 0), Color.White);
            if (pause)
            {
                spriteBatch.Draw(gridRenderTarget, new Vector2(0, 0), Color.White);
            }
            spriteBatch.Draw(pixel, new Rectangle(new Point(MouseInput.MousePosition.X - 2, MouseInput.MousePosition.Y - 2), new Point(4, 4)), Color.Red);
            spriteBatch.Draw(monoRenderTarget, new Rectangle(0, 0, monoRenderTarget.Width, monoRenderTarget.Height), Color.White);
            spriteBatch.End();
            base.Draw(gameTime);
            leftMousePressed = false;
        }
예제 #2
0
        protected override void Draw(GameTime gameTime)
        {
            //Draw our game to a seperate texture
            if (_displayMode == DisplayModes.Game)
            {
                //Initialize our render target if not done yet
                if (_backbufferRenderTarget == null || _backbufferRenderTarget.Width != Width ||
                    _backbufferRenderTarget.Height != Height)
                {
                    _backbufferRenderTarget = new RenderTarget2D(GraphicsDevice, Width, Height);
                }

                //Background
                _sampleGame.DrawBackground(GraphicsDevice, Width, Height);

                //Foreground
                GraphicsDevice.SetRenderTarget(_backbufferRenderTarget);

                _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
                _sampleGame.Draw(_spriteBatch);
                _spriteBatch.End();
            }

            /*this is the important step
             * We need to provide an image for the color grading
             * filter to process, along with a look up table.
             * If we use this for a game we must draw our game to a texture (rendertarget) beforehand*/
            Texture2D output = null;

            if (_lutModes == LUTModes.None)
            {
                output = GetSelectedImage();
            }
            else
            {
                output = _colorGradingFilter.Draw(GraphicsDevice, GetSelectedImage(), GetSelectedLUT());
            }


            //Apply bloom filter if we draw the game!
            Texture2D bloom = null;

            if (_displayMode == DisplayModes.Game)
            {
                bloom = _bloomFilter.Draw(output, Width, Height);
            }

            //Draw to the backbuffer
            GraphicsDevice.SetRenderTarget(null);
            GraphicsDevice.Clear(Color.Black);

            //Draw our images to the screen
            _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive);

            //The texture can be treated just as any other one.
            _spriteBatch.Draw(output, new Rectangle(0, 0, Width, Height), Color.White);

            //Bloom for our game
            if (_displayMode == DisplayModes.Game)
            {
                _spriteBatch.Draw(bloom, Vector2.Zero, Color.White);
            }


            _spriteBatch.End();
        }
예제 #3
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            // Draw lines to texture and apply blink-highlighting effect if line is at end point
            RenderLinesToTexture(lineTexture);

            // Draw bloom when elimination is not not started or when panel is solved
            if (line != null && (!panelState.State.HasFlag(PanelStates.EliminationStarted) || panelState.State.HasFlag(PanelStates.Solved)))
            {
                // We are using separate SpriteBatch to draw bloom, so we have to draw background in this batch too, so it will be below bloom texture
                internalBatch.Begin();
                internalBatch.Draw(backgroundTexture, GraphicsDevice.Viewport.Bounds, Color.White);

                if (SettingsManager.BloomFX)
                {
                    // Idk, more weird majiks, but if i call this Draw outside of this batch or inside next (additive) batch, background goes black
                    // So yeah... I guess it stays here now...
                    Texture2D bloom = bloomFilter.Draw(lineTexture, ScreenSize.X, ScreenSize.Y);

                    internalBatch.End();

                    // Now draw bloom texture in additive blend mode
                    internalBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive);
                    internalBatch.Draw(bloom, GraphicsDevice.Viewport.Bounds, Color.White * 0.8f);
                }
                internalBatch.End();
            }
            else
            {
                // If we don't draw bloom, then we can use the same SpriteBatch to draw background texture
                spriteBatch.Draw(backgroundTexture, GraphicsDevice.Viewport.Bounds, Color.White);
            }

            // Draw line to the backbuffer
            spriteBatch.Draw(lineTexture, GraphicsDevice.Viewport.Bounds, Color.White);

            // Draw fading line after aborting tracing or submitting wrong solution
            if (panelState.State.HasFlag(PanelStates.LineFade) && lineFadeTexture != null)
            {
                spriteBatch.Draw(lineFadeTexture, GraphicsDevice.Viewport.Bounds, (panelState.State.HasFlag(PanelStates.ErrorHappened) ? Color.Black : Color.White) * panelState.LineFadeOpacity);
            }

            // Draw red blinking rules after submitting the wrong solution
            if (panelState.State.HasFlag(PanelStates.ErrorBlink) && errorsBlinkTexture != null)
            {
                spriteBatch.Draw(errorsBlinkTexture, GraphicsDevice.Viewport.Bounds, Color.White * panelState.ErrorBlinkOpacity);
            }

            // Animate fading into gray of eliminated rules
            if (panelState.State.HasFlag(PanelStates.EliminationFinished) && eliminatedErrorsTexture != null)
            {
                spriteBatch.Draw(eliminatedErrorsTexture, GraphicsDevice.Viewport.Bounds, Color.White * panelState.EliminationFadeOpacity);
            }

            // Draw buttons
            foreach (var button in buttons)
            {
                button.Draw(spriteBatch);
            }

            // Draw node IDs
            if (drawDebug)
            {
                DebugDrawNodeIDs(spriteBatch);
            }

            if (fade.IsActive)
            {
                spriteBatch.Draw(texPixel, new Rectangle(Point.Zero, ScreenSize), Color.Black * fade.Opacity);
            }

            base.Draw(spriteBatch);
        }