public void UpdatingHueOnGreyDoesntCauseColorToChange()
        {
            BrushPropertyViewModel vm = PrepareMockViewModel();
            var grey = new CommonColor(20, 20, 20);

            vm.Value = new CommonSolidBrush(grey);

            var colorChanged    = false;
            var hueColorChanged = false;
            var shadeChanged    = false;

            vm.Solid.PropertyChanged += (s, e) => {
                switch (e.PropertyName)
                {
                case nameof(SolidBrushViewModel.Color):
                    colorChanged = true;
                    break;

                case nameof(SolidBrushViewModel.HueColor):
                    hueColorChanged = true;
                    break;

                case nameof(SolidBrushViewModel.Shade):
                    shadeChanged = true;
                    break;
                }
            };

            vm.Solid.HueColor = new CommonColor(0, 0, 255);

            Assert.IsFalse(colorChanged);
            Assert.AreEqual(grey, vm.Solid.Color);
            Assert.IsTrue(hueColorChanged);
            Assert.IsFalse(shadeChanged);
        }
        private void Initialize(IHostResourceProvider hostResources)
        {
            WantsLayer = true;
            Editors    = CreateEditors(hostResources, EditorType);

            this.hexLabel = new UnfocusableTextField {
                StringValue = "#:",
                Alignment   = NSTextAlignment.Right,
                ToolTip     = Properties.Resources.HexValue
            };
            AddSubview(this.hexLabel);

            this.hexEditor = new NSTextField {
                Alignment   = NSTextAlignment.Right,
                ControlSize = NSControlSize.Small,
                Font        = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small))
            };
            AddSubview(this.hexEditor);

            this.hexEditor.EditingEnded += (o, e) => {
                if (CommonColor.TryParseArgbHex(this.hexEditor.StringValue, out CommonColor c))
                {
                    ViewModel.Color            = c;
                    this.hexEditor.StringValue = c.ToString();
                }
            };
        }
        public void UpdatingHueOnSaturatedColorsCausesColorToChange()
        {
            BrushPropertyViewModel vm = PrepareMockViewModel();
            var blue = new CommonColor(20, 20, 255);

            vm.Value = new CommonSolidBrush(blue);

            var colorChanged    = false;
            var hueColorChanged = false;
            var shadeChanged    = false;

            vm.Solid.PropertyChanged += (s, e) => {
                switch (e.PropertyName)
                {
                case nameof(SolidBrushViewModel.Color):
                    colorChanged = true;
                    break;

                case nameof(SolidBrushViewModel.HueColor):
                    hueColorChanged = true;
                    break;

                case nameof(SolidBrushViewModel.Shade):
                    shadeChanged = true;
                    break;
                }
            };

            vm.Solid.HueColor = new CommonColor(255, 0, 0);

            Assert.IsTrue(colorChanged);
            Assert.IsTrue(hueColorChanged);
            Assert.IsFalse(shadeChanged);
        }
        public void UpdateGradientLayer(CAGradientLayer layer, CommonColor color)
        {
            var c = color.UpdateRGB(a: 255);

            layer.Colors = LerpSteps(MinimumValue, MaximumValue, 7)
                           .Select(value => UpdateColorFromValue(c, value).ToCGColor()).ToArray();
        }
예제 #5
0
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var color      = (CommonColor)value;
            var colorStart = CommonColor.FromCMYK(color.C, 0, color.Y, color.K, color.A).ToColor();
            var colorEnd   = CommonColor.FromCMYK(color.C, 1, color.Y, color.K, color.A).ToColor();

            return(ConvertImplementation(colorStart, colorEnd));
        }
예제 #6
0
        protected override CommonBrush GetRandomTestValue(Random rand)
        {
            CommonColor color      = rand.NextColor();
            var         colorSpace = rand.NextString();
            var         opacity    = rand.NextDouble();

            return(new CommonSolidBrush(color, colorSpace, opacity));
        }
