private void DrawBorder(ACanvas canvas, PancakeView control)
        {
            var borderThickness     = Context.ToPixels(control.BorderThickness);
            var halfBorderThickness = borderThickness / 2;

            // TODO: This doesn't look entirely right yet when using it with rounded corners.
            using (var paint = new Paint {
                AntiAlias = true
            })
                using (var path = new Path())
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)

                            using (var rect = new RectF(control.DrawBorderOnOutside && !control.HasShadow ? -halfBorderThickness : halfBorderThickness,
                                                        control.DrawBorderOnOutside && !control.HasShadow ? -halfBorderThickness : halfBorderThickness,
                                                        control.DrawBorderOnOutside && !control.HasShadow ? canvas.Width + halfBorderThickness : canvas.Width - halfBorderThickness,
                                                        control.DrawBorderOnOutside && !control.HasShadow ? canvas.Height + halfBorderThickness : canvas.Height - halfBorderThickness))
                            {
                                path.AddRoundRect(rect, GetRadii(control), direction);

                                if (control.BorderIsDashed)
                                {
                                    paint.SetPathEffect(new DashPathEffect(new float[] { 10, 20 }, 0));
                                }

                                paint.StrokeCap   = Paint.Cap.Square;
                                paint.StrokeWidth = borderThickness;
                                paint.SetStyle(style);
                                paint.Color = control.BorderColor.ToAndroid();

                                canvas.DrawPath(path, paint);
                            }
        }
Пример #2
0
        public override void Draw(Canvas canvas)
        {
            base.Draw(canvas);

            if (Element == null || Element.BorderColor.A <= 0)
            {
                return;
            }
            using (var paint = new Paint
            {
                AntiAlias = true
            })
                using (var path = new Path())
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)
                            using (var rect = new RectF(0, 0, canvas.Width, canvas.Height))
                            {
                                var raduis = Android.App.Application.Context.ToPixels(Element.CornerRadius);
                                path.AddRoundRect(rect, raduis, raduis, direction);
                                //paint.StrokeWidth = Context.Resources.DisplayMetrics.Density * 2;
                                paint.SetStyle(style);
                                paint.Color = Element.BorderColor.ToAndroid();
                                canvas.DrawPath(path, paint);
                            }
        }
Пример #3
0
            void DrawBackground(ACanvas canvas, int width, int height, float cornerRadius, bool pressed)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var path = new Path())
                        using (Path.Direction direction = Path.Direction.Cw)
                            using (Paint.Style style = Paint.Style.Fill)
                                using (var rect = new RectF(
                                           _bounds + _boundsDiff + _contentBounds,
                                           _bounds + _boundsDiff + _contentBounds,
                                           width - (_bounds + _boundsDiff + _contentBounds),
                                           height - (_bounds + _boundsDiff + _contentBounds)))
                                {
                                    float rx = _convertToPixels(cornerRadius);
                                    float ry = _convertToPixels(cornerRadius);
                                    path.AddRoundRect(rect, rx, ry, direction);

                                    global::Android.Graphics.Color color = _frame.BackgroundColor.ToAndroid();


                                    paint.SetStyle(style);
                                    paint.Color = color;

                                    canvas.DrawPath(path, paint);
                                }
            }
