示例#1
0
        void makeInnerShadow(SKImageInfo info, SKCanvas canvas, TypeShadow typeShadow, float x, float y, Color color, Color backgroundColor)
        {
            SKPaint skPaint = new SKPaint()
            {
                Style       = SKPaintStyle.Stroke,
                Color       = color.ToSKColor().WithAlpha((byte)(0xFF * OpacityShadow)),
                StrokeWidth = SizeStroker,
                IsAntialias = true,
                ImageFilter = SKImageFilter.CreateDropShadow(
                    x,
                    y,
                    SizeStroker,
                    SizeStroker,
                    color.ToSKColor().WithAlpha((byte)(0xFF * OpacityShadow)),
                    SKDropShadowImageFilterShadowMode.DrawShadowAndForeground)
            };

            SKRect skRectangle = new SKRect();

            if (!ShowOut)
            {
                skRectangle.Size     = new SKSize(info.Width, info.Height);
                skRectangle.Location = new SKPoint(0, 0);
            }
            else
            {
                skRectangle.Size     = new SKSize(info.Width - (SizeShadow * 2), info.Height - (SizeShadow * 2));
                skRectangle.Location = new SKPoint(SizeShadow, SizeShadow);
            }



            skRectangle.Inflate(SizeStroker, SizeStroker);
            canvas.DrawRoundRect(skRectangle, BorderRadius, BorderRadius, skPaint);
        }
示例#2
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            using (SKPaint textPaint = new SKPaint
            {
                Style = SKPaintStyle.Stroke,
                Color = SKColors.Blue,
                StrokeWidth = 0.1f,
                StrokeJoin = SKStrokeJoin.Round
            })
            {
                SKRect textBounds = new SKRect();
                textPaint.MeasureText("HELLO", ref textBounds);

                // Inflate bounds by the stroke width
                textBounds.Inflate(textPaint.StrokeWidth / 2,
                                   textPaint.StrokeWidth / 2);

                canvas.Scale(info.Width / textBounds.Width,
                             info.Height / textBounds.Height);
                canvas.Translate(-textBounds.Left, -textBounds.Top);

                canvas.DrawText("HELLO", 0, 0, textPaint);
            }
        }
        public LinkedChainPage()
        {
            Title = "Linked Chain";

            SKCanvasView canvasView = new SKCanvasView();

            canvasView.PaintSurface += OnCanvasViewPaintSurface;
            Content = canvasView;

            // Create the path for the individual links
            SKRect outer = new SKRect(-linkRadius, -linkRadius, linkRadius, linkRadius);
            SKRect inner = outer;

            inner.Inflate(-linkThickness, -linkThickness);

            using (SKPath linkPath = new SKPath())
            {
                linkPath.AddArc(outer, 55, 160);
                linkPath.ArcTo(inner, 215, -160, false);
                linkPath.Close();

                linkPath.AddArc(outer, 235, 160);
                linkPath.ArcTo(inner, 395, -160, false);
                linkPath.Close();

                // Set that path as the 1D path effect for linksPaint
                linksPaint.PathEffect =
                    SKPathEffect.Create1DPath(linkPath, 1.3f * linkRadius, 0,
                                              SKPath1DPathEffectStyle.Rotate);
            }
        }
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            // Find largest square that fits
            float  rectSize = Math.Min(info.Width, info.Height);
            float  x        = (info.Width - rectSize) / 2;
            float  y        = (info.Height - rectSize) / 2;
            SKRect rect     = new SKRect(x, y, x + rectSize, y + rectSize);

            // Draw destination bitmap
            canvas.DrawBitmap(dstBitmap, rect);

            // Draw source bitmap
            using (SKPaint paint = new SKPaint())
            {
                paint.BlendMode = blendMode;
                canvas.DrawBitmap(srcBitmap, rect, paint);
            }

            // Draw outline
            using (SKPaint paint = new SKPaint())
            {
                paint.Style       = SKPaintStyle.Stroke;
                paint.Color       = SKColors.Black;
                paint.StrokeWidth = 2;
                rect.Inflate(-1, -1);
                canvas.DrawRect(rect, paint);
            }
        }
示例#5
0
        public SKRect InflateRect(SKRect rect, float n)
        {
            SKRect inflated = rect;

            inflated.Inflate(n, n);
            return(inflated);
        }
