Пример #1
0
        private static void OnIsPrimaryChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            ColorPoint target   = obj as ColorPoint;
            bool       oldValue = (bool)args.OldValue;
            bool       newValue = (bool)args.NewValue;

            if (oldValue != newValue)
            {
                target.OnIsPrimaryChanged(oldValue, newValue);
            }
        }
Пример #2
0
        private static void OnHsvColorChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            ColorPoint target   = obj as ColorPoint;
            HsvColor   oldValue = (HsvColor)args.OldValue;
            HsvColor   newValue = (HsvColor)args.NewValue;

            if (oldValue.Equals(newValue) == false)
            {
                target.OnHsvColorChanged(oldValue, newValue);
            }
        }
Пример #3
0
        public override void OnColorChanged(ColorPoint colorPoint, HsvColor oldColor, IList <ColorPoint> colorPoints)
        {
            base.OnColorChanged(colorPoint, oldColor, colorPoints);
            if (_isColorsChanging)
            {
                return;
            }

            _isColorsChanging = true;
            try
            {
                var primaryColorPoint = colorPoints.FirstOrDefault(p => p.IsPrimary);
                if (primaryColorPoint == null)
                {
                    return;
                }

                var colorPointHsv   = colorPoint.HsvColor;
                var colorPointIndex = colorPoints.IndexOf(colorPoint);
                var primaryHsv      = primaryColorPoint.HsvColor;
                var primatyIndex    = colorPoints.IndexOf(primaryColorPoint);
                var oldHsv          = oldColor;
                for (int i = 0; i < colorPoints.Count; i++)
                {
                    var hue        = colorPointHsv.H;
                    var saturation = colorPointHsv.S;
                    var value      = 0d;
                    var point      = colorPoints[i];
                    if (colorPointIndex != primatyIndex)
                    {
                        value = point.HsvColor.V;
                    }
                    else
                    {
                        value = (colorPointHsv.V + (i - colorPointIndex + 5) % 5 * .2) % 1;
                    }

                    point.HsvColor = new HsvColor {
                        A = 1, H = hue, S = saturation, V = value
                    };
                }
            }
            finally
            {
                _isColorsChanging = false;
            }
        }
Пример #4
0
        public override void OnColorChanged(ColorPoint colorPoint, HsvColor oldColor, IList <ColorPoint> colorPoints)
        {
            base.OnColorChanged(colorPoint, oldColor, colorPoints);
            if (_isColorsChanging)
            {
                return;
            }

            _isColorsChanging = true;
            try
            {
                var primaryPoint = colorPoints.FirstOrDefault(p => p.IsPrimary);
                if (primaryPoint == null)
                {
                    return;
                }

                if (primaryPoint != colorPoint)
                {
                    var index            = colorPoints.IndexOf(colorPoint);
                    var hsv              = colorPoint.HsvColor;
                    var primaryHsv       = primaryPoint.HsvColor;
                    var primaryIndex     = colorPoints.IndexOf(primaryPoint);
                    var degreeDifference = hsv.H - primaryHsv.H;
                    if (degreeDifference < -180)
                    {
                        degreeDifference += 360;
                    }

                    _degree = (degreeDifference) / (index - primaryIndex);
                }

                ChangeColorPoints(colorPoints);
            }
            finally
            {
                _isColorsChanging = false;
            }
        }
 public virtual void OnColorChanged(ColorPoint colorPoint, HsvColor oldColor, IList <ColorPoint> colorPoints)
 {
 }
