Пример #1
0
        public Slider(float min, float max, float stepSize, bool vertical, SliderStyle style)
        {
            if (min > max)
                throw new ArgumentException("min must be > max: " + min + " > " + max);
            if (stepSize < 0)
                throw new ArgumentOutOfRangeException("stepSize must be > 0: " + stepSize);

            Style = style;
            _min = min;
            _max = max;
            _stepSize = stepSize;
            _vertical = vertical;
            _value = min;

            Width = PrefWidth;
            Height = PrefHeight;
        }
Пример #2
0
        public Slider(float min, float max, float stepSize, bool vertical, SliderStyle style)
        {
            if (min > max)
            {
                throw new ArgumentException("min must be > max: " + min + " > " + max);
            }
            if (stepSize < 0)
            {
                throw new ArgumentOutOfRangeException("stepSize must be > 0: " + stepSize);
            }

            Style     = style;
            _min      = min;
            _max      = max;
            _stepSize = stepSize;
            _vertical = vertical;
            _value    = min;

            Width  = PrefWidth;
            Height = PrefHeight;
        }
Пример #3
0
 public SliderStyle(SliderStyle style)
 {
     Background = style.Background;
     Knob       = style.Knob;
 }
Пример #4
0
        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);
                }
            }
        }
Пример #5
0
 public SliderStyle(SliderStyle style)
 {
     Background = style.Background;
     Knob = style.Knob;
 }