示例#6
0
        private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();
            string str = "Hello SkiaSharp!";
            // crea un SKPaint oggetto per visualizzare il testo
            SKPaint textPaint = new SKPaint
            {
                Color = SKColors.Chocolate
            };
            // regola la proprietà TextSize in modo che il testo sia 90% della larghezza dello schermo
            float textWidth = textPaint.MeasureText(str);

            textPaint.TextSize = 0.9f * info.Width * textPaint.TextSize / textWidth;
            // trovare i limiti del testo
            SKRect textBounds = new SKRect();

            textPaint.MeasureText(str, ref textBounds);
            // calcola gli offset per centrare il testo sullo schermo
            float xText = info.Width / 2 - textBounds.MidX;
            float yText = info.Height / 2 - textBounds.MidY;

            // e disegna il testo
            canvas.DrawText(str, xText, yText, textPaint);
            // crea un nuovo skRect oggetto per la cornice intorno al testo
            SKRect frameRect = textBounds;

            frameRect.Offset(xText, yText);
            frameRect.Inflate(10, 10);
            // crea un SKPaint oggetto per visualizzare il frame
            SKPaint framePaint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 5,
                Color       = SKColors.Blue
            };

            // disegna un frame
            canvas.DrawRoundRect(frameRect, 20, 20, framePaint);
            // gonfiare il frameRect e disegnarne un altro
            frameRect.Inflate(10, 10);
            framePaint.Color = SKColors.DarkBlue;
            canvas.DrawRoundRect(frameRect, 30, 30, framePaint);
        }
        private static void MeasureText(SKImageInfo info, SKCanvas canvas)
        {
            string str = "SkiaSharp Demo";

            SKRect textBounds = new SKRect();
            float  xText;
            float  yText;

            using (SKPaint textPaint = new SKPaint()
            {
                Color = SKColors.Chocolate
            })
            {
                float textWidth = textPaint.MeasureText(str);
                textPaint.TextSize = 0.9f * info.Width * textPaint.TextSize / textWidth;

                // Find the text bounds
                textPaint.MeasureText(str, ref textBounds);

                // Calculate offsets to center the text on the screen
                xText = info.Width / 2 - textBounds.MidX;
                yText = info.Height / 2 - textBounds.MidY;

                // And draw the text
                canvas.DrawText(str, xText, yText, textPaint);
            }


            using (SKPaint framePaint = new SKPaint()
            {
                Color = SKColors.Blue, StrokeWidth = 5, Style = SKPaintStyle.Stroke
            })
            {
                SKRect frameRect = textBounds;
                frameRect.Offset(xText, yText);
                frameRect.Inflate(10, 10);

                canvas.DrawRoundRect(frameRect, 20, 20, framePaint);

                // Inflate the frameRect and draw another
                frameRect.Inflate(10, 10);
                framePaint.Color = SKColors.DarkBlue;

                canvas.DrawRoundRect(frameRect, 30, 30, framePaint);
            }
        }
示例#8
0
        internal async Task CreateAnnotations(FishModel fish)
        {
            // create a bitmap
            SKBitmap bitmap = new SKBitmap(Width + 2 * Padding, Height + 2 * Padding);

            using (SKCanvas canvas = new SKCanvas(bitmap))
            {
                canvas.Clear();
                // draw a rounded rect
                SKRect outline = new SKRect(0, 0, bitmap.Width, bitmap.Height);
                outline.Inflate(-Padding, -Padding);
                canvas.DrawRoundRect(outline, Radius, Radius, annotationBackground);

                // draw a fish in the middle
                outline.Inflate(-Padding, -Padding);
                var fishImage = await BitmapHelper.LoadBitmapFromUrl(fish.Image);

                canvas.DrawBitmap(fishImage, outline);
            }
            OnscreenAnnotation = bitmap;
        }
示例#9
0
 public static void DrawRectAround(this SKCanvas canvas, SKRect rect, SKPaint paint, Extent <float>?offset = null)
 {
     if (offset is Extent <float> off)
     {
         rect.Left   -= off.Left;
         rect.Top    -= off.Top;
         rect.Right  += off.Right;
         rect.Bottom += off.Left;
     }
     rect.Inflate(paint.StrokeWidth / 2, paint.StrokeWidth / 2);
     canvas.DrawRect(rect, paint);
 }
示例#10
0
        private static SKRect MeasureRect(string text, SKPaint paint)
        {
            var rect = new SKRect();

            paint.MeasureText(text, ref rect);

            var padding = 3; // todo get this from LabelStyle

            rect = SKRect.Inflate(rect, padding, padding);
            //rect = SnapToPixel(rect);
            return(rect);
        }
示例#11
0
 protected override void DrawBackgroundRect(SKCanvas canvas, SKRect size)
 {
     if (_rules.IsDayOutOfSelectableRange(Date))
     {
         base.DrawBackgroundRect(canvas, size);
     }
     else
     {
         size.Inflate(-10, -10);
         canvas.DrawCircle(size.Location.X + (size.Width / 2),
                           size.Location.Y + (size.Height / 2),
                           size.Height / 2, BackgroundPaint);
     }
 }
示例#12
0
        internal async Task <SKBitmap> CreateBaseAnnotation(FishModel fish)
        {
            // create a bitmap
            SKBitmap bitmap = new SKBitmap(width + 2 * padding, height + 2 * padding);

            using (SKCanvas canvas = new SKCanvas(bitmap))
            {
                canvas.Clear();

                // draw a rounded rect
                SKRect outline = new SKRect(0, 0, bitmap.Width, bitmap.Height);
                outline.Inflate(-padding, -padding);
                canvas.DrawRoundRect(outline, radius, radius, annotationBackground);

                // draw a fish in the middle
                outline.Inflate(-padding, -padding);
                var fishImage = await BitmapHelper.LoadBitmapFromUrl(fish.Image);

                //canvas.DrawBitmap(fishImage, outline);
                canvas.DrawBitmap(fishImage, outline, BitmapStretch.AspectFit, BitmapAlignment.Center, BitmapAlignment.Center);
            }
            return(bitmap);
        }
示例#13
0
        public void RectangleInflatesCorrectly()
        {
            var rect = new SKRect(15, 25, 55, 75);

            Assert.AreEqual(15f, rect.Left);
            Assert.AreEqual(25f, rect.Top);
            Assert.AreEqual(55f, rect.Right);
            Assert.AreEqual(75f, rect.Bottom);

            rect.Inflate(10, 20);

            Assert.AreEqual(5f, rect.Left);
            Assert.AreEqual(5f, rect.Top);
            Assert.AreEqual(65f, rect.Right);
            Assert.AreEqual(95f, rect.Bottom);
        }
