示例#1
0
        SKPath CreateShadowPath()
        {
            var geometry = NativeView.Geometry;

            if (ShadowElement.Content != null)
            {
                var contentNativeView = Platform.GetOrCreateRenderer(ShadowElement.Content)?.NativeView;
                if (contentNativeView != null)
                {
                    geometry = contentNativeView.Geometry;
                }
            }

            var path           = new SKPath();
            var left           = geometry.Left - _shadowCanvasView.Geometry.Left;
            var top            = geometry.Top - _shadowCanvasView.Geometry.Top;
            var rect           = new SKRect(left, top, left + geometry.Width, top + geometry.Height);
            var scaledTLRadius = Forms.ConvertToScaledPixel(ShadowElement.CornerRadius.TopLeft) * 2;
            var scaledTRRadius = Forms.ConvertToScaledPixel(ShadowElement.CornerRadius.TopRight) * 2;
            var scaledBLRadius = Forms.ConvertToScaledPixel(ShadowElement.CornerRadius.BottomLeft) * 2;
            var scaledBRRadius = Forms.ConvertToScaledPixel(ShadowElement.CornerRadius.BottomRight) * 2;
            var topLeft        = new SKRect(rect.Left, rect.Top, rect.Left + scaledTLRadius, rect.Top + scaledTLRadius);
            var topRight       = new SKRect(rect.Right - scaledTRRadius, rect.Top, rect.Right, rect.Top + scaledTRRadius);
            var bottomLeft     = new SKRect(rect.Left, rect.Bottom - scaledBLRadius, rect.Left + scaledBLRadius, rect.Bottom);
            var bottomRight    = new SKRect(rect.Right - scaledBRRadius, rect.Bottom - scaledBRRadius, rect.Right, rect.Bottom);

            path.ArcTo(topLeft, 180, 90, false);
            path.ArcTo(topRight, 270, 90, false);
            path.ArcTo(bottomRight, 0, 90, false);
            path.ArcTo(bottomLeft, 90, 90, false);
            path.Close();
            return(path);
        }
