示例#1
0
        private static SKMatrix CreateRotationMatrix(IReadOnlyViewport viewport, BoundingBox boundingBox, SKMatrix priorMatrix)
        {
            SKMatrix matrix = SKMatrix.MakeIdentity();

            // The front-end sets up the canvas with a matrix based on screen scaling (e.g. retina).
            // We need to retain that effect by combining our matrix with the incoming matrix.

            // We'll create four matrices in addition to the incoming matrix. They perform the
            // zoom scale, focal point offset, user rotation and finally, centering in the screen.

            var userRotation     = SKMatrix.MakeRotationDegrees((float)viewport.Rotation);
            var focalPointOffset = SKMatrix.MakeTranslation(
                (float)(boundingBox.Left - viewport.Center.X),
                (float)(viewport.Center.Y - boundingBox.Top));
            var zoomScale      = SKMatrix.MakeScale((float)(1.0 / viewport.Resolution), (float)(1.0 / viewport.Resolution));
            var centerInScreen = SKMatrix.MakeTranslation((float)(viewport.Width / 2.0), (float)(viewport.Height / 2.0));

            // We'll concatenate them like so: incomingMatrix * centerInScreen * userRotation * zoomScale * focalPointOffset

            SKMatrix.Concat(ref matrix, zoomScale, focalPointOffset);
            SKMatrix.Concat(ref matrix, userRotation, matrix);
            SKMatrix.Concat(ref matrix, centerInScreen, matrix);
            SKMatrix.Concat(ref matrix, priorMatrix, matrix);

            return(matrix);
        }
示例#2
0
        public Symbol(SvgSymbol svgSymbol)
        {
            x      = 0f;
            y      = 0f;
            width  = svgSymbol.ViewBox.Width;
            height = svgSymbol.ViewBox.Height;

            if (svgSymbol.CustomAttributes.TryGetValue("width", out string _widthString))
            {
                if (new SvgUnitConverter().ConvertFrom(_widthString) is SvgUnit _width)
                {
                    width = _width.ToDeviceValue(null, UnitRenderingType.Horizontal, svgSymbol);
                }
            }

            if (svgSymbol.CustomAttributes.TryGetValue("height", out string heightString))
            {
                if (new SvgUnitConverter().ConvertFrom(heightString) is SvgUnit _height)
                {
                    height = _height.ToDeviceValue(null, UnitRenderingType.Vertical, svgSymbol);
                }
            }

            bounds = SKRect.Create(x, y, width, height);

            matrix = SvgHelper.GetSKMatrix(svgSymbol.Transforms);
            var viewBoxMatrix = SvgHelper.GetSvgViewBoxTransform(svgSymbol.ViewBox, svgSymbol.AspectRatio, x, y, width, height);

            SKMatrix.Concat(ref matrix, ref matrix, ref viewBoxMatrix);
        }
示例#3
0
        public override void DrawBound(SKRect boundingRect, SKCanvas canvas)
        {
            SKMatrix scaleMatrix = SKMatrix.MakeScale(1, 1);
            //// Gum uses counter clockwise rotation, Skia uses clockwise, so invert:
            SKMatrix rotationMatrix  = SKMatrix.MakeRotationDegrees(-Rotation);
            SKMatrix translateMatrix = SKMatrix.MakeTranslation(this.GetAbsoluteX(), this.GetAbsoluteY());
            SKMatrix result          = SKMatrix.MakeIdentity();

            SKMatrix.Concat(
                ref result, rotationMatrix, scaleMatrix);
            SKMatrix.Concat(
                ref result, translateMatrix, result);
            canvas.Save();
            canvas.SetMatrix(result);


            SKPath path = new SKPath();

            path.MoveTo(Points[0]);

            for (int i = 0; i < Points.Count; i++)
            {
                path.LineTo(Points[i]);
            }
            path.LineTo(Points[0]);

            path.Close();
            using (var paintToUse = paint)
            {
                canvas.DrawPath(path, paintToUse);
            }

            canvas.Restore();
        }