Пример #4
0
            void DrawOutline(ACanvas canvas, int width, int height, Thickness cornerRadius)
            {
                var borderThickness     = _convertToPixels(_pancake.BorderThickness);
                var halfBorderThickness = borderThickness / 2;

                // TODO: This doesn't look entirely right yet when using it with rounded corners.
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var path = new Path())
                        using (Path.Direction direction = Path.Direction.Cw)
                            using (Paint.Style style = Paint.Style.Stroke)
                                using (var rect = new RectF(halfBorderThickness, halfBorderThickness, width - halfBorderThickness, height - halfBorderThickness))
                                {
                                    float topLeft     = _convertToPixels(cornerRadius.Left);
                                    float topRight    = _convertToPixels(cornerRadius.Top);
                                    float bottomRight = _convertToPixels(cornerRadius.Right);
                                    float bottomLeft  = _convertToPixels(cornerRadius.Bottom);

                                    path.AddRoundRect(rect, new float[] { topLeft, topLeft, topRight, topRight, bottomRight, bottomRight, bottomLeft, bottomLeft }, direction);

                                    if (_pancake.BorderIsDashed)
                                    {
                                        paint.SetPathEffect(new DashPathEffect(new float[] { 10, 20 }, 0));
                                    }

                                    paint.StrokeCap   = Paint.Cap.Round;
                                    paint.StrokeWidth = borderThickness;
                                    paint.SetStyle(style);
                                    paint.Color = _pancake.BorderColor.ToAndroid();

                                    canvas.DrawPath(path, paint);
                                }
            }
        private void DrawBorder(ACanvas canvas, CorneredContentView control)
        {
            if (control.BorderThickness > 0)
            {
                float borderThickness     = this.Context.ToPixels(control.BorderThickness);
                float halfBorderThickness = borderThickness / 2;

                using (Paint paint = new Paint {
                    AntiAlias = true
                })
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)
                            using (RectF rect = new RectF(!control.HasShadow ? -halfBorderThickness : halfBorderThickness,
                                                          !control.HasShadow ? -halfBorderThickness : halfBorderThickness,
                                                          !control.HasShadow ? canvas.Width + halfBorderThickness : canvas.Width - halfBorderThickness,
                                                          !control.HasShadow ? canvas.Height + halfBorderThickness : canvas.Height - halfBorderThickness))
                            {
                                Path path = new Path();
                                path.AddRoundRect(rect, this.GetRadii(control), direction);

                                paint.Color = control.BorderColor.ToAndroid();

                                paint.StrokeCap   = Paint.Cap.Square;
                                paint.StrokeWidth = borderThickness;

                                paint.SetStyle(style);

                                canvas.DrawPath(path, paint);
                            }
            }
        }
Пример #6
0
        /// <summary>
        /// Adds the given direction to the currently active path, and starts a new path if that finishes that pipe.
        /// </summary>
        /// <param name="d">The direction to add</param>
        public void AddDirectionToCurrentPath(Path.Direction d)
        {
            pathsOfColors.Last().Add(d);
            if (grid[pathsOfColors.Last().lastPoint.Y, pathsOfColors.Last().lastPoint.X] == pathsOfColors.Last().color)
            {
                if (pathsOfColors.Count < startNodes.Length)
                {
                    pathsOfColors.Add(new Path(startNodes[pathsOfColors.Count], colors[1 + Array.IndexOf(colors, pathsOfColors.Last().color)]));
                }
                else
                {
                    bool successful = true;
                    foreach (int i in FlattenGrid())
                    {
                        if (i == -1)
                        {
                            successful = false;
                        }
                    }

                    if (successful)
                    {
                        state = SolveState.Success;
                    }
                    else
                    {
                        state = SolveState.Failed;
                    }
                }
            }
        }
Пример #7
0
        void DrawBackground(ACanvas canvas, int width, int height, CornerRadius cornerRadius, bool pressed)
        {
            using (Paint paint = new Paint {
                AntiAlias = true
            })
                using (Path.Direction direction = Path.Direction.Cw)
                    using (Paint.Style style = Paint.Style.Fill)
                    {
                        Path path = new Path();

                        using (RectF rect = new RectF(0, 0, width, height))
                        {
                            float topLeft     = this._convertToPixels(cornerRadius.TopLeft);
                            float topRight    = this._convertToPixels(cornerRadius.TopRight);
                            float bottomRight = this._convertToPixels(cornerRadius.BottomRight);
                            float bottomLeft  = this._convertToPixels(cornerRadius.BottomLeft);

                            if (!this._corneredContentView.HasShadow)
                            {
                                path.AddRoundRect(rect, new float[] { topLeft, topLeft, topRight, topRight, bottomRight, bottomRight, bottomLeft, bottomLeft }, direction);
                            }
                            else
                            {
                                path.AddRoundRect(rect, new float[] { topLeft, topLeft, topLeft, topLeft, topLeft, topLeft, topLeft, topLeft }, direction);
                            }
                        }

                        global::Android.Graphics.Color color = this._corneredContentView.BackgroundColor.ToAndroid();
                        paint.SetStyle(style);
                        paint.Color = color;

                        canvas.DrawPath(path, paint);
                    }
        }
        void DrawShadow(Canvas canvas)
        {
            using (var paint = new Paint()
            {
                AntiAlias = true
            })
                using (var path = new Path())
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (var rect = new RectF(ExtendedElement.ShadowOffsetX,
                                                    ExtendedElement.ShadowOffsetY,
                                                    this.Width + ExtendedElement.ShadowOffsetX,
                                                    this.Height + ExtendedElement.ShadowOffsetY))
                        {
                            float rx = Context.ToPixels(ExtendedElement.CornerRadius);
                            float ry = Context.ToPixels(ExtendedElement.CornerRadius);
                            path.AddRoundRect(rect, rx, ry, direction);

                            int shadowOpacity = (int)(255 * ExtendedElement.ShadowOpacity);
                            paint.Color = Android.Graphics.Color.Argb(shadowOpacity, 0, 0, 0);
                            paint.SetMaskFilter(new BlurMaskFilter(ExtendedElement.ShadowRadius, BlurMaskFilter.Blur.Normal));

                            canvas.DrawPath(path, paint);
                            //canvas.DrawOval(rect, paint);
                        }
        }
        public override void Draw(Canvas canvas)
        {
            base.Draw(canvas);

            Paint myPaint = new Paint();
            var   effect  = Element as CustomShadowEffects;
            var   path    = new Path();

            Path.Direction direction = Path.Direction.Cw;

            float radius    = effect.Radius;
            float distanceX = effect.DistanceX;
            float distanceY = effect.DistanceY;

            Android.Graphics.Color color = effect.ShadowColor.ToAndroid();

            myPaint.SetStyle(Paint.Style.Stroke);

            myPaint.SetShadowLayer(radius, distanceX, distanceY, color);

            RectF rectF = new RectF(0, 0, Width, Height);

            path.AddRoundRect(rectF, 10, 10, direction);

            myPaint.Color = color;
            canvas.DrawPath(path, myPaint);
        }