예제 #7
0
        public void ValueChangesTriggerPropertyChanges()
        {
            BrushPropertyViewModel vm = PrepareMockViewModel();

            var colorChanged       = false;
            var colorNameChanged   = false;
            var alphaChanged       = false;
            var accentChanged      = false;
            var normalChanged      = false;
            var accentScaleChanged = false;
            var normalScaleChanged = false;

            vm.MaterialDesign.PropertyChanged += (s, e) => {
                switch (e.PropertyName)
                {
                case nameof(MaterialDesignColorViewModel.Color):
                    colorChanged = true;
                    break;

                case nameof(MaterialDesignColorViewModel.ColorName):
                    colorNameChanged = true;
                    break;

                case nameof(MaterialDesignColorViewModel.Alpha):
                    alphaChanged = true;
                    break;

                case nameof(MaterialDesignColorViewModel.AccentColor):
                    accentChanged = true;
                    break;

                case nameof(MaterialDesignColorViewModel.NormalColor):
                    normalChanged = true;
                    break;

                case nameof(MaterialDesignColorViewModel.AccentColorScale):
                    accentScaleChanged = true;
                    break;

                case nameof(MaterialDesignColorViewModel.NormalColorScale):
                    normalScaleChanged = true;
                    break;
                }
            };

            CommonColor newColor = GetNewRandomColor(Random, vm.MaterialDesign.Color);

            vm.Value = new CommonSolidBrush(newColor);

            Assert.AreEqual(newColor, vm.MaterialDesign.Color);
            Assert.IsTrue(colorChanged);
            Assert.IsTrue(colorNameChanged);
            Assert.IsTrue(alphaChanged);
            Assert.IsTrue(accentChanged);
            Assert.IsTrue(normalChanged);
            Assert.IsTrue(accentScaleChanged);
            Assert.IsTrue(normalScaleChanged);
        }
예제 #8
0
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var color      = (CommonColor)value;
            var hue        = color.Hue;
            var saturation = color.Saturation;
            var colorStart = CommonColor.FromHSB(hue, saturation, 0).ToColor();
            var colorEnd   = CommonColor.FromHSB(hue, saturation, 1).ToColor();

            return(ConvertImplementation(colorStart, colorEnd));
        }
예제 #9
0
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var color      = (CommonColor)value;
            var hue        = color.Hue;
            var lightness  = color.Lightness;
            var colorStart = CommonColor.FromHLS(hue, lightness, 0).ToColor();
            var colorEnd   = CommonColor.FromHLS(hue, lightness, 1).ToColor();

            return(ConvertImplementation(colorStart, colorEnd));
        }
예제 #10
0
        private static CommonColor GetNewRandomScaledColor(Random rand, MaterialColorScale scale, CommonColor oldColor)
        {
            CommonColor newAccent = scale.Colors[rand.Next(scale.Colors.Count)];

            while (newAccent.Equals(oldColor, true))
            {
                newAccent = scale.Colors[rand.Next(scale.Colors.Count)];
            }
            return(newAccent);
        }
예제 #11
0
        private static CommonColor GetNewRandomColor(Random rand, CommonColor oldColor)
        {
            CommonColor newColor = rand.NextColor();

            while (newColor.Equals(oldColor, true))
            {
                newColor = rand.NextColor();
            }
            return(newColor);
        }
예제 #12
0
        public Divider(CommonColor color) : base(null)
        {
            byte paletteColor = (byte)color;

            _pixel = new EightBitTexture(
                "Divider",
                1, 1, 1, 1,
                new[] { paletteColor },
                new[] { new EightBitTexture.SubImage(0, 0, 1, 1, 0), });
        }