示例#4
0
        public void Render(SKCanvas canvas)
        {
            if (AbsoluteVisible)
            {
                var textureBox    = Texture.ViewBox;
                var textureWidth  = textureBox.Width;
                var textureHeight = textureBox.Height;

                var scaleX = this.Width / textureWidth;
                var scaleY = this.Height / textureHeight;

                SKMatrix scaleMatrix = SKMatrix.MakeScale(scaleX, scaleY);
                // Gum uses counter clockwise rotation, Skia uses clockwise, so invert:
                SKMatrix rotationMatrix  = SKMatrix.MakeRotationDegrees(-Rotation);
                SKMatrix translateMatrix = SKMatrix.MakeTranslation(this.GetAbsoluteX(), this.GetAbsoluteY());
                SKMatrix result          = SKMatrix.MakeIdentity();

                SKMatrix.Concat(
                    ref result, rotationMatrix, scaleMatrix);
                SKMatrix.Concat(
                    ref result, translateMatrix, result);

                canvas.DrawPicture(Texture.Picture, ref result);
            }
        }
示例#5
0
        public void Pinch(GestureState state, float scale, SKPoint origin)
        {
            switch (state)
            {
            case GestureState.Started:
                startPinchMatrix = Matrix;
                startPinchOrigin = origin;
                totalPinchScale  = 1f;
                break;

            case GestureState.Running:
                totalPinchScale *= scale;
                var pinchTranslation  = origin - startPinchOrigin;
                var canvasTranslation = SKMatrix.MakeTranslation(pinchTranslation.X, pinchTranslation.Y);
                var canvasScaling     = SKMatrix.MakeScale(totalPinchScale, totalPinchScale, origin.X, origin.Y);
                var canvasCombined    = SKMatrix.MakeIdentity();
                SKMatrix.Concat(ref canvasCombined, ref canvasScaling, ref canvasTranslation);
                SKMatrix.Concat(ref Matrix, ref canvasCombined, ref startPinchMatrix);
                break;

            default:
                startPinchMatrix = SKMatrix.MakeIdentity();
                startPinchOrigin = SKPoint.Empty;
                totalPinchScale  = 1f;
                break;
            }
        }
示例#6
0
        static SKMatrix Multiply(SKMatrix first, SKMatrix second)
        {
            SKMatrix target = SKMatrix.CreateIdentity();

            SKMatrix.Concat(ref target, first, second);
            return(target);
        }
