Ejemplo n.º 1
0
        public virtual void Render(SKCanvas canvas)
        {
            SKMatrix visual = VisualTransform;
            SKMatrix invert = visual.Invert();

            canvas.Concat(ref visual);
            Draw(canvas);
            canvas.Concat(ref invert);
        }
Ejemplo n.º 2
0
        public override void Render(SKCanvas canvas)
        {
            base.Render(canvas);
            SKMatrix visual = _childrenVisualTransform;
            SKMatrix invert = visual.Invert();

            canvas.Concat(ref visual);
            RenderChildren(canvas);
            canvas.Concat(ref invert);
        }
Ejemplo n.º 3
0
        public override void DrawLayer(SKCanvas canvas, Matrix3X3 parentMatrix, byte parentAlpha)
        {
            var bitmap = Bitmap;

            if (bitmap == null)
            {
                return;
            }
            var density = Utils.Utils.DpScale();

            _paint.SetAlpha(parentAlpha);
            if (_colorFilterAnimation != null)
            {
                _paint.ColorFilter = _colorFilterAnimation.Value;
            }
            canvas.Save();
            var sk = parentMatrix.ToSKMatrix();

            canvas.Concat(ref sk);
            parentMatrix = sk.To3x3Matrix();
            RectExt.Set(ref _src, 0, 0, PixelWidth, PixelHeight);
            RectExt.Set(ref _dst, 0, 0, (int)(PixelWidth * density), (int)(PixelHeight * density));
            canvas.DrawBitmap(bitmap, _src, _dst, _paint);
            canvas.Restore();
        }
        public void Paint(SKCanvas canvas)
        {
            canvas.Save();
            SKMatrix matrix = Matrix;

            canvas.Concat(ref matrix);
            canvas.DrawBitmap(bitmap, 0, 0);
            canvas.Restore();
        }
Ejemplo n.º 5
0
        public static void DrawImage(SKCanvas canvas, SvgImage svg, SKPaint paint, SKRect bounds, float indent = 2)
        {
            var matrix = GetMatrix(svg, bounds, indent);

            canvas.Save();
            canvas.Concat(ref matrix);
            canvas.DrawPath(svg.Path, paint);
            canvas.Restore();
        }
Ejemplo n.º 6
0
        public void Render(SKCanvas canvas)
        {
            canvas.Concat(ref Matrix);
            var center         = GetCenter();
            var angleInRadians = GetAngleInRadians();
            var scale          = GetScale();

            _sceneRenderer.Render(canvas, angleInRadians, center, scale);
        }
Ejemplo n.º 7
0
        protected void OnDrawSample(SKCanvas canvas, int width, int height)
        {
            var length = Math.Min(width / 6, height / 6);
            var rect   = new SKRect(-length, -length, length, length);
            var side   = rotationMatrix.MapPoint(new SKPoint(1, 0)).X > 0;

            canvas.Clear(SampleMedia.Colors.XamarinLightBlue);

            // first do 2D translation to the center of the screen
            canvas.Translate(width / 2, height / 2);

            // then apply the 3D rotation
            var matrix = rotationMatrix.Matrix;

            canvas.Concat(ref matrix);

            var paint = new SKPaint
            {
                Color       = side ? SampleMedia.Colors.XamarinPurple : SampleMedia.Colors.XamarinGreen,
                Style       = SKPaintStyle.Fill,
                IsAntialias = true
            };

            canvas.DrawRoundRect(rect, 30, 30, paint);

            var shadow = SKShader.CreateLinearGradient(
                new SKPoint(0, 0), new SKPoint(0, length * 2),
                new[] { paint.Color.WithAlpha(127), paint.Color.WithAlpha(0) },
                null,
                SKShaderTileMode.Clamp);

            paint = new SKPaint
            {
                Shader      = shadow,
                Style       = SKPaintStyle.Fill,
                IsAntialias = true
            };

            rect.Offset(0, length * 2 + 5);
            canvas.DrawRoundRect(rect, 30, 30, paint);

            Log.Debug("Demo", "Enter");

            if (cnt == 0)
            {
                Log.Debug("Demo", "Enter");
                InitEvent();
            }
        }