Пример #10
0
        void DrawOutline(Android.Graphics.Canvas canvas, int width, int height)
        {
            if (this.Element is FrameApp)
            {
                int strokeWidth = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 1, Context.Resources.DisplayMetrics);

                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var path = new Path())
                        using (Path.Direction direction = Path.Direction.Cw)
                            using (Paint.Style style = Paint.Style.Stroke)


                                using (var rect = new RectF(strokeWidth + strokeWidth / 2, strokeWidth + strokeWidth / 2, width - strokeWidth - strokeWidth / 2, height - strokeWidth - strokeWidth / 2))
                                {
                                    if (this.Element.CornerRadius > 0)
                                    {
                                        float rx = this.Context.ToPixels(this.Element.CornerRadius);
                                        float ry = this.Context.ToPixels(this.Element.CornerRadius);

                                        path.AddRoundRect(rect, rx, ry, direction);
                                    }
                                    else
                                    {
                                        path.AddRect(rect, direction);
                                    }
                                    paint.StrokeWidth = strokeWidth; //set outline stroke
                                    paint.SetStyle(style);
                                    paint.Color = (this.Element as FrameApp).BorderColor.ToAndroid();

                                    canvas.DrawPath(path, paint);
                                }
            }
        }
Пример #11
0
            void DrawOutline(ACanvas canvas, int width, int height, float cornerRadius)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var path = new Path())
                        using (Path.Direction direction = Path.Direction.Cw)
                            using (Paint.Style style = Paint.Style.Stroke)
                                using (var rect = new RectF(left: _bounds, top: _bounds, right: width - _bounds, bottom: height - _bounds))
                                    using (var innerRect = new RectF(
                                               left: _bounds + _boundsDiff,
                                               top: _bounds + _boundsDiff,
                                               right: width - (_bounds + _boundsDiff),
                                               bottom: height - (_bounds + _boundsDiff)))
                                    {
                                        float rx = _convertToPixels(cornerRadius);
                                        float ry = _convertToPixels(cornerRadius);
                                        path.AddRoundRect(rect, rx, ry, direction);
                                        path.AddRoundRect(innerRect, rx, ry, direction);

                                        paint.StrokeWidth = _frameThickness;
                                        paint.SetStyle(style);
                                        paint.Color = _frame.BorderColor.ToAndroid();

                                        canvas.DrawPath(path, paint);
                                    }
            }
Пример #12
0
 public Case(int rows, int columns, Path.Direction direction, Level ctx, int xOffset, int yOffset)
 {
     _rows         = rows;
     _columns      = columns;
     _ctx          = ctx;
     _xTilesOffset = xOffset * 20;
     _yTilesOffset = yOffset * 14;
     Border        = new Rectangle(_xTilesOffset * 64, _yTilesOffset * 64, 20 * 64, 14 * 64);
     _xLevel       = xOffset;
     _yLevel       = yOffset;
     _direction    = direction;
     Tiles         = new Tile[columns, rows];
 }
