Exemple #1
0
        protected override void InternalDraw(SKCanvas canvas)
        {
            base.InternalDraw(canvas);

            if (Drawable != null)
            {
                var renderBounds = RenderBounds;
                var drawableSize = Drawable.GetSize(renderBounds.Width, renderBounds.Height);

                double ratioX = (double)renderBounds.Width / (double)drawableSize.Width;
                double ratioY = (double)renderBounds.Height / (double)drawableSize.Height;
                double ratio  = ratioX < ratioY ? ratioX : ratioY;

                double newWidth  = drawableSize.Width * ratio;
                double newHeight = drawableSize.Height * ratio;

                float cx = (float)(renderBounds.X + (renderBounds.Width / 2.0) - (newWidth / 2.0));
                float cy = (float)(renderBounds.Y + (renderBounds.Height / 2.0) - (newHeight / 2.0));

                using (var paint = new SKPaint())
                {
                    paint.XferMode      = SKXferMode.SrcOver;
                    paint.FilterQuality = SKFilterQuality.Low;
                    Drawable.Draw(canvas, new Rectangle(cx, cy, newWidth, newHeight), paint);
                }
            }
        }
Exemple #2
0
        protected override void InternalDraw(SkiaSharp.SKCanvas canvas)
        {
            base.InternalDraw(canvas);

            using (var paint = new SKPaint())
            {
                var renderBounds = RenderBounds;

                var smallestSize = Math.Min(renderBounds.Size.Width, renderBounds.Size.Height);
                var square       = new Rectangle(renderBounds.Center.X - smallestSize / 2.0, renderBounds.Center.Y - smallestSize / 2.0, smallestSize, smallestSize);

                Rectangle imageBounds = renderBounds;

                paint.IsAntialias = true;

                if (IsCheckable)
                {
                    paint.Color = SelectionBackgroundColor.ToSKColor();
                    canvas.DrawOval(square.ToSKRect(), paint);

                    var darkerOutline = SelectionBackgroundColor.AddLuminosity(-0.1);
                    paint.IsStroke    = true;
                    paint.Color       = darkerOutline.ToSKColor();
                    paint.StrokeWidth = 1.0f;

                    canvas.DrawOval(square.ToSKRect(), paint);

                    imageBounds = renderBounds.Inflate(-BorderSize, -BorderSize);
                }

                if (Drawable != null && !IsSelected)
                {
                    var drawableSize = Drawable.GetSize(imageBounds.Width, imageBounds.Height);

                    double ratioX = (double)imageBounds.Width / (double)drawableSize.Width;
                    double ratioY = (double)imageBounds.Height / (double)drawableSize.Height;
                    double ratio  = ratioX < ratioY ? ratioX : ratioY;

                    double newWidth  = drawableSize.Width * ratio;
                    double newHeight = drawableSize.Height * ratio;

                    float cx = (float)(imageBounds.X + (imageBounds.Width / 2.0) - (newWidth / 2.0));
                    float cy = (float)(imageBounds.Y + (imageBounds.Height / 2.0) - (newHeight / 2.0));

                    paint.XferMode      = SKXferMode.SrcOver;
                    paint.FilterQuality = SKFilterQuality.Low;
                    Drawable.Draw(canvas, new Rectangle(cx, cy, newWidth, newHeight), paint);
                }

                if (IsCheckable && IsSelected)
                {
                    paint.Color    = SelectionColor.ToSKColor();
                    paint.IsStroke = false;
                    canvas.DrawOval(square.ToSKRect(), paint);

                    double ratioX = (double)imageBounds.Width / (double)TickBitmap.Width;
                    double ratioY = (double)imageBounds.Height / (double)TickBitmap.Height;
                    double ratio  = ratioX < ratioY ? ratioX : ratioY;

                    double newWidth  = TickBitmap.Width * ratio;
                    double newHeight = TickBitmap.Height * ratio;

                    float cx = (float)(imageBounds.X + (imageBounds.Width / 2.0) - (newWidth / 2.0));
                    float cy = (float)(imageBounds.Y + (imageBounds.Height / 2.0) - (newHeight / 2.0));

                    paint.XferMode      = SKXferMode.SrcOver;
                    paint.FilterQuality = SKFilterQuality.Low;
                    canvas.DrawBitmap(TickBitmap, new SKRect(cx, cy, (float)(cx + newWidth), (float)(cy + newHeight)), paint);
                }
            }
        }