예제 #13
0
 public void SetFromStoreData(StoreData storeData)
 {
     Nickname        = storeData.CoreData.Nickname;
     CreateId        = storeData.CreateId;
     FontRegion      = storeData.CoreData.FontRegion;
     FavoriteColor   = storeData.CoreData.FavoriteColor;
     Gender          = storeData.CoreData.Gender;
     Height          = storeData.CoreData.Height;
     Build           = storeData.CoreData.Build;
     Type            = storeData.CoreData.Type;
     RegionMove      = storeData.CoreData.RegionMove;
     FacelineType    = storeData.CoreData.FacelineType;
     FacelineColor   = storeData.CoreData.FacelineColor;
     FacelineWrinkle = storeData.CoreData.FacelineWrinkle;
     FacelineMake    = storeData.CoreData.FacelineMake;
     HairType        = storeData.CoreData.HairType;
     HairColor       = storeData.CoreData.HairColor;
     HairFlip        = storeData.CoreData.HairFlip;
     EyeType         = storeData.CoreData.EyeType;
     EyeColor        = storeData.CoreData.EyeColor;
     EyeScale        = storeData.CoreData.EyeScale;
     EyeAspect       = storeData.CoreData.EyeAspect;
     EyeRotate       = storeData.CoreData.EyeRotate;
     EyeX            = storeData.CoreData.EyeX;
     EyeY            = storeData.CoreData.EyeY;
     EyebrowType     = storeData.CoreData.EyebrowType;
     EyebrowColor    = storeData.CoreData.EyebrowColor;
     EyebrowScale    = storeData.CoreData.EyebrowScale;
     EyebrowAspect   = storeData.CoreData.EyebrowAspect;
     EyebrowRotate   = storeData.CoreData.EyebrowRotate;
     EyebrowX        = storeData.CoreData.EyebrowX;
     EyebrowY        = storeData.CoreData.EyebrowY;
     NoseType        = storeData.CoreData.NoseType;
     NoseScale       = storeData.CoreData.NoseScale;
     NoseY           = storeData.CoreData.NoseY;
     MouthType       = storeData.CoreData.MouthType;
     MouthColor      = storeData.CoreData.MouthColor;
     MouthScale      = storeData.CoreData.MouthScale;
     MouthAspect     = storeData.CoreData.MouthAspect;
     MouthY          = storeData.CoreData.MouthY;
     BeardColor      = storeData.CoreData.BeardColor;
     BeardType       = storeData.CoreData.BeardType;
     MustacheType    = storeData.CoreData.MustacheType;
     MustacheScale   = storeData.CoreData.MustacheScale;
     MustacheY       = storeData.CoreData.MustacheY;
     GlassType       = storeData.CoreData.GlassType;
     GlassColor      = storeData.CoreData.GlassColor;
     GlassScale      = storeData.CoreData.GlassScale;
     GlassY          = storeData.CoreData.GlassY;
     MoleType        = storeData.CoreData.MoleType;
     MoleScale       = storeData.CoreData.MoleScale;
     MoleX           = storeData.CoreData.MoleX;
     MoleY           = storeData.CoreData.MoleY;
     Reserved        = 0;
 }
        public CGPoint LocationFromColor(CAGradientLayer layer, CommonColor color)
        {
            var pos = ValueFromColor(color) * Scale;

            var amount  = InvLerp(MinimumValue, MaximumValue, pos);
            var unitLoc = Lerp(layer.StartPoint, layer.EndPoint, amount);

            return(new CGPoint(
                       layer.Frame.X + unitLoc.X * layer.Frame.Width,
                       layer.Frame.Y + unitLoc.Y * layer.Frame.Height));
        }
 public ColorTestCase(
     byte red, byte green, byte blue,
     double cyanPercent, double magentaPercent, double yellowPercent, double blackPercent,
     double hue, double lightnessPercent, double saturationPercent,
     double brightnessPercent, byte alpha = 255)
 {
     Color = new CommonColor(red, green, blue, alpha);
     CMYK  = new CMYK(cyanPercent / 100, magentaPercent / 100, yellowPercent / 100, blackPercent / 100);
     HLS   = new HLS(hue, lightnessPercent / 100, saturationPercent / 100);
     HSB   = new HSB(hue, saturationPercent / 100, brightnessPercent / 100);
 }
