Exemplo n.º 1
0
        public bool ClipBegin(float x, float y, float width, float height)
        {
            Rectangle tableBounds   = new Rectangle((int)x, (int)y, (int)width, (int)height);
            Rectangle scissorBounds = ScissorStack.CalculateScissors(Stage.Camera, Stage.SpriteBatch.TransformMatrix, tableBounds);

            return(Stage.ScissorStack.PushScissors(scissorBounds));
        }
Exemplo n.º 2
0
        public override bool Draw(Batcher2D batcher, Point position, Vector3?hue = null)
        {
            Children[0].Draw(batcher, new Point(position.X + Children[0].X, position.Y + Children[0].Y));
            _rect.X      = position.X;
            _rect.Y      = position.Y;
            _rect.Width  = Width - 14;
            _rect.Height = Height;
            Rectangle scissor = ScissorStack.CalculateScissors(batcher.TransformMatrix, _rect);

            if (ScissorStack.PushScissors(scissor))
            {
                batcher.EnableScissorTest(true);
                int  height    = 0;
                int  maxheight = _scrollBar.Value + Height;
                bool drawOnly1 = true;

                position = _rect.Location;

                for (int i = 1; i < Children.Count; i++)
                {
                    Control child = Children[i];

                    if (!child.IsVisible)
                    {
                        continue;
                    }

                    child.Y = height - _scrollBar.Value /*+ (_isNormalScroll ? 20 : 0)*/;

                    if (height + child.Height <= _scrollBar.Value)
                    {
                        // do nothing
                    }
                    else if (height + child.Height <= maxheight)
                    {
                        child.Draw(batcher, new Point(position.X + child.X, position.Y + child.Y));
                    }
                    else
                    {
                        if (drawOnly1)
                        {
                            child.Draw(batcher, new Point(position.X + child.X, position.Y + child.Y));
                            drawOnly1 = false;
                        }
                    }

                    height += child.Height;
                }

                batcher.EnableScissorTest(false);
                ScissorStack.PopScissors();
            }

            return(true);
        }
Exemplo n.º 3
0
        public override bool Draw(Batcher2D batcher, int x, int y)
        {
            var scrollbar = Children[0];

            scrollbar.Draw(batcher, x + scrollbar.X, y + scrollbar.Y);

            Rectangle scissor = ScissorStack.CalculateScissors(batcher.TransformMatrix, x, y, Width - 14, Height);

            if (ScissorStack.PushScissors(scissor))
            {
                batcher.EnableScissorTest(true);
                int  height    = 0;
                int  maxheight = _scrollBar.Value + Height;
                bool drawOnly1 = true;


                for (int i = 1; i < Children.Count; i++)
                {
                    Control child = Children[i];

                    if (!child.IsVisible)
                    {
                        continue;
                    }

                    child.Y = height - _scrollBar.Value /*+ (_isNormalScroll ? 20 : 0)*/;

                    if (height + child.Height <= _scrollBar.Value)
                    {
                        // do nothing
                    }
                    else if (height + child.Height <= maxheight)
                    {
                        child.Draw(batcher, x + child.X, y + child.Y);
                    }
                    else
                    {
                        if (drawOnly1)
                        {
                            child.Draw(batcher, x + child.X, y + child.Y);
                            drawOnly1 = false;
                        }
                    }

                    height += child.Height;
                }

                batcher.EnableScissorTest(false);
                ScissorStack.PopScissors();
            }

            return(true);
        }
Exemplo n.º 4
0
        public override bool Draw(SpriteBatchUI spriteBatch, Point position, Vector3?hue = null)
        {
            Children[0].Draw(spriteBatch, new Point(position.X + Children[0].X, position.Y + Children[0].Y));
            _rect.X      = position.X;
            _rect.Y      = position.Y;
            _rect.Width  = Width;
            _rect.Height = Height;
            Rectangle scissor = ScissorStack.CalculateScissors(spriteBatch.TransformMatrix, _rect);

            if (ScissorStack.PushScissors(scissor))
            {
                spriteBatch.EnableScissorTest(true);
                int  height    = 0;
                int  maxheight = _scrollBar.Value + _scrollBar.Height;
                bool drawOnly1 = true;

                for (int i = 1; i < Children.Count; i++)
                {
                    GumpControl child = Children[i];

                    if (!child.IsVisible)
                    {
                        continue;
                    }
                    child.Y = height - _scrollBar.Value;

                    if (height + child.Height <= _scrollBar.Value)
                    {
                        // do nothing
                    }
                    else if (height + child.Height <= maxheight)
                    {
                        child.Draw(spriteBatch, new Point(position.X + child.X, position.Y + child.Y));
                    }
                    else
                    {
                        if (drawOnly1)
                        {
                            child.Draw(spriteBatch, new Point(position.X + child.X, position.Y + child.Y));
                            drawOnly1 = false;
                        }
                    }

                    height += child.Height;
                }

                spriteBatch.EnableScissorTest(false);
                ScissorStack.PopScissors();
            }

            return(true);
        }
