Esempio n. 1
0
        public WrapperView(EvasObject parent) : base(parent)
        {
            _drawableCanvas = new Lazy <SkiaGraphicsView>(() =>
            {
                var view = new SkiaGraphicsView(parent)
                {
                    IgnorePixelScaling = true,
                    Drawable           = new MauiDrawable(),
                    PassEvents         = true
                };
                view.Show();
                Children.Add(view);
                view.Lower();
                Content?.RaiseTop();
                return(view);
            });

            _clipperView = new Lazy <SKClipperView>(() =>
            {
                var clipper = new SKClipperView(parent)
                {
                    PassEvents = true
                };
                clipper.DrawClip += OnClipPaint;
                clipper.Show();
                clipper.DeviceScalingFactor = (float)DeviceInfo.ScalingFactor;
                Children.Add(clipper);
                clipper.Lower();
                Content?.RaiseTop();
                return(clipper);
            });

            LayoutUpdated += OnLayout;
        }
Esempio n. 2
0
        public override void Run(ElmSharp.Box parent)
        {
            var container = new Canvas(parent)
            {
                AlignmentX    = -1,
                AlignmentY    = -1,
                WeightX       = 1,
                WeightY       = 1,
                MinimumHeight = 300,
            };

            container.Show();
            parent.PackEnd(container);

            container.LayoutUpdated += (s, e) =>
            {
                foreach (var child in container.Children)
                {
                    child.Geometry = container.Geometry;
                    if (child is SKClipperView clip)
                    {
                        clip.Invalidate();
                    }
                }
            };

            var img1 = new Image(parent);

            img1.Show();
            img1.Load(Application.Current.DirectoryInfo.Resource + "animated.gif");
            img1.SetIsAnimationPlaying(true);

            var clipper = new SKClipperView(parent);

            clipper.Show();
            clipper.PaintSurface += (s, e) =>
            {
                var canvas = e.Surface.Canvas;
                var width  = e.Info.Width;
                var height = e.Info.Height;

                using (var paint = new SKPaint
                {
                    IsAntialias = true,
                    Color = SKColors.White,
                    Style = SKPaintStyle.Fill,
                })
                {
                    canvas.Clear();
                    canvas.DrawCircle(width / 2.0f, height / 2.0f, Math.Min(width / 2.0f, height / 2.0f) / 2.0f, paint);
                }

                img1.SetClipperCanvas(clipper);
            };
            clipper.Lower();
            container.Children.Add(img1);
            container.Children.Add(clipper);
        }