Ejemplo 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);
            }
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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;
        }