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); } }
public override void OnColorChanged(ColorPoint colorPoint, Color 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.Color.ToHsvEx(); var primaryHsv = primaryPoint.Color.ToHsvEx(); 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; } }
protected virtual void OnColorPointChanged(ColorPoint oldValue, ColorPoint newValue) { }
public override void OnColorChanged(ColorPoint colorPoint, Color 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.Color.ToHsvEx(); var primatyIndex = colorPoints.IndexOf(primaryColorPoint); var colorPointHsv = colorPoint.Color.ToHsvEx(); var colorPointIndex = colorPoints.IndexOf(colorPoint); if (primaryColorPoint != colorPoint) { if (colorPointIndex > primatyIndex) { primaryHsv.H = colorPointHsv.H + 180; if (primaryHsv.H > 360) { primaryHsv.H -= 360; } } else { primaryHsv.H = colorPointHsv.H; } } var oldHsv = oldColor.ToHsvEx(); for (int i = 0; i < colorPoints.Count; i++) { var hue = primaryHsv.H; var point = colorPoints[i]; var pointHsv = point.Color.ToHsvEx(); if (i > primatyIndex) { hue += 180; if (hue > 360) { 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.15; } saturation = saturationRate * primaryHsv.S; saturation = Math.Min(1, saturation); if (i == 0) { Debug.WriteLine("saturationRate:" + saturationRate); Debug.WriteLine("oldHsv.S:" + oldHsv.S); Debug.WriteLine("primaryHsv.S:" + primaryHsv.S); Debug.WriteLine("saturation:" + saturation); Debug.WriteLine("pointHsv.S:" + pointHsv.S); } } //var saturationRate = primaryHsv.S / pointHsv.S; //if (saturationRate == 1 ) //{ // saturationRate = 1 + Math.Abs(i - primatyIndex) * 0.15; //} //var saturation = primaryHsv.S / saturationRate; point.Color = ColorExtensions.FromHsvEx(hue, saturation, pointHsv.V); } } finally { _isColorsChanging = false; } }
protected virtual void OnColorChanged(ColorPoint colorPoint, Color oldValue, Color newValue) { }
protected override void OnColorChanged(ColorPoint colorPoint, Color oldValue, Color newValue) { base.OnColorChanged(colorPoint, oldValue, newValue); ColorPaletteStrategy?.OnColorChanged(colorPoint, oldValue, Items.OfType <ColorPoint>().ToList()); }
public virtual void OnColorChanged(ColorPoint colorPoint, Color oldColor, IList <ColorPoint> colorPoints) { }