예제 #1
0
        public void ValidateFractionalWidthDoesNotCrash()
        {
            ColorSpectrum colorSpectrum = null;

            RunOnUIThread.Execute(() =>
            {
                colorSpectrum        = new ColorSpectrum();
                colorSpectrum.Width  = 300.75;
                colorSpectrum.Height = 300.75;
            });

            SetAsRootAndWaitForColorSpectrumFill(colorSpectrum);
        }
        public void ColorSpectrumEventsTest()
        {
            RunOnUIThread.Execute(() =>
            {
                ColorSpectrum colorSpectrum = new ColorSpectrum();

                colorSpectrum.ColorChanged += (ColorSpectrum sender, ColorChangedEventArgs args) =>
                {
                    Verify.AreEqual(args.OldColor, Colors.Red);
                    Verify.AreEqual(args.NewColor, Colors.Green);
                };

                colorSpectrum.Color = Colors.Green;
            });
        }
        public void ValidateFractionalWidthDoesNotCrash()
        {
            ColorSpectrum colorSpectrum = null;

            RunOnUIThread.Execute(() =>
            {
                colorSpectrum = new ColorSpectrum();

                // 332.75 is the fractional value that caused a crash in Settings when DPI was set to 200%
                // and text scaling was set to >160%.  It ensures that we exercise all of the round() fixes
                // that we made in ColorSpectrum to ensure we always round fractional values instead of
                // truncating them.
                colorSpectrum.Width  = 332.75;
                colorSpectrum.Height = 332.75;
            });

            SetAsRootAndWaitForColorSpectrumFill(colorSpectrum);
        }
        public void ColorSpectrumTest()
        {
            RunOnUIThread.Execute(() =>
            {
                ColorSpectrum colorSpectrum = new ColorSpectrum();
                Verify.IsNotNull(colorSpectrum);

                Verify.AreEqual(Colors.White, colorSpectrum.Color);
                Verify.AreEqual(new Vector4()
                {
                    X = 0.0f, Y = 0.0f, Z = 1.0f, W = 1.0f
                }, colorSpectrum.HsvColor);
                Verify.AreEqual(0, colorSpectrum.MinHue);
                Verify.AreEqual(359, colorSpectrum.MaxHue);
                Verify.AreEqual(0, colorSpectrum.MinSaturation);
                Verify.AreEqual(100, colorSpectrum.MaxSaturation);
                Verify.AreEqual(0, colorSpectrum.MinValue);
                Verify.AreEqual(100, colorSpectrum.MaxValue);
                Verify.AreEqual(ColorSpectrumShape.Box, colorSpectrum.Shape);
                Verify.AreEqual(ColorSpectrumComponents.HueSaturation, colorSpectrum.Components);

                colorSpectrum.Color         = Colors.Green;
                colorSpectrum.MinHue        = 10;
                colorSpectrum.MaxHue        = 300;
                colorSpectrum.MinSaturation = 10;
                colorSpectrum.MaxSaturation = 90;
                colorSpectrum.MinValue      = 10;
                colorSpectrum.MaxValue      = 90;
                colorSpectrum.Shape         = ColorSpectrumShape.Ring;
                colorSpectrum.Components    = ColorSpectrumComponents.HueValue;

                Verify.AreEqual(Colors.Green, colorSpectrum.Color);

                // We'll probably encounter some level of rounding error here,
                // so we want to check that the HSV color is *close* to what's expected,
                // not exactly equal.
                Verify.IsLessThan(Math.Abs(colorSpectrum.HsvColor.X - 120.0), 0.1);
                Verify.IsLessThan(Math.Abs(colorSpectrum.HsvColor.Y - 1.0), 0.1);
                Verify.IsLessThan(Math.Abs(colorSpectrum.HsvColor.Z - 0.5), 0.1);

                Verify.AreEqual(10, colorSpectrum.MinHue);
                Verify.AreEqual(300, colorSpectrum.MaxHue);
                Verify.AreEqual(10, colorSpectrum.MinSaturation);
                Verify.AreEqual(90, colorSpectrum.MaxSaturation);
                Verify.AreEqual(10, colorSpectrum.MinValue);
                Verify.AreEqual(90, colorSpectrum.MaxValue);
                Verify.AreEqual(ColorSpectrumShape.Ring, colorSpectrum.Shape);
                Verify.AreEqual(ColorSpectrumComponents.HueValue, colorSpectrum.Components);

                colorSpectrum.HsvColor = new Vector4()
                {
                    X = 120.0f, Y = 1.0f, Z = 1.0f, W = 1.0f
                };

                Verify.AreEqual(Color.FromArgb(255, 0, 255, 0), colorSpectrum.Color);
                Verify.AreEqual(new Vector4()
                {
                    X = 120.0f, Y = 1.0f, Z = 1.0f, W = 1.0f
                }, colorSpectrum.HsvColor);
            });
        }