MonoGdx.Scene2D.UI.Slider.CalculatePositionAndValue C# (CSharp) Méthode

CalculatePositionAndValue() private méthode

private CalculatePositionAndValue ( float x, float y ) : bool
x float
y float
Résultat bool
        bool CalculatePositionAndValue(float x, float y)
        {
            ISceneDrawable knob = (IsDisabled && _style.DisabledKnob != null) ? _style.DisabledKnob : _style.Knob;
            ISceneDrawable bg = (IsDisabled && _style.DisabledBackground != null) ? _style.DisabledBackground : _style.Background;

            float value;
            float oldPosition = _sliderPos;

            if (_vertical) {
                float height = Height - bg.TopHeight - bg.BottomHeight;
                float knobHeight = (knob == null) ? 0 : knob.MinHeight;
                _sliderPos = y - bg.BottomHeight - knobHeight * .5f;
                value = _min + (_max - _min) * (_sliderPos / (height - knobHeight));
                _sliderPos = Math.Max(0, _sliderPos);
                _sliderPos = Math.Min(height - knobHeight, _sliderPos);
            }
            else {
                float width = Width - bg.LeftWidth - bg.RightWidth;
                float knobWidth = (knob == null) ? 0 : knob.MinWidth;
                _sliderPos = x - bg.LeftWidth - knobWidth * .5f;
                value = _min + (_max - _min) * (_sliderPos / (width - knobWidth));
                _sliderPos = Math.Max(0, _sliderPos);
                _sliderPos = Math.Min(width - knobWidth, _sliderPos);
            }

            float oldValue = value;
            bool valueSet = SetValue(value);
            if (value == oldValue)
                _sliderPos = oldPosition;

            return valueSet;
        }