示例#7
0
        /// <inheritdoc />
        public override void Render(SKCanvas canvas, SKRect bounds, SKPaint paint)
        {
            _lastBounds = bounds;

            // For brevity's sake
            ColorGradient gradient = Properties.Colors.BaseValue;

            SKMatrix matrix = SKMatrix.Concat(
                SKMatrix.CreateRotationDegrees(Properties.Rotation, bounds.MidX, bounds.MidY),
                SKMatrix.CreateTranslation(_scrollX, _scrollY)
                );

            // LinearGradientRepeatMode.Mirror is currently the only setting that requires a different tile mode
            SKShaderTileMode tileMode = Properties.RepeatMode.CurrentValue == LinearGradientRepeatMode.Mirror
                ? SKShaderTileMode.Mirror
                : SKShaderTileMode.Repeat;

            // Render gradient
            paint.Shader = SKShader.CreateLinearGradient(
                new SKPoint(bounds.Left, bounds.Top),
                new SKPoint(
                    (Properties.Orientation == LinearGradientOrientationMode.Horizontal ? bounds.Right : bounds.Left) * Properties.WaveSize / 100,
                    (Properties.Orientation == LinearGradientOrientationMode.Horizontal ? bounds.Top : bounds.Bottom) * Properties.WaveSize / 100
                    ),
                gradient.GetColorsArray(0, Properties.RepeatMode.CurrentValue == LinearGradientRepeatMode.RepeatSeamless),
                gradient.GetPositionsArray(0, Properties.RepeatMode.CurrentValue == LinearGradientRepeatMode.RepeatSeamless),
                tileMode,
                matrix
                );

            canvas.DrawRect(bounds, paint);
            paint.Shader?.Dispose();
            paint.Shader = null;
        }
        static SKMatrix Multiply(SKMatrix first, SKMatrix second)
        {
            SKMatrix target;

            SKMatrix.Concat(ref target, first, second);
            return(target);
        }
        private void HandlePan(object sender, PanUpdatedEventArgs puea)
        {
            Debug.WriteLine($"{puea.StatusType} ({puea.TotalX},{puea.TotalY})");

            switch (puea.StatusType)
            {
            case GestureStatus.Started:
                _startPanM = _m;
                break;

            case GestureStatus.Running:
                float    canvasTotalX      = (float)puea.TotalX * _screenScale;
                float    canvasTotalY      = (float)puea.TotalY * _screenScale;
                SKMatrix canvasTranslation = SKMatrix.MakeTranslation(canvasTotalX, canvasTotalY);
                SKMatrix.Concat(ref _m, ref canvasTranslation, ref _startPanM);
                _currentTransformM = canvasTranslation;
                _canvasV.InvalidateSurface();
                break;

            default:
                _startPanM = SKMatrix.MakeIdentity();

                // force textLayer to regenerate
                _textLayer?.Dispose();
                _textLayer = null;
                _canvasV.InvalidateSurface();
                break;
            }
        }
示例#10
0
        protected override void OnDrawSample(SKCanvas canvas, int width, int height)
        {
            canvas.Clear(SKColors.White);

            var blockSize = 30;

            // create the path
            var path = new SKPath();
            // the rect must be offset as the path uses the center
            var rect = SKRect.Create(blockSize / -2, blockSize / -2, blockSize, blockSize);

            path.AddRect(rect);

            // move the path around: across 1 block
            var offsetMatrix = SKMatrix.CreateScale(2 * blockSize, blockSize);

            // each row, move across a bit / offset
            offsetMatrix = SKMatrix.Concat(offsetMatrix, SKMatrix.CreateSkew(0.5f, 0));

            // create the paint
            var paint = new SKPaint
            {
                PathEffect = SKPathEffect.Create2DPath(offsetMatrix, path),
                Color      = SKColors.LightGray
            };

            // draw a rectangle
            canvas.DrawRect(SKRect.Create(width + blockSize, height + blockSize), paint);
        }
