コード例 #1
0
 private void DrawPathCContent(SKCanvas canvas)
 {
     canvas.Save();
     GetPathA((float)Width, (float)Height);
     _region.SetRect(ToSKRectI(canvas.LocalClipBounds));
     ClipRegion(_region, _pathA);
     ClipRegion(_region, GetPathC(), SKRegionOperation.ReverseDifference);
     canvas.ClipRegion(_region);
     canvas.DrawColor(SKColors.Green);
     canvas.Restore();
 }
コード例 #2
0
        void DisplayClipOp(SKCanvas canvas, SKRect rect, SKRegionOperation regionOp)
        {
            float textSize = textPaint.TextSize;

            canvas.DrawText(regionOp.ToString(), rect.MidX, rect.Top + textSize, textPaint);
            rect.Top += textSize;

            float radius  = 0.9f * Math.Min(rect.Width / 3, rect.Height / 2);
            float xCenter = rect.MidX;
            float yCenter = rect.MidY;

            SKRectI recti = new SKRectI((int)rect.Left, (int)rect.Top,
                                        (int)rect.Right, (int)rect.Bottom);

            using (SKRegion wholeRectRegion = new SKRegion())
            {
                wholeRectRegion.SetRect(recti);

                using (SKRegion region1 = new SKRegion(wholeRectRegion))
                    using (SKRegion region2 = new SKRegion(wholeRectRegion))
                    {
                        using (SKPath path1 = new SKPath())
                        {
                            path1.AddCircle(xCenter - radius / 2, yCenter, radius);
                            region1.SetPath(path1);
                        }

                        using (SKPath path2 = new SKPath())
                        {
                            path2.AddCircle(xCenter + radius / 2, yCenter, radius);
                            region2.SetPath(path2);
                        }

                        region1.Op(region2, regionOp);

                        canvas.Save();
                        canvas.ClipRegion(region1);
                        canvas.DrawPaint(fillPaint);
                        canvas.Restore();
                    }
            }
        }
コード例 #3
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            float xCenter = info.Width / 2;
            float yCenter = info.Height / 2;
            float radius  = 0.24f * Math.Min(info.Width, info.Height);

            using (SKRegion wholeScreenRegion = new SKRegion())
            {
                wholeScreenRegion.SetRect(new SKRectI(0, 0, info.Width, info.Height));

                using (SKRegion leftRegion = new SKRegion(wholeScreenRegion))
                    using (SKRegion rightRegion = new SKRegion(wholeScreenRegion))
                        using (SKRegion topRegion = new SKRegion(wholeScreenRegion))
                            using (SKRegion bottomRegion = new SKRegion(wholeScreenRegion))
                            {
                                using (SKPath circlePath = new SKPath())
                                {
                                    // Make basic circle path
                                    circlePath.AddCircle(xCenter, yCenter, radius);

                                    // Left leaf
                                    circlePath.Transform(SKMatrix.MakeTranslation(-radius, 0));
                                    leftRegion.SetPath(circlePath);

                                    // Right leaf
                                    circlePath.Transform(SKMatrix.MakeTranslation(2 * radius, 0));
                                    rightRegion.SetPath(circlePath);

                                    // Make union of right with left
                                    leftRegion.Op(rightRegion, SKRegionOperation.Union);

                                    // Top leaf
                                    circlePath.Transform(SKMatrix.MakeTranslation(-radius, -radius));
                                    topRegion.SetPath(circlePath);

                                    // Combine with bottom leaf
                                    circlePath.Transform(SKMatrix.MakeTranslation(0, 2 * radius));
                                    bottomRegion.SetPath(circlePath);

                                    // Make union of top with bottom
                                    bottomRegion.Op(topRegion, SKRegionOperation.Union);

                                    // Exclusive-OR left and right with top and bottom
                                    leftRegion.Op(bottomRegion, SKRegionOperation.XOR);

                                    // Set that as clip region
                                    canvas.ClipRegion(leftRegion);

                                    // Set transform for drawing lines from center
                                    canvas.Translate(xCenter, yCenter);

                                    // Draw 360 lines
                                    for (double angle = 0; angle < 360; angle++)
                                    {
                                        float x = 2 * radius * (float)Math.Cos(Math.PI * angle / 180);
                                        float y = 2 * radius * (float)Math.Sin(Math.PI * angle / 180);

                                        using (SKPaint strokePaint = new SKPaint())
                                        {
                                            strokePaint.Color       = SKColors.Green;
                                            strokePaint.StrokeWidth = 2;

                                            canvas.DrawLine(0, 0, x, y, strokePaint);
                                        }
                                    }
                                }
                            }
            }
        }