private void Canvas_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs e) { var aint = new SKPaint() { Color = new SKColor(255, 255, 255, 0), IsStroke = false }; e.Surface.Canvas.Clear(); if (selCoord == null) { return; } var pt = (UniPoint)selCoord; var uc = SelectedColor.GetUniColor(); uc = ((uint)uc) ^ 0x00ffffff; pt.X *= ((e.Info.Width / Width)); pt.Y *= ((e.Info.Height / Height)); aint.Color = new SKColor(uc); aint.IsStroke = true; aint.StrokeWidth = 6; e.Surface.Canvas.DrawCircle(new SKPoint((float)pt.X, (float)pt.Y), 32, aint); }
public ColorPicker() { InitializeComponent(); vm = new ColorViewModel(SelectedColor.GetUniColor()); vm.PropertyChanged += Vm_PropertyChanged; ControlGrid.DataContext = vm; Rearrange(); }
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 RenderPickerZone(bool force = false, bool hide = false) { var uc = SelectedColor.GetUniColor(); if (_container == null) { return; } if (selCoord == null || uc == UniColor.Empty || force || hide) { if (currentShape != null) { try { if (_container.Children.Contains(currentShape)) { _container.Children.Remove(currentShape); } } catch { } currentShape = null; currentGeo = null; currentSprite = null; GC.Collect(0); } if (selCoord == null || uc == UniColor.Empty || hide) { return; } } var pt = (UniPoint)selCoord; uc = ((uint)uc) ^ 0x00ffffff; var comp = _container.Compositor; if (currentShape != null) { currentSprite.StrokeBrush = comp.CreateColorBrush(uc.GetWinUIColor()); currentShape.Offset = new Vector3((float)pt.X - 10, (float)pt.Y - 10, 0); return; } var ellipseGeo = comp.CreateEllipseGeometry(); ellipseGeo.Radius = new Vector2(8f, 8f); var spriteShape = comp.CreateSpriteShape(ellipseGeo); ellipseGeo.Center = new Vector2(10f, 10f); spriteShape.StrokeThickness = 1.35f; spriteShape.StrokeBrush = comp.CreateColorBrush(uc.GetWinUIColor()); var shapeVisual = comp.CreateShapeVisual(); shapeVisual.CompositeMode = CompositionCompositeMode.DestinationInvert; shapeVisual.Shapes.Add(spriteShape); shapeVisual.Offset = new Vector3((float)pt.X - 10, (float)pt.Y - 10, 0); shapeVisual.Size = new Vector2(20f, 20f); _container.Children.InsertAtTop(shapeVisual); currentShape = shapeVisual; currentSprite = spriteShape; currentGeo = ellipseGeo; }