示例#11
0
        /// <summary>
        /// Configure paint wrapper for using tile brush.
        /// </summary>
        /// <param name="paintWrapper">Paint wrapper.</param>
        /// <param name="targetSize">Target size.</param>
        /// <param name="tileBrush">Tile brush to use.</param>
        /// <param name="tileBrushImage">Tile brush image.</param>
        private void ConfigureTileBrush(ref PaintWrapper paintWrapper, Size targetSize, ITileBrush tileBrush, IDrawableBitmapImpl tileBrushImage)
        {
            var calc         = new TileBrushCalculator(tileBrush, tileBrushImage.PixelSize.ToSizeWithDpi(_dpi), targetSize);
            var intermediate = CreateRenderTarget(calc.IntermediateSize);

            paintWrapper.AddDisposable(intermediate);

            using (var context = intermediate.CreateDrawingContext(null))
            {
                var sourceRect = new Rect(tileBrushImage.PixelSize.ToSizeWithDpi(96));
                var targetRect = new Rect(tileBrushImage.PixelSize.ToSizeWithDpi(_dpi));

                context.Clear(Colors.Transparent);
                context.PushClip(calc.IntermediateClip);
                context.Transform = calc.IntermediateTransform;
                context.DrawBitmap(
                    RefCountable.CreateUnownedNotClonable(tileBrushImage),
                    1,
                    sourceRect,
                    targetRect,
                    tileBrush.BitmapInterpolationMode);
                context.PopClip();
            }

            var tileTransform =
                tileBrush.TileMode != TileMode.None
                    ? SKMatrix.CreateTranslation(-(float)calc.DestinationRect.X, -(float)calc.DestinationRect.Y)
                    : SKMatrix.CreateIdentity();

            SKShaderTileMode tileX =
                tileBrush.TileMode == TileMode.None
                    ? SKShaderTileMode.Clamp
                    : tileBrush.TileMode == TileMode.FlipX || tileBrush.TileMode == TileMode.FlipXY
                        ? SKShaderTileMode.Mirror
                        : SKShaderTileMode.Repeat;

            SKShaderTileMode tileY =
                tileBrush.TileMode == TileMode.None
                    ? SKShaderTileMode.Clamp
                    : tileBrush.TileMode == TileMode.FlipY || tileBrush.TileMode == TileMode.FlipXY
                        ? SKShaderTileMode.Mirror
                        : SKShaderTileMode.Repeat;


            var image = intermediate.SnapshotImage();

            paintWrapper.AddDisposable(image);

            var paintTransform = default(SKMatrix);

            SKMatrix.Concat(
                ref paintTransform,
                tileTransform,
                SKMatrix.CreateScale((float)(96.0 / _dpi.X), (float)(96.0 / _dpi.Y)));

            using (var shader = image.ToShader(tileX, tileY, paintTransform))
            {
                paintWrapper.Paint.Shader = shader;
            }
        }
示例#12
0
    private void SaveVector(Shape shape)
    {
        var svg = new SkiaSharp.Extended.Svg.SKSvg();

        svg.Load(shape.OutputPath);

        var svgRect = svg.Picture.CullRect;

        var(w, h) = CalculateResized((int)svgRect.Width, (int)svgRect.Height);
        float svgMax = Math.Max(w, h);

        float scale   = w / svgRect.Width;
        var   matrixS = SKMatrix.MakeScale(scale, scale);
        var   matrixT = SKMatrix.MakeTranslation((MAX_SIZE - w) / 2, (MAX_SIZE - h) / 2);
        var   matrix  = SKMatrix.MakeIdentity();

        SKMatrix.Concat(ref matrix, matrixT, matrixS);

        var target = new SKBitmap(MAX_SIZE, MAX_SIZE,
                                  SKImageInfo.PlatformColorType, SKAlphaType.Premul);

        using (target)
            using (var canvas = new SKCanvas(target))
            {
                canvas.Clear();
                canvas.DrawPicture(svg.Picture, ref matrix, _skPaint);
                SaveToFile(shape.Id, "svg", target);
            }
    }
示例#13
0
        public virtual IElement GetElementAtPoint(SKPoint point, Func <IElement, bool> predicate, SKMatrix transformStack)
        {
            IList <IElement> items;

            if (predicate != null)
            {
                items = Children.Where(predicate).ToList();
            }
            else
            {
                items = Children;
            }
            var childrenStack = transformStack.Concat(this._childrenVisualTransform);

            for (int i = items.Count - 1; i >= 0; i--)
            {
                var element = items[i];
                if (element.IsPointInside(point, childrenStack))
                {
                    var subElement = element.GetElementAtPoint(point, predicate, childrenStack);
                    if (subElement != null)
                    {
                        return(subElement);
                    }
                    else
                    {
                        return(element);
                    }
                }
            }
            return(null);
        }
示例#14
0
        public void MatrixCanConcat()
        {
            var a = SKMatrix.CreateTranslation(10, 20);
            var b = SKMatrix.CreateTranslation(5, 7);

            var c = SKMatrix.Concat(a, b);

            Assert.Equal(SKMatrix.CreateTranslation(15, 27).Values, c.Values);
        }