Пример #13
0
 void UpdateClipPath()
 {
     if (_clipPath != null && _width > 0 && _height > 0)
     {
         using (var bounds = new RectF(PaddingLeft, PaddingTop, _width - PaddingRight, _height - PaddingBottom)) {
             bounds.Inset(_borderWidth, _borderWidth);
             using (Path.Direction direction = Path.Direction.Cw) {
                 _clipPath.Reset();
                 _clipPath.AddRoundRect(bounds, _cornerRadius, _cornerRadius, direction);
                 _clipPath.Close();
             }
         }
     }
 }
        void DrawBackground(ACanvas canvas, int width, int height, CornerRadius cornerRadius)
        {
            using (var paint = new Paint {
                AntiAlias = true
            })
                using (Path.Direction direction = Path.Direction.Cw)
                    using (Paint.Style style = Paint.Style.Fill)
                    {
                        var path = new Path();

                        if (_pancake.Sides != 4)
                        {
                            path = DrawingExtensions.CreatePolygonPath(width, height, _pancake.Sides, _pancake.CornerRadius.TopLeft, _pancake.OffsetAngle);
                        }
                        else
                        {
                            float topLeft     = _convertToPixels(cornerRadius.TopLeft);
                            float topRight    = _convertToPixels(cornerRadius.TopRight);
                            float bottomRight = _convertToPixels(cornerRadius.BottomRight);
                            float bottomLeft  = _convertToPixels(cornerRadius.BottomLeft);

                            path = DrawingExtensions.CreateRoundedRectPath(width, height, topLeft, topRight, bottomRight, bottomLeft);
                        }

                        if (_pancake.BackgroundGradientStops != null && _pancake.BackgroundGradientStops.Any())
                        {
                            // A range of colors is given. Let's add them.
                            var orderedStops = _pancake.BackgroundGradientStops.OrderBy(x => x.Offset).ToList();
                            var colors       = orderedStops.Select(x => x.Color.ToAndroid().ToArgb()).ToArray();
                            var locations    = orderedStops.Select(x => x.Offset).ToArray();

                            var shader = new LinearGradient((float)(canvas.Width * _pancake.BackgroundGradientStartPoint.X),
                                                            (float)(canvas.Height * _pancake.BackgroundGradientStartPoint.Y),
                                                            (float)(canvas.Width * _pancake.BackgroundGradientEndPoint.X),
                                                            (float)(canvas.Height * _pancake.BackgroundGradientEndPoint.Y),
                                                            colors, locations, Shader.TileMode.Clamp);

                            paint.SetShader(shader);
                        }
                        else
                        {
                            global::Android.Graphics.Color color = _pancake.BackgroundColor.ToAndroid();
                            paint.SetStyle(style);
                            paint.Color = color;
                        }

                        canvas.DrawPath(path, paint);
                    }
        }
Пример #15
0
            void DrawOutline(ACanvas canvas, Path path)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)
                        {
                            paint.StrokeWidth = 1;
                            paint.SetStyle(style);
                            paint.Color = _frame.OutlineColor.ToAndroid();

                            canvas.DrawPath(path, paint);
                        }
            }
Пример #16
0
            void DrawBackground(ACanvas canvas, Path path, bool pressed)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Fill)
                        {
                            global::Android.Graphics.Color color = _frame.InnerBackground.ToAndroid();

                            paint.SetStyle(style);
                            paint.Color = color;

                            canvas.DrawPath(path, paint);
                        }
            }
        void DrawBackground(ACanvas canvas, int width, int height, CornerRadius cornerRadius, bool pressed)
        {
            using (var paint = new Paint {
                AntiAlias = true
            })
                using (var path = new Path())
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Fill)
                            using (var rect = new RectF(0, 0, width, height))
                            {
                                float topLeft     = _convertToPixels(cornerRadius.TopLeft);
                                float topRight    = _convertToPixels(cornerRadius.TopRight);
                                float bottomRight = _convertToPixels(cornerRadius.BottomRight);
                                float bottomLeft  = _convertToPixels(cornerRadius.BottomLeft);

                                if (!_pancake.HasShadow)
                                {
                                    path.AddRoundRect(rect, new float[] { topLeft, topLeft, topRight, topRight, bottomRight, bottomRight, bottomLeft, bottomLeft }, direction);
                                }
                                else
                                {
                                    path.AddRoundRect(rect, new float[] { topLeft, topLeft, topLeft, topLeft, topLeft, topLeft, topLeft, topLeft }, direction);
                                }

                                if (_pancake.BackgroundGradientStartColor != default(Xamarin.Forms.Color) && _pancake.BackgroundGradientEndColor != default(Xamarin.Forms.Color))
                                {
                                    var angle = _pancake.BackgroundGradientAngle / 360.0;

                                    // Calculate the new positions based on angle between 0-360.
                                    var a = width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.75) / 2)), 2);
                                    var b = height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.0) / 2)), 2);
                                    var c = width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.25) / 2)), 2);
                                    var d = height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.5) / 2)), 2);

                                    var shader = new LinearGradient(width - (float)a, (float)b, width - (float)c, (float)d, _pancake.BackgroundGradientStartColor.ToAndroid(), _pancake.BackgroundGradientEndColor.ToAndroid(), Shader.TileMode.Clamp);
                                    paint.SetShader(shader);
                                }
                                else
                                {
                                    global::Android.Graphics.Color color = _pancake.BackgroundColor.ToAndroid();
                                    paint.SetStyle(style);
                                    paint.Color = color;
                                }

                                canvas.DrawPath(path, paint);
                            }
        }
