internal (SKColor strokeClr, SKColor fillClr) drawClockPaths(SKCanvas canvas, List <ClockPath> pathList, xColor colorStroke, xColor colorFill) { strokePaint.Color = colorFill.ToSKColor(); fillPaint.Color = colorStroke.ToSKColor(); if (pathList != null) { foreach (var path in pathList) { canvas?.Translate(path.OffsetX, path.OffsetY); if (!string.IsNullOrEmpty(path.StrokeColor) && !"-".Equals(path.StrokeColor)) { strokePaint.Color = colorStroke.IsDefault || colorStroke.IsEmpty ? path.GetStrokeColor(ClockfaceInfo != null && !BackImageAllowsBackColor ? ClockfaceInfo.MainColor + " " + ClockfaceInfo.HandColorsBanned : ColorBackground.HexString, ClockfaceInfo?.HandColorSuggestion).ToSKColor() : colorStroke.ToSKColor(); strokePaint.StrokeWidth = path.StrokeWidth; canvas?.DrawPath(path.SkPath, strokePaint); } if (!string.IsNullOrEmpty(path.FillColor) && !"-".Equals(path.FillColor)) { fillPaint.Color = colorFill.IsDefault || colorFill.IsEmpty ? path.GetFillColor(ClockfaceInfo != null && !BackImageAllowsBackColor ? ClockfaceInfo.MainColor + " " + ClockfaceInfo.HandColorsBanned : ColorBackground.HexString, ClockfaceInfo?.HandColorSuggestion).ToSKColor() : colorFill.ToSKColor(); canvas?.DrawPath(path.SkPath, fillPaint); } canvas?.Translate(-(path.OffsetX), -(path.OffsetY)); } } return(strokePaint.Color, fillPaint.Color); }
protected void DrawAxes(SKCanvas canvas, int height, int width, SKPoint[] points, float footerHeight, float headerHeight) { if (showYAxe && points.Length > 0) { var firstPointX = points.First().X; var lowestY = points.Min(p => p.Y); var highestY = points.Max(p => p.Y); using (var paint = new SKPaint { Style = SKPaintStyle.Stroke, Color = SKColors.Gray, StrokeWidth = this.LineSize, IsAntialias = true, }) { var path = new SKPath(); var from = new SKPoint(firstPointX, lowestY - MarginY + MarginY / 2); path.MoveTo(from); var toYAxe = new SKPoint(firstPointX, highestY + MarginY); path.LineTo(toYAxe); var toXAxe = new SKPoint(width - MarginX, highestY + MarginY); path.LineTo(toXAxe); canvas.DrawPath(path, paint); } using (var paint = new SKPaint()) { paint.TextSize = this.LabelTextSize; paint.IsAntialias = true; paint.Color = SKColors.Gray; paint.IsStroke = false; SKRect boundsLow = new SKRect(); SKRect boundsHigh = new SKRect(); var HighestValue = MaxValue.ToString(); var LowestValue = MinValue.ToString(); paint.MeasureText(HighestValue, ref boundsHigh); paint.MeasureText(LowestValue, ref boundsLow); canvas.DrawText(HighestValue, firstPointX - MarginX - boundsHigh.Width, lowestY + boundsHigh.Height / 2, paint); canvas.DrawText(LowestValue, firstPointX - MarginX - boundsLow.Width, highestY + boundsLow.Height / 2, paint); } } }
/********************************************************************** *********************************************************************/ // draws an arrow from receiver to sender for the given round static void DrawAckArrow(SKCanvas canvas, int round, SKPaint paint, String part, String dupAck, String cwnd, String tresh) { SKPoint arrowBegin, arrowEnd; arrowBegin = new SKPoint(); arrowEnd = new SKPoint(); switch (part) { case "start": // arrow start arrowBegin = new SKPoint(xEnd * xe, (yStart + yWidthStep * round) * ye); arrowEnd = new SKPoint((xEnd - arrowLength) * xe, (yStart + yWidthStep * round) * ye); break; case "arrive": // arrow arrive arrowBegin = new SKPoint((xStart + arrowLength) * xe, (yStart + yWidthStep * round) * ye); arrowEnd = new SKPoint(xStart * xe, (yStart + yWidthStep * round) * ye); DrawTextDupAck(canvas, round, dupAck, sk_blackTextSmall); DrawTextCwnd(canvas, round, cwnd, sk_blackTextSmall); DrawTextTresh(canvas, round, tresh, sk_blackTextSmall); break; } canvas.DrawLine(arrowBegin, arrowEnd, paint); // arrow head //calculate stuff double a = Math.Abs(arrowBegin.Y - arrowEnd.Y); double b = Math.Abs(arrowBegin.X - arrowEnd.X); //arrow head: calculate rotation degree double cos = a / b; double arcCos = Math.Acos(cos); double degree = arcCos * (180.0 / Math.PI); float rotationDegree = (float)degree - 45f; //arrow head: draw SKPath head = new SKPath(); head.MoveTo(arrowEnd); head.RLineTo(xPercent(0.02f), -xPercent(0.01f)); head.RLineTo(xPercent(0.0f), xPercent(0.02f)); head.Close(); var rotate = SKMatrix.CreateRotationDegrees(rotationDegree, arrowEnd.X, arrowEnd.Y); //head.Transform(rotate); canvas.DrawPath(head, paint); }
private void DrawOrganicInside(SKRect rect, SKCanvas canvas) { var quarterWidth = rect.Width / 4f; var cMultiplier = new SKPoint(quarterWidth * 0.5f, 0); var p0 = new SKPoint(rect.Left, rect.MidY); var p1 = new SKPoint(rect.Left + quarterWidth, rect.Top) + DeltaPoint(0); var p2 = new SKPoint(rect.Right - quarterWidth, rect.Top) + DeltaPoint(.5f); var p3 = new SKPoint(rect.Right, rect.MidY) + DeltaPoint(.9f); var p4 = new SKPoint(rect.Right - quarterWidth, rect.Bottom) + DeltaPoint(.65f); var p5 = new SKPoint(rect.Left + quarterWidth, rect.Bottom) + DeltaPoint(.4f); var qp1 = new SKPoint(rect.Left, rect.Top); var qp2 = new SKPoint(rect.Right, rect.Top); var qp3 = new SKPoint(rect.Right, rect.Bottom); var qp4 = new SKPoint(rect.Left, rect.Bottom); var m1 = new SKPoint(rect.MidX, rect.Top) + Multiply(DeltaPoint(.25f), new SKPoint(-1.5f, 2.4f)); var m2 = new SKPoint(rect.MidX, rect.Bottom) + Multiply(DeltaPoint(.65f), new SKPoint(0.5f, 1.8f)); var cp1 = p1 + cMultiplier; var cm1 = m1 - cMultiplier; var cp2 = p2 - cMultiplier; var cm2 = m1 + cMultiplier; var cp3 = p4 - cMultiplier; var cm3 = m2 + cMultiplier; var cp4 = p5 + cMultiplier; var cm4 = m2 - cMultiplier; // Draw path with quadratic Bezier using (var path = new SKPath()) { path.MoveTo(p0); path.QuadTo(qp1, p1); path.CubicTo(cp1, cm1, m1); path.CubicTo(cm2, cp2, p2); path.QuadTo(qp2, p3); path.QuadTo(qp3, p4); path.CubicTo(cp3, cm3, m2); path.CubicTo(cm4, cp4, p5); path.QuadTo(qp4, p0); canvas.DrawPath(path, _backgroundPaint); } }
void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); int numVertices = 7; float radius = 0.45f * Math.Min(info.Width, info.Height); SKPoint[] vertices = new SKPoint[numVertices]; double vertexAngle = -0.5f * Math.PI; // straight up // Coordinates of the vertices of the polygon for (int vertex = 0; vertex < numVertices; vertex++) { vertices[vertex] = new SKPoint(radius * (float)Math.Cos(vertexAngle), radius * (float)Math.Sin(vertexAngle)); vertexAngle += 2 * Math.PI / numVertices; } float cornerRadius = 100; // Create the path using (SKPath path = new SKPath()) { path.AddPoly(vertices, true); // Render the path in the center of the screen using (SKPaint paint = new SKPaint()) { paint.Style = SKPaintStyle.Stroke; paint.Color = SKColors.Blue; paint.StrokeWidth = 10; // Set argument to half the desired corner radius! paint.PathEffect = SKPathEffect.CreateCorner(cornerRadius / 2); canvas.Translate(info.Width / 2, info.Height / 2); canvas.DrawPath(path, paint); // Uncomment DrawCircle call to verify corner radius float offset = cornerRadius / (float)Math.Sin(Math.PI * (numVertices - 2) / numVertices / 2); paint.Color = SKColors.Green; // canvas.DrawCircle(vertices[0].X, vertices[0].Y + offset, cornerRadius, paint); } } }
public override void DrawSpecial(SKCanvas canvas) { var color = Color == null ? SKColors.Black : Color.ColorSpace.GetColor(Color, Alpha); using (var paint = new SKPaint { Color = color }) { Border?.Apply(paint, null); foreach (var pathData in Paths) { canvas.DrawPath(pathData, paint); } } }
void addAxeToCanvas(int vertexIndex) { SKPoint vertexPoint = getSKPointByCoordinates(vertexIndex, 0); SKPoint center = new SKPoint(0, 0); // Create the path using (SKPath path = new SKPath()) { // Begin at the first midpoint path.MoveTo(vertexPoint); path.LineTo(center); path.Close(); // Render the path from vertex to center of graph using (SKPaint paint = new SKPaint()) { paint.Style = SKPaintStyle.Stroke; paint.Color = Xamarin.Forms.Color.FromHex("#1F0D0F").ToSKColor(); paint.StrokeWidth = options.GraduationStrokeWidth / 2; canvas.DrawPath(path, paint); } } }
private void OnPainting(object sender, SKPaintSurfaceEventArgs e) { surface = e.Surface; canvas = surface.Canvas; canvas.Clear(SKColors.White); var touchPathStroke = new SKPaint { IsAntialias = true, Style = SKPaintStyle.Stroke, Color = SKColors.Black, StrokeWidth = 5 }; foreach (var touchPath in temporaryPaths) { canvas.DrawPath(touchPath.Value, touchPathStroke); } foreach (var touchPath in paths) { canvas.DrawPath(touchPath, touchPathStroke); } skimage = surface.Snapshot(); }
public override void DrawImage(SKCanvas dc) { if (NeedsToClear == true) { dc.Clear(); } var bounds = GetMainRect(); SKPath gp = new SKPath(); gp.AddOval(SKRect.Create(bounds.Left, bounds.Top + bounds.Height * 4 / 5, bounds.Width, bounds.Height / 5)); dc.DrawPath(gp, MainPaint); dc.DrawPath(gp, _borderBrush); gp = new SKPath(); gp.AddLine(new SKPoint(bounds.Left + bounds.Width / 4, bounds.Top + bounds.Height * 9 / 10), new SKPoint(bounds.Left + bounds.Width * 3 / 8, bounds.Top + bounds.Height * 5 / 10), true); gp.ArcTo(SKRect.Create(bounds.Left, bounds.Top + bounds.Height * 3 / 8, bounds.Width / 4, bounds.Height * 2 / 16), 90, 180, false); gp.ArcTo(SKRect.Create(bounds.Left + bounds.Width / 4, bounds.Top, bounds.Width / 2, bounds.Height * 3 / 8), 110, 320, false); // was 320 gp.ArcTo(SKRect.Create(bounds.Left + bounds.Width * 3 / 4, bounds.Top + bounds.Height * 3 / 8, bounds.Width / 4, bounds.Height * 2 / 16), -90, 180, false); gp.AddLine(new SKPoint(bounds.Left + bounds.Width * 5 / 8, bounds.Top + bounds.Height * 5 / 10), new SKPoint(bounds.Left + bounds.Width * 3 / 4, bounds.Top + bounds.Height * 9 / 10)); gp.AddLine(new SKPoint(bounds.Left + bounds.Width * 9 / 16, bounds.Top + bounds.Height * 9 / 10), new SKPoint(bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height * 7 / 10)); gp.AddLine(new SKPoint(bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height * 7 / 10), new SKPoint(bounds.Left + bounds.Width * 7 / 16, bounds.Top + bounds.Height * 9 / 10)); gp.Close(); dc.DrawPath(gp, MainPaint); dc.DrawPath(gp, _borderBrush); }
public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, IStyle style, ISymbolCache symbolCache) { if (!(feature.Geometry is MapsuiPolygon polygon && style is VectorStyle vectorStyle)) { return(false); } using (var path = polygon.ToSkiaPath(viewport, canvas.LocalClipBounds, 0)) using (var paint = new SKPaint { IsAntialias = true }) { paint.Style = SKPaintStyle.Stroke; paint.Color = vectorStyle.Outline.Color.ToSkia(); paint.StrokeWidth = (float)vectorStyle.Outline.Width; canvas.DrawPath(path, paint); paint.Style = SKPaintStyle.Fill; paint.Color = vectorStyle.Fill.Color.ToSkia(); path.FillType = SKPathFillType.InverseWinding; canvas.DrawPath(path, paint); } return(true); }
void PaintSurface(SKCanvas canvas, SKSize dimension, SKSize viewsize) { canvas.Clear(BackgroundColor); canvas.DrawRect(FitRectange(canvas.DeviceClipBounds), curStyle); if (ShowPoly) { if (dimension.Width == 0) { InvalidateMeasure(); return; } canvas.Scale(dimension.Width / (float)Width); canvas.DrawPath(path, curStyle); } }
protected override void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); /* * 500 is the diameter of the outer arc * each inner arc from the outer arc will get reduced by 50 * you can change the value according to make the arc smaller or bigger * */ float left, right; float top, bottom; right = left = (info.Width - 500) / 2; //get the left and right postions to support all the devices top = bottom = (info.Height - 500) / 2; //get the top and bottom postions to support all the devices //first Arc SKRect rect = new SKRect(left, top, info.Width - right, info.Height - bottom); //canvas.DrawCircle(info.Width / 2, info.Height / 2, 250, firstArcPaint); using (SKPath path = new SKPath()) { path.AddArc(rect, OvalStartAngle, OvalSweepAngle); canvas.DrawPath(path, firstArcPaint); } using (SKPath path = new SKPath()) { path.AddArc(rect, SecondStartAngle, SecondSweepAngle); canvas.DrawPath(path, secondArcPaint); } }
void DrawLeftBGPart(SKCanvas canvas, SKPaint paint, SKPaint shadowPaint) { using (var leftArcPath = new SKPath()) { // shadow canvas.DrawLine(LeftLines.Point2, LeftLines.End, shadowPaint); leftArcPath.MoveTo(LeftLines.Start); leftArcPath.LineTo(LeftLines.Point1); leftArcPath.AddArc(LeftLines.Arc, 135, 180); leftArcPath.MoveTo(LeftLines.Point2); leftArcPath.LineTo(LeftLines.End); canvas.DrawPath(leftArcPath, paint); } }
public static void DrawBanner(SKCanvas c, BaseIcon icon) { var f = (int)(ChicRatios.Get1024(50) * icon.Height); var tf = (int)(ChicRatios.Get1024(25) * icon.Height); var tt = (int)(ChicRatios.Get1024(23) * icon.Height); var t = (int)(ChicRatios.Get1024(20) * icon.Height); var et = (int)(ChicRatios.Get1024(18) * icon.Height); var ft = (int)(ChicRatios.Get1024(15) * icon.Height); var tw = (int)(ChicRatios.Get1024(12) * icon.Height); var n = (int)(ChicRatios.Get1024(9) * icon.Height); var s = (int)(ChicRatios.Get1024(7) * icon.Height); using (var textPaint = new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, Color = SKColors.White, Typeface = ChicTypefaces.BurbankBigRegularBlack, TextAlign = SKTextAlign.Left, TextSize = f }) { int width = (int)textPaint.MeasureText(icon.Banner); using (var path = new SKPath()) { path.FillType = SKPathFillType.EvenOdd; path.MoveTo(ft, ft); path.LineTo(width + f, tw); path.LineTo(width + tf, textPaint.TextSize + tt); path.LineTo(t, textPaint.TextSize + et); path.Close(); using (var filter = SKImageFilter.CreateDropShadow(0, 0, s, s, SKColors.Black)) c.DrawPath(path, new SKPaint { IsAntialias = true, FilterQuality = SKFilterQuality.High, Color = SKColor.Parse("#f5112c"), ImageFilter = filter }); } c.DrawText(icon.Banner, tf, textPaint.TextSize + n, textPaint); } }
private void DrawForeground(SKRect rect, SKCanvas canvas) { for (var i = 0; i < SegmentCount; i++) { var segmentWidth = TotalProgress / SegmentCount; var progress = Math.Max(0, Math.Min((CurrentProgress - (i * segmentWidth)) / segmentWidth, 1f)); using (var path = Segment(rect, i, SegmentCount, progress)) { if (!path.IsEmpty) { canvas.DrawPath(path, _foregroundPaint); } } } }
private static SKImageInfo BuildOuterDayRing(SKImageInfo info, SKCanvas canvas, float outerRingPercentageWidth, SKPaint arcPainter) { var outerRingActualWidth = Utility.GetWidthValueFromPercentage(info, outerRingPercentageWidth) * 2; var outerRingPaddingx = (info.Width - outerRingActualWidth) / 2; var outerRingPaddingy = (info.Height - outerRingActualWidth) / 2; SKRect rect = new SKRect(outerRingPaddingx, outerRingPaddingy, info.Width - outerRingPaddingx, info.Height - outerRingPaddingy); using (SKPath path = new SKPath()) { path.AddArc(rect, -79, 337); canvas.DrawPath(path, arcPainter); } return(info); }
public SKPath Render(SKCanvas g, Rectangle r, NodeStyle o) { this.UpdateBounds(r); var skPath = new SKPath(); skPath.AddCircle(this.Bounds.Center().X, this.Bounds.Center().Y, this.Bounds.Center().Y - this.Bounds.Y); using (var p = new SKPaint() { IsAntialias = true }) { p.Color = new Pen(this.GetBackBrush()).Color.ToSKColor(); g.DrawPath(skPath, p); return(skPath); } }
public void RenderLimitLineLine(SKCanvas c, LimitLine limitLine, SKPoint position) { LimitLineSegmentsBuffer[0] = new SKPoint(position.X, ViewPortHandler.ContentTop); LimitLineSegmentsBuffer[1] = new SKPoint(position.Y, ViewPortHandler.ContentBottom); LimitLinePath.Reset(); LimitLinePath.MoveTo(LimitLineSegmentsBuffer[0]); LimitLinePath.LineTo(LimitLineSegmentsBuffer[1]); LimitLinePaint.Style = SKPaintStyle.Stroke; LimitLinePaint.Color = limitLine.LineColor; LimitLinePaint.StrokeWidth = limitLine.LineWidth; LimitLinePaint.PathEffect = limitLine.DashPathEffect; c.DrawPath(LimitLinePath, LimitLinePaint); }
void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); using (SKPaint textPaint = new SKPaint()) { // Set Style for the character outlines textPaint.Style = SKPaintStyle.Stroke; // Set TextSize based on screen size textPaint.TextSize = Math.Min(info.Width, info.Height); // Measure the text SKRect textBounds; textPaint.MeasureText("@", ref textBounds); // Coordinates to center text on screen float xText = info.Width / 2 - textBounds.MidX; float yText = info.Height / 2 - textBounds.MidY; // Get the path for the character outlines using (SKPath textPath = textPaint.GetTextPath("@", xText, yText)) { // Create a new path for the outlines of the path using (SKPath outlinePath = new SKPath()) { // Convert the path to the outlines of the stroked path textPaint.StrokeWidth = 25; textPaint.GetFillPath(textPath, outlinePath); // Stroke that new path using (SKPaint outlinePaint = new SKPaint()) { outlinePaint.Style = SKPaintStyle.Stroke; outlinePaint.StrokeWidth = 5; outlinePaint.Color = SKColors.Red; canvas.DrawPath(outlinePath, outlinePaint); } } } } }
public void Render(SKCanvas canvas, float angleInRadians, SKPoint center, float scale) { if (_cachedScene == null) { _cachedScene = new CachedScene(); var paint = new SKPaint(); paint.IsAntialias = true; paint.Color = new SKColor(0x2c, 0x3e, 0x50); paint.StrokeCap = SKStrokeCap.Round; _cachedScene.LogoPaint = paint; _cachedScene.BackgroundRect = new SKRect(0, 0, 1080, 1800); _cachedScene.BackgroundPaint = new SKPaint { Color = new SKColor(255, 10, 10) }; _cachedScene.LogoPaths = new List <SKPath>(); for (int i = 1; i <= Columns; i++) { for (int y = 1; y <= Rows; y++) { var path = new SKPath(); path.MoveTo(71.4311121f, 56f); path.CubicTo(68.6763107f, 56.0058575f, 65.9796704f, 57.5737917f, 64.5928855f, 59.965729f); path.LineTo(43.0238921f, 97.5342563f); path.CubicTo(41.6587026f, 99.9325978f, 41.6587026f, 103.067402f, 43.0238921f, 105.465744f); path.LineTo(64.5928855f, 143.034271f); path.CubicTo(65.9798162f, 145.426228f, 68.6763107f, 146.994582f, 71.4311121f, 147f); path.LineTo(114.568946f, 147f); path.CubicTo(117.323748f, 146.994143f, 120.020241f, 145.426228f, 121.407172f, 143.034271f); path.LineTo(142.976161f, 105.465744f); path.CubicTo(144.34135f, 103.067402f, 144.341209f, 99.9325978f, 142.976161f, 97.5342563f); path.LineTo(121.407172f, 59.965729f); path.CubicTo(120.020241f, 57.5737917f, 117.323748f, 56.0054182f, 114.568946f, 56f); path.LineTo(71.4311121f, 56f); path.Close(); path.Offset(160 * i, 160 * y); _cachedScene.LogoPaths.Add(path); } } } canvas.Clear(SKColors.White); canvas.DrawRect(_cachedScene.BackgroundRect, _cachedScene.BackgroundPaint); foreach (var path in _cachedScene.LogoPaths) { canvas.DrawPath(path, _cachedScene.LogoPaint); } }
private void onPaintsurface(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; using (SKPaint paint = new SKPaint() { Style = SKPaintStyle.Stroke, Color = SKColors.WhiteSmoke, IsAntialias = true }) { canvas.Clear(); var redState = GetRedState(); var yellowState = GetYellowState(); var greenState = GetGreenState(); paint.Color = redState; paint.Style = redState != IDLE_COLOR ? SKPaintStyle.StrokeAndFill : SKPaintStyle.Stroke; // Some goofy geometry float Th = 0.62f * info.Height - 0.67f * info.Width; float x = 0.035f * info.Height; // 3.5 percentage of height gap using (SKPath path = new SKPath()) { path.MoveTo(0, Th); path.LineTo(info.Width / 2, 0); path.LineTo(info.Width, Th); path.LineTo(0, Th); path.Close(); canvas.DrawPath(path, paint); } SKRect middleRect = new SKRect(0, Th + x, info.Width, x + 1.5f * Th); paint.Color = yellowState; paint.Style = yellowState != IDLE_COLOR ? SKPaintStyle.StrokeAndFill : SKPaintStyle.Stroke; canvas.DrawRect(middleRect, paint); paint.Color = greenState; paint.Style = greenState != IDLE_COLOR ? SKPaintStyle.StrokeAndFill : SKPaintStyle.Stroke; canvas.DrawCircle(info.Width / 2.0f, 1.5f * Th + 2.0f * x + info.Width / 2.0f, info.Width / 2.0f, paint); } }
public override void DrawContent(SKCanvas canvas, int width, int height) { if (Entries != null) { DrawCaption(canvas, width, height); using (new SKAutoCanvasRestore(canvas)) { if (DrawDebugRectangles) { using (var paint = new SKPaint { Color = SKColors.Red, IsStroke = true, }) { canvas.DrawRect(DrawableChartArea, paint); } } canvas.Translate(DrawableChartArea.Left + DrawableChartArea.Width / 2, height / 2); var sumValue = Entries.Sum(x => Math.Abs(x.Value)); var radius = (Math.Min(DrawableChartArea.Width, DrawableChartArea.Height) - (2 * Margin)) / 2; var start = 0.0f; for (int i = 0; i < Entries.Count(); i++) { var entry = Entries.ElementAt(i); var end = start + ((Math.Abs(entry.Value) / sumValue) * AnimationProgress); // Sector var path = RadialHelpers.CreateSectorPath(start, end, radius, radius * HoleRadius); using (var paint = new SKPaint { Style = SKPaintStyle.Fill, Color = entry.Color, IsAntialias = true, }) { canvas.DrawPath(path, paint); } start = end; } } } }
private void PlotStockEvolution(ArrayList points, int no, float MaxValue, float MinValue) { float value_offset = MaxValue - MinValue; var paddingHeight = height / 8; var paddingWidht = width / 8; var bottom = 2 * paddingHeight + height / 2;; int levels = xLabels.Count; int realHeight = height / 2; int realWidth = 3 * width / 4; int y_offset = height / levels / 2; int dy = realHeight - y_offset; var path = new SKPath(); var topLine = new SKPath(); path.MoveTo(paddingWidht, bottom); path.LineTo(paddingWidht, bottom - (y_offset + dy * (((float)points[0] - MinValue) / value_offset))); topLine.MoveTo(paddingWidht, bottom - (y_offset + dy * (((float)points[0] - MinValue) / value_offset))); for (int i = 1; i < points.Count; i++) { path.LineTo(paddingWidht + realWidth * i / (points.Count - 1), bottom - (y_offset + dy * (((float)points[i] - MinValue) / value_offset))); topLine.LineTo(paddingWidht + realWidth * i / (points.Count - 1), bottom - (y_offset + dy * (((float)points[i] - MinValue) / value_offset))); } path.LineTo(paddingWidht + realWidth, bottom); path.LineTo(paddingWidht, bottom); if (no == 1) { canvas.DrawPath(path, paint1); canvas.DrawPath(topLine, topLinePaint1); } else { canvas.DrawPath(path, paint2); canvas.DrawPath(topLine, topLinePaint2); } }
protected void DrawArea(SKCanvas canvas, SKPoint[] points, SKSize itemSize, float origin) { if (LineAreaAlpha > 0 && points.Length > 1) { using (var paint = new SKPaint { Style = SKPaintStyle.Fill, Color = SKColors.White, IsAntialias = true, }) { using (var shaderX = CreateXGradient(points, (byte)(LineAreaAlpha * AnimationProgress))) using (var shaderY = CreateYGradient(points, (byte)(LineAreaAlpha * AnimationProgress))) { paint.Shader = EnableYFadeOutGradient ? SKShader.CreateCompose(shaderY, shaderX, SKBlendMode.SrcOut) : shaderX; var path = new SKPath(); path.MoveTo(points.First().X, origin); path.LineTo(points.First()); var last = (LineMode == LineMode.Spline) ? points.Length - 1 : points.Length; for (int i = 0; i < last; i++) { if (LineMode == LineMode.Spline) { var entry = Entries.ElementAt(i); var nextEntry = Entries.ElementAt(i + 1); var cubicInfo = CalculateCubicInfo(points, i, itemSize); path.CubicTo(cubicInfo.control, cubicInfo.nextControl, cubicInfo.nextPoint); } else if (LineMode == LineMode.Straight) { path.LineTo(points[i]); } } path.LineTo(points.Last().X, origin); path.Close(); canvas.DrawPath(path, paint); } } } }
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); } }
void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); // Translate to center canvas.Translate(info.Width / 2, info.Height / 2); // Draw the circle float radius = Math.Min(info.Width, info.Height) / 4; canvas.DrawCircle(0, 0, radius, blackStroke); // Get the value of the Slider float angle = (float)angleSlider.Value; // Calculate sin and cosine for half that angle float sin = (float)Math.Sin(Math.PI * angle / 180 / 2); float cos = (float)Math.Cos(Math.PI * angle / 180 / 2); // Find the points and weight SKPoint point0 = new SKPoint(-radius * sin, radius * cos); SKPoint point1 = new SKPoint(0, radius / cos); SKPoint point2 = new SKPoint(radius * sin, radius * cos); float weight = cos; // Draw the points canvas.DrawCircle(point0.X, point0.Y, 10, blackFill); canvas.DrawCircle(point1.X, point1.Y, 10, blackFill); canvas.DrawCircle(point2.X, point2.Y, 10, blackFill); // Draw the tangent lines canvas.DrawLine(point0.X, point0.Y, point1.X, point1.Y, dottedStroke); canvas.DrawLine(point2.X, point2.Y, point1.X, point1.Y, dottedStroke); // Draw the conic using (SKPath path = new SKPath()) { path.MoveTo(point0); path.ConicTo(point1, point2, weight); canvas.DrawPath(path, redStroke); } }
static void DrawArc(SKCanvas canvas, float position, int strokeWidth, SKColor color) { // Offset to match other tracks position += 0.5f; using var trackPath = new SKPath(); trackPath.MoveTo(0, position); trackPath.ArcTo(position, position, 0, SKPathArcSize.Small, SKPathDirection.CounterClockwise, position, 0); using var trackPaint = new SKPaint() { Style = SKPaintStyle.Stroke, StrokeWidth = strokeWidth, Color = color, IsAntialias = true }; canvas.DrawPath(trackPath, trackPaint); }
public void Draw(ref SKCanvas canvas, SKPaint paint, SKPathFillType fillType) { for (int iter = 1; iter < base.Count; iter++) { using (SKPath path = new SKPath()) { path.MoveTo(base[iter - 1].intersect); path.CubicTo(base[iter - 1].touch, base[iter].touch, base[iter].intersect); path.FillType = fillType; canvas.DrawPath(path, paint); } canvas.DrawCircle(base[iter].touch.X, base[iter].touch.Y, 6, paint); canvas.DrawCircle(base[iter].intersect.X, base[iter].intersect.Y, 6, paint); } canvas.DrawCircle(base[0].touch.X, base[0].touch.Y, 6, paint); canvas.DrawCircle(base[0].intersect.X, base[0].intersect.Y, 6, paint); }
public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IFeature feature, IGeometry geometry, float opacity) { if (style is LabelStyle labelStyle) { var worldCenter = geometry.GetBoundingBox().GetCentroid(); var center = viewport.WorldToScreen(worldCenter); LabelRenderer.Draw(canvas, labelStyle, feature, (float)center.X, (float)center.Y, opacity); } else { var lineString = ((LineString)geometry).Vertices; float lineWidth = 1; var lineColor = new Color(); var vectorStyle = style as VectorStyle; var strokeCap = PenStrokeCap.Butt; var strokeStyle = PenStyle.Solid; if (vectorStyle != null) { lineWidth = (float)vectorStyle.Line.Width; lineColor = vectorStyle.Line.Color; strokeCap = vectorStyle.Line.PenStrokeCap; strokeStyle = vectorStyle.Line.PenStyle; } var line = WorldToScreen(viewport, lineString); var path = ToSkia(line); using (var paint = new SKPaint()) { paint.IsStroke = true; paint.StrokeWidth = lineWidth; paint.Color = lineColor.ToSkia(opacity); paint.StrokeJoin = SKStrokeJoin.Round; paint.StrokeCap = strokeCap.ToSkia(); if (strokeStyle != PenStyle.Solid) { paint.PathEffect = strokeStyle.ToSkia(lineWidth); } canvas.DrawPath(path, paint); } } }
/// <summary> /// Point of this function is to be same as DrawFill (ie draw 'tubes') but to draw /// in such a way that overlap regions are highlighted. However it does not work yet, /// need to draw continuous SKPaths as much as possible but break at direction changes. /// </summary> private void DrawFillOverlaps(ToolpathSet pathSetIn, SKCanvas baseCanvas) { SKColor fillColor = SkiaUtil.Color(255, 0, 255, 64); using (var paint = new SKPaint()) { paint.IsAntialias = true; paint.StrokeWidth = dimensionScale * PathDiameterMM; paint.Style = SKPaintStyle.Stroke; paint.StrokeCap = SKStrokeCap.Round; paint.StrokeJoin = SKStrokeJoin.Round; paint.Color = fillColor; Action <LinearToolpath3 <PrintVertex> > drawPath3F = (polyPath) => { if (polyPath.Type != ToolpathTypes.Deposition) { return; } Vector3d v0 = polyPath.Start.Position; byte layer_alpha = LayerFilterF(v0); if (layer_alpha != 255) { return; } // draw each segment separately. results in lots of duplicate-circles, no good //for (int i = 1; i < polyPath.VertexCount; i++) { // SKPoint a = SceneToSkiaF(polyPath[i - 1].Position.xy); // SKPoint b = SceneToSkiaF(polyPath[i].Position.xy); // baseCanvas.DrawLine(a.X, a.Y, b.X, b.Y, paint); //} // draw full path in one shot. Only shows overlaps between separate paths. //SKPath path = MakePath(polyPath, SceneToSkiaF); //baseCanvas.DrawPath(path, paint); // draw w/ angle threshold List <SKPath> paths = MakePathSegments(polyPath, SceneToSkiaF, 45); foreach (var path in paths) { baseCanvas.DrawPath(path, paint); } }; ProcessLinearPaths(pathSetIn, drawPath3F); } }