示例#14
0
        /// <summary>
        /// Gets the smallest square that would completely contain the given rectangle, with the rectangle positioned
        /// at its centre.
        /// </summary>
        /// <param name="rect">The rectangle to find the containing square for.</param>
        internal static SKRect GetEnclosingSquare(this SKRect rect)
        {
            // Inflate the smaller dimension
            if (rect.Width > rect.Height)
            {
                return(SKRect.Inflate(rect, x: 0, y: (rect.Width - rect.Height) / 2));
            }

            if (rect.Height > rect.Width)
            {
                return(SKRect.Inflate(rect, x: (rect.Height - rect.Width) / 2, y: 0));
            }

            // It was already a square, but we need to return a copy
            return(SKRect.Create(rect.Location, rect.Size));
        }
示例#15
0
        public void Blur(int radius)
        {
            using (var surface = SKSurface.Create(new SKImageInfo(Context.Image.Width, Context.Image.Height)))
            using (var canvas = surface.Canvas)
            using (var paint = new SKPaint())
            {
                paint.ImageFilter = SKImageFilter.CreateBlur(radius, radius);

                SKRect rect = new SKRect(0, 0, Context.Image.Width, Context.Image.Height);
                rect.Inflate(10, 10); //removes black border

                canvas.DrawBitmap(Context.Image, rect, paint);
                canvas.Flush();

                // save
                Context.Image = SKBitmap.FromImage(surface.Snapshot());
            }
        }
示例#16
0
        public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, IStyle style, ISymbolCache symbolCache)
        {
            var vectorTile = ((DrawableTile)feature.Geometry).Data;

            vectorTile.Context.Zoom = (float)viewport.Resolution.ToZoomLevel();

            var boundingBox = feature.Geometry.BoundingBox;

            if (viewport.IsRotated)
            {
                var priorMatrix = canvas.TotalMatrix;

                var matrix = CreateRotationMatrix(viewport, boundingBox, priorMatrix);
                // TODO
                canvas.SetMatrix(matrix);

                var destination = new BoundingBox(0.0, 0.0, boundingBox.Width, boundingBox.Height).ToSkia();

                canvas.DrawDrawable(vectorTile, destination.Left, destination.Top);
            }
            else
            {
                var destination = RoundToPixel(WorldToScreen(viewport, feature.Geometry.BoundingBox)).ToSkia();
                //var clipRect = vectorTile.Bounds;

                var scale = Math.Max(destination.Width, destination.Height) / vectorTile.Bounds.Width;
                vectorTile.Context.Scale = 1f / scale;

                //canvas.ClipRect(canvas.DeviceClipBounds);

                canvas.Translate(new SKPoint(destination.Left, destination.Top));
                canvas.Scale(scale, scale);
                canvas.ClipRect(new SKRect(0, 0, vectorTile.Bounds.Width, vectorTile.Bounds.Height));
                canvas.DrawDrawable(vectorTile, 0, 0);

                var frame = SKRect.Inflate(vectorTile.Bounds, (float)-vectorTile.Context.Zoom, (float)-vectorTile.Context.Zoom);
                canvas.DrawRect(frame, new SKPaint()
                {
                    Style = SKPaintStyle.Stroke, Color = new SKColor((byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256))
                });
            }

            return(true);
        }
示例#17
0
        protected override void OnDrawSample(SKCanvas canvas, int width, int height)
        {
            canvas.Clear(SKColors.White);

            using (var stream = new SKManagedStream(SampleMedia.Images.NinePatch))
                using (var bitmap = SKBitmap.Decode(stream))
                {
                    var patchCenter = new SKRectI(33, 33, 256 - 33, 256 - 33);

                    // 2x3 for portrait, or 3x2 for landscape
                    var land   = width > height;
                    var min    = land ? Math.Min(width / 3f, height / 2f) : Math.Min(width / 2f, height / 3f);
                    var wide   = SKRect.Inflate(SKRect.Create(0, land ? min : (min * 2f), min * 2f, min), -20, -20);
                    var tall   = SKRect.Inflate(SKRect.Create(land ? (min * 2f) : min, 0, min, min * 2f), -20, -20);
                    var square = SKRect.Inflate(SKRect.Create(0, 0, min, min), -20, -20);
                    var text   = SKRect.Create(land ? min : 0, land ? 0 : min, min, min / 5f);
                    text.Offset(text.Width / 2f, text.Height * 1.5f);
                    text.Right = text.Left;

                    // draw the bitmaps
                    canvas.DrawBitmapNinePatch(bitmap, patchCenter, square);
                    canvas.DrawBitmapNinePatch(bitmap, patchCenter, tall);
                    canvas.DrawBitmapNinePatch(bitmap, patchCenter, wide);

                    // describe what we see
                    using (var paint = new SKPaint())
                    {
                        paint.IsAntialias = true;
                        paint.TextAlign   = SKTextAlign.Center;
                        paint.TextSize    = text.Height * 0.75f;

                        canvas.DrawText("The corners", text.Left, text.Top, paint);
                        text.Offset(0, text.Height);
                        canvas.DrawText("should always", text.Left, text.Top, paint);
                        text.Offset(0, text.Height);
                        canvas.DrawText("be square", text.Left, text.Top, paint);
                    }
                }
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear(SKColors.Pink);

            // Get values from XAML controls
            SKBlurStyle blurStyle =
                (SKBlurStyle)(blurStylePicker.SelectedIndex == -1 ?
                              0 : blurStylePicker.SelectedItem);

            float sigma = (float)sigmaSlider.Value;

            using (SKPaint paint = new SKPaint())
            {
                // Set SKPaint properties
                paint.TextSize   = (info.Width - 100) / (TEXT.Length / 2);
                paint.MaskFilter = SKMaskFilter.CreateBlur(blurStyle, sigma);

                // Get text bounds and calculate display rectangle
                SKRect textBounds = new SKRect();
                paint.MeasureText(TEXT, ref textBounds);
                SKRect textRect = new SKRect(0, 0, info.Width, textBounds.Height + 50);

                // Center the text in the display rectangle
                float xText = textRect.Width / 2 - textBounds.MidX;
                float yText = textRect.Height / 2 - textBounds.MidY;

                canvas.DrawText(TEXT, xText, yText, paint);

                // Calculate rectangle for bitmap
                SKRect bitmapRect = new SKRect(0, textRect.Bottom, info.Width, info.Height);
                bitmapRect.Inflate(-50, -50);

                canvas.DrawBitmap(bitmap, bitmapRect, BitmapStretch.Uniform, paint: paint);
            }
        }
