Beispiel #1
0
        /// <summary>
        /// Calculates the size.
        /// </summary>
        /// <returns>The size.</returns>
        /// <param name="size">Size.</param>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        public static SKSize CalcSize(SkiaSharp.SKSize size, double width, double height)
        {
            double w;
            double h;

            if (width <= 0 && height <= 0)
            {
                return(size);
            }
            else if (width <= 0)
            {
                h = height;
                w = height * (size.Width / size.Height);
            }
            else if (height <= 0)
            {
                w = width;
                h = width * (size.Height / size.Width);
            }
            else
            {
                w = width;
                h = height;
            }

            return(new SkiaSharp.SKSize((float)w, (float)h));
        }
Beispiel #2
0
        /// <summary>
        /// Calculates the scale.
        /// </summary>
        /// <returns>The scale.</returns>
        /// <param name="originalSize">Original size.</param>
        /// <param name="scaledSize">Scaled size.</param>
        /// <param name="screenScale">Screen scale.</param>
        public static Tuple <float, float> CalcScale(SkiaSharp.SKSize originalSize, SkiaSharp.SKSize scaledSize, float screenScale)
        {
            var sx = scaledSize.Width * screenScale / originalSize.Width;
            var sy = scaledSize.Height * screenScale / originalSize.Height;

            return(new Tuple <float, float>((float)sx, (float)sy));
        }
Beispiel #3
0
 public void Inflate(SKSize size)
 {
     Inflate(size.Width, size.Height);
 }
Beispiel #4
0
        private SKRect AspectResize(SKSize size, bool fit)
        {
            if (size.Width == 0 || size.Height == 0 || Width == 0 || Height == 0)
                return SKRect.Create(MidX, MidY, 0, 0);

            float aspectWidth = size.Width;
            float aspectHeight = size.Height;
            float imgAspect = aspectWidth / aspectHeight;
            float fullRectAspect = Width / Height;

            bool compare = fit ? (fullRectAspect > imgAspect) : (fullRectAspect < imgAspect);
            if (compare)
            {
                aspectHeight = Height;
                aspectWidth = aspectHeight * imgAspect;
            }
            else
            {
                aspectWidth = Width;
                aspectHeight = aspectWidth / imgAspect;
            }
            float aspectLeft = MidX - (aspectWidth / 2f);
            float aspectTop = MidY - (aspectHeight / 2f);

            return SKRect.Create(aspectLeft, aspectTop, aspectWidth, aspectHeight);
        }
Beispiel #5
0
 public SKRect AspectFill(SKSize size) => AspectResize(size, false);
Beispiel #6
0
 public SKRect AspectFit(SKSize size) => AspectResize(size, true);
Beispiel #7
0
 public static SKSize Subtract(SKSize sz1, SKSize sz2) => sz1 - sz2;
Beispiel #8
0
 public static SKSize Add(SKSize sz1, SKSize sz2) => sz1 + sz2;
Beispiel #9
0
 public void Inflate(SKSize size)
 {
     Inflate(size.Width, size.Height);
 }
Beispiel #10
0
 public static SKPoint Add(SKPoint pt, SKSize sz) => pt + sz;
Beispiel #11
0
 public void DrawOval(SKPoint c, SKSize r, SKPaint paint)
 {
     DrawOval(c.X, c.Y, r.Width, r.Height, paint);
 }
Beispiel #12
0
 public void DrawRoundRect(SKRect rect, SKSize r, SKPaint paint)
 {
     DrawRoundRect(rect, r.Width, r.Height, paint);
 }
Beispiel #13
0
 public SKSvg(float pixelsPerInch, SKSize canvasSize)
     : base(pixelsPerInch, canvasSize)
 {
 }
Beispiel #14
0
 public SKSvg(SKSize canvasSize)
     : base(canvasSize)
 {
 }
Beispiel #15
0
 public static SKRect Create(SKPoint location, SKSize size)
 {
     return SKRect.Create(location.X, location.Y, size.Width, size.Height);
 }
Beispiel #16
0
 public static SKPoint Subtract(SKPoint pt, SKSize sz) => pt - sz;
Beispiel #17
0
 public static SKRect Create(SKSize size)
 {
     return SKRect.Create(SKPoint.Empty, size);
 }
Beispiel #18
0
 public void Deflate(SKSize size)
 {
     Deflate(size.Width, size.Height);
 }