示例#15
0
        public void MatrixCanConcat()
        {
            var a = SKMatrix.MakeTranslation(10, 20);
            var b = SKMatrix.MakeTranslation(5, 7);
            var c = new SKMatrix();

            SKMatrix.Concat(ref c, ref a, ref b);

            Assert.Equal(SKMatrix.MakeTranslation(15, 27).Values, c.Values);
        }
示例#16
0
        private void DoPanZoom(SKMatrix startM, SKPoint anchorPt, SKPoint totalTranslation, double totalScale)
        {
            SKPoint  canvasAnchorPt         = new SKPoint(anchorPt.X * _screenScale, anchorPt.Y * _screenScale);
            SKPoint  totalCanvasTranslation = new SKPoint(totalTranslation.X * _screenScale, totalTranslation.Y * _screenScale);
            SKMatrix canvasTranslation      = SKMatrix.MakeTranslation((float)totalCanvasTranslation.X, (float)totalCanvasTranslation.Y);
            SKMatrix canvasScaling          = SKMatrix.MakeScale((float)totalScale, (float)totalScale, (float)canvasAnchorPt.X, (float)canvasAnchorPt.Y);
            SKMatrix canvasCombined         = SKMatrix.MakeIdentity();

            SKMatrix.Concat(ref canvasCombined, ref canvasTranslation, ref canvasScaling);
            SKMatrix.Concat(ref _m, ref canvasCombined, ref startM);
            CanvasView.SetNeedsDisplayInRect(CanvasView.Bounds);
        }
        public ZoomCanvas()
        {
            overlaySurface.TransformationPivot = SKPoint.Empty;
            overlaySurface.AttachParent(this);
            this.GestureRecognizers.Add(panGesture);
            panGesture.PanUpdated += PanGesture_PanUpdated;

            this.GestureRecognizers.Add(pinchGesture);
            pinchGesture.PinchUpdated += OnPinchUpdated;
            ZoomCommand = new Command(o =>
            {
                float scaleFactor = 0;
                if (o is string)
                {
                    scaleFactor = float.Parse((string)o, CultureInfo.InvariantCulture);
                }
                else
                {
                    scaleFactor = Convert.ToSingle(o);
                }
                scaleTransformation    = SKMatrix.MakeScale((float)scaleFactor, (float)scaleFactor);
                surface.Transformation = translateTransformation.Concat(scaleTransformation);
            });
            IncrementalZoomCommand = new Command(o =>
            {
                float scaleFactor = 0;
                if (o is string)
                {
                    scaleFactor = float.Parse((string)o, CultureInfo.InvariantCulture);
                }
                else
                {
                    scaleFactor = Convert.ToSingle(o);
                }
                scaleTransformation = scaleTransformation
                                      .Scale(scaleFactor, scaleFactor);
                surface.Transformation = translateTransformation.Concat(scaleTransformation);
            });
        }
示例#18
0
        public override void Preroll(PrerollContext context, SKMatrix matrix)
        {
            SKMatrix child_matrix = new SKMatrix();

            SKMatrix.Concat(ref child_matrix, matrix, transform_);

            SKRect child_paint_bounds = SKRect.Empty;

            PrerollChildren(context, child_matrix, ref child_paint_bounds);

            transform_.MapRect(child_paint_bounds);
            set_paint_bounds(child_paint_bounds);
        }
示例#19
0
        public Fragment(SvgFragment svgFragment)
        {
            x      = svgFragment.X.ToDeviceValue(null, UnitRenderingType.Horizontal, svgFragment);
            y      = svgFragment.Y.ToDeviceValue(null, UnitRenderingType.Vertical, svgFragment);
            width  = svgFragment.Width.ToDeviceValue(null, UnitRenderingType.Horizontal, svgFragment);
            height = svgFragment.Height.ToDeviceValue(null, UnitRenderingType.Vertical, svgFragment);
            bounds = SKRect.Create(x, y, width, height);

            matrix = SvgHelper.GetSKMatrix(svgFragment.Transforms);
            var viewBoxMatrix = SvgHelper.GetSvgViewBoxTransform(svgFragment.ViewBox, svgFragment.AspectRatio, x, y, width, height);

            SKMatrix.Concat(ref matrix, ref matrix, ref viewBoxMatrix);
        }