Ejemplo n.º 8
0
        protected override void OnDrawSample(SKCanvas canvas, int width, int height)
        {
            // get the 2D equivalent of the 3D matrix
            var rotationMatrix = rotationView.Matrix;

            // get the properties of the rectangle
            var length = Math.Min(width / 6, height / 6);
            var rect   = new SKRect(-length, -length, length, length);
            var side   = rotationMatrix.MapPoint(new SKPoint(1, 0)).X > 0;

            canvas.Clear(SampleMedia.Colors.XamarinLightBlue);

            // first do 2D translation to the center of the screen
            canvas.Translate(width / 2, height / 2);

            // then apply the 3D rotation
            canvas.Concat(ref rotationMatrix);

            var paint = new SKPaint
            {
                Color       = side ? SampleMedia.Colors.XamarinPurple : SampleMedia.Colors.XamarinGreen,
                Style       = SKPaintStyle.Fill,
                IsAntialias = true
            };

            canvas.DrawRoundRect(rect, 30, 30, paint);

            var shadow = SKShader.CreateLinearGradient(
                new SKPoint(0, 0), new SKPoint(0, length * 2),
                new[] { paint.Color.WithAlpha(127), paint.Color.WithAlpha(0) },
                null,
                SKShaderTileMode.Clamp);

            paint = new SKPaint
            {
                Shader      = shadow,
                Style       = SKPaintStyle.Fill,
                IsAntialias = true
            };

            rect.Offset(0, length * 2 + 5);
            canvas.DrawRoundRect(rect, 30, 30, paint);
        }
Ejemplo n.º 9
0
        internal static RasterCacheResult Rasterize(GRContext context, SKMatrix ctm, SKColorSpace dst_color_space, bool checkerboard, SKRect logical_rect, Action <SKCanvas> draw_function)
        {
            SKRectI cache_rect = RasterCache.GetDeviceBounds(logical_rect, ctm);

            SKImageInfo image_info = new SKImageInfo(cache_rect.Width, cache_rect.Height);

            SKSurface surface = context != null?SKSurface.CreateAsRenderTarget(context, new GRGlBackendTextureDesc()
            {
                Width = cache_rect.Width, Height = cache_rect.Height
            }) : SKSurface.Create(image_info);                                                                                                                                                                    //{ image_info.

            if (surface == null)
            {
                return(new RasterCacheResult());
            }

            SKCanvas canvas      = surface.Canvas;
            SKCanvas xformCanvas = canvas;

            //if (dst_color_space != null)
            //{
            //    xformCanvas = SkCreateColorSpaceXformCanvas(canvas, GlobalMembers.sk_ref_sp(dst_color_space));
            //    if (xformCanvas != null)
            //    {
            //        canvas = xformCanvas;
            //    }
            //}

            canvas.Clear(GlobalMembers.SK_ColorTRANSPARENT);
            canvas.Translate(-cache_rect.Left, -cache_rect.Top);
            canvas.Concat(ref ctm);
            draw_function(canvas);

            //if (checkerboard)
            //{
            //    DrawCheckerboard(canvas, logical_rect);
            //}

            return(new RasterCacheResult(surface.Snapshot(), logical_rect));
        }
