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.MakeScale(2 * blockSize, blockSize); // each row, move across a bit / offset SKMatrix.PreConcat(ref offsetMatrix, SKMatrix.MakeSkew(0.5f, 0)); // create the paint var paint = new SKPaint(); paint.PathEffect = SKPathEffect.Create2DPath(offsetMatrix, path); paint.Color = SKColors.LightGray; // draw a rectangle canvas.DrawRect(SKRect.Create(width, height), paint); }
private void DrawTransparencyBackground(SKCanvas canvas, int width, int height, float scale) { var blockSize = BaseBlockSize * scale; var offsetMatrix = SKMatrix.MakeScale(2 * blockSize, blockSize); var skewMatrix = SKMatrix.MakeSkew(0.5f, 0); SKMatrix.PreConcat(ref offsetMatrix, ref skewMatrix); using (var path = new SKPath()) using (var paint = new SKPaint()) { path.AddRect(SKRect.Create(blockSize / -2, blockSize / -2, blockSize, blockSize)); paint.PathEffect = SKPathEffect.Create2DPath(offsetMatrix, path); paint.Color = AlternatePaneColor; canvas.DrawRect(SKRect.Create(width + blockSize, height + blockSize), paint); } }
public static SKMatrix BuildTransformMatrix(string Transform) { var Output = SKMatrix.MakeIdentity(); char[] delim = { ',', ' ', '(', ')' }; var v_s = Transform.Split(delim, StringSplitOptions.RemoveEmptyEntries); if (v_s.Length == 0) { throw (new Exception("Malformed transform.")); } //Get the name of the transform type int i = 0; var Type = v_s[i++].ToLower(); //Switch to correct transform type switch (Type) { case "matrix": var a = float.Parse(v_s[i++]); var b = float.Parse(v_s[i++]); var c = float.Parse(v_s[i++]); var d = float.Parse(v_s[i++]); var e = float.Parse(v_s[i++]); var f = float.Parse(v_s[i++]); Output.ScaleX = a; Output.ScaleY = d; Output.SkewX = c; Output.SkewY = b; Output.TransX = e; Output.TransY = f; break; case "translate": var tx = float.Parse(v_s[i++]); var ty = 0.0f; if (i < v_s.Length) { ty = float.Parse(v_s[i++]); } // Output = SKMatrix.MakeTranslation(tx, ty); break; case "scale": var sx = float.Parse(v_s[i++]); var sy = 0.0f; if (i < v_s.Length) { sy = float.Parse(v_s[i++]); } // Output = SKMatrix.MakeScale(sx, sy); break; case "rotate": // var angle = float.Parse(v_s[i++]); // var cx = 0.0f; if (i < v_s.Length) { cx = float.Parse(v_s[i++]); } // var cy = 0.0f; if (i < v_s.Length) { cy = float.Parse(v_s[i++]); } // Output = SKMatrix.MakeRotationDegrees(angle, cx, cy); break; case "skewX": var sk_x_angle = float.Parse(v_s[i++]); var anglx_radians = ((float)Math.PI / 180.0f) * sk_x_angle; Output = SKMatrix.MakeSkew((float)Math.Tan(anglx_radians), 0); break; case "skewY": var sk_y_angle = float.Parse(v_s[i++]); var angly_radians = ((float)Math.PI / 180.0f) * sk_y_angle; Output = SKMatrix.MakeSkew(0, (float)Math.Tan(angly_radians)); break; } ; // SVG always have these settings Output.Persp0 = 0; Output.Persp1 = 0; Output.Persp2 = 1; return(Output); }
public static SKMatrix ToSKMatrix(this SvgTransformCollection svgTransformCollection) { var skMatrixTotal = SKMatrix.MakeIdentity(); if (svgTransformCollection == null) { return(skMatrixTotal); } foreach (var svgTransform in svgTransformCollection) { switch (svgTransform) { case SvgMatrix svgMatrix: { var skMatrix = svgMatrix.ToSKMatrix(); SKMatrix.PreConcat(ref skMatrixTotal, ref skMatrix); } break; case SvgRotate svgRotate: { var skMatrixRotate = SKMatrix.MakeRotationDegrees(svgRotate.Angle, svgRotate.CenterX, svgRotate.CenterY); SKMatrix.PreConcat(ref skMatrixTotal, ref skMatrixRotate); } break; case SvgScale svgScale: { var skMatrixScale = SKMatrix.MakeScale(svgScale.X, svgScale.Y); SKMatrix.PreConcat(ref skMatrixTotal, ref skMatrixScale); } break; case SvgShear svgShear: { // Not in the svg specification. } break; case SvgSkew svgSkew: { float sx = (float)Math.Tan(Math.PI * svgSkew.AngleX / 180); float sy = (float)Math.Tan(Math.PI * svgSkew.AngleY / 180); var skMatrixSkew = SKMatrix.MakeSkew(sx, sy); SKMatrix.PreConcat(ref skMatrixTotal, ref skMatrixSkew); } break; case SvgTranslate svgTranslate: { var skMatrixTranslate = SKMatrix.MakeTranslation(svgTranslate.X, svgTranslate.Y); SKMatrix.PreConcat(ref skMatrixTotal, ref skMatrixTranslate); } break; default: break; } } return(skMatrixTotal); }
public void Shear(float sx, float sy) { var m = SKMatrix.MakeSkew(sx, sy); SKMatrix.PreConcat(ref _m, ref m); }