示例#20
0
        private void CanvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            SKMatrix.Concat(ref currentmatrix, translationMatrix, startMatrix);
            canvas.SetMatrix(currentmatrix);
            canvas.Clear();
            if (pageBitmap != null)
            {
                canvas.DrawBitmap(pageBitmap, 0, 0);
            }
        }
        private void OnRendering(object sender, SKNativePaintGLSurfaceEventArgs e)
        {
            _shouldRender = false;
            var surface = e.Surface;
            var canvas  = surface.Canvas;

            var worldMatrix = SKMatrix.MakeIdentity();

            // Apply DPI scaling.
            SKMatrix.Concat(ref worldMatrix, worldMatrix, SKMatrix.MakeScale(ScaleFactor, ScaleFactor));

            canvas.ResetMatrix();
            canvas.SetMatrix(worldMatrix);

            Draw?.Invoke(this, e.Surface);
        }
示例#22
0
        public static SKMatrix ToSKMatrix(this IViewport viewport)
        {
            var mapCenterX         = (float)viewport.Width * 0.5f;
            var mapCenterY         = (float)viewport.Height * 0.5f;
            var invertedResolution = 1f / (float)viewport.Resolution;

            var matrix = SKMatrix.CreateScale(invertedResolution, invertedResolution, mapCenterX, mapCenterY);

            matrix = SKMatrix.Concat(matrix, SKMatrix.CreateScale(1, -1, 0, -mapCenterY)); // As a consequence images will be up side down :(
            if (viewport.IsRotated)
            {
                matrix = SKMatrix.Concat(matrix, SKMatrix.CreateRotationDegrees((float)-viewport.Rotation));
            }
            matrix = SKMatrix.Concat(matrix, SKMatrix.CreateTranslation((float)-viewport.Center.X, (float)-viewport.Center.Y));
            return(matrix);
        }
示例#23
0
        private void CanvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            InputManager.EpxToPxCoefficient = (float)(CanvasView.CanvasSize.Height / CanvasView.RenderSize.Height);
            var paint = new SKPaint
            {
                Color       = SKColors.Black,
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                TextAlign   = SKTextAlign.Center,
                TextSize    = 24
            };

            e.Surface.Canvas.DrawColor(new SKColor(255, 0, 0));
            e.Surface.Canvas.DrawText("SkiaSharp", new SKPoint(500, 500), paint);
            SKSurface surface = e.Surface;
            SKCanvas  canvas  = surface.Canvas;

            _CanvasInfoProvider.Canvas = canvas;
            canvas.Clear(SKColors.DarkBlue);
            if (_FirstFrame)
            {
                _ControlPanel.Start();
                _FirstFrame = false;
            }
            SkiaBehaviourEngine.Update();
            _ControlPanel.Update();

            SKMatrix m1 = new SKMatrix();

            m1.Values = new float[] { 1, 1, 0, 0, 1, 0, 0, 0, 1 };
            SKMatrix m2 = new SKMatrix
            {
                Values = new float[] { 1, 0, 1, 0, 1, 0, 0, 0, 1 }
            };
            SKMatrix m3 = new SKMatrix();

            SKMatrix.Concat(ref m3, m1, m2);
            string s = "";

            for (int i = 0; i < m3.Values.Length; i++)
            {
                s += m3.Values[i];
                s += ", ";
            }
            System.Diagnostics.Debug.WriteLine(s);
        }
        private void Transform(SKPoint positionScreen, SKPoint previousPositionScreen, float scaleDelta, float rotationDelta)
        {
            var positionDelta = positionScreen - previousPositionScreen;

            if (!positionDelta.IsEmpty)
            {
                totalTranslate += positionDelta;
                var m = SKMatrix.MakeTranslation(positionDelta.X, positionDelta.Y);
                SKMatrix.Concat(ref totalMatrix, ref m, ref totalMatrix);
            }

            if (scaleDelta != 1)
            {
                if (totalScale * scaleDelta > MaxScale)
                {
                    scaleDelta = MaxScale / totalScale;
                }
                if (totalScale * scaleDelta < MinScale)
                {
                    scaleDelta = MinScale / totalScale;
                }

                totalScale *= scaleDelta;
                var m = SKMatrix.MakeScale(scaleDelta, scaleDelta, positionScreen.X, positionScreen.Y);
                SKMatrix.Concat(ref totalMatrix, ref m, ref totalMatrix);
            }

            if (rotationDelta != 0)
            {
                if (totalRotation + rotationDelta > MaxRotation)
                {
                    rotationDelta = MaxRotation - totalRotation;
                }
                if (totalRotation + rotationDelta < MinRotation)
                {
                    rotationDelta = MinRotation - totalRotation;
                }

                totalRotation += rotationDelta;
                var m = SKMatrix.MakeRotationDegrees(rotationDelta, positionScreen.X, positionScreen.Y);
                SKMatrix.Concat(ref totalMatrix, ref m, ref totalMatrix);
            }

            gestureSurface.InvalidateSurface();
        }
