public void Dispose() { SKRect rc; _path.GetBounds(out rc); _geometryImpl.Bounds = rc.ToAvaloniaRect(); }
public GlobularTextPage() { Title = "Globular Text"; canvasView = new SKCanvasView(); canvasView.PaintSurface += OnCanvasViewPaintSurface; Content = canvasView; using (SKPaint textPaint = new SKPaint()) { textPaint.Typeface = SKTypeface.FromFamilyName("Times New Roman"); textPaint.TextSize = 100; using (SKPath textPath = textPaint.GetTextPath("HELLO", 0, 0)) { SKRect textPathBounds; textPath.GetBounds(out textPathBounds); globePath = textPath.CloneWithTransform((SKPoint pt) => { double longitude = (Math.PI / textPathBounds.Width) * (pt.X - textPathBounds.Left) - Math.PI / 2; double latitude = (Math.PI / textPathBounds.Height) * (pt.Y - textPathBounds.Top) - Math.PI / 2; longitude *= 0.75; latitude *= 0.75; float x = (float)(Math.Cos(latitude) * Math.Sin(longitude)); float y = (float)Math.Sin(latitude); return(new SKPoint(x, y)); }); } } }
public CanvasRectangleF GetBounds() { SKRect rect; _path.GetBounds(out rect); return(rect.ToCanvasRectangleF()); }
public ChildNode(IBaseShape shape, string styleId, double dx, double dy, double scale, SKPath geometry) { this.Shape = shape; this.StyleId = styleId; this.dX = dx; this.dY = dy; this.Scale = scale; this.Geometry = geometry; geometry.GetBounds(out this.Bounds); }
public void GetBounds(out SKRect outBounds, Matrix3X3 parentMatrix) { _path.Reset(); for (var i = 0; i < _paths.Count; i++) { var m = parentMatrix.ToSKMatrix(); _path.AddPath(_paths[i].Path, ref m); } _path.GetBounds(out outBounds); // Add padding to account for rounding errors. RectExt.Set(ref outBounds, outBounds.Left - 1, outBounds.Top - 1, outBounds.Right + 1, outBounds.Bottom + 1); }
protected override void OnDrawSample(SKCanvas canvas, int width, int height) { canvas.Clear(SKColors.White); canvas.Scale(2, 2); using (SKPaint paint = new SKPaint()) using (SKPaint textPaint = new SKPaint()) { paint.Style = SKPaintStyle.Stroke; paint.StrokeWidth = 1; paint.IsAntialias = true; paint.StrokeCap = SKStrokeCap.Round; textPaint.IsAntialias = true; using (SKPath path = new SKPath()) { path.MoveTo(-6.2157825e-7f, -25.814698f); path.RCubicTo(-34.64102137842175f, 19.9999998f, 0f, 40f, 0f, 40f); path.Offset(50, 35); // draw using GetBounds paint.Color = SampleMedia.Colors.XamarinLightBlue; canvas.DrawPath(path, paint); SKRect rect; path.GetBounds(out rect); paint.Color = SampleMedia.Colors.XamarinDarkBlue; canvas.DrawRect(rect, paint); canvas.DrawText("Bounds", rect.Left, rect.Bottom + paint.TextSize + 10, textPaint); // move for next curve path.Offset(100, 0); // draw using GetTightBounds paint.Color = SampleMedia.Colors.XamarinLightBlue; canvas.DrawPath(path, paint); path.GetTightBounds(out rect); paint.Color = SampleMedia.Colors.XamarinDarkBlue; canvas.DrawRect(rect, paint); canvas.DrawText("TightBounds", rect.Left, rect.Bottom + paint.TextSize + 10, textPaint); } } }
public void Dispose() { // TODO: Not sure what we need to do here. This code left here for reference. // // var arr = _elements.ToArray(); // SkRect rc; // _path?.Dispose(); // _path = new SKPath(new SkPath(MethodTable.Instance.CreatePath(arr, arr.Length, out rc))); // _geometryImpl.ApplyTransform(); // _geometryImpl.Bounds = rc.ToRect(); SKRect rc; _path.GetBounds(out rc); _geometryImpl.ApplyTransform(); _geometryImpl.Bounds = rc.ToPerspexRect(); }
void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(SKColors.Black); SKRect bounds; catPath.GetBounds(out bounds); canvas.Translate(info.Width / 2, info.Height / 2); canvas.Scale(0.9f * Math.Min(info.Width / bounds.Width, info.Height / bounds.Height)); canvas.Translate(-bounds.MidX, -bounds.MidY); canvas.DrawPath(catPath, paint); }