Exemplo n.º 5
0
        public override bool Draw(UltimaBatcher2D batcher, int x, int y)
        {
            Rectangle rectangle = ScissorStack.CalculateScissors(Matrix.Identity, x, y, Width, Height);

            if (ScissorStack.PushScissors(rectangle))
            {
                batcher.EnableScissorTest(true);

                ResetHueVector();

                if (Engine.Profile.Current != null && Engine.Profile.Current.UseXBR)
                {
                    // draw regular world
                    _xBR.SetSize(_scene.ViewportTexture.Width, _scene.ViewportTexture.Height);

                    batcher.End();

                    batcher.Begin(_xBR);
                    batcher.Draw2D(_scene.ViewportTexture, x, y, Width, Height, ref _hueVector);
                    batcher.End();

                    batcher.Begin();
                }
                else
                {
                    batcher.Draw2D(_scene.ViewportTexture, x, y, Width, Height, ref _hueVector);
                }


                // draw lights
                if (_scene.UseLights)
                {
                    batcher.SetBlendState(_blend);
                    batcher.Draw2D(_scene.Darkness, x, y, Width, Height, ref _hueVector);
                    batcher.SetBlendState(null);
                }

                // draw overheads
                _scene.DrawSelection(batcher, x, y);
                _scene.DrawOverheads(batcher, x, y);

                base.Draw(batcher, x, y);

                batcher.EnableScissorTest(false);
                ScissorStack.PopScissors();
            }

            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Clips the specified screen aligned rectangle, specified relative to the transform matrix of the stage's Batch. The
        /// transform matrix and the stage's camera must not have rotational components. Calling this method must be followed by a call
        /// to clipEnd() if true is returned.
        /// </summary>
        public bool ClipBegin(Batcher batcher, float x, float y, float width, float height)
        {
            if (width <= 0 || height <= 0)
            {
                return(false);
            }

            var tableBounds   = RectangleExt.FromFloats(x, y, width, height);
            var scissorBounds = ScissorStack.CalculateScissors(stage?.Entity?.Scene?.Camera, batcher.TransformMatrix, tableBounds);

            if (ScissorStack.PushScissors(scissorBounds))
            {
                batcher.EnableScissorTest(true);
                return(true);
            }

            return(false);
        }
Exemplo n.º 7
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            Stage stage = Stage;

            Validate();

            ISceneDrawable handle = _style.Handle;

            ApplyTransform(spriteBatch, ComputeTransform());
            Matrix transform = spriteBatch.TransformMatrix;

            if (_firstWidget != null)
            {
                _firstScissors = ScissorStack.CalculateScissors(stage.Camera, spriteBatch.TransformMatrix, (Rectangle)_firstWidgetBounds);
                if (stage.ScissorStack.PushScissors(_firstScissors))
                {
                    if (_firstWidget.IsVisible)
                    {
                        _firstWidget.Draw(spriteBatch, parentAlpha * Color.A / 255f);
                    }
                    spriteBatch.Flush();
                    stage.ScissorStack.PopScissors();
                }
            }

            if (_secondWidget != null)
            {
                _secondScissors = ScissorStack.CalculateScissors(stage.Camera, spriteBatch.TransformMatrix, (Rectangle)_secondWidgetBounds);
                if (stage.ScissorStack.PushScissors(_secondScissors))
                {
                    if (_secondWidget.IsVisible)
                    {
                        _secondWidget.Draw(spriteBatch, parentAlpha * Color.A / 255f);
                    }
                    spriteBatch.Flush();
                    stage.ScissorStack.PopScissors();
                }
            }

            spriteBatch.Color = Color;
            handle.Draw(spriteBatch, _handleBounds.X, _handleBounds.Y, _handleBounds.Width, _handleBounds.Height);
            ResetTransform(spriteBatch);
        }
