private void LinePicker_ColorHit(object sender, DataTools.Graphics.ColorHitEventArgs e) { NamedColor nc = NamedColor.FindColor(e.Color, true); LineColor.Background = new SolidColorBrush(e.Color.GetWPFColor()); if (nc != null) { LineColorName.Content = nc.Name; } else { LineColorName.Content = (e.Color).ToString(); } }
private void SetSelectedColor(UniColor?selc = null) { UniColor clr; string cname; if (selc != null) { clr = (UniColor)selc; } else { clr = SelectedColor.GetUniColor(); } NamedColor nc; if (SnapToNamedColor) { nc = NamedColor.GetClosestColor(clr, 0.05, false); } else { nc = NamedColor.FindColor(clr); } if (nc != null) { cname = nc.Name; clr = nc.Color; } else { cname = clr.ToString("rwH"); } if (SelectedColor != clr.GetWinUIColor()) { SelectedColor = clr.GetWinUIColor(); } if (SelectedColorName != cname) { SelectedColorName = cname; } RenderPickerZone(); }
private void SetSelectedColor(UniColor?selc = null) { UniColor clr; string cname; if (selc != null) { clr = (UniColor)selc; } else { clr = SelectedColor.GetUniColor(); } NamedColor nc; if (SnapToNamedColor) { nc = NamedColor.GetClosestColor(clr, 0.05, false); } else { nc = NamedColor.FindColor(clr); } if (nc != null) { cname = nc.Name; clr = nc.Color; } else { cname = clr.GetXamarinColor().ToHex(); } if (SelectedColor != clr.GetXamarinColor()) { SelectedColor = clr.GetXamarinColor(); } if (SelectedColorName != cname) { SelectedColorName = cname; } }
private void SetSelectedColor(UniColor?selc = null) { UniColor clr; if (selc != null) { clr = (UniColor)selc; SelectedColor = Color.FromArgb(clr.A, clr.R, clr.G, clr.B); return; } else if (SelectedColor == null) { SelectedColorName = null; Point.Visibility = Surround.Visibility = Visibility.Hidden; HuePicker.Visibility = Visibility.Hidden; return; } clr = ((Color)SelectedColor).GetUniColor(); var nc = NamedColor.FindColor(clr, NameResolution == ColorNameResolution.Closest); if (nc != null) { SelectedColorName = nc.Name; } else { SelectedColorName = clr.ToString(UniColorFormatOptions.HexRgbWebFormat); } if (cpRender == null) { return; } HSVDATA hsv1 = ColorToHSV(clr); HSVDATA hsv2; HSVDATA hsv3; HSVDATA? hsv4 = null; HSVDATA? hsv5 = null; UniColor uc; ColorPickerElement cel = new ColorPickerElement(); foreach (var c in cpRender.Elements) { uc = c.Color; hsv2 = ColorToHSV(uc); hsv3 = (hsv1 - hsv2).Abs(); if (hsv4 == null) { hsv4 = hsv3; } else if (hsv3 < hsv4) { hsv5 = hsv2; hsv4 = hsv3; cel = c; } if (selc == uc) { cel = c; break; } } if (Mode == ColorPickerMode.HueWheel && !double.IsNaN(ActualWidth) && !double.IsNaN(ActualHeight) && ActualWidth != -1 && ActualHeight != -1) { if (hsv5 is HSVDATA hsv) { Point.Visibility = Surround.Visibility = Visibility.Hidden; HuePicker.Visibility = Visibility.Visible; int hp = HuePointerSize; PolarCoordinates pc = new PolarCoordinates(); double arc = hsv.Hue - HueOffset; if (arc < 0) { arc += 360; } int rad; int h = (int)ActualHeight, w = (int)ActualWidth; if (h < w) { rad = h / 2; w = h; } else { rad = w / 2; h = w; } pc.Arc = arc; pc.Radius = rad; var lc = pc.ToScreenCoordinates(new Rect(0, 0, w, h)); if (lc.X < (w / 2)) { lc.X -= hp; } if (lc.Y < (h / 2)) { lc.Y -= hp; } HuePicker.SetValue(Canvas.LeftProperty, lc.X); HuePicker.SetValue(Canvas.TopProperty, lc.Y); HueSize.ScaleX = (HuePointerSize / 5); HueSize.ScaleY = (HuePointerSize / 5); HueAngle.Angle = pc.Arc; } } else { Point.Visibility = Surround.Visibility = Visibility.Visible; HuePicker.Visibility = Visibility.Hidden; Point.SetValue(Canvas.LeftProperty, (double)cel.Center.X); Point.SetValue(Canvas.TopProperty, (double)cel.Center.Y); Surround.SetValue(Canvas.LeftProperty, (double)cel.Center.X - 8); Surround.SetValue(Canvas.TopProperty, (double)cel.Center.Y - 8); Surround.Stroke = Point.Stroke = new SolidColorBrush((Color)SelectedColor); selectedElement = cel; } }