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

Draw() public method

public Draw ( Graphics spriteBatch, float parentAlpha ) : void
spriteBatch Graphics
parentAlpha float
return void
        public override void Draw(Graphics.G2D.GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            SliderStyle style = Style;
            bool disabled = IsDisabled;

            ISceneDrawable knob = (disabled && style.DisabledKnob != null) ? style.DisabledKnob : style.Knob;
            ISceneDrawable bg = (disabled && style.DisabledBackground != null) ? style.DisabledBackground : style.Background;
            ISceneDrawable knobBefore = (disabled && style.DisabledKnobBefore != null) ? style.DisabledKnobBefore : style.KnobBefore;
            ISceneDrawable knobAfter = (disabled && style.DisabledKnobAfter != null) ? style.DisabledKnobAfter : style.KnobAfter;

            Color color = Color;
            float x = X;
            float y = Y;
            float width = Width;
            float height = Height;
            float knobHeight = (knob == null) ? 0 : knob.MinHeight;
            float knobWidth = (knob == null) ? 0 : knob.MinWidth;
            float value = VisualValue;

            spriteBatch.Color = color.MultiplyAlpha(parentAlpha);

            if (_vertical) {
                bg.Draw(spriteBatch, x + (int)((width - bg.MinWidth) * .5f), y, bg.MinWidth, height);

                float sliderPosHeight = height - (bg.TopHeight + bg.BottomHeight);
                if (_min != _max) {
                    _sliderPos = (value - _min) / (_max - _min) * (sliderPosHeight - knobHeight);
                    _sliderPos = Math.Max(0, _sliderPos);
                    _sliderPos = Math.Min(sliderPosHeight - knobHeight, _sliderPos) + bg.BottomHeight;
                }

                float knobHeightHalf = knobHeight * .5f;
                if (knobBefore != null)
                    knobBefore.Draw(spriteBatch, x + (int)((width - knobBefore.MinWidth) * .5f), y,
                        knobBefore.MinWidth, (int)(_sliderPos + knobHeightHalf));
                if (knobAfter != null)
                    knobAfter.Draw(spriteBatch, x + (int)((width - knobAfter.MinWidth) * .5f), y + (int)(_sliderPos + knobHeightHalf),
                        knobAfter.MinWidth, height - (int)(_sliderPos + knobHeightHalf));
                if (knob != null)
                    knob.Draw(spriteBatch, x + (int)((width - knobWidth) * .5f), (int)(y + _sliderPos), knobWidth, knobHeight);
            }
            else {
                bg.Draw(spriteBatch, x, y + (int)((height - bg.MinHeight) * .5f), width, bg.MinHeight);

                float sliderPosWidth = width - (bg.LeftWidth + bg.RightWidth);
                if (_min != _max) {
                    _sliderPos = (value - _min) / (_max - _min) * (sliderPosWidth - knobWidth);
                    _sliderPos = Math.Max(0, _sliderPos);
                    _sliderPos = Math.Min(sliderPosWidth - knobWidth, _sliderPos) + bg.LeftWidth;
                }

                float knobWidthHalf = knobWidth * .5f;
                if (knobBefore != null)
                    knobBefore.Draw(spriteBatch, x, y + (int)((height - knobBefore.MinHeight) * .5f),
                        (int)(_sliderPos + knobWidthHalf), knobBefore.MinHeight);
                if (knobAfter != null)
                    knobAfter.Draw(spriteBatch, x + (int)(_sliderPos + knobWidthHalf), y + (int)((height - knobAfter.MinWidth) * .5f),
                        width - (int)(_sliderPos + knobWidthHalf), knobAfter.MinHeight);
                if (knob != null)
                    knob.Draw(spriteBatch, (int)(x + _sliderPos), (int)(y + (height - knobHeight) * .5f), knobWidth, knobHeight);
            }
        }