Exemplo n.º 8
0
        public override bool Draw(UltimaBatcher2D batcher, int x, int y)
        {
            var scrollbar = Children[0];

            scrollbar.Draw(batcher, x + scrollbar.X, y + scrollbar.Y);

            Rectangle scissor = ScissorStack.CalculateScissors(Matrix.Identity, x + ScissorRectangle.X, y + ScissorRectangle.Y, (Width - 14) + ScissorRectangle.Width, Height + ScissorRectangle.Height);

            if (ScissorStack.PushScissors(scissor))
            {
                batcher.EnableScissorTest(true);
                int height = ScissorRectangle.Y;

                for (int i = 1; i < Children.Count; i++)
                {
                    Control child = Children[i];

                    if (!child.IsVisible)
                    {
                        continue;
                    }

                    child.Y = height - _scrollBar.Value;

                    if (height + child.Height <= _scrollBar.Value)
                    {
                        // do nothing
                    }
                    else
                    {
                        child.Draw(batcher, x + child.X, y + child.Y);
                    }

                    height += child.Height;
                }

                batcher.EnableScissorTest(false);
                ScissorStack.PopScissors();
            }

            return(true);
        }
Exemplo n.º 9
0
        public override bool Draw(UltimaBatcher2D batcher, int x, int y)
        {
            ScrollBarBase scrollbar = (ScrollBarBase)Children[0];

            scrollbar.Draw(batcher, x + scrollbar.X, y + scrollbar.Y);

            Rectangle scissor = ScissorStack.CalculateScissors
                                (
                Matrix.Identity,
                x + ScissorRectangle.X,
                y + ScissorRectangle.Y,
                Width - 14 + ScissorRectangle.Width,
                Height + ScissorRectangle.Height
                                );

            if (ScissorStack.PushScissors(batcher.GraphicsDevice, scissor))
            {
                batcher.EnableScissorTest(true);

                for (int i = 1; i < Children.Count; i++)
                {
                    Control child = Children[i];

                    if (!child.IsVisible)
                    {
                        continue;
                    }

                    int finalY = y + child.Y - scrollbar.Value + ScissorRectangle.Y;

                    //if (finalY + child.Bounds.Height >= scissor.Y && finalY - child.Height < scissor.Bottom)
                    {
                        child.Draw(batcher, x + child.X, finalY);
                    }
                }

                batcher.EnableScissorTest(false);
                ScissorStack.PopScissors(batcher.GraphicsDevice);
            }

            return(true);
        }
Exemplo n.º 10
0
        public override bool Draw(UltimaBatcher2D batcher, int x, int y)
        {
            if (IsDisposed)
            {
                return(false);
            }

            ResetHueVector();

            Rectangle scissor = ScissorStack.CalculateScissors
                                (
                Matrix.Identity,
                x,
                y,
                Width,
                Height
                                );

            if (ScissorStack.PushScissors(batcher.GraphicsDevice, scissor))
            {
                batcher.EnableScissorTest(true);
                base.Draw(batcher, x, y);

                _gameText.Draw
                (
                    batcher,
                    Width + ScrollX,
                    Height + ScrollY,
                    x,
                    y,
                    Width,
                    Height,
                    ScrollX,
                    ScrollY
                );

                batcher.EnableScissorTest(false);
                ScissorStack.PopScissors(batcher.GraphicsDevice);
            }

            return(true);
        }
