Пример #1
0
        private void DrawSolidCircle(Canvas canvas, int i, int iterations, Paint p)
        {
            p.SetStyle(Paint.Style.FillAndStroke);
            var radius = ShadowHelpers.GetOldWidth(canvas.Width, (int)_densityOffsetX, _iterations) / 2 - (i - iterations);

            DrawCircle(canvas, p, radius);
        }
Пример #2
0
        private void DrawShadowsOutsideBackground(Canvas canvas, Paint p, int iterations)
        {
            for (int i = 0; i < iterations; i++)
            {
                p.Color = _colors[i];
                var radius = ShadowHelpers.GetOldWidth(canvas.Width, (int)_densityOffsetX, _iterations) / 2 + i;

                DrawCircle(canvas, p, radius);
            }
        }
        public override void Draw(Canvas canvas)
        {
            var center   = GetCanvasCenter(canvas);
            var oldWidth = ShadowHelpers.GetOldWidth(canvas.Width, (int)_densityOffsetX, _iterations) / 2;
            var radius   = oldWidth + _iterations - 1;

            CreateAndSetShader(canvas, center, oldWidth, radius);
            _paint.Alpha     = _drawableAlpha;
            _paint.AntiAlias = true;
            canvas.DrawCircle(center.X, center.Y, radius, _paint);
        }
Пример #4
0
        private void DrawShadowsBehindBackground(Canvas canvas, Paint p, int iterations)
        {
            var pivotParameter = GetPivotParameter(canvas);

            for (int i = iterations + 1; i < pivotParameter / 2; i++)
            {
                //'Inside' shadow will be with negative index
                p.Color = GetColorValue((i - iterations) * -1);
                //If Alpha = 255 for 'inside' shadow, then we can draw solid circle and break the loop
                if (p.Color == _config.Color)
                {
                    DrawSolidCircle(canvas, i, iterations, p);
                    break;
                }

                var radius = ShadowHelpers.GetOldWidth(canvas.Width, (int)_densityOffsetX, _iterations) / 2 - (i - iterations);
                DrawCircle(canvas, p, radius);
            }
        }
        public UpdatedCircleShadowDrawable(ShadowConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            //Stroke width sgould be device density, to avoid broken pixels
            //_paint.StrokeWidth = 1f;//(float)(Math.Round(Application.Context.Resources.DisplayMetrics.Density));

            _circleShadowState = new UpdatedCircleShadowState(config);
            _config            = config;
            _iterations        = (int)Helpers.DpToPx(_config.Blur);
            _densityOffsetX    = Helpers.DpToPx(_config.Offset.X);
            //Wrong implementation for y offset should be inverted
            //TODO need to fix
            _densityOffsetY  = Helpers.DpToPx(_config.Offset.Y) * -1;
            _offsetWithBlurX = ShadowHelpers.GetOffsetWithBlur((int)_densityOffsetX, _iterations);
            _offsetWithBlurY = ShadowHelpers.GetOffsetWithBlur((int)_densityOffsetY, _iterations);
        }
Пример #6
0
        //Get center point for drawing shadow circle,
        //Take into account offset, blur, view translations, etc.
        private PointF GetCanvasCenter(Canvas canvas)
        {
            float x = 0;
            float y = 0;

            if (_densityOffsetX > 0)
            {
                if (_offsetWithBlurX == 0)
                {
                    x = GetPivotParameter(canvas) / 2 + _offsetWithBlurX;
                }
                else
                {
                    x = ShadowHelpers.GetOldWidth(canvas.Width, (int)_densityOffsetX, _iterations) / 2 + _densityOffsetX;
                }
            }
            else
            {
                //shouldnt move anything because view itself already moved
                //just draw on the center
                x = ((float)GetPivotParameter(canvas) / 2);
            }
            if (_densityOffsetY > 0)
            {
                y = ((float)GetPivotParameter(canvas) / 2) - _offsetWithBlurY;
            }
            else
            {
                if (_offsetWithBlurY == 0)
                {
                    y = ((float)GetPivotParameter(canvas) / 2);// + _densityOffsetY * -1;
                }
                else
                {
                    y = ShadowHelpers.GetOldWidth(canvas.Height, (int)_densityOffsetY, _iterations) / 2 - _densityOffsetY;
                }
            }
            return(new PointF(x, y));
        }