示例#19
0
        /// <summary>
        /// Paint checkbox
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaintSelectionElement(SKPaintSurfaceEventArgs e)
        {
            if (_checkMarkSvg == null && string.IsNullOrEmpty(CheckMarkIconAssemblyName) == false && string.IsNullOrEmpty(CheckMarkIconResourceKey) == false)
            {
                _checkMarkSvg = SvgImage.GetSvgImage(CheckMarkIconAssemblyName, CheckMarkIconResourceKey);
            }

            Rectangle checkBoxAvailableLocation = new Rectangle();
            Rectangle availableSpace            = new Rectangle(EllipseDiameter, EllipseDiameter, Width, Height - Padding.VerticalThickness);

            if (CheckBoxLocation == HorizontalLocations.Left)
            {
                checkBoxAvailableLocation = availableSpace;
            }
            else
            {
                checkBoxAvailableLocation = new Rectangle(availableSpace.Width - CheckBoxWidthRequest - CheckBoxMargin.HorizontalThickness + EllipseDiameter, EllipseDiameter, availableSpace.Width, availableSpace.Height);
            }

            Rectangle checkBoxActualLocation = CheckBoxActualLocation(checkBoxAvailableLocation);

            float skCheckBoxBorderThickness = (float)CheckBoxBorderThickness * DeviceScale;
            float skCheckBoxX      = (float)checkBoxActualLocation.X * DeviceScale;
            float skCheckBoxY      = (float)checkBoxActualLocation.Y * DeviceScale;
            float skCheckBoxWidth  = (float)CheckBoxWidthRequest * DeviceScale;
            float skCheckBoxHeight = (float)CheckBoxHeightRequest * DeviceScale;
            float skCornerRadius   = (float)CheckBoxCornerRadius * DeviceScale;

            SKMatrix checkMarkMatrix   = new SKMatrix();
            SKPoint  checkMarkPosition = new SKPoint();

            Size checkMarkIconSize = new Size(CheckBoxWidthRequest - CheckMarkIconMargin.HorizontalThickness, CheckBoxHeightRequest - CheckMarkIconMargin.VerticalThickness);

            float scale = SvgImage.CalculateScale(_checkMarkSvg.Picture.CullRect.Size, checkMarkIconSize.Width, checkMarkIconSize.Height);

            Size actualCheckMarkIconSize = new Size(_checkMarkSvg.Picture.CullRect.Width * scale, _checkMarkSvg.Picture.CullRect.Height * scale);

            scale = scale * DeviceScale;

            checkMarkPosition.X = (float)skCheckBoxX + (float)((CheckBoxWidthRequest - actualCheckMarkIconSize.Width) / 2) * DeviceScale;
            checkMarkPosition.Y = (float)skCheckBoxY + (float)((CheckBoxHeightRequest - actualCheckMarkIconSize.Height) / 2) * DeviceScale;
            checkMarkMatrix.SetScaleTranslate(scale, scale, checkMarkPosition.X, checkMarkPosition.Y);

            SKRect checkBoxPaintRect = new SKRect(skCheckBoxX + skCheckBoxBorderThickness / 2,
                                                  skCheckBoxY + skCheckBoxBorderThickness / 2,
                                                  skCheckBoxX + skCheckBoxWidth - skCheckBoxBorderThickness / 2,
                                                  skCheckBoxY + skCheckBoxHeight - skCheckBoxBorderThickness / 2);

            if (EllipseDiameter > 0 && _toggledAnimationProcess > 0 && _toggledAnimationProcess < 1 && IsEllipseAnimationEnabled)
            {
                SKPaint ellipsePaint = new SKPaint()
                {
                    IsAntialias = true,
                    Style       = SKPaintStyle.Fill,
                };

                if (_toggledAnimationProcess <= 0.5)
                {
                    ellipsePaint.Color = EllipseColor.MultiplyAlpha(_toggledAnimationProcessWithoutEasing * 2).ToSKColor();
                }
                else
                {
                    ellipsePaint.Color = EllipseColor.MultiplyAlpha(1 - (_toggledAnimationProcessWithoutEasing - 0.5) * 2).ToSKColor();
                }

                e.Surface.Canvas.DrawCircle(new SKPoint(checkBoxPaintRect.MidX, checkBoxPaintRect.MidY), (float)(EllipseDiameter / 2) * DeviceScale, ellipsePaint);
            }

            Color backgroundColor = Color.Transparent;

            if (CheckBoxBackgroundColor != null && CheckBoxBackgroundColor != Color.Transparent && ToggledCheckBoxBackgroundColor != null && ToggledCheckBoxBackgroundColor != Color.Transparent)
            {
                backgroundColor = AnimationUtils.ColorTransform(_toggledAnimationProcess, CheckBoxBackgroundColor, ToggledCheckBoxBackgroundColor);
            }
            else if ((CheckBoxBackgroundColor == null || CheckBoxBackgroundColor == Color.Transparent) && ToggledCheckBoxBackgroundColor != null && ToggledCheckBoxBackgroundColor != Color.Transparent)
            {
                backgroundColor = ToggledCheckBoxBackgroundColor;
            }
            else
            {
                backgroundColor = CheckBoxBackgroundColor;
            }

            SKPaint checkBoxBackgroundPaint = new SKPaint
            {
                Style       = SKPaintStyle.Fill,
                IsAntialias = true,
                Color       = backgroundColor.ToSKColor(),
            };

            SKRect rect = new SKRect(
                skCheckBoxX + skCheckBoxBorderThickness,
                skCheckBoxY + skCheckBoxBorderThickness,
                skCheckBoxX + skCheckBoxWidth - skCheckBoxBorderThickness,
                skCheckBoxY + skCheckBoxHeight - skCheckBoxBorderThickness);

            e.Surface.Canvas.Save();

            SKRect r = SKRect.Create(rect.Left, rect.Top, rect.Width, rect.Height);

            if (_toggledAnimationProcess <= 0.75)
            {
                float v = (float)(_toggledAnimationProcess * (1 / 0.75));
                r.Inflate(-rect.Width * v / 2, -rect.Height * v / 2);
                e.Surface.Canvas.ClipRect(r, SKClipOperation.Difference);
            }

            e.Surface.Canvas.DrawRoundRect(checkBoxPaintRect, skCornerRadius, skCornerRadius, checkBoxBackgroundPaint);
            e.Surface.Canvas.Restore();

            SKPaint checkBoxBorderPaint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                IsAntialias = true,
                StrokeWidth = skCheckBoxBorderThickness,
                Color       = AnimationUtils.ColorTransform(_toggledAnimationProcess, CheckBoxBorderColor, ToggledCheckBoxBorderColor).ToSKColor(),
            };

            e.Surface.Canvas.DrawRoundRect(checkBoxPaintRect, skCornerRadius, skCornerRadius, checkBoxBorderPaint);

            using (var paint = new SKPaint())
            {
                Color color = Color.Transparent;

                if (_toggledAnimationProcess > 0.75)
                {
                    float v = (float)((_toggledAnimationProcess - 0.75) * (1 / 0.25));
                    color = AnimationUtils.ColorTransform(v, CheckMarkIconColor, ToggledCheckMarkIconColor);
                }

                if (color != Color.Transparent)
                {
                    paint.ColorFilter = SKColorFilter.CreateBlendMode(color.ToSKColor(), SKBlendMode.SrcIn);
                    paint.Style       = SKPaintStyle.Fill;
                    paint.IsAntialias = true;

                    e.Surface.Canvas.DrawPicture(_checkMarkSvg.Picture, ref checkMarkMatrix, paint);
                }
            }
        }