Exemplo n.º 11
0
        public override void Draw(Graphics graphics, float parentAlpha)
        {
            Validate();

            if (transform)
            {
                ApplyTransform(graphics, ComputeTransform());
            }
            if (_firstWidget != null && _firstWidget.IsVisible())
            {
                var scissor = ScissorStack.CalculateScissors(stage?.Camera, graphics.Batcher.TransformMatrix,
                                                             _firstWidgetBounds);
                if (ScissorStack.PushScissors(scissor))
                {
                    graphics.Batcher.EnableScissorTest(true);
                    _firstWidget.Draw(graphics, parentAlpha * color.A);
                    graphics.Batcher.EnableScissorTest(false);
                    ScissorStack.PopScissors();
                }
            }

            if (_secondWidget != null && _secondWidget.IsVisible())
            {
                var scissor = ScissorStack.CalculateScissors(stage?.Camera, graphics.Batcher.TransformMatrix,
                                                             _secondWidgetBounds);
                if (ScissorStack.PushScissors(scissor))
                {
                    graphics.Batcher.EnableScissorTest(true);
                    _secondWidget.Draw(graphics, parentAlpha * color.A);
                    graphics.Batcher.EnableScissorTest(false);
                    ScissorStack.PopScissors();
                }
            }

            _style.Handle.Draw(graphics, _handleBounds.X, _handleBounds.Y, _handleBounds.Width, _handleBounds.Height,
                               new Color(color, (int)(color.A * parentAlpha)));

            if (transform)
            {
                ResetTransform(graphics);
            }
        }
Exemplo n.º 12
0
        public override void DebugRender(Graphics graphics)
        {
            if (transform)
            {
                ApplyTransform(graphics, ComputeTransform());
            }

            var scissor = ScissorStack.CalculateScissors(stage?.Camera, graphics.Batcher.TransformMatrix, _widgetAreaBounds);

            if (ScissorStack.PushScissors(scissor))
            {
                graphics.Batcher.EnableScissorTest(true);
                DebugRenderChildren(graphics, 1f);
                graphics.Batcher.EnableScissorTest(false);
                ScissorStack.PopScissors();
            }

            if (transform)
            {
                ResetTransform(graphics);
            }
        }
Exemplo n.º 13
0
        public override bool Draw(UltimaBatcher2D batcher, int x, int y)
        {
            ResetHueVector();

            var rect = ScissorStack.CalculateScissors(Matrix.Identity, x, y, Width, Height);

            if (ScissorStack.PushScissors(rect))
            {
                ShaderHuesTraslator.GetHueVector(ref _hueVector, 0, false, Alpha, true);

                batcher.EnableScissorTest(true);

                DrawInternal(batcher, x, y, ref _hueVector);
                base.Draw(batcher, x, y);

                batcher.EnableScissorTest(false);
                ScissorStack.PopScissors();

                return(true);
            }

            return(false);
        }
