Example #1
0
        public DominoRenderer(ProjectCanvas pc)
        {
            _noSkia = new FormattedText()
            {
                Text = "Current rendering API is not Skia"
            };
            Bounds                 = new Rect(0, 0, pc.Bounds.Width, pc.Bounds.Height);
            TightBounds            = pc.TransformedBounds;
            shift_x                = (float)pc.ShiftX;
            shift_y                = (float)pc.ShiftY;
            zoom                   = (float)pc.Zoom;
            unselectedBorderColor  = pc.UnselectedBorderColor.ToSKColor();
            selectedBorderColor    = pc.SelectedBorderColor.ToSKColor();
            pasteHightlightColor   = Colors.Violet.ToSKColor();
            deletionHighlightColor = SKColors.Red;
            selectionColor         = pc.SelectionDomainColor.ToSKColor();
            selectionPath          = pc.SelectionDomain.Clone();
            this.project           = pc.Project;
            // Transform the selection path into screen coordinates
            var transform = SKMatrix.CreateScaleTranslation(zoom, zoom, -shift_x * zoom, -shift_y * zoom);

            this.ProjectHeight       = (float)pc.ProjectHeight;
            this.ProjectWidth        = (float)pc.ProjectWidth;
            this.above               = pc.SourceImageAbove;
            this.background          = pc.BackgroundColor.ToSKColor();
            this.AdditionalDrawables = pc.AdditionalDrawables;

            selectionPath?.Transform(transform);
            selectionVisible = pc.SelectionDomainVisible;
            bitmap           = pc.SourceImage;
            bitmapopacity    = (byte)(pc.SourceImageOpacity * 255);
            dominoopacity    = (byte)(pc.DominoOpacity * 255);
            BorderSize       = pc.BorderSize;
        }
Example #2
0
        public static SKMatrix GetFullSvgScaledMatrix(int width, int height, SKPicture picture)
        {
            float imageScale = height / picture.CullRect.Height;
            float xPosition  = (picture.CullRect.Width * imageScale) / 2;

            return(SKMatrix.CreateScaleTranslation(imageScale, imageScale, (width / 2) - xPosition, 0));
        }
        void canvasFront_PaintSurface(System.Object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs e)
        {
            SKCanvas canvas = e.Surface.Canvas;

            canvas.Clear();

            SKMatrix matrix = DrawHelper.GetFullSvgScaledMatrix(e.Info.Width, e.Info.Height, pictureFront);

            canvas.DrawPicture(pictureFront, ref matrix);
            float offsetY = e.Info.Height / 5;

            foreach (DrawItem item in DrawData.DrawnPathsFront)
            {
                SKPath p           = new SKPath(item.Path);
                float  offsetCalcY = (float)DrawHelper.GetOffsetCalculationsForFullDisplay(item.Area, offsetY);
                float  offsetCalcX = ((e.Info.Width - matrix.TransX) / 2.0f) * 0.375f;

                p.Transform(SKMatrix.CreateScaleTranslation(0.25f, 0.25f, offsetCalcX, offsetCalcY));

                _data.Add(new SvgData
                {
                    BodyRegion  = item.Area.ToString(),
                    IsFront     = true,
                    StrokeColor = item.Paint.Color.ToFormsColor(),
                    StrokeWidth = item.Paint.StrokeWidth,
                    SvgPath     = p.ToSvgPathData(),
                    ConcernName = item.Name
                });

                canvas.DrawPath(p, DrawHelper.GetScaledPaintObject(item.Paint.Color, item.Paint.StrokeWidth));
            }

            imageDataF = e.Surface.Snapshot();
        }