示例#20
0
        public static SKMatrix GetMatrix(SvgImage svg, SKRect bound, float indent, float rotate = 0)
        {
            bound.Inflate(-indent, -indent);

            return(GetMatrix(svg, bound.Left, bound.Top, bound.Width, bound.Height, rotate));
        }
示例#21
0
        /// <summary>
        /// Draws a line connecting two SKPoint structures.
        /// </summary>
        /// <param name="series">Chart series.</param>
        /// <param name="point">Series last data point in the group.</param>
        /// <param name="pointMin">Series minimum Y value data point in the group.</param>
        /// <param name="pointMax">Series maximum Y value data point in the group.</param>
        /// <param name="pointIndex">Point index.</param>
        /// <param name="pen">Pen object that determines the color, width, and style of the line.</param>
        /// <param name="firstPointX">First point X coordinate.</param>
        /// <param name="firstPointY">First point Y coordinate</param>
        /// <param name="secondPointX">Second point X coordinate.</param>
        /// <param name="secondPointY">Second point Y coordinate</param>
        public virtual void DrawLine(
            Series series,
            DataPoint point,
            DataPoint pointMin,
            DataPoint pointMax,
            int pointIndex,
            SKPaint pen,
            float firstPointX,
            float firstPointY,
            float secondPointX,
            float secondPointY
            )
        {
            // Transform 3D coordinates
            if (chartArea3DEnabled)
            {
                Point3D[] points = new Point3D[2];

                // All coordinates has to be transformed in relative coordinate system
                // NOTE: Fixes issue #5496
                SKPoint firstPoint  = Graph.GetRelativePoint(new SKPoint(firstPointX, firstPointY));
                SKPoint secondPoint = Graph.GetRelativePoint(new SKPoint(secondPointX, secondPointY));

                points[0] = new Point3D(firstPoint.X, firstPoint.Y, seriesZCoordinate);
                points[1] = new Point3D(secondPoint.X, secondPoint.Y, seriesZCoordinate);
                matrix3D.TransformPoints(points);

                // All coordinates has to be transformed back to pixels
                // NOTE: Fixes issue #5496
                points[0].SKPoint = Graph.GetAbsolutePoint(points[0].SKPoint);
                points[1].SKPoint = Graph.GetAbsolutePoint(points[1].SKPoint);

                firstPointX  = points[0].X;
                firstPointY  = points[0].Y;
                secondPointX = points[1].X;
                secondPointY = points[1].Y;
            }

            // Draw line
            Graph.DrawLine(pen, firstPointX, firstPointY, secondPointX, secondPointY);

            // Process selection regions
            if (Common.ProcessModeRegions)
            {
                // Create grapics path object for the line
                using SKPath path = new();
                float width = pen.StrokeWidth + 2;

                if (Math.Abs(firstPointX - secondPointX) > Math.Abs(firstPointY - secondPointY))
                {
                    path.AddLine(firstPointX, firstPointY - width, secondPointX, secondPointY - width);
                    path.AddLine(secondPointX, secondPointY + width, firstPointX, firstPointY + width);
                    path.Close();
                }
                else
                {
                    path.AddLine(firstPointX - width, firstPointY, secondPointX - width, secondPointY);
                    path.AddLine(secondPointX + width, secondPointY, firstPointX + width, firstPointY);
                    path.Close();
                }

                // Calculate bounding rectangle
                SKRect pathBounds = path.GetBounds();

                // If one side of the bounding rectangle is less than 2 pixels
                // use rectangle region shape to optimize used coordinates space
                if (pathBounds.Width <= 2.0 || pathBounds.Height <= 2.0)
                {
                    // Add hot region path as rectangle
                    pathBounds.Inflate(pen.StrokeWidth, pen.StrokeWidth);
                    Common.HotRegionsList.AddHotRegion(
                        Graph.GetRelativeRectangle(pathBounds),
                        point,
                        point.series.Name,
                        pointIndex);
                }
                else
                {
                    // Add hot region path as polygon
                    Common.HotRegionsList.AddHotRegion(
                        path,
                        false,
                        point,
                        point.series.Name,
                        pointIndex);
                }
            }
        }