Exemplo n.º 14
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            if (_widget == null)
            {
                return;
            }

            Validate();

            // Setup transform for this group
            ApplyTransform(spriteBatch, ComputeTransform());

            if (IsScrollX)
            {
                _hKnobBounds.X = _hScrollBounds.X + (int)((_hScrollBounds.Width - _hKnobBounds.Width) * ScrollPercentX);
            }
            if (IsScrollY)
            {
                _vKnobBounds.Y = _vScrollBounds.Y + (int)((_vScrollBounds.Height - _vKnobBounds.Height) * (1 - ScrollPercentY));
            }

            // Calculate the widget's position depending on the scroll state and available widget area.
            float y = _widgetAreaBounds.Y;

            if (!IsScrollY)
            {
                y -= (int)MaxY;
            }
            else
            {
                y -= (int)(MaxY - _visualAmountY);
            }

            if (!_fadeScrollBars && ScrollBarsOnTop && IsScrollX)
            {
                float scollbarHeight = 0;
                if (_style.HScrollKnob != null)
                {
                    scollbarHeight = _style.HScrollKnob.MinHeight;
                }
                if (_style.HScroll != null)
                {
                    scollbarHeight = Math.Max(scollbarHeight, _style.HScroll.MinHeight);
                }
                y += scollbarHeight;
            }

            float x = _widgetAreaBounds.X;

            if (IsScrollX)
            {
                x -= (int)_visualAmountX;
            }

            _widget.SetPosition(x, y);

            if (_widget is ICullable)
            {
                _widgetCullingArea.X      = -_widget.X + _widgetAreaBounds.X;
                _widgetCullingArea.Y      = -_widget.Y + _widgetAreaBounds.Y;
                _widgetCullingArea.Width  = _widgetAreaBounds.Width;
                _widgetCullingArea.Height = _widgetAreaBounds.Height;

                (_widget as ICullable).SetCullingArea(_widgetCullingArea);
            }

            // Caculate the scissor bounds based on the batch transform, the available widget area and the camera transform. We need to
            // project those to screen coordinates for OpenGL ES to consume.
            _scissorBounds = ScissorStack.CalculateScissors(Stage.Camera, spriteBatch.TransformMatrix, (Rectangle)_widgetAreaBounds);

            // Draw the background ninepatch
            spriteBatch.Color = Color.MultiplyAlpha(parentAlpha);
            if (_style.Background != null)
            {
                _style.Background.Draw(spriteBatch, 0, 0, Width, Height);
            }
            spriteBatch.Flush();

            // Enable scissors for widget area and draw the widget.
            if (Stage.ScissorStack.PushScissors(_scissorBounds))
            {
                DrawChildren(spriteBatch, parentAlpha);
                Stage.ScissorStack.PopScissors();
            }

            // Render scrollbars and knobs on top.
            spriteBatch.Color = Color.MultiplyAlpha(parentAlpha * Interpolation.Fade.Apply(_fadeAlpha / FadeAlphaSeconds));
            if (IsScrollX && IsScrollY)
            {
                if (_style.Corner != null)
                {
                    _style.Corner.Draw(spriteBatch, _hScrollBounds.X + _hScrollBounds.Width, _hScrollBounds.Y, _vScrollBounds.Width, _vScrollBounds.Height);
                }
            }

            if (IsScrollX)
            {
                if (_style.HScroll != null)
                {
                    _style.HScroll.Draw(spriteBatch, _hScrollBounds.X, _hScrollBounds.Y, _hScrollBounds.Width, _hScrollBounds.Height);
                }
                if (_style.HScrollKnob != null)
                {
                    _style.HScrollKnob.Draw(spriteBatch, _hKnobBounds.X, _hKnobBounds.Y, _hKnobBounds.Width, _hKnobBounds.Height);
                }
            }

            if (IsScrollY)
            {
                if (_style.VScroll != null)
                {
                    _style.VScroll.Draw(spriteBatch, _vScrollBounds.X, _vScrollBounds.Y, _vScrollBounds.Width, _vScrollBounds.Height);
                }
                if (_style.VScrollKnob != null)
                {
                    _style.VScrollKnob.Draw(spriteBatch, _vKnobBounds.X, _vKnobBounds.Y, _vKnobBounds.Width, _vKnobBounds.Height);
                }
            }

            ResetTransform(spriteBatch);
        }
Exemplo n.º 15
0
        public override bool Draw(UltimaBatcher2D batcher, int x, int y)
        {
            if (_scene.ViewportTexture == null)
            {
                return(false);
            }

            Rectangle rectangle = ScissorStack.CalculateScissors(Matrix.Identity, x, y, Width, Height);

            if (ScissorStack.PushScissors(batcher.GraphicsDevice, rectangle))
            {
                batcher.EnableScissorTest(true);

                ResetHueVector();

                if (ProfileManager.Current != null && ProfileManager.Current.UseXBR)
                {
                    // draw regular world
                    if (_xBR == null)
                    {
                        _xBR = new XBREffect(batcher.GraphicsDevice);
                    }

                    _xBR.SetSize(_scene.ViewportTexture.Width, _scene.ViewportTexture.Height);

                    batcher.End();

                    batcher.Begin(_xBR);
                    batcher.Draw2D(_scene.ViewportTexture, x, y, Width, Height, ref _hueVector);
                    batcher.End();

                    batcher.Begin();
                }
                else
                {
                    batcher.Draw2D(_scene.ViewportTexture, x, y, Width, Height, ref _hueVector);
                }


                // draw lights
                // if (_scene.UseAltLights)
                // {
                //     batcher.SetBlendState(_altLightsBlend);
                //     _hueVector.Z = 0.5f;
                //     batcher.Draw2D(_scene.LightRenderTarget, x, y, Width, Height, ref _hueVector);
                //     _hueVector.Z = 0;
                //     batcher.SetBlendState(null);
                // }
                // else if (_scene.UseLights)
                // {
                //     batcher.SetBlendState(_darknessBlend);
                //     batcher.Draw2D(_scene.LightRenderTarget, x, y, Width, Height, ref _hueVector);
                //     batcher.SetBlendState(null);
                // }

                // draw overheads
                _scene.DrawSelection(batcher, x, y);
                _scene.DrawOverheads(batcher, x, y);

                base.Draw(batcher, x, y);

                batcher.EnableScissorTest(false);
                ScissorStack.PopScissors(batcher.GraphicsDevice);
            }

            return(true);
        }
