Ejemplo n.º 1
0
 private void BriSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
 {
     if (slidersAllowed)
     {
         PutEvents.ChangeBrightness(LightProperty.GetLightSource(((Slider)sender)), (int)((Slider)sender).Value);
     }
 }
Ejemplo n.º 2
0
        private void MegaSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            double fraction = MegaSlider.Value / oldMega;

            if (slidersAllowed && !usingSlider)
            {
                usingMega = true;

                double approachFraction;
                if (fraction > 1)
                {
                    approachFraction = (MegaSlider.Value - oldMega) / (MegaSlider.Maximum - oldMega);
                }
                else
                {
                    approachFraction = 1;
                }

                foreach (string light in Storage.groupData.lights)
                {
                    double brightness = JsonParser.Read(Storage.latestData, new string[] { "lights", light, "state", "bri" });
                    if (fraction > 1)
                    {
                        brightness += (254 - brightness) * approachFraction;
                    }
                    else
                    {
                        brightness *= fraction;
                    }
                    PutEvents.ChangeBrightness(light, (int)brightness);
                }

                //Visual change only
                for (int i = 1; i <= 5; i++)
                {
                    string sliderName = String.Format("Slider{0}", i);
                    Slider sliderRef  = (Slider)this.FindName(sliderName);

                    if (sliderRef.IsEnabled)
                    {
                        if (fraction > 1)
                        {
                            sliderRef.Value += (sliderRef.Maximum - sliderRef.Value) * approachFraction;
                        }
                        else
                        {
                            sliderRef.Value *= fraction;
                        }
                    }
                }

                usingMega = false;
            }

            oldMega = MegaSlider.Value;
        }