示例#22
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            base.OnPaintSurface(e);

            var canvas = e.Surface.Canvas;

            canvas.Clear();

            int width  = e.Info.Width;
            int height = e.Info.Height;

            SKPaint backPaint = new SKPaint
            {
                Style = SKPaintStyle.Fill,
                Color = SKColors.WhiteSmoke,
            };

            canvas.DrawRect(new SKRect(0, 0, width, height), backPaint);

            canvas.Save();

            canvas.Translate(width / 2, height / 2);
            canvas.Scale(Math.Min(width / 210f, height / 520f));
            SKPoint center = new SKPoint(0, 0);

            var rect = new SKRect(-100, -100, 100, 100);

            // Add a buffer for the rectangle
            rect.Inflate(-10, -10);


            SKPaint GaugePointPaint = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                Color       = ValueColor.ToSKColor()
            };

            SKPaint HighlightRangePaint = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                Color       = RangeColor.ToSKColor()
            };


            // Draw the range of values

            var rangeStartAngle = AmountToAngle(HighlightRangeStartValue);
            var rangeEndAngle   = AmountToAngle(HighlightRangeEndValue);
            var angleDistance   = rangeEndAngle - rangeStartAngle;

            using (SKPath path = new SKPath())
            {
                path.AddArc(rect, rangeStartAngle, angleDistance);
                path.LineTo(center);
                canvas.DrawPath(path, HighlightRangePaint);
            }

            // Draw the main gauge line/arc
            SKPaint GaugeMainLinePaintP1 = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.Blue,
                StrokeWidth = 10
            };
            var startAngle = 135;
            var sweepAngle = 67.5f;

            using (SKPath path = new SKPath())
            {
                path.AddArc(rect, startAngle, sweepAngle);
                canvas.DrawPath(path, GaugeMainLinePaintP1);
            }

            //Sector2
            SKPaint GaugeMainLinePaintP2 = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.Green,
                StrokeWidth = 10
            };

            var startAngleP2 = 202.5f;

            using (SKPath path = new SKPath())
            {
                path.AddArc(rect, startAngleP2, sweepAngle);
                canvas.DrawPath(path, GaugeMainLinePaintP2);
            }

            //Sector3
            SKPaint GaugeMainLinePaintP3 = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.Orange,
                StrokeWidth = 10
            };

            var startAngleP3 = 270f;

            using (SKPath path = new SKPath())
            {
                path.AddArc(rect, startAngleP3, sweepAngle);
                canvas.DrawPath(path, GaugeMainLinePaintP3);
            }

            //Sector 4

            SKPaint GaugeMainLinePaintP4 = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.Red,
                StrokeWidth = 10
            };

            var startAngleP4 = 337.5f;

            using (SKPath path = new SKPath())
            {
                path.AddArc(rect, startAngleP4, sweepAngle);
                canvas.DrawPath(path, GaugeMainLinePaintP4);
            }

            //Draw Needle
            DrawNeedle(canvas, Value);

            //Draw Screw
            SKPaint NeedleScrewPaint = new SKPaint()
            {
                IsAntialias = true,
                Shader      = SKShader.CreateRadialGradient(center, width / 60, new SKColor[]
                                                            { new SKColor(171, 171, 171), SKColors.White }, new float[] { 0.05f, 0.9f }, SKShaderTileMode.Mirror)
            };

            canvas.DrawCircle(center, width / 60, NeedleScrewPaint);

            SKPaint paint = new SKPaint
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                Color       = new SKColor(81, 84, 89).WithAlpha(100),
                StrokeWidth = 1f
            };

            canvas.DrawCircle(center, width / 60, paint);

            // Draw the Units of Measurement Text on the display
            SKPaint textPaint = new SKPaint
            {
                IsAntialias = true,
                Color       = SKColors.Black
            };

            float textWidth = textPaint.MeasureText(UnitsText);

            textPaint.TextSize = 12f;

            SKRect textBounds = SKRect.Empty;

            textPaint.MeasureText(UnitsText, ref textBounds);

            float xText = -1 * textBounds.MidX;
            float yText = 95 - textBounds.Height;

            // And draw the text
            canvas.DrawText(UnitsText, xText, yText, textPaint);

            // Draw the Value on the display
            var   valueText      = Value.ToString("F0"); //You can set F1 or F2 if you need float values
            float valueTextWidth = textPaint.MeasureText(valueText);

            textPaint.TextSize = ValueFontSize;

            textPaint.MeasureText(valueText, ref textBounds);

            xText = -1 * textBounds.MidX;
            yText = 85 - textBounds.Height;

            // And draw the text
            canvas.DrawText(valueText, xText, yText, textPaint);
            canvas.Restore();
        }