Example #4
0
        public static SKMatrix GetAreaSvgScaledMatrix(int width, int height, SKPicture picture, BodyArea areaUsed)
        {
            float imageScale = (height / picture.CullRect.Height) * 4.0f;
            float tY         = (float)GetOffsetCalculations(areaUsed, height);

            float axisScale = picture.CullRect.Width * imageScale;
            float xPosition = (width - axisScale) / 2;

            return(SKMatrix.CreateScaleTranslation(imageScale, imageScale, xPosition, tY));
        }
        public void DesenharSvg(ISvgElement svgDoc, Transformacao matriz)
        {
            using (var paint = new SKPaint())
            {
                var escala  = matriz.Escala.Value;
                var posicao = matriz.Posicao.Value;
                var matrix  = SKMatrix.CreateScaleTranslation(escala.X, escala.Y, posicao.X, posicao.Y);

                paint.IsAntialias = true;
                paint.ImageFilter = Color.FromHex("#66000000").ToSKDropShadow(6, 12f);
                paint.MaskFilter  = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, Constantes.SVG.Mapa.DESFOQUE_SOMBRA);

                if (svgDoc is SKSvgElement svgElement)
                {
                    _canvas.DrawPicture(svgElement.ToSkia(), ref matrix, paint);
                }
            }
        }
Example #6
0
 private void DrawAdditionals(SKCanvas canvas, bool beforeBorders)
 {
     try
     {
         foreach (CanvasDrawable d in AdditionalDrawables.ToList())
         {
             if (d == null)
             {
                 continue;
             }
             if (d.BeforeBorders == beforeBorders)
             {
                 var transform = SKMatrix.CreateScaleTranslation(zoom, zoom, -shift_x * zoom, -shift_y * zoom);
                 d.Render(canvas, transform);
             }
         }
     }
     catch {} // happens mostly when AdditionalDrawables is modified during a render pass. This triggers a redraw anyway, so let's ignore it
 }
Example #7
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs args)
        {
            base.OnPaintSurface(args);

            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear(SkiaHelper.backgroundColor);

            // 计算显示位图的矩形
            var rect = SkiaHelper.CalculateRectangle(new SKRect(0, 0, info.Width, info.Height), bitmap);

            canvas.DrawBitmap(bitmap, rect.rect);

            // 计算用于显示裁剪矩形的矩阵变换
            SKMatrix bitmapScaleMatrix = SKMatrix.CreateIdentity();

            SKMatrix.CreateScaleTranslation(rect.scaleX, rect.scaleX, rect.rect.Left, rect.rect.Top);

            // 显示矩形
            SKRect scaledCropRect = bitmapScaleMatrix.MapRect(croppingRect.Rect);


            using (SKPaint edgeStroke = new SKPaint())
            {
                edgeStroke.Style       = SKPaintStyle.Stroke;
                edgeStroke.Color       = SKColors.White;
                edgeStroke.StrokeWidth = 3;
                edgeStroke.IsAntialias = true;
                canvas.DrawRect(scaledCropRect, edgeStroke);
            }

            canvas.DrawSurrounding(rect.rect, scaledCropRect, SKColors.Gray.WithAlpha(190));

            // Display heavier corners
            using (SKPaint cornerStroke = new SKPaint())
                using (SKPath path = new SKPath())
                {
                    cornerStroke.Style       = SKPaintStyle.Stroke;
                    cornerStroke.Color       = SKColors.White;
                    cornerStroke.StrokeWidth = 7;

                    path.MoveTo(scaledCropRect.Left, scaledCropRect.Top + corner);
                    path.LineTo(scaledCropRect.Left, scaledCropRect.Top);
                    path.LineTo(scaledCropRect.Left + corner, scaledCropRect.Top);

                    path.MoveTo(scaledCropRect.Right - corner, scaledCropRect.Top);
                    path.LineTo(scaledCropRect.Right, scaledCropRect.Top);
                    path.LineTo(scaledCropRect.Right, scaledCropRect.Top + corner);

                    path.MoveTo(scaledCropRect.Right, scaledCropRect.Bottom - corner);
                    path.LineTo(scaledCropRect.Right, scaledCropRect.Bottom);
                    path.LineTo(scaledCropRect.Right - corner, scaledCropRect.Bottom);

                    path.MoveTo(scaledCropRect.Left + corner, scaledCropRect.Bottom);
                    path.LineTo(scaledCropRect.Left, scaledCropRect.Bottom);
                    path.LineTo(scaledCropRect.Left, scaledCropRect.Bottom - corner);

                    canvas.DrawPath(path, cornerStroke);
                }

            // 反转变换以进行触摸跟踪
            bitmapScaleMatrix.TryInvert(out inverseBitmapMatrix);
        }