예제 #16
0
        public void ColorNameChangesScalesAndKeepsAlphaAndAccent()
        {
            // Set the color to some accent color
            BrushPropertyViewModel vm          = PrepareMockViewModel();
            MaterialColorScale     scale       = GetRandomScale(Random, true);    // Accent color
            CommonColor            scaledColor = GetNewRandomScaledColor(Random, scale, CommonColor.Black);
            var color = new CommonColor(scaledColor.R, scaledColor.G, scaledColor.B, Random.NextByte());

            vm.Value = new CommonSolidBrush(color);

            Assert.AreEqual(scale.Colors, vm.MaterialDesign.AccentColorScale);

            MaterialColorScale expectedNormalScale = MaterialDesignColorViewModel.MaterialPalettes
                                                     .First(p => !p.IsAccent && p.Name == scale.Name);

            Assert.AreEqual(expectedNormalScale.Colors, vm.MaterialDesign.NormalColorScale);
            Assert.AreEqual(color.A, vm.MaterialDesign.Alpha);

            var accentIndex = Array.IndexOf(scale.Colors.ToArray(), scaledColor);

            // Then change to another scale that has accents too
            MaterialColorScale newScale = GetRandomScale(Random, true);
            var newColorName            = newScale.Name;

            while (newColorName == scale.Name)
            {
                newColorName = GetRandomScale(Random, true).Name;
            }
            vm.MaterialDesign.ColorName = newColorName;

            Assert.AreEqual(newColorName, vm.MaterialDesign.ColorName);
            Assert.AreEqual(newScale.Colors, vm.MaterialDesign.AccentColorScale);
            Assert.AreEqual(accentIndex, Array.IndexOf(newScale.Colors.ToArray(), vm.MaterialDesign.AccentColor));
            expectedNormalScale = MaterialDesignColorViewModel.MaterialPalettes
                                  .First(p => !p.IsAccent && p.Name == newScale.Name);
            Assert.AreEqual(expectedNormalScale.Colors, vm.MaterialDesign.NormalColorScale);
            Assert.AreEqual(color.A, vm.MaterialDesign.Alpha);

            // Finally, change to grey, which has only normal nuances, but no accents,
            // so color should snap to the closest normal.
            var grey = Properties.Resources.MaterialColorGrey;

            vm.MaterialDesign.ColorName = Properties.Resources.MaterialColorGrey;

            Assert.AreEqual(grey, vm.MaterialDesign.ColorName);
            Assert.AreEqual(MaterialDesignColorViewModel.EmptyColorScale, vm.MaterialDesign.AccentColorScale);
            Assert.IsNull(vm.MaterialDesign.AccentColor);
            Assert.AreEqual(MaterialDesignColorViewModel.MaterialPalettes.First(p => p.Name == grey).Colors,
                            vm.MaterialDesign.NormalColorScale);
            Assert.IsNotNull(vm.MaterialDesign.NormalColor);
            Assert.AreEqual(color.A, vm.MaterialDesign.Alpha);
        }
 public static CommonColor UpdateHLS(
     this CommonColor color,
     double?hue        = null,
     double?lightness  = null,
     double?saturation = null,
     byte?alpha        = null)
 {
     return(CommonColor.FromHLS(
                hue: hue ?? color.Hue,
                lightness: lightness ?? color.Lightness,
                saturation: saturation ?? color.Saturation,
                alpha: alpha ?? color.A));
 }
 public static CommonColor UpdateHSB(
     this CommonColor color,
     double?hue        = null,
     double?saturation = null,
     double?brightness = null,
     byte?alpha        = null)
 {
     return(CommonColor.FromHSB(
                hue: hue ?? color.Hue,
                saturation: saturation ?? color.Saturation,
                brightness: brightness ?? color.Brightness,
                alpha: alpha ?? color.A));
 }
 public static CommonColor UpdateRGB(
     this CommonColor color,
     byte?r = null,
     byte?g = null,
     byte?b = null,
     byte?a = null)
 {
     return(new CommonColor(
                r: r ?? color.R,
                g: g ?? color.G,
                b: b ?? color.B,
                a: a ?? color.A));
 }
        public void ColorEquality()
        {
            var c1 = new CommonColor(1, 2, 3, 4, "one");
            var c2 = new CommonColor(1, 2, 3, 4, "two");
            var c3 = new CommonColor(1, 2, 3, 5, "three");
            var c4 = new CommonColor(5, 6, 7, 4, "four");

            Assert.That(c1 == c2, Is.True);
            Assert.That(c1 != c2, Is.False);
            Assert.That(c1.Equals(c2), Is.True);
            Assert.That(c1.Equals(c3), Is.False);
            Assert.That(c1.Equals(c3, true), Is.True);
            Assert.That(c1.Equals(c4), Is.False);
        }
