private void SpectrumGrid_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed) { var x = e.GetPosition(SpectrumGrid).X; SpectrumGridBar.Margin = new Thickness(x, 0, 0, 0); currH = 360 * (x / this.Width); MiddleStop.Color = HSV.RGBFromHSV(currH, 1f, 1f).Color(); } }
public ColorPicker() { InitializeComponent(); var g6 = HSV.GradientSpectrum(); LinearGradientBrush gradientBrush = new LinearGradientBrush(); gradientBrush.StartPoint = new Point(0, 0); gradientBrush.EndPoint = new Point(1, 0); for (int i = 0; i < g6.Length; i++) { GradientStop stop = new GradientStop(g6[i].Color(), (i) * 0.16); gradientBrush.GradientStops.Add(stop); } SpectrumGrid.Opacity = 1; SpectrumGrid.Background = gradientBrush; MiddleStop.Color = HSV.RGBFromHSV(0, 1f, 1f).Color(); }
private void RgbGradient_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed) { var pos = e.GetPosition(sender as Canvas); var x = pos.X; var y = pos.Y; RGB c; if (x < Width / 2) { c = HSV.RGBFromHSV(currH, 1f, x / (Width / 2)); } else { c = HSV.RGBFromHSV(currH, (Width / 2 - (x - Width / 2)) / Width, 1f); } HexCode.Background = new SolidColorBrush(c.Color()); HexCode.Text = "#" + c.Hex(); Selected = c; } }