示例#23
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info = args.Info;


            string   resourceID = "TouchTrackingEffectDemos.DrawBG.png";
            Assembly assembly   = GetType().GetTypeInfo().Assembly;

            using (Stream stream = assembly.GetManifestResourceStream(resourceID))
                using (SKManagedStream skStream = new SKManagedStream(stream))
                {
                    resourceBitmap = SKBitmap.Decode(skStream);
                }

            SKCanvas canvas = args.Surface.Canvas;


            //SKCanvas canvas = new SKCanvas(bitmap);
            canvas.Clear();


            if (resourceBitmap != null)
            {
                float x = (info.Width - resourceBitmap.Width) / 2;
                float y = (info.Height / 3 - resourceBitmap.Height) / 2;

                canvas.DrawBitmap(resourceBitmap, x, y);
            }

            //foreach (FingerPaintPolyline polyline in completedPolylines)
            //{
            //    paint.Color = polyline.StrokeColor.ToSKColor();
            //    paint.StrokeWidth = polyline.StrokeWidth;
            //    canvas.DrawPath(polyline.Path, paint);
            //}

            //foreach (FingerPaintPolyline polyline in inProgressPolylines.Values)
            //{
            //    paint.Color = polyline.StrokeColor.ToSKColor();
            //    paint.StrokeWidth = polyline.StrokeWidth;
            //    canvas.DrawPath(polyline.Path, paint);
            //}

            //
            var brush = new SKPaint
            {
                TextSize    = 35.0f,
                IsAntialias = true,
                Color       = new SKColor(255, 255, 255, 255)
            };

            //ConvertToPixel(args.Location)
            if (txt.Text == null)
            {
                txt.Text = "";
            }
            if (txt.Text != "")
            {
                //
                // Adjust TextSize property so text is 90% of screen width
                //float textWidth = brush.MeasureText(txt.Text);
                //brush.TextSize = 0.9f * args.Info.Width * brush.TextSize / textWidth;

                // Find the text bounds
                SKRect textBounds;
                brush.MeasureText(txt.Text, ref textBounds);
                //

                canvas.DrawText(txt.Text, Convert.ToSingle(touchPoint1.X), Convert.ToSingle(touchPoint1.Y + 30), brush);
                txt.Text = "";
                //txt.Unfocus();



                //
                // Create a new SKRect object for the frame around the text
                SKRect frameRect = textBounds;
                frameRect.Offset(Convert.ToSingle(touchPoint1.X), Convert.ToSingle(touchPoint1.Y + 30));
                frameRect.Inflate(10, 10);

                // Create an SKPaint object to display the frame
                SKPaint framePaint = new SKPaint
                {
                    Style       = SKPaintStyle.Stroke,
                    StrokeWidth = 5,
                    Color       = SKColors.White
                };

                // Draw one frame
                //canvas.DrawRoundRect(frameRect, 20, 20, framePaint);
                canvas.DrawRect(frameRect, framePaint);

                // Inflate the frameRect and draw another
                //frameRect.Inflate(10, 10);
                //framePaint.Color = SKColors.DarkBlue;
                //canvas.DrawRoundRect(frameRect, 30, 30, framePaint);
                //
            }


            //canvas.DrawPositionedText(.DrawNamedDestinationAnnotation(point, "");
            //canvas.DrawText("Sample text", ConvertToPixel(args.Surface.Canvas..Location), brush);
            //


            image1 = args.Surface.Snapshot();
            //canvas.SaveLayer(paint);
        }