示例#2
0
        protected override EvasObject OnGetContent(Cell cell, string part)
        {
            if (part == MainContentPart)
            {
                var viewCell = (ViewCell)cell;

                var listView = viewCell?.RealParent as ListView;

                // It is a condition for reusable the cell
                if (listView != null &&
                    listView.HasUnevenRows == false &&
                    !(listView.ItemTemplate is DataTemplateSelector) && !GetCurrentItem().IsGroupItem)
                {
                    return(CreateReusableContent(viewCell));
                }

                Platform.GetRenderer(viewCell.View)?.Dispose();
                var    renderer = Platform.GetOrCreateRenderer(viewCell.View);
                double height   = viewCell.RenderHeight;
                height = height > 0 ? height : FindCellContentHeight(viewCell);

                renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(height);
                (renderer as ILayoutRenderer)?.RegisterOnLayoutUpdated();

                UpdatePropagateEvent(viewCell.View);

                return(renderer.NativeView);
            }
            return(null);
        }
        /// <summary>
        /// Gets the item class used for header and footer cells.
        /// </summary>
        /// <returns>The header and footer item class.</returns>
        GenItemClass GetHeaderFooterItemClass()
        {
            if (_headerFooterItemClass == null)
            {
                _headerFooterItemClass = new GenItemClass("full")
                {
                    GetContentHandler = (data, part) =>
                    {
                        VisualElement element  = data as VisualElement;
                        var           renderer = Platform.GetOrCreateRenderer(element);

                        if (element.MinimumHeightRequest == -1)
                        {
                            SizeRequest request = element.Measure(double.PositiveInfinity, double.PositiveInfinity);
                            renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(request.Request.Height);
                        }
                        else
                        {
                            renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(element.MinimumHeightRequest);
                        }

                        (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();

                        return(renderer.NativeView);
                    }
                };
            }
            return(_headerFooterItemClass);
        }
示例#4
0
        public SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
        {
            if (null == NativeView)
            {
                return(new SizeRequest(new Size(0, 0)));
            }
            else
            {
                int availableWidth  = Forms.ConvertToScaledPixel(widthConstraint);
                int availableHeight = Forms.ConvertToScaledPixel(heightConstraint);

                if (availableWidth < 0)
                {
                    availableWidth = int.MaxValue;
                }
                if (availableHeight < 0)
                {
                    availableHeight = int.MaxValue;
                }

                Size measured;
                var  nativeViewMeasurable = NativeView as Native.IMeasurable;
                if (nativeViewMeasurable != null)
                {
                    measured = nativeViewMeasurable.Measure(availableWidth, availableHeight).ToDP();
                }
                else
                {
                    measured = Measure(availableWidth, availableHeight).ToDP();
                }

                return(new SizeRequest(measured, MinimumSize()));
            }
        }
示例#5
0
        void ApplyTranslation(EvasMap map, ERect geometry, ref bool changed)
        {
            var shiftX = Forms.ConvertToScaledPixel(Element.TranslationX);
            var shiftY = Forms.ConvertToScaledPixel(Element.TranslationY);

            // apply translation, i.e. move/shift the object a little
            if (shiftX != 0 || shiftY != 0)
            {
                if (changed)
                {
                    // special care is taken to apply the translation last
                    Point3D p;
                    for (int i = 0; i < 4; i++)
                    {
                        p    = map.GetPointCoordinate(i);
                        p.X += shiftX;
                        p.Y += shiftY;
                        map.SetPointCoordinate(i, p);
                    }
                }
                else
                {
                    // in case when we only need translation, then construct the map in a simpler way
                    geometry.X += shiftX;
                    geometry.Y += shiftY;
                    map.PopulatePoints(geometry, 0);

                    changed = true;
                }
            }
        }
示例#6
0
        void OnLayout()
        {
            if (Geometry.Width == 0 || Geometry.Height == 0)
            {
                return;
            }

            var bound = Geometry;
            int navBarHeight;

            if (NavBarIsVisible)
            {
                var navBound = bound;
                navBarHeight    = Forms.ConvertToScaledPixel(_navBar.GetDefaultHeight());
                navBound.Height = navBarHeight;

                _navBar.Show();
                _navBar.Geometry = navBound;
                _navBar.RaiseTop();
            }
            else
            {
                navBarHeight = 0;
                _navBar.Hide();
            }

            bound.Y            += navBarHeight;
            bound.Height       -= navBarHeight;
            _viewStack.Geometry = bound;
        }
示例#7
0
        SKPath CreateRoundRectPath(float width, float height)
        {
            var path        = new SKPath();
            var topLeft     = Forms.ConvertToScaledPixel(ShadowElement.CornerRadius.TopLeft);
            var topRight    = Forms.ConvertToScaledPixel(ShadowElement.CornerRadius.TopRight);
            var bottomLeft  = Forms.ConvertToScaledPixel(ShadowElement.CornerRadius.BottomLeft);
            var bottomRight = Forms.ConvertToScaledPixel(ShadowElement.CornerRadius.BottomRight);
            var padding     = Convert.ToSingle(ShadowElement.BorderWidth);
            var diameter    = padding * 2;

            width  = width > diameter ? width - diameter : 0;
            height = height > diameter ? height - diameter : 0;
            var startX = topLeft + padding;
            var startY = padding;

            path.MoveTo(startX, startY);
            path.LineTo(width - topRight + padding, startY);
            path.ArcTo(topRight, new SKPoint(width + padding, topRight + padding));
            path.LineTo(width + padding, height - bottomRight + padding);
            path.ArcTo(bottomRight, new SKPoint(width - bottomRight + padding, height + padding));
            path.LineTo(bottomLeft + padding, height + padding);
            path.ArcTo(bottomLeft, new SKPoint(padding, height - bottomLeft + padding));
            path.LineTo(padding, topLeft + padding);
            path.ArcTo(topLeft, new SKPoint(startX, startY));
            path.Close();
            return(path);
        }
示例#8
0
        /// <summary>
        /// Gets the item class used for header and footer cells.
        /// </summary>
        /// <returns>The header and footer item class.</returns>
        protected GenItemClass GetHeaderFooterItemClass()
        {
            if (_headerFooterItemClass == null)
            {
                _headerFooterItemClass = new GenItemClass(ThemeConstants.GenItemClass.Styles.Full)
                {
                    GetContentHandler = (data, part) =>
                    {
                        var context = data as HeaderFooterItemContext;
                        if (context == null || context.Element == null)
                        {
                            return(null);
                        }

                        var renderer = Platform.GetOrCreateRenderer(context.Element);
                        if (context.Element.MinimumHeightRequest == -1)
                        {
                            SizeRequest request = context.Element.Measure(double.PositiveInfinity, double.PositiveInfinity);
                            renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(request.Request.Height);
                        }
                        else
                        {
                            renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(context.Element.MinimumHeightRequest);
                        }

                        (renderer as ILayoutRenderer)?.RegisterOnLayoutUpdated();

                        return(renderer.NativeView);
                    }
                };
            }
            return(_headerFooterItemClass);
        }
示例#9
0
        public static SKMatrix ToSkia(this Transform transform)
        {
            SKMatrix skMatrix = SKMatrix.CreateIdentity();

            if (transform == null)
            {
                return(skMatrix);
            }

            Matrix matrix = transform.Value;

            skMatrix.Values = new float[] {
                (float)matrix.M11,
                (float)matrix.M21,
                Forms.ConvertToScaledPixel(matrix.OffsetX),
                (float)matrix.M12,
                (float)matrix.M22,
                Forms.ConvertToScaledPixel(matrix.OffsetY),
                0,
                0,
                1
            };

            return(skMatrix);
        }
示例#10
0
        protected override EvasObject OnGetContent(Cell cell, string part)
        {
            if (part == ImagePart)
            {
                var imgCell   = cell as ImageCell;
                int pixelSize = Forms.ConvertToScaledPixel(imgCell.RenderHeight);
                if (pixelSize <= 0)
                {
                    pixelSize = this.GetDefaultHeightPixel();
                }

                var image = new Native.Image(Forms.NativeParent)
                {
                    MinimumWidth  = pixelSize,
                    MinimumHeight = pixelSize
                };
                image.SetAlignment(-1.0, -1.0);            // fill
                image.SetWeight(1.0, 1.0);                 // expand

                var task = image.LoadFromImageSourceAsync(imgCell.ImageSource);
                return(image);
            }
            else
            {
                return(null);
            }
        }
示例#11
0
        void UpdateGeometry()
        {
            var geometry = ContentNativeView == null ? NativeView.Geometry : ContentNativeView.Geometry;

            double left = 0;
            double top = 0;
            double right = 0;
            double bottom = 0;

            foreach (var shadow in _shadesSource)
            {
                var scaledOffsetX = Forms.ConvertToScaledPixel(shadow.Offset.X);
                var scaledOffsetY = Forms.ConvertToScaledPixel(shadow.Offset.Y);
                var scaledBlurRadius = Forms.ConvertToScaledPixel(shadow.BlurRadius);
                var spreadSize = scaledBlurRadius * 2 + scaledBlurRadius;
                var sl = scaledOffsetX - spreadSize;
                var sr = scaledOffsetX + spreadSize;
                var st = scaledOffsetY - spreadSize;
                var sb = scaledOffsetY + spreadSize;
                if (left > sl) left = sl;
                if (top > st) top = st;
                if (right < sr) right = sr;
                if (bottom < sb) bottom = sb;
            }

            var canvasGeometry = new Rect(geometry.X + (int)left, geometry.Y + (int)top, geometry.Width + (int)right - (int)left, geometry.Height + (int)bottom - (int)top);
            if (_canvasView != null)
            {
                _canvasView.Geometry = canvasGeometry;
                _canvasView.Invalidate();
            }
        }
示例#12
0
        protected override ElmSharp.Size Measure(int availableWidth, int availableHeight)
        {
            var size = _image.Measure(availableHeight, availableHeight);

            size.Width  += Forms.ConvertToScaledPixel(Element.Padding.HorizontalThickness);
            size.Height += Forms.ConvertToScaledPixel(Element.Padding.VerticalThickness);
            return(size);
        }
示例#13
0
        SKRoundRect CreateRoundRect(SKRect bounds)
        {
            var border    = Forms.ConvertToScaledPixel(s_borderWidth) * (Element.HasShadow ? 4 : 2);
            var radius    = Forms.ConvertToScaledPixel(Element.CornerRadius);
            var roundRect = new SKRoundRect(bounds, radius);

            roundRect.Deflate(border, border);
            return(roundRect);
        }
示例#14
0
        EvasObject GetContent(object data, string part)
        {
            ShellSection section = data as ShellSection;

            var box = new EBox(Forms.NativeParent);

            box.Show();

            EImage icon = null;

            if (section.Icon != null)
            {
                icon = new EImage(Forms.NativeParent);
                icon.Show();
                box.PackEnd(icon);
                _ = icon.LoadFromImageSourceAsync(section.Icon);
            }

            var title = new Native.Label(Forms.NativeParent)
            {
                Text     = section.Title,
                FontSize = Forms.ConvertToEflFontPoint(14),
                HorizontalTextAlignment = Native.TextAlignment.Start,
                VerticalTextAlignment   = Native.TextAlignment.Center,
            };

            title.Show();
            box.PackEnd(title);
            int iconPadding = Forms.ConvertToScaledPixel(this.GetIconPadding());
            int iconSize    = Forms.ConvertToScaledPixel(this.GetIconSize());
            int cellHeight  = iconPadding * 2 + iconSize;

            box.SetLayoutCallback(() =>
            {
                var bound      = box.Geometry;
                int leftMargin = iconPadding;

                if (icon != null)
                {
                    var iconBound    = bound;
                    iconBound.X     += iconPadding;
                    iconBound.Y     += iconPadding;
                    iconBound.Width  = iconSize;
                    iconBound.Height = iconSize;
                    icon.Geometry    = iconBound;
                    leftMargin       = (2 * iconPadding + iconSize);
                }

                bound.X       += leftMargin;
                bound.Width   -= leftMargin;
                title.Geometry = bound;
            });

            box.MinimumHeight = cellHeight;
            return(box);
        }
 private void UpdateCornerRadius(PancakeView pancake)
 {
     pancake.CornerRadius.Deconstruct(out double topLeft, out double topRight, out double bottomLeft, out double bottomRight);
     _borderRectangle.SetRadius(Forms.ConvertToScaledPixel(topLeft), Forms.ConvertToScaledPixel(topRight),
                                Forms.ConvertToScaledPixel(bottomLeft), Forms.ConvertToScaledPixel(bottomRight));
     _roundRectangle.SetRadius(Forms.ConvertToScaledPixel(topLeft), Forms.ConvertToScaledPixel(topRight),
                               Forms.ConvertToScaledPixel(bottomLeft), Forms.ConvertToScaledPixel(bottomRight));
     _roundRectangle.Draw();
     _borderRectangle.Draw();
 }
        private void DrawBorder(SKCanvas canvas)
        {
            var pancake = Element as PancakeView;

            if (pancake.Border != null && pancake.Border.Thickness != default)
            {
                using (var paint = new SKPaint())
                {
                    var border = pancake.Border;
                    paint.Style       = SKPaintStyle.Stroke;
                    paint.Color       = border.Color.ToNative().ToSKColor();
                    paint.StrokeWidth = Forms.ConvertToScaledPixel(border.Thickness);
                    paint.IsAntialias = true;

                    SKPath path;
                    if (pancake.Sides != 4)
                    {
                        path = DrawingExtensions.CreatePolygonPath(Control.Geometry.Width, Control.Geometry.Height,
                                                                   pancake.Sides, pancake.CornerRadius.TopLeft, pancake.OffsetAngle);
                    }
                    else
                    {
                        var left = Control.Geometry.Left - _skCanvasView.Geometry.Left;
                        var top  = Control.Geometry.Top - _skCanvasView.Geometry.Top;
                        path = DrawingExtensions.CreateRoundedRectPath(left, top, left + Control.Geometry.Width, top + Control.Geometry.Height, pancake.CornerRadius);
                    }

                    if (border.DashPattern.Pattern != null &&
                        border.DashPattern.Pattern.Length > 0 &&
                        (border.DashPattern.Pattern.Length % 2 == 0 || border.DashPattern.Pattern.Length == 1))
                    {
                        var items = border.DashPattern.Pattern.Select(x => Convert.ToSingle(x)).ToList();

                        if (items.Count == 1)
                        {
                            items.Add(items[0]);
                        }

                        paint.PathEffect = SKPathEffect.CreateDash(items.ToArray(), 0);
                    }

                    if (border.GradientStops != null && border.GradientStops.Any())
                    {
                        var startPoint       = new SKPoint((float)(border.GradientStartPoint.X * Control.Geometry.Width), (float)(border.GradientStartPoint.Y * Control.Geometry.Height));
                        var endPoint         = new SKPoint((float)(border.GradientEndPoint.X * Control.Geometry.Width), (float)(border.GradientEndPoint.Y * Control.Geometry.Height));
                        var orderedStops     = border.GradientStops.OrderBy(x => x.Offset).ToList();
                        var gradientColors   = orderedStops.Select(x => x.Color.ToNative().ToSKColor()).ToArray();
                        var gradientColorPos = orderedStops.Select(x => x.Offset).ToArray();
                        paint.Shader = SKShader.CreateLinearGradient(startPoint, endPoint, gradientColors, gradientColorPos, SKShaderTileMode.Clamp);
                    }
                    canvas.ClipPath(path, SKClipOperation.Intersect, true);
                    canvas.DrawPath(path, paint);
                }
            }
        }
示例#17
0
        void UpdateShadowGeometry()
        {
            var geometry = NativeView.Geometry;

            if (ShadowElement.Content != null)
            {
                var contentNativeView = Platform.GetOrCreateRenderer(ShadowElement.Content)?.NativeView;
                if (contentNativeView != null)
                {
                    geometry = contentNativeView.Geometry;
                }
            }
            double left             = 0;
            double top              = 0;
            double right            = 0;
            double bottom           = 0;
            var    scaledOffsetX    = Forms.ConvertToScaledPixel(ShadowElement.ShadowOffsetX);
            var    scaledOffsetY    = Forms.ConvertToScaledPixel(ShadowElement.ShadowOffsetY);
            var    scaledBlurRadius = Forms.ConvertToScaledPixel(ShadowElement.ShadowBlurRadius);
            var    spreadSize       = scaledBlurRadius * 3;
            var    sl = scaledOffsetX - spreadSize;
            var    sr = scaledOffsetX + spreadSize;
            var    st = scaledOffsetY - spreadSize;
            var    sb = scaledOffsetY + spreadSize;

            if (left > sl)
            {
                left = sl;
            }
            if (top > st)
            {
                top = st;
            }
            if (right < sr)
            {
                right = sr;
            }
            if (bottom < sb)
            {
                bottom = sb;
            }

            var canvasGeometry = new ElmSharp.Rect(
                geometry.X + (int)left,
                geometry.Y + (int)top,
                geometry.Width + (int)right - (int)left,
                geometry.Height + (int)bottom - (int)top);

            if (_shadowCanvasView != null)
            {
                _shadowCanvasView.Geometry = canvasGeometry;
                _shadowCanvasView.Invalidate();
            }
        }
示例#18
0
        void UpdateHorizontalScrollStep(bool initialize)
        {
            var step = Specific.GetHorizontalScrollStep(Element);

            if (initialize && step == -1)
            {
                return;
            }

            Control.HorizontalStepSize = step != -1 ? Forms.ConvertToScaledPixel(step) : _defaultHorizontalStepSize;
        }
示例#19
0
        protected override void OnBackgroundPaint(object sender, SKPaintSurfaceEventArgs e)
        {
            var canvas = e.Surface.Canvas;
            var bound  = e.Info.Rect;

            canvas.Clear();
            var bgColor     = Element.BackgroundColor.IsDefault() ? s_defaultColor : SKColor.Parse(Element.BackgroundColor.ToHex());
            var borderColor = Element.BorderColor.IsDefault() ? s_defaultColor : SKColor.Parse(Element.BorderColor.ToHex());
            var roundRect   = CreateRoundRect(bound);

            using (var paint = new SKPaint
            {
                IsAntialias = true,
            })
            {
                if (Element.HasShadow)
                {
                    paint.Color = SKColors.White;
                    paint.Style = SKPaintStyle.Stroke;
                    // Draw shadow
                    paint.ImageFilter = SKImageFilter.CreateDropShadowOnly(
                        Forms.ConvertToScaledPixel(0),
                        Forms.ConvertToScaledPixel(0),
                        Forms.ConvertToScaledPixel(s_borderWidth * 2),
                        Forms.ConvertToScaledPixel(s_borderWidth * 2),
                        SKColors.Black);
                    canvas.DrawRoundRect(roundRect, paint);
                }

                paint.ImageFilter = null;
                paint.Style       = SKPaintStyle.Fill;
                paint.Color       = bgColor;

                // Draw background color
                canvas.DrawRoundRect(roundRect, paint);

                paint.Style       = SKPaintStyle.Stroke;
                paint.StrokeWidth = Forms.ConvertToScaledPixel(s_borderWidth);
                paint.Color       = borderColor;

                // Draw Background (Brush)
                using (var brushPaint = Element.GetBackgroundPaint(bound))
                {
                    if (brushPaint != null)
                    {
                        canvas.DrawRoundRect(roundRect, brushPaint);
                    }
                }

                // Draw border
                canvas.DrawRoundRect(roundRect, paint);
            }
        }
        void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            var geometry = ContentNativeView == null ? NativeView.Geometry : ContentNativeView.Geometry;
            var canvas   = e.Surface.Canvas;

            canvas.Clear();

            var path         = new SKPath();
            var left         = geometry.Left - _canvasView.Geometry.Left;
            var top          = geometry.Top - _canvasView.Geometry.Top;
            var rect         = new SKRect(left, top, left + geometry.Width, top + geometry.Height);
            var scaledRadius = Forms.ConvertToScaledPixel(ShadowsElement.CornerRadius) * 2;
            var topLeft      = new SKRect(rect.Left, rect.Top, rect.Left + scaledRadius, rect.Top + scaledRadius);
            var topRight     = new SKRect(rect.Right - scaledRadius, rect.Top, rect.Right, rect.Top + scaledRadius);
            var bottomLeft   = new SKRect(rect.Left, rect.Bottom - scaledRadius, rect.Left + scaledRadius, rect.Bottom);
            var bottomRight  = new SKRect(rect.Right - scaledRadius, rect.Bottom - scaledRadius, rect.Right, rect.Bottom);

            path.ArcTo(topLeft, 180, 90, false);
            path.ArcTo(topRight, 270, 90, false);
            path.ArcTo(bottomRight, 0, 90, false);
            path.ArcTo(bottomLeft, 90, 90, false);
            path.Close();

            using (var paint = new SKPaint())
            {
                paint.IsAntialias = true;
                paint.Style       = SKPaintStyle.StrokeAndFill;
                foreach (var shade in _shadesSource)
                {
                    var scaledOffsetX    = Forms.ConvertToScaledPixel(shade.Offset.X);
                    var scaledOffsetY    = Forms.ConvertToScaledPixel(shade.Offset.Y);
                    var scaledBlurRadius = Forms.ConvertToScaledPixel(shade.BlurRadius);

                    canvas.Save();
                    canvas.ClipPath(path, SKClipOperation.Difference, true);
                    paint.ImageFilter = SKImageFilter.CreateDropShadow(
                        scaledOffsetX,
                        scaledOffsetY,
                        scaledBlurRadius,
                        scaledBlurRadius,
                        shade.Color.MultiplyAlpha(shade.Opacity).ToSK(),
                        SKDropShadowImageFilterShadowMode.DrawShadowOnly);
                    canvas.DrawPath(path, paint);
                    canvas.Restore();

                    canvas.Save();
                    canvas.ClipPath(path, SKClipOperation.Intersect, true);
                    canvas.DrawPath(path, paint);
                    canvas.Restore();
                }
            }
        }