Пример #6
0
        public override void OnColorChanged(ColorPoint colorPoint, HsvColor oldColor, IList <ColorPoint> colorPoints)
        {
            base.OnColorChanged(colorPoint, oldColor, colorPoints);
            if (_isColorsChanging)
            {
                return;
            }

            _isColorsChanging = true;
            try
            {
                var primaryColorPoint = colorPoints.FirstOrDefault(p => p.IsPrimary);
                if (primaryColorPoint == null)
                {
                    return;
                }

                var primaryHsv      = primaryColorPoint.HsvColor;
                var primatyIndex    = colorPoints.IndexOf(primaryColorPoint);
                var colorPointHsv   = colorPoint.HsvColor;
                var colorPointIndex = colorPoints.IndexOf(colorPoint);
                if (primaryColorPoint != colorPoint)
                {
                    primaryHsv.H = colorPointHsv.H;
                }
                var oldHsv = oldColor;
                for (int i = 0; i < colorPoints.Count; i++)
                {
                    var hue      = primaryHsv.H;
                    var point    = colorPoints[i];
                    var pointHsv = point.HsvColor;

                    var saturation = pointHsv.S;
                    var value      = pointHsv.V;
                    if (colorPoint == primaryColorPoint)
                    {
                        if (i == primatyIndex)
                        {
                            continue;
                        }

                        var saturationRate = pointHsv.S / oldHsv.S;
                        if (pointHsv.S == 1)
                        {
                            saturationRate = 1 + Math.Min(0, i - primatyIndex) * .25;
                        }
                        saturation = saturationRate * primaryHsv.S;
                        saturation = Math.Min(1, saturation);

                        var valueRate = pointHsv.V / oldHsv.V;
                        if (pointHsv.V == 1)
                        {
                            valueRate = 1 + Math.Max(0, primatyIndex - i) * .25;
                        }
                        value = valueRate * primaryHsv.V;
                        value = Math.Min(1, value);
                    }

                    point.HsvColor = new HsvColor {
                        A = 1, H = hue, S = saturation, V = value
                    };
                }
            }
            finally
            {
                _isColorsChanging = false;
            }
        }
Пример #7
0
        public override void OnColorChanged(ColorPoint colorPoint, HsvColor oldColor, IList <ColorPoint> colorPoints)
        {
            base.OnColorChanged(colorPoint, oldColor, colorPoints);
            if (_isColorsChanging)
            {
                return;
            }

            _isColorsChanging = true;
            try
            {
                var primaryColorPoint = colorPoints.FirstOrDefault(p => p.IsPrimary);
                if (primaryColorPoint == null)
                {
                    return;
                }

                var primaryHsv      = primaryColorPoint.HsvColor;
                var primatyIndex    = colorPoints.IndexOf(primaryColorPoint);
                var colorPointHsv   = colorPoint.HsvColor;
                var colorPointIndex = colorPoints.IndexOf(colorPoint);
                if (primaryColorPoint != colorPoint)
                {
                    if (colorPointIndex > primatyIndex)
                    {
                        primaryHsv.H = colorPointHsv.H - 120;
                        if (primaryHsv.H < 0)
                        {
                            primaryHsv.H += 360;
                        }
                    }
                    else
                    {
                        primaryHsv.H = colorPointHsv.H + 120;
                        if (primaryHsv.H > 360)
                        {
                            primaryHsv.H -= 360;
                        }
                    }
                }
                var oldHsv = oldColor;
                for (int i = 0; i < colorPoints.Count; i++)
                {
                    var hue      = primaryHsv.H;
                    var point    = colorPoints[i];
                    var pointHsv = point.HsvColor;
                    if (i > primatyIndex)
                    {
                        hue += 120;
                        if (hue > 360)
                        {
                            hue -= 360;
                        }
                    }
                    else if (i < primatyIndex)
                    {
                        hue -= 120;
                        if (hue < 0)
                        {
                            hue += 360;
                        }
                    }

                    var saturation = pointHsv.S;
                    if (colorPoint == primaryColorPoint)
                    {
                        if (i == primatyIndex)
                        {
                            continue;
                        }

                        var saturationRate = pointHsv.S / oldHsv.S;
                        if (pointHsv.S == 1)
                        {
                            saturationRate = 1 + Math.Abs(i - primatyIndex) * 0.1;
                        }

                        saturation = saturationRate * primaryHsv.S;
                        saturation = Math.Min(1, saturation);
                    }

                    point.HsvColor = new HsvColor {
                        A = 1, H = hue, S = saturation, V = pointHsv.V
                    };
                }
            }
            finally
            {
                _isColorsChanging = false;
            }
        }
Пример #8
0
        protected override void OnColorChanged(ColorPoint colorPoint, HsvColor oldValue, HsvColor newValue)
        {
            base.OnColorChanged(colorPoint, oldValue, newValue);

            ColorPaletteStrategy?.OnColorChanged(colorPoint, oldValue, Items.OfType <ColorPoint>().ToList());
        }
Пример #9
0
 protected virtual void OnColorPointChanged(ColorPoint oldValue, ColorPoint newValue)
 {
 }
Пример #10
0
 protected virtual void OnColorChanged(ColorPoint colorPoint, HsvColor oldValue, HsvColor newValue)
 {
 }