Exemplo n.º 16
0
        public override bool Draw(UltimaBatcher2D batcher, int x, int y)
        {
            base.Draw(batcher, x, y);
            Rectangle scissor = ScissorStack.CalculateScissors(Matrix.Identity, x, y, Width, Height);

            if (ScissorStack.PushScissors(batcher.GraphicsDevice, scissor))
            {
                batcher.EnableScissorTest(true);
                RenderedText t         = _bookPage.renderedText;
                int          startpage = (ActivePage - 1) * 2;

                if (startpage < BookPageCount)
                {
                    int poy = _bookPage._pageCoords[startpage, 0], phy = _bookPage._pageCoords[startpage, 1];
                    _bookPage.DrawSelection(batcher, x + RIGHT_X, y + UPPER_MARGIN, poy, poy + phy);
                    t.Draw(batcher, x + RIGHT_X, y + UPPER_MARGIN, 0, poy, t.Width, phy);

                    if (startpage == _bookPage._caretPage)
                    {
                        if (_bookPage._caretPos.Y < poy + phy)
                        {
                            if (_bookPage._caretPos.Y >= poy)
                            {
                                if (_bookPage.HasKeyboardFocus)
                                {
                                    _bookPage.renderedCaret.Draw
                                    (
                                        batcher, _bookPage._caretPos.X + x + RIGHT_X,
                                        _bookPage._caretPos.Y + y + UPPER_MARGIN - poy, 0, 0,
                                        _bookPage.renderedCaret.Width, _bookPage.renderedCaret.Height
                                    );
                                }
                            }
                            else
                            {
                                _bookPage._caretPage = _bookPage.GetCaretPage();
                            }
                        }
                        else if (_bookPage._caretPos.Y <= _bookPage.Height)
                        {
                            if (_bookPage._caretPage + 2 < _bookPage._pagesChanged.Length)
                            {
                                _bookPage._focusPage = _bookPage._caretPage++;
                                SetActivePage(_bookPage._caretPage / 2 + 2);
                            }
                        }
                    }
                }

                startpage--;

                if (startpage > 0)
                {
                    int poy = _bookPage._pageCoords[startpage, 0], phy = _bookPage._pageCoords[startpage, 1];
                    _bookPage.DrawSelection(batcher, x + LEFT_X, y + UPPER_MARGIN, poy, poy + phy);
                    t.Draw(batcher, x + LEFT_X, y + UPPER_MARGIN, 0, poy, t.Width, phy);

                    if (startpage == _bookPage._caretPage)
                    {
                        if (_bookPage._caretPos.Y < poy + phy)
                        {
                            if (_bookPage._caretPos.Y >= poy)
                            {
                                if (_bookPage.HasKeyboardFocus)
                                {
                                    _bookPage.renderedCaret.Draw
                                    (
                                        batcher, _bookPage._caretPos.X + x + LEFT_X,
                                        _bookPage._caretPos.Y + y + UPPER_MARGIN - poy, 0, 0,
                                        _bookPage.renderedCaret.Width, _bookPage.renderedCaret.Height
                                    );
                                }
                            }
                            else if (_bookPage._caretPage > 0)
                            {
                                _bookPage._focusPage = _bookPage._caretPage--;
                                SetActivePage(_bookPage._caretPage / 2 + 1);
                            }
                        }
                        else if (_bookPage._caretPos.Y <= _bookPage.Height)
                        {
                            if (_bookPage._caretPage + 2 < _bookPage._pagesChanged.Length)
                            {
                                _bookPage._caretPage++;
                            }
                        }
                    }
                }

                batcher.EnableScissorTest(false);
                ScissorStack.PopScissors(batcher.GraphicsDevice);
            }

            return(true);
        }