示例#21
0
        static SKPath MakePath(EllipseGeometry ellipseGeometry)
        {
            var path = new SKPath();

            path.AddOval(new SKRect(
                             Forms.ConvertToScaledPixel(ellipseGeometry.Center.X - ellipseGeometry.RadiusX),
                             Forms.ConvertToScaledPixel(ellipseGeometry.Center.Y - ellipseGeometry.RadiusY),
                             Forms.ConvertToScaledPixel(ellipseGeometry.Center.X + ellipseGeometry.RadiusX),
                             Forms.ConvertToScaledPixel(ellipseGeometry.Center.Y + ellipseGeometry.RadiusY)),
                         SKPathDirection.Clockwise);

            return(path);
        }
示例#22
0
        void UpdateRadius(bool init)
        {
            CornerRadius = Element.CornerRadius;
            int topLeft     = Forms.ConvertToScaledPixel(Element.CornerRadius.TopLeft);
            int topRight    = Forms.ConvertToScaledPixel(Element.CornerRadius.TopRight);
            int bottomLeft  = Forms.ConvertToScaledPixel(Element.CornerRadius.BottomLeft);
            int bottomRight = Forms.ConvertToScaledPixel(Element.CornerRadius.BottomRight);

            if (!init)
            {
                RealControl.Draw();
            }
        }