Пример #18
0
        void DrawOutline(ACanvas canvas, int width, int height, float cornerRadius)
        {
            using (var paint = new Paint {
                AntiAlias = true
            })
                using (var path = new Path())
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)
                            using (var rect = new RectF(0, 0, width, height)) {
                                float rx = Forms.Context.ToPixels(cornerRadius);
                                float ry = Forms.Context.ToPixels(cornerRadius);
                                path.AddRoundRect(rect, rx, ry, direction);

                                paint.StrokeWidth = element.OutlineWidth;  //set outline stroke
                                paint.SetStyle(style);
                                paint.Color = element.OutlineColor.ToAndroid();
                                //paint.Color = Color.ParseColor("#A7AE22");//set outline color //_frame.OutlineColor.ToAndroid();
                                canvas.DrawPath(path, paint);
                            }
        }
Пример #19
0
        void DrawOutline(ACanvas canvas, int width, int height, float cornerRadius)
        {
            using (var paint = new Paint {
                AntiAlias = true
            })
                using (var path = new Path())
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)
                            using (var rect = new RectF(0, 0, width, height))
                            {
                                float rx = Forms.Context.ToPixels(cornerRadius);
                                float ry = Forms.Context.ToPixels(cornerRadius);
                                path.AddRoundRect(rect, rx, ry, direction);

                                paint.StrokeWidth = 2f;
                                paint.SetStyle(style);
                                paint.Color = Color.ParseColor("#4CAF50");
                                canvas.DrawPath(path, paint);
                            }
        }
Пример #20
0
            void DrawOutline(ACanvas canvas, int width, int height)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var path = new Path())
                        using (Path.Direction direction = Path.Direction.Cw)
                            using (Paint.Style style = Paint.Style.Stroke)
                                using (var rect = new RectF(0, 0, width, height)) {
                                    float rx = Forms.Context.ToPixels(_frame.CornerRadius);
                                    float ry = Forms.Context.ToPixels(_frame.CornerRadius);
                                    path.AddRoundRect(rect, rx, ry, direction);

                                    paint.StrokeWidth = Forms.Context.ToPixels(_frame.BorderWidth);
                                    paint.SetStyle(style);
                                    paint.Color = _frame.BorderColor.ToAndroid();

                                    canvas.DrawPath(path, paint);
                                }
            }
Пример #21
0
            void DrawBackground(ACanvas canvas, int width, int height, bool pressed)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var path = new Path())
                        using (Path.Direction direction = Path.Direction.Cw)
                            using (Paint.Style style = Paint.Style.Fill)
                                using (var rect = new RectF(0, 0, width, height)) {
                                    float rx = Forms.Context.ToPixels(_frame.CornerRadius);
                                    float ry = Forms.Context.ToPixels(_frame.CornerRadius);
                                    path.AddRoundRect(rect, rx, ry, direction);

                                    global::Android.Graphics.Color color = _frame.BackgroundColor.ToAndroid();

                                    paint.SetStyle(style);
                                    paint.Color = color;

                                    canvas.DrawPath(path, paint);
                                }
            }