예제 #21
0
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var color      = (CommonColor)value;
            var hue        = color.Hue;
            var saturation = color.Saturation;
            var colorStart = CommonColor.FromHLS(hue, 0, saturation).ToColor();
            var colorEnd   = CommonColor.FromHLS(hue, 1, saturation).ToColor();

            return(new LinearGradientBrush(new GradientStopCollection {
                new GradientStop(colorStart, 0),
                new GradientStop(color.ToColor(), color.Lightness),
                new GradientStop(colorEnd, 1)
            }, 0));
        }
        public void ValueChangesTriggerSolidColorAndColorSpacePropertyChangesOnly()
        {
            BrushPropertyViewModel vm = PrepareMockViewModel();

            var colorChanged      = false;
            var colorSpaceChanged = false;
            var hueColorChanged   = false;
            var shadeChanged      = false;

            CommonColor initialColor = vm.Solid.InitialColor;
            CommonColor lastColor    = vm.Solid.LastColor;
            CommonColor shade        = vm.Solid.Shade;
            CommonColor hueColor     = vm.Solid.HueColor;

            vm.Solid.PropertyChanged += (s, e) => {
                switch (e.PropertyName)
                {
                case nameof(SolidBrushViewModel.Color):
                    colorChanged = true;
                    break;

                case nameof(SolidBrushViewModel.ColorSpace):
                    colorSpaceChanged = true;
                    break;

                case nameof(SolidBrushViewModel.HueColor):
                    hueColorChanged = true;
                    break;

                case nameof(SolidBrushViewModel.Shade):
                    shadeChanged = true;
                    break;
                }
            };

            CommonColor newColor = GetNewRandomColor(Random, vm.Solid.Color);

            vm.Value = new CommonSolidBrush(newColor);

            Assert.IsTrue(colorChanged);
            Assert.AreEqual(newColor, vm.Solid.Color);
            Assert.IsTrue(colorSpaceChanged);
            Assert.IsFalse(hueColorChanged);
            Assert.AreEqual(hueColor, vm.Solid.HueColor);
            Assert.IsFalse(shadeChanged);
            Assert.AreEqual(shade, vm.Solid.Shade);
            Assert.AreEqual(initialColor, vm.Solid.InitialColor);
            Assert.AreEqual(lastColor, vm.Solid.LastColor);
        }
 public static CommonColor UpdateCMYK(
     this CommonColor color,
     double?c   = null,
     double?m   = null,
     double?y   = null,
     double?k   = null,
     byte?alpha = null)
 {
     return(CommonColor.FromCMYK(
                c: c ?? color.C,
                m: m ?? color.M,
                y: y ?? color.Y,
                k: k ?? color.K,
                alpha: alpha ?? color.A));
 }
 private static IEnumerable HueColorFromColorCases()
 {
     foreach (KeyValuePair <string, ColorTestCase> testCaseKVP in PrimaryTestCases)
     {
         yield return(new TestCaseData(testCaseKVP.Value.Color)
                      .Returns(CommonColor.GetHueColorFromHue(testCaseKVP.Value.Color.Hue))
                      .SetName("HueColorFromColor_" + testCaseKVP.Key));
     }
     foreach (KeyValuePair <string, ColorTestCase> testCaseKVP in RGBTestCases)
     {
         yield return(new TestCaseData(testCaseKVP.Value.Color)
                      .Returns(CommonColor.GetHueColorFromHue(testCaseKVP.Value.Color.Hue))
                      .SetName("HueColorFromColor_" + testCaseKVP.Key));
     }
 }
        public void InitialAndLastColorDontChangeOnceSet()
        {
            BrushPropertyViewModel vm = PrepareMockViewModel();

            vm.Value = GetRandomTestValue(Random);

            CommonColor initialColor = vm.Solid.InitialColor;
            CommonColor lastColor    = vm.Solid.LastColor;

            CommonColor newColor = GetNewRandomColor(Random, vm.Solid.Color);

            vm.Solid.Color = newColor;

            Assert.AreEqual(initialColor, vm.Solid.InitialColor);
            Assert.AreEqual(lastColor, vm.Solid.InitialColor);
        }
        public void CommitLastColorChangesLastColorAndShade()
        {
            BrushPropertyViewModel vm = PrepareMockViewModel();

            vm.Value = GetRandomTestValue(Random);

            CommonColor lastColor = vm.Solid.LastColor;

            CommonColor newColor = GetNewRandomColor(Random, vm.Solid.Color);

            vm.Solid.Color = newColor;

            var colorChanged     = false;
            var hueColorChanged  = false;
            var shadeChanged     = false;
            var lastColorChanged = false;

            vm.Solid.PropertyChanged += (s, e) => {
                switch (e.PropertyName)
                {
                case nameof(SolidBrushViewModel.Color):
                    colorChanged = true;
                    break;

                case nameof(SolidBrushViewModel.HueColor):
                    hueColorChanged = true;
                    break;

                case nameof(SolidBrushViewModel.Shade):
                    shadeChanged = true;
                    break;

                case nameof(SolidBrushViewModel.LastColor):
                    lastColorChanged = true;
                    break;
                }
            };

            vm.Solid.CommitLastColor();

            Assert.IsTrue(lastColorChanged);
            Assert.IsTrue(shadeChanged);
            Assert.IsFalse(colorChanged);
            Assert.IsFalse(hueColorChanged);
            Assert.AreEqual(newColor, vm.Solid.LastColor);
        }