示例#23
0
        void OnRadiusUpdate(bool init)
        {
            int topLeft     = Forms.ConvertToScaledPixel(Element.CornerRadius.TopLeft);
            int topRight    = Forms.ConvertToScaledPixel(Element.CornerRadius.TopRight);
            int bottomLeft  = Forms.ConvertToScaledPixel(Element.CornerRadius.BottomLeft);
            int bottomRight = Forms.ConvertToScaledPixel(Element.CornerRadius.BottomRight);

            Control.SetRadius(topLeft, topRight, bottomLeft, bottomRight);
            if (!init)
            {
                Control.Draw();
            }
        }
示例#24
0
        void UpdateContentSize()
        {
            _scrollCanvas.MinimumWidth  = Forms.ConvertToScaledPixel(Element.ContentSize.Width + Element.Padding.HorizontalThickness);
            _scrollCanvas.MinimumHeight = Forms.ConvertToScaledPixel(Element.ContentSize.Height + Element.Padding.VerticalThickness);

            // elm-scroller updates the CurrentRegion after render
            Application.Current.Dispatcher.Dispatch(() =>
            {
                if (Control != null)
                {
                    OnScrolled(Control, EventArgs.Empty);
                }
            });
        }
示例#25
0
        void UpdateContentSize()
        {
            _scrollCanvas.MinimumWidth  = Forms.ConvertToScaledPixel(Element.ContentSize.Width + Element.Padding.HorizontalThickness);
            _scrollCanvas.MinimumHeight = Forms.ConvertToScaledPixel(Element.ContentSize.Height + Element.Padding.VerticalThickness);

            // elm-scroller updates the CurrentRegion after render
            Device.BeginInvokeOnMainThread(() =>
            {
                if (Control != null)
                {
                    OnScrolled(Control, EventArgs.Empty);
                }
            });
        }
