/// <summary> /// The get hsv color. /// </summary> /// <returns>The <see cref="Color" />.</returns> private Color GetHSVColor() { double h = _sliderHsv.Value; double x = (double)_ellipseHsv.GetValue(Canvas.LeftProperty) + _ellipseHsv.ActualWidth / 2; double y = (double)_ellipseHsv.GetValue(Canvas.TopProperty) + _ellipseHsv.ActualHeight / 2; double s = x / (_rectangleHsv.ActualWidth - 1); if (s < 0d) { s = 0d; } else if (s > 1d) { s = 1d; } double v = 1 - y / (_rectangleHsv.ActualHeight - 1); if (v < 0d) { v = 0d; } else if (v > 1d) { v = 1d; } return(ColorHelper.HSV2RGB(h, s, v)); }
/// <summary> /// The get hsv color. /// </summary> /// <returns>The <see cref="Color" />.</returns> private Color GetHSVColor() { var h = _hsvSlider.Value; var x = (double)_hsvEllipse.GetValue(Canvas.LeftProperty) + _hsvEllipse.ActualWidth / 2; var y = (double)_hsvEllipse.GetValue(Canvas.TopProperty) + _hsvEllipse.ActualHeight / 2; var s = x / (_hsvRectangle.ActualWidth - 1); if (s < 0d) { s = 0d; } else if (s > 1d) { s = 1d; } var v = 1 - y / (_hsvRectangle.ActualHeight - 1); if (v < 0d) { v = 0d; } else if (v > 1d) { v = 1d; } return(ColorHelper.HSV2RGB(h, s, v)); }
/// <summary> /// The slider hs v_ value changed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> private void sliderHSV_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (Updating) { return; } _gradientStopHsvColor.SetCurrentValue(GradientStop.ColorProperty, ColorHelper.HSV2RGB(e.NewValue, 1d, 1d)); var color = GetHSVColor(); UpdateControls(color, false, true, true); }
public void SetHsvColor(Color color) { var h = ColorHelper.GetHSV_H(color); var s = ColorHelper.GetHSV_S(color); var v = ColorHelper.GetHSV_V(color); _hsvSlider.SetCurrentValue(RangeBase.ValueProperty, h); _hsvColorGradientStop.SetCurrentValue(GradientStop.ColorProperty, ColorHelper.HSV2RGB(h, 1d, 1d)); var x = s * (_hsvRectangle.ActualWidth - 1); var y = (1 - v) * (_hsvRectangle.ActualHeight - 1); _hsvEllipse.SetCurrentValue(Canvas.LeftProperty, x - _hsvEllipse.ActualWidth / 2); _hsvEllipse.SetCurrentValue(Canvas.TopProperty, y - _hsvEllipse.ActualHeight / 2); }
/// <summary> /// The update controls. /// </summary> /// <param name="color">The color.</param> /// <param name="hsv">The hsv.</param> /// <param name="rgb">The rgb.</param> /// <param name="predifined">The predifined.</param> private void UpdateControls(Color color, bool hsv, bool rgb, bool predifined) { if (Updating) { return; } try { BeginUpdate(); // HSV if (hsv) { var h = ColorHelper.GetHSV_H(color); var s = ColorHelper.GetHSV_S(color); var v = ColorHelper.GetHSV_V(color); _sliderHsv.SetCurrentValue(Slider.ValueProperty, h); _gradientStopHsvColor.SetCurrentValue(GradientStop.ColorProperty, ColorHelper.HSV2RGB(h, 1d, 1d)); var x = s * (_rectangleHsv.ActualWidth - 1); var y = (1 - v) * (_rectangleHsv.ActualHeight - 1); _ellipseHsv.SetCurrentValue(Canvas.LeftProperty, x - _ellipseHsv.ActualWidth / 2); _ellipseHsv.SetCurrentValue(Canvas.TopProperty, y - _ellipseHsv.ActualHeight / 2); } if (rgb) { var a = color.A; var r = color.R; var g = color.G; var b = color.B; _sliderA.SetCurrentValue(RangeBase.ValueProperty, (double)a); _gradientStopA0.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(0, r, g, b)); _gradientStopA1.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(255, r, g, b)); _textBoxA.SetCurrentValue(TextBox.TextProperty, a.ToString("X2")); _sliderR.SetCurrentValue(RangeBase.ValueProperty, (double)r); _gradientStopR0.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(255, 0, g, b)); _gradientStopR1.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(255, 255, g, b)); _textBoxR.SetCurrentValue(TextBox.TextProperty, r.ToString("X2")); _sliderG.SetCurrentValue(RangeBase.ValueProperty, (double)g); _gradientStopG0.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(255, r, 0, b)); _gradientStopG1.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(255, r, 255, b)); _textBoxG.SetCurrentValue(TextBox.TextProperty, g.ToString("X2")); _sliderB.SetCurrentValue(RangeBase.ValueProperty, (double)b); _gradientStopB0.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(255, r, g, 0)); _gradientStopB1.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(255, r, g, 255)); _textBoxB.SetCurrentValue(TextBox.TextProperty, b.ToString("X2")); } if (predifined) { _brushColor.SetCurrentValue(SolidColorBrush.ColorProperty, color); if (_dictionaryColor.ContainsKey(color)) { _comboBoxColor.SetCurrentValue(Selector.SelectedItemProperty, _dictionaryColor[color]); _textBoxColor.SetCurrentValue(TextBox.TextProperty, string.Empty); } else { _comboBoxColor.SetCurrentValue(Selector.SelectedItemProperty, null); _textBoxColor.SetCurrentValue(TextBox.TextProperty, color.ToString()); } } SetCurrentValue(ColorProperty, color); } finally { EndUpdate(); } }
/// <summary> /// The update controls. /// </summary> /// <param name="color">The color.</param> /// <param name="hsv">The hsv.</param> /// <param name="rgb">The rgb.</param> /// <param name="predifined">The predifined.</param> private void UpdateControls(Color color, bool hsv, bool rgb, bool predifined) { if (Updating) { return; } try { BeginUpdate(); // HSV if (hsv) { double h = ColorHelper.GetHSV_H(color); double s = ColorHelper.GetHSV_S(color); double v = ColorHelper.GetHSV_V(color); _sliderHsv.Value = h; _gradientStopHsvColor.Color = ColorHelper.HSV2RGB(h, 1d, 1d); double x = s * (_rectangleHsv.ActualWidth - 1); double y = (1 - v) * (_rectangleHsv.ActualHeight - 1); _ellipseHsv.SetValue(Canvas.LeftProperty, x - _ellipseHsv.ActualWidth / 2); _ellipseHsv.SetValue(Canvas.TopProperty, y - _ellipseHsv.ActualHeight / 2); } if (rgb) { byte a = color.A; byte r = color.R; byte g = color.G; byte b = color.B; _sliderA.Value = a; _gradientStopA0.Color = Color.FromArgb(0, r, g, b); _gradientStopA1.Color = Color.FromArgb(255, r, g, b); _textBoxA.Text = a.ToString("X2"); _sliderR.Value = r; _gradientStopR0.Color = Color.FromArgb(255, 0, g, b); _gradientStopR1.Color = Color.FromArgb(255, 255, g, b); _textBoxR.Text = r.ToString("X2"); _sliderG.Value = g; _gradientStopG0.Color = Color.FromArgb(255, r, 0, b); _gradientStopG1.Color = Color.FromArgb(255, r, 255, b); _textBoxG.Text = g.ToString("X2"); _sliderB.Value = b; _gradientStopB0.Color = Color.FromArgb(255, r, g, 0); _gradientStopB1.Color = Color.FromArgb(255, r, g, 255); _textBoxB.Text = b.ToString("X2"); } if (predifined) { _brushColor.Color = color; if (_dictionaryColor.ContainsKey(color)) { _comboBoxColor.SelectedItem = _dictionaryColor[color]; _textBoxColor.Text = string.Empty; } else { _comboBoxColor.SelectedItem = null; _textBoxColor.Text = color.ToString(); } } Color = color; } finally { EndUpdate(); } }
/// <summary> /// The update controls. /// </summary> /// <param name="color">The color.</param> /// <param name="hsv">The hsv.</param> /// <param name="rgb">The rgb.</param> /// <param name="predefined">The predefined.</param> private void UpdateControls(Color color, bool hsv, bool rgb, bool predefined) { if (Updating) { return; } try { BeginUpdate(); // HSV if (hsv) { var h = ColorHelper.GetHSV_H(color); var s = ColorHelper.GetHSV_S(color); var v = ColorHelper.GetHSV_V(color); _hsvSlider.SetCurrentValue(RangeBase.ValueProperty, h); _hsvColorGradientStop.SetCurrentValue(GradientStop.ColorProperty, ColorHelper.HSV2RGB(h, 1d, 1d)); var x = s * (_hsvRectangle.ActualWidth - 1); var y = (1 - v) * (_hsvRectangle.ActualHeight - 1); _hsvEllipse.SetCurrentValue(Canvas.LeftProperty, x - _hsvEllipse.ActualWidth / 2); _hsvEllipse.SetCurrentValue(Canvas.TopProperty, y - _hsvEllipse.ActualHeight / 2); } if (rgb) { var a = color.A; var r = color.R; var g = color.G; var b = color.B; _aSlider.SetCurrentValue(RangeBase.ValueProperty, (double)a); _a0GradientStop.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(0, r, g, b)); _a1GradientStop.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(255, r, g, b)); _aTextBox.SetCurrentValue(TextBox.TextProperty, a.ToString("X2")); _rSlider.SetCurrentValue(RangeBase.ValueProperty, (double)r); _r0GradientStop.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(255, 0, g, b)); _r1GradientStop.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(255, 255, g, b)); _rTextBox.SetCurrentValue(TextBox.TextProperty, r.ToString("X2")); _gSlider.SetCurrentValue(RangeBase.ValueProperty, (double)g); _g0GradientStop.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(255, r, 0, b)); _g1GradientStop.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(255, r, 255, b)); _gTextBox.SetCurrentValue(TextBox.TextProperty, g.ToString("X2")); _bSlider.SetCurrentValue(RangeBase.ValueProperty, (double)b); _b0GradientStop.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(255, r, g, 0)); _b1GradientStop.SetCurrentValue(GradientStop.ColorProperty, Color.FromArgb(255, r, g, 255)); _bTextBox.SetCurrentValue(TextBox.TextProperty, b.ToString("X2")); } if (predefined) { _colorBrush.SetCurrentValue(SolidColorBrush.ColorProperty, color); if (_dictionaryColor.ContainsKey(color)) { _colorComboBox.SetCurrentValue(Selector.SelectedItemProperty, _dictionaryColor[color]); _colorTextBox.SetCurrentValue(TextBox.TextProperty, string.Empty); } else { _colorComboBox.SetCurrentValue(Selector.SelectedItemProperty, null); _colorTextBox.SetCurrentValue(TextBox.TextProperty, color.ToString()); } Keyboard.Focus(_colorComboBox); } SetCurrentValue(ColorProperty, color); } finally { EndUpdate(); } }