コード例 #1
0
        private void OnCanvasViewOnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            var info    = e.Info;
            var surface = e.Surface;
            var canvas  = surface.Canvas;

            canvas.Clear();

            if (Gradients != null && Gradients.Any())
            {
                _fillPaint.Shader = GetGradient(info, Gradients, GradientOrientation);
            }
            else
            {
                _fillPaint.Color = Color.ToSKColor();
            }

            var radius = (float)(info.Width >= info.Height ? info.Height : info.Width) / 2;

            if (IsOnlyBorder)
            {
                radius                 = radius - ConvertToDeviceScaleFactor(BorderWidth);
                _fillPaint.Style       = SKPaintStyle.Stroke;
                _fillPaint.StrokeWidth = CalculateScaled.Size(BorderWidth);
            }

            canvas.DrawCircle((float)info.Width / 2, (float)info.Height / 2, radius, _fillPaint);
        }
コード例 #2
0
        private void OnCanvasViewOnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            var info    = e.Info;
            var surface = e.Surface;
            var canvas  = surface.Canvas;

            canvas.Clear();

            if (Gradients != null && Gradients.Any())
            {
                _fillPaint.Shader = GetGradient(info, Gradients, GradientOrientation);
            }
            else
            {
                _fillPaint.Color = Color.ToSKColor();
            }

            var topRadius         = ConvertToDeviceScaleFactor(CornerRadius.Left);
            var bottomRightRadius = ConvertToDeviceScaleFactor(CornerRadius.Top);
            var bottomLeftRadius  = ConvertToDeviceScaleFactor(CornerRadius.Right);

            var top         = new SKPoint((float)info.Width / 2, 0);
            var bottomRight = new SKPoint(info.Width, info.Height);
            var bottomLeft  = new SKPoint(0, info.Height);

            using (var path = new SKPath())
            {
                path.MoveTo(bottomLeft);
                path.ArcTo(top, bottomRight, topRadius);
                path.ArcTo(bottomRight, bottomLeft, bottomRightRadius);
                path.ArcTo(bottomLeft, top, bottomLeftRadius);
                path.Close();

                canvas.DrawPath(path, _fillPaint);
            }
        }
コード例 #3
0
ファイル: Button.cs プロジェクト: dariodotnet/SkiaControls
        protected virtual void OnCanvasViewOnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            var info    = e.Info;
            var surface = e.Surface;
            var canvas  = surface.Canvas;

            canvas.Clear();

            if (Gradients != null && Gradients.Any())
            {
                _fillPaint.Shader = GetGradient(info, Gradients, GradientOrientation);
            }
            else
            {
                _fillPaint.Color = Color.ToSKColor();
            }

            var topLeftRadius     = ConvertToDeviceScaleFactor(CornerRadius.Left);
            var topRightRadius    = ConvertToDeviceScaleFactor(CornerRadius.Top);
            var bottomRightRadius = ConvertToDeviceScaleFactor(CornerRadius.Right);
            var bottomLeftRadius  = ConvertToDeviceScaleFactor(CornerRadius.Bottom);

            var topLeft     = new SKPoint(0, 0);
            var topRight    = new SKPoint(info.Width, 0);
            var bottomRight = new SKPoint(info.Width, info.Height);
            var bottomLeft  = new SKPoint(0, info.Height);

            using (var path = new SKPath())
            {
                path.MoveTo(bottomLeft);
                path.ArcTo(topLeft, topRight, topLeftRadius);
                path.ArcTo(topRight, bottomRight, topRightRadius);
                path.ArcTo(bottomRight, bottomLeft, bottomRightRadius);
                path.ArcTo(bottomLeft, topLeft, bottomLeftRadius);
                path.Close();

                canvas.ClipPath(path);

                if (IsOnlyBorder)
                {
                    var border = ConvertToDeviceScaleFactor(BorderWidth) * 2;

                    var scalaX = (info.Width - border) / info.Width;
                    var scalaY = (info.Height - border) / info.Height;

                    canvas.Translate(ConvertToDeviceScaleFactor(BorderWidth), ConvertToDeviceScaleFactor(BorderWidth));

                    canvas.Scale(scalaX, scalaY);

                    using (var center = new SKPath())
                    {
                        center.MoveTo(bottomLeft);
                        center.ArcTo(topLeft, topRight, topLeftRadius);
                        center.ArcTo(topRight, bottomRight, topRightRadius);
                        center.ArcTo(bottomRight, bottomLeft, bottomRightRadius);
                        center.ArcTo(bottomLeft, topLeft, bottomLeftRadius);
                        center.Close();

                        canvas.ClipPath(center, SKClipOperation.Difference);
                    }
                }
            }

            canvas.DrawPaint(_fillPaint);
        }