示例#26
0
        static SKPath MakePath(RectangleGeometry rectangleGeometry)
        {
            var            path = new SKPath();
            FormsRectangle rect = rectangleGeometry.Rect;

            path.AddRect(new SKRect(
                             Forms.ConvertToScaledPixel(rect.Left),
                             Forms.ConvertToScaledPixel(rect.Top),
                             Forms.ConvertToScaledPixel(rect.Right),
                             Forms.ConvertToScaledPixel(rect.Bottom)),
                         SKPathDirection.Clockwise);

            return(path);
        }
示例#27
0
        static SKPath MakePath(LineGeometry lineGeometry)
        {
            var path = new SKPath();

            path.MoveTo(
                Forms.ConvertToScaledPixel(lineGeometry.StartPoint.X),
                Forms.ConvertToScaledPixel(lineGeometry.StartPoint.Y));

            path.LineTo(
                Forms.ConvertToScaledPixel(lineGeometry.EndPoint.X),
                Forms.ConvertToScaledPixel(lineGeometry.EndPoint.Y));

            return(path);
        }
示例#28
0
        void OnLayout()
        {
            var outter     = Control.Geometry;
            var width      = outter.Width - Forms.ConvertToScaledPixel(Element.Padding.HorizontalThickness);
            var height     = outter.Height - Forms.ConvertToScaledPixel(Element.Padding.VerticalThickness);
            var left       = outter.Left + Forms.ConvertToScaledPixel(Element.Padding.Left);
            var top        = outter.Top + Forms.ConvertToScaledPixel(Element.Padding.Top);
            var imageBound = new ERect(left, top, width, height);

            _image.Geometry  = imageBound;
            _button.Geometry = outter;
            _round.Draw(outter);
            _border.Draw(outter);
        }
