/// <summary> /// If a HSL property changed, we should update the RGB values all at once. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HSL_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (_rgbChanging) { return; // don't change the RGB values if that's why this method was called. } Color color = RGBHSL.HSL_to_RGB(new RGBHSL.HSL(HSL)); // convert HSL to RGB if (Color == color) { return; } if (e.PropertyName != "H") { HSL.LockHue = true; // We lock the Hue unless we intended to change that value (due to errors in conversion from RGB to HSL0 } Color = color; _hslChanging = true; // so we don't stack overflow on recursive calls to HSL_Changed and RGB_Changed RGB.R = color.R; RGB.G = color.G; RGB.B = color.B; RGB.A = color.A; _hslChanging = false; if (e.PropertyName == "H") { HSL.LockHue = false; // Now we can unlock the hue } }
private void UpdateHSL() { if (_hslChanging) { return; } Color color = Color.FromArgb(RGB.A, RGB.R, RGB.G, RGB.B); if (Color == color) { return; } Color = color; RGBHSL.HSL hsl = RGBHSL.RGB_to_HSL(color); _rgbChanging = true; // so we don't stack overflow on recursive calls to HSL_Changed and RGB_Changed HSL.H = hsl.H; HSL.S = hsl.S; HSL.L = hsl.L; HSL.A = hsl.A; _rgbChanging = false; }