Пример #22
0
            void DrawRect(ACanvas canvas, int width, int height, float cornerRadius, float strokeWidth, Android.Graphics.Color color, Paint.Style style)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var path = new Path())
                        using (Path.Direction direction = Path.Direction.Cw)
                            using (style)
                                using (var rect = new RectF(0, 0, width, height))
                                {
                                    cornerRadius -= strokeWidth / 2;

                                    float rx = Forms.Context.ToPixels(cornerRadius);
                                    float ry = Forms.Context.ToPixels(cornerRadius);
                                    path.AddRoundRect(rect, rx, ry, direction);

                                    paint.StrokeWidth = strokeWidth;
                                    paint.SetStyle(style);
                                    paint.Color = color;

                                    canvas.DrawPath(path, paint);
                                }
            }
        private void DrawBorder(ACanvas canvas, PancakeView pancake)
        {
            if (pancake.Border != null && pancake.Border.Thickness != default)
            {
                var  borderThickness      = Context.ToPixels(pancake.Border.Thickness);
                var  halfBorderThickness  = borderThickness / 2;
                bool hasShadowOrElevation = pancake.Shadow != null && Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop;

                // TODO: This doesn't look entirely right yet when using it with rounded corners.
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)
                            using (var rect = new RectF(pancake.Border.DrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? -halfBorderThickness : halfBorderThickness,
                                                        pancake.Border.DrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? -halfBorderThickness : halfBorderThickness,
                                                        pancake.Border.DrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? canvas.Width + halfBorderThickness : canvas.Width - halfBorderThickness,
                                                        pancake.Border.DrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? canvas.Height + halfBorderThickness : canvas.Height - halfBorderThickness))
                            {
                                Path path = null;
                                if (pancake.Sides != 4)
                                {
                                    path = DrawingExtensions.CreatePolygonPath(Width, Height, pancake.Sides, pancake.CornerRadius.TopLeft, pancake.OffsetAngle);
                                }
                                else

                                {
                                    path = DrawingExtensions.CreateRoundedRectPath(Width, Height,
                                                                                   Context.ToPixels(pancake.CornerRadius.TopLeft),
                                                                                   Context.ToPixels(pancake.CornerRadius.TopRight),
                                                                                   Context.ToPixels(pancake.CornerRadius.BottomRight),
                                                                                   Context.ToPixels(pancake.CornerRadius.BottomLeft));
                                }

                                if (pancake.Border.DashPattern.Pattern != null && pancake.Border.DashPattern.Pattern.Length > 0)
                                {
                                    var items = pancake.Border.DashPattern.Pattern.Select(x => Context.ToPixels(Convert.ToSingle(x))).ToArray();

                                    // dashes merge when thickness is increased
                                    // off-distance should be scaled according to thickness
                                    for (int i = 0; i < items.Count(); i++)
                                    {
                                        if (i % 2 != 0)
                                        {
                                            items[i] = items[i] * ((float)pancake.Border.Thickness * 0.5f);
                                        }
                                    }

                                    paint.SetPathEffect(new DashPathEffect(items, 0));
                                }

                                if (pancake.Border.GradientStops != null && pancake.Border.GradientStops.Any())
                                {
                                    // A range of colors is given. Let's add them.
                                    var orderedStops = pancake.Border.GradientStops.OrderBy(x => x.Offset).ToList();
                                    var colors       = orderedStops.Select(x => x.Color.ToAndroid().ToArgb()).ToArray();
                                    var locations    = orderedStops.Select(x => x.Offset).ToArray();

                                    var shader = new LinearGradient((float)(canvas.Width * pancake.Border.GradientStartPoint.X),
                                                                    (float)(canvas.Height * pancake.Border.GradientStartPoint.Y),
                                                                    (float)(canvas.Width * pancake.Border.GradientEndPoint.X),
                                                                    (float)(canvas.Height * pancake.Border.GradientEndPoint.Y),
                                                                    colors, locations, Shader.TileMode.Clamp);
                                    paint.SetShader(shader);
                                }
                                else
                                {
                                    paint.Color = pancake.Border.Color.ToAndroid();
                                }

                                paint.StrokeCap   = Paint.Cap.Square;
                                paint.StrokeWidth = borderThickness;
                                paint.SetStyle(style);

                                canvas.DrawPath(path, paint);
                            }
            }
        }