Ejemplo n.º 10
0
        private void ReadElement(XElement e, SKCanvas canvas, SKPaint stroke, SKPaint fill)
        {
            ReadPaints(e, ref stroke, ref fill);

            // transform matrix
            var transform = ReadTransform(e.Attribute("transform")?.Value ?? string.Empty);

            canvas.Save();
            canvas.Concat(ref transform);

            // SVG elements
            var elementName = e.Name.LocalName;

            switch (elementName)
            {
            case "text":
                if (stroke != null || fill != null)
                {
                    ReadText(e, canvas, stroke?.Clone(), fill?.Clone());
                }
                break;

            case "rect":
                if (stroke != null || fill != null)
                {
                    var x      = ReadNumber(e.Attribute("x"));
                    var y      = ReadNumber(e.Attribute("y"));
                    var width  = ReadNumber(e.Attribute("width"));
                    var height = ReadNumber(e.Attribute("height"));
                    var rx     = ReadNumber(e.Attribute("rx"));
                    var ry     = ReadNumber(e.Attribute("ry"));
                    var rect   = SKRect.Create(x, y, width, height);
                    if (rx > 0 || ry > 0)
                    {
                        if (fill != null)
                        {
                            canvas.DrawRoundRect(rect, rx, ry, fill);
                        }
                        if (stroke != null)
                        {
                            canvas.DrawRoundRect(rect, rx, ry, stroke);
                        }
                    }
                    else
                    {
                        if (fill != null)
                        {
                            canvas.DrawRect(rect, fill);
                        }
                        if (stroke != null)
                        {
                            canvas.DrawRect(rect, stroke);
                        }
                    }
                }
                break;

            case "ellipse":
                if (stroke != null || fill != null)
                {
                    var cx = ReadNumber(e.Attribute("cx"));
                    var cy = ReadNumber(e.Attribute("cy"));
                    var rx = ReadNumber(e.Attribute("rx"));
                    var ry = ReadNumber(e.Attribute("ry"));
                    if (fill != null)
                    {
                        canvas.DrawOval(cx, cy, rx, ry, fill);
                    }
                    if (stroke != null)
                    {
                        canvas.DrawOval(cx, cy, rx, ry, stroke);
                    }
                }
                break;

            case "circle":
                if (stroke != null || fill != null)
                {
                    var cx = ReadNumber(e.Attribute("cx"));
                    var cy = ReadNumber(e.Attribute("cy"));
                    var rr = ReadNumber(e.Attribute("r"));
                    if (fill != null)
                    {
                        canvas.DrawCircle(cx, cy, rr, fill);
                    }
                    if (stroke != null)
                    {
                        canvas.DrawCircle(cx, cy, rr, stroke);
                    }
                }
                break;

            case "path":
                if (stroke != null || fill != null)
                {
                    var d = e.Attribute("d")?.Value;
                    if (!string.IsNullOrWhiteSpace(d))
                    {
                        var path = SKPath.ParseSvgPathData(d);
                        if (fill != null)
                        {
                            canvas.DrawPath(path, fill);
                        }
                        if (stroke != null)
                        {
                            canvas.DrawPath(path, stroke);
                        }
                    }
                }
                break;

            case "polygon":
            case "polyline":
                if (stroke != null || fill != null)
                {
                    var close = elementName == "polygon";
                    var p     = e.Attribute("points")?.Value;
                    if (!string.IsNullOrWhiteSpace(p))
                    {
                        var path = ReadPolyPath(p, close);
                        if (fill != null)
                        {
                            canvas.DrawPath(path, fill);
                        }
                        if (stroke != null)
                        {
                            canvas.DrawPath(path, stroke);
                        }
                    }
                }
                break;

            case "g":
                if (e.HasElements)
                {
                    foreach (var gElement in e.Elements())
                    {
                        ReadElement(gElement, canvas, stroke?.Clone(), fill?.Clone());
                    }
                }
                break;

            case "use":
                if (e.HasAttributes)
                {
                    var href = ReadHref(e);
                    if (href != null)
                    {
                        // TODO: copy/process other attributes

                        var x            = ReadNumber(e.Attribute("x"));
                        var y            = ReadNumber(e.Attribute("y"));
                        var useTransform = SKMatrix.MakeTranslation(x, y);

                        canvas.Save();
                        canvas.Concat(ref useTransform);

                        ReadElement(href, canvas, stroke?.Clone(), fill?.Clone());

                        canvas.Restore();
                    }
                }
                break;

            case "line":
                if (stroke != null)
                {
                    var x1 = ReadNumber(e.Attribute("x1"));
                    var x2 = ReadNumber(e.Attribute("x2"));
                    var y1 = ReadNumber(e.Attribute("y1"));
                    var y2 = ReadNumber(e.Attribute("y2"));
                    canvas.DrawLine(x1, y1, x2, y2, stroke);
                }
                break;

            case "switch":
                if (e.HasElements)
                {
                    foreach (var ee in e.Elements())
                    {
                        var requiredFeatures   = ee.Attribute("requiredFeatures");
                        var requiredExtensions = ee.Attribute("requiredExtensions");
                        var systemLanguage     = ee.Attribute("systemLanguage");

                        // TODO: evaluate requiredFeatures, requiredExtensions and systemLanguage
                        var isVisible =
                            requiredFeatures == null &&
                            requiredExtensions == null &&
                            systemLanguage == null;

                        if (isVisible)
                        {
                            ReadElement(ee, canvas, stroke?.Clone(), fill?.Clone());
                        }
                    }
                }
                break;

            case "defs":
            case "title":
            case "desc":
            case "description":
                // already read earlier
                break;

            default:
                LogOrThrow($"SVG element '{elementName}' is not supported");
                break;
            }

            // restore matrix
            canvas.Restore();
        }