示例#29
0
 void UpdateBorderWidth(bool init)
 {
     if (Element.BorderWidth > 0)
     {
         _border.BorderWidth = Forms.ConvertToScaledPixel(Element.BorderWidth);
     }
     else
     {
         _border.BorderWidth = 0;
     }
     if (!init)
     {
         _border.Draw();
     }
 }
        private void DrawShadow(SKCanvas canvas)
        {
            var pancake = Element as PancakeView;

            if (pancake.Shadow != null)
            {
                SKPath path;
                if (pancake.Sides != 4)
                {
                    path = DrawingExtensions.CreatePolygonPath(Control.Geometry.Width, Control.Geometry.Height,
                                                               pancake.Sides, pancake.CornerRadius.TopLeft, pancake.OffsetAngle);
                }
                else
                {
                    var left = Control.Geometry.Left - _skCanvasView.Geometry.Left;
                    var top  = Control.Geometry.Top - _skCanvasView.Geometry.Top;
                    path = DrawingExtensions.CreateRoundedRectPath(left, top, left + Control.Geometry.Width, top + Control.Geometry.Height, pancake.CornerRadius);
                }

                using (var paint = new SKPaint())
                {
                    paint.IsAntialias = true;
                    paint.Style       = SKPaintStyle.StrokeAndFill;

                    var shadow           = pancake.Shadow;
                    var scaledOffsetX    = Forms.ConvertToScaledPixel(shadow.Offset.X);
                    var scaledOffsetY    = Forms.ConvertToScaledPixel(shadow.Offset.Y);
                    var scaledBlurRadius = Forms.ConvertToScaledPixel(shadow.BlurRadius);

                    canvas.Save();
                    canvas.ClipPath(path, SKClipOperation.Difference, true);
                    paint.ImageFilter = SKImageFilter.CreateDropShadow(
                        scaledOffsetX,
                        scaledOffsetY,
                        scaledBlurRadius,
                        scaledBlurRadius,
                        shadow.Color.MultiplyAlpha(shadow.Opacity).ToNative().ToSKColor(),
                        SKDropShadowImageFilterShadowMode.DrawShadowOnly);
                    canvas.DrawPath(path, paint);
                    canvas.Restore();

                    canvas.Save();
                    canvas.ClipPath(path, SKClipOperation.Intersect, true);
                    canvas.DrawPath(path, paint);
                    canvas.Restore();
                }
            }
        }