Exemplo n.º 17
0
        public override void Draw(Graphics graphics, float parentAlpha)
        {
            if (_widget == null)
            {
                return;
            }

            Update();
            Validate();

            // setup transform for this group.
            if (transform)
            {
                ApplyTransform(graphics, ComputeTransform());
            }

            if (_scrollX)
            {
                _hKnobBounds.X = _hScrollBounds.X + (int)((_hScrollBounds.Width - _hKnobBounds.Width) * GetVisualScrollPercentX());
            }
            if (_scrollY)
            {
                _vKnobBounds.Y = _vScrollBounds.Y + (int)((_vScrollBounds.Height - _vKnobBounds.Height) * GetVisualScrollPercentY());
            }

            // calculate the widget's position depending on the scroll state and available widget area.
            float eleY = _widgetAreaBounds.Y;

            if (!_scrollY)
            {
                eleY -= _maxY;
            }
            else
            {
                eleY -= _visualAmountY;
            }

            float eleX = _widgetAreaBounds.Y;

            if (_scrollX)
            {
                eleX -= (int)_visualAmountX;
            }

            if (!_fadeScrollBars && _scrollbarsOnTop)
            {
                if (_scrollX && _hScrollOnBottom)
                {
                    var scrollbarHeight = 0f;
                    if (_style.HScrollKnob != null)
                    {
                        scrollbarHeight = _style.HScrollKnob.MinHeight;
                    }
                    if (_style.HScroll != null)
                    {
                        scrollbarHeight = Math.Max(scrollbarHeight, _style.HScroll.MinHeight);
                    }
                    eleY += scrollbarHeight;
                }
                if (_scrollY && !_vScrollOnRight)
                {
                    var scrollbarWidth = 0f;
                    if (_style.HScrollKnob != null)
                    {
                        scrollbarWidth = _style.HScrollKnob.MinWidth;
                    }
                    if (_style.HScroll != null)
                    {
                        scrollbarWidth = Math.Max(scrollbarWidth, _style.HScroll.MinWidth);
                    }
                    eleX += scrollbarWidth;
                }
            }

            _widget.SetPosition(eleX, eleY);

            if (_widget is ICullable)
            {
                var cull = new Rectangle(
                    (int)(-_widget.GetX() + _widgetAreaBounds.X),
                    (int)(-_widget.GetY() + _widgetAreaBounds.Y),
                    _widgetAreaBounds.Width,
                    _widgetAreaBounds.Height);
                ((ICullable)_widget).SetCullingArea(cull);
            }

            // draw the background
            var color = GetColor();

            color = new Color(color, (int)(color.A * parentAlpha));
            if (_style.Background != null)
            {
                _style.Background.Draw(graphics, 0, 0, GetWidth(), GetHeight(), color);
            }

            // caculate the scissor bounds based on the batch transform, the available widget area and the camera transform. We need to
            // project those to screen coordinates for OpenGL to consume.
            var scissor = ScissorStack.CalculateScissors(stage?.Camera, graphics.Batcher.TransformMatrix, _widgetAreaBounds);

            if (ScissorStack.PushScissors(scissor))
            {
                graphics.Batcher.EnableScissorTest(true);
                DrawChildren(graphics, parentAlpha);
                graphics.Batcher.EnableScissorTest(false);
                ScissorStack.PopScissors();
            }

            // render scrollbars and knobs on top
            var alpha = (float)color.A;

            color.A = (byte)(alpha * (_fadeAlpha / _fadeAlphaSeconds));
            if (_scrollX && _scrollY)
            {
                if (_style.Corner != null)
                {
                    _style.Corner.Draw(graphics, _hScrollBounds.X + _hScrollBounds.Width, _hScrollBounds.Y, _vScrollBounds.Width, _vScrollBounds.Y, color);
                }
            }
            if (_scrollX)
            {
                if (_style.HScroll != null)
                {
                    _style.HScroll.Draw(graphics, _hScrollBounds.X, _hScrollBounds.Y, _hScrollBounds.Width, _hScrollBounds.Height, color);
                }
                if (_style.HScrollKnob != null)
                {
                    _style.HScrollKnob.Draw(graphics, _hKnobBounds.X, _hKnobBounds.Y, _hKnobBounds.Width, _hKnobBounds.Height, color);
                }
            }
            if (_scrollY)
            {
                if (_style.VScroll != null)
                {
                    _style.VScroll.Draw(graphics, _vScrollBounds.X, _vScrollBounds.Y, _vScrollBounds.Width, _vScrollBounds.Height, color);
                }
                if (_style.VScrollKnob != null)
                {
                    _style.VScrollKnob.Draw(graphics, _vKnobBounds.X, _vKnobBounds.Y, _vKnobBounds.Width, _vKnobBounds.Height, color);
                }
            }

            if (transform)
            {
                ResetTransform(graphics);
            }
        }