Ejemplo n.º 11
0
        }; // спец эмоджи

        // отрисока схемы этажа
        public void Paint(SKCanvas canvas, int floor)
        {
            canvas.Save();
            SKMatrix matrix = Matrix;

            canvas.Concat(ref matrix);
            canvas.DrawBitmap(bitmap, 0, 0);

            // рисуем стены
            foreach (var edge in EdgeData.CurrentFloorWalls)
            {
                canvas.DrawLine((float)edge.PointFrom.X, (float)edge.PointFrom.Y,
                                (float)edge.PointTo.X, (float)edge.PointTo.Y, wallpaint);
            }

            // рисуем маршрут если есть
            foreach (var edge in EdgeData.Ways)
            {
                if (edge.PointFrom.Floor.Level == floor)
                {
                    canvas.DrawLine((float)edge.PointFrom.X, (float)edge.PointFrom.Y,
                                    (float)edge.PointTo.X, (float)edge.PointTo.Y, waypaint);
                }
            }

            // рисуем имена помещений
            foreach (var point in PointData.CurrentFloorRoomPoints)
            {
                if (point.Floor.Level == floor)
                {
                    canvas.Save();

                    #region textRotate
                    if (matrix.Values[0] > matrix.Values[1] &&
                        matrix.Values[4] > matrix.Values[3] &&
                        matrix.Values[0] > 0 && matrix.Values[1] > 0)
                    {
                        //  canvas.RotateDegrees(0, (float)point.X, (float)point.Y);
                    }
                    else if (matrix.Values[0] > matrix.Values[1] &&
                             matrix.Values[3] > matrix.Values[4] &&
                             matrix.Values[1] < 0 && matrix.Values[3] > 0)
                    {
                        canvas.RotateDegrees(270, (float)point.X, (float)point.Y);
                    }
                    else if (matrix.Values[0] < matrix.Values[1] &&
                             matrix.Values[3] < matrix.Values[4] &&
                             matrix.Values[2] > 0 && matrix.Values[3] < 0)
                    {
                        canvas.RotateDegrees(90, (float)point.X, (float)point.Y);
                    }
                    else if (matrix.Values[0] < matrix.Values[1] &&
                             matrix.Values[3] > matrix.Values[4] &&
                             matrix.Values[0] < 0 && matrix.Values[4] < 0)
                    {
                        canvas.RotateDegrees(180, (float)point.X, (float)point.Y);
                    }
                    #endregion

                    canvas.DrawText(point.Room.Name, (float)point.X, (float)point.Y, textpaint);

                    if (Client.isRoomFavoit(point.Room) != null)
                    {
                        canvas.DrawText("⭐", (float)point.X, (float)point.Y + 42, starpaint);
                    }

                    canvas.Restore();
                }
            }

            canvas.Restore();
        }