Пример #24
0
        void DrawBackground(ACanvas canvas, int width, int height, CornerRadius cornerRadius, bool pressed)
        {
            using (var paint = new Paint {
                AntiAlias = true
            })
                using (Path.Direction direction = Path.Direction.Cw)
                    using (Paint.Style style = Paint.Style.Fill)
                    {
                        var path = new Path();

                        if (_pancake.Sides != 4)
                        {
                            path = ShapeUtils.CreatePolygonPath(width, height, _pancake.Sides, _pancake.CornerRadius.TopLeft, _pancake.OffsetAngle);
                        }
                        else
                        {
                            float topLeft     = _convertToPixels(cornerRadius.TopLeft);
                            float topRight    = _convertToPixels(cornerRadius.TopRight);
                            float bottomRight = _convertToPixels(cornerRadius.BottomRight);
                            float bottomLeft  = _convertToPixels(cornerRadius.BottomLeft);

                            path = ShapeUtils.CreateRoundedRectPath(width, height, topLeft, topRight, bottomRight, bottomLeft);
                        }

                        if ((_pancake.BackgroundGradientStartColor != default(Xamarin.Forms.Color) && _pancake.BackgroundGradientEndColor != default(Xamarin.Forms.Color)) || (_pancake.BackgroundGradientStops != null && _pancake.BackgroundGradientStops.Any()))
                        {
                            var angle = _pancake.BackgroundGradientAngle / 360.0;

                            // Calculate the new positions based on angle between 0-360.
                            var a = width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.75) / 2)), 2);
                            var b = height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.0) / 2)), 2);
                            var c = width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.25) / 2)), 2);
                            var d = height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.5) / 2)), 2);

                            if (_pancake.BackgroundGradientStops != null && _pancake.BackgroundGradientStops.Count > 0)
                            {
                                // A range of colors is given. Let's add them.
                                var orderedStops = _pancake.BackgroundGradientStops.OrderBy(x => x.Offset).ToList();
                                var colors       = orderedStops.Select(x => x.Color.ToAndroid().ToArgb()).ToArray();
                                var locations    = orderedStops.Select(x => x.Offset).ToArray();

                                var shader = new LinearGradient(width - (float)a, (float)b, width - (float)c, (float)d, colors, locations, Shader.TileMode.Clamp);
                                paint.SetShader(shader);
                            }
                            else
                            {
                                // Only two colors provided, use that.
                                var shader = new LinearGradient(width - (float)a, (float)b, width - (float)c, (float)d, _pancake.BackgroundGradientStartColor.ToAndroid(), _pancake.BackgroundGradientEndColor.ToAndroid(), Shader.TileMode.Clamp);
                                paint.SetShader(shader);
                            }
                        }
                        else
                        {
                            global::Android.Graphics.Color color = _pancake.BackgroundColor.ToAndroid();
                            paint.SetStyle(style);
                            paint.Color = color;
                        }

                        canvas.DrawPath(path, paint);
                    }
        }
        private void DrawBorder(ACanvas canvas, PancakeView control)
        {
            var  borderThickness      = Context.ToPixels(control.BorderThickness);
            var  halfBorderThickness  = borderThickness / 2;
            bool hasShadowOrElevation = control.HasShadow || control.Elevation > 0;

            // TODO: This doesn't look entirely right yet when using it with rounded corners.
            using (var paint = new Paint {
                AntiAlias = true
            })
                using (var path = new Path())
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)

                            using (var rect = new RectF(control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? -halfBorderThickness : halfBorderThickness,
                                                        control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? -halfBorderThickness : halfBorderThickness,
                                                        control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? canvas.Width + halfBorderThickness : canvas.Width - halfBorderThickness,
                                                        control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? canvas.Height + halfBorderThickness : canvas.Height - halfBorderThickness))
                            {
                                path.AddRoundRect(rect, GetRadii(control), direction);

                                if (control.BorderIsDashed)
                                {
                                    paint.SetPathEffect(new DashPathEffect(new float[] { 10, 20 }, 0));
                                }

                                if ((control.BorderGradientStartColor != default(Color) && control.BorderGradientEndColor != default(Color)) || (control.BorderGradientStops != null && control.BorderGradientStops.Any()))
                                {
                                    var angle = control.BorderGradientAngle / 360.0;

                                    // Calculate the new positions based on angle between 0-360.
                                    var a = canvas.Width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.75) / 2)), 2);
                                    var b = canvas.Height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.0) / 2)), 2);
                                    var c = canvas.Width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.25) / 2)), 2);
                                    var d = canvas.Height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.5) / 2)), 2);

                                    if (control.BorderGradientStops != null)
                                    {
                                        // A range of colors is given. Let's add them.
                                        var orderedStops = control.BorderGradientStops.OrderBy(x => x.Offset).ToList();
                                        var colors       = orderedStops.Select(x => x.Color.ToAndroid().ToArgb()).ToArray();
                                        var locations    = orderedStops.Select(x => x.Offset).ToArray();

                                        var shader = new LinearGradient(canvas.Width - (float)a, (float)b, canvas.Width - (float)c, (float)d, colors, locations, Shader.TileMode.Clamp);
                                        paint.SetShader(shader);
                                    }
                                    else
                                    {
                                        // Only two colors provided, use that.
                                        var shader = new LinearGradient(canvas.Width - (float)a, (float)b, canvas.Width - (float)c, (float)d, control.BorderGradientStartColor.ToAndroid(), control.BorderGradientEndColor.ToAndroid(), Shader.TileMode.Clamp);
                                        paint.SetShader(shader);
                                    }
                                }
                                else
                                {
                                    paint.Color = control.BorderColor.ToAndroid();
                                }

                                paint.StrokeCap   = Paint.Cap.Square;
                                paint.StrokeWidth = borderThickness;
                                paint.SetStyle(style);

                                canvas.DrawPath(path, paint);
                            }
        }