예제 #27
0
        public void ColorsSnapBetweenBlackAndWhiteAndOtherPalettes()
        {
            BrushPropertyViewModel vm = PrepareMockViewModel();

            MaterialColorScale blackAndWhiteScale = MaterialDesignColorViewModel.MaterialPalettes.Last();
            MaterialColorScale normalScale        = MaterialDesignColorViewModel.MaterialPalettes[0];
            MaterialColorScale accentScale        = MaterialDesignColorViewModel.MaterialPalettes[1];

            CommonColor lightNormalColor = normalScale.Colors[0];
            CommonColor darkNormalColor  = normalScale.Colors[9];

            CommonColor lightAccentColor = accentScale.Colors[0];
            CommonColor darkAccentColor  = accentScale.Colors[3];

            vm.Value = new CommonSolidBrush(lightNormalColor);

            vm.MaterialDesign.ColorName = blackAndWhiteScale.Name;
            Assert.That(vm.Solid.Color, Is.EqualTo(CommonColor.White));

            vm.MaterialDesign.ColorName = normalScale.Name;
            Assert.That(vm.Solid.Color, Is.EqualTo(lightNormalColor));

            vm.Value = new CommonSolidBrush(darkNormalColor);

            vm.MaterialDesign.ColorName = blackAndWhiteScale.Name;
            Assert.That(vm.Solid.Color, Is.EqualTo(CommonColor.Black));

            vm.MaterialDesign.ColorName = normalScale.Name;
            Assert.That(vm.Solid.Color, Is.EqualTo(darkNormalColor));

            vm.Value = new CommonSolidBrush(lightAccentColor);

            vm.MaterialDesign.ColorName = blackAndWhiteScale.Name;
            Assert.That(vm.Solid.Color, Is.EqualTo(CommonColor.White));

            vm.MaterialDesign.ColorName = accentScale.Name;
            Assert.That(vm.Solid.Color, Is.EqualTo(lightNormalColor));

            vm.Value = new CommonSolidBrush(darkAccentColor);

            vm.MaterialDesign.ColorName = blackAndWhiteScale.Name;
            Assert.That(vm.Solid.Color, Is.EqualTo(CommonColor.Black));

            vm.MaterialDesign.ColorName = accentScale.Name;
            Assert.That(vm.Solid.Color, Is.EqualTo(darkNormalColor));
        }
        public void UpdatingColorCausesParentValueToChangeAndInitialColorToBeSetOnTheFirstTime()
        {
            BrushPropertyViewModel vm = PrepareMockViewModel();

            vm.Value = GetRandomTestValue(Random);

            var colorChanged    = false;
            var hueColorChanged = false;
            var shadeChanged    = false;
            var parentChanged   = false;
            var alpha           = vm.Solid.Color.A;

            vm.Solid.PropertyChanged += (s, e) => {
                switch (e.PropertyName)
                {
                case nameof(SolidBrushViewModel.Color):
                    colorChanged = true;
                    break;

                case nameof(SolidBrushViewModel.HueColor):
                    hueColorChanged = true;
                    break;

                case nameof(SolidBrushViewModel.Shade):
                    shadeChanged = true;
                    break;
                }
            };
            vm.PropertyChanged += (s, e) => {
                parentChanged = true;
            };

            CommonColor newColor = GetNewRandomColor(Random, vm.Solid.Color);

            vm.Solid.Color = newColor;

            Assert.IsTrue(parentChanged);
            Assert.IsTrue(colorChanged);
            Assert.IsFalse(hueColorChanged);
            Assert.IsFalse(shadeChanged);
            Assert.AreEqual(newColor, vm.Solid.Color);
            Assert.AreEqual(newColor, vm.Solid.InitialColor);
        }
        public static CommonColor Blend(this CommonColor a, CommonColor b)
        {
            byte C(byte cb1, byte ab1, byte cb2)
            {
                var c1 = cb1 / 255f;
                var a1 = ab1 / 255f;
                var c2 = cb2 / 255f;

                var c = Math.Max(0, Math.Min(255, (c1 + c2 * (1 - a1)) * 255));

                return((byte)c);
            }

            return(new CommonColor(
                       C(a.R, a.A, b.R),
                       C(a.G, a.A, b.G),
                       C(a.B, a.A, b.B),
                       C(a.A, a.A, b.A)));
        }
        public void ColorParseArgb()
        {
            CommonColor parsed;

            Assert.IsTrue(CommonColor.TryParseArgbHex("#123", out parsed));
            Assert.AreEqual(new CommonColor(0x11, 0x22, 0x33), parsed);

            Assert.IsTrue(CommonColor.TryParseArgbHex("#123456", out parsed));
            Assert.AreEqual(new CommonColor(0x12, 0x34, 0x56), parsed);

            Assert.IsTrue(CommonColor.TryParseArgbHex("#1234", out parsed));
            Assert.AreEqual(new CommonColor(0x22, 0x33, 0x44, 0x11), parsed);

            Assert.IsTrue(CommonColor.TryParseArgbHex("#12345678", out parsed));
            Assert.AreEqual(new CommonColor(0x34, 0x56, 0x78, 0x12), parsed);

            Assert.IsFalse(CommonColor.TryParseArgbHex("not a color", out parsed));
            Assert.AreEqual(CommonColor.Black, parsed);
        }