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); }
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); }