예제 #1
0
        public override void PreDraw(UISpriteBatch batch)
        {
            //If our matrix is dirty, recalculate it
            if (_MtxDirty)
            {
                CalculateMatrix();
            }

            if (!Visible)
            {
                return;
            }

            var gd = batch.GraphicsDevice;

            if (Invalidated)
            {
                var size = Size * Scale;
                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, (UseZ)?DepthFormat.Depth24:DepthFormat.None);
                }

                lock (Children)
                {
                    foreach (var child in Children)
                    {
                        if (child == DynamicOverlay)
                        {
                            continue;
                        }
                        child.PreDraw(batch);
                    }
                }

                batch.End();
                gd.SetRenderTarget(Target);
                gd.Clear(ClearColor);
                var pos = LocalPoint(0, 0);

                batch.Begin(transformMatrix: Microsoft.Xna.Framework.Matrix.CreateTranslation(-(pos.X - BackOffset.X), -(pos.Y - BackOffset.Y), 0), blendState: BlendState.AlphaBlend, sortMode: SpriteSortMode.Deferred);
                batch.GraphicsDevice.RasterizerState = RasterizerState.CullNone;
                lock (Children)
                {
                    foreach (var child in Children)
                    {
                        if (child == DynamicOverlay)
                        {
                            continue;
                        }
                        child.Draw(batch);
                    }
                }
                batch.End();
                gd.SetRenderTarget(null);
                Invalidated = false;
            }
            DynamicOverlay.PreDraw(batch);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="batch"></param>
        /// <param name="mtx"></param>
        public override void Draw(UISpriteBatch batch)
        {
            if (Width == 0 || Height == 0 || !DoRedraw)
            {
                return;
            }
            DoRedraw = false;
            batch    = Batch;
            batch.UIBegin(BlendState.AlphaBlend, SpriteSortMode.Deferred);
            Promise <Texture2D> bufferTexture = null;

            using (batch.WithBuffer(ref bufferTexture))
            {
                lock (Children)
                {
                    foreach (var child in Children)
                    {
                        child.PreDraw(batch);
                    }
                    foreach (var child in Children)
                    {
                        child.Draw(batch);
                    }
                }
                batch.Pause();
                batch.Resume();
            }

            var tex = bufferTexture.Get();

            batch.End();

            tex.GetData(RawImage, 0, (GameFacade.DirectX) ? RawImage.Length : RawImage.Length / 4);

            for (int i = 0; i < RawImage.Length; i += 4)
            {
                var swap = RawImage[i];
                RawImage[i]     = RawImage[i + 2];
                RawImage[i + 2] = swap;
            }
            if (OnFrame != null)
            {
                OnFrame();
            }
            //batch.Draw(tex, Vector2.Zero, _BlendColor);
        }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="batch"></param>
        /// <param name="mtx"></param>
        public override void Draw(UISpriteBatch batch)
        {
            if (Width == 0 || Height == 0 || !DoRedraw) return;
            DoRedraw = false;
            batch = Batch;
            batch.UIBegin(BlendState.AlphaBlend, SpriteSortMode.Deferred);
            Promise<Texture2D> bufferTexture = null;
            using (batch.WithBuffer(ref bufferTexture))
            {
                lock (Children)
                {
                    foreach (var child in Children)
                    {
                        child.PreDraw(batch);
                    }
                    foreach (var child in Children)
                    {
                        child.Draw(batch);
                    }
                }
                batch.Pause();
                batch.Resume();
            }

            var tex = bufferTexture.Get();
            batch.End();

            tex.GetData(RawImage, 0, (GameFacade.DirectX) ? RawImage.Length : RawImage.Length/4);

            for (int i=0; i<RawImage.Length; i+=4)
            {
                var swap = RawImage[i];
                RawImage[i] = RawImage[i + 2];
                RawImage[i + 2] = swap;
            }
            if (OnFrame != null) OnFrame();
            //batch.Draw(tex, Vector2.Zero, _BlendColor);
        }
예제 #4
0
        public override void PreDraw(UISpriteBatch batch)
        {
            //If our matrix is dirty, recalculate it
            if (_MtxDirty)
            {
                CalculateMatrix();
            }

            if (!Visible)
            {
                return;
            }

            var gd = batch.GraphicsDevice;

            if (Invalidated)
            {
                var size = Size * Scale;
                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, UseMip, SurfaceFormat.Color, (UseZ)?DepthFormat.Depth24:DepthFormat.None, (UseMultisample && !FSOEnvironment.DirectX)?4:0, RenderTargetUsage.PreserveContents);
                }

                lock (Children)
                {
                    foreach (var child in Children)
                    {
                        if (child == DynamicOverlay)
                        {
                            continue;
                        }
                        child.PreDraw(batch);
                    }
                }

                try { batch.End(); } catch { }
                gd.SetRenderTarget(Target);

                gd.Clear(ClearColor);
                var pos = LocalPoint(0, 0);

                var mat = Microsoft.Xna.Framework.Matrix.CreateTranslation(-(pos.X), -(pos.Y), 0) *
                          Microsoft.Xna.Framework.Matrix.CreateScale(1f) *
                          Microsoft.Xna.Framework.Matrix.CreateTranslation(
                    BackOffset.X / FSOEnvironment.DPIScaleFactor,
                    BackOffset.Y / FSOEnvironment.DPIScaleFactor, 0);

                batch.BatchMatrixStack.Push(mat);

                batch.Begin(transformMatrix: mat, blendState: BlendState.AlphaBlend, sortMode: SpriteSortMode.Deferred, rasterizerState: RasterizerState.CullNone);
                batch.GraphicsDevice.RasterizerState = RasterizerState.CullNone;
                if (InternalBefore)
                {
                    InternalDraw(batch);
                }
                lock (Children)
                {
                    foreach (var child in Children)
                    {
                        if (child == DynamicOverlay)
                        {
                            continue;
                        }
                        child.Draw(batch);
                    }
                }
                if (!InternalBefore)
                {
                    InternalDraw(batch);
                }
                batch.BatchMatrixStack.Pop();
                batch.End();
                gd.SetRenderTarget(null);
                Invalidated = false;
            }
            DynamicOverlay.PreDraw(batch);
        }