Esempio n. 1
0
        public override void PreDraw(UISpriteBatch batch)
        {
            if (!Visible)
            {
                return;
            }
            base.PreDraw(batch);

            if (Mask)
            {
                var gd   = batch.GraphicsDevice;
                var size = Size;
                if (Target == null || (int)size.X != Target.Width || (int)size.Y != Target.Height)
                {
                    Target?.Dispose();
                    Target = new RenderTarget2D(gd, (int)size.X, (int)size.Y, false, SurfaceFormat.Color, DepthFormat.None);
                }
                batch.End();
                gd.SetRenderTarget(Target);
                gd.Clear(Color.Transparent);
                var pos = LocalPoint(0, 0);

                batch.Begin(transformMatrix: Microsoft.Xna.Framework.Matrix.CreateTranslation(-pos.X, -pos.Y, 0), blendState: BlendState.AlphaBlend, sortMode: SpriteSortMode.Deferred);
                batch.GraphicsDevice.RasterizerState = RasterizerState.CullNone;
                _Draw(batch);
                batch.End();
                gd.SetRenderTarget(null);
            }
        }
Esempio n. 2
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)
        {
            base.Draw(gameTime);

            /** Any pre-draw work **/
            lock (GraphicsDevice)
            {
                spriteBatch.UIBegin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
                ScreenMgr.PreDraw(spriteBatch);
                spriteBatch.End();
            }

            GraphicsDevice.Clear(new Color(23, 23, 23));
            GraphicsDevice.RenderState.AlphaBlendEnable  = true;
            GraphicsDevice.RenderState.DepthBufferEnable = true;

            //Deferred sorting seems to just work...
            //NOTE: Using SaveStateMode.SaveState is IMPORTANT to make 3D rendering work properly!
            lock (GraphicsDevice)
            {
                spriteBatch.UIBegin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
                ScreenMgr.Draw(spriteBatch, m_FPS);
                spriteBatch.End();
                SceneMgr.Draw();
            }
        }
Esempio n. 3
0
        public void PreDraw(GraphicsDevice device)
        {
            lock (m_ExtContainers)
            {
                foreach (var ext in m_ExtContainers)
                {
                    lock (ext)
                    {
                        if (!ext.HasUpdated)
                        {
                            ext.Update(null);
                        }
                        ext.PreDraw(SpriteBatch);
                        ext.Draw(SpriteBatch);
                    }
                }
            }

            SpriteBatch.UIBegin(BlendState.AlphaBlend, SpriteSortMode.Immediate);
            this.PreDraw(SpriteBatch);
            SpriteBatch.End();
        }
Esempio n. 4
0
        public override void Draw(UISpriteBatch batch)
        {
            batch.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            batch.GraphicsDevice.BlendState        = BlendState.NonPremultiplied;
            Camera.ProjectionOrigin = new Vector2(batch.GraphicsDevice.Viewport.Width, batch.GraphicsDevice.Viewport.Height) / 2;
            Scene.Draw(batch.GraphicsDevice);

            var text = (Comp3D?.Sum(x => x.Mesh?.Geoms?.FirstOrDefault()?.Sum(y => y.Value.PrimCount) ?? 0) ?? 0) + " tris";

            batch.End();
            GameFacade.EdithVectorFont.Draw(batch.GraphicsDevice, text, new Vector2(10), Color.Black, Vector2.One * 0.6f, null);

            batch.Begin();
        }
Esempio n. 5
0
        /* Graphics functions */

        /// <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)
        {
            GraphicsDevice.Clear(Color.Blue);
            UISpriteBatch.Begin();

            if (CurrentGameState == GameStatus.Title)
            {
                TitleState.Draw();
            }
            else if (CurrentGameState == GameStatus.Loading)
            {
                TitleState.DrawLoadingScreen();
            }
            else if (CurrentGameState == GameStatus.Playing)
            {
                DrawPlaying(gameTime);
            }

            UISpriteBatch.End();
            base.Draw(gameTime);
        }
Esempio n. 6
0
 public void PreDraw(GraphicsDevice device)
 {
     spriteBatch.UIBegin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
     this.PreDraw(spriteBatch);
     spriteBatch.End();
 }
Esempio n. 7
0
        public override void PreDraw(UISpriteBatch batch)
        {
            base.PreDraw(batch);
            if (Z > 0)
            {
                return;
            }
            var newIntScale = (float)((ScaleX > 1) ? Math.Round(ScaleX) : 1 / (Math.Round((1 / ScaleX))));

            if (newIntScale > 5)
            {
                newIntScale = 5;
            }

            if (IntScale != newIntScale)
            {
                IntScale = newIntScale;
                Invalid  = true;
            }
            var width      = CaptionWidth + 120;
            var activeRect = new Rectangle((int)(IntScale * width / -2), (int)(-40 * IntScale), (int)(width * IntScale), (int)(80 * IntScale));

            if (activeRect.Width == 0)
            {
                activeRect.Width = 1;
            }
            if (activeRect.Height == 0)
            {
                activeRect.Height = 1;
            }
            if (Invalid || Target == null || activeRect.Size != new Point(Target.Width, Target.Height))
            {
                var gd = GameFacade.GraphicsDevice;
                if (Batch == null)
                {
                    Batch = new UISpriteBatch(gd, 0);
                }
                Target?.Dispose();
                Target = new RenderTarget2D(gd, activeRect.Width, activeRect.Height);

                //draw the banner
                gd.SetRenderTarget(Target);
                gd.Clear(Color.Transparent);
                var scale = Microsoft.Xna.Framework.Matrix.CreateScale(IntScale);
                Batch.BatchMatrixStack.Push(scale);
                Batch.Begin(transformMatrix: scale);

                var o = Opacity;
                Opacity = 1;
                CalculateOpacity();
                gd.RasterizerState = RasterizerState.CullNone;
                InternalDraw(Batch);
                Opacity = o;
                CalculateOpacity();

                Batch.BatchMatrixStack.Pop();
                Batch.End();
                //batch.Resume();
                gd.SetRenderTarget(null);
                Invalid = false;
            }
            Position = Position;
        }