示例#24
0
        private async Task <SKBitmap> GetLigneSymbolBitmap(string ligne, string destination, int height, int?maxDestinationlength = null)
        {
            _ = 2;
            try
            {
                float elementsSpacing   = (float)height * 0.2f;
                float backgroundPadding = (float)height * 0.2f;
                if (destination != null && maxDestinationlength.HasValue && destination.Length > maxDestinationlength.Value)
                {
                    destination = destination.Substring(0, maxDestinationlength.Value) + "...";
                }
                SKPaint bitmapPaint = new SKPaint
                {
                    FilterQuality = SKFilterQuality.High,
                    IsAntialias   = true
                };
                SKPaint sKPaint = new SKPaint
                {
                    Style       = SKPaintStyle.StrokeAndFill,
                    StrokeWidth = 1f,
                    Color       = new SKColor(48, 48, 47)
                };
                SKPaint sKPaint2 = sKPaint;
                sKPaint2.Typeface     = SKTypeface.FromStream(await _fileManager.GetBundleBinaryFile("Fonts/TCL-Regular_0.otf"));
                sKPaint.TextAlign     = SKTextAlign.Left;
                sKPaint.TextEncoding  = SKTextEncoding.Utf8;
                sKPaint.TextSize      = (float)height * 0.8f;
                sKPaint.FilterQuality = SKFilterQuality.High;
                sKPaint.IsAntialias   = true;
                SKPaint destinationPaint = sKPaint;
                SKPaint backgroundPaint  = new SKPaint
                {
                    Style = SKPaintStyle.StrokeAndFill,
                    Color = new SKColor(255, 255, 255, 255)
                };
                SKBitmap modeBitmap = await GetModeBitmap(ligne);

                SKBitmap bitmap = await GetLigneBitmap(ligne);

                SKRect modeSpriteRect  = GetModeSpriteRect(modeBitmap, height);
                SKRect ligneSpriteRect = GetLigneSpriteRect(bitmap, height, modeSpriteRect.Right + elementsSpacing / 2f);
                SKRect bounds          = default(SKRect);
                if (destination != null)
                {
                    destinationPaint.MeasureText(destination, ref bounds);
                }
                float  num  = (destination != null) ? (elementsSpacing * 1.5f) : elementsSpacing;
                SKRect rect = new SKRect(0f, 0f, modeSpriteRect.Width + ligneSpriteRect.Width + num + bounds.Width, height);
                rect.Inflate(backgroundPadding, backgroundPadding);
                rect.Offset(backgroundPadding, backgroundPadding);
                modeSpriteRect.Offset(backgroundPadding, backgroundPadding);
                ligneSpriteRect.Offset(backgroundPadding, backgroundPadding);
                SKBitmap sKBitmap = new SKBitmap((int)rect.Width, (int)rect.Height);
                sKBitmap.Erase(SKColors.Transparent);
                SKRoundRect rect2 = new SKRoundRect(rect, rect.Height / 4f, rect.Height / 4f);
                using (SKCanvas sKCanvas = new SKCanvas(sKBitmap))
                {
                    sKCanvas.DrawRoundRect(rect2, backgroundPaint);
                    sKCanvas.DrawBitmap(modeBitmap, modeSpriteRect, bitmapPaint);
                    sKCanvas.DrawBitmap(bitmap, ligneSpriteRect, bitmapPaint);
                    if (destination != null)
                    {
                        sKCanvas.DrawText(destination, ligneSpriteRect.Right + elementsSpacing - bounds.Left, destinationPaint.TextSize + backgroundPadding, destinationPaint);
                    }
                }
                SKRect   dest      = SKRect.Create(0f, 0f, rect.Width * (float)height / rect.Height, height);
                SKBitmap sKBitmap2 = new SKBitmap((int)dest.Width, (int)dest.Height);
                sKBitmap2.Erase(SKColors.Transparent);
                using (SKCanvas sKCanvas2 = new SKCanvas(sKBitmap2))
                {
                    sKCanvas2.DrawBitmap(sKBitmap, dest, bitmapPaint);
                }
                return(sKBitmap2);
            }
            catch (Exception)
            {
                return(null);
            }
        }
示例#25
0
        public void Redraw(SKPoint tipPoint, SKCanvas canvas, float scale)
        {
            Scale = scale;

            // Not creating new paint objects for each draw, therefore scale the properties here.
            TextPaint.TextSize     = ValueLabelFontSize;
            FramePaint.StrokeWidth = BorderThickness;

            // Move the tip little away from the dot
            var tipX = tipPoint.X + 8 * scale;
            var tipY = tipPoint.Y;

            SKRect frameRect = new SKRect();

            TextPaint.MeasureText(Text, ref frameRect);
            var textHeight = frameRect.Top;

            // Inflate for padding
            frameRect.Inflate(ValueLabelPadding, ValueLabelPadding);


            // Start from the tip then move clockwise. Triangle is on negetive side
            //                 |
            //               c1|     ------------------------------     . c2
            //                 |    /                               \
            //                 |   /                                 \
            //                 |  /                                   \
            //                 | /                                     \
            //                 |                                       |
            //                 |                                       |
            //                 |                                       |
            //                 |                                       |
            //                /|                                       |
            //               / |                                       |
            //              /  |                                       |
            //             /   |                                       |
            //---------------------------------------------------------|---------------------
            //             \   |                                       |
            //              \  |                                       |

            // TODO: Use SKCanvas.Translate?
            SKPoint GetPoint(float x, float y) => new SKPoint(tipX + x + TriangleWidth, tipY + y);

            using (var path = new SKPath())
            {
                var corners = new SKPoint[] {
                    GetPoint(0, -frameRect.Height / 2),
                    GetPoint(frameRect.Width, -frameRect.Height / 2),
                    GetPoint(frameRect.Width, frameRect.Height / 2),
                    GetPoint(0, frameRect.Height / 2)
                };

                path.MoveTo(GetPoint(-TriangleWidth, 0));
                path.LineTo(GetPoint(0, -TriangleWidth));
                path.ArcTo(corners[0], corners[1], ToolTipCornerRadius);
                path.ArcTo(corners[1], corners[2], ToolTipCornerRadius);
                path.ArcTo(corners[2], corners[3], ToolTipCornerRadius);
                path.ArcTo(corners[3], corners[0], ToolTipCornerRadius);
                path.LineTo(GetPoint(0, TriangleWidth));
                path.Close();
                canvas.DrawPath(path, FillPaint);
                canvas.DrawPath(path, FramePaint);
            }

            var xText = tipX + TriangleWidth + ValueLabelPadding;
            var yText = tipY - frameRect.Height / 2 + ValueLabelPadding - textHeight;

            canvas.DrawText(Text, xText, yText, TextPaint);
        }