public virtual void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
{
var layoutWidth = layout.Width - skinLayout.HorizontalScrollBarHeight;
var layoutHeight = layout.Height - skinLayout.VerticalScrollBarWidth;
int childWidth, childHeight;
if (!(_child is IHasDesiredSize))
{
childWidth = layoutWidth;
childHeight = layoutHeight;
}
else
{
var hasDesiredSize = (IHasDesiredSize) _child;
childWidth = hasDesiredSize.GetDesiredWidth(skinLayout) ?? layoutWidth;
childHeight = hasDesiredSize.GetDesiredHeight(skinLayout) ?? layoutHeight;
if (childWidth < layoutWidth)
{
childWidth = layoutWidth;
}
if (childHeight < layoutHeight)
{
childHeight = layoutHeight;
}
}
if (_renderTarget == null || _renderTarget.Width != childWidth ||
_renderTarget.Height != childHeight)
{
_renderTarget?.Dispose();
_renderTarget = new RenderTarget2D(
context.GraphicsDevice,
Math.Max(1, childWidth),
Math.Max(1, childHeight));
}
context.SpriteBatch.End();
context.PushRenderTarget(_renderTarget);
context.GraphicsDevice.Clear(Color.Transparent);
context.SpriteBatch.Begin();
try
{
_child?.Render(
context,
skinLayout,
skinDelegator,
new Rectangle(0, 0, childWidth, childHeight));
}
finally
{
context.SpriteBatch.End();
context.PopRenderTarget();
context.SpriteBatch.Begin();
}
skinDelegator.Render(context, layout, this);
}