示例#25
0
        public void Pan(GestureState state, SKPoint translation)
        {
            switch (state)
            {
            case GestureState.Started:
                startPanMatrix = Matrix;
                break;

            case GestureState.Running:
                var canvasTranslation = SKMatrix.MakeTranslation(translation.X, translation.Y);
                SKMatrix.Concat(ref Matrix, ref canvasTranslation, ref startPanMatrix);
                break;

            default:
                startPanMatrix = SKMatrix.MakeIdentity();
                break;
            }
        }
示例#26
0
        /// <inheritdoc />
        public override void Render(SKCanvas canvas, SKRect bounds, SKPaint paint)
        {
            SKMatrix matrix = SKMatrix.Concat(
                SKMatrix.CreateTranslation(_scrollX, _scrollY),
                SKMatrix.CreateRotationDegrees(Properties.Rotation, bounds.MidX, bounds.MidY)
                );

            paint.Shader = SKShader.CreateLinearGradient(
                new SKPoint(bounds.Left, bounds.Top),
                new SKPoint(bounds.Right, bounds.Top),
                Properties.Colors.BaseValue.GetColorsArray(Properties.ColorsMultiplier),
                Properties.Colors.BaseValue.GetPositionsArray(Properties.ColorsMultiplier),
                SKShaderTileMode.Repeat,
                matrix
                );
            canvas.DrawRect(bounds, paint);
            paint.Shader?.Dispose();
            paint.Shader = null;
        }
示例#27
0
文件: Use.cs 项目: Monkeybin11/Draw2D
        public Use(SvgUse svgUse, SvgVisualElement svgVisualElement)
        {
            matrix = SvgHelper.GetSKMatrix(svgUse.Transforms);

            float x = svgUse.X.ToDeviceValue(null, UnitRenderingType.Horizontal, svgUse);
            float y = svgUse.Y.ToDeviceValue(null, UnitRenderingType.Vertical, svgUse);

            var skMatrixTranslateXY = SKMatrix.MakeTranslation(x, y);

            SKMatrix.Concat(ref matrix, ref matrix, ref skMatrixTranslateXY);

            var ew = svgUse.Width.ToDeviceValue(null, UnitRenderingType.Horizontal, svgUse);
            var eh = svgUse.Height.ToDeviceValue(null, UnitRenderingType.Vertical, svgUse);

            if (ew > 0 && eh > 0)
            {
                var _attributes = svgVisualElement.GetType().GetField("_attributes", BindingFlags.NonPublic | BindingFlags.Instance);
                if (_attributes != null)
                {
                    var attributes = _attributes.GetValue(svgVisualElement) as SvgAttributeCollection;
                    if (attributes != null)
                    {
                        var viewBox = attributes.GetAttribute <SvgViewBox>("viewBox");
                        //var viewBox = svgVisualElement.Attributes.GetAttribute<SvgViewBox>("viewBox");
                        if (viewBox != SvgViewBox.Empty && Math.Abs(ew - viewBox.Width) > float.Epsilon && Math.Abs(eh - viewBox.Height) > float.Epsilon)
                        {
                            var sw = ew / viewBox.Width;
                            var sh = eh / viewBox.Height;

                            var skMatrixTranslateSWSH = SKMatrix.MakeTranslation(sw, sh);
                            SKMatrix.Concat(ref matrix, ref matrix, ref skMatrixTranslateSWSH);
                        }
                    }
                }
                //else
                //{
                //    throw new Exception("Can not get 'use' referenced element transform.");
                //}
            }
        }