Пример #26
0
        private void DrawBorder(ACanvas canvas, PancakeView control)
        {
            if (control.BorderThickness > 0)
            {
                var  borderThickness      = Context.ToPixels(control.BorderThickness);
                var  halfBorderThickness  = borderThickness / 2;
                bool hasShadowOrElevation = control.HasShadow || (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop && control.Elevation > 0);

                // TODO: This doesn't look entirely right yet when using it with rounded corners.
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)
                            using (var rect = new RectF(control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? -halfBorderThickness : halfBorderThickness,
                                                        control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? -halfBorderThickness : halfBorderThickness,
                                                        control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? canvas.Width + halfBorderThickness : canvas.Width - halfBorderThickness,
                                                        control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? canvas.Height + halfBorderThickness : canvas.Height - halfBorderThickness))
                            {
                                Path path = null;
                                if (control.Sides != 4)
                                {
                                    path = ShapeUtils.CreatePolygonPath(Width, Height, control.Sides, control.CornerRadius.TopLeft, control.OffsetAngle);
                                }
                                else
                                {
                                    path = ShapeUtils.CreateRoundedRectPath(Width, Height,
                                                                            Context.ToPixels(control.CornerRadius.TopLeft),
                                                                            Context.ToPixels(control.CornerRadius.TopRight),
                                                                            Context.ToPixels(control.CornerRadius.BottomRight),
                                                                            Context.ToPixels(control.CornerRadius.BottomLeft));
                                }

                                if (control.BorderIsDashed)
                                {
                                    // dashes merge when thickness is increased
                                    // off-distance should be scaled according to thickness
                                    paint.SetPathEffect(new DashPathEffect(new float[] { 10, 5 * control.BorderThickness }, 0));
                                }

                                if ((control.BorderGradientStartColor != default(Color) && control.BorderGradientEndColor != default(Color)) || (control.BorderGradientStops != null && control.BorderGradientStops.Any()))
                                {
                                    var angle = control.BorderGradientAngle / 360.0;

                                    // Calculate the new positions based on angle between 0-360.
                                    var a = canvas.Width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.75) / 2)), 2);
                                    var b = canvas.Height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.0) / 2)), 2);
                                    var c = canvas.Width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.25) / 2)), 2);
                                    var d = canvas.Height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.5) / 2)), 2);

                                    if (control.BorderGradientStops != null && control.BorderGradientStops.Count > 0)
                                    {
                                        // A range of colors is given. Let's add them.
                                        var orderedStops = control.BorderGradientStops.OrderBy(x => x.Offset).ToList();
                                        var colors       = orderedStops.Select(x => x.Color.ToAndroid().ToArgb()).ToArray();
                                        var locations    = orderedStops.Select(x => x.Offset).ToArray();

                                        var shader = new LinearGradient(canvas.Width - (float)a, (float)b, canvas.Width - (float)c, (float)d, colors, locations, Shader.TileMode.Clamp);
                                        paint.SetShader(shader);
                                    }
                                    else
                                    {
                                        // Only two colors provided, use that.
                                        var shader = new LinearGradient(canvas.Width - (float)a, (float)b, canvas.Width - (float)c, (float)d, control.BorderGradientStartColor.ToAndroid(), control.BorderGradientEndColor.ToAndroid(), Shader.TileMode.Clamp);
                                        paint.SetShader(shader);
                                    }
                                }
                                else
                                {
                                    paint.Color = control.BorderColor.ToAndroid();
                                }

                                paint.StrokeCap   = Paint.Cap.Square;
                                paint.StrokeWidth = borderThickness;
                                paint.SetStyle(style);

                                canvas.DrawPath(path, paint);
                            }
            }
        }