Ejemplo n.º 12
0
        private void ReadElement(XElement e, SKCanvas canvas, SKPaint stroke, SKPaint fill)
        {
            if (e.Attribute("display")?.Value == "none")
            {
                return;
            }

            // transform matrix
            var transform = ReadTransform(e.Attribute("transform")?.Value ?? string.Empty);

            canvas.Save();
            canvas.Concat(ref transform);

            // clip-path
            var clipPath = ReadClipPath(e.Attribute("clip-path")?.Value ?? string.Empty);

            if (clipPath != null)
            {
                canvas.ClipPath(clipPath);
            }

            // SVG element
            var elementName = e.Name.LocalName;
            var isGroup     = elementName == "g";

            // read style
            var style = ReadPaints(e, ref stroke, ref fill, isGroup);

            // parse elements
            switch (elementName)
            {
            case "image":
            {
                var image = ReadImage(e);
                if (image.Bytes != null)
                {
                    using (var bitmap = SKBitmap.Decode(image.Bytes))
                    {
                        if (bitmap != null)
                        {
                            canvas.DrawBitmap(bitmap, image.Rect);
                        }
                    }
                }
                break;
            }

            case "text":
                if (stroke != null || fill != null)
                {
                    var spans = ReadText(e, stroke?.Clone(), fill?.Clone());
                    if (spans.Any())
                    {
                        canvas.DrawText(spans);
                    }
                }
                break;

            case "rect":
            case "ellipse":
            case "circle":
            case "path":
            case "polygon":
            case "polyline":
            case "line":
                if (stroke != null || fill != null)
                {
                    var elementPath = ReadElement(e);
                    if (elementPath != null)
                    {
                        if (fill != null)
                        {
                            canvas.DrawPath(elementPath, fill);
                        }
                        if (stroke != null)
                        {
                            canvas.DrawPath(elementPath, stroke);
                        }
                    }
                }
                break;

            case "g":
                if (e.HasElements)
                {
                    // get current group opacity
                    float groupOpacity = ReadOpacity(style);
                    if (groupOpacity != 1.0f)
                    {
                        var opacity      = (byte)(255 * groupOpacity);
                        var opacityPaint = new SKPaint {
                            Color = SKColors.Black.WithAlpha(opacity)
                        };

                        // apply the opacity
                        canvas.SaveLayer(opacityPaint);
                    }

                    foreach (var gElement in e.Elements())
                    {
                        ReadElement(gElement, canvas, stroke?.Clone(), fill?.Clone());
                    }

                    // restore state
                    if (groupOpacity != 1.0f)
                    {
                        canvas.Restore();
                    }
                }
                break;

            case "use":
                if (e.HasAttributes)
                {
                    var href = ReadHref(e);
                    if (href != null)
                    {
                        // TODO: copy/process other attributes

                        var x            = ReadNumber(e.Attribute("x"));
                        var y            = ReadNumber(e.Attribute("y"));
                        var useTransform = SKMatrix.MakeTranslation(x, y);

                        canvas.Save();
                        canvas.Concat(ref useTransform);

                        ReadElement(href, canvas, stroke?.Clone(), fill?.Clone());

                        canvas.Restore();
                    }
                }
                break;

            case "switch":
                if (e.HasElements)
                {
                    foreach (var ee in e.Elements())
                    {
                        var requiredFeatures   = ee.Attribute("requiredFeatures");
                        var requiredExtensions = ee.Attribute("requiredExtensions");
                        var systemLanguage     = ee.Attribute("systemLanguage");

                        // TODO: evaluate requiredFeatures, requiredExtensions and systemLanguage
                        var isVisible =
                            requiredFeatures == null &&
                            requiredExtensions == null &&
                            systemLanguage == null;

                        if (isVisible)
                        {
                            ReadElement(ee, canvas, stroke?.Clone(), fill?.Clone());
                        }
                    }
                }
                break;

            case "defs":
            case "title":
            case "desc":
            case "description":
                // already read earlier
                break;

            default:
                LogOrThrow($"SVG element '{elementName}' is not supported");
                break;
            }

            // restore matrix
            canvas.Restore();
        }
Ejemplo n.º 13
0
        public void Concat(Matrix matrix)
        {
            var m = ((Matrix)matrix).SKMatrix;

            _canvas.Concat(ref m);
        }