Пример #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;
        }
Пример #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);
        }
 protected override void OnElementChanged(ElementChangedEventArgs <Layout> e)
 {
     base.OnElementChanged(e);
     _clipper = new SKClipperView(Forms.NativeParent);
     _clipper.Show();
     _clipper.PassEvents    = true;
     _clipper.PaintSurface += OnCliperPaint;
     Control.Children.Add(_clipper);
     BackgroundCanvas?.StackAbove(_clipper);
     if (!UseShadowClipping)
     {
         CreateShadowCanvas();
     }
 }
Пример #4
0
        protected override void OnElementChanged(ElementChangedEventArgs <Layout> e)
        {
            base.OnElementChanged(e);
            _clipper = new SKClipperView(Forms.NativeParent);
            _clipper.Show();
            _clipper.PassEvents    = true;
            _clipper.PaintSurface += OnCliperPaint;
            Control.Children.Add(_clipper);
            BackgroundCanvas?.StackAbove(_clipper);

            _shadowCanvasView = new SKCanvasView(Forms.NativeParent);
            _shadowCanvasView.Show();
            _shadowCanvasView.PassEvents    = true;
            _shadowCanvasView.PaintSurface += OnShadowPaint;
            Control.Children.Add(_shadowCanvasView);
            _shadowCanvasView.Lower();
            _shadowCanvasView.SetClip(null);
        }
Пример #5
0
        public override View Run()
        {
            var scrollView = new Tizen.UIExtensions.NUI.ScrollView
            {
                BackgroundColor     = Color.Blue,
                WidthSpecification  = LayoutParamPolicies.MatchParent,
                HeightSpecification = LayoutParamPolicies.MatchParent
            };

            scrollView.ContentContainer.Layout = new LinearLayout
            {
                LinearAlignment   = LinearLayout.Alignment.Center,
                LinearOrientation = LinearLayout.Orientation.Vertical,
            };

            scrollView.ContentContainer.WidthSpecification  = LayoutParamPolicies.MatchParent;
            scrollView.ContentContainer.HeightSpecification = LayoutParamPolicies.WrapContent;

            {
                var clipper = new SKClipperView
                {
                    WidthSpecification = LayoutParamPolicies.MatchParent,
                    SizeHeight         = 300,
                };
                clipper.DrawClippingArea += OnDrawCircle;
                clipper.Add(new Image
                {
                    WidthSpecification  = LayoutParamPolicies.MatchParent,
                    HeightSpecification = LayoutParamPolicies.MatchParent,
                    ResourceUrl         = Application.Current.DirectoryInfo.Resource + "dotnet_bot.png",
                });

                scrollView.ContentContainer.Add(clipper);

                var btn = new Button
                {
                    Text = "Change"
                };
                scrollView.ContentContainer.Add(btn);

                btn.Clicked += (s, e) =>
                {
                    if (isCircle)
                    {
                        clipper.DrawClippingArea -= OnDrawCircle;
                        clipper.DrawClippingArea += OnDrawRoundRect;
                    }
                    else
                    {
                        clipper.DrawClippingArea -= OnDrawRoundRect;
                        clipper.DrawClippingArea += OnDrawCircle;
                    }
                    isCircle = !isCircle;
                    clipper.Invalidate();
                };
            }

            for (int i = 0; i < 10; i++)
            {
                var clipper = new SKClipperView
                {
                    WidthSpecification = LayoutParamPolicies.MatchParent,
                    SizeHeight         = 300,
                };
                clipper.DrawClippingArea += (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, height) / 2.0f, paint);
                    }
                };

                clipper.Add(new Image
                {
                    WidthSpecification  = LayoutParamPolicies.MatchParent,
                    HeightSpecification = LayoutParamPolicies.MatchParent,
                    ResourceUrl         = Application.Current.DirectoryInfo.Resource + "dotnet_bot.png",
                });

                clipper.Add(new Label
                {
                    WidthSpecification  = LayoutParamPolicies.MatchParent,
                    HeightSpecification = LayoutParamPolicies.MatchParent,
                    Text          = "Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text",
                    LineBreakMode = LineBreakMode.CharacterWrap,
                });
                scrollView.ContentContainer.Add(clipper);
            }

            return(scrollView);
        }