public void Clip(IGradientMask mask, TContext context)
        {
            switch (mask)
            {
            case IEllipseMask ellipseMask:
                EllipsePainter.Clip(ellipseMask, context);
                break;

            case IRectangleMask rectangleMask:
                RectanglePainter.Clip(rectangleMask, context);
                break;

            case ITextMask textMask:
                TextPainter.Clip(textMask, context);
                break;

            case IPathMask pathMask:
                PathPainter.Clip(pathMask, context);
                break;

            case IMaskCollection maskCollection:
                ClipCollection(maskCollection, context);
                break;
            }
        }
示例#2
0
        protected internal void ClipRoundRect(SKRoundRect roundRect, IGradientMask mask, DrawContext context)
        {
            using var canvasLock = new CanvasLock(context.Canvas);

            LayoutBounds(mask, roundRect.Rect, context, false);
            context.Canvas.ClipRoundRect(roundRect, mask.ClipMode.ToSkOperation(), true);
        }
        protected override void BeginLayout(IGradientMask mask, SKRect bounds, DrawContext context)
        {
            var textMask = (ITextMask)mask;

            var posX = textMask.HorizontalTextAlignment switch
            {
                TextAlignment.Center => (float)context.RenderRect.Width / 2,
                TextAlignment.End => context.RenderRect.Width,
                _ => 0
            };

            var posY = textMask.VerticalTextAlignment switch
            {
                TextAlignment.Center => (float)context.RenderRect.Height / 2,
                TextAlignment.End => context.RenderRect.Height,
                _ => 0
            };

            context.Canvas.Translate(posX, posY);
        }
示例#4
0
        protected void LayoutBounds(IGradientMask mask, SKRect bounds, DrawContext context, bool keepAspectRatio)
        {
            BeginLayout(mask, bounds, context);

            if (mask.Stretch == Stretch.None)
            {
                var scaleX = (float)context.RenderRect.Width / context.CanvasRect.Width;
                var scaleY = (float)context.RenderRect.Height / context.CanvasRect.Height;

                if (keepAspectRatio)
                {
                    context.Canvas.Scale(Math.Max(scaleX, scaleY));
                }
                else
                {
                    context.Canvas.Scale(scaleX, scaleY);
                }
            }
            else
            {
                var scaleX = context.RenderRect.Width / bounds.Width;
                var scaleY = context.RenderRect.Height / bounds.Height;

                if (mask.Stretch == Stretch.AspectFit)
                {
                    context.Canvas.Scale(Math.Min(scaleX, scaleY));
                }

                if (mask.Stretch == Stretch.AspectFill)
                {
                    context.Canvas.Scale(Math.Max(scaleX, scaleY));
                }

                if (mask.Stretch == Stretch.Fill)
                {
                    context.Canvas.Scale(scaleX, scaleY);
                }
            }

            EndLayout(mask, bounds, context);
        }
        protected override void EndLayout(IGradientMask mask, SKRect bounds, DrawContext context)
        {
            var textMask = (ITextMask)mask;

            var movX = textMask.HorizontalTextAlignment switch
            {
                TextAlignment.Center => - bounds.MidX,
                TextAlignment.End => - bounds.Right,
                _ => - bounds.Left
            };

            var movY = textMask.VerticalTextAlignment switch
            {
                TextAlignment.Center => - bounds.MidY,
                TextAlignment.End => - bounds.Bottom,
                _ => - bounds.Top
            };

            context.Canvas.Translate(movX, movY);
        }
    }
}
示例#6
0
 protected virtual void EndLayout(IGradientMask mask, SKRect bounds, DrawContext context)
 {
     context.Canvas.Translate(-bounds.MidX, -bounds.MidY);
 }
示例#7
0
 protected virtual void BeginLayout(IGradientMask mask, SKRect bounds, DrawContext context)
 {
     context.Canvas.Translate((float)context.RenderRect.Width / 2, (float)context.RenderRect.Height / 2);
 }
示例#8
0
 public static T Mask <T>(this T control, IGradientMask mask) where T : IGradientControl
 {
     control.Mask = mask;
     return(control);
 }