Ejemplo n.º 1
0
        public virtual void Draw(IRenderContext context, ISkin skin, Rectangle layout)
        {
            var layoutWidth  = layout.Width - skin.HorizontalScrollBarHeight;
            var layoutHeight = layout.Height - skin.VerticalScrollBarWidth;

            int childWidth, childHeight;

            if (this.m_Child == null || !(this.m_Child is IHasDesiredSize))
            {
                childWidth  = layoutWidth;
                childHeight = layoutHeight;
            }
            else
            {
                var hasDesiredSize = this.m_Child as IHasDesiredSize;
                childWidth  = hasDesiredSize.GetDesiredWidth(skin) ?? layoutWidth;
                childHeight = hasDesiredSize.GetDesiredHeight(skin) ?? layoutHeight;
                if (childWidth < layoutWidth)
                {
                    childWidth = layoutWidth;
                }
                if (childHeight < layoutHeight)
                {
                    childHeight = layoutHeight;
                }
            }

            if (this.m_RenderTarget == null || this.m_RenderTarget.Width != childWidth ||
                this.m_RenderTarget.Height != childHeight)
            {
                if (this.m_RenderTarget != null)
                {
                    this.m_RenderTarget.Dispose();
                }

                this.m_RenderTarget = new RenderTarget2D(
                    context.GraphicsDevice,
                    Math.Max(1, childWidth),
                    Math.Max(1, childHeight));
            }

            skin.BeforeRenderTargetChange(context);
            context.PushRenderTarget(this.m_RenderTarget);
            context.GraphicsDevice.Clear(Color.Transparent);
            skin.AfterRenderTargetChange(context);
            try
            {
                if (this.m_Child != null)
                {
                    this.m_Child.Draw(
                        context,
                        skin,
                        new Rectangle(0, 0, childWidth, childHeight));
                }
            }
            finally
            {
                skin.BeforeRenderTargetChange(context);
                context.PopRenderTarget();
                skin.AfterRenderTargetChange(context);
            }

            skin.DrawScrollableContainer(context, layout, this, this.m_RenderTarget);
        }