示例#28
0
        static SKMatrix ComputeMatrix(SKSize size, SKPoint ptUL, SKPoint ptUR, SKPoint ptLL)
        {
            // Scale transform
            SKMatrix S = SKMatrix.MakeScale(1 / size.Width, 1 / size.Height);

            // Affine transform
            SKMatrix A = new SKMatrix
            {
                ScaleX = ptUR.X - ptUL.X,
                SkewY  = ptUR.Y - ptUL.Y,
                SkewX  = ptLL.X - ptUL.X,
                ScaleY = ptLL.Y - ptUL.Y,
                TransX = ptUL.X,
                TransY = ptUL.Y,
                Persp2 = 1
            };

            SKMatrix result = SKMatrix.MakeIdentity();

            SKMatrix.Concat(ref result, A, S);
            return(result);
        }
示例#29
0
        public void Render(SKCanvas canvas)
        {
            if (AbsoluteVisible)
            {
                SKMatrix scaleMatrix = SKMatrix.MakeScale(1, 1);
                //// Gum uses counter clockwise rotation, Skia uses clockwise, so invert:
                SKMatrix rotationMatrix  = SKMatrix.MakeRotationDegrees(-Rotation);
                SKMatrix translateMatrix = SKMatrix.MakeTranslation(this.GetAbsoluteX(), this.GetAbsoluteY());
                SKMatrix result          = SKMatrix.MakeIdentity();

                SKMatrix.Concat(
                    ref result, rotationMatrix, scaleMatrix);
                SKMatrix.Concat(
                    ref result, translateMatrix, result);
                canvas.Save();
                canvas.SetMatrix(result);

                var destination = new SKRect(0, 0, Width, Height);

                canvas.DrawBitmap(Texture, destination);
                canvas.Restore();
            }
        }
示例#30
0
        /// <summary>Définit le modèle pour la définition de disposition de réorganisation au niveau du noyau WPF. </summary>
        /// <param name="finalRect">Zone finale dans le parent que cet élément doit utiliser pour se réorganiser et réorganiser ses éléments enfants.</param>
        protected virtual void ArrangeCore(SKRect finalRect)
        {
            CreateBounds(finalRect);

            if (NeverTransform || TransformationDirty)
            {
                computedTransformation = SKMatrix.MakeIdentity();
                if (Transformation.HasValue)
                {
                    var transformationPivot = this.TransformationPivot;
                    var tx = (boundsMinusMargin.Width * transformationPivot.X);
                    var ty = (boundsMinusMargin.Height * transformationPivot.Y);

                    var anchor  = SKMatrix.MakeTranslation(tx, ty);
                    var anchorN = SKMatrix.MakeTranslation(-tx, -ty);

                    computedTransformation = computedTransformation.Concat(anchor).Concat(Transformation.Value)
                                             .Concat(anchorN);
                }
            }

            this.VisualTransform = SKMatrix.MakeIdentity().Translate(boundsMinusMargin.Left, boundsMinusMargin.Top).Concat(computedTransformation);
        }