MonoGdx.Scene2D.UI.ScrollPane.Draw C# (CSharp) Method

Draw() public method

public Draw ( GdxSpriteBatch spriteBatch, float parentAlpha ) : void
spriteBatch MonoGdx.Graphics.G2D.GdxSpriteBatch
parentAlpha float
return void
        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);
        }