public void ParsePathReturnsValidPath() { // based on ParsePath foreach (var test in parsePathTestCases) { var path = SKPath.ParseSvgPathData(test.Item1); Assert.IsNotNull(path); Assert.AreEqual(test.Item2, path.Bounds); TestToFromSvgPath(path); } var r = SKRect.Create(0, 0, 10, 10.5f); using (var p = new SKPath()) { p.AddRect(r); TestToFromSvgPath(p); p.AddOval(r); TestToFromSvgPath(p); p.AddRoundedRect(r, 4, 4.5f); TestToFromSvgPath(p); } }
void PaintHeaderBar(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); SKPath path = new SKPath { FillType = SKPathFillType.EvenOdd }; path.AddRect(new SKRect(0, 0, info.Width, 8)); SKPaint paint = new SKPaint() { Style = SKPaintStyle.Fill, Color = new SKColor(0xFFE69A28) }; canvas.DrawPath(path, paint); paint.Style = SKPaintStyle.Stroke; paint.StrokeWidth = 2; paint.Color = SKColors.Black; canvas.DrawPath(path, paint); paint.Dispose(); path.Dispose(); }
/// <inheritdoc /> public override void CalculateRenderProperties() { SKPath path = new SKPath(); path.AddRect(SKRect.Create(Layer.Bounds.Width, Layer.Bounds.Height)); Path = path; }
private SKPath NonPathShapeToSkiaPath(IShape shape) { SKPath skPath = new SKPath(); if (shape is IRectangle rectangle) { SKRect skRect = SKRect.Create((float)rectangle.Left, (float)rectangle.Top, (float)rectangle.Width, (float)rectangle.Height); if (rectangle.RadiusX > 0 || rectangle.RadiusY > 0) { skPath.AddRoundRect(skRect, (float)rectangle.RadiusX, (float)rectangle.RadiusY); } else { skPath.AddRect(skRect); } } else if (shape is ILine line) { skPath.MoveTo((float)line.X1, (float)line.Y1); skPath.LineTo((float)line.X2, (float)line.Y2); } else if (shape is IEllipse ellipse) { SKRect skRect = SKRect.Create((float)ellipse.Left, (float)ellipse.Top, (float)ellipse.Width, (float)ellipse.Height); skPath.AddOval(skRect); } return(skPath); }
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); }
public override void PreProcess(SKCanvas canvas, SKRect bounds, SKPaint paint) { // TODO: Lets see whether we can tell Artemis we only support layers if (ProfileElement is not Layer layer || !layer.Leds.Any()) { return; } // Find out how many LEDs to reveal according to the current percentage int toReveal = Properties.RoundingFunction.CurrentValue switch { RoundingFunction.Round => (int)Math.Round(layer.Leds.Count / 100.0 * Math.Min(100, Properties.Percentage.CurrentValue), MidpointRounding.AwayFromZero), RoundingFunction.Floor => (int)Math.Floor(layer.Leds.Count / 100.0 * Math.Min(100, Properties.Percentage.CurrentValue)), RoundingFunction.Ceiling => (int)Math.Ceiling(layer.Leds.Count / 100.0 * Math.Min(100, Properties.Percentage.CurrentValue)), _ => throw new ArgumentOutOfRangeException() }; // If the amount hasn't changed, reuse the last path if (toReveal == _lastToReveal && Properties.MaxVisibleLeds == _lastMaxVisible && _clipPath != null) { canvas.ClipPath(_clipPath); return; } // Order LEDs by their position to create a nice revealing effect from left top right, top to bottom List <ArtemisLed> leds = layer.Leds.OrderBy(l => l.AbsoluteRectangle.Top).ThenBy(l => l.AbsoluteRectangle.Left).ToList(); // Because rendering for effects is 0,0 based, zero out the position of LEDs starting at the top-left float offsetX = leds.First().AbsoluteRectangle.Left; float offsetY = leds.First().AbsoluteRectangle.Top; // Create or reset the path if (_clipPath == null) { _clipPath = new SKPath(); } else { _clipPath.Reset(); } IEnumerable <ArtemisLed> ledsEnumerable = leds.Take(toReveal); if (Properties.LimitVisibleLeds) { ledsEnumerable = ledsEnumerable.Skip(toReveal - Properties.MaxVisibleLeds); } foreach (ArtemisLed artemisLed in ledsEnumerable) { _clipPath.AddRect(SKRect.Create( artemisLed.AbsoluteRectangle.Left - offsetX, artemisLed.AbsoluteRectangle.Top - offsetY, artemisLed.AbsoluteRectangle.Width, artemisLed.AbsoluteRectangle.Height)); } canvas.ClipPath(_clipPath); _lastMaxVisible = Properties.MaxVisibleLeds; _lastToReveal = toReveal; }
public override void DrawSpecial(SKCanvas canvas) { using (var path = new SKPath()) { path.AddRect(Box); DrawPath(canvas, path); } }
public static SKPath ToPath(this SKRectI bounds) { var path = new SKPath(); path.AddRect(bounds); path.Close(); return(path); }
public static SKPath CreateRectanglePath(float width, float height, SKPathDirection direction = SKPathDirection.Clockwise) { var path = new SKPath(); path.AddRect(new SKRect(width / -2, height / -2, width / 2, height / 2), direction); path.Close(); return(path); }
protected override void OnUpdateHitTestPath(SKImageInfo info) { if (CanvasSizeChanged) { HitTestPath = new SKPath(); HitTestPath.AddRect(_destRect); } }
public void PathContainsPoint() { using (var path = new SKPath ()) { path.AddRect (SKRect.Create (10, 10, 100, 100), SKPathDirection.Clockwise); Assert.IsTrue (path.Contains (30, 30)); Assert.IsFalse (path.Contains (5, 30)); } }
/// <inheritdoc /> public override void AddRectangle(double x, double y, double width, double height) { x *= _coordinateScale; y *= -_coordinateScale; width *= _coordinateScale; height *= -_coordinateScale; _path.AddRect(new SKRect((float)x, (float)(y + height), (float)(x + width), (float)y)); }
public override void CalculateRenderProperties() { RenderRectangle = GetUnscaledRectangle(); var path = new SKPath(); path.AddRect(RenderRectangle); RenderPath = path; }
public RectangleGeometryImpl(Rect rect) { var path = new SKPath(); path.AddRect(rect.ToSKRect()); EffectivePath = path; Bounds = rect; }
public void PathContainsPoint() { using (var path = new SKPath()) { path.AddRect(SKRect.Create(10, 10, 100, 100), SKPathDirection.Clockwise); Assert.IsTrue(path.Contains(30, 30)); Assert.IsFalse(path.Contains(5, 30)); } }
private static SKPath Rigid() { // Изображение шарнира SKPath pin = new SKPath(); // Шарнир вверху pin.AddRect(new SKRect(-0.5f, -0.5f, 0.5f, 0.5f)); return(pin); }
public void SetPathWithoutClipDoesNotCreateEmptyRegion() { using var path = new SKPath(); path.AddRect(SKRect.Create(10, 20, 30, 40)); using var region = new SKRegion(); var isNonEmpty = region.SetPath(path); Assert.True(isNonEmpty); Assert.Equal(SKRectI.Truncate(path.Bounds), region.Bounds); }
public void FromPathWithoutClipDoesNotCreateEmptyRegion() { var path = new SKPath(); path.AddRect(SKRect.Create(10, 20, 30, 40)); var region = new SKRegion(path); Assert.NotEqual(SKRectI.Empty, region.Bounds); Assert.Equal(SKRectI.Truncate(path.Bounds), region.Bounds); }
public void SetPathWithEmptyClipDoesCreatesEmptyRegion() { var path = new SKPath(); path.AddRect(SKRect.Create(10, 20, 30, 40)); var region = new SKRegion(); var isNonEmpty = region.SetPath(path, new SKRegion()); Assert.IsFalse(isNonEmpty); Assert.AreEqual(SKRectI.Empty, region.Bounds); }
/// <summary> /// Given a text view and bounds (usually text bounds of a line), adds a rectangle representing the provided bounds to the path argument. /// This method will clip the provided bounds if they move beyond the endpoints of the viewport. /// </summary> internal static void AddRectangleToPath(double left, double top, double right, double bottom, double leftClip, double rightClip, SKPath path) { left = Math.Max(left, leftClip); right = Math.Min(right, rightClip); if (right > left) { path.AddRect(new SKRect( (float)left, (float)(top - BrushSelectionPainter.Overlap), (float)right, (float)(bottom + 2.0 * BrushSelectionPainter.Overlap))); } }
private void CreateRectangleContour() { // Прямоугольное сечение с начальными размерами if (contour != null) { contour.Dispose(); } contour = new SKPath(); contour.AddRect(new SKRect() { Left = 0, Right = 10, Bottom = 0, Top = 10 }); }
public void TestGeneratedShape(SKCanvas canvas) { // Fill color for Group Style var GroupStyleFillColor = new SKColor(230, 230, 230, 255); // Create Group Style fill paint var GroupStyleFillPaint = new SKPaint() { Style = SKPaintStyle.Fill, Color = GroupStyleFillColor, BlendMode = SKBlendMode.SrcOver, IsAntialias = true }; // Frame color for Group Style var GroupStyleFrameColor = new SKColor(0, 0, 0, 255); // Create Group Style frame paint var GroupStyleFramePaint = new SKPaint() { Style = SKPaintStyle.Stroke, Color = GroupStyleFrameColor, BlendMode = SKBlendMode.SrcOver, IsAntialias = true, StrokeWidth = 1f, StrokeMiter = 4f, StrokeJoin = SKStrokeJoin.Mitter, StrokeCap = SKStrokeCap.Butt }; //----------------------------------------------------------------------------- // Draw Group shape group // Define Rectangle shape path var RectanglePath = new SKPath(); RectanglePath.AddRect(new SKRect(29.55859f, 28.60938f, 193.6055f, 149.0313f), SKPathDirection.Clockwise); var GroupPath = RectanglePath; // Define Oval shape path var OvalPath = new SKPath(); OvalPath.AddOval(new SKRect(113.043f, 72.44141f, 294.5547f, 234.2383f), SKPathDirection.Clockwise); GroupPath = GroupPath.Op(OvalPath, SKPathOp.Union); // Draw Group boolean shape canvas.DrawPath(GroupPath, GroupStyleFillPaint); canvas.DrawPath(GroupPath, GroupStyleFramePaint); //----------------------------------------------------------------------------- }
static SKPath MakePath(RectangleGeometry rectangleGeometry) { var path = new SKPath(); FormsRectangle rect = rectangleGeometry.Rect; path.AddRect(new SKRect( Forms.ConvertToScaledPixel(rect.Left), Forms.ConvertToScaledPixel(rect.Top), Forms.ConvertToScaledPixel(rect.Right), Forms.ConvertToScaledPixel(rect.Bottom)), SKPathDirection.Clockwise); return(path); }
/// <summary> /// Converts the current shape to a path. /// </summary> /// <returns>The shape as a <c>SKPath</c>.</returns> public override SKPath ToPath() { // Update any attached properties EvaluateConnectedProperties(); // Construct new path var path = new SKPath(); // Define path path.AddRect(Rect, SKPathDirection.Clockwise); // Return path return(path); }
public override SKPath Render(SKCanvas g, Rectangle r, NodeStyle o) { var skPath = new SKPath(); skPath.AddRect(r.ToSKRect()); using (var p = new SKPaint() { IsAntialias = true }) { p.Color = new Pen(o.BackBrush).Color.ToSKColor(); g.DrawPath(skPath, p); p.IsStroke = true; p.Color = o.BorderPen.Color.ToSKColor(); p.StrokeWidth = o.BorderPen.Width; g.DrawPath(skPath, p); } return skPath; }
public SKPath CreateCircleMaskPath(float width, float height) { var min = Math.Min(width, height); SKPath path = new SKPath(); path.FillType = SKPathFillType.EvenOdd; path.AddCircle(width / 2, height / 2, min / 2); path.AddRect(new SKRect(0, 0, width, height)); path.Close(); return(path); }
public void DrawRectangle(IRectangle rectangle) { SKPath skPath = new SKPath(); SKRect skRect = SKRect.Create(0, 0, (float)rectangle.Width, (float)rectangle.Height); if (rectangle.RadiusX > 0 || rectangle.RadiusY > 0) { skPath.AddRoundRect(skRect, (float)rectangle.RadiusX, (float)rectangle.RadiusY); } else { skPath.AddRect(skRect); } DrawShapePath(skPath, rectangle); }
public void RectPathIsRect() { using (var path = new SKPath()) { var rect = SKRect.Create(10, 10, 100, 100); path.AddRect(rect, SKPathDirection.CounterClockwise); Assert.False(path.IsOval); Assert.False(path.IsLine); Assert.True(path.IsRect); Assert.False(path.IsRoundRect); Assert.Equal(rect, path.GetRect(out var isClosed, out var dir)); Assert.True(isClosed); Assert.Equal(SKPathDirection.CounterClockwise, dir); } }
private async void HandlePaintCanvas(object sender, SKPaintSurfaceEventArgs e) { SKImageInfo info = e.Info; SKCanvas canvas = e.Surface.Canvas; canvas.Clear(); if (_doSave) { using (var hole = new SKPath()) { hole.AddCircle(info.Width / 2, info.Height / 2, info.Width / 3); canvas.ClipPath(hole, antialias: true); } } canvas.SetMatrix(_m); //Draw ball image SKSize imgSize = new SKSize(_bitmap.Width, _bitmap.Height); SKRect aspectRect = SKRect.Create(info.Width, info.Height).AspectFit(imgSize); canvas.DrawBitmap(_bitmap, aspectRect); if (!_doSave) { canvas.ResetMatrix(); //Draw circle overlay using (var frame = new SKPath()) using (var hole = new SKPath()) { frame.AddRect(info.Rect); hole.AddCircle(info.Width / 2, info.Height / 2, info.Width / 3); SKPath frameHole = frame.Op(hole, SKPathOp.Difference); using (var p = new SKPaint { IsAntialias = true, Style = SKPaintStyle.Fill, Color = new SKColor(128, 128, 128, 200) }) { canvas.DrawPath(frameHole, p); } } } else { SKImage snapI = e.Surface.Snapshot(); snapI = snapI.Subset(canvas.DeviceClipBounds); SKData pngImage = snapI.Encode(); File.WriteAllBytes(_ballFilename, pngImage.ToArray()); await Navigation.PopAsync(); OnBallImageUpdated(_ballFilename); } }
public void GetFillPathIsWorking() { var paint = new SKPaint(); var rect = new SKRect(10, 10, 30, 30); var path = new SKPath(); path.AddRect(rect); var fillPath = new SKPath(); var isFilled = paint.GetFillPath(path, fillPath); Assert.True(isFilled); Assert.Equal(rect, fillPath.Bounds); Assert.Equal(4, fillPath.PointCount); }
public void ToWinding() { using var path = new SKPath(); path.AddRect(new SKRect(1, 2, 3, 4)); using var result = new SKPath(); path.FillType = SKPathFillType.Winding; Assert.True(path.ToWinding(result)); Assert.NotEqual(path, result); Assert.Equal(SKPathFillType.Winding, path.FillType); path.FillType = SKPathFillType.EvenOdd; Assert.True(path.ToWinding(result)); Assert.NotEqual(path, result); Assert.Equal(SKPathFillType.Winding, result.FillType); }