From cc06b827ffdb0f2e94f25c66bdb980173a015470 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 2 Apr 2020 17:54:10 +0200 Subject: [PATCH] use the new system in panel --- MLEM.Ui/Elements/Panel.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index b3806b3..87fb8a0 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -147,18 +147,18 @@ namespace MLEM.Ui.Elements { this.UpdateAreaIfDirty(); if (this.scrollOverflow && this.renderTarget != null) { // draw children onto the render target - batch.GraphicsDevice.SetRenderTarget(this.renderTarget); - batch.GraphicsDevice.Clear(Color.Transparent); - // offset children by the render target's location - var area = this.GetRenderTargetArea(); - var trans = Matrix.CreateTranslation(-area.X, -area.Y, 0); - // do the usual draw, but within the render target - batch.Begin(SpriteSortMode.Deferred, blendState, samplerState, null, null, null, trans); - base.Draw(time, batch, alpha, blendState, samplerState, trans); - batch.End(); - // also draw any children early within the render target with the translation applied - base.DrawEarly(time, batch, alpha, blendState, samplerState, trans); - batch.GraphicsDevice.SetRenderTarget(null); + using (batch.GraphicsDevice.WithRenderTarget(this.renderTarget)) { + batch.GraphicsDevice.Clear(Color.Transparent); + // offset children by the render target's location + var area = this.GetRenderTargetArea(); + var trans = Matrix.CreateTranslation(-area.X, -area.Y, 0); + // do the usual draw, but within the render target + batch.Begin(SpriteSortMode.Deferred, blendState, samplerState, null, null, null, trans); + base.Draw(time, batch, alpha, blendState, samplerState, trans); + batch.End(); + // also draw any children early within the render target with the translation applied + base.DrawEarly(time, batch, alpha, blendState, samplerState, trans); + } } else { base.DrawEarly(time, batch, alpha, blendState, samplerState, matrix); }