Exemplo n.º 1
0
 // Use this for initialization
 void Awake()
 {
     colorBinding  = new Binding <Color> (myColor, nameOfBinding);
     colorProperty = new Property <Color> (myColor);
     colorBinding.AddProperty(colorProperty, BindingDirection.BiDirectional);
     colorProperty.AddListener(UpdateColor);
     if (sliderR != null)
     {
         sliderRProperty = new SliderProperty(sliderR);
         sliderRProperty.AddListener(UpdateR);
         UpdateR(sliderR.value);
     }
     if (sliderG != null)
     {
         sliderGProperty = new SliderProperty(sliderG);
         sliderGProperty.AddListener(UpdateG);
         UpdateG(sliderG.value);
     }
     if (sliderB != null)
     {
         sliderBProperty = new SliderProperty(sliderB);
         sliderBProperty.AddListener(UpdateB);
         UpdateB(sliderB.value);
     }
     if (sliderA != null)
     {
         sliderAProperty = new SliderProperty(sliderA);
         sliderAProperty.AddListener(UpdateA);
         UpdateA(sliderA.value);
     }
 }
Exemplo n.º 2
0
 set => SetValue(SliderProperty, value);
Exemplo n.º 3
0
        public override void Update(GameTime gameTime, Vector2 mousePosition, Vector2 parentPosition)
        {
            if (GUIControl.UIElementEngaged && !IsEngaged)
            {
                return;
            }

            //Break Engagement
            if (IsEngaged && !GUIControl.IsLMBPressed())
            {
                GUIControl.UIElementEngaged = false;
                IsEngaged = false;
            }

            if (!GUIControl.IsLMBPressed())
            {
                return;
            }

            Vector2 bound1 = Position + parentPosition + _textBlock.Dimensions * Vector2.UnitY /*+ SliderIndicatorBorder*Vector2.UnitX*/;
            Vector2 bound2 = bound1 + SliderDimensions /* - 2*SliderIndicatorBorder * Vector2.UnitX*/;

            if (mousePosition.X >= bound1.X && mousePosition.Y >= bound1.Y && mousePosition.X < bound2.X &&
                mousePosition.Y < bound2.Y + 1)
            {
                GUIControl.UIElementEngaged = true;
                IsEngaged = true;
            }

            if (IsEngaged)
            {
                GUIControl.UIWasUsed = true;

                float lowerx = bound1.X + SliderIndicatorBorder;
                float upperx = bound2.X - SliderIndicatorBorder;

                _sliderPercent = MathHelper.Clamp((mousePosition.X - lowerx) / (upperx - lowerx), 0, 1);

                _sliderValue = (int)Math.Round(_sliderPercent * (float)(MaxValue - MinValue) + MinValue) / StepSize * StepSize;

                UpdateText();

                _sliderPercent = (float)(_sliderValue - MinValueInt) / (MaxValueInt - MinValueInt);

                if (SliderObject != null)
                {
                    if (SliderField != null)
                    {
                        SliderField.SetValue(SliderObject, SliderValue, BindingFlags.Public, null, null);
                    }
                    else if (SliderProperty != null)
                    {
                        SliderProperty.SetValue(SliderObject, SliderValue);
                    }
                }
                else
                {
                    if (SliderField != null)
                    {
                        SliderField.SetValue(null, SliderValue, BindingFlags.Static | BindingFlags.Public, null, null);
                    }
                    else if (SliderProperty != null)
                    {
                        SliderProperty.SetValue(null, SliderValue);
                    }
                }
            }
        }
Exemplo n.º 4
0
 public void SetProperty(Object obj, string property)
 {
     SliderObject   = obj;
     SliderProperty = obj.GetType().GetProperty(property);
     SliderValue    